:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #18233a;
  --text: #e6edf7;
  --muted: #93a3bd;
  --line: #26344f;
  --control-border: #6b7a96; /* >= 3:1 on --bg, --panel and --panel-2 (WCAG 1.4.11) */
  --home: #38bdf8;
  --away: #fbbf24;
  --accent: #a78bfa;
  --ok: #34d399;
  --warn: #f87171;
  --pitch: #14532d;
  --pitch-line: rgba(255, 255, 255, 0.75);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; display: flex; flex-direction: column; }
button, select, .button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--control-border); border-radius: 8px; padding: 0.4rem 0.7rem; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 0.3rem;
}
button:hover, .button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, .button:focus-visible, input:focus-visible,
summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0.75rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; }
.brand h1 { font-size: inherit; font-weight: 400; margin: 0; }
.logo { color: var(--accent); font-size: 1.4rem; }
.pill { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.synthetic { color: var(--accent); border-color: var(--accent); }

.scoreboard {
  display: flex; flex-wrap: wrap; justify-content: center; max-width: 100%; align-items: center; gap: 0.2rem 0.6rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.35rem 0.8rem; font-variant-numeric: tabular-nums;
}
.scoreboard .team { font-weight: 600; }
.scoreboard .home { color: var(--home); }
.scoreboard .away { color: var(--away); }
.score { font-size: 1.4rem; font-weight: 800; }
.dash { margin: 0 0.3rem; color: var(--muted); }
.clock { font-weight: 700; min-width: 3.5rem; text-align: right; }
.period { color: var(--muted); font-size: 0.8rem; }

.mode-toggle { display: inline-flex; border: 1px solid var(--control-border); border-radius: 999px; overflow: hidden; }
.mode-toggle button:focus-visible { outline-offset: -4px; outline-color: var(--text); } /* not clipped by the pill */
.mode-toggle button { border: 0; border-radius: 0; background: transparent; padding: 0.45rem 0.9rem; }
.mode-toggle button[aria-checked="true"] { background: var(--accent); color: #111; font-weight: 700; }

.layout {
  flex: 1; display: grid; gap: 1rem; padding: 1rem;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr);
}
@media (max-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.stage, .side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; }
.side { display: flex; flex-direction: column; gap: 0.6rem; max-height: calc(100vh - 7rem); overflow: auto; }
@media (max-width: 960px) { .side { max-height: none; } }
.side h2 { margin: 0.2rem 0; font-size: 1rem; }
.shortcuts { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.shortcuts button { font-size: 0.85rem; }
.shortcuts button.primary { background: var(--accent); color: #111; font-weight: 700; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }

.pitch-wrap { position: relative; }
#pitch, #lineup { width: 100%; height: auto; display: block; background: var(--pitch); border-radius: 10px; }
#markings *, .lineup-markings * { fill: none; stroke: var(--pitch-line); stroke-width: 0.3; }
#markings .spot, .lineup-markings .spot { fill: var(--pitch-line); stroke: none; }
.ev { stroke-linecap: round; fill: none; }
.ev.home { stroke: var(--home); }
.ev.away { stroke: var(--away); }
.ev.shot { stroke-width: 0.8; stroke-dasharray: 1.2 0.8; }
.ev.pass { stroke-width: 0.45; }
.dot.home { fill: var(--home); }
.dot.away { fill: var(--away); }
.ball { fill: #fff; stroke: #111; stroke-width: 0.25; }
.goal-mark { fill: #fff; stroke: var(--ok); stroke-width: 0.4; }
.hl { stroke: #fff; stroke-width: 1.1; fill: none; }
.hl-dot { fill: #fff; stroke: var(--accent); stroke-width: 0.5; }

.lower-third {
  position: absolute; left: 4%; right: 4%; bottom: 6%; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem;
  background: rgba(11, 18, 32, 0.88); border-left: 4px solid var(--accent); border-radius: 8px; padding: 0.5rem 0.75rem;
}
.lt-kind { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.lt-title { font-weight: 700; }
.lt-fact { color: var(--text); font-size: 0.9rem; flex-basis: 100%; }
@media (max-width: 600px) { .lower-third { position: static; margin-top: 0.4rem; } } /* never hide the play */
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; color: var(--muted); font-size: 0.8rem; margin-top: 0.4rem; }
.key { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; }
.home-key { background: var(--home); }
.away-key { background: var(--away); }
.dir { margin-left: auto; }

/* Pitch view: live ball events or both lineups */
.view-toggle { display: inline-flex; border: 1px solid var(--control-border); border-radius: 999px; overflow: hidden; margin: 0 0 0.5rem; }
.view-toggle button { border: 0; border-radius: 0; background: transparent; padding: 0.3rem 0.85rem; font-size: 0.85rem; }
.view-toggle button[aria-pressed="true"] { background: var(--text); color: #111; font-weight: 700; }
.view-toggle button:focus-visible { outline-offset: -4px; }
.lp { cursor: pointer; }
.lp-dot { stroke: var(--bg); stroke-width: 0.35; }
.lp.home .lp-dot { fill: var(--home); }
.lp.away .lp-dot { fill: var(--away); }
.lp-num { font-size: 2.6px; font-weight: 800; text-anchor: middle; fill: var(--bg); pointer-events: none; }
.lp-name { font-size: 2px; font-weight: 600; text-anchor: middle; fill: #fff; paint-order: stroke; stroke: rgba(11, 18, 32, 0.85); stroke-width: 0.6px; pointer-events: none; }
.lp-name.long { font-size: 1.7px; }
.lp-goal { fill: #fff; stroke: var(--bg); stroke-width: 0.35; }
.lp:hover .lp-dot, .lp.followed .lp-dot { stroke: #fff; stroke-width: 0.7; }
.lp:focus-visible .lp-dot { stroke: var(--accent); stroke-width: 0.9; }
@media (max-width: 600px) { .lp-name { display: none; } } /* too small to read: numbers, with names in each label */
.lineup-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; align-items: center; justify-content: space-between; font-size: 0.85rem; margin-top: 0.4rem; }
.lineup-team { font-weight: 700; }
.lineup-team.home { color: var(--home); }
.lineup-team.away { color: var(--away); }

/* Casual: one comparison bar per stat */
.bars {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0.6rem 1.5rem;
  margin: 0.7rem 0; padding: 0.7rem 0.85rem; background: var(--panel-2); border-radius: 10px;
}
.bars-head { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 1rem; font-size: 0.8rem; font-weight: 700; }
.bars-head .home { color: var(--home); }
.bars-head .away { color: var(--away); text-align: right; }
.bar-row { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr) 3.4rem; align-items: baseline; row-gap: 0.3rem; font-variant-numeric: tabular-nums; }
.bar-val { font-weight: 800; font-size: 1.05rem; }
.bar-val.away { text-align: right; }
.bar-label { text-align: center; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.bar { grid-column: 1 / -1; display: flex; gap: 3px; height: 6px; }
.bar span { border-radius: 3px; min-width: 3px; }
.bar-home { background: var(--home); }
.bar-away { background: var(--away); }
.bar.empty span { background: var(--line); }
.bar-row.heuristic .bar span { opacity: 0.55; } /* synthetic xG: a heuristic, drawn fainter */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 0.5rem; margin: 0.7rem 0; }
.stats > div { background: var(--panel-2); border-radius: 8px; padding: 0.45rem 0.6rem; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.75rem; }
#stat-last { font-size: 0.85rem; overflow-wrap: anywhere; } /* wrap, never truncate (WCAG 1.4.10) */

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.controls .speed { display: inline-flex; gap: 0.35rem; align-items: center; color: var(--muted); font-size: 0.85rem; max-width: 100%; }
.controls .speed select { min-width: 0; }
.controls #download { margin-left: auto; }
.controls .keys { flex-basis: 100%; }

.timeline { position: relative; margin-top: 1.4rem; }
.markers { position: relative; height: 1.6rem; }
.marker {
  position: absolute; top: 0; transform: translateX(-50%); width: 1.5rem; height: 1.5rem; padding: 0; /* 24px target */
  border-radius: 50%; font-size: 0.75rem; justify-content: center; border: 2px solid var(--line);
}
.marker.goal { background: var(--ok); color: #111; border-color: var(--ok); }
.marker.big_chance_missed { background: var(--warn); color: #111; border-color: var(--warn); }
.marker.press_win { background: var(--accent); color: #111; border-color: var(--accent); }
.marker.full_time { background: var(--text); color: #111; border-color: var(--text); width: 1.9rem; border-radius: 0.75rem; font-size: 0.65rem; font-weight: 700; }
.marker.goal-tick { width: 0.5rem; height: 0.5rem; top: 0.5rem; background: #fff; border: 0; cursor: default; }
#seek { width: 100%; accent-color: var(--accent); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; }

.card {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 10px; padding: 0.65rem 0.75rem; margin-bottom: 0.6rem;
}
.card.home { border-left-color: var(--home); }
.card.away { border-left-color: var(--away); }
.card.active { box-shadow: 0 0 0 2px var(--accent); }
.card header { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.card h3 { margin: 0.1rem 0 0; font-size: 1.12rem; line-height: 1.25; flex-basis: 100%; }
.card.full_time { border-left-color: var(--text); }
.kind { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.minute { font-size: 0.75rem; color: var(--muted); }
.facts { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-direction: column; gap: 0.35rem; }
.facts li { display: flex; gap: 0.4rem; font-size: 0.9rem; line-height: 1.35; }
.facts li .check { color: var(--ok); font-weight: 700; }
.facts li.heuristic .check { color: var(--away); }
.facts li.why { font-size: 0.98rem; font-weight: 600; }
details.chain, details.more { margin: 0 0 0.5rem; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; min-height: 24px; }
details.more .personalized-note { margin-top: 0.35rem; }
details.chain summary, .review summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; min-height: 24px; }
.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem; }
.chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 6px; min-height: 24px; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.chip.metric { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); color: #111; }
.review { border-top: 1px dashed var(--line); padding-top: 0.45rem; margin-bottom: 0.5rem; font-size: 0.85rem; }
.review h4 { margin: 0 0 0.2rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.review h5 { margin: 0.55rem 0 0; font-size: 0.8rem; color: var(--text); }
.review .summary { margin: 0.25rem 0; font-weight: 600; }
.review .explain { margin: 0.3rem 0 0.4rem; font-size: 0.9rem; line-height: 1.4; }
.review details.claims > summary { margin-top: 0.15rem; }
.review details.calls .hint { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; }
.review.spotlight { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.verdicts { list-style: none; padding: 0; margin: 0.4rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; }
.verdicts li { display: flex; gap: 0.4rem; line-height: 1.35; }
.verdicts li.ok .check { color: var(--ok); font-weight: 700; }
.verdicts li.rejected .check { color: var(--warn); font-weight: 700; }
.verdicts li.rejected { border-left: 3px solid var(--warn); padding-left: 0.35rem; }
.verdicts .source { display: block; font-size: 0.72rem; color: var(--muted); }
.verdicts .claim { font-size: 0.75rem; overflow-wrap: anywhere; }
.verdicts .reason { color: var(--warn); margin: 0.15rem 0 0; }
.verdicts .correction { margin: 0.15rem 0 0; }
.narrative { border-top: 1px dashed var(--line); padding-top: 0.45rem; font-size: 0.85rem; }
.narrative { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: center; }
.narrative > p, .narrative > details { flex-basis: 100%; }
.verified-note { color: var(--ok); font-size: 0.75rem; }
.narrative .status { display: inline-block; font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 999px; }
.status.template { background: #1f2937; color: var(--muted); border: 1px solid var(--line); }
.status.unverified { background: #3b0d0d; color: var(--warn); border: 1px solid var(--warn); }
.narrative .text { margin: 0.2rem 0 0; font-style: italic; }
.narrative summary { cursor: pointer; color: var(--muted); font-size: 0.8rem; }
.live { margin: 0 0 0.5rem; }
.live .live-check { border-color: var(--accent); }
.live .live-check[disabled] { opacity: 0.7; cursor: progress; }
.live p { margin: 0.35rem 0 0; font-size: 0.82rem; }
.live .live-ok { color: var(--ok); }
.live .warn { color: var(--warn); }
.narrative .warn { color: var(--warn); margin: 0.2rem 0 0; font-size: 0.78rem; }

.recap-open { font-size: 0.85rem; margin: 0 0 0.5rem; border-color: var(--accent); }
.recap {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 0.65rem 0.75rem;
}
.recap h3 { margin: 0.45rem 0 0; font-size: 1.12rem; line-height: 1.25; }
.recap h4 { margin: 0.55rem 0 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.recap-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
#recap-copy { background: var(--accent); color: #111; font-weight: 700; border-color: var(--accent); }
#recap-status { margin-top: 0.4rem; color: var(--ok); }
#recap-status:empty { display: none; }

.inspector { border-top: 1px solid var(--line); padding-top: 0.6rem; }
.inspector pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem;
  font-size: 0.75rem; overflow: auto; max-height: 16rem; white-space: pre-wrap; word-break: break-word;
}
.inspector dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.6rem; font-size: 0.85rem; margin: 0.3rem 0; }
.inspector dt { color: var(--muted); }
.inspector dd { margin: 0; }

#match { max-width: 100%; }
.personalize { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; margin: 0 0 0.6rem; color: var(--muted); font-size: 0.85rem; }
.personalize label { display: inline-flex; gap: 0.35rem; align-items: center; }
.personalize select { max-width: 100%; }
.personalized-note { font-size: 0.78rem; margin: 0 0 0.45rem; }
.footer { padding: 0.6rem 1rem 1rem; color: var(--muted); font-size: 0.8rem; }
.footer p { margin: 0; max-width: 70rem; }
.player-panel { background: var(--panel-2); border-radius: 8px; padding: 0.55rem 0.7rem; margin: 0.8rem 0 0; border-left: 4px solid var(--line); }
.player-panel.home { border-left-color: var(--home); }
.player-panel.away { border-left-color: var(--away); }
.player-panel h2 { margin: 0 0 0.15rem; font-size: 1rem; }
.player-panel .team-line { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.player-facts { list-style: none; padding: 0; margin: 0.4rem 0 0; display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.player-facts .heuristic { color: var(--away); }
.player-table { width: 100%; border-collapse: collapse; margin-top: 0.4rem; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.passing-panel { background: var(--panel-2); border-radius: 8px; padding: 0.55rem 0.7rem; margin: 0.8rem 0 0; }
.passing-panel h2 { margin: 0 0 0.15rem; font-size: 1rem; }
.player-table td.num { white-space: nowrap; }
.player-table th, .player-table td { text-align: left; padding: 0.2rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.player-table th { color: var(--muted); font-weight: 400; }
.player-table td.kind-heuristic { color: var(--away); }
.ev.mine { stroke-width: 0.9; }
.dot.mine { stroke: #fff; stroke-width: 0.3; }
.player-pos { fill: none; stroke: #fff; stroke-width: 0.45; stroke-dasharray: 0.8 0.5; }
.features { font-size: 0.7rem; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid var(--accent); color: var(--text); }
#player { max-width: 100%; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
