: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-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; }
.url-row { display: flex; gap: 8px; }
.url-row input, .pgn-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;
}
.url-row input:focus, .pgn-form textarea:focus, select:focus { border-color: var(--accent); }
.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; }
.pgn-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.pgn-form textarea { font: 13px/1.45 ui-monospace, Consolas, monospace; resize: vertical; }
.pgn-form .primary { align-self: flex-end; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.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-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; }
  .url-row { flex-direction: column; }
  .evalbar { width: 18px; }
  .player-strip, .controls, .keys { padding-left: 26px; }
  .keys { display: none; }
}
