/* Race to Bognor — design 2a: navy header · cream body */
:root {
  --navy: #1e1450;
  --cream: #f8f4ea;
  --cream-head: #f1ebdc;
  --tabbar-bg: #fdfaf2;
  --line: #ebe3d2;
  --line-strong: #e3dac6;
  --ink: #1e1450;
  --ink-2: #4a4560;
  --ink-3: #5d5870;
  --ink-4: #6e6880;
  --avatar: #e6e1ef;
  --same: #b3aec0;
  --up: oklch(0.55 0.15 150);
  --down: oklch(0.55 0.18 27);

  --tabbar-h: 72px;
  --lb-cols: 44px minmax(0, 1fr) 38px 36px 26px 30px;
  --maxw: 720px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

ol, ul { list-style: none; margin: 0; padding: 0; }

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

/* ---------- Header ---------- */
.site-header {
  position: relative;
  overflow: hidden;
  background: var(--navy);
  color: var(--cream);
  padding: calc(24px + env(safe-area-inset-top)) 0 24px;
}
/* Design 4a: two faint contour rings in the top-right corner */
.site-header::before,
.site-header::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.site-header::before { right: -90px; top: -70px; width: 300px; height: 300px; border: 1px solid rgba(248, 244, 234, 0.10); }
.site-header::after { right: -50px; top: -30px; width: 220px; height: 220px; border: 1px solid rgba(248, 244, 234, 0.12); }
.site-header .wrap { position: relative; }
.site-header__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}
.brand__mark { flex: none; display: block; }
.brand__name {
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 19px;
  line-height: 1;
  letter-spacing: -0.02em;
}
.admin-btn {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid rgba(248, 244, 234, 0.55);
  border-radius: 999px;
  color: var(--cream);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.admin-btn:hover { background: rgba(248, 244, 234, 0.12); }

.site-header h1 {
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 26px 0 8px;
}
.subtitle { margin: 0; font-size: 13px; opacity: 0.85; }

/* ---------- Leaderboard ---------- */
.lb-head,
.lb-row {
  display: grid;
  grid-template-columns: var(--lb-cols);
  gap: 6px;
  align-items: center;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}
.lb-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: 10px;
  padding-bottom: 10px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  /* full-bleed background even when the grid is width-capped */
  background: var(--cream-head);
  box-shadow: 0 0 0 100vmax var(--cream-head);
  clip-path: inset(0 -100vmax);
  border-bottom: 1px solid var(--line-strong);
}
.lb-head .c-pos { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.lb-row {
  min-height: 62px;
  padding-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.lb-row .c-pos {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.pos {
  height: 28px;
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
}
.pos--top {
  width: 28px;
  justify-content: center;
  border-radius: 50%;
  background: var(--navy);
  color: var(--cream);
  font-size: 14px;
}
.move {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.move--up { color: var(--up); }
.move--down { color: var(--down); }
.move--same { width: 9px; height: 2px; margin: 4px 0; background: var(--same); }

.name { font-size: 15px; font-weight: 600; line-height: 1.25; text-wrap: pretty; }
.pts { font-size: 16px; font-weight: 700; }
/* Rounds played: a navy pill once a player has played the maximum */
/* Rounds played: every count sits in the same size pill so the column lines up;
   it's only filled navy once a player has played the maximum. */
.rds {
  display: inline-block;
  min-width: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
}
.rds--max {
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.sub { font-size: 13px; color: var(--ink-2); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding-top: 16px;
  padding-bottom: 20px;
  font-size: 12px;
  color: var(--ink-3);
}

/* ---------- Leaderboard switcher: the season and any open one-off comps ---------- */
.board-switch {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-top: 14px;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.board-switch[hidden] { display: none; }
.board-switch a {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.board-switch a[aria-current="page"] { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ---------- Comps tab: nothing running ---------- */
.empty { padding-top: 48px; padding-bottom: 48px; text-align: center; }
.empty__title {
  margin: 0;
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.empty__text { margin: 8px auto 0; max-width: 300px; font-size: 14px; line-height: 1.45; color: var(--ink-3); }
.empty[hidden], #comp-board[hidden] { display: none; }

/* ---------- Tappable rows: the name's button covers the whole row ---------- */
.is-openable { position: relative; }
.row-open {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row-open::after { content: ""; position: absolute; inset: 0; }
.row-open:focus-visible { outline: none; }
.row-open:focus-visible::after { outline: 2px solid var(--navy); outline-offset: -2px; border-radius: 4px; }
@media (hover: hover) {
  .is-openable:hover { background: var(--cream-head); }
}

/* ---------- Player stats panel (slides up from the bottom) ---------- */
body.sheet-open { overflow: hidden; }
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 560px;
  max-height: min(88vh, 720px);
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgba(30, 20, 80, 0.25);
}
.sheet[open] { display: flex; flex-direction: column; overflow: hidden; }
.sheet::backdrop { background: rgba(30, 20, 80, 0.45); }
.sheet[open] { animation: sheet-up 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet[open]::backdrop { animation: sheet-fade 0.28s ease-out; }
.sheet.is-closing { animation: sheet-down 0.22s ease-in forwards; }
.sheet.is-closing::backdrop { animation: sheet-fade 0.22s ease-in reverse forwards; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes sheet-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .sheet[open], .sheet[open]::backdrop, .sheet.is-closing, .sheet.is-closing::backdrop { animation: none; }
}
.sheet__inner {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
}
.sheet__handle { width: 40px; height: 4px; margin: 0 auto 12px; border-radius: 2px; background: var(--line-strong); }
.sheet__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet__name:focus { outline: none; }
.sheet__name {
  margin: 0;
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: -0.03em;
}
.sheet__sub { margin: 6px 0 0; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.sheet__close {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -6px -10px 0 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.sheet__close:hover { background: var(--cream-head); }
.sheet__close:focus-visible { outline: 2px solid var(--navy); outline-offset: 0; }

.sheet__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 0; }
.stat {
  padding: 12px 10px;
  background: var(--tabbar-bg);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  text-align: center;
}
.stat dt { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.stat dd {
  margin: 4px 0 0;
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.sheet__label {
  margin: 18px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
/* Five rounds visible; the rest scroll inside the list while the stats above stay put. */
.sheet__rounds {
  --round-h: 58px;
  max-height: calc(var(--round-h) * 5);
  /* On very short screens the list shrinks (and scrolls) so the stats stay in view */
  flex: 0 1 auto;
  min-height: calc(var(--round-h) * 2);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
}
.sheet__rounds:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.sheet-round {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--round-h);
  border-bottom: 1px solid var(--line);
}
.sheet-round__title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.sheet-round__date { margin-top: 2px; font-size: 12px; color: var(--ink-4); }
.sheet-round__score {
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.sheet-round__score span { font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-weight: 400; color: var(--ink-3); }
.tag {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tag--high { background: var(--navy); color: #fff; }
.tag--low { background: var(--cream-head); color: var(--ink-2); border: 1px solid var(--line-strong); }
.sheet__rounds .status { padding: 24px 0; }

/* ---------- Rules card (under the leaderboard) ---------- */
.rules {
  margin: 4px 0 28px;
  padding: 18px 18px 8px;
  background: var(--tabbar-bg);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(30, 20, 80, 0.04);
}
.rules__title {
  margin: 0 0 6px;
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  letter-spacing: -0.03em;
}
.rules__list { counter-reset: rule; }
/* The number sits in the left margin (not a grid column) so a rule's text always flows as one
   sentence, even with markup inside it such as rule 8's number of rounds. */
.rules__list li {
  counter-increment: rule;
  position: relative;
  padding: 10px 0 10px 36px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}
.rules__list li + li { border-top: 1px solid var(--line); }
.rules__list li::before {
  content: counter(rule);
  position: absolute;
  left: 0;
  top: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--cream-head);
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Previous winners: one card per year ---------- */
.winners {
  display: grid;
  gap: 14px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}
.season-card {
  padding: 16px 18px 6px;
  background: var(--tabbar-bg);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(30, 20, 80, 0.04);
}
.season-card__title {
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.season-card__sub {
  margin: 2px 0 4px;
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 24px; /* same size as the comp name above it */
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
#winners-switch { padding-bottom: 0; }
.season-card__year {
  font-family: "Bricolage Grotesque", Helvetica, sans-serif;
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.podium__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 0;
}
.podium__row + .podium__row { border-top: 1px solid var(--line); }
.podium__body { display: flex; flex-direction: column; gap: 3px; }
.podium__place {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
}
.podium__name { font-size: 15px; font-weight: 600; line-height: 1.25; }
.podium__row--first .podium__name { font-size: 17px; }
.podium__stats { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* The cell stretches to the height of the row's text; the trophy fills it without adding height. */
.trophy { position: relative; align-self: stretch; width: 46px; }
.trophy svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.player {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}

/* ---------- Players ---------- */
.player {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 64px;
  padding-top: 12px;
  padding-bottom: 12px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--avatar);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.player__body { display: flex; flex-direction: column; gap: 3px; }
.player__name { font-size: 15px; font-weight: 600; line-height: 1.25; }
.player__stats { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.player__pos { font-size: 14px; font-weight: 700; }

/* ---------- Loading / empty / error ---------- */
.status {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 32px 20px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-3);
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tabbar-bg);
  border-top: 1px solid var(--line-strong);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 4px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-4);
  text-decoration: none;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a::before {
  content: "";
  width: 28px;
  height: 3px;
  border-radius: 2px;
}
.tabbar a[aria-current="page"] { font-weight: 700; color: var(--navy); }
.tabbar a[aria-current="page"]::before { background: var(--navy); }

a:focus-visible { outline: 2px solid var(--up); outline-offset: 2px; }
.site-header a:focus-visible { outline-color: var(--cream); }

/* ---------- Larger screens: same layout, more breathing room ---------- */
@media (min-width: 600px) {
  :root { --lb-cols: 56px minmax(0, 1fr) 56px 56px 48px 48px; }
  .site-header { padding-top: calc(32px + env(safe-area-inset-top)); padding-bottom: 28px; }
  .site-header h1 { font-size: 44px; }
  .lb-head { font-size: 11px; }
  .tabbar a { font-size: 14px; }
}
