:root {
            --glass-bg: rgba(255, 255, 255, 0.03);
            --glass-border: rgba(255, 255, 255, 0.08);
            --glass-highlight: rgba(255, 255, 255, 0.2);
            --neon-accent: #667eea;
            --text-main: rgba(255, 255, 255, 0.9);
            --text-muted: rgba(255, 255, 255, 0.6);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            user-select: none;
            -webkit-user-select: none;
        }

        body {
            overflow: hidden;
            background: #050508;
            font-family: 'Outfit', sans-serif;
            color: var(--text-main);
        }

        canvas {
            display: block;
            width: 100vw !important;
            height: 100vh !important;
            height: 100dvh !important;
            cursor: crosshair;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1;
        }

        :-webkit-full-screen canvas,
        :fullscreen canvas {
            width: 100vw !important;
            height: 100vh !important;
        }

        .glass-panel {
            backdrop-filter: blur(24px) saturate(120%);
            -webkit-backdrop-filter: blur(24px) saturate(120%);
            background: linear-gradient(145deg,
                    rgba(255, 255, 255, 0.05) 0%,
                    rgba(255, 255, 255, 0.01) 100%);
            border: 1px solid var(--glass-border);
            border-top: 1px solid var(--glass-highlight);
            border-left: 1px solid var(--glass-highlight);
            box-shadow:
                0 20px 40px rgba(0, 0, 0, 0.4),
                inset 0 0 20px rgba(255, 255, 255, 0.02);
            border-radius: 24px;
            color: var(--text-main);
            transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
            position: absolute;
            z-index: 10;
            overflow: hidden;
        }

        .glass-panel::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg,
                    transparent,
                    rgba(255, 255, 255, 0.05),
                    transparent);
            transform: skewX(-15deg);
            transition: 0.5s;
            pointer-events: none;
        }

        .glass-panel:hover {
            background: linear-gradient(145deg,
                    rgba(255, 255, 255, 0.08) 0%,
                    rgba(255, 255, 255, 0.02) 100%);
            box-shadow:
                0 30px 60px rgba(0, 0, 0, 0.5),
                inset 0 0 20px rgba(255, 255, 255, 0.05);
            transform: translateY(-2px);
            border-color: rgba(255, 255, 255, 0.15);
        }

        .glass-panel:hover::before {
            left: 150%;
            transition: 0.7s ease-in-out;
        }

        #instructions-container {
            top: 32px;
            left: 32px;
            width: 280px;
            padding: 24px;
        }

        #instruction-title {
            font-weight: 500;
            font-size: 18px;
            margin-bottom: 8px;
            letter-spacing: -0.02em;
            background: linear-gradient(135deg, #fff 30%, #a5b4fc 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
        }

        .instruction-text {
            font-size: 14px;
            line-height: 1.5;
            color: var(--text-muted);
            font-weight: 300;
        }

        /* ── Sidebar ──────────────────────────────────────────────────────────── */
        #sidebar {
            top: 24px;
            right: 24px;
            width: 200px;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 0;
            max-height: 80vh;
            overflow-y: auto;
            border-radius: 20px;
        }

        .sidebar-section {
            padding: 14px 0;
        }

        .sidebar-label {
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 2px;
            color: rgba(255, 255, 255, 0.3);
            margin-bottom: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .sidebar-label #density-value {
            color: rgba(255, 255, 255, 0.7);
            font-weight: 400;
            text-shadow: none;
            letter-spacing: 0;
            font-size: 10px;
            text-transform: none;
        }

        #formation-name {
            font-size: 14px;
            font-weight: 400;
            color: rgba(255, 255, 255, 0.8);
            letter-spacing: 0.2px;
        }

        .sidebar-divider {
            height: 1px;
            background: rgba(255, 255, 255, 0.06);
            margin: 0 -20px;
        }

        .theme-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
            justify-items: center;
        }

        .theme-button {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            border: none;
            cursor: pointer;
            position: relative;
            transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
            box-shadow:
                0 4px 10px rgba(0, 0, 0, 0.3),
                inset 0 2px 4px rgba(255, 255, 255, 0.4),
                inset 0 -2px 4px rgba(0, 0, 0, 0.2);
        }

        #theme-1 { background: radial-gradient(circle at 30% 30%, #a78bfa, #4c1d95); }
        #theme-2 { background: radial-gradient(circle at 30% 30%, #fb7185, #9f1239); }
        #theme-3 { background: radial-gradient(circle at 30% 30%, #38bdf8, #0c4a6e); }
        #theme-4 { background: radial-gradient(circle at 30% 30%, #e0e8ff, #4060aa); }
        #theme-5 { background: radial-gradient(circle at 30% 30%, #00ff88, #004422); }
        #theme-6 { background: radial-gradient(circle at 30% 30%, #ffd700, #8b4500); }
        #theme-7 { background: radial-gradient(circle at 30% 30%, #ff6b9d, #6600cc); }
        #theme-8 { background: radial-gradient(circle at 30% 30%, #00f5d4, #003366); }

        .theme-button::after {
            content: '';
            position: absolute;
            top: -4px;
            left: -4px;
            right: -4px;
            bottom: -4px;
            border-radius: 50%;
            border: 2px solid rgba(255, 255, 255, 0.8);
            opacity: 0;
            transform: scale(1.1);
            transition: all 0.3s ease;
        }

        .theme-button:hover {
            transform: scale(1.15) translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 2px 6px rgba(255, 255, 255, 0.6);
        }

        .theme-button.active::after {
            opacity: 1;
            transform: scale(1);
            border-color: rgba(255, 255, 255, 0.9);
            box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
        }

        /* ── Random color mode ────────────────────────────────────────────────── */
        .random-color-toggle {
            display: flex;
            align-items: center;
            gap: 8px;
            width: 100%;
            padding: 8px 12px;
            border-radius: 10px;
            border: 1px solid rgba(255, 255, 255, 0.08);
            background: rgba(255, 255, 255, 0.03);
            color: rgba(255, 255, 255, 0.4);
            font-family: 'Outfit', sans-serif;
            font-size: 12px;
            font-weight: 400;
            cursor: pointer;
            transition: all 0.2s ease;
            text-align: left;
        }

        .random-color-toggle:hover {
            background: rgba(255, 255, 255, 0.07);
            color: rgba(255, 255, 255, 0.7);
            border-color: rgba(255, 255, 255, 0.15);
        }

        .random-color-toggle.active {
            background: rgba(255, 255, 255, 0.08);
            border-color: rgba(255, 255, 255, 0.25);
            color: white;
        }

        .theme-grid.randomized .theme-button {
            opacity: 0.3;
            pointer-events: none;
            cursor: default;
        }

        .density-label {
            display: flex;
            justify-content: space-between;
            font-size: 10px;
            color: rgba(255, 255, 255, 0.3);
            text-transform: uppercase;
            letter-spacing: 2px;
        }

        .density-slider {
            -webkit-appearance: none;
            width: 100%;
            height: 6px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            outline: none;
            box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
        }

        .density-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: #fff;
            cursor: pointer;
            box-shadow:
                0 0 15px rgba(255, 255, 255, 0.8),
                0 2px 5px rgba(0, 0, 0, 0.3);
            transition: all 0.2s ease;
            margin-top: -6px;
            position: relative;
            z-index: 2;
        }

        .density-slider::-webkit-slider-runnable-track {
            width: 100%;
            height: 6px;
            cursor: pointer;
            background: linear-gradient(90deg, rgba(255, 255, 255, 0.3) var(--val, 100%), rgba(255, 255, 255, 0.05) var(--val, 100%));
            border-radius: 3px;
        }

        .density-slider::-webkit-slider-thumb:hover {
            transform: scale(1.2);
            box-shadow: 0 0 20px rgba(255, 255, 255, 1);
        }

        /* ── Control bar ──────────────────────────────────────────────────────── */
        #control-bar {
            position: fixed;
            bottom: 28px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            align-items: center;
            gap: 2px;
            z-index: 20;
            padding: 6px 10px;
            background: rgba(5, 5, 10, 0.65);
            border: 1px solid rgba(255, 255, 255, 0.07);
            border-radius: 50px;
            backdrop-filter: blur(24px);
            -webkit-backdrop-filter: blur(24px);
            transition: opacity 0.4s ease;
        }

        .ctrl-btn {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 3px;
            background: transparent;
            border: none;
            color: rgba(255, 255, 255, 0.5);
            padding: 6px 14px;
            border-radius: 36px;
            cursor: pointer;
            font-family: 'Outfit', sans-serif;
            transition: color 0.2s, background 0.2s;
            white-space: nowrap;
        }

        .ctrl-btn:hover {
            color: rgba(255, 255, 255, 0.9);
            background: rgba(255, 255, 255, 0.06);
        }

        .ctrl-btn:active {
            background: rgba(255, 255, 255, 0.1);
        }

        .ctrl-btn.active {
            color: white;
        }

        .ctrl-btn.ctrl-disabled {
            opacity: 0.3;
            cursor: not-allowed;
            pointer-events: none;
        }

        .ctrl-icon {
            display: block;
            flex-shrink: 0;
        }

        .ctrl-label {
            font-size: 9px;
            font-weight: 500;
            letter-spacing: 1.2px;
            text-transform: uppercase;
        }

        .ctrl-divider {
            width: 1px;
            height: 24px;
            background: rgba(255, 255, 255, 0.08);
            margin: 0 2px;
            flex-shrink: 0;
        }

        /* ── Interval control (inside control bar, shown when autoplay active) ── */
        #interval-control {
            display: flex;
            align-items: center;
            gap: 4px;
            padding: 0 6px 0 2px;
        }

        #interval-display {
            font-size: 11px;
            color: rgba(255, 255, 255, 0.75);
            font-family: 'Outfit', sans-serif;
            min-width: 26px;
            text-align: center;
        }

        .interval-btn {
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.65);
            width: 22px;
            height: 22px;
            border-radius: 50%;
            cursor: pointer;
            font-size: 15px;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
            font-family: 'Outfit', sans-serif;
            transition: background 0.15s, color 0.15s;
        }

        .interval-btn:hover {
            background: rgba(255, 255, 255, 0.16);
            color: white;
        }

        @media (min-width: 641px) and (max-width: 1023px) {
            #sidebar {
                width: 180px;
                padding: 16px;
            }
        }

        @media (max-width: 640px) {
            #instructions-container { display: none; }
            #sidebar { display: none; }
            #interval-control { display: none !important; }
            #fullscreen-hint { display: none; }

            #mobile-menu-btn {
                display: flex;
                align-items: center;
                justify-content: center;
            }

            #control-bar {
                bottom: 20px;
                padding: 5px 8px;
            }

            .ctrl-btn {
                padding: 5px 10px;
            }

            .ctrl-label {
                font-size: 8px;
                letter-spacing: 0.8px;
            }
        }

        @media (max-width: 640px) and (orientation: landscape) {
            #control-bar { bottom: 8px; }
        }

        /* ── Opacity transitions for UI panels ───────────────────────────────── */
        #sidebar, #instructions-container, #mobile-menu-btn {
            transition: opacity 0.4s ease;
        }

        /* ── Fullscreen cursor autohide ──────────────────────────────────────── */
        body.cursor-hidden,
        body.cursor-hidden canvas,
        body.cursor-hidden * {
            cursor: none !important;
        }

        /* ── Hide UI mode ─────────────────────────────────────────────────────── */
        body.ui-hidden #sidebar,
        body.ui-hidden #control-bar,
        body.ui-hidden #instructions-container,
        body.ui-hidden #mobile-menu-btn {
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.4s ease;
        }

        /* ── Swipe hint ───────────────────────────────────────────────────────── */
        #swipe-hint {
            display: none;
        }

        @media (max-width: 1023px) {
            #swipe-hint {
                display: flex;
                justify-content: space-between;
                align-items: center;
                position: fixed;
                inset: 0;
                pointer-events: none;
                z-index: 5;
                padding: 0 12px;
                transition: opacity 1s ease;
            }

            #swipe-hint.hidden {
                opacity: 0;
            }

            #swipe-hint span {
                font-size: 32px;
                color: rgba(255, 255, 255, 0.15);
                font-weight: 200;
            }
        }

        /* ── Canvas state ─────────────────────────────────────────────────────── */
        canvas.splash-active {
            filter: blur(8px) brightness(0.4);
            transition: filter 0.8s ease;
        }

        /* ── Fullscreen hint (SVG icon) ───────────────────────────────────────── */
        #fullscreen-hint {
            position: fixed;
            bottom: 16px;
            right: 16px;
            color: rgba(255, 255, 255, 0.18);
            z-index: 5;
            pointer-events: none;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: color 0.2s;
        }

        /* ── Audio bars visualizer ────────────────────────────────────────────── */
        .sound-btn-inner {
            position: relative;
            width: 16px;
            height: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        #audio-bars {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: flex-end;
            justify-content: center;
            gap: 2px;
            padding-bottom: 1px;
            pointer-events: none;
        }

        #audio-bars.hidden { display: none; }

        #audio-bars span {
            width: 2px;
            background: rgba(255, 255, 255, 0.85);
            border-radius: 1px;
            animation: bar-bounce 0.7s ease-in-out infinite alternate;
            min-height: 3px;
        }

        #audio-bars span:nth-child(1) { animation-delay: 0.00s; }
        #audio-bars span:nth-child(2) { animation-delay: 0.15s; }
        #audio-bars span:nth-child(3) { animation-delay: 0.30s; }
        #audio-bars span:nth-child(4) { animation-delay: 0.45s; }

        @keyframes bar-bounce {
            from { height: 3px;  opacity: 0.5; }
            to   { height: 14px; opacity: 1.0; }
        }

        /* When bars are visible, hide the mic icon underneath */
        #sound-btn.active .sound-btn-inner svg {
            opacity: 0;
            transition: opacity 0.2s;
        }

        .sound-btn-inner svg {
            transition: opacity 0.2s;
        }

        .ctrl-icon.hidden { display: none; }

        /* ── Mobile gear button ───────────────────────────────────────────────── */
        #mobile-menu-btn {
            display: none;
            position: fixed;
            bottom: 88px;
            right: 16px;
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid rgba(255, 255, 255, 0.15);
            color: white;
            font-size: 22px;
            cursor: pointer;
            z-index: 30;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            transition: opacity 0.4s ease;
        }

        /* ── Mobile menu overlay ──────────────────────────────────────────────── */
        #mobile-menu-overlay {
            position: fixed;
            bottom: 148px;
            right: 16px;
            width: 260px;
            padding: 20px;
            z-index: 25;
            flex-direction: column;
            gap: 16px;
        }
        #mobile-menu-overlay:not([hidden]) {
            display: flex;
        }

        /* ── Splash screen ────────────────────────────────────────────────────── */
        #splash-screen {
            position: fixed;
            inset: 0;
            background: #050508;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 100;
            transition: opacity 0.8s ease;
        }
        #splash-screen.fade-out {
            opacity: 0;
            pointer-events: none;
        }

        #splash-content {
            position: relative;
            width: min(420px, 90vw);
            padding: 40px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 16px;
            text-align: center;
        }

        #splash-title {
            font-size: 26px;
            font-weight: 500;
            letter-spacing: -0.02em;
            background: linear-gradient(135deg, #fff 30%, #a5b4fc 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        #splash-subtitle {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.4);
            font-weight: 300;
        }
        #splash-divider {
            width: 40px;
            height: 1px;
            background: rgba(255, 255, 255, 0.15);
            margin: 4px 0;
        }
        #splash-mic-text {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.55);
            line-height: 1.6;
            font-weight: 300;
        }

        #splash-mic-btn, #splash-skip-btn {
            width: 100%;
            padding: 14px 24px;
            border-radius: 50px;
            font-family: 'Outfit', sans-serif;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            letter-spacing: 0.3px;
        }
        #splash-mic-btn {
            background: linear-gradient(135deg, rgba(102,126,234,0.3), rgba(118,75,162,0.3));
            border: 1px solid rgba(102, 126, 234, 0.6);
            color: white;
        }
        #splash-mic-btn:hover {
            background: linear-gradient(135deg, rgba(102,126,234,0.5), rgba(118,75,162,0.5));
            box-shadow: 0 0 30px rgba(102, 126, 234, 0.4);
            transform: translateY(-2px);
        }
        #splash-mic-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
        #splash-skip-btn {
            background: transparent;
            border: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.4);
        }
        #splash-skip-btn:hover {
            border-color: rgba(255, 255, 255, 0.25);
            color: rgba(255, 255, 255, 0.7);
        }

        @media (max-width: 640px) {
            #splash-content {
                padding: 28px 20px;
            }
            #splash-title {
                font-size: 22px;
            }
        }

        /* #audio-indicator removed — replaced by #audio-bars */

        /* ── Mobile help button (? / shortcuts) ─────────────────────────────── */
        #mobile-help-btn {
            display: none;
            position: fixed;
            top: 16px;
            left: 16px;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid rgba(255, 255, 255, 0.15);
            color: rgba(255, 255, 255, 0.5);
            font-size: 16px;
            font-family: 'Outfit', sans-serif;
            font-weight: 400;
            cursor: pointer;
            z-index: 30;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            transition: opacity 0.4s ease, color 0.2s;
            align-items: center;
            justify-content: center;
        }
        #mobile-help-btn:hover { color: white; }

        @media (max-width: 1023px) {
            #mobile-help-btn { display: flex; }
        }

        /* ── Keyboard shortcuts overlay ──────────────────────────────────────── */
        #shortcuts-overlay {
            position: fixed;
            inset: 0;
            z-index: 50;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
        }
        #shortcuts-overlay[hidden] { display: none; }

        #shortcuts-panel {
            position: relative;
            width: min(360px, 88vw);
            padding: 32px;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        #shortcuts-title {
            font-size: 16px;
            font-weight: 500;
            letter-spacing: 0.5px;
            background: linear-gradient(135deg, #fff 30%, #a5b4fc 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        #shortcuts-close {
            position: absolute;
            top: 16px;
            right: 16px;
            color: rgba(255, 255, 255, 0.4);
            cursor: pointer;
            font-size: 16px;
            transition: color 0.2s;
            line-height: 1;
            padding: 4px;
        }
        #shortcuts-close:hover { color: white; }
        .shortcuts-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        .shortcut-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 14px;
            color: rgba(255, 255, 255, 0.6);
        }
        kbd {
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 6px;
            padding: 3px 10px;
            font-family: 'Outfit', sans-serif;
            font-size: 13px;
            color: white;
            min-width: 32px;
            text-align: center;
            display: inline-block;
        }
        #shortcuts-footer {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.2);
            text-align: center;
        }
