        @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700;900&family=Orbitron:wght@900&display=swap');

        :root {
            --bg-color: #121218;
            --panel-color: rgba(255, 255, 255, 0.05);
            --text-color: #ffffff;
            --accent-color: #ff0055;
            --lock-color: #333340;
        }

        body {
            margin: 0;
            padding: 0;
            background-color: var(--bg-color);
            background-image: 
                radial-gradient(circle at 10% 20%, rgba(40, 40, 60, 0.4) 0%, transparent 20%),
                radial-gradient(circle at 90% 80%, rgba(60, 40, 60, 0.4) 0%, transparent 20%);
            color: var(--text-color);
            font-family: 'Montserrat', sans-serif;
            overflow: hidden;
            touch-action: none;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            user-select: none;
            -webkit-user-select: none;
        }

        /* --- SCREENS --- */
        .screen {
            position: absolute;
            top: 0; left: 0; width: 100%; height: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            transition: opacity 0.3s ease, transform 0.3s ease;
            pointer-events: none;
            opacity: 0;
            z-index: 0;
        }

        .screen.active {
            opacity: 1;
            pointer-events: auto;
            z-index: 10;
        }


        /* --- GAME SCREEN --- */
        #game-container {
            position: relative;
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        canvas {
            border-radius: 20px;
            filter: drop-shadow(0 0 20px rgba(0,0,0,0.5));
        }

        #ui-layer {
            position: absolute;
            top: 0; left: 0; width: 100%; height: 100%;
            pointer-events: none;
            display: flex;
            flex-direction: column;
            align-items: center;
            z-index: 10;
        }

        #game-header {
            position: absolute;
            top: 12px;
            left: 12px;
            right: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            pointer-events: none;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 12px;
            pointer-events: auto;
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 10px;
            pointer-events: auto;
        }

        .level-badge {
            background: transparent; /* no background box for level */
            border: none;
            box-shadow: none;
            padding: 0;
            height: 32px; /* still align with buttons */
            display: flex;
            align-items: center;
        }

        .level-text {
            font-size: 14px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 2px;
            color: #d5d5d5;
        }

        .action-btn {
            padding: 0 16px;
            background: #d5d5d5;
            border: none;
            color: #121218;
            border-radius: 8px;
            font-size: 12px;
            font-weight: 700;
            cursor: pointer;
            pointer-events: auto;
            transition: all 0.2s;
            text-transform: uppercase;
            letter-spacing: 1px;
            display: flex;
            align-items: center;
            gap: 6px;
            height: 32px; /* Make all header buttons the same height */
        }

        /* Header buttons (Home & Restart) */
        .header-btn {
            pointer-events: auto;
        }

        /* Home button: square with equal padding */
        #menu-btn {
            padding: 0;
            width: 32px;
            justify-content: center;
            border-radius: 6px; /* slightly smaller radius for home */
        }

        /* Solution & Reset: a bit tighter horizontally */
        #solution-btn,
        #restart-btn {
            padding: 0 10px;
        }

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

        /* Overlay (victory backdrop) */
        #overlay {
            position: absolute;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(18, 18, 24, 0.7); /* light dim behind victory popup, no blur */
            /* no backdrop-filter here so background is NOT blurred */
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 100;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.4s ease;
        }
        #overlay.visible { opacity: 1; pointer-events: auto; }

        /* Centered victory popup panel inside overlay */
        .victory-panel {
            background: rgba(18, 18, 24, 1); /* more transparent victory card */
            border-radius: 24px;
            padding: 28px 32px 24px;
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow:
                0 24px 60px rgba(0, 0, 0, 0.7),
                0 0 0 1px rgba(255, 255, 255, 0.02);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
            min-width: 260px;
            max-width: 360px;
        }

        .overlay-title {
            font-size: 40px;
            font-weight: 900;
            margin-bottom: 4px;
            font-family: 'Orbitron', sans-serif; /* same font as logo */
            letter-spacing: 4px;
            text-transform: uppercase;
            color: #d5d5d5; /* match logo text color in popup */
        }
        
        .primary-btn {
            padding: 12px 32px;
            background: #d5d5d5;
            color: #121218;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 800;
            cursor: pointer;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            transition: transform 0.2s, background 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            justify-content: center; /* center icon + text inside button */
        }
        .primary-btn:hover { 
            transform: translateY(-2px);
            background: #c5c5c5;
        }

        .victory-actions {
            display: flex;
            gap: 12px;
            width: 100%;
            justify-content: center;
        }

        .victory-actions .primary-btn.secondary {
            background: transparent;
            color: #d5d5d5;
            border: 1px solid rgba(255, 255, 255, 0.25);
            box-shadow: none;
        }

        .victory-actions .primary-btn.secondary:hover {
            background: rgba(255, 255, 255, 0.06);
        }

        .icon { font-size: 20px; line-height: 1; }

        .material-symbols-rounded {
            font-family: 'Material Symbols Rounded', sans-serif;
            font-weight: normal;
            font-style: normal;
            font-size: inherit;
            display: inline-block;
            line-height: 1;
            text-transform: none;
            letter-spacing: normal;
            white-space: nowrap;
            direction: ltr;
            -webkit-font-smoothing: antialiased;
            font-variation-settings:
              'FILL' 0,
              'wght' 400,
              'GRAD' 0,
              'opsz' 24;
        }

        /* --- LEVEL POPUP --- */
        #level-popup {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(18, 18, 24, 0.7); /* softer dim behind level popup */
            z-index: 200;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s ease;
        }

        #level-popup.visible {
            opacity: 1;
            pointer-events: auto;
        }

        .popup-panel {
            width: min(520px, 95vw); /* wider popup */
            max-height: 80vh;
            background: rgba(18, 18, 24, 1); /* fully opaque starting popup card */
            border-radius: 24px;
            padding: 0; /* no outer padding on popup */
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow:
                0 24px 60px rgba(0, 0, 0, 0.7),
                0 0 0 1px rgba(255, 255, 255, 0.02);
            display: flex;
            flex-direction: column;
            overflow: hidden; /* clip scrollbar inside rounded corners */
        }

        .popup-scroll {
            max-height: 80vh;
            display: flex;
            flex-direction: column;
            overflow-y: auto; /* scroll inside, stays within border radius */
            scrollbar-color: #00CECB transparent; /* Firefox: use logo accent color */
        }

        /* Scrollbar styled similar to logo accent gradient */
        .popup-scroll::-webkit-scrollbar {
            width: 6px;
        }

        .popup-scroll::-webkit-scrollbar-track {
            background: transparent;
        }

        .popup-scroll::-webkit-scrollbar-thumb {
            background: linear-gradient(180deg, #00CECB, #8D3CFF);
            border-radius: 4px;
        }

        .popup-header {
            text-align: center;
            position: sticky; /* keep logo/title fixed at top */
            top: 0;
            z-index: 1;
            padding: 18px 28px 12px; /* more horizontal padding */
            margin: 0; /* no outside margin */
            background: rgba(18, 18, 24, 0.96); /* same as popup background */
        }

        .popup-title {
            font-size: 26px;
            font-weight: 900;
            letter-spacing: 4px;
            text-transform: uppercase;
            font-family: 'Orbitron', sans-serif;
            margin: 0;
            color: #d5d5d5;
        }

        .level-grid {
            margin-top: 0; /* no gap under logo */
            display: grid;
            grid-template-columns: repeat(5, minmax(0, 1fr));
            gap: 10px;
            padding: 10px 28px 22px; /* increased horizontal padding */
        }

        .level-btn {
            position: relative;
            border-radius: 12px;
            border: 1px solid rgba(255, 255, 255, 0.12);
            background: rgba(18, 18, 24, 0.95);
            color: #fff;
            font-size: 14px;
            font-weight: 700;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 4px;
            padding: 0;
            aspect-ratio: 1 / 1; /* perfect square */
            cursor: pointer;
            box-shadow: 0 8px 18px rgba(0, 0, 0, 0.55);
            transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
        }

        .level-btn:hover:not(.locked) {
            transform: translateY(-2px);
            box-shadow: 0 12px 26px rgba(0, 0, 0, 0.65);
            border-color: rgba(255, 255, 255, 0.6);
        }

        .level-btn.locked {
            background: linear-gradient(135deg, #191926, #111118);
            border-color: rgba(255, 255, 255, 0.06);
            color: rgba(255, 255, 255, 0.35);
            cursor: not-allowed;
            box-shadow: none;
        }

        .level-btn.locked span {
            font-size: 16px;
        }

        .level-btn.completed {
            /* cleaner, flatter green */
            background: #1DB954; /* Spotify-style green */
            border-color: #18a34a;
            color: #ffffff;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35); /* much softer glow */
        }

        .level-num {
            font-size: 16px;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
            opacity: 0.8;
        }

        .level-icon {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .level-btn.current {
            background: linear-gradient(135deg, #00CECB, #8D3CFF);
            color: #121218;
            border-color: #ffffff;
            box-shadow:
                0 0 24px rgba(141, 60, 255, 0.7),
                0 0 10px rgba(255, 255, 255, 0.4);
        }

        .level-btn-label {
            position: absolute;
            top: 4px;
            right: 6px;
            font-size: 9px;
            letter-spacing: 2px;
            opacity: 0.7;
        }

        /* Current level: only a glowing dot in the corner (no text) */
        .level-btn.current .level-btn-label::before {
            content: '●';
            font-size: 11px;
        }

        /* Central check icon for completed cards */
        .level-check {
            font-size: 20px;
            line-height: 1;
        }

        /* --- RESPONSIVE LAYOUT --- */

        /* Base: keep board full-bleed inside game container */
        #game-container {
            padding: 0;
            box-sizing: border-box;
        }

        #game-header {
            gap: 4px;
        }

        .action-btn {
            padding: 0 12px;
        }

        /* --- Small Mobile (≤480px) --- */
        @media (max-width: 480px) {
            body {
                font-size: 12px;
            }

            #game-container {
                padding: 0;
            }

            #game-header {
                top: 6px;
                left: 6px;
                right: 6px;
            }

            .header-left,
            .header-right {
                gap: 6px;
            }

            .level-text {
                font-size: 11px;
                letter-spacing: 1px;
            }

            .action-btn {
                height: 28px;
                font-size: 10px;
                padding: 0 8px;
            }

            #menu-btn {
                width: 28px;
            }

            .popup-panel {
                width: 95vw;
            }

            .popup-title {
                font-size: 20px;
                letter-spacing: 3px;
            }

            .level-grid {
                grid-template-columns: repeat(3, minmax(0, 1fr));
                gap: 8px;
                padding: 10px 18px 18px;
            }

            .level-btn {
                border-radius: 10px;
                font-size: 12px;
            }

            .victory-panel {
                max-width: 90vw;
                padding: 20px 18px 18px;
                gap: 14px;
            }

            .overlay-title {
                font-size: 28px;
                letter-spacing: 3px;
            }

            .primary-btn {
                padding: 10px 18px;
                font-size: 13px;
            }

            .victory-actions {
                flex-direction: column;
                align-items: stretch;
            }
        }

        /* --- Mobile (481px–640px) --- */
        @media (min-width: 481px) and (max-width: 640px) {
            body {
                font-size: 13px;
            }

            #game-header {
                top: 8px;
                left: 8px;
                right: 8px;
            }

            .action-btn {
                height: 30px;
                font-size: 11px;
                padding: 0 10px;
            }

            .popup-panel {
                width: 90vw;
            }

            .popup-title {
                font-size: 22px;
            }

            .level-grid {
                grid-template-columns: repeat(4, minmax(0, 1fr));
            }

            .victory-panel {
                max-width: 88vw;
            }
        }

        /* --- Tablet Portrait (641px–768px) --- */
        @media (min-width: 641px) and (max-width: 768px) {
            body {
                font-size: 14px;
            }

            #game-header {
                top: 10px;
                left: 10px;
                right: 10px;
            }

            .menu-title {
                font-size: 32px;
            }

            .popup-panel {
                width: 80vw;
            }

            .level-grid {
                grid-template-columns: repeat(4, minmax(0, 1fr));
            }

            .victory-panel {
                max-width: 70vw;
            }
        }

        /* --- Tablet Landscape (769px–1024px) --- */
        @media (min-width: 769px) and (max-width: 1024px) {
            body {
                font-size: 15px;
            }

            #game-header {
                top: 12px;
                left: 16px;
                right: 16px;
            }

            .menu-title {
                font-size: 34px;
            }

            .popup-panel {
                width: 70vw;
            }

            .level-grid {
                grid-template-columns: repeat(5, minmax(0, 1fr));
            }

            .victory-panel {
                max-width: 60vw;
            }
        }

        /* --- Desktop (≥1025px) --- */
        @media (min-width: 1025px) {
            body {
                font-size: 16px;
            }

            #game-container {
                padding: 0;
            }

            .popup-panel {
                width: min(520px, 60vw);
            }

            .victory-panel {
                max-width: 420px;
            }
        }

        /* --- Landscape Mobile (orientation: landscape) --- */
        @media (max-width: 812px) and (orientation: landscape) {
            body {
                font-size: 12px;
            }

            #game-container {
                padding: 0;
            }

            #game-header {
                top: 4px;
                left: 4px;
                right: 4px;
            }

            .header-left,
            .header-right {
                gap: 4px;
            }

            .action-btn {
                height: 26px;
                font-size: 10px;
                padding: 0 6px;
            }

            .victory-panel {
                max-width: 80vw;
                padding: 18px 16px 16px;
            }

            .victory-actions {
                flex-direction: row;
                gap: 8px;
            }
        }