  :root { --bs: max(300px, min(560px, calc(100vh - 230px))); }
:root {
  --bg: #f4f1ea; --surface: #ffffff; --text: #22201c; --muted: #6f6a60; --line: #e2ddd2;
  --accent: #3d6b4f; --accent-text: #ffffff; --ok: #2f7d43; --bad: #b23a2e; --warn: #9a6a12;
  --sq-light: #ecdab9; --sq-dark: #ae8a68; --sq-sel: #e6c35c; --sq-last: rgba(214, 190, 60, .45);
  --sq-hint: rgba(61, 107, 79, .55); --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18; --surface: #262421; --text: #ece8e0; --muted: #a39d92; --line: #3a3733;
    --accent: #6aa57f; --accent-text: #10160f; --ok: #6cc183; --bad: #ec7b6e; --warn: #e0b35a;
    --sq-light: #c9b48f; --sq-dark: #8b6c50; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1a18; --surface: #262421; --text: #ece8e0; --muted: #a39d92; --line: #3a3733;
  --accent: #6aa57f; --accent-text: #10160f; --ok: #6cc183; --bad: #ec7b6e; --warn: #e0b35a;
  --sq-light: #c9b48f; --sq-dark: #8b6c50; --shadow: none;
}
* { 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; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .2rem; }
h2 { font-size: 1.02rem; margin: 0 0 .6rem; }
h3 { font-size: .98rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.top { display: flex; gap: 1rem; align-items: baseline; flex-wrap: wrap; padding: .8rem 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.balance { margin-left: auto; font: 600 .82rem/1 ui-monospace, Menlo, Consolas, monospace; padding: .4rem .6rem; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); white-space: nowrap; }
.balance.low { border-color: var(--bad); color: var(--bad); }
.balance.off { border-color: var(--line); color: var(--muted); }
.or { margin-top: .4rem; }
.prompt-box summary { cursor: pointer; color: var(--muted); }
.prompt-box pre { white-space: pre-wrap; word-break: break-word; font: .78rem/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; margin: .4rem 0 0; }
.jobs .btn { margin-top: .3rem; font-size: .8rem; padding: .25rem .6rem; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } .view { order: -1; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: .5rem; }
label { font-size: .88rem; color: var(--muted); }
input[type=url] { width: 100%; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
input:disabled { opacity: .6; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .5rem .8rem; border-radius: 7px; font: inherit; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.tag { font-size: .72rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); vertical-align: middle; }
.seg { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.seg label { color: var(--text); }
.side-pick button { border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: .4rem .7rem; border-radius: 7px; font: inherit; cursor: pointer; }
.side-pick button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.status { margin-top: .6rem; padding: .55rem .7rem; border-radius: 7px; background: var(--bg); font-size: .9rem; }
.status.err { color: var(--bad); }
.jobs, .trainers, .lines, .ideas { list-style: none; padding: 0; margin: 0; }
.jobs li { font-size: .85rem; padding: .35rem 0; border-top: 1px dashed var(--line); }
.trainers li { padding: .6rem .6rem; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.trainers li:hover { background: var(--bg); }
.trainers li.on { border-color: var(--accent); background: var(--bg); }
.trainers li.dir, .trainers li.dir:hover { padding: 0; cursor: default; background: none; }
.dir summary { cursor: pointer; font-weight: 600; padding: .45rem .2rem; }
.l-src { display: block; font-weight: 400; }
.dir .trainers { padding-left: .6rem; }
.trainers .tt { font-weight: 600; }
.th-row { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.t-summary { margin: 0 0 16px; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-top: .4rem; }
.tabs button { border: 0; background: none; color: var(--muted); padding: .5rem .8rem; font: inherit; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.trainzone { display: grid; grid-template-columns: minmax(0, var(--bs)) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .trainzone { grid-template-columns: 1fr; } }
.board-wrap { min-width: 0; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); container-type: inline-size; width: 100%; max-width: var(--bs); aspect-ratio: 1; border-radius: 6px; overflow: hidden; user-select: none; touch-action: manipulation; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.sq { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--sq-last); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: var(--sq-sel); opacity: .75; }
.sq.hint::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 4px var(--sq-hint); }
.sq.bad::before { content: ""; position: absolute; inset: 0; background: rgba(200, 50, 40, .45); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(230,40,30,.8), transparent 70%); }
.sq.dot::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(30, 30, 30, .28); }
.sq.cap::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(30, 30, 30, .28); }
/* фигуры cburnett (Lichess), CC BY-SA 3.0, Colin M.L. Burnett */
.pc { position: absolute; inset: 0; z-index: 1; background-size: 100% 100%; background-repeat: no-repeat; pointer-events: none; }
/* перетаскивание */
.board.dnd { touch-action: none; }
.sq.dragfrom .pc { opacity: .3; }
.sq.hover::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .75); }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; background-size: 100% 100%; background-repeat: no-repeat; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); will-change: transform; }
.sound-btn { margin-left: .5rem; padding: 4px 10px; }
.coord { position: absolute; font-size: 10px; font-weight: 700; opacity: .7; z-index: 2; color: #3a2d20; }
.coord.f { right: 3px; bottom: 1px; } .coord.r { left: 3px; top: 1px; }
.controls { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }
.panel { display: flex; flex-direction: column; gap: .5rem; min-height: 200px; }
.l-title { font-weight: 700; font-size: 1.05rem; }
.l-restored summary { cursor: pointer; color: var(--warn); }
.msg { font-weight: 600; min-height: 1.4em; }
.msg.ok { color: var(--ok); } .msg.bad { color: var(--bad); } .msg.warn { color: var(--warn); }
[hidden] { display: none !important; }
/* Итог варианта и конец урока — «парят» поверх центра доски, доска не сдвигается */
.board-box { position: relative; max-width: var(--bs); }
.done-box, .lesson-end, .round-end { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(88%, 460px); z-index: 5;
  box-shadow: 0 12px 36px rgba(0,0,0,.45); border-radius: 10px; animation: float-in .22s ease-out; }
@keyframes float-in { from { opacity: 0; transform: translate(-50%, -42%) scale(.96); } to { opacity: 1; transform: translate(-50%, -50%); } }
@media (prefers-reduced-motion: reduce) { .done-box, .lesson-end, .round-end { animation: none; } }
.done-box { display: flex; flex-direction: column; gap: .5rem; padding: .6rem; background: var(--surface); }
.done-main { font: inherit; font-weight: 700; font-size: 1.1rem; text-align: center; padding: .9rem 1rem; border-radius: 8px; cursor: pointer;
  border: 2px solid var(--ok); background: var(--ok); color: var(--surface); }
.done-main.warn { border-color: var(--warn); background: var(--warn); }
.done-main:hover { filter: brightness(1.08); }
.done-row { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.lesson-end, .round-end { display: flex; flex-direction: column; gap: .5rem; padding: 1rem; background: var(--surface); border: 1px solid var(--line); }
:is(.le-title, .re-title) { font-weight: 700; font-size: 1.1rem; }
:is(.lesson-end, .round-end) .btn { align-self: flex-start; }
.note { background: var(--bg); border-left: 3px solid var(--accent); padding: .6rem .7rem; border-radius: 4px; min-height: 3em; white-space: pre-wrap; }
.note:empty { display: none; }
.movelist { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: .15rem .5rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; }
.movelist .cur { background: var(--sq-sel); color: #222; border-radius: 3px; padding: 0 3px; }
.movelist .hid { color: var(--muted); }
.lines-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
@media (max-width: 1100px) { .lines-wrap { grid-template-columns: 1fr; } }
.lines li { display: flex; justify-content: space-between; gap: .6rem; padding: .45rem .5rem; border-radius: 7px; cursor: pointer; }
.lines li:hover { background: var(--bg); }
.lines li.on { background: var(--bg); outline: 1px solid var(--accent); }
.badge { font-size: .75rem; white-space: nowrap; color: var(--muted); }
.badge.done { color: var(--ok); font-weight: 600; }
.ideas-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .ideas-grid { grid-template-columns: 1fr; } }
.video { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.ideas li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.ideas .it { font-weight: 700; }
.ideas .ts { font-size: .82rem; margin-left: .4rem; }
.ideas .il { margin-top: .4rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.ideas .il button { font-size: .8rem; padding: .2rem .5rem; }
.empty p { margin: 0; }
/* ---------- Партии чемпионов ---------- */
:root { --c-theory: #3b6ea8; --c-best: #2f7d43; --c-good: #5f8f3a; --c-inacc: #b08214; --c-mist: #c8661c; --c-blun: #b23a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --c-theory: #7fa8dc; --c-best: #6cc183; --c-good: #a2c46e; --c-inacc: #e0b35a; --c-mist: #ec9a5a; --c-blun: #ec7b6e; } }
:root[data-theme="dark"] { --c-theory: #7fa8dc; --c-best: #6cc183; --c-good: #a2c46e; --c-inacc: #e0b35a; --c-mist: #ec9a5a; --c-blun: #ec7b6e; }
.back-link { display: inline-block; margin-bottom: .2rem; text-decoration: none; }
.remarks { display: flex; flex-direction: column; gap: .5rem; }
.rm { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; background: var(--bg); }
.rm.mine { border-left: 4px solid var(--accent); }
.rm.theirs { border-left: 4px solid var(--line); }
.rm-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; }
.rm-who { font-size: .8rem; color: var(--muted); }
.rm-move { font: 700 1.05rem/1.2 ui-monospace, Menlo, Consolas, monospace; }
.rm-eval { margin-left: auto; font: 600 .85rem/1 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
.rm-text { margin-top: .3rem; }
.rm-best { margin-top: .2rem; color: var(--muted); }
.b-str, .b-src { font-size: .78rem; font-weight: 700; border-radius: 99px; padding: 2px 9px; white-space: nowrap; }
.b-str { color: #fff; background: var(--muted); }
.b-str.s-theory { background: var(--c-theory); } .b-str.s-best, .b-str.s-only { background: var(--c-best); }
.b-str.s-good { background: var(--c-good); } .b-str.s-inaccuracy { background: var(--c-inacc); }
.b-str.s-mistake { background: var(--c-mist); } .b-str.s-blunder { background: var(--c-blun); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .b-str { color: #15130f; } }
:root[data-theme="dark"] .b-str { color: #15130f; }
.b-src { border: 1px solid var(--line); color: var(--text); background: var(--surface); }
.b-src.th { border-color: var(--c-theory); color: var(--c-theory); }
.b-src.r1 { border-color: var(--c-best); color: var(--c-best); }
.b-src.r2, .b-src.r3 { border-color: var(--c-good); color: var(--c-good); }
.b-src.r0 { border-color: var(--c-mist); color: var(--c-mist); font-weight: 600; }
.movelist sup { font-size: .7em; font-weight: 700; }
.movelist .mv-theory { color: var(--c-theory); }
.movelist .mv-inaccuracy { color: var(--c-inacc); } .movelist .mv-mistake { color: var(--c-mist); } .movelist .mv-blunder { color: var(--c-blun); font-weight: 700; }
.movelist .cur { color: #222; }
.games { list-style: none; padding: 0; margin: 0; }
.games li { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .55rem .5rem; border-top: 1px solid var(--line); }
.games li:first-child { border-top: 0; }
.games.added li[data-open] { cursor: pointer; border-radius: 7px; }
.games.added li[data-open]:hover { background: var(--bg); }
.games .g-main { min-width: 0; }
.games .btn { flex: none; font-size: .85rem; padding: .35rem .7rem; }
.pk-head { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0 .6rem; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 99px; padding: .3rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chip span { color: var(--muted); font-size: .78rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip.on span { color: inherit; }
.pk-search { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; margin-bottom: .4rem; }
.picker .act-more { margin-top: .5rem; }
.bar { height: 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
@media (max-width: 600px) { .games li { flex-direction: column; align-items: stretch; } .rm-eval { margin-left: 0; } }
.pk-tools { display: flex; gap: .4rem 1rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.pk-tools .pk-search { flex: 1 1 260px; margin: 0; }
.pk-classic { color: var(--text); white-space: nowrap; }

.t-texts { margin-top: .4rem; }
.tx-tag { display: inline-block; font-size: .78rem; font-weight: 600; border-radius: 99px; padding: 1px 9px; border: 1px solid var(--line); color: var(--muted); background: var(--bg); white-space: nowrap; }
.tx-tag.openrouter { border-color: var(--c-theory); color: var(--c-theory); }
.tx-tag.terminal { border-color: var(--accent); color: var(--accent); }
.tx-tag.work { border-color: var(--warn); color: var(--warn); }
.tx-act { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; margin-top: .4rem; }
.tx-act .btn { font-size: .85rem; padding: .3rem .7rem; }
.g-num { color: var(--muted); font-weight: 600; margin-right: .2rem; }
.games .tx-tag { margin-left: .3rem; vertical-align: 1px; }
.movelist.nav li[data-k] { cursor: pointer; border-radius: 3px; padding: 0 2px; }
.movelist.nav li[data-k]:hover { background: var(--bg); outline: 1px solid var(--line); }
.movelist .fut { opacity: .45; }
.tx-term { margin-top: .5rem; display: flex; flex-direction: column; gap: .3rem; align-items: flex-start; }
.tx-prompt { margin: 0; white-space: pre-wrap; word-break: break-word; font: .85rem/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .6rem; user-select: all; }
.tx-term .btn { font-size: .85rem; padding: .3rem .7rem; }
.pk-moves { display: flex; gap: .4rem; margin-bottom: .3rem; }
.pk-line { flex: 1; min-width: 0; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: .95rem ui-monospace, Menlo, Consolas, monospace; }
.pk-line-info { min-height: 1.2em; margin-bottom: .2rem; font-weight: 400; }
.next-moves { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-bottom: .5rem; }
.next-moves .chip { font-family: ui-monospace, Menlo, Consolas, monospace; padding: .2rem .55rem; }
.rm.concl { border-left: 4px solid var(--c-best); background: var(--surface); }
.rm.concl.empty { border-left-color: var(--line); background: var(--bg); }
.rm.concl .rm-text { white-space: pre-wrap; }

/* окна итога: крестик */
.ov-close { position: absolute; top: .3rem; right: .4rem; width: 2.25rem; height: 2.25rem; border: 0; background: none; color: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer; border-radius: 6px; }
.ov-close:hover { background: var(--line); }
:is(.le-title, .re-title) { padding-right: 2.25rem; }

/* chess2: только тренировка */
.balance + .sync { margin-left: 0; }
.train-only .authoring, .train-only #balance, .train-only .act-add, .train-only .picker, .train-only .tx-act, .train-only .tx-term { display: none !important; }
.train-only .balance.sync { margin-left: auto; }
