/* =========================================================
   HYPERCAR SHOWDOWN — Arcade Neon HUD Restyle
   Design tokens, dark neon identity, dashboard aesthetic.
   Game logic in script.js is untouched; this only restyles
   the shell, HUD, menus and feedback.
   ========================================================= */

:root {
    /* Surfaces */
    --bg-color: #07080d;
    --bg-color-2: #11131f;
    --panel-bg: rgba(18, 22, 36, 0.55);
    --panel-bg-2: rgba(10, 13, 22, 0.65);
    --panel-border: rgba(120, 160, 255, 0.14);

    /* Brand neon — accent MUST stay #00ffcc to match JS-set colors */
    --accent: #00ffcc;
    --accent-glow: rgba(0, 255, 204, 0.45);
    --accent-2: #19b6ff;        /* electric blue */
    --danger: #ff0055;          /* matches JS lose/boost color */
    --danger-glow: rgba(255, 0, 85, 0.5);
    --amber: #ffbe0b;

    /* Text */
    --text-primary: #f4f8ff;
    --text-secondary: #8a96b8;
    --text-dim: #7a86ad;

    /* Track */
    --track-color: #0c0e16;

    /* Type scale (modular, responsive) */
    --fs-hero: clamp(2.1rem, 6vw, 3.6rem);
    --fs-h1: clamp(1.8rem, 5vw, 2.8rem);
    --fs-gauge: clamp(2.2rem, 7vw, 3.6rem);
    --fs-countdown: clamp(5rem, 22vw, 11rem);

    /* Rhythm */
    --space: clamp(1rem, 2.5vw, 2.5rem);
    --radius-lg: 26px;
    --radius-md: 16px;
    --radius-sm: 12px;

    /* Shadows */
    --shadow-deep: 0 30px 60px -18px rgba(0, 0, 0, 0.75);
    --ease-pop: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    background:
        radial-gradient(1200px 700px at 50% -10%, #1a2140 0%, transparent 60%),
        radial-gradient(900px 600px at 100% 110%, #1e1030 0%, transparent 55%),
        radial-gradient(circle at center, var(--bg-color-2) 0%, var(--bg-color) 70%);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, .countdown, .value, .primary-btn, .brand-badge {
    font-family: 'Orbitron', sans-serif;
}

/* =========================================================
   Ambient background FX
   ========================================================= */
.bg-fx {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-grid {
    position: absolute;
    inset: -50%;
    background-image:
        linear-gradient(rgba(0, 255, 204, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(25, 182, 255, 0.06) 1px, transparent 1px);
    background-size: 60px 60px;
    transform: perspective(600px) rotateX(62deg) translateY(10%) scale(1.6);
    transform-origin: center bottom;
    mask-image: linear-gradient(to top, #000 0%, transparent 70%);
    -webkit-mask-image: linear-gradient(to top, #000 0%, transparent 70%);
    animation: gridScroll 6s linear infinite;
    opacity: 0.55;
}

@keyframes gridScroll {
    from { background-position: 0 0, 0 0; }
    to   { background-position: 0 60px, 0 60px; }
}

.bg-glow {
    position: absolute;
    width: 50vmax;
    height: 50vmax;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
    animation: floatGlow 14s ease-in-out infinite alternate;
}

.bg-glow--cyan {
    top: -15%;
    left: -10%;
    background: radial-gradient(circle, var(--accent) 0%, transparent 65%);
}

.bg-glow--magenta {
    bottom: -20%;
    right: -12%;
    background: radial-gradient(circle, var(--danger) 0%, transparent 65%);
    animation-delay: -7s;
}

@keyframes floatGlow {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to   { transform: translate3d(4%, 6%, 0) scale(1.15); }
}

.bg-scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.02) 0,
        rgba(255, 255, 255, 0.02) 1px,
        transparent 1px,
        transparent 3px
    );
    mix-blend-mode: overlay;
    opacity: 0.6;
}

/* =========================================================
   Screens
   ========================================================= */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: clamp(0.75rem, 3vw, 2rem);
    z-index: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Center panels vertically when there is room; allow scroll when there isn't */
.screen > .glass-panel {
    margin-top: auto;
    margin-bottom: auto;
}

/* Race screen: track-container is the only in-flow element; centre it vertically */
#race-screen > .track-container {
    margin-top: auto;
    margin-bottom: auto;
}

.screen.active {
    display: flex;
    animation: screenIn 0.5s ease both;
}

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

/* =========================================================
   Glass Panel (menus)
   ========================================================= */
.glass-panel {
    position: relative;
    background:
        linear-gradient(160deg, var(--panel-bg) 0%, var(--panel-bg-2) 100%);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(22px) saturate(140%);
    -webkit-backdrop-filter: blur(22px) saturate(140%);
    border-radius: var(--radius-lg);
    padding: clamp(1.5rem, 4vw, 2.75rem);
    text-align: center;
    box-shadow: var(--shadow-deep),
                inset 0 1px 0 rgba(255, 255, 255, 0.06);
    max-width: 640px;
    width: 100%;
    z-index: 10;
    overflow: hidden;
    animation: panelIn 0.6s var(--ease-pop) both;
}

@keyframes panelIn {
    from { opacity: 0; transform: translateY(28px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* neon top edge */
.glass-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 12%;
    right: 12%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
    box-shadow: 0 0 18px var(--accent-glow);
}

.brand-badge {
    display: inline-block;
    font-size: clamp(0.6rem, 1.6vw, 0.72rem);
    letter-spacing: 0.45em;
    font-weight: 800;
    color: var(--accent);
    padding: 0.45em 1em 0.45em 1.4em;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    margin-bottom: clamp(0.75rem, 2vw, 1.25rem);
    background: rgba(0, 255, 204, 0.05);
    text-shadow: 0 0 12px var(--accent-glow);
}

.glass-panel h1 {
    font-size: var(--fs-hero);
    font-weight: 900;
    line-height: 1.02;
    margin-bottom: 0.4rem;
    letter-spacing: 0.04em;
    text-shadow: 0 2px 30px rgba(0, 0, 0, 0.6);
}

.glass-panel h1 span {
    background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 18px var(--accent-glow));
}

.glass-panel p {
    color: var(--text-secondary);
    font-size: clamp(0.95rem, 2.2vw, 1.05rem);
    margin-bottom: clamp(1.5rem, 4vw, 2.25rem);
}

/* =========================================================
   Car Selection (cards are JS-generated: img + span)
   ========================================================= */
.car-selection {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    justify-content: center;
    margin-bottom: clamp(1.75rem, 4vw, 2.5rem);
    /* Allow internal scroll when many cars overflow on short viewports */
    max-height: clamp(200px, 38vh, 340px);
    overflow-y: auto;
    overflow-x: hidden;
    /* Padding gives focus rings room to render inside the scroll container */
    padding: 10px 12px 6px 10px;
    /* Custom scrollbar for neon aesthetic */
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.car-selection::-webkit-scrollbar {
    width: 4px;
}
.car-selection::-webkit-scrollbar-track {
    background: transparent;
}
.car-selection::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 999px;
    opacity: 0.5;
}

.car-option {
    position: relative;
    width: clamp(116px, 30vw, 150px);
    padding: clamp(0.75rem, 2vw, 1rem) 0.75rem;
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
    border: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    transition: transform 0.3s var(--ease-pop), border-color 0.3s ease,
                box-shadow 0.3s ease, background 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
}

.car-option::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(120% 80% at 50% 130%, var(--accent-glow), transparent 60%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.car-option:hover {
    transform: translateY(-4px);
    border-color: rgba(0, 255, 204, 0.35);
    box-shadow: 0 16px 30px -16px rgba(0, 0, 0, 0.8);
}

.car-option.selected {
    border-color: var(--accent);
    background: linear-gradient(180deg, rgba(0, 255, 204, 0.1), rgba(0, 255, 204, 0.02));
    box-shadow: 0 0 0 1px var(--accent),
                0 0 26px -4px var(--accent-glow),
                inset 0 0 26px -8px var(--accent-glow);
    transform: translateY(-4px);
}

.car-option.selected::after { opacity: 1; }

.car-option img {
    width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 12px 12px rgba(0, 0, 0, 0.5));
    transition: transform 0.35s var(--ease-pop);
}

.car-option:hover img { transform: scale(1.06); }

.car-option span {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.car-option.selected span {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
}

/* =========================================================
   Buttons
   ========================================================= */
.primary-btn {
    position: relative;
    background: transparent;
    color: var(--accent);
    border: 2px solid var(--accent);
    padding: clamp(0.8rem, 2.2vw, 1rem) clamp(2rem, 6vw, 2.8rem);
    font-size: clamp(1rem, 2.6vw, 1.2rem);
    font-weight: 700;
    border-radius: 999px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    transition: color 0.3s ease, box-shadow 0.3s ease, transform 0.15s ease;
    box-shadow: 0 0 0 transparent, inset 0 0 0 transparent;
    overflow: hidden;
    isolation: isolate;
}

.primary-btn::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(100deg, var(--accent), var(--accent-2));
    transform: translateY(101%);
    transition: transform 0.35s var(--ease-pop);
}

.primary-btn:hover,
.primary-btn:focus-visible {
    color: var(--bg-color);
    box-shadow: 0 0 28px var(--accent-glow);
}

.primary-btn:hover::before,
.primary-btn:focus-visible::before {
    transform: translateY(0);
}

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

/* =========================================================
   Race HUD
   ========================================================= */
.ui-layer {
    position: absolute;
    top: clamp(0.9rem, 3vw, 2rem);
    left: clamp(0.9rem, 3vw, 2rem);
    right: clamp(0.9rem, 3vw, 2rem);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    z-index: 20;
    pointer-events: none;
}

.gauges {
    display: flex;
    gap: clamp(0.75rem, 3vw, 2rem);
}

.gauge {
    display: flex;
    flex-direction: column;
    padding: clamp(0.5rem, 1.5vw, 0.85rem) clamp(0.7rem, 2vw, 1.1rem);
    border-radius: var(--radius-sm);
    background: linear-gradient(160deg, rgba(10, 14, 24, 0.6), rgba(10, 14, 24, 0.3));
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.gauge .value {
    font-size: var(--fs-gauge);
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 14px var(--accent-glow);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.rpm-gauge .value {
    color: var(--amber);
    text-shadow: 0 0 14px rgba(255, 190, 11, 0.45);
}

.gauge .unit {
    font-family: 'Rajdhani', sans-serif;
    font-size: clamp(0.65rem, 1.6vw, 0.85rem);
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.22em;
    margin-top: 0.25rem;
}

.boost-indicator {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    padding: clamp(0.5rem, 1.5vw, 0.85rem) clamp(0.7rem, 2vw, 1.1rem);
    border-radius: var(--radius-sm);
    background: linear-gradient(160deg, rgba(10, 14, 24, 0.88), rgba(10, 14, 24, 0.78));
    border: 1px solid rgba(255, 0, 85, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.boost-bar {
    width: clamp(110px, 28vw, 160px);
    height: 9px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6);
}

/* boost-fill width is driven by JS inline style — keep it width-based */
.boost-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--danger), #ff5e8a);
    box-shadow: 0 0 12px var(--danger-glow);
    border-radius: 999px;
    transition: width 0.1s linear;
}

.boost-indicator span {
    font-family: 'Rajdhani', sans-serif;
    font-size: clamp(0.65rem, 1.6vw, 0.8rem);
    color: #ff5e8a;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-shadow: 0 0 10px var(--danger-glow);
}

/* Countdown — JS toggles display:block/none, so keep centering on transform */
.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--fs-countdown);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 40px rgba(255, 255, 255, 0.6),
                 0 0 80px var(--accent-glow);
    z-index: 30;
    display: none;
    animation: countPop 0.9s var(--ease-pop);
}

@keyframes countPop {
    0%   { transform: translate(-50%, -50%) scale(1.7); opacity: 0; }
    35%  { opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Tap hint — JS toggles display:block/none, keep centered via transform */
.tap-hint {
    position: absolute;
    bottom: clamp(1.5rem, 5vw, 3rem);
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Orbitron', sans-serif;
    color: var(--accent);
    letter-spacing: 0.18em;
    font-size: clamp(0.8rem, 2.6vw, 1.2rem);
    text-align: center;
    text-shadow: 0 0 16px var(--accent-glow);
    animation: pulse 1.5s infinite;
    pointer-events: none;
    z-index: 20;
    display: none;
    width: 90%;
    white-space: normal;
}

@keyframes pulse {
    0%, 100% { opacity: 0.45; }
    50%      { opacity: 1; }
}

/* =========================================================
   Track
   ========================================================= */
.track-container {
    width: 100%;
    height: clamp(220px, 42vh, 460px);
    background:
        linear-gradient(180deg, #11131f 0%, var(--track-color) 50%, #0a0c14 100%);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-top: 2px solid var(--panel-border);
    border-bottom: 2px solid var(--panel-border);
    box-shadow: 0 0 70px rgba(0, 0, 0, 0.85) inset,
                0 0 30px var(--accent-glow);
}

/* neon rail accents top & bottom of the track */
.track-container::before,
.track-container::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 6;
    pointer-events: none;
}
.track-container::before {
    top: 0;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    box-shadow: 0 0 14px var(--accent-glow);
}
.track-container::after {
    bottom: 0;
    background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
    box-shadow: 0 0 14px rgba(25, 182, 255, 0.5);
}

.lane {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

/* subtle lane ground texture */
.lane::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 140% at 0% 50%, rgba(0, 255, 204, 0.05), transparent 45%);
    pointer-events: none;
}

/* lane-divider: JS drives animationDuration on moveLines — keep name & element */
.lane-divider {
    height: 5px;
    width: 100%;
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.65) 50%, transparent 50%);
    background-size: 100px 100%;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
    animation: moveLines 0s linear infinite;
    z-index: 4;
}

/* finish-line: JS drives style.right — keep absolutely positioned with right */
.finish-line {
    position: absolute;
    right: -100px;
    top: 0;
    height: 100%;
    width: 56px;
    background-image: repeating-linear-gradient(45deg, #fff 0, #fff 10px, #0a0a0a 10px, #0a0a0a 20px);
    z-index: 5;
    box-shadow: -8px 0 28px rgba(255, 255, 255, 0.3);
}

@keyframes moveLines {
    from { background-position: 0 0; }
    to   { background-position: -100px 0; }
}

/* =========================================================
   Cars — DO NOT add base transform (JS sets translateX).
   Flip lives on the <img>.
   ========================================================= */
.car-wrapper {
    position: absolute;
    left: 5%;
    width: clamp(150px, 38vw, 320px);
    transition: transform 0.1s ease-out;
    z-index: 10;
}

.car-wrapper img {
    width: 100%;
    filter: drop-shadow(-10px 15px 16px rgba(0, 0, 0, 0.65));
    transform: scaleX(-1); /* assets face left; flip to face right */
}

.exhaust-flame {
    position: absolute;
    left: -20px;
    top: 60%;
    width: 42px;
    height: 16px;
    background: linear-gradient(90deg, transparent, var(--accent-2), var(--danger), #fb5607, var(--amber));
    border-radius: 50% 0 0 50%;
    filter: blur(2px);
    opacity: 0;
    transform-origin: right center;
    transition: opacity 0.2s;
}

.exhaust-flame.active {
    opacity: 1;
    animation: flicker 0.1s infinite alternate;
}

@keyframes flicker {
    from { transform: scaleX(0.8) scaleY(0.8); }
    to   { transform: scaleX(1.3) scaleY(1.15); }
}

#tap-zone {
    cursor: pointer;
}

#tap-zone::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 160% at 0% 50%, rgba(0, 255, 204, 0.08), transparent 50%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

#tap-zone:active::after { opacity: 1; }

/* =========================================================
   End Screen
   ========================================================= */
.result-panel {
    animation: slideUp 0.55s var(--ease-pop);
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.result-panel h1 {
    font-size: var(--fs-h1);
    letter-spacing: 0.06em;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin: clamp(1.5rem, 4vw, 2rem) 0;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    flex-wrap: wrap;
}

.stat-box {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.2));
    padding: clamp(1rem, 3vw, 1.4rem);
    border-radius: var(--radius-sm);
    flex: 1 1 140px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.stat-box span {
    display: block;
    font-family: 'Rajdhani', sans-serif;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.stat-box strong {
    font-size: clamp(1.4rem, 4vw, 1.9rem);
    color: var(--accent);
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    text-shadow: 0 0 14px var(--accent-glow);
    font-variant-numeric: tabular-nums;
}

/* =========================================================
   Focus visibility (keyboard accessibility)
   ========================================================= */
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}

.car-option:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px var(--accent-glow), 0 0 30px var(--accent-glow);
}

/* Tap-zone focus ring — decorative neon inset glow matching game aesthetic */
#tap-zone:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
    box-shadow: inset 0 0 40px rgba(0, 255, 204, 0.12);
}

/* =========================================================
   Responsive tuning
   ========================================================= */
@media (max-width: 560px) {
    .ui-layer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }
    .boost-indicator {
        align-items: flex-start;
        text-align: left;
    }
    .gauges {
        justify-content: space-between;
    }
}

@media (max-width: 380px) {
    .glass-panel { padding: 1.25rem 1rem; }
    .car-selection { gap: 0.6rem; }
}

/* Reduced motion: disable non-essential animation */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .bg-grid,
    .bg-glow,
    .tap-hint,
    .exhaust-flame.active { animation: none !important; }
}
