:root {
    --bg0: #06101c;
    --bg1: #0a1826;

    --panel: rgba(10, 18, 30, 0.72);
    --panel2: rgba(255, 255, 255, 0.06);
    --text: rgba(255, 255, 255, 0.94);
    --muted: rgba(255, 255, 255, 0.65);

    --c1: #23b6ff;
    --c2: #2f7bff;
    --c3: #6ee7f9;
    --c-warm: #ff8a3d;
    --c-success: #10b981;
    --c-danger: #ef4444;

    --border: rgba(255, 255, 255, 0.14);
    --border-glow: rgba(35, 182, 255, 0.4);

    --shadow-xl: 0 40px 120px rgba(0, 0, 0, 0.65);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.42);

    --r-lg: 24px;
    --r-md: 12px;
    --r-sm: 8px;

    --ease: cubic-bezier(.2, .8, .2, 1);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    /* Updated Font */
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: url("./img/bg.png") center / cover no-repeat fixed;
    background-color: var(--bg0);
    /* Fallback */
    overflow-x: hidden;
}

/* Premium tint overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(1200px 700px at 8% 8%, rgba(35, 182, 255, .18), transparent 60%),
        radial-gradient(1000px 650px at 88% 16%, rgba(255, 138, 61, .12), transparent 58%),
        linear-gradient(180deg, rgba(5, 10, 22, .6), rgba(7, 18, 39, .82));
    filter: blur(18px);
    opacity: 0.95;
    animation: floatAurora 15s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -2;
}

@keyframes floatAurora {
    from {
        transform: translate(-2%, -1%) scale(1.02);
    }

    to {
        transform: translate(2%, 1%) scale(1.06);
    }
}

.hidden {
    display: none !important;
}

/* ===== Landing Screen ===== */
.landing {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 28px 18px 54px;
    background:
        radial-gradient(circle at 50% 78%, rgba(35, 182, 255, 0.16), transparent 28%),
        linear-gradient(180deg, rgba(2, 8, 18, 0.18), rgba(2, 8, 18, 0.68));
}

.landing-start {
    width: min(420px, 92vw);
    padding: 20px 18px;
    border-radius: var(--r-md);
    font-weight: 900;
    letter-spacing: 4px;
    font-size: 20px;
    text-transform: uppercase;
    animation: pulseGlow 2s infinite alternate;
}

@keyframes pulseGlow {
    from {
        box-shadow: 0 15px 40px rgba(14, 165, 255, 0.2);
    }

    to {
        box-shadow: 0 15px 60px rgba(14, 165, 255, 0.6);
    }
}

/* ===== App Layout & Topbar ===== */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 12, 22, 0.60);
    backdrop-filter: blur(16px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 900;
    font-size: 1.2rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.brand-logo {
    height: 40px;
    /* Scaled down slightly for cleaner topbar */
    object-fit: contain;
    border-radius: 8px;
}

.hint {
    color: var(--muted);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.audio-toggle {
    margin-left: auto;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(110, 176, 255, 0.28);
    background: linear-gradient(180deg, rgba(18, 31, 52, 0.96), rgba(8, 16, 29, 0.94));
    color: #dbeafe;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.audio-toggle[aria-pressed="true"] {
    color: rgba(219, 234, 254, 0.72);
    border-color: rgba(148, 163, 184, 0.24);
    background: linear-gradient(180deg, rgba(29, 35, 44, 0.92), rgba(15, 20, 28, 0.94));
}

kbd {
    font-family: inherit;
    font-weight: 700;
    font-size: 13px;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border);
    color: #fff;
}

/* ===== Play Stage ===== */
.stage {
    width: min(1320px, 100%);
    margin: 0 auto;
    padding: 24px 18px;
    display: grid;
    place-items: center;
    position: relative;
    flex: 1;
}

.race-side-ui {
    position: fixed;
    left: 22px;
    top: 92px;
    z-index: 7;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
}

.stage-glow {
    position: absolute;
    top: 50%;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(55px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.55;
}

.stage-glow-left {
    left: -40px;
    background: radial-gradient(circle, rgba(35, 182, 255, 0.3), transparent 68%);
    transform: translateY(-55%);
}

.stage-glow-right {
    right: -35px;
    background: radial-gradient(circle, rgba(255, 138, 61, 0.22), transparent 68%);
    transform: translateY(-35%);
}

canvas {
    position: relative;
    z-index: 1;
    width: min(1280px, 100%);
    aspect-ratio: 16 / 9;
    height: auto;
    border-radius: var(--r-lg);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        var(--shadow-xl);
    background: #070a12;
}

/* ===== Overlay / Screens ===== */
.overlay {
    width: min(1280px, 100%);
    aspect-ratio: 16 / 9;
    height: auto;
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: grid;
    place-items: center;
    pointer-events: none;
    z-index: 3;
}

.screen {
    width: min(520px, 92%);
    background:
        linear-gradient(155deg, rgba(19, 31, 49, 0.92), rgba(10, 18, 30, 0.88) 58%, rgba(9, 27, 41, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--r-lg);
    padding: 34px 34px 30px;
    box-shadow: var(--shadow-xl);
    display: none;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(24px);
    transform: translateY(10px) scale(0.98);
    opacity: 0;
    animation: popIn 400ms var(--ease) forwards;
}

.screen.active {
    display: block;
}

@keyframes popIn {
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Fancy screen background glow */
.screen::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(circle at 35% 35%, rgba(35, 182, 255, 0.14) 0%, transparent 45%),
        radial-gradient(circle at 75% 25%, rgba(255, 138, 61, 0.08) 0%, transparent 36%);
    pointer-events: none;
    z-index: 0;
}

.screen>* {
    position: relative;
    z-index: 1;
}

.screen-kicker {
    display: inline-flex;
    margin-bottom: 10px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--c3);
}

h1 {
    margin: 0 0 8px 0;
    font-size: 38px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1.4px;
}

.muted {
    color: var(--muted);
    margin: 0 0 22px 0;
    font-size: 16px;
    line-height: 1.45;
}

.micro {
    margin: 16px 0 0 0;
    font-size: 13px;
    color: var(--muted);
}

.screen-info {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.info-chip {
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.82);
}

/* ===== Inputs / Buttons ===== */
.input {
    width: 100%;
    padding: 16px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.38);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    outline: none;
    margin-bottom: 16px;
    transition: all 200ms var(--ease);
}

.input:focus {
    border-color: var(--c1);
    box-shadow: 0 0 0 4px rgba(14, 165, 255, 0.2);
    background: rgba(0, 0, 0, 0.6);
}

.w-full {
    width: 100%;
}

.btn {
    padding: 14px 24px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-family: inherit;
    font-weight: 800;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 150ms var(--ease);
}

.btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn.primary {
    border-color: rgba(255, 255, 255, 0.14);
    background: linear-gradient(135deg, var(--c2), var(--c1) 65%, var(--c3));
    box-shadow: 0 8px 20px rgba(14, 165, 255, 0.28);
}

.btn.primary:hover:not(:disabled) {
    box-shadow: 0 12px 28px rgba(14, 165, 255, 0.5);
    filter: brightness(1.1);
}

.row {
    display: flex;
    gap: 12px;
}

.row>.btn {
    flex: 1;
}

/* ===== Car select cards ===== */
.car-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.car-btn {
    padding: 18px 12px 16px;
    border-radius: var(--r-md);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
        rgba(0, 0, 0, 0.34);
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 200ms var(--ease);
}

.car-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-4px);
}

.car-btn.selected {
    border-color: var(--c1);
    background:
        linear-gradient(180deg, rgba(35, 182, 255, 0.2), rgba(35, 182, 255, 0.05)),
        rgba(14, 165, 255, 0.14);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 12px 26px rgba(14, 165, 255, 0.22);
}

.chip {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), 0 4px 8px rgba(0, 0, 0, 0.5);
}

.chip.blue {
    background: #3b82f6;
}

.chip.red {
    background: #ef4444;
}

.chip.yellow {
    background: #f59e0b;
}

.car-label {
    font-weight: 800;
    font-size: 16px;
    text-transform: uppercase;
}

.car-sub {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

/* ===== HUD Dashboard ===== */
.hud {
    position: static;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 18px 20px;
    border-radius: 22px;
    background:
        linear-gradient(180deg, rgba(16, 28, 46, 0.92), rgba(8, 14, 23, 0.86));
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 24px 46px rgba(0, 0, 0, 0.48);
    width: 320px;
    min-width: 320px;
    flex-wrap: wrap;
}

.hud-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hud-block-primary {
    min-width: 156px;
}

.hud-block-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.46);
}

.hud-name {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 21px;
    text-transform: uppercase;
}

.pill {
    font-size: 11px;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--c1), var(--c2));
    color: #fff;
    box-shadow: 0 8px 18px rgba(35, 182, 255, 0.22);
}

.hud-mini {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.72);
}

.hud-divider {
    width: 2px;
    height: 56px;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.18), transparent);
}

.hud-right {
    display: flex;
    gap: 14px;
}

.hud-stat {
    min-width: 92px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hud-stat-accent {
    background: linear-gradient(180deg, rgba(35, 182, 255, 0.16), rgba(35, 182, 255, 0.05));
}

.hud-progress {
    flex: 1 1 100%;
}

.hud-progress-track {
    position: relative;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.hud-progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--c1), var(--c3), var(--c-warm));
    box-shadow: 0 0 18px rgba(35, 182, 255, 0.3);
    transition: width 0.22s ease-out;
}

.minimap-panel {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 320px;
    min-width: 320px;
    padding: 14px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(21, 35, 56, 0.94), rgba(8, 14, 23, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 22px 42px rgba(0, 0, 0, 0.42);
}

.minimap-head-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.minimap-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.minimap-title {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.minimap-subtitle {
    font-size: 10px;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.48);
}

.minimap-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.player-dot {
    background: #22d3ee;
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.55);
}

.rival-dot {
    background: #fb7185;
    box-shadow: 0 0 8px rgba(251, 113, 133, 0.45);
}

.minimap-canvas {
    width: 100%;
    height: 200px;
    border-radius: 12px;
    background:
        radial-gradient(circle at 50% 50%, rgba(14, 165, 255, 0.12), transparent 60%),
        rgba(4, 9, 18, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.boost-panel {
    width: 320px;
    min-width: 320px;
    padding: 14px 16px 16px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(8, 22, 46, 0.94), rgba(5, 14, 30, 0.92));
    border: 1px solid rgba(96, 165, 250, 0.22);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 22px 42px rgba(0, 0, 0, 0.42);
}

.boost-inventory-panel {
    width: 320px;
    min-width: 320px;
    padding: 14px 16px 16px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(18, 32, 56, 0.94), rgba(9, 18, 33, 0.92));
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 22px 42px rgba(0, 0, 0, 0.38);
}

.boost-inventory-copy {
    font-size: 12px;
    line-height: 1.45;
    color: rgba(226, 232, 240, 0.76);
}

.boost-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.boost-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(191, 219, 254, 0.9);
}

.boost-time {
    font-size: 18px;
    font-weight: 900;
    font-style: italic;
    color: #dbeafe;
}

.boost-track {
    height: 14px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(96, 165, 250, 0.16);
}

.boost-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #38bdf8, #3b82f6 55%, #2563eb);
    box-shadow:
        0 0 18px rgba(59, 130, 246, 0.5),
        inset 0 0 12px rgba(255, 255, 255, 0.16);
    transition: width 0.08s linear;
}

.countdown-overlay {
    position: absolute;
    inset: 24px 18px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    border-radius: var(--r-lg);
    background:
        radial-gradient(circle at 50% 50%, rgba(35, 182, 255, 0.08), transparent 34%),
        rgba(0, 0, 0, 0.72);
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    pointer-events: none;
}

.countdown-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
}

.countdown-lights {
    display: flex;
    gap: 25px;
    background: linear-gradient(180deg, rgba(26, 26, 26, 0.96), rgba(12, 12, 12, 0.98));
    padding: 25px 50px;
    border-radius: 100px;
    border: 5px solid #333;
    box-shadow: 0 28px 55px rgba(0, 0, 0, 0.42);
}

.countdown-light {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: #000;
    border: 4px solid #222;
}

.countdown-light.active-red {
    background: #ff4757;
    box-shadow: 0 0 40px #ff4757, inset 0 0 15px white;
}

.countdown-light.active-green {
    background: #2ed573;
    box-shadow: 0 0 50px #2ed573, inset 0 0 15px white;
}

.countdown-text {
    margin-top: 20px;
    font-size: 10rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 30px #00f2ff;
    letter-spacing: 4px;
}

.hud-stat {
    display: flex;
    flex-direction: column;
}

.hud-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.hud-value {
    font-size: 24px;
    font-weight: 900;
    font-style: italic;
    line-height: 1;
}

.speed-value {
    color: var(--c1);
    text-shadow: 0 0 10px rgba(14, 165, 255, 0.4);
}

.hud-total {
    font-size: 16px;
    color: var(--muted);
}

/* Responsive adjustments */
@media (max-width: 820px) {
    .car-row {
        grid-template-columns: 1fr;
    }

    .hint {
        display: none;
    }

    .stage {
        padding: 12px;
    }

    .overlay {
        top: 12px;
    }

    .hud {
        min-width: 0;
        width: min(92vw, 360px);
        padding: 14px;
        gap: 12px;
    }

    .hud-divider {
        display: none;
    }

    .hud-right {
        width: 100%;
        gap: 10px;
    }

    .hud-stat {
        flex: 1;
        min-width: 0;
    }

    .hud-value {
        font-size: 20px;
    }

    .race-side-ui {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 12px;
        gap: 10px;
    }

    .minimap-panel {
        width: 100%;
        min-width: 0;
    }

    .minimap-canvas {
        width: 100%;
        height: auto;
        aspect-ratio: 11 / 8;
    }

    .countdown-overlay {
        inset: 12px;
    }

    .countdown-lights {
        gap: 14px;
        padding: 16px 22px;
    }

    .countdown-light {
        width: 44px;
        height: 44px;
    }

    .countdown-text {
        font-size: 5rem;
    }
}

.prog-fill {
    width: var(--hud-progress);
    transition: width 0.2s ease-out;
    /* Smoothly animates even if JS is chunky */
    background: linear-gradient(90deg, #2563eb, #60a5fa);
}
