:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #22201c;
  --muted: #77716a;
  --border: #e2ddd3;
  --accent: #2f7a4d;
  --accent-text: #ffffff;
  --bad: #c0392b;
  --warn: #b7791f;
  --good-bg: #e7f4ec;
  --bad-bg: #fbeae8;
  --info-bg: #eef1f6;
  --black-bg: #f1eee8;
  --done-bg: #fff4d6;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --last: rgba(155, 199, 0, 0.42);
  --sel: rgba(20, 85, 30, 0.5);
  --hint: rgba(40, 120, 220, 0.45);
  --arrow: rgba(30, 110, 210, 0.8);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18; --surface: #262422; --text: #ece8e1; --muted: #a29b91; --border: #3a3733;
    --accent: #4caf73; --good-bg: #1f3427; --bad-bg: #3d2220; --info-bg: #232a35; --black-bg: #2c2a27; --done-bg: #3a3220;
    --bad: #ef6f61; --warn: #e0a84a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header { max-width: 1120px; margin: 0 auto; padding: 14px 16px 6px; }
h1 { font-size: 20px; margin: 0; }
h1 span { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 6px; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }

main {
  max-width: 1120px; margin: 0 auto; padding: 8px 16px;
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start;
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
}

/* ── board ── */
.board-wrap { width: 100%; max-width: min(680px, calc(100vh - 90px)); justify-self: center; }
@media (max-width: 860px) { .board-wrap { max-width: 640px; } }
.board {
  position: relative; width: 100%; aspect-ratio: 1; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 4px; overflow: hidden; box-shadow: 0 3px 14px rgba(0,0,0,.18);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.sq { position: relative; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.last::before, .sq.sel::before, .sq.hint::before, .sq.bad::before, .sq.check::before {
  content: ""; position: absolute; inset: 0;
}
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.hint::before { background: var(--hint); }
.sq.bad::before { background: rgba(220, 40, 30, .5); }
.sq.check::before { background: radial-gradient(circle, rgba(255,0,0,.85) 0%, rgba(230,0,0,.4) 45%, transparent 75%); }
.sq.target::after {
  content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(20, 85, 30, .45); pointer-events: none;
}
.sq.capture::after {
  content: ""; position: absolute; inset: 4%; border-radius: 50%;
  border: 5px solid rgba(20, 85, 30, .45); pointer-events: none; z-index: 2;
}
.piece {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;
  pointer-events: none; will-change: transform;
}
.piece.dragging { z-index: 10; filter: drop-shadow(0 6px 6px rgba(0,0,0,.35)); }
.coord { position: absolute; font-size: clamp(9px, 1.6vw, 12px); font-weight: 600; pointer-events: none; z-index: 0; }
.coord.file { right: 3px; bottom: 1px; }
.coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 8; }
.arrows line { stroke: var(--arrow); }
.arrows polygon { fill: var(--arrow); }

/* ── panel ── */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.opening { font-weight: 700; font-size: 16px; }
.status { color: var(--muted); font-size: 14px; }
.status .warn { color: var(--warn); font-weight: 600; }
.feed { display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.msg { padding: 7px 10px; border-radius: 7px; font-size: 14px; border-left: 3px solid transparent; }
.msg.good { background: var(--good-bg); border-color: var(--accent); }
.msg.bad { background: var(--bad-bg); border-color: var(--bad); }
.msg.info { background: var(--info-bg); border-color: #6b8ac4; }
.msg.black { background: var(--black-bg); border-color: #555; }
.msg.done { background: var(--done-bg); border-color: var(--warn); }

.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  font: inherit; padding: 8px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.small { padding: 3px 9px; font-size: 13px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

.moves {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px;
  background: var(--bg); border-radius: 7px; padding: 8px 10px; max-height: 96px; overflow-y: auto;
}
.moves .num { color: var(--muted); margin-right: 3px; }
.moves .mv { margin-right: 4px; }
.moves .mv.cur { font-weight: 700; }
.moves .mv.mistake { color: var(--bad); }

.settings { display: flex; flex-direction: column; gap: 8px; font-size: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.settings select { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.settings .check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.settings .check input { margin-top: 3px; }
.drill { background: var(--info-bg); padding: 8px 10px; border-radius: 7px; font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drill button { margin-left: auto; }
.errors { color: var(--bad); font-size: 13px; }

/* ── lines browser ── */
.lines-wrap { max-width: 1120px; margin: 10px auto 30px; padding: 0 16px; }
.lines-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
details { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; }
summary { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
summary .muted { font-weight: 400; font-size: 13px; }
.line { padding: 8px 14px; border-top: 1px solid var(--border); }
.line-head { display: flex; gap: 8px; align-items: center; }
.line-name { flex: 1; min-width: 0; }
.line-moves { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.badge { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.badge.new { background: var(--info-bg); color: var(--muted); }
.badge.ok { background: var(--good-bg); color: var(--accent); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.trap { background: var(--done-bg); color: var(--warn); }
.foot { font-size: 13px; }
