:root {
    --bg-dark: #08090d;
    --bg-panel: rgba(14, 16, 24, 0.92);
    --bg-card: rgba(22, 25, 38, 0.75);
    --bg-input: #10131e;
    
    --accent-purple: #8d5cff;
    --accent-cyan: #00d2ff;
    --accent-magenta: #f9393f;
    --accent-green: #38ef7d;
    --accent-yellow: #ffd700;
    
    --text-main: #f4f6ff;
    --text-muted: #8d94a8;
    --text-dim: #525868;
    
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(141, 92, 255, 0.3);
    
    --glow-purple: 0 0 25px rgba(141, 92, 255, 0.25);
    --glow-cyan: 0 0 25px rgba(0, 210, 255, 0.25);
    --glow-green: 0 0 20px rgba(56, 239, 125, 0.25);
    
    --sidebar-width: 320px;
    --radius-main: 16px;
    --radius-sm: 8px;
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
}

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

html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    position: fixed;
    inset: 0;
}

body {
    display: flex;
    background-image: 
        radial-gradient(circle at 10% 10%, rgba(141, 92, 255, 0.08), transparent 30rem),
        radial-gradient(circle at 90% 90%, rgba(0, 210, 255, 0.05), transparent 30rem);
}

body.is-mobile-active {
    background: #08090d !important;
}

body.is-mobile-active::before {
    display: none !important;
}

body::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* --- DESKTOP SIDEBAR PANEL --- */
#sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: calc(20px + var(--sat)) 18px calc(20px + var(--sab)) calc(18px + var(--sal));
    z-index: 10;
    overflow-y: auto;
    position: relative;
    transition: opacity 0.2s ease, transform 0.3s ease;
}

#sidebar::-webkit-scrollbar {
    width: 5px;
}
#sidebar::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 4px;
}

.brand-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 18px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: 14px;
    color: #050608;
    box-shadow: var(--glow-purple);
    letter-spacing: -1px;
}

.brand-title {
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, #fff, var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-version {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    background: rgba(0, 210, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(0, 210, 255, 0.2);
    display: inline-block;
    margin-top: 2px;
}

.section-header {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 18px 0 10px 4px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

label .val-tag {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    font-size: 11px;
}

select, input[type="text"], input[type="file"] {
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    outline: none;
    width: 100%;
    transition: all 0.2s ease;
}

select:focus, input[type="text"]:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(141, 92, 255, 0.2);
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-purple);
    cursor: pointer;
    box-shadow: var(--glow-purple);
    transition: transform 0.1s ease;
}

.btn-ui {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    width: 100%;
    text-decoration: none;
}

.btn-ui:hover, .btn-ui:active {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-ui.active-toggle {
    background: rgba(141, 92, 255, 0.15);
    border-color: var(--accent-purple);
    color: #fff;
    box-shadow: var(--glow-purple);
}

.btn-ui.btn-danger {
    background: rgba(249, 57, 63, 0.12);
    border-color: rgba(249, 57, 63, 0.4);
    color: var(--accent-magenta);
}

.btn-ui.btn-danger:hover {
    background: rgba(249, 57, 63, 0.25);
    border-color: var(--accent-magenta);
}

.btn-studio-link {
    background: linear-gradient(135deg, rgba(141, 92, 255, 0.2), rgba(0, 210, 255, 0.1));
    border: 1px solid var(--border-accent);
    color: #fff;
    font-weight: 700;
    margin-top: 15px;
    padding: 12px;
    box-shadow: var(--glow-purple);
}

.btn-studio-link:hover {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
    color: #000;
    border-color: transparent;
}

.keybind-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.keybind-grid input {
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 700;
    text-transform: uppercase;
    padding: 6px 0;
}

/* --- MAIN GAME STAGE --- */
#main-stage {
    flex-grow: 1;
    position: relative;
    background: #08090d;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#fps-display {
    position: absolute;
    top: calc(12px + var(--sat));
    right: calc(12px + var(--sar));
    z-index: 40;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-green);
    background: rgba(8, 9, 13, 0.75);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    pointer-events: none;
}

#fps-display.hidden {
    display: none;
}

/* --- V-SLICE STYLE CAPTIONS --- */
#vslice-lyrics {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    width: 85%;
    text-align: center;
    font-family: var(--font-sans);
    font-weight: 900;
    font-size: 32px;
    color: #ffffff;
    text-shadow: 3px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 0px 8px 16px rgba(0,0,0,0.8);
    z-index: 45;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.2;
}

canvas#game {
    width: 100%;
    height: 100%;
    background: #08090d;
    display: block;
    z-index: 1;
    touch-action: none;
}

#cutscene-layer {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    overflow: hidden;
}

#cutscene-layer video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    object-fit: contain;
    background: #000;
    pointer-events: none;
}

#cutscene-layer video.cutscene-active {
    display: block;
}

#main-stage.cutscene-hide-gameplay #game,
#main-stage.cutscene-hide-gameplay #fps-display,
#main-stage.cutscene-hide-gameplay #mobile-pause-btn {
    visibility: hidden !important;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 6, 8, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 50;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
}

.overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.btn-start {
    padding: 18px 48px;
    font-size: 20px;
    font-weight: 800;
    font-family: var(--font-sans);
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--accent-green), #00b0ff);
    color: #000;
    border: none;
    border-radius: var(--radius-main);
    cursor: pointer;
    box-shadow: var(--glow-green);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-start:disabled {
    background: #222530;
    color: var(--text-dim);
    cursor: not-allowed;
    box-shadow: none;
}

.pause-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-accent);
    padding: 28px;
    border-radius: 24px;
    box-shadow: var(--glow-purple);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 340px;
    gap: 12px;
}

.pause-btn {
    padding: 14px;
    font-size: 14px;
    font-weight: 700;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: center;
    text-decoration: none;
    display: block;
}

.pause-btn.active, .pause-btn:hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    color: #fff;
    box-shadow: var(--glow-purple);
}

#pause-countdown-overlay {
    position: absolute;
    inset: 0;
    z-index: 60;
    background: rgba(8, 9, 13, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 80px;
    font-weight: 900;
    color: var(--accent-cyan);
    text-shadow: 0 0 30px var(--accent-cyan);
    font-family: var(--font-mono);
    pointer-events: none;
}

#pause-countdown-overlay.hidden {
    display: none;
}

#toast-container {
    position: fixed;
    bottom: calc(24px + var(--sab));
    right: calc(24px + var(--sar));
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}

.toast-item {
    background: rgba(14, 16, 24, 0.95);
    border: 1px solid var(--accent-green);
    color: var(--text-main);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 13px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--glow-green);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 260px;
    pointer-events: auto;
}

.toast-item.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--accent-green);
}

.toast-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 8px;
    margin: -4px -4px -4px 0;
    transition: color 0.2s ease;
}

.toast-close-btn:hover {
    color: var(--text-main);
}

.toast-progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
    display: none;
}

.toast-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-cyan);
    transition: width 0.1s linear;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-subtle);
    border-top: 4px solid var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#mobile-pause-btn {
    display: none;
    position: absolute;
    top: calc(12px + var(--sat));
    right: calc(12px + var(--sar));
    z-index: 45;
    background: rgba(14, 16, 24, 0.85);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

#mobile-launcher {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    z-index: 30;
    background: var(--bg-dark);
    padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
    overflow-y: auto;
}

.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.mobile-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-main);
    padding: 16px;
    margin-bottom: 14px;
}

.mobile-card-title {
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.mobile-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

#rotate-warning {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 6, 8, 0.98);
    z-index: 999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 24px;
}

#error-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 13, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    text-align: center;
}

#error-overlay.hidden {
    display: none;
}

@media (max-width: 850px) {
    #sidebar {
        display: none !important;
    }

    #mobile-launcher {
        display: flex;
    }

    #start-screen {
        display: none !important;
    }

    body.playing-active #mobile-launcher {
        display: none !important;
    }

    body.playing-active #mobile-pause-btn {
        display: flex;
    }

    #toast-container {
        bottom: calc(16px + var(--sab));
        right: 16px;
        left: 16px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #rotate-warning {
        display: flex;
    }
}

body.playing-active #sidebar {
    display: none !important;
}

#bg-video, #bg-image { display: none; }