:root {
    --bg-dark: #080c14;
    --card-bg: rgba(15, 23, 42, 0.88);
    --border-glow: rgba(56, 189, 248, 0.35);
    --accent-blue: #38bdf8;
    --accent-orange: #f97316;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-gold: #facc15;
    --glass-surface: rgba(15, 23, 42, 0.75);
    --glass-border: rgba(255, 255, 255, 0.12);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Outfit', sans-serif;
    color: #f8fafc;
    touch-action: none;
}

#game-app {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* In-Game HUD Overlay */
#hud-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 20px;
}

/* 1. Sleek Top Bar */
.hud-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 12px;
}

.hud-nav-cluster {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    padding: 6px 10px;
    border-radius: 999px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
}

.icon-hud-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 1.1rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s, background 0.2s;
}

.icon-hud-btn:active {
    transform: scale(0.9);
    background: rgba(56, 189, 248, 0.25);
}

.pill-hud-btn {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: var(--accent-blue);
    font-family: inherit;
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-hud-btn:active {
    transform: scale(0.94);
    background: rgba(56, 189, 248, 0.25);
    border-color: var(--accent-blue);
}

/* Center Tournament Badge */
.tournament-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.88), rgba(15, 23, 42, 0.94));
    border: 1.5px solid rgba(250, 204, 21, 0.4);
    padding: 8px 22px;
    border-radius: 20px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 15px rgba(250, 204, 21, 0.15);
}

.badge-title {
    font-size: 1.05rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: var(--accent-gold);
    text-transform: uppercase;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.badge-stats-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.badge-pill {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.pill-lbl {
    color: #94a3b8;
    font-size: 0.72rem;
}

.pill-val {
    color: #f8fafc;
    font-weight: 800;
}

.pill-val.mono {
    font-family: monospace;
    font-size: 0.95rem;
    letter-spacing: 1px;
}

/* Right Flip Button */
.hud-action-cluster {
    pointer-events: auto;
}

.flip-alert-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #f97316, #dc2626);
    border: 2px solid rgba(254, 202, 202, 0.5);
    color: #ffffff;
    font-family: inherit;
    font-weight: 900;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    padding: 10px 18px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.45);
    transition: transform 0.1s, box-shadow 0.2s;
}

.flip-alert-btn:active {
    transform: scale(0.92);
}

.flip-icon {
    font-size: 1.15rem;
}

/* Floating Popups */
#hud-popup {
    align-self: center;
    margin-top: 80px;
    background: linear-gradient(135deg, #facc15, #f97316);
    color: #0f172a;
    font-weight: 900;
    font-size: 1.4rem;
    letter-spacing: 0.5px;
    padding: 10px 26px;
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(249, 115, 22, 0.6);
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
}

.pop-anim {
    animation: popBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fade-out {
    opacity: 0;
    transform: translateY(-24px) scale(0.85);
}

@keyframes popBounce {
    0% { transform: scale(0.4); opacity: 0; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* 2. Cockpit Instrument Cluster (Bottom Center) */
.hud-cockpit {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 24px;
}

.cockpit-card {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.85), rgba(8, 12, 20, 0.92));
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    border-radius: 20px;
    padding: 10px 20px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5), 0 0 20px rgba(56, 189, 248, 0.12);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 290px;
}

.cockpit-metrics {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.metric-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.metric-label {
    font-size: 0.65rem;
    font-weight: 800;
    color: #64748b;
    letter-spacing: 1px;
}

.metric-number {
    font-size: 1.15rem;
    font-weight: 900;
    color: #e2e8f0;
}

.speedometer-cell {
    display: flex;
    align-items: baseline;
    gap: 4px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 16px;
    border-radius: 12px;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.speed-number {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--accent-blue);
    line-height: 1;
}

.speed-unit {
    font-size: 0.8rem;
    font-weight: 800;
    color: #94a3b8;
}

.nitro-gauge-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nitro-gauge-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 800;
}

.nitro-badge {
    color: var(--accent-gold);
    letter-spacing: 0.5px;
}

.nitro-hotkey {
    color: #64748b;
}

.nitro-track {
    width: 100%;
    height: 10px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.nitro-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f97316, #eab308, #38bdf8);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
    transition: width 0.1s linear;
}

/* 3. Modern Arcade Touch Controls (Tablet & Mobile) */
#touch-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: auto;
    z-index: 20;
}

.arcade-touch-btn {
    border: none;
    font-family: inherit;
    font-weight: 900;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    transition: transform 0.08s ease, filter 0.08s ease;
}

.arcade-touch-btn:active, .arcade-touch-btn.active {
    transform: scale(0.92);
    filter: brightness(1.3);
}

/* Left Steer Buttons */
.touch-steer-zone {
    display: flex;
    gap: 14px;
}

.steer-btn {
    width: 82px;
    height: 82px;
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
    border: 2px solid rgba(56, 189, 248, 0.4);
    border-radius: 24px;
    color: var(--accent-blue);
    font-size: 2.2rem;
}

.steer-btn:active, .steer-btn.active {
    border-color: var(--accent-blue);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.5);
}

/* Right Drive & Turbo Pedals */
.touch-drive-zone {
    display: flex;
    align-items: flex-end;
    gap: 14px;
}

.nitro-btn {
    width: 84px;
    height: 84px;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.92), rgba(234, 179, 8, 0.95));
    border: 2.5px solid rgba(254, 240, 138, 0.6);
    border-radius: 50%;
    color: #0f172a;
    box-shadow: 0 8px 25px rgba(249, 115, 22, 0.55), 0 0 15px rgba(250, 204, 21, 0.35);
}

.nitro-sym {
    font-size: 1.8rem;
    line-height: 1;
}

.nitro-txt {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.5px;
}

.pedals-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.gas-btn {
    width: 92px;
    height: 72px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.9), rgba(16, 185, 129, 0.95));
    border: 2px solid rgba(134, 239, 172, 0.6);
    border-radius: 20px;
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.45);
}

.brake-btn {
    width: 92px;
    height: 56px;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.88), rgba(220, 38, 38, 0.92));
    border: 2px solid rgba(252, 165, 165, 0.5);
    border-radius: 18px;
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.4);
}

.pedal-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.pedal-label {
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 0.5px;
}

/* 4. Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(4, 7, 14, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.hidden {
    display: none !important;
}

.modal-card {
    background: var(--card-bg);
    border: 1.5px solid var(--border-glow);
    border-radius: 24px;
    padding: 24px;
    max-width: 650px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

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

.modal-header h2 {
    font-size: 1.4rem;
    font-weight: 900;
    color: #ffffff;
}

.modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.modal-subtitle {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 20px;
}

/* Garage Cards */
.garage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}

.truck-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.2s, border-color 0.2s;
}

.truck-card.selected {
    border-color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(250, 204, 21, 0.35);
}

.truck-card.locked {
    opacity: 0.55;
    filter: grayscale(0.6);
}

.truck-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: #f8fafc;
}

.truck-tag {
    font-size: 0.78rem;
    color: var(--accent-blue);
    font-weight: 600;
}

.stat-bar {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    gap: 8px;
    color: #94a3b8;
}

.stat-bar label {
    width: 75px;
}

.stat-bar .bar-fill {
    height: 6px;
    border-radius: 4px;
}

.select-truck-btn {
    margin-top: 8px;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: white;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
}

.select-truck-btn:disabled {
    background: #334155;
    cursor: not-allowed;
}

/* Levels Grid */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}

.level-card {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.level-card.unlocked:hover, .level-card.unlocked:active {
    transform: translateY(-2px);
    border-color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.15);
}

.level-card.current {
    border-color: var(--accent-gold);
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.4);
}

.level-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
}

.lvl-num {
    font-size: 0.95rem;
    font-weight: 900;
    color: var(--accent-blue);
}

.lvl-name {
    font-size: 0.72rem;
    color: #cbd5e1;
    margin: 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lvl-stars {
    font-size: 0.85rem;
    letter-spacing: 2px;
}

/* Victory & Game Over Modals */
.victory-card {
    text-align: center;
    max-width: 440px;
}

.victory-banner {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--accent-gold);
    margin-bottom: 8px;
    text-shadow: 0 4px 15px rgba(250, 204, 21, 0.4);
}

.gameover-banner {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--accent-red);
    margin-bottom: 8px;
}

.victory-stars {
    font-size: 2.2rem;
    letter-spacing: 8px;
    margin-bottom: 18px;
}

.stats-summary {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 16px;
    padding: 14px 18px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.stat-item .lbl { color: #94a3b8; }
.stat-item .val { font-weight: 800; color: #f8fafc; }

.modal-btn-row {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.action-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn.primary {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4);
}

.action-btn.secondary {
    background: rgba(51, 65, 85, 0.8);
    color: #cbd5e1;
}

/* Tablet & Mobile responsive adjustments */
@media (max-width: 768px) {
    #hud-overlay {
        padding: 10px 12px;
    }
    .hud-top-bar {
        gap: 6px;
    }
    .pill-hud-btn {
        display: none; /* Conserve space on small phones; pause & sound remain */
    }
    .tournament-badge {
        padding: 6px 14px;
    }
    .badge-title {
        font-size: 0.88rem;
    }
    .steer-btn {
        width: 68px;
        height: 68px;
    }
    .nitro-btn {
        width: 70px;
        height: 70px;
    }
    .gas-btn {
        width: 78px;
        height: 60px;
    }
    .brake-btn {
        width: 78px;
        height: 48px;
    }
    .cockpit-card {
        min-width: 240px;
        padding: 8px 14px;
    }
}
