:root {
    /* DAY MODE (Aero Tech) */
    --bg-dark: #eef2f6;
    --bg-gradient: radial-gradient(circle at center, #ffffff 0%, #eef2f6 100%);
    
    --surface: rgba(255, 255, 255, 0.7);
    --surface-border: rgba(37, 99, 235, 0.15);
    --surface-glow: 0 4px 30px rgba(0, 0, 0, 0.05);
    --screen-bg: rgba(238, 242, 246, 0.6);
    
    --text: #0f172a;
    --text-muted: #64748b;
    --font-head: 'Orbitron', sans-serif;
    --font-main: 'Rajdhani', sans-serif;

    --accent: #2563eb;
    --accent-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --accent-glow: rgba(37, 99, 235, 0.3);
    
    --secondary: #6366f1;
    --secondary-glow: rgba(99, 102, 241, 0.3);

    --danger: #ef4444;
    --success: #10b981;

    --lane-line: rgba(15, 23, 42, 0.08);
    
    --card-bg-sub: rgba(255, 255, 255, 0.5);
    --border-sub: rgba(37, 99, 235, 0.1);
    
    --input-bg: rgba(255, 255, 255, 0.8);
    --input-border: rgba(0, 0, 0, 0.1);
}

body.dark-mode {
    /* ADVANCE CYBERPUNK / HOLOGRAPHIC THEME */
    --bg-dark: #030014;
    --bg-gradient: radial-gradient(circle at center, #0f0c29 0%, #030014 100%);
    
    --surface: rgba(16, 16, 32, 0.75);
    --surface-border: rgba(0, 243, 255, 0.3);
    --surface-glow: 0 0 40px rgba(0, 243, 255, 0.15);
    --screen-bg: rgba(3, 0, 20, 0.7);
    
    --text: #e0e7ff;
    --text-muted: #94a3b8;
    
    --accent: #00f3ff;
    --accent-gradient: linear-gradient(135deg, #00f3ff 0%, #0066ff 100%);
    --accent-glow: rgba(0, 243, 255, 0.5);
    
    --secondary: #d946ef;
    --secondary-glow: rgba(217, 70, 239, 0.4);
    
    --lane-line: rgba(0, 243, 255, 0.2);
    
    --card-bg-sub: rgba(0, 0, 0, 0.4);
    --border-sub: rgba(255, 255, 255, 0.1);
    
    --input-bg: rgba(0, 0, 0, 0.3);
    --input-border: rgba(0, 243, 255, 0.2);
}

body {
    margin: 0;
    overflow: hidden;
    background: var(--bg-dark);
    /* High Tech Grid Pattern */
    background-image: 
        linear-gradient(var(--lane-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--lane-line) 1px, transparent 1px);
    background-size: 50px 50px;
    font-family: var(--font-main);
    color: var(--text);
    user-select: none;
    touch-action: manipulation;
    transition: background 0.5s ease;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    /* touch-action: none;  <-- REMOVED from here */
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* Moved to canvas only */
}

/* --- UI SCREENS --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--screen-bg);
    backdrop-filter: blur(8px);
    z-index: 10;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.1); /* Zoom out effect */
}

/* --- CARD STYLE (HUD Panel) --- */
.card {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 3rem;
    border: 1px solid var(--surface-border);
    box-shadow: var(--surface-glow);
    max-width: 90%;
    width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
    /* Tech Corners */
    clip-path: polygon(
        20px 0, 100% 0, 
        100% calc(100% - 20px), calc(100% - 20px) 100%, 
        0 100%, 0 20px
    );
    animation: cardEntrance 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes cardEntrance {
    from { opacity: 0; transform: translateY(30px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Decorative Card Lines */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-gradient);
    box-shadow: 0 0 15px var(--accent);
}

.card::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 30%;
    height: 2px;
    background: var(--accent);
}

/* Typography */
h1 {
    font-family: var(--font-head);
    font-size: clamp(3rem, 8vw, 4.5rem);
    font-weight: 900;
    letter-spacing: 4px;
    margin: 0 0 0.5rem 0;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    filter: drop-shadow(0 0 10px var(--accent-glow));
    font-style: italic;
    line-height: 1.1;
}

h2 {
    font-family: var(--font-head);
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text);
}

p {
    font-family: var(--font-main);
    font-size: 1.1rem;
    letter-spacing: 1px;
}

/* --- INPUTS (Data Entry Style) --- */
input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-left: 2px solid var(--text-muted);
    padding: 1rem 1.2rem;
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 1rem;
    outline: none;
    transition: all 0.3s ease;
    box-sizing: border-box;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input:focus {
    border-color: var(--accent);
    border-left-color: var(--accent);
    background: rgba(var(--accent), 0.05);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: translateX(5px);
}

input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

/* --- BUTTONS (Cyber Style) --- */
.btn {
    background: var(--accent-gradient);
    color: #fff; /* Always white text on gradient */
    border: none;
    padding: 1.2rem 2.5rem;
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    /* Slanted Tech Shape */
    clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
    width: 100%;
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    box-shadow: 0 5px 20px var(--accent-glow);
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s ease;
    z-index: 1;
}

.btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 10px 30px var(--accent-glow);
}

.btn:hover::before {
    left: 100%;
}

.btn:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-muted);
    box-shadow: none;
    text-shadow: none;
}

.btn-secondary:hover {
    border-color: var(--text);
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 15px rgba(255,255,255,0.1);
}

/* --- HUD (Tech Overlay) --- */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    box-sizing: border-box;
    z-index: 5;
}

.hud-group {
    display: flex;
    gap: 2rem;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* Glass Capsules for HUD (Simplified) */
.hud-glass {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    box-shadow: none;
}

.hud-label {
    font-size: 0.7rem;
    color: var(--accent);
    letter-spacing: 1px;
    margin-bottom: 0.1rem;
    font-weight: 600;
    text-shadow: none;
}

.hud-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: monospace;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    line-height: 1;
}

/* --- LEADERBOARD --- */
.leaderboard-container {
    width: 100%;
    flex: 1;
    overflow-y: auto;
    margin-top: 1rem;
    padding-right: 5px; /* Space for scrollbar */
}

/* Custom Scrollbar */
.leaderboard-container::-webkit-scrollbar {
    width: 6px;
}
.leaderboard-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}
.leaderboard-container::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.lb-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.lb-row:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(5px);
    border-color: var(--accent);
}

.lb-rank {
    font-family: var(--font-head);
    font-weight: 900;
    color: var(--text-muted);
    width: 40px;
    font-size: 1.2rem;
}

.lb-rank:nth-child(1) { color: #FFD700; text-shadow: 0 0 10px rgba(255, 215, 0, 0.5); }
.lb-rank:nth-child(2) { color: #C0C0C0; }
.lb-rank:nth-child(3) { color: #CD7F32; }

.lb-name {
    flex: 1;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    padding: 0 1rem;
}

.lb-score {
    font-family: monospace;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 8px var(--accent-glow);
}

.stagger-appear {
    animation: slideInRight 0.4s ease-out forwards;
    opacity: 0;
    transform: translateX(20px);
}

@keyframes slideInRight {
    to { opacity: 1; transform: translateX(0); }
}

/* --- SETTINGS / WORLD --- */
.toggle-btn {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text);
    padding: 0.8rem 1.5rem;
    font-family: var(--font-main);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    text-transform: uppercase;
    letter-spacing: 1px;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.toggle-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

.world-container {
    display: grid;
    gap: 1rem;
    width: 100%;
    margin: 1rem 0;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.world-card {
    background: var(--card-bg-sub);
    border: 1px solid var(--border-sub);
    padding: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
    overflow: hidden;
}

.world-card:hover {
    transform: translateX(5px);
    border-color: var(--accent);
    background: rgba(var(--accent), 0.05);
    box-shadow: -2px 0 10px var(--accent-glow);
}

.world-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: var(--accent);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.world-card:hover::before {
    transform: scaleY(1);
}

.world-card.active {
    border-color: var(--success);
    background: rgba(var(--success), 0.1);
    box-shadow: inset 0 0 20px rgba(var(--success), 0.1);
}

.world-card.active::before {
    background: var(--success);
    transform: scaleY(1);
}

.world-card.locked {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

.world-card h3 {
    margin: 0;
    font-family: var(--font-head);
    font-size: 1.1rem;
    color: var(--text);
}

.world-card p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn-mini-enter {
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    font-family: var(--font-head);
    font-size: 0.7rem;
    padding: 0.5rem 1rem;
    border: none;
    clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.btn-mini-enter:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--accent-glow);
}
.btn-mini-enter:hover {
    transform: scale(1.1);
    background: #fff;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card > * {
    animation: fadeIn 0.4s ease-out forwards;
}
.card > *:nth-child(1) { animation-delay: 0.1s; }
.card > *:nth-child(2) { animation-delay: 0.2s; }
.card > *:nth-child(3) { animation-delay: 0.3s; }
.card > *:nth-child(4) { animation-delay: 0.4s; }

/* Mobile Adjustments */
@media (max-width: 600px) {
    .card {
        width: 90%;
        height: auto;
        max-height: 90vh;
        max-width: 380px;
        padding: 1.5rem;
        border-radius: 20px;
        clip-path: none;
        justify-content: flex-start;
        overflow-y: auto;
        /* Re-add corners visually via border/shadow since clip-path is removed */
        box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    }
    
    h1 {
        font-size: 2.5rem;
    }

    h2 {
        font-size: 1.5rem;
    }
    
    .btn {
        padding: 1rem 1.5rem;
        font-size: 1rem;
    }

    /* Stack buttons vertically */
    .card > div[style*="display: flex"] {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .btn-secondary {
        width: 100%;
        margin: 0 !important;
    }
}

/* Compact HUD for Landscape/Small Screens */
@media (max-height: 500px) {
    #hud {
        padding: 0.5rem 1rem;
    }
    .hud-glass {
        padding: 0.2rem 0.5rem;
        background: rgba(0,0,0,0.2);
    }
    .hud-value {
        font-size: 1.1rem;
    }
    .hud-label {
        font-size: 0.6rem;
    }
}