:root {
    --neon-cyan: #00f3ff;
    --neon-gold: #ffd60a;
    --neon-pink: #ff5e78;
    --warm-red: #e63946;
    --bg-deep: #0f0a1f;
    --glass-bg: rgba(15, 10, 31, 0.55);
    --glass-border: rgba(255, 255, 255, 0.15);
    /* HUD scales relative to viewport but caps at sensible sizes */
    --hud-scale: clamp(0.7, 1vw, 1.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', 'Segoe UI', sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #1a0a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#game-container {
    position: relative;
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 16 / 9;
    box-shadow: 0 0 80px rgba(0, 243, 255, 0.2), 0 20px 60px rgba(0,0,0,0.5);
    background: #87ceeb;
    overflow: hidden;
    border-radius: 8px;
}

#game-container:fullscreen,
#game-container:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* === HUD — responsive, always visible === */
#hud {
    position: absolute;
    top: clamp(8px, 1.5%, 20px);
    left: clamp(8px, 1.5%, 20px);
    right: clamp(8px, 1.5%, 20px);
    display: flex;
    justify-content: space-between;
    gap: clamp(6px, 1%, 14px);
    pointer-events: none;
    z-index: 10;
    flex-wrap: wrap;
    align-items: flex-start;
}

.hud-item {
    background: var(--glass-bg);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border: 1.5px solid var(--glass-border);
    padding: clamp(4px, 0.8vw, 10px) clamp(10px, 1.4vw, 20px);
    border-radius: clamp(8px, 1.2vw, 16px);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255,255,255,0.1);
    min-width: clamp(60px, 8vw, 100px);
}

.hud-label {
    font-size: clamp(8px, 0.85vw, 11px);
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 2px;
    font-weight: 700;
    text-transform: uppercase;
}

.hud-value {
    font-size: clamp(16px, 2vw, 28px);
    font-weight: 900;
    color: var(--neon-cyan);
    text-shadow: 0 0 12px rgba(0, 243, 255, 0.7), 0 2px 4px rgba(0,0,0,0.5);
    letter-spacing: 1px;
    font-family: 'Courier New', monospace;
    line-height: 1;
    margin-top: 2px;
}

#nitro-charges {
    display: flex;
    gap: clamp(2px, 0.4vw, 6px);
    margin-top: 4px;
}

.nitro-charge {
    width: clamp(8px, 1vw, 14px);
    height: clamp(14px, 1.8vw, 24px);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transform: skewX(-15deg);
    transition: all 0.2s;
    border-radius: 2px;
}

.nitro-charge.active {
    background: linear-gradient(180deg, #ffd60a, #ff8800);
    border-color: #fff;
    box-shadow: 0 0 10px var(--neon-gold), inset 0 0 4px rgba(255,255,255,0.5);
}

.hud-buttons {
    display: flex;
    gap: clamp(4px, 0.5vw, 8px);
    pointer-events: auto;
}

.hud-btn {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    color: #fff;
    width: clamp(44px, 4.5vw, 60px);
    height: clamp(44px, 4.5vw, 60px);
    font-size: clamp(24px, 3vw, 38px);
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    text-shadow:
        0 0 8px rgba(0, 0, 0, 0.9),
        0 2px 4px rgba(0, 0, 0, 0.8),
        0 0 2px rgba(255, 255, 255, 0.3);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    padding: 0;
}

.hud-btn:hover {
    transform: scale(1.15);
}
.hud-btn:active {
    transform: scale(0.95);
}

/* === Modals === */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(15,10,31,0.85) 0%, rgba(5,7,15,0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: linear-gradient(145deg, rgba(30, 20, 60, 0.95), rgba(15, 10, 40, 0.95));
    border: 2px solid rgba(255, 214, 10, 0.3);
    padding: clamp(20px, 3vw, 36px) clamp(24px, 4vw, 44px);
    border-radius: 24px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 60px rgba(255, 214, 10, 0.2), inset 0 1px 0 rgba(255,255,255,0.1);
    max-height: 92vh;
    overflow-y: auto;
}

.modal-content.welcome {
    border-color: rgba(0, 243, 255, 0.4);
    box-shadow: 0 0 80px rgba(0, 243, 255, 0.25);
}

.modal-content h1 {
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 900;
    letter-spacing: 1px;
    line-height: 1.1;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #ffd60a, #ff5e78, #00f3ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 30px rgba(255, 214, 10, 0.4);
}

.modal-content h2 { font-size: clamp(22px, 2.5vw, 28px); margin-bottom: 12px; }
.modal-content h3 {
    font-size: clamp(13px, 1.4vw, 16px);
    margin: 18px 0 8px;
    letter-spacing: 2px;
    color: var(--neon-gold);
    text-shadow: 0 0 12px rgba(255, 214, 10, 0.5);
}

.modal-content p {
    color: rgba(255, 255, 255, 0.75);
    font-size: clamp(13px, 1.3vw, 16px);
    margin-bottom: 16px;
}

.subtitle { font-size: clamp(13px, 1.4vw, 16px) !important; color: rgba(255,255,255,0.8) !important; }

.title-block { margin-bottom: 20px; }

.name-input-wrap { margin-bottom: 16px; }

#player-name-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: clamp(15px, 1.5vw, 18px);
    text-align: center;
    letter-spacing: 1px;
    border-radius: 12px;
    outline: none;
    font-weight: 700;
    transition: all 0.2s;
}

#player-name-input:focus {
    border-color: var(--neon-cyan);
    background: rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 16px rgba(0, 243, 255, 0.3);
}

#player-name-input::placeholder { color: rgba(255,255,255,0.4); font-weight: 500; }

.big-btn {
    width: 100%;
    padding: clamp(12px, 1.6vw, 18px);
    border: none;
    color: white;
    font-size: clamp(16px, 1.8vw, 22px);
    font-weight: 900;
    letter-spacing: 2px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 12px;
    text-transform: uppercase;
    font-family: inherit;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.big-btn.primary {
    background: linear-gradient(90deg, #ff5e78, #ffd60a, #ff8800);
    background-size: 200% 100%;
    animation: shimmer 3s linear infinite;
}

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

.big-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 32px rgba(255, 94, 120, 0.4);
}

.big-btn:active { transform: translateY(-1px) scale(1.0); }

.text-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: clamp(11px, 1.1vw, 13px);
    cursor: pointer;
    padding: 8px;
    text-decoration: underline;
    font-family: inherit;
    transition: color 0.2s;
}

.text-btn:hover { color: var(--neon-cyan); }

.controls-hint { font-size: clamp(11px, 1.2vw, 14px); color: rgba(255,255,255,0.7); margin-bottom: 12px; }

kbd {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    padding: 3px 8px;
    font-family: monospace;
    font-size: clamp(10px, 1vw, 12px);
    margin: 0 2px;
}

/* === Leaderboard === */
.mini-board, #leaderboard-table {
    margin: 12px 0;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 10px 12px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid rgba(255,255,255,0.1);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 12px;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: clamp(12px, 1.3vw, 14px);
    align-items: center;
}

.leaderboard-row:last-child { border-bottom: none; }
.lb-rank { color: var(--neon-gold); font-weight: 900; text-align: center; }
.lb-name { text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--neon-cyan); font-weight: 700; font-family: monospace; }

.leaderboard-row.current-player { background: rgba(255, 214, 10, 0.15); border-radius: 6px; }
.leaderboard-row.current-player .lb-name { color: var(--neon-gold); }
.empty-board { text-align: center; color: rgba(255,255,255,0.4); font-size: 13px; padding: 10px; }

/* === End screen === */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.stat {
    background: rgba(0,0,0,0.3);
    padding: 12px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label { font-size: 11px; color: rgba(255,255,255,0.5); letter-spacing: 1px; text-transform: uppercase; }
.stat-value {
    font-size: clamp(18px, 2.2vw, 26px);
    font-weight: 900;
    color: var(--neon-gold);
    text-shadow: 0 0 8px rgba(255, 214, 10, 0.5);
    margin-top: 4px;
    font-family: 'Courier New', monospace;
}

/* Spinner */
.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255,255,255,0.1);
    border-top-color: var(--neon-cyan);
    border-radius: 50%;
    margin: 16px auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* === HUD opacity baseline (0.9) and dim transition === */
#hud {
    opacity: 0.9;
    transition: opacity 0.6s ease;
}
#hud.dimmed {
    opacity: 0 !important;
}

.hud-left-group {
    display: flex;
    gap: clamp(8px, 1.2vw, 16px);
    align-items: stretch;
}

/* === Mario-style coin counter beside timer === */
.coin-counter {
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.6vw, 10px);
    padding: clamp(6px, 1vw, 12px) clamp(14px, 1.8vw, 24px);
    background: linear-gradient(180deg, rgba(20, 18, 40, 0.7) 0%, rgba(10, 8, 20, 0.85) 100%);
    border: 2px solid rgba(255, 214, 10, 0.55);
    border-radius: clamp(14px, 1.8vw, 22px);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    box-shadow:
        inset 0 1px 0 rgba(255, 214, 10, 0.3),
        0 6px 18px rgba(0, 0, 0, 0.4),
        0 0 14px rgba(255, 214, 10, 0.25);
}
.coin-icon {
    font-size: clamp(28px, 3.5vw, 50px);
    line-height: 1;
    filter: drop-shadow(0 0 8px rgba(255, 214, 10, 0.6))
            drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
    animation: coin-spin-counter 2.2s linear infinite;
}
@keyframes coin-spin-counter {
    0%, 60%, 100% { transform: rotateY(0deg); }
    70% { transform: rotateY(180deg); }
    80% { transform: rotateY(360deg); }
}
.coin-mult {
    font-size: clamp(18px, 2.4vw, 32px);
    color: rgba(255, 255, 255, 0.85);
    font-weight: 700;
    font-family: Georgia, serif;
    margin: 0 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.coin-num {
    font-size: clamp(26px, 3.4vw, 48px);
    font-weight: 900;
    color: var(--neon-gold);
    font-family: 'Courier New', monospace;
    text-shadow:
        2px 2px 0 rgba(0, 0, 0, 0.6),
        0 0 12px rgba(255, 214, 10, 0.7);
    letter-spacing: 1px;
    min-width: 1.5ch;
    text-align: left;
    transition: transform 0.15s;
}
.coin-counter.bump .coin-num {
    transform: scale(1.3);
}

/* === Bigger lively kid-friendly timer HUD with bevels === */
#timer-display {
    background: linear-gradient(180deg, #fde047 0%, #fbbf24 50%, #d97706 100%);
    border: 3px solid #fff;
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.7),
        inset 0 -2px 0 rgba(0,0,0,0.25),
        0 6px 0 #92400e,
        0 10px 24px rgba(0,0,0,0.4);
    padding: clamp(8px, 1.3vw, 14px) clamp(16px, 2.2vw, 30px) !important;
    border-radius: clamp(14px, 1.8vw, 22px) !important;
    transform: translateY(0);
    transition: transform 0.2s;
}
#timer-display .hud-label {
    color: #78350f !important;
    font-weight: 900;
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}
#timer-display .hud-value {
    color: #78350f !important;
    font-size: clamp(28px, 4vw, 56px) !important;
    text-shadow:
        2px 2px 0 #fff,
        0 4px 0 rgba(146, 64, 14, 0.4),
        0 6px 12px rgba(0,0,0,0.3) !important;
    font-weight: 900;
}

/* === Casino mode: pulse + red when ≤ 60s === */
#timer-display.urgent {
    background: linear-gradient(180deg, #fecaca 0%, #ef4444 50%, #991b1b 100%);
    border-color: #fef2f2;
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.6),
        inset 0 -2px 0 rgba(0,0,0,0.35),
        0 6px 0 #7f1d1d,
        0 0 30px rgba(239, 68, 68, 0.6),
        0 10px 28px rgba(0,0,0,0.5);
    animation: casino-pulse 0.7s ease-in-out infinite;
}
#timer-display.urgent .hud-label,
#timer-display.urgent .hud-value {
    color: #fff !important;
    text-shadow:
        2px 2px 0 #7f1d1d,
        0 4px 0 rgba(0,0,0,0.4),
        0 0 16px rgba(255, 255, 255, 0.6) !important;
}
@keyframes casino-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

/* === Splash multi-stage sequence === */
.splash-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, #2a1a55 0%, #0a0e1a 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.splash-overlay.hidden { display: none; }
.splash-stage {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.splash-stage.hidden { display: none; }

/* Spinner with truck inside */
.spinner-circle {
    position: relative;
    width: clamp(180px, 28vw, 280px);
    height: clamp(180px, 28vw, 280px);
    display: flex;
    align-items: center;
    justify-content: center;
}
.spinner-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 10px solid rgba(255, 255, 255, 0.1);
    border-top-color: #ffd60a;
    border-right-color: #ff5e78;
    animation: spin 1.1s linear infinite;
    box-shadow: 0 0 60px rgba(255, 214, 10, 0.4);
}
.spinner-truck-img {
    width: clamp(140px, 22vw, 220px);
    height: auto;
    z-index: 2;
    animation: truck-bob 0.7s ease-in-out infinite;
    filter: drop-shadow(0 6px 20px rgba(0,0,0,0.6));
}
@keyframes truck-bob {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50% { transform: translateY(-8px) rotate(3deg); }
}
.splash-tap-prompt {
    font-family: 'Impact', 'Bebas Neue', 'Arial Black', sans-serif;
    font-size: clamp(22px, 3.4vw, 36px);
    color: #fff;
    letter-spacing: 4px;
    margin-top: 32px;
    animation: tap-blink 1s ease-in-out infinite;
    text-shadow: 0 2px 6px rgba(0,0,0,0.7);
}
.splash-start-button {
    margin-top: 36px;
    padding: 18px 48px;
    font-family: 'Impact', 'Bebas Neue', 'Arial Black', sans-serif;
    font-size: clamp(22px, 3.6vw, 38px);
    font-weight: 900;
    letter-spacing: 4px;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 50%, #15803d 100%);
    color: #fff;
    border: 4px solid #fff;
    border-radius: 18px;
    cursor: pointer;
    box-shadow:
        inset 0 4px 0 rgba(255,255,255,0.45),
        inset 0 -6px 0 rgba(0,0,0,0.3),
        0 12px 0 #14532d,
        0 16px 40px rgba(34, 197, 94, 0.7);
    text-shadow: 3px 3px 0 rgba(0,0,0,0.4);
    animation: btn-pulse 1.4s ease-in-out infinite;
    transition: transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.splash-start-button:hover { transform: scale(1.05); }
.splash-start-button:active {
    transform: translateY(6px) scale(0.97);
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 4px 0 #14532d;
}
@keyframes btn-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}
@keyframes tap-blink {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Animated word fly-ins */
.anim-word {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0) rotate(-10deg);
    opacity: 0;
    font-family: 'Impact', 'Bebas Neue', 'Arial Black', sans-serif;
    font-weight: 900;
    letter-spacing: 4px;
    -webkit-text-stroke: 3px #fff;
    text-shadow:
        4px 4px 0 rgba(0,0,0,0.5),
        0 0 30px rgba(0, 0, 0, 0.8);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    pointer-events: none;
}
.anim-word.show {
    transform: translate(-50%, -50%) scale(1) rotate(0);
    opacity: 1;
}
.anim-word.hide {
    transform: translate(-50%, -50%) scale(1.6) rotate(8deg);
    opacity: 0;
    transition: all 0.35s ease-out;
}
.w-welcome {
    font-size: clamp(60px, 12vw, 140px);
    color: #ffd60a;
    -webkit-text-stroke-color: #c81e1e;
}
.w-to {
    font-size: clamp(50px, 9vw, 100px);
    color: #06b6d4;
    -webkit-text-stroke-color: #fff;
}
.w-monstertruck {
    font-size: clamp(56px, 11vw, 130px);
    color: #ff5e78;
    -webkit-text-stroke-color: #fff;
}
.w-hilltop {
    font-size: clamp(56px, 11vw, 130px);
    color: #7cfc00;
    -webkit-text-stroke-color: #1a1a1a;
}

/* Final assembled logo */
.anim-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    font-family: 'Impact', 'Bebas Neue', 'Arial Black', sans-serif;
    text-align: center;
    line-height: 0.95;
    letter-spacing: 3px;
    transition: all 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.anim-logo.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}
.anim-logo.hide {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    transition: all 0.4s ease-out;
}
.logo-line-1 {
    display: block;
    font-size: clamp(48px, 9.5vw, 110px);
    color: #ffd60a;
    -webkit-text-stroke: 3px #c81e1e;
    text-shadow: 4px 4px 0 rgba(0,0,0,0.5), 0 0 40px rgba(255, 214, 10, 0.5);
    margin-bottom: 6px;
}
.logo-line-2 {
    display: block;
    font-size: clamp(40px, 7.5vw, 88px);
    color: #06b6d4;
    -webkit-text-stroke: 3px #1d3557;
    text-shadow: 4px 4px 0 rgba(0,0,0,0.5), 0 0 40px rgba(0, 200, 255, 0.5);
}

/* === Penalty -1 flash (smooth casino-style) === */
.penalty-flash {
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 22;
    animation: penalty-pop 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.penalty-coin {
    width: clamp(80px, 11vw, 130px);
    height: clamp(80px, 11vw, 130px);
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 30%, #ff8a8a 0%, #ef4444 50%, #991b1b 100%);
    border: 5px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Impact', 'Bebas Neue', 'Arial Black', sans-serif;
    font-size: clamp(40px, 6vw, 64px);
    font-weight: 900;
    color: #fff;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.4),
        inset 0 -4px 0 rgba(0,0,0,0.3),
        0 0 50px rgba(239, 68, 68, 0.7),
        0 14px 30px rgba(0,0,0,0.5);
    letter-spacing: 1px;
}
@keyframes penalty-pop {
    0%   { transform: translate(-50%, -50%) scale(0.4) rotate(-15deg); opacity: 0; }
    25%  { transform: translate(-50%, -50%) scale(1.15) rotate(5deg);  opacity: 1; }
    55%  { transform: translate(-50%, -50%) scale(1.0)  rotate(-2deg); opacity: 1; }
    100% { transform: translate(-50%, -95%) scale(0.85) rotate(0);     opacity: 0; }
}

/* === Flashy "5x BONUS!" popup === */
.bonus-flash {
    position: absolute;
    top: 32%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(48px, 9vw, 110px);
    font-weight: 900;
    color: #fff;
    text-align: center;
    letter-spacing: 4px;
    background: linear-gradient(180deg, #ffd60a 0%, #ff8800 40%, #ff5e78 80%, #c026d3 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow:
        4px 4px 0 rgba(0, 0, 0, 0.4),
        0 0 60px rgba(255, 214, 10, 0.7);
    pointer-events: none;
    z-index: 26;
    animation: bonus-burst 1.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    white-space: nowrap;
    filter: drop-shadow(4px 4px 0 rgba(0,0,0,0.5));
}
@keyframes bonus-burst {
    0%   { transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); opacity: 0; }
    20%  { transform: translate(-50%, -50%) scale(1.3) rotate(3deg);   opacity: 1; }
    40%  { transform: translate(-50%, -50%) scale(1.0) rotate(-2deg);  opacity: 1; }
    60%  { transform: translate(-50%, -50%) scale(1.1) rotate(2deg);   opacity: 1; }
    80%  { transform: translate(-50%, -50%) scale(1.0) rotate(0);      opacity: 1; }
    100% { transform: translate(-50%, -85%) scale(1.0) rotate(0);      opacity: 0; }
}

/* === Duration picker on welcome screen === */
.duration-picker {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.duration-btn {
    margin: 0 !important;
    padding: 14px 8px !important;
    font-size: clamp(13px, 1.7vw, 17px) !important;
    line-height: 1.1;
    letter-spacing: 1px !important;
    border-radius: 12px !important;
}
.duration-btn .dbl {
    display: block;
    font-size: 0.65em;
    opacity: 0.85;
    font-weight: 700;
    margin-top: 3px;
    letter-spacing: 0.5px;
}
/* All 3 duration buttons share the same primary yellow/orange gradient */
.duration-btn {
    background: linear-gradient(90deg, #ff5e78, #ffd60a, #ff8800) !important;
    background-size: 200% 100% !important;
    animation: shimmer 3s linear infinite !important;
    color: #fff !important;
    border: none !important;
}
@media (max-width: 540px) {
    .duration-picker { grid-template-columns: 1fr; }
}

/* === Pause overlay with center play button === */
#pause-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
    background: rgba(5, 10, 22, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: coin-fade 0.3s ease;
}
.pause-content {
    text-align: center;
    animation: coin-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pause-play-btn {
    width: clamp(140px, 22vw, 220px);
    height: clamp(140px, 22vw, 220px);
    border-radius: 50%;
    border: 6px solid #fff;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 50%, #15803d 100%);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        inset 0 4px 0 rgba(255, 255, 255, 0.4),
        inset 0 -6px 0 rgba(0, 0, 0, 0.3),
        0 12px 0 #14532d,
        0 20px 60px rgba(34, 197, 94, 0.6),
        0 0 80px rgba(255, 255, 255, 0.4);
    transition: transform 0.1s;
    animation: pause-pulse 1.2s ease-in-out infinite;
    font-family: inherit;
    padding: 0;
}
@keyframes pause-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow:
            inset 0 4px 0 rgba(255, 255, 255, 0.4),
            inset 0 -6px 0 rgba(0, 0, 0, 0.3),
            0 12px 0 #14532d,
            0 20px 60px rgba(34, 197, 94, 0.6),
            0 0 60px rgba(255, 255, 255, 0.3);
    }
    50% {
        transform: scale(1.08);
        box-shadow:
            inset 0 4px 0 rgba(255, 255, 255, 0.5),
            inset 0 -6px 0 rgba(0, 0, 0, 0.3),
            0 12px 0 #14532d,
            0 28px 80px rgba(34, 197, 94, 0.85),
            0 0 100px rgba(255, 255, 255, 0.6);
    }
}
.pause-play-btn:hover {
    transform: scale(1.05);
}
.pause-play-btn:active {
    transform: scale(0.95) translateY(4px);
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.3),
        inset 0 -3px 0 rgba(0, 0, 0, 0.4),
        0 4px 0 #14532d,
        0 8px 20px rgba(34, 197, 94, 0.5);
}
.play-triangle {
    font-size: clamp(64px, 11vw, 110px);
    color: #fff;
    line-height: 1;
    margin-left: 10px; /* optical center for triangle */
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
.pause-message {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(22px, 3vw, 36px);
    color: #fff;
    font-weight: 900;
    margin-top: 28px;
    letter-spacing: 1px;
    text-shadow:
        3px 3px 0 rgba(0, 0, 0, 0.5),
        0 0 24px rgba(34, 197, 94, 0.5);
    animation: pause-text-bob 1.4s ease-in-out infinite;
}
@keyframes pause-text-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* === Celebration screen (post-game, pre-scoreboard) === */
#celebration-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 28;
    background: radial-gradient(circle at center, rgba(50, 30, 90, 0.85) 0%, rgba(5, 7, 15, 0.92) 70%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: coin-fade 0.4s ease;
}
.celebration-content {
    text-align: center;
    padding: 18px;
    max-width: 540px;
    max-height: 92vh;
    animation: coin-bounce 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.celebration-emoji {
    font-size: clamp(40px, 6vw, 70px);
    margin-bottom: 4px;
    animation: celebrate-bob 1.4s ease-in-out infinite;
    line-height: 1;
}
@keyframes celebrate-bob {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50% { transform: translateY(-12px) rotate(3deg); }
}
.celebration-title {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(22px, 3.4vw, 36px);
    font-weight: 900;
    background: linear-gradient(180deg, #ffd60a 0%, #ff8800 60%, #ff5e78 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.4);
    margin-bottom: 8px;
    line-height: 1.05;
    letter-spacing: 1px;
}
.celebration-place {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(18px, 2.6vw, 28px);
    font-weight: 700;
    color: #fff;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.5), 0 0 14px rgba(0, 243, 255, 0.4);
    margin-bottom: 18px;
    letter-spacing: 1px;
}
.celebration-quote {
    display: none;
}
.celebration-prompt {
    font-size: clamp(11px, 1.3vw, 14px) !important;
    color: rgba(255, 255, 255, 0.7) !important;
    font-weight: 600 !important;
    margin-top: 10px !important;
    margin-bottom: 0 !important;
    letter-spacing: 1.5px;
}
.celebration-buttons {
    margin: 4px 0;
}
.celeb-btn {
    padding: 12px 32px !important;
    font-size: clamp(16px, 2.4vw, 24px) !important;
    min-width: 110px !important;
}
.celebration-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}
.celeb-btn {
    padding: 16px 40px;
    font-size: clamp(20px, 3vw, 30px);
    font-weight: 900;
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    border: 4px solid #fff;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 2px;
    box-shadow: 0 6px 0 rgba(0,0,0,0.3), 0 10px 24px rgba(0,0,0,0.4);
    min-width: 140px;
}
.celeb-yes {
    background: linear-gradient(180deg, #22c55e, #15803d);
    color: #fff;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}
.celeb-no {
    background: linear-gradient(180deg, #ef4444, #991b1b);
    color: #fff;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}
.celeb-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 9px 0 rgba(0,0,0,0.3), 0 14px 28px rgba(0,0,0,0.5);
}
.celeb-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.3), 0 4px 10px rgba(0,0,0,0.4);
}

/* === Get Ready / Set / Go countdown === */
#start-countdown {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    background: radial-gradient(circle at center, rgba(0, 80, 160, 0.4), rgba(0, 0, 0, 0.7) 70%);
    pointer-events: none;
    animation: coin-fade 0.2s ease;
}
.start-countdown-text {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(60px, 13vw, 160px);
    font-weight: 900;
    color: #fff;
    text-shadow:
        4px 4px 0 #1e3a8a,
        8px 8px 0 #ef4444,
        0 0 40px rgba(255, 255, 255, 0.5);
    letter-spacing: 4px;
    animation: count-pop 0.6s ease;
}
.start-countdown-text.go {
    background: linear-gradient(180deg, #22c55e 0%, #15803d 50%, #ffd60a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow:
        4px 4px 0 rgba(0,0,0,0.4),
        0 0 60px rgba(34, 197, 94, 0.6);
    font-size: clamp(80px, 18vw, 220px);
}

/* === COIN ROUND interlude overlay === */
#coin-round {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    background:
        radial-gradient(circle at center, rgba(255, 214, 10, 0.35), rgba(0, 0, 0, 0.85) 70%);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: coin-fade 0.4s ease;
}
@keyframes coin-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}
.coin-round-content {
    text-align: center;
    animation: coin-bounce 0.6s ease;
}
@keyframes coin-bounce {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}
.coin-round-title {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(60px, 12vw, 140px);
    font-weight: 900;
    letter-spacing: 4px;
    background: linear-gradient(180deg, #ffd60a 0%, #fbbf24 50%, #ff5e78 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow:
        4px 4px 0 #000,
        8px 8px 24px rgba(255, 214, 10, 0.4);
    margin-bottom: 12px;
}
.coin-round-emoji {
    font-size: clamp(40px, 7vw, 80px);
    margin-bottom: 16px;
    animation: spin 1s linear infinite;
}
.coin-round-countdown {
    font-family: 'Impact', 'Bebas Neue', 'Anton', 'Oswald', 'Arial Black', sans-serif;
    font-size: clamp(80px, 16vw, 200px);
    font-weight: 900;
    color: #fff;
    text-shadow:
        4px 4px 0 #ef4444,
        0 8px 32px rgba(255, 255, 255, 0.5);
    animation: count-pop 0.5s ease;
}
@keyframes count-pop {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); }
}

/* Sticky play-again button on end-modal so users never scroll for it */
#end-modal .modal-content {
    padding-bottom: 0;
}
#end-modal #restart-btn {
    position: sticky;
    bottom: 0;
    margin: 16px -40px -36px;
    width: calc(100% + 80px);
    padding: 18px 24px;
    border-radius: 0;
    z-index: 5;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}
@media (max-width: 540px) {
    #end-modal #restart-btn {
        margin: 16px -24px -20px;
        width: calc(100% + 48px);
    }
}

/* v3 specific */
.version-tag {
    margin-top: 16px;
    font-size: 10px;
    color: rgba(255,255,255,0.3);
    letter-spacing: 2px;
}

/* ============================================================
   Mobile touch controls — big thumb-friendly buttons
   ============================================================ */
#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 24px 28px;
    pointer-events: none;
    z-index: 15;
}

.touch-btn {
    pointer-events: auto;
    width: clamp(80px, 14vw, 130px);
    height: clamp(80px, 14vw, 130px);
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.7);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.08s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.touch-btn:active {
    transform: scale(0.92);
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
.touch-icon {
    font-size: clamp(28px, 5vw, 44px);
    line-height: 1;
}
.touch-label {
    font-size: clamp(11px, 1.4vw, 15px);
    font-weight: 900;
    letter-spacing: 2px;
    margin-top: 4px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
/* JUMP stays as a circular friendly button */
.touch-jump {
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.6), rgba(0, 100, 220, 0.6));
    border-color: rgba(150, 220, 255, 0.85);
}

/* GAS is now a real metallic gas pedal coming from the bottom of the screen */
.touch-gas {
    width: clamp(72px, 10vw, 110px) !important;
    height: clamp(110px, 16vw, 170px) !important;
    border-radius: 14px 14px 6px 6px !important;
    background: linear-gradient(180deg, #cfcfcf 0%, #9a9a9a 45%, #6e6e6e 100%) !important;
    border: 3px solid #2a2a2a !important;
    box-shadow:
        inset 0 4px 0 rgba(255,255,255,0.45),
        inset 0 -6px 0 rgba(0,0,0,0.35),
        0 10px 0 #2a2a2a,
        0 14px 24px rgba(0,0,0,0.5) !important;
    position: relative;
    overflow: hidden;
    transform-origin: bottom center;
    transition: transform 0.08s ease;
}
.touch-gas:active {
    transform: rotate(-3deg) scale(0.98);
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.3),
        inset 0 -3px 0 rgba(0,0,0,0.4),
        0 4px 0 #2a2a2a,
        0 6px 14px rgba(0,0,0,0.5) !important;
}
/* Hide the default icon/label spans inside the pedal — we use ::before/::after for pedal lines */
.touch-gas .touch-icon { display: none; }
.touch-gas .touch-label {
    position: absolute;
    bottom: 6px;
    left: 0; right: 0;
    text-align: center;
    color: #1a1a1a;
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
    font-weight: 900;
    letter-spacing: 2px;
    font-size: clamp(11px, 1.3vw, 14px);
}
/* Vertical grooves on the pedal face */
.touch-gas::before {
    content: '';
    position: absolute;
    top: 14%;
    left: 18%;
    right: 18%;
    height: 56%;
    background:
        repeating-linear-gradient(
            90deg,
            #4a4a4a 0px,
            #4a4a4a 3px,
            transparent 3px,
            transparent 11px
        );
    border-radius: 4px;
    opacity: 0.7;
}

/* Show on touch devices automatically while playing */
@media (hover: none) and (pointer: coarse) {
    #touch-controls:not(.hidden) {
        display: flex !important;
    }
}
/* Hide on desktop unless explicitly shown */
@media (hover: hover) and (pointer: fine) {
    #touch-controls {
        display: none !important;
    }
}

