/* Rolling Rally — page styles. Phone first (390 x 844), calm contrast, big targets. */
:root {
  --ink: #2a2230;
  --cream: #fff7e8;
  --paper: #fffdf6;
  --teal: #3ec9d6;
  --teal-d: #1c8e99;
  --coral: #ff6b57;
  --gold: #ffd23f;
  --dusk: #2b2d6e;
  --plum: #4b3f66;
  --hud: rgba(30, 24, 48, 0.78);
  --font-d: 'Fredoka', 'Atkinson Hyperlegible', system-ui, sans-serif;
  --font-b: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --big: 1;
}
body.large-hud { --big: 1.3; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--dusk); color: var(--cream); font-family: var(--font-b); font-size: 100%; line-height: 1.45; overflow: hidden; -webkit-text-size-adjust: 100%; }
html { touch-action: manipulation; }
body { overscroll-behavior: none; touch-action: manipulation; }
/* Racing: no pinch, no double-tap zoom, no text-selection loupe or callout anywhere on the road screen (it is a game surface, not a page). */
body.racing, body.racing #stage, body.racing #hud, body.racing #hud *, body.racing .overlay, body.racing .overlay * { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: var(--dusk); }

:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; border-radius: 12px; }
[tabindex='-1']:focus { outline: none; }   /* headings we move focus to for screen readers */

/* ----------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  padding: max(64px, calc(env(safe-area-inset-top) + 56px)) 16px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(rgba(24, 20, 52, 0.55), rgba(24, 20, 52, 0.86)); }
.screen[hidden] { display: none; }
#sLoad { align-items: center; background: var(--dusk); }
.panel { width: 100%; max-width: 440px; margin: 0 auto; }
.panel.wide { max-width: 560px; }
.panel.menu { text-align: center; }
.loadbox { width: 100%; max-width: 360px; text-align: center; }
.bar-track { height: 14px; border-radius: 99px; background: rgba(255, 255, 255, 0.18); overflow: hidden; margin: 18px 0 8px; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--gold)); border-radius: 99px; transition: width 0.2s; }

.logo { font-family: var(--font-d); font-weight: 700; font-size: clamp(2.6rem, 14vw, 4.2rem); line-height: 0.95; margin: 6px 0 4px; letter-spacing: 0.01em; display: flex; flex-direction: column; align-items: center; text-shadow: 0 4px 0 var(--ink), 0 8px 18px rgba(0, 0, 0, 0.35); }
.logo span:first-child { color: var(--gold); }
.logo span:last-child { color: var(--teal); -webkit-text-stroke: 0; }
.tag { margin: 8px 0 18px; font-size: 1.05rem; color: #e9e4f6; }
.lede { margin: 6px 0 14px; color: #efeaf8; }
.note { margin: 10px 0; font-size: 0.95rem; color: #e1dcf0; }
.hint { margin: 6px 0 0; font-size: 0.9rem; color: #d9d3ea; }
.error { margin: 10px 0; padding: 10px 14px; border-radius: 14px; background: #ffe3dc; color: #7a1d0c; font-weight: 700; }
.mission { margin: 22px 0 6px; font-size: 0.82rem; color: #d3cde6; }
.mission a { color: var(--gold); }

.faces { display: flex; justify-content: center; gap: 4px; margin: 4px 0 6px; }
.faces canvas { width: 80px; height: auto; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.25)); }
.faces canvas:nth-child(odd) { transform: translateY(6px); }

h2, h3 { font-family: var(--font-d); margin: 0; }
h2 { font-size: 1.6rem; }
h2.sub, h3.sub { font-size: 1.2rem; margin: 20px 0 8px; color: var(--gold); }
.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bar h2 { margin: 0; }

/* ----------------------------------------------------------- buttons */
.btn { appearance: none; font: 600 1.1rem/1.1 var(--font-d); min-height: 56px; padding: 0 22px; border-radius: 18px; border: 3px solid var(--ink);
  background: var(--cream); color: var(--ink); cursor: pointer; box-shadow: 0 5px 0 var(--ink); text-align: center; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn.primary { background: var(--teal); }
.btn.big { min-height: 64px; font-size: 1.28rem; }
.btn.small { min-height: 46px; padding: 0 16px; font-size: 1rem; border-radius: 14px; box-shadow: 0 4px 0 var(--ink); }
.btn.ghost { background: transparent; color: var(--cream); border-color: rgba(255, 247, 232, 0.7); box-shadow: none; }
.btn.wide-btn { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.menu-btns { display: flex; flex-direction: column; gap: 14px; margin: 8px auto; max-width: 340px; }
.menu-btns .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.menu-btns .pair .btn { padding: 0 10px; }
.cup-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding-top: 8px; padding-bottom: 8px; background: var(--gold); }
.cup-btn small { font: 600 0.84rem/1.15 var(--font-b); }

/* -------------------------------------------------------- pick screen */
.riders { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.rider { position: relative; appearance: none; text-align: center; padding: 10px 8px 12px; border-radius: 22px; border: 4px solid transparent; background: var(--cream); color: var(--ink); cursor: pointer;
  font-family: var(--font-d); box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); }
.rider canvas { width: 88%; max-width: 170px; height: auto; display: block; margin: 0 auto 4px; }
.rider b { display: block; font-size: 1.02rem; line-height: 1.15; }
.rider[aria-checked='true'] { border-color: var(--gold); background: #fff2c2; box-shadow: 0 0 0 3px var(--ink), 0 6px 0 rgba(0, 0, 0, 0.35); transform: translateY(-2px); }
.rider[aria-checked='true']::after { content: '✓'; position: absolute; top: 6px; right: 10px; font-size: 1.3rem; color: var(--ink); }
.rider[aria-disabled='true'] { opacity: 0.45; cursor: default; }

.rider-info { margin: 14px 0 4px; padding: 14px 16px; border-radius: 20px; background: var(--hud); }
.rider-info h3 { font-size: 1.25rem; color: var(--gold); }
.rider-info .says { margin: 2px 0 8px; font-style: italic; color: #fff; }
.rider-info p { margin: 8px 0 0; font-size: 0.95rem; color: #e9e4f6; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; margin: 8px 0 0; }
.stats dt { font-weight: 700; font-size: 0.95rem; }
.stats dd { margin: 0; }
.pips { display: inline-flex; gap: 4px; }
.pip { width: 22px; height: 12px; border-radius: 99px; background: rgba(255, 255, 255, 0.22); position: relative; overflow: hidden; }
.pip i { position: absolute; inset: 0 auto 0 0; background: var(--gold); border-radius: 99px; }

.tracks { display: grid; gap: 10px; }
.track { position: relative; appearance: none; width: 100%; text-align: left; display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: stretch; padding: 8px; border-radius: 20px; border: 4px solid transparent;
  background: var(--cream); color: var(--ink); cursor: pointer; font-family: var(--font-b); box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); }
.track .thumb-art { border-radius: 14px; min-height: 84px; background-size: auto 150%; background-position: 20% 100%; border: 3px solid var(--ink); background-color: #bfe3ee; }
.track b { display: block; font: 700 1.1rem/1.15 var(--font-d); }
.track small { display: block; margin-top: 2px; font-size: 0.88rem; color: #4a4258; }
.track .dots { font-size: 0.85rem; letter-spacing: 2px; color: var(--coral); }
.track[aria-checked='true'] { border-color: var(--gold); background: #fff2c2; box-shadow: 0 0 0 3px var(--ink), 0 6px 0 rgba(0, 0, 0, 0.35); }
.track .best-t { display: block; margin-top: 2px; font-weight: 700; font-size: 0.85rem; color: var(--teal-d); }
/* your best finish on a track (or overall in a cup): the rosette sits in the card's corner */
.track .rosette { position: absolute; top: -8px; right: -6px; width: 44px; height: 44px; display: grid; place-items: center; font: 700 0.9rem var(--font-d); }
.track .rosette canvas { width: 44px; height: auto; display: block; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35)); }
.track.cup { grid-template-columns: 1fr; }
.cup-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cup-strip .thumb-art { min-height: 66px; border-width: 2px; border-radius: 10px; }
.track .cup-blurb { color: #5b5370; font-style: italic; }
.cup-table .tm { font-variant-numeric: tabular-nums; }

.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0 0; flex-wrap: wrap; }
.opt-label { font: 600 1.05rem var(--font-d); display: block; }
.opt-label small { font: 400 0.85rem var(--font-b); color: #d9d3ea; }
.seg { display: inline-flex; gap: 6px; background: rgba(255, 255, 255, 0.12); padding: 5px; border-radius: 18px; flex-wrap: wrap; }
.seg.five { display: flex; }
.seg.five .seg-b { flex: 1 1 0; padding: 0 6px; }
.seg-b { appearance: none; min-height: 48px; min-width: 54px; padding: 0 14px; border-radius: 14px; border: 3px solid transparent; background: transparent; color: var(--cream); font: 600 1rem var(--font-d); cursor: pointer; }
.seg-b[aria-checked='true'] { background: var(--cream); color: var(--ink); border-color: var(--ink); }
.seg-b:disabled { opacity: 0.5; }
/* six tracks in a room's picker: three to a row, so every name fits at phone width */
.seg.six { display: grid; grid-template-columns: repeat(3, 1fr); }
.seg.six .seg-b { min-width: 0; padding: 0 4px; font-size: 0.95rem; }
.set-group { margin: 18px 0; }
.set-group .seg { margin-top: 8px; }

.switch { display: flex; align-items: center; gap: 12px; min-height: 52px; margin: 6px 0; font-size: 1.02rem; cursor: pointer; }
.switch input { width: 28px; height: 28px; accent-color: var(--teal); flex: none; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font: 600 1rem var(--font-d); margin-bottom: 6px; }
.field input[type='text'] { width: 100%; min-height: 56px; padding: 0 16px; border-radius: 16px; border: 3px solid var(--ink); background: var(--paper); color: var(--ink); font: 600 1.25rem var(--font-d); letter-spacing: 0.05em; }
#codeIn { text-transform: uppercase; text-align: center; letter-spacing: 0.3em; }
.field input[type='range'] { width: 100%; height: 40px; accent-color: var(--teal); }
.grow { flex: 1; margin: 0; }
.join-row { display: flex; gap: 10px; align-items: flex-end; }
.join-row .btn { margin-bottom: 0; }
.or { text-align: center; margin: 18px 0 8px; position: relative; color: #d9d3ea; }
.or::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px solid rgba(255, 255, 255, 0.2); }
.or span { position: relative; padding: 0 12px; background: transparent; }

/* ----------------------------------------------------------- the lobby */
.code-card { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 20px; background: var(--hud); margin-bottom: 14px; flex-wrap: wrap; }
.code-label { font: 600 0.95rem var(--font-d); color: #d9d3ea; }
.code { font: 700 2rem var(--font-d); letter-spacing: 0.25em; color: var(--gold); flex: 1; text-align: center; }
.seats { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.seat { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 18px; background: var(--hud); }
.seat canvas { width: 54px; height: auto; }
.seat.empty { opacity: 0.55; background: rgba(255, 255, 255, 0.08); }
.seat.me { outline: 3px solid var(--gold); }
.seat b { display: block; font: 600 1.05rem var(--font-d); }
.seat small { color: #d9d3ea; }
.seat .state { font: 700 0.9rem var(--font-d); padding: 4px 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.16); }
.seat .state.ok { background: #4fd05a; color: var(--ink); }
.mini-riders { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini { position: relative; appearance: none; padding: 6px 4px 8px; border-radius: 16px; border: 4px solid transparent; background: var(--cream); color: var(--ink); cursor: pointer; font: 600 0.85rem var(--font-d); text-align: center; }
.mini canvas { width: 100%; height: auto; display: block; }
.mini[aria-checked='true'] { border-color: var(--gold); background: #fff2c2; }
.mini[aria-disabled='true'] { opacity: 0.4; cursor: default; }
.host-box { margin-top: 6px; }
.lobby-actions { display: flex; gap: 12px; margin: 18px 0 6px; flex-wrap: wrap; }
.lobby-actions .btn { flex: 1 1 150px; }

.podium { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 10px; }
.podium li { display: grid; grid-template-columns: 44px 56px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 18px; background: var(--hud); }
.podium li.me { outline: 3px solid var(--gold); }
.podium .pl { position: relative; display: grid; place-items: center; width: 44px; height: 44px; font: 700 1.5rem var(--font-d); color: var(--gold); text-align: center; }
.podium .pl canvas { position: absolute; inset: 0; width: 44px; height: 44px; }
/* the number sits on the rosette's centre, outlined so it reads on any colour */
.podium .pl b { position: relative; top: -3px; font: 700 1.05rem/1 var(--font-d); color: var(--ink); -webkit-text-stroke: 3px #fff; paint-order: stroke fill; }
.podium canvas { width: 56px; height: auto; }
.podium b { display: block; font: 600 1.05rem/1.15 var(--font-d); }
.podium small { color: #d9d3ea; }
.podium .tm { font: 700 1.05rem var(--font-d); font-variant-numeric: tabular-nums; }
.res-title { font-size: 2rem; color: var(--gold); text-shadow: 0 3px 0 var(--ink); }
.res-badge { display: flex; justify-content: center; margin: 4px 0 -2px; }
.res-badge canvas { width: 104px; height: 104px; filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.3)); }
.res-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ----------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud > * { pointer-events: none; }
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(120px, calc(env(safe-area-inset-left) + 120px)); right: max(10px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.chip { background: var(--hud); color: var(--cream); border-radius: 18px; padding: 6px 14px; font-family: var(--font-d); display: inline-flex; align-items: baseline; gap: 6px; border: 3px solid var(--ink); }
.chip.place b { font-size: calc(1.9rem * var(--big)); line-height: 1; color: var(--gold); }
.chip.place small { font-size: calc(0.95rem * var(--big)); white-space: nowrap; }
.chip { white-space: nowrap; }
.chip.lap { font-size: calc(1.15rem * var(--big)); font-weight: 600; min-height: 44px; align-items: center; }
.icon-btn { pointer-events: auto; appearance: none; width: calc(48px * var(--big)); height: calc(48px * var(--big)); border-radius: 16px; border: 3px solid var(--ink); background: var(--cream); color: var(--ink); font: 700 1.2rem var(--font-d); cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
.progress { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 64px * var(--big)); left: 18px; right: 18px; height: 22px; }
.progress-line { position: absolute; left: 0; right: 0; top: 9px; height: 5px; border-radius: 4px; background: rgba(255, 255, 255, 0.45); box-shadow: 0 0 0 2px rgba(30, 24, 48, 0.5); }
.dot { position: absolute; top: 2px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; border: 3px solid var(--ink); transition: left 0.3s linear; }
.dot.me { top: -1px; width: 24px; height: 24px; margin-left: -12px; box-shadow: 0 0 0 3px var(--cream); z-index: 2; }
.count { position: absolute; left: 0; right: 0; top: 24%; text-align: center; font: 700 calc(7rem * var(--big)) var(--font-d); color: var(--gold); text-shadow: 0 6px 0 var(--ink), 0 0 30px rgba(0, 0, 0, 0.4); }
.count.go { color: #6dff9b; }
.finish-banner { position: absolute; left: 12px; right: 12px; top: 22%; text-align: center; padding: 14px 16px; border-radius: 22px; background: var(--hud); border: 3px solid var(--ink); font: 700 calc(1.6rem * var(--big)) var(--font-d); color: var(--gold); }
.finish-banner small { display: block; font: 400 1rem var(--font-b); color: var(--cream); margin-top: 4px; }

.controls { position: absolute; left: 0; right: 0; bottom: 0; height: 46%; }
.steer-zone { position: absolute; inset: 0; pointer-events: auto; touch-action: none; display: flex; align-items: flex-end; justify-content: flex-start; padding: 0 0 max(16px, env(safe-area-inset-bottom)) 18px; }
.steer-hint { background: var(--hud); border-radius: 99px; padding: 8px 16px; font: 600 0.95rem var(--font-d); transition: opacity 0.6s; margin-bottom: 8px; }
.steer-hint.fade { opacity: 0; }
.thumb { position: absolute; width: 74px; height: 74px; margin: -37px 0 0 -37px; border-radius: 50%; border: 4px solid rgba(255, 247, 232, 0.9); background: rgba(255, 247, 232, 0.22); pointer-events: none; }
.btn-steer { position: absolute; inset: auto 0 max(16px, env(safe-area-inset-bottom)) 0; display: flex; justify-content: space-between; padding: 0 14px; pointer-events: none; }
.steer-btn { pointer-events: auto; width: 31%; height: calc(86px * var(--big)); border-radius: 26px; border: 4px solid var(--ink); background: rgba(255, 247, 232, 0.82); color: var(--ink); font: 700 2.2rem var(--font-d); box-shadow: 0 5px 0 var(--ink); touch-action: none; }
.steer-btn.on { background: var(--gold); }
.use-item { pointer-events: auto; position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 8px); width: calc(104px * var(--big)); min-height: calc(104px * var(--big)); border-radius: 30px; border: 4px solid var(--ink); background: rgba(255, 247, 232, 0.9); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px; cursor: pointer; box-shadow: 0 6px 0 var(--ink); font-family: var(--font-d); touch-action: manipulation; }
.use-item:disabled { opacity: 0.62; box-shadow: 0 3px 0 var(--ink); }
.use-item:not(:disabled) { background: var(--gold); animation: ready 1.1s ease-in-out infinite; }
.btn-steer:not([hidden]) ~ .use-item { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 100px * var(--big)); }
.ui-icon canvas { width: calc(54px * var(--big)); height: calc(54px * var(--big)); display: block; }
.ui-name { font-size: calc(0.8rem * var(--big)); font-weight: 700; line-height: 1.05; text-align: center; }
/* "Use them for me": the button still works, and a small tag says the kart is choosing the moment */
.use-item.auto::after { content: 'Auto'; position: absolute; top: -12px; left: 50%; transform: translateX(-50%); padding: 1px 8px; border-radius: 99px; background: var(--ink); color: var(--cream); font: 700 0.72rem/1.4 var(--font-d); }
/* a glowing ring, not a moving button: the target stays put for shaky thumbs */
@keyframes ready { 50% { box-shadow: 0 6px 0 var(--ink), 0 0 0 10px rgba(255, 210, 63, 0.45); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 100px * var(--big)); z-index: 40; max-width: calc(100% - 28px); padding: 10px 18px; border-radius: 99px; background: var(--cream); color: var(--ink); font: 600 1rem var(--font-d); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); text-align: center; pointer-events: none; }

.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(24, 20, 52, 0.82); }
.overlay .panel { text-align: center; }

/* The Map link only belongs on the menus; mid-race it is easy to tap by accident. */
body.racing > a[aria-label^='Back to Sterling'] { display: none !important; }

/* ------------------------------------------------------------ motion */
.reduced .use-item:not(:disabled) { animation: none; }
.reduced .bar-fill, .reduced .dot, .reduced .steer-hint { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .use-item:not(:disabled) { animation: none; }
  .bar-fill, .dot, .steer-hint { transition: none; }
}

@media (min-width: 900px) {
  /* on a wide screen, keep the race controls in a comfortable column in the middle */
  .hud-top { left: 50%; right: auto; width: min(560px, 100%); transform: translateX(-50%); }
  .progress { left: calc(50% - 270px); right: calc(50% - 270px); }
  .use-item { right: calc(50% - 290px); }
  .steer-zone { padding-left: calc(50% - 280px); }
}
@media (min-width: 700px) {
  .riders { grid-template-columns: repeat(4, 1fr); }
  .tracks { grid-template-columns: 1fr; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .controls { height: 62%; }
  .count { top: 14%; font-size: calc(4.5rem * var(--big)); }
  .use-item { width: calc(86px * var(--big)); min-height: calc(86px * var(--big)); }
}
