/* ============================================================
   Chess Coach — Main Stylesheet
   Design system: "Nocturne" — dark-first, near-black neutral
   surfaces, spring-green accent, Inter UI + JetBrains Mono.
   ============================================================ */

/* ---- Design tokens ---- */
:root {
  /* Opt into native dark handling so the browser won't force-darken/invert
     images (e.g. Chrome auto-dark flipping black pieces to white). */
  color-scheme: dark light;

  /* ---- Surface elevation (OKLCH + hex fallback) ---- */
  /* Base — page background, near-black, neutral (barely-violet) tint */
  --surface-base:    oklch(13.5% 0.004 286); /* #09090b */
  /* Panel — card/aside background, one step up */
  --surface-panel:   oklch(17% 0.005 286);   /* #101014 */
  /* Raised — inputs, code blocks, secondary cards */
  --surface-raised:  oklch(20.5% 0.006 286); /* #15151b */
  /* Overlay — dialogs, tooltips, dropdowns */
  --surface-overlay: oklch(24% 0.008 286);   /* #1c1c23 */
  /* Border default */
  --border:          oklch(30% 0.012 286);   /* #2a2a36 */
  /* Border subtle — hairlines */
  --border-subtle:   oklch(24.5% 0.009 286); /* #1f1f28 */

  /* ---- Text hierarchy ---- */
  /* Primary — nearly white, neutral tint, ≥7:1 on surface-base */
  --text:         oklch(94% 0.004 286); /* #e6e6ec */
  /* Secondary — label text, slightly dimmed, ≥4.5:1 on surface-panel */
  --text-secondary: oklch(74% 0.008 286); /* #a3a3af */
  /* Muted — very dim metadata, ≥4.5:1 on EVERY surface incl. overlay */
  --muted:        oklch(64% 0.01 286); /* #8a8a98 */

  /* ---- Accent — spring green ---- */
  --accent:        oklch(79% 0.17 152);  /* #4ade80  green-400-ish */
  --accent-dim:    oklch(26% 0.055 152); /* #0a2f1a — subtle tinted bg */
  --accent-dim-hover: oklch(22% 0.05 152); /* #062513 — accent-dim, one step deeper on hover */
  --accent-on:     oklch(20% 0.05 152);  /* near-black green text on accent bg */

  /* ---- Semantic error ---- */
  --error: oklch(68% 0.18 22); /* #f87171 */

  /* ---- Move quality colors (retuned for dark surfaces, ≥4.5:1) ---- */
  --q-best:       oklch(74% 0.16 145); /* #4ade80 */
  --q-good:       oklch(72% 0.14 285); /* #8b7cf6 — violet, distinct from accent green */
  --q-inaccuracy: oklch(82% 0.16 85);  /* #fde047 */
  --q-mistake:    oklch(75% 0.16 55);  /* #fb923c */
  --q-blunder:    oklch(65% 0.18 22);  /* #f87171 */
  --q-book:       oklch(72% 0.12 231); /* #7dc4f0 — soft azure, book stays informational */

  /* ---- Quality tinted backgrounds (badge/button fills, pair with --q-*) ---- */
  --q-best-dim:       oklch(18% 0.05 145); /* dark green tint  — pairs --q-best */
  --q-inaccuracy-dim: oklch(18% 0.05 85);  /* dark amber tint  — pairs --q-inaccuracy */
  --q-blunder-dim:    oklch(18% 0.05 22);  /* dark red tint    — pairs --q-blunder */
  --q-blunder-border: oklch(32% 0.07 22);  /* danger button border */

  /* ---- Eval bar (chess-semantic: Black/White advantage — theme-INDEPENDENT,
          identical in both themes; do not retune for light) ---- */
  --eval-bar-black: oklch(18% 0.01 248);  /* near-black, matches board dark theme */
  --eval-bar-white: oklch(94% 0.004 248); /* near-white with cool tint */

  /* ---- Spacing scale (4px base) ---- */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;

  /* ---- Radii ---- */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;

  /* ---- Elevation shadows ---- */
  --shadow-sm:  0 1px 3px oklch(0% 0 0 / 0.3), 0 1px 2px oklch(0% 0 0 / 0.2);
  --shadow-md:  0 4px 12px oklch(0% 0 0 / 0.35), 0 2px 4px oklch(0% 0 0 / 0.2);
  --shadow-lg:  0 8px 24px oklch(0% 0 0 / 0.45), 0 4px 8px oklch(0% 0 0 / 0.25);
  --shadow-toast: 0 2px 8px oklch(0% 0 0 / 0.35);

  /* ---- Scrim (modal backdrop) ---- */
  --scrim: oklch(0% 0 0 / 0.65);

  /* ---- Motion ---- */
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Light theme — the Nocturne system on neutral paper.
   Applied via html[data-theme="light"], set pre-paint by the
   inline <head> script (theme.js keeps it live). Overrides
   TOKENS ONLY; component rules never change per theme.
   Elevation flips direction here: panel/raised are LIGHTER than
   base (white cards on a gray desk), matching modern light UIs.
   All pairs verified ≥4.5:1 text / ≥3:1 UI (see each comment).
   ============================================================ */
html[data-theme="light"] {
  /* Both values, light first — dropping `dark` re-enables Chrome
     auto-dark image inversion (white-pieces bug, see :root note). */
  color-scheme: light dark;

  /* ---- Surfaces — neutral paper; white cards on a soft gray base ---- */
  --surface-base:    oklch(97.5% 0.002 286); /* #f7f7f9 */
  --surface-panel:   oklch(100% 0 0);        /* #ffffff */
  --surface-raised:  oklch(95.5% 0.003 286); /* #f0f0f4 */
  --surface-overlay: oklch(93% 0.004 286);   /* #e8e8ee */
  --border:          oklch(85% 0.006 286);   /* #d3d3dd */
  --border-subtle:   oklch(91.5% 0.004 286); /* #e5e5eb */

  /* ---- Text — ≥12:1 / ≥7:1 / ≥5:1 on panel; ≥4.5:1 on overlay ---- */
  --text:           oklch(22% 0.008 286); /* #1b1b22 */
  --text-secondary: oklch(42% 0.012 286); /* #4c4c58 */
  --muted:          oklch(47% 0.014 286); /* #5f5f6e */

  /* ---- Accent — deep green, ≥4.5:1 on base/panel ---- */
  --accent:           oklch(52% 0.14 152);  /* #16843f */
  /* Lightened so --accent text clears 4.5:1 on the tinted fill (was 93.5% →
     4.3:1, 0.2 short of AA — failed on every accent-dim chip: seg/best-move/
     review-btn-primary + T5 chip/pill/initials). 96% → 4.61:1; hover stays a
     touch darker at 95.3% → 4.54:1, still AA. Dark theme untouched (8.5:1). */
  --accent-dim:       oklch(96% 0.035 152);   /* #e1f9e6 — tinted bg under --accent text */
  --accent-dim-hover: oklch(95.3% 0.04 152);  /* #ddf8e3 — one step deeper on hover */
  --accent-on:        oklch(98.5% 0.002 286); /* #fafafc — on-accent text */

  /* ---- Semantic error — 6.4:1 on base ---- */
  --error: oklch(49% 0.175 25); /* #ae2228 */

  /* ---- Quality ramp — each ≥5.8:1 on panel, ≥4.5:1 on overlay ---- */
  --q-best:       oklch(47% 0.125 145); /* #216c29 */
  --q-good:       oklch(47% 0.15 285);  /* #5b3fd1 — violet, matches dark ramp hue */
  --q-inaccuracy: oklch(49% 0.10 85);   /* #7a5b01 */
  --q-mistake:    oklch(49% 0.125 55);  /* #944900 */
  --q-blunder:    oklch(49% 0.175 25);  /* #ae2228 */
  --q-book:       oklch(46.5% 0.10 231); /* #1a6390 — soft azure */

  /* ---- Quality tinted backgrounds — each ≥5.3:1 under paired --q-* ---- */
  --q-best-dim:       oklch(93% 0.05 145);  /* #d4f1d4 */
  --q-inaccuracy-dim: oklch(94% 0.055 85);  /* #fce9c2 */
  --q-blunder-dim:    oklch(93% 0.035 25);  /* #ffdfdc */
  --q-blunder-border: oklch(62% 0.12 25);   /* #c46761 — 3.3:1 on panel */

  /* ---- Shadows — softer, cool-tinted, lower opacity for daylight ---- */
  --shadow-sm:  0 1px 3px oklch(25% 0.02 248 / 0.10), 0 1px 2px oklch(25% 0.02 248 / 0.07);
  --shadow-md:  0 4px 12px oklch(25% 0.02 248 / 0.13), 0 2px 4px oklch(25% 0.02 248 / 0.08);
  --shadow-lg:  0 8px 24px oklch(25% 0.02 248 / 0.17), 0 4px 8px oklch(25% 0.02 248 / 0.10);
  --shadow-toast: 0 2px 8px oklch(25% 0.02 248 / 0.18);

  /* ---- Scrim — lighter veil ---- */
  --scrim: oklch(25% 0.02 248 / 0.45);

  /* --eval-bar-black / --eval-bar-white deliberately NOT overridden:
     chess-semantic (Black vs White advantage), identical in both themes. */
}

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

/* Mobile bot-rail sheet entrance (T6). Slide the panel in from the right and
   fade the scrim; reduced-motion zeroes both durations via the rule above. */
@keyframes bot-rail-slide-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

@keyframes bot-rail-scrim-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
   Base reset + typography
   ============================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--surface-base);
  color: var(--text);
  /* Full-height grid shell: header row (auto) + content row (1fr) */
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* Stored Russian is applied by i18n.js before reveal — avoid an English flash. */
html[data-i18n-pending] body {
  visibility: hidden;
}

/* ============================================================
   Header
   ============================================================ */

header {
  /* Slim topbar: title + subtitle on one baseline row.
     Right padding reserves the theme-toggle column at EVERY width:
     24px inset + 36px button + 8px clearance = 68px. Wrapped title/subtitle
     text can therefore never run under the absolutely-positioned toggle. */
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3)
           calc(var(--space-6) + 36px + var(--space-2) + 80px)
           var(--space-3)
           var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-base);
  /* Anchor for the absolutely-positioned theme toggle */
  position: relative;
}

/* EN | RU — sits just left of the theme toggle. Labels stay "EN" / "RU"
   so the control is readable in either language. */
.lang-switch {
  position: absolute;
  top: 50%;
  right: calc(var(--space-6) + 36px + var(--space-2));
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
}
.lang-switch button {
  min-width: 2rem;
  height: 22px;
  padding: 0 0.45rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
}
.lang-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-on);
}
.lang-switch button:hover {
  color: var(--text);
  background: transparent;
}
.lang-switch button[aria-pressed="true"]:hover {
  color: var(--accent-on);
  background: var(--accent);
}

/* Theme toggle — quiet header chrome, top-right. Icon reflects the stored
   PREFERENCE (monitor/sun/moon), not the resolved theme; theme.js swaps it. */
#theme-toggle {
  position: absolute;
  top: 50%;
  right: var(--space-6);
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

#theme-toggle:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: var(--border);
}

#theme-toggle svg {
  width: 18px;
  height: 18px;
}

header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Green logo tick before the title — pure CSS, no markup */
header h1::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--accent);
  margin-right: var(--space-2);
}

header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ============================================================
   Main layout — CSS grid, board column intrinsic + panel fills
   ============================================================ */

main {
  /* Closed rail (4 tracks): tab-rail | board-col | action-col | panel.
     The board-col track is a BOUNDED FLEX track: minmax(0, 582px) — it grows to
     582px when there's room and shrinks below it when the rail opens and steals
     width. 582px = 560px board cap + 22px row chrome (14px eval-bar + 8px gap),
     so the board (which reads --board-size = 100cqw − 22px) can reach its 560px
     cap. A definite track width (not `auto`) is REQUIRED for .board-col's
     container query (`100cqw`) to resolve — an `auto`/content-sized track would
     make the board size from the container while the container sizes from the
     board (circular) and collapse. The action column is intrinsic (auto); the
     panel takes the slack but stays 280–300px (Chess.com anchor: board dominant,
     panel slim). */
  display: grid;
  grid-template-columns: auto minmax(0, 582px) auto minmax(280px, 300px);
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-5) var(--space-4);
  overflow: hidden;
  min-height: 0;
}

/* Open rail (5 tracks): + bot-rail (~300px) as the last track. The rail
   element (T5) mounts empty for now; the class is toggled on <main> so the
   grid gains/loses the track without DOM surgery. */
main.bot-rail-open {
  grid-template-columns: auto minmax(0, 582px) auto minmax(280px, 300px) 300px;
}

/* Bot rail — hidden-by-default mount point (T5 builds the interior). It will
   carry a flex/grid display, so the [hidden] attribute needs an explicit
   override or it no-ops (the [hidden]-on-flex gotcha; contract #8). */
#bot-rail[hidden] { display: none; }

/* ============================================================
   Board column
   ============================================================ */

.board-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 0 0 auto;
  overflow-y: auto;
  min-height: 0;
  /* Container query context so the board can respond to its OWN column width,
     not just viewport height. When the bot rail opens the grid steals width from
     this track; a height-only cap would keep the board at 560px and clip it
     (h-file + FEN Load button cut off at the right edge). 100cqw = the actual
     board-col track width. */
  container-type: inline-size;
  /* Board sizing — THREE caps, whichever is smallest wins:
       560px                     — the design cap (Chess.com anchor).
       calc(100dvh - 160px)      — height guard (short viewports).
                                    header ~50 + main padding (space-5 ×2 = 40)
                                    + board→fen gap (space-3 = 12) + fen-row ~46
                                    + border/slack ~12 = 160px.
       calc(100cqw - 22px)       — width guard (rail-open / narrow columns).
                                    22px = 14px eval-bar + 8px gap (space-2),
                                    the chrome sharing the row beside the board.
     Both #board and #eval-bar read --board-size so the pair shrinks as one.
     At 1440 closed → 560px cap; at 1440/1280 rail-open → the 100cqw term wins
     and the board fits its (narrower) column with zero clipping. */
  --board-size: min(560px, calc(100dvh - 160px), calc(100cqw - 22px));
  /* Full board+eval-bar row width — the below-board bars (FEN/setup/trap/rep/
     trainer) span this so their edges line up with the board+eval-bar row, not
     the board alone. Derived from the single --board-size source (+ the 22px
     chrome back on). */
  --board-row-width: calc(var(--board-size) + 22px);
}

/* Keep match identity, clocks, and actions beside the board during bot play. */
.bot-game-player,
.bot-game-info { display: none; }

body[data-mode="bot-play"] .board-col {
  --board-size: min(560px, calc(100dvh - 320px), calc(100cqw - 22px));
}

body[data-mode="bot-play"] .fen-row { display: none; }

body[data-mode="bot-play"] .bot-game-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: var(--board-row-width);
  min-height: 34px;
  flex-shrink: 0;
}

.bot-game-player-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.bot-game-profile {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 3px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.bot-game-profile:hover { background: var(--surface-raised); border-color: var(--border); }
.bot-game-profile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bot-game-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.bot-game-avatar img { width: 100%; height: 100%; object-fit: cover; }
.bot-game-identity { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.bot-game-profile-meta { font-size: 0.72rem; color: var(--text-secondary); }
.bot-game-profile[hidden], .bot-game-avatar [hidden], .bot-game-player-name[hidden] { display: none; }
.bot-game-player .botplay-clock { flex-shrink: 0; }

body[data-mode="bot-play"] .bot-game-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: var(--board-row-width);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
}

.bot-game-info:focus-visible { outline: 2px solid var(--accent); }
.bot-game-summary { font-size: 0.8rem; color: var(--text-secondary); }
.bot-game-info .botplay-status { color: var(--text); font-weight: 600; }
#botplay-start[hidden], #bot-game-new[hidden],
#bot-game-return[hidden], #bot-game-history[hidden] { display: none; }

.board-wrap {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--space-2);
}

/* Eval bar — empty mount; another agent fills + styles in panel.css */
#eval-bar {
  width: 14px;
  flex: 0 0 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  /* min-height mirrors the board */
  min-height: var(--board-size);
}

/* Board itself — refined framed container */
#board {
  width: var(--board-size);
  height: var(--board-size);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-md), 0 0 0 2px var(--border);
}

/* ============================================================
   Action column — narrow vertical board-control stack between the
   board and the panel (3rd grid track). Holds Undo/Redo/Flip/Reset/
   Set up as labeled icon+text buttons; a quiet "BOARD" caption groups
   them. At ≤820px it folds back into a horizontal row under the board
   (see the responsive tier).
   ============================================================ */

.action-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 0 0 auto;
  /* Stretch to the grid row (was align-self:start): the Moves card below the
     buttons needs a definite remaining height to fill — a start-aligned column
     is content-height, so its flex:1 child has nothing to grow into and long
     games would be clipped by main{overflow:hidden} with no scrollbar. Buttons
     keep their compact top-stack look; only the card consumes the slack. */
  align-self: stretch;
  min-height: 0;
  /* Left-align the caption + buttons so the capped-width buttons read as a
     compact tool rail under the BOARD caption, not full-width stretched bars. */
  align-items: flex-start;
  min-width: 0;
}

/* ---- Moves list card (relocated from the panel's eval card) ----
   Every rule is scoped under .action-col .movelist-block: the .movelist-toggle /
   .movelist-chevron classes are shared with the Play-vs-Bot and analysis-settings
   disclosures in the panel, so the shared selectors in movelist.css must stay
   untouched. Width is responsive (not a fixed 220px) so the rail-open grid at
   1281–1440px doesn't crush the board — the board's own 100cqw width-guard
   handles the rest. */
.action-col .movelist-block {
  align-self: stretch;
  width: clamp(160px, 13vw, 220px);
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3);
  margin-top: var(--space-2);
}

/* Collapsed: header-only footprint — without this the collapsed card would keep
   its flex:1 share and hold the column open as blank space. */
.action-col .movelist-block.collapsed {
  flex: 0 0 auto;
}

/* The list itself is the ONLY scroller: kill movelist.css's 18rem cap and let
   the flex chain (stretch → min-height:0 → flex:1) hand it the real remaining
   column height. */
.action-col #move-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

/* Special modes (setup / trap / repertoire / blunder drill): the board area is
   taken over by each mode's own bar and movelist.js renders nothing — hide the
   card so no stale table lingers. Same body[data-mode] mechanism as the
   tab-panel hide below. bot-play is deliberately absent: the list renders live
   during bot games. */
body[data-mode="setup"] .action-col .movelist-block,
body[data-mode="trap-watch"] .action-col .movelist-block,
body[data-mode="trap-practice"] .action-col .movelist-block,
body[data-mode="rep-practice"] .action-col .movelist-block,
body[data-mode="blunder-practice"] .action-col .movelist-block {
  display: none;
}

/* Group caption — reuses the .eval-label idiom (uppercase, tracked, muted). */
.action-col-caption {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 var(--space-1);
  margin-bottom: var(--space-1);
}

/* Buttons stack as a compact tool rail: left-aligned icon+label, ≥40px tall
   targets, capped width so the column reads as a slim control stack rather than
   full-width stretched bars. Fill up to the cap (width:100% + max-width) so all
   buttons share one edge under the BOARD caption. */
.action-col button {
  justify-content: flex-start;
  width: 100%;
  max-width: 180px;
  min-height: 40px;
  height: auto;
  gap: var(--space-2);
  white-space: normal;
  text-align: left;
}

/* ============================================================
   Buttons — base system
   ============================================================ */

button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.8rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    border-color var(--motion-fast) var(--ease-out),
    background var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
}

button:hover {
  border-color: var(--accent);
  background: var(--surface-overlay);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:active {
  background: var(--accent-dim);
}

/* Lucide icon inside buttons — size-match text. The svg[data-lucide] arm
   covers the post-createIcons DOM (the <i> placeholder is replaced by an
   <svg> that keeps the data-lucide attribute). */
button i[data-lucide],
button svg[data-lucide] {
  width: 1em;
  height: 1em;
  display: inline-block;
  flex-shrink: 0;
}

/* ============================================================
   FEN row
   ============================================================ */

.fen-row {
  display: flex;
  gap: var(--space-2);
  /* Sole below-board chrome — spans the full board+eval-bar row width so its
     right edge lines up with the board (not 22px short). */
  width: var(--board-row-width);
}

#fen-input {
  flex: 1;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  transition: border-color var(--motion-fast) var(--ease-out);
}

#fen-input::placeholder { color: var(--muted); }

#fen-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.error { color: var(--error); font-size: 0.85rem; }

/* ============================================================
   Primary button variant
   ============================================================ */

button.primary {
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
  border-color: var(--accent);
}

button.primary:hover {
  filter: brightness(1.1);
  border-color: var(--accent);
  background: var(--accent);
}

/* ============================================================
   Setup (pregame) editor bar
   ============================================================ */

body.setup-mode #undo,
body.setup-mode #redo,
body.setup-mode #reset,
body.setup-mode .fen-row,
body.setup-mode #fen-error { display: none; }

/* Border diet: mode bars group by surface step (panel on base) + shadow;
   the old hairline outline was redundant box-lining. */
.setup-bar {
  width: var(--board-row-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--surface-panel);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.setup-bar[hidden] { display: none; }

.setup-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.palette { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }

.palette-set {
  display: inline-flex;
  gap: var(--space-1);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.palette-set.dark {
  /* Raised surface alone groups the black-piece set — no outline needed. */
  background: var(--surface-raised);
}

.palette button {
  min-width: 2.1rem;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.3rem 0.45rem;
}

.palette .tool { font-size: 0.85rem; }

.palette button.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.setup-row { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.setup-label { font-size: 0.82rem; color: var(--text-secondary); }
.setup-spacer { flex: 1; }

.seg.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.setup-actions { display: flex; gap: var(--space-2); }

/* ============================================================
   Right panel — tabbed aside
   ============================================================ */

.panel {
  background: var(--surface-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;        /* children scroll inside */
  min-height: 0;
  min-width: 0;
}

/* Scrollable interior below the tab bar */
.panel > [role="tabpanel"] {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-height: 0;
}

/* ---- Play-vs-Bot pill — bottom-right of the panel column ----
   A direct child of .panel (a flex column), pushed to the bottom edge via
   margin-top:auto so it never overlaps the scrolling tab-panel above it (the
   tab-panel owns the flex:1 scroll region; the pill claims its own reserved
   strip below). Lives OUTSIDE every [role=tabpanel], so it stays visible on
   all tabs and in special modes. Green accent pill; toggles #bot-rail (T5). */
.bot-rail-toggle {
  /* margin-top:auto pushes it to the panel's bottom edge; align-self:flex-end
     anchors it to the right. It claims its own reserved strip below the
     scrolling tab-panel, so it never overlaps content. */
  margin-top: auto;
  margin-right: var(--space-5);
  margin-bottom: var(--space-4);
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.35rem 0.7rem 0.35rem 0.35rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out);
}

.bot-rail-toggle:hover {
  background: var(--accent-dim-hover);
  border-color: var(--accent);
}

.bot-rail-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Avatar thumbnail — 22px circle. The <img> fills it when the persona file
   exists; onerror hides the <img> and the circle falls back to an accent-tinted
   dot (its own background). */
.pill-avatar {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent);
  display: inline-flex;
}

.pill-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   Bot rail (T5) — right-hand roster of opponents. Fills its
   ~300px grid track (5th track under main.bot-rail-open), owns
   its own scroll, surface-panel background + left hairline.
   Single .bot-rail block so T6 (mobile overlay sheet) can
   override cleanly. Desktop only in this ticket.
   ============================================================ */
#bot-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;               /* allow the inner list to scroll, not the grid */
  overflow: hidden;
  background: var(--surface-panel);
  border-left: 1px solid var(--border-subtle);
}

/* [hidden] override lives at the grid section (#bot-rail[hidden]{display:none})
   so the flex display doesn't no-op the attribute. */

.bot-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-2);
  flex-shrink: 0;
}

.bot-rail-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.bot-rail-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  /* Global button padding (0.45/0.8rem) would leave a 2.4px content box in
     this fixed 28px square and crush the × glyph to a sliver. */
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
}

.bot-rail-close:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.bot-rail-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.bot-rail-close i[data-lucide] {
  width: 16px;
  height: 16px;
}

.bot-rail-lock-hint {
  padding: 0 var(--space-4) var(--space-2);
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* Scrolling card list — the one scroll region in the rail. */
.bot-rail-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-4);
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

/* Rung heading between card groups (18-bot roster, grouped by rating).
   Sticky so the current group's rating stays visible while its cards
   scroll (design-review fold); the surface background stops card bleed. */
.bot-rail-rung {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-panel);
  padding: var(--space-2) var(--space-1) var(--space-1);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bot-rail-rung:first-child {
  padding-top: 0;
}

/* ---- Persona card ---- */
.bot-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}

.bot-card:hover {
  border-color: var(--border);
  background: var(--surface-overlay);
}

.bot-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Selected persona — accent frame + tinted fill; the rail's one focal state. */
.bot-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Mid-game lock — muted + not-allowed; a live game freezes selection. */
.bot-card.is-locked {
  cursor: not-allowed;
  opacity: 0.55;
}

.bot-card.is-locked:hover {
  border-color: var(--border-subtle);
  background: var(--surface-raised);
}

.bot-card.is-locked.is-selected:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Avatar — 56px round portrait, clickable (opens lightbox). */
.bot-card-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border: none;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.bot-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bot-card-avatar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Initials fallback (no photo) — accent-tinted circle, tokens only. */
.bot-card-avatar.is-initials {
  cursor: default;
  background: var(--accent-dim);
}

.bot-card-initials {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.bot-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;               /* let long blurbs wrap instead of overflow */
}

.bot-card-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.bot-card-rating {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bot-card-blurb {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .bot-card,
  .bot-rail-close { transition: none; }
}

/* ---- Tab rail — vertical icon+label nav in the first grid column.
   Lives as a direct child of <main> (moved out of the aside); tab wiring
   in panel.js is ID-based and unaffected. ---- */
#panel-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 152px;
  flex-shrink: 0;
  align-self: start;
  padding-top: var(--space-1);
}

#panel-tabs button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0;
  padding: var(--space-2) var(--space-3);
  text-transform: none;
  transition:
    color var(--motion-fast) var(--ease-out),
    background var(--motion-fast) var(--ease-out);
  white-space: nowrap;
}

#panel-tabs button i[data-lucide],
#panel-tabs button svg[data-lucide] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

#panel-tabs button:hover {
  color: var(--text);
  background: var(--surface-raised);
}

#panel-tabs button[aria-selected="true"] {
  color: var(--text);
  background: var(--accent-dim);
}

#panel-tabs button[aria-selected="true"] svg[data-lucide] {
  color: var(--accent);
}

#panel-tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---- Tab panels: non-active hidden ---- */
[role="tabpanel"]:not(.is-active) { display: none; }

/* ---- data-mode: in special modes each mode's own bar still lives BELOW the
   board (setup-bar / trap-bar / rep-bar / trainer-bar), but the tab strip stays
   visible in the panel so tabs are reachable from EVERY mode. Keep the two-column
   layout and the panel shown; hide only the tab-panel *contents* (no contradictory
   play-mode eval). The mode indicator below the strip explains a tab click leaves
   the mode. Reverts automatically in play mode. (blunder-practice included here so
   all special modes share one rule.) ---- */
body[data-mode="setup"] .tab-panel,
body[data-mode="trap-watch"] .tab-panel,
body[data-mode="trap-practice"] .tab-panel,
body[data-mode="rep-practice"] .tab-panel,
body[data-mode="blunder-practice"] .tab-panel {
  display: none;
}

/* Mode indicator: contextual line filling the panel in special modes; app.js
   sets its text on mode:change and clears it in play. :empty hides it so play
   mode shows no empty box. */
.mode-indicator {
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--accent-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
}
.mode-indicator:empty { display: none; }

/* ============================================================
   Analysis panel — instrument card (mock-E)
   The panel's focal point: a raised card gathering the eval readout,
   the BEST NOW chip, best line/depth, and the move list into one
   cohesive instrument. Everything below the card (utility cluster,
   botplay disclosure) reads quieter by comparison.
   ============================================================ */

.panel-eval-card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Utility cluster — engine seams below the card. De-emphasized: no card
   frame, tighter rhythm, so the eye lands on the instrument card first. */
.panel-utility {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ============================================================
   Analysis panel — eval readouts + review commentary side-by-side
   ============================================================ */

.analysis-eval-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: flex-start;
}

.analysis-eval-col {
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.analysis-review-col {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Collapse the column out of the flex row in play mode so the eval column
   fills the full width (global [hidden] is overridden by display:flex above). */
.analysis-review-col[hidden] {
  display: none;
}

/* ============================================================
   Section label
   ============================================================ */

.eval-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: var(--space-1);
}

/* ============================================================
   Eval display
   ============================================================ */

.eval {
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', sans-serif;
  line-height: 1;
  letter-spacing: -0.02em;
}

/* ============================================================
   Move quality
   ============================================================ */

.quality {
  font-size: 1.15rem;
  font-weight: 600;
  text-transform: capitalize;
}

.q-best       { color: var(--q-best); }
.q-good       { color: var(--q-good); }
.q-inaccuracy { color: var(--q-inaccuracy); }
.q-mistake    { color: var(--q-mistake); }
.q-blunder    { color: var(--q-blunder); }
.q-book       { color: var(--q-book); }
.q-checkmate  { color: var(--q-best); }  /* game won — reuse the "best" green */
.q-draw       { color: var(--q-book); }  /* drawn result — neutral azure */

/* ============================================================
   Best move + PV
   ============================================================ */

.best-move {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

/* BEST NOW chip — the current-position best move (#best-move only, NOT the
   retrospective one) reads as a filled green pill inside the instrument card.
   accent-dim fill + accent text keeps it AA and on-aesthetic in both themes.
   :empty / em-dash placeholder still gets the chip; that's fine — it reads as
   an awaiting-eval slot. */
#best-move.best-move {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  margin-bottom: 0;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.pv {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  word-spacing: 0.1rem;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Status
   ============================================================ */

.status {
  font-size: 0.82rem;
  color: var(--text-secondary);
  min-height: 1.2em;
}

.status.error { color: var(--error); }

/* Analysis status mount (loading indicator) is styled in feedback.css (owner). */

/* ============================================================
   Opening panel
   ============================================================ */

.opening-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.empty-state p { margin: 0; }

/* Hide the repertoire placeholder once the tree is populated (section unhidden). */
#repertoire-section:not([hidden]) ~ #repertoire-empty-state { display: none; }

/* ============================================================
   Trap modes — hide play/setup controls
   ============================================================ */

body.trap-watch-mode #undo,
body.trap-watch-mode #redo,
body.trap-watch-mode #reset,
body.trap-watch-mode #setup-toggle,
body.trap-watch-mode .fen-row,
body.trap-watch-mode #fen-error,
body.trap-practice-mode #undo,
body.trap-practice-mode #redo,
body.trap-practice-mode #reset,
body.trap-practice-mode #setup-toggle,
body.trap-practice-mode .fen-row,
body.trap-practice-mode #fen-error { display: none; }

/* ============================================================
   Traps section (inside Traps tab)
   ============================================================ */

.traps-section { display: flex; flex-direction: column; gap: var(--space-2); }

.traps-filters { display: flex; gap: var(--space-2); }

#traps-name-filter {
  flex: 1;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  transition: border-color var(--motion-fast) var(--ease-out);
}

#traps-name-filter::placeholder { color: var(--muted); }

#traps-name-filter:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

#traps-color-filter {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.45rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out);
}

#traps-color-filter:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.traps-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 340px;
  overflow-y: auto;
}

.traps-list button {
  text-align: left;
  font-size: 0.83rem;
  padding: 0.4rem 0.55rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface-raised);
  border-color: transparent;
}

.traps-list button:hover {
  border-color: var(--accent);
  background: var(--surface-overlay);
}

.trap-item-name { flex: 1; }

.trap-item-meta {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.trap-item-eco { font-variant-numeric: tabular-nums; }
.trap-item-color { text-transform: capitalize; }
.trap-item-commonness { font-size: 0.72rem; }
/* .traps-empty (app.js) carries .empty-state too — the shared empty-state
   style is the single source; no local override so all tabs match. */

/* ============================================================
   Trap chip (live nudge, inside analysis tab)
   ============================================================ */

.trap-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
}

.trap-chip[hidden] { display: none; }

.trap-chip-text {
  flex: 1;
  font-weight: 600;
  color: var(--accent);
}

.trap-chip-drill {
  font-size: 0.8rem;
  padding: 0.25rem 0.55rem;
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
  border-color: var(--accent);
}

.trap-chip-drill:hover {
  filter: brightness(1.1);
  border-color: var(--accent);
  background: var(--accent);
}

.trap-chip-dismiss {
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  min-width: unset;
}

.trap-chip-dismiss:hover {
  border-color: var(--error);
  color: var(--error);
}

/* ============================================================
   Engine restart button (Analysis tab)
   ============================================================ */

.engine-restart-btn {
  font-size: 0.8rem;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
  margin: var(--space-2) 0;
  transition:
    border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.engine-restart-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.engine-restart-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.engine-restart-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.engine-restart-btn.is-busy {
  opacity: 0.8;
  font-style: italic;
}

/* ============================================================
   Analyze color row (evaluate color selector)
   ============================================================ */

.analyze-color-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}

.analyze-color-select {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out);
}

.analyze-color-select:hover {
  border-color: var(--accent);
}

.analyze-color-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* ============================================================
   Engine speed row (Fast / Balanced / Deep preset selector)
   ============================================================ */

.engine-speed-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}

.engine-speed-select {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out);
}

.engine-speed-select:hover {
  border-color: var(--accent);
}

.engine-speed-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* ============================================================
   Analysis-mode settings — collapsible disclosure in the Analysis
   tab. Header button reuses the movelist-toggle/chevron classes
   (movelist.css) for a matching look; only the body + segmented
   control are styled here.
   ============================================================ */

.analysis-settings-block {
  margin: var(--space-2) 0;
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-2);
}

.analysis-settings-block.collapsed .analysis-settings-body {
  display: none;
}

/* Chevron points right when collapsed (same motion as the move list). */
.analysis-settings-block.collapsed .movelist-chevron {
  transform: rotate(-90deg);
}

/* Header hint: shows the active non-Full mode while collapsed. */
.analysis-mode-hint {
  color: var(--muted);
  font-weight: 400;
}

.analysis-mode-row,
.eval-bar-toggle-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}

/* Segmented Full / Blunders only / Off selector — one bordered pill,
   accent-filled active segment (mirrors the old eval-toggle's ON look). */
.analysis-mode-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-raised);
}

.analysis-mode-seg button {
  margin: 0;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out);
}

.analysis-mode-seg button:last-child {
  border-right: none;
}

.analysis-mode-seg button:hover {
  background: color-mix(in oklch, var(--accent) 15%, transparent);
}

.analysis-mode-seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.analysis-mode-seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
}

.eval-bar-toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.eval-bar-toggle-row input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ============================================================
   Play vs Bot — collapsible disclosure in the play area (board
   column). Same movelist-toggle/chevron header pattern as the
   Analysis-mode block above; ships collapsed. Static shell only —
   botplay.js (T5) wires state, app.js/T3 owns mode entry.
   ============================================================ */

/* Lives inside the bot rail's pregame screen (two-step flow): a hairline
   divider under the hero, then the settings/controls stack. */
.botplay-block {
  margin: 0;
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
}

.botplay-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

.botplay-persona {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ---- Two-step rail screens (roster → pregame) ---- */
/* Each screen owns the rail's full height; [hidden] needs the explicit
   override because both carry a flex display (same gotcha as #bot-rail). */
.bot-rail-roster,
.bot-rail-pregame {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.bot-rail-roster[hidden],
.bot-rail-pregame[hidden] { display: none; }

/* ← All bots — quiet text button mirroring bot-rail-close's hover treatment. */
.bot-rail-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
}

.bot-rail-back:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.bot-rail-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Pregame scroll region — the one scroll container on screen 2. */
.bot-rail-pregame-scroll {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

/* Hero — big portrait, name, rating, blurb, Maia line; all centered. */
.pregame-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-1);
  padding-bottom: var(--space-2);
}

.pregame-avatar {
  padding: 0;
  border: 0;
  cursor: zoom-in;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-dim);
  display: inline-flex;
  margin-bottom: var(--space-1);
}

.pregame-avatar:disabled { cursor: default; }

.pregame-avatar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.pregame-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* display:block above would override the [hidden] attr's UA display:none
   (same gotcha as #bot-rail[hidden]) — the broken-image glyph would peek
   through behind the initials fallback. */
.pregame-avatar img[hidden] { display: none; }

/* Initials fallback (no photo) — accent on the dim circle, card-style. */
.pregame-avatar-initials {
  margin: auto;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.pregame-avatar-initials[hidden] { display: none; }

.pregame-hero .botplay-persona {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.pregame-rating {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.pregame-hero .botplay-persona-caption {
  margin-top: var(--space-1);
  color: var(--text-secondary);
}

/* Maia readiness indicator — subtle informational dot + label, not a
   control. Color is set via a data attribute botplay.js toggles
   (ready/not-ready); default (no attribute) reads as unknown/muted. */
.botplay-maia-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 0.75rem;
  color: var(--muted);
}

.botplay-maia-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.botplay-maia-indicator[data-ready="true"] .botplay-maia-dot {
  background: var(--accent);
}

.botplay-maia-indicator[data-ready="false"] .botplay-maia-dot {
  background: var(--border);
}

.botplay-color-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Segmented White/Black picker reuses the analysis-mode-seg look (border,
   pill, accent-filled active segment) via the shared class on the markup;
   only the aria-checked→visual mapping is added here since this is a
   radiogroup, not aria-pressed buttons. */
.botplay-color-seg button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
}

/* Select idiom shared by the takeback/time-control pickers (and the hidden
   persona state-carrier): surface-raised fill, border token, accent on
   hover/focus; disabled mid-game via the native attribute. */
.botplay-persona-select {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out);
  max-width: 100%;
}

.botplay-persona-select:hover:not(:disabled) {
  border-color: var(--accent);
}

.botplay-persona-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.botplay-persona-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.botplay-persona-caption {
  margin-top: calc(-1 * var(--space-2));
}

/* Takeback policy selector — reuses the persona-picker-row layout and the
   persona-select control look (same select idiom, disabled mid-game by
   botplay.js/T3). */
.botplay-takeback-policy-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Time-control selector — reuses the persona-picker-row layout + persona-select
   control look (same select idiom, disabled mid-game by botplay.js/T3). */
.botplay-time-control-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Clocks-pause-on-reload hint — reuses botplay-hint's subdued caption look. */
.botplay-clock-hint {
  margin-top: calc(-1 * var(--space-2));
}

/* Clock readouts in the board's player rows — shown only for a timed game
   (botplay.js toggles [hidden]). Tabular figures so digits don't jitter as the
   clock ticks; the side-to-move's clock is emphasized, low time (<10s) flagged
   in the danger tone. */
.botplay-clock {
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
  min-width: 4.5rem;
  text-align: center;
}

.botplay-clock[hidden] { display: none; }

.botplay-clock[data-active="true"] {
  color: var(--text);
  border-color: var(--accent);
}

.botplay-clock[data-low="true"] {
  color: var(--q-blunder);
  border-color: var(--q-blunder-border);
}

.botplay-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  min-height: 1.2em;
}

.botplay-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.botplay-resign:hover {
  border-color: var(--q-blunder-border);
}

.botplay-takeback:hover {
  border-color: var(--accent);
}

/* Takeback counter — sits inline next to the button in .botplay-controls,
   reads as a muted caption (same tone as botplay-hint). */
.botplay-takeback-count {
  font-size: 0.78rem;
  color: var(--muted);
  align-self: center;
}

/* Rated→casual note — shown once a takeback flips a rated game to casual;
   reuses botplay-hint's subdued caption look. */
.botplay-takeback-note {
  margin-top: calc(-1 * var(--space-2));
}

/* Start — the pregame screen's one primary action: full-width accent CTA
   (same treatment as button.primary). Shrinks back to a peer button once the
   in-game controls (Resign/Take back) join the row. */
.botplay-start {
  flex: 1;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
  border-color: var(--accent);
}

.botplay-start:hover {
  filter: brightness(1.1);
  border-color: var(--accent);
  background: var(--accent);
}

/* Disabled state — Start button when /api/bot/status.available is false.
   A class (not the native disabled attribute) so botplay.js can pair it
   with the hint text below without fighting pointer-events edge cases. */
.botplay-start.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.botplay-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.botplay-hint[hidden] { display: none; }

/* Rated toggle — reuses eval-bar-toggle-row's flex/checkbox styling; the
   hint below it reuses botplay-hint's subdued caption look. */
.botplay-rated-row {
  margin: 0;
}

.botplay-rated-hint {
  margin-top: calc(-1 * var(--space-2));
}

/* Rating readout — bot-ELO (app's estimate) + chess.com reference
   (user-entered). Kept visually distinct: bot-ELO reads as primary text,
   chess.com reference reads as a muted aside next to it. Values/visibility
   are filled by botplay.js (T4); this ticket only ships the static shell. */
.botplay-rating-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.botplay-elo {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
}

.botplay-chesscom {
  font-size: 0.78rem;
  color: var(--muted);
}

.botplay-chesscom[hidden] { display: none; }

.botplay-chesscom-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.botplay-chesscom-input {
  width: 5.5rem;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  transition: border-color var(--motion-fast) var(--ease-out);
}

.botplay-chesscom-input:hover {
  border-color: var(--accent);
}

.botplay-chesscom-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Global `button { display: inline-flex }` overrides the [hidden] attr's
   UA display:none, so the Retry button needs an explicit guard (it's shown
   only on engine-down). id+attr specificity beats the bare `button` rule. */
#botplay-retry[hidden],
#botplay-resign[hidden],
#botplay-takeback[hidden] { display: none; }

#botplay-takeback-note[hidden] { display: none; }

/* Win-chances bar hidden: class set on .board-wrap by app.js. Pure CSS hide —
   setEvalBar keeps updating underneath so a re-show is instantly current. */
.board-wrap.eval-bar-hidden #eval-bar {
  display: none;
}

/* Evaluation-score readout hidden: class set on .panel-eval-card by app.js
   (syncEvalDisplay). display: none — removes the readout from assistive tech
   AND collapses its reserved space (a 56px visibility:hidden gap at the top
   of the card read as a rendering bug, not a deliberate hide), while the
   render path (panel.js) keeps painting the true value underneath so a
   re-show is instantly current. This is the ONLY authority for hiding the
   score — there is no render-time branch for it, which is what keeps the
   switch live through Off's freeze. Targets .eval-block (label + #eval), not
   #eval alone, so the "Evaluation" label doesn't float above blank space
   while its value is hidden. .eval-block (index.html) wraps only that label +
   #eval and has no other CSS/JS consumer. */
.panel-eval-card.eval-score-hidden .eval-block {
  display: none;
}

/* Same switch, for the 2nd-best/retro "(+0.2)" score annotations — a separate
   child span (see panel.js renderSecond) so it can be targeted independently
   of the move text, which must stay visible even when the score is hidden.
   display: none (not visibility) so "· or Qd5" doesn't leave a trailing gap.
   A display:none child is still a DOM child, so panel.css's
   `.best-second:empty { display: none }` (which only fires when renderSecond
   clears textContent entirely, i.e. no line at all) is unaffected — verified
   by reading that rule; :empty checks child-node presence, not computed style. */
.panel-eval-card.eval-score-hidden .line-eval {
  display: none;
}

/* "vs Bot" provenance badge (Game Library row, review.js) — reuses the
   .review-badge base (review.css) sizing/shape; a neutral (non-result)
   color modifier so it reads as provenance, not a win/loss/draw signal. */
.review-badge-bot {
  color: var(--text-secondary);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
}

/* ============================================================
   Trap bar (drill study bar — stays in board column)
   ============================================================ */

.trap-bar {
  width: var(--board-row-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--surface-panel);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.trap-bar[hidden] { display: none; }

.trap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.trap-title { font-weight: 600; }

.trap-stepper { display: flex; align-items: center; gap: var(--space-1); }
.trap-stepper[hidden] { display: none; }

.trap-controls { display: flex; gap: var(--space-1); flex-wrap: wrap; }

.trap-move { font-size: 1rem; font-weight: 600; }

.trap-note {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-line;
}

.trap-feedback {
  font-size: 0.9rem;
  font-weight: 600;
  padding: var(--space-1) 0;
}

.trap-feedback[hidden] { display: none; }
.trap-feedback.feedback-good { color: var(--q-best); }
.trap-feedback.feedback-bad  { color: var(--error); }

.trap-reveal { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.trap-reveal[hidden] { display: none; }

/* .trap-bar mobile width lives in the unified ≤560px tier at the bottom. */

/* ============================================================
   Repertoire trainer mode — hide play/setup controls
   ============================================================ */

body.rep-mode #undo,
body.rep-mode #redo,
body.rep-mode #reset,
body.rep-mode #setup-toggle,
body.rep-mode .fen-row,
body.rep-mode #fen-error { display: none; }

/* ============================================================
   Repertoire section (inside Repertoire tab)
   ============================================================ */

.repertoire-section { display: flex; flex-direction: column; gap: var(--space-2); }
.repertoire-section[hidden] { display: none; }

.repertoire-tree {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 340px;
  overflow-y: auto;
}

.rep-color { display: flex; flex-direction: column; }

.rep-color-hdr {
  text-align: left;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  background: transparent;
  border: none;
  padding: var(--space-1) var(--space-1);
  cursor: pointer;
}

.rep-color-hdr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.rep-color-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: var(--space-2);
}

.rep-color-body.collapsed { display: none; }

.rep-opening { display: flex; flex-direction: column; }

.rep-opening-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.rep-opening-name {
  flex: 1;
  text-align: left;
  font-size: 0.83rem;
  font-weight: 600;
  background: transparent;
  border: none;
  color: var(--text);
  padding: var(--space-1) var(--space-1);
  cursor: pointer;
}

.rep-opening-name:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.rep-opening-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: var(--space-3);
}

.rep-opening-body.collapsed { display: none; }

.rep-practice-btn {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 700;
  border-color: var(--accent);
  min-width: unset;
}

.rep-practice-btn:hover {
  filter: brightness(1.1);
  border-color: var(--accent);
  background: var(--accent);
}

.rep-line { display: flex; align-items: center; gap: var(--space-1); }

.rep-line-jump {
  flex: 1;
  text-align: left;
  font-size: 0.82rem;
  background: var(--surface-raised);
  /* Border diet: raised surface marks the row (matches .traps-list buttons);
     the border slot stays for the accent hover/focus affordance. */
  border: 1px solid transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out);
}

.rep-line-jump:hover { border-color: var(--accent); }

.rep-line-jump:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.rep-line-jump.is-trap { color: var(--q-book); }

.rep-line-practice {
  font-size: 0.72rem;
  padding: 0.2rem 0.4rem;
  min-width: unset;
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.rep-line-practice:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Repertoire practice bar (stays in board column)
   ============================================================ */

.rep-bar {
  width: var(--board-row-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--surface-panel);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.rep-bar[hidden] { display: none; }

.rep-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.rep-title { font-weight: 600; }
.rep-move { font-size: 1rem; font-weight: 600; }

.rep-note {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-line;
}

.rep-feedback {
  font-size: 0.9rem;
  font-weight: 600;
  padding: var(--space-1) 0;
}

.rep-feedback[hidden] { display: none; }
.rep-feedback.feedback-good { color: var(--q-best); }
.rep-feedback.feedback-bad  { color: var(--error); }

.rep-controls { display: flex; gap: var(--space-1); flex-wrap: wrap; }

/* .rep-bar mobile width lives in the unified ≤560px tier at the bottom. */

/* ============================================================
   Promotion dialog (native <dialog> replaces the old overlay)
   ============================================================ */

#promo-dialog {
  background: var(--surface-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
  text-align: center;
  color: var(--text);
  /* Override browser defaults */
  max-width: 320px;
  width: 90vw;
}

#promo-dialog::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(2px);
}

.promo-title {
  margin-bottom: var(--space-4);
  font-weight: 600;
  font-size: 1rem;
}

.promo-choices {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
}

.promo-choices button { font-size: 1rem; }

/* ---- Avatar lightbox (T5) — native <dialog> top-layer (no z-index needed).
   Full persona portrait + name/rating caption; ×/backdrop/Esc close. ---- */
#avatar-lightbox {
  position: relative;
  background: var(--surface-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  max-width: min(80vw, 80vh);
}

#avatar-lightbox::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(2px);
}

.avatar-lightbox-img {
  display: block;
  width: 100%;
  max-width: min(80vw, 80vh);
  max-height: 80vh;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.avatar-lightbox-caption {
  margin-top: var(--space-3);
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.avatar-lightbox-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out);
}

.avatar-lightbox-close:hover { background: var(--surface-panel); }

.avatar-lightbox-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.avatar-lightbox-close i[data-lucide] { width: 18px; height: 18px; }

@media (prefers-reduced-motion: reduce) {
  .avatar-lightbox-close { transition: none; }
}

/* ============================================================
   Toasts container — styled in feedback.css (single owner).
   ============================================================ */

/* ============================================================
   Trap variation select
   ============================================================ */

.trap-variation {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.45rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.trap-variation[hidden] { display: none; }

/* ============================================================
   Responsive — mid-width rail overlay (821–1280px)
   ============================================================ */

/* Below 1280px the push-rail would crush the board: four rigid tracks
   (tab | board | action | panel) plus a 5th 300px rail track leaves the board
   the smallest thing on screen (~252px at 1280×800). So below 1280px the rail
   stops being a grid track and becomes the same fixed overlay sheet used on
   mobile — main keeps its CLOSED 4-track layout while the rail is open, and the
   board returns to its closed-rail size. The ≤820px tier below inherits this
   and further flattens the whole grid to 1fr (it subsumes these rules).
   botplay.js's railIsOverlay() matches this same 1280px breakpoint so a
   backdrop click closes the sheet everywhere it overlays. */
@media (max-width: 1280px) {
  /* Rail open must NOT add the 5th track here — pin main back to the closed
     4-track grid so the board keeps its full closed-rail width. */
  main.bot-rail-open {
    grid-template-columns: auto minmax(0, 582px) auto minmax(280px, 300px);
  }

  /* Rail becomes a right-anchored sheet over a full-bleed scrim (identical to
     the mobile treatment). The <aside> is the sheet panel; its ::before paints
     the scrim across the whole viewport. Below toasts (z-index 9000) at 8000.
     Board width is untouched — the sheet overlays, never a grid track. */
  #bot-rail {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    z-index: 8000;
    width: min(320px, 90vw);
    max-width: 90vw;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    /* overflow visible so the fixed ::before scrim isn't clipped; the card
       list keeps its own inner scroll. */
    overflow: visible;
    /* Slide in from the right. An animation (not a transition) is used because
       the sheet enters via display:none→flex. The global prefers-reduced-motion
       rule (line ~158) zeroes this duration — movement collapses to an instant
       appear with the scrim fade, feedback preserved. */
    animation: bot-rail-slide-in var(--motion-base) var(--ease-out);
  }

  /* Overlay sheet: the close button is the primary touch dismissal — grow
     its hit area to 44px (design-review fold; glyph stays 16px). */
  .bot-rail-close {
    width: 44px;
    height: 44px;
  }

  /* Full-viewport scrim behind the sheet. A ::before can't catch clicks, so
     backdrop-to-close is handled in botplay.js (document pointerdown outside
     the sheet, gated on railIsOverlay()). */
  #bot-rail::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--scrim);
    animation: bot-rail-scrim-in var(--motion-base) var(--ease-out);
  }

  /* Inner card list keeps the sheet's scroll (root is overflow:visible so the
     pseudo-scrim can escape). */
  .bot-rail-list {
    max-height: 100%;
  }
}

/* ============================================================
   Responsive — tablet/mobile
   ============================================================ */

@media (max-width: 820px) {
  body {
    height: auto;
    overflow: auto;
  }

  main {
    grid-template-columns: 1fr;
    overflow: visible;
    padding: var(--space-4);
  }

  /* Rail flattens into a horizontal, scrollable tab row above the board */
  #panel-tabs {
    flex-direction: row;
    width: auto;
    overflow-x: auto;
    padding-top: 0;
  }

  .board-col {
    overflow-y: visible;
  }

  /* Action column folds back into the old horizontal .controls row under the
     board (grid collapses to 1fr, so the column would otherwise stack full
     width). Caption hides — the icon+label buttons are self-explanatory in a
     row and the "BOARD" grouping header only earns its keep in the tall stack. */
  .action-col {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-2);
    /* Row-folded column is content-height again — the desktop stretch chain
       must not force it to the (now vertical) grid row. */
    align-self: auto;
  }

  .action-col-caption { display: none; }

  .action-col button {
    width: auto;
    min-width: 0;
  }

  /* Moves card in the folded row: flex-basis:100% forces its own wrap line
     BELOW the button row (flex-wrap alone would let it sit beside a button
     when widths happen to fit), capped height with internal scroll. */
  .action-col .movelist-block {
    flex: 1 1 100%;
    width: auto;
    max-height: 12rem;
    margin-top: 0;
  }

  .panel {
    /* On mobile the panel sits below the board; remove fixed height */
    min-height: 400px;
    max-height: none;
  }

  #eval-bar {
    min-height: 0;
    height: auto;
    align-self: stretch;
  }

  /* ---- Bot rail → fixed overlay sheet (T6) ----
     The grid flattens to 1fr here, so the rail is NO LONGER a track. When open
     it must not re-expand main to 5 tracks (the .bot-rail-open class rule has
     higher specificity than this media block's `main{grid-template-columns:1fr}`
     — override it explicitly so it stays single-column on mobile). */
  main.bot-rail-open {
    grid-template-columns: 1fr;
  }

  /* The rail sheet, scrim, and inner-list treatment come from the ≤1280px tier
     above — it already turns #bot-rail into the fixed overlay sheet and this
     tier (being narrower) is fully subsumed by it. Only the whole-grid flatten
     (main → 1fr, action-col fold) and the pill pinning are ≤820px-specific. */

  /* ---- Play-vs-Bot pill → fixed bottom-right (T6) ----
     The panel stacks below the board on mobile, so the pill would scroll away.
     Pin it to the viewport, above content, below toasts + the open sheet. Its
     bottom offset respects the iOS home-indicator safe area. */
  .bot-rail-toggle {
    position: fixed;
    right: var(--space-4);
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    margin: 0;
    z-index: 7000;
    box-shadow: var(--shadow-md);
    background: var(--accent-dim);
    /* Primary floating action on touch — meet the 44px comfortable touch
       target (WCAG 2.2 AA SC 2.5.8 floor is 24px; 44px for a primary action). */
    min-height: 44px;
  }

  /* ---- Touch targets — WCAG 2.2 AA (SC 2.5.8): dense controls get
     ≥24×24px hit-boxes at touch widths; desktop density unchanged. ---- */
  .trap-chip-dismiss {
    min-width: 24px;
    min-height: 24px;
    justify-content: center; /* icon-only ✕ stays centered in the grown box */
  }

  .rep-practice-btn,
  .rep-line-practice {
    min-width: 24px;
    min-height: 24px;
  }

  .rep-color-hdr,
  .rep-opening-name,
  .rep-line-jump {
    min-height: 24px;
  }
}

/* ============================================================
   Nocturne board theme — overrides chessground.brown.css.
   A theme-aware checkerboard drawn with a conic-gradient (2×2
   squares per tile, tiled 4×4 over the board) so both themes
   recolor via the tokens below — no image assets.
   ============================================================ */

:root {
  --board-light: oklch(36% 0.014 286); /* #3d3d4b */
  --board-dark:  oklch(27% 0.01 286);  /* #26262f */
}

html[data-theme="light"] {
  --board-light: oklch(94.5% 0.006 275); /* #eceef4 */
  --board-dark:  oklch(76% 0.02 275);    /* #aeb3c7 */
}

cg-board {
  background-color: var(--board-light);
  /* Quadrants clockwise from 12: TR dark, BR light, BL dark, TL light */
  background-image: conic-gradient(
    var(--board-dark) 0 25%,
    var(--board-light) 0 50%,
    var(--board-dark) 0 75%,
    var(--board-light) 0
  );
  background-size: 25% 25%;
}

/* Highlights — accent-tinted instead of chessground's mustard yellow */
cg-board square.last-move {
  background-color: color-mix(in oklab, var(--accent) 32%, transparent);
}

cg-board square.selected {
  background-color: color-mix(in oklab, var(--accent) 45%, transparent);
}

/* Board coordinates — quiet, readable on both board themes */
.cg-wrap coords coord {
  color: color-mix(in oklab, var(--text) 45%, transparent);
  text-shadow: none;
}

@media (max-width: 560px) {
  /* ---- Exact-fit board row ----
     Available content = 100vw − 32px (main padding var(--space-4) × 2).
     Row chrome beside the board = 14px eval-bar + 8px gap = 22px.
     Board = 100vw − 54px  →  375px: 321 + 22 = 343 = available (0 overflow)
                              320px: 266 + 22 = 288 = available (0 overflow).
     Height matches width — board stays square. */
  #board {
    width: calc(100vw - 54px);
    height: calc(100vw - 54px);
  }

  /* Eval bar mirrors the board's edge so the pair reads as one instrument. */
  #eval-bar { min-height: calc(100vw - 54px); }

  /* Bar hidden → the 22px of row chrome (14px bar + 8px gap) is gone; the
     board reclaims it so no dead gutter is left (full content width). */
  .board-wrap.eval-bar-hidden #board {
    width: calc(100vw - 32px);
    height: calc(100vw - 32px);
  }

  /* FEN row + mode bars stretch to the column (same width as the full
     eval-bar + board row), keeping every left/right edge on one line. */
  .fen-row,
  .setup-bar,
  .trap-bar,
  .rep-bar { width: auto; }

  /* Long trap/line titles wrap above their action button instead of
     forcing the header row past the viewport. */
  .trap-header,
  .rep-header { flex-wrap: wrap; }

  /* The subtitle wraps into a 4-line column beside the title at phone
     widths — the title alone identifies the app there. */
  header .sub { display: none; }

  /* ---- Avatar lightbox on phones (T6) ----
     Shrink the portrait so the dialog (photo + caption + × chrome) fits within
     the viewport and the close button stays on-screen and tappable. */
  #avatar-lightbox {
    max-width: min(92vw, 70vh);
    padding: var(--space-3);
  }

  .avatar-lightbox-img {
    max-width: min(92vw, 70vh);
    max-height: 70vh;
  }
}
