/* Micro Racer — UI styles.
 * Layout: one portrait "stage" (max 480px) centred on the screen; the canvas
 * fills it and every menu is a layer on top.
 * Single committed look: racing green panels, lemon actions, chalk text. */
:root {
  --bg: #0a231b;          /* page behind the stage */
  --panel: #0f3326;       /* menus */
  --raised: #164535;      /* cards, inputs */
  --raised-2: #1d5642;
  --line: rgba(232, 244, 226, 0.14);
  --chalk: #f2f0e6;       /* text */
  --muted: #a7c0b2;
  --lemon: #ffd23f;       /* primary action */
  --lemon-ink: #1a2620;
  --good: #63e6a6;
  --bad: #ff7d68;
  --gold: #f4c542;
  --silver: #cdd6de;
  --bronze: #d4915a;
  --scrim: rgba(6, 22, 16, 0.72);

  --f-display: 'Saira Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --f-body: 'Saira', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --f-mono: 'Azeret Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --r-lg: 18px;
  --r-md: 12px;
  --pad: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 14px, transparent 14px 28px);
  color: var(--chalk);
  font: 500 15px/1.4 var(--f-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--lemon); outline-offset: 2px; }

#app { height: 100%; display: flex; justify-content: center; }
#stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, 0.5);
}
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* Phones and tablets held upright: the game takes the whole screen like an app.
   #ui holds every interface layer; main.js lays it out at the phone's real width
   and scales it up with a transform, so it looks right even when a browser lays
   the page out at desktop width. */
@media (orientation: portrait) {
  #stage { max-width: none; box-shadow: none; }
}
#ui { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform-origin: 0 0; pointer-events: none; }
/* Size rules for the interface use container queries on #ui (its real layout
   size, before the scale), not @media: the page itself may be laid out wider. */
#ui { container: ui / size; }
#ui > .screen, #ui > .overlay { pointer-events: auto; }
html, body { overscroll-behavior: none; }
body { -webkit-touch-callout: none; touch-action: manipulation; }

/* ------------------------------------------------------------ shared controls */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 0 20px;
  border: 0; border-radius: 999px;
  font: 800 20px/1 var(--f-display);
  letter-spacing: 0.06em; text-transform: uppercase;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--lemon); color: var(--lemon-ink); box-shadow: 0 4px 0 #c79f1b; }
.btn-primary:active { box-shadow: 0 1px 0 #c79f1b; transform: translateY(3px); }
.btn-secondary { background: var(--raised-2); color: var(--chalk); }
.btn-ghost { background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 2px var(--line); }
.btn-danger { background: var(--bad); color: #2a0d07; }
.btn-small { min-height: 40px; font-size: 16px; width: auto; }
.btn:disabled { filter: grayscale(1) brightness(0.7); cursor: not-allowed; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--raised); color: var(--chalk);
}
.icon-btn svg path + circle { fill: none; }
.profile-btn {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: none; box-shadow: 0 0 0 2px var(--raised-2);
}
.profile-btn .avatar { width: 44px; height: 44px; }
.icon-btn svg, .hud-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.hud-btn svg rect { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------ screens */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--panel);
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px var(--pad);
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 20;
}
.modal {
  width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 22px 18px;
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 1px var(--line), 0 16px 40px rgba(0, 0, 0, 0.4);
  -webkit-user-select: text; user-select: text;
}
.modal-title { margin: 0 0 4px; font: 900 30px/1 var(--f-display); text-transform: uppercase; letter-spacing: 0.02em; }
.modal-copy { margin: 0; color: var(--muted); font-size: 14px; }
.fine-print { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------ menu */
.menu-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px var(--pad) 10px;
}
.wordmark { display: flex; align-items: center; gap: 6px; transform: skewX(-9deg); }
.wm-tag {
  padding: 3px 7px 2px; border-radius: 5px;
  background: var(--lemon); color: var(--lemon-ink);
  font: 900 15px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase;
}
.wm-word { font: 900 32px/0.9 var(--f-display); letter-spacing: 0.01em; text-transform: uppercase; }
.wordmark::after {
  content: ''; width: 22px; height: 14px; margin-left: 2px;
  background: conic-gradient(var(--chalk) 25%, transparent 0 50%, var(--chalk) 0 75%, transparent 0) 0 0 / 7px 7px;
  opacity: 0.85;
}
.menu-top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
/* phones: the wordmark stacks (MICRO over RACER) and the buttons tighten,
   so the profile, medal points, coins, full screen and settings all fit */
@container ui (max-width: 560px) {
  .menu-top { gap: 6px; }
  .menu-top-actions { gap: 5px; }
  .wordmark { flex-direction: column; align-items: flex-start; gap: 2px; }
  .wm-tag { font-size: 11px; padding: 2px 5px 1px; }
  .wm-word { font-size: 25px; }
  .wordmark::after { display: none; }
  .menu-top-actions .icon-btn, .profile-btn, .profile-btn .avatar { width: 38px; height: 38px; }
  .menu-top .coin-chip { padding: 6px 8px; gap: 5px; }
  .menu-top .points-chip { padding: 6px 8px 6px 5px; gap: 3px; }
}
@container ui (max-width: 400px) {
  .menu-top { padding-left: 12px; padding-right: 12px; }
  .menu-top-actions { gap: 4px; }
  .menu-top .coin-chip, .menu-top .points-chip { font-size: 13px; }
}
@container ui (max-width: 370px) {
  .menu-top { gap: 4px; padding-left: 10px; padding-right: 10px; }
  .menu-top-actions { gap: 3px; }
  .wm-word { font-size: 22px; }
  .menu-top-actions .icon-btn, .profile-btn, .profile-btn .avatar { width: 36px; height: 36px; }
  .menu-top .coin-chip, .menu-top .points-chip { padding: 5px 6px; font-size: 12px; gap: 3px; }
  .points-chip svg { width: 15px; height: 15px; }
  .coin-chip .coin { transform: scale(0.85); }
}
/* the smallest phones: full screen stays in Settings */
@container ui (max-width: 330px) { #btn-fullscreen { display: none; } }
@container ui (max-width: 345px) {
  .wm-word { font-size: 19px; }
  .wm-tag { font-size: 9px; }
  .menu-top-actions .icon-btn, .profile-btn, .profile-btn .avatar { width: 33px; height: 33px; }
}

.tabs {
  display: flex; gap: 3px;
  margin: 0 var(--pad) 12px; padding: 4px;
  background: rgba(0, 0, 0, 0.22); border-radius: 999px;
}
.tabs { position: relative; }
/* One pill glides between the tabs (positioned by movePill in main.js). */
.tab-pill {
  position: absolute; top: 4px; bottom: 4px; left: 0; width: 0; z-index: 0; pointer-events: none;
  border-radius: 999px; background: var(--chalk); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  transition: transform 0.42s cubic-bezier(0.3, 1.25, 0.45, 1), width 0.42s cubic-bezier(0.3, 1.25, 0.45, 1);
}
.tabs.no-anim .tab-pill { transition: none; }
.tab {
  position: relative; z-index: 1; transition: color 0.25s ease, transform 0.12s ease;
  min-height: 40px; border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font: 800 15px/1 var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; padding: 0 8px;
  flex: 1 1 auto; white-space: nowrap;
}
@container ui (max-width: 400px) { .tab { font-size: 13px; letter-spacing: 0.03em; padding: 0 5px; } }
@container ui (max-width: 340px) { .tab { font-size: 12px; letter-spacing: 0.01em; padding: 0 3px; } }
.tab[aria-selected="true"] { color: var(--lemon-ink); }
.tab:active { transform: scale(0.95); }
.panels { flex: 1; min-height: 0; position: relative; }
/* The browser keeps vertical scrolling; sideways drags are ours (tab swipes). */
.panels, .panels > .panel { touch-action: pan-y; }
.panel {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  padding: 0 var(--pad) 24px;
  display: flex; flex-direction: column; gap: 14px;
}

.eyebrow {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted);
  font: 700 13px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase;
}
.eyebrow::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* track card */
.track-card { display: flex; flex-direction: column; gap: 12px; }
.tc-preview {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-width: 100%;
  border-radius: var(--r-lg); overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.tc-preview canvas { width: 100%; height: 100%; display: block; }
.tc-badge {
  position: absolute; left: 10px; top: 10px;
  padding: 5px 9px; border-radius: 999px;
  background: rgba(10, 35, 27, 0.78); color: var(--chalk);
  font: 700 12px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase;
}
.tc-head { display: flex; flex-direction: column; gap: 4px; }
.tc-name { margin: 0; font: 900 34px/0.95 var(--f-display); text-transform: uppercase; letter-spacing: 0.01em; text-wrap: balance; }
.tc-note { margin: 0; color: var(--muted); font-size: 14px; }
.tc-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font: 600 13px/1.2 var(--f-mono); }

.medals { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.medal {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 9px; border-radius: var(--r-md);
  background: var(--raised); color: var(--muted);
}
.medal b { font: 800 12px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
.medal span { font: 700 15px/1 var(--f-mono); font-variant-numeric: tabular-nums; color: var(--chalk); }
.medal.gold { color: var(--gold); }
.medal.silver { color: var(--silver); }
.medal.bronze { color: var(--bronze); }
.medal.earned { box-shadow: inset 0 0 0 2px currentColor; }

.best-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 14px; border-radius: var(--r-md); background: rgba(0, 0, 0, 0.2);
}
.best-row span { color: var(--muted); font: 700 13px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
.best-row b { font: 800 22px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.best-row.rival b { color: var(--lemon); }

.link-btn {
  align-self: center; border: 0; background: none; color: var(--chalk);
  font: 700 15px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
  text-decoration: underline; text-decoration-color: var(--lemon); text-underline-offset: 5px; text-decoration-thickness: 2px;
  padding: 10px;
}

/* recent dailies */
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; border: 0; border-radius: var(--r-md); background: var(--raised);
}
.day small { color: var(--muted); font: 700 11px/1 var(--f-display); letter-spacing: 0.14em; }
.day b { font: 900 22px/1 var(--f-display); }

/* tour */
.chapter { display: flex; flex-direction: column; gap: 10px; }
.chapter-lock { color: var(--muted); font-size: 13px; margin: -2px 0 0; }
.tour-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tour-tile {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 0 0 10px;
  border: 0; border-radius: var(--r-md); background: var(--raised); overflow: hidden; text-align: left;
}
.tour-tile canvas { width: 100%; aspect-ratio: 4 / 3; display: block; }
.tour-tile .tt-name { padding: 0 10px; font: 800 17px/1.05 var(--f-display); text-transform: uppercase; letter-spacing: 0.02em; min-height: 2.1em; }
.tour-tile .tt-meta { display: flex; justify-content: space-between; align-items: center; padding: 0 10px; color: var(--muted); font: 600 12px/1 var(--f-mono); }
.tour-tile.locked canvas { filter: grayscale(1) brightness(0.45); }
.tour-tile.locked .tt-name { color: var(--muted); }
.tt-lock {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 999px;
  background: rgba(10, 35, 27, 0.85); font: 700 12px/1 var(--f-mono);
}
.tour-tile .tt-req { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; color: var(--muted); font: 600 12px/1.25 var(--f-body); }
.tt-req b { color: var(--chalk); font: 800 13px/1.1 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase; }
/* milestone progress: bar + "12/20" */
.progress { display: flex; align-items: center; gap: 8px; }
.progress-track { flex: 1; display: block; height: 6px; border-radius: 999px; background: rgba(0, 0, 0, 0.35); overflow: hidden; }
.progress-track i { display: block; height: 100%; border-radius: 999px; background: var(--lemon); }
.progress b { flex: none; color: var(--chalk); font: 700 11px/1 var(--f-mono); white-space: nowrap; }
.progress.big .progress-track { height: 8px; background: rgba(0, 0, 0, 0.3); }
.progress.big .progress-track i { background: var(--good); }
.progress.big b { font-size: 12px; }
.chapter > .progress, .garage-note + .progress { margin: -2px 0 2px; }
.tt-lock svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* garage */
.garage-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.car-tile {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 8px 12px;
  border: 0; border-radius: var(--r-md); background: var(--raised); text-align: center;
}
.car-tile canvas { width: 100%; aspect-ratio: 3 / 2; display: block; border-radius: 8px; background: radial-gradient(circle at 50% 60%, #6aa956, #4f8a3c); }
.car-tile b { font: 800 16px/1 var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; }
.car-tile small { color: var(--muted); font: 600 12px/1 var(--f-mono); }
.car-tile.selected { box-shadow: inset 0 0 0 3px var(--lemon); }
.car-tile.for-sale canvas { filter: saturate(0.55) brightness(0.8); }
.garage-note { margin: -4px 0 0; color: var(--muted); font-size: 13px; }

/* sheet */
.sheet-top { display: flex; align-items: center; gap: 12px; padding: 4px var(--pad) 10px; }
.sheet-title { font: 800 15px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 var(--pad) 24px; }

/* ------------------------------------------------------------ HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: 52px 1fr auto; align-items: start; gap: 8px;
  padding: max(12px, env(safe-area-inset-top, 0px)) 12px 0;
}
.hud-btn {
  pointer-events: auto;
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: rgba(10, 35, 27, 0.78); color: var(--chalk);
}
.hud-clock { text-align: center; }
.hud-time {
  display: inline-block; padding: 4px 14px 5px; border-radius: 12px;
  background: rgba(10, 35, 27, 0.8); color: var(--chalk);
  font: 800 34px/1 var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.hud-delta { margin-top: 5px; min-height: 20px; font: 800 16px/1 var(--f-mono); font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }
.hud-delta span { display: inline-block; padding: 3px 8px; border-radius: 8px; background: rgba(10, 35, 27, 0.8); }
.hud-delta .good { color: var(--good); }
.hud-delta .bad { color: var(--bad); }
.hud-lap {
  display: inline-block; margin-top: 4px; padding: 4px 9px; border-radius: 8px;
  background: rgba(10, 35, 27, 0.8); color: var(--lemon);
  font: 800 12px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase;
}
.hud-target {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  padding: 7px 10px; border-radius: 12px; background: rgba(10, 35, 27, 0.78);
}
.hud-target-label { color: var(--gold); font: 800 11px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; }
.hud-target-time { font: 700 16px/1 var(--f-mono); font-variant-numeric: tabular-nums; }

.gantry {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  display: flex; gap: 10px; padding: 10px 14px; border-radius: 14px;
  background: #15171a; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  transition: opacity 0.3s ease;
}
.gantry i { width: 28px; height: 28px; border-radius: 50%; background: #2b2f35; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35); }
.gantry i.red { background: #ff3b30; box-shadow: 0 0 16px #ff3b30, inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.gantry i.green { background: #3ee07f; box-shadow: 0 0 16px #3ee07f, inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.gantry.gone { opacity: 0; }

.hud-flash {
  position: absolute; left: 0; right: 0; top: 33%;
  text-align: center; color: var(--lemon);
  font: 900 76px/1 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase;
  -webkit-text-stroke: 3px var(--lemon-ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  opacity: 0; transform: scale(0.8);
}
.hud-flash.show { animation: flash 0.9s ease-out forwards; }
@keyframes flash {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.08); }
  60% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15) translateY(-12px); }
}
.hud-wrong {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 10px; background: var(--bad); color: #2a0d07;
  font: 900 22px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase;
}

.speedo {
  position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  width: 132px; height: 82px; padding: 6px 6px 0; border-radius: 70px 70px 18px 18px;
  background: rgba(10, 35, 27, 0.8);
}
.speedo svg { width: 100%; height: auto; display: block; }
.sp-track, .sp-fill { fill: none; stroke-width: 9; stroke-linecap: round; }
.sp-track { stroke: rgba(255, 255, 255, 0.12); }
.sp-fill { stroke: var(--lemon); stroke-dasharray: 100; stroke-dashoffset: 100; }
.sp-num {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; flex-direction: column; align-items: center;
}
.sp-num b { font: 800 26px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.sp-num small { color: var(--muted); font: 700 10px/1 var(--f-display); letter-spacing: 0.18em; text-transform: uppercase; }

.touch-hint {
  position: absolute; left: 12px; right: 12px; bottom: calc(118px + env(safe-area-inset-bottom, 0px));
  display: flex; justify-content: space-between;
}
.touch-hint span {
  display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; border-radius: 999px;
  background: rgba(10, 35, 27, 0.78); font: 800 14px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
}
.touch-hint svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

#touch-dots { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.touch-dot {
  position: absolute; left: 0; top: 0; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  will-change: transform;
  background: rgba(255, 255, 255, 0.28); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}

/* ------------------------------------------------------------ results */
/* Sizes follow the screen height, so everything fits on short phones too;
   if it still can't, the overlay scrolls (margin: auto keeps it centred). */
.results {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: clamp(8px, 1.5cqh, 14px);
  margin: auto 0;
}
#results { overflow-y: auto; align-items: flex-start; }
.res-kicker {
  align-self: flex-start; padding: 6px 12px; border-radius: 8px;
  font: 900 18px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase;
  transform: skewX(-9deg);
}
.res-kicker.win { background: var(--good); color: #062417; }
.res-kicker.lose { background: var(--bad); color: #2a0d07; }
.res-time { display: flex; align-items: baseline; gap: 4px; font: 800 clamp(46px, 8.4cqh, 72px)/0.95 var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.res-time small { font-size: 0.44em; color: var(--muted); }
.res-medal { display: flex; align-items: center; gap: 10px; min-height: 30px; font: 800 18px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase; }
.res-rows { margin: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.res-rows > div { display: flex; justify-content: space-between; align-items: baseline; padding: clamp(7px, 1.3cqh, 11px) 0; border-bottom: 1px solid var(--line); }
.res-rows dt { color: var(--muted); font: 700 14px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
.res-rows dd { margin: 0; font: 800 18px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.res-rows dd.good { color: var(--good); }
.res-rows dd.bad { color: var(--bad); }
.res-rows dd.hi { color: var(--lemon); }
.res-unlocks {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.res-unlocks span {
  padding: 5px 9px; border-radius: 999px; background: var(--lemon); color: var(--lemon-ink);
  font: 800 12px/1 var(--f-display); letter-spacing: 0.08em; text-transform: uppercase;
}
.res-unlocks span.more { background: rgba(255, 210, 63, 0.18); color: var(--lemon); }
#results.swipeable { touch-action: none; }
.results.dragging { transition: none; }
.results.leaving { transition: transform 0.22s ease-in, opacity 0.22s ease-in; transform: translateY(-40%) !important; opacity: 0 !important; }
.results.settling { transition: transform 0.2s ease-out, opacity 0.2s ease-out; }
.res-actions { display: flex; flex-direction: column; gap: clamp(6px, 1.1cqh, 10px); margin-top: 4px; }
.res-actions .btn { min-height: clamp(44px, 6.4cqh, 54px); }

/* ------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--muted); font: 700 13px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
input[type="text"], .code-box {
  width: 100%; padding: 12px 14px; border: 0; border-radius: var(--r-md);
  background: var(--raised); color: var(--chalk);
  font: 600 16px/1.35 var(--f-body);
  -webkit-user-select: text; user-select: text;
}
.code-box { font: 500 13px/1.4 var(--f-mono); resize: none; word-break: break-all; }
.form-error { margin: 0; color: var(--bad); font-size: 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 999px; background: rgba(0, 0, 0, 0.22); }
.seg button { min-height: 38px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: 700 14px/1 var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; }
.seg button[aria-checked="true"] { background: var(--chalk); color: var(--lemon-ink); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { position: relative; flex: none; width: 48px; height: 28px; border-radius: 999px; background: var(--raised-2); transition: background 0.15s; }
.toggle i::after { content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--chalk); transition: transform 0.15s; }
.toggle input:checked + i { background: var(--lemon); }
.toggle input:checked + i::after { transform: translateX(20px); background: var(--lemon-ink); }
.toggle input:focus-visible + i { outline: 3px solid var(--lemon); outline-offset: 2px; }
.danger { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.confirm-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }

.toast {
  position: absolute; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--chalk); color: var(--lemon-ink);
  font: 700 15px/1.2 var(--f-body); z-index: 40; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------ motion
   Entrances when a tab opens (classes added by enterPanel in main.js, each
   with its own --d delay so items arrive one after another), plus dialogs,
   screens and the toast. "backwards" fill: nothing lingers once it's done. */
@keyframes panel-in { from { transform: translate3d(calc(var(--dir, 0) * var(--from, 26px)), 0, 0); } }
@keyframes enter-rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes enter-slide { from { opacity: 0; transform: translateX(56px); } }
@keyframes enter-pop { from { opacity: 0; transform: translateY(18px) scale(0.94); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(0.96); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes screen-right { from { opacity: 0; transform: translateX(40px); } }
@keyframes screen-up { from { opacity: 0; transform: translateY(40px); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } }
.panel-in { animation: panel-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
.enter-rise { animation: enter-rise 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) var(--d, 0ms) backwards; }
.enter-slide { animation: enter-slide 0.46s cubic-bezier(0.2, 0.85, 0.25, 1) var(--d, 0ms) backwards; }
.enter-pop { animation: enter-pop 0.44s cubic-bezier(0.25, 1.1, 0.4, 1) var(--d, 0ms) backwards; }
.overlay:not([hidden]) { animation: fade-in 0.2s ease backwards; }
.overlay:not([hidden]) > .modal, .overlay:not([hidden]) > .results { animation: modal-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.05) 0.04s backwards; }
#sheet:not([hidden]) { animation: screen-right 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
#feed:not([hidden]) { animation: screen-up 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
#menu:not([hidden]) { animation: fade-in 0.22s ease backwards; }
.toast:not([hidden]) { animation: toast-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }

@media (prefers-reduced-motion: reduce) {
  .panel-in, .enter-rise, .enter-slide, .enter-pop, .overlay:not([hidden]), .overlay:not([hidden]) > .modal,
  .overlay:not([hidden]) > .results, #sheet:not([hidden]), #feed:not([hidden]), #menu:not([hidden]), .toast:not([hidden]) { animation: none; }
  .tab-pill, .tab { transition: none; }
  .hud-flash.show { animation-duration: 0.01s; }
  .btn, .toggle i, .toggle i::after, .gantry { transition: none; }
}

/* ------------------------------------------------------------ coins and tiers */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.coin {
  display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 45%, #c48f12);
  box-shadow: inset 0 0 0 1.5px rgba(120, 80, 0, 0.45);
}
.coin-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; background: var(--raised);
  font: 700 14px/1 var(--f-mono); font-variant-numeric: tabular-nums;
}
/* medal points, beside the coins */
.points-chip {
  display: inline-flex; align-items: center; gap: 4px; border: 0; color: var(--chalk);
  padding: 6px 10px 6px 7px; border-radius: 999px; background: var(--raised);
  font: 700 14px/1 var(--f-mono); font-variant-numeric: tabular-nums;
}
.points-chip svg { width: 18px; height: 18px; flex: none; }
.points-chip:active { transform: scale(0.95); }
.coin-tag {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; align-self: center;
  padding: 4px 9px; border-radius: 999px; background: rgba(0, 0, 0, 0.25);
  font: 700 12px/1 var(--f-mono); color: var(--muted);
}
.coin-tag.can-buy { background: var(--lemon); color: var(--lemon-ink); }
.coin-tag .coin { width: 11px; height: 11px; }

/* Tier marker: trophy cup (top tier) or a disc for silver / bronze. */
/* medals and trophies (art: trophies.js, drawn in a 40 x 48 box) */
.tier { display: inline-block; flex: none; width: 23px; height: 28px; color: inherit; }
.tier svg { display: block; width: 100%; height: 100%; overflow: visible; }
.tier.none { color: var(--muted); }
.tier.mini { width: 15px; height: 18px; }
.tier.gold, .tier.silver, .tier.bronze { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.medal .tier { width: 30px; height: 36px; opacity: 0.32; filter: grayscale(0.6); }
.medal.earned .tier { opacity: 1; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4)); }
.res-medal .tier { width: 40px; height: 48px; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.45)); animation: medal-pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.res-medal span small { display: block; margin-top: 4px; font: 700 13px/1.2 var(--f-body); letter-spacing: 0.02em; text-transform: none; color: var(--chalk); opacity: 0.85; }
/* a race's own trophy: big, with a soft glow behind it */
.res-medal.own { flex-direction: column; gap: 6px; text-align: center; }
.res-medal.own .tier { width: clamp(56px, 10.5cqh, 92px); height: clamp(67px, 12.6cqh, 110px); background: radial-gradient(closest-side, rgba(255, 210, 63, 0.35), rgba(255, 210, 63, 0)); }
@keyframes medal-pop { 0% { transform: scale(0.4) rotate(-8deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .res-medal .tier { animation: none; } }
.res-medal.gold { color: var(--gold); }
.res-medal.silver { color: var(--silver); }
.res-medal.bronze { color: var(--bronze); }
.res-medal.none { color: var(--muted); }

.res-coins {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: 10px 12px; border-radius: var(--r-md); background: rgba(244, 197, 66, 0.12);
}
.res-coins .coin { width: 20px; height: 20px; }
.res-coins b { font: 800 22px/1 var(--f-mono); color: var(--gold); }
.res-coins span { font: 700 13px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.res-coins small { flex-basis: 100%; color: var(--chalk); font-size: 13px; }
.res-coins small:empty { display: none; }

.buy-modal { align-items: stretch; text-align: center; }
.buy-car { width: 100%; height: 150px; border-radius: var(--r-md); background: radial-gradient(circle at 50% 60%, #6aa956, #4f8a3c); }
.buy-price { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; font: 700 16px/1 var(--f-body); color: var(--muted); }
.buy-price b { font: 800 26px/1 var(--f-mono); color: var(--gold); }
.buy-price .coin { width: 22px; height: 22px; }

/* engine labels and the garage "Hear it" button */
.engine-tag { color: var(--muted); font: 600 11px/1 var(--f-mono); letter-spacing: 0.02em; }
.buy-engine { display: flex; align-items: center; justify-content: center; gap: 10px; margin: -4px 0 0; color: var(--muted); font: 600 14px/1 var(--f-mono); }
.hear-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border: 0; border-radius: 999px; background: var(--raised-2); color: var(--chalk);
  font: 800 13px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
}
.hear-btn svg { width: 16px; height: 16px; fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ------------------------------------------------------------ daily challenges */
.ch-hero { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--r-lg); background: var(--raised); }
.ch-hero h2 { margin: 0; font: 900 30px/0.95 var(--f-display); text-transform: uppercase; text-wrap: balance; }
.ch-hero p { margin: 0; color: var(--muted); font-size: 14px; }
.ch-progress { height: 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.3); overflow: hidden; }
.ch-progress i { display: block; height: 100%; background: var(--good); border-radius: 999px; }
.ch-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ch-row {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  width: 100%; padding: 8px 12px 8px 8px; border: 0; border-radius: var(--r-md); background: var(--raised); text-align: left;
}
.ch-row .avatar { width: 44px; height: 44px; }
.ch-row .ch-who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ch-row .ch-who b { font: 800 17px/1 var(--f-display); text-transform: uppercase; letter-spacing: 0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-row .ch-who small { color: var(--muted); font: 600 12px/1.2 var(--f-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-row .ch-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ch-row .ch-time { font: 800 16px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.ch-row.beaten { background: rgba(99, 230, 166, 0.1); }
.ch-row.beaten .ch-time { color: var(--good); }
.avatar { display: block; flex: none; border-radius: 50%; }
.avatar-lg { width: 88px; height: 88px; align-self: center; }
.avatar-xl { width: 104px; height: 104px; }

/* profile editor */
.modal.profile { gap: 14px; max-width: 420px; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-head .field { flex: 1; min-width: 0; }
.field-hint { color: var(--muted); font-size: 12px; line-height: 1.35; }
.design-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.design-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 2px 7px;
  border: 0; border-radius: var(--r-md); background: var(--raised); color: var(--muted);
  font: 700 11px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
}
.design-grid canvas { width: 46px; height: 46px; }
.design-grid button[aria-checked="true"] { background: var(--raised-2); color: var(--chalk); box-shadow: inset 0 0 0 2px var(--lemon); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button {
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--lemon); }
.profile-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; text-align: left;
  border-radius: var(--r-md); background: var(--raised); color: var(--chalk);
}
.profile-row .avatar { width: 46px; height: 46px; }
.profile-row b { display: block; font: 800 18px/1.1 var(--f-display); letter-spacing: 0.04em; }
.profile-row small { color: var(--muted); font-size: 13px; }
.brag-me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.brag-me .avatar { width: 28px; height: 28px; }
.brag-me b { color: var(--chalk); }
.brag-me button { padding: 0; border: 0; background: none; color: var(--lemon); font: inherit; text-decoration: underline; }
.ai-tag {
  display: inline-block; padding: 3px 6px; border-radius: 6px; background: var(--raised-2); color: var(--muted);
  font: 700 10px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase; vertical-align: middle;
}
/* trophy room: race trophies on shelves, dark silhouettes until won */
.trophy-count { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-md); background: rgba(0, 0, 0, 0.18); }
.trophy-count .tier { width: 26px; height: 31px; }
.trophy-count b { font: 800 18px/1 var(--f-display); letter-spacing: 0.04em; }
.trophy-count span { color: var(--muted); font-size: 13px; }
.trophy-shelf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.trophy-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0;
  padding: 10px 6px 10px; border: 0; border-radius: var(--r-md); color: var(--chalk); text-align: center;
  background: var(--raised);
}
/* each trophy stands on a short shelf */
.trophy-item .art { position: relative; width: 58px; height: 74px; padding-bottom: 4px; display: block; }
.trophy-item .art::after { content: ''; position: absolute; left: -12px; right: -12px; bottom: 0; height: 4px; border-radius: 2px; background: rgba(0, 0, 0, 0.32); }
.trophy-item .art svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4)); }
.trophy-item.unwon .art svg { filter: brightness(0) opacity(0.42); }
.trophy-item .tr-track { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; max-width: 100%; margin-top: 4px; font: 800 12px/1.1 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase; }
.trophy-item .tr-track .flag { flex: none; }
.trophy-item small { color: var(--muted); font-size: 11px; line-height: 1.2; }
.trophy-item.won small { color: var(--gold); }
.trophy-item:active { transform: scale(0.97); }

/* rally */
.tab.has-new { position: relative; }
.tab.has-new::after {
  content: ''; position: absolute; top: 4px; right: 3px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--lemon); box-shadow: 0 0 0 2px var(--panel);
}
.rally-car { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px 12px; border-radius: var(--r-md); background: rgba(0, 0, 0, 0.18); }
.rally-car canvas { width: 92px; height: 64px; flex: none; }
.rally-car b { display: block; font: 800 18px/1.1 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase; }
.rally-car small { color: var(--muted); font-size: 13px; }
/* ---------------------------------------------------------- first-time experience */
.ftue-intro .modal { gap: 12px; }
.ftue-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 2px 0; }
.ftue-controls span {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 64px; border-radius: var(--r-md);
  background: var(--raised); color: var(--chalk); font: 800 16px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
}
.ftue-controls kbd {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px; border-radius: 8px;
  background: var(--chalk); color: var(--lemon-ink); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); font: 800 20px/1 var(--f-mono);
}
.ftue-controls svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.ftue-controls-text { margin: -4px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.ftue-privacy { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.ftue-privacy a { color: var(--lemon); }

/* a coaching line during the first race, under the timer */
@keyframes tip-in { from { opacity: 0; transform: translate(-50%, -8px); } }
.coach-tip {
  position: absolute; left: 50%; top: calc(112px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  width: max-content; max-width: min(88%, 380px); padding: 10px 16px; border-radius: 14px; text-align: center;
  background: var(--chalk); color: var(--lemon-ink); font: 700 16px/1.3 var(--f-body);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); animation: tip-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

/* the first race stops before a corner: hold this side to turn */
.steer-cue {
  position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; pointer-events: none;
  background: rgba(4, 14, 10, 0.22); animation: fade-in 0.2s ease backwards;
}
/* the cue sits in the bottom corner of the side to hold, where thumbs rest */
.sc-side {
  display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; opacity: 0; transition: opacity 0.2s;
  padding: 0 22px calc(92px + env(safe-area-inset-bottom, 0px));
}
.sc-left { align-items: flex-start; }
.sc-right { align-items: flex-end; }
.sc-side b { width: 86px; text-align: center; }
.steer-cue[data-dir="-1"] .sc-left, .steer-cue[data-dir="1"] .sc-right { opacity: 1; }
.steer-cue[data-dir="-1"] .sc-left { background: radial-gradient(130% 60% at 0% 100%, rgba(255, 210, 63, 0.38), rgba(255, 210, 63, 0) 70%); }
.steer-cue[data-dir="1"] .sc-right { background: radial-gradient(130% 60% at 100% 100%, rgba(255, 210, 63, 0.38), rgba(255, 210, 63, 0) 70%); }
/* holding the right side: the game runs again and the button becomes a
   timer: red while it's too early to let go (the ring fills up), green when
   it's time to let go, red and flashing when it's too late */
.steer-cue.holding { background: none; }
.steer-cue.holding .sc-ring { animation: none; transform: scale(0.94); }
.steer-cue.holding .sc-side { background: none; }
.sc-ring { position: relative; transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease; }
.sc-ring .sc-timer { position: absolute; inset: -9px; width: auto; height: auto; overflow: visible; stroke-width: 7; fill: none; opacity: 0; transition: opacity 0.15s; }
.sc-timer .t-track { stroke: rgba(255, 255, 255, 0.22); }
.sc-timer .t-arc { stroke: #fff; stroke-linecap: round; stroke-dasharray: var(--p, 0) 100; transform: rotate(-90deg); transform-origin: 50% 50%; }
.steer-cue.early .sc-timer, .steer-cue.go .sc-timer, .steer-cue.late .sc-timer { opacity: 1; }
.steer-cue.early .sc-ring, .steer-cue.late .sc-ring, .steer-cue.again .sc-ring { background: #e8453c; color: #fff; }
.steer-cue.go .sc-ring { background: #2fd27a; color: #062417; transform: scale(1.06); }
.steer-cue.go .sc-timer .t-arc { stroke: #c9ffe1; }
.steer-cue.late .sc-ring { animation: sc-late 0.3s steps(2) infinite; }
@keyframes sc-late { 50% { background: #8f1f19; } }
.steer-cue.go .sc-text { background: #2fd27a; color: #062417; }
.steer-cue.late .sc-text, .steer-cue.again .sc-text { background: #e8453c; color: #fff; }
@keyframes sc-pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0.6); } 100% { box-shadow: 0 0 0 26px rgba(255, 210, 63, 0); } }
.sc-ring {
  display: grid; place-items: center; width: 86px; height: 86px; border-radius: 50%;
  background: var(--lemon); color: var(--lemon-ink); animation: sc-pulse 1.1s ease-out infinite;
}
.sc-ring svg { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.sc-side b { font: 900 22px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--chalk); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
.sc-text {
  position: absolute; left: 50%; bottom: calc(232px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); margin: 0;
  width: max-content; max-width: 90%; padding: 12px 18px; border-radius: 16px; text-align: center;
  background: var(--chalk); color: var(--lemon-ink); font: 800 20px/1.2 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
@keyframes sc-nudge { 0%, 100% { transform: translateX(-50%); } 25% { transform: translateX(calc(-50% - 8px)); } 75% { transform: translateX(calc(-50% + 8px)); } }
.steer-cue.nudge .sc-text { animation: sc-nudge 0.3s ease; }
@media (prefers-reduced-motion: reduce) { .sc-ring, .steer-cue.late .sc-ring { animation: none; } .steer-cue.nudge .sc-text { animation: none; } }

/* note on the first results screen */
.res-coach {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--r-md);
  background: rgba(255, 210, 63, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 210, 63, 0.45);
}
.res-coach b { font: 900 20px/1 var(--f-display); letter-spacing: 0.04em; text-transform: uppercase; color: var(--lemon); }
.res-coach p { margin: 0; font-size: 14px; line-height: 1.4; }

/* lobby tour: a spotlight (the hole's huge shadow dims everything else) and a bubble */
.coach { position: absolute; inset: 0; z-index: 55; pointer-events: auto; }
.coach-hole {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; border-radius: 18px; pointer-events: none;
  box-shadow: 0 0 0 2px var(--lemon), 0 0 0 9999px rgba(4, 14, 10, 0.66);
  transition: left 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.26s cubic-bezier(0.2, 0.8, 0.2, 1),
    width 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.coach-bubble {
  position: absolute; left: 14px; right: 14px; top: 50%; max-width: 420px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 12px; border-radius: var(--r-lg);
  background: var(--panel); box-shadow: 0 0 0 1px var(--line), 0 14px 40px rgba(0, 0, 0, 0.5);
  transition: top 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.coach.no-glide .coach-hole, .coach.no-glide .coach-bubble { transition: none; }
.coach-count { color: var(--muted); font: 700 12px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
.coach-title { margin: 0; font: 900 24px/1 var(--f-display); text-transform: uppercase; letter-spacing: 0.02em; }
.coach-text { margin: 0; font-size: 15px; line-height: 1.45; }
.coach-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.coach-actions .link-btn { padding: 0; }
.coach.final { background: rgba(4, 14, 10, 0.66); }
.coach.final .coach-hole { display: none; }
.coach.final .coach-bubble { top: 50% !important; transform: translateY(-50%); }
.coach.final .coach-title { font-size: 30px; }
.coach.final #coach-next { flex: 1; min-height: 48px; font-size: 17px; }
@media (prefers-reduced-motion: reduce) { .coach-hole, .coach-bubble { transition: none; } .coach-tip { animation: none; } }

/* full screen notes */
.settings-note { margin: -4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.settings-note b, .ios-hint b { color: var(--chalk); }
.ios-share {
  display: inline-block; width: 14px; height: 16px; vertical-align: -2px; margin: 0 2px;
  border: 2px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; position: relative;
}
.ios-share::before { content: ''; position: absolute; left: 50%; top: -7px; width: 2px; height: 11px; margin-left: -1px; background: currentColor; }

/* privacy */
.privacy-links { display: flex; flex-wrap: wrap; gap: 14px; }
.privacy-links .link-btn { padding: 0; }
.privacy-notice {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 45;
  display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--panel); box-shadow: 0 0 0 1px var(--line), 0 10px 30px rgba(0, 0, 0, 0.4);
  pointer-events: auto; animation: privacy-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
.privacy-notice p { margin: 0; font-size: 14px; line-height: 1.4; }
.privacy-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
@keyframes privacy-in { from { opacity: 0; transform: translateY(16px); } }
.hero-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-stat {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.18); color: var(--muted); font: 600 13px/1 var(--f-body);
}
.hero-stat b { color: var(--chalk); font: 800 15px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.surface-note { margin: -2px 0 10px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.car-tile.locked { opacity: 0.55; }
/* country flag in front of a track name */
.flag {
  display: inline-block; width: 1.4em; height: 0.93em; margin-right: 0.4em; vertical-align: -0.08em;
  border-radius: 2px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28); flex: none;
}
.flag svg { display: block; width: 100%; height: 100%; }
.tc-name .flag { width: 1.05em; height: 0.7em; vertical-align: 0.06em; }
.tour-tile.locked .flag { opacity: 0.6; }
.laps-chip {
  position: absolute; right: 10px; top: 10px; padding: 5px 9px; border-radius: 999px;
  background: rgba(10, 35, 27, 0.82); color: var(--chalk);
  font: 800 11px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase;
}
.laps-chip.multi { background: var(--lemon); color: #1d2433; }
.diff { display: inline-block; padding: 4px 8px; border-radius: 999px; font: 800 11px/1 var(--f-display); letter-spacing: 0.12em; text-transform: uppercase; }
.diff.easy { background: rgba(99, 230, 166, 0.2); color: var(--good); }
.diff.medium { background: rgba(255, 210, 63, 0.2); color: var(--lemon); }
.diff.hard { background: rgba(255, 138, 31, 0.22); color: #ffab5e; }
.diff.brutal { background: rgba(255, 125, 104, 0.22); color: var(--bad); }
.diff.done { background: var(--good); color: #062417; }

/* full-screen feed: one rival per screen, snapping vertical swipe */
.screen.feed { padding: 0; }
.feed-top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(12px, env(safe-area-inset-top, 0px)) var(--pad) 10px;
  background: linear-gradient(var(--panel) 60%, transparent);
}
.feed-count { font: 800 15px/1 var(--f-mono); color: var(--muted); }
.feed-list {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  scroll-snap-type: y mandatory; scrollbar-width: none;
}
.feed-list::-webkit-scrollbar { display: none; }
.feed-card {
  height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; gap: 12px;
  padding: calc(66px + env(safe-area-inset-top, 0px)) var(--pad) calc(16px + env(safe-area-inset-bottom, 0px));
}
.fc-track { position: relative; flex: 1; min-height: 120px; border-radius: var(--r-lg); overflow: hidden; }
.fc-track canvas { width: 100%; height: 100%; display: block; }
.fc-rival { display: flex; align-items: center; gap: 12px; }
.fc-rival .avatar { width: 54px; height: 54px; }
.fc-who { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fc-who b { font: 900 26px/1 var(--f-display); text-transform: uppercase; letter-spacing: 0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-who small { color: var(--muted); font: 600 13px/1.2 var(--f-mono); }
.fc-time { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.fc-time span { color: var(--muted); font: 700 13px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; }
.fc-time b { font: 800 46px/1 var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.fc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fc-beaten {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-md); background: rgba(99, 230, 166, 0.14);
  color: var(--good); font: 800 17px/1 var(--f-display); letter-spacing: 0.08em; text-transform: uppercase;
}
.fc-beaten b { font: 800 18px/1 var(--f-mono); }
.fc-actions { display: grid; gap: 10px; }
.fc-hint { margin: 0; text-align: center; color: var(--muted); font: 700 12px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase; }
.fc-hint::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-left: 2px solid currentColor; border-top: 2px solid currentColor; transform: translateY(2px) rotate(45deg); }

/* brag */
.brag-modal { text-align: center; }
.taunts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.taunt {
  min-height: 40px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--raised-2); color: var(--chalk);
  font: 700 15px/1 var(--f-body);
}
.taunt[aria-checked="true"] { background: var(--lemon); color: var(--lemon-ink); }
.brag-reply { padding: 12px 14px; border-radius: var(--r-md); background: var(--raised); text-align: left; }
.brag-from { color: var(--muted); font: 700 12px/1 var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; }
.brag-reply p { margin: 6px 0 0; font: 600 16px/1.35 var(--f-body); }

/* swipe-up cue on the results screen (feed) */
.swipe-cue {
  display: flex; flex-direction: column; align-items: center; gap: 2px; align-self: center;
  margin-top: 6px; padding: 8px 18px; border: 0; background: none; color: var(--chalk);
  font: 800 14px/1 var(--f-display); letter-spacing: 0.16em; text-transform: uppercase;
}
.swipe-cue svg { width: 30px; height: 30px; fill: none; stroke: var(--lemon); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; animation: cue 1.4s ease-in-out infinite; }
.swipe-cue svg + span { color: var(--muted); }
@keyframes cue { 0%, 100% { transform: translateY(4px); opacity: 0.6; } 50% { transform: translateY(-6px); opacity: 1; } }

/* in-game notification banner */
.notify {
  position: absolute; left: 12px; right: 12px; top: calc(10px + env(safe-area-inset-top, 0px)); z-index: 60;
  display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px;
  border: 0; border-radius: 16px; background: rgba(242, 240, 230, 0.97); color: var(--lemon-ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); text-align: left; pointer-events: auto;
  animation: notify-in 0.35s cubic-bezier(.2, .9, .3, 1.2);
  touch-action: none; transition: transform 0.18s ease, opacity 0.18s ease;
}
.notify .avatar { width: 42px; height: 42px; }
.notify-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.notify-body b { font: 800 15px/1 var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; }
.notify-body span { font: 600 14px/1.3 var(--f-body); overflow: hidden; text-overflow: ellipsis; }
@keyframes notify-in { from { transform: translateY(-140%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .swipe-cue svg, .notify { animation: none; } }

/* short phones: a denser results screen so it fits without scrolling */
@container ui (max-height: 740px) {
  #results { padding-top: 14px; padding-bottom: 14px; }
  .res-kicker { font-size: 15px; padding: 5px 10px; }
  .res-time { font-size: max(42px, 7.4cqh); }
  .res-medal.own .tier { width: 9cqh; height: 10.8cqh; }
  .res-medal { font-size: 16px; }
  .res-rows dt { font-size: 12px; }
  .res-rows dd { font-size: 16px; }
  .res-coins { padding: 7px 10px; gap: 4px 8px; }
  .res-coins b { font-size: 19px; }
  .res-coins small { font-size: 12px; }
  .res-unlocks { gap: 4px; }
  .res-actions .btn { font-size: 18px; }
  .res-actions .btn-row .btn { min-height: 40px; }
}

/* ---------------------------------------------------------- tour categories */
/* the category bar sticks under the main tabs while the Tour scrolls */
.cat-nav {
  position: sticky; top: 0; z-index: 4;
  margin: 0 calc(-1 * var(--pad)); padding: 2px var(--pad) 8px;
  background: linear-gradient(var(--panel) 82%, rgba(15, 51, 38, 0));
}
.cat-strip {
  display: flex; gap: 6px; overflow-x: auto; touch-action: pan-x; scrollbar-width: none;
  overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
}
.cat-strip::-webkit-scrollbar { display: none; }
.cat-chip {
  position: relative; flex: none; display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 13px; border: 0; border-radius: 999px; background: var(--raised); color: var(--muted);
  font: 800 13px/1 var(--f-display); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.cat-chip svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.cat-chip.locked { opacity: 0.75; }
.cat-chip.on { background: var(--chalk); color: var(--lemon-ink); opacity: 1; }
.cat-chip.has-new::after {
  content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--lemon); box-shadow: 0 0 0 2px var(--panel);
}
.cat-chip:active { transform: scale(0.95); }

.cat { display: flex; flex-direction: column; gap: 12px; }
.cat + .cat { margin-top: 6px; }
.cat-hero { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--r-lg); background: var(--raised); }
.cat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cat-top h3 { margin: 0; font: 900 24px/1 var(--f-display); letter-spacing: 0.02em; text-transform: uppercase; }
.cat-tally { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; background: rgba(0, 0, 0, 0.2); }
.cat-tally b { font: 700 13px/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.cat-hero > p { margin: 0; color: var(--muted); font-size: 13px; }
.cat-hero .chapter-lock { margin: 0; }
.cat-hero .rally-car { margin-top: 2px; padding: 8px 10px; cursor: pointer; }
.cat-hero .rally-car canvas { width: 76px; height: 52px; }
.cat-hero .rally-car b { font-size: 16px; }
.cat-change {
  margin-left: auto; flex: none; padding: 6px 10px; border-radius: 999px;
  background: rgba(255, 210, 63, 0.14); color: var(--lemon);
  font: 800 12px/1 var(--f-display); letter-spacing: 0.1em; text-transform: uppercase;
}
.cat-car:active { transform: scale(0.98); }
