/* ── Font ─────────────────────────────────────────────────── */
@font-face {
    font-family: 'Press Start 2P';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/PressStart2P-Regular.woff2') format('woff2');
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --retro-pink: #ff2d75;
    --retro-cyan: #00e5ff;
    --retro-yellow: #ffe600;
    --retro-orange: #ff8800;
    --retro-purple: #b300ff;
    --retro-dark: #0a0a1a;
    --retro-glass: rgba(10, 10, 30, 0.7);
    --retro-glass-border: rgba(0, 229, 255, 0.3);
    --font-retro: 'Press Start 2P', monospace;
}

body {
    overflow: hidden;
    background: #000;
    font-family: var(--font-retro);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
}

#game-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 0;
    image-rendering: pixelated;
}

/* ── Overlays ────────────────────────────────────────────── */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.overlay.hidden { display: none; }

.overlay-card {
    background: var(--retro-glass);
    border: 2px solid var(--retro-glass-border);
    border-radius: 4px;
    padding: 2rem 2.5rem;
    text-align: center;
    max-width: 90vw;
    box-shadow:
        0 0 30px rgba(0, 229, 255, 0.15),
        inset 0 0 30px rgba(0, 229, 255, 0.05);
    animation: cardAppear 0.4s ease-out;
}

@keyframes cardAppear {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ── Start Screen ────────────────────────────────────────── */
.game-title {
    font-size: 2.5rem;
    color: var(--retro-cyan);
    text-shadow:
        0 0 10px var(--retro-cyan),
        0 0 30px var(--retro-cyan),
        3px 3px 0 var(--retro-pink);
    line-height: 1.4;
    letter-spacing: 0.1em;
}

.title-sub {
    font-size: 0.7rem;
    color: var(--retro-yellow);
    margin-top: 0.5rem;
    letter-spacing: 0.3em;
    text-shadow: 0 0 8px var(--retro-yellow);
}

.start-best-score {
    font-size: 0.6rem;
    color: var(--retro-orange);
    margin: 1.5rem 0 0.5rem;
    letter-spacing: 0.1em;
}

.controls-hint {
    margin-top: 1.2rem;
    font-size: 0.45rem;
    color: rgba(255, 255, 255, 0.4);
    line-height: 2;
}

/* ── Theme Selector ──────────────────────────────────────── */
.theme-selector {
    margin: 1.2rem 0 0.2rem;
    text-align: center;
}

.theme-label {
    font-size: 0.4rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.2em;
    display: block;
    margin-bottom: 0.5rem;
}

.theme-options {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.theme-btn {
    font-family: var(--font-retro);
    font-size: 0.5rem;
    padding: 0.4rem 1rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    letter-spacing: 0.1em;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.theme-btn:hover {
    border-color: var(--retro-cyan);
    color: var(--retro-cyan);
}

.theme-btn.active {
    border-color: var(--retro-cyan);
    color: var(--retro-cyan);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.3), inset 0 0 8px rgba(0, 229, 255, 0.1);
    text-shadow: 0 0 6px var(--retro-cyan);
}

/* ── Buttons ─────────────────────────────────────────────── */
.retro-btn {
    font-family: var(--font-retro);
    font-size: 0.75rem;
    padding: 0.8rem 2rem;
    margin-top: 1.2rem;
    color: var(--retro-dark);
    background: var(--retro-cyan);
    border: none;
    border-radius: 2px;
    cursor: pointer;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
    transition: all 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.retro-btn:hover {
    background: #fff;
    box-shadow: 0 0 25px rgba(0, 229, 255, 0.7);
    transform: scale(1.05);
}

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

.pulse {
    animation: btnPulse 1.5s ease-in-out infinite;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 15px rgba(0, 229, 255, 0.4); }
    50% { box-shadow: 0 0 30px rgba(0, 229, 255, 0.8); }
}

/* ── Game Over ───────────────────────────────────────────── */
.gameover-title {
    font-size: 1.8rem;
    color: var(--retro-pink);
    text-shadow: 0 0 20px var(--retro-pink), 3px 3px 0 #800030;
    margin-bottom: 1.5rem;
}

.gameover-stats {
    margin: 1rem 0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.55rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label { color: rgba(255, 255, 255, 0.5); }
.stat-value { color: var(--retro-yellow); text-shadow: 0 0 6px var(--retro-yellow); }

.new-record {
    font-size: 0.7rem;
    color: var(--retro-yellow);
    margin: 1rem 0;
    animation: recordBlink 0.5s ease-in-out infinite alternate;
    text-shadow: 0 0 12px var(--retro-yellow);
}

.new-record.hidden { display: none; }

@keyframes recordBlink {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

/* ── Error ───────────────────────────────────────────────── */
.error-card h1 {
    color: var(--retro-pink);
    font-size: 1.2rem;
    margin-bottom: 1rem;
    text-shadow: 0 0 10px var(--retro-pink);
}

.error-card p {
    font-size: 0.5rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 2;
}

.error-hint {
    color: rgba(255, 255, 255, 0.35) !important;
    margin-top: 0.5rem;
}

/* ── HUD ─────────────────────────────────────────────────── */
#hud {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 50;
    pointer-events: none;
}

#hud.hidden { display: none; }

.hud-top {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
}

.hud-card {
    background: var(--retro-glass);
    border: 1px solid var(--retro-glass-border);
    border-radius: 3px;
    padding: 6px 14px;
    min-width: 80px;
    text-align: center;
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.1);
}

.hud-label {
    font-size: 0.35rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.15em;
    margin-bottom: 2px;
}

.hud-value {
    font-size: 0.7rem;
    color: var(--retro-cyan);
    text-shadow: 0 0 6px var(--retro-cyan);
}

.hud-speed .hud-value {
    color: var(--retro-yellow);
    text-shadow: 0 0 6px var(--retro-yellow);
}

.hud-bottom-left {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    gap: 10px;
}

.hud-bottom-right {
    position: absolute;
    bottom: 16px;
    right: 16px;
}

.life-hearts {
    font-size: 0.6rem;
    color: var(--retro-pink);
    text-shadow: 0 0 8px var(--retro-pink);
    letter-spacing: 0.15em;
}

.hud-combo .hud-value {
    color: var(--retro-orange);
    text-shadow: 0 0 6px var(--retro-orange);
    transition: transform 0.15s;
}

.nitro-bar-bg {
    width: 100px;
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(0, 229, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.nitro-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--retro-cyan), var(--retro-purple));
    box-shadow: 0 0 8px var(--retro-cyan);
    transition: width 0.2s;
    border-radius: 1px;
}

/* ── Mute Button ─────────────────────────────────────────── */
.mute-btn {
    position: fixed;
    top: 50px;
    right: 12px;
    z-index: 101;
    font-family: var(--font-retro);
    font-size: 0.35rem;
    padding: 5px 10px;
    background: var(--retro-glass);
    border: 1px solid var(--retro-glass-border);
    border-radius: 3px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    pointer-events: auto;
}

.mute-btn:hover {
    color: var(--retro-cyan);
    border-color: var(--retro-cyan);
}

/* ── Popups (near miss, combo) ───────────────────────────── */
#popup-container {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    pointer-events: none;
    text-align: center;
}

.popup-text {
    font-family: var(--font-retro);
    font-size: 0.8rem;
    color: var(--retro-yellow);
    text-shadow: 0 0 10px var(--retro-yellow), 2px 2px 0 #804000;
    animation: popupFloat 1s ease-out forwards;
    position: relative;
}

@keyframes popupFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.3); }
}

/* ── Screen FX ───────────────────────────────────────────── */
#vignette {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 40;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.6) 100%);
}

#speed-lines {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 41;
    pointer-events: none;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 48%,
        rgba(255,255,255,0.02) 48%,
        rgba(255,255,255,0.02) 52%,
        transparent 52%
    );
    opacity: 0;
    transition: opacity 0.3s;
}

#speed-lines.active { opacity: 1; }
#speed-lines.hidden { display: none; }

#nitro-glow {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 42;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 80%, rgba(0, 229, 255, 0.15) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.3s;
}

#nitro-glow.active { opacity: 1; }
#nitro-glow.hidden { display: none; }

#hit-flash {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 43;
    pointer-events: none;
    background: rgba(255, 45, 117, 0.4);
    opacity: 0;
}

#hit-flash.active {
    animation: hitFlash 0.3s ease-out forwards;
}

#hit-flash.hidden { display: none; }

@keyframes hitFlash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Scanline overlay for retro feel ─────────────────────── */
#vignette::after {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.06) 2px,
        rgba(0, 0, 0, 0.06) 4px
    );
    pointer-events: none;
}

/* ── Mobile Controls ─────────────────────────────────────── */
#mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    z-index: 55;
    display: flex;
    justify-content: space-between;
    padding: 0 12px calc(24px + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}

#mobile-controls.hidden { display: none; }

.mobile-left, .mobile-right {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.mobile-btn {
    font-family: var(--font-retro);
    font-size: 0.6rem;
    width: 56px;
    height: 56px;
    border: 2px solid var(--retro-glass-border);
    border-radius: 4px;
    background: var(--retro-glass);
    color: var(--retro-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-btn:active {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--retro-cyan);
}

.mobile-gas { color: var(--retro-yellow); border-color: rgba(255, 230, 0, 0.3); }
.mobile-gas:active { background: rgba(255, 230, 0, 0.2); }
.mobile-brake { color: var(--retro-pink); border-color: rgba(255, 45, 117, 0.3); }
.mobile-brake:active { background: rgba(255, 45, 117, 0.2); }
.mobile-nitro { color: var(--retro-purple); border-color: rgba(179, 0, 255, 0.3); }
.mobile-nitro:active { background: rgba(179, 0, 255, 0.2); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
    .game-title { font-size: 1.6rem; }
    .title-sub { font-size: 0.5rem; }
    .overlay-card { padding: 1.5rem 1.2rem; }
    .hud-card { padding: 4px 8px; min-width: 60px; }
    .hud-label { font-size: 0.28rem; }
    .hud-value { font-size: 0.5rem; }
    .retro-btn { font-size: 0.6rem; padding: 0.6rem 1.2rem; }
    .controls-hint { display: none; }
    .theme-btn { font-size: 0.4rem; padding: 0.3rem 0.7rem; }
    .gameover-title { font-size: 1.3rem; }
    .hud-bottom-left { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
    .hud-bottom-right { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
    .nitro-bar-bg { width: 70px; }
}

@media (max-width: 380px) {
    .game-title { font-size: 1.2rem; }
    .hud-top { gap: 5px; }
    .mobile-btn { width: 46px; height: 46px; font-size: 0.5rem; }
}
