:root {
  /* colour */
  --bg: #fff;
  --fg: #1b1f24;
  --muted: #59616b;
  --line: #d9dde2;
  --tint: #eef1f5;
  --accent: #1d4ed8;
  --on-accent: #fff;
  --accent-tint: #dbe5ff;
  /* the article keeps a light surface in both schemes: Wikipedia markup carries inline colours */
  --paper: #fff;
  --paper-fg: #202122;
  --paper-muted: #54595d;
  --paper-line: #c8ccd1;
  --paper-tint: #f2f4f7;
  /* spacing, radius, type */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem; --s6: 1.5rem; --s8: 2rem; --s12: 3rem;
  --r: 6px;
  --t-sm: .875rem; --t-md: 1rem; --t-lg: 1.25rem; --t-xl: 1.75rem; --t-code: clamp(2.5rem, 12vw, 4rem);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --motion: 180ms;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --fg: #e6e8eb; --muted: #a3abb5; --line: #343a42; --tint: #1e232a;
    --accent: #8ab4ff; --on-accent: #0b1220; --accent-tint: #26385c;
  }
}
@media (prefers-reduced-motion: reduce) { :root { --motion: 0s; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* keep their space so the bar does not jump when they appear (layout shift) */
.topbar button[hidden] { display: inline-block !important; visibility: hidden; }
body { margin: 0; background: var(--bg); color: var(--fg); font: var(--t-md)/1.5 var(--font); }
h1, h2 { text-wrap: balance; line-height: 1.2; margin: 0; }
h1 { font-size: var(--t-xl); }
h2 { font-size: var(--t-lg); margin-top: var(--s8); margin-bottom: var(--s3); }
p { margin: 0; }
.mono, .num { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.plain { list-style: none; margin: 0; padding: 0; }
.label { color: var(--muted); font-size: var(--t-sm); }
.note { color: var(--muted); font-size: var(--t-sm); }

/* header */
.site { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s3) var(--s4); }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; }
.site-actions { display: flex; align-items: center; gap: var(--s3); }

/* controls */
button, input, select { font: inherit; color: inherit; }
button {
  min-height: 2.5rem; padding: 0 var(--s4); border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line); background: var(--bg);
  transition: background-color var(--motion), color var(--motion), opacity var(--motion);
}
button:hover:not(:disabled) { background: var(--tint); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); opacity: .9; }
button.quiet { border-color: transparent; color: var(--muted); }
button.quiet:hover:not(:disabled) { color: var(--fg); }
.seg { display: flex; }
.seg button { min-height: 2rem; padding: 0 var(--s3); border-radius: 0; }
.seg button:first-child { border-radius: var(--r) 0 0 var(--r); }
.seg button:last-child { border-radius: 0 var(--r) var(--r) 0; border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select { min-height: 2.5rem; width: 100%; padding: 0 var(--s3); border-radius: var(--r); border: 1px solid var(--line); background: var(--bg); }
input[type="checkbox"] { width: 1.1rem; min-height: 0; height: 1.1rem; accent-color: var(--accent); }
input:disabled, select:disabled { background: var(--tint); color: var(--fg); opacity: 1; border-color: transparent; }
.field { display: grid; gap: var(--s1); }
.field label { font-size: var(--t-sm); color: var(--muted); }
.check { display: flex; align-items: center; gap: var(--s2); }
.with-btn { display: flex; gap: var(--s2); }
.with-btn button { flex: none; }

/* views */
main { padding: 0 var(--s4) var(--s12); }
.view { margin: 0 auto; display: grid; gap: var(--s4); align-content: start; }
.narrow { max-width: 34rem; }
.wide { max-width: 80rem; }
#view-home { gap: var(--s6); padding-top: var(--s8); }
.lead { color: var(--muted); }
.join { display: flex; align-items: end; gap: var(--s2); }
.join .field { flex: 1; }
.code-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }
.code { font-size: var(--t-code); line-height: 1; letter-spacing: .02em; overflow-wrap: anywhere; }
.settings { display: grid; gap: var(--s4); }
.actions { display: grid; gap: var(--s2); justify-items: start; margin-top: var(--s4); }
.players { display: grid; gap: var(--s2); }
.players li { display: flex; gap: var(--s3); align-items: baseline; }
.players .off { color: var(--muted); }
.tag { color: var(--muted); font-size: var(--t-sm); }

/* race */
.topbar {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s6); padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}
.topbar .goal { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.topbar .stat { white-space: nowrap; }
.topbar .stat .num { font-size: var(--t-lg); }
.finish { font-weight: 600; }
.race-players { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s6); font-size: var(--t-sm); color: var(--muted); }
.race-players .me { color: var(--fg); }
.stage { position: relative; }
.article {
  background: var(--paper); color: var(--paper-fg); border-radius: var(--r);
  padding: var(--s6) var(--s4); min-height: 70vh; overflow-wrap: break-word;
}
.article > * { max-width: 72ch; margin-left: auto; margin-right: auto; }
.article[aria-busy="true"] .article-body { opacity: .45; }
.article-body { transition: opacity var(--motion); line-height: 1.65; }
#article-title { font-size: var(--t-xl); margin-bottom: var(--s4); outline: none; }
.article a[data-to] { color: #1d4ed8; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; cursor: pointer; }
.article a[data-to].is-target { background: #dbe5ff; font-weight: 600; border-radius: 2px; }
.article-body img { max-width: 100%; height: auto; }
.article-body h2, .article-body h3 { margin: var(--s6) 0 var(--s2); }
.article-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.article-body th, .article-body td { border: 1px solid var(--paper-line); padding: var(--s1) var(--s2); }
.article-body .infobox, .article-body table.infobox { float: none; width: 100%; background: var(--paper-tint); font-size: var(--t-sm); margin: 0 0 var(--s4); }
/* fixed layout: wide images inside (maps) shrink to the box instead of overflowing it */
.article-body table.infobox { display: table; table-layout: fixed; overflow: visible; }
.article-body figure { margin: 0 0 var(--s4); max-width: 100%; }
.article-body figcaption { font-size: var(--t-sm); color: var(--paper-muted); }
.article-body ul, .article-body ol { padding-left: var(--s6); }
@media (min-width: 52rem) {
  .article { padding: var(--s8); }
  .article-body .infobox, .article-body table.infobox { float: right; width: 20rem; margin: 0 0 var(--s4) var(--s6); }
  .article-body figure { float: right; width: 18rem; margin: 0 0 var(--s4) var(--s6); }
  .article-body figure.mw-halign-left { float: left; margin: 0 var(--s6) var(--s4) 0; }
  .article-body figure.mw-halign-none, .article-body figure.mw-halign-center { float: none; width: auto; margin-left: auto; margin-right: auto; }
}
.countdown { position: absolute; inset: 0; display: grid; place-items: center; background: var(--paper); border-radius: var(--r); }
.countdown .num { font-size: clamp(6rem, 30vw, 14rem); color: var(--paper-fg); line-height: 1; }

/* results */
.route { color: var(--muted); }
.results { width: 100%; border-collapse: collapse; }
.results th { text-align: left; font-weight: 400; color: var(--muted); font-size: var(--t-sm); padding: var(--s2) var(--s2) var(--s2) 0; }
.results td { padding: var(--s2) var(--s2) var(--s2) 0; vertical-align: top; }
.results .r { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; }
.results td.r { font-family: var(--mono); }
.results details summary { cursor: pointer; border-radius: var(--r); }
.results .path { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); }
.results .path .bk { font-style: normal; }

/* feedback */
.toast {
  position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%); max-width: min(30rem, calc(100vw - 2rem));
  padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--fg); color: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity var(--motion);
}
.toast.show { opacity: 1; }
