/* ============================================================================
   Chess — style.css
   Theme tokens, responsive layout, board, pieces, panels, dialogs, animations.
   ========================================================================== */

/* ------------------------------ Design tokens ----------------------------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.18);
  --anim: 220ms; /* overwritten from JS via --anim */
  --board-max: 640px;

  /* board square colors (overridden per board theme) */
  --sq-light: #ebd8b7;
  --sq-dark: #a97a52;
  --sq-accent: #2f6f4e;
}

/* ---- Dark theme (default) ---- */
:root[data-theme="dark"] {
  --bg: #12141a;
  --bg-2: #191c24;
  --surface: #1f2430;
  --surface-2: #262c3a;
  --border: #333a4b;
  --text: #eef1f7;
  --text-dim: #a4adc0;
  --primary: #6ea8fe;
  --primary-ink: #0a2444;
  --danger: #ff6b6b;
  --good: #4cd07d;
  --focus: #ffd166;
}

/* ---- Light theme ---- */
:root[data-theme="light"] {
  --bg: #eef1f6;
  --bg-2: #e3e8f0;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --border: #d6dce6;
  --text: #1b2030;
  --text-dim: #5b6478;
  --primary: #2f6bd6;
  --primary-ink: #ffffff;
  --danger: #d64545;
  --good: #1f9d57;
  --focus: #c47f00;
}

/* ---- High contrast overlay (applies over either theme) ---- */
:root[data-contrast="on"] {
  --bg: #000000;
  --bg-2: #000000;
  --surface: #0a0a0a;
  --surface-2: #141414;
  --border: #ffffff;
  --text: #ffffff;
  --text-dim: #ffffff;
  --primary: #ffe500;
  --primary-ink: #000000;
  --danger: #ff5555;
  --good: #00ff88;
  --focus: #00e5ff;
  --sq-light: #ffffff;
  --sq-dark: #000000;
  --sq-accent: #ffe500;
  --shadow: none;
}
:root[data-contrast="on"] .board { border-color: #fff; }

/* ------------------------------ Board themes ------------------------------ */
:root[data-board="classic"] { --sq-light: #ebd8b7; --sq-dark: #a2703f; --sq-accent: #6b8e23; }
:root[data-board="blue"]    { --sq-light: #dbe7f2; --sq-dark: #4f7aa8; --sq-accent: #f2c14e; }
:root[data-board="green"]   { --sq-light: #eeeed2; --sq-dark: #769656; --sq-accent: #d6a02e; }
:root[data-board="slate"]   { --sq-light: #cfd5de; --sq-dark: #64707f; --sq-accent: #e08a4b; }
:root[data-board="purple"]  { --sq-light: #e6dcf2; --sq-dark: #8062a8; --sq-accent: #f0c04a; }
:root[data-board="coral"]   { --sq-light: #ffe6d5; --sq-dark: #d9776b; --sq-accent: #4fb0a5; }

/* ------------------------------ Base / reset ------------------------------ */
* { box-sizing: border-box; }

/* The `hidden` attribute must always win over layout display rules below. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--bg-2), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  min-height: 100%;
}

h1, h2, p { margin: 0; }

button { font-family: inherit; }

/* Focus visibility for keyboard users */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ------------------------------ App shell --------------------------------- */
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(12px, 2.5vw, 26px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 40px;
  line-height: 1;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}
.brand-text h1 {
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: 0.5px;
  font-weight: 800;
}
.brand-sub { color: var(--text-dim); font-size: 13px; }

.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform var(--anim), background 0.2s, border-color 0.2s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }

/* sun/moon swap */
#btnTheme .icon-moon { display: none; }
:root[data-theme="light"] #btnTheme .icon-sun { display: none; }
:root[data-theme="light"] #btnTheme .icon-moon { display: inline; }

/* ------------------------------ Layout grid ------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, var(--board-max)) minmax(260px, 1fr);
  gap: clamp(12px, 2vw, 22px);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ------------------------------ Status card ------------------------------- */
.status-card { display: flex; flex-direction: column; gap: 6px; }
.turn-row { display: flex; align-items: center; gap: 10px; }
.turn-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border);
  background: #f4f4f4;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
  transition: background 0.2s;
}
.turn-dot[data-turn="b"] { background: #21242c; }
.turn-label { font-weight: 700; font-size: 16px; }
.game-status { color: var(--text-dim); font-size: 13px; min-height: 1.2em; }
.game-status.over { color: var(--good); font-weight: 700; }

/* ------------------------------ Evaluation bar ---------------------------- */
.eval-head {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-dim); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.eval-text { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.eval-bar {
  position: relative;
  height: 14px;
  border-radius: 8px;
  background: #20242c;
  overflow: hidden;
  border: 1px solid var(--border);
}
.eval-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 50%;
  background: linear-gradient(90deg, #f2f2f2, #ffffff);
  transition: width var(--anim) ease;
}
.eval-mid {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: var(--sq-accent); transform: translateX(-1px);
}

/* ------------------------------ Clocks ------------------------------------ */
.clocks { display: flex; flex-direction: column; gap: 8px; }
.clock {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}
.clock.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.clock.low .clock-time { color: var(--danger); }
.clock-name { color: var(--text-dim); font-size: 13px; }
.clock-time { font-size: 22px; font-weight: 800; }

/* ------------------------------ Captures ---------------------------------- */
.captures { display: flex; flex-direction: column; gap: 10px; }
.capture-row { display: flex; flex-direction: column; gap: 4px; }
.capture-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim);
}
.capture-pieces {
  display: flex; flex-wrap: wrap; gap: 1px; min-height: 26px;
  align-items: center;
}
.capture-pieces img { width: 24px; height: 24px; }
.capture-pieces .cap-adv {
  font-size: 12px; font-weight: 700; color: var(--good);
  margin-left: 4px;
}
.material-line { font-size: 13px; color: var(--text-dim); }
.material-line strong { color: var(--text); }

/* ------------------------------ Board area -------------------------------- */
.board-area { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.board-frame {
  position: relative;
  width: 100%;
  max-width: var(--board-max);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px; /* space for coordinates */
  background: var(--surface);
  border: 1px solid var(--border);
}
:root[data-coords="off"] .board-frame { padding: 6px; }

.board {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }

/* Coordinate labels */
.square .coord {
  position: absolute;
  font-size: clamp(8px, 1.5vw, 11px);
  font-weight: 700;
  opacity: 0.7;
  pointer-events: none;
}
.square .coord.file { right: 3px; bottom: 1px; }
.square .coord.rank { left: 3px; top: 1px; }
.square.light .coord { color: var(--sq-dark); }
.square.dark .coord { color: var(--sq-light); }
:root[data-coords="off"] .square .coord { display: none; }

/* Piece rendering */
.piece {
  width: 92%;
  height: 92%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 3;
  pointer-events: none;
  transition: transform var(--anim) ease;
  will-change: transform;
}
.piece.dragging { opacity: 0.35; }

/* Unicode-based piece styles */
:root[data-pieces="symbol"] .piece,
:root[data-pieces="outline"] .piece {
  background: none !important;
  display: grid;
  place-items: center;
  font-size: 82%; /* relative to square via container query fallback below */
  line-height: 1;
}
:root[data-pieces="symbol"] .piece::before,
:root[data-pieces="outline"] .piece::before {
  content: attr(data-glyph);
  font-size: min(9vw, 3.6rem);
}
:root[data-pieces="symbol"] .piece[data-color="w"]::before { color: #f6f6f6; text-shadow: 0 1px 2px rgba(0,0,0,.55), 0 0 2px #000; }
:root[data-pieces="symbol"] .piece[data-color="b"]::before { color: #1b1d22; text-shadow: 0 1px 1px rgba(255,255,255,.35); }
:root[data-pieces="outline"] .piece[data-color="w"]::before { color: #fafafa; -webkit-text-stroke: 1px #222; }
:root[data-pieces="outline"] .piece[data-color="b"]::before { color: #1b1d22; -webkit-text-stroke: 1px #eee; }

/* Square state highlights */
.square.selected::after {
  content: ""; position: absolute; inset: 0;
  background: var(--sq-accent);
  opacity: 0.45; z-index: 1;
}
.square.last-move::before {
  content: ""; position: absolute; inset: 0;
  background: var(--sq-accent); opacity: 0.28; z-index: 0;
}
.square.check-flag::after {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(circle, rgba(255,40,40,0.85), rgba(255,0,0,0) 70%);
}

/* Legal move indicators */
.square .hint {
  position: absolute; z-index: 2; pointer-events: none;
  width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20, 20, 20, 0.32);
}
.square.light .hint { background: rgba(20, 20, 20, 0.28); }
.square .hint.capture {
  width: 88%; height: 88%; border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 6px rgba(20, 20, 20, 0.30);
}
:root[data-hints="off"] .square .hint { display: none; }

/* Keyboard focus cursor on a square */
.square.kbd-focus { box-shadow: inset 0 0 0 4px var(--focus); z-index: 4; }

/* Win overlay */
.win-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  border-radius: var(--radius);
  animation: fade-in var(--anim) ease;
}
.win-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px 30px; text-align: center;
  box-shadow: var(--shadow); animation: pop 0.35s cubic-bezier(.2,1.3,.4,1);
}
.win-title { font-size: 28px; font-weight: 800; }
.win-sub { color: var(--text-dim); margin: 6px 0 16px; }

.board-hint { color: var(--text-dim); font-size: 13px; text-align: center; min-height: 1.2em; }

/* ------------------------------ Controls ---------------------------------- */
.controls { display: flex; flex-direction: column; gap: 12px; }
.control-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.io-grid { grid-template-columns: 1fr 1fr; }

.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 12px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  transition: transform var(--anim), background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface); border-color: var(--primary); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.small { padding: 9px 8px; font-size: 13px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.full { width: 100%; }

.io-group summary {
  cursor: pointer; font-weight: 600; font-size: 14px;
  padding: 6px 2px; color: var(--text-dim);
}
.io-group[open] summary { color: var(--text); margin-bottom: 8px; }

/* ------------------------------ Move history ------------------------------ */
.history-wrap { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.history-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim);
}
.move-counter {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 8px; border-radius: 20px; font-weight: 700; color: var(--text);
}
.move-list {
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 340px; overflow-y: auto;
  display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 2px 6px;
  align-content: start;
  font-variant-numeric: tabular-nums;
  scrollbar-width: thin;
}
.move-list .mv-num { color: var(--text-dim); font-size: 13px; padding: 4px 2px; text-align: right; }
.move-list .mv {
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
  font-size: 14px; font-weight: 600; transition: background 0.12s;
}
.move-list .mv:hover { background: var(--surface); }
.move-list .mv.current { background: var(--primary); color: var(--primary-ink); }
.move-list .empty { grid-column: 1 / -1; color: var(--text-dim); font-size: 13px; padding: 8px; text-align: center; }

.history-nav { display: flex; gap: 6px; justify-content: center; }
.nav-btn {
  flex: 1; padding: 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; font-size: 15px;
  transition: background 0.15s;
}
.nav-btn:hover { background: var(--surface); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ------------------------------ Settings drawer --------------------------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  animation: fade-in var(--anim) ease;
}
.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(360px, 92vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform var(--anim) ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 18px; }
.drawer-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }

.setting { display: flex; flex-direction: column; gap: 6px; }
.setting label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.setting.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.setting.toggle label { color: var(--text); }
.setting select, .setting input[type="range"] {
  width: 100%; padding: 9px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px;
}
.setting input[type="range"] { padding: 0; accent-color: var(--primary); }
.setting-val { font-size: 12px; color: var(--text-dim); }

/* Toggle switch */
.setting.toggle input[type="checkbox"] {
  appearance: none; width: 46px; height: 26px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative; cursor: pointer; transition: background 0.2s; flex: none;
}
.setting.toggle input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-dim); transition: transform 0.2s, background 0.2s;
}
.setting.toggle input[type="checkbox"]:checked { background: var(--primary); }
.setting.toggle input[type="checkbox"]:checked::after { transform: translateX(20px); background: #fff; }

/* ------------------------------ Modals ------------------------------------ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in var(--anim) ease;
  padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; width: min(520px, 100%);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.modal h2 { font-size: 18px; }
.modal textarea {
  width: 100%; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.modal-error { color: var(--danger); font-size: 13px; min-height: 1em; }
.modal-message { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Promotion picker */
.promotion {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 22px; box-shadow: var(--shadow);
  text-align: center; animation: pop 0.25s cubic-bezier(.2,1.3,.4,1);
}
.promotion-title { font-weight: 700; margin-bottom: 12px; }
.promotion-choices { display: flex; gap: 10px; }
.promo-choice {
  width: 66px; height: 66px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; display: grid; place-items: center;
  transition: transform var(--anim), border-color 0.15s, background 0.15s;
}
.promo-choice:hover { border-color: var(--primary); background: var(--surface); transform: translateY(-2px); }
.promo-choice img { width: 80%; height: 80%; }

/* ------------------------------ Toast ------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 30px;
  padding: 12px 22px; box-shadow: var(--shadow); z-index: 80;
  font-weight: 600; font-size: 14px; opacity: 0;
  transition: opacity var(--anim), transform var(--anim);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------ Confetti ---------------------------------- */
.confetti-canvas {
  position: fixed; inset: 0; z-index: 70;
  pointer-events: none; width: 100%; height: 100%;
}

/* ------------------------------ Animations -------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes check-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 0, 0, 0); }
  50% { box-shadow: inset 0 0 24px 4px rgba(255, 0, 0, 0.5); }
}
.board-frame.in-check { animation: check-pulse 0.7s ease; }

/* flip animation */
.board.flipping { transition: transform 0.5s cubic-bezier(.6,0,.3,1); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------ Responsive -------------------------------- */
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr minmax(280px, var(--board-max)) 1fr;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "board" "left" "right";
  }
  .board-area { grid-area: board; order: -1; }
  .left-panel { grid-area: left; }
  .right-panel { grid-area: right; }
  .left-panel { flex-direction: row; flex-wrap: wrap; }
  .left-panel > * { flex: 1 1 180px; }
}

@media (max-width: 560px) {
  .app { padding: 10px; gap: 12px; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .brand-mark { font-size: 30px; }
  .board-frame { padding: 14px; }
  .left-panel { flex-direction: column; }
  .left-panel > * { flex: none; }
  .move-list { max-height: 220px; }
}

/* Fullscreen tweaks */
:root:fullscreen .app, .app:fullscreen { max-width: 1400px; }

/* ============================ Play-mode control ============================ */
.play-mode {
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
}
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; border-radius: 10px; background: var(--bg-2);
}
.seg-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-checked="true"] {
  background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 2px 8px -2px var(--primary);
}
.seg-icon { font-size: 16px; line-height: 1; }
.bot-config { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bot-field { display: flex; flex-direction: column; gap: 4px; }
.bot-field > span { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.bot-field select {
  padding: 7px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer;
}

/* ============================ Computer opponent ============================ */
.thinking-badge {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--primary);
}
.thinking-spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--primary);
  animation: think-spin 0.7s linear infinite;
}
@keyframes think-spin { to { transform: rotate(360deg); } }

/* subtle glow on the board while the engine searches */
.board-frame.thinking { box-shadow: 0 0 0 2px var(--primary), 0 0 24px -6px var(--primary); }

/* grouped computer settings */
.ai-options {
  display: flex; flex-direction: column; gap: 14px;
  padding: 12px; margin-bottom: 4px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.setting-note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) {
  .thinking-spinner { animation: none; }
}

/* ============================ Post-game analysis =========================== */
/* Move classification colors */
:root {
  --tag-best: var(--good);
  --tag-inaccuracy: #e8b33a;
  --tag-mistake: #f08a3c;
  --tag-blunder: var(--danger);
}

/* history-panel Analyze link + counter grouping */
.history-head .link-btn {
  margin-left: auto;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  font-weight: 700; color: var(--primary); padding: 2px 4px; border-radius: 6px;
}
.history-head .link-btn:hover { text-decoration: underline; }
.history-head .link-btn:disabled { opacity: 0.4; cursor: not-allowed; text-decoration: none; }
.history-head .link-btn[aria-pressed="true"] { color: var(--good); }
.history-head .move-counter { margin-left: 10px; }

/* Move-list: SAN + optional classification badge */
.move-list .mv { display: flex; align-items: center; gap: 5px; }
.mv-san { white-space: nowrap; }
.mv-tag {
  font-size: 11px; font-weight: 800; line-height: 1;
  padding: 1px 4px; border-radius: 5px;
}
.mv-tag.tag-inaccuracy { color: #4a3600; background: var(--tag-inaccuracy); }
.mv-tag.tag-mistake { color: #3a1e00; background: var(--tag-mistake); }
.mv-tag.tag-blunder { color: #fff; background: var(--tag-blunder); }
.move-list .mv.has-blunder { box-shadow: inset 2px 0 0 var(--tag-blunder); }
.move-list .mv.has-mistake { box-shadow: inset 2px 0 0 var(--tag-mistake); }
.move-list .mv.has-inaccuracy { box-shadow: inset 2px 0 0 var(--tag-inaccuracy); }
.move-list .mv.has-best { box-shadow: inset 2px 0 0 var(--tag-best); }
.move-list .mv.current .mv-tag { filter: none; }

/* Win-card actions + analysis progress + summary */
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.win-card { max-width: min(420px, 90vw); }

.analysis-progress { margin-top: 16px; }
.ap-track {
  height: 8px; border-radius: 6px; overflow: hidden;
  background: var(--bg-2); border: 1px solid var(--border);
}
.ap-fill {
  height: 100%; width: 0%; border-radius: 6px;
  background: var(--primary); transition: width 0.2s ease;
}
.ap-label { display: block; margin-top: 6px; font-size: 12px; color: var(--text-dim); }

.analysis-summary { margin-top: 18px; text-align: left; }
.an-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); font-weight: 700; margin-bottom: 10px; text-align: center;
}
.an-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.an-side {
  padding: 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.an-side-head {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px;
}
.an-side-name { font-weight: 700; font-size: 14px; }
.an-accuracy { font-weight: 800; font-size: 18px; color: var(--primary); font-variant-numeric: tabular-nums; }
.an-tallies { display: flex; flex-direction: column; gap: 4px; }
.an-tally { font-size: 12px; color: var(--text-dim); }
.an-tally b { font-variant-numeric: tabular-nums; color: var(--text); }
.an-tally.tag-blunder b { color: var(--tag-blunder); }
.an-tally.tag-mistake b { color: var(--tag-mistake); }
.an-tally.tag-inaccuracy b { color: var(--tag-inaccuracy); }
.an-acpl { margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.an-hint { margin-top: 12px; font-size: 12px; color: var(--text-dim); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .ap-fill { transition: none; }
}
