:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efede7;
  --line: #dcd9d0;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7872;
  --accent: #1d6b4f;          /* mallard green */
  --accent-ink: #ffffff;
  --bill: #f2b632;            /* duck-bill yellow, highlights only */
  --win: #2a78d6;             /* diverging pole: winning */
  --loss: #e34948;            /* diverging pole: losing */
  --mid: #f0efec;             /* diverging neutral midpoint */
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .04);
  --radius: 10px;
  --head: "Oswald", "Arial Narrow", "Segoe UI", system-ui, sans-serif;
  --body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #34332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8d85;
    --accent: #3fa37c;
    --accent-ink: #0b0b0b;
    --win: #3987e5;
    --loss: #e66767;
    --mid: #383835;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--body); font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--head); font-weight: 600; letter-spacing: .01em; margin: 0; }
h2 { font-size: 22px; text-transform: uppercase; }
h3 { font-size: 15px; text-transform: uppercase; color: var(--text-2); }
button, select, input { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  background: var(--accent); color: var(--accent-ink);
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 0;
}
.top-inner { max-width: 1240px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: end; gap: 8px 24px; }
.brand { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 50%; background: var(--bill);
  display: grid; place-items: center; font-size: 22px; flex: none;
}
.brand h1 { font-size: 26px; line-height: 1; text-transform: uppercase; }
.brand p { margin: 2px 0 0; font-size: 12px; opacity: .85; }
nav { display: flex; gap: 4px; margin-left: auto; }
nav a {
  color: inherit; text-decoration: none; font-family: var(--head); text-transform: uppercase;
  font-size: 15px; padding: 10px 14px; border-radius: 8px 8px 0 0; opacity: .85;
}
nav a[aria-current="page"] { background: var(--bg); color: var(--text); opacity: 1; }

main { max-width: 1240px; margin: 0 auto; padding: 0 16px 64px; }

/* ---------- filter bar ---------- */
.filters {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--bg); padding: 12px 0; border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
}
.filters label.f { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
select, input[type="search"] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; min-height: 34px; max-width: 100%;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.filters .reset { margin-left: auto; background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---------- sections / cards ---------- */
section.block { margin-top: 28px; }
.block-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 10px; }
.block-head p { margin: 0; color: var(--muted); font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px 16px; }
.scroll { overflow-x: auto; }
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.jump a { font-size: 12px; text-decoration: none; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
th:first-child, td:first-child { text-align: left; }
td.l, th.l { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th.sorted::after { content: " ▾"; }
th.sorted.asc::after { content: " ▴"; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.focus td { background: color-mix(in srgb, var(--bill) 18%, transparent); }
.mgr { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.w { color: var(--win); font-weight: 600; }
.lo { color: var(--loss); font-weight: 600; }
.pos { display: inline-block; min-width: 30px; font-size: 11px; color: var(--muted); }

/* ---------- head-to-head heatmap ---------- */
.matrix { border-collapse: separate; border-spacing: 2px; width: auto; }
.matrix th, .matrix td { border: 0; padding: 0; }
.matrix thead th { height: 96px; vertical-align: bottom; position: static; background: none; }
.matrix thead th span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); padding: 4px 0; text-transform: none; font-size: 12px; letter-spacing: 0; color: var(--text-2); }
.matrix tbody th { text-align: right; padding-right: 8px; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--text-2); position: static; background: none; font-weight: 600; }
.matrix td.cell {
  width: 52px; min-width: 48px; height: 36px; text-align: center; font-size: 12px; border-radius: 4px; cursor: pointer;
  color: var(--text);
}
.matrix td.cell:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.matrix td.self { background: repeating-linear-gradient(45deg, var(--surface-2) 0 4px, transparent 4px 8px); cursor: default; }
.matrix td.cell.none { background: var(--surface-2); color: var(--muted); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-top: 10px; flex-wrap: wrap; }
.legend .bar { width: 160px; height: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--loss), var(--mid), var(--win)); }

/* ---------- rivalry ---------- */
.rival-pick { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.rival-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--head); font-size: 24px; font-weight: 600; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }

.stat-btn { border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.stat-btn:hover, .stat-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- player detail ---------- */
.pl-body { padding: 6px 18px 20px; overflow-y: auto; }
.pl-body h3 { margin: 18px 0 6px; }
.pl-body td { padding: 5px 8px; }
.moves { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.moves li { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- finishes grid ---------- */
.finish td { text-align: center; }
.finish td.champ { background: color-mix(in srgb, var(--bill) 35%, transparent); font-weight: 700; }
.finish td.last { background: color-mix(in srgb, var(--loss) 14%, transparent); }
.finish .rec { display: block; font-size: 11px; color: var(--muted); }

/* ---------- records ---------- */
.records { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.records .card h3 { padding: 12px 14px 4px; }
.records .card { overflow: hidden; }
.records table td { padding: 6px 8px; white-space: normal; vertical-align: top; }
.records table td:first-child { padding-left: 14px; }
.records table td:last-child { padding-right: 14px; white-space: nowrap; }
.records table td.sub { white-space: nowrap; }
.records .rank { color: var(--muted); width: 1.5em; }

/* ---------- game log ---------- */
.log-tools { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; align-items: center; }
.more { display: block; margin: 12px auto 0; padding: 8px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.tag.playoff { background: color-mix(in srgb, var(--bill) 40%, transparent); color: var(--text); }
.tag.toilet_bowl { background: color-mix(in srgb, var(--loss) 18%, transparent); }

/* ---------- box score dialog ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(900px, calc(100vw - 24px));
  max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.box-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: start; }
.box-head .x { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.box-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.box-cols > div { padding: 12px 18px 18px; overflow-x: auto; }
.box-cols > div + div { border-left: 1px solid var(--line); }
.box-team { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.box-team .score { font-family: var(--head); font-size: 30px; font-weight: 600; }
.box-cols td { padding: 4px 6px; }
.box-cols tr.bench td { color: var(--muted); }
.box-cols tr.sep td { padding-top: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 0; }
@media (max-width: 680px) {
  .box-cols { grid-template-columns: 1fr; }
  .box-cols > div + div { border-left: 0; border-top: 1px solid var(--line); }
}

/* ---------- tooltip ---------- */
.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; max-width: 260px; line-height: 1.4;
}

/* ---------- fun facts ---------- */
.ff-hero { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; margin-top: 24px; }
.ff-avatar {
  width: 84px; height: 84px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-family: var(--head); font-size: 34px; text-transform: uppercase;
}
.ff-hero h2 { font-size: 34px; text-transform: none; }
.ff-hero .aka { color: var(--muted); font-size: 13px; margin-top: 4px; }
.ff-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 18px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 18px; }
.fact { padding: 16px; display: flex; flex-direction: column; gap: 6px; border-top: 4px solid var(--line); }
.fact.roast { border-top-color: var(--loss); }
.fact.brag { border-top-color: var(--win); }
.fact .icon { font-size: 26px; line-height: 1; }
.fact h4 { margin: 0; font-family: var(--head); font-size: 18px; font-weight: 600; }
.fact p { margin: 0; color: var(--text-2); }
.fact .big { font-family: var(--head); font-size: 28px; font-weight: 600; line-height: 1.1; color: var(--text); }
.fact button.link { align-self: start; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: 13px; margin-top: auto; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; grid-column: 1 / -1; }
.pick { display: flex; gap: 12px; align-items: center; padding: 14px; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.pick:hover, .pick:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.pick-body { display: flex; flex-direction: column; min-width: 0; }
.pick-body .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ff-avatar.sm { width: 44px; height: 44px; font-size: 20px; flex: none; }
button.back { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: 13px; margin-bottom: 4px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
footer { max-width: 1240px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom, 0px)); color: var(--muted); font-size: 12px; }

@media (max-width: 600px) {
  .top { padding-left: 16px; padding-right: 16px; }
  nav { margin-left: 0; }
  .brand h1 { font-size: 21px; }
  .filters { position: static; }
  .records { grid-template-columns: 1fr; }
  .ff-hero h2 { font-size: 26px; }
}
