:root {
    --bg-dark: #070913;
    --glass-bg: rgba(15, 23, 42, 0.78);
    --glass-border: rgba(255, 255, 255, 0.14);
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --accent-cyan: #22d3ee;
    --accent-pink: #f43f5e;
    --accent-yellow: #facc15;
    --accent-nitro: #ec4899;
    --accent-jump: #a855f7;
    --neon-shadow: 0 0 20px rgba(34, 211, 238, 0.4);
    --font-sans: 'Outfit', sans-serif;
    --font-retro: 'Press Start 2P', monospace;
}

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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    touch-action: none;
}

body {
    background: radial-gradient(circle at 50% 50%, #0f172a 0%, var(--bg-dark) 100%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100dvh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.85);
    background: #000;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    touch-action: none;
}

/* ==========================================================================
   Top Track Progress Bar (Screenshot 1 Inspiration)
   ========================================================================== */
#track-progress-container {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 760px;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 6;
    pointer-events: none;
}

.track-flag {
    font-size: 1.2rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}

.track-bar-track {
    position: relative;
    flex: 1;
    height: 10px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.6), 0 0 12px rgba(34, 211, 238, 0.25);
    overflow: visible;
}

#track-progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ec4899, #8b5cf6, #3b82f6, #10b981);
    border-radius: 999px;
    transition: width 0.1s linear;
}

.racer-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    transition: left 0.08s linear;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9));
    z-index: 3;
}

.rival-marker {
    font-size: 0.95rem;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.8));
    z-index: 2;
    opacity: 0.95;
    transition: left 0.08s linear;
}

.police-marker {
    font-size: 1.05rem;
    filter: drop-shadow(0 0 8px #ef4444);
    animation: police-blink 0.5s infinite alternate;
    z-index: 4;
}

@keyframes police-blink {
    0% { filter: drop-shadow(0 0 8px #ef4444); }
    100% { filter: drop-shadow(0 0 8px #3b82f6); }
}

/* ==========================================================================
   HUD Layout (Levels, Rounds, Scores, Timers)
   ========================================================================== */
#hud {
    position: absolute;
    top: 46px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 5;
}

.hud-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    padding: 6px 14px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 90px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.hud-label {
    font-family: var(--font-retro);
    font-size: 0.5rem;
    color: var(--text-muted);
    margin-bottom: 2px;
    letter-spacing: 1px;
}

.hud-value {
    font-family: var(--font-retro);
    font-size: 0.95rem;
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

#hud-level .hud-value { color: var(--accent-cyan); }
#hud-round .hud-value { color: var(--accent-yellow); }
#hud-score .hud-value { color: #34d399; }
#hud-time .hud-value { color: #f472b6; }

/* ==========================================================================
   Dashboard Gauges (Speedometer & Nitro) - Anchored at Top Below HUD
   ========================================================================== */
#dashboard {
    position: absolute;
    top: 96px;
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
}

.gauge-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 8px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Speedometer Dial */
#speedo-card {
    min-width: 150px;
}

.speedo-dial {
    position: relative;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid var(--accent-cyan);
    background: radial-gradient(circle, #0f172a 40%, #0369a1 100%);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
}

.speedo-needle {
    position: absolute;
    bottom: 50%;
    left: 50%;
    width: 2.5px;
    height: 19px;
    background: #f43f5e;
    transform-origin: bottom center;
    transform: rotate(-120deg);
    transition: transform 0.08s ease-out;
    border-radius: 2px;
    box-shadow: 0 0 6px #f43f5e;
}

.speedo-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
}

.speedo-text {
    display: flex;
    flex-direction: column;
}

#speed-num {
    font-family: var(--font-retro);
    font-size: 1.25rem;
    color: #fff;
    line-height: 1.1;
    text-shadow: 0 0 10px rgba(34, 211, 238, 0.6);
}

.speed-unit {
    font-size: 0.65rem;
    color: var(--accent-cyan);
    font-weight: bold;
    letter-spacing: 1px;
}

/* Nitro Gauge */
#nitro-card {
    min-width: 175px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.nitro-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nitro-label {
    font-family: var(--font-retro);
    font-size: 0.55rem;
    color: #f472b6;
    letter-spacing: 1px;
}

.nitro-pct {
    font-family: var(--font-retro);
    font-size: 0.6rem;
    color: #facc15;
}

.nitro-bar-wrap {
    width: 155px;
    height: 12px;
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(236, 72, 153, 0.5);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

#nitro-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #f59e0b, #ec4899, #a855f7);
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.8);
    transition: width 0.08s linear;
}

.nitro-hint {
    font-size: 0.58rem;
    color: var(--text-muted);
}

/* ==========================================================================
   Police Warning Banner & Toast Notifications
   ========================================================================== */
.police-banner {
    position: absolute;
    top: 92px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(185, 28, 28, 0.88);
    border: 2px solid #ef4444;
    backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 6px 22px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    font-family: var(--font-retro);
    font-size: 0.65rem;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.7);
    z-index: 7;
    animation: banner-pulse 0.8s infinite alternate;
}

@keyframes banner-pulse {
    0% { transform: translateX(-50%) scale(0.98); box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }
    100% { transform: translateX(-50%) scale(1.02); box-shadow: 0 0 30px rgba(239, 68, 68, 0.9); }
}

.toast {
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(16, 185, 129, 0.94);
    border: 2px solid #34d399;
    border-radius: 16px;
    padding: 16px 36px;
    text-align: center;
    color: #fff;
    box-shadow: 0 10px 35px rgba(16, 185, 129, 0.5);
    animation: toast-in-out 2.2s forwards;
    pointer-events: none;
    z-index: 8;
}

.toast-title {
    font-family: var(--font-retro);
    font-size: 1.1rem;
    margin-bottom: 6px;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.toast-subtitle {
    font-size: 0.9rem;
    font-weight: 600;
}

@keyframes toast-in-out {
    0% { transform: translate(-50%, -100%) scale(0.8); opacity: 0; }
    15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    25% { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
    100% { transform: translate(-50%, -30%) scale(0.9); opacity: 0; }
}

/* ==========================================================================
   Overlays & Menus
   ========================================================================== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 9, 19, 0.88);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.overlay-content {
    width: 90%;
    max-width: 620px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 28px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.hidden {
    opacity: 0;
    pointer-events: none;
    display: none !important;
}

.game-logo {
    font-family: var(--font-retro);
    font-size: 2.1rem;
    font-weight: 900;
    letter-spacing: -1px;
    margin-bottom: 4px;
    display: flex;
    justify-content: center;
    gap: 8px;
}

.logo-rainbow {
    background: linear-gradient(90deg, #f43f5e, #f59e0b, #10b981, #06b6d4, #8b5cf6);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: rainbow-shimmer 3s linear infinite;
    filter: drop-shadow(0 0 10px rgba(236, 72, 153, 0.6));
}

@keyframes rainbow-shimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.logo-accent {
    background: linear-gradient(180deg, var(--accent-cyan) 0%, #0284c7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(34, 211, 238, 0.6));
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 16px;
}

.instructions {
    text-align: left;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 14px;
    padding: 15px 18px;
    margin-bottom: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.instructions p {
    color: var(--text-primary);
    font-size: 0.88rem;
    line-height: 1.45;
    margin-bottom: 10px;
}

.level-preview-badge {
    background: rgba(34, 211, 238, 0.1);
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: 8px;
    padding: 7px 12px;
    margin-bottom: 12px;
    font-family: var(--font-retro);
    font-size: 0.62rem;
    color: var(--accent-cyan);
    text-align: center;
}

.controls-card {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 10px;
}

.controls-card h3 {
    font-size: 0.82rem;
    color: var(--accent-pink);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

.controls-card p {
    margin-bottom: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.menu-btn {
    font-family: var(--font-retro);
    font-size: 0.92rem;
    background: linear-gradient(135deg, var(--accent-cyan) 0%, #0284c7 100%);
    color: #000;
    border: none;
    padding: 13px 34px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.4);
}

.menu-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(34, 211, 238, 0.8);
    background: linear-gradient(135deg, #67e8f9 0%, var(--accent-cyan) 100%);
}

.menu-btn:active {
    transform: scale(0.97);
}

.start-pulse {
    animation: btn-pulse 2s infinite ease-in-out;
}

@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 0 15px rgba(34, 211, 238, 0.4); }
    50% { box-shadow: 0 0 30px rgba(34, 211, 238, 0.9); }
}

.next-pulse {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.next-pulse:hover {
    background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
}

.danger-title {
    font-family: var(--font-retro);
    color: var(--accent-pink);
    font-size: 1.8rem;
    margin-bottom: 12px;
    text-shadow: 0 0 15px rgba(244, 63, 94, 0.5);
}

.victory-title {
    font-family: var(--font-retro);
    color: #10b981;
    font-size: 1.8rem;
    margin-bottom: 10px;
    text-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.grand-title {
    font-family: var(--font-retro);
    background: linear-gradient(90deg, #f59e0b, #ec4899, #8b5cf6, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 2rem;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 15px rgba(245, 158, 11, 0.6));
}

.trophy-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.stats-box {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 16px;
    padding: 15px 18px;
    margin: 16px auto;
    width: 90%;
    max-width: 380px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stats-box p {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 8px 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
    padding-bottom: 5px;
}

.stats-box p:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.stats-box span {
    font-family: var(--font-retro);
    color: #fff;
    font-size: 0.75rem;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Mobile Touch Controls
   ========================================================================== */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    padding: 0 24px;
    pointer-events: none;
    z-index: 30;
}

.control-group {
    display: flex;
    gap: 16px;
    pointer-events: none;
}

.touch-btn {
    width: 82px;
    height: 82px;
    border-radius: 26px;
    background: rgba(15, 23, 42, 0.85);
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    font-family: var(--font-retro);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    backdrop-filter: blur(16px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.65), 0 12px 28px rgba(0, 0, 0, 0.6);
    transition: transform 0.05s ease-out, box-shadow 0.05s ease-out, filter 0.05s ease-out;
    cursor: pointer;
}

.btn-icon {
    font-size: 1.35rem;
    line-height: 1;
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.btn-text {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.5px;
    line-height: 1;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.touch-btn:active, .touch-btn.active {
    transform: translateY(5px) scale(0.96);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.7), 0 4px 12px rgba(0, 0, 0, 0.5);
    filter: brightness(1.3);
}

.touch-btn.tilt-btn {
    background: linear-gradient(180deg, rgba(244, 63, 94, 0.7) 0%, rgba(190, 24, 93, 0.85) 100%);
    border-color: rgba(254, 205, 211, 0.8);
    box-shadow: 0 6px 0 #9f1239, 0 12px 24px rgba(244, 63, 94, 0.45);
}

.touch-btn.tilt-btn:active, .touch-btn.tilt-btn.active {
    box-shadow: 0 1px 0 #9f1239, 0 4px 14px rgba(244, 63, 94, 0.8);
}

.touch-btn.jump-btn {
    background: linear-gradient(180deg, rgba(168, 85, 247, 0.7) 0%, rgba(126, 34, 206, 0.85) 100%);
    border-color: rgba(243, 232, 255, 0.8);
    box-shadow: 0 6px 0 #6b21a8, 0 12px 24px rgba(168, 85, 247, 0.45);
}

.touch-btn.jump-btn:active, .touch-btn.jump-btn.active {
    box-shadow: 0 1px 0 #6b21a8, 0 4px 14px rgba(168, 85, 247, 0.8);
}

.touch-btn.gas-btn {
    background: linear-gradient(180deg, rgba(34, 211, 238, 0.7) 0%, rgba(14, 116, 144, 0.85) 100%);
    border-color: rgba(207, 250, 254, 0.8);
    box-shadow: 0 6px 0 #0e7490, 0 12px 24px rgba(34, 211, 238, 0.45);
}

.touch-btn.gas-btn:active, .touch-btn.gas-btn.active {
    box-shadow: 0 1px 0 #0e7490, 0 4px 14px rgba(34, 211, 238, 0.8);
}

.touch-btn.nitro-btn {
    background: linear-gradient(180deg, rgba(236, 72, 153, 0.7) 0%, rgba(157, 23, 77, 0.85) 100%);
    border-color: rgba(251, 207, 232, 0.8);
    box-shadow: 0 6px 0 #9d174d, 0 12px 24px rgba(236, 72, 153, 0.45);
}

.touch-btn.nitro-btn:active, .touch-btn.nitro-btn.active {
    box-shadow: 0 1px 0 #9d174d, 0 4px 14px rgba(236, 72, 153, 0.8);
}

/* Tablet & iPad Specific Layout Enhancements */
@media (min-width: 600px) and (pointer: coarse) {
    #mobile-controls {
        display: flex;
        bottom: 24px;
        padding: 0 36px;
    }

    .touch-btn {
        width: 96px;
        height: 96px;
        border-radius: 30px;
    }

    .btn-icon {
        font-size: 1.6rem;
    }

    .btn-text {
        font-size: 0.82rem;
    }

    .control-group {
        gap: 22px;
    }
}

@media (max-width: 768px) {
    #dashboard {
        top: 88px;
        left: 10px;
        right: 10px;
    }

    #speedo-card {
        transform: scale(0.85);
        transform-origin: top left;
    }

    #nitro-card {
        transform: scale(0.85);
        transform-origin: top right;
    }
}

@media (max-width: 599px) and (pointer: coarse) {
    #mobile-controls {
        display: flex;
        bottom: 12px;
        padding: 0 12px;
    }

    .touch-btn {
        width: 72px;
        height: 72px;
        border-radius: 20px;
    }

    .btn-icon {
        font-size: 1.2rem;
    }

    .btn-text {
        font-size: 0.65rem;
    }

    .control-group {
        gap: 12px;
    }
}

/* ==========================================================================
   Rotate Device Overlay
   ========================================================================== */
#rotate-device {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 9, 19, 0.96);
    backdrop-filter: blur(10px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 100;
}

.rotate-icon {
    font-size: 3.5rem;
    margin-bottom: 20px;
    animation: rotate-pulse 1.8s infinite ease-in-out;
}

@keyframes rotate-pulse {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(-90deg) scale(1.15); }
    100% { transform: rotate(0deg) scale(1); }
}

@media (max-width: 1024px) and (pointer: coarse) and (orientation: portrait) {
    #rotate-device {
        display: flex;
    }
}

/* Landscape compact overrides */
@media (max-height: 500px) {
    .overlay-content {
        padding: 12px 18px !important;
        max-width: 520px !important;
        border-radius: 16px !important;
    }
    .game-logo {
        font-size: 1.4rem !important;
        margin-bottom: 2px !important;
    }
    .subtitle {
        font-size: 0.72rem !important;
        margin-bottom: 6px !important;
        letter-spacing: 3px !important;
    }
    .instructions {
        padding: 8px 12px !important;
        margin-bottom: 8px !important;
    }
    .instructions p {
        font-size: 0.74rem !important;
        margin-bottom: 3px !important;
        line-height: 1.25 !important;
    }
    .level-preview-badge {
        font-size: 0.58rem !important;
        padding: 3px 8px !important;
        margin-bottom: 5px !important;
    }
    .controls-card {
        padding-top: 3px !important;
    }
    .controls-card h3 {
        font-size: 0.68rem !important;
        margin-bottom: 2px !important;
    }
    .controls-card p {
        font-size: 0.66rem !important;
        margin-bottom: 1px !important;
    }
    .menu-btn {
        padding: 7px 22px !important;
        font-size: 0.78rem !important;
        border-radius: 8px !important;
    }
    .stats-box {
        padding: 6px !important;
        margin: 6px auto !important;
    }
    .stats-box p {
        margin: 2px 0 !important;
        font-size: 0.72rem !important;
    }
    .danger-title, .victory-title, .grand-title {
        font-size: 1.25rem !important;
        margin-bottom: 4px !important;
    }
    .touch-btn {
        width: 62px;
        height: 62px;
        font-size: 0.6rem;
    }
    #dashboard {
        bottom: 6px;
    }
    .gauge-card {
        padding: 5px 8px;
    }
}
