:root {
  color-scheme: light dark;
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1f1d1a;
  --muted: #6e6a62;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --line: #ddd8cc;
  --light: #eeeed2;
  --dark: #769656;
  --good: #3fa34d;
  --bad: #d64545;
  --hint: #2d6cdf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161512;
    --card: #23211d;
    --text: #ece9e2;
    --muted: #a39e94;
    --accent: #5aa37a;
    --accent-text: #0f0e0c;
    --line: #3a3731;
    --light: #c9c3ad;
    --dark: #6b8a4e;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  overscroll-behavior: none;
}
header { display: flex; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 0 8px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 17px; margin: 8px 0 4px; }
button {
  font: inherit; border: 0; border-radius: 10px; padding: 11px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.icon { background: none; color: var(--text); font-size: 26px; padding: 0 8px; line-height: 1; }
button:disabled { opacity: .5; }
input[type=search] {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
input[type=range] { width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.list { margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer;
}
.item .ru { font-weight: 600; }
.item .en { font-size: 12px; color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.actions.row { flex-direction: row; flex-wrap: wrap; }
.actions.row button { flex: 1 1 40%; }
.line { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.credits { font-size: 11px; color: var(--muted); margin-top: 24px; }

/* доска */
#board { width: 100%; max-width: 480px; margin: 6px auto; }
.board { position: relative; aspect-ratio: 1; user-select: none; touch-action: none; }
.board .grid { display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); width: 100%; height: 100%;
  border-radius: 6px; overflow: hidden; }
.sq { position: relative; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sq img.lifted { opacity: .3; }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(255, 213, 0, .38); }
.sq.selected::before { content: ""; position: absolute; inset: 0; background: rgba(20, 85, 30, .45); }
.sq.check::before { content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255, 0, 0, .8) 0, rgba(231, 0, 0, .4) 45%, transparent 75%); }
.sq.dest::after { content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(20, 85, 30, .45); }
.sq.capture::after { content: ""; position: absolute; inset: 4%; border-radius: 50%;
  border: 5px solid rgba(20, 85, 30, .45); }
.sq.good::before { content: ""; position: absolute; inset: 0; background: rgba(63, 163, 77, .55); }
.sq.bad::before { content: ""; position: absolute; inset: 0; background: rgba(214, 69, 69, .55); }
.coord { position: absolute; font-size: 10px; font-weight: 700; z-index: 1; opacity: .75; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.arrows line { stroke-width: .16; stroke-linecap: round; opacity: .8; }
.arrows line.hint, .arrows marker.hint path { stroke: var(--hint); fill: var(--hint); }
.arrows line.good, .arrows marker.good path { stroke: var(--good); fill: var(--good); }
.arrows line.bad, .arrows marker.bad path { stroke: var(--bad); fill: var(--bad); }
.ghost { position: fixed; pointer-events: none; z-index: 10; }

.status {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  min-height: 44px; margin-top: 8px;
}
.status .good { color: var(--good); font-weight: 600; }
.status .bad { color: var(--bad); font-weight: 600; }
.stats { margin-top: 8px; font-size: 13px; }
.stats table { width: 100%; border-collapse: collapse; }
.stats td { padding: 3px 4px; border-bottom: 1px solid var(--line); }
.stats td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }

/* изучение */
#study-board { width: 100%; max-width: 480px; margin: 6px auto; }
.nav { margin: 6px 0; }
.actions.row.nav button { flex: 1 1 20%; padding: 8px; font-size: 17px; }
.path { font-size: 14px; line-height: 1.9; margin: 6px 0; }
.path .ply { padding: 2px 4px; border-radius: 5px; cursor: pointer; }
.path .ply.current { background: var(--accent); color: var(--accent-text); }
.path .ply.future { color: var(--muted); }
.path .num { color: var(--muted); margin-left: 4px; }
.stats tr.branch { cursor: pointer; }
.stats tr.branch:active { background: var(--line); }
.stats tr.main td:first-child b::after { content: " ★"; color: var(--accent); font-size: 11px; }
.note-mark { color: var(--hint); }
.comment p { margin: 4px 0; }
.comment .name { font-weight: 600; }
.note { border-left: 3px solid var(--hint); padding-left: 8px; margin-top: 6px; white-space: pre-wrap; }
textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 10px; margin-top: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); resize: vertical;
}
.stats td .sub { font-size: 11px; color: var(--muted); font-weight: normal; }
.stats tr.branch td { padding-top: 8px; padding-bottom: 8px; }
.path .ply { display: inline-block; min-height: 28px; }
