/* Šachová pracovna: slate analysis room with brass fittings, like a tournament clock. */
:root {
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --raised: #F5F7F9;
  --ink: #15202B;
  --pencil: #5E6B78;
  --rule: #D6DCE2;
  --accent: #9A7420;
  --accent-soft: rgba(154, 116, 32, .12);
  --accent-ink: #FFFFFF;
  --eval-white: #F7F9FB;
  --eval-black: #2A333D;
  --good: #32743E;
  --bad: #C3352E;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 8px 24px rgba(20, 30, 40, .08);

  /* Board colours are set from js/themes.js. */
  --sq-light: #EBECD0;
  --sq-dark: #779556;
  --last: rgba(246, 222, 90, .55);
  --check: rgba(235, 64, 52, .75);

  /* Same meaning as on chess.com, so the colours read at a glance. */
  --k-brilliant: #1DAFA2;
  --k-great: #4C88C8;
  --k-best: #6FAE2C;
  --k-excellent: #6FAE2C;
  --k-good: #86A07F;
  --k-book: #A4825F;
  --k-forced: #8A96A3;
  --k-inaccuracy: #E2AC1F;
  --k-mistake: #E07F22;
  --k-miss: #DD5444;
  --k-blunder: #C3352E;

  --font: 'Schibsted Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1B2129; --surface: #232B35; --raised: #2B3440; --ink: #E8ECEF; --pencil: #9AA6B2; --rule: #36414E;
  --accent: #D4A84B; --accent-soft: rgba(212, 168, 75, .14); --accent-ink: #1B2129;
  --eval-white: #E9EEF3; --eval-black: #10151B; --good: #79C07F; --bad: #EF6A5E;
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 10px 30px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B2129; --surface: #232B35; --raised: #2B3440; --ink: #E8ECEF; --pencil: #9AA6B2; --rule: #36414E;
    --accent: #D4A84B; --accent-soft: rgba(212, 168, 75, .14); --accent-ink: #1B2129;
    --eval-white: #E9EEF3; --eval-black: #10151B; --good: #79C07F; --bad: #EF6A5E;
    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 10px 30px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
h3 { margin: 0 0 8px; font-size: 14.5px; font-weight: 700; }
svg { flex: none; }
button svg, .mode svg, .chip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.note { margin: 0; color: var(--pencil); font-size: 13.5px; }

/* ---------- buttons and inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--pencil); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13.5px; }
.btn.wide { width: 100%; }
.btn.big { padding: 12px 16px; font-size: 16.5px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid transparent;
  border-radius: var(--r-sm); background: none; color: var(--pencil); cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--accent-soft); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 17px; height: 17px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid var(--rule);
  border-radius: 999px; background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--pencil); cursor: pointer;
}
.chip svg { width: 15px; height: 15px; }
.chip:hover { color: var(--ink); border-color: var(--pencil); }
.chip[aria-pressed="true"], .chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
select, input[type="text"], input[type="search"], textarea {
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
}
input[type="range"] { accent-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--pencil); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.field.inline select, .field.inline input { min-width: 0; max-width: 60%; }
.field textarea { resize: vertical; font-size: 13.5px; }
.form-error:empty { display: none; }
.form-error { margin: 0; color: var(--bad); font-size: 14px; }

.switch { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; font-size: 14.5px; }
.switch input {
  appearance: none; flex: none; width: 34px; height: 20px; margin: 0; border-radius: 10px; background: var(--rule);
  position: relative; cursor: pointer; transition: background .15s;
}
.switch input::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

.segmented { display: flex; padding: 3px; gap: 3px; border-radius: var(--r-sm); background: var(--raised); border: 1px solid var(--rule); }
.segmented button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px;
  border: 0; border-radius: 4px; background: none; font-size: 14px; font-weight: 600; color: var(--pencil); cursor: pointer;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.disc { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--pencil); }
.disc.w { background: #fff; } .disc.b { background: #222; } .disc.r { background: linear-gradient(90deg, #fff 50%, #222 50%); }

/* ---------- top bar ---------- */
.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--rule); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); background: var(--ink); color: var(--accent); font-size: 22px; }
.modes { display: flex; gap: 2px; padding: 3px; border-radius: var(--r); background: var(--raised); border: 1px solid var(--rule); }
.mode {
  display: flex; align-items: center; gap: 7px; padding: 7px 14px; border: 0; border-radius: 7px; background: none;
  font-weight: 650; color: var(--pencil); cursor: pointer;
}
.mode:hover { color: var(--ink); }
.mode[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.mode[aria-current="page"] svg { color: var(--accent); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

.engine-pick { position: relative; }
.engine-btn {
  display: flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); font-size: 14px; color: var(--pencil); cursor: pointer;
}
.engine-btn b { color: var(--ink); }
.engine-btn:hover, .engine-btn[aria-expanded="true"] { border-color: var(--pencil); }
.engine-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--k-best); }
.engine-btn[data-mode="high"] .engine-dot { background: var(--k-great); }
.engine-btn[data-mode="max"] .engine-dot { background: var(--accent); }
.engine-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: min(340px, calc(100vw - 24px));
  padding: 6px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow);
}
.engine-opt {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; padding: 9px 10px;
  border: 0; border-radius: var(--r-sm); background: none; text-align: left; cursor: pointer;
}
.engine-opt:hover, .engine-opt:focus-visible { background: var(--accent-soft); }
.engine-opt .desc { grid-column: 1; color: var(--pencil); font-size: 13px; line-height: 1.4; }
.engine-opt .check { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--accent); visibility: hidden; }
.engine-opt[aria-selected="true"] .check { visibility: visible; }
body:not([data-mode="analyse"]) .engine-pick { display: none; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); gap: 28px;
  max-width: 1320px; margin: 0 auto; padding: 18px 16px 40px; align-items: start;
}
.board-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; align-items: center; }
.board-col > * { width: min(100%, calc(100dvh - 210px) + 36px); }
.board-row { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; }
.board-wrap { position: relative; aspect-ratio: 1; min-width: 0; border-radius: 4px; overflow: hidden; box-shadow: var(--shadow); }
#board { width: 100%; height: 100%; }
body.no-evalbar .board-row { grid-template-columns: minmax(0, 1fr); }
body.no-evalbar .evalbar { display: none; }
body.no-evalbar .player, body.no-evalbar .controls, body.no-evalbar .timeline, body.no-evalbar .variation { padding-left: 0; margin-left: 0; }

.panel { display: flex; flex-direction: column; min-width: 0; }
.view { display: flex; flex-direction: column; gap: 14px; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------- players, captured material, clocks ---------- */
.player { display: flex; align-items: center; gap: 10px; padding-left: 36px; min-height: 34px; }
.player .avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm); flex: none;
  background: var(--raised); border: 1px solid var(--rule); font-size: 12px; font-weight: 800; color: #fff;
}
.player .avatar.w { background: #F4F4F2; color: #222; } .player .avatar.b { background: #2B2B2B; color: #eee; }
.player .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.player .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .elo { color: var(--pencil); font-weight: 500; font-size: 13px; }
.captured { display: flex; align-items: center; min-height: 16px; }
.captured svg { width: 17px; height: 17px; margin-right: -6px; }
.captured .adv { margin-left: 10px; font-size: 12px; font-weight: 700; color: var(--pencil); }
.player .acc { margin-left: auto; font-size: 13px; color: var(--pencil); white-space: nowrap; }
.player .acc b { color: var(--ink); font-size: 15px; }
.clock {
  margin-left: auto; min-width: 92px; padding: 5px 12px; border-radius: var(--r-sm); text-align: right;
  font-size: 22px; font-weight: 800; letter-spacing: -.01em; background: var(--raised); color: var(--pencil); border: 1px solid var(--rule);
}
.clock.running { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.clock.low { background: var(--bad); color: #fff; border-color: var(--bad); }
.clock.small { min-width: 0; padding: 2px 8px; font-size: 13px; font-weight: 700; }

/* ---------- eval bar ---------- */
.evalbar { position: relative; border-radius: 4px; overflow: hidden; background: var(--eval-black); }
.evalbar-white { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--eval-white); transition: height .4s cubic-bezier(.3, .7, .3, 1); }
.evalbar.flipped .evalbar-white { top: 0; bottom: auto; }
.evalbar-score { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-size: 10.5px; font-weight: 800; color: var(--eval-black); }
.evalbar.black-better .evalbar-score { top: 6px; bottom: auto; color: var(--eval-white); }
.evalbar.flipped .evalbar-score { top: 6px; bottom: auto; }
.evalbar.flipped.black-better .evalbar-score { top: auto; bottom: 6px; }
body.hide-eval .evalbar-white { height: 50% !important; }
body.hide-eval .evalbar-score { visibility: hidden; }

/* ---------- board ---------- */
.cm-chessboard.themed .board .square.white { fill: var(--sq-light); }
.cm-chessboard.themed .board .square.black { fill: var(--sq-dark); }
.cm-chessboard.themed .board .border { fill: var(--sq-dark); }
.cm-chessboard.themed .coordinates .coordinate { font-weight: 700; font-family: var(--font); }
.cm-chessboard.themed .coordinates .coordinate.white { fill: var(--sq-dark); }
.cm-chessboard.themed .coordinates .coordinate.black { fill: var(--sq-light); }
.cm-chessboard .markers .marker.marker-dot { fill: #000; opacity: .2; }
.cm-chessboard .markers .marker.marker-circle { stroke: #000; stroke-width: 5px; opacity: .2; }
.cm-chessboard .markers .marker.marker-square { fill: var(--last); opacity: 1; }
.cm-chessboard .markers .marker.marker-frame { stroke: var(--accent); stroke-width: 4px; }
.cm-chessboard .markers .marker.marker-circle-danger-filled { fill: var(--check); opacity: 1; }
.cm-chessboard .markers .marker.marker-bevel { fill: #2E9BDB; opacity: .45; }
.cm-chessboard .markers .marker.marker-frame-primary { stroke: #2E9BDB; stroke-width: 5px; }
.cm-chessboard .arrow-best .arrow-head, .cm-chessboard .arrow-best .arrow-line { fill: var(--k-best); stroke: var(--k-best); opacity: .9; }
.cm-chessboard .arrow-engine .arrow-head, .cm-chessboard .arrow-engine .arrow-line { fill: #2E9BDB; stroke: #2E9BDB; opacity: .8; }
.cm-chessboard .arrow-engine2 .arrow-head, .cm-chessboard .arrow-engine2 .arrow-line { fill: #2E9BDB; stroke: #2E9BDB; opacity: .38; }
.cm-chessboard .arrow-threat .arrow-head, .cm-chessboard .arrow-threat .arrow-line { fill: #E5484D; stroke: #E5484D; opacity: .8; }
.cm-chessboard .arrow-hint .arrow-head, .cm-chessboard .arrow-hint .arrow-line { fill: var(--accent); stroke: var(--accent); opacity: .9; }
.cm-chessboard .arrow-line { stroke-linecap: round; }

/* The app picks the cursor (grab / pointer / default) on #board; see initCursor. */
#board .cm-chessboard .board .square { cursor: inherit; }
body.grabbing, body.grabbing * { cursor: grabbing !important; }

/* Chess.com-style planning: right-click squares and right-drag arrows. */
.cm-chessboard .markers .marker.marker-hl { opacity: .8; }
.cm-chessboard .markers .marker.marker-hl-red { fill: #EB6150; }
.cm-chessboard .markers .marker.marker-hl-orange { fill: #FFAA00; }
.cm-chessboard .markers .marker.marker-hl-green { fill: #ACCE59; }
.cm-chessboard .markers .marker.marker-hl-blue { fill: #52B0DC; }
.annotations { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.plan-arrow { opacity: .8; }
.plan-arrow polyline { fill: none; stroke-width: .2; stroke-linejoin: round; }
.plan-orange { --plan: #FFAA00; }
.plan-red { --plan: #F15C50; }
.plan-green { --plan: #9FCF3F; }
.plan-blue { --plan: #48C1F9; }
.plan-arrow polyline { stroke: var(--plan); }
.plan-arrow polygon { fill: var(--plan); }

.badges { position: absolute; inset: 0; pointer-events: none; }
.badge {
  position: absolute; width: 4.8%; aspect-ratio: 1; min-width: 20px; transform: translate(-62%, -38%);
  display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 800; font-size: clamp(9px, 1.3vw, 13px);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 2px 6px rgba(0, 0, 0, .3); animation: stamp .22s ease-out;
}
@keyframes stamp { from { transform: translate(-62%, -38%) scale(.4); opacity: 0; } }
.board-toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); padding: 8px 14px; border-radius: 999px;
  background: rgba(16, 21, 27, .88); color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap; pointer-events: none;
  animation: toast .2s ease-out;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- timeline: eval as a tide with pins ---------- */
.timeline { position: relative; height: 84px; margin-left: 36px; border-radius: var(--r-sm); background: var(--eval-black); overflow: hidden; cursor: pointer; }
.timeline svg { display: block; width: 100%; height: 100%; }
.timeline .tide { fill: var(--eval-white); }
.timeline .phase { fill: rgba(127, 140, 155, .14); }
.timeline .mid { stroke: #7F8C9B; stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.timeline .cursor { stroke: var(--accent); stroke-width: 2; }
.timeline .hover { stroke: #7F8C9B; stroke-width: 1; }
.timeline-tip {
  position: absolute; top: 6px; padding: 3px 8px; border-radius: 4px; background: var(--surface); color: var(--ink);
  font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow); pointer-events: none; white-space: nowrap; transform: translateX(-50%);
}
body:not([data-mode="analyse"]) .timeline { display: none; }

.controls { display: flex; gap: 6px; padding-left: 36px; }
.ctrl {
  flex: 1; display: grid; place-items: center; height: 42px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.ctrl svg { fill: currentColor; stroke-width: 1.4; }
#btnFlip svg { fill: none; stroke-width: 1.8; }
#btnAuto[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ctrl:hover { border-color: var(--pencil); }
.ctrl:disabled { opacity: .4; cursor: default; }
body[data-mode="play"] #btnAuto, body[data-mode="train"] #btnAuto { display: none; }
.variation {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-left: 36px; padding: 8px 12px;
  border-radius: var(--r-sm); background: var(--accent-soft); border: 1px dashed var(--accent); font-weight: 600; font-size: 14px;
}

/* ---------- progress ---------- */
.progress-text { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.progress-track { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- start card ---------- */
.start-card { padding: 20px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--rule); }
.start-card p { margin: 6px 0 16px; color: var(--pencil); }
.start-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- summary ---------- */
.summary { padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--rule); display: flex; flex-direction: column; gap: 14px; }
.duel { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.duel .side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.duel .side.b { text-align: right; align-items: flex-end; }
.duel .pname { font-size: 13.5px; color: var(--pencil); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.duel .acc { font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.duel .rating { font-size: 13px; color: var(--pencil); }
.duel .rating b { color: var(--ink); }
.duel .vs { align-self: center; color: var(--pencil); font-size: 12.5px; text-align: center; line-height: 1.3; }
.phase-row { display: grid; grid-template-columns: 1fr repeat(3, 64px); gap: 4px 6px; font-size: 13px; align-items: center; }
.phase-row .h { color: var(--pencil); text-align: center; }
.phase-row .pn { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phase-row .pv { text-align: center; font-weight: 700; padding: 2px 0; border-radius: 4px; background: var(--raised); }
.phase-row .pv[data-q="great"] { color: var(--k-best); } .phase-row .pv[data-q="ok"] { color: var(--k-inaccuracy); } .phase-row .pv[data-q="bad"] { color: var(--k-blunder); }
.counts { margin: 0; padding: 0; list-style: none; }
.counts li { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; padding: 3px 0; font-size: 14px; }
.counts li > span:first-child, .counts li > span:last-child { text-align: center; font-weight: 800; }
.counts .kind-name { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--pencil); }
.counts .zero { opacity: .35; font-weight: 400 !important; }
.counts li[data-kind] { cursor: pointer; border-radius: 4px; }
.counts li[data-kind]:hover { background: var(--raised); }
details.more > summary { cursor: pointer; color: var(--pencil); font-size: 13.5px; font-weight: 600; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ' ▾'; }
details.more[open] > summary::after { content: ' ▴'; }
.moments { display: flex; flex-wrap: wrap; gap: 6px; }
.moment { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 4px; border-radius: 999px; border: 1px solid var(--rule); background: var(--raised); cursor: pointer; font-size: 13px; font-weight: 600; }
.moment:hover { border-color: var(--pencil); }
.summary-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- classification stamps ---------- */
.stamp {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 3px; border-radius: 10px;
  color: #fff; font-size: 11px; font-weight: 800; line-height: 1; flex: none;
}
[data-kind="brilliant"] { --k: var(--k-brilliant); } [data-kind="great"] { --k: var(--k-great); }
[data-kind="best"] { --k: var(--k-best); } [data-kind="excellent"] { --k: var(--k-excellent); }
[data-kind="good"] { --k: var(--k-good); } [data-kind="book"] { --k: var(--k-book); }
[data-kind="forced"] { --k: var(--k-forced); } [data-kind="inaccuracy"] { --k: var(--k-inaccuracy); }
[data-kind="mistake"] { --k: var(--k-mistake); } [data-kind="miss"] { --k: var(--k-miss); }
[data-kind="blunder"] { --k: var(--k-blunder); }
.stamp, .badge { background: var(--k, var(--pencil)); }

/* ---------- coach ---------- */
.coach:empty { display: none; }
.coach { padding: 12px 14px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--k, var(--rule)); }
.coach p { margin: 0; }
.coach .what { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coach .loss { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--pencil); }
.coach .why { color: var(--pencil); font-size: 14px; margin-top: 4px; }
.coach .why b { color: var(--ink); }
.coach .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag { padding: 1px 8px; border-radius: 999px; background: var(--raised); border: 1px solid var(--rule); font-size: 12px; font-weight: 600; color: var(--pencil); }
.coach .coach-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- engine lines ---------- */
.engine { border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); overflow: hidden; }
.engine-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--rule); }
.engine-head .switch { padding: 0; font-weight: 700; font-size: 14px; }
.engine-depth { font-size: 12.5px; color: var(--pencil); }
.engine-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; font-size: 13px; font-weight: 700; }
.stepper button { width: 26px; height: 26px; border: 0; background: none; cursor: pointer; color: var(--pencil); }
.stepper button:hover { background: var(--raised); color: var(--ink); }
.stepper span { min-width: 14px; text-align: center; }
.lines:empty { display: none; }
.line { display: grid; grid-template-columns: 58px 1fr; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--rule); font-size: 14px; cursor: pointer; }
.line:last-child { border-bottom: 0; }
.line:hover { background: var(--raised); }
.line .score { font-weight: 800; text-align: center; border-radius: 4px; padding: 1px 0; background: var(--eval-white); color: #1B2129; border: 1px solid var(--rule); font-size: 13.5px; }
.line .score.neg { background: var(--eval-black); color: #E9EEF3; }
.line .pv { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--pencil); }
.line .pv b { color: var(--ink); font-weight: 700; }
.lines .note { padding: 8px 10px; font-size: 13px; }
.engine.off .lines { display: none; }

/* ---------- figurine notation ---------- */
.fig { display: inline-flex; align-items: baseline; white-space: nowrap; }
.fig svg { width: 1.15em; height: 1.15em; margin-right: -1px; align-self: center; position: relative; top: -1px; }

/* ---------- scoresheet ---------- */
.sheet-wrap { border: 1px solid var(--rule); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--rule); }
.opening { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.opening b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opening span { font-size: 12px; color: var(--pencil); }
.sheet-tools { display: flex; flex: none; }
.sheet { position: relative; margin: 0; padding: 0; list-style: none; max-height: min(42vh, 520px); overflow-y: auto; }
.sheet li { display: grid; grid-template-columns: 40px 1fr 1fr; }
.sheet li:nth-child(odd) { background: var(--raised); }
.sheet .no { padding: 6px 8px; color: var(--pencil); text-align: right; font-size: 13.5px; }
.sheet .mv {
  display: flex; align-items: center; gap: 6px; padding: 5px 9px; min-width: 0;
  border: 0; background: none; text-align: left; cursor: pointer; font-weight: 600;
}
.sheet .mv .t { margin-left: auto; font-size: 11.5px; font-weight: 500; color: var(--pencil); }
.sheet .mv:hover { background: var(--accent-soft); }
.sheet .mv[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
.sheet .mv[aria-current="true"] .t { color: inherit; opacity: .8; }
.sheet .mv[aria-current="true"] .stamp { box-shadow: 0 0 0 2px var(--accent-ink); }
.sheet li.empty { display: block; padding: 18px 12px; color: var(--pencil); background: none; }
.sheet li.result { display: block; padding: 8px 12px; text-align: center; font-weight: 700; background: none; }

/* ---------- play ---------- */
.play-setup { display: flex; flex-direction: column; gap: 14px; }
.bots { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.bot {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); cursor: pointer; text-align: left; min-width: 0;
}
.bot:hover { border-color: var(--pencil); }
.bot[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.bot .face { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; color: #fff; font-weight: 800; font-size: 12.5px; flex: none; }
.bot .bn { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.bot .bn b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot .bn span { font-size: 12px; color: var(--pencil); }
.elo-row { display: grid; grid-template-columns: auto 1fr 64px; align-items: center; gap: 12px; font-weight: 600; }
.elo-row output { font-size: 20px; font-weight: 800; text-align: right; }
.bot-bio { margin: -6px 0 0; color: var(--pencil); font-size: 14px; min-height: 21px; }
.setup-grid { display: flex; flex-direction: column; gap: 12px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--pencil); }
.toggles { gap: 0; }

.play-live { display: flex; flex-direction: column; gap: 12px; }
.bot-card { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); }
.bot-card .face { width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 16px; flex: none; }
.bot-card .say { position: relative; padding: 8px 12px; border-radius: var(--r); background: var(--raised); font-size: 14px; flex: 1; min-height: 38px; }
.bot-card .say b { display: block; font-size: 13px; color: var(--pencil); }
.thinking::after { content: '…'; animation: dots 1s steps(3) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }
.mini-sheet { display: flex; flex-wrap: wrap; gap: 2px 8px; margin: 0; padding: 10px 12px; list-style: none; max-height: 180px; overflow-y: auto; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); font-weight: 600; font-size: 14px; min-height: 44px; }
.mini-sheet .no { color: var(--pencil); font-weight: 500; margin-right: -4px; }
.mini-sheet .cur { color: var(--accent); }
.play-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.play-actions .btn { padding: 8px 6px; font-size: 13.5px; }
.game-over { padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 2px solid var(--accent); text-align: center; animation: toast .25s ease-out; }
.go-title { margin: 0; font-size: 22px; font-weight: 800; }
.go-sub { margin: 2px 0 14px; color: var(--pencil); }
.go-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* ---------- train ---------- */
.train-stats, .lib-stats { display: flex; gap: 14px; font-size: 13px; color: var(--pencil); }
.train-stats b, .lib-stats b { color: var(--ink); font-size: 15px; }
.puzzle { display: flex; flex-direction: column; gap: 12px; }
.puzzle-card { padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--rule); }
.puzzle-card .task { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.puzzle-card .ctx { margin: 0; color: var(--pencil); font-size: 14px; }
.puzzle-card.ok { border-color: var(--good); }
.puzzle-card.fail { border-color: var(--bad); }
.puzzle-card .verdict { margin: 10px 0 0; font-weight: 700; }
.puzzle-card.ok .verdict { color: var(--good); } .puzzle-card.fail .verdict { color: var(--bad); }
.puzzle-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-state { padding: 22px; border-radius: var(--r-lg); border: 1px dashed var(--rule); text-align: center; color: var(--pencil); }
.empty-state p { margin: 0 0 12px; }

/* ---------- library ---------- */
.lib-filter { display: flex; flex-direction: column; gap: 8px; }
.lib-trend { padding: 10px 12px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); }
.lib-trend svg { display: block; width: 100%; height: 56px; overflow: visible; }
.lib-trend .tl { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.lib-trend .ta { fill: var(--accent-soft); }
.lib-trend p { margin: 0 0 4px; font-size: 13px; color: var(--pencil); }
.lib-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 62vh; overflow-y: auto; }
.lib-item { display: grid; grid-template-columns: 6px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 6px 8px 0; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--rule); overflow: hidden; }
.lib-item .res-bar { align-self: stretch; margin: -8px 0; background: var(--rule); }
.lib-item .res-bar.win { background: var(--good); } .lib-item .res-bar.loss { background: var(--bad); } .lib-item .res-bar.draw { background: var(--pencil); }
.lib-item button.open { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.lib-item .players { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .meta { font-size: 12.5px; color: var(--pencil); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .accs { font-size: 13px; text-align: right; color: var(--pencil); white-space: nowrap; }
.lib-item .accs b { color: var(--ink); }

/* ---------- dialogs ---------- */
.dialog { width: min(640px, calc(100vw - 20px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog.wide { width: min(780px, calc(100vw - 20px)); }
.dialog::backdrop { background: rgba(10, 14, 20, .55); }
.dialog-card { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tab { border: 0; background: none; padding: 8px 10px; cursor: pointer; font-weight: 600; color: var(--pencil); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab-panel { display: flex; flex-direction: column; gap: 10px; }
.file { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--pencil); }
.online-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: end; }
.games-filter { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.games-count { font-size: 13px; color: var(--pencil); }
.games { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.games li + li { border-top: 1px solid var(--rule); }
.games button { width: 100%; display: grid; grid-template-columns: 6px 1fr auto; gap: 2px 10px; padding: 8px 6px 8px 0; border: 0; background: none; text-align: left; cursor: pointer; }
.games button:hover { background: var(--accent-soft); }
.games .res-bar { grid-row: span 2; align-self: stretch; border-radius: 3px; background: var(--rule); }
.games .res-bar.win { background: var(--good); } .games .res-bar.loss { background: var(--bad); } .games .res-bar.draw { background: var(--pencil); }
.games .meta { color: var(--pencil); font-size: 13px; }
.games .res { font-weight: 700; grid-row: span 2; align-self: center; }
.games .hint { padding: 10px 4px; color: var(--pencil); font-size: 14px; }

.set-section { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--rule); }
.set-section.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
.set-section.two h3:not(:first-child) { margin-top: 14px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.swatch { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: none; cursor: pointer; font-size: 13px; font-weight: 600; text-align: left; }
.swatch .sq { display: grid; grid-template-columns: repeat(4, 1fr); aspect-ratio: 2; border-radius: 4px; overflow: hidden; }
.swatch[aria-checked="true"], .pset[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.piece-sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.pset { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: none; cursor: pointer; font-size: 13px; font-weight: 600; }
.pset .row { display: flex; gap: 0; padding: 2px 4px; border-radius: 4px; background: var(--sq-light); }
.pset .row:nth-child(2) { background: var(--sq-dark); }
.pset svg { width: 26px; height: 26px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
.keys dt { text-align: right; white-space: nowrap; }
.keys dd { margin: 0; color: var(--pencil); }
kbd { display: inline-block; min-width: 24px; padding: 1px 6px; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 5px; background: var(--raised); font: 600 13px var(--font); text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%); padding: 10px 16px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px; box-shadow: var(--shadow); animation: toast .2s ease-out;
}

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .brand-name, .engine-label, #btnLoad span { display: none; }
  .mode { padding: 7px 10px; }
}
@media (max-width: 900px) {
  .top { grid-template-columns: auto 1fr; }
  .modes {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; justify-content: space-around; border-radius: 0; border: 0;
    border-top: 1px solid var(--rule); background: var(--surface); padding: 4px 4px max(4px, env(safe-area-inset-bottom));
  }
  .mode { flex-direction: column; gap: 2px; font-size: 11.5px; padding: 6px 8px; flex: 1; }
  .mode[aria-current="page"] { box-shadow: none; background: var(--accent-soft); }
  body { padding-bottom: 64px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 10px 10px 24px; }
  .board-col > * { width: 100%; }
  .board-row { grid-template-columns: 14px minmax(0, 1fr); gap: 6px; }
  .player, .controls, .timeline, .variation { padding-left: 0; margin-left: 20px; width: calc(100% - 20px); }
  .controls { padding-left: 0; }
  .evalbar-score { display: none; }
  .online-row { grid-template-columns: 1fr 1fr; }
  .online-row .field:first-child, .online-row .btn { grid-column: 1 / -1; }
  .set-section.two { grid-template-columns: 1fr; }
  .clock { font-size: 19px; min-width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- live board ---------- */
.live-card { padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--rule); min-height: 132px; }
.live-card[data-state="tip"] { background: var(--accent-soft); border-color: var(--accent); }
.lc-turn { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; color: var(--pencil); font-size: 14px; }
.lc-big { margin: 6px 0 0; font-size: 34px; font-weight: 800; line-height: 1.15; color: var(--ink); }
.lc-who { margin: 2px 0 0; font-size: 13px; color: var(--pencil); }
.lc-wait { margin: 10px 0 0; color: var(--pencil); font-style: italic; }
.mini-sheet [aria-current="step"] { color: var(--accent); }
.mini-sheet .empty { color: var(--pencil); font-weight: 500; }
[data-view="live"] .play-actions { grid-template-columns: 1fr 1fr; }
body[data-mode="live"] #btnFirst, body[data-mode="live"] #btnPrev, body[data-mode="live"] #btnAuto,
body[data-mode="live"] #btnNext, body[data-mode="live"] #btnLast { display: none; }
[data-view="live"] .elo-row { grid-template-columns: auto 1fr auto; }
[data-view="live"] .elo-row output { white-space: nowrap; min-width: 84px; }
