:root {
  --paper: #ffffff;
  --sheet: #eef2f7;
  --rule: #cfd8e3;
  --rule-strong: #0b1f3a;
  --ink: #0b1f3a;
  --ink-soft: #55657d;
  --red: #d7141a;
  --red-wash: #fbe9ea;
  --blue: #11457e;
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1626;
    --sheet: #162138;
    --rule: #2b3b5a;
    --rule-strong: #e8eef7;
    --ink: #e8eef7;
    --ink-soft: #a7b4ca;
    --red: #ff5f63;
    --red-wash: #3a1b22;
    --blue: #8fbcff;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 16px 40px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-variation-settings: 'wdth' 100;
  font-variant-numeric: tabular-nums;
}

a { color: var(--blue); }

abbr[title] { text-decoration: none; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Masthead ---------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 32px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 0 14px;
  border-bottom: 3px solid var(--rule-strong);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 64px);
  font-weight: 800;
  font-variation-settings: 'wdth' 62;
  letter-spacing: -0.01em;
  line-height: 0.92;
}

.masthead__sub {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.nation {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 14px;
}

.nation select {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 6px 10px;
  max-width: min(100%, 320px);
}

.days {
  display: flex;
  gap: 4px;
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 52px;
  padding: 6px 8px 2px;
  border-bottom: 4px solid transparent;
  color: var(--ink);
  text-decoration: none;
  font-size: 36px;
  font-weight: 700;
  font-variation-settings: 'wdth' 62;
  line-height: 1;
}

.day__label {
  font-size: 11px;
  font-weight: 500;
  font-variation-settings: 'wdth' 100;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.day.is-future { color: var(--ink-soft); opacity: 0.55; }
.day:hover { border-bottom-color: var(--rule); }
.day.is-current { color: var(--red); border-bottom-color: var(--red); opacity: 1; }
.day.is-current .day__label { color: var(--red); }

.masthead__nav {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.views {
  display: inline-flex;
  border: 1px solid var(--rule);
}

.view {
  padding: 6px 16px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.view + .view { border-left: 1px solid var(--rule); }
.view.is-current { background: var(--rule-strong); color: var(--paper); }

/* Status ------------------------------------------------------------ */

.status {
  max-width: 1400px;
  margin: 10px auto 22px;
  color: var(--ink-soft);
  font-size: 14px;
}

.status[data-tone='warn'] { color: var(--red); }

/* Groups and table -------------------------------------------------- */

main { max-width: 1400px; margin: 0 auto; }

.group + .group { margin-top: 40px; }

.group__title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 700;
  font-variation-settings: 'wdth' 75;
  line-height: 1.1;
}

.group__count {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 400;
  font-variation-settings: 'wdth' 100;
}

.empty {
  margin: 0;
  padding: 18px 0;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.sheet th,
.sheet td {
  padding: 8px 10px;
  vertical-align: top;
  text-align: right;
  white-space: nowrap;
}

.sheet thead th {
  border-bottom: 2px solid var(--rule-strong);
  padding-bottom: 6px;
  font-weight: 600;
  font-size: 13px;
}

.sheet tbody tr { border-bottom: 1px solid var(--rule); }
.sheet tbody tr:last-child { border-bottom: 2px solid var(--rule-strong); }

.sheet .c-rider,
.sheet .c-cls,
.sheet .c-day,
.sheet .c-overall { text-align: left; }

.sheet thead .c-test { text-align: right; }

.test-code { display: block; }
.test-name {
  display: block;
  color: var(--ink-soft);
  font-weight: 400;
  font-size: 11px;
}

/* sticky first columns so phones can scroll the tests */
.sheet .c-pos,
.sheet .c-rider {
  position: sticky;
  background: var(--paper);
  z-index: 1;
}
.sheet .c-pos { left: 0; min-width: 56px; }
.sheet .c-rider { left: 56px; }
.sheet .c-rider::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 1px;
  background: var(--rule);
}

.sheet .c-pos .pos,
.sheet .c-overall .pos {
  display: block;
  font-size: 22px;
  font-weight: 700;
  font-variation-settings: 'wdth' 68;
  line-height: 1;
  margin-bottom: 3px;
}

.sheet .c-overall .pos { display: inline-block; margin-right: 8px; vertical-align: -2px; }

.sheet .num {
  display: inline-block;
  min-width: 2.4em;
  margin-right: 6px;
  color: var(--ink-soft);
  font-weight: 600;
}

.sheet .name { font-weight: 600; }
.sheet .flag { margin-left: 4px; font-size: 13px; }

.sheet .t { display: block; }

.sheet .sub {
  display: block;
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.3;
  margin-top: 2px;
  white-space: nowrap;
}

.sheet .c-rider .sub { white-space: normal; max-width: 260px; }

.sheet .c-test.is-best { background: var(--red-wash); }
.sheet .c-test.is-best .t { color: var(--red); font-weight: 700; }

.sheet .c-day .t { font-weight: 600; }
.sheet .sub.pen { color: var(--red); }

.muted { color: var(--ink-soft); }

.sheet tr.is-ns td,
.sheet tr.is-out td { color: var(--ink-soft); }
.sheet tr.is-out .name { text-decoration: line-through; text-decoration-thickness: 1px; }
.sheet tr.is-ns .name,
.sheet tr.is-out .name { color: var(--ink-soft); }

/* Legend ------------------------------------------------------------ */

.legend {
  max-width: 1400px;
  margin: 36px auto 0;
  color: var(--ink-soft);
  font-size: 13px;
  max-width: 78ch;
}

.legend p { margin: 0 0 8px; }

/* Small screens ----------------------------------------------------- */

/* Teams ------------------------------------------------------------- */

.summary {
  margin: 0 0 32px;
  padding: 14px 18px;
  border-left: 4px solid var(--red);
  background: var(--sheet);
}

.summary__title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  font-variation-settings: 'wdth' 75;
  line-height: 1.1;
}

.summary__list { margin: 0; padding-left: 1.2em; }
.summary__list li { margin: 2px 0; }
.summary__empty { margin: 0; color: var(--ink-soft); }

.stage-note {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.stages {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 10px;
}

.stage {
  font: inherit;
  font-size: 13px;
  padding: 4px 9px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.stage.is-current { border-color: var(--red); color: var(--red); font-weight: 600; }
.stage:disabled { opacity: 0.45; cursor: default; }
.stage__count { margin-left: 5px; color: var(--ink-soft); font-size: 11px; }

.sheet.teams .c-pos { position: static; }
.sheet.teams .c-team { text-align: left; white-space: normal; min-width: 220px; }
.sheet.teams .c-team .sub { white-space: normal; }
.sheet.teams .c-gap { color: var(--ink-soft); }
.sheet.teams tr.is-mine .c-pos { box-shadow: inset 3px 0 0 var(--red); }
.sheet.teams tr.is-mine .name { color: var(--red); }

@media (max-width: 640px) {
  .masthead { padding-top: 18px; }
  .masthead__nav { width: 100%; align-items: stretch; }
  .views { align-self: flex-start; }
  .days { width: 100%; justify-content: space-between; }
  .day { min-width: 0; flex: 1; font-size: 30px; }
  .sheet th, .sheet td { padding: 7px 7px; }
  .sheet .c-pos { min-width: 48px; }
  .sheet .c-rider { left: 48px; }
  .sheet .c-rider .sub { max-width: 170px; }
}

/* Rider panel ------------------------------------------------------- */

.rider-panel { padding: 4px 0 6px; }

.rider-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}

.rider-panel__name {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  font-variation-settings: 'wdth' 75;
  line-height: 1.1;
}

.rider-panel__name .num { font-size: 18px; }
.rider-panel__meta { margin: 4px 0 0; color: var(--ink-soft); font-size: 14px; }
.rider-panel__out { margin: 4px 0 0; color: var(--red); font-size: 14px; }

.rider-panel__close {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.rider-grid .c-dayno { text-align: left; min-width: 48px; }
.rider-grid .c-dayno .pos { display: block; font-size: 22px; font-weight: 700; font-variation-settings: 'wdth' 68; line-height: 1; }
.rider-grid .c-day .pos,
.rider-grid .c-overall .pos { display: inline-block; margin-right: 8px; vertical-align: -2px; }
.rider-grid .c-day { min-width: 150px; }

.sheet a.name { color: inherit; text-decoration: none; }
.sheet a.name:hover { text-decoration: underline; color: var(--blue); }
.sheet .c-team .sub a { color: inherit; }
.out { color: var(--red); }

/* On wide screens the tables fit, so the header can stick to the viewport. */
@media (min-width: 1200px) {
  .table-wrap { overflow: visible; }
  .sheet thead th { position: sticky; top: 0; background: var(--paper); z-index: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
