/* ---------- Login / landing page ---------- */
.login-body { min-height: 100vh; display: flex; flex-direction: column; }
.login-body header { justify-content: flex-start; }

.login-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "intro" "card" "visual";
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 48px 24px 72px;
  align-content: center;
}
@media (min-width: 880px) {
  .login-main {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-areas: "intro card" "visual card";
    column-gap: 72px; row-gap: 36px;
    padding: 64px 24px;
    align-items: start;
  }
  .login-card { justify-self: stretch; align-self: start; }
}
.login-intro  { grid-area: intro; max-width: 540px; align-self: end; }
.login-visual { grid-area: visual; display: flex; }
.login-card   { grid-area: card; }

.login-headline {
  margin: 0;
  font-family: 'Instrument Serif', Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: -0.01em;
  color: #F3F4F6;
}
@media (min-width: 880px) { .login-headline { font-size: 58px; } }
.login-sub {
  margin: 18px 0 0;
  font-size: 16px;
  line-height: 1.6;
  color: rgba(255,255,255,0.55);
  max-width: 440px;
}
.login-tagline {
  display: flex; align-items: center; gap: 14px;
  margin-top: 22px;
  font: 600 11px/1 'Inter', system-ui, sans-serif;
  text-transform: uppercase; letter-spacing: 0.16em;
  color: rgba(255,255,255,0.42);
}
.login-tagline span:not(:last-child)::after {
  content: ""; display: inline-block; vertical-align: middle;
  width: 4px; height: 4px; margin-left: 14px;
  border-radius: 50%; background: #34d399; opacity: 0.75;
}

/* Splash board visual */
.login-visual { justify-content: flex-start; }
@media (max-width: 879px) { .login-visual { justify-content: center; } }
.splash-board-wrap { position: relative; width: 100%; max-width: 440px; }
.splash-board-frame {
  padding: 10px; border-radius: 18px;
  background: linear-gradient(140deg, #2a221b 0%, #1a1410 60%, #0f0b08 100%);
  box-shadow: 0 30px 80px -24px rgba(0,0,0,0.75), 0 0 0 1px rgba(255,255,255,0.04), inset 0 0 0 1px rgba(255,255,255,0.03);
}
.sb-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1 / 1;
  border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
.sb-sq { position: relative; }
.sb-sq.light { background: linear-gradient(180deg, #efe1c2 0%, #e6d5ad 100%); }
.sb-sq.dark  { background: linear-gradient(180deg, #9a7a52 0%, #7e5f3c 100%); }
.sb-sq.sb-hl::before { content: ""; position: absolute; inset: 0; background: rgba(224,196,72,0.34); }
.sb-pc { position: relative; display: block; width: 100%; height: 100%; }

.splash-chip {
  position: absolute; z-index: 2;
  background: rgba(16,18,21,0.92); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 9px 12px;
  box-shadow: 0 18px 44px -18px rgba(0,0,0,0.75);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.splash-chip-eval  { top: 16px; right: -20px; min-width: 122px; }
.splash-chip-field { bottom: 22px; left: -24px; min-width: 190px; }
.sc-eval-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sc-bot { font: 600 10px/1 'Inter', system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(255,255,255,0.5); }
.sc-score { font: 700 15px/1 'JetBrains Mono', ui-monospace, monospace; color: #F3F4F6; }
.sc-bar { margin-top: 7px; height: 4px; border-radius: 9999px; background: rgba(255,255,255,0.12); overflow: hidden; }
.sc-bar > span { display: block; height: 100%; background: linear-gradient(90deg, #6ee7b7, #34d399); border-radius: 9999px; }
.sc-field-head { display: flex; align-items: baseline; gap: 8px; }
.sc-san { font: 600 13px/1 'JetBrains Mono', ui-monospace, monospace; color: #F3F4F6; }
.sc-freq { font: 500 11px/1 'Inter', system-ui, sans-serif; color: rgba(255,255,255,0.45); }
.sc-wr { display: flex; height: 6px; margin-top: 8px; border-radius: 9999px; overflow: hidden; background: rgba(255,255,255,0.08); }
.sc-wr i { display: block; height: 100%; }
.sc-wr .wr-w { background: #e9e6df; }
.sc-wr .wr-d { background: #6f6a63; }
.sc-wr .wr-b { background: #2a2722; }
.sc-wr-legend { display: flex; justify-content: space-between; margin-top: 5px; font: 500 10px/1 'Inter', system-ui, sans-serif; color: rgba(255,255,255,0.4); }
@media (max-width: 879px) { .splash-chip-eval { right: 8px; } .splash-chip-field { left: 8px; } }
@media (max-width: 520px) { .splash-chip { display: none; } }

.login-card {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  justify-self: center;
}

.login-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: 18px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 9999px;
}
.login-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 7px 14px;
  font: 500 12px/1.4 'Inter', system-ui, sans-serif;
  color: rgba(255,255,255,0.55);
  border-radius: 9999px;
  cursor: pointer;
}
.login-tab:hover { color: rgba(255,255,255,0.85); }
.login-tab.active { background: #F3F4F6; color: #0a0b0d; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field > span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  font-weight: 500;
}
.login-field input {
  background: rgba(255,255,255,0.04);
  color: #F3F4F6;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 10px 12px;
  font: 400 14px/1.4 'Inter', system-ui, sans-serif;
  width: 100%;
}
.login-field input:focus {
  outline: none;
  border-color: rgba(52,211,153,0.45);
  box-shadow: 0 0 0 3px rgba(52,211,153,0.12);
}
/* Show/hide password toggle */
.login-pw-wrap { position: relative; }
.login-pw-wrap input { padding-right: 56px; }
.login-pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  background: transparent; border: none; cursor: pointer;
  padding: 4px 8px; border-radius: 8px;
  font: 600 11px/1 'Inter', system-ui, sans-serif; letter-spacing: 0.02em;
  color: rgba(255,255,255,0.55);
}
.login-pw-toggle:hover { color: #F3F4F6; background: rgba(255,255,255,0.06); }

.login-submit {
  margin-top: 4px;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid #34d399;
  background: #34d399;
  color: #062018;
  font: 600 14px/1.4 'Inter', system-ui, sans-serif;
  cursor: pointer;
}
.login-submit:hover { filter: brightness(1.08); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error:not(:empty) {
  background: rgba(251,113,133,0.06);
  border: 1px solid rgba(251,113,133,0.25);
  color: #fda4af;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
}
.login-note {
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  line-height: 1.5;
  margin: 4px 0 0;
}
.login-note.hidden { display: none; }

/* ---------- Design tokens ---------- */
:root {
  --bg: #0a0b0d;

  /* Surface alphas (used over the dark bg) */
  --surf-1: rgba(255, 255, 255, 0.02);   /* card */
  --surf-2: rgba(255, 255, 255, 0.04);   /* input / hover */
  --surf-3: rgba(255, 255, 255, 0.06);   /* hover-on-hover */

  /* Borders */
  --line:    rgba(255, 255, 255, 0.08);
  --line-2:  rgba(255, 255, 255, 0.05);
  --line-3:  rgba(255, 255, 255, 0.12);

  /* Text */
  --text:        rgba(255, 255, 255, 0.92);
  --text-soft:   rgba(255, 255, 255, 0.70);
  --text-muted:  rgba(255, 255, 255, 0.45);
  --text-faint:  rgba(255, 255, 255, 0.30);

  /* Brand + semantic */
  --emerald-300: #6ee7b7;
  --emerald-400: #34d399;
  --emerald-500: #10b981;
  --amber-300:   #fcd34d;
  --amber-400:   #fbbf24;
  --sky-300:     #7dd3fc;
  --sky-400:     #38bdf8;
  --rose-300:    #fda4af;
  --rose-400:    #fb7185;

  /* Radius scale */
  --r-sm:  6px;
  --r-md:  8px;
  --r-lg:  10px;
  --r-xl:  12px;
  --r-2xl: 16px;
  --r-full: 9999px;

  /* Fonts */
  --font-sans:   'Inter', ui-sans-serif, system-ui, sans-serif;
  --font-serif:  'Instrument Serif', Georgia, serif;
  --font-mono:   'JetBrains Mono', ui-monospace, Menlo, monospace;
}

/* ---------- Lucide icons ---------- */
/* Lucide replaces <i data-lucide="..."> with an inline SVG.classed .lucide.
   Size + stroke globally; let button/chip context tune position. */
[data-lucide], .lucide { display: inline-block; width: 14px; height: 14px; stroke-width: 2; vertical-align: -2px; }
button .lucide, .chip .lucide { width: 14px; height: 14px; flex-shrink: 0; }
.icon-only .lucide { width: 16px; height: 16px; }
.chip .lucide { width: 13px; height: 13px; }
#tabs .lucide { width: 12px; height: 12px; }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { font-size: 14px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(52,211,153,0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, rgba(56,189,248,0.06), transparent 60%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }

/* ---------- Header / brand ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 11, 13, 0.78);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--emerald-300), var(--emerald-500));
  color: #062018;
  box-shadow: 0 6px 18px -6px rgba(52,211,153,0.8);
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-text { line-height: 1.1; }
.brand-name {
  font-family: var(--font-serif); font-style: italic;
  font-size: 20px; color: var(--text);
}
.brand-sub {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 1px;
}
/* Header right side: Pro pill + account avatar */
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.pro-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-full); padding: 6px 12px;
  font: 500 12px/1.4 var(--font-sans); color: #fde68a;
  background: linear-gradient(135deg, rgba(252,211,77,0.20), rgba(245,158,11,0.10));
  border: 1px solid rgba(251,191,36,0.30);
}
.pro-pill:hover { background: linear-gradient(135deg, rgba(252,211,77,0.28), rgba(245,158,11,0.14)); color: #fef3c7; }
.pro-pill .lucide { width: 14px; height: 14px; color: var(--amber-300); }
.avatar {
  width: 32px; height: 32px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-soft); cursor: pointer;
}
.avatar:hover { background: rgba(255,255,255,0.14); color: var(--text); }
.avatar .lucide { width: 16px; height: 16px; }
button.avatar { padding: 0; }

/* User dropdown — hangs below the avatar button. */
.user-menu { position: relative; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 200px; padding: 6px;
  background: #14161b; border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px; box-shadow: 0 18px 40px -12px rgba(0,0,0,0.6);
  z-index: 50;
}
.user-menu-id { padding: 8px 10px 6px; }
.user-menu-name {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-menu-sub {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--text-muted); margin-top: 2px;
}
.user-menu-sep { height: 1px; background: rgba(255,255,255,0.08); margin: 6px 0; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-soft); font: 500 13px/1.4 'Inter', system-ui, sans-serif;
  cursor: pointer; text-align: left;
}
.user-menu-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.user-menu-item .lucide { width: 14px; height: 14px; color: var(--text-muted); }
.user-menu-item:hover .lucide { color: var(--text-soft); }
/* Slim notice bar below the header (e.g. missing Lichess token) */
.tokenbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 24px;
  font-size: 12px; line-height: 1.4;
  background: rgba(251,191,36,0.08);
  border-bottom: 1px solid rgba(251,191,36,0.20);
}
.tokenbar .lucide { color: var(--amber-400); flex-shrink: 0; }
.tokenbar span { flex: 1; color: var(--text-soft); }
.tokenbar a { color: var(--amber-300); }
.tokenbar code { font-family: var(--font-mono); background: var(--surf-2); padding: 1px 5px; border-radius: 4px; }
.tokenbar-x {
  background: transparent; border: none; color: var(--text-muted);
  padding: 4px; width: auto; flex-shrink: 0;
}
.tokenbar-x:hover { background: transparent; color: var(--text); }

/* ---------- Main layout ---------- */
/* Board + gear-gutter + panel, sized to content and centered as a group so the
   board and panel are top-aligned and separated only by the gear gutter. */
main {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 24px;
}
/* Audit / Scores are full-width reports — hide the board + gutter, panel goes wide. */
body[data-view="audit"] #boardCol, body[data-view="scores"] #boardCol,
body[data-view="audit"] #boardSettings, body[data-view="scores"] #boardSettings { display: none; }
body[data-view="audit"] #panel, body[data-view="scores"] #panel { flex: 1 1 100%; }

/* Spar mode = clean practice: hide the repertoire-building UI (tree + edit tools). */
body[data-mode="spar"] .tree-card,
body[data-mode="spar"] .tools-row { display: none !important; }

#boardCol {
  flex: 0 0 auto;
  width: max(280px, min(calc(100vh - 230px), calc(100vw - 540px), 960px));
  display: flex; flex-direction: column; gap: 12px;
}
#panel { flex: 0 1 420px; min-width: 0; }
/* Wood frame + inner board, matching the Figma 'Polished Chess App Design' */
#boardWrap {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  border-radius: var(--r-2xl);
  overflow: hidden;
  padding: 12px;
  background: linear-gradient(140deg, #2a221b 0%, #1a1410 60%, #0f0b08 100%);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04), inset 0 0 0 1px rgba(255,255,255,0.03);
}
#board { width: 100%; height: 100%; border-radius: var(--r-md); overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); }

/* ---------- Board theme: gradient squares + coord colors. Default = Figma "Wood" ---------- */
:root              { --fl: url(#sqL-wood);  --fd: url(#sqD-wood);  --coord-light: #7e5f3c; --coord-dark: #efe1c2; }
body[data-board="teal"]  { --fl: url(#sqL-teal);  --fd: url(#sqD-teal);  --coord-light: #2f6e5d; --coord-dark: #dcebe6; }
body[data-board="green"] { --fl: url(#sqL-green); --fd: url(#sqD-green); --coord-light: #5e7a44; --coord-dark: #eeeed2; }
body[data-board="slate"] { --fl: url(#sqL-slate); --fd: url(#sqD-slate); --coord-light: #44536b; --coord-dark: #dde3ea; }

.cm-chessboard .board .square.white { fill: var(--fl) !important; }
.cm-chessboard .board .square.black { fill: var(--fd) !important; }
.cm-chessboard .coordinates .coordinate { font-weight: 500; }
.cm-chessboard .coordinates .coordinate.white { fill: var(--coord-light) !important; opacity: 0.85; }
.cm-chessboard .coordinates .coordinate.black { fill: var(--coord-dark) !important; opacity: 0.85; }
/* Markers: neutral legal-move dots, emerald selection + hint (matches the Figma) */
.cm-chessboard .markers .marker.marker-dot { fill: #000; opacity: 0.3; }
.cm-chessboard .markers .marker.marker-square { fill: var(--emerald-400); opacity: 0.30; }
.cm-chessboard .markers .marker.marker-frame-primary { stroke: var(--emerald-400); opacity: 0.95; stroke-width: 2.4px; }
#coords { position: absolute; inset: 12px; pointer-events: none; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); z-index: 2; border-radius: var(--r-md); overflow: hidden; }
#coords > span { display: flex; align-items: flex-end; justify-content: flex-start;
  padding: 2px 4px; font-size: 9px; line-height: 1; color: rgba(0,0,0,0.45);
  font-family: var(--font-mono); user-select: none; }
#coords.hidden { display: none; }

/* Current opening label — standalone, shown in both modes */
.opening-name {
  font-family: var(--font-serif); font-style: italic; font-size: 16px;
  color: var(--text-soft); line-height: 1.2; text-align: center;
  margin: 2px 0;
}
.opening-name:empty { display: none; }

/* ---------- Board settings (gear in the gutter between board and panel) ---------- */
#boardSettings {
  flex: 0 0 44px; align-self: stretch;
  display: flex; justify-content: center;
  position: relative; z-index: 10;
}
.board-gear {
  width: 32px; height: 32px; padding: 0; justify-content: center;
  background: var(--surf-2); border: 1px solid var(--line);
  color: var(--text-soft);
}
.board-gear:hover { background: var(--surf-3); color: var(--text); }
.board-gear .lucide { width: 16px; height: 16px; }
.settings-menu {
  position: absolute; top: 38px; right: 0; min-width: 200px;
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: rgba(16,18,21,0.96); border: 1px solid var(--line-3);
  border-radius: var(--r-lg);
  box-shadow: 0 18px 44px -12px rgba(0,0,0,0.75);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.settings-menu.hidden { display: none; }
.menu-item {
  justify-content: flex-start; width: 100%;
  background: transparent; border: none; border-radius: var(--r-sm);
  padding: 7px 9px; color: var(--text-soft); font-size: 12px;
}
.menu-item:hover { background: var(--surf-3); color: var(--text); }
.menu-item .lucide { width: 14px; height: 14px; color: var(--text-muted); }
.menu-item.on { color: var(--emerald-300); }
.menu-item.on .lucide { color: var(--emerald-400); }
.menu-sep { height: 1px; background: var(--line-2); margin: 4px 2px; }
.menu-label { padding: 4px 9px 3px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-muted); font-weight: 500; }
.theme-swatches { display: flex; gap: 6px; padding: 2px 9px 4px; }
.theme-swatch {
  width: 26px; height: 26px; padding: 0; border-radius: var(--r-sm);
  border: 1px solid var(--line); cursor: pointer;
  background: conic-gradient(var(--d) 0 25%, var(--l) 0 50%, var(--d) 0 75%, var(--l) 0);
}
.theme-swatch:hover { border-color: var(--line-3); }
.theme-swatch.active { outline: 2px solid var(--emerald-400); outline-offset: 1px; border-color: transparent; }

/* ---------- Board actions (Reset · Pin) — lives in the Mode card ---------- */
#boardActions { gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
#boardActions #btnPin { margin-left: auto; }

/* ---------- Tooltips (instant, styled — for icon-only controls) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  padding: 4px 8px; border-radius: var(--r-sm);
  background: rgba(16,18,21,0.97); border: 1px solid var(--line-3); color: var(--text);
  font: 500 11px/1.3 var(--font-sans); white-space: nowrap;
  box-shadow: 0 6px 16px -6px rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity .12s ease .25s;
}
[data-tip]:hover::after { opacity: 1; }
/* Gear sits at the board's top-right corner — drop the tip below and right-align
   it so it doesn't run past the board edge (which clips via overflow:hidden). */
.board-gear[data-tip]::after { top: calc(100% + 6px); bottom: auto; left: auto; right: 0; transform: none; }

/* ---------- Buttons ---------- */
button {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surf-2); color: var(--text-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 6px 12px;
  font: 500 12px/1.4 var(--font-sans);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { background: var(--surf-3); color: var(--text); }
button:focus-visible { outline: 2px solid var(--emerald-400); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: var(--emerald-400); color: #062018;
  border-color: var(--emerald-400); font-weight: 600;
  box-shadow: 0 8px 24px -8px rgba(52,211,153,0.6);
}
button.primary:hover { background: var(--emerald-300); color: #062018; }

button.danger {
  background: var(--surf-2); color: var(--rose-300);
  border-color: rgba(251,113,133,0.18);
}
button.danger:hover { background: rgba(251,113,133,0.08); color: var(--rose-400); border-color: rgba(251,113,133,0.30); }

button.ghost {
  background: transparent; border-color: transparent; color: var(--text-muted);
  padding: 4px 8px;
}
button.ghost:hover { background: transparent; color: var(--text); }

button.toggle { /* legacy class used in a few spots; render as default */ }

button.icon-only {
  width: 32px; height: 32px; padding: 0;
  justify-content: center; font-size: 14px;
}

/* ---------- Inputs ---------- */
select, input[type=text], input[type=number], input:not([type]), textarea {
  background: var(--surf-2); color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font: 400 13px/1.4 var(--font-sans);
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: rgba(52,211,153,0.45);
  box-shadow: 0 0 0 3px rgba(52,211,153,0.12);
}
input.bad { border-color: var(--rose-400); }
label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text-soft); font-size: 12px; white-space: nowrap; }

/* ---------- Tabs (pill nav, in the header) ---------- */
#tabs {
  display: inline-flex; gap: 2px;
  background: var(--surf-1);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 3px;
  margin-left: 8px;
}
#tabs button {
  background: transparent; border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  font: 500 12px/1.4 var(--font-sans);
  border-radius: var(--r-full);
}
#tabs button:hover { background: transparent; color: var(--text); }
#tabs button.active {
  background: var(--text); color: #0a0b0d;
}

/* ---------- Modal (Raw PGN editor) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-card {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  background: rgba(16,18,21,0.98); border: 1px solid var(--line-3);
  border-radius: var(--r-xl);
  box-shadow: 0 28px 64px -16px rgba(0,0,0,0.8);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font: 500 14px/1.4 var(--font-sans); color: var(--text); }
.modal-head .hint { font-weight: 400; margin-left: 6px; }

/* ---------- Commit (Add lines) confirm modal ---------- */
.commit-body { display: flex; flex-direction: column; gap: 12px; max-height: 52vh; overflow-y: auto; }
.commit-section-title { font: 600 10px/1 var(--font-sans); text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-muted); }
.commit-section-title.warn { color: var(--amber-300); }
.commit-section-title.danger { color: var(--rose-300); }
.commit-count { color: var(--emerald-300); background: rgba(52,211,153,0.10); border-radius: var(--r-sm); padding: 1px 6px; margin-left: 4px; }
.commit-count.danger { color: var(--rose-300); background: rgba(251,113,133,0.12); }
.commit-minus { color: var(--rose-400); font-weight: 700; flex-shrink: 0; }
.commit-removed { color: var(--rose-300); text-decoration: line-through; text-decoration-color: rgba(251,113,133,0.5); font-variant-numeric: tabular-nums; }
.commit-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.commit-lines li { display: flex; gap: 8px; align-items: baseline; font: 13px/1.45 var(--font-mono); }
.commit-plus { color: var(--emerald-400); font-weight: 700; flex-shrink: 0; }
.commit-san { font-variant-numeric: tabular-nums; }
.commit-more { color: var(--text-muted); font-style: italic; }
.commit-ctx { color: var(--text-muted); }
.ld-old { color: var(--text-muted); }     /* committed prefix — dimmed */
.ld-new { color: var(--amber-300); font-weight: 600; }   /* the tentative moves being added */
.commit-actions { justify-content: flex-end; gap: 8px; }

/* ---------- History modal (rep snapshots) ---------- */
.history-card { max-width: 640px; }
.history-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 56vh; overflow-y: auto;
  /* The row separators do the visual chunking; no border on the list itself. */
}
.history-row {
  display: grid;
  /* time | label/kind | plies | action buttons */
  grid-template-columns: 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font: 13px/1.4 var(--font-sans);
}
.history-row:last-child { border-bottom: none; }
.history-row.current {
  background: rgba(52,211,153,0.06);
  border-radius: var(--r-md);
}
.history-when {
  display: flex; flex-direction: column; gap: 2px;
}
.history-when-rel { color: var(--text); font-weight: 500; }
.history-when-abs { color: var(--text-muted); font-size: 11px; }
.history-meta {
  display: flex; gap: 6px; align-items: center;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.history-label { color: var(--text); font-style: italic; }
.history-kind {
  font: 600 10px/1 var(--font-sans);
  text-transform: uppercase; letter-spacing: 0.12em;
  padding: 3px 6px; border-radius: var(--r-sm);
  background: rgba(255,255,255,0.06); color: var(--text-soft);
}
.history-kind.manual    { background: rgba(96,165,250,0.14); color: #60a5fa; }
.history-kind.pre_restore { background: rgba(251,191,36,0.14); color: var(--amber-300); }
.history-kind.current   { background: rgba(52,211,153,0.16); color: var(--emerald-300); }
.history-actions { display: flex; gap: 4px; align-items: center; }
/* Inline action row: both <a> (download) and <button> (restore/delete) get
   the same compact ghost-button look here. .ghost is button-scoped elsewhere
   in the stylesheet, so we re-establish the same visual for anchors locally. */
.history-actions a,
.history-actions button {
  display: inline-flex; align-items: center; gap: 4px;
  font: 500 12px/1 var(--font-sans); color: var(--text-soft);
  padding: 6px 10px; border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}
.history-actions a:hover,
.history-actions button:hover:not(:disabled) {
  color: var(--text); background: rgba(255,255,255,0.04);
}
.history-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.history-actions .icon-only { padding: 6px; }
.history-empty {
  text-align: center; color: var(--text-muted);
  padding: 32px 8px; font-style: italic;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surf-1);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
/* The board panel stacks its cards/controls with one uniform rhythm (set on the
   container) instead of per-element margins, so spacing never looks haphazard. */
#tab-board { display: flex; flex-direction: column; gap: 14px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.card-title {
  margin: 0; font: 500 14px/1.4 var(--font-sans); color: var(--text);
  letter-spacing: -0.01em;
}
.card-eyebrow {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500;
}
.card-meta { font-size: 10px; color: var(--text-faint); }
.card-foot { font-size: 11px; color: var(--text-muted); padding-top: 4px; border-top: 1px solid var(--line-2); }

/* ---------- Repertoire card ---------- */
.savemsg { color: var(--emerald-400); font-size: 11px; }
.rep-pick { gap: 8px; }
.rep-pick #repSelect { flex: 1; min-width: 0; }
.rep-editor {
  display: flex; flex-direction: column; gap: 12px;
  margin-top: 4px; padding: 14px;
  background: var(--surf-2); border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.rep-editor.hidden { display: none; }
.rep-editor > label { gap: 6px; }
.rep-editor input, .rep-editor select { width: 100%; }
.rep-editor-actions { display: flex; align-items: center; gap: 8px; }
.rep-editor-spacer { flex: 1; }
.rep-editor-actions #btnDeleteRep.hidden { display: none; }

/* ---------- Modes card ---------- */
.modes-card .mode-name {
  font-family: var(--font-serif); font-style: italic;
  font-size: 20px; color: var(--text); line-height: 1.1;
  margin-top: 2px;
}
.modes-card .mode-desc {
  max-width: 60%; text-align: right;
  font-size: 11px; line-height: 1.4; color: var(--text-muted);
}
/* Two-mode segmented control (Spar | Analyze) */
.modeseg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  padding: 3px;
  background: var(--surf-1); border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.modeseg-btn {
  justify-content: center;
  background: transparent; border: none; border-radius: var(--r-md);
  padding: 8px 12px; color: var(--text-muted); font-weight: 500;
}
.modeseg-btn:hover { background: transparent; color: var(--text); }
.modeseg-btn.active {
  background: var(--surf-3); color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
#btnModeSpar.active    { color: var(--emerald-300); }
#btnModeSpar.active .lucide { color: var(--emerald-400); }
#btnModeAnalyze.active { color: var(--sky-300); }
#btnModeAnalyze.active .lucide { color: var(--sky-400); }

/* ---------- Repertoire-mode sub-tabs (Engine / Session / Tree) ---------- */
#repTabs {
  display: none; gap: 2px; align-self: flex-start;
  background: var(--surf-1); border: 1px solid var(--line);
  border-radius: var(--r-full); padding: 3px;
}
body[data-mode="analyze"] #repTabs { display: inline-flex; }
#repTabs button {
  background: transparent; border: none; color: var(--text-muted);
  padding: 6px 14px; font: 500 12px/1.4 var(--font-sans); border-radius: var(--r-full);
}
#repTabs button:hover { background: transparent; color: var(--text); }
#repTabs button.active { background: var(--text); color: #0a0b0d; }

/* In Repertoire mode, only the active sub-tab's card is shown */
body[data-mode="analyze"] #engineBox,
body[data-mode="analyze"] .log-card,
body[data-mode="analyze"] .tree-card,
body[data-mode="analyze"] .tools-row { display: none !important; }
body[data-mode="analyze"][data-reptab="engine"]  #engineBox  { display: flex !important; }
body[data-mode="analyze"][data-reptab="tree"]    .tree-card  { display: flex !important; }
body[data-mode="analyze"][data-reptab="tree"]    .tools-row  { display: flex !important; }

/* Base chip (used by named-line tags) */
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: var(--r-full);
  padding: 5px 12px;
  font: 500 12px/1.4 var(--font-sans);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--line);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { color: var(--text); }

/* ---------- Drill indicator ---------- */
#drillIndicator {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(90deg, rgba(52,211,153,0.08), rgba(52,211,153,0.02) 60%, transparent);
  border: 1px solid rgba(52,211,153,0.22);
  border-radius: var(--r-xl);
  font-size: 13px;
}
#drillIndicator .lucide { width: 14px; height: 14px; color: var(--emerald-400); flex-shrink: 0; }
#drillIndicator .drill-label {
  color: var(--emerald-300); font-weight: 500;
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
}
#drillIndicator code {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text); background: transparent; padding: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#drillIndicator a { cursor: pointer; font-size: 11px; flex-shrink: 0; }
#drillIndicator #gotoPinLink { margin-left: auto; color: var(--emerald-300); font-weight: 500; }
#drillIndicator #gotoPinLink:hover { color: var(--emerald-400); }
#drillIndicator #unpinLink { color: var(--text-muted); font-size: 13px; }
#drillIndicator #unpinLink:hover { color: var(--rose-300); }

/* ---------- Engine + Field analysis panel ---------- */
#engineBox {
  padding: 0;
  background: var(--surf-1);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  font-size: 13px;
  display: flex; flex-direction: column;
}
#engineBox > * { padding-left: 14px; padding-right: 14px; }

.eng-loading-row, .eng-miss-row {
  padding: 14px;
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); font-size: 12px; font-style: italic;
}

/* Refetch: keep the prior analysis on screen but dimmed (no collapse/flash) */
#engineBox.loading { opacity: 0.45; pointer-events: none; transition: opacity .15s ease; }

/* Skeleton placeholders — only on a cold start, shape-matched to the real panel */
.eng-skel {
  display: inline-block; border-radius: 4px;
  background: linear-gradient(90deg, var(--surf-2) 25%, var(--surf-3) 50%, var(--surf-2) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.3s ease-in-out infinite;
}
@keyframes skel-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
#engineBox .eng-skel-bar { display: block; height: 6px; margin: 0 14px 12px; border-radius: var(--r-full); }
#engineBox .skel-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
#engineBox .skel-cp { width: 40px; height: 14px; flex-shrink: 0; }
#engineBox .skel-line { flex: 1; height: 12px; }

/* Header: brand + score */
#engineBox .eng-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 12px; padding-bottom: 10px;
}
#engineBox .eng-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-soft); font-weight: 500;
}
#engineBox .eng-brand .lucide { color: var(--sky-400); }
#engineBox .eng-brand span:first-of-type { font-family: var(--font-sans); }
#engineBox .eng-depth {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-muted);
  background: var(--surf-2); padding: 1px 6px; border-radius: var(--r-sm);
  border: 1px solid var(--line);
}
#engineBox .eng-score {
  font-family: var(--font-mono); font-weight: 600; font-size: 16px;
  font-variant-numeric: tabular-nums; color: var(--text);
}

/* Horizontal eval bar */
#engineBox .eng-bar {
  height: 6px; margin: 0 14px 12px; padding: 0;
  background: linear-gradient(90deg, #0a0b0d 0%, var(--text-faint) 50%, var(--text) 100%);
  border-radius: var(--r-full); overflow: hidden; position: relative;
}
#engineBox .eng-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 50%; background: rgba(255,255,255,0.1);
  border-right: 2px solid var(--sky-400);
}

/* Section headers */
#engineBox .eng-section-title {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500;
  padding-top: 10px; padding-bottom: 6px;
  border-top: 1px solid var(--line-2);
}
#engineBox > .eng-section-title:first-of-type { border-top: none; padding-top: 0; }

/* Top engine PV lines */
#engineBox .eng-pvs { display: flex; flex-direction: column; gap: 4px; padding-bottom: 12px; }
#engineBox .eng-pv-row {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-soft);
}
#engineBox .eng-pv-cp {
  font-weight: 600; min-width: 48px;
  font-variant-numeric: tabular-nums;
  padding: 2px 7px; border-radius: var(--r-sm);
  background: var(--surf-2); border: 1px solid var(--line);
  color: var(--text-soft); font-size: 11px;
  text-align: center;
}
#engineBox .eng-pv-best .eng-pv-cp {
  color: var(--sky-300); background: rgba(56,189,248,0.10); border-color: rgba(56,189,248,0.30);
}
#engineBox .eng-pv-line {
  color: var(--text-soft); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#engineBox .eng-pv-best .eng-pv-line { color: var(--text); }
/* Clickable PV rows — play the line's first move */
#engineBox .eng-pv-row.clickable { cursor: pointer; padding: 2px 8px; margin: 0 -8px; border-radius: var(--r-sm); transition: background .1s; }
#engineBox .eng-pv-row.clickable:hover { background: var(--surf-2); }
#engineBox .eng-pv-row.clickable:hover .eng-pv-line { color: var(--text); }

/* Field distribution table */
#engineBox .field-table {
  display: flex; flex-direction: column; gap: 2px;
  padding-bottom: 12px;
}
#engineBox .field-row {
  display: grid;
  grid-template-columns: 58px 32px 46px 46px 1fr;
  align-items: center; gap: 8px;
  padding: 5px 0;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-soft);
}
#engineBox .field-row.clickable { cursor: pointer; padding: 5px 8px; margin: 0 -8px; border-radius: var(--r-sm); transition: background .1s; }
#engineBox .field-row.clickable:hover { background: var(--surf-2); }
#engineBox .field-san {
  font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#engineBox .field-freq {
  font-variant-numeric: tabular-nums; color: var(--text-soft);
}
#engineBox .field-games {
  font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 11px;
}
#engineBox .field-eval {
  font-variant-numeric: tabular-nums; font-size: 11px;
  padding: 1px 4px; border-radius: var(--r-sm);
  background: var(--surf-2); border: 1px solid var(--line);
  color: var(--text-muted); text-align: center;
}
#engineBox .field-eval.pos { color: var(--emerald-300); }
#engineBox .field-eval.neg { color: var(--rose-300); }
#engineBox .field-eval:empty { background: transparent; border: none; }

/* Win-rate: white | draw | black, split out (draw inferred) */
#engineBox .field-wr { display: flex; align-items: center; gap: 6px; }
#engineBox .wr-num { font-variant-numeric: tabular-nums; font-size: 10px; min-width: 26px; }
#engineBox .wr-num-w { text-align: right; color: var(--text-soft); }
#engineBox .wr-num-b { text-align: left; color: var(--text-muted); }
#engineBox .wr-bar {
  flex: 1; min-width: 48px; display: flex; height: 8px;
  border-radius: 3px; overflow: hidden; background: var(--surf-2);
}
#engineBox .wr-seg { height: 100%; }
#engineBox .wr-w { background: #e9e6df; }   /* white wins  */
#engineBox .wr-d { background: #6f6a63; }   /* draws (inferred) */
#engineBox .wr-b { background: #2a2722; }   /* black wins */

/* Prep designation — moves already in the user's repertoire */
.prep-mark { width: 11px; height: 11px; color: var(--emerald-400); flex-shrink: 0; }
#engineBox .field-san .prep-mark { margin-left: 4px; vertical-align: -1px; }
#engineBox .field-row.prep { background: rgba(52,211,153,0.06); }
#engineBox .field-row.prep .field-san { color: var(--emerald-300); }
#engineBox .eng-pv-row.prep .prep-mark { margin-left: 4px; }
#engineBox .eng-pv-row.prep .eng-pv-line { color: var(--emerald-300); }

/* ---------- Session log ---------- */
.log-card { gap: 0; padding: 0; }
.log-card .card-head { padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; }
/* Spar score: right vs wrong of your own moves this session */
.session-meta-group { display: flex; align-items: center; gap: 10px; }
.spar-score { display: inline-flex; align-items: center; gap: 8px; font: 600 11px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.spar-score:empty { display: none; }
.spar-score .sc-right { color: var(--emerald-300); }
.spar-score .sc-wrong { color: var(--rose-300); }
.log {
  list-style: none; margin: 0; padding: 0;
  max-height: 260px; overflow-y: auto;
  font-size: 13px;
}
.log:empty { display: none; }
.log:empty + * { display: none; }
/* Hide the whole Session card (incl. its header) until there's something to show */
.log-card:has(.log:empty) { display: none; }
.log-card.has-score { display: flex !important; }   /* keep visible to show the spar score */
.log-card:has(.spar-end:not(.hidden)) { display: flex !important; }  /* …and when announcing end-of-line */

/* End-of-line banner — tells you why Spar stopped instead of silently freezing */
.spar-end {
  display: block;
  margin: 10px 14px 0; padding: 10px 12px 10px 14px;
  font-size: 12.5px; line-height: 1.45; color: var(--text);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--emerald-400);
  background: rgba(52,211,153,0.08);
}
.spar-end.warn { border-left-color: var(--amber-400); background: rgba(251,191,36,0.08); }
.spar-end strong { color: var(--text-strong, #fff); margin-right: 4px; }
.spar-end b { font-family: var(--font-mono); font-weight: 600; }
.spar-end .spar-end-cta { color: var(--text-muted); }
.spar-end.hidden { display: none; }
.log .entry {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line-2);
  color: var(--text-soft);
  font-family: var(--font-mono); font-size: 12px;
}
.log .entry:last-child { border-bottom: none; }
.log .entry.clickable { cursor: pointer; }
.log .entry.clickable:hover { background: var(--surf-2); }
.log .entry.book { color: var(--text); }
.log .entry.me   { color: var(--text); }
.log .entry.oob  { color: var(--amber-300); font-style: italic; }
.log .entry-text { flex: 1; min-width: 0; }
.log .entry-icon { margin-left: auto; flex-shrink: 0; opacity: 0.85; }
.log .entry.book .entry-icon, .log .entry.me .entry-icon { color: var(--emerald-400); }
.log .entry.oob .entry-icon { color: var(--amber-400); }

/* Structured columns: [#] [WHO] [SAN] [FREQ%] [LABEL] [ICON] */
.log .log-num   { width: 26px; text-align: right; color: var(--text-faint); font-variant-numeric: tabular-nums; font-size: 11px; }
.log .log-who   { width: 36px; text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; color: var(--text-muted); font-family: var(--font-sans); font-weight: 500; }
.log .log-who.who-you { color: var(--emerald-400); }
.log .log-san   { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; min-width: 56px; }
.log .entry.me .log-san { color: var(--text); }
.log .entry.oob .log-san { color: var(--amber-300); }
.log .log-freq  { color: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.log .log-label {
  font-family: var(--font-sans); font-size: 10px; font-weight: 500;
  color: var(--emerald-300); background: rgba(52,211,153,0.10);
  border: 1px solid rgba(52,211,153,0.25);
  border-radius: var(--r-full); padding: 1px 8px;
}
.log .log-pre {
  font-family: var(--font-sans); font-size: 10px; font-weight: 500;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; width: 36px;
}
.log .entry.pre .log-san { color: var(--text-muted); }
.log .entry.pre { background: rgba(255,255,255,0.015); }

/* ---------- Status line ---------- */
.status {
  margin: 0; min-height: 0; font-size: 13px; color: var(--text-muted);
}
.status:empty { display: none; }
.status:not(:empty) {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--surf-1); border: 1px solid var(--line);
  border-left: 3px solid var(--line-3); border-radius: 0 var(--r-md) var(--r-md) 0;
}
.status.good { color: var(--emerald-300); border-left-color: var(--emerald-400); }
.status.bad  { color: var(--rose-300);    border-left-color: var(--rose-400); }
.status.warn { color: var(--amber-300);   border-left-color: var(--amber-400); }

/* ---------- Named lines + tree ---------- */
.tree-card { gap: 0; padding: 0; }
.tree-card .card-head { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tree-card .card-foot { padding: 8px 14px; }

.namedlines {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-2);
}
.namedlines:empty { display: none; }
.namedlines .chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px;
  background: var(--surf-2);
  border: 1px solid var(--line);
  color: var(--text-soft);
  border-radius: var(--r-full);
  padding: 3px 10px;
  cursor: pointer;
}
.namedlines .chip:hover { background: rgba(52,211,153,0.08); color: var(--emerald-300); border-color: rgba(52,211,153,0.30); }
.namedlines .chip .x { opacity: 0.4; padding: 0 2px; }
.namedlines .chip:hover .x { opacity: 1; color: var(--rose-300); }

.movelist {
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  max-height: 280px; overflow-y: auto;
}
.movelist .mv {
  cursor: pointer; padding: 1px 5px; border-radius: 4px;
  color: var(--text-soft); transition: background .1s, color .1s;
}
.movelist .mv:hover { background: var(--surf-2); color: var(--text); }
/* The whole line you're on is tinted; the current move is the strong highlight. */
.movelist .mv.on-path { background: rgba(52,211,153,0.10); color: var(--emerald-300); }
.movelist .mv.current { background: rgba(52,211,153,0.30); color: #d7fbe9; font-weight: 600; }
/* Off-book: played but not yet committed to the rep (amber, overrides the line tint) */
.movelist .mv.off-book { background: rgba(251,191,36,0.12); color: var(--amber-300); }
.movelist .mv.off-book.current { background: rgba(251,191,36,0.32); color: #fde68a; font-weight: 600; }
.movelist .num { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.movelist .treerow { white-space: nowrap; padding: 1px 0; }
.movelist .treerow.branch { border-left: 1px solid var(--line-2); margin-left: 4px; padding-left: 8px; }
/* The whole row (line) you're currently on */
.movelist .treerow.current-row { background: rgba(52,211,153,0.10); border-radius: 4px; }
.movelist .note { cursor: pointer; margin: 0 3px; font-size: 11px; color: var(--text-faint); }
.movelist .choicemark { color: var(--amber-300); font-size: 10px; font-style: italic; }
.movelist .label {
  font-family: var(--font-sans); font-size: 10px; font-weight: 500;
  color: var(--emerald-300); background: rgba(52,211,153,0.10);
  border: 1px solid rgba(52,211,153,0.25);
  border-radius: var(--r-sm); padding: 0 6px; margin: 0 4px;
}

/* ---------- Edit tools row ---------- */
.tools-row { gap: 6px; }
/* Destructive actions stay quiet at rest, pushed to the far edge */
#btnDeleteNode { margin-left: auto; color: var(--text-muted); }
#btnDeleteNode:hover { color: var(--rose-400); background: rgba(251,113,133,0.08); border-color: rgba(251,113,133,0.30); }
#btnRemoveUnsaved { margin-left: auto; color: var(--text-muted); }
#btnRemoveUnsaved:hover { color: var(--rose-400); background: rgba(251,113,133,0.08); border-color: rgba(251,113,133,0.30); }

/* ---------- Settings / PGN <details> ---------- */
details {
  margin-top: 12px;
  background: var(--surf-1); border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 0;
}
details > summary {
  list-style: none; cursor: pointer;
  padding: 10px 14px;
  color: var(--text-muted); font-size: 12px; font-weight: 500;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "▸ "; color: var(--text-faint);
  display: inline-block; transition: transform .1s;
}
details[open] > summary::before { content: "▾ "; }
details > summary:hover { color: var(--text); }
details > :not(summary) { padding: 0 14px 14px; }
details > .row:first-of-type { margin-top: 0; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin: 8px 0;
}
legend {
  color: var(--text-muted); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  padding: 0 6px; font-weight: 500;
}
/* Rating / time controls as toggle chips (in the gear modal) */
.boxes { display: flex; flex-wrap: wrap; gap: 6px; }
.boxes label {
  flex-direction: row; align-items: center; gap: 0;
  padding: 5px 12px; border-radius: var(--r-full);
  border: 1px solid var(--line); background: var(--surf-2);
  color: var(--text-muted); font-size: 12px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.boxes label:hover { color: var(--text); }
.boxes label input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.boxes label:has(input:checked) {
  background: rgba(52,211,153,0.12); color: var(--emerald-300); border-color: rgba(52,211,153,0.4);
}
.band-group { display: flex; flex-direction: column; gap: 8px; }
.band-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-muted); font-weight: 500; }
.band-group .inline { color: var(--text-soft); }
.band-group input[type=number] {
  width: 56px; background: var(--surf-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px 6px;
}

textarea#pgnArea, textarea#addPgnArea {
  width: 100%; min-height: 120px;
  background: var(--surf-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 10px 12px;
  font-family: var(--font-mono); font-size: 12px;
  resize: vertical;
}

/* Add-PGN dedup strategy chooser */
.addpgn-strat { display: flex; flex-direction: column; gap: 8px; }
.addpgn-strat-label { font-size: 12px; color: var(--text-soft); }
.addpgn-opt { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-lg); cursor: pointer; }
.addpgn-opt:hover { background: rgba(255,255,255,0.02); border-color: var(--line-3); }
.addpgn-opt:has(input:checked) { border-color: var(--emerald-400); background: rgba(52,211,153,0.08); }
.addpgn-opt input { margin-top: 2px; accent-color: var(--emerald-400); }
.addpgn-opt span { display: flex; flex-direction: column; gap: 2px; }
.addpgn-opt b { font-size: 13px; font-weight: 600; color: var(--text); }
.addpgn-opt i { font-style: normal; font-size: 12px; color: var(--text-muted); }
.addpgn-status:not(:empty) { font-size: 12px; color: var(--text-soft); padding: 2px 0; }
.addpgn-status.warn { color: var(--amber-300); }

/* ---------- Hint + rows ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.hint { color: var(--text-muted); font-size: 11px; line-height: 1.5; }
.hint code { background: var(--surf-2); padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: 11px; }

.fetch-oob { color: var(--rose-300); font-size: 14px; font-weight: 600; }
.transpose:empty { display: none; }
.transpose {
  margin-top: 8px; font-size: 12px; color: var(--sky-300);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: rgba(56,189,248,0.06); border: 1px solid rgba(56,189,248,0.18);
  border-radius: var(--r-md);
}

/* ---------- Move entry input full-width on its row ---------- */
#moveEntry { gap: 10px; }
#moveInput { flex: 1; min-width: 200px; font-family: var(--font-mono); font-size: 12px; }
#moveInput.bad { border-color: var(--rose-400); background: rgba(251,113,133,0.06); }

/* ---------- Audit ---------- */
#auditResult h3 {
  font-size: 11px; color: var(--text-muted);
  margin: 18px 0 6px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.16em;
}
.covnode {
  background: var(--surf-1); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 12px; margin: 8px 0; font-size: 13px;
}
.covnode .line { font-family: var(--font-mono); font-size: 12px; }
.covbar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.covbar > div { height: 100%; background: var(--emerald-400); }
.gap { color: var(--amber-300); font-family: var(--font-mono); font-size: 12px; }
#scoresList .inb { color: var(--emerald-400); }

/* ---------- Scrollbars ---------- */
.log::-webkit-scrollbar, .movelist::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-track, .movelist::-webkit-scrollbar-track { background: transparent; }
.log::-webkit-scrollbar-thumb, .movelist::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.log::-webkit-scrollbar-thumb:hover, .movelist::-webkit-scrollbar-thumb:hover { background: var(--line-3); }

/* ===========================================================================
   Onboarding wizard
   =========================================================================== */
.ob-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
  background: rgba(6,7,9,0.78); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.ob-card {
  width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: rgba(16,18,21,0.98); border: 1px solid var(--line-3);
  border-radius: var(--r-2xl);
  box-shadow: 0 40px 100px -24px rgba(0,0,0,0.85);
}
.ob-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: rgba(16,18,21,0.98);
}
.ob-brand { display: flex; align-items: baseline; gap: 8px; }
.ob-brand-name { font-family: var(--font-serif); font-style: italic; font-size: 18px; color: var(--text); }
.ob-brand-sub { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-muted); }
.ob-dots { display: flex; gap: 6px; }
.ob-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,0.16); transition: background 0.2s, transform 0.2s; }
.ob-dot.done { background: var(--emerald-500); }
.ob-dot.active { background: var(--emerald-400); transform: scale(1.35); }

.ob-content { padding: 32px 28px; }
.ob-step { display: flex; flex-direction: column; gap: 16px; }
.ob-step-center { align-items: center; text-align: center; padding: 24px 0; }

.ob-eyebrow { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--emerald-300); font-weight: 600; }
.ob-title { margin: 0; font-family: var(--font-serif); font-style: italic; font-weight: 400; font-size: 38px; line-height: 1.08; letter-spacing: -0.01em; color: #F3F4F6; }
.ob-lede { margin: 0; font-size: 15px; line-height: 1.6; color: var(--text-soft); max-width: 560px; }
.ob-lede em { color: var(--emerald-300); font-style: italic; }

/* premise / tip cards */
.ob-premise { display: grid; gap: 12px; margin-top: 8px; }
.ob-premise-card {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--r-xl);
  background: rgba(255,255,255,0.02); border: 1px solid var(--line);
}
.ob-premise-card .lucide { width: 20px; height: 20px; color: var(--emerald-400); flex-shrink: 0; margin-top: 1px; }
.ob-premise-h { font-size: 14px; font-weight: 600; color: var(--text); }
.ob-premise-p { font-size: 13px; line-height: 1.5; color: var(--text-muted); margin-top: 2px; }

/* first-move chooser */
.ob-firstmove { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.ob-fm-card {
  text-align: left; cursor: pointer;
  padding: 16px 18px; border-radius: var(--r-xl);
  background: rgba(255,255,255,0.02); border: 1px solid var(--line); color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.ob-fm-card:hover { background: rgba(255,255,255,0.04); border-color: var(--line-3); }
.ob-fm-card.sel { border-color: var(--emerald-400); background: rgba(52,211,153,0.08); box-shadow: 0 0 0 3px rgba(52,211,153,0.12); }
.ob-fm-label { font-family: var(--font-serif); font-style: italic; font-size: 24px; }
.ob-fm-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* single-select option groups */
.ob-group { margin-top: 6px; }
.ob-group-title { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--text-soft); margin-bottom: 8px; }
.ob-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.ob-opt {
  text-align: left; cursor: pointer; position: relative;
  padding: 12px 14px; border-radius: var(--r-lg);
  background: rgba(255,255,255,0.02); border: 1px solid var(--line); color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.ob-opt:hover { background: rgba(255,255,255,0.04); border-color: var(--line-3); }
.ob-opt.sel { border-color: var(--emerald-400); background: rgba(52,211,153,0.08); box-shadow: 0 0 0 3px rgba(52,211,153,0.12); }
.ob-opt.sel::after { content: ""; position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--emerald-400); }
.ob-opt-name { font-size: 14px; font-weight: 600; }
.ob-opt-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.ob-opt-line { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-top: 8px; }

/* footer */
.ob-foot { display: flex; align-items: center; gap: 10px; margin-top: 24px; }
.ob-foot-spacer { flex: 1; }
.ob-btn { cursor: pointer; border-radius: var(--r-lg); padding: 10px 18px; font: 600 14px/1 var(--font-sans); border: 1px solid transparent; }
.ob-btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--line); }
.ob-btn-ghost:hover { color: var(--text); border-color: var(--line-3); }
.ob-btn-primary { background: var(--emerald-400); color: #062018; border-color: var(--emerald-400); }
.ob-btn-primary:hover { filter: brightness(1.08); }
.ob-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* build + done */
.ob-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.12); border-top-color: var(--emerald-400); animation: ob-spin 0.7s linear infinite; }
@keyframes ob-spin { to { transform: rotate(360deg); } }
.ob-build-status { text-align: center; }
.ob-build-err { color: var(--rose-300); }
.ob-check { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(52,211,153,0.14); color: var(--emerald-300); }
.ob-check .lucide { width: 26px; height: 26px; stroke-width: 2.5; }

/* onboarding coach popover (shown on first drill in the app) */
.ob-coach {
  position: fixed; z-index: 150; max-width: 300px;
  background: rgba(16,18,21,0.98); border: 1px solid var(--emerald-400);
  border-radius: var(--r-xl); padding: 14px 16px;
  box-shadow: 0 24px 60px -18px rgba(0,0,0,0.8), 0 0 0 4px rgba(52,211,153,0.10);
}
.ob-coach-h { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.ob-coach-p { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); }
.ob-coach-x { margin-top: 10px; }

@media (max-width: 560px) {
  .ob-content { padding: 24px 18px; }
  .ob-title { font-size: 30px; }
  .ob-firstmove { grid-template-columns: 1fr; }
}

/* onboarding: an option blocked by a conflicting pick */
.ob-opt.disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.4); }
.ob-opt.disabled:hover { background: rgba(255,255,255,0.02); border-color: var(--line); }
.ob-opt-clash { display: flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 11px; color: var(--amber-300); }
.ob-opt-clash .lucide { width: 11px; height: 11px; }

/* ===========================================================================
   Scores (recall report)
   =========================================================================== */
.report-head { margin-bottom: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.scores-replabel { display: inline-flex; flex-direction: column; gap: 5px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.scores-replabel select { background: var(--surf-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 10px; font: 500 13px/1.2 var(--font-sans); min-width: 200px; }
.report-eyebrow { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
.report-title { margin: 4px 0 0; font-family: var(--font-serif); font-style: italic; font-weight: 400; font-size: 34px; line-height: 1.1; color: #F3F4F6; }
.report-sub { margin: 6px 0 0; font-size: 14px; line-height: 1.55; color: var(--text-muted); max-width: 620px; }

.scores-empty { color: var(--text-muted); font-size: 14px; padding: 14px 0; }

/* bucket colours (shared by the overview bar, dots, and per-row bars) */
.sb-mastered { background: var(--emerald-400); }
.sb-learning { background: var(--amber-400); }
.sb-weak     { background: var(--rose-400); }
.sb-untested { background: rgba(255,255,255,0.16); }

.scores-overview { margin-bottom: 18px; }
.scores-bar { display: flex; height: 10px; border-radius: 9999px; overflow: hidden; background: rgba(255,255,255,0.06); }
.scores-bar > span { display: block; height: 100%; }
.scores-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-soft); }
.scores-leg { display: inline-flex; align-items: center; gap: 6px; }
.scores-leg .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.scores-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.scores-segment { display: inline-flex; gap: 2px; padding: 3px; background: var(--surf-1); border: 1px solid var(--line); border-radius: var(--r-full); }
.scores-segment button { background: transparent; border: none; color: var(--text-muted); padding: 5px 12px; font: 500 12px/1.2 var(--font-sans); border-radius: var(--r-full); cursor: pointer; }
.scores-segment button:hover { color: var(--text); }
.scores-segment button.active { background: var(--text); color: #0a0b0d; }
.scores-sortlabel { font-size: 12px; color: var(--text-muted); display: inline-flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.scores-sortlabel select { background: var(--surf-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-full); padding: 7px 12px; font: 500 12px/1.2 var(--font-sans); }
.scores-refresh { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }

.scores-table { border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; }
.scores-row {
  display: grid; grid-template-columns: 1fr 72px 52px 150px 52px; gap: 12px; align-items: center;
  padding: 9px 14px; border-bottom: 1px solid var(--line-2);
}
.scores-row:last-child { border-bottom: none; }
.scores-thead { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); padding-top: 8px; padding-bottom: 8px; }
.scores-thead:hover { background: transparent; }
.scores-table .scores-row:not(.scores-thead):hover { background: rgba(255,255,255,0.02); }
.sc-line { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-move { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--text); }
.sc-num { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.sc-mastery { display: flex; align-items: center; gap: 8px; }
.sc-mbar { flex: 1; height: 6px; border-radius: 9999px; background: rgba(255,255,255,0.08); overflow: hidden; display: block; }
.sc-mbar > span { display: block; height: 100%; border-radius: 9999px; }
.sc-mpct { font-family: var(--font-mono); font-size: 11px; color: var(--text-soft); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.sc-untested { font-size: 11px; color: var(--text-faint); font-style: italic; }
.sc-last { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); text-align: right; }
.scores-more { margin-top: 12px; font-size: 12px; color: var(--text-muted); text-align: center; }
