:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76746f;
  --series-1: #2a78d6;
  --grid: #e7e5df;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --series-1: #3987e5;
    --grid: #2b2b28;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f; --series-1: #3987e5; --grid: #2b2b28; --accent: #3987e5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
h2, h3 { margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
kbd { font: 11px ui-monospace, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: .7; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 650; font-size: 17px; }
.sync { display: flex; align-items: center; gap: 10px; margin-left: auto; font-size: 13px; }
.sync button:disabled { opacity: .6; cursor: progress; }
.brand .muted { font-weight: 400; font-size: 14px; margin-left: 6px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: none; color: var(--text-2); padding: 6px 14px; border-radius: 7px; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }

/* ---------- Train ---------- */
.train { display: grid; grid-template-columns: minmax(0, 600px) minmax(280px, 1fr); gap: 24px; align-items: start; }
.board-col { width: 100%; }
.board { width: 100%; aspect-ratio: 1; }
.board .cg-wrap { width: 100%; height: 100%; }
.line-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.line-nav button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; width: 40px; height: 34px; }
.queue { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--text-2); }
.pill b { color: var(--text); font-weight: 600; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.result h3 { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.result .moves { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 4px; }
.result .moves dt { color: var(--muted); }
.result .moves dd { margin: 0; }
.line-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.primary, .secondary, .chip {
  border-radius: 9px; padding: 9px 16px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip { padding: 5px 11px; font-size: 13px; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.explain { white-space: pre-wrap; }
.explain.loading { color: var(--muted); }

/* ---------- Insights ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.takeaways { margin: 8px 0 0; padding-left: 20px; }
.takeaways li { margin: 6px 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid2 .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 16px; }
figure { margin: 0; }
figcaption p { margin: 0 0 8px; font-size: 13px; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .bar-hit { fill: transparent; }
.chart .bar-row:hover .bar { opacity: .82; }
.chart .dot { fill: var(--muted); opacity: .45; }
.chart .avg { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .focus { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; background: var(--series-1); }
.legend i.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .6; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .14); max-width: 260px;
}
.tooltip .tt-title { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; }
tr.weak td:first-child { box-shadow: inset 3px 0 0 var(--critical); }

@media (max-width: 860px) {
  .train { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  main { padding: 16px; }
  .top { padding: 10px 16px; }
}

/* ---------- Game review ---------- */
/* Label colours follow chess.com's conventions so they read the same way. */
:root {
  --cc-brilliant: #26c2a3; --cc-great: #749bbf; --cc-best: #81b64c; --cc-excellent: #81b64c;
  --cc-good: #95b776; --cc-book: #a88865; --cc-inaccuracy: #f7c631; --cc-mistake: #ffa459;
  --cc-miss: #ff7769; --cc-blunder: #fa412d; --cc-forced: #97af8b;
}
.review-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.review-body { display: grid; grid-template-columns: minmax(0, 600px) minmax(300px, 1fr); gap: 24px; align-items: start; margin-bottom: 24px; }
.board-with-bar { display: flex; gap: 8px; }
.board-with-bar .board { flex: 1; min-width: 0; }
.evalbar { position: relative; width: 22px; flex: none; background: #403d39; border-radius: 4px; overflow: hidden; }
.evalbar-fill { position: absolute; left: 0; right: 0; bottom: 0; background: #f2f0eb; transition: height .25s ease; }
.evalbar span { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-size: 10px; font-weight: 700; color: #403d39; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: 10px; font-size: 11px; font-weight: 800; color: #fff; flex: none; line-height: 1;
}
.badge.inaccuracy { color: #3d3000; }
.rv-comment-line { display: flex; align-items: center; gap: 10px; font-size: 16px; }
#rv-comment p { margin: 6px 0 0; }
.summary td, .summary th { padding: 5px 8px; }
.summary td:first-child { display: flex; align-items: center; gap: 8px; }
.summary .zero { color: var(--muted); opacity: .6; }
.movelist { position: relative; display: grid; grid-template-columns: 36px 1fr 1fr; gap: 2px 6px; max-height: 360px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.movelist .num { color: var(--muted); padding: 4px 0; }
.movelist button {
  display: flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text);
  padding: 4px 6px; border-radius: 6px; text-align: left;
}
.movelist button:hover { background: var(--surface-2); }
.movelist button[aria-current="true"] { background: var(--surface-2); outline: 1px solid var(--border); font-weight: 600; }
.movelist .badge { min-width: 16px; height: 16px; font-size: 9px; }
#games tr.clickable { cursor: pointer; }
#games tr.clickable:hover td { background: var(--surface-2); }
@media (max-width: 860px) { .review-body { grid-template-columns: 1fr; } }
