/* ============================================================
   Retro Racer - "Modern Retro Fusion" UI
   A Forza-style premium HUD fused with a retro sunset palette.
   Visual layer only - all IDs/classes the game JS drives are kept.
   Fonts (Chakra Petch + Sora) are linked from the page template.
   ============================================================ */

.retro-racer {
    /* ---- design tokens ---- */
    --rr-bg:          #0a0612;                 /* deep violet-black */
    --rr-frame:       #0c0818;                 /* frame backdrop base */
    --rr-ink:         #f6f1ff;                 /* warm near-white */
    --rr-muted:       #b6a9cf;                 /* lavender-gray */
    --rr-faint:       #8579a0;                 /* dim label gray */

    --rr-orange:      #ff8a3d;
    --rr-pink:        #ff3d77;
    --rr-purple:      #7c3aed;

    /* sunset ramp - the hero accent */
    --rr-grad:        linear-gradient(100deg, #ff8a3d 0%, #ff3d77 50%, #7c3aed 100%);
    --rr-grad-soft:   linear-gradient(100deg, #ffab63 0%, #ff6a98 52%, #9a64ee 100%);

    --rr-glass:        rgba(20, 13, 33, 0.52);
    --rr-glass-strong: rgba(14, 9, 24, 0.80);
    --rr-line:         rgba(255, 255, 255, 0.12);

    --rr-gas:         #28c76f;                  /* accelerate (kept green) */
    --rr-brake:       #ff4d4d;                  /* brake (kept red) */

    --rr-glow-pink:   rgba(255, 61, 119, 0.45);
    --rr-glow-orange: rgba(255, 138, 61, 0.40);

    max-width: 1000px;
    margin: 0 auto;
    padding: 16px;
    font-family: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--rr-ink);
}

/* ---------- title ---------- */

.racer-title {
    margin: 0 0 6px;
    font-family: "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
    font-size: clamp(34px, 6vw, 52px);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
    background: var(--rr-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 6px 26px rgba(255, 61, 119, 0.35));
}

.racer-subtitle {
    margin: 0 0 22px;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--rr-muted);
    text-align: center;
}

/* ---------- game frame ---------- */

.racer-frame {
    position: relative;
    width: min(100%, calc(78vh * 1.6));
    margin: 0 auto;
    aspect-ratio: 16 / 10;
    /* sunset sky -> warm horizon: shown while the 3D canvas loads */
    background:
        linear-gradient(180deg, #271743 0%, #5a2a55 42%, #b04d45 70%, #e89351 100%);
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow:
        0 28px 70px -26px rgba(0, 0, 0, 0.85),
        0 0 60px -22px var(--rr-glow-pink),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

/* faint sunset rim-glow hugging the frame */
.racer-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    background:
        radial-gradient(120% 80% at 50% -10%, rgba(255, 138, 61, 0.10), transparent 55%);
    z-index: 4;
}

#racerCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    z-index: 1;
}

/* ---------- HUD ---------- */

.racer-hud {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
    z-index: 5;
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 78px;
    padding: 9px 15px;
    border-radius: 14px;
    background: var(--rr-glass);
    border: 1px solid var(--rr-line);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    backdrop-filter: blur(16px) saturate(150%);
    box-shadow:
        0 10px 26px -14px rgba(0, 0, 0, 0.85),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

.hud-item:last-child {
    align-items: flex-end;
    text-align: right;
}

.hud-label {
    font-family: "Chakra Petch", sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--rr-faint);
}

.hud-value {
    font-family: "Chakra Petch", sans-serif;
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
    color: var(--rr-ink);
    font-variant-numeric: tabular-nums;
}

/* speed is the hero readout - gradient fill + a tinted panel */
.hud-item--speed {
    align-items: center;
    text-align: center;
    border-color: rgba(255, 61, 119, 0.40);
    box-shadow:
        0 10px 26px -14px rgba(0, 0, 0, 0.85),
        0 0 26px -10px var(--rr-glow-pink),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.hud-item--speed .hud-value {
    font-size: 22px;
    background: var(--rr-grad-soft);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ---------- overlays (start / results) ---------- */

.racer-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
    padding: 28px;
    background:
        radial-gradient(125% 90% at 50% 0%, rgba(124, 58, 237, 0.28), transparent 55%),
        radial-gradient(120% 90% at 50% 100%, rgba(255, 61, 119, 0.18), transparent 55%),
        rgba(8, 5, 16, 0.82);
    -webkit-backdrop-filter: blur(12px) saturate(135%);
    backdrop-filter: blur(12px) saturate(135%);
}

.racer-overlay h2 {
    margin: 0;
    font-family: "Chakra Petch", sans-serif;
    font-size: clamp(30px, 6vw, 46px);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: var(--rr-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 4px 22px rgba(255, 61, 119, 0.38));
}

.racer-overlay p {
    margin: 0;
    max-width: 440px;
    font-size: 15px;
    line-height: 1.55;
    color: var(--rr-muted);
}

.racer-best {
    font-family: "Chakra Petch", sans-serif;
    font-size: 14px;
    letter-spacing: 0.04em;
    color: var(--rr-muted);
    font-variant-numeric: tabular-nums;
}

.racer-result-time {
    font-family: "Chakra Petch", sans-serif;
    font-size: clamp(28px, 5vw, 40px);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--rr-ink);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 30px rgba(255, 138, 61, 0.35);
}

/* ---------- primary button ---------- */

.racer-btn {
    position: relative;
    min-height: 52px;
    padding: 14px 38px;
    font-family: "Chakra Petch", sans-serif;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    border: none;
    border-radius: 13px;
    color: #1a0c12;
    background: var(--rr-grad);
    cursor: pointer;
    box-shadow:
        0 12px 32px -10px var(--rr-glow-pink),
        inset 0 1px 0 rgba(255, 255, 255, 0.45);
    transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.racer-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.06) saturate(1.05);
    box-shadow:
        0 18px 42px -10px var(--rr-glow-pink),
        inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.racer-btn:active {
    transform: translateY(0) scale(0.98);
}

.racer-btn:disabled {
    background: rgba(255, 255, 255, 0.07);
    color: var(--rr-faint);
    cursor: wait;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10);
    transform: none;
    filter: none;
}

.racer-loading {
    font-family: "Chakra Petch", sans-serif;
    font-size: 13px;
    letter-spacing: 0.06em;
    color: var(--rr-faint);
    font-variant-numeric: tabular-nums;
    animation: rr-pulse 1.5s ease-in-out infinite;
}

@keyframes rr-pulse {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 1; }
}

/* ---------- countdown / GO banner ---------- */

.racer-banner {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 16%;
    pointer-events: none;
    font-family: "Chakra Petch", sans-serif;
    font-size: clamp(72px, 17vw, 150px);
    font-weight: 700;
    letter-spacing: 0.02em;
    background: var(--rr-grad-soft);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 8px 34px rgba(255, 61, 119, 0.55));
}

.racer-banner:not(.hidden) {
    animation: rr-pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes rr-pop {
    from { transform: scale(0.72); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

/* ---------- cinematic intro flyby ---------- */

/* full-frame chrome shown only during the pre-race camera sweep.
   sits above the HUD (z 5) so the letterbox bars cover it; the
   container ignores pointer events so only the Skip button is clickable. */
.racer-cinematic {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: block;
    pointer-events: none;
}

.racer-letterbox {
    position: absolute;
    left: 0;
    right: 0;
    height: 11%;
    background: #000;
}

.racer-letterbox--top {
    top: 0;
    animation: rr-bar-top 0.5s ease both;
}

.racer-letterbox--bottom {
    bottom: 0;
    animation: rr-bar-bottom 0.5s ease both;
}

@keyframes rr-bar-top {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

@keyframes rr-bar-bottom {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* car nameplate, lower-left, rising into view inside the bottom bar gutter */
.racer-flyby-label {
    position: absolute;
    left: 26px;
    bottom: calc(11% + 18px);
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: rr-fade-up 0.7s ease 0.25s both;
}

.racer-flyby-name {
    font-family: "Chakra Petch", sans-serif;
    font-size: clamp(22px, 4.4vw, 38px);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: var(--rr-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 6px 26px rgba(255, 61, 119, 0.4));
}

.racer-flyby-sub {
    font-family: "Chakra Petch", sans-serif;
    font-size: clamp(11px, 1.8vw, 14px);
    font-weight: 600;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--rr-muted);
}

@keyframes rr-fade-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* skip control, lower-right, smaller sibling of .racer-btn */
.racer-skip-btn {
    position: absolute;
    right: 22px;
    bottom: calc(11% + 18px);
    pointer-events: auto;
    min-height: 44px;
    padding: 10px 22px;
    font-family: "Chakra Petch", sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border: 1px solid var(--rr-line);
    border-radius: 12px;
    color: var(--rr-ink);
    background: var(--rr-glass-strong);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10);
    transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
    animation: rr-fade-up 0.7s ease 0.25s both;
}

.racer-skip-btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 24px -6px var(--rr-glow-pink), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

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

.hidden {
    display: none !important;
}

/* ---------- touch controls ---------- */

/* Two-thumb layout: drive cluster pinned to the left edge (left thumb holds
   gas/brake), steer cluster pinned to the right edge (right thumb rocks the
   arrows). space-between leaves a clear centre gap separating the thumb zones. */
.racer-touch {
    display: none;
    margin: 14px auto 0;
    width: 100%;
    justify-content: space-between;
    align-items: stretch;
    gap: 10px;
}

@media (pointer: coarse) {
    .racer-touch {
        display: flex;
    }
}

.touch-cluster {
    display: flex;
    flex: 1;
    max-width: 48%;
    gap: 10px;
}

.touch-cluster--drive {
    justify-content: flex-start;
}

.touch-cluster--steer {
    justify-content: flex-end;
}

.touch-btn {
    flex: 1;
    min-width: 0;
    max-width: 150px;
    padding: 0 8px;
    min-height: 60px;
    border: 1px solid var(--rr-line);
    border-radius: 15px;
    background: var(--rr-glass-strong);
    color: var(--rr-ink);
    font-family: "Chakra Petch", sans-serif;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: transform 0.08s ease, box-shadow 0.15s ease;
}

/* arrows light up with the sunset accent */
.touch-btn:active,
.touch-btn.pressed {
    background: var(--rr-grad);
    color: #1a0c12;
    border-color: transparent;
    box-shadow: 0 0 26px -4px var(--rr-glow-pink);
    transform: translateY(1px);
}

.touch-btn--gas {
    flex: 1.4;
    background: linear-gradient(180deg, rgba(40, 199, 111, 0.30), rgba(20, 120, 66, 0.42));
    border-color: rgba(40, 199, 111, 0.45);
    color: #dffaeb;
}

.touch-btn--brake {
    background: linear-gradient(180deg, rgba(255, 77, 77, 0.30), rgba(150, 30, 30, 0.42));
    border-color: rgba(255, 77, 77, 0.45);
    color: #ffe3e3;
}

.touch-btn--gas:active,
.touch-btn--gas.pressed {
    background: linear-gradient(180deg, #34e07d, #159b54);
    color: #062013;
    border-color: transparent;
    box-shadow: 0 0 26px -4px rgba(40, 199, 111, 0.65);
}

.touch-btn--brake:active,
.touch-btn--brake.pressed {
    background: linear-gradient(180deg, #ff6b6b, #c62222);
    color: #2a0606;
    border-color: transparent;
    box-shadow: 0 0 26px -4px rgba(255, 77, 77, 0.6);
}

/* ---------- footer note ---------- */

.racer-note {
    margin: 18px auto 0;
    max-width: 660px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--rr-faint);
    text-align: center;
}

.racer-note a {
    color: var(--rr-muted);
    text-decoration: underline;
    text-decoration-color: rgba(255, 138, 61, 0.5);
    text-underline-offset: 2px;
    transition: color 0.15s ease;
}

.racer-note a:hover {
    color: var(--rr-orange);
}

/* ---------- small screens ---------- */

@media (max-width: 480px) {
    .retro-racer {
        padding: 10px;
    }

    .racer-title {
        font-size: 30px;
    }

    .racer-subtitle {
        font-size: 13px;
        margin-bottom: 16px;
    }

    .hud-item {
        min-width: 0;
        padding: 7px 11px;
    }

    .hud-label {
        font-size: 9px;
        letter-spacing: 0.16em;
    }

    .hud-value {
        font-size: 15px;
    }

    .hud-item--speed .hud-value {
        font-size: 17px;
    }

    .racer-overlay p {
        font-size: 13px;
    }

    /* narrower flex buttons: shrink the label so "BRAKE" still fits */
    .racer-touch {
        gap: 8px;
    }

    .touch-cluster {
        gap: 8px;
    }

    .touch-btn {
        font-size: 16px;
        letter-spacing: 0.03em;
        padding: 0 4px;
    }

    .racer-flyby-label {
        left: 14px;
        bottom: calc(11% + 12px);
    }

    .racer-skip-btn {
        right: 12px;
        bottom: calc(11% + 12px);
        padding: 9px 16px;
        letter-spacing: 0.08em;
    }
}

/* short landscape phones: keep the frame inside the viewport */
@media (max-height: 480px) and (orientation: landscape) {
    .racer-frame {
        width: min(100%, calc(70vh * 1.6));
    }

    .racer-touch {
        margin-top: 8px;
    }

    .touch-btn {
        min-height: 48px;
    }

    /* thinner bars so the car still reads in a short viewport */
    .racer-letterbox {
        height: 8%;
    }

    .racer-flyby-label,
    .racer-skip-btn {
        bottom: calc(8% + 10px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .racer-loading,
    .racer-banner:not(.hidden),
    .racer-letterbox--top,
    .racer-letterbox--bottom,
    .racer-flyby-label,
    .racer-skip-btn {
        animation: none;
    }
}
