/* ============================================
   CSS Variables & Base Reset
   ============================================ */

:root {
    --neon-cyan: #00f5ff;
    --neon-pink: #ff2a6d;
    --deep-black: #0a0a0f;
    --glow-cyan: 0 0 10px #00f5ff, 0 0 20px rgba(0, 245, 255, 0.6), 0 0 40px rgba(0, 245, 255, 0.3), 0 0 60px rgba(0, 245, 255, 0.1);
    --glow-pink: 0 0 10px rgba(255, 42, 109, 0.8), 0 0 20px rgba(255, 42, 109, 0.8), 0 0 30px rgba(255, 42, 109, 0.8);
}

/* Reset default browser styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Main body container */
body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--deep-black);
    font-family: 'Share Tech Mono', monospace;
    overflow: hidden;
    position: relative;
}

/* Animated background grid */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(90deg, rgba(0, 245, 255, 0.03) 1px, transparent 1px),
        linear-gradient(rgba(0, 245, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: gridMove 20s linear infinite;
    pointer-events: none;
}

@keyframes gridMove {
    0% { transform: perspective(500px) rotateX(60deg) translateY(0); }
    100% { transform: perspective(500px) rotateX(60deg) translateY(50px); }
}

/* Scanline overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 1000;
}

/* ============================================
   Background Animation (Menu Screens)
   ============================================ */

/* Background animation container */
.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: -1;
}

/* Hide background animation when game screen is active */
body:has(#gameScreen.active) .bg-animation {
    display: none;
}

/* Animated grid layer */
.bg-grid {
    position: absolute;
    top: -50%;
    left: -50%;
    right: -50%;
    bottom: -50%;
    background:
        linear-gradient(90deg, rgba(0, 245, 255, 0.12) 1px, transparent 1px),
        linear-gradient(rgba(0, 245, 255, 0.12) 1px, transparent 1px);
    background-size: 60px 60px;
    transform: perspective(500px) rotateX(60deg);
    animation: bgGridScroll 20s linear infinite;
}

@keyframes bgGridScroll {
    0% { transform: perspective(500px) rotateX(60deg) translateY(0); }
    100% { transform: perspective(500px) rotateX(60deg) translateY(60px); }
}

/* Horizon-bound particles (aligned with grid perspective) */
.bg-particles {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    perspective: 500px;
    perspective-origin: 50% 30%;
}

/* Individual particle element */
.bg-particle {
    position: absolute;
    left: var(--x);
    bottom: -10px;
    width: 3px;
    height: 3px;
    background: var(--neon-cyan);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--neon-cyan), 0 0 12px var(--neon-cyan);
    animation: particleToHorizon 10s linear var(--delay) infinite;
}

@keyframes particleToHorizon {
    0% {
        opacity: 0;
        transform: translateY(0) translateZ(100px) scale(1.2);
    }
    8% {
        opacity: 0.9;
    }
    70% {
        opacity: 0.5;
    }
    100% {
        opacity: 0;
        transform: translateY(-70vh) translateZ(-400px) scale(0.1);
    }
}

/* ============================================
   Game Container & Title
   ============================================ */

/* Main game container */
.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Title wrapper */
.game-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    text-transform: uppercase;
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

/* TENSION - Hero text with molten heat effect */
.title-tension {
    font-size: 5.5rem;
    letter-spacing: 0.25em;
    color: #ff2020;
    text-shadow:
        0 0 10px rgba(255, 32, 32, 0.7),
        0 0 25px rgba(255, 32, 32, 0.4),
        0 2px 0 #aa0000;
    position: relative;
    animation: tensionBurn 3s ease-in-out infinite, titleRedGlitch 2s ease-in-out infinite;
    padding-right: 0.25em;
}

/* Scan line overlay effect */
.title-tension::before {
    content: '';
    position: absolute;
    top: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.15) 2px,
        rgba(0, 0, 0, 0.15) 4px
    );
    pointer-events: none;
    animation: scanDrift 8s linear infinite;
}

/* Hot core glow beneath */
.title-tension::after {
    content: 'TENSION';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-right: 0.25em;
    color: transparent;
    background: linear-gradient(180deg,
        #ff6040 0%,
        #ff2020 50%,
        #cc0000 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    filter: blur(6px);
    opacity: 0.4;
    z-index: -1;
}

/* TENSION burn pulse animation */
@keyframes tensionBurn {
    0%, 100% {
        text-shadow:
            0 0 10px rgba(255, 32, 32, 0.7),
            0 0 25px rgba(255, 32, 32, 0.4),
            0 2px 0 #aa0000;
        filter: brightness(1);
    }
    50% {
        text-shadow:
            0 0 12px rgba(255, 32, 32, 0.8),
            0 0 30px rgba(255, 32, 32, 0.5),
            0 2px 0 #aa0000;
        filter: brightness(1.05);
    }
}

/* GRID - Hero text with molten heat effect */
.title-grid {
    font-size: 5.5rem;
    letter-spacing: 0.25em;
    color: #ff2020;
    text-shadow:
        0 0 10px rgba(255, 32, 32, 0.7),
        0 0 25px rgba(255, 32, 32, 0.4),
        0 2px 0 #aa0000;
    position: relative;
    animation: gridBurn 3s ease-in-out infinite, titleRedGlitch 2s ease-in-out infinite 0.15s;
    padding-right: 0.25em;
}

/* Scan line overlay effect */
.title-grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.15) 2px,
        rgba(0, 0, 0, 0.15) 4px
    );
    pointer-events: none;
    animation: scanDrift 8s linear infinite;
}

/* Hot core glow beneath */
.title-grid::after {
    content: 'GRID';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-right: 0.25em;
    color: transparent;
    background: linear-gradient(180deg,
        #ff6040 0%,
        #ff2020 50%,
        #cc0000 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    filter: blur(6px);
    opacity: 0.4;
    z-index: -1;
}

/* GRID burn pulse animation */
@keyframes gridBurn {
    0%, 100% {
        text-shadow:
            0 0 10px rgba(255, 32, 32, 0.7),
            0 0 25px rgba(255, 32, 32, 0.4),
            0 2px 0 #aa0000;
        filter: brightness(1);
    }
    50% {
        text-shadow:
            0 0 12px rgba(255, 32, 32, 0.8),
            0 0 30px rgba(255, 32, 32, 0.5),
            0 2px 0 #aa0000;
        filter: brightness(1.05);
    }
}

/* Title red glitch flicker effect */
@keyframes titleRedGlitch {
    0%, 100% {
        opacity: 1;
    }
    92% {
        opacity: 1;
    }
    93% {
        opacity: 0.8;
        text-shadow: -2px 0 var(--neon-cyan), 2px 0 #ff2020,
            0 0 10px rgba(255, 32, 32, 0.7),
            0 0 25px rgba(255, 32, 32, 0.4);
        transform: translateX(-2px);
    }
    94% {
        opacity: 1;
        transform: translateX(0);
    }
    96% {
        opacity: 0.9;
        text-shadow: 2px 0 var(--neon-cyan), -2px 0 #ff2020,
            0 0 10px rgba(255, 32, 32, 0.7),
            0 0 25px rgba(255, 32, 32, 0.4);
        transform: translateX(1px);
    }
    97% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scan line drift animation */
@keyframes scanDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(4px); }
}

/* ============================================
   HUD (Heads-Up Display)
   ============================================ */

/* HUD container */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 500;
    display: flex;
    justify-content: center;
    gap: 40px;
    padding: 12px 24px;
    background: rgba(10, 10, 15, 0.85);
    border: 1px solid rgba(0, 245, 255, 0.3);
    box-shadow: 0 0 15px rgba(0, 245, 255, 0.1), inset 0 0 20px rgba(0, 245, 255, 0.03);
}

/* HUD item wrapper */
.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

/* HUD label text */
.hud-label {
    font-size: 0.7rem;
    color: rgba(0, 245, 255, 0.6);
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

/* HUD value display */
.hud-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--neon-cyan);
    filter: drop-shadow(0 0 6px #00f5ff) drop-shadow(0 0 12px rgba(0, 245, 255, 0.5)) drop-shadow(0 0 20px rgba(0, 245, 255, 0.25));
}

/* Score value with fixed width */
.hud-value.score {
    min-width: 120px;
    text-align: center;
}

/* ============================================
   Canvas & Game Screen
   ============================================ */

/* Canvas wrapper */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Game canvas element */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, #0f0f1a 0%, #0a0a0f 100%);
}

/* Game screen container */
#gameScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
}

/* Game screen canvas wrapper */
#gameScreen .canvas-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Vignette effect on canvas */
.canvas-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
}

/* Screen shake animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* ============================================
   Menu System
   ============================================ */

/* Base screen container (hidden by default) */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

/* Active screen visibility */
.screen.active {
    display: flex;
}

/* Home screen layout */
#homeScreen {
    min-height: 100vh;
    justify-content: center;
}

/* Menu button container */
.menu {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 280px;
    margin-top: 300px;
}

/* Base menu button style */
.menu-button {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(0, 245, 255, 0.5);
    background: transparent;
    border: none;
    padding: 16px 32px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    outline: none;
}

/* Button hover/focus background effect */
.menu-button::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -20px;
    right: -20px;
    bottom: -10px;
    background: radial-gradient(ellipse at center, rgba(0, 245, 255, 0.08) 0%, transparent 70%);
    opacity: 0;
    filter: blur(8px);
    transition: opacity 0.2s ease;
}

/* Selected button glow state */
.menu-button.selected {
    color: var(--neon-cyan);
    filter: drop-shadow(0 0 6px #00f5ff) drop-shadow(0 0 12px rgba(0, 245, 255, 0.5)) drop-shadow(0 0 20px rgba(0, 245, 255, 0.25));
}

/* Selected button animated background */
.menu-button.selected::before {
    opacity: 1;
}

/* Levels screen layout */
#levelsScreen {
    min-height: 100vh;
    justify-content: center;
}

/* Settings screen layout */
#settingsScreen {
    min-height: 100vh;
    justify-content: center;
}

/* ============================================
   Settings Screen
   ============================================ */

/* Screen title heading */
.screen-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--neon-pink);
    text-shadow: var(--glow-pink);
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
}

/* Settings panel container */
.settings-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 320px;
    padding: 30px 40px;
    margin-top: 300px;
}

/* Settings row with label and control */
.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 60px;
}

/* Settings label text */
.settings-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    color: rgba(0, 245, 255, 0.7);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* Toggle switch wrapper */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

/* Hide native checkbox */
.toggle-switch input {
    display: none;
}

/* Toggle track background */
.toggle-track {
    position: relative;
    width: 84px;
    height: 42px;
    background: rgba(0, 245, 255, 0.1);
    transition: all 0.3s ease;
}

/* Toggle thumb (diamond shape) */
.toggle-thumb {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 30px;
    height: 30px;
    background: rgba(0, 245, 255, 0.4);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    transition: all 0.3s ease;
}

/* Checked state track */
.toggle-switch input:checked + .toggle-track {
    background: rgba(0, 245, 255, 0.15);
    border-color: var(--neon-cyan);
    box-shadow: inset 0 0 10px rgba(0, 245, 255, 0.2);
}

/* Checked state thumb with glow */
.toggle-switch input:checked + .toggle-track .toggle-thumb {
    left: 49px;
    background: var(--neon-cyan);
    box-shadow: 0 0 8px var(--neon-cyan), 0 0 16px var(--neon-cyan);
}

/* ============================================
   Pause Menu
   ============================================ */

/* Pause overlay backdrop */
.pause-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 15, 0.6);
    backdrop-filter: blur(3px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

/* Active pause overlay with fade-in */
.pause-overlay.active {
    display: flex;
    animation: overlayFadeIn 0.3s ease-out;
}

/* Overlay fade-in animation */
@keyframes overlayFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* Pause modal container */
.pause-modal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    padding: 48px 64px;
    position: relative;
    background: rgba(10, 10, 15, 0.95);
    border: 1px solid rgba(0, 245, 255, 0.4);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.15);
    animation: modalFadeIn 0.3s ease-out;
}

/* Modal scale-in animation */
@keyframes modalFadeIn {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Pause title with glitch effect */
.pause-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: 0.4em;
    color: var(--neon-pink);
    text-shadow: var(--glow-pink);
    position: relative;
    animation: titleGlitch 4s ease-in-out infinite;
}

/* Title glitch chromatic aberration effect */
@keyframes titleGlitch {
    0%, 100% {
        opacity: 1;
        text-shadow: var(--glow-pink);
    }
    92% {
        opacity: 1;
        text-shadow: var(--glow-pink);
    }
    93% {
        opacity: 0.8;
        text-shadow: -2px 0 var(--neon-cyan), 2px 0 var(--neon-pink);
        transform: translateX(-2px);
    }
    94% {
        opacity: 1;
        text-shadow: var(--glow-pink);
        transform: translateX(0);
    }
    96% {
        opacity: 0.9;
        text-shadow: 2px 0 var(--neon-cyan), -2px 0 var(--neon-pink);
        transform: translateX(1px);
    }
    97% {
        opacity: 1;
        text-shadow: var(--glow-pink);
        transform: translateX(0);
    }
}

/* Pause modal menu override */
.pause-modal .menu {
    margin-top: 8px;
    min-width: 220px;
}

/* Blur HUD when pause overlay is active */
#gameScreen:has(.pause-overlay.active) .hud {
    filter: blur(3px);
    transition: filter 0.3s ease-out;
}
