/* --- 1. ЗМІННІ ТА БАЗОВІ НАЛАШТУВАННЯ --- */
        :root {
            --bg-dark: #020617;
            --bg-light: #1e293b;
            --ui-text: #f1f5f9;
            --ui-muted: #94a3b8;

            --col-success: #22c55e;
            --col-warning: #fbbf24;
            --col-danger: #ef4444;
            --col-accent: #f59e0b;

            --wall-base: #334155;
            --wall-border: #475569;

            --btn-primary: #22c55e;
            --btn-primary-shade: #15803d;
            --btn-secondary: #f97316;
            --btn-secondary-shade: #c2410c;
        }

        * {
            box-sizing: border-box;
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }

        .sr-only {
            position: absolute;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            white-space: nowrap;
            border: 0;
        }

        .skip-link {
            position: absolute;
            top: 8px;
            left: 8px;
            z-index: 1000;
            padding: 12px 16px;
            color: #fff;
            background: #0f172a;
            border-radius: 8px;
            transform: translateY(-140%);
            transition: transform 0.2s ease;
        }

        .skip-link:focus {
            transform: translateY(0);
        }

        body {
            margin: 0;
            padding: 0;
            background: linear-gradient(to bottom, var(--bg-dark) 0%, var(--bg-light) 100%);
            font-family: 'Roboto Mono', monospace;
            overflow: hidden;
            height: 100vh;
            color: var(--ui-text);
            display: flex;
            flex-direction: column;
            transition: box-shadow 0.1s;
        }

        body.miss-flash {
            box-shadow: inset 0 0 50px rgba(239, 68, 68, 0.8);
        }

        body.screen-shake {
            animation: screen-shake 0.08s linear;
        }

        /* --- 2. ІГРОВИЙ СВІТ --- */
        #game-area {
            position: absolute;
            inset: 0;
            z-index: 10;
            overflow: hidden;
        }

        #damage-overlay {
            position: absolute;
            inset: 0;
            pointer-events: none;
            z-index: 90;
            background: radial-gradient(circle, transparent 50%, rgba(239, 68, 68, 0) 100%);
            transition: background 0.3s ease;
        }

        .city-skyline {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30vh;
            background-color: #0f172a;
            clip-path: polygon(0% 100%, 0% 80%, 5% 80%, 5% 60%, 10% 60%, 10% 85%,
                    15% 85%, 15% 40%, 25% 40%, 25% 70%, 30% 70%, 30% 50%,
                    40% 50%, 40% 80%, 45% 80%, 45% 20%, 55% 20%, 55% 90%,
                    60% 90%, 60% 55%, 70% 55%, 70% 80%, 75% 80%, 75% 45%,
                    85% 45%, 85% 75%, 90% 75%, 90% 60%, 95% 60%, 95% 90%,
                    100% 90%, 100% 100%);
            z-index: 1;
            opacity: 0.8;
        }

        .city-skyline::before {
            content: '';
            position: absolute;
            inset: 0;
            background-image: radial-gradient(#facc15 1px, transparent 1px);
            background-size: 12px 18px;
            opacity: 0.15;
        }

        #the-wall {
            position: absolute;
            right: 0;
            top: 0;
            bottom: 0;
            width: 80px;
            background: linear-gradient(90deg, var(--wall-base), var(--bg-light));
            border-left: 4px solid var(--wall-border);
            z-index: 50;
            box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
            transition: border-color 0.3s;
            overflow: hidden;
        }

        #the-wall.wall-left {
            left: 0;
            right: auto;
            border-left: none;
            border-right: 4px solid var(--wall-border);
            box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
            background: linear-gradient(270deg, var(--wall-base), var(--bg-light));
        }

        #the-wall.critical {
            border-left-color: var(--col-danger);
            animation: wall-shake 0.5s infinite;
        }

        #the-wall::after {
            content: '';
            position: absolute;
            inset: 0;
            background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.1'/%3E%3C/svg%3E");
            opacity: 0.4;
            pointer-events: none;
        }

        /* --- 3. UI ЕЛЕМЕНТИ --- */
        #ui-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            padding: 20px;
            z-index: 100;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            pointer-events: none;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        }

        .ui-group {
            display: flex;
            gap: 15px;
            pointer-events: auto;
        }

        .stat-box {
            background: rgba(15, 23, 42, 0.85);
            backdrop-filter: blur(4px);
            padding: 12px 20px;
            border-radius: 8px;
            border: 1px solid rgba(255, 255, 255, 0.15);
            font-size: 1.1rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
            transition: transform 0.2s;
        }

        .stat-box i {
            color: var(--ui-muted);
            font-size: 1.2em;
        }

        .stat-col {
            display: flex;
            flex-direction: column;
            line-height: 1.2;
        }

        .stat-label {
            font-size: 0.7em;
            color: var(--ui-muted);
        }

        .stat-val {
            font-size: 1.2em;
        }

        .timer-val {
            color: var(--ui-text);
        }

        .health-val {
            color: var(--col-success);
        }

        .score-val {
            color: var(--col-warning);
        }

        .combo-icon {
            color: var(--col-accent);
        }

        .combo-val {
            color: var(--col-warning);
            transition: all 0.1s;
        }

        .control-btn {
            background: rgba(30, 41, 59, 0.9);
            border: 1px solid var(--ui-muted);
            color: white;
            width: 48px;
            height: 48px;
            border-radius: 8px;
            font-size: 1.3rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
        }

        .control-btn:hover {
            background: #475569;
            transform: translateY(-2px);
        }

        .control-btn:focus-visible,
        .btn:focus-visible,
        select:focus-visible {
            outline: 3px solid var(--col-warning);
            outline-offset: 2px;
        }

        #layout-warning {
            position: absolute;
            top: 100px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(239, 68, 68, 0.95);
            color: white;
            padding: 12px 30px;
            border-radius: 50px;
            font-size: 1.2rem;
            font-weight: bold;
            z-index: 90;
            box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
            opacity: 0;
            transition: opacity 0.2s;
            pointer-events: none;
        }

        #layout-warning.visible {
            opacity: 1;
        }

        /* --- 4. ВОРОГИ ТА ЕФЕКТИ --- */
        .enemy {
            position: absolute;
            display: flex;
            align-items: center;
            justify-content: center;
            will-change: transform;
            z-index: 20;
        }

        /* Шахед */
        .enemy-shahed-body {
            width: 0;
            height: 0;
            border-top: 35px solid transparent;
            border-bottom: 35px solid transparent;
            border-left: 60px solid #1e293b;
            position: relative;
            filter: drop-shadow(0 0 1px #cbd5e1) drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.5));
        }

        .enemy-rtl .enemy-shahed-body {
            border-left: none;
            border-right: 60px solid #1e293b;
            filter: drop-shadow(0 0 1px #cbd5e1) drop-shadow(-2px 4px 6px rgba(0, 0, 0, 0.5));
        }

        .enemy-shahed-body::after {
            content: '';
            position: absolute;
            left: -63px;
            top: -5px;
            width: 8px;
            height: 10px;
            background: var(--col-accent);
            border-radius: 2px;
            box-shadow: -2px 0 8px var(--col-accent);
            animation: flicker 0.1s infinite;
        }

        .enemy-rtl .enemy-shahed-body::after {
            left: auto;
            right: -63px;
            box-shadow: 2px 0 8px var(--col-accent);
        }

        .enemy-label {
            /* Центрування літери відносно центру маси трикутника */
            position: absolute;
            left: -40px;
            top: 50%;
            transform: translate(-50%, -50%);
            font-family: 'Roboto Mono', monospace;
            font-size: 1.6rem;
            font-weight: 800;
            color: white;
            z-index: 22;
            background: rgba(0, 0, 0, 0.5);
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            pointer-events: none;
            text-shadow: 1px 1px 0 #000;
        }

        .enemy-rtl .enemy-label {
            left: auto;
            right: -40px;
            transform: translate(50%, -50%);
        }

        /* Ракета */
        .rocket-body {
            background: #1e293b;
            padding: 8px 12px 8px 24px;
            border-radius: 4px 30px 30px 4px;
            border: 2px solid #cbd5e1;
            display: flex;
            align-items: center;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
            position: relative;
            color: #fff;
            min-width: 80px;
        }

        .enemy-rtl .rocket-body {
            padding: 8px 24px 8px 12px;
            border-radius: 30px 4px 4px 30px;
        }

        .rocket-flame {
            position: absolute;
            left: -12px;
            top: 50%;
            transform: translateY(-50%);
            width: 18px;
            height: 12px;
            background: var(--col-accent);
            border-radius: 50%;
            box-shadow: -4px 0 10px var(--col-accent);
            animation: flame 0.1s infinite alternate;
        }

        .enemy-rtl .rocket-flame {
            left: auto;
            right: -12px;
            box-shadow: 4px 0 10px var(--col-accent);
        }

        .rocket-text {
            display: flex;
            align-items: center;
            gap: 1px;
            white-space: nowrap;
        }

        /* Текст */
        .word-char {
            font-size: 1.5rem;
            color: var(--ui-muted);
            margin: 0 1px;
            font-weight: 800;
        }

        .word-char.active {
            color: #fff;
            text-shadow: 0 0 10px #fff;
            transform: scale(1.2);
            display: inline-block;
        }

        .word-char.done {
            color: var(--col-success);
            text-shadow: 0 0 5px var(--col-success);
        }

        .word-char.error {
            color: var(--col-danger);
            text-shadow: 0 0 8px var(--col-danger);
            transform: scale(1.16);
            display: inline-block;
        }

        /* Стани цілі */
        .enemy.locked-target .enemy-shahed-body {
            border-left-color: var(--col-danger);
        }

        .enemy.locked-target .rocket-body {
            border-color: var(--col-danger);
        }

        .enemy.dimmed {
            opacity: 0.4;
        }

        /* Ефекти */
        .impact-crater {
            position: absolute;
            background: radial-gradient(circle, #020617 30%, #1e293b 70%);
            border-radius: 50%;
            border: 2px solid #334155;
            transform: translate(-50%, -50%);
            box-shadow: inset 3px 3px 8px rgba(0, 0, 0, 0.8);
            z-index: 51;
        }

        .wall-debris {
            position: absolute;
            width: 8px;
            height: 8px;
            background: #475569;
            z-index: 55;
            animation: debrisFly 0.8s ease-out forwards;
            border: 1px solid #1e293b;
        }

        .explosion {
            position: absolute;
            width: 80px;
            height: 80px;
            background: radial-gradient(circle, var(--col-accent) 0%, transparent 70%);
            border-radius: 50%;
            animation: explode 0.3s ease-out forwards;
            z-index: 60;
            mix-blend-mode: screen;
            pointer-events: none;
        }

        .laser {
            position: absolute;
            height: 3px;
            background: #fff;
            transform-origin: left center;
            box-shadow: 0 0 8px #fff, 0 0 15px var(--col-success);
            z-index: 25;
            pointer-events: none;
        }

        /* --- 5. МЕНЮ --- */
        .menu-overlay {
            position: absolute;
            inset: 0;
            background: rgba(15, 23, 42, 0.85);
            backdrop-filter: blur(8px);
            z-index: 200;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
        }

        #start-menu {
            padding: 32px 40px;
        }

        .start-layout {
            width: min(1360px, 100%);
            display: grid;
            grid-template-columns: minmax(420px, 1.1fr) minmax(720px, 1.35fr);
            gap: 32px;
            align-items: center;
        }

        .start-hero {
            text-align: left;
            display: flex;
            flex-direction: column;
            gap: 18px;
            padding-right: 16px;
        }

        .start-kicker {
            margin: 0;
            font-size: 0.95rem;
            font-weight: 700;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: #93c5fd;
        }

        .start-lead {
            max-width: 58ch;
            margin: 0;
            font-size: 1.18rem;
            color: #e2e8f0;
        }

        .start-features {
            display: grid;
            grid-template-columns: 1fr;
            gap: 14px;
            margin-top: 8px;
        }

        .start-feature {
            display: flex;
            align-items: center;
            gap: 14px;
            padding: 14px 16px;
            border-radius: 12px;
            background: rgba(15, 23, 42, 0.52);
            border: 1px solid rgba(148, 163, 184, 0.16);
            color: #dbeafe;
            font-size: 1rem;
            line-height: 1.45;
        }

        .start-feature i {
            flex: 0 0 auto;
            color: #fbbf24;
            font-size: 1.1rem;
        }

        .start-panel {
            background: rgba(8, 15, 30, 0.88);
            border: 1px solid rgba(148, 163, 184, 0.18);
            border-radius: 22px;
            box-shadow: 0 24px 80px rgba(2, 6, 23, 0.45);
            padding: 28px;
            display: flex;
            flex-direction: column;
            gap: 20px;
            text-align: left;
        }

        .start-panel-head h2 {
            margin: 0 0 10px;
            font-size: 1.8rem;
            color: #fff;
            text-transform: uppercase;
            letter-spacing: 0.06em;
        }

        .start-panel-head p {
            margin: 0;
            max-width: none;
            font-size: 1rem;
            color: #94a3b8;
        }

        .hidden {
            display: none !important;
        }

        h1 {
            font-size: clamp(3.6rem, 5vw, 5.8rem);
            margin: 0;
            color: #fff;
            text-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
            text-transform: uppercase;
            letter-spacing: 2px;
            font-weight: 700;
            line-height: 0.95;
        }

        p {
            color: #cbd5e1;
            max-width: 600px;
            margin-bottom: 20px;
            font-size: 1.1rem;
            line-height: 1.6;
        }

        .btn {
            border: none;
            padding: 16px 40px;
            color: #fff;
            font-size: 1.2rem;
            font-weight: 800;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            margin: 15px;
            text-transform: uppercase;
            font-family: inherit;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            background: var(--btn-primary);
            box-shadow: 0 5px 0 var(--btn-primary-shade);
        }

        .menu-overlay .btn {
            width: min(280px, 80vw);
            min-height: 62px;
            justify-content: center;
        }

        .start-actions {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 18px;
            flex-wrap: wrap;
        }

        .start-actions .btn {
            width: min(320px, 100%);
            margin: 0;
        }

        .start-hint {
            margin: 0;
            max-width: 360px;
            color: #94a3b8;
            font-size: 0.98rem;
            line-height: 1.45;
        }

        .confirm-panel {
            width: min(520px, calc(100vw - 32px));
            background: rgba(8, 15, 30, 0.96);
            border: 1px solid rgba(148, 163, 184, 0.2);
            border-radius: 20px;
            box-shadow: 0 24px 80px rgba(2, 6, 23, 0.45);
            padding: 28px;
            text-align: left;
        }

        .confirm-panel h2 {
            margin: 0 0 12px;
            font-size: 1.8rem;
            color: #fff;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .confirm-panel p {
            margin: 0 0 22px;
            max-width: none;
        }

        .confirm-actions {
            display: flex;
            gap: 16px;
            flex-wrap: wrap;
        }

        .confirm-actions .btn {
            margin: 0;
            min-width: 220px;
        }

        .btn:hover {
            transform: translateY(-2px);
            filter: brightness(1.1);
            box-shadow: 0 7px 0 var(--btn-primary-shade);
        }

        .btn:active {
            transform: translateY(2px);
            box-shadow: 0 0 0 var(--btn-primary-shade);
        }

        .btn-alt {
            background: var(--btn-secondary);
            box-shadow: 0 5px 0 var(--btn-secondary-shade);
        }

        .btn-alt:hover {
            box-shadow: 0 7px 0 var(--btn-secondary-shade);
        }

        .btn-alt:active {
            box-shadow: 0 0 0 var(--btn-secondary-shade);
        }

        .game-over-title {
            text-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
        }

        .game-over-stats {
            grid-template-columns: repeat(2, minmax(220px, 1fr));
            gap: 18px 28px;
            margin: 16px 0 10px;
            padding: 18px 22px;
            align-items: start;
        }

        .game-over-line {
            margin: 0;
        }

        .game-over-metric {
            display: flex;
            flex-direction: column;
            gap: 0;
        }

        .game-over-high-score {
            color: var(--ui-muted);
            font-size: 1rem;
            margin-top: 4px;
            grid-column: 1 / -1;
        }

        .options-grid {
            display: grid;
            grid-template-columns: repeat(2, minmax(240px, 1fr));
            gap: 18px 20px;
            margin: 0;
        }

        .option-group label {
            display: block;
            margin-bottom: 10px;
            color: var(--ui-muted);
            font-size: 0.9rem;
            font-weight: bold;
            text-align: left;
        }

        select {
            width: 100%;
            min-height: 60px;
            padding: 12px 16px;
            background: #0f172a;
            color: white;
            border: 2px solid #334155;
            border-radius: 10px;
            font-size: 1rem;
            font-family: inherit;
            cursor: pointer;
        }

        select:focus {
            border-color: var(--col-success);
        }

        /* Стилі для туторіалу */
        .tutorial-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            margin: 20px 0;
            max-width: 800px;
            width: 100%;
        }

        .tut-item {
            background: rgba(255, 255, 255, 0.05);
            padding: 20px;
            border-radius: 12px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .enemy-preview {
            width: 80px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 15px;
            position: relative;
        }

        .tut-shahed .body {
            width: 0;
            height: 0;
            border-top: 20px solid transparent;
            border-bottom: 20px solid transparent;
            border-left: 40px solid #1e293b;
            filter: drop-shadow(0 0 1px #cbd5e1);
        }

        .tut-shahed .label {
            position: absolute;
            left: 46px;
            top: 50%;
            transform: translate(-50%, -50%);
            background: rgba(0, 0, 0, 0.5);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
        }

        .tut-rocket .body {
            background: #1e293b;
            padding: 4px 12px;
            border-radius: 4px 20px 20px 4px;
            border: 2px solid #cbd5e1;
            color: white;
            font-size: 1rem;
        }

        .tut-info {
            text-align: left;
            background: rgba(0, 0, 0, 0.3);
            padding: 15px 30px;
            border-radius: 8px;
            margin-bottom: 20px;
            border-left: 4px solid var(--col-warning);
        }

        .tut-info p {
            margin: 5px 0;
            font-size: 1rem;
            color: #e2e8f0;
        }

        /* --- 6. АНІМАЦІЇ --- */
        @keyframes flicker {
            0% {
                opacity: 0.8;
            }

            100% {
                opacity: 1;
            }
        }

        @keyframes flame {
            from {
                width: 12px;
                opacity: 0.8;
            }

            to {
                width: 18px;
                opacity: 1;
            }
        }

        @keyframes explode {
            0% {
                transform: scale(0.1);
                opacity: 1;
            }

            100% {
                transform: scale(1.5);
                opacity: 0;
            }
        }

        @keyframes debrisFly {
            0% {
                transform: translate(0, 0) rotate(0);
                opacity: 1;
            }

            100% {
                transform: translate(-50px, 150px) rotate(360deg);
                opacity: 0;
            }
        }

        @keyframes pulse-red {

            0%,
            100% {
                color: var(--ui-text);
                transform: scale(1);
            }

            50% {
                color: var(--col-danger);
                transform: scale(1.1);
            }
        }

        @keyframes pulse-gold {

            0%,
            100% {
                transform: scale(1);
                text-shadow: 0 0 10px var(--col-warning);
            }

            50% {
                transform: scale(1.2);
                text-shadow: 0 0 20px var(--col-warning), 0 0 30px white;
            }
        }

        @keyframes screen-shake {
            0% {
                transform: translate(0, 0);
            }

            25% {
                transform: translate(4px, -3px);
            }

            50% {
                transform: translate(-4px, 3px);
            }

            75% {
                transform: translate(3px, 2px);
            }

            100% {
                transform: translate(0, 0);
            }
        }

        @keyframes wall-shake {
            0% {
                transform: translateX(0);
            }

            25% {
                transform: translateX(-2px);
            }

            75% {
                transform: translateX(2px);
            }

            100% {
                transform: translateX(0);
            }
        }

        @media (max-width: 900px) {
            #start-menu {
                padding: 24px 18px;
            }

            .start-layout {
                grid-template-columns: 1fr;
                gap: 24px;
            }

            .start-hero {
                padding-right: 0;
                text-align: center;
                align-items: center;
            }

            .start-lead {
                max-width: 44rem;
            }

            .start-feature {
                text-align: left;
            }

            .start-panel {
                padding: 22px;
            }

            .options-grid {
                grid-template-columns: 1fr 1fr;
            }

            #ui-layer {
                flex-direction: column;
                gap: 16px;
                padding: 16px;
            }

            .ui-group {
                flex-wrap: wrap;
            }

            .tutorial-grid {
                grid-template-columns: 1fr;
                max-width: 560px;
            }

            h1 {
                font-size: clamp(2.8rem, 8vw, 4.1rem);
                letter-spacing: 1px;
            }
        }

        @media (max-width: 640px) {
            .stat-box {
                padding: 10px 14px;
                gap: 8px;
            }

            .menu-overlay {
                padding: 16px;
                justify-content: flex-start;
                overflow-y: auto;
            }

            .options-grid {
                width: min(100%, 560px);
                grid-template-columns: 1fr;
            }

            .game-over-stats {
                grid-template-columns: 1fr;
                gap: 12px;
            }

            p {
                font-size: 1rem;
            }

            .start-actions {
                align-items: stretch;
            }

            .start-actions .btn {
                width: 100%;
            }

            .start-hint {
                max-width: none;
            }

            .confirm-panel {
                padding: 22px;
            }

            .confirm-actions .btn {
                width: 100%;
                min-width: 0;
            }
        }

        @media (prefers-reduced-motion: reduce) {
            *,
            *::before,
            *::after {
                animation-duration: 0.01ms !important;
                animation-iteration-count: 1 !important;
                transition-duration: 0.01ms !important;
                scroll-behavior: auto !important;
            }
        }

        .combo-glow {
            animation: pulse-gold 0.3s ease-in-out;
            color: #fff !important;
        }

        .timer-warning {
            animation: pulse-red 1s infinite;
        }
