:root {
  color-scheme: dark;
  --bg: #161512;
  --bg-2: #1d1b18;
  --panel: #262421;
  --panel-2: #2f2c28;
  --panel-3: #3a3733;
  --border: #3d3a35;
  --text: #ebe9e5;
  --muted: #9e9890;
  --accent: #81b64c;
  --accent-2: #a3d160;
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --hl: rgba(255, 220, 60, .45);
  --radius: 10px;
  --c-brilliant: #26c2a3;
  --c-great: #749bbf;
  --c-best: #81b64c;
  --c-excellent: #96bc4b;
  --c-good: #97af8b;
  --c-inaccuracy: #f7c631;
  --c-mistake: #ffa459;
  --c-blunder: #fa412d;
  --c-forced: #97a0a8;
  --c-book: #a88865;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 10px 20px; background: var(--bg-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 19px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); font-weight: 700; }
.brand-ico { width: 30px; height: 30px; display: inline-block; }
.top-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { border: 1px solid var(--border); background: var(--panel); color: var(--muted); border-radius: 8px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; flex: none; transition: color .15s, background .15s; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.home-links { display: flex; align-items: center; justify-content: center; gap: 10px 14px; flex-wrap: wrap; margin-top: 4px; }
.pill-btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px; }
.pill-btn:hover { background: var(--panel-2); }
.top-search { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: min(320px, 50vw); }
.top-search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 12px; outline: none; }
.top-search button { border: 0; background: transparent; padding: 8px 12px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.top-search button:hover { color: var(--text); }
body.home .top-search { visibility: hidden; }

main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 20px 40px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px;
  padding: 10px 18px; cursor: pointer; font-weight: 600; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 3px 0 #5d8a32; }
.btn-primary:hover { background: #8fc45a; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--text); }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 40px 0 20px; max-width: 720px; margin: 0 auto; position: relative; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); line-height: 1.12; margin: 0 0 14px; letter-spacing: -.02em; }
.accent { color: var(--accent); }
.lead { color: var(--muted); font-size: 17px; margin: 0 auto 28px; max-width: 600px; }
.hero-board {
  width: 88px; height: 88px; margin: 0 auto 22px; border-radius: 14px; overflow: hidden;
  background: conic-gradient(var(--sq-dark) 90deg, var(--sq-light) 90deg 180deg, var(--sq-dark) 180deg 270deg, var(--sq-light) 270deg) 0 0 / 50% 50%;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  position: relative;
}
.hero-board i { position: absolute; inset: 8px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.35)); }
.big-search { display: flex; gap: 10px; max-width: 560px; margin: 0 auto; }
.big-search input {
  flex: 1; min-width: 0; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); font-size: 17px; outline: none; transition: border-color .15s;
}
.big-search input:focus, .pgn-form textarea:focus { border-color: var(--accent); }
.big-search .btn { font-size: 16px; padding: 12px 22px; }
.recent { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 6px; min-height: 8px; }
.recent a { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; color: var(--text); font-size: 13px; }
.recent a:hover { background: var(--panel-2); text-decoration: none; }
.pgn-form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; margin: 10px auto 0; }
.pgn-form textarea { width: 100%; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); padding: 12px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; resize: vertical; outline: none; }
.pgn-form .btn { align-self: center; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 48px auto 0; max-width: 900px; }
.feature { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.feature h3 { margin: 10px 0 4px; font-size: 16px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }
.fi { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 16px; }

/* ---------- Profile / games ---------- */
.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.profile img, .avatar-ph { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--panel-2); flex: none; }
.avatar-ph { display: grid; place-items: center; font-size: 26px; font-weight: 700; color: var(--muted); }
.profile h2 { margin: 0; font-size: 24px; line-height: 1.2; }
.profile .ratings { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; margin-top: 4px; }
.profile .ratings b { color: var(--text); }
.games-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--panel-3); color: var(--text); }
.games-list { display: flex; flex-direction: column; gap: 6px; }
.game-row {
  display: grid; grid-template-columns: 6px 64px minmax(0, 1fr) auto auto 18px; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px 10px 0;
  cursor: pointer; color: var(--text); transition: background .12s, border-color .12s; overflow: hidden;
}
.game-row:hover { background: var(--panel-2); border-color: #4a463f; text-decoration: none; }
.game-row .res-bar { align-self: stretch; margin: -10px 0; }
.res-win .res-bar { background: var(--accent); }
.res-loss .res-bar { background: var(--c-blunder); }
.res-draw .res-bar { background: var(--muted); }
.game-row .tc { display: flex; flex-direction: column; align-items: center; color: var(--muted); font-size: 12px; line-height: 1.2; text-align: center; }
.game-row .tc svg { width: 20px; height: 20px; margin-bottom: 2px; }
.game-row .players { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.game-row .pl { display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-row .pl .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; border: 1px solid #000; }
.game-row .pl .dot.w { background: #f2f2f2; }
.game-row .pl .dot.b { background: #333; border-color: #666; }
.game-row .pl.me { font-weight: 700; }
.game-row .pl small { color: var(--muted); font-weight: 400; }
.game-row .acc { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--muted); line-height: 1.35; min-width: 52px; }
.game-row .acc b { color: var(--text); font-size: 13px; }
.game-row .meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--muted); white-space: nowrap; }
.game-row .meta .result { font-weight: 700; font-size: 14px; }
.res-win .result { color: var(--accent); }
.res-loss .result { color: var(--c-blunder); }
.res-draw .result { color: var(--muted); }
.game-row .go { color: var(--muted); }
.games-more { display: flex; justify-content: center; margin-top: 16px; }

/* ---------- State / loading ---------- */
.state { text-align: center; padding: 60px 20px; color: var(--muted); }
.state h2 { color: var(--text); margin: 0 0 8px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--panel-3); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Analysis layout ---------- */
.view-analysis:not([hidden]) {
  display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 22px; align-items: start;
}
.board-col { --bsize: min(calc(100vh - 230px), 100%); display: flex; flex-direction: column; align-items: stretch; max-width: calc(min(100vh - 230px, 720px) + 34px); width: 100%; margin: 0 auto; }
.board-wrap { display: flex; gap: 8px; }
.side-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 14px; margin-bottom: 8px; }

/* Player bars */
.player-bar { display: flex; align-items: center; gap: 10px; padding: 8px 0 8px 34px; min-height: 52px; }
.player-bar img, .player-bar .avatar-ph { width: 36px; height: 36px; border-radius: 6px; font-size: 16px; }
.player-bar .pname { font-weight: 700; display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.player-bar .pname span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar .pname small { color: var(--muted); font-weight: 400; }
.player-bar .mat { font-size: 12px; color: var(--muted); height: 16px; display: flex; align-items: center; gap: 1px; }
.player-bar .mat i { width: 16px; height: 16px; margin-right: -4px; display: inline-block; }
.player-bar .mat b { margin-left: 6px; font-weight: 600; }
.player-bar .pinfo { min-width: 0; flex: 1; }
.clock { margin-left: auto; background: var(--panel-2); border-radius: 6px; padding: 4px 10px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; color: var(--muted); min-width: 80px; text-align: right; }
.clock.active { background: #e7e6e3; color: #161512; }

/* Board */
.board {
  position: relative; flex: 1; aspect-ratio: 1 / 1; border-radius: 4px; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
.board .squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq { position: relative; }
.sq.l { background: var(--sq-light); }
.sq.d { background: var(--sq-dark); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(20, 85, 30, .5); }
.sq.check::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(255,0,0,.85) 0%, rgba(231,0,0,.5) 35%, rgba(169,0,0,0) 72%); }
.sq .coord { position: absolute; font-size: clamp(9px, 1.5vw, 13px); font-weight: 700; line-height: 1; pointer-events: none; z-index: 1; }
.sq .coord.rank { top: 3px; left: 3px; }
.sq .coord.file { bottom: 2px; right: 4px; }
.sq.l .coord { color: var(--sq-dark); }
.sq.d .coord { color: var(--sq-light); }
.sq.dest::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(0,0,0,.18); }
.sq.dest.cap::after { width: 86%; height: 86%; background: transparent; border: 6px solid rgba(0,0,0,.18); box-sizing: border-box; }
.board .pieces { position: absolute; inset: 0; pointer-events: none; }
.piece { position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; will-change: transform; }
.piece.anim { transition: transform var(--anim-ms, 180ms) ease-out; }
[data-p] { background: no-repeat center / contain; }
[data-p="wk"] { background-image: var(--p-wk); } [data-p="wq"] { background-image: var(--p-wq); }
[data-p="wr"] { background-image: var(--p-wr); } [data-p="wb"] { background-image: var(--p-wb); }
[data-p="wn"] { background-image: var(--p-wn); } [data-p="wp"] { background-image: var(--p-wp); }
[data-p="bk"] { background-image: var(--p-bk); } [data-p="bq"] { background-image: var(--p-bq); }
[data-p="br"] { background-image: var(--p-br); } [data-p="bb"] { background-image: var(--p-bb); }
[data-p="bn"] { background-image: var(--p-bn); } [data-p="bp"] { background-image: var(--p-bp); }
body.no-coords .sq .coord { display: none; }
body.no-hl .sq.hl::before { display: none; }
body.no-evalbar .evalbar { display: none; }
body.no-evalbar .player-bar, body.no-evalbar .controls { padding-left: 0; }
.board .arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.badge {
  position: absolute; width: 4.6%; height: 4.6%; min-width: 18px; min-height: 18px; border-radius: 50%; z-index: 4;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: clamp(9px, 1.25vw, 13px); line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.55); transform: translate(-55%, -45%); pointer-events: none; letter-spacing: -.04em;
}

/* Eval bar */
.evalbar { position: relative; width: 26px; flex: none; border-radius: 4px; overflow: hidden; background: #403d39; }
.evalbar-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #f2f1ee; transition: height .35s ease; }
.evalbar.flipped .evalbar-fill { bottom: auto; top: 0; }
.evalbar-txt { position: absolute; left: 0; right: 0; font-size: 10px; font-weight: 800; text-align: center; z-index: 1; bottom: 4px; color: #403d39; letter-spacing: -.03em; }
.evalbar-txt.top { bottom: auto; top: 4px; color: #f2f1ee; }

/* Controls */
.controls { display: flex; gap: 6px; padding-left: 34px; margin-top: 4px; }
.ctl { flex: 1; height: 44px; border: 0; border-radius: 8px; background: var(--panel-2); color: var(--text); cursor: pointer; display: grid; place-items: center; transition: background .12s; }
.ctl:hover { background: var(--panel-3); }
.ctl svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ctl[data-act="flip"] svg { fill: none; }
.ctl[data-act="first"] svg, .ctl[data-act="last"] svg { stroke-width: 2.4; }

/* Side panels */
.game-head { display: flex; flex-direction: column; gap: 4px; }
.game-head .gh-title { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.game-head .gh-sub { color: var(--muted); font-size: 13px; }
.game-head .gh-sub a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.game-head .back { font-size: 13px; color: var(--muted); }
.gh-acc { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.gh-acc b { padding: 2px 10px; border-radius: 6px; font-size: 15px; font-variant-numeric: tabular-nums; }
.gh-acc b.w { background: #f2f1ee; color: #161512; }
.gh-acc b.b { background: #121110; color: #f2f1ee; border: 1px solid var(--border); }
.progress-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.progress { height: 8px; background: var(--panel-3); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .25s; }

.move-explain { display: flex; gap: 12px; align-items: flex-start; min-height: 66px; }
.move-explain .ic { width: 34px; height: 34px; font-size: 15px; flex: none; }
.move-explain .txt { min-width: 0; }
.move-explain .head { font-weight: 700; font-size: 15px; }
.move-explain .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.move-explain .sub b { color: var(--text); }
.move-explain .ev { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; background: var(--panel-2); padding: 3px 8px; border-radius: 6px; font-size: 13px; flex: none; }
.move-explain .ev.w { background: #f2f1ee; color: #161512; }
.move-explain .ev.b { background: #111; color: #f2f1ee; }

.engine-lines { display: flex; flex-direction: column; gap: 4px; min-height: 30px; }
.eline { display: flex; gap: 8px; align-items: baseline; font-size: 13px; cursor: pointer; padding: 3px 4px; border-radius: 5px; }
.eline:hover { background: var(--panel-2); }
.eline .sc { flex: none; min-width: 50px; text-align: center; font-weight: 800; border-radius: 4px; padding: 1px 4px; font-variant-numeric: tabular-nums; }
.eline .sc.w { background: #f2f1ee; color: #161512; }
.eline .sc.b { background: #111; color: #f2f1ee; }
.eline .pv { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eline .pv b { color: var(--text); font-weight: 600; }

.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--panel-3); border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.graph-panel { padding: 0; overflow: hidden; }
.graph { display: block; width: 100%; height: 110px; cursor: pointer; background: #403d39; }

.moves-panel { padding: 0; overflow: hidden; }
.moves { max-height: 320px; overflow-y: auto; font-size: 14px; scrollbar-width: thin; }
.mrow { display: grid; grid-template-columns: 44px 1fr 1fr; }
.mrow:nth-child(even) { background: rgba(255,255,255,.025); }
.mno { color: var(--muted); padding: 5px 0 5px 12px; font-variant-numeric: tabular-nums; }
.mv { display: flex; align-items: center; gap: 6px; padding: 5px 8px; cursor: pointer; border-radius: 4px; margin: 1px 2px; white-space: nowrap; }
.mv:hover { background: var(--panel-3); }
.mv.cur { background: #4b4740; font-weight: 700; }
.mv .ic { width: 17px; height: 17px; font-size: 9px; }
.mv .clk { margin-left: auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 400; }
.variation-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: #3b3527; border-bottom: 1px solid var(--border); font-size: 13px; color: #f0d58a; }
.var-moves { padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 4px 2px; font-size: 14px; border-bottom: 1px solid var(--border); }
.var-moves .mv { padding: 2px 6px; margin: 0; }

.ic { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 800; flex: none; line-height: 1; letter-spacing: -.04em; }
.c-brilliant { background: var(--c-brilliant); }
.c-great { background: var(--c-great); }
.c-best { background: var(--c-best); }
.c-excellent { background: var(--c-excellent); }
.c-good { background: var(--c-good); }
.c-inaccuracy { background: var(--c-inaccuracy); }
.c-mistake { background: var(--c-mistake); }
.c-blunder { background: var(--c-blunder); }
.c-forced { background: var(--c-forced); }
.c-book { background: var(--c-book); }
.t-brilliant { color: var(--c-brilliant); }
.t-great { color: var(--c-great); }
.t-best { color: var(--c-best); }
.t-excellent { color: var(--c-excellent); }
.t-good { color: var(--c-good); }
.t-inaccuracy { color: var(--c-inaccuracy); }
.t-mistake { color: var(--c-mistake); }
.t-blunder { color: var(--c-blunder); }
.t-forced { color: var(--c-forced); }
.t-book { color: var(--c-book); }

/* Summary */
.summary h3 { margin: 0 0 12px; font-size: 15px; }
.acc-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.acc-card { border-radius: 9px; padding: 10px 12px; text-align: center; }
.acc-card.w { background: #f2f1ee; color: #161512; }
.acc-card.b { background: #121110; color: #f2f1ee; border: 1px solid var(--border); }
.acc-card .nm { font-size: 12px; font-weight: 600; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-card .val { font-size: 30px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.acc-card .lbl { font-size: 11px; opacity: .65; }
.cls-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cls-table td { padding: 4px 2px; }
.cls-table td:first-child, .cls-table td:last-child { width: 44px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.cls-table .lab { display: flex; align-items: center; gap: 8px; justify-content: center; font-weight: 600; }
.cls-table .ic { width: 20px; height: 20px; font-size: 10px; }
.cls-table tr.zero td:first-child, .cls-table tr.zero td:last-child { color: var(--muted); font-weight: 400; }

.settings { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.settings select { background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; flex: 1; min-width: 150px; }

/* Settings dialog */
.settings-dlg { padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text); width: min(940px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.settings-dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg-inner { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 19px; }
.dlg-body { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 22px; padding: 18px; overflow-y: auto; }
.dlg-preview { position: sticky; top: 0; align-self: start; }
.dlg-preview .board { width: 100%; flex: none; }
.dlg-controls h3 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dlg-controls h3:not(:first-child) { margin-top: 20px; }
.pset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.pset, .btheme { border: 2px solid transparent; background: var(--panel-2); border-radius: 10px; padding: 8px 4px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); transition: border-color .12s, background .12s; }
.pset:hover, .btheme:hover { background: var(--panel-3); }
.pset.on, .btheme.on { border-color: var(--accent); background: #34402a; }
.pset-img { display: flex; height: 40px; }
.pset-img i { width: 38px; height: 40px; background: no-repeat center / contain; display: block; }
.pset-img i + i { margin-left: -10px; }
.pset-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.btheme-sw { width: 44px; height: 44px; border-radius: 6px; overflow: hidden; background: conic-gradient(var(--d) 90deg, var(--l) 90deg 180deg, var(--d) 180deg 270deg, var(--l) 270deg) 0 0 / 50% 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.credit { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.opt-list { display: flex; flex-direction: column; background: var(--panel-2); border-radius: 10px; overflow: hidden; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; font-size: 14px; cursor: pointer; }
.opt + .opt { border-top: 1px solid var(--border); }
.opt select { background: var(--panel); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; min-width: 150px; }
.opt-r { display: flex; align-items: center; gap: 8px; }
.opt-link { color: var(--accent-2); font-weight: 600; }
.opt-link:hover { text-decoration: none; background: var(--panel-3); }

/* Sound comparison page */
.klang-wrap { max-width: 900px; margin: 0 auto; }
.klang-wrap h1 { font-size: clamp(26px, 4vw, 34px); margin: 6px 0 6px; letter-spacing: -.02em; }
.klang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 20px; }
.klang { background: var(--panel); border: 2px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.klang.on { border-color: var(--accent); background: #2b3324; }
.klang h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.klang h3 .tag { font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 99px; padding: 2px 8px; }
.klang p { margin: 0; color: var(--muted); font-size: 13px; min-height: 36px; }
.klang-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.klang-btns button { border: 1px solid var(--border); background: var(--panel-2); border-radius: 7px; padding: 6px 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
.klang-btns button:hover { background: var(--panel-3); }
.klang .use { margin-top: auto; }
.icon-btn-sm { width: 30px; height: 30px; border-radius: 7px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }

/* Footer */
.footer { text-align: center; padding: 24px 20px 30px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }
.footer p { margin: 2px 0; }
.footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-3); border: 1px solid var(--border); padding: 10px 16px; border-radius: 9px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .view-analysis:not([hidden]) { grid-template-columns: 1fr; }
  .board-col { max-width: 640px; }
  .side-col { max-width: 640px; margin: 0 auto; width: 100%; }
  .moves { max-height: 260px; }
}
@media (max-width: 760px) {
  .dlg-body { grid-template-columns: 1fr; gap: 16px; padding: 14px; }
  .dlg-preview { position: static; max-width: 260px; width: 100%; margin: 0 auto; }
}
@media (max-width: 720px) {
  .features { grid-template-columns: 1fr; }
  .game-row { grid-template-columns: 5px 46px minmax(0, 1fr) auto; gap: 10px; }
  .game-row .acc, .game-row .go { display: none; }
}
@media (max-width: 560px) {
  main { padding: 14px 12px 30px; }
  .topbar { padding: 8px 12px; }
  .brand span { display: none; }
  .top-search { width: auto; flex: 1; max-width: 260px; }
  .big-search { flex-direction: column; }
  .hero { padding-top: 16px; }
  .board-wrap { gap: 5px; }
  .evalbar { width: 18px; }
  .evalbar-txt { font-size: 8px; }
  .player-bar, .controls { padding-left: 23px; }
  .player-bar { min-height: 44px; padding-top: 5px; padding-bottom: 5px; }
  .clock { font-size: 15px; min-width: 66px; }
  .profile img, .profile .avatar-ph { width: 52px; height: 52px; }
  .profile { flex-wrap: wrap; }
  .profile .btn { order: 3; width: 100%; text-align: center; }
}
