/* Mobile-first, high contrast, readable outdoors. Light/dark via prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #475569;
  --surface: #f1f5f9;
  --surface-2: #dde3ea;
  --border: #8a96a8;
  --ok: #15803d;
  --ok-fg: #ffffff;
  --warn: #c2410c;
  --warn-fg: #ffffff;
  --bad: #b91c1c;
  --bad-fg: #ffffff;
  --info: #1d4ed8;
  --info-fg: #ffffff;
  --accent: #334155;
  --accent-fg: #ffffff;
  --accent-soft: #e2e8f0;
  --dock-h: 0px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #05070a;
    --fg: #f8fafc;
    --muted: #a7b4c4;
    --surface: #131921;
    --surface-2: #232d3a;
    --border: #5b6b80;
    --ok: #22c55e;
    --ok-fg: #03140a;
    --warn: #fb923c;
    --warn-fg: #1c0b00;
    --bad: #f87171;
    --bad-fg: #1f0000;
    --info: #60a5fa;
    --info-fg: #020c1f;
    --accent: #a5b4c8;
    --accent-fg: #05070a;
    --accent-soft: #1b2330;
  }
}

/* Each role gets its own colour so nobody uses the wrong page */
body[data-role="start"] { --accent: #0b7a35; --accent-fg: #ffffff; --accent-soft: #dcfce7; }
body[data-role="finish"] { --accent: #1d4ed8; --accent-fg: #ffffff; --accent-soft: #dbeafe; }
body[data-role="results"] { --accent: #0f766e; --accent-fg: #ffffff; --accent-soft: #ccfbf1; }
@media (prefers-color-scheme: dark) {
  body[data-role="start"] { --accent: #22c55e; --accent-fg: #03140a; --accent-soft: #0a2615; }
  body[data-role="finish"] { --accent: #60a5fa; --accent-fg: #020c1f; --accent-soft: #0b1b38; }
  body[data-role="results"] { --accent: #2dd4bf; --accent-fg: #021512; --accent-soft: #062824; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.console-root { overscroll-behavior: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.35 var(--font);
}
body.console {
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.console input { -webkit-user-select: text; user-select: text; }
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
input, select, textarea { font-size: 17px; }
[hidden] { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
a { color: inherit; }

/* ---------- header bar ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); }
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--accent);
  color: var(--accent-fg);
}
/* Fixed height: a longer status pill must never push the list down under a thumb */
body.console .bar { height: calc(60px + max(0px, env(safe-area-inset-top) - 8px)); }
.bar h1 { flex: none; margin: 0; font-size: 32px; font-weight: 900; letter-spacing: .06em; line-height: 1; }
.bar .where { min-width: 0; overflow: hidden; white-space: nowrap; font-size: 12px; font-weight: 700; line-height: 1.15; opacity: .92; }
.bar .pill { flex: none; }
.bar .spacer { flex: 1; }
.bar .jump {
  font-size: 14px; font-weight: 800; text-decoration: none; white-space: nowrap;
  padding: 6px 10px; border-radius: 999px; border: 2px solid currentColor;
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  background: var(--surface-2);
}
.pill.ok { background: var(--ok); color: var(--ok-fg); }
.pill.warn { background: var(--warn); color: var(--warn-fg); }
.pill.bad { background: var(--bad); color: var(--bad-fg); }

/* ---------- search ---------- */
.searchrow { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--surface-2); background: var(--bg); }
.searchrow input {
  flex: 1;
  min-width: 0;
  height: 50px;
  padding: 0 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  font-weight: 700;
}
.searchrow .kbd {
  flex: none; width: 64px; height: 50px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--bg); font-weight: 800; font-size: 15px;
}

/* ---------- start: batch tray ---------- */
.tray {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 64px;
  padding: 0 12px;
  background: var(--accent-soft);
  border-bottom: 3px solid var(--accent);
}
.tray .label { flex: none; max-width: 40%; font-size: 12px; font-weight: 800; line-height: 1.15; }
.tray .label b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; }
.tray .chips { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; height: 100%; align-items: center; }
.tray .chips::-webkit-scrollbar { display: none; }
.tray .empty { color: var(--muted); font-weight: 600; font-size: 15px; }
.chip {
  flex: none;
  height: 46px;
  min-width: 56px;
  padding: 0 10px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: var(--bg);
  font-size: 17px;
  font-weight: 900;
  white-space: nowrap;
}
.chip small { font-size: 14px; font-weight: 600; opacity: .6; margin-left: 4px; }
.undo-btn {
  flex: none;
  height: 48px;
  padding: 0 12px;
  border-radius: 10px;
  border: 3px solid var(--bad);
  background: var(--bg);
  color: var(--bad);
  font-weight: 900;
  font-size: 15px;
  line-height: 1.05;
}

/* ---------- start: runner grid ---------- */
main { padding-bottom: calc(var(--dock-h) + 28px); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  padding: 4px 12px 12px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  min-width: 0;
}
.tile .tname { font-size: 19px; font-weight: 800; line-height: 1.15; text-align: center; overflow-wrap: break-word; }
.tile:active { transform: scale(.96); }
.tile.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.plan-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .02em;
}
.addall {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: var(--bg);
  color: var(--fg);
  font-weight: 800;
  font-size: 14px;
}
.addall.on { background: var(--accent-soft); }
.note-row {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}
.empty-state { grid-column: 1 / -1; padding: 24px 12px; text-align: center; color: var(--muted); font-weight: 600; }

/* ---------- climbing waves ---------- */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 18px 12px 8px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.wave { margin: 0 12px 10px; padding: 10px 12px; border: 2px solid var(--surface-2); border-radius: 14px; }
.wave-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wave-head b { font-size: 19px; }
.wave-head .at { color: var(--muted); font-size: 14px; }
.wave-head .clock { margin-left: auto; font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.wave .bibs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.wave .bibs span { min-width: 42px; padding: 4px 8px; border-radius: 8px; background: var(--surface); text-align: center; font-weight: 800; }
.wave .bibs span.fin { opacity: .45; text-decoration: line-through; }

/* ---------- bottom dock (GO bar + debug footer) ---------- */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--bg);
  border-top: 2px solid var(--surface-2);
  padding-bottom: env(safe-area-inset-bottom);
}
.gobar {
  display: flex;
  gap: 12px;
  padding: 14px 12px 6px;
  background: var(--surface);
  border-top: 4px solid var(--border);
}
.gobar .side { flex: none; width: 112px; display: flex; flex-direction: column; justify-content: center; gap: 8px; font-size: 13px; font-weight: 700; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; }
.switch input { width: 26px; height: 26px; margin: 0; accent-color: var(--accent); }
.go {
  flex: 1;
  height: 100px;
  border: none;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 54px;
  font-weight: 900;
  letter-spacing: .12em;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .3);
}
.go:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .3); }
.go:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; font-size: 20px; letter-spacing: 0; }
.debug {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.debug .more {
  margin-left: auto;
  min-width: 48px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
}
.clock-warn { color: var(--warn); font-weight: 800; }
.clock-bad { color: var(--bad); font-weight: 900; }
.dock-hint { margin: 8px 12px 0; padding: 8px 12px; border-radius: 10px; background: var(--warn); color: var(--warn-fg); font-weight: 700; font-size: 14px; }

/* ---------- start: countdown ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  text-align: center;
  padding: 16px;
}
.overlay .count { font-size: min(58vw, 46vh); font-weight: 900; line-height: .9; font-variant-numeric: tabular-nums; }
.overlay .count.go-now { font-size: min(36vw, 30vh); }
.overlay .info { font-size: 22px; font-weight: 800; }
.overlay .cancel {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  height: 68px;
  border-radius: 16px;
  border: 3px solid currentColor;
  background: transparent;
  font-size: 22px;
  font-weight: 900;
}

/* ---------- finish ---------- */
.callout {
  height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 14px;
  background: var(--accent-soft);
  border-bottom: 3px solid var(--accent);
  overflow: hidden;
}
.callout .idle { color: var(--muted); font-weight: 700; font-size: 16px; }
.callout .line { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; min-width: 0; }
.callout .line .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 24px; font-weight: 900; }
.callout .line .n small { display: block; font-size: 13px; font-weight: 700; color: var(--muted); }
.callout .line .t { font-size: 46px; font-weight: 900; font-variant-numeric: tabular-nums; }
.callout .line.older { opacity: .7; }
.callout .line.older .n, .callout .line.older .t { font-size: 20px; }
.group-title { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 12px 8px; font-weight: 900; font-size: 16px; }
.group-title .dim { font-weight: 700; font-size: 14px; }
.group-title .gl { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.group-title .gl small { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 13px; font-weight: 700; }
.ftiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 0 12px 6px; }
.ftile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  min-height: 100px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  text-align: left;
  min-width: 0;
}
.ftile:active { transform: scale(.97); }
/* Names get the full width; the ⋯ sits in the bottom corner beside the (short) time */
.ftile .tname { display: block; width: 100%; font-size: 21px; font-weight: 900; line-height: 1.12; overflow-wrap: break-word; }
.ftile .run { margin-top: 6px; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ftile .menu {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 14px 0 14px 0;
  background: var(--surface-2);
  color: var(--fg);
  font-size: 22px;
  line-height: 1;
}
.ftile.done { background: var(--ok); border-color: var(--ok); color: var(--ok-fg); }
.ftile.done .run { color: inherit; }
.ftile.done .run { font-size: 28px; font-weight: 900; }
.ftile.unseen { border-style: dashed; }
.ftile.unseen .run { color: var(--warn); font-size: 14px; }
.ftile.past { opacity: .75; }

details.box { margin: 14px 12px; border: 2px solid var(--surface-2); border-radius: 14px; overflow: hidden; }
details.box > summary { padding: 16px 14px; font-size: 18px; font-weight: 900; list-style: none; cursor: pointer; }
details.box > summary::-webkit-details-marker { display: none; }
details.box > summary::before { content: '▸ '; }
details.box[open] > summary::before { content: '▾ '; }
.row { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 6px 6px 6px 14px; border-top: 1px solid var(--surface-2); }
.row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; font-weight: 800; }
.row .n small { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.row .t { font-size: 21px; font-weight: 900; font-variant-numeric: tabular-nums; }
.row .menu { flex: none; width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 22px; }
.row.dnf .t { color: var(--bad); }

/* ---------- buttons, forms, dialogs ---------- */
.btn {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-weight: 800;
  font-size: 16px;
}
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--bad-fg); }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 14px; border-radius: 9px; }
.btn:disabled { opacity: .45; cursor: default; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 800; color: var(--muted); }
.field input, .field select, input.inline, select.inline {
  height: 46px;
  padding: 0 10px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 17px;
  font-weight: 600;
  min-width: 0;
}
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 10px 0; }
.form-row .grow { flex: 1; min-width: 140px; }
dialog.dlg {
  width: min(560px, calc(100vw - 20px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 18px;
  border: none;
  border-radius: 18px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
dialog.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg h2 { margin: 0 0 10px; font-size: 22px; }
.dlg h3 { margin: 18px 0 6px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg.menu .dlg-actions, .dlg.tools .dlg-actions { flex-direction: column; align-items: stretch; }
.dlg.menu .dlg-actions .btn { min-height: 62px; font-size: 20px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0; font-size: 15px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
#toasts {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--dock-h) + 12px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast { max-width: 540px; padding: 12px 16px; border-radius: 12px; background: var(--fg); color: var(--bg); font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
.toast.warn { background: var(--warn); color: var(--warn-fg); }
.toast.bad { background: var(--bad); color: var(--bad-fg); }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--surface-2); scrollbar-width: none; }
.tabs button {
  flex: none;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--bg);
  font-weight: 800;
}
.tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.panel { max-width: 1200px; margin: 0 auto; padding: 12px; }
.panel h2 { font-size: 20px; margin: 18px 0 8px; }
.panel p { margin: 6px 0; }
.counts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.counts span { padding: 6px 10px; border-radius: 10px; background: var(--surface); font-weight: 800; }
.table-wrap { overflow-x: auto; border: 1px solid var(--surface-2); border-radius: 12px; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--surface-2); text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: var(--surface); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 900; white-space: nowrap; }
.badge.not_started { background: var(--surface-2); color: var(--fg); }
.badge.climbing { background: var(--info); color: var(--info-fg); }
.badge.finished { background: var(--ok); color: var(--ok-fg); }
.badge.dnf { background: var(--bad); color: var(--bad-fg); }
.badge.issue { background: var(--warn); color: var(--warn-fg); }
.history { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.history li { padding: 6px 0; border-top: 1px solid var(--surface-2); font-variant-numeric: tabular-nums; }
.history li.undone { opacity: .55; text-decoration: line-through; }
.history small { color: var(--muted); }
.danger-zone { margin-top: 28px; padding: 14px; border: 2px solid var(--bad); border-radius: 14px; }
.msg { margin-top: 8px; font-weight: 700; }
.msg.bad { color: var(--bad); }
.msg.ok { color: var(--ok); }

/* ---------- results ---------- */
body[data-role="results"] { font-size: clamp(16px, 0.9vw + 10px, 34px); }
.results-bar h1 { font-size: 1.5em; letter-spacing: .02em; }
body[data-role="results"] .tabs button { height: 2.4em; font-size: .9em; }
.board-wrap { padding: 0 12px 40px; max-width: 1600px; margin: 0 auto; }
/* Fixed layout so the finished, climbing and DNF tables line up column for column */
.board { width: 100%; border-collapse: collapse; table-layout: fixed; }
.board th { padding: .5em .5em .3em; text-align: left; font-size: .7em; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.board td { padding: .45em .5em; border-bottom: 1px solid var(--surface-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board col.rank { width: 2.6em; }
.board col.cat { width: 20%; }
.board col.wavec { width: 12%; }
.board col.pred { width: 6.5em; }
.board col.time { width: 5.6em; }
.board col.diff { width: 6.4em; }
.board .rank { font-weight: 900; }
.board .time, .board th.time { text-align: right; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; }
.board .name { font-weight: 700; white-space: normal; overflow-wrap: break-word; }
.board .pred, .board th.pred { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.board .diff, .board th.diff { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.board td.diff.faster { color: var(--ok); }
.board tr.p1 .rank, .board tr.p2 .rank, .board tr.p3 .rank { color: var(--accent); }
.board tr.live td { color: var(--muted); }
.board tr.live .time { color: var(--fg); }
.board-title { margin: 1.2em 0 .3em; font-size: .85em; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.updated { font-size: .7em; opacity: .9; }

/* ---------- plain pages ---------- */
.plain .narrow { max-width: 560px; margin: 12vh auto; padding: 0 16px; }
.plain h1 { font-size: 28px; }
.plain .btn { display: inline-flex; align-items: center; text-decoration: none; }
