/* Reading clarity, November 2026. Colour and type only: table geometry, sticky
   headings, responsive column controls and the underlying values stay intact. */
html[data-theme="light"],
html[data-theme="light"] body[data-palette],
body[data-palette] {
  /* Light mode retains the existing palette; only reading emphasis changes. */
  --table-heading: var(--bg);
  --table-row: var(--panel);
  --table-row-hover: var(--soft);
  --table-selected: var(--column);
  --table-rule: var(--line);
  --table-heading-ink: var(--ink);
  --table-accent: var(--green);
  --table-track: var(--line);
  --table-bar: #9eb6d5;
}

/* Distinct slate canvas, lighter blue panels and navy headings keep dark mode
   soft while giving each surface a clear role within the blue identity. */
html[data-theme="dark"],
html[data-theme="dark"] body[data-palette],
body[data-palette].dark {
  --bg: #273543;
  --panel: #344c63;
  --ink: #f0f4f8;
  --muted: #c7d2dd;
  --line: #586e83;
  --control-edge: #8398ac;
  --soft: #364e65;
  --column: #3b5d7e;
  --sidebar: #1e3045;
  --selected: #496e95;
  --on-selected: #edf4ff;
  --surface: var(--panel);
  --surface-muted: var(--soft);
  --surface-control: #22394f;
  --surface-hover: #415e79;
  --table-heading: #22364b;
  --table-row: #344c63;
  --table-row-hover: #415e79;
  --table-selected: #3b5d7e;
  --table-rule: #586e83;
  --table-heading-ink: #e2eeff;
  --table-accent: #c5ddff;
  --table-track: #526a80;
  --table-bar: #a0bddc;
  --shadow: 0 8px 24px #10223a12;
}

/* The initial HTML sets an inline page colour; use the current theme after paint. */
html[data-theme="dark"] { background-color: #273543 !important; }
html[data-theme="dark"] body[data-palette] {
  background: var(--bg);
  color: var(--ink);
}
html[data-theme="dark"] body[data-palette] :is(select, .search) {
  background-color: var(--surface-control);
  border-color: var(--control-edge);
}
html[data-theme="dark"] body[data-palette] dialog::backdrop,
html[data-theme="dark"] body[data-palette] .app-guide-dialog::backdrop {
  background: #10223a99;
  backdrop-filter: blur(3px);
}
html[data-theme="dark"] #menu-backdrop { background: #10223a99; }
html[data-theme="dark"] body[data-palette] #main :is(.table-tools,.global-table-toolbar){background:var(--panel)}
html[data-theme="dark"] body[data-palette] #main :is(.table-tools,.global-table-toolbar){border-radius:9px 9px 0 0}
html[data-theme="dark"] body[data-palette] #main :is(.table-options,#performance-toolbar){background:var(--surface-control)}
html[data-theme="dark"] body[data-palette] #main :is(#strength-table,#global-table,.snapshot-table) td:not(.main-metric) .score{color:var(--ink)}
html[data-theme="dark"] body[data-palette] :is(#ratings,#todays-fixtures) .fixture-card .fixture-score{background:var(--surface-control)}
html[data-theme="dark"] body[data-palette] :is(#ratings,#todays-fixtures) .fixture-card details{background:var(--table-heading)}

/* Uniform rows, clear dividers and a readable header band. Both themes add
   one continuous selected-column band below; there is no alternating shading. */
body[data-palette] #main .table-shell {
  border-color: var(--table-rule);
  background: var(--table-row);
}
body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) thead th {
  background: var(--table-heading);
  color: var(--table-heading-ink);
  font-weight: 700;
  border-color: var(--table-rule);
  box-shadow: inset 0 -2px var(--table-rule);
}
body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) th button {
  color: inherit;
  font-weight: inherit;
}
body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) th small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}
body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) tbody td {
  background-color: var(--table-row);
  border-bottom-color: var(--table-rule);
  font-weight: 550;
  font-variant-numeric: tabular-nums lining-nums;
}
body[data-palette] :is(#main, dialog) .history-table tbody tr.selected-snapshot td {
  background-color: var(--table-selected);
  font-weight: 700;
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) tbody td.main-metric {
  background-color: var(--table-row);
  font-weight: 700;
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) thead th.main-metric {
  color: var(--table-accent);
  background-color: var(--table-heading);
  box-shadow: inset 0 -2px var(--table-rule);
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) :is(.club, .club-name) {
  font-weight: 650;
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) .club-name small {
  color: var(--muted);
  font-weight: 450;
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) :is(.score, .change, .goal-value) {
  font-weight: 650;
}
body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) .main-metric .score {
  color: var(--table-accent);
  font-weight: 750;
}
body[data-palette] #main .table-shell .bar { background: var(--table-track); }
body[data-palette] #main .table-shell .bar i { background: var(--table-bar); }
body[data-palette] #main .table-shell .main-metric .bar i { background: var(--green); }
body[data-palette] #main .table-tools h3 { font-weight: 700; }
body[data-palette] #main .table-foot { border-top-color: var(--table-rule); }
body[data-palette] #main .fixture-card {
  border-color: var(--table-rule);
}
body[data-palette] #main .fixture-card :is(.club, .probabilities b) { font-weight: 650; }

/* Follow the active sort column continuously in both themes. */
@media (forced-colors: none) {
  html[data-theme="light"] body[data-palette]:not(.dark) #main :is(#strength-table, #global-table, .snapshot-table) :is(th, td).main-metric {
    background-color: var(--brand-blue-100, #e8f0fb);
  }
  html[data-theme="dark"] body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) td.main-metric {
    background-color: #425f7e;
  }
  html[data-theme="dark"] body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) th.main-metric {
    background-color: #3c6188;
    color: #f0f6ff;
    box-shadow: inset 0 -2px #b2d3ff;
  }
}

/* Keep Windows high-contrast mode authoritative. */
@media (forced-colors: active) {
  html[data-theme="dark"] { background-color: Canvas !important; }
  body[data-palette] #main .table-shell { border-color: CanvasText; }
  body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) :is(th, td),
  body[data-palette] :is(#main, dialog) :is(#strength-table, #global-table, .snapshot-table, .history-table, .chart-values) tbody tr:is(:hover, :focus-within) td {
    background: Canvas;
    color: CanvasText;
    border-color: CanvasText;
    box-shadow: none;
  }
  body[data-palette] #main :is(#strength-table, #global-table, .snapshot-table) thead th.main-metric {
    background: Highlight;
    color: HighlightText;
    outline: 1px solid HighlightText;
  }
}
