/* ==========================================================================
   Simmy Lunatics league app: stylesheet (phone first, black / red / white)
   Load order: tokens.css, app.css, screens.css. Plain CSS, no build step.
   Rules live in brand/BRAND.md; the reasoning lives in design/DESIGN-NOTES.md.

   - Red is the single accent: primary button, active tab, leader marker, the
     streak. Small red text uses --accent-text (the plain red fails AA on black).
   - Two devices only: the streak (red parallelogram) and the chequer edge.
     Both are cut at --skew, the angle of the italic display type.
   - 4px radius on controls, 6px on cards. Borders, not shadows. No pills.
   - Display: Barlow Condensed italic, uppercase for short headings.
     Body and interface: Barlow. Numbers tabular.

   Contents
    1. Fonts
    2. Base and typography
    3. Utilities
    4. App shell (opening strip, header, main, footer, tab bar)
    5. Buttons and links
    6. Tags, swatch
    7. Home crest, join crest, next-race hero, RSVP
    8. Entry list, race list
    9. Standings tower, rounds table
   10. Racer profile, stat grid
   11. Result rows
   12. Forms, result-entry row
   13. Admin rows, disclosure
   14. Alerts, empty state, segmented control, skeleton
   15. Rendered Markdown (.prose)
   ========================================================================== */

/* 1. Fonts --------------------------------------------------------------- */
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/barlow-condensed-latin-800-italic.woff2") format("woff2"); font-weight: 800; font-style: italic; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/barlow-condensed-latin-700-italic.woff2") format("woff2"); font-weight: 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("../assets/fonts/barlow-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("../assets/fonts/barlow-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("../assets/fonts/barlow-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
/* RautingTech lockup only (the "Powered by" credit) */
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("../assets/fonts/atkinson-hyperlegible-next-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("../assets/fonts/atkinson-hyperlegible-next-latin-800-normal.woff2") format("woff2"); font-weight: 800; font-style: normal; font-display: swap; }

/* 2. Base and typography ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: dark;
  background: var(--surface);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: 400;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
#root { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; }
h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  line-height: var(--lh-tight);
  letter-spacing: 0.005em;
  text-wrap: balance;
}
h3, h4 { font-weight: 700; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-lede); }
p { margin: 0; }
p + p { margin-top: var(--space-3); }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-5) 0; }
small, .small { font-size: var(--fs-small); }
strong, b { font-weight: 700; }
::selection { background: var(--red); color: var(--white); }

.lede { font-size: var(--fs-lede); line-height: 1.45; color: var(--text-2); }
/* Caption: condensed capitals, the small voice of the interface */
.caption {
  font-family: var(--font-display);
  font-size: var(--fs-caption);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--text-muted);
}
.muted { color: var(--text-muted); }
.text-2 { color: var(--text-2); }
.num { font-family: var(--font-sans); font-weight: 500; font-variant-numeric: tabular-nums; }
code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.05em 0.4em;
}

/* Visible focus everywhere: white ring, 2px, offset. */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: var(--r);
}

/* 3. Utilities ----------------------------------------------------------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-3); top: -100px; z-index: 100;
  background: var(--white); color: var(--black);
  font-family: var(--font-sans); font-weight: 700;
  padding: var(--space-2) var(--space-4); border-radius: var(--r);
}
.skip-link:focus { top: var(--space-3); }
.stack > * + * { margin-top: var(--space-4); }
.stack--lg > * + * { margin-top: var(--space-6); }
.stack--sm > * + * { margin-top: var(--space-2); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.cluster--between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
[hidden] { display: none !important; }

/* 4. App shell ----------------------------------------------------------- */
/* <body> [.opening-strip] <div id="root"> <div .app> header, main, footer, nav.tabbar */
.app {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Opening strip: "Powered by RautingTech", in flow at the very top for about
   three seconds on the first open of a browser session. It fades, then its
   height collapses smoothly, then lib/opening-strip.js removes it. */
.opening-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--strip-h);
  flex: none;
  overflow: hidden;
  background: #000;
  border-bottom: 1px solid var(--line);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1;
  transition: opacity .4s ease, height .3s ease .4s, border-bottom-width .3s ease .4s;
}
.opening-strip.is-leaving { opacity: 0; height: 0; border-bottom-width: 0; }
.opening-strip .rt-logo { font-size: 13px; }
.opening-strip .rt-logo::after { inset: -8px -4px; }

/* Header: round logo + league name (from the API) on the left, the chequer tail on the right. */
.app-header {
  position: relative;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-2) 0 var(--space-2) var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 64px;
  overflow: hidden;
}
.app-league {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0.01em;
}
.app-league:hover .app-league__name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; text-decoration-color: var(--red); }
.app-league__logo { width: 40px; height: 40px; flex: none; display: block; border-radius: 50%; }
.app-league__name { min-width: 0; }
/* The chequer tail: two rows of checks cut on the slant, fading in from the left. Decorative. */
.app-header__checks {
  flex: none;
  width: 112px;
  height: 20px;
  margin-right: -14px;
  transform: skewX(var(--skew));
  background: repeating-conic-gradient(var(--white) 0 25%, #1c1c1c 0 50%) 0 0 / 20px 20px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 75%);
  mask-image: linear-gradient(90deg, transparent, #000 75%);
}

/* RautingTech lockup (see brand/rautingtech-lockup.md). Set font-size on .rt-logo to scale. */
.rt-logo {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--font-lockup);
  font-size: 15px;
  line-height: 1;
  color: var(--text);
  text-decoration: none;
}
.rt-logo::after { content: ""; position: absolute; inset: -14px -6px; }   /* 44px hit area */
.rt-logo svg { height: 1.15em; width: auto; flex: none; display: block; }
.rt-logo .wm { font-weight: 400; letter-spacing: -0.01em; }
.rt-logo .wm b { font-weight: 800; }
.rt-logo:hover .wm { text-decoration: underline; text-underline-offset: 3px; }

/* Main column */
.app-main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
.app-main > * + * { margin-top: var(--space-6); }
.app-main > .section + .section { margin-top: var(--space-6); }

/* Page head: caption, h1, optional lede */
.page-head > * + * { margin-top: var(--space-2); }
.page-head .lede { margin-top: var(--space-3); }

/* Section: h2 with optional trailing action */
.section > * + * { margin-top: var(--space-3); }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-2);
}
.section__head h2 { font-size: var(--fs-h3); font-weight: 700; }
.section__head a, .section__head .link-quiet { position: relative; font-family: var(--font-sans); font-size: var(--fs-small); font-weight: 500; }
.section__head a::after { content: ""; position: absolute; inset: -14px -6px; }   /* 44px hit area */

/* Footer: the RautingTech credit, at the end of the content, above the fixed tab bar */
.app-footer {
  flex: none;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-5));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1;
}
.app-footer__inner { width: 100%; display: flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--tap); border-top: 1px solid var(--line); padding-top: var(--space-2); }
.app-footer .rt-logo { font-size: 14px; }
/* The footer supplies the clearance below the content */
.app-main:has(+ .app-footer) { padding-bottom: var(--space-5); }

/* Bottom tab bar: fixed, safe-area aware, 44px+ targets. Active tab: white
   label and a red slanted bar on top. */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar__list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--content-max);
  height: var(--tabbar-h);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
}
.tabbar__list > li { display: contents; }
.tabbar__item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  height: 100%;
  padding: 0 2px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-align: center;
  color: var(--text-muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar__item:hover { color: var(--text); }
.tabbar__item[aria-current="page"] { color: var(--text); }
.tabbar__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: -1px; left: 50%;
  width: 44%; height: 4px;
  margin-left: -22%;
  background: var(--red);
  transform: skewX(var(--skew));
}
.tabbar__item:focus-visible { outline-offset: -4px; }

/* 5. Buttons and links --------------------------------------------------- */
a { color: var(--text); text-decoration-color: var(--text-muted); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--text); }
.link-quiet { color: var(--text-2); text-decoration: none; }
.link-quiet:hover { color: var(--text); text-decoration: underline; }

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--fs-ui);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-3); border-color: var(--text); }
.btn:active { background: var(--surface-2); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* Primary: red fill, white text (4.96:1) */
.btn--primary { background: var(--red); border-color: var(--red); color: var(--white); }
.btn--primary:hover { background: #c80512; border-color: #c80512; }
.btn--primary:active { background: var(--red-deep); border-color: var(--red-deep); }
.btn--primary:focus-visible { outline-offset: 3px; }

.btn--secondary { }

/* Danger: outline in red text colour; hover fills it */
.btn--danger { color: var(--red-text); border-color: var(--red-text); }
.btn--danger:hover { background: var(--red); border-color: var(--red); color: var(--white); }

.btn--ghost { border-color: transparent; }

/* Small: 36px visible, hit area extended to 44px */
.btn--sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-small); }
.btn--sm::before { content: ""; position: absolute; inset: -4px 0; }

.btn--lg { min-height: 52px; font-size: 18px; padding: 0 var(--space-5); }
.btn--block { display: flex; width: 100%; }

.btn-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* 6. Tags, swatch ---------------------------------------------------------- */
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--space-2);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
}
.tag--warm { color: var(--warm); border-color: var(--warm); }
.tag--danger { color: var(--red-text); border-color: var(--red-text); }
.tag--solid { background: var(--white); border-color: var(--white); color: var(--black); }
.tag--muted { color: var(--text-muted); border-color: var(--line); }

/* Team colour swatch: set the colour inline, style="--team:#e8002d". A mini slant, so it reads as data in the league's own geometry. */
.swatch {
  display: inline-block;
  flex: none;
  width: var(--swatch-w);
  align-self: stretch;
  min-height: 1.2em;
  border-radius: 1px;
  background: var(--team, var(--text-muted));
  transform: skewX(var(--skew));
  outline: 1px solid rgb(255 255 255 / .16);   /* keeps dark team colours visible on black */
}

/* 7. Home crest, join crest, next-race hero, RSVP ------------------------ */
.home-crest { display: flex; align-items: center; gap: var(--space-4); }
.home-crest__logo { width: 104px; height: 104px; flex: none; display: block; border-radius: 50%; }
.home-crest__text > * + * { margin-top: var(--space-1); }
.home-crest__line {
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  font-size: 34px;
  line-height: .95;
  letter-spacing: 0.005em;
  text-wrap: balance;
}

/* Join / welcome: the logo large, on a dark red glow */
.join-crest { position: relative; overflow: clip; display: grid; place-items: center; padding: var(--space-4) 0 var(--space-2); isolation: isolate; }
.join-crest::before {
  content: "";
  position: absolute; z-index: -1;
  inset: -10% -20%;
  background: radial-gradient(closest-side, rgb(225 6 19 / .34), rgb(225 6 19 / .1) 55%, transparent 80%);
}
.join-crest__logo { width: min(74vw, 300px); height: auto; aspect-ratio: 1; display: block; border-radius: 50%; }
.join-crest + .page-head { text-align: center; }

/* Next-race hero: the one place the look is loud. Chequer edge on top, a red
   streak beside a huge italic track name, the countdown in big numerals. */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: calc(var(--space-5) + 14px) var(--space-4) var(--space-4);
}
.hero::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 78%; height: 14px;
  background: repeating-conic-gradient(var(--white) 0 25%, #1c1c1c 0 50%) 0 0 / 14px 14px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 0 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 65%);
  mask-image: linear-gradient(90deg, transparent, #000 65%);
}
.hero > * { position: relative; }
.hero > * + * { margin-top: var(--space-3); }
.hero__meta {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--red-text);
}
.hero__meta + .hero__track { margin-top: var(--space-2); }
.hero__track {
  position: relative;
  padding-left: 26px;
  font-size: clamp(38px, 12vw, 84px);
  line-height: .92;
  letter-spacing: 0;
  overflow-wrap: break-word;
  hyphens: auto;
}
.hero__track::before {   /* the streak */
  content: "";
  position: absolute;
  left: 2px; top: .06em; bottom: .04em;
  width: 11px;
  background: var(--red-hi);
  transform: skewX(var(--skew));
}
.hero__track + .hero__meta { margin-top: var(--space-2); color: var(--text-2); }
.hero__when {
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.hero__count {
  font-size: var(--fs-small);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.hero__count strong {
  display: block;
  margin-top: 2px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 40px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
}
.hero__notes {
  border-top: 1px solid var(--line);
  padding-top: var(--space-3);
  font-size: var(--fs-small);
  color: var(--text-2);
  white-space: pre-line;
}
.hero__rsvp { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--line); }

/* RSVP control. Three states, one wrapper: .rsvp--undecided | --in | --out. */
.rsvp { display: grid; gap: var(--space-3); }
.rsvp__state {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  text-transform: uppercase;
  font-size: var(--fs-h2);
  line-height: 1;
}
.rsvp--in .rsvp__state::before, .rsvp--out .rsvp__state::before {   /* slanted status marker, never colour alone */
  content: "";
  width: 12px; height: 22px;
  flex: none;
  border: 2px solid var(--text-muted);
  transform: skewX(var(--skew));
}
.rsvp--in .rsvp__state::before { background: var(--white); border-color: var(--white); }
.rsvp--out .rsvp__state { color: var(--text-muted); }
.rsvp__sub { margin-top: -6px; font-size: var(--fs-small); color: var(--text-muted); }
.rsvp__actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.rsvp--in .rsvp__actions, .rsvp--out .rsvp__actions { grid-template-columns: 1fr; }
.rsvp--undecided .rsvp__actions .btn { min-height: 52px; font-size: 18px; }

/* 8. Entry list, race list ---------------------------------------------- */
.entry-list { list-style: none; margin: 0; padding: 0; counter-reset: entry; border-top: 1px solid var(--line); }
.entry-list__item {
  counter-increment: entry;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}
.entry-list__item::before {
  content: counter(entry);
  flex: none;
  width: 28px;
  text-align: right;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.entry-list__name { flex: 1; min-width: 0; font-size: 18px; font-weight: 700; line-height: 1.25; }
.entry-list__name a { text-decoration: none; }
.entry-list__name a:hover { text-decoration: underline; }
.entry-list__item .num { color: var(--text-muted); font-size: var(--fs-small); }
.entry-list__item .tag { margin-left: auto; }
/* Lobby details under the name (signed-in viewers only); long gamertags wrap rather than overflow. */
.entry-list__ids { display: block; margin-top: 2px; font-size: var(--fs-small); font-weight: 400; color: var(--text-muted); overflow-wrap: anywhere; }
.entry-list__ids.is-missing { color: var(--warm); }
.entry-list__tools { margin-top: var(--space-3); }
.entry-out { margin-top: var(--space-3); font-size: var(--fs-small); color: var(--text-muted); }
.entry-out strong { font-weight: 700; color: var(--text-2); }

.race-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.race-list > li { border-bottom: 1px solid var(--line); }
.race-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3) 0;
  color: var(--text);
  text-decoration: none;
}
a.race-row:hover { background: var(--surface-2); }
a.race-row:hover .race-row__track { text-decoration: underline; text-underline-offset: 3px; }
.race-row__round {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.race-row__main { min-width: 0; display: grid; gap: 2px; }
.race-row__track { font-size: 18px; font-weight: 700; line-height: 1.2; }
.race-row__date { font-size: var(--fs-small); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.race-row__side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: var(--fs-small); color: var(--text-muted); }
.race-row--done .race-row__track { color: var(--text-2); font-weight: 500; }
.race-row--next .race-row__round { color: var(--text); }

/* 9. Standings tower, rounds table -------------------------------------- */
/* One row per racer or constructor. The leader carries the red streak. */
.tower { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.tower__row {
  position: relative;
  display: grid;
  grid-template-columns: 36px var(--swatch-w) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding: var(--space-2) var(--space-1) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--line);
}
.tower__pos {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  color: var(--text-2);
}
.tower__row .swatch { align-self: stretch; margin: 6px 0; }
.tower__who { min-width: 0; display: grid; gap: 1px; }
.tower__name { font-size: 18px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.tower__name a { text-decoration: none; }
.tower__name a:hover { text-decoration: underline; }
.tower__sub { font-size: var(--fs-small); color: var(--text-muted); line-height: 1.35; }
.tower__wins { font-size: var(--fs-small); color: var(--text-muted); text-align: right; white-space: nowrap; min-width: 4.5ch; }
.tower__pts {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 32px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 3ch;
}
.tower__row.is-leader::before {   /* the streak, as the leader marker */
  content: "";
  position: absolute; left: 3px; top: -1px; bottom: -1px;
  width: 7px;
  background: var(--red);
  transform: skewX(var(--skew));
}
.tower__row.is-leader .tower__pos { color: var(--text); }
.tower__head { display: flex; justify-content: space-between; padding: var(--space-2) var(--space-1) var(--space-2) var(--space-3); }

/* Round-by-round table: wrap in .table-scroll (tabindex="0" and an aria-label). First column sticks. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  max-width: 100%;
}
.rounds-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-ui);
  font-variant-numeric: tabular-nums;
}
.rounds-table th, .rounds-table td {
  padding: var(--space-2) var(--space-3);
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  min-width: 48px;
  height: 44px;
}
.rounds-table thead th {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
}
.rounds-table thead th a { color: inherit; text-decoration: none; }
.rounds-table thead th a:hover { color: var(--text); text-decoration: underline; }
.rounds-table tbody tr:last-child > * { border-bottom: 0; }
.rounds-table th:first-child {
  position: sticky; left: 0; z-index: 1;
  text-align: left;
  min-width: 132px; max-width: 132px;
  overflow: hidden; text-overflow: ellipsis;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
}
.rounds-table thead th:first-child { background: var(--surface-2); color: var(--text-muted); font-weight: 600; }
.rounds-table td.is-win { color: var(--text); font-weight: 700; background: var(--surface-raised); box-shadow: inset 0 -2px 0 var(--red); }
.rounds-table td.is-zero, .rounds-table td.is-dropped { color: var(--text-muted); }
.rounds-table td.is-total { font-family: var(--font-display); font-style: italic; font-weight: 800; font-size: 20px; border-left: 1px solid var(--line); }
.rounds-table thead th.is-total { border-left: 1px solid var(--line); }

/* 10. Racer profile, stat grid ------------------------------------------ */
.profile-head {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: end;
  gap: var(--space-2) var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--line);
}
.profile-head__num {
  grid-row: span 2;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 96px;
  line-height: .8;
  color: transparent;
  -webkit-text-stroke: 2px var(--text-2);
  min-width: 1.1ch;
}
.profile-head__name { font-size: var(--fs-h1); line-height: .92; align-self: end; }
.profile-head__team {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-ui); font-weight: 700; color: var(--text-2);
}
.profile-head__team .swatch { align-self: center; height: 1.2em; }
.profile-head__tags { grid-column: 1 / -1; display: flex; gap: var(--space-2); flex-wrap: wrap; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin: 0;
}
.stat { background: var(--surface-raised); padding: var(--space-3) var(--space-4); margin: 0; display: flex; flex-direction: column-reverse; } /* markup order: dt label, dd value; value shows first */
.stat__value { font-family: var(--font-display); font-style: italic; font-weight: 800; font-size: 38px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat__label { font-family: var(--font-display); font-size: var(--fs-caption); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
dl.stat-grid dt, dl.stat-grid dd { margin: 0; }

.placeholder {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  padding: var(--space-4);
  color: var(--text-muted);
  font-size: var(--fs-small);
}
.placeholder strong { display: block; font-weight: 700; color: var(--text-2); margin-bottom: 2px; }

/* 11. Result rows -------------------------------------------------------- */
.result-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.result-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 62px;
  padding: var(--space-2) var(--space-1);
  border-bottom: 1px solid var(--line);
}
.result-row__pos {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-2);
}
.result-row:first-child .result-row__pos { color: var(--text); }
.result-row--status .result-row__pos { font-size: 16px; font-weight: 700; color: var(--text-muted); letter-spacing: .06em; }
.result-row--dsq .result-row__pos { color: var(--red-text); }
.result-row__main { min-width: 0; display: grid; gap: 1px; }
.result-row__name { font-size: 18px; font-weight: 700; line-height: 1.2; display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.result-row__name > a, .result-row__name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.result-row__team { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-small); color: var(--text-muted); line-height: 1.4; }
.result-row__team .swatch { align-self: center; height: 0.95em; min-height: 0; width: 4px; }
.result-row__detail { font-size: var(--fs-small); color: var(--text-muted); line-height: 1.4; }
.result-row__pts { font-family: var(--font-display); font-style: italic; font-weight: 800; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; text-align: right; min-width: 2.4ch; }
.result-row__pts small { display: block; margin-top: 2px; font-family: var(--font-sans); font-style: normal; font-size: 12px; font-weight: 400; color: var(--text-muted); }
/* Fastest-lap marker: an inverted chip (white on black), text-labelled */
.fl-mark {
  flex: none;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  padding: 3px 6px;
  color: var(--black);
  background: var(--white);
  border-radius: 3px;
}

/* 12. Forms -------------------------------------------------------------- */
.form > * + *, .fieldset > :not(legend) + * { margin-top: var(--space-4); }
.field { display: grid; gap: var(--space-2); min-width: 0; }
.label, .field > label { font-size: var(--fs-ui); font-weight: 700; line-height: 1.3; color: var(--text); }
.label__opt { font-weight: 400; color: var(--text-muted); }
.input, .select, .textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px var(--space-3);
  font-family: var(--font-sans);
  font-size: 16px;               /* >=16px stops iOS zooming on focus */
  line-height: 1.4;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  appearance: none;
  -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; border-color: var(--text); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.select {
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.input[type="datetime-local"], .input[type="date"], .input[type="time"] { font-variant-numeric: tabular-nums; color-scheme: dark; }
.input[type="number"] { font-variant-numeric: tabular-nums; }
.input[disabled], .select[disabled], .textarea[disabled] { opacity: .5; cursor: not-allowed; }
.hint { font-size: var(--fs-small); color: var(--text-muted); line-height: 1.5; }
.field-error { font-size: var(--fs-small); color: var(--danger); line-height: 1.5; }
.field-error::before { content: "Problem: "; font-weight: 700; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea,
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--red-text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.form-row > * { min-width: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); }
.fieldset { border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--space-4); margin: 0; min-width: 0; }
.fieldset > legend { font-weight: 700; padding: 0 var(--space-2); }

/* Checkbox / radio: wrap input + text in label.check. 44px row, 22px box. */
.check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
  font-size: var(--fs-ui);
  font-weight: 500;
  cursor: pointer;
}
.check input {
  appearance: none; -webkit-appearance: none;
  flex: none;
  width: 22px; height: 22px; margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--text-muted);
  border-radius: 3px;
  display: inline-grid; place-content: center;
  cursor: pointer;
}
.check input[type="radio"] { border-radius: 50%; }   /* radios must read as radios */
.check input:checked { background: var(--red); border-color: var(--red); }
.check input:checked::after {
  content: "";
  width: 6px; height: 11px;
  border: solid var(--white); border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.check input[type="radio"]:checked::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--white); transform: none; }
.check input:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.check input[disabled] { opacity: .45; }

/* Compact result-entry row for stewards. One per classified driver. */
.result-entry { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.result-entry__row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 92px;
  grid-template-areas:
    "pos who status"
    ".   team team"
    ".   flags flags";
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.result-entry__pos { grid-area: pos; font-family: var(--font-display); font-style: italic; font-weight: 800; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; text-align: center; color: var(--text-2); }
.result-entry__who { grid-area: who; }
.result-entry__status { grid-area: status; }
.result-entry__team { grid-area: team; }
.result-entry__flags { grid-area: flags; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-4); }
.result-entry__flags .input { width: 112px; }
.result-entry__flags .check { min-height: var(--tap); }
.result-entry__move { display: flex; gap: var(--space-1); margin-left: auto; }
.result-entry__row .select, .result-entry__row .input { min-height: 44px; padding-top: 8px; padding-bottom: 8px; font-size: 16px; }
.result-entry__row .select { padding-right: 32px; background-position: calc(100% - 16px) 50%, calc(100% - 10px) 50%; }
@media (min-width: 720px) {
  .result-entry__row {
    grid-template-columns: 40px minmax(0, 1.3fr) 100px minmax(0, 1.1fr) auto;
    grid-template-areas: "pos who status team flags";
  }
  .result-entry__flags { flex-wrap: nowrap; }
}

/* 13. Admin rows, disclosure -------------------------------------------- */
.admin-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.admin-row {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
}
.admin-row__main { min-width: 0; display: grid; gap: 2px; }
.admin-row__title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.admin-row__sub { font-size: var(--fs-small); color: var(--text-muted); }
.admin-row__tags { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-1); }
.admin-row__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.admin-row--inactive .admin-row__title { color: var(--text-muted); }
@media (min-width: 720px) {
  .admin-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .admin-row__actions { justify-content: flex-end; }
}

.disclosure { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-raised); }
.disclosure + .disclosure { margin-top: var(--space-2); }
.disclosure > summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-4);
  font-size: var(--fs-ui); font-weight: 700;
  cursor: pointer;
  border-radius: var(--r-lg);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after {
  content: "";
  flex: none;
  width: 8px; height: 8px;
  border: solid var(--text-2); border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s;
}
.disclosure[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.disclosure[open] > summary { border-bottom: 1px solid var(--line); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.disclosure__body { padding: var(--space-4); }
.disclosure__body > * + * { margin-top: var(--space-3); }

/* 14. Alerts, empty state, segmented control, skeleton ------------------ */
/* Meaning is in the words (.alert__title), not the colour alone. */
.alert {
  display: grid;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--r);
  font-size: var(--fs-small);
  line-height: 1.55;
  color: var(--text-2);
}
.alert__title { line-height: 1.4; font-size: var(--fs-ui); font-weight: 700; color: var(--text); }
.alert--info { border-left-color: var(--text-muted); }
.alert--success { border-left-color: var(--white); }   /* neutral by design: success is white, not green */
.alert--warning { border-color: var(--warm); border-left-color: var(--warm); }
.alert--warning .alert__title { color: var(--warm); }
.alert--error { border-color: var(--red-text); border-left-color: var(--red); }
.alert--error .alert__title { color: var(--red-text); }

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  display: grid;
  justify-items: center;
  gap: var(--space-3);
}
.empty__title { font-family: var(--font-display); font-style: italic; font-weight: 800; text-transform: uppercase; font-size: var(--fs-h2); line-height: 1; }
.empty__text { font-size: var(--fs-small); color: var(--text-muted); max-width: 34ch; }

/* Segmented control: buttons with aria-pressed. Selected = white fill, black text. */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
}
.segmented__btn {
  min-height: var(--tap);
  padding: 0 var(--space-3);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.segmented__btn:hover { color: var(--text); }
.segmented__btn[aria-pressed="true"], .segmented__btn[aria-selected="true"], .segmented__btn[aria-current="true"] {
  color: var(--black);
  background: var(--white);
}

.skeleton {
  display: block;
  min-height: 1em;
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton--line { height: 14px; }
.skeleton--title { height: 40px; width: 60%; }
.skeleton--row { height: 58px; }
.skeleton--w-40 { width: 40%; } .skeleton--w-60 { width: 60%; } .skeleton--w-80 { width: 80%; }
@keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* 15. Rendered Markdown (rules page): wrap output in .prose ------------- */
.prose { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text); max-width: 68ch; }
.prose > * + * { margin-top: var(--space-4); }
.prose h1 { font-size: var(--fs-h1); }
.prose h2 { font-size: var(--fs-h2); margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.prose h3 { font-size: var(--fs-h3); margin-top: var(--space-5); }
.prose h4 { margin-top: var(--space-4); }
.prose h1 + *, .prose h2 + *, .prose h3 + * { margin-top: var(--space-3); }
.prose ul, .prose ol { padding-left: 1.4em; margin-left: 0; }
.prose li + li { margin-top: var(--space-2); }
.prose li::marker { color: var(--text-muted); }
/* Numbered clauses: <ol class="clauses"> nests as 1, 1.1, 1.2 */
.prose ol.clauses, .prose ol.clauses ol { list-style: none; padding-left: 0; counter-reset: clause; }
.prose ol.clauses li { position: relative; }
.prose ol.clauses li::before {
  position: absolute; left: 0;
  font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-muted);
}
.prose ol.clauses > li { counter-increment: clause; padding-left: 3.4ch; }
.prose ol.clauses > li::before { content: counter(clause) "."; }
.prose ol.clauses ol { margin-top: var(--space-2); counter-reset: sub; }
.prose ol.clauses ol > li { counter-increment: sub; padding-left: 4.6ch; }
.prose ol.clauses ol > li::before { content: counter(clause) "." counter(sub); }
.prose blockquote {
  margin-left: 0; margin-right: 0;
  padding: var(--space-1) 0 var(--space-1) var(--space-4);
  border-left: 3px solid var(--red);
  color: var(--text-2);
}
.prose blockquote > * + * { margin-top: var(--space-2); }
.prose a { text-decoration-color: var(--text-muted); }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; width: 100%; font-size: var(--fs-small); max-width: 100%; }
.prose th, .prose td { padding: var(--space-2) var(--space-3); border: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { font-weight: 700; background: var(--surface-2); white-space: nowrap; }
.prose td:not(:first-child) { font-variant-numeric: tabular-nums; }
.prose pre { overflow-x: auto; padding: var(--space-3) var(--space-4); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); font-size: var(--fs-small); }
.prose pre code { border: 0; background: none; padding: 0; }
.prose hr { margin: var(--space-6) 0; }
.prose img { height: auto; border-radius: var(--r); }

/* Reduced motion: no animation, no transitions */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .skeleton { animation: none; background: var(--surface-3); }
}

/* Desktop refinements */
@media (min-width: 720px) {
  .app-main { padding-top: var(--space-6); }
  .app-league { font-size: 30px; }
  .app-league__logo { width: 44px; height: 44px; }
  .app-header__inner { min-height: 72px; }
  .home-crest__logo { width: 132px; height: 132px; }
  .home-crest__line { font-size: 44px; }
  .hero { padding: calc(var(--space-6) + 14px) var(--space-5) var(--space-5); }
  .hero__count strong { font-size: 52px; }
  .tabbar__item { font-size: 18px; }
  .tabbar__list { max-width: var(--content-max); }
}

/* 44px hit areas for name links that sit in taller rows */
.tower__name a, .entry-list__name a, .result-row__name > a, .rounds-table thead th a { position: relative; }
.tower__name a::after, .entry-list__name a::after, .result-row__name > a::after, .rounds-table thead th a::after { content: ""; position: absolute; inset: -14px -4px; }
.result-row__name > a { overflow: visible; }
