:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1d1f24;
  --muted: #6b6f78;
  --border: #e2ded6;
  --accent: #3f9b5a;
  --accent-text: #ffffff;
  --sq-light: #eedfc6;
  --sq-dark: #b08a64;
  --c-brilliant: #1aa9a1;
  --c-book: #a5825f;
  --c-great: #4a86d9;
  --c-miss: #d4527c;
  --c-best: #3f9b5a;
  --c-excellent: #64a97a;
  --c-good: #8aa48f;
  --c-inaccuracy: #e1a325;
  --c-mistake: #e5752f;
  --c-blunder: #d33f3f;
  --c-forced: #8b8f98;
  --graph-black: #2b2e35;
  --graph-white: #f4f2ee;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 24px rgba(0, 0, 0, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b;
    --surface: #1d2027;
    --surface-2: #262a33;
    --text: #e9eaee;
    --muted: #9aa0ab;
    --border: #2e333d;
    --graph-black: #0f1115;
    --graph-white: #d9dbe0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; max-width: 1180px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand-icon { width: 30px; height: 30px; background: var(--accent); border-radius: 8px; padding: 2px; }
.lang { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang button { background: none; border: 0; padding: 5px 11px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px 32px; }

.hero { text-align: center; padding: 40px 0 20px; }
.hero h1 { font-size: clamp(26px, 4.5vw, 40px); line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.02em; }
.tagline { color: var(--muted); margin: 0 auto; max-width: 560px; font-size: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }

.load { max-width: 720px; margin: 8px auto 0; padding: 18px; }
body.has-game .load { max-width: none; padding: 12px 14px; }
body.has-game .hero, body.has-game .features, body.has-game .hint { display: none; }
.source-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.source-row label { color: var(--muted); font-size: 14px; white-space: nowrap; }
.source-row select { flex: 1; max-width: 260px; font-weight: 600; }
.load-form { display: flex; gap: 8px; align-items: flex-start; }
.load-form textarea { font: 13px/1.45 ui-monospace, Consolas, monospace; resize: vertical; }
.load-form input, .load-form textarea, select {
  flex: 1; min-width: 0; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none;
}
.load-form input:focus, .load-form textarea:focus, select:focus { border-color: var(--accent); }

.games { margin-top: 12px; }
.games-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.games-list li + li { border-top: 1px solid var(--border); }
.games-list button {
  width: 100%; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px;
  background: none; border: 0; padding: 9px 12px; cursor: pointer; text-align: left;
}
.games-list button:hover { background: var(--surface-2); }
.res { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; font-size: 14px; }
.res-win { background: var(--c-best); }
.res-loss { background: var(--c-blunder); }
.res-draw { background: var(--c-forced); }
.g-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-main .pcolor { display: inline-block; width: 10px; height: 10px; border-radius: 2px; border: 1px solid var(--muted); margin-right: 6px; vertical-align: 0; }
.g-main .pcolor.w { background: #f4f2ee; }
.g-main .pcolor.b { background: #22252b; }
.g-main .rating { color: var(--muted); }
.g-meta { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.secondary {
  margin-top: 8px; width: 100%; padding: 9px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.secondary:hover { filter: brightness(1.08); }
body.single-pos .graph-card, body.single-pos .summary, body.single-pos .moves-card { display: none; }
.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px; padding: 11px 20px; font-weight: 650; cursor: pointer; white-space: nowrap;
}
.primary:hover { filter: brightness(1.07); }
.load-options { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 12px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }
.depth { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.depth select { padding: 6px 10px; flex: none; }
.hint { color: var(--muted); font-size: 13px; margin: 0; flex: 1; min-width: 200px; }
.status { margin: 8px 0 0; font-size: 14px; min-height: 0; }
.status:empty { display: none; }
.status.error { color: var(--c-blunder); }

.features { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px 26px; margin: 26px auto 0; color: var(--muted); font-size: 14px; }
.features div { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- review layout ---------- */
.review { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; margin-top: 16px; align-items: start; }
.board-col { min-width: 0; }
.side-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.player-strip { display: flex; align-items: center; gap: 10px; padding: 8px 2px 8px 34px; min-height: 44px; }
.player-strip .avatar { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.player-strip .pname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-strip .ptitle { background: var(--c-blunder); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }
.player-strip .prating { color: var(--muted); }
.player-strip .clock { margin-left: auto; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 2px 9px; font-weight: 600; }
.player-strip .clock.active { background: var(--text); color: var(--bg); }

.board-wrap { display: flex; gap: 8px; }
.evalbar { position: relative; width: 26px; flex: none; border-radius: 6px; overflow: hidden; background: var(--graph-black); }
.evalbar-white { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--graph-white); transition: height .35s ease; }
.evalbar.flipped .evalbar-white { top: 0; bottom: auto; }
.evalbar-text { position: absolute; left: 0; right: 0; text-align: center; font-size: 10.5px; font-weight: 700; bottom: 4px; color: #222; }
.evalbar-text.top { bottom: auto; top: 4px; color: #eee; }
.board { flex: 1; min-width: 0; aspect-ratio: 1; border-radius: 6px; overflow: hidden; user-select: none; }
.board-svg { display: block; width: 100%; height: 100%; }
.sq-light { fill: var(--sq-light); }
.sq-dark { fill: var(--sq-dark); }
.coord { font: 700 7.5px system-ui, sans-serif; }
.coord.on-light { fill: var(--sq-dark); }
.coord.on-dark { fill: var(--sq-light); }
.hl { fill: rgba(255, 214, 64, .45); }
.hl-best, .hl-excellent, .hl-forced { fill: rgba(79, 170, 104, .45); }
.hl-good { fill: rgba(140, 170, 145, .45); }
.hl-brilliant { fill: rgba(26, 169, 161, .5); }
.hl-great { fill: rgba(74, 134, 217, .5); }
.hl-miss { fill: rgba(212, 82, 124, .5); }
.hl-book { fill: rgba(165, 130, 95, .45); }
.comment .opening { margin-top: 6px; font-size: 14px; color: var(--muted); }
.comment .opening b { color: var(--text); font-weight: 600; }
.comment .eco { font-size: 12px; opacity: .8; }.hl-inaccuracy { fill: rgba(232, 172, 40, .5); }
.hl-mistake { fill: rgba(232, 120, 50, .5); }
.hl-blunder { fill: rgba(214, 60, 60, .5); }
.arrow { fill: rgba(40, 150, 75, .82); }
.badge-text { font: 800 9px system-ui, sans-serif; fill: #fff; }

.controls { display: flex; justify-content: center; gap: 6px; margin-top: 6px; padding-left: 34px; }
.controls button {
  flex: 1; max-width: 86px; padding: 9px 0; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 15px;
}
.controls button:hover { background: var(--surface-2); }
.keys { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0 0; padding-left: 34px; }

.progress-card { padding: 12px 14px; display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.comment { padding: 14px 16px; min-height: 92px; }
.comment .headline { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 650; }
.comment .ico { width: 24px; height: 24px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex: none; }
.comment .ev { margin-left: auto; font-variant-numeric: tabular-nums; background: var(--surface-2); padding: 2px 9px; border-radius: 6px; font-size: 14px; }
.comment .better { margin-top: 6px; color: var(--muted); }
.comment .line { margin-top: 8px; font-size: 13px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.comment .line b { font-family: system-ui, sans-serif; font-weight: 600; }

.graph-card { padding: 8px; }
.graph { display: block; width: 100%; height: 110px; cursor: pointer; border-radius: 6px; touch-action: none; }

.summary { padding: 12px 14px; }
.summary table { width: 100%; border-collapse: collapse; font-size: 14px; }
.summary th { font-weight: 600; text-align: center; padding: 2px 4px 8px; }
.summary th:first-child, .summary td:first-child { text-align: left; }
.summary td { padding: 4px; text-align: center; font-variant-numeric: tabular-nums; }
.summary .acc td { font-size: 22px; font-weight: 750; padding-bottom: 10px; }
.summary .acc td:first-child { font-size: 14px; font-weight: 600; color: var(--muted); }
.summary .clsname { display: flex; align-items: center; gap: 8px; }
.summary .zero { color: var(--muted); opacity: .5; }

.moves-card { padding: 6px; max-height: 340px; overflow: auto; }
.moves { list-style: none; margin: 0; padding: 0; }
.moves li { display: grid; grid-template-columns: 36px 1fr 1fr; align-items: center; border-radius: 6px; }
.moves li:nth-child(odd) { background: var(--surface-2); }
.moves .num { color: var(--muted); font-size: 13px; padding-left: 8px; }
.moves button {
  display: flex; align-items: center; gap: 6px; text-align: left; background: none; border: 0; padding: 4px 8px; border-radius: 5px; cursor: pointer; font-weight: 550; min-height: 30px;
}
.moves button:hover { background: var(--border); }
.moves button.current { background: var(--accent); color: var(--accent-text); }
.mini { width: 16px; height: 16px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 800; flex: none; }

.actions { display: flex; gap: 18px; flex-wrap: wrap; padding: 0 4px; }

.footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 18px 20px 26px; }
.footer p { margin: 2px 0; }
.credits { opacity: .75; }

@media (max-width: 900px) {
  .review { grid-template-columns: 1fr; }
  .board-col { max-width: 600px; margin: 0 auto; width: 100%; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  main { padding: 0 16px 24px; }
  .hero { padding: 24px 0 14px; }
  .load-form { flex-direction: column; align-items: stretch; }
  .source-row select { max-width: none; }
  .evalbar { width: 18px; }
  .player-strip, .controls, .keys { padding-left: 26px; }
  .keys { display: none; }
}
.g-date { display: block; }
@media (max-width: 560px) {
  .games-list button { grid-template-columns: 26px 1fr; row-gap: 2px; }
  .g-meta { grid-column: 2; text-align: left; }
  .g-date { display: inline; }
  .g-date::before { content: " · "; }
}
.copyright { margin-top: 8px !important; font-weight: 600; color: var(--text); opacity: .8; }
.time-wrap { margin-top: 8px; }
.graph-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 0 2px 4px; }
.graph.time-graph { height: 72px; background: var(--surface-2); }
.comment .spent { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: auto; white-space: nowrap; }
.comment .spent + .ev { margin-left: 0; }
.summary .est td { font-size: 17px; font-weight: 700; padding-bottom: 10px; }
.summary .est td:first-child { font-size: 14px; font-weight: 600; color: var(--muted); }
.summary .est .range { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.summary .est .q { cursor: help; border-bottom: 1px dotted var(--muted); }

/* ---------- recent-games statistics ---------- */
.stats-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.stats-bar:empty { display: none; }
.stats-label { font-size: 13px; color: var(--muted); margin-right: 4px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; font-weight: 600; }
.chip:hover { border-color: var(--accent); }
.stats { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface-2); }
.stats-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stats-head .link { text-decoration: none; color: var(--muted); font-size: 15px; }
.stats-progress { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tv { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.tv .w { color: var(--c-best); } .tv .l { color: var(--c-blunder); } .tv .d { color: var(--muted); }
.tl { font-size: 13px; font-weight: 600; }
.ts { font-size: 12px; color: var(--muted); }
.stats-sub { font-size: 12.5px; color: var(--muted); margin: 12px 0 5px; }
.phasebar { display: flex; height: 26px; border-radius: 7px; overflow: hidden; font-size: 12px; font-weight: 600; color: #fff; }
.ph { display: flex; align-items: center; justify-content: center; white-space: nowrap; overflow: hidden; min-width: 0; padding: 0 4px; }
.ph-open { background: var(--c-book); } .ph-mid { background: var(--c-mistake); } .ph-end { background: #6a7bd1; }
.stats-line { font-size: 13px; margin: 10px 0 0; }
.accbars { display: flex; align-items: flex-end; gap: 4px; height: 70px; }
.accbar { flex: 1; border: 0; border-radius: 4px 4px 0 0; cursor: pointer; position: relative; padding: 0; min-width: 0; }
.accbar.res-win { background: var(--c-best); } .accbar.res-loss { background: var(--c-blunder); } .accbar.res-draw { background: var(--c-forced); }
.accbar span { position: absolute; top: 2px; left: 0; right: 0; font-size: 10px; font-weight: 700; color: #fff; }
.accbar:hover { filter: brightness(1.15); }
.bestworst { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; align-items: flex-start; }
.stats-note { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; }
.muted { color: var(--muted); }
@media (max-width: 560px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tv { font-size: 19px; }
}

/* ---------- mistakes trainer ---------- */
.board-svg.clickable { cursor: pointer; }
.sel { fill: rgba(63, 155, 90, .55); }
.hintsq { fill: rgba(80, 140, 230, .55); }
.target-dot { fill: rgba(20, 20, 20, .28); }
.target-ring { fill: none; stroke: rgba(20, 20, 20, .28); stroke-width: 3.5; }
body.training .evalbar > * { visibility: hidden; }
body.training .side-col > .card:not(.trainer-card), body.training .side-col > .actions,
body.training .controls, body.training .keys { display: none; }
.trainer-cta { padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.trainer-cta .t-title { font-weight: 650; margin-right: 4px; }
.trainer-card { padding: 16px; }
.trainer-card .t-step { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.trainer-card h3 { margin: 0 0 6px; font-size: 18px; }
.trainer-card .t-task { margin: 0 0 12px; }
.trainer-card .t-msg { padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; font-weight: 600; }
.t-msg.ok { background: color-mix(in srgb, var(--c-best) 18%, transparent); color: var(--c-best); }
.t-msg.bad { background: color-mix(in srgb, var(--c-blunder) 16%, transparent); color: var(--c-blunder); }
.t-msg.info { background: var(--surface-2); color: var(--text); font-weight: 500; }
.t-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.t-actions button { width: auto; margin: 0; }
.t-actions .primary { padding: 9px 18px; }
.t-tries { display: inline-flex; gap: 4px; }
.t-tries i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); display: inline-block; }
.t-tries i.used { background: var(--c-blunder); }
.t-summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 8px 0 14px; font-size: 15px; }
.t-summary b { text-align: right; font-variant-numeric: tabular-nums; }
.progress-fill.quick { background: var(--c-inaccuracy); }

.var-moves { margin-top: 6px; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.var-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.var-actions .secondary { width: auto; margin: 0; padding: 7px 12px; }
.board-svg { cursor: pointer; }

.op-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.op-col { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.op-title { font-size: 12.5px; font-weight: 700; margin-bottom: 4px; }
.op-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.op-table td { padding: 3px 0; }
.op-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-res { width: 82px; text-align: right; font-variant-numeric: tabular-nums; }
.op-res .w { color: var(--c-best); } .op-res .l { color: var(--c-blunder); } .op-res .d { color: var(--muted); }
.op-acc { width: 30px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .op-grid { grid-template-columns: 1fr; } }
.mini svg, .ico svg { width: 62%; height: 62%; display: block; }

/* ---------- extension dialog ---------- */
.ext-promo { text-align: center; margin: 18px 0 0; }
body.has-game .ext-promo { display: none; }
.ext-dialog { max-width: 460px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: 16px; padding: 18px 22px 20px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.ext-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.ext-dialog h2 { margin: 0 0 8px; font-size: 20px; }
.ext-dialog p { margin: 0 0 12px; color: var(--muted); }
.ext-close-row { display: flex; justify-content: flex-end; margin: -6px -8px 0 0; }
.ext-close-row .link { text-decoration: none; color: var(--muted); font-size: 16px; }
.ext-preview { display: flex; justify-content: center; padding: 16px; margin: 4px 0 14px; border-radius: 12px; background: var(--surface-2); }
.ext-mock { display: inline-flex; align-items: center; gap: 8px; padding: 11px 16px; border-radius: 999px; background: #3f9b5a; color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.ext-download { display: block; text-align: center; text-decoration: none; margin-bottom: 14px; }
.ext-steps { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 6px; }
.ext-note { font-size: 12.5px; }

/* =========================================================
   Navigation & page structure (redesign)
   ========================================================= */
.topbar { gap: 16px; }
.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 12px; }
.nav a, .nav button {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 9px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14.5px; background: none; border: 0; cursor: pointer;
}
.nav a:hover, .nav button:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }
.nav-ico { font-size: 15px; }

.page-title { font-size: clamp(24px, 4vw, 32px); margin: 28px 0 6px; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); margin: 0 0 16px; max-width: 640px; }

/* page 1 */
.smart-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px; max-width: 760px; margin: 8px auto 0; }
.smart-box textarea {
  flex: 1; min-width: 0; resize: none; overflow: auto; padding: 12px 14px; font-size: 16px; line-height: 1.4;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none; max-height: 240px;
}
.smart-box textarea:focus { border-color: var(--accent); }
.smart-box .primary { padding: 12px 22px; font-size: 15.5px; }
.smart-hint { max-width: 760px; margin: 8px auto 0; font-size: 13.5px; color: var(--muted); min-height: 20px; padding: 0 4px; }
.smart-hint.ok { color: var(--c-best); font-weight: 600; }
.smart-hint .link { font-weight: 600; margin-left: 2px; }
#analyze-status { max-width: 760px; margin: 4px auto 0; padding: 0 4px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 760px; margin: 28px auto 0; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
.step b { color: var(--text); font-size: 15px; }
.step-n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; margin-bottom: 4px; }
.games-cta { display: flex; align-items: center; gap: 14px; max-width: 760px; margin: 14px auto 0; padding: 16px 18px; text-decoration: none; color: var(--text); }
.games-cta:hover { border-color: var(--accent); }
.games-cta > span:nth-child(2) { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 14px; flex: 1; }
.games-cta b { color: var(--text); font-size: 15.5px; }
.games-cta-ico { font-size: 26px; }
.games-cta-arrow { font-size: 22px; color: var(--accent); }

/* page 2 */
.games-form { padding: 14px; display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.seg { display: inline-flex; align-self: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: 3px; background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 7px 16px; border-radius: 8px; font-weight: 650; cursor: pointer; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.games-row { display: flex; gap: 8px; }
.games-row input { flex: 1; min-width: 0; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none; font-size: 15px; }
.games-row input:focus { border-color: var(--accent); }
#games-status { margin: 10px 0 0; }
#page-games .games { max-width: 760px; margin-top: 16px; }
.list-title { font-size: 16px; margin: 18px 0 8px; }

/* page 3: review */
.review-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.back-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 14px; font-weight: 650; cursor: pointer; }
.back-btn:hover { border-color: var(--accent); }
.review-title { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-bar .depth { margin-left: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.tool:hover:not(:disabled) { border-color: var(--accent); }
.tool:disabled { opacity: .45; cursor: default; }
#tool-trainer:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.tip { margin: 8px 0 0; padding: 8px 12px 8px 34px; font-size: 13px; color: var(--muted); }
body.has-game main { padding-top: 0; }
.review { margin-top: 10px; }

@media (max-width: 900px) {
  .steps { grid-template-columns: 1fr; }
  .toolbar .tool { flex: 1 1 40%; }
}
@media (max-width: 700px) {
  /* menu becomes a bottom tab bar, like a mobile app */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 50; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .nav a, .nav button { flex-direction: column; gap: 2px; font-size: 11.5px; padding: 6px 10px; }
  .nav a.active { box-shadow: none; color: var(--accent); background: none; }
  .nav-ico { font-size: 19px; }
  body { padding-bottom: 64px; }
  .smart-box { flex-direction: column; align-items: stretch; }
  .smart-box textarea { min-height: 76px; }
  .review-bar .depth span { display: none; }
  .tip { padding-left: 26px; }
}
body.training .toolbar, body.training .tip { display: none; }

/* "My games" centred like the analyze page */
#page-games .page-title, #page-games .page-sub { text-align: center; margin-left: auto; margin-right: auto; }
#page-games .page-title { margin-top: 40px; }
#page-games .page-sub { max-width: 560px; }
#page-games .games-form { max-width: 760px; margin: 8px auto 0; }
#page-games .seg { align-self: center; }
#page-games #games-status { max-width: 760px; margin: 10px auto 0; padding: 0 4px; }
#page-games .games { max-width: 760px; margin: 16px auto 0; }
#page-games .stats-bar { justify-content: center; }

/* explanations, promotion picker, trainer extras */
.comment .why { margin-top: 6px; color: var(--text); font-size: 14px; }
.t-why { margin: 0 0 12px; font-size: 14px; }
.t-source { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.board { position: relative; }
.promo-shade { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); z-index: 5; }
.promo { position: absolute; width: 12.5%; z-index: 6; display: flex; flex-direction: column; background: var(--surface); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.45); overflow: hidden; }
.promo[style*="bottom"] { flex-direction: column-reverse; }
.promo button { border: 0; background: none; padding: 0; aspect-ratio: 1; cursor: pointer; }
.promo button:hover { background: var(--surface-2); }
.promo svg { width: 100%; height: 100%; display: block; }

/* recent reviews */
.history { max-width: 760px; margin: 22px auto 0; }
.history-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; padding: 0 2px; }
.history-head h2 { font-size: 16px; margin: 0; }
.history-head .link { font-size: 13px; color: var(--muted); }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.history-list li { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.history-list li:hover { border-color: var(--accent); }
.h-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.h-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-res { color: var(--muted); font-weight: 600; }
.h-meta { font-size: 12.5px; color: var(--muted); }
.h-del { border: 0; background: none; color: var(--muted); padding: 0 12px; cursor: pointer; font-size: 17px; }
.h-del:hover { color: var(--c-blunder); }
@media (max-width: 700px) { .history-list { grid-template-columns: 1fr; } }

/* trainer across several games */
body.training-standalone .player-strip, body.training-standalone .evalbar, body.training-standalone .review-bar .depth { visibility: hidden; }

/* trainer page */
#page-trainer .page-title, #page-trainer .page-sub { text-align: center; margin-left: auto; margin-right: auto; }
#page-trainer .page-title { margin-top: 40px; }
#page-trainer .page-sub { max-width: 560px; }
.tr-card { max-width: 760px; margin: 16px auto 0; padding: 18px; }
.tr-card h2 { font-size: 18px; margin: 0 0 4px; }
.tr-sub { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.tr-form { display: flex; flex-direction: column; gap: 10px; }
.tr-speeds { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; }
.tr-speeds .stats-label { margin-right: 4px; }
#tr-progress { margin-top: 14px; }
#trainer-status { margin: 10px 0 0; }
.tr-empty { color: var(--muted); font-size: 14px; margin: 0; }
.h-tasks { color: var(--accent); font-weight: 650; }
.h-tasks.none { color: var(--muted); font-weight: 500; }

/* sound toggle */
.icon-btn { border: 1px solid var(--border); background: none; border-radius: 8px; width: 34px; height: 30px; cursor: pointer; font-size: 15px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }

/* learn openings */
#page-learn .page-title, #page-learn .page-sub { text-align: center; margin-left: auto; margin-right: auto; }
#page-learn .page-title { margin-top: 40px; }
#page-learn .page-sub { max-width: 560px; }
.learn-filter-row { display: flex; justify-content: center; margin: 4px 0 18px; }
.learn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; max-width: 1000px; margin: 0 auto; }
.learn-item { text-align: left; padding: 14px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; color: var(--text); font: inherit; }
.learn-item:hover { border-color: var(--accent); }
.learn-item-head { display: flex; gap: 10px; align-items: center; }
.learn-item-head > span { display: flex; flex-direction: column; }
.learn-item-head b { font-size: 16px; }
.learn-piece { width: 38px; height: 38px; flex: none; background: var(--surface-2); border-radius: 9px; }
.learn-side-label { font-size: 12.5px; color: var(--muted); }
.learn-item-idea { font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.learn-item-progress { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); margin-top: auto; }
.lp-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.lp-bar span { display: block; height: 100%; background: var(--accent); }
.learn-bar { max-width: 1100px; }
.learn-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; margin-top: 12px; align-items: start; }
.learn-board-col { min-width: 0; }
.learn-board { width: 100%; flex: none; }
.learn-board-col .controls { padding-left: 0; margin-top: 10px; }
.learn-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.learn-idea { margin: 0; color: var(--muted); }
.learn-lines { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.learn-mode { align-self: flex-start; }
#learn-msg { margin: 0; }
.learn-moves { max-height: 260px; overflow: auto; }
.learn-moves button[disabled] { color: var(--muted); cursor: default; }
@media (max-width: 900px) { .learn-layout { grid-template-columns: 1fr; } .learn-board-col { max-width: 560px; margin: 0 auto; width: 100%; } }
@media (max-width: 700px) { .nav a, .nav button { padding: 6px 4px; font-size: 10.5px; } }

.credits a { color: inherit; }

/* free analysis board */
#page-free .page-title, #page-free .page-sub { text-align: center; margin-left: auto; margin-right: auto; }
#page-free .page-title { margin-top: 32px; }
#page-free .page-sub { max-width: 560px; }
.free-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; margin-top: 14px; align-items: start; }
.free-board-col { min-width: 0; }
.free-controls { padding-left: 34px; }
.free-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.free-status { margin: 0; font-weight: 600; }
.free-lines { display: flex; flex-direction: column; gap: 6px; }
.free-line { display: flex; gap: 10px; align-items: baseline; text-align: left; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; cursor: pointer; color: var(--text); font: inherit; }
.free-line:hover { border-color: var(--accent); }
.free-line .ev { background: var(--surface); border-radius: 6px; padding: 1px 8px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; min-width: 52px; text-align: center; }
.free-pv { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.free-moves { max-height: 220px; overflow: auto; }
.free-empty { color: var(--muted); font-size: 14px; padding: 8px; display: block !important; }
.free-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.free-load { display: flex; gap: 8px; }
.free-load input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none; }
.free-load input:focus { border-color: var(--accent); }
.free-load .secondary { width: auto; margin: 0; }
.free-load-msg { margin: 0; color: var(--c-blunder); font-size: 13px; }
.free-load-msg:empty { display: none; }
@media (max-width: 900px) { .free-layout { grid-template-columns: minmax(0, 1fr); } .free-board-col { max-width: 600px; margin: 0 auto; width: 100%; } }
@media (max-width: 700px) { .nav .ext-open { display: none; } .free-controls { padding-left: 26px; } }
.free-card, .free-line { min-width: 0; }
.free-pv { flex: 1; min-width: 0; }

.free-comment { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; }
.free-comment .mini { width: 20px; height: 20px; font-size: 10px; }
.free-moves .mv { display: inline-flex; align-items: center; gap: 6px; }
/* drag and drop on the board */
.board-svg.clickable { touch-action: none; cursor: grab; }
.board-svg.clickable:active { cursor: grabbing; }
.drag-piece { pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .45)); }

/* own variation in the review: move marks */
.var-mv { display: inline-flex; align-items: center; gap: 4px; margin-right: 4px; }
.var-rating { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 15px; }
