:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f0ece5;
  --border: #e2dcd2;
  --text: #22201c;
  --muted: #736c61;
  --accent: #5b8a3c;
  --accent-text: #ffffff;
  --c-best: #3f8f4f;
  --c-good: #7a8a6a;
  --c-inacc: #c49a1a;
  --c-mistake: #d97a1e;
  --c-blunder: #d03b32;
  --g-bg: #3b3833;
  --g-area: #f2efe9;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18;
    --surface: #262421;
    --surface-2: #302e2a;
    --border: #3a3732;
    --text: #ebe7e0;
    --muted: #a39d92;
    --accent: #79ad55;
    --accent-text: #11140e;
    --c-good: #9aa88c;
    --c-inacc: #e3b736;
    --c-mistake: #ee9541;
    --c-blunder: #ee5a50;
    --g-bg: #1b1a18;
    --g-area: #d9d4cb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; line-height: 1; }
.engine-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.engine-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c-inacc); }
.engine-status[data-kind="ok"]::before { background: var(--c-best); }
.engine-status[data-kind="err"]::before { background: var(--c-blunder); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 600px) minmax(300px, 400px);
  gap: 24px; justify-content: center;
  padding: 20px 16px 40px;
}
.board-col, .side-col { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
/* На десктопе доска с подписями игроков и кнопками помещается в высоту экрана. */
.board-col { width: 100%; max-width: max(380px, calc(100vh - 170px)); justify-self: end; }

/* ---- Доска ---- */
.board-row { display: flex; gap: 8px; align-items: stretch; }
.board-wrap { flex: 1; min-width: 0; }
.board { width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: hidden; }

.cg-wrap coords { font-size: 11px; font-weight: 700; opacity: 1; font-family: system-ui, sans-serif; }
.cg-wrap coords.ranks { left: 3px; top: 2px; height: 100%; width: 12px; }
.cg-wrap coords.ranks coord { transform: none; }
.cg-wrap coords.files { left: 0; bottom: 1px; width: 100%; height: 14px; text-align: right; text-transform: none; }
.cg-wrap coords.files coord { padding-right: 3px; }
.cg-wrap coords coord:nth-child(odd) { color: #f0d9b5; }
.cg-wrap coords coord:nth-child(even) { color: #946f51; }
.cg-wrap.orientation-black coords coord:nth-child(odd) { color: #946f51; }
.cg-wrap.orientation-black coords coord:nth-child(even) { color: #f0d9b5; }
cg-board square.last-move { background-color: rgba(155, 199, 0, 0.41); }
cg-board square.check { background: radial-gradient(ellipse at center, rgba(255,0,0,1) 0%, rgba(231,0,0,1) 25%, rgba(169,0,0,0) 89%, rgba(158,0,0,0) 100%); }

.evalbar {
  position: relative; width: 22px; flex: none; border-radius: 4px; overflow: hidden;
  background: #403d39; display: flex; flex-direction: column-reverse;
}
.evalbar.flipped { flex-direction: column; }
.evalbar-white { background: #f4f2ee; height: 50%; transition: height .35s ease; }
.evalbar-text {
  position: absolute; left: 0; right: 0; top: 4px; text-align: center;
  font-size: 10px; font-weight: 700; color: #f4f2ee; writing-mode: horizontal-tb;
}
.evalbar-text.on-white { top: auto; bottom: 4px; color: #403d39; }
.evalbar.flipped .evalbar-text { top: auto; bottom: 4px; }
.evalbar.flipped .evalbar-text.on-white { top: 4px; bottom: auto; }

.player-strip { display: flex; align-items: center; gap: 8px; min-height: 24px; padding-left: 30px; font-size: 14px; }
.elo { color: var(--muted); font-size: 13px; font-weight: 400; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; border: 1px solid #8a847a; }
.dot.white { background: #f4f2ee; }
.dot.black { background: #2b2926; }

.controls { display: flex; align-items: center; gap: 6px; padding-left: 30px; }
.spacer { flex: 1; }
.icon-btn, .btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; transition: background .15s, border-color .15s;
}
.icon-btn { min-width: 40px; }
.btn { white-space: nowrap; }
.btn .sm { display: none; }
@media (max-width: 480px) { .btn .lg { display: none; } .btn .sm { display: inline; } }
.icon-btn:hover, .btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding-left: 30px; cursor: pointer; }

.graph { margin-left: 30px; height: 110px; border-radius: 6px; overflow: hidden; cursor: pointer; }
.graph svg { width: 100%; height: 100%; display: block; }
.g-bg { fill: var(--g-bg); }
.g-area { fill: var(--g-area); }
.g-mid { stroke: #8a847a; stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.g-line { fill: none; stroke: #b8b2a7; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.g-cursor { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.g-mark { stroke: #1b1a18; stroke-width: 1; vector-effect: non-scaling-stroke; }
.g-mark.inaccuracy { fill: var(--c-inacc); }
.g-mark.mistake { fill: var(--c-mistake); }
.g-mark.blunder { fill: var(--c-blunder); }

/* ---- Правая колонка ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card-title { font-weight: 600; margin-bottom: 8px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; margin-bottom: 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
textarea, input[type="text"], select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 8px 10px;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.row input { flex: 1; }
.depth-row { margin-top: 12px; font-size: 13px; color: var(--muted); }
.depth-row label { white-space: nowrap; }
.depth-row select { flex: 1; width: auto; }
.error { color: var(--c-blunder); font-size: 13px; margin: 8px 0 0; }

.game-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; max-height: 260px; overflow-y: auto; }
.game-item {
  text-align: left; border: 1px solid transparent; background: var(--surface-2); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; font-size: 13px;
}
.game-item:hover { border-color: var(--border); }
.game-item.selected { border-color: var(--accent); }
.gi-players { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.gi-meta { color: var(--muted); font-size: 12px; }
.vs { color: var(--muted); }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.comment p { margin: 6px 0 0; }
.cm-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cm-move { font-weight: 700; font-size: 17px; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; color: #fff; background: var(--c-good); }
.badge.best { background: var(--c-best); }
.badge.inaccuracy { background: var(--c-inacc); color: #2a2208; }
.badge.mistake { background: var(--c-mistake); }
.badge.blunder { background: var(--c-blunder); }
.badge.pending { background: var(--surface-2); color: var(--muted); }
.eval-row { display: flex; gap: 10px; align-items: baseline; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.eval-chip { font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface-2); padding: 2px 8px; border-radius: 6px; flex: none; }
.pv { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.comment > p.muted:first-child { margin-top: 0; }

.sum-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto auto auto; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.sum-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.cnt { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.cnt.inaccuracy { color: var(--c-inacc); }
.cnt.mistake { color: var(--c-mistake); }
.cnt.blunder { color: var(--c-blunder); }

.moves-card { padding: 6px; }
.moves-list {
  display: grid; grid-template-columns: 3em 1fr 1fr; align-items: stretch;
  max-height: 340px; overflow-y: auto; position: relative; font-size: 14px;
}
.moves-list:empty { display: none; }
.moves-card:has(.moves-list:empty) { display: none; }
.mno { color: var(--muted); padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.mcell { border: 0; background: transparent; text-align: left; padding: 4px 8px; border-radius: 5px; cursor: pointer; font-weight: 500; }
.mcell:hover { background: var(--surface-2); }
.mcell.active { background: var(--accent); color: var(--accent-text); }
.mcell.empty { cursor: default; color: var(--muted); }
.sym { margin-left: 2px; font-weight: 800; }
.mcell.inaccuracy .sym { color: var(--c-inacc); }
.mcell.mistake .sym { color: var(--c-mistake); }
.mcell.blunder .sym { color: var(--c-blunder); }
.mcell.active .sym { color: inherit; }

/* ---- Переключатель режимов ---- */
.modes { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.mode { padding: 6px 14px; border-radius: 7px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap; }
.mode:hover { color: var(--text); }
.mode[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.top .engine-status { min-width: 150px; justify-content: flex-end; }

/* ---- Задачи ---- */
.puzzles .controls { padding-left: 0; }
.puzzles .board-wrap { flex: none; }
.puzzles .board-col { max-width: max(360px, calc(100vh - 150px)); }
.btn:disabled { opacity: .45; cursor: default; background: var(--surface); }
.pz-status { border-left: 4px solid var(--border); min-height: 76px; }
.pz-status[data-kind="ok"] { border-left-color: var(--c-best); }
.pz-status[data-kind="bad"] { border-left-color: var(--c-blunder); }
.pz-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.pz-status[data-kind="ok"] .pz-title { color: var(--c-best); }
.pz-status[data-kind="bad"] .pz-title { color: var(--c-blunder); }
.pz-sub { margin-top: 4px; color: var(--muted); font-size: 14px; }
.delta { font-size: 14px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.delta.up { color: var(--c-best); }
.delta.down { color: var(--c-blunder); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field + .field { margin-top: 10px; }
.stats { display: grid; grid-template-columns: auto 1fr 1fr; gap: 16px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-value.small-value { font-size: 15px; padding-top: 6px; }
.hist-label { margin-top: 14px; }
.history { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; min-height: 24px; align-items: center; }
.hist { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 13px; font-weight: 700; text-decoration: none; color: #fff; }
.hist.ok { background: var(--c-best); }
.hist.bad { background: var(--c-blunder); }
.link-btn { border: 0; background: none; color: var(--muted); padding: 0; margin-top: 12px; cursor: pointer; text-decoration: underline; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); }
.card a { color: var(--accent); }
.credit { margin: 0 4px; }
.stats.two { grid-template-columns: auto 1fr; gap: 28px; }
.row-links { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-top: 12px; }
.row-links .link-btn { margin-top: 0; }
.mine-about { margin: 0; }
#pzInfo p { margin: 8px 0 0; }
#pzInfo .badge { font-size: 11px; padding: 2px 7px; }
.train-card p { margin: 0 0 10px; }
.train-hint { margin-top: 10px; line-height: 1.3; }
.credit a { color: inherit; }

/* ---- Уроки ---- */
.lessons .board-wrap { flex: none; }
.lessons .board-col { max-width: max(360px, calc(100vh - 110px)); }
.mode .sm { display: none; }
.ls-intro p { margin: 0 0 12px; }
.ls-intro .progress { margin: 0 0 6px; }
.ls-continue { margin-top: 12px; width: 100%; white-space: normal; }
.ls-section { padding: 10px; }
.ls-section .card-title { padding: 4px 6px 2px; }
.ls-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; cursor: pointer;
}
.ls-item:hover { background: var(--surface-2); }
.ls-num {
  width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.ls-item.done .ls-num { background: var(--c-best); color: #fff; }
.ls-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ls-check { color: var(--c-best); font-weight: 800; }
.ls-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ls-head .link-btn { margin: 0; }
.ls-title { font-size: 20px; font-weight: 700; margin-top: 8px; }
.ls-dots { display: flex; gap: 5px; margin: 8px 0 4px; }
.ls-dot { height: 5px; flex: 1; max-width: 36px; border-radius: 3px; background: var(--surface-2); }
.ls-dot.past { background: var(--c-best); }
.ls-dot.now { background: var(--accent); opacity: .6; }
.ls-text { font-size: 15px; line-height: 1.55; }
.ls-text p { margin: 10px 0 0; }
.ls-text ul, .ls-text ol { margin: 8px 0 0; padding-left: 22px; }
.ls-text li { margin: 3px 0; }
.ls-feedback { margin-top: 12px; padding: 9px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.ls-feedback[data-kind="ok"] { color: var(--c-best); font-weight: 600; }
.ls-feedback[data-kind="bad"] { color: var(--c-blunder); }
.ls-buttons { display: flex; gap: 6px; align-items: center; margin-top: 14px; }
.btn:disabled.primary { background: var(--surface-2); border-color: var(--border); color: var(--muted); filter: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 32px; gap: 16px; }
  .board-col { max-width: 600px; width: 100%; margin: 0 auto; }
}
@media (max-width: 640px) {
  .brand-name, .top .engine-status { display: none; }
  .modes { flex: 1; }
  .mode { flex: 1; text-align: center; padding: 6px 8px; }
  .mode .lg { display: none; }
  .mode .sm { display: inline; }
}
@media (max-width: 480px) {
  .top { padding: 10px 16px; }
  .engine-status { font-size: 12px; }
  .player-strip, .controls, .check { padding-left: 0; }
  .graph { margin-left: 0; }
  .btn { padding: 7px 10px; }
  .board-row { gap: 6px; }
  .evalbar { width: 16px; }
}
