/* ---------- tokens ---------- */
/* The theme is chosen by data-theme on <html>: a tiny inline script in
   index.html resolves the saved choice (or the OS preference) before first
   paint, and app.js keeps it in sync with the toggle in the header. Secondary
   text (--ink-2, --muted) and every coloured text token clear WCAG AA (4.5:1)
   on --surface in both themes. */
:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #6b6a64;   /* 5.3:1 on --surface */
  --grid-line:   #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --good:        #006300;   /* success text on light */
  --critical:    #c33131;   /* 5.4:1 */
  --accent:      #1d69c4;   /* 5.3:1 */
  --accent-deep: #1a57a3;   /* solid fills carrying white text, 7.1:1 */
  --row-hover:   rgba(29, 105, 196, 0.07);
  --in-tint:     rgba(12, 163, 12, 0.07);
}
/* Meaning by colour, chosen to stay distinct under red-green colour blindness:
   blue = approaching a clinch (also the grid ramp and hot magic numbers),
   red = elimination / danger, green = already clinched. Blue vs red separates
   well for protan, deutan and tritan viewers; a red/green pair does not, so
   red and green never carry meaning side by side without a symbol or text. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid-line:   #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255, 255, 255, 0.10);
  --good:        #0ca30c;
  --critical:    #e35252;   /* 4.6:1 on --surface */
  --accent:      #3987e5;
  --accent-deep: #256abf;
  --row-hover:   rgba(57, 135, 229, 0.12);
  --in-tint:     rgba(12, 163, 12, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--grid-line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 16px 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.site-header h1 { font-size: 20px; margin: 0; }
.season { color: var(--muted); font-weight: 400; }

.refresh-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-2);
}
.countdown { font-variant-numeric: tabular-nums; color: var(--muted); }
#refresh-btn, #theme-btn {
  border: 1px solid var(--border);
  background: none;
  color: var(--ink-2);
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.3;
  padding: 2px 9px;
  cursor: pointer;
}
#refresh-btn:hover, #theme-btn:hover { background: var(--row-hover); }
#refresh-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.league-nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 8px;
  display: flex;
  gap: 18px;
  font-size: 13px;
}
.league-nav a { color: var(--ink-2); text-decoration: none; }
.league-nav a:hover { color: var(--accent); }

.error-banner {
  margin: 16px 0;
  padding: 10px 14px;
  border: 1px solid var(--critical);
  border-radius: 8px;
  color: var(--critical);
  background: var(--surface);
}

/* ---------- scoreboard ---------- */
.scoreboard { margin: 14px -16px 0; padding: 0 16px; overflow-x: auto; }
.score-nav {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.score-nav a { color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.score-nav a:hover { color: var(--accent); }
.score-nav .score-date { font-weight: 600; color: var(--ink); white-space: nowrap; }
.score-nav .score-date a { font-weight: 400; color: var(--accent); }
.score-strip { display: flex; gap: 8px; min-height: 10px; padding-bottom: 6px; }
.game-card {
  flex: 0 0 auto;
  min-width: 122px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: inherit;
  text-decoration: none;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.game-card:hover, .game-card:focus-visible {
  border-color: var(--ink-2);
}
.game-card .gc-status {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 3px;
  white-space: nowrap;
}
.game-card.live .gc-status .gc-state { color: var(--critical); font-weight: 600; }
.game-card.live .gc-status .gc-state::before { content: "\25CF\00a0"; }
.game-card .gc-team {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}
.game-card .gc-team.winner { font-weight: 650; }
.gc-rec { color: var(--muted); font-size: 11px; }
.game-card.clinch-game { border-color: var(--accent); }
.game-card.elim-game { border-color: var(--critical); }
.game-card.clinch-game.elim-game { border-color: var(--accent); border-left: 3px solid var(--critical); }
.game-card.related-game { border-color: var(--ink-2); border-style: dashed; }
/* Glyphs so the outline colour is never the only cue. */
.gc-flag { font-weight: 700; font-size: 12px; line-height: 1; }
.gc-flag.clinch { color: var(--accent); }
.gc-flag.elim { color: var(--critical); }
.stakes-notes { display: flex; flex-direction: column; gap: 8px; }
.stakes-notes:not(:empty) { margin-top: 8px; }
.watch {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--critical);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.watch h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--critical); }
.watch ul { margin: 0; padding-left: 18px; }
.watch li { margin: 3px 0; line-height: 1.4; }
.watch.clinch-watch { border-left-color: var(--accent); }
.watch.clinch-watch h3 { color: var(--accent); }
/* A settled scenario stays listed: tinted when it happened, greyed out when it
   did not, and the results of the games that decided it follow in bold. A dead
   path inside a still-open scenario is struck through. */
.watch li.done { margin-left: -6px; padding: 2px 6px; border-radius: 6px; background: color-mix(in srgb, var(--critical) 12%, transparent); }
.watch.clinch-watch li.done { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.watch li.missed { color: var(--muted); }
.watch .path.hit { font-weight: 600; }
.watch .path.miss { color: var(--muted); text-decoration: line-through; }
.watch li.missed .path.miss { text-decoration: none; }
.watch .outcome { font-weight: 600; color: var(--ink); }
.watch li.done .outcome { color: var(--critical); }
.watch.clinch-watch li.done .outcome { color: var(--accent); }
.watch li.open .outcome { font-weight: 400; color: var(--ink-2); }

/* small pill labels in the team panel */
.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-deep);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
  white-space: nowrap;
}
.tag.elim { background: var(--critical); }
.team-col a { color: inherit; text-decoration: none; }
.team-col a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- team panel ---------- */
.team-panel {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 20px 22px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}
.team-panel::backdrop { background: rgba(0, 0, 0, 0.45); }
.tp-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.tp-close:hover { color: var(--ink); }
.team-panel h2 { font-size: 18px; margin: 0 28px 4px 0; }
.team-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 6px; }
.tp-sub { color: var(--ink-2); }
.tp-milestones { list-style: none; margin: 0; padding: 0; }
.tp-milestones li { padding: 5px 0 5px 12px; border-left: 3px solid var(--border); margin-bottom: 4px; }
.tp-milestones li.clinch { border-left-color: var(--good); }
.tp-milestones li.elim { border-left-color: var(--critical); }
.tp-milestones li.open { color: var(--ink-2); }
.tp-schedule { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tp-schedule td { padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tp-schedule td:last-child { text-align: right; }
.tp-schedule tr.win td:nth-child(3) { color: var(--good); font-weight: 600; }
.tp-schedule tr.loss td:nth-child(3) { color: var(--critical); }
.tp-schedule tr.live td:nth-child(3) { color: var(--critical); font-weight: 600; }
.tp-schedule tr.clinch-chance td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tp-schedule tr.clinch-chance td:first-child { border-left: 3px solid var(--accent); }
.tp-schedule tr.elim-chance td { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.tp-schedule tr.elim-chance td:first-child { border-left: 3px solid var(--critical); }
.tp-schedule .tag { margin-left: 8px; }
.team-panel a { color: var(--accent); text-decoration: none; }
.team-panel a:hover { text-decoration: underline; }
.tp-links { margin: 14px 0 0; }

/* ---------- league sections ---------- */
.league h2 {
  font-size: 18px;
  margin: 30px 0 4px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--baseline);
}
.division-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr));
  gap: 16px;
  margin-top: 12px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 12px;
  overflow-x: auto;
}
.panel h3 {
  margin: 2px 0 8px;
  font-size: 14px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 4px 7px; text-align: right; white-space: nowrap; }
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid var(--grid-line);
}
td { font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--grid-line); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }
th.team-col, td.team-col {
  text-align: left;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
}
td.team-col { font-variant-numeric: normal; }
.num-hot { font-weight: 650; color: var(--accent); }
.num-danger { font-weight: 650; color: var(--critical); }
.badge {
  font-weight: 700;
  font-size: 12px;
  margin-right: 4px;
}
.badge.clinch { color: var(--good); }
.badge.elim { color: var(--critical); }
.status-note { color: var(--muted); }
tr.wc-line td { border-bottom: 2px dashed var(--baseline); }
tr.wc-in td { background: var(--in-tint); }
tr.eliminated td.team-col, tr.eliminated td { color: var(--muted); }

.wc-grid-row {
  display: grid;
  grid-template-columns: minmax(330px, 2fr) minmax(0, 3fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}
/* The 16-column grid needs ~610px and the wild card table ~410px; below this
   they can't share a row without side-scrolling, so stack them instead. */
@media (max-width: 1080px) {
  .wc-grid-row { grid-template-columns: 1fr; }
}

/* Each panel adapts to its own width (container queries), so a squeezed table
   switches to team abbreviations and tighter cells only when full names would
   force a side-scroll. Thresholds are the tables' natural widths. */
.division-row .panel { container: division / inline-size; }
.wc-grid-row .panel { container: wildcard / inline-size; }
.team-col .team-abbr { display: none; }
@container division (max-width: 333px) {
  .team-col .team-name { display: none; }
  .team-col .team-abbr { display: inline; }
}
@container division (max-width: 340px) {
  th, td { padding: 3px 3px; }
}
@container wildcard (max-width: 387px) {
  .team-col .team-name { display: none; }
  .team-col .team-abbr { display: inline; }
}
@container wildcard (max-width: 340px) {
  table:not(.magic-grid) { font-size: 12px; }
  table:not(.magic-grid) th { font-size: 10.5px; }
  table:not(.magic-grid) th, table:not(.magic-grid) td { padding: 3px 2px; }
}

/* ---------- the grid ---------- */
.magic-grid-wrap { overflow: auto; max-height: 640px; }
.magic-grid { font-size: 12.5px; border-collapse: separate; border-spacing: 2px 2px; }
.magic-grid th, .magic-grid td {
  text-align: center;
  padding: 3px 0;
  min-width: 34px;
  border-bottom: none;
}
.magic-grid thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  border-bottom: 1px solid var(--grid-line);
}
.magic-grid .team-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  text-align: left;
  padding-right: 8px;
  font-weight: 550;
  font-variant-numeric: normal;
}
.magic-grid thead th.team-col { z-index: 3; }
.magic-grid tbody tr:hover td { background-color: initial; }
.magic-grid tbody tr:hover td.team-col { background: var(--surface); color: var(--accent); }
.mg-cell { border-radius: 4px; }
/* Tighter grid cells when the panel is narrower than the grid's natural 582px. */
@container wildcard (max-width: 581px) {
  .magic-grid { font-size: 11.5px; }
  .magic-grid th, .magic-grid td { min-width: 30px; }
}
.cell-self { color: var(--grid-line); }
.cell-clinched { color: var(--good); font-weight: 700; }
.cell-impossible { color: var(--muted); }
.cell-demo { font-weight: 700; }
.cell-demo.cell-clinched { color: var(--good); }
.cell-demo.cell-impossible { color: var(--muted); }

/* sequential ramp (blue, light→dark): closer to clinching = darker */
.m7 { background: #cde2fb; color: #0b0b0b; }
.m6 { background: #9ec5f4; color: #0b0b0b; }
.m5 { background: #6da7ec; color: #0b0b0b; }
.m4 { background: #3987e5; color: #ffffff; }
.m3 { background: #256abf; color: #ffffff; }
.m2 { background: #184f95; color: #ffffff; }
.m1 { background: #0d366b; color: #ffffff; }

/* ---------- explainer ---------- */
.explainer { margin-top: 40px; font-size: 14px; color: var(--ink-2); max-width: 720px; }
.explainer h2 { color: var(--ink); font-size: 17px; }
.explainer dt { font-weight: 650; color: var(--ink); margin-top: 12px; }
.explainer dd { margin: 4px 0 0 0; }
.fineprint { margin-top: 22px; font-size: 12px; color: var(--muted); }

@media (max-width: 600px) {
  body { font-size: 14px; }
  .site-header h1 { font-size: 17px; }
  th, td { padding: 4px 5px; }
}
