:root {
  --bg:        #0d1117;
  --bg-bar:    #161b22;
  --bg-row:    #0d1117;
  --bg-alt:    #12181f;
  --bg-hover:  #1c2530;
  --line:      #262d36;
  --line-soft: #1c222b;
  --fg:        #e6edf3;
  --fg-dim:    #8b949e;
  --fg-faint:  #6e7681;
  --accent:    #4493f8;
  --accent-dim:#1f4b7f;
  --good:      #3fb950;
  --good-soft: #1f6f31;
  /* a bright yellow, not the dark amber this used to be - it reads as yellow next to the
     red below rather than as a dim orange */
  --warn:      #eac54f;
  --blue:      #58a6ff;
  --danger:    #ff7b72;
  --live:      #f85149;
  --radius:    6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.4 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

body { display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ header */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 8px;
  flex: none;
}
.bar-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.bar-meta { margin-top: 8px; align-items: center; }

.field { display: flex; flex-direction: column; gap: 3px; }
.field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--fg-faint);
}

input {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}

.btn {
  background: #21262d;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  height: 30px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2c333c; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent-dim); border-color: #2f6bb0; }
.btn-primary:hover:not(:disabled) { background: #2a5f9e; }

/* auto-refresh toggle: off is a plain button, on glows and counts down */
.btn-auto { min-width: 96px; }
.btn-auto.is-active {
  background: #1d3b25;
  border-color: var(--good-soft);
  color: var(--good);
}
.btn-auto.is-active:hover { background: #24492e; }
.auto-count { color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.btn-auto.is-active .auto-count { color: #7ee08c; }

/* --------------------------------------------- championship multiselect */
.multi { position: relative; }
.multi-btn { display: flex; align-items: center; gap: 6px; min-width: 210px; justify-content: space-between; }
.multi-btn .caret { color: var(--fg-faint); font-size: 10px; }
.multi-btn.has-selection { border-color: var(--accent); color: var(--accent); }

.multi-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  min-width: 260px; max-height: 60vh; overflow: auto;
  background: var(--bg-bar);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
  padding: 6px;
}
.multi-actions { display: flex; gap: 10px; padding: 2px 6px 6px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.linkish {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: 11px;
}
.linkish:hover { text-decoration: underline; }

.multi-list { display: flex; flex-direction: column; }
.multi-item {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 6px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.multi-item:hover { background: var(--bg-hover); }
.multi-item input { height: auto; margin: 0; accent-color: var(--accent); }
.muted { color: var(--fg-faint); font-style: normal; font-size: 11px; }

.status { color: var(--fg-dim); font-size: 12px; }
.status .hl { color: var(--fg); }
.status.is-busy { color: var(--accent); }
.status.is-error { color: #f85149; }
.rowcount { margin-left: auto; color: var(--fg-faint); font-size: 12px; }

.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--live); margin-right: 7px; vertical-align: 1px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.spinner {
  display: inline-block; width: 10px; height: 10px; margin-right: 6px;
  border: 2px solid var(--accent-dim); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------- main */
main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* live match strip above the table */
.matches {
  flex: none;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #111720;
  max-height: 92px; overflow: auto;
}
/* each match is a toggle: click to show only its players, click again for all */
.match {
  display: flex; align-items: baseline; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 3px 8px; background: var(--bg-row);
  font: inherit; font-size: 12px; color: var(--fg-dim);
  cursor: pointer; text-align: left;
}
.match:hover:not(:disabled) { background: var(--bg-hover); border-color: #3a4552; }
.match:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.match:disabled { cursor: default; }
.match-empty { opacity: .45; }
/* the picked match */
.match.is-selected {
  border-color: var(--accent); background: #16283d; color: var(--fg);
}
.match.is-selected .m-league { color: #7fb3f0; }
/* everything else recedes while one match is pinned */
.match.is-muted { opacity: .4; }
.m-min { color: var(--live); font-variant-numeric: tabular-nums; min-width: 26px; }
/* match xG less 0.75 per goal - the strip's sort key, so it reads as a figure not a note */
.m-xg { color: var(--good); font-variant-numeric: tabular-nums; font-size: 11px; }
.match.is-muted .m-xg { color: var(--fg-dim); }
.m-teams b { color: var(--fg); }
.m-league { color: var(--fg-faint); font-size: 11px; }
.m-players {
  color: var(--fg-faint); font-size: 10px;
  border: 1px solid var(--line-soft); border-radius: 8px; padding: 0 5px;
}
.match.is-selected .m-players { color: var(--accent); border-color: var(--accent-dim); }

.empty { margin: 48px auto; text-align: center; color: var(--fg-dim); max-width: 480px; }
.empty p { margin: 0; }

.table-wrap { flex: 1 1 auto; overflow: auto; min-height: 0; }

/* ------------------------------------------------------------------ table */
table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }

th, td { padding: 3px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line-soft); }

thead th {
  position: sticky; top: 0; z-index: 10;
  background: #1b222b;
  color: var(--fg-dim);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--line);
}
thead th:hover { color: var(--fg); background: #222b36; }
/* primary sort is bright; the two remembered tiebreaks are dimmed and numbered */
thead th.sorted { color: var(--accent); }
thead th.sorted-tie { color: #6f8fb5; }
thead th .arrow { margin-left: 3px; font-size: 9px; opacity: .9; }
thead th.sorted-tie .arrow { font-size: 8px; opacity: .8; letter-spacing: .5px; }
thead th.flag-head { color: #b3c4d4; }
thead th.hot-head { color: var(--good); }

/* group separators keep the stat blocks visually distinct */
th.group-start, td.group-start { border-left: 1px solid var(--line); }

tbody tr { background: var(--bg-row); }
tbody tr:nth-child(even) { background: var(--bg-alt); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:hover td.sticky { background: var(--bg-hover); }

td.num, td.txt { font-variant-numeric: tabular-nums; }
td.txt { text-align: left; color: var(--fg-dim); }
td.zero { color: var(--fg-faint); }

/* sticky player + team columns */
th.sticky, td.sticky { position: sticky; text-align: left; }
th.c-player, td.c-player { left: 0; width: 178px; max-width: 178px; overflow: hidden; text-overflow: ellipsis; }
th.c-team,   td.c-team   { left: 178px; width: 128px; max-width: 128px; overflow: hidden; text-overflow: ellipsis; color: var(--fg-dim); border-right: 1px solid var(--line); }

td.sticky { z-index: 5; background: var(--bg-row); }
tbody tr:nth-child(even) td.sticky { background: var(--bg-alt); }
thead th.sticky { z-index: 15; background: #1b222b; }

/* flag columns: a lit flag is the signal, a 0 should recede */
td.flag { color: #d7e3ef; font-weight: 600; }
td.flag.zero { color: #3d444d; font-weight: 400; }
td.flag-total { color: var(--fg); font-weight: 600; }
td.flag-total.zero { color: var(--fg-faint); font-weight: 400; }
td.lit-hot { color: var(--good); }
td.lit-warn { color: var(--warn); }
td.lit-danger { color: var(--danger); }
td.lit-volume { color: var(--blue); font-weight: 600; }

/* Row highlights, on the player's name. One tone per row; the server picks which - green
   beats blue on the shooting side, red beats yellow on the fouling side, shooting beats
   fouling overall. */
tbody tr.is-hot    td.c-player { color: var(--good);   font-weight: 600; }
tbody tr.is-volume td.c-player { color: var(--blue);   font-weight: 600; }
tbody tr.is-danger td.c-player { color: var(--danger); font-weight: 600; }
tbody tr.is-warn   td.c-player { color: var(--warn);   font-weight: 600; }

/* ---------------------------------------------- change since the last refresh */
td.delta-up { color: var(--accent); font-weight: 600; text-align: left; }
td.delta-on { color: var(--fg-faint); text-align: left; font-size: 11px; }
thead th.delta-head { color: var(--accent); }

/* A row that moved since the last poll fades from a highlight back to normal, so a glance
   at the board a few seconds after a refresh still shows what happened. */
tbody tr.is-fresh { animation: freshen 12s ease-out 1; }
tbody tr.is-fresh td.sticky { animation: freshen-cell 12s ease-out 1; }
@keyframes freshen {
  0%   { background: #17334f; }
  35%  { background: #142a41; }
  100% { background: transparent; }
}
@keyframes freshen-cell {
  0%   { background: #17334f; }
  35%  { background: #142a41; }
  100% { background: var(--bg-row); }
}
@media (prefers-reduced-motion: reduce) {
  tbody tr.is-fresh, tbody tr.is-fresh td.sticky { animation: none; background: #142a41; }
  .live-dot { animation: none; }
}

/* ------------------------------------------------------------------- defcon */
td.defcon { font-weight: 600; color: #d7e3ef; }
td.defcon.zero { color: var(--fg-faint); font-weight: 400; }
thead th.defcon-head { color: #9db6d0; }

/* ----------------------------------------------------------------- legend */
.legend {
  flex: none;
  display: flex; gap: 18px; flex-wrap: wrap;
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-bar);
  color: var(--fg-faint);
  font-size: 11px;
}
.legend b { font-weight: 600; }
.k-hot { color: var(--good); }
.k-warn { color: var(--warn); }
.k-delta { color: var(--accent); }
.k-blue { color: var(--blue); }
.k-danger { color: var(--danger); }
