:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #1b1f24; --muted: #5f6b7a; --line: #e2e6eb;
  --accent: #e8641b; --accent-soft: #fdebdf; --win: #13734b; --loss: #b3261e;
  --official: #11663f; --official-soft: #e2f2e9; --video: #a94508; --video-soft: #fdebdf;
  --exp: #5f6b7a; --exp-soft: #eceff3; --zebra: #f9fafb; --sorted: #fff6d6;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171b; --card: #1d2127; --text: #e8ebef; --muted: #9aa5b3; --line: #2c323a;
          --accent: #ff8a4c; --accent-soft: #3a261b; --win: #5fd39e; --loss: #ff8a80;
          --official: #7fe0b0; --official-soft: #173528; --video: #ffab7a; --video-soft: #3a261b;
          --exp: #aab4c0; --exp-soft: #262b33; --zebra: #20252c; --sorted: #3a3418; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
main { max-width: 860px; margin: 0 auto; padding: 8px 16px 40px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 12px; align-items: center; }
.brand { font-weight: 700; text-decoration: none; }
.lang button { background: none; border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
h1 { font-size: 1.6rem; margin: 16px 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.num, .score { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.date { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.win { color: var(--win); font-weight: 600; }
.pos { color: var(--win); }
.neg { color: var(--loss); }
.own-team { color: var(--accent); font-weight: 700; }
.res-win { color: var(--win); }
.res-loss { color: var(--loss); }
.badge { display: inline-block; min-width: 1.5em; margin-left: 6px; padding: 0 4px; border-radius: 4px; text-align: center;
         font-size: .75rem; font-weight: 700; color: var(--card); background: var(--muted); }
.res-win .badge { background: var(--win); }
.res-loss .badge { background: var(--loss); }
tr.own td { background: var(--accent-soft); font-weight: 600; }
tr.total td { border-top: 2px solid var(--line); font-weight: 600; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.pills a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: .9rem; }
.pills a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.crumbs { margin: 12px 0 0; color: var(--muted); font-size: .9rem; }
.record { font-size: 1.05rem; }
.cards { list-style: none; padding: 0; display: grid; gap: 8px; }
.cards li a { display: block; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; font-weight: 600; }
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 18px; margin-top: 12px; }
.scoreboard .side { font-weight: 600; text-decoration: none; }
.scoreboard .side:last-child { text-align: right; }
.scoreboard .final { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
footer { max-width: 860px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: .8rem; }
.msg { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.msg.success { border-color: var(--win); }
.msg.warning, .msg.error { border-color: var(--loss); }
.steps { padding-left: 20px; color: var(--muted); }
.paste { display: grid; gap: 10px; padding: 12px; }
.paste textarea { width: 100%; font: .85rem/1.3 ui-monospace, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.paste button { justify-self: start; background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 16px; font-weight: 600; cursor: pointer; }
.badge-tier { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: .75rem; font-weight: 600; border: 1px solid var(--line); }
.badge-tier.tier-official { color: var(--official); background: var(--official-soft); }
.badge-tier.tier-rich { color: var(--video); background: var(--video-soft); }
.badge-tier.tier-experimental { color: var(--exp); background: var(--exp-soft); font-style: italic; }
table.video th, table.video td { padding: 6px 8px; }
details { margin: 8px 0; }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
/* Stats tables: tier bands above the headers, readable headers, neutral numbers, zebra, sorting */
table.stats th { color: var(--text); font-size: .78rem; white-space: nowrap; }
table.stats tr.bands th { padding: 3px 8px; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; text-align: center; border-bottom: 0; }
th.band.tier-official { background: var(--official-soft); color: var(--official); }
th.band.tier-rich { background: var(--video-soft); color: var(--video); }
th.band.tier-experimental { background: var(--exp-soft); color: var(--exp); font-style: italic; }
th.col-official { box-shadow: inset 0 3px 0 var(--official); }
th.col-rich { box-shadow: inset 0 3px 0 var(--video); }
th.col-experimental { box-shadow: inset 0 3px 0 var(--exp); }
table.stats tr:not(:has(th)):nth-child(even) td { background: var(--zebra); }
table.stats tr:not(:has(th)):hover td { background: var(--accent-soft); }
table.stats td.sorted { background: var(--sorted) !important; }
table.stats tr.pin td { background: var(--card); }
th.sortable-th { cursor: pointer; user-select: none; }
th.sortable-th:hover { text-decoration: underline; }
th[data-dir="desc"]::after { content: " ▼"; font-size: .65rem; }
th[data-dir="asc"]::after { content: " ▲"; font-size: .65rem; }
/* Frozen # and player columns: opaque (zebra and hover aware) so scrolled cells pass underneath */
table.stats .sticky { position: sticky; left: 0; z-index: 2; width: 3.2em; min-width: 3.2em; max-width: 3.2em;
                      background: var(--card); }
table.stats .sticky2 { position: sticky; left: 3.2em; z-index: 2; background: var(--card);
                       box-shadow: inset -1px 0 0 var(--line); white-space: nowrap; }
table.stats tr:not(:has(th)):nth-child(even) td.sticky,
table.stats tr:not(:has(th)):nth-child(even) td.sticky2 { background: var(--zebra); }
table.stats tr:not(:has(th)):hover td.sticky, table.stats tr:not(:has(th)):hover td.sticky2 { background: var(--accent-soft); }
table.stats tr.bands th:first-child { position: sticky; left: 0; z-index: 2; background: var(--card); }
a.drill { color: inherit; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
a.drill:hover, a.drill:focus { color: var(--video); text-decoration: underline solid var(--video); }
.watch { display: grid; gap: 12px; }
@media (min-width: 900px) { main:has(.watch) { max-width: 1200px; } .watch { grid-template-columns: 2fr 1fr; align-items: start; } }
.player video { width: 100%; background: #000; border-radius: 8px; aspect-ratio: 16 / 9; }
.player .controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.player button, .events button { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.events { list-style: none; margin: 0; padding: 4px; max-height: 70vh; overflow-y: auto; }
.events li button.ev { width: 100%; text-align: left; border: 0; padding: 6px 8px; }
.events li.on button.ev { background: var(--accent-soft); }
.events button:disabled { cursor: default; opacity: .8; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px; margin-bottom: 8px; }
.filters select, .filters input[type=text], .filters input:not([type]) , .filters input[inputmode] { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.player button.part.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.events li[hidden] { display: none; }
a.button { display: inline-block; padding: 6px 14px; border-radius: 6px; background: var(--accent); color: #fff; text-decoration: none; font-weight: 600; }
.narrow { max-width: 420px; }
.paste label { display: grid; gap: 4px; font-size: .9rem; }
.paste input:not([type=checkbox]):not([type=radio]) { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
.hintbox { position: fixed; z-index: 50; background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 8px;
           font-size: .82rem; line-height: 1.35; box-shadow: 0 4px 16px rgba(0,0,0,.25); pointer-events: none; }
th[data-hint] { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.glossary { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; padding: 8px; margin: 0; }
.glossary dt { text-align: right; } .glossary dd { margin: 0; font-size: .9rem; }
.paste label:has(input[type=radio]), .paste label:has(input[type=checkbox]) { display: inline-flex; align-items: center;
                                                                               gap: 6px; margin-right: 14px; }
fieldset.group { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px 10px; }
fieldset.group p { margin: 2px 0 6px; }

/* Replay player (bball_portal#41) */
.player .stage { position: relative; overflow: hidden; background: #000; border-radius: 8px; aspect-ratio: 16 / 9;
                 touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.player .stage video { width: 100%; height: 100%; display: block; object-fit: contain; transform-origin: center center;
                       border-radius: 0; aspect-ratio: auto; background: #000; }
.player.zoomed .stage { touch-action: none; }
.player .unzoom { display: none; position: absolute; right: 8px; top: 8px; }
.player.zoomed .unzoom { display: block; }
.player .label { position: absolute; left: 8px; top: 8px; color: #fff; background: rgba(0,0,0,.55); padding: 2px 8px;
                 border-radius: 6px; font-size: .85rem; pointer-events: none; display: none; }
.player.big .label:not(:empty) { display: block; }
.player .bar { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.player .bar button, .player .unzoom { min-width: 40px; min-height: 40px; font-size: 1rem; background: var(--card);
       color: var(--text); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.player .bar .play { min-width: 52px; background: var(--accent); color: #fff; border-color: var(--accent); }
.player .seek { flex: 1 1 120px; min-width: 100px; accent-color: var(--accent); height: 32px; }
.player .time { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); }
.player .hint { margin: 4px 0 0; }
/* big view: real fullscreen where allowed, a fixed overlay elsewhere (iPhone) */
.player.big, .watch .player.big { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column;
              padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.player.big .stage { flex: 1; border-radius: 0; aspect-ratio: auto; }
.player.big .bar { background: rgba(0,0,0,.85); padding: 6px; margin: 0; }
.player.big .bar button { background: #222; color: #fff; border-color: #444; }
.player.big .time, .player.big .hint { color: #ccc; }
.player.big .hint { display: none; }
body.noscroll { overflow: hidden; }

/* phones: the player stays on top while the list scrolls; bigger touch targets */
@media (max-width: 899px) {
  .watch .player { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-bottom: 6px; }
  .player .hint { display: none; }
  .events { max-height: none; overflow: visible; }
}
@media (pointer: coarse) {
  table.stats td { padding-top: 0; padding-bottom: 0; height: 42px; }
  a.drill { display: block; padding: 11px 0; margin: 0 -4px; padding-left: 4px; padding-right: 4px; }
  .events li button.ev { min-height: 44px; }
  .pills a, .player button.part, details summary { min-height: 40px; display: inline-flex; align-items: center; }
}
.quarters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.quarters button.part { min-width: 44px; min-height: 36px; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
.quarters button.part.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.player .turn { display: none; position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); color: #fff;
                background: rgba(0,0,0,.55); padding: 2px 10px; border-radius: 6px; font-size: .8rem; white-space: nowrap; pointer-events: none; }
@media (orientation: portrait) and (max-width: 899px) { .player.big .turn { display: block; } }
@media (pointer: coarse) {
  .top nav a, .top nav button, .crumbs a, .lang button { min-height: 40px; display: inline-flex; align-items: center; }
  .lang button { padding: 0 12px; }
}
@media (pointer: coarse) {
  .brand, .scoreboard .side { min-height: 40px; display: inline-flex; align-items: center; }
  a.button { min-height: 44px; display: inline-flex; align-items: center; }
}
.player .quality { min-height: 40px; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.player.big .quality { background: #222; color: #fff; border-color: #444; }
.player .data { white-space: nowrap; }
