:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #30363d;
  --text: #d9dde3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --pre: #101418;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
header h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
header nav { display: flex; gap: 6px; }
.tab {
  text-decoration: none; color: var(--muted);
  padding: 5px 10px; border-radius: 5px; font-size: 13px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: var(--text); background: var(--panel-2); border: 1px solid var(--line); }

.status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--yellow); box-shadow: 0 0 6px currentColor;
}
.dot.ok { background: var(--green); color: var(--green); }
.dot.bad { background: var(--red); color: var(--red); }

main { padding: 14px 18px 60px; }

.view { display: block; }
.view.hidden { display: none; }

.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 9px 12px; margin-bottom: 12px;
}
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.toolbar label.checkbox { gap: 4px; }
.toolbar input, .toolbar select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px;
  font: inherit; font-size: 13px;
}
.toolbar button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px;
  cursor: pointer; font: inherit; font-size: 12px;
}
.toolbar button:hover { border-color: var(--accent); }
.grow { flex: 1; }
.meta { color: var(--muted); font-size: 12px; }

/* matches list */
.match-list { display: grid; gap: 6px; }
.match {
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
  padding: 7px 12px; cursor: pointer;
  transition: border-color .12s;
}
.match:hover { border-color: var(--accent); }
.match-line1 {
  display: grid;
  grid-template-columns: 96px 1fr 1fr auto auto;
  align-items: center; gap: 14px;
}
.match-line2 {
  color: var(--muted); font-size: 11px;
  margin-top: 2px;
  padding-left: 110px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, monospace;
}
.match .sid {
  color: var(--muted); font-size: 11px;
  font-family: ui-monospace, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.match .home, .match .away { font-weight: 500; }
.match .away { text-align: right; opacity: .9; }
.match .live {
  font-size: 10px; padding: 2px 6px; border-radius: 3px;
  background: var(--red); color: white; letter-spacing: .04em;
  font-family: ui-monospace, monospace; font-weight: 600;
  white-space: nowrap;
}
.match .live.paused    { background: var(--yellow); color: #0e1117; }
.match .live.finished  { background: #444;          color: #ddd; }
.match .upstreams { display: flex; gap: 4px; }
.match .pill {
  font-size: 10px; padding: 2px 7px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  font-family: ui-monospace, monospace;
}
.match .pill.has-365zeta { color: #79c0ff; border-color: #1f6feb55; }
.match .pill.has-kswin365 { color: #ffa657; border-color: #d2992233; }

/* match detail */
.match-detail {
  position: fixed; right: 18px; top: 70px; bottom: 18px; width: 640px; max-width: calc(100vw - 36px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  overflow: auto; padding: 16px 18px; z-index: 6;
  box-shadow: -10px 0 30px rgba(0,0,0,0.4);
}
.match-detail.hidden { display: none; }
.match-detail h2 { margin: 0 0 4px; font-size: 16px; }
.match-detail .md-league { color: var(--text); font-size: 12px; margin: 0 0 6px; opacity: 0.85; }
.match-detail .md-league:empty { display: none; }
.match-detail .close {
  position: absolute; top: 8px; right: 10px;
  background: transparent; border: 0; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.match-detail .close:hover { color: var(--text); }
.match-detail table {
  width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px;
}
.match-detail th, .match-detail td {
  padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right;
}
.match-detail th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; text-align: right; }
.match-detail th:nth-child(-n+2), .match-detail td:nth-child(-n+2) { text-align: left; }
.match-detail td.price { font-family: ui-monospace, monospace; }
.match-detail td.price.blocked { color: var(--muted); text-decoration: line-through; }
.match-detail td.price.flash { background: #1f6feb33; transition: background 1s; }
.match-detail td.diff.up { color: var(--green); }
.match-detail td.diff.down { color: var(--red); }
.match-detail td.diff.zero { color: var(--muted); }

/* stream tape */
.tape {
  background: var(--pre); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 12px; height: calc(100vh - 200px); overflow: auto;
  font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.5;
}
.tape .row { display: grid; grid-template-columns: 70px 90px 130px 100px 70px 70px 1fr;
  gap: 8px; padding: 2px 0; border-bottom: 1px dotted #ffffff10;
  animation: appear .3s ease;
}
@keyframes appear { from { background: #1f6feb22; } to { background: transparent; } }
.tape .ts { color: var(--muted); }
.tape .up-365zeta { color: #79c0ff; }
.tape .up-kswin365 { color: #ffa657; }
.tape .gid { color: var(--muted); }
.tape .price { font-weight: 600; }
.tape .price.blocked { color: var(--red); }

/* outflow tree (sport > league > match > odds squares) */
.outflow-tree { display: flex; flex-direction: column; gap: 18px; padding-bottom: 80px; }
.of-sport { }
.of-sport-h {
  margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.of-count { color: var(--muted); font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.of-league { margin: 8px 0 14px 6px; }
.of-league-h {
  margin: 0 0 6px; font-size: 13px; color: var(--text); font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.of-match {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; margin-bottom: 8px;
}
.of-match-h {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--line);
}
.of-teams { font-weight: 600; font-size: 13px; }
.of-sub { color: var(--muted); font-size: 11px; }
.of-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600; letter-spacing: .04em;
}
.of-live { background: var(--green); color: #fff; }
.of-brk  { background: #d29922; color: #000; }
.of-fin  { background: #444; color: #fff; }
.of-markets { display: flex; flex-direction: column; gap: 10px; }
.of-market { }
.of-market-h {
  margin: 0 0 4px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
}
.of-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
}
.of-odd {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 6px 8px; font-size: 11px; line-height: 1.4;
  display: flex; flex-direction: column; gap: 2px;
  transition: background 1s;
}
.of-odd.flash { background: #1f6feb33; }
.of-odd.blocked { opacity: 0.55; }
.of-odd.blocked .of-odd-price { text-decoration: line-through; color: var(--muted); }
.of-odd-outcome { color: var(--text); font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.of-odd-price { font-family: ui-monospace, monospace; font-size: 14px; font-weight: 600; }
.of-odd-age { color: var(--muted); font-size: 10px; }

/* health cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 12px 14px;
}
.card h3 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card .row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.card .row .k { color: var(--muted); }
.card .row .v { font-family: ui-monospace, monospace; }
.card .ok { color: var(--green); }
.card .bad { color: var(--red); }
.card .stale { color: var(--yellow); }

details.raw { margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
pre {
  background: var(--pre); border: 1px solid var(--line); border-radius: 5px;
  padding: 10px 12px; overflow: auto; font-size: 12px;
  margin-top: 8px;
}

footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; gap: 14px; align-items: center;
  padding: 6px 18px; background: var(--panel); border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}
footer a { color: var(--muted); }
code { font-family: ui-monospace, monospace; }

/* ----- events tape + per-match timeline ----- */
.event-tape .row, .event-timeline .event-row {
  display: grid;
  grid-template-columns: 80px 110px 50px 60px 120px 60px 120px 1fr auto;
  gap: 8px; align-items: baseline;
  padding: 4px 8px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-family: ui-monospace, monospace;
}
.event-tape .row .ev-text, .event-timeline .ev-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-kind { font-weight: 600; }
.ev-kind-incident { color: #f0883e; }
.ev-kind-score    { color: #3fb950; }
.ev-kind-period   { color: #d29922; }
.ev-kind-stat     { color: #58a6ff; }
.ev-kind-heartbeat{ color: var(--muted); opacity: .7; }
.ev-min { color: var(--muted); }
.ev-team { font-size: 10px; padding: 1px 5px; border-radius: 3px; }
.ev-team.ev-home { background: rgba(63,185,80,.16); color: #3fb950; }
.ev-team.ev-away { background: rgba(248,81,73,.16); color: #f85149; }
.ev-player, .ev-type, .ev-ordinal {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-player { color: var(--text); }
.ev-type { text-transform: lowercase; }
.ev-ordinal { text-align: center; }
.ev-score { background: var(--pre); padding: 1px 6px; border-radius: 3px; }
.ev-stat { color: var(--muted); font-size: 11px; }
.event-timeline { max-height: 480px; overflow-y: auto; background: var(--panel); border-radius: 5px; }

/* ----- match-detail sub-tabs (Odds vs Events) ----- */
.md-subtabs {
  display: flex; gap: 4px;
  margin: 14px 0 10px;
  border-bottom: 1px solid var(--line);
}
.md-subtab {
  padding: 8px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms, border-color 120ms;
}
.md-subtab:hover { color: var(--fg); }
.md-subtab.active {
  color: var(--fg);
  border-bottom-color: var(--accent, #58a6ff);
}
.md-subtab[data-subtab="stats"].active {
  color: #ffd0b3;
  border-bottom-color: #ff6600;
}
.md-subtab-count {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
.md-pane { padding-top: 6px; }
.md-pane.hidden { display: none; }

/* ----- match-detail stats tab ----- */
#md-pane-stats {
  --stats-accent: #ff6600;
}
.stat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-row {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.00));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px 11px;
}
.stat-head {
  display: grid;
  grid-template-columns: minmax(56px, 1fr) auto minmax(56px, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.stat-value {
  font: 700 16px/1.1 ui-monospace, monospace;
  color: #f3f5f7;
}
.stat-home { text-align: left; }
.stat-away { text-align: right; }
.stat-label {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: none;
}
.stat-bar {
  position: relative;
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: #242a33;
}
.stat-fill {
  position: absolute;
  top: 0;
  bottom: 0;
}
.stat-fill.left {
  left: 0;
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
}
.stat-fill.right {
  right: 0;
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}
.stat-fill.accent { background: var(--stats-accent); }
.stat-fill.muted { background: #525a66; }
.stat-fill.neutral { background: #6b7280; }
.stat-empty { color: var(--muted); }

/* Generic .hidden — children of panes need to be toggleable too
   (e.g. #md-events-empty inside the events pane). The existing
   .view.hidden / .md-pane.hidden rules above stay specific so this
   doesn't override them. */
.hidden { display: none !important; }

/* ----- incident subkinds (parsed from LA= text in events.js) ----- */
.ev-sub-goal           { color: #3fb950; font-weight: 600; }
.ev-sub-own-goal       { color: #f0883e; font-weight: 600; }
.ev-sub-penalty        { color: #3fb950; font-weight: 600; }
.ev-sub-yellow-card    { color: #e3b341; }
.ev-sub-red-card       { color: #f85149; font-weight: 600; }
.ev-sub-substitution   { color: #58a6ff; }
.ev-sub-period-marker  { color: #d29922; font-style: italic; }
.ev-sub-shot-on        { color: #58a6ff; }
.ev-sub-shot-off       { color: var(--muted); }
.ev-sub-corner         { color: #79c0ff; }
.ev-sub-offside        { color: #db6d28; }
.ev-sub-free-kick      { color: var(--muted); }
.ev-sub-throw-in       { color: var(--muted); }
.ev-sub-goal-kick      { color: var(--muted); }
/* Race-to-N-Corners is a betting-derivative marker, not a real
   incident — mute it so the timeline isn't dominated by them. */
.ev-sub-race           { color: var(--muted); opacity: 0.65; font-size: 11px; }

/* ----- match-detail header (Task 7) ----- */
.md-header {
  margin-bottom: 10px;
}

/* Three-column grid: home team | score | away team.
   Cap the score column so the name columns get at least half the panel. */
.md-teams-row {
  display: grid;
  grid-template-columns: 1fr minmax(80px, 120px) 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
}

.md-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.md-team-home { align-items: flex-start; }
.md-team-away { align-items: flex-end; }

.team-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 4px;
}
.team-initials {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .02em;
  color: var(--text);
  flex-shrink: 0;
}

/* Team name: stretch to fill the full grid column regardless of align-items.
   Without align-self:stretch the name is bounded by the cross-axis of the
   flex container, which collapses to the badge width (40px) with
   align-items:flex-end — truncating long names and appearing to overlap. */
.md-team .team-name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  align-self: stretch;
  word-break: break-word;
  text-align: left;
}
.md-team-away .team-name { text-align: right; }

/* Score column — centered between the two team columns */
.md-score-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 80px;
}
.md-score-main {
  font: 700 26px/1 ui-monospace, monospace;
  color: var(--text);
  letter-spacing: .03em;
  white-space: nowrap;
}
.md-halftime-scores {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}
.md-halftime-scores:empty { display: none; }

/* Goal scorer strip — one line per goal, shown under half-time scores */
.md-goals {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  justify-content: center;
  margin-top: 2px;
}
.md-goals:empty { display: none; }
.goal-line {
  font-size: 11px;
  color: var(--fg);
  white-space: nowrap;
}
.goal-line.goal-home { color: var(--accent); }
.goal-line.goal-away { color: var(--muted); }

.md-period-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.md-period-label:empty { display: none; }
.md-clock {
  font: 600 13px/1 ui-monospace, monospace;
  color: var(--accent);
}

/* Extra row: referee + venue (hidden by default) */
.md-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--muted);
}
.md-extra-item { white-space: nowrap; }

/* Source health indicator (BM / KH dots) */
.md-source-health {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 4px;
  font-size: 11px;
  color: var(--muted);
}
.src-health-label { color: var(--muted); }
.src-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  letter-spacing: .04em;
  background: #3a2a00;
  color: var(--yellow);
}
.src-dot.ok    { background: #0d2a14; color: var(--green); }
.src-dot.stale { background: #2a0d0d; color: var(--red); }

/* Suspended badge in the Odds subtab */
.suspended-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  background: var(--yellow);
  color: #0e1117;
  vertical-align: middle;
  margin-left: 4px;
}

/* Banner below the subtabs when odds are suspended */
.suspended-notice {
  background: #2a200a;
  border: 1px solid #5a4010;
  border-radius: 5px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--yellow);
  margin-bottom: 10px;
}

/* Stat row with no proportional bar (e.g. Substitutions) */
.stat-no-bar .stat-bar { display: none; }
