:root {
  --bg: #0f1216;
  --surface: #161a20;
  --surface-2: #1d222a;
  --border: #2a313b;
  --border-strong: #3a4350;
  --text: #e9e6df;
  --muted: #9aa3ae;
  --faint: #6b7480;
  --accent: #f2b33d;
  --accent-ink: #1a1405;
  --ours: #f2b33d;
  --theirs: #6fa8dc;
  --win: #4cc38a;
  --loss: #ef6b6b;
  --draw: #b9a7f0;
  --paper: #f5f0e4;
  --paper-ink: #1f1c17;
  --paper-muted: #6b6457;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  --mono: 'Cascadia Mono', Consolas, 'SFMono-Regular', Menlo, monospace;
  --topbar-bg: rgba(15, 18, 22, 0.92);
  --q-win-ink: #7ee2a8;
  --q-loss-ink: #ffb0ad;
  /* Charts (validated for colour-blind separation and 3:1 contrast on their surface) */
  --chart-ours: #c98500;
  --chart-theirs: #3987e5;
  --chart-grid: #262c35;
  --chart-axis: #9aa3ae;
  --chart-bg: #161a20;
  --chart-ink: #e9e6df;
  color-scheme: dark;
}

/* Light theme: chosen in your profile ("System" follows the computer's setting). */
:root[data-theme='light'] {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --border: #dde1e7;
  --border-strong: #c5cbd3;
  --text: #1c2026;
  --muted: #545d69;
  --faint: #7d8591;
  --accent: #9c6300;
  --accent-ink: #ffffff;
  --ours: #b06f00;
  --theirs: #2f6fd0;
  --win: #18804d;
  --loss: #c23a3a;
  --draw: #6a52c7;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --q-win-ink: #11713f;
  --q-loss-ink: #b02f2f;
  --chart-ours: #b06f00;
  --chart-theirs: #2f6fd0;
  --chart-grid: #e3e6eb;
  --chart-axis: #5f6874;
  --chart-bg: #ffffff;
  --chart-ink: #1c2026;
  color-scheme: light;
}
:root[data-theme='light'] body.admin { --accent: #5b48c2; --accent-ink: #ffffff; }
:root[data-theme='light'] body.admin .topbar { background: linear-gradient(180deg, #efecfb, var(--surface)); }
:root[data-theme='light'] dialog::backdrop { background: rgba(20, 24, 30, 0.35); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; }
h1 { font-size: 1.7rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }
.ai-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
}
.ai-pill:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--win); box-shadow: 0 0 0 3px rgba(76, 195, 138, 0.18); }
.dot.off { background: var(--loss); }

/* ---------- layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; }
.crumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.sidebar-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) {
  .split, .grid-2, .sidebar-layout { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .page { padding: 20px 16px 60px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin: 0 0 10px; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.danger { color: var(--loss); }
button.danger:hover { border-color: var(--loss); }
button.small, .btn.small { padding: 5px 10px; font-size: 0.82rem; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
textarea.code { font-family: var(--mono); font-size: 0.86rem; }
input[type='checkbox'], input[type='radio'] { width: auto; accent-color: var(--accent); }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.92rem; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text); font-weight: 600; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 22px; background: var(--border-strong); border-radius: 999px; position: relative; transition: background 0.15s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--win); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.4; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 6px 12px; }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button.on { background: var(--surface-2); color: var(--text); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 10px 14px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--muted); }
.chip.win { color: var(--win); border-color: rgba(76, 195, 138, 0.45); }
.chip.loss { color: var(--loss); border-color: rgba(239, 107, 107, 0.45); }
.chip.draw { color: var(--draw); border-color: rgba(185, 167, 240, 0.45); }
.chip.accent { color: var(--accent); border-color: rgba(242, 179, 61, 0.45); }
.status-draft { color: var(--muted); }
.status-approved { color: var(--theirs); border-color: rgba(111, 168, 220, 0.45); }
.status-published { color: var(--win); border-color: rgba(76, 195, 138, 0.45); }
.status-archived { color: var(--faint); }

/* ---------- team cards ---------- */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.team-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text); min-height: 150px;
  transition: border-color 0.12s, transform 0.12s;
}
.team-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.team-card .name { font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.team-card .meta { color: var(--muted); font-size: 0.85rem; }
.team-card .foot { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 0.82rem; color: var(--muted); }
.progress { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.group-title { margin: 26px 0 10px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* ---------- lists / tables ---------- */
.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list-row {
  display: grid; grid-template-columns: 120px minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text); cursor: pointer;
}
.list-row:first-child { border-top: 0; }
.list-row:hover { background: var(--surface-2); text-decoration: none; }
.list-row .round { font-weight: 700; }
.list-row .sub { color: var(--muted); font-size: 0.84rem; }
.list-row.empty .round { color: var(--muted); }
@media (max-width: 640px) { .list-row { grid-template-columns: 1fr auto; } .list-row .hide-sm { display: none; } }

.story-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text); }
.story-row:first-child { border-top: 0; }
.story-row:hover { background: var(--surface-2); text-decoration: none; }
.story-row .t { font-weight: 600; }

table.stats { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.stats th, table.stats td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.stats tr.total td { font-weight: 700; border-bottom: 0; }
table.stats td.hl { color: var(--accent); font-weight: 700; }
.table-wrap { overflow-x: auto; }

.scoreboard { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.scoreboard .side { display: flex; flex-direction: column; }
.scoreboard .side .n { font-size: 2.4rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.scoreboard .side .l { font-size: 0.85rem; color: var(--muted); max-width: 260px; }
.scoreboard .ours .n { color: var(--ours); }
.scoreboard .theirs .n { color: var(--theirs); }
.scoreboard .dash { font-size: 1.6rem; color: var(--faint); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.kpi .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k { font-size: 0.78rem; color: var(--muted); }

.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* ---------- newsprint ---------- */
.paper {
  background: var(--paper); color: var(--paper-ink);
  border-radius: 6px; padding: 34px 40px 30px;
  font: 17px/1.65 var(--serif);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2), 0 12px 30px rgba(0,0,0,0.35);
}
.paper .kicker { font: 600 0.72rem/1 var(--font); letter-spacing: 0.14em; text-transform: uppercase; color: var(--paper-muted); border-bottom: 1px solid #cfc6b3; padding-bottom: 10px; margin-bottom: 18px; display: flex; justify-content: space-between; gap: 10px; }
.paper h1 { font: 700 2rem/1.15 var(--serif); margin: 0 0 18px; letter-spacing: -0.01em; }
.paper h2, .paper h3 { font-family: var(--serif); margin: 20px 0 8px; }
.paper p { margin: 0 0 14px; }
.paper ul, .paper ol { margin: 0 0 14px; padding-left: 22px; }
.paper table { border-collapse: collapse; margin: 6px 0 16px; font: 0.86rem/1.4 var(--font); width: 100%; }
.paper th, .paper td { border-bottom: 1px solid #d8cfbc; padding: 5px 8px; text-align: left; }
.paper th { color: var(--paper-muted); }
@media (max-width: 640px) { .paper { padding: 22px 18px; font-size: 16px; } .paper h1 { font-size: 1.5rem; } }

.editor-title { font: 700 1.4rem/1.2 var(--serif); }
.story-editor { min-height: 460px; font: 16px/1.6 var(--serif); }

/* ---------- reporter editor ---------- */
.rules-editor { min-height: 62vh; font-family: var(--mono); font-size: 0.86rem; line-height: 1.55; tab-size: 2; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0; }
.toolbar + textarea { border-radius: 0 0 8px 8px; }
.toolbar .sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 4px; }
.findbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.findbar input { width: 160px; padding: 5px 8px; font-size: 0.85rem; }
.rep-item { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); border: 1px solid transparent; }
.rep-item:hover { background: var(--surface-2); text-decoration: none; }
.rep-item.on { background: var(--surface-2); border-color: var(--border-strong); }
.rep-item .n { font-weight: 600; }
.rep-item .d { font-size: 0.8rem; color: var(--muted); }
.dirty-flag { color: var(--accent); font-size: 0.82rem; font-weight: 600; }

/* ---------- misc ---------- */
.notice { border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); background: var(--surface); padding: 12px 14px; border-radius: 8px; font-size: 0.9rem; }
.notice.warn { border-left-color: var(--loss); }
.notice.ok { border-left-color: var(--win); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.empty-state { text-align: center; padding: 48px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }
.empty-state h2 { color: var(--text); }
.steps { text-align: left; max-width: 520px; margin: 14px auto 18px; }
pre.prompt { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font: 0.8rem/1.5 var(--mono); max-height: 50vh; overflow: auto; margin: 0; }
details > summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 0.88rem; }
details[open] > summary { margin-bottom: 10px; }
.kbd { font: 0.75rem var(--mono); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }
.bookmarklet { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: grab; }
.bookmarklet:hover { text-decoration: none; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.working { display: flex; align-items: center; gap: 10px; color: var(--muted); }

dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 0; width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog .dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
dialog .dlg-head h2 { margin: 0; }
dialog .dlg-body { padding: 18px 20px; overflow: auto; max-height: calc(100vh - 200px); }
dialog .dlg-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 3px solid var(--win); padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); font-size: 0.9rem; }
.toast.error { border-left-color: var(--loss); }

/* ---------- squad gaps & attendance chips ---------- */
table.stats tr.gap td { color: var(--muted); }
.gap-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chips { display: inline-flex; gap: 4px; }
.chip-btn { padding: 1px 8px; font-size: 0.72rem; font-weight: 600; border-radius: 999px; background: transparent; color: var(--faint); border: 1px solid var(--border-strong); }
.chip-btn:hover { color: var(--text); }
.chip-btn.on.quiet { color: var(--theirs); border-color: rgba(111, 168, 220, 0.6); background: rgba(111, 168, 220, 0.12); }
.chip-btn.on.absent { color: var(--loss); border-color: rgba(239, 107, 107, 0.6); background: rgba(239, 107, 107, 0.12); }

/* ---------- results, quarter verdicts, paired stats, chart hover ---------- */
.chip.result { font-size: 1.05rem; padding: 4px 13px; font-weight: 700; letter-spacing: 0.01em; }
.chip.result.big { font-size: 1.25rem; padding: 6px 16px; }
.scoreboard .side .n { color: var(--text); border-bottom: 4px solid var(--team, var(--border-strong)); padding-bottom: 4px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: baseline; }
table.stats.quarters td.q-win { color: var(--q-win-ink); background: rgba(12, 163, 12, 0.16); font-weight: 700; }
table.stats.quarters td.q-loss { color: var(--q-loss-ink); background: rgba(208, 59, 59, 0.16); }
table.stats.quarters td.q-even { color: var(--muted); }
table.stats.quarters td.total { font-size: 1.05rem; }
.q-mark { font-size: 0.7em; margin-left: 4px; opacity: 0.9; }
.kpi.pair .v2 { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.pair .k { order: -1; }
.chart-holder { position: relative; }
.chart-tip { position: absolute; top: 10px; min-width: 170px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 0.85rem; pointer-events: none; box-shadow: 0 8px 20px rgba(0,0,0,0.4); }
.chart-cross { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); opacity: 0.6; pointer-events: none; }
.small-seg button { padding: 4px 10px; font-size: 0.82rem; }

/* Grid columns may shrink below their content, so wide tables scroll inside their card instead of widening the page. */
.split > *, .sidebar-layout > *, .grid-2 > * { min-width: 0; }

/* Two cards side by side that always start level (game page lists | points; team page games | squad). */
.pair-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .pair-row { grid-template-columns: 1fr; } }

/* ---------- settings boxes ---------- */
.settings-box { border: 1px solid var(--border); border-radius: 14px; padding: 18px; background: rgba(255, 255, 255, 0.015); }
.settings-box-head { margin-bottom: 14px; }
.settings-box-head h2 { margin: 0 0 4px; font-size: 1.15rem; }
.settings-box-head p { margin: 0; max-width: 760px; }
.slim-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px dashed var(--border-strong); border-radius: 10px; }
.bookmarklet.small { padding: 4px 10px; font-size: 0.82rem; flex: none; }

/* ---------- sortable headers ---------- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sort-arrow { font-size: 0.65em; margin-left: 4px; opacity: 0.45; letter-spacing: -1px; }
th[data-dir] .sort-arrow { opacity: 1; color: var(--accent); }

/* ---------- points heatmap ---------- */
table.stats.heatmap td.heat { text-align: center; font-variant-numeric: tabular-nums; position: relative; color: var(--faint); }
table.stats.heatmap td.heat[style] { color: var(--text); background: color-mix(in srgb, var(--heat) calc(var(--heat-a) * 100%), transparent); }
table.stats.heatmap td.heat.heat-strong { color: #14100a; font-weight: 700; }
table.stats.heatmap th:not(:first-child) { text-align: center; }

/* ---------- scrolling tables (division games) ---------- */
.scroll-box { max-height: 460px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.sticky-head thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
table.stats tr.clickable { cursor: pointer; }
table.stats tr.clickable:hover td { background: var(--surface-2); }
table.stats td.actions { text-align: right; }

/* ---------- competition ladder ---------- */
table.stats tr.club-row td { color: var(--accent); font-weight: 600; }
.team-card.club { border-color: rgba(242, 179, 61, 0.45); }

table.stats th.left, table.stats td.left { text-align: left; }
.ai-pill { max-width: 520px; line-height: 1.3; }

/* ---------- logins, club switcher, user menu ---------- */
.who { display: flex; align-items: center; gap: 10px; }
.club-switch { width: auto; max-width: 220px; padding: 5px 8px; font-size: 0.88rem; }
.club-name { color: var(--muted); font-size: 0.9rem; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 0.9rem; color: var(--text); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu[open] summary { border-color: var(--border-strong); }
.user-menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 260px; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
.user-menu-list .bookmarklet { align-self: flex-start; }
.admin-link { color: var(--draw) !important; }
body.signed-out .topbar .nav, body.signed-out .topbar .who { visibility: hidden; }
.auth-card { max-width: 400px; margin: 8vh auto 0; padding: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 4px; }
.auth-card button[type='submit'] { margin-top: 6px; }
.auth-brand { color: var(--accent); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.8rem; margin-bottom: 10px; }
tr.faint td { color: var(--faint); }

/* ---------- admin console: same parts, its own colour so it's never mistaken for a club's view ---------- */
body.admin { --accent: #b9a7f0; --accent-ink: #160f2b; }
body.admin .topbar { border-bottom: 2px solid #6d5bd0; background: linear-gradient(180deg, #1b1830, var(--surface)); }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.demo { color: #6fa8dc; border-color: rgba(111, 168, 220, 0.5); }
.badge.mine { color: var(--accent); border-color: rgba(185, 167, 240, 0.5); }
.badge.suspended { color: var(--loss); border-color: rgba(239, 107, 107, 0.5); }
.badge.trial { color: #f2b33d; border-color: rgba(242, 179, 61, 0.5); }
.meter { display: inline-block; width: 70px; height: 6px; border-radius: 3px; background: var(--border); vertical-align: middle; margin-left: 6px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--win); border-radius: 3px; }
.meter.full > i { background: var(--loss); }
.mods { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { white-space: nowrap; }
.who { flex: none; }
.ai-pill { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1400px) { .ai-pill .faint { display: none; } .ai-pill { max-width: 230px; } .topbar .nav a { padding: 6px 9px; } }

/* AI lights in the top bar */
.ai-pill { display: inline-flex; gap: 14px; max-width: none; }
.ai-light { display: inline-flex; align-items: center; gap: 6px; cursor: help; }
.ai-light .model { font-size: 0.85em; }
.dot.capped { background: var(--loss); box-shadow: 0 0 0 3px rgba(239, 107, 107, 0.18); }
.dot.standby { background: #f2b33d; }
@media (max-width: 1400px) { .ai-light .model { display: none; } }
.ai-light .dot.off { background: var(--faint); }

/* ---------- avatar, notices bell, profile ---------- */
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; overflow: hidden; font-size: 0.8rem; font-weight: 700; color: #fff; background: var(--avatar-bg, #5b6b82); object-fit: cover; }
.avatar.big { width: 96px; height: 96px; font-size: 2rem; }
.user-menu summary { padding: 0; border: 0; border-radius: 50%; display: block; }
.user-menu summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-menu-head { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.bell { position: relative; background: transparent; border: 1px solid var(--border); border-radius: 50%; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; color: var(--muted); }
.bell:hover { color: var(--text); border-color: var(--border-strong); }
.bell svg { width: 17px; height: 17px; }
.bell .count { position: absolute; top: -5px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--loss); color: #fff; font-size: 0.68rem; font-weight: 700; line-height: 17px; text-align: center; }
.notice-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: 360px; max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.notice-panel .item { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notice-panel .item:last-child { border-bottom: 0; }
.notice-panel .item.unread { background: var(--surface-2); }
.notice-panel .item .t { font-weight: 600; }
.notice-panel .item .b { font-size: 0.88rem; color: var(--muted); white-space: pre-wrap; margin-top: 2px; }
.lvl { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; margin-right: 6px; }
.lvl.info { color: var(--theirs); }
.lvl.maintenance { color: var(--accent); }
.lvl.problem { color: var(--loss); }
.site-banner { display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 0.9rem; }
.site-banner.problem { border-left: 4px solid var(--loss); }
.site-banner.maintenance { border-left: 4px solid var(--accent); }
.site-banner .grow { flex: 1; }
.theme-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-pick label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; cursor: pointer; margin: 0; color: var(--text); }
.theme-pick label:has(input:checked) { border-color: var(--accent); }
.who-wrap { position: relative; }

/* ---------- readable hover text (tooltip.js) ---------- */
.tip {
  position: fixed; z-index: 1000; max-width: min(380px, calc(100vw - 24px));
  padding: 10px 13px; border-radius: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font: 500 0.95rem/1.45 var(--font); white-space: pre-line; pointer-events: none;
}
:root[data-theme='light'] .tip { box-shadow: 0 10px 30px rgba(20, 24, 30, 0.18); }
.rep-item.is-off .n, .rep-item.is-off .d { opacity: 0.55; }

/* ---------- top bar v2: brand | menu (scrolls sideways if it must) | AI, club, bell, you (always visible) ---------- */
.topbar { gap: 18px; padding: 8px 20px; min-height: 58px; flex-wrap: nowrap; }
.topbar .brand { flex: none; }
.topbar .nav { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; gap: 2px; }
.topbar .nav::-webkit-scrollbar { display: none; }
.topbar .nav a { position: relative; padding: 8px 12px; border-radius: 8px; }
.topbar .nav a.active { background: transparent; color: var(--text); }
.topbar .nav a.active::after { content: ''; position: absolute; left: 12px; right: 12px; bottom: 1px; height: 2px; border-radius: 2px; background: var(--accent); }
.who { flex: none; margin-left: auto; flex-wrap: nowrap; gap: 10px; }
.who .ai-pill { gap: 12px; padding: 5px 12px; max-width: none; }
.who .club-switch { max-width: 170px; }
.who .who-wrap, .who .user-menu { flex: none; }
.user-menu summary .avatar { width: 34px; height: 34px; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border-strong); }
.bell { width: 34px; height: 34px; }
@media (max-width: 1150px) { .who .ai-name { display: none; } .who .ai-pill { gap: 8px; padding: 7px 10px; } }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: 8px 14px; }
  .topbar .nav { order: 3; flex: 1 1 100%; }
  .who .club-switch { max-width: 130px; }
}

/* ---------- top bar v3: row 1 = MatchBard + who you are / what you're viewing; row 2 = the menu, full width ---------- */
.topbar { flex-wrap: wrap; row-gap: 0; padding: 0 20px; min-height: 0; }
.topbar .brand, .topbar .who { padding: 10px 0; }
.topbar .nav { order: 3; flex: 1 1 100%; margin: 0 -20px; padding: 0 12px; border-top: 1px solid var(--border); }
.topbar .nav a { padding: 10px 12px; border-radius: 0; }
.topbar .nav a:hover { background: transparent; color: var(--text); }
.topbar .nav a.active::after { bottom: 0; }
@media (max-width: 900px) { .topbar { padding: 0 14px; } .topbar .nav { margin: 0 -14px; padding: 0 6px; } }

/* Scrolling lists keep their column headings in view: the rows scroll underneath. */
.scroll-box table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); box-shadow: inset 0 -1px 0 var(--border-strong); }
.scroll-box.card { padding-top: 0; }
a.auth-brand { display: block; }
a.auth-brand:hover { text-decoration: none; }
.rep-head { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

/* ---------- printing (Print / Save PDF on a game) ---------- */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; }
  .topbar, #banner, .toasts, .tip, .no-print, dialog, .table-wrap::-webkit-scrollbar { display: none !important; }
  .print-only { display: block; color: #555; margin-top: 10px; }
  .page { max-width: none; padding: 0; }
  .card { box-shadow: none !important; break-inside: avoid; page-break-inside: avoid; }
  .split, .pair-row { display: block; }
  .split > *, .pair-row > * { margin-bottom: 12px; }
  .stack { gap: 12px; }
  .chips button:not(.on), .chip-btn:not(.on) { display: none; }
  button, .btn { display: none !important; }
  .scroll-box, .table-wrap { max-height: none !important; overflow: visible !important; }
  a { color: inherit; text-decoration: none; }
  svg { max-width: 100%; height: auto; }
}
@media print { .chip-btn.on { display: inline-flex !important; } }
/* Keep the team colours (dots, keys, shaded quarters, heatmap) when printing: browsers drop
   background colours on paper unless told otherwise, and those colours say who's who. */
@media print { *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; } }

/* Browser extension page */
.ext-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.ext-card.mine { border-color: var(--accent); }
.ext-card .btn { align-self: flex-start; }
.ext-card code { font-size: 0.85em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* Records and ladder: wins green, losses red */
.record .w, table.stats td.w { color: var(--win); font-weight: 700; }
.record .l, table.stats td.l { color: var(--loss); font-weight: 700; }
.record .d { color: var(--draw); font-weight: 700; }
table.ladder td.hl { font-weight: 700; }
