/* Turf Archive — one stylesheet for every page. Light + dark via prefers-color-scheme. */
:root {
  --bg: #f7f4ed;
  --surface: #fffdf8;
  --fg: #1c2620;
  --muted: #5f6b63;
  --accent: #1f5c3a;
  --accent-soft: #e3ece4;
  --rule: #ddd6c6;
  --gold: #a57a1e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --wrap: 68rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --surface: #171e1a;
    --fg: #e7e3d9;
    --muted: #9ba79f;
    --accent: #85c39b;
    --accent-soft: #1f2b24;
    --rule: #2b352f;
    --gold: #d6b25e;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.6 var(--serif);
}
a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; height: auto; display: block; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

/* masthead */
.masthead { border-bottom: 1px solid var(--rule); background: var(--surface); }
.masthead-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 1.15rem/1 var(--serif); color: var(--fg); text-decoration: none; letter-spacing: 0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--accent); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 10px var(--gold); }
.nav { display: flex; gap: 20px; font: 500 0.9rem/1 var(--sans); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nav a { white-space: nowrap; }
.nav a { color: var(--fg); text-decoration: none; padding: 8px 0; }
.nav a:hover { color: var(--accent); }

/* type */
main { padding-bottom: 48px; }
h1, h2, h3 { font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.9rem); margin: 0.2em 0 0.25em; }
h2 { font-size: 1.35rem; margin: 2.2em 0 0.7em; padding-top: 0.6em; border-top: 1px solid var(--rule); }
.kicker { font: 600 0.72rem/1.2 var(--sans); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin: 0; }
.kicker a { text-decoration: none; }
.sub { color: var(--muted); margin: 0; font-size: 1rem; }
.lede { font-size: 1.12rem; max-width: 44rem; }
.muted { color: var(--muted); }
.fine { font: 0.82rem/1.5 var(--sans); color: var(--muted); }
.page-head { padding: 28px 0 8px; }

.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 18px 0 0; margin: 0; font: 0.8rem/1.4 var(--sans); color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-right: 6px; }
.crumbs a { color: var(--muted); }

/* hero */
.hero { padding: 48px 0 16px; max-width: 46rem; }
.hero h1 { font-size: clamp(2.2rem, 6.5vw, 3.6rem); }
.button { display: inline-block; background: var(--accent); color: var(--bg); padding: 11px 18px; border-radius: 4px; font: 600 0.92rem/1 var(--sans); text-decoration: none; }
.button:hover { filter: brightness(1.08); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 1em; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font: 0.9rem/1.4 var(--sans); }
caption { text-align: left; font: 600 0.72rem/1 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); padding: 12px 12px 4px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { font-weight: 600; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
tbody th { font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.win { background: var(--accent-soft); }
.tag { display: inline-block; font: 600 0.68rem/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--gold); border: 1px solid currentColor; border-radius: 3px; padding: 2px 4px; margin-left: 6px; vertical-align: 1px; }
.fav { font: 600 0.68rem/1 var(--sans); color: var(--gold); margin-left: 4px; }
.history td, .history th { white-space: nowrap; }

/* winners grid: sticky year column, horizontal scroll */
.grid-wrap { max-height: 75vh; }
.grid { font-size: 0.82rem; }
.grid th, .grid td { white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.grid tbody th, .grid thead th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.grid td a { color: var(--fg); text-decoration: none; }
.grid td a:hover { color: var(--accent); text-decoration: underline; }
.grid td.none { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--rule) 6px 7px); opacity: 0.5; }

/* facts */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0; margin: 0 0 1em; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
.facts div { padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.facts dt { font: 600 0.7rem/1.2 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; }

/* replay */
.replay { margin: 20px 0 6px; max-width: 46rem; }
.replay-play, .replay iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 6px; overflow: hidden; background: #000; }
.replay-play { position: relative; padding: 0; cursor: pointer; }
.replay-play img { width: 100%; height: 100%; object-fit: cover; opacity: 0.85; }
.replay-play:hover img, .replay-play:focus-visible img { opacity: 1; }
.replay-icon { position: absolute; inset: 0; margin: auto; width: 72px; height: 72px; border-radius: 50%; background: rgba(0, 0, 0, 0.62); }
.replay-icon::after { content: ""; position: absolute; left: 29px; top: 22px; border-style: solid; border-width: 14px 0 14px 22px; border-color: transparent transparent transparent #fff; }
.replay figcaption { font: 0.82rem/1.4 var(--sans); color: var(--muted); padding-top: 8px; }

/* lists */
.cols { columns: 2 16rem; padding-left: 1.1em; }
.cols li { break-inside: avoid; margin-bottom: 4px; }
.race-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0 24px; }
.race-list li { padding: 8px 0; border-bottom: 1px solid var(--rule); }
.winners { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0 24px; }
.winners a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); color: var(--fg); text-decoration: none; }
.winners a:hover .horse { color: var(--accent); }
.winners .race { font: 0.88rem/1.4 var(--sans); color: var(--muted); }
.winners .horse { font-weight: 600; text-align: right; }

.pager { display: flex; justify-content: space-between; gap: 16px; margin: 2em 0 0; padding-top: 1em; border-top: 1px solid var(--rule); font: 0.9rem/1.4 var(--sans); }
.pager .next { margin-left: auto; text-align: right; }
.source { font: 0.88rem/1.5 var(--sans); color: var(--muted); }

/* stat tiles (person pages) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; margin: 8px 0 1em; }
.stats div { padding: 12px; box-shadow: inset -1px -1px 0 var(--rule); }
.stats .n { display: block; font: 600 1.45rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.stats .l { display: block; font: 600 0.68rem/1.3 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }

/* entries */
.entries th[scope=row], .entries td { white-space: normal; }
.entries .line { display: block; font: 400 0.76rem/1.35 var(--sans); color: var(--muted); margin-top: 2px; }
.entries tr.scr th, .entries tr.scr td { opacity: 0.55; }
.show-sm { display: none; }
.stack > a, .stack > .line { display: block; }
.stack .line { font: 400 0.76rem/1.35 var(--sans); color: var(--muted); }
.stack .line a { color: inherit; }
.entries tr.scr th { text-decoration: line-through; }

/* sortable tables + filter */
.sortable thead th button { all: unset; cursor: pointer; }
.sortable thead th button:focus-visible { outline: 2px solid var(--accent); }
.sortable thead th[aria-sort=descending] button::after { content: " ▾"; }
.sortable thead th[aria-sort=ascending] button::after { content: " ▴"; }
.filter { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font: 0.88rem/1.3 var(--sans); }
.filter input { flex: 1; max-width: 20rem; font: inherit; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 4px;
  background: var(--surface); color: var(--fg); }
.table-wrap.tall { max-height: 75vh; }
.table-wrap.tall thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

/* footer */
.footer { border-top: 1px solid var(--rule); background: var(--surface); padding: 24px 0 40px; font-size: 0.95rem; }
.footer p { margin: 0 0 8px; max-width: 46rem; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .hide-sm { display: none; }
  .show-sm { display: table-cell; }
  .history td, .history th { white-space: normal; }
  .history td.num, .history th.num { white-space: nowrap; }
  .stack > a + span.line { margin-bottom: 4px; }
  .masthead-in { gap: 6px 16px; padding: 10px 16px; }
  .nav { width: 100%; }
  th, td { padding: 7px 9px; }
  .nav { gap: 14px; }
}
