/* Race Results — "Lime Notch": a dark studio look with grain, square corners and one lime accent.
   The shell (header, title band, tab bar) is grain-black in both themes; the page ground is dark by default
   with a light option. Lime marks you, first place, the racing line and accent fills; red marks DNFs and errors.
   Type: Stack Sans Notch (headings, light and tight), Geist (body), Atkinson Hyperlegible Mono (labels, tags, nav).
   The admin has no data-theme and follows the system setting. */

/* Fonts are served from the site (public/fonts, Latin subset, variable weights) so they load on weak signal. */
@font-face { font-family: "Stack Sans Notch"; font-style: normal; font-weight: 200 700; font-display: swap; src: url("/fonts/stack-sans-notch.woff2") format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("/fonts/geist.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Mono"; font-style: normal; font-weight: 200 800; font-display: swap; src: url("/fonts/atkinson-hyperlegible-mono.woff2") format("woff2"); }
/* Thai and Japanese: IBM Plex, one family for both scripts. Thai is small and declared here; it loads only when
   a page shows Thai characters. Japanese is split into many slices declared in fonts-ja.css (see locale.js). */
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-weight: 300; font-display: swap; src: url("/fonts/ibm-plex-sans-thai/300-thai.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-sans-thai/400-thai.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/ibm-plex-sans-thai/600-thai.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }

:root {
  color-scheme: dark;
  --font: Geist, "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Stack Sans Notch", Geist, "IBM Plex Sans Thai", system-ui, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* The eight palette colours; everything below is built from these plus two text greys for contrast. */
  --lime: #9cff07; --red: #ff463c;
  --grey-01: #ffffff; --grey-02: #f2f2f2; --grey-03: #d5d9da; --grey-04: #444444; --grey-05: #232323; --grey-06: #070707;

  /* The shell: header, title band, tab bar, champion. Grain-black in both themes. */
  --shell: var(--grey-06);
  --shell-line: var(--grey-05);
  --on-shell: var(--grey-02);
  --on-shell-muted: #a1a5a6;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 .11 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");

  /* Dark ground (the default). */
  --bg: #0c0c0c;
  --ground-grain: var(--grain);
  --surface: #141414;
  --surface-2: #1c1c1c;
  --text: var(--grey-02);
  --heading: var(--grey-01);
  --muted: #a1a5a6;
  --border: var(--grey-05);        /* one hairline weight everywhere */
  --line-strong: #6b6f70;          /* input and control edges: 3:1 on the surface */

  --accent: var(--lime);           /* fills, always with --on-accent text */
  --accent-hover: #b8ff52;
  --on-accent: var(--grey-06);
  --accent-ink: var(--lime);       /* accent-coloured text */
  --accent-ink-strong: #c9ff7d;
  --accent-tint: rgb(156 255 7 / 0.12);
  --accent-line: var(--lime);
  --win-ink: var(--lime);          /* first place, everywhere */

  --btn-bg: var(--grey-01);        /* primary button: white on dark, black on light */
  --on-btn: var(--grey-06);

  --me-bg: var(--lime);            /* your own row and pin: a lime fill with black text */
  --on-me: var(--grey-06);
  --me-muted: #33421a;
  --me-win: var(--grey-06);

  --tag-bg: var(--grey-03); --on-tag: var(--grey-06);       /* the grey tag */
  --quiet-bg: var(--grey-05); --quiet-ink: var(--grey-03);  /* draft, finished, skipped */
  --ok-ink: var(--lime); --ok-bg: rgb(156 255 7 / 0.1);
  --bad-ink: var(--red); --bad-bg: #2a0f0d;

  --round-done-bg: #121212;                  --round-done-line: var(--grey-04);  --round-done-ink: var(--grey-03);
  --round-current-bg: rgb(156 255 7 / 0.07); --round-current-line: var(--lime); --round-current-ink: var(--lime);
  --round-upcoming-bg: transparent;          --round-upcoming-line: var(--grey-04); --round-upcoming-ink: #a1a5a6;

  --hl-bg: rgb(156 255 7 / 0.18); --hl-line: var(--lime);
  --target-line: var(--lime);
  --line-casing: var(--grey-06);   /* racing line outline */
  --focus: var(--lime);
  --focus-on-shell: var(--lime);
  --radius: 0px;

  --fs-xs: 0.8125rem; --fs-sm: 0.875rem; --fs-base: 1rem; --fs-h3: 1.25rem; --fs-h2: clamp(1.5rem, 1.15rem + 1.2vw, 2rem); --fs-h1: clamp(2.25rem, 1.4rem + 3.4vw, 4.25rem);
  font-family: var(--font);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: var(--grey-02);
  --ground-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .07 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --surface: var(--grey-01); --surface-2: #e9ebec; --text: var(--grey-06); --heading: var(--grey-06); --muted: #4f5354;
  --border: var(--grey-03); --line-strong: #7a7e7f;
  --accent-hover: #8ae600; --accent-ink: #3a6200; --accent-ink-strong: var(--grey-06); --accent-tint: rgb(156 255 7 / 0.25); --accent-line: #3a6200;
  --win-ink: #3a6200;
  --btn-bg: var(--grey-06); --on-btn: var(--grey-01);
  --quiet-bg: #e9ebec; --quiet-ink: #4f5354;
  --ok-ink: #3a6200; --ok-bg: rgb(156 255 7 / 0.22); --bad-ink: #c42318; --bad-bg: #fde4e2;
  --round-done-bg: var(--grey-01); --round-done-line: var(--grey-03); --round-done-ink: #4f5354;
  --round-current-bg: rgb(156 255 7 / 0.18); --round-current-line: #3a6200; --round-current-ink: #3a6200;
  --round-upcoming-line: #a1a5a6; --round-upcoming-ink: #4f5354;
  --hl-bg: rgb(156 255 7 / 0.45); --hl-line: #3a6200;
  --target-line: var(--grey-06);
  --focus: var(--grey-06);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: var(--grey-02);
    --ground-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .07 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    --surface: var(--grey-01); --surface-2: #e9ebec; --text: var(--grey-06); --heading: var(--grey-06); --muted: #4f5354;
    --border: var(--grey-03); --line-strong: #7a7e7f;
    --accent-hover: #8ae600; --accent-ink: #3a6200; --accent-ink-strong: var(--grey-06); --accent-tint: rgb(156 255 7 / 0.25); --accent-line: #3a6200;
    --win-ink: #3a6200;
    --btn-bg: var(--grey-06); --on-btn: var(--grey-01);
    --quiet-bg: #e9ebec; --quiet-ink: #4f5354;
    --ok-ink: #3a6200; --ok-bg: rgb(156 255 7 / 0.22); --bad-ink: #c42318; --bad-bg: #fde4e2;
    --round-done-bg: var(--grey-01); --round-done-line: var(--grey-03); --round-done-ink: #4f5354;
    --round-current-bg: rgb(156 255 7 / 0.18); --round-current-line: #3a6200; --round-current-ink: #3a6200;
    --round-upcoming-line: #a1a5a6; --round-upcoming-ink: #4f5354;
    --hl-bg: rgb(156 255 7 / 0.45); --hl-line: #3a6200;
    --target-line: var(--grey-06);
    --focus: var(--grey-06);
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-color: var(--line-strong) transparent; }
body { margin: 0; background: var(--bg) var(--ground-grain); color: var(--text); line-height: 1.5; font-size: var(--fs-base); -webkit-text-size-adjust: 100%; }
::selection { background: var(--accent); color: var(--on-accent); }
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
:is(h1, h2, h3, main)[tabindex="-1"]:focus { outline: none; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
/* Scrollers and rows contain their visually-hidden labels, so those never widen the page. */
.rounds, .table-scroll, .heat-row, .pick, .file-btn, .toolbar, .chip, .badge, td, th { position: relative; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 50; padding: 10px 14px; background: var(--surface); color: var(--text); border: 2px solid var(--focus); }
.skip-link:focus { top: 10px; }
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; }

h1, h2, h3 { font-family: var(--font-display); color: var(--heading); text-wrap: balance; }
h1 { font-size: var(--fs-h1); font-weight: 300; line-height: 0.98; letter-spacing: -0.03em; margin: 0 0 6px; }
h2 { font-size: var(--fs-h2); font-weight: 400; line-height: 1.05; letter-spacing: -0.025em; margin: 36px 0 14px; }
h3 { font-size: var(--fs-h3); font-weight: 500; line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.hint { font-size: var(--fs-sm); color: var(--muted); margin: 8px 0; max-width: 75ch; }
.num, .tnum { font-variant-numeric: tabular-nums; }
/* Mono labels: nav, tabs, table heads, tags. Uppercase and spaced, never above a heading. */
.mono { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- the shell: header, page band ---------- */
/* Whatever the page theme, things on the shell use the dark-ground values. */
.shell, .champion {
  background-color: var(--shell); background-image: var(--grain); color: var(--on-shell);
  --heading: var(--grey-01); --text: var(--grey-02); --muted: #a1a5a6; --border: var(--grey-05); --line-strong: #6b6f70;
  --accent-ink: var(--lime); --accent-line: var(--lime); --win-ink: var(--lime); --focus: var(--lime);
  --quiet-bg: var(--grey-05); --quiet-ink: var(--grey-03);
  --ok-ink: var(--lime); --ok-bg: rgb(156 255 7 / 0.1); --bad-ink: var(--red); --bad-bg: #2a0f0d;
}

header.site { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--shell-line); }
header.site .wrap { display: flex; align-items: center; gap: 12px 18px; min-height: 60px; }
.shell :focus-visible { outline-color: var(--focus-on-shell); }
.brand { font-family: var(--font-display); font-weight: 500; font-size: 1.3rem; letter-spacing: -0.02em; text-decoration: none; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; min-width: 44px; flex: none; }
.brand .name::after { content: "_" / ""; color: var(--lime); }
.shell .brand:hover { color: var(--on-shell); }
/* The mark: a lime square with a notch cut from one corner, like the notches in the heading face. */
.brand .logo { width: 22px; height: 22px; background: var(--lime); clip-path: polygon(0 0, 55% 0, 55% 45%, 100% 45%, 100% 100%, 0 100%); }
nav.main { display: flex; gap: 2px; min-width: 0; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
nav.main::-webkit-scrollbar { display: none; }
nav.main a { position: relative; text-decoration: none; display: inline-flex; align-items: center; min-height: 48px; padding: 0 12px; color: var(--on-shell-muted); font-family: var(--font-mono); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
nav.main a:hover { color: var(--on-shell); }
/* The current-link underline: a 2px bar that grows from the left (see the motion section). */
nav.main a::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; background: var(--lime); transform: scaleX(0); transform-origin: left; }
nav.main a.active, nav.main a[aria-current="page"] { color: var(--on-shell); }
nav.main a.active::after, nav.main a[aria-current="page"]::after { transform: scaleX(1); }
.icon-btn { min-width: 44px; min-height: 44px; padding: 0; justify-content: center; flex: none; }
.shell .icon-btn, .shell button, .shell .btn { background: transparent; color: var(--on-shell); border-color: var(--grey-04); }
.shell .icon-btn:hover, .shell button:hover, .shell .btn:hover { border-color: var(--on-shell); color: var(--on-shell); }
.shell button.primary, .shell .btn.primary { background: var(--grey-01); border-color: var(--grey-01); color: var(--grey-06); }
.shell button.primary:hover, .shell .btn.primary:hover { background: var(--lime); border-color: var(--lime); color: var(--grey-06); }
/* The language menu: each language is named in its own script, so it stays readable whatever is chosen. */
.lang-pick { display: inline-flex; flex: none; }
.shell select { background-color: transparent; color: var(--on-shell); border-color: var(--grey-04); cursor: pointer; }
.shell select:hover { border-color: var(--on-shell); }
.shell select option { background-color: var(--shell); color: var(--on-shell); }
.lang-pick select { min-height: 44px; padding: 0 8px; font-size: var(--fs-sm); }

.band { padding: 22px 0 34px; border-bottom: 1px solid var(--shell-line); }
.band .page-head h1, .band h1 { margin: 0; font-size: var(--fs-h1); }
/* The blinking cursor after the page title: the "Think_" motif. */
.band h1::after { content: "_" / ""; color: var(--lime); font-weight: 400; }
@media (prefers-reduced-motion: no-preference) { .band h1::after { animation: cursor-blink 1.2s steps(1) infinite; } }
@keyframes cursor-blink { 50% { opacity: 0; } }
.band a { color: var(--on-shell); }
.band a:hover { color: var(--lime); }
.band .sub, .band .meta, .band .format-line, .band p { color: var(--on-shell-muted); }
.band .sub { margin: 8px 0 0; }
.band .meta { margin-top: 8px; }
.band .back { margin: 0 0 8px; }
.band .back a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none; font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--on-shell-muted); }
.band .back a::before { content: "[" / ""; }
.band .back a::after { content: "]" / ""; }
.band .back a:hover { color: var(--lime); }
.band .live-status { color: var(--on-shell-muted); }
.band .live-status::before { background: var(--lime); }
.band .live-status.is-stale { color: var(--red); }
.band .live-status.is-stale::before { background: transparent; box-shadow: inset 0 0 0 2px var(--red); }
:is(.shell, .champion) .you-tag { background: var(--grey-01); color: var(--grey-06); }
.is-me .you-tag { background: var(--on-me); color: var(--me-bg); }
/* Admin: a tournament's band ends in its own tabs (Races, Registration, Points, Rules, Settings),
   sitting on the band's bottom line, with the same underline as the header menu. */
.band:has(.t-nav) { padding-bottom: 0; }
.band .band-title { margin: 0; font-family: var(--font-display); font-size: var(--fs-h2); font-weight: 400; line-height: 1.05; letter-spacing: -0.025em; color: var(--on-shell); }
.t-nav { display: flex; gap: 2px; margin: 18px -12px 0; overflow-x: auto; scrollbar-width: none; }
.t-nav::-webkit-scrollbar { display: none; }
.t-nav a { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 12px; text-decoration: none; white-space: nowrap; color: var(--on-shell-muted); font-family: var(--font-mono); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.06em; }
.t-nav a::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; background: var(--lime); transform: scaleX(0); transform-origin: left; }
.band .t-nav a:hover { color: var(--on-shell); }
.band .t-nav a[aria-current="page"] { color: var(--on-shell); }
.t-nav a[aria-current="page"]::after { transform: scaleX(1); }
.t-nav .t-nav-ext { margin-left: auto; }
#view > h2:first-child, #view > .page-head:first-child > h2 { margin-top: 0; }
.page-head h2 { margin: 0; }
.band-loading { color: var(--on-shell-muted); margin: 0; min-height: 2.25rem; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--fs-xs); }
@media (max-width: 640px) {
  .wrap { padding: 0 14px; }
  nav.main a.nav-home { display: none; }
  nav.main a { padding: 0 10px; }
  .band { padding: 16px 0 28px; }
}

main.wrap { padding-top: 22px; padding-bottom: 64px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); padding: 16px 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.stack > * + * { margin-top: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }
.page-head h1 { margin: 0; }
.meta { color: var(--muted); font-size: var(--fs-sm); margin: 2px 0 0; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.data th { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.pts { font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; letter-spacing: -0.02em; }
table.data tr.is-hl td { background: var(--hl-bg); }
table.data tr.is-me td { background: var(--me-bg); color: var(--on-me); font-weight: 600; border-bottom-color: var(--me-bg); }
table.data tr.is-me td.muted, table.data tr.is-me .muted { color: var(--me-muted); }
/* Career counts: a short label/value list, kept narrow so each number sits next to its label. */
table.data.career-stats { width: min(100%, 26rem); }
table.data.career-stats tr:last-child th { border-bottom: 0; }
table.data td.wrap { white-space: normal; min-width: 8.5rem; }
table.data tr.is-me a { color: var(--on-me); }
tr.superseded td { color: var(--muted); }
/* Changes by race control: one entry per change, newest last; superseded ones fade like superseded draws. */
.move-log { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.move-log li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.move-log p { margin: 0 0 4px; }
.move-log li.superseded { color: var(--muted); }
.next-link { font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; letter-spacing: -0.01em; display: inline-flex; align-items: center; min-height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); text-decoration: none; white-space: nowrap; background: transparent; color: var(--text); }
.next-link:hover { border-color: var(--accent-line); color: var(--accent-ink); }
table.data tr.is-me .next-link { background: var(--on-me); border-color: var(--on-me); color: var(--me-bg); }
table.data tr.is-target td { box-shadow: inset 0 2px 0 var(--target-line), inset 0 -2px 0 var(--target-line); }
table.data tr.is-me.is-target td { box-shadow: inset 0 3px 0 var(--grey-06), inset 0 -3px 0 var(--grey-06); }
tr[id^="row-"] { scroll-margin: 90px 0 120px; }
.is-me :focus-visible { outline-color: var(--on-me); }
@media (pointer: coarse) { .next-link { min-height: 44px; } }

/* Finishing place: one fixed ramp everywhere (tables, heats, results). 1st is largest and lime. */
.pos, .rk { font-family: var(--font-display); font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; color: var(--muted); }
.pos { display: inline-block; min-width: 1.6ch; font-size: 1.1rem; }
.pos.p1, .rk.p1 { font-size: 1.5rem; font-weight: 600; color: var(--win-ink); }
.pos.p2, .rk.p2 { font-size: 1.3rem; font-weight: 600; color: var(--text); }
.pos.p3, .rk.p3 { font-size: 1.17rem; color: var(--text); }
tr.is-me .pos, .heat-row.is-me .rk { color: var(--me-muted); }
tr.is-me .pos.p1, .heat-row.is-me .rk.p1 { color: var(--me-win); font-weight: 700; }
tr.is-me .pos:is(.p2, .p3), .heat-row.is-me .rk:is(.p2, .p3) { color: var(--on-me); }
@media (max-width: 640px) {
  table.data th, table.data td { padding: 8px 8px; }
  .hide-sm { display: none; }
}

/* ---------- chips, tags, badges ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: var(--fs-sm); padding: 4px 11px; background: transparent; color: var(--text); border: 1px solid var(--line-strong); display: inline-flex; align-items: center; gap: 6px; }
.chip.me { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
a.chip { text-decoration: none; min-height: 36px; }
a.chip:hover { border-color: var(--accent-line); }
@media (pointer: coarse) { a.chip { min-height: 44px; } }
.badge { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 8px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.badge.draft, .badge.t-finished, .badge.skip { background: var(--quiet-bg); color: var(--quiet-ink); }
.badge.drawn, .badge.t-not_started { background: var(--tag-bg); color: var(--on-tag); }
.badge.running, .badge.t-running { background: var(--lime); color: var(--grey-06); }
.badge.done, .badge.ok { background: var(--ok-bg); color: var(--ok-ink); box-shadow: inset 0 0 0 1px var(--ok-ink); }
.badge.bad { background: var(--bad-bg); color: var(--bad-ink); box-shadow: inset 0 0 0 1px var(--bad-ink); }
.badge.running::before, .badge.t-running::before { content: ""; width: 7px; height: 7px; background: currentColor; }
@media (prefers-reduced-motion: no-preference) { .badge.running::before, .badge.t-running::before { animation: cursor-blink 1.2s steps(1) infinite; } }
.format-line { color: var(--muted); font-size: var(--fs-sm); margin: 4px 0 0; }
.you-tag { flex: none; font-family: var(--font-mono); font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; background: var(--accent); color: var(--on-accent); padding: 2px 6px; line-height: 1.4; }

/* ---------- lists of tournaments and races ---------- */
.t-list, .race-list { display: grid; gap: 12px; }
.t-group { margin-top: 32px; }
.t-group:first-child { margin-top: 0; }
.t-group > h2 { margin-top: 0; }
/* Tournament list: a wall of posters, each with its name underneath. A tournament without a poster gets
   one set in the site's own type on the black shell. Posters keep their whole face (contain, never cropped). */
.t-wall { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; align-items: start; }
.t-card { display: flex; flex-direction: column; padding: 0; text-decoration: none; }
.t-cover { container-type: inline-size; aspect-ratio: 5 / 7; display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--border); }
.t-cover-img { display: block; width: 100%; height: 100%; object-fit: contain; }
.t-cover-name { align-self: end; justify-self: start; padding: 16px; font-family: var(--font-display); font-weight: 300; font-size: clamp(1.25rem, 14cqi, 2.25rem); line-height: 0.98; letter-spacing: -0.03em; color: var(--on-shell); overflow-wrap: break-word; }
.t-cover-name::after { content: "_" / ""; color: var(--lime); font-weight: 400; }
.t-body { display: grid; gap: 6px; padding: 14px 16px 16px; }
.t-card h3 { margin: 0; font-size: 1.625rem; font-weight: 400; line-height: 1.05; letter-spacing: -0.025em; }
.t-card .meta { margin: 0; }
.t-status { margin-top: 4px; }
/* Admin tournament wall: the tournament you are working on. */
.t-card.is-current { border-color: var(--text); }
.t-card .leaders { display: flex; flex-wrap: wrap; gap: 6px; }
:root[data-device="phone"] .t-wall { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
:root[data-device="phone"] .t-body { padding: 10px 10px 12px; gap: 4px; }
:root[data-device="phone"] .t-card h3 { font-size: 1.125rem; }
:root[data-device="phone"] .t-card .meta { font-size: var(--fs-xs); }
:root[data-device="phone"] .t-card .chip { white-space: normal; }
:root[data-device="phone"] .t-cover-name { padding: 10px; }

/* Tournament page: poster and name lead the title band, side by side on a PC, poster first on a phone. */
.t-hero { display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr); gap: 20px 36px; align-items: end; }
.t-poster-link { display: block; border: 1px solid var(--shell-line); }
.t-poster { display: block; width: 100%; height: auto; }
.t-hero-text { min-width: 0; padding-bottom: 4px; }
:root[data-device="phone"] .t-hero { grid-template-columns: minmax(0, 1fr); gap: 18px; }
:root[data-device="phone"] .t-poster-link { justify-self: center; width: min(100%, 420px); }
.t-banner { width: 100%; max-height: 280px; object-fit: contain; background: var(--surface); border: 1px solid var(--border); display: block; margin-bottom: 18px; }
a.card:hover { border-color: var(--accent-line); color: inherit; }
.race-item { display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: start; text-decoration: none; }
.race-item .no { font-family: var(--font-display); font-weight: 300; font-size: 2.25rem; letter-spacing: -0.04em; line-height: 0.9; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.race-item h3 { margin: 0; }
.summary-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-decoration: none; }
.summary-card h3 { margin: 0; }
/* A finished tournament's race results: one board per race with its top three, opening the race. */
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.result-card { display: grid; gap: 6px; align-content: start; text-decoration: none; }
.result-card h3 { margin: 0; }
.result-class { margin: 6px 0 0; font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.result-podium { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 2px; }
.result-podium li { display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); align-items: baseline; gap: 8px; overflow-wrap: anywhere; }
:root[data-device="phone"] .result-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 10px; }
:root[data-device="phone"] .result-card { padding: 12px; }
:root[data-device="phone"] .result-podium li { grid-template-columns: 1.5rem minmax(0, 1fr); gap: 6px; }
.video-card h3 .icon { vertical-align: -0.15em; }
/* Podium photo of the selected class, above its standings. */
.podium-photo { margin: 0 0 18px; background: var(--surface); border: 1px solid var(--border); }
.podium-photo img { display: block; width: 100%; height: auto; max-height: 560px; object-fit: contain; background: var(--surface-2); }
.podium-photo figcaption { display: flex; gap: 8px; align-items: center; padding: 10px 12px; font-size: 0.9rem; color: var(--muted); border-top: 1px solid var(--border); }
.podium-thumb { display: block; max-width: 100%; height: auto; max-height: 220px; width: auto; border: 1px solid var(--border); }

/* ---------- your next heat ---------- */
.next-heat { background: var(--surface); border: 1px solid var(--border); padding: 14px 16px 16px; margin: 0 0 20px; max-width: 680px; }
.next-heat .nh-code { margin: 2px 0 8px; font-family: var(--font-display); font-weight: 500; font-size: 2.875rem; letter-spacing: -0.035em; line-height: 1; color: var(--heading); }
.next-heat .nh-code.quiet { font-size: 1.875rem; font-weight: 400; }
.next-heat .nh-code em { font-style: normal; color: var(--accent-ink); }
.next-heat .nh-facts { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.next-heat .nh-facts strong { color: var(--text); }
.next-heat .chips { margin-top: 10px; }
.next-heat .btn { margin-top: 14px; }
.btn.block { display: flex; width: 100%; }

/* ---------- fact list (player summary) ---------- */
dl.facts-table { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; align-items: baseline; }
dl.facts-table dt { color: var(--muted); font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
dl.facts-table dd { margin: 0; font-weight: 600; }

/* ---------- tabs ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line-strong); width: fit-content; max-width: 100%; margin: 16px 0; }
.tabs a, .tabs button { text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; color: var(--muted); font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; border: 0; background: none; }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs a.active, .tabs button.active { background: var(--text); color: var(--bg); }
/* Standings: the selected class's own rules, under the class tabs. */
.class-rules-link { margin: -8px 0 12px; }
.class-rules-link a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.class-rules-link svg { width: 18px; height: 18px; flex: none; }
/* Standings decided by a class's blacklist: the order comes from the ladder, not the points column. */
.decided-note { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; color: var(--muted); }
.decided-note svg { width: 18px; height: 18px; flex: none; }
.decided-note a { padding-block: 12px; } /* a taller hit area without moving the line */
/* Admin: one card per class with a blacklist, its progress and the button that starts it. */
.blacklist-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.blacklist-card h3 { margin: 0; }
.blacklist-card .meta { margin: 4px 0 0; }
/* A tab whose page has content of its own (admin rules: a class with rules written). */
.tab-mark { width: 6px; height: 6px; margin-left: 8px; background: currentColor; flex: none; }

/* ---------- buttons and forms ---------- */
button, .btn { font: inherit; font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; border: 1px solid var(--line-strong); background: transparent; color: var(--text); min-height: 40px; padding: 0 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:hover, .btn:hover { border-color: var(--text); color: var(--text); }
button.primary, .btn.primary { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--on-btn); }
button.primary:hover, .btn.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.danger, .btn.danger { color: var(--bad-ink); border-color: var(--bad-ink); background: transparent; }
button.danger:hover { background: var(--bad-bg); color: var(--bad-ink); }
button.small, .btn.small { min-height: 34px; padding: 0 12px; font-size: var(--fs-xs); }
button.big, .btn.big { min-height: 48px; padding: 0 22px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
@media (pointer: coarse) {
  button, .btn { min-height: 44px; }
  button.small, .btn.small { min-height: 44px; }
}

select, input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], input[type=email], textarea {
  font: inherit; min-height: 40px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 0; background: var(--surface); color: var(--text); max-width: 100%;
}
input[type=search] { -webkit-appearance: none; appearance: none; }
::placeholder { color: var(--muted); opacity: 1; }
input[type=checkbox] { accent-color: var(--accent); width: 24px; height: 24px; margin: 0; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
@media (pointer: coarse) {
  select, input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], input[type=email] { min-height: 44px; }
}
label.field { display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--muted); }
label.field > span { font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.form-grid label:not(.field) { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- notices and toasts ---------- */
.notice { padding: 10px 14px; margin: 12px 0; border: 1px solid var(--border); background: var(--surface); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.notice.error { border-color: var(--bad-ink); color: var(--bad-ink); background: var(--bad-bg); }
.notice.ok { border-color: var(--ok-ink); color: var(--ok-ink); background: var(--ok-bg); }
.toast-host { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; width: min(560px, calc(100vw - 24px)); display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid; box-shadow: 0 8px 24px rgb(0 0 0 / 0.3); font-weight: 600; background: var(--surface); }
.toast.ok { color: var(--ok-ink); border-color: var(--ok-ink); background: var(--surface); }
.toast.error { color: var(--bad-ink); border-color: var(--bad-ink); background: var(--bad-bg); }
.toast button { margin-left: auto; min-height: 32px; padding: 0 10px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.live-status { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.live-status::before { content: ""; width: 8px; height: 8px; background: var(--ok-ink); }
.live-status.is-stale { color: var(--bad-ink); }
.live-status.is-stale::before { background: currentColor; }

/* ---------- bracket: each round is a column ---------- */
.bracket-section { margin-top: 20px; }
.bracket-section > h3 { margin-bottom: 10px; }
.rounds { display: flex; gap: 22px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.round-col { min-width: 240px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; scroll-snap-align: start; padding: 8px; border: 1px solid transparent; }
.round-col.round-done { background: var(--round-done-bg); border-color: var(--round-done-line); }
.round-col.round-current { background: var(--round-current-bg); border-color: var(--round-current-line); }
.round-col.round-upcoming { background: var(--round-upcoming-bg); border: 1px dashed var(--round-upcoming-line); }
.round-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 2px 4px; font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; letter-spacing: -0.02em; color: var(--heading); }
.round-state { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; }
.round-done .round-state { color: var(--round-done-ink); }
.round-current .round-state { color: var(--round-current-ink); }
.round-upcoming .round-state { color: var(--round-upcoming-ink); }
.round-heats { flex: 1; display: flex; flex-direction: column; gap: 8px; justify-content: space-around; }
.round-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 2px; font-size: var(--fs-sm); color: var(--muted); }
.round-legend span { display: inline-flex; align-items: center; gap: 6px; }
.round-legend i { width: 14px; height: 14px; display: inline-block; }
.round-legend .lg-done i { background: var(--round-done-bg); border: 1px solid var(--round-done-line); }
.round-legend .lg-current i { background: var(--round-current-bg); border: 1px solid var(--round-current-line); }
.round-legend .lg-upcoming i { background: var(--round-upcoming-bg); border: 1px dashed var(--round-upcoming-line); }
.heat { background: var(--surface); border: 1px solid var(--border); overflow: hidden; scroll-margin: 90px 0 24px; }
.heat.has-hl { border-color: var(--hl-line); }
.heat.has-me { border-color: var(--accent-line); }
.heat.is-target { box-shadow: 0 0 0 2px var(--target-line); }
.heat.placeholder { border-style: dashed; background: transparent; }
.heat.empty-filter { padding: 10px; font-size: var(--fs-sm); color: var(--muted); text-align: center; border-style: dashed; background: transparent; }
.heat-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 1px solid var(--border); }
.heat-row { display: grid; grid-template-columns: 42px 1fr 22px; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--border); font-size: 0.9375rem; min-height: 38px; }
.heat-head + .heat-row { border-top: 0; }
.heat-row .rk:not(.p1, .p2, .p3) { font-size: 1.05rem; }
.heat-row .rk.dnf { color: var(--bad-ink); font-family: var(--font-mono); font-size: 0.8125rem; letter-spacing: 0.04em; }
.heat-row .nm { display: flex; align-items: center; gap: 6px; min-width: 0; }
.heat-row .nm > a, .heat-row .nm > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.heat-row .nm > a { display: inline-block; padding: 3px 0; }
.heat-row .nm > a:hover { text-decoration: underline; }
/* The whole row is the tap target for the racer's page. */
.heat-row .nm > a::after { content: ""; position: absolute; inset: 0; }
@media (pointer: coarse) { .heat-row { min-height: 44px; } }
.heat-row.out .nm { color: var(--muted); }
.heat-row .mark { display: inline-flex; justify-content: flex-end; }
.heat-row .mark.adv { color: var(--ok-ink); }
.heat-row .mark.drop { color: var(--text); }
.heat-row .mark.out { color: var(--muted); }
.heat-row.is-hl { background: var(--hl-bg); }
.heat-row.is-me { background: var(--me-bg); color: var(--on-me); font-weight: 600; border-top-color: var(--me-bg); }
.heat-row.is-me a, .heat-row.is-me .nm, .heat-row.is-me .mark { color: var(--on-me); }
.heat-row.is-me .nm > a:hover { color: var(--on-me); }
.heat-foot { padding: 8px 10px; border-top: 1px solid var(--border); }
.heat-foot button { width: 100%; }
/* Phone layout: one round per swipe. The next round peeks in at the edge, and the racing line
   runs across the gap between them, so it carries on as you swipe. */
.round-pager { display: none; }
:root[data-device="phone"] .round-pager { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; margin: 0 0 10px; }
.round-pager button { min-height: 44px; padding: 0 16px; font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 400; letter-spacing: 0.06em; border-color: var(--border); color: var(--muted); flex: none; }
.round-pager button + button { border-left-width: 0; }
.round-pager button[aria-current="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
:root[data-device="phone"] .rounds { gap: 26px; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; }
:root[data-device="phone"] .round-col { min-width: 0; flex: 0 0 calc(100% - 34px); scroll-snap-align: start; scroll-snap-stop: always; }
:root[data-device="phone"] .round-col:only-of-type { flex-basis: 100%; }

/* The racing line: your path through the bracket, drawn over the gaps between rounds. */
.race-line { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 2; }
.race-line path { fill: none; stroke-linecap: square; stroke-linejoin: miter; }
.race-line .casing { stroke: var(--line-casing); stroke-width: 8; }
.race-line .core { stroke: var(--lime); stroke-width: 4; }
@media (prefers-reduced-motion: no-preference) {
  .race-line.draw path { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: race-line-draw 700ms cubic-bezier(.2, .7, .2, 1) 150ms forwards; }
}
@keyframes race-line-draw { to { stroke-dashoffset: 0; } }

/* Your path (phone only): your heats stacked in racing order, the racing line down the left edge
   turning in to your slot in each one. */
.my-path { display: none; }
:root[data-device="phone"] .my-path { display: block; margin: 14px 0 6px; }
.my-path > h3 { margin-bottom: 8px; }
.path-track { position: relative; list-style: none; margin: 0; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 14px; }
.path-step { margin: 0; }
.path-round { margin: 0 0 6px; font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* A bracket's state beside its heading: current, finished, not started (the same marks as the round columns). */
.bracket-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.state-tag { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; line-height: 1.2; padding: 4px 8px; border: 1px solid; white-space: nowrap; }
.state-tag.st-current { color: var(--round-current-ink); background: var(--round-current-bg); border-color: var(--round-current-line); }
.state-tag.st-done { color: var(--round-done-ink); background: var(--round-done-bg); border-color: var(--round-done-line); }
.state-tag.st-upcoming { color: var(--round-upcoming-ink); border: 1px dashed var(--round-upcoming-line); }

/* Race control (admin): drag a racer onto another to swap them, or onto a heat to move them there. */
.heat-row.can-drag { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* Race control (admin): click a racer to mark the result (next place, DNF, clear), then Save on the heat. */
.heat-row[data-mark] { cursor: pointer; }
.heat-row[data-mark]:not(.is-me):hover { background: var(--surface-2); }
:root[data-device="phone"] .heat-row[data-mark] { min-height: 44px; }
.heat.is-marking { border-color: var(--text); }
.heat.is-marking .mark:not(.grip) { visibility: hidden; } /* the old result's arrows no longer apply */
.heat.is-marking .heat-row.out .nm { color: inherit; }
.mark-bar { display: grid; gap: 8px; }
.mark-status { margin: 0; color: var(--muted); }
.mark-status.error { color: var(--bad-ink); }
.mark-actions { display: grid; gap: 8px; } /* stacked, so the heat card keeps its width */
.heat-row.can-drag .grip { color: var(--muted); }
.heat-row.is-dragging { opacity: 0.4; }
.heat.drop-target { box-shadow: 0 0 0 1px var(--text); border-color: var(--text); }
.heat-row.drop-target { background: var(--hl-bg); box-shadow: inset 0 0 0 1px var(--text); }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; margin: 0; background: var(--surface); border: 1px solid var(--text); box-shadow: 0 6px 18px rgb(0 0 0 / 0.35); }

.champion { display: flex; align-items: center; gap: 16px; padding: 16px 20px; margin: 16px 0; border: 1px solid var(--shell-line); }
.champion .icon { width: 30px; height: 30px; color: var(--lime); }
.champion h2 { margin: 0; font-size: var(--fs-h2); }
.champion a { color: var(--on-shell); }
.champion a:hover { color: var(--lime); }
.champion .meta { color: var(--on-shell-muted); }

/* ---------- focus bar (find / filter / I am) ---------- */
.focus-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 14px; margin: 14px 0; background: var(--surface); border: 1px solid var(--border); }
.focus-bar input[type=search] { flex: 1 1 220px; min-width: 0; }
.focus-bar .check, .focus-bar .field-inline { font-size: var(--fs-sm); color: var(--text); }
.focus-bar .field-inline { display: inline-flex; align-items: center; gap: 8px; }
.focus-bar .count { font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---------- long-form text: rules ---------- */
.prose { line-height: 1.6; }
.prose > :is(p, ul, ol, blockquote, h2, h3, h4) { max-width: 72ch; }
.prose h2 { margin: 1.6em 0 0.4em; scroll-margin-top: 80px; }
.prose h3 { margin: 1.4em 0 0.3em; scroll-margin-top: 80px; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 0.9em; }
.prose li + li { margin-top: 0.3em; }
.prose blockquote { margin: 0 0 1em; padding: 10px 14px; border: 1px solid var(--border); background: var(--surface); }
.prose table.data { margin-bottom: 1em; }
.prose .points-table { width: auto; min-width: 220px; }
.prose .rules-races td { white-space: normal; vertical-align: top; }
.prose .rules-races td:first-child, .prose .rules-races td:nth-child(2) { min-width: 150px; }
.prose .rules-races td:nth-child(3) { min-width: 260px; max-width: 46ch; }
.toc { margin: 0 0 24px; padding: 12px 16px; border: 1px solid var(--border); background: var(--surface); max-width: 72ch; }
.toc h2 { font-size: 1.25rem; margin: 0; }
.toc ul { margin: 6px 0 0; padding-left: 18px; columns: 2; }
.toc a { display: inline-block; padding: 10px 0; }
.rules-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.rules-editor .prose { max-height: 70vh; overflow: auto; }
@media (max-width: 900px) { .rules-editor { grid-template-columns: 1fr; } .toc ul { columns: 1; } }

/* ---------- admin bits ---------- */
details.section { background: var(--surface); border: 1px solid var(--border); margin-top: 16px; }
details.section > summary { cursor: pointer; padding: 14px 18px; font-family: var(--font-display); font-size: 1.25rem; font-weight: 500; letter-spacing: -0.02em; color: var(--heading); display: flex; align-items: center; gap: 10px; min-height: 52px; list-style: none; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform 150ms ease-out; flex: none; }
details.section[open] > summary::before { transform: rotate(45deg); }
details.section > summary .muted { font-family: var(--font); font-size: var(--fs-sm); font-weight: 400; letter-spacing: 0; }
details.section > .body { padding: 0 18px 18px; }
details.section > .body > * + * { margin-top: 12px; }
#paste { font-family: var(--font-mono); font-size: var(--fs-sm); white-space: pre; tab-size: 18; }
.race-control { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.race-control h2 { margin: 0; }
.danger-zone { margin-top: 40px; border-color: var(--bad-ink); }
main[inert] { opacity: 0.65; cursor: progress; transition: opacity 150ms ease-out; }

dialog { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); padding: 20px; width: min(480px, 94vw); }
dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.pick-list { display: grid; gap: 8px; margin: 14px 0; }
.pick { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.pick-main { justify-content: flex-start; gap: 12px; min-height: 48px; text-align: left; font-weight: 600; text-transform: none; letter-spacing: 0; font-size: var(--fs-base); }
.pick-main .slot { min-width: 3.2em; font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.pick-main[aria-pressed="true"] { border: 2px solid var(--accent-line); background: var(--accent-tint); }
.pick.is-dnf .pick-main { color: var(--muted); }
.pick.is-dnf .pick-main .slot { color: var(--bad-ink); }
.pick-dnf { min-height: 48px; }
.pick-dnf[aria-pressed="true"] { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-ink); }
kbd { font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 700; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--surface-2); }

code.seed { font-family: var(--font-mono); font-size: var(--fs-xs); word-break: break-all; white-space: normal; display: block; min-width: 16ch; max-width: 22ch; }
table.data td:has(> code.seed) { white-space: normal; }
.verify-ok { color: var(--ok-ink); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.verify-bad { color: var(--bad-ink); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }

/* ---------- device layouts: data-device="phone" | "pc" is set on <html> by index.html ---------- */
:root:not([data-device="phone"]) .only-phone { display: none; }
.layout { padding-top: 24px; padding-bottom: 64px; }
.layout > main { min-width: 0; }
.site-foot { border-top: 1px solid var(--border); }
.site-foot .wrap { display: flex; gap: 16px; padding-top: 4px; padding-bottom: 4px; }
.site-foot a { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.site-foot a:hover { color: var(--text); }

/* PC: main column plus a sticky side panel (your next heat, the next race, quick links). */
.side { display: none; }
:root[data-device="pc"] .layout.has-side { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 27vw, 340px); gap: 32px; align-items: start; }
:root[data-device="pc"] .layout.has-side > .side { display: grid; gap: 14px; position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; }
.side .next-heat { margin: 0; max-width: none; }
.side .next-heat .nh-code:not(.quiet) { font-size: 2.5rem; }
.side .card > h2 { font-size: var(--fs-h3); font-weight: 500; letter-spacing: -0.015em; margin: 0; }
.side-race { display: grid; gap: 6px; justify-items: start; text-decoration: none; }
.side-links ul { list-style: none; margin: 6px 0 0; padding: 0; }
.side-links a { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; text-decoration: none; border-top: 1px solid var(--border); }
.side-links li:first-child a { border-top: 0; }
.side-links a:hover { color: var(--accent-ink); }
.side-hint { margin: 0; color: var(--muted); font-size: var(--fs-sm); }

/* Phone: sections in a bottom tab bar within thumb reach; the header scrolls away. */
body { --tabbar-h: 0px; }
body.has-tabbar { --tabbar-h: 58px; }
:root[data-device="phone"] nav.main { display: none; }
:root[data-device="phone"] header.site { position: relative; }
/* The public header: the language menu and theme button sit at the right end. */
header.site .wrap > .lang-pick { margin-left: auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--shell-line); }
:root:not([data-device="phone"]) .tabbar { display: none; }
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px; text-decoration: none; color: var(--on-shell-muted); font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tabbar a .icon { width: 22px; height: 22px; }
.tabbar a:hover { color: var(--on-shell); }
.tabbar a::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--lime); transform: scaleX(0); }
.tabbar a[aria-current="page"] { color: var(--on-shell); }
.tabbar a[aria-current="page"]::before { transform: scaleX(1); }
.tabbar a[aria-current="page"] .icon { color: var(--lime); }
:root[data-device="phone"] body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* Phone: your next heat pinned above the tabs while the board and the heat are off screen. */
.pin { position: fixed; left: 10px; right: 10px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 19; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 14px; background: var(--me-bg); color: var(--on-me); text-decoration: none; box-shadow: 0 0 0 3px var(--bg); }
:root:not([data-device="phone"]) .pin { display: none; }
.pin:hover { color: var(--on-me); }
.pin:focus-visible { outline-color: var(--text); }
.pin .pin-code { font-family: var(--font-display); font-weight: 600; font-size: 1.375rem; letter-spacing: -0.03em; line-height: 1; white-space: nowrap; }
.pin .pin-code em { font-style: normal; }
.pin .pin-wait { flex: 1; min-width: 0; color: var(--me-muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
:root[data-device="phone"] body.has-pin { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 72px); }

/* Your race, under the board on the standings: the race title and its bracket with your racing line. */
.race-preview { margin: 0 0 24px; }
.race-preview > h2 { margin: 0; }
.race-preview > h2 a { text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }
.race-preview > h2 a:hover { text-decoration: underline; }
.race-preview > h2 .muted { font-size: var(--fs-h3); }
.race-preview .bracket-section { margin-top: 10px; }

/* ---------- motion: quick, square, and only in answer to something you did ----------
   Colour changes ease everywhere; movement is skipped for people who ask for reduced motion.
   Page-enter motion runs only while body.is-entering is set (a new page, never a live refresh). */
:root { --ease: cubic-bezier(.2, .7, .2, 1); --dur-fast: 150ms; --dur: 240ms; }
a, button, .btn, .chip, .card, .next-link, .heat, .heat-row, table.data td, select, input, textarea {
  transition: color var(--dur-fast) ease-out, background-color var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out, box-shadow var(--dur-fast) ease-out;
}
/* Rows you can open lift to the raised board colour on hover (your own and highlighted rows keep theirs). */
@media (hover: hover) {
  .heat-row:has(.nm > a):not(.is-me, .is-hl):hover { background: var(--surface-2); }
  table.data tbody tr:not(.is-me, .is-hl):hover td { background: var(--surface-2); }
}

@media (prefers-reduced-motion: no-preference) {
  /* Primary buttons: the lime fill wipes in from the left; a trailing arrow nudges forward. */
  button.primary, .btn.primary {
    background-image: linear-gradient(var(--accent), var(--accent)); background-repeat: no-repeat; background-size: 0% 100%;
    transition: background-size var(--dur) var(--ease), color var(--dur) ease-out, border-color var(--dur) ease-out;
  }
  button.primary:hover, .btn.primary:hover { background-color: var(--btn-bg); background-size: 100% 100%; }
  .shell button.primary:hover, .shell .btn.primary:hover { background-color: var(--grey-01); }
  :is(button, .btn, .side-links a, .pin) .icon { transition: transform var(--dur) var(--ease); }
  :is(button, .btn, .side-links a):hover > .icon:last-child:not(:first-child), .pin:hover > .icon { transform: translateX(4px); }
  .back a .icon { transition: transform var(--dur) var(--ease); }
  .back a:hover .icon { transform: translateX(-4px); }
  /* Press: everything you tap sinks a pixel. */
  :is(button, .btn, a.chip, .next-link, a.card, .pin, .tabbar a):active { transform: translateY(1px); }
  .tabbar a:active .icon { transform: scale(0.9); }

  /* Nav underlines grow from the left on hover (grey) and on the current page (lime). */
  nav.main a::after, .t-nav a::after { transition: transform var(--dur) var(--ease), background-color var(--dur-fast) ease-out; }
  nav.main a:not([aria-current="page"]):hover::after { transform: scaleX(1); background: var(--grey-04); }
  .tabbar a::before { transition: transform var(--dur) var(--ease); }

  /* Linked cards: the title picks up the blinking lime cursor. */
  a.card:hover :is(h2, h3)::after { content: "_" / ""; color: var(--accent-ink); animation: cursor-blink 1.2s steps(1) infinite; }

  /* Class tabs and the round pager: the fill follows your pick. */
  .tabs a, .tabs button, .round-pager button { transition: color var(--dur-fast) ease-out, background-color var(--dur) var(--ease), border-color var(--dur-fast) ease-out; }

  /* A new page: the title types itself out, then the rest rises into place in reading order. */
  body.is-entering .band h1 { animation: title-in 520ms var(--ease) both; }
  body.is-entering .band :is(.sub, .meta, .toolbar, .back, .format-line) { animation: rise-in 380ms var(--ease) 120ms both; }
  body.is-entering #view > * { animation: rise-in 380ms var(--ease) both; }
  body.is-entering #view > :nth-child(2) { animation-delay: 50ms; }
  body.is-entering #view > :nth-child(3) { animation-delay: 100ms; }
  body.is-entering #view > :nth-child(4) { animation-delay: 150ms; }
  body.is-entering #view > :nth-child(n + 5) { animation-delay: 200ms; }
  body.is-entering .side > * { animation: rise-in 380ms var(--ease) 140ms both; }
  body.is-entering .side > :nth-child(2) { animation-delay: 200ms; }
  body.is-entering .side > :nth-child(n + 3) { animation-delay: 260ms; }
  body.is-entering .rounds > .round-col { animation: slide-in 420ms var(--ease) both; }
  body.is-entering .rounds > .round-col:nth-child(2) { animation-delay: 70ms; }
  body.is-entering .rounds > .round-col:nth-child(3) { animation-delay: 140ms; }
  body.is-entering .rounds > .round-col:nth-child(n + 4) { animation-delay: 210ms; }
  body.is-entering table.data tbody tr { animation: rise-in 320ms var(--ease) both; }
  body.is-entering table.data tbody tr:nth-child(2) { animation-delay: 30ms; }
  body.is-entering table.data tbody tr:nth-child(3) { animation-delay: 60ms; }
  body.is-entering table.data tbody tr:nth-child(4) { animation-delay: 90ms; }
  body.is-entering table.data tbody tr:nth-child(5) { animation-delay: 120ms; }
  body.is-entering table.data tbody tr:nth-child(n + 6) { animation-delay: 150ms; }
  body.is-entering nav.main a[aria-current="page"]::after, body.is-entering .tabbar a[aria-current="page"]::before { animation: grow-x 360ms var(--ease) both; }
  /* Where a link landed you: the ring closes in on the heat or row. */
  body.is-entering .heat.is-target { animation: target-in 900ms var(--ease) 200ms both; }
  body.is-entering table.data tr.is-target td { animation: row-target-in 900ms var(--ease) 200ms both; }

  /* The pinned next heat slides up from the tab bar when it appears. */
  :root[data-device="phone"] .pin { animation: pin-in 320ms var(--ease); }
  /* Each live refresh pings the Live dot once. */
  .live-status:not(.is-stale)::before { animation: live-ping 1s ease-out; }
  .toast { animation: rise-in 260ms var(--ease); }
  details.section[open] > .body { animation: rise-in 240ms var(--ease); }
  #theme-toggle.is-switching .icon { animation: spin-in 420ms var(--ease); }

  /* Switching theme: the new theme wipes down over the old one. */
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
  ::view-transition-new(root) { animation: theme-wipe 480ms var(--ease); }
}
@keyframes title-in { from { clip-path: inset(-0.2em 100% -0.3em 0); } to { clip-path: inset(-0.2em -1ch -0.3em 0); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes pin-in { from { opacity: 0; transform: translateY(calc(100% + 12px)); } }
@keyframes target-in { from { box-shadow: 0 0 0 14px transparent; } 40% { box-shadow: 0 0 0 7px var(--hl-bg); } }
@keyframes row-target-in { 0%, 45% { background-color: var(--hl-bg); } }
@keyframes live-ping { from { box-shadow: 0 0 0 0 rgb(156 255 7 / 0.7); } to { box-shadow: 0 0 0 7px rgb(156 255 7 / 0); } }
@keyframes spin-in { from { transform: rotate(-90deg); opacity: 0; } }
@keyframes theme-wipe { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }

/* Wider screens give the racing line room to run between rounds. */
@media (min-width: 900px) { .rounds { gap: 40px; } }

/* Venue screen: on a wide display the bracket packs tighter so a whole class fits. */
@media (min-width: 1400px) {
  .wrap { max-width: 1360px; }
  .round-col { min-width: 220px; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

@media print {
  header.site, .no-print, .focus-bar, .toast-host, .skip-link, .race-line { display: none !important; }
  :root { --bg: #fff; --surface: #fff; --text: #000; --heading: #000; --muted: #333; --ground-grain: none; }
  body { background: #fff; color: #000; }
  .band, .champion { background: none; color: #000; padding: 0 0 12px; border: 0; }
  .band h1::after { display: none; }
  .band :is(a, p, .sub, .meta) { color: #000; }
  main.wrap, .layout { padding: 0; display: block; }
  .side, .pin, .tabbar, .round-pager { display: none !important; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- Japanese and Thai ---------- */
/* The house faces carry Latin only. Japanese and Thai text uses IBM Plex (self-hosted, one family for both
   scripts), so it looks the same on every device; names and numbers in Latin keep the house faces. The
   system fonts after Plex only cover the moment before it loads. */
:root:lang(ja) {
  --font-ja: "IBM Plex Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  --font: Geist, var(--font-ja);
  --font-display: "Stack Sans Notch", Geist, var(--font-ja);
  --font-mono: "Atkinson Hyperlegible Mono", var(--font-ja);
}
:root:lang(th) {
  --font-th: "IBM Plex Sans Thai", "Noto Sans Thai", "Noto Sans Thai UI", Thonburi, "Sukhumvit Set", "Leelawadee UI", Leelawadee, Tahoma, sans-serif;
  --font: Geist, var(--font-th);
  --font-display: "Stack Sans Notch", Geist, var(--font-th);
  --font-mono: "Atkinson Hyperlegible Mono", var(--font-th);
}
/* Tracking is tuned for the Latin faces: in Japanese it scatters the characters, and in Thai it pulls
   vowel and tone marks away from their letters. */
:root:lang(ja) body *, :root:lang(th) body * { letter-spacing: 0 !important; }
/* Thai marks sit above and below the line, and Japanese needs more air than the tight display leading. */
:root:lang(ja) :is(h1, h2, h3) { line-height: 1.3; word-break: auto-phrase; overflow-wrap: anywhere; }
:root:lang(th) :is(h1, h2, h3) { line-height: 1.4; }
:root:lang(ja) :is(.pos, .rk, .nh-code, .pin-code, .race-item .no),
:root:lang(th) :is(.pos, .rk, .nh-code, .pin-code, .race-item .no) { line-height: 1.25; }
:root:lang(th) body { line-height: 1.65; }
/* Japanese characters are each about a square wide, so the text-only next-heat heading steps down to fit a
   whole phrase on a line in the narrow side column. */
:root:lang(ja) .next-heat .nh-code.quiet { font-size: 1.5rem; }
