:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efede8; --line: #e1ded6;
  --text: #1b1a17; --muted: #6b675e; --accent: #e8641b; --accent-ink: #9a3c08; --accent-strong: #c2410c;
  --in: #17693a; --out: #6b675e; --gold: #c99a1a; --gold-bar: #a67c00;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --num: "Barlow Condensed", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1b1b19; --surface-2: #242421; --line: #2f2e2a;
    --text: #f1efe9; --muted: #a29d92; --accent: #f07a35; --accent-ink: #ff9a5c;
    --in: #3ccf7c; --out: #a29d92; --gold-bar: #d4a72c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1b1b19; --surface-2: #242421; --line: #2f2e2a;
  --text: #f1efe9; --muted: #a29d92; --accent: #f07a35; --accent-ink: #ff9a5c;
  --in: #3ccf7c; --out: #a29d92; --gold-bar: #d4a72c; --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; }
a { color: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
h1, h2, h3 { font-family: var(--num); letter-spacing: .01em; line-height: 1.1; margin: 0 0 .4em; }
h1 { font-size: 40px; } h2 { font-size: 26px; margin-top: 1.6em; } h3 { font-size: 20px; }

/* header */
.top { position: sticky; top: 0; z-index: 1000; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { font: 700 24px var(--num); text-decoration: none; display: flex; align-items: center; gap: 8px; letter-spacing: .02em; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
nav a.on, nav a:hover { color: var(--text); background: var(--surface-2); }
.search { margin-left: auto; }
.search input { width: 220px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }
main { padding: 28px 16px 60px; min-height: 70vh; }
.foot { color: var(--muted); font-size: 13px; padding-bottom: 40px; }

/* cards & grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
a.card { text-decoration: none; display: block; transition: border-color .15s; }
a.card:hover { border-color: var(--accent); }
.card .title { font-weight: 600; font-size: 16px; margin-bottom: 2px; }
.stats { display: flex; gap: 28px; margin: 14px 0 10px; }
.stat b { display: block; font: 700 38px/1 var(--num); }
.stat span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat.big b { font-size: 64px; color: var(--accent); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.live { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent-ink); }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.leaders { list-style: none; padding: 0; margin: 8px 0 0; font-size: 14px; }
.leaders li { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px dashed var(--line); }
.strip { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0 24px; }
.strip .card { padding: 12px 16px; flex: 1 1 140px; }
.strip b { font: 700 28px/1 var(--num); display: block; }
.strip span { font-size: 12px; color: var(--muted); }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.empty { text-align: center; padding: 36px 18px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.yards { font: 700 20px var(--num); }
tr.out td { color: var(--out); }
.status-in { color: var(--in); font-weight: 600; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; }
.badge.w { background: var(--gold); color: #1b1a17; } .badge.a { background: var(--surface-2); color: var(--muted); }

/* controls */
.controls { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 18px; }
.controls input, .controls select { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font: inherit; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
#map { height: 360px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 18px; z-index: 0; }
.month { font: 600 14px Inter; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }
.race-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 10px 14px; text-decoration: none; border-bottom: 1px solid var(--line); }
.race-row:hover { background: var(--surface-2); }
.race-row .d { font: 700 22px/1 var(--num); text-align: center; }
.race-row .d small { display: block; font: 500 11px Inter; color: var(--muted); text-transform: uppercase; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chart { width: 100%; height: 160px; display: block; }
.chart text { fill: var(--muted); font: 11px Inter; }
.meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.desc { max-width: 70ch; color: var(--muted); }

@media (max-width: 640px) {
  .top-inner { gap: 6px 10px; flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; }
  .search { margin-left: 0; width: 100%; order: 3; }
  .search input { width: 100%; }
  .stats { gap: 18px; }
  .race-row { grid-template-columns: 48px 1fr; }
  .race-row > :last-child { display: none; }
  .hide-sm { display: none; }
  th, td { padding: 9px 8px; white-space: normal; }
  table { font-size: 13px; }
  nav a { padding: 6px 8px; }
  h1 { font-size: 30px; }
  .stat.big b { font-size: 48px; }
  .brand { font-size: 20px; }
}

/* ---- additions ---- */
.accent { color: var(--accent-ink); }
.pill.demo { background: #6b4bd8; color: #fff; }
.logo { height: 64px; max-width: 220px; object-fit: contain; margin-bottom: 8px; }
.cols { display: grid; gap: 0 24px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cols h2 { margin-top: 1.2em; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bar span { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar small { font-size: 11px; color: var(--muted); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; width: 340px; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; }
.toast { display: block; background: var(--text); color: var(--bg); pointer-events: auto;
  padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; text-decoration: none;
  opacity: 0; transform: translateY(10px); transition: opacity .3s, transform .3s; }
.toast.show { opacity: 1; transform: none; }
form.submit h3 { margin-bottom: 4px; }
@media (max-width: 640px) {
  .cols { grid-template-columns: 1fr; }
  .toasts { left: 16px; width: auto; }
}

/* ---- review fixes: focus, headings in cards, connection status, phones ---- */
:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 2px; border-radius: 4px; }
h1[tabindex="-1"]:focus { outline: none; }
.card-title { font-size: 20px; margin: 0 0 .5em; }
.netstatus { position: sticky; top: 60px; z-index: 999; margin: 0 auto; max-width: 1120px; padding: 8px 16px;
  background: #7a2e04; color: #fff; font-size: 14px; text-align: center; }
@media (max-width: 640px) {
  .top { position: static; }        /* the 3-row header scrolls away instead of covering a third of the screen */
  .netstatus { top: 0; }
}

/* live race: one-line verdict, and a warning when the source has gone quiet */
.summary { font-size: 17px; margin: 12px 0 6px; }
.stale { background: color-mix(in srgb, var(--accent) 10%, transparent); border-left: 3px solid var(--accent);
  padding: 8px 12px; border-radius: 6px; font-size: 14px; margin: 8px 0; }

/* fourth sweep: legends under tables, quiet-source warning on cards, screen-reader-only text */
.legend { font-size: 12px; margin: 6px 0 0; }
.warn { color: var(--accent-ink); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.cols > * { min-width: 0; }  /* long tables scroll inside their column instead of widening the page */
@media (max-width: 640px) { #map { height: 220px; } }

/* follow a runner from a live race's table */
/* (a 32 px target for fingers that doesn't make rows taller: the padding reaches into the cell's own,
   and the gap keeps the focus ring off the name) */
.star { background: none; border: 0; cursor: pointer; font-size: 16px; line-height: 1; color: var(--muted);
  display: inline-block; min-width: 32px; padding: 8px; margin: -8px 0 -8px 6px; vertical-align: middle; }
.star[aria-pressed="true"] { color: var(--accent); }

/* a sponsor's card: compact and clearly labelled */
.sponsor { display: flex; align-items: center; gap: 12px; margin: 14px 0; padding: 8px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); color: inherit; text-decoration: none; font-size: 14px; }
.sponsor:hover { border-color: var(--accent); }
.sponsor img { max-height: 32px; max-width: 120px; width: auto; object-fit: contain; }
.sponsor-tag { font: 600 10px Inter, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; }
@media (max-width: 640px) {
  .sponsor { font-size: 13px; gap: 8px; padding: 8px 10px; }
  .sponsor img { max-width: 72px; max-height: 24px; }
}
