:root {
  --bg: #12161b;
  --panel: #1a2027;
  --panel-2: #222a33;
  --line: #2e3945;
  --text: #e8edf2;
  --muted: #93a1b0;
  --accent: #35c9a5;
  --accent-ink: #062a22;
  --warn: #f0a23b;
  --bad: #ef5d5d;
  --sq-light: #e6ebef;
  --sq-dark: #7d98ae;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button, select, input { font: inherit; color: inherit; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 24px; line-height: 1; font-family: "Segoe UI Symbol", "Noto Sans Symbols2", sans-serif; }
.field { display: flex; align-items: center; gap: 8px; }
.field > span { color: var(--muted); font-size: 13px; }
.field.col { flex-direction: column; align-items: stretch; gap: 6px; margin: 14px 0; }
select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 180px;
}
.modes { margin-left: auto; display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.modes button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.modes button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- layout ---------- */
main {
  flex: 1; min-height: 0; display: grid; gap: 16px; padding: 16px 20px;
  grid-template-columns: minmax(240px, 300px) minmax(320px, 1fr) minmax(280px, 360px);
}
.side, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 0; overflow: auto; }
.side { padding: 10px; }
.panel { display: flex; flex-direction: column; }
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.boardFrame { position: relative; width: min(100%, calc(100vh - 170px)); min-width: 280px; }
.who { width: min(100%, calc(100vh - 170px)); color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; min-height: 20px; }
.who b { color: var(--text); font-weight: 600; }
.caps { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; min-height: 22px; }
.cap { font-family: "Segoe UI Symbol", "Noto Sans Symbols2", sans-serif; font-size: 19px; line-height: 1; margin-left: -3px; paint-order: stroke fill; -webkit-text-stroke: 1px #1b1e24; }
.cap.w { color: #fbfaf6; }
.cap.b { color: #2a2d35; -webkit-text-stroke-color: #9aa5b1; }
.lead { margin-left: 8px; font-weight: 700; color: var(--accent); font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid #0008; display: inline-block; }
.dot.w { background: #f4f4f0; } .dot.b { background: #23262b; border-color: #fff5; }

/* ---------- line list ---------- */
details.var { border-radius: 10px; margin-bottom: 4px; }
details.var > summary {
  list-style: none; cursor: pointer; padding: 9px 10px; border-radius: 10px; display: flex; align-items: center; gap: 8px; font-weight: 600;
}
details.var > summary::-webkit-details-marker { display: none; }
details.var > summary::before { content: "\25B8"; color: var(--muted); transition: transform .15s; }
details.var[open] > summary::before { transform: rotate(90deg); }
details.var > summary:hover { background: var(--panel-2); }
.count { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.varBlurb { color: var(--muted); font-size: 13px; padding: 0 10px 6px 28px; }
.lineBtn {
  display: flex; width: 100%; text-align: left; gap: 8px; align-items: baseline; border: 0; background: none; cursor: pointer;
  padding: 6px 10px 6px 28px; border-radius: 8px; color: var(--text);
}
.lineBtn:hover { background: var(--panel-2); }
.lineBtn.on { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.lineBtn .nm { flex: 1; min-width: 0; }
.lineBtn .sub { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; width: 18px; text-align: center; color: var(--muted); flex: none; }
.badge.learned { color: var(--warn); } .badge.clean { color: var(--accent); }

/* ---------- practice setup ---------- */
#setup { padding: 8px; }
.levels { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.levels button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 8px 0; cursor: pointer; font-weight: 700; }
.levels button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; margin: 12px 0; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
button.primary, .controls button.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer;
}
#startBtn { width: 100%; margin: 6px 0 10px; }

/* ---------- right panel ---------- */
.panelHead { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.crumb { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chips:empty { display: none; }
.chip { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.chip.good { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.note { padding: 12px 16px; min-height: 96px; border-bottom: 1px solid var(--line); }
.note .mv { font-weight: 700; color: var(--accent); margin-right: 6px; }
.note p { margin: 0 0 6px; }
.note .bad { color: var(--bad); font-weight: 600; }
.note .good { color: var(--accent); font-weight: 600; }
.moves { list-style: none; margin: 0; padding: 10px 12px; flex: 1; overflow: auto; display: grid; grid-template-columns: 34px 1fr 1fr; align-content: start; gap: 2px 4px; font-variant-numeric: tabular-nums; }
.moves .n { color: var(--muted); text-align: right; padding: 3px 4px; }
.moves button { border: 0; background: none; text-align: left; padding: 3px 8px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.moves button:hover { background: var(--panel-2); }
.moves button.on { background: var(--accent); color: var(--accent-ink); }
.moves button:disabled { cursor: default; }
.moves button:disabled:hover { background: none; }
.moves button.on:disabled:hover { background: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; border-top: 1px solid var(--line); }
.controls button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-weight: 600; }
.controls button:hover { border-color: var(--muted); }
.controls button:disabled { opacity: .4; cursor: default; }
.controls .grow { flex: 1; }

/* ---------- board ---------- */
.board { position: relative; width: 100%; aspect-ratio: 1; container-type: inline-size; user-select: none; touch-action: none; border-radius: 8px; overflow: hidden; box-shadow: 0 10px 30px #0007; }
.squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: #f6d24a; opacity: .5; }
.sq.selected::before { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: .55; }
.sq.check { background-image: radial-gradient(circle, #ff4d4d 0%, #ff4d4d88 45%, transparent 75%); }
.sq.target::after { content: ""; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; transform: translate(-50%, -50%); border-radius: 50%; background: #0b1a2540; }
.sq.target.occupied::after { width: 86%; height: 86%; background: none; border: 0.7cqw solid #0b1a2540; }
.sq.hint { box-shadow: inset 0 0 0 0.7cqw var(--warn); }
.sq.wrong { animation: wrong .6s; }
@keyframes wrong { 0%, 60% { box-shadow: inset 0 0 0 100vmax #ef5d5dcc; } 100% { box-shadow: inset 0 0 0 100vmax #ef5d5d00; } }
.coord { position: absolute; font-size: 2.3cqw; font-weight: 700; opacity: .75; pointer-events: none; }
.coord.file { right: 4%; bottom: 1%; } .coord.rank { left: 4%; top: 1%; }
.sq.light .coord { color: var(--sq-dark); } .sq.dark .coord { color: var(--sq-light); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.arrow.next { fill: #1f9d7fd0; }
.arrow.hint { fill: #f0a23be0; }
.pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%; display: grid; place-items: center;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols2", "Apple Symbols", "DejaVu Sans", sans-serif;
  font-size: 10.4cqw; line-height: 1; transition: left .17s ease, top .17s ease;
  paint-order: stroke fill; -webkit-text-stroke: 0.55cqw #1b1e24;
}
.piece.w { color: #fbfaf6; filter: drop-shadow(0 0.3cqw 0.25cqw #0005); }
.piece.b { color: #2a2d35; -webkit-text-stroke-color: #0e0f13; filter: drop-shadow(0 0.3cqw 0.25cqw #0004); }
.piece.instant, .piece.dragging { transition: none; }
.piece.dragging { z-index: 9; scale: 1.12; }

.promo { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: #0b0e12b0; border-radius: 8px; }
.promo[hidden] { display: none; }
.promo .box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 8px; }
.promo button { width: 64px; height: 64px; font-size: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--sq-dark); cursor: pointer; color: #fff; font-family: "Segoe UI Symbol", sans-serif; }

@media (max-width: 1000px) {
  body { height: auto; }
  main { grid-template-columns: 1fr; }
  .modes { margin-left: 0; }
  .boardFrame, .who { width: min(100%, 560px); }
  .side { max-height: 320px; }
}
