:root {
  color-scheme: light;
  --ink: #1f252b;
  --muted: #5c6670;
  --line: #d7dde3;
  --surface: #ffffff;
  --accent: #b8242f;
  --accent-dark: #7d1720;
  --track: #f2f5f7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.standings-shell {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 18px 12px 24px;
}

.standings-header {
  align-items: end;
  border-bottom: 3px solid var(--ink);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding-bottom: 12px;
}

.header-copy {
  min-width: 0;
}

.team-link {
  border: 2px solid var(--accent);
  color: var(--accent-dark);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  padding: 10px 12px;
  text-decoration: none;
}

.team-link:focus,
.team-link:hover {
  background: var(--accent);
  color: #ffffff;
}

.eyebrow,
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2 {
  margin: 4px 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.4rem;
}

.notice {
  border-left: 4px solid var(--accent);
  color: var(--muted);
  margin: 14px 0;
  padding: 8px 10px;
  background: #fff7f7;
}

.toolbar {
  margin: 16px 0 4px;
}

#rider-search {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

#rider-search:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.table-region {
  --category-color: var(--ink);
  --category-text-color: #ffffff;
  margin-top: 22px;
  width: 100%;
}

.table-region.is-hidden {
  display: none;
}

.table-region h2 {
  border-left: 6px solid var(--category-color);
  padding-left: 10px;
}

.table-scroll {
  border: 1px solid var(--line);
  border-top: 3px solid var(--category-color);
  overflow-x: auto;
  width: 100%;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--category-color);
  color: var(--category-text-color);
  font-size: 0.82rem;
  text-transform: uppercase;
}

tbody tr:nth-child(even) {
  background: var(--track);
}

.number,
.points,
.volunteer,
.race-result {
  text-align: right;
}

.name {
  font-weight: 700;
}

/* Position column: rank plus movement since the previous race. */
.pos {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank {
  font-weight: 700;
}

.move {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72rem;
  font-weight: 700;
}

.move-up {
  color: #1b7f3b;
}

.move-down {
  color: var(--accent-dark);
}

.move-new {
  background: #ffe08a;
  color: var(--ink);
  padding: 1px 5px;
}

.move-same {
  color: var(--muted);
}

/* Most recent race: emphasised so the freshest result reads first. */
.latest-tag {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

td.race-result.is-latest {
  background: #fff7e6;
  font-weight: 700;
}

tbody tr:nth-child(even) td.race-result.is-latest {
  background: #ffeccc;
}

/* Find-a-rider: filter to matching rows in place rather than scrolling to them,
   so the page stays put while typing. Non-matches are removed from the flow. */
tbody tr.is-hidden {
  display: none;
}

/* Keep position and name in view while paging through weeks (wide screens). */
@media (min-width: 641px) {
  .pos,
  .sticky-name {
    position: sticky;
    z-index: 2;
  }

  th.pos,
  td.pos {
    left: 0;
    width: 56px;
    min-width: 56px;
  }

  /* Offsets are measured at runtime (updateStickyOffsets) because the Pos and
     name columns size to their content. Fallbacks cover the first paint. */
  th.sticky-col-1,
  td.sticky-col-1 {
    left: var(--sticky-col1-left, 56px);
  }

  th.sticky-col-2,
  td.sticky-col-2 {
    left: var(--sticky-col2-left, 176px);
  }

  td.pos,
  td.sticky-name {
    background: var(--surface);
  }

  tbody tr:nth-child(even) td.pos,
  tbody tr:nth-child(even) td.sticky-name {
    background: var(--track);
  }

  th.pos,
  th.sticky-name {
    z-index: 3;
  }
}

.empty {
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

@media (max-width: 640px) {
  .standings-shell {
    padding: 14px 8px 20px;
  }

  .standings-header {
    align-items: start;
    flex-direction: column;
  }

  h1 {
    font-size: 1.55rem;
  }

  /* Each rider becomes a card instead of a row in a 760px-wide table. */
  .table-scroll {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
  }

  tbody tr {
    padding: 10px 12px;
    border-bottom: 2px solid var(--line);
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 3px 0;
    border: none;
    white-space: normal;
    text-align: right;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
  }

  td.pos {
    justify-content: flex-start;
    gap: 8px;
    align-items: baseline;
    font-size: 1.1rem;
  }

  td.pos::before {
    content: "#";
  }

  td.name {
    font-size: 1.05rem;
  }

  td.total {
    font-size: 1.1rem;
    font-weight: 700;
  }

  td.race-result.is-latest::before {
    color: var(--accent-dark);
  }
}
