:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --border: #deddd8;
  --accent: #2f6fb3;
  --good: #2e8540;
  --bad: #c0392b;
  --active: #e8eef7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --surface: #252523;
    --text: #e9e8e4;
    --muted: #9c9b96;
    --border: #3a3a37;
    --accent: #6ea8e8;
    --good: #5cbf6f;
    --bad: #e8675a;
    --active: #2e3642;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, sans-serif;
}
header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
h1 { font-size: 18px; margin: 0; }
#summary { color: var(--muted); }

main {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 50px);
}
aside {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
select { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
#list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#list li {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
}
#list li:hover { background: var(--active); }
#list li.current { background: var(--active); box-shadow: inset 3px 0 var(--accent); }
#list .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .when { color: var(--muted); font-size: 12px; grid-column: 1; }
#list .drop { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; font-variant-numeric: tabular-nums; }
#list .drop b { color: var(--bad); display: block; }
#list .drop small { color: var(--muted); }
#list .state { margin-right: 4px; }
#list .state.solved { color: var(--good); }
#list .state.failed { color: var(--bad); }

#play {
  display: flex;
  gap: 24px;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  align-items: flex-start;
}
#board-area { flex-shrink: 0; }
#board-col { width: min(634px, calc(100vh - 176px)); display: flex; flex-direction: column; gap: 6px; }
#board-row { display: flex; gap: 8px; }
#board { flex: 1; min-width: 0; aspect-ratio: 1; }
.clock, .nav { margin-left: 34px; }

/* Eval bar: white share from the bottom (from the top when the board is flipped). */
#evalbar {
  position: relative;
  width: 26px;
  background: #403d39;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
#eval-white { position: absolute; left: 0; right: 0; bottom: 0; background: #f4f4f0; transition: height .3s; }
#evalbar.flipped #eval-white { bottom: auto; top: 0; }
#eval-num {
  position: absolute; left: 0; right: 0;
  text-align: center; font-size: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.3px;
}
#eval-num.bottom { bottom: 4px; }
#eval-num.top { top: 4px; }
#eval-num.on-white { color: #1d1d1b; }
#eval-num.on-black { color: #f4f4f0; }

.clock {
  display: flex; justify-content: space-between; align-items: center;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface);
}
.clock .who { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.clock .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.clock .material { white-space: nowrap; font-size: 20px; line-height: 1; color: var(--text); letter-spacing: -2px; }
.clock .time { font: 600 17px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.clock.running { border-color: var(--accent); box-shadow: inset 4px 0 var(--accent); }
.clock.running .name { color: var(--text); }
.nav { display: flex; gap: 8px; }
.nav button { flex: 1; padding: 8px; }
.line-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.line-tabs button.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
#panel { flex: 1; min-width: 260px; max-width: 420px; display: flex; flex-direction: column; gap: 14px; }
#meta { color: var(--muted); font-size: 13px; }
#meta a { color: var(--accent); }
#prompt { font-size: 18px; font-weight: 600; }
#feedback { min-height: 3em; }
#feedback .good { color: var(--good); font-weight: 600; }
#feedback .bad { color: var(--bad); font-weight: 600; }
.line { font-family: ui-monospace, monospace; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  font: inherit;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: .4; cursor: default; }
.small { font-size: 13px; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); }
#moves {
  display: flex; flex-wrap: wrap; gap: 2px 4px; align-content: flex-start;
  font-family: ui-monospace, monospace; font-size: 13px;
  max-height: 180px; overflow-y: auto; position: relative;
}
#moves .mv.branch { font-style: italic; }
#moves .mv.answer { outline: 1px solid var(--good); }
#moves .num { color: var(--muted); margin-left: 6px; }
#moves .mv { cursor: pointer; padding: 0 3px; border-radius: 3px; }
#moves .mv:hover { background: var(--active); }
#moves .mv.shown { background: var(--accent); color: #fff; }
#moves .mv.critical { outline: 1px solid var(--bad); color: var(--bad); }
#moves .mv.critical.shown, #moves .mv.answer.shown { color: #fff; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
  aside { border-right: 0; border-bottom: 1px solid var(--border); max-height: 35vh; }
  #play { flex-direction: column; padding: 16px; }
  #board-area { width: 100%; }
  #board-col { width: 100%; }
  #panel { max-width: none; }
}

header { flex-wrap: wrap; align-items: center; row-gap: 8px; }
#player-form { display: flex; gap: 6px; }
#player-form input {
  font: inherit; width: 170px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
#player-form button { padding: 5px 12px; }
#job { color: var(--muted); font-size: 13px; }
#account { color: var(--muted); font-size: 13px; }
#account:not(:empty)::before { content: "signed in as "; }
#empty { padding: 24px; max-width: 560px; }
.theme { margin-left: auto; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  #play { order: 1; }
  aside { order: 2; max-height: none; border-bottom: 0; border-top: 1px solid var(--border); }
  #list { overflow: visible; }
}

/* E-ink: pure black on white, no animation, no hover, no colour-only signals. */
:root[data-theme="eink"] {
  --bg: #fff;
  --surface: #fff;
  --text: #000;
  --muted: #000;
  --border: #000;
  --accent: #000;
  --good: #000;
  --bad: #000;
  --active: #fff;
}
:root[data-theme="eink"] body { font-size: 17px; }
:root[data-theme="eink"] *, :root[data-theme="eink"] *::before { transition: none !important; animation: none !important; }
:root[data-theme="eink"] #list li:hover,
:root[data-theme="eink"] #moves .mv:hover { background: none; }
:root[data-theme="eink"] #list li.current { box-shadow: inset 6px 0 #000; font-weight: 600; }
:root[data-theme="eink"] #list .when,
:root[data-theme="eink"] #list .drop small { color: #000; }
:root[data-theme="eink"] button { border: 2px solid #000; padding: 10px 18px; font-weight: 600; }
:root[data-theme="eink"] button.primary { background: #000; color: #fff; }
:root[data-theme="eink"] #feedback .good, :root[data-theme="eink"] #feedback .bad { text-decoration: underline; }
:root[data-theme="eink"] #moves .mv.shown { background: #000; color: #fff; }
:root[data-theme="eink"] #moves .mv.critical { outline: 2px solid #000; }
:root[data-theme="eink"] .cg-wrap cg-board {
  background-image: repeating-conic-gradient(#b4b4b4 0 25%, #fff 0 50%);
  background-size: 25% 25%;
}
:root[data-theme="eink"] #board { outline: 2px solid #000; }
:root[data-theme="eink"] #evalbar { background: #000; border: 2px solid #000; border-radius: 0; }
:root[data-theme="eink"] #eval-white { background: #fff; }
:root[data-theme="eink"] #eval-num { font-size: 11px; }
:root[data-theme="eink"] .clock { border: 2px solid #000; border-radius: 0; }
:root[data-theme="eink"] .clock.running { background: #000; box-shadow: none; }
:root[data-theme="eink"] .clock.running .name, :root[data-theme="eink"] .clock.running .time,
:root[data-theme="eink"] .clock.running .material { color: #fff; }
:root[data-theme="eink"] .line-tabs button.selected { background: #000; color: #fff; }
:root[data-theme="eink"] #moves .mv.critical { color: #000; outline: 2px solid #000; text-decoration: line-through; }
:root[data-theme="eink"] #moves .mv.answer { outline: 2px solid #000; }
:root[data-theme="eink"] #moves .mv.critical.shown { color: #fff; }
:root[data-theme="eink"] cg-board square.last-move { background: none; box-shadow: inset 0 0 0 4px #000; }
:root[data-theme="eink"] cg-board square.selected { background: none; box-shadow: inset 0 0 0 6px #000; }
:root[data-theme="eink"] cg-board square.move-dest { background: radial-gradient(#000 18%, transparent 20%); }
:root[data-theme="eink"] cg-board square.oc.move-dest { background: radial-gradient(transparent 70%, #000 72%, #000 80%, transparent 82%); }
:root[data-theme="eink"] cg-board square.check { background: radial-gradient(transparent 55%, #000 58%, #000 66%, transparent 69%); }
:root[data-theme="eink"] .cg-wrap coords { color: #000 !important; text-shadow: none; }
:root[data-theme="eink"] .cg-wrap coords coord { color: #000 !important; }
[hidden] { display: none !important; }

/* Move labels: a small round mark after the move, coloured per label (see LABELS in app.js). */
.nag {
  display: inline-block; min-width: 1.5em; margin-left: 3px; padding: 0 3px;
  border-radius: 8px; color: #fff; font: 700 11px/1.45 system-ui, sans-serif;
  text-align: center; vertical-align: 1px; font-style: normal;
}
.nag-brilliant { background: #1b9aaa; }
.nag-great { background: #3b7dd8; }
.nag-best { background: #2e8540; }
.nag-excellent { background: #56a05a; }
.nag-good { background: #7f9c6c; }
.nag-inaccuracy { background: #d9a21b; }
.nag-mistake { background: #e07b26; }
.nag-miss { background: #d6453d; }
.nag-blunder { background: #b7282e; }
:root[data-theme="eink"] .nag { background: #000; }
#feedback .nag { font-size: 12px; }
