/* race.css — styles for the isolated typing-race page (/{lang}/typing-race).
   Self-contained: uses the site theme CSS variables so it adapts to every
   theme, and defines a couple of race-only accents with fallbacks. No
   dependency on the core typing engine / tf-widget. Tuned compact so the
   whole race (lanes + text) fits one screen without scrolling.

   THEME VAR NAMING (important): text/border tokens are `--color-ink` and
   `--color-line` (Tailwind-v4 style) — there are NO bare `--ink`/`--line`
   aliases, so using those silently drops the rule (missing borders/text).
   Surfaces/accents DO have bare aliases: --surface/--surface2/--surface3,
   --primary, --muted, --muted-dark, --yellow, --orange, --bg. */

:root {
    --race-green: #16a34a;
    --race-red: #ef4444;
}

.race-wrap { max-width: 62rem; margin: 0 auto; padding: .9rem 1.25rem; }

/* ── Compact hero ──────────────────────────────────────────────── */
.race-hero { text-align: center; padding: 1.1rem 1.25rem .6rem; }
.race-hero h1 { font-size: clamp(1.9rem, 4vw, 2.35rem); font-weight: 800; letter-spacing: -.02em; color: var(--color-ink); line-height: 1.1; }
.race-hero p { max-width: 44rem; margin: .35rem auto 0; font-size: .9rem; color: var(--muted); }

/* ── Lanes / racetrack ─────────────────────────────────────────── */
.race-lanes { display: flex; flex-direction: column; gap: .4rem; }

.race-lane {
    background: var(--surface);
    border: 1px solid var(--color-line);
    border-radius: 12px;
    padding: .4rem .7rem .5rem;
}
.race-lane.is-you { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }

.race-lane-head {
    display: flex; align-items: center; gap: .45rem;
    font-size: .8rem; margin-bottom: .3rem; color: var(--color-ink);
}
.race-name { font-weight: 600; }
.race-guest-pill {
    font-size: .6rem; font-weight: 700; letter-spacing: .03em;
    text-transform: uppercase; padding: .05rem .38rem; border-radius: 999px;
    background: var(--surface3); color: var(--muted);
}
.race-lane-wpm { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .8rem; }
.race-lane-wpm b { color: var(--color-ink); font-weight: 700; }

.race-track {
    position: relative; height: 20px; border-radius: 999px;
    background: var(--surface2);
    overflow: hidden;
}
.race-fill {
    position: absolute; inset: 0 auto 0 0; width: 0;
    background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 32%, transparent), color-mix(in srgb, var(--primary) 10%, transparent));
    transition: width .09s linear;
}
/* Cars: vehicle emoji faces LEFT by default; we travel left→right, so mirror it. */
.race-car {
    position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%) scaleX(-1);
    font-size: 17px; line-height: 1; will-change: left;
    transition: left .09s linear;
}
.race-finish-flag { position: absolute; top: 0; right: 3px; height: 100%; display: grid; place-items: center; opacity: .45; font-size: 12px; }

/* ── Typing box ────────────────────────────────────────────────── */
.race-text {
    margin-top: .85rem; padding: .8rem 1rem;
    background: var(--surface); border: 1px solid var(--color-line); border-radius: 14px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 1.05rem; line-height: 1.85; letter-spacing: .3px;
    color: var(--muted); user-select: none; position: relative;
}
.race-text .ch { position: relative; }
.race-text .ch.correct { color: var(--color-ink); }
.race-text .ch.wrong { color: var(--race-red); background: color-mix(in srgb, var(--race-red) 16%, transparent); border-radius: 3px; }
.race-text .ch.cur::before {
    content: ""; position: absolute; left: -1px; top: 8%; bottom: 8%; width: 2px;
    background: var(--primary); border-radius: 2px; animation: race-blink 1s steps(1) infinite;
}
@keyframes race-blink { 50% { opacity: 0; } }

.race-hint { margin-top: .55rem; text-align: center; font-size: .82rem; color: var(--muted); min-height: 1.1em; }

/* ── Countdown overlay ─────────────────────────────────────────── */
.race-count {
    position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
    background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(2px);
}
.race-count-num {
    font-family: 'JetBrains Mono', monospace; font-weight: 800;
    font-size: clamp(4rem, 18vw, 9rem); color: var(--primary); line-height: 1;
    animation: race-pop .6s ease;
}
@keyframes race-pop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Result screen ─────────────────────────────────────────────── */
.race-result { margin-top: 1rem; }
.race-result h2 { text-align: center; font-weight: 800; font-size: 1.4rem; color: var(--color-ink); margin: .3rem 0 .5rem; }
.race-place { text-align: center; font-weight: 700; font-size: 1.05rem; color: var(--muted); margin-bottom: 1rem; }
.race-place.win { color: var(--yellow); font-size: 1.2rem; }
.race-podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; align-items: end; margin-bottom: 1rem; }
.race-pod {
    background: var(--surface); border: 1px solid var(--color-line); border-radius: 14px;
    padding: .85rem .7rem; text-align: center;
}
.race-pod .medal { font-size: 1.6rem; line-height: 1; }
.race-pod .nm { margin-top: .4rem; font-weight: 600; color: var(--color-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-pod .big { font-family: 'JetBrains Mono', monospace; font-size: 1.5rem; font-weight: 800; color: var(--primary); margin-top: .2rem; }
.race-pod .sub { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.race-pod.p1 { transform: translateY(-.5rem); box-shadow: 0 0 0 2px color-mix(in srgb, var(--yellow) 45%, transparent); }

.race-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--color-line); border-radius: 14px; overflow: hidden; }
.race-table th, .race-table td { padding: .6rem .85rem; text-align: left; font-size: .88rem; }
.race-table thead th { background: var(--surface2); color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; }
.race-table tbody tr { border-top: 1px solid var(--color-line); }
.race-table td.num, .race-table th.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
.race-table tr.is-you td { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.race-table tr.racing td { opacity: .68; }   /* still finishing */

.race-btn {
    display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
    padding: .65rem 1.3rem; border-radius: 11px; border: 1px solid var(--primary);
    background: var(--primary); color: #fff; font-weight: 700; font-size: .92rem;
}
.race-btn.ghost { background: transparent; color: var(--color-ink); border-color: var(--color-line); }
.race-actions { margin-top: 1rem; display: flex; gap: .7rem; justify-content: center; }
/* FAQ uses the site's card-style Tailwind pattern (bg-card / border-line),
   same as touch-typing-test. The `group-open:rotate-180` utility isn't in the
   compiled build, so the chevron flip is done here instead. */
details.group summary svg { transition: none; transform-box: fill-box; transform-origin: center; }
details.group[open] summary svg { transform: rotate(180deg); }
