:root {
  --bg: #12161c;
  --panel: #1a2029;
  --panel-2: #212936;
  --line: #2c3645;
  --text: #e8ecf2;
  --muted: #93a0b4;
  --accent: #3ec9a7;
  --accent-ink: #06201a;
  --danger: #ef6b6b;
  --warn: #f0b429;
  --radius: 10px;
  --bs: 100%;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--danger); min-height: 1.2em; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #2a3445; border-color: #3a4659; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: #5ad8b9; border-color: #5ad8b9; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 7px 11px; min-width: 40px; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:focus-visible, .mv:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .moves:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 22px; max-width: 1320px; margin: 0 auto; padding: 18px 16px 40px; align-items: start; }
.board-col { width: min(100%, calc(100vh - 215px)); min-width: 300px; margin: 0 auto; }
.board-wrap { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; align-items: stretch; margin: 6px 0; }
.board-box { position: relative; aspect-ratio: 1 / 1; }

/* ---------- players ---------- */
.player { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 4px 4px 4px 36px; min-height: 40px; }
.pl-name { font-weight: 650; }
.pl-think { color: var(--accent); margin-left: 8px; font-size: 13px; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
.pl-cap { display: flex; align-items: center; min-height: 22px; font-size: 12px; color: var(--muted); }
.pl-cap img { width: 17px; height: 17px; margin-right: -7px; }
.pl-cap .adv { margin-left: 12px; font-weight: 650; }
.clock { font: 600 20px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 88px; text-align: right; }
.clock.active { background: #e8ecf2; color: #12161c; border-color: #e8ecf2; }
.clock.low { color: var(--danger); }
.clock.active.low { background: var(--danger); color: #fff; border-color: var(--danger); }
.player.turn .pl-name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 8px; }

/* ---------- eval bar ---------- */
.evalbar { position: relative; background: #14171d; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.ev-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #eceff4; transition: height .25s ease; }
.evalbar.flipped .ev-fill { bottom: auto; top: 0; }
.ev-label { position: absolute; left: 0; right: 0; text-align: center; font: 700 10px/1 ui-monospace, Menlo, Consolas, monospace; padding: 4px 0; white-space: nowrap; }
.ev-label.white-side { color: #12161c; bottom: 0; }
.ev-label.black-side { color: #e8ecf2; top: 0; }
.evalbar.flipped .ev-label.white-side { bottom: auto; top: 0; }
.evalbar.flipped .ev-label.black-side { top: auto; bottom: 0; }

/* ---------- board ---------- */
.board { --light: #eeeed2; --dark: #769656; --last: rgba(246, 246, 105, .55); --sel: rgba(246, 246, 105, .7);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 6px; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
.board[data-theme="forest"] { --light: #eeeed2; --dark: #769656; }
.board[data-theme="walnut"] { --light: #f0d9b5; --dark: #b58863; }
.board[data-theme="ocean"] { --light: #dee3e6; --dark: #6d8aa3; }
.board[data-theme="slate"] { --light: #d4d6da; --dark: #7b8290; }
.board[data-theme="rose"] { --light: #f3e1e1; --dark: #c47f8e; }
.sq { position: relative; background: var(--light); display: flex; align-items: center; justify-content: center; }
.sq.d { background: var(--dark); }
.sq.last::before, .sq.sel::before { content: ""; position: absolute; inset: 0; background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.check { background: radial-gradient(circle, rgba(255, 60, 60, .95) 0%, rgba(255, 60, 60, .6) 40%, transparent 72%), var(--light); }
.sq.d.check { background: radial-gradient(circle, rgba(255, 60, 60, .95) 0%, rgba(255, 60, 60, .6) 40%, transparent 72%), var(--dark); }
.sq.hover::after { content: ""; position: absolute; inset: 2px; border: 4px solid rgba(255, 255, 255, .6); border-radius: 4px; }
.sq .pc { position: relative; width: 100%; height: 100%; z-index: 2; pointer-events: none; -webkit-user-drag: none; }
.sq i { position: absolute; z-index: 3; pointer-events: none; }
.sq i.dot { width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 30, 20, .28); }
.sq i.cap { inset: 0; border-radius: 50%; background: radial-gradient(circle, transparent 58%, rgba(20, 30, 20, .28) 60%); }
.sq .co { position: absolute; font: 700 clamp(9px, 1.6vmin, 13px)/1 system-ui, sans-serif; pointer-events: none; z-index: 1; }
.sq .co.rk { top: 3px; left: 4px; }
.sq .co.fl { bottom: 3px; right: 4px; }
.sq.l .co { color: var(--dark); }
.sq.d .co { color: var(--light); }
.ghost { position: fixed; z-index: 1000; pointer-events: none; transform: translate(-50%, -50%); filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .45)); }
.sq.dragging .pc { opacity: .3; }

.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }

.promo { position: absolute; z-index: 10; width: 12.5%; height: 50%; background: #f2f2f2; border-radius: 6px; box-shadow: 0 8px 30px rgba(0, 0, 0, .6); display: flex; flex-direction: column; }
.promo.up { flex-direction: column-reverse; }
.promo button { flex: 1 1 0; border: 0; background: transparent; padding: 0; cursor: pointer; border-radius: 50%; }
.promo button:hover { background: rgba(62, 201, 167, .45); }
.promo img { width: 100%; height: 100%; }
.promo-shade { position: absolute; inset: 0; z-index: 9; background: rgba(0, 0, 0, .35); }

.board-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; padding-left: 36px; }
.board-controls .sep { flex: 1; }

/* ---------- side ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.opening { font-weight: 650; }
.status { margin-top: 4px; color: var(--muted); min-height: 1.3em; }
.status.over { color: var(--text); font-weight: 650; font-size: 16px; }
.status .tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; margin-right: 6px; }
.tag.blunder { background: #ef6b6b33; color: #ff9a9a; } .tag.mistake { background: #f08a3a33; color: #ffb277; } .tag.inaccuracy { background: #f0b42933; color: #f6cd63; }
.status-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.status-actions:empty { display: none; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .slider { width: 36px; height: 20px; border-radius: 999px; background: #3a4659; position: relative; transition: background .15s; flex: none; }
.switch .slider::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
select, input[type=text], input[type=number], textarea { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; }

.engine-stat { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.eline { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; border-top: 1px solid var(--line); }
.eline:first-child { border-top: 0; }
.ev { flex: none; min-width: 54px; text-align: center; font: 700 13px/1.6 ui-monospace, Menlo, Consolas, monospace; border-radius: 6px; padding: 0 6px; background: #e8ecf2; color: #12161c; }
.ev.neg { background: #2b323d; color: #e8ecf2; }
.pv { font-size: 13.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pv .n { color: var(--muted); margin-right: 2px; }
.pv a { cursor: pointer; margin-right: 5px; border-radius: 3px; }
.pv a:hover { background: var(--panel-2); color: var(--accent); }

.moves-card { display: flex; flex-direction: column; }
.moves { max-height: 300px; min-height: 120px; overflow: auto; line-height: 1.9; padding: 2px; border-radius: 6px; }
.moves .mn { color: var(--muted); margin: 0 3px 0 6px; font-size: 13px; }
.mv { display: inline-block; padding: 0 6px; border-radius: 5px; cursor: pointer; font-weight: 550; }
.mv:hover { background: var(--panel-2); }
.mv.cur { background: var(--accent); color: var(--accent-ink); }
.mv .g { font-weight: 800; margin-left: 2px; }
.mv.blunder .g { color: #ff6f6f; } .mv.mistake .g { color: #ff9f55; } .mv.inaccuracy .g { color: #f2c744; }
.mv.cur .g { color: inherit; }
.var { margin: 2px 0 2px 10px; padding-left: 10px; border-left: 2px solid var(--line); color: #c0c9d6; font-size: 14px; line-height: 1.7; }
.move-actions { display: flex; gap: 8px; margin-top: 8px; }

.review-out .accs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; text-align: center; margin: 6px 0 10px; align-items: center; }
.acc { font-size: 24px; font-weight: 750; }
.acc small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.review-out table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.review-out td { padding: 2px 4px; } .review-out td:nth-child(2) { text-align: center; color: var(--muted); } .review-out td:nth-child(1) { text-align: right; width: 22%; } .review-out td:nth-child(3) { width: 22%; }
.graph { width: 100%; height: 86px; display: block; border-radius: 6px; background: #14171d; cursor: pointer; }
.progress { position: relative; height: 22px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: #2b6f5f; transition: width .2s; }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #e8ecf2; color: #12161c; padding: 9px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); z-index: 100; font-weight: 550; max-width: 90vw; }

/* ---------- dialogs ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
dialog::backdrop { background: rgba(5, 8, 12, .65); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; padding: 8px 12px; }
dialog legend { color: var(--muted); font-size: 12.5px; padding: 0 6px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }
dialog textarea { width: 100%; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; resize: vertical; }
dialog textarea.drop { outline: 2px dashed var(--accent); }
.row { display: flex; gap: 12px; align-items: flex-end; margin: 10px 0; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row label.choice { flex-direction: row; align-items: center; color: var(--text); }
.grow { flex: 1; min-width: 0; }
.grow input[type=text], .grow select { width: 100%; }
.choice { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.btn.file { display: inline-block; }
.setup { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 12px; }
.small-board { aspect-ratio: 1 / 1; height: auto; }
.palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; align-content: start; }
.palette button { background: var(--panel-2); border: 2px solid transparent; border-radius: 8px; padding: 2px; cursor: pointer; aspect-ratio: 1; }
.palette button.on { border-color: var(--accent); }
.palette img { width: 100%; height: 100%; }
.palette .erase { grid-column: span 2; aspect-ratio: auto; padding: 6px; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 10px 10px 40px; }
  .board-col { width: 100%; max-width: 680px; }
  .side { max-width: 680px; margin: 0 auto; width: 100%; }
  .moves { max-height: 200px; }
}
@media (max-width: 520px) {
  .top { padding: 8px 10px; }
  .btn { padding: 6px 9px; }
  .board-wrap { grid-template-columns: 14px minmax(0, 1fr); gap: 6px; }
  .player { padding-left: 20px; }
  .board-controls { padding-left: 20px; }
  .clock { font-size: 17px; min-width: 74px; }
  .ev-label { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
