/* ============================================================================
   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; }
:root:fullscreen .site-nav,
:root:fullscreen .site-footer { display: none; }

/* ============================ 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; }
}

/* ============================================================================
   SEO content section, footer, and screen-reader utility
   ========================================================================== */

/* Visually hidden but available to assistive tech + crawlers */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.seo-content {
  max-width: var(--board-max);
  margin: 40px auto 0;
  padding: 0 20px;
  color: var(--text);
}
.seo-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--shadow-sm);
}
.seo-content h2 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  line-height: 1.2;
}
.seo-content h3 {
  margin: 26px 0 10px;
  font-size: 1.12rem;
}
.seo-content p { line-height: 1.65; color: var(--text-dim); margin: 0 0 12px; }
.seo-content strong { color: var(--text); }
.seo-features, .seo-steps { margin: 0; padding-left: 20px; }
.seo-features li, .seo-steps li { line-height: 1.6; color: var(--text-dim); margin-bottom: 6px; }
.seo-features { list-style: none; padding-left: 0; }
.seo-features li { position: relative; padding-left: 24px; }
.seo-features li::before {
  content: "\265E"; /* knight */
  position: absolute; left: 0; top: 0;
  color: var(--primary);
}

.seo-faq { margin-top: 4px; }
.seo-faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg-2);
}
.seo-faq summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.seo-faq summary::-webkit-details-marker { display: none; }
.seo-faq summary::after { content: " +"; color: var(--text-dim); float: right; }
.seo-faq details[open] summary::after { content: " –"; }
.seo-faq details p { margin: 10px 0 0; }

.site-footer {
  max-width: var(--board-max);
  margin: 28px auto 40px;
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
}
.footer-nav {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.footer-nav a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.footer-nav a:hover { text-decoration: underline; }
.footer-note { font-size: 0.9rem; margin: 0; line-height: 1.6; }

@media (max-width: 520px) {
  .seo-inner { padding: 22px 18px; }
}

/* ==========================================================================
   Multi-page chrome: site nav, footer, content pages, blog
   ========================================================================== */

/* ------------------------------ Site nav ---------------------------------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px clamp(12px, 2.5vw, 26px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--border);
}
/* full-bleed border under the centered nav content */
.site-nav::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  border-bottom: 1px solid var(--border);
  z-index: -1;
}
.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
}
.site-brand .brand-mark { font-size: 26px; }
.site-brand-name { font-size: 1.15rem; letter-spacing: 0.4px; }

.nav-menu { display: flex; align-items: center; gap: 18px; }
.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a {
  display: inline-block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a[aria-current="page"] { color: var(--primary); }

.nav-theme .icon-moon { display: none; }
:root[data-theme="light"] .nav-theme .icon-sun { display: none; }
:root[data-theme="light"] .nav-theme .icon-moon { display: inline; }

.nav-toggle {
  display: none;
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

/* ------------------------------ Site footer ------------------------------- */
.site-footer {
  max-width: 1100px;
  margin: 56px auto 40px;
  padding: 32px clamp(16px, 4vw, 28px) 20px;
  text-align: left;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.footer-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1.6fr;
  gap: 28px;
}
.footer-h {
  font-size: 0.95rem;
  color: var(--text);
  margin: 0 0 12px;
  letter-spacing: 0.3px;
}
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin-bottom: 8px; }
.footer-col a {
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
}
.footer-col a:hover { color: var(--primary); text-decoration: underline; }
.footer-about p { font-size: 0.92rem; line-height: 1.6; margin: 0; max-width: 40ch; }
.footer-note {
  margin: 24px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  text-align: center;
}

/* ------------------------------ Content pages ----------------------------- */
.page {
  max-width: 820px;
  margin: 32px auto 0;
  padding: 0 clamp(16px, 4vw, 24px);
}
.page-wide { max-width: 1120px; }
.page-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(24px, 4vw, 40px);
  box-shadow: var(--shadow-sm);
}
.page-inner h1 { font-size: clamp(1.7rem, 4vw, 2.2rem); line-height: 1.15; margin: 0 0 10px; }
.page-inner h2 { font-size: 1.25rem; margin: 30px 0 12px; }
.page-inner h3 { font-size: 1.08rem; margin: 22px 0 8px; }
.page-inner p { line-height: 1.7; color: var(--text-dim); margin: 0 0 14px; }
.page-inner a { color: var(--primary); }
.page-inner strong { color: var(--text); }
.page-lead { font-size: 1.1rem; color: var(--text) !important; margin-bottom: 22px !important; }
.page-cta { margin-top: 28px; }
.page-note { font-size: 0.9rem; margin-top: 24px; }
.legal h2 { font-size: 1.15rem; }

.feature-list, .step-list { margin: 0 0 16px; padding-left: 22px; }
.feature-list li, .step-list li { line-height: 1.65; color: var(--text-dim); margin-bottom: 8px; }
.feature-list { list-style: none; padding-left: 0; }
.feature-list li { position: relative; padding-left: 26px; }
.feature-list li::before {
  content: "\265E";
  position: absolute; left: 0; top: 0;
  color: var(--primary);
}
.feature-list strong, .step-list strong { color: var(--text); }

/* ------------------------------ FAQ accordion ----------------------------- */
.faq-list { margin-top: 6px; }
.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--bg-2);
}
.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  padding-right: 24px;
  position: relative;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  position: absolute; right: 0; top: 0;
  color: var(--text-dim);
  font-size: 1.2rem; line-height: 1;
}
.faq-item[open] summary::after { content: "–"; }
.faq-item p { margin: 10px 0 0; line-height: 1.65; }

/* ------------------------------ Blog listing ------------------------------ */
.blog-inner { max-width: 1080px; }
.blog-header { text-align: center; margin-bottom: 8px; }
.blog-header h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); margin: 0 0 8px; }
.blog { }
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px;
  margin-top: 26px;
}
.blog-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.blog-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.blog-card-media { display: block; aspect-ratio: 1200 / 630; background: var(--surface-2); }
.blog-card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.blog-card-body { padding: 18px 18px 20px; display: flex; flex-direction: column; gap: 8px; }
.blog-card-body h2 { font-size: 1.2rem; line-height: 1.25; margin: 2px 0; }
.blog-card-body h2 a { color: var(--text); text-decoration: none; }
.blog-card-body h2 a:hover { color: var(--primary); }
.blog-excerpt { color: var(--text-dim); line-height: 1.6; font-size: 0.95rem; margin: 0; }
.read-more { color: var(--primary); text-decoration: none; font-weight: 600; font-size: 0.92rem; }
.read-more:hover { text-decoration: underline; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.tag-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--text-dim) !important;
  font-size: 0.88rem;
  margin: 0 !important;
}

/* ------------------------------ Blog article ------------------------------ */
.article { max-width: 760px; margin: 0 auto; }
.article-back { margin: 0 0 18px; }
.article-back a { color: var(--text-dim); text-decoration: none; font-weight: 600; }
.article-back a:hover { color: var(--primary); }
.article-head h1 { font-size: clamp(1.9rem, 4.5vw, 2.6rem); line-height: 1.12; margin: 0 0 12px; color: var(--text); }
.article-head .post-meta { margin-bottom: 12px !important; }
.article-head .tag-list { margin-bottom: 6px; }
.article-hero {
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 630;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 18px 0 26px;
  background: var(--surface);
}
.article-body { color: var(--text); }
.article-body h2 { font-size: 1.5rem; margin: 34px 0 12px; line-height: 1.2; }
.article-body h3 { font-size: 1.2rem; margin: 26px 0 10px; }
.article-body p { line-height: 1.75; color: var(--text-dim); margin: 0 0 16px; }
.article-body ul, .article-body ol { margin: 0 0 16px; padding-left: 24px; }
.article-body li { line-height: 1.7; color: var(--text-dim); margin-bottom: 8px; }
.article-body a { color: var(--primary); }
.article-body strong { color: var(--text); }
.article-body blockquote {
  margin: 20px 0;
  padding: 12px 18px;
  border-left: 3px solid var(--primary);
  background: var(--bg-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-dim);
  font-style: italic;
}
.article-body pre {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 18px;
}
.article-body pre code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; color: var(--text); }
.article-body :not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
}
.article hr { border: none; border-top: 1px solid var(--border); margin: 30px 0; }

/* ------------------------------ Contact ----------------------------------- */
.contact-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  margin: 18px 0;
}
.contact-card h2 { margin: 0 0 8px; font-size: 1.15rem; }
.contact-email { font-size: 1.15rem; font-weight: 700; }
.contact-email a { color: var(--primary); text-decoration: none; }
.contact-email a:hover { text-decoration: underline; }

/* ------------------------------ Buttons as links -------------------------- */
a.btn { display: inline-block; text-decoration: none; }

/* ------------------------------ Responsive nav ---------------------------- */
@media (max-width: 720px) {
  .nav-toggle { display: inline-grid; place-items: center; }
  .nav-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 10px clamp(12px, 2.5vw, 26px) 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: none;
  }
  .nav-menu.open { display: flex; }
  .nav-links { flex-direction: column; align-items: stretch; gap: 2px; }
  .nav-links a { padding: 12px 10px; }
  .nav-theme { align-self: flex-start; margin-top: 6px; }
}

@media (max-width: 640px) {
  .footer-cols { grid-template-columns: 1fr 1fr; }
  .footer-about { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 420px) {
  .footer-cols { grid-template-columns: 1fr; }
}
