:root {
  --bg: #312e2b;
  --panel: #262522;
  --card: #3c3a37;
  --card-hover: #454340;
  --line: #1d1c1a;
  --text: #e2e0de;
  --muted: #9e9c9a;
  --green: #81b64c;
  --green-dark: #45753c;
  --green-shadow: #5d8a36;
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --brilliant: #26c2a3;
  --great: #749bbf;
  --best: #81b64c;
  --excellent: #96bc4b;
  --good: #95af8a;
  --book: #a88865;
  --inaccuracy: #f7c045;
  --mistake: #ffa459;
  --miss: #ff7769;
  --blunder: #fa412d;
  --board-size: max(420px, min(calc(100vh - 185px), calc(100vw - 530px), 900px));
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}
header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 7px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.logo { font-size: 20px; font-weight: 800; white-space: nowrap; letter-spacing: -.2px; }
.logo em { font-size: 11px; color: var(--green); font-style: normal; margin-left: 4px; font-weight: 600; }
.fetch-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; }
.engine-bar { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
.engine-status.ready { color: var(--green); }
.engine-status.err { color: var(--blunder); }

input, select {
  background: #211f1c; color: var(--text);
  border: 1px solid #46433f; border-radius: 6px;
  padding: 8px 10px; font-size: 14px;
}
input:focus, select:focus { outline: 1px solid var(--green); }
input#username { width: 180px; }
button {
  background: var(--card); color: var(--text);
  border: none; border-radius: 6px;
  padding: 8px 12px; font-size: 14px; cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25);
}
button:hover { background: var(--card-hover); }
button:active { box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); transform: translateY(1px); }
.cc-btn {
  background: var(--green); color: #fff; font-weight: 700;
  box-shadow: inset 0 -4px 0 var(--green-dark);
  padding: 9px 16px; border-radius: 8px;
}
.cc-btn:hover { background: #8fc75b; }
.cc-btn:active { box-shadow: inset 0 -1px 0 var(--green-dark); }
.cc-btn:disabled { opacity: .5; cursor: default; }
.cc-btn.big { width: 100%; padding: 14px; font-size: 17px; }

main {
  display: flex; gap: 22px; padding: 10px 16px 16px;
  justify-content: center; align-items: flex-start; flex-wrap: wrap;
}

/* ---------- board ---------- */
.board-area { display: flex; flex-direction: column; gap: 5px; }
.player-row { display: flex; gap: 8px; align-items: center; padding: 1px 0 1px 32px; }
.player-row .avatar {
  width: 26px; height: 26px; border-radius: 5px; background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: var(--muted);
}
.player-row .pname { font-weight: 700; font-size: 14px; }
.player-row .prating { color: var(--muted); font-size: 12px; }
.board-wrap { display: flex; gap: 8px; }
.eval-bar {
  width: 24px; border-radius: 3px; overflow: hidden; position: relative;
  background: #403d3a; height: var(--board-size);
}
.eval-bar-white {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #f0f0f0; height: 50%;
  transition: height .4s ease;
}
.eval-bar-label {
  position: absolute; left: 0; right: 0; text-align: center;
  font-size: 9px; font-weight: 700; color: #57544f; bottom: 2px;
}
.eval-bar-label.on-top { bottom: auto; top: 2px; color: #ddd; }

.board-frame {
  position: relative;
  width: var(--board-size); height: var(--board-size);
  border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
  border-radius: 4px;
  user-select: none;
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.hl::before, .sq.sel::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(255, 255, 51, .5);
}
.sq .coord {
  position: absolute; font-size: 11px; font-weight: 700; pointer-events: none; z-index: 1;
}
.sq .coord.rank { top: 2px; left: 3px; }
.sq .coord.file { bottom: 1px; right: 3px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.sq .hint {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
}
.sq .hint::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 32%; height: 32%; transform: translate(-50%,-50%);
  border-radius: 50%; background: rgba(0,0,0,.16);
}
.sq .hint.cap::before {
  width: 92%; height: 92%; background: none;
  border: 6px solid rgba(0,0,0,.16);
}

.piece-layer { position: absolute; inset: 0; z-index: 2; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%;
  background-size: 100% 100%; background-repeat: no-repeat;
  transition: transform .18s cubic-bezier(.25,.6,.35,1);
  will-change: transform;
  cursor: grab;
}
.piece.no-anim { transition: none; }
.piece.dragging {
  transition: none; cursor: grabbing; z-index: 10;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.45));
  transform-origin: center;
}
.piece.fade { opacity: 0; transition: opacity .15s; }
.piece.pop { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform-origin: center; } to { opacity: 1; } }

.badge {
  position: absolute; top: -8px; right: -8px; z-index: 6;
  width: 27px; height: 27px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.55);
  pointer-events: none;
}
.arrow-layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 4;
}
.promo-picker {
  position: absolute; z-index: 20; width: 12.5%;
  background: #fff; border-radius: 6px;
  box-shadow: 0 4px 18px rgba(0,0,0,.6);
  display: flex; flex-direction: column; overflow: hidden;
}
.promo-picker button {
  background: #fff; border-radius: 0; box-shadow: none; padding: 0;
  width: 100%; aspect-ratio: 1;
}
.promo-picker button:hover { background: #d8e5c3; }
.promo-picker img { width: 100%; height: 100%; display: block; }

.nav-row { display: flex; gap: 6px; justify-content: center; padding-left: 30px; }
.nav-row button { font-size: 14px; padding: 5px 12px; }
.nav-row button.toggled { background: var(--green-dark); box-shadow: inset 0 2px 3px rgba(0,0,0,.35); }

.variation-bar {
  margin-left: 32px; max-width: var(--board-size);
  display: flex; align-items: center; gap: 10px;
  background: #3a3733; border-radius: 6px; padding: 7px 10px;
  font-size: 13px;
}
.variation-bar .v-tag {
  background: var(--great); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 4px; padding: 2px 6px;
}
.variation-bar #variationMoves { flex: 1; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.variation-bar button { padding: 3px 9px; font-size: 12px; }

.coach-box {
  margin-left: 32px; min-height: 20px; max-width: var(--board-size);
  font-size: 13.5px; line-height: 1.5;
  background: var(--panel); border-radius: 8px; padding: 10px 14px;
}
.coach-box:empty { display: none; }
.coach-box .cls-word { font-weight: 800; }
.coach-box .pv { color: var(--muted); }
.coach-box .sugg { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.coach-box .sugg .eng { color: var(--muted); font-size: 12px; }
.coach-box .sugg b { color: var(--best); font-size: 15px; }
.coach-box .divider { border-top: 1px solid #3a3835; margin: 7px 0; }

/* ---------- side panel ---------- */
.side-panel {
  width: 430px; max-width: 96vw;
  background: var(--panel); border-radius: 10px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 80px); overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: none; border-radius: 0; box-shadow: none;
  padding: 13px; font-size: 15px; font-weight: 700; color: var(--muted);
}
.tab:active { transform: none; }
.tab.active { color: var(--text); box-shadow: inset 0 -3px 0 var(--green); }
.tab-page { overflow-y: auto; flex: 1; }
.tab-page::-webkit-scrollbar { width: 8px; }
.tab-page::-webkit-scrollbar-thumb { background: #4a4744; border-radius: 4px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 16px; }

.games-list { display: flex; flex-direction: column; }
.game-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; cursor: pointer;
  border-bottom: 1px solid #2b2926;
}
.game-row:hover { background: var(--card); }
.game-row.selected { background: var(--card-hover); }
.game-row .g-result {
  width: 34px; text-align: center; font-weight: 800; font-size: 13px;
  border-radius: 4px; padding: 4px 0; flex-shrink: 0;
}
.g-result.win { background: var(--green); color: #fff; }
.g-result.loss { background: var(--blunder); color: #fff; }
.g-result.draw { background: #6b6966; color: #fff; }
.game-row .g-main { flex: 1; min-width: 0; }
.game-row .g-players { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-row .g-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.game-row .g-tc { font-size: 11px; color: var(--muted); flex-shrink: 0; text-align: right; }

.game-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; line-height: 1.4; }
.progress-label { font-size: 13px; margin-bottom: 8px; color: var(--muted); }
.progress-track { height: 10px; background: var(--card); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--green); transition: width .15s; }

.accuracy-cards { display: flex; gap: 10px; padding: 14px 14px 6px; }
.acc-card { flex: 1; border-radius: 10px; padding: 12px 10px 10px; text-align: center; }
.acc-card.acc-white { background: #f5f5f5; color: #312e2b; }
.acc-card.acc-black { background: #403e3b; color: #fff; }
.acc-side { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
.acc-value { font-size: 30px; font-weight: 800; margin-top: 2px; }
.acc-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; opacity: .55; }
.acc-sub { font-size: 10.5px; opacity: .6; margin-top: 2px; min-height: 13px; }
.opening-line { padding: 6px 16px 8px; font-size: 12.5px; color: var(--muted); }
.eval-graph { width: 100%; height: 90px; display: block; background: #232220; cursor: pointer; }

.counts-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 10px 0; }
.counts-table td { padding: 3.5px 18px; }
.counts-table td.c-num { text-align: center; font-weight: 800; width: 64px; }
.counts-table td.c-label { text-align: center; font-weight: 700; }

.movelist {
  display: grid; grid-template-columns: 44px 1fr 1fr;
  font-size: 14px; padding: 6px 10px 20px;
}
.movelist .mnum { color: var(--muted); padding: 5px 6px; }
.mv {
  padding: 5px 8px; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px; font-weight: 600;
}
.mv:hover { background: var(--card); }
.mv.current { background: var(--card-hover); box-shadow: inset 0 -2px 0 var(--green); }
.mv .mini {
  width: 17px; height: 17px; border-radius: 50%; flex-shrink: 0;
  font-size: 9.5px; font-weight: 800; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}

.cls-brilliant { background: var(--brilliant); }
.cls-great { background: var(--great); }
.cls-best { background: var(--best); }
.cls-excellent { background: var(--excellent); }
.cls-good { background: var(--good); }
.cls-book { background: var(--book); }
.cls-inaccuracy { background: var(--inaccuracy); color: #5c4a00 !important; }
.cls-mistake { background: var(--mistake); }
.cls-miss { background: var(--miss); }
.cls-blunder { background: var(--blunder); }
.tx-brilliant { color: var(--brilliant); }
.tx-great { color: var(--great); }
.tx-best { color: var(--best); }
.tx-excellent { color: var(--excellent); }
.tx-good { color: var(--good); }
.tx-book { color: var(--book); }
.tx-inaccuracy { color: var(--inaccuracy); }
.tx-mistake { color: var(--mistake); }
.tx-miss { color: var(--miss); }
.tx-blunder { color: var(--blunder); }

@media (max-width: 1080px) {
  :root { --board-size: min(96vw, calc(100vh - 185px), 640px); }
}
