:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --team-a: #2a78d6;
  --team-b: #eb6834;
  --good: #0ca30c;
  --bad: #d03b3b;
  --accent: #2a78d6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --team-a: #3987e5;
    --team-b: #d95926;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --team-a: #3987e5;
  --team-b: #d95926;
  --accent: #3987e5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

header.top {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
header.top .brand { font-weight: 700; text-decoration: none; color: var(--ink); }
header.top .spacer { flex: 1; }
main { max-width: 1280px; margin: 0 auto; padding: 1rem 16px 3rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 1rem; }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--ink); padding: .45rem .8rem; text-decoration: none;
  display: inline-flex; align-items: center; gap: .4rem;
}
button:hover, .btn:hover { filter: brightness(0.96); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--accent); color: #fff; border-color: transparent; }
button.danger { color: var(--bad); }
kbd {
  font: 600 .72rem ui-monospace, monospace; padding: .05rem .35rem; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
}

input[type=text], input[type=number] {
  font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--axis);
  background: var(--surface); color: var(--ink); width: 100%;
}
label { display: block; font-size: .85rem; color: var(--ink-2); }
label input { margin-top: .25rem; }
label input[type=text] { font-size: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--grid); }
th { color: var(--ink-2); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: baseline; margin-right: .3rem; }
.swatch.a { background: var(--team-a); }
.swatch.b { background: var(--team-b); }

/* ---- Tracker ---- */
.video-box { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.video-box video { width: 100%; height: 100%; }
.video-box .placeholder { color: #c3c2b7; text-align: center; padding: 1rem; }
.clock-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.clock { font: 700 1.6rem ui-monospace, monospace; font-variant-numeric: tabular-nums; min-width: 7ch; }
.source-tabs { display: flex; gap: .25rem; margin-bottom: .75rem; }
.source-tabs button[aria-pressed=true] { background: var(--accent); color: #fff; border-color: transparent; }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; gap: .5rem; }
.scoreboard .score { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.scoreboard .team-name { font-weight: 600; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.team-panel { border-top: 4px solid var(--team-a); padding-top: .5rem; }
.team-panel.b { border-top-color: var(--team-b); }
.outcome-btn {
  width: 100%; justify-content: space-between; padding: 1.1rem .9rem; font-size: 1.05rem; font-weight: 600;
  margin-top: .5rem; border-width: 2px;
}
.outcome-btn.winner { border-color: color-mix(in srgb, var(--good) 55%, transparent); }
.outcome-btn.error { border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.outcome-btn.selected { outline: 3px solid var(--accent); outline-offset: 2px; }

.shot-picker { margin-top: 1rem; border: 2px dashed var(--accent); border-radius: var(--radius); padding: .75rem; }
.shot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .5rem; margin-top: .5rem; }
.shot-grid button { padding: .9rem .7rem; justify-content: space-between; font-weight: 600; }

.log { max-height: 420px; overflow-y: auto; }
.log td button { padding: .15rem .45rem; font-size: .8rem; }
.log tr.flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 25%, transparent); } to { background: transparent; } }
.seek { background: none; border: none; padding: 0; color: var(--accent); font-variant-numeric: tabular-nums; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page);
  padding: .5rem .9rem; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* ---- Summary ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.tile .value { font-size: 1.9rem; font-weight: 700; }
.tile .label { color: var(--ink-2); font-size: .85rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.chart-box { position: relative; height: 300px; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--ink-2); margin-bottom: .5rem; }

/* ---- YouTube + names dialog ---- */
.video-box > * { grid-area: 1 / 1; }
.video-box iframe { width: 100%; height: 100%; border: 0; }
dialog {
  width: min(440px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); padding: 1.25rem;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.url-bar { display: flex; gap: .5rem; margin-bottom: .75rem; }

/* ---- Player fields ---- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
fieldset.players { border: 0; padding: 0; margin-inline: 0; margin-bottom: 0; }
.format-toggle { display: inline-flex; gap: .25rem; padding: .2rem; border-radius: 10px; background: var(--surface-2); margin-bottom: .75rem; }
.format-toggle .chip { display: inline-flex; cursor: pointer; }
.format-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.format-toggle span { padding: .35rem .9rem; border-radius: 8px; color: var(--ink-2); font-size: .9rem; }
.format-toggle input:checked + span { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.format-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.sides { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; }
.side { display: grid; gap: .4rem; align-content: start; }
.side-label { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.form-errors { color: var(--bad); margin: 0 0 .75rem; padding-left: 1.2rem; font-size: .9rem; }

/* ---- Single-page layout ---- */
[hidden] { display: none !important; }
header.top .brand { cursor: default; }
nav.views { display: flex; gap: .35rem; }
.setup { max-width: 720px; margin: 0 auto; }
.note { margin: 1.25rem 0 0; padding: .6rem .8rem; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); }
.stats-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stats-actions .spacer { flex: 1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
label.inline { display: flex; align-items: center; gap: .35rem; }
input[aria-invalid] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
