:root {
  --bg: #0b1220;
  --card: rgba(255, 255, 255, 0.055);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #e6edf7;
  --muted: #8ea0b8;
  --accent: #4cc2ff;
  --accent-2: #2b9fe6;
  --sq-light: #f2dcb3;
  --sq-dark: #b08463;
  --hl: rgba(246, 214, 94, 0.5);
  --radius: 14px;
  --board: max(min(92vw, calc(100vh - 260px), 620px), 280px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1100px 700px at 75% -10%, #182741 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-header { text-align: center; padding: 18px 16px 2px; }
.app-header h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: 0.3px; }
.app-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.app-footer {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 0 16px 16px;
}
.app-footer .dot { opacity: 0.45; padding: 0 6px; }
.app-footer .dot:has(+ #engine-version[hidden]) { display: none; }

.banner {
  position: sticky; top: 0; z-index: 50;
  max-width: 720px; margin: 12px auto 0; width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; line-height: 1.4;
  background: #3d1420; color: #ffc2c2; border: 1px solid #7f2740;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.banner.warn { background: #3a2c0d; color: #ffd98a; border-color: #8a6d1f; }
.banner.hidden { display: none; }

.layout {
  display: flex; justify-content: center; align-items: stretch;
  gap: 22px; padding: 16px 16px 48px;
}

/* ---------- board ---------- */
.board-panel { display: flex; flex-direction: column; gap: 10px; align-self: flex-start; }

.status-bar {
  display: flex; justify-content: flex-start; align-items: center; gap: 12px;
  min-height: 26px; padding: 0 4px; flex-wrap: wrap; row-gap: 8px;
  /* Keep the bar the same width as the board so long status text cannot widen
     the board panel / shift the centred layout. */
  width: var(--board); max-width: 100%;
}
.turn {
  font-size: 14px; display: flex; align-items: center; gap: 9px;
  /* The status text owns the variable left region. flex-basis: 0 makes it
     take only the space left after the fixed-width right group, so long
     messages ellipsize instead of wrapping or pushing the clocks/nav group. */
  flex: 1 1 0; min-width: 0; max-width: 100%; overflow: hidden;
}
#turn-text {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 0; min-width: 0; max-width: 100%;
}
/* The clock + nav group is pinned to the right (margin-left: auto absorbs the
   variable width of the turn text / eval indicator), so the nav controls keep
   a stable position. */
.clocks { margin-left: auto; }
.turn .spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: var(--accent);
  display: none; animation: spin 0.8s linear infinite;
}
.turn.thinking .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.eval { font-size: 13px; color: var(--muted); white-space: nowrap; flex: none; }
.eval.has { color: #bfe3ff; }

/* move navigation (status bar) */
.nav-group { display: flex; gap: 4px; flex: none; }
.nav-btn {
  appearance: none; border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.07); color: var(--text);
  width: 32px; height: 28px; padding: 0; border-radius: 8px;
  font-size: 12px; line-height: 1; cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.nav-btn:active:not(:disabled) { transform: translateY(1px); }
.nav-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- chess clocks (status bar) ---------- */
.clocks { display: flex; gap: 6px; flex: none; }
.clock {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 9px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.clock-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.clock-w .clock-dot { background: #f2dcb3; border: 1px solid rgba(15, 23, 42, 0.5); }
.clock-b .clock-dot { background: #2b333f; border: 1px solid rgba(255, 255, 255, 0.28); }
.clock-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 0.2px;
  /* Compact, fixed width so the clock chips (and the nav group after them)
     stay the same size as the time text changes (0:00 → 12:34 → 12:34.5). */
  min-width: 48px; text-align: right;
}
.clock.active {
  border-color: var(--accent);
  background: rgba(76, 194, 255, 0.13);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.clock.low .clock-time { color: #ffd98a; }
.clock.critical .clock-time { color: #ff8f8f; }
.clock.critical { animation: clockpulse 1s ease-in-out infinite; }
@keyframes clockpulse { 50% { background: rgba(255, 96, 96, 0.22); border-color: rgba(255, 96, 96, 0.6); } }

.board {
  width: var(--board); height: var(--board);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 10px; overflow: hidden;
  border: 3px solid #2c3a52;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.square { position: relative; cursor: pointer; }
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.board.locked .square { cursor: default; }

.square .piece {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--board) / 11.2); line-height: 1;
  pointer-events: none;
}
.piece-w { color: #ffffff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7), 0 0 1px rgba(0, 0, 0, 0.9); }
.piece-b { color: #17181c; text-shadow: 0 1px 2px rgba(255, 255, 255, 0.28), 0 0 1px rgba(255, 255, 255, 0.25); }

.square.selected { box-shadow: inset 0 0 0 3px var(--hl), inset 0 0 18px rgba(0, 0, 0, 0.18); }
.square.last-from, .square.last-to { background-image: linear-gradient(var(--hl), var(--hl)); }
.square.in-check {
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 64, 64, 0.85) 0%, rgba(255, 64, 64, 0.35) 60%, rgba(255, 64, 64, 0) 78%);
}
.square.hint-empty::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 26%; height: 26%; transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(15, 23, 42, 0.3);
}
.square.hint-capture { box-shadow: inset 0 0 0 4px rgba(15, 23, 42, 0.42); }
.square:not(.selected):hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28); }
/* Suggested moves (Hint action): up to three candidates, color-coded by
   quality — rank 1 = best (cyan), rank 2 (green), rank 3 (amber). A square
   shared by several candidates takes the best rank's color. Declared after
   the hover rule with equal-or-higher specificity so the rings stay visible
   even while a square is hovered or selected. */
.board .square.hint-rank1 {
  box-shadow: inset 0 0 0 4px rgba(76, 194, 255, 0.95), inset 0 0 16px rgba(76, 194, 255, 0.5);
}
.board .square.hint-rank2 {
  box-shadow: inset 0 0 0 4px rgba(124, 227, 139, 0.9), inset 0 0 14px rgba(124, 227, 139, 0.42);
}
.board .square.hint-rank3 {
  box-shadow: inset 0 0 0 4px rgba(246, 214, 94, 0.85), inset 0 0 12px rgba(246, 214, 94, 0.38);
}

/* ---------- sidebar ---------- */
.sidebar { width: 280px; max-width: 100%; display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px; backdrop-filter: blur(6px);
}
.card h2 {
  margin: 0 0 12px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); font-weight: 600;
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row #new-game { flex-basis: 100%; }
.btn {
  appearance: none; border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.07); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-size: 14px; cursor: pointer; flex: 1;
  transition: background 0.15s ease, transform 0.05s ease, filter 0.15s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: rgba(255, 255, 255, 0.07); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #04121f; font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.1); background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.btn.danger { border-color: rgba(255, 96, 96, 0.35); }
.btn.danger:hover:not(:disabled) { background: rgba(255, 96, 96, 0.16); border-color: rgba(255, 96, 96, 0.55); color: #ffc9c9; }
.btn.small { padding: 4px 10px; font-size: 12px; flex: none; border-radius: 8px; }

.field { margin-top: 12px; }
.field > label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
select {
  border-radius: 9px; border: 1px solid var(--card-border);
  background: #0d1728; color: var(--text); padding: 8px 10px; font-size: 14px;
  cursor: pointer; width: 100%;
}
select:disabled {
  opacity: 0.55;
  background: #09111d;
  color: #74879f;
  border-color: rgba(255, 255, 255, 0.05);
  cursor: default;
}

.seg { display: flex; border: 1px solid var(--card-border); border-radius: 9px; overflow: hidden; }
.seg label { flex: 1; margin: 0; display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 8px 10px;
  font-size: 13px; color: var(--muted); transition: background 0.15s, color 0.15s;
}
.seg input:checked + span {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #04121f; font-weight: 600;
}
.seg input:disabled + span { opacity: 0.55; cursor: default; }
.seg input:checked:disabled + span {
  background: rgba(255, 255, 255, 0.12);
  color: #a9b7c9;
  font-weight: 500;
}

/* ---------- opening card ---------- */
.opening-card.hidden { display: none; }
.opening-name {
  font-size: 16px; font-weight: 600; color: var(--text);
  margin: -4px 0 8px; line-height: 1.3;
}
.opening-eco {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  padding: 2px 8px; border-radius: 999px;
}

/* ---------- captured ---------- */
.cap-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.cap-label { color: var(--muted); width: 112px; flex: none; }
.cap-glyphs {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  font-size: 20px; letter-spacing: 3px; flex: 1; text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  background: linear-gradient(180deg, #f1e3c3, #e7d4ab);
  border: 1px solid rgba(15, 23, 42, 0.22);
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.28);
  color: #3c4250;
}
.cap-none { color: var(--muted) !important; font-size: 13px !important; text-shadow: none !important; }
.cap-adv {
  font-size: 12px; font-weight: 700; color: #7ce38b;
  background: rgba(124, 227, 139, 0.12); padding: 2px 8px; border-radius: 999px; flex: none;
}

/* ---------- move list ---------- */
.moves-card { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.moves-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
.moves-head h2 {
  margin: 0; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); font-weight: 600;
}
.move-list { flex: 1 1 auto; min-height: 0; max-height: 320px; overflow-y: auto; font-size: 14px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.18) transparent; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; padding: 4px 6px; border-radius: 6px; }
.move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.move-row.active { background: rgba(76, 194, 255, 0.16); }
.move-row.active .mv { color: #bfe3ff; }
.mv-num { color: var(--muted); }
.mv { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.moves-empty { color: var(--muted); font-size: 13px; padding: 4px 6px; }
.mv[data-ply] { cursor: pointer; }
.mv[data-ply]:hover { text-decoration: underline; }
/* Annotation badge in the move list: the engine glyph right after the
   SAN (e4!), in the cooler "auto" blue. */
.mv-anno {
  display: inline-block; margin-left: 3px; padding: 1px 4px;
  border-radius: 6px; font-size: 11px; font-weight: 700; line-height: 15px;
  color: #9fd4ff; background: rgba(76, 194, 255, 0.14); vertical-align: 1px;
}

/* ---------- analysis (balance chart + thinking log) ---------- */
.analysis-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 0 0 12px;
}
.analysis-head h2 {
  margin: 0; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); font-weight: 600;
}
.chart-legend { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; letter-spacing: 0.2px; }
.toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.toggle input {
  flex: none; width: 16px; height: 16px;
  accent-color: var(--accent); cursor: pointer;
}

.eval-chart {
  position: relative; height: 120px;
  display: flex; align-items: stretch; gap: 2px;
  border-bottom: 1px solid var(--card-border);
  padding: 0 2px;
}
.eval-chart .zero-line {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 1px; background: rgba(255, 255, 255, 0.2); z-index: 2;
}
.eval-chart .eval-bar { flex: 1 1 0; min-width: 0; position: relative; }
.eval-chart .eval-half { position: absolute; left: 0; right: 0; border: 1px solid rgba(255, 255, 255, 0.10); }
.eval-chart .eval-half.up { bottom: 50%; border-radius: 2px 2px 0 0; }
.eval-chart .eval-half.down { top: 50%; border-radius: 0 0 2px 2px; }
.eval-chart .eval-half.light { background: #eef2f8; }
.eval-chart .eval-half.dark { background: #6b7c9a; }
.eval-chart .eval-empty {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px;
}

.thinking-log { margin-top: 12px; max-height: 220px; overflow-y: auto; }
.thinking-log.hidden { display: none; }
.thinking-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.think-row { padding: 6px 2px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.think-row:last-child { border-bottom: none; }
.think-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.think-head .mv-num { color: var(--muted); }
.think-head .mv { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.think-eval { font-weight: 600; color: #bfe3ff; }
.think-meta { color: var(--muted); font-size: 12px; margin-left: auto; }
.think-line {
  margin-top: 3px; font-size: 12.5px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
}

/* ---------- promotion modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 8, 16, 0.62); backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-box {
  background: #152238; border: 1px solid var(--card-border);
  border-radius: 16px; padding: 22px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); text-align: center;
}
.modal-box p { margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.promo-options { display: flex; gap: 10px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.promo-btn {
  appearance: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 10px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text); transition: background 0.15s, border-color 0.15s;
}
.promo-btn:hover { background: rgba(76, 194, 255, 0.18); border-color: var(--accent); }
.promo-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 34px; line-height: 1; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  background: linear-gradient(180deg, #f1e3c3, #e7d4ab);
  border: 1px solid rgba(15, 23, 42, 0.22);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.28);
}
.promo-name { font-size: 12px; color: var(--muted); }

/* ---------- responsive ---------- */
/* Tablet: board on top (centered), settings + data side by side below */
@media (max-width: 1300px) {
  .layout { flex-wrap: wrap; }
  .board-panel { order: 1; flex-basis: 100%; align-items: center; }
  .sidebar { order: 2; width: auto; flex: 1 1 260px; min-width: 240px; }
  .moves-card { flex: none; }
  .move-list { flex: none; max-height: 320px; }
}

/* Mobile: single column, board first */
@media (max-width: 720px) {
  .layout { gap: 16px; }
  .sidebar { flex-basis: 100%; width: 100%; min-width: 0; }
  .app-header { padding-top: 12px; }
}


/* ---------- piece sets (themes) ---------- */
.piece.set-classic.piece-w { color:#ffffff; text-shadow:0 1px 2px rgba(0,0,0,.7),0 0 1px rgba(0,0,0,.9); }
.piece.set-classic.piece-b { color:#17181c; text-shadow:0 1px 2px rgba(255,255,255,.28),0 0 1px rgba(255,255,255,.25); }
.piece.set-wood.piece-w { color:#f2d8ab; text-shadow:0 1px 2px rgba(0,0,0,.55); }
.piece.set-wood.piece-b { color:#4b2f17; text-shadow:0 1px 2px rgba(255,255,255,.22); }
.piece.set-neon.piece-w { color:#9ff7ff; text-shadow:0 0 6px #22d3ee,0 0 12px #22d3ee; }
.piece.set-neon.piece-b { color:#e2a6ff; text-shadow:0 0 6px #a855f7,0 0 12px #a855f7; }
.piece.set-royal.piece-w { color:#f7d873; text-shadow:0 1px 1px rgba(0,0,0,.55),0 0 7px rgba(247,216,115,.45); }
.piece.set-royal.piece-b { color:#b7c2d3; text-shadow:0 1px 1px rgba(0,0,0,.7),0 0 6px rgba(183,194,211,.35); }
.piece.set-slate.piece-w { color:#eef2f8; text-shadow:0 1px 2px rgba(0,0,0,.6); }
.piece.set-slate.piece-b { color:#39465a; text-shadow:0 1px 2px rgba(255,255,255,.25); }
.square .piece .pset-img { width:80%; height:80%; object-fit:contain; display:block; }
.cap-glyphs .pset-img { width:18px; height:18px; object-fit:contain; }
.promo-glyph .pset-img { width:40px; height:40px; object-fit:contain; }

/* ---------- board themes ---------- */
.board[data-board-theme="classic"] { --sq-light:#f2dcb3; --sq-dark:#b08463; }
.board[data-board-theme="green"]   { --sq-light:#eaeed0; --sq-dark:#769656; }
.board[data-board-theme="blue"]    { --sq-light:#d7e3f0; --sq-dark:#5b7fa6; }
.board[data-board-theme="dark"]    { --sq-light:#5a6472; --sq-dark:#2b333f; }
.board[data-board-theme="neon"]    { --sq-light:#1b2333; --sq-dark:#0e1420; }

/* ---------- difficulty ---------- */
.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- sound ---------- */
label[for="soundEnabled"] {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
#soundEnabled {
  flex: none;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
#soundTest { width: 100%; }

/* ---------- board coordinates ---------- */
.board.coords .square.coord-rank::before {
  content: attr(data-rank);
  position: absolute; top: 2px; left: 3px;
  font-size: 10px; font-weight: 600; line-height: 1;
  pointer-events: none; user-select: none;
}
.board .square.coord-file > .coord {
  position: absolute; bottom: 2px; right: 3px;
  font-size: 10px; font-weight: 600; line-height: 1;
  pointer-events: none; user-select: none;
}
.board:not(.coords) .square.coord-file > .coord { display: none; }
.board .square.light.coord-rank::before { color: rgba(15, 23, 42, 0.55); }
.board .square.light.coord-file > .coord { color: rgba(15, 23, 42, 0.55); }
.board .square.dark.coord-rank::before { color: rgba(255, 255, 255, 0.65); }
.board .square.dark.coord-file > .coord { color: rgba(255, 255, 255, 0.65); }
.board[data-board-theme="neon"] .square.coord-rank::before { color: rgba(255, 255, 255, 0.65); }
.board[data-board-theme="neon"] .square.coord-file > .coord { color: rgba(255, 255, 255, 0.65); }

label[for="showCoords"] {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
#showCoords {
  flex: none;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- captured tray (light surface) ---------- */
/* Captured pieces sit on a light wood/cream tray so their natural set colors
   (white = light art w/ dark outline, black = dark art) stay visible, like on the board. */
.cap-glyphs .cap-none { color: #5b6472 !important; }

/* ---------- custom game (button + modal) ---------- */
.btn.secondary {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text);
}
.btn.secondary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
.btn-row #custom-game { flex-basis: 100%; }

.custom-box {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  text-align: left;
  padding: 18px 22px;
}
.custom-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.custom-head p { margin: 0; font-size: 14px; color: var(--text); font-weight: 600; }

.tabs {
  display: flex; gap: 4px; margin: 14px 0 12px;
  padding: 4px; border-radius: 9px;
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--card-border);
}
.tab {
  appearance: none; border: none; background: transparent; color: var(--muted);
  flex: 1; padding: 7px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #04121f; font-weight: 600;
}
.pane.hidden { display: none; }
.pane-label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }

.pgn-input {
  width: 100%; min-height: 150px; resize: vertical;
  background: #0d1728; color: var(--text);
  border: 1px solid var(--card-border); border-radius: 9px;
  padding: 10px 12px; font-size: 13px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.pgn-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pgn-input::placeholder { color: #5c7089; }

.inline-error {
  margin-top: 10px; padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.4;
  background: #3d1420; color: #ffc2c2; border: 1px solid #7f2740;
}
.inline-error.hidden { display: none; }

.setup-palette {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-bottom: 12px;
}
.setup-piece-btn {
  appearance: none; cursor: pointer; padding: 3px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #f1e3c3, #e7d4ab);
  border: 1px solid rgba(15, 23, 42, 0.22); border-radius: 8px;
  box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.28);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.setup-piece-btn:hover { border-color: rgba(76, 194, 255, 0.6); }
.setup-piece-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.setup-piece-btn .piece {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
}
.setup-piece-btn .pset-img { width: 80%; height: 80%; object-fit: contain; display: block; }

.setup-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-auto-rows: 1fr;
  width: min(100%, 384px); aspect-ratio: 1; margin: 0 auto 14px;
  border-radius: 8px; overflow: hidden;
  border: 2px solid #2c3a52;
  user-select: none; -webkit-user-select: none;
}
.setup-square { position: relative; cursor: pointer; }
.setup-square.light { background: var(--sq-light); }
.setup-square.dark { background: var(--sq-dark); }
.setup-square:hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35); }
.setup-square .piece {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; line-height: 1; pointer-events: none;
}
.setup-square .pset-img { width: 80%; height: 80%; object-fit: contain; display: block; }
/* Follow the active board theme (the main board's theme vars live on #board). */
.setup-grid[data-board-theme="classic"] { --sq-light:#f2dcb3; --sq-dark:#b08463; }
.setup-grid[data-board-theme="green"]   { --sq-light:#eaeed0; --sq-dark:#769656; }
.setup-grid[data-board-theme="blue"]    { --sq-light:#d7e3f0; --sq-dark:#5b7fa6; }
.setup-grid[data-board-theme="dark"]    { --sq-light:#5a6472; --sq-dark:#2b333f; }
.setup-grid[data-board-theme="neon"]    { --sq-light:#1b2333; --sq-dark:#0e1420; }

.setup-options { display: flex; flex-direction: column; gap: 10px; }
.check-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px;
}
.check-title { color: var(--muted); }
.check-row label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.check-row input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
