/* Tokens (design handoff, Paddock) */
:root {
  --bg: #F2EFE8;
  --surface: #FFFFFF;
  --row-border: #E6E1D6;
  --line: #DFD9CC;
  --ink: #15151E;
  --muted: #6B6860;
  --nav-idle: #8B877D;
  --accent: #E10600;
  --danger: #C00500;
  --good: #1F7A45;
  --saved: #1F8A4C;
  --me-row: #FDE8E6;
  --track-base: #E4DED2;
  --stripe-shadow: inset 0 0 0 1px rgba(21, 21, 30, .2);
  --r-row: 8px;
  --r-input: 10px;
  --r-pill: 999px;
  --row-h: 42px;
  --row-gap: 4px;
  --display: 'Saira', sans-serif;
  --body: 'Titillium Web', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.4 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
input {
  height: 50px;
  width: 100%;
  border-radius: var(--r-input);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 16px;
  font: 600 17px var(--body);
  outline: none;
}
input:focus { border-color: var(--ink); }
input::placeholder { color: #8A8A96; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible { outline: none; }
::-webkit-scrollbar { display: none; }
.hdr-title, .wordmark, .sheet h2, .rule b, .cta, .hero-speed b {
  font-family: var(--display);
  font-stretch: 125%;
  font-weight: 800;
}
.label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.err { color: var(--danger); font-size: 14px; font-weight: 700; }

/* Chrome: header, screen, bottom nav */
#app {
  position: relative;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.hdr {
  flex: none;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.hdr-title { font-style: italic; font-size: 19px; text-transform: uppercase; }
.hdr-right { display: flex; align-items: center; gap: 2px; }
.hdr-meta { font-family: var(--mono); font-size: 12px; opacity: .85; margin-right: 6px; }
.icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.gear.on { background: rgba(128, 128, 128, .28); }
#screen { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.nav {
  flex: none;
  display: flex;
  height: calc(74px + max(14px, env(safe-area-inset-bottom)));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--nav-idle);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.nav i { width: 44px; height: 3px; }
.nav a.on { color: var(--ink); }
.nav a.on i { background: var(--accent); }
.bare .hdr, .bare .nav { display: none; }

/* Toast */
.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 92px;
  z-index: 30;
  height: 46px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

/* Rules sheet */
.dim {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 36px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-top { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { font-style: italic; font-size: 20px; text-transform: uppercase; }
.x { width: 44px; height: 44px; font-size: 26px; line-height: 1; color: var(--muted); }
.sheet-intro { font-size: 15px; line-height: 1.4; color: var(--muted); }
.sheet hr { width: 100%; height: 1px; margin: 0; border: 0; background: var(--line); }
.rule { display: flex; gap: 14px; align-items: baseline; font-size: 15px; line-height: 1.35; }
.rule b { width: 44px; flex: none; font-size: 22px; color: var(--good); }

/* Circuit outline (circuit.js); Predict overrides the widths and --dot-r for its small outline */
.trk-base, .trk-prev, .trk-lit { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trk-base { stroke: var(--track-base); stroke-width: 7; }
.trk-prev, .trk-lit { stroke: var(--accent); stroke-width: 3.5; }
.trk-prev { opacity: 0; }
.trk-lit { stroke-dasharray: 0 2000; }
.trk-dot { fill: var(--ink); filter: drop-shadow(0 0 6px var(--accent)); }

/* Landing */
.landing { flex: 1; display: flex; flex-direction: column; }
.hero { position: relative; background: var(--surface); padding: 16px 18px 18px; }
.hero-top { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; letter-spacing: .06em; opacity: .8; }
.hero svg { display: block; width: 100%; height: auto; margin-top: 6px; }
.hero-speed { position: absolute; left: 18px; bottom: 16px; display: flex; align-items: baseline; gap: 6px; }
.hero-speed b { font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-speed span { font-family: var(--mono); font-size: 11px; opacity: .7; }
.landing-body { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 22px 20px 28px; }
.wordmark { font-style: italic; font-size: 34px; line-height: 1; text-transform: uppercase; letter-spacing: -.01em; }
.tagline { color: var(--muted); font-size: 16px; margin-top: 6px; }
.step, .stack { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.grow { flex: 1; }
.seg { display: flex; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill); }
.seg button {
  flex: 1;
  height: 38px;
  border-radius: var(--r-pill);
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.seg button.on { background: var(--ink); color: #FFFFFF; }
.cars { display: flex; flex-direction: column; gap: 8px; }
.car-scroll { display: flex; gap: 8px; overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.car {
  flex: none;
  width: 112px;
  height: 76px;
  border-radius: var(--r-input);
  background: var(--surface);
  border: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.car.on { border-color: var(--accent); }
.car img { width: 96px; height: 30px; object-fit: contain; display: block; }
.car span { font-size: 12px; font-weight: 700; color: var(--muted); }
.cta {
  flex: none;
  height: 54px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: #FFFFFF;
  font-size: 17px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cta:disabled { opacity: .6; }
.note { color: var(--muted); font-size: 13px; text-align: center; }
.sent { font-size: 16px; }
.code { height: 56px; font: 700 26px var(--mono); letter-spacing: .3em; text-align: center; }
.again { align-self: center; min-height: 40px; padding: 0 12px; color: var(--accent); font-weight: 700; font-size: 15px; }
.again:disabled { color: var(--muted); }

/* Account (phase 3, Task 3) */
.account { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.value { font-size: 17px; font-weight: 700; }
.hint { color: var(--muted); font-size: 14px; }
.account input { font-weight: 700; }
.account input.bad { border-color: var(--danger); }
.car-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.car-grid .car { position: relative; width: auto; height: 74px; }
.car-grid .car i { position: absolute; left: 10px; top: 10px; width: 4px; height: 14px; transform: skewX(-14deg); box-shadow: var(--stripe-shadow); }
.car-grid .car img { width: 130px; height: 32px; }
.car-grid .car span { font-size: 13px; }
.btn-line, .btn-del { flex: none; height: 50px; border-radius: var(--r-pill); border: 1px solid var(--ink); font-weight: 700; font-size: 15px; }
.btn-del { border-color: var(--danger); color: var(--danger); }
.btn-del.armed { background: var(--accent); color: #FFFFFF; }
.btn-line:disabled, .btn-del:disabled { opacity: .6; }

/* Predict (Task 8) */
.predict { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.race {
  flex: none;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.race-trk { flex: none; width: 112px; }
.race-trk svg { display: block; width: 112px; height: auto; overflow: visible; --dot-r: 11; }
.race-trk .trk-base { stroke-width: 13; }
.race-trk .trk-prev, .race-trk .trk-lit { stroke-width: 7; }
.race-info { flex: 1; min-width: 0; }
.race-name { font: italic 800 16px/1.1 var(--display); font-stretch: 125%; text-transform: uppercase; }
.race-sub { font-size: 14px; color: var(--muted); }
.race-clock { margin-top: 2px; font: 700 20px var(--mono); color: var(--accent); font-variant-numeric: tabular-nums; }
.plist {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  -webkit-user-select: none;
  user-select: none;
}
.predict .row {
  flex: none;
  position: relative;
  height: var(--row-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 12px;
  border-radius: var(--r-row);
  background: var(--surface);
  border: 1px solid var(--row-border);
}
.predict .pos { flex: none; width: 40px; text-align: right; font: 800 20px var(--display); font-stretch: 125%; font-variant-numeric: tabular-nums; }
.predict .out { opacity: .6; }
.predict .out .pos { font-size: 13px; }
.predict .stripe { flex: none; width: 5px; height: 24px; transform: skewX(-14deg); box-shadow: var(--stripe-shadow); }
.predict .tla { flex: none; font: 800 21px var(--display); font-stretch: 125%; letter-spacing: .01em; }
.predict .sub { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.predict .team { flex: none; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.grip {
  flex: none;
  width: 48px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  touch-action: none;
  cursor: grab;
}
.grip i { width: 18px; height: 2px; background: var(--muted); }
.predict .dnf { gap: 10px; padding-left: 16px; border: 0; border-radius: 0; background: var(--bg); }
.dnf .line { flex: 1; height: 2px; background: var(--accent); }
.dnf b { font: 700 12px var(--mono); letter-spacing: .08em; color: var(--danger); }
.dnf .grip i { background: var(--accent); }
.locked .grip { visibility: hidden; touch-action: auto; }
.savebar { flex: none; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line); }
.save { width: 100%; height: 52px; font-size: 16px; }
.save.saved { background: var(--saved); }
.save.closed { background: var(--muted); opacity: 1; }

/* Standings and Leagues (phase 2, Task 7). .chipbar, .chips, .chip and .empty are shared: History uses them too. */
.standings { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chipbar { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px; align-items: center; }
.chip {
  flex: none;
  height: 36px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.empty { padding: 16px; color: var(--muted); font-size: 15px; }
.empty.err { color: var(--danger); }
.cols { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 16px 6px 12px; font: 11px var(--mono); letter-spacing: .08em; color: var(--muted); }
.c-pos { width: 40px; text-align: right; }
.c-name { flex: 1; padding-left: 17px; }
.slist { flex: 1; min-height: 0; overflow: auto; padding: 0 10px 8px; display: flex; flex-direction: column; gap: var(--row-gap); }
.srow {
  flex: none;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 12px;
  border-radius: var(--r-row);
  background: var(--surface);
  border: 1px solid var(--row-border);
}
.srow.me { background: var(--me-row); }
.srow .pos { flex: none; width: 40px; text-align: right; font: 800 20px var(--display); font-stretch: 125%; }
.srow .stripe { flex: none; width: 5px; height: 26px; transform: skewX(-14deg); box-shadow: var(--stripe-shadow); }
.carimg { flex: none; width: 64px; height: 24px; object-fit: contain; display: block; }
.srow .name { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow .pts { flex: none; font: 700 16px var(--mono); }
.srow.me .pts { color: var(--accent); }
.leagues { flex: 1; display: flex; flex-direction: column; gap: 16px; padding: 16px; }
.create { display: flex; gap: 8px; }
.create input { flex: 1; min-width: 0; padding: 0 14px; font-size: 16px; }
.pill {
  flex: none;
  height: 50px;
  padding: 0 18px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: #FFFFFF;
  font: 800 14px var(--display);
  font-stretch: 125%;
  text-transform: uppercase;
}
.pill.full { background: var(--muted); }
.pill:disabled { opacity: .6; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.league {
  padding: 14px 14px 14px 16px;
  border-radius: var(--r-row);
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.league-main { flex: 1; min-width: 0; }
.league-name { font: 800 17px var(--display); font-stretch: 125%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.league-meta { font-size: 14px; color: var(--muted); }
.btn-sm { flex: none; height: 40px; padding: 0 12px; border-radius: var(--r-pill); border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.btn-sm.danger { border-color: var(--danger); color: var(--danger); }
.btn-sm:disabled { opacity: .6; }
.league-url { flex-basis: 100%; font-size: 14px; overflow-wrap: anywhere; -webkit-user-select: all; user-select: all; }
.foot { font-size: 14px; color: var(--muted); }
.sheet-acts { display: flex; justify-content: flex-end; gap: 8px; }

/* History (phase 2, Task 8) */
.history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.vs { flex: none; font: 11px var(--mono); letter-spacing: .08em; color: var(--muted); }
.hgrid { display: grid; grid-template-columns: 30px repeat(3, minmax(0, 1fr)); gap: 4px; align-items: center; }
.history.two .hgrid { grid-template-columns: 30px repeat(2, minmax(0, 1fr)); }
.hhead { flex: none; padding: 10px 8px 6px; font: 11px var(--mono); letter-spacing: .06em; color: var(--muted); }
.hhead > div { padding-left: 6px; }
.ht { min-width: 0; display: flex; justify-content: space-between; gap: 4px; }
.ht span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: uppercase; }
.ht b { flex: none; color: var(--good); font-weight: 700; }
.hist-list { flex: 1; min-height: 0; overflow: auto; padding: 0 8px 8px; }
.hrows { display: flex; flex-direction: column; gap: var(--row-gap); }
.hrow { flex: none; height: 36px; border-radius: var(--r-row); background: var(--surface); }
.hpos { text-align: right; font: 800 16px var(--display); font-stretch: 125%; font-variant-numeric: tabular-nums; }
.hpos.dnf { font-size: 11px; }
.hc { min-width: 0; height: 100%; display: flex; align-items: center; gap: 6px; padding: 0 6px; border-radius: var(--r-row); }
.hc.out { background: var(--line); }
.hc .stripe { flex: none; width: 4px; height: 18px; transform: skewX(-14deg); box-shadow: var(--stripe-shadow); }
.hc b { flex: 1; min-width: 0; font: 800 15px var(--display); font-stretch: 125%; }
.hc span { flex: none; font: 700 12px var(--mono); }
.hc .good { color: var(--good); }
.hc .zero { color: var(--muted); }
.history .foot { font-size: 13px; padding: 10px 8px 0; }

/* Sideways rows with a mouse (phase 4, Task 1) */
@media (hover: hover) and (pointer: fine) {
  .car-scroll { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); overflow-x: visible; margin: 0; padding: 0; }
  .car-scroll .car { width: auto; }
  .chips { flex-wrap: wrap; overflow-x: visible; }
}
