/* Run the Numbers — shared styles */
:root {
  --bg: #faf6ef;
  --surface: #fffdf8;
  --ink: #2a2521;
  --muted: #74695e;
  --line: #e7dfd2;
  --accent: #c2512f;
  --teal: #2f6f73;
  --ochre: #d29a2e;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --max: 1040px;
  --read: 680px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img, svg { max-width: 100%; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(250, 246, 239, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  max-width: var(--max); margin: 0 auto; padding: 0 24px;
  height: 60px; display: flex; align-items: center; justify-content: space-between;
}
.brand {
  font-family: var(--serif); font-weight: 600; font-size: 1.25rem;
  text-decoration: none; letter-spacing: -0.01em;
}
.brand span { color: var(--accent); }
.site-header nav { display: flex; gap: 28px; }
.site-header nav a {
  text-decoration: none; font-size: 0.95rem; color: var(--muted);
  padding: 6px 0; border-bottom: 2px solid transparent; transition: color .2s, border-color .2s;
}
.site-header nav a:hover { color: var(--ink); }
.site-header nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); margin-top: 96px; }
.site-footer .inner {
  max-width: var(--max); margin: 0 auto; padding: 28px 24px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  color: var(--muted); font-size: 0.9rem;
}
.site-footer a { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.site-footer svg { width: 18px; height: 18px; }

/* ---------- Layout helpers ---------- */
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 24px; }
.eyebrow {
  font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; margin: 0 0 14px;
}

/* ---------- Home ---------- */
.hero { padding: 88px 0 56px; }
.hero h1 {
  font-family: var(--serif); font-weight: 600; font-size: clamp(2.4rem, 6vw, 4rem);
  line-height: 1.05; letter-spacing: -0.02em; margin: 0 0 20px; max-width: 14ch;
}
.hero p { font-size: 1.2rem; color: var(--muted); max-width: 46ch; margin: 0; }

.article-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr));
  gap: 28px;
}
.card {
  display: flex; flex-direction: column; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; transition: transform .25s ease, box-shadow .25s ease, border-color .25s;
}
.card:hover, .card:focus-visible {
  transform: translateY(-3px); border-color: #d9cdb9;
  box-shadow: 0 12px 28px -14px rgba(60, 40, 20, 0.28);
}
.card .thumb { background: #f3ebdd; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.card .thumb svg { display: block; width: 100%; height: 110px; }
.card .body { padding: 22px 24px 26px; display: flex; flex-direction: column; gap: 10px; }
.card .meta { font-size: 0.82rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.card .tag { color: var(--accent); font-weight: 600; }
.card h2 {
  font-family: var(--serif); font-weight: 600; font-size: 1.55rem;
  line-height: 1.2; letter-spacing: -0.01em; margin: 0;
}
.card p { margin: 0; color: var(--muted); }

/* ---------- Text pages ---------- */
.page { padding: 72px 0 0; }
.page h1 {
  font-family: var(--serif); font-weight: 600; font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 24px;
}
.prose { max-width: var(--read); margin: 0 auto; padding: 0 24px; font-size: 1.1rem; }
.prose p { margin: 0 0 1.3em; }
.prose h2 {
  font-family: var(--serif); font-weight: 600; font-size: 1.7rem;
  letter-spacing: -0.01em; line-height: 1.2; margin: 2.2em 0 0.6em;
}
.prose a { color: var(--accent); text-underline-offset: 3px; }
.page-narrow { max-width: var(--read); margin: 0 auto; padding: 0 24px; }
.page-narrow p { font-size: 1.1rem; }

/* ---------- Articles ---------- */
.article-head { max-width: 820px; margin: 0 auto; padding: 72px 24px 40px; }
.article-head h1 {
  font-family: var(--serif); font-weight: 600; font-size: clamp(2.2rem, 5.5vw, 3.6rem);
  line-height: 1.08; letter-spacing: -0.02em; margin: 0 0 18px;
}
.article-head .dek { font-size: 1.25rem; color: var(--muted); margin: 0 0 22px; max-width: 40ch; }
.article-head .series { font-size: 0.95rem; color: var(--muted); margin: 0 0 18px; }
.article-head .byline { font-size: 0.9rem; color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 28px; font-size: 0.9rem; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--accent); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 820px; margin: 8px auto 40px; padding: 0 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.stat b { display: block; font-family: var(--serif); font-size: 2.1rem; line-height: 1.1; color: var(--accent); }
.stat span { font-size: 0.88rem; color: var(--muted); }

.pullquote {
  max-width: 820px; margin: 2.4em auto; padding: 0 24px;
  font-family: var(--serif); font-size: clamp(1.4rem, 3.2vw, 1.9rem); line-height: 1.3;
}
.pullquote p { margin: 0; padding-left: 22px; border-left: 4px solid var(--accent); }

.chart-block { max-width: 860px; margin: 2.6em auto; padding: 0 24px; }
.chart-block h3 { font-family: var(--serif); font-size: 1.3rem; margin: 0 0 4px; font-weight: 600; }
.chart-block .sub { color: var(--muted); font-size: 0.95rem; margin: 0 0 14px; }
.chart-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 12px 8px; }
.chart-block figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 10px; }
.chart-block figure { margin: 0; }
.hint { font-size: 0.8rem; color: var(--muted); text-align: right; padding: 0 8px 6px; }

.data-note {
  max-width: var(--read); margin: 3em auto 0; padding: 18px 22px; font-size: 0.92rem;
  background: #f3ebdd; border-radius: 12px; color: var(--muted);
}
.data-note strong { color: var(--ink); }

.chart-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-pair .chart-panel h4, .chart-stack .chart-panel h4 { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; margin: 4px 8px 6px; }
@media (max-width: 640px) { .chart-pair { grid-template-columns: 1fr; } }
.chart-stack { display: grid; gap: 14px; }

.legend-item { display: inline-flex; align-items: center; }
.legend-item[tabindex] { cursor: pointer; border-radius: 6px; }
.legend-item[tabindex]:hover, .legend-item[tabindex]:focus-visible { color: var(--ink); }

.table-view { margin: 4px 8px 8px; font-size: 0.85rem; color: var(--muted); }
.table-view summary { cursor: pointer; padding: 6px 0; }
.table-view summary:hover { color: var(--ink); }
.table-scroll { overflow-x: auto; }
.table-view table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table-view thead th { color: var(--ink); font-weight: 600; }
.table-view tbody th { color: var(--ink); font-weight: 500; }

/* Stops a wide table from stretching its chart column (which would trigger a redraw) */
.chart-panel { min-width: 0; }

/* Finishing-positions table */
.pos-scale { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; }
.pos-scale i { display: inline-block; width: 160px; height: 10px; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--line);
  background: linear-gradient(90deg, #8f2a14 0%, #c4553a 12%, #f0bfa8 41%, #f9ece3 100%); }
.pos-scale-note { margin-left: 8px; }
.pos-grid-scroll { overflow-x: auto; padding: 0 8px 10px; }
.pos-grid { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.pos-grid th { font-weight: 500; text-align: left; color: var(--ink); padding: 0 10px 0 0; white-space: nowrap; }
.pos-grid thead th { color: var(--muted); text-align: center; padding: 0 0 6px; }
.pos-grid thead th:first-child { text-align: left; }
.pos-grid tbody th.club { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.pos-grid .grp th { padding-top: 12px; font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.pos-grid td { text-align: center; height: 26px; min-width: 34px; border-radius: 4px; }
.pos-grid td.podium { font-weight: 700; }
.pos-grid td.empty { box-shadow: inset 0 0 0 1px var(--line); }
.pos-grid .y2 { display: none; }
@media (max-width: 480px) {
  .pos-grid { font-size: 0.72rem; border-spacing: 2px; }
  .pos-grid th { padding-right: 6px; }
  .pos-grid td { min-width: 22px; height: 24px; }
  .pos-grid .y4 { display: none; }
  .pos-grid .y2 { display: inline; }
  .pos-grid-scroll { padding: 0 4px 10px; }
}

/* ---------- Chart internals ---------- */
svg text { font-family: var(--sans); }
.axis text { fill: var(--muted); font-size: 12px; }
.grid line { stroke: var(--line); }
.axis-title { fill: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 0 8px 10px 44px; font-size: 0.85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; }
.chart-panel svg { display: block; touch-action: pan-y; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; opacity: 0;
  background: var(--ink); color: #fffdf8; border-radius: 10px; padding: 10px 14px;
  font-size: 0.85rem; line-height: 1.5; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.35);
  transition: opacity .12s; max-width: 290px;
}
.tooltip.visible { opacity: 1; }
.tooltip strong { display: block; margin-bottom: 2px; font-weight: 600; }
.tooltip .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tooltip .row i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }

/* ---------- Scrollytelling ---------- */
.scrolly {
  position: relative; max-width: 1120px; margin: 0 auto; padding: 0 24px;
  display: grid; grid-template-columns: minmax(280px, 380px) 1fr; column-gap: 40px;
}
.scrolly .figure {
  grid-column: 2; grid-row: 1; align-self: start;
  position: sticky; top: 84px; height: calc(100vh - 116px); max-height: 640px; margin-top: 8vh;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
}
.scrolly #chart { width: 100%; height: 100%; }
.scrolly .steps { grid-column: 1; grid-row: 1; }
.step { min-height: 90vh; display: flex; align-items: center; }
.step:first-child { min-height: 70vh; }
.step:last-child { min-height: 80vh; }
.step .step-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px; opacity: 0.35; transition: opacity .35s, transform .35s; transform: translateY(6px);
}
.step.active .step-card { opacity: 1; transform: none; }
.step h3 { font-family: var(--serif); font-size: 1.35rem; margin: 0 0 8px; font-weight: 600; line-height: 1.2; }
.step p { margin: 0; color: #4a4139; }

@media (max-width: 820px) {
  .scrolly { display: block; }
  .scrolly .figure {
    top: 64px; height: 44vh; margin-top: 0; z-index: 5;
  }
  .step { min-height: 70vh; align-items: flex-end; padding-bottom: 8vh; }
  .stat-row { grid-template-columns: 1fr; }
  .site-header nav { gap: 20px; }
  .site-footer .inner { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card, .step .step-card, .tooltip { transition: none; }
}
