/* WNBA Hindsight
   Themes: tokens below. index.html sets <html data-theme="light|dark"> before first paint;
   the media query only matters if scripting is off. */

@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("fonts/BarlowCondensed-800.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Impact, sans-serif;

  --surface-0: #edf0f8;   /* page */
  --surface-1: #ffffff;   /* cards */
  --surface-2: #f3f5fb;   /* tinted fills: chips, table heads */
  --border: #d6dcec;
  --text-primary: #0e1630;
  --text-secondary: #424c69;
  --text-muted: #59637f;
  --grid: #e3e8f3;
  --zero: #7d88a3;
  --shadow: 0 1px 2px rgba(14, 22, 48, 0.06), 0 8px 22px rgba(14, 22, 48, 0.06);

  --home: #2a78d6;        /* categorical slot 1 */
  --away: #eb6834;        /* categorical slot 2 */
  --sel: #6250d6;         /* period selection (violet, not a team color) */
  --focus: #2a78d6;
  --accent: #0b7f78;      /* brand teal, for text and controls on surfaces */
  --accent-soft: #def4f1;
  --danger: #b42318;
  --on-accent: #ffffff;

  --brand-from: #0f1a44;  /* header gradient */
  --brand-to: #34207a;
  --brand-mint: #5eead4;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0a0f20;
  --surface-1: #131a30;
  --surface-2: #1a2342;
  --border: #283253;
  --text-primary: #eaf0ff;
  --text-secondary: #b8c3e0;
  --text-muted: #8f9cc0;
  --grid: #222b47;
  --zero: #66728f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.3);

  --home: #3987e5;
  --away: #d95926;
  --sel: #9085e9;
  --focus: #6aa6ee;
  --accent: #2dd4bf;
  --accent-soft: #11373a;
  --danger: #ff8a80;
  --on-accent: #06222a;

  --brand-from: #080d24;
  --brand-to: #25135a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --surface-0: #0a0f20; --surface-1: #131a30; --surface-2: #1a2342; --border: #283253;
    --text-primary: #eaf0ff; --text-secondary: #b8c3e0; --text-muted: #8f9cc0; --grid: #222b47; --zero: #66728f;
    --home: #3987e5; --away: #d95926; --sel: #9085e9; --focus: #6aa6ee;
    --accent: #2dd4bf; --accent-soft: #11373a; --danger: #ff8a80; --on-accent: #06222a;
    --brand-from: #080d24; --brand-to: #25135a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(100deg, var(--brand-from), var(--brand-to));
  color: #fff;
}
.app-header::after {   /* team-color stripe: home blue to away orange */
  content: ""; display: block; height: 4px;
  background: linear-gradient(90deg, var(--home), var(--brand-mint) 50%, var(--away));
}
.app-header-inner {
  max-width: 1040px; margin: 0 auto; padding: 14px 16px;
  display: flex; align-items: center; gap: 8px 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand:focus-visible, .theme-switch input:focus-visible { outline-color: #fff; }
.brand-mark { flex: none; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35)); }
.brand-name {
  margin: 0; font-family: var(--display); font-weight: 800; font-size: 2.1rem; line-height: 1;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.brand-wnba { color: #fff; }
.brand-hind { color: var(--brand-mint); }
.brand-tag { margin: 2px 0 0; color: rgba(255, 255, 255, 0.72); font-size: 0.85rem; flex: 1; min-width: 0; }
.theme-switch { margin-left: auto; display: flex; align-items: center; gap: 9px; color: rgba(255, 255, 255, 0.92); font-size: 0.85rem; cursor: pointer; user-select: none; }
.theme-switch input {   /* still a real checkbox; drawn as a switch */
  appearance: none; -webkit-appearance: none; margin: 0; cursor: pointer;
  width: 44px; height: 24px; border-radius: 999px; position: relative;
  background: rgba(255, 255, 255, 0.22); border: 1px solid rgba(255, 255, 255, 0.45);
  transition: background 0.15s;
}
.theme-switch input::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.theme-switch input:checked { background: var(--brand-mint); border-color: var(--brand-mint); }
.theme-switch input:checked::before { transform: translateX(20px); background: #0f1a44; }
@media (prefers-reduced-motion: reduce) { .theme-switch input, .theme-switch input::before { transition: none; } }
@media (max-width: 640px) {
  .brand-name { font-size: 1.8rem; }
  .brand-tag { display: none; }
}

/* ---------- Page ---------- */
.page { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; margin: 0 0 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: min(100%, 340px); }
.field label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); }
select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; box-shadow: var(--shadow);
}
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; max-width: 340px; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.check small { color: var(--text-muted); }
.check:has(input:disabled) { cursor: not-allowed; opacity: 0.65; }

.message {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin: 0 0 16px;
}
.message code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Scoreboard ---------- */
.scoreboard {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 12px 16px 14px; margin-bottom: 18px;
}
.scoreboard:empty { display: none; }
.sb-meta {
  margin: 0 0 8px; text-align: center; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent);
}
.sb-teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.sb-team { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 14px; border-radius: 10px; min-width: 0; }
.sb-team.away { border-left: 6px solid var(--away); }
.sb-team.home { border-right: 6px solid var(--home); flex-direction: row-reverse; }
.sb-id { display: flex; flex-direction: column; min-width: 0; }
.sb-team.home .sb-id { align-items: flex-end; text-align: right; }
.sb-tri { font-family: var(--display); font-weight: 800; font-size: 1.5rem; letter-spacing: 0.06em; line-height: 1; }
.sb-name { color: var(--text-secondary); font-size: 0.85rem; overflow-wrap: anywhere; }
.sb-score {
  font-family: var(--display); font-weight: 800; font-size: 3.4rem; line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--text-secondary);
}
.sb-team.winner .sb-score { color: var(--text-primary); }
.sb-team.away.winner { background: color-mix(in srgb, var(--away) 12%, transparent); }
.sb-team.home.winner { background: color-mix(in srgb, var(--home) 12%, transparent); }
.sb-at { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; }
@media (max-width: 620px) {
  .sb-teams { grid-template-columns: 1fr; gap: 6px; }
  .sb-at { display: none; }
  .sb-score { font-size: 2.6rem; }
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 4px 0 16px; overflow-x: auto; }
.tabs [role="tab"] {
  font: inherit; font-weight: 700; color: var(--text-secondary); background: none; border: 0;
  border-bottom: 4px solid transparent; border-radius: 8px 8px 0 0; padding: 10px 18px; margin-bottom: -2px;
  cursor: pointer; white-space: nowrap;
}
.tabs [role="tab"]:hover { color: var(--text-primary); background: var(--surface-2); }
.tabs [role="tab"][aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-soft); }
[role="tabpanel"]:focus-visible { outline-offset: 4px; }

/* ---------- Lead tracker ---------- */
.chart-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow), inset 0 4px 0 var(--accent);
  padding: 18px 12px 10px;
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; margin: 0 4px 8px; padding: 0;
  color: var(--text-secondary); font-size: 0.85rem; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch.home, .bg-home { background: var(--home); }
.swatch.away, .bg-away { background: var(--away); }
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.chart svg.dragging { cursor: ew-resize; }
.note { margin: 6px 4px 0; color: var(--text-muted); font-size: 0.8rem; }
.tri.home { color: var(--home); }
.tri.away { color: var(--away); }
.to-hit { cursor: pointer; }
.sub-hit { cursor: pointer; }
.lane-label { font-size: 10px; letter-spacing: 0.04em; }
.t-tag { color: var(--text-secondary); font-size: 0.72rem; }
.tooltip .t-rate { margin-top: 4px; font-variant-numeric: tabular-nums; }
.tooltip .t-rate b { color: var(--accent); }
.tt-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

/* SVG parts */
.ax-text { fill: var(--text-muted); font-size: 11px; }
.ax-label { fill: var(--text-secondary); font-size: 11px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.zero-line { stroke: var(--zero); stroke-width: 1.25; }
.band { fill: var(--text-primary); opacity: 0.035; }
.period-line { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 3 3; }
.halo { stroke: var(--surface-1); fill: none; stroke-linecap: round; stroke-linejoin: round; }
.run-badge { fill: var(--surface-1); stroke-width: 2; }
.run-num { fill: var(--text-primary); font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.cross-dot { fill: var(--surface-1); stroke: var(--text-primary); stroke-width: 2; }
.run-hit { cursor: pointer; }
.win { opacity: 0; pointer-events: none; }
.win.active { opacity: 0.16; }
g[data-run].active .main { stroke-width: 4.5; }
g[data-run].active .run-badge { stroke-width: 3; }

.tooltip {
  position: absolute; z-index: 2; pointer-events: none; min-width: 190px; max-width: 300px;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22); font-size: 0.82rem;
}
.tooltip .t-time { color: var(--text-secondary); font-size: 0.75rem; }
.tooltip .t-score { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .t-play { color: var(--text-secondary); margin-top: 4px; }

/* Period selection */
.brush-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 4px 8px; font-size: 0.85rem; color: var(--text-secondary); }
.chips { display: flex; gap: 6px; }
.chip {
  font: inherit; font-size: 0.82rem; font-weight: 600; color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 13px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.link-btn { font: inherit; font-size: 0.82rem; color: var(--accent); background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 3px 4px; }
.sel-rect { fill: var(--sel); fill-opacity: 0.22; }
.sel-edge { stroke: var(--sel); stroke-width: 2; }
.sel-label { paint-order: stroke; stroke: var(--surface-1); stroke-width: 4px; stroke-linejoin: round; fill: var(--text-primary); font-weight: 600; }
/* no browser text/element highlight on the chart, and none anywhere while a selection drag is in progress */
.chart svg *::selection, .chart svg::selection { background: transparent; }
body.brushing, body.brushing * { user-select: none !important; -webkit-user-select: none !important; cursor: ew-resize !important; }
body.brushing ::selection { background: transparent !important; }
.selection { margin-top: 16px; }
.selection-card { border-left-color: var(--sel) !important; }

/* Run cards */
.runs { margin-top: 20px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
.run-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px; border-left: 6px solid var(--text-muted);
}
.run-card.home { border-left-color: var(--home); }
.run-card.away { border-left-color: var(--away); }
.run-card.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.run-card h3 { margin: 0; font-size: 1rem; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.run-card .num { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.run-card .when { margin: 2px 0 10px; color: var(--text-secondary); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
@media (max-width: 520px) { .metrics { grid-template-columns: 1fr; } }
.metric { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.metric h4 { margin: 0 0 4px; font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.who { display: flex; gap: 6px; align-items: baseline; font-size: 0.9rem; margin: 2px 0; }
.who .tag { color: var(--text-secondary); font-size: 0.72rem; width: 3.1em; flex: none; }
.who .names { flex: 1; min-width: 0; }
.who .val { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.name-line { display: block; }
.tag { color: var(--text-secondary); font-size: 0.72rem; }
.names .tag { color: var(--text-secondary); font-size: 0.72rem; }
.team-chip { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: baseline; }
.run-card details { margin-top: 10px; }
.run-card summary, .table-view summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; font-weight: 600; }

table { border-collapse: collapse; width: 100%; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-secondary); font-weight: 700; position: sticky; top: 0; background: var(--surface-2); }
.table-scroll { overflow: auto; max-height: 320px; margin-top: 6px; }
.table-view { margin-top: 20px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
#plays-table td:last-child, #plays-table th:last-child { text-align: left; white-space: normal; }

/* ---------- Player stats ---------- */
.leaders { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; margin-bottom: 16px; }
.leader {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow), inset 0 4px 0 var(--accent);
  padding: 14px 14px 10px;
}
.leader-title { grid-column: 1 / -1; font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.leader-val { font-family: var(--display); font-weight: 800; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; grid-row: 2; grid-column: 2; }
.leader-who { grid-row: 2; grid-column: 1; }
.team-stats { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 16px 14px 12px; margin-bottom: 16px; }
.team-stats[data-side="home"] { box-shadow: var(--shadow), inset 0 5px 0 var(--home); }
.team-stats[data-side="away"] { box-shadow: var(--shadow), inset 0 5px 0 var(--away); }
.team-stats h2 { margin: 0 0 8px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.team-score { font-family: var(--display); font-weight: 800; font-size: 1.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.team-role { color: var(--text-muted); font-size: 0.8rem; font-weight: 400; }
.stats-scroll { max-height: none; overflow-x: auto; }
.stats-table th, .stats-table td { text-align: right; }
.stats-table th.left, .stats-table td.left { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
.stats-table th { top: auto; position: static; }
.stats-table th.left { position: sticky; background: var(--surface-2); }
.stats-table th button {
  font: inherit; font-weight: 700; color: var(--text-secondary); background: none; border: 0; padding: 2px 0; cursor: pointer;
  display: inline-flex; gap: 3px; align-items: baseline;
}
.stats-table th button:hover { color: var(--accent); }
.stats-table th[aria-sort="ascending"] button, .stats-table th[aria-sort="descending"] button { color: var(--accent); }
.stats-table .arrow { font-size: 0.65rem; min-width: 0.8em; }
.stats-table .metric { font-weight: 700; }
.stats-table tbody tr:hover td { background: var(--accent-soft); }
.stats-table tfoot td { font-weight: 700; border-top: 2px solid var(--grid); border-bottom: 0; background: var(--surface-2); }
.stats-table .metric:not(.left) { background: var(--accent-soft); }
.stats-table th.metric:not(.left) { background: var(--accent-soft); }
.stats-table tfoot td.metric:not(.left) { background: var(--accent-soft); }
.stats-table tbody tr:hover td.left { background: var(--accent-soft); }

/* ---------- Footer ---------- */
.foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; max-width: 80ch; }
.foot strong { color: var(--text-secondary); }
.foot .legal { margin-top: 14px; }

/* Run size box */
.run-setting { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 4px 12px; }
.run-setting-label { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.stepper button {
  font: inherit; font-size: 1.1rem; font-weight: 700; line-height: 1; width: 34px; border: 0; cursor: pointer;
  color: var(--accent); background: var(--surface-2);
}
.stepper button:hover:not(:disabled) { background: var(--accent-soft); }
.stepper button:disabled { color: var(--text-muted); opacity: 0.5; cursor: not-allowed; }
.stepper input {
  width: 3.4rem; text-align: center; font: inherit; font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--text-primary); background: var(--surface-1); border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  padding: 6px 4px; outline-offset: -2px;
}
.stepper input[aria-invalid="true"] { color: var(--danger); box-shadow: inset 0 -3px 0 var(--danger); }
.run-hint { color: var(--text-muted); font-size: 0.82rem; }
.stepper input[aria-invalid="true"] ~ * , .run-setting:has(input[aria-invalid="true"]) .run-hint { color: var(--danger); }

#panel-lead > .controls { align-items: flex-start; }
