:root {
    --c-cyan: #7fffff;  /* Sickly Cyan */
    --c-mag: #e0a0f0;   /* Pale Lavender */
    --c-red: #ff0000;   /* Warning Red */
    --c-yel: #ff9a00;   /* Ember Orange */
    --c-dark: #050505;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    overflow: hidden; /* Critical: Prevents scrollbars from resizing canvas */
    font-family: 'Share Tech Mono', monospace;
    color: var(--c-cyan);
}

/* --- GAME LAYER --- */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    display: block;
    /* subtle contrast boost for the 'horror' feel */
    filter: contrast(1.1) saturate(1.1); 
}

/* --- POST-PROCESSING OVERLAYS (The "Scary" Factor) --- */
body::before {
    /* Vignette (Darkened corners) */
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 5;
    pointer-events: none;
    background: radial-gradient(circle, transparent 60%, rgba(0,0,0,0.8) 100%);
}

body::after {
    /* CRT Scanlines */
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 6;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* --- HUD LAYER --- */
#hud-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to canvas */
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-shadow: 0 0 5px var(--c-cyan);
}

/* HUD Elements */
#hud-score {
    font-size: 32px;
    font-weight: bold;
    letter-spacing: 2px;
}

#hud-top-center {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

#hud-title {
    font-family: 'Rajdhani', sans-serif;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 5px;
    color: var(--c-red);
    opacity: 0.8;
    text-shadow: 2px 0px 0px rgba(255,0,0,0.5), -2px 0px 0px rgba(0,255,255,0.5);
    animation: glitch-skew 3s infinite linear alternate-reverse;
}

#hud-wave-info {
    font-size: 18px;
    color: var(--c-yel);
    margin-top: 5px;
}

#hud-mult {
    position: absolute;
    top: 50%;
    right: 50px;
    transform: translateY(-50%);
    font-size: 64px;
    font-weight: bold;
    color: var(--c-yel);
    opacity: 0;
    transition: opacity 0.2s;
    text-shadow: 0 0 20px var(--c-yel);
}

#hud-mult.pulse {
    opacity: 0.8;
    animation: flicker 0.1s infinite;
}

/* Status / Bombs / Shield */
#hud-bottom-left {
    font-size: 20px;
    line-height: 1.5;
}

/* Grid Stability Bar */
.wave-cluster {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 200px;
    text-align: right;
}

#hud-grid-status .label {
    font-size: 12px;
    color: var(--c-red);
    margin-bottom: 5px;
    animation: flicker 2s infinite;
}

.bar-container {
    width: 100%;
    height: 10px;
    background: #220000;
    border: 1px solid #550000;
    box-shadow: 0 0 10px #ff0000 inset;
}

.bar-fill {
    height: 100%;
    background: #ff0000;
    width: 0%;
    box-shadow: 0 0 10px #ff0000;
    transform-origin: left;
    transition: transform 0.1s linear;
}

/* --- MODAL (Menu) --- */
#game-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 90%;
    max-width: 500px;
    padding: 40px;
    
    /* Smeared Glass Effect */
    background-color: rgba(20, 0, 0, 0.6);
    backdrop-filter: blur(8px) sepia(0.5);
    -webkit-backdrop-filter: blur(8px) sepia(0.5);
    
    border: 1px solid var(--c-red);
    box-shadow: 0 0 50px rgba(255, 0, 0, 0.2);
    text-align: center;
    pointer-events: auto;
}

#modal-title {
    font-family: 'Rajdhani', sans-serif;
    font-size: 48px;
    margin: 0 0 10px 0;
    color: var(--c-red);
    text-shadow: 4px 4px 0px #000;
    letter-spacing: 4px;
}

#modal-subtitle {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 30px;
    font-style: italic;
}

/* Controls */
#name-input {
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--c-cyan);
    color: #fff;
    font-family: 'Share Tech Mono', monospace;
    font-size: 24px;
    text-align: center;
    width: 100%;
    margin-bottom: 30px;
    outline: none;
}

.row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.ai-row {
    margin-bottom: 30px;
    border: 1px solid #333;
    padding: 10px;
    background: rgba(0,0,0,0.5);
}

/* Cyber Buttons */
.cyber-btn {
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--c-cyan);
    color: var(--c-cyan);
    font-family: 'Share Tech Mono', monospace;
    font-size: 18px;
    padding: 15px 30px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

.cyber-btn:hover {
    background: var(--c-cyan);
    color: #000;
    box-shadow: 0 0 20px var(--c-cyan);
}

.cyber-btn.small {
    font-size: 14px;
    padding: 10px 20px;
    border-color: #555;
    color: #888;
}
.cyber-btn.small:hover {
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 10px #fff;
}

/* AI Selector Buttons */
.ai-btn {
    background: transparent;
    border: 1px solid #555;
    color: #fff;
    width: 30px; height: 30px;
    cursor: pointer;
}
.ai-btn:hover { border-color: var(--c-cyan); color: var(--c-cyan); }
#ai-count-display { font-size: 20px; color: var(--c-cyan); width: 30px; display: inline-block; }

/* High Contrast / Helper Classes */
body.high-contrast #game-canvas { filter: grayscale(100%) contrast(200%); }
.c-red { color: var(--c-red); }
.c-cyan { color: var(--c-cyan); }
.c-yel { color: var(--c-yel); }
.c-green { color: var(--c-green); }

/* --- ANIMATIONS --- */
@keyframes flicker {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    51% { opacity: 1; }
    100% { opacity: 1; }
}

@keyframes glitch-skew {
    0% { transform: translateX(-50%) skew(0deg); }
    20% { transform: translateX(-50%) skew(-2deg); }
    40% { transform: translateX(-50%) skew(2deg); }
    60% { transform: translateX(-50%) skew(0deg); }
    80% { transform: translateX(-50%) skew(1deg); }
    100% { transform: translateX(-50%) skew(0deg); }
}

/* Help Content */
#help-content ul { text-align: left; list-style: none; padding: 0; }
#help-content li { margin-bottom: 10px; }