:root {
  --bg: #1e1e22;
  --panel: #26262c;
  --panel-2: #2d2d34;
  --text: #e6e6ea;
  --muted: #9a9aa3;
  --accent: #7cc4ff;
  --bad: #ff7a7a;
  --good: #84e09a;
  --warn: #f0c674;

  --light-sq: #ebd2a0;
  --dark-sq:  #a17a52;
  --sel-sq:   #f6e36b;
  --hint:     rgba(60, 140, 90, 0.55);
  --last-from: rgba(247, 235, 100, 0.45);
  --last-to:   rgba(247, 235, 100, 0.65);
  --check:    rgba(255, 80, 80, 0.65);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Prevent rogue overflow from any panel pushing the page into
     horizontal scroll on phones. */
  overflow-x: hidden;
}
.app {
  max-width: 1340px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
}
.sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.layout {
  display: grid;
  /* Right column has a minimum width so the board can't squeeze it.
     Middle column is `auto` (sized by the board's --board-size). */
  grid-template-columns: 190px auto minmax(280px, 1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* --- Board --- */
.board-wrap {
  display: inline-grid;
  grid-template-columns: 22px 1fr;
  /* Row 1: eval-bar + analysis-toggle button (the "board top bar").
     Row 2: rank-labels + board.
     Row 3: file-labels. */
  grid-template-rows: auto 1fr 22px;
  gap: 4px;
  width: var(--board-size, 572px);
  max-width: 100%;
}
.board-top-bar {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 2px;
  /* When the eval bar is hidden, the magnifier still hugs the right
     edge of the board (matching the board's top-right corner). */
  justify-content: flex-end;
}
.board-stack {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  width: 100%;
}
.resize-handle {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 20px;
  height: 20px;
  z-index: 12;
  cursor: nwse-resize;
  pointer-events: auto;
  background: linear-gradient(135deg, transparent 0 45%, var(--accent) 45% 60%, transparent 60% 70%, var(--accent) 70% 85%, transparent 85%);
  border-radius: 0 0 4px 0;
  touch-action: none;
}
.resize-handle:hover { filter: brightness(1.25); }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 2px solid #111;
  user-select: none;
  box-shadow: 0 6px 22px rgba(0,0,0,0.4);
  /* Establish the board as a size container so squares can size
     pieces relative to the actual board width (one square ≈ 12.5cqw). */
  container-type: inline-size;
}
.arrow-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}
.rank-labels {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding-right: 4px;
}
.rank-labels span { display: flex; align-items: center; justify-content: flex-end; }
.file-labels {
  grid-column: 2;
  grid-row: 3;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Pieces scale with the board itself rather than the viewport so
     resizing the board (or shrinking the column) keeps proportions
     consistent. 9cqw ≈ 72% of a single square's width. The clamp
     fallback covers older browsers without container query units. */
  font-size: clamp(20px, 9cqw, 64px);
  line-height: 1;
  cursor: pointer;
  /* Eliminates the 300ms tap delay on mobile and prevents double-tap-
     to-zoom from interfering with successive square taps. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(124, 196, 255, 0.18);
}
@supports not (font-size: 1cqw) {
  .square { font-size: clamp(28px, 7vw, 52px); }
}
.square.light { background: var(--light-sq); }
.square.dark  { background: var(--dark-sq); }
.square.selected { box-shadow: inset 0 0 0 4px var(--sel-sq); }
.square.last-from::before,
.square.last-to::before {
  content: ""; position: absolute; inset: 0;
  pointer-events: none;
}
.square.last-from::before { background: var(--last-from); }
.square.last-to::before   { background: var(--last-to); }
.square .user-hl {
  position: absolute; inset: 0;
  background: rgba(155, 124, 214, 0.55);
  pointer-events: none;
}
.square.hint-from { box-shadow: inset 0 0 0 5px rgba(124, 196, 255, 0.95); }
.square.hint-to   { box-shadow: inset 0 0 0 5px rgba(124, 196, 255, 0.55); }
/* hint-from + selected: hint wins */
.square.hint-from.selected { box-shadow: inset 0 0 0 5px rgba(124, 196, 255, 0.95); }
.square.check-sq::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at center, var(--check) 0%, transparent 65%);
  pointer-events: none;
}
.square .hint {
  position: absolute;
  width: 32%; height: 32%;
  border-radius: 50%;
  background: var(--hint);
  pointer-events: none;
}
.square .hint.capture {
  width: 86%; height: 86%;
  background: transparent;
  border: 5px solid var(--hint);
  box-sizing: border-box;
}
.piece {
  position: relative;
  z-index: 1;
  pointer-events: none;
  text-shadow:
    0 1px 0 rgba(0,0,0,0.25),
    0 2px 4px rgba(0,0,0,0.15);
}
.piece.white { color: #fafafa; -webkit-text-stroke: 1.2px #222; }
.piece.black { color: #1b1b1b; }

/* --- Panels --- */
.panel {
  background: var(--panel);
  border: 1px solid #33333a;
  border-radius: 10px;
  padding: 14px 16px;
}
.panel + .panel { margin-top: 14px; }
.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
input[type="text"], select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #44444d;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
}
input[type="text"] { flex: 1 1 140px; max-width: 180px; }
select { flex: 0 0 auto; }
button {
  background: #34343c; color: var(--text);
  border: 1px solid #44444d; border-radius: 6px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}
button:hover { background: #3e3e47; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  color: #0b1f30;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.danger {
  background: transparent;
  color: var(--bad);
  border-color: rgba(255, 122, 122, 0.5);
  font-weight: 600;
}
button.danger:hover { background: rgba(255, 122, 122, 0.12); }

.site-footer {
  margin: 22px 0 8px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.site-footer span { margin: 0 8px; opacity: 0.6; }

.legal h2 { font-size: 15px; margin: 18px 0 6px; }
.legal p { font-size: 13px; line-height: 1.55; color: var(--text); margin: 6px 0; }
.legal ul { font-size: 13px; line-height: 1.55; padding-left: 20px; margin: 6px 0; }
.legal li { margin: 4px 0; }
.legal a { color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: 110px 140px 110px 110px auto;
  gap: 10px;
  align-items: end;
  justify-content: start;
}
.form-grid input[type="text"],
.form-grid select {
  width: 100%;
  max-width: none;
  flex: none;
  box-sizing: border-box;
}
.form-grid input[type="number"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #44444d;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
}

.progress-bar {
  height: 6px;
  background: #1a1a1f;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.error-text { color: var(--bad); font-size: 12px; margin-top: 6px; }
.sync-info {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.sync-info.sync-success { color: var(--accent); }

/* Mirrors .sync-info, but for the training-session status row. */
.training-info {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.training-info.training-success { color: var(--accent); }
.training-info a { color: inherit; text-decoration: underline; }

/* --- Puzzle list --- */
.puzzle-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
}
.puzzle-item {
  display: grid;
  /* 6 cols: rank | swing | meta | last-attempt | game-link | side-dot.
     last-attempt is auto so it collapses to 0 when there's no badge to
     render (i.e. for puzzles the user has never tried). */
  grid-template-columns: 24px 80px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid #393941;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
/* Per-FEN attempt history pill — shown when the user has tried this
   puzzle before. Color codes pass (green) vs fail (red); kept small and
   monospace-ish so it doesn't visually compete with the swing label. */
.last-attempt {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid #393941;
  color: var(--muted);
  white-space: nowrap;
}
.last-attempt.pass { color: var(--good); border-color: rgba(132, 224, 154, 0.35); }
.last-attempt.fail { color: var(--bad);  border-color: rgba(255, 122, 122, 0.35); }
.puzzle-game-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.puzzle-game-link:hover {
  background: rgba(124, 196, 255, 0.12);
  border-color: rgba(124, 196, 255, 0.35);
  text-decoration: none;
}
.puzzle-item:hover { background: #353540; }
.puzzle-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.puzzle-item .rank { color: var(--muted); }
.puzzle-item.solved { border-color: rgba(132, 224, 154, 0.55); }
.puzzle-item .solved-check {
  color: var(--good);
  font-weight: 700;
  margin-right: 4px;
}
.err-details-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.err-raw {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  white-space: pre-wrap;
}
.puzzle-item .swing { font-weight: 600; color: var(--warn); font-family: ui-monospace, monospace; }
.puzzle-item .swing.mate { color: var(--bad); }
.puzzle-item .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.puzzle-item .side-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #ddd; border: 1px solid #888;
}
.puzzle-item .side-dot.black { background: #1a1a1a; border-color: #555; }

/* --- Ranked / By-Game segmented toggle --- */
.view-toggle {
  display: inline-flex;
  gap: 0;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 1px solid #393941;
  border-radius: 7px;
  padding: 2px;
}
.view-toggle button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
}
.view-toggle button.active {
  background: var(--accent);
  color: #0e0e12;
  font-weight: 600;
}
.view-toggle .view-count {
  margin-left: 6px;
  opacity: 0.75;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.view-toggle button.active .view-count {
  opacity: 0.85;
}
.view-toggle .view-count:empty {
  display: none;
}
.solved-progress {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.solved-progress:empty {
  display: none;
}
.view-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.view-toggle-row .view-toggle {
  /* The wrapper handles spacing now, so the inner toggle drops its own
     bottom margin to keep the row a single horizontal band. */
  margin-bottom: 0;
}
.btn-back-to-games {
  background: var(--panel-2);
  border: 1px solid #393941;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-back-to-games:hover {
  background: #353540;
  color: var(--text);
  border-color: #4a4a55;
}
.game-focus-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid #393941;
  border-radius: 7px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.game-focus-header .game-focus-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.by-game-result-filter {
  background: var(--panel-2);
  border: 1px solid #393941;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.by-game-result-filter:hover {
  background: #353540;
  color: var(--text);
  border-color: #4a4a55;
}
.by-game-result-filter:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--text);
}
.by-game-result-filter[hidden] {
  display: none;
}

/* --- Ranked-view filter & sort controls ---
   A small inline cluster of <select>s shown only when the Ranked view is
   active. Uses the same visual language as the By-Game result filter so
   the two control rows feel like a single family. */
.ranked-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.ranked-controls[hidden] {
  display: none;
}
.ranked-filter {
  background: var(--panel-2);
  border: 1px solid #393941;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ranked-filter:hover {
  background: #353540;
  color: var(--text);
  border-color: #4a4a55;
}
.ranked-filter:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--text);
}

/* --- By-Game grouped rows --- */
.game-row {
  background: var(--panel-2);
  border: 1px solid #393941;
  border-radius: 7px;
  overflow: hidden;
}
.game-row.contains-active {
  border-color: var(--accent);
}
.game-row-header {
  display: grid;
  grid-template-columns: 90px auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.game-row-header:hover { background: #353540; }
.game-row .date { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.game-row .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-row .opp .opp-prefix { color: var(--muted); }
.game-row .tc {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  white-space: nowrap;
}
.game-row .mistake-count { color: var(--muted); font-size: 12px; }
.result-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  font-family: ui-monospace, monospace;
}
.result-badge.w { background: rgba(132, 224, 154, 0.16); color: var(--good); border: 1px solid rgba(132, 224, 154, 0.45); }
.result-badge.l { background: rgba(255, 122, 122, 0.16); color: var(--bad);  border: 1px solid rgba(255, 122, 122, 0.45); }
.result-badge.d { background: rgba(255, 207, 102, 0.16); color: var(--warn); border: 1px solid rgba(255, 207, 102, 0.45); }
.result-badge.unknown { background: #2a2a32; color: var(--muted); border: 1px solid #393941; }

.game-puzzles {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0 0;
}
.game-puzzle-item {
  display: grid;
  /* grank | ply | swing | played | last-attempt | game-link | dot */
  grid-template-columns: 36px 48px 70px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid #393941;
}
.game-puzzle-item:hover { background: #353540; }
.game-puzzle-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.game-puzzle-item.solved { border-color: rgba(132, 224, 154, 0.55); }
.game-puzzle-item .grank {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.game-puzzle-item .ply { color: var(--muted); font-family: ui-monospace, monospace; }
.game-puzzle-item .swing { font-weight: 600; color: var(--warn); font-family: ui-monospace, monospace; }
.game-puzzle-item .swing.mate { color: var(--bad); }
.game-puzzle-item .played { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Status / feedback --- */
.status { font-size: 14px; margin-bottom: 8px; }
.status .turn  { color: var(--accent); font-weight: 600; }
.status .check { color: var(--bad);    font-weight: 600; }
.status .over  { color: var(--good);   font-weight: 600; }
.status .puzzle-index {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.feedback {
  display: none;
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;
  margin-top: 4px;
}
.feedback.show { display: block; }
.feedback.ok    { background: rgba(132, 224, 154, 0.13); border: 1px solid rgba(132, 224, 154, 0.45); color: var(--good); }
.feedback.bad   { background: rgba(255, 122, 122, 0.13); border: 1px solid rgba(255, 122, 122, 0.45); color: var(--bad); }
.feedback.info  { background: rgba(124, 196, 255, 0.10); border: 1px solid rgba(124, 196, 255, 0.40); color: var(--accent); }

.puzzle-progress {
  display: flex; flex-direction: column; gap: 6px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  margin-top: 4px;
}
.puzzle-move-bar-wrap {
  display: flex; align-items: center; gap: 8px; width: 100%;
}
.puzzle-move-bar {
  flex: 1; height: 5px; border-radius: 3px;
  background: #3a3a44;
  overflow: hidden;
}
.puzzle-move-bar-fill {
  height: 100%; border-radius: 3px;
  background: var(--accent);
  width: 0%;
  transition: width 0.25s ease, background 0.2s;
}
.puzzle-move-counter {
  font-size: 11px; color: var(--muted); white-space: nowrap;
}

.controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.auto-next {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  margin: 0;
  cursor: pointer;
  user-select: none;
}
/* Hide the real checkbox; the visible track+thumb do the job */
.auto-next input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: inline-flex;
  width: 28px; height: 16px;
  background: #4a4a56;
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
  cursor: pointer;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.auto-next input:checked + .toggle-track { background: var(--accent); }
.auto-next input:checked + .toggle-track .toggle-thumb { transform: translateX(12px); }

/* Inline FEN import row */
.fen-import-row {
  display: none;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.fen-import-row.open { display: flex; }
.fen-import-row input[type="text"] {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid #4a4a56;
  border-radius: 4px;
  color: var(--text);
  min-width: 0;
}
.fen-import-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.fen-import-row .btn-cancel {
  background: transparent;
  border: 1px solid #4a4a56;
  color: var(--muted);
  padding: 3px 7px;
  font-size: 13px;
  line-height: 1;
}
.fen-import-row .btn-cancel:hover { color: var(--text); background: #3e3e47; }
.buffering-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.buffering-note .spin {
  width: 11px; height: 11px;
  border: 2px solid #4a4a56;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.moves {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; line-height: 1.7;
  max-height: 180px; overflow-y: auto;
}
.moves .ply  { color: var(--muted); margin-right: 6px; }
.moves .move { margin-right: 10px; }

/* --- Move-history panel (left of board) --- */
.moves-panel { position: sticky; top: 16px; }
.move-history {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 10px;
}
.mv-row {
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  gap: 4px;
  align-items: stretch;
}
.mv-row .num { color: var(--muted); display: flex; align-items: center; }
.mv {
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.mv:hover { background: var(--panel-2); }
.mv.active { background: none; color: var(--accent); font-weight: 600; }
.move-history .empty { color: var(--muted); }

/* --- Move tree (analysis-mode variations) --- */
.tree-mv {
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  display: inline-block;
}
.tree-mv:hover { background: var(--panel-2); }
.tree-mv.active { background: none; color: var(--accent); font-weight: 600; }
.tree-variation {
  margin-left: 18px;
  padding: 2px 4px;
  color: var(--muted);
  border-left: 2px solid #3a3a44;
  font-size: 12px;
  line-height: 1.5;
}
.tree-variation .tree-mv { color: var(--text); }
.tree-variation .num.inline { color: var(--muted); margin-right: 2px; }
.tree-divider {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 8px 0 4px;
  text-align: center;
  opacity: 0.7;
}
.tree-elide { color: var(--muted); }
.tree-row .num { color: var(--muted); }
button.full { width: 100%; }
.preview-tag {
  display: none;
  font-size: 11px;
  color: var(--warn);
  margin-bottom: 8px;
}
.preview-tag.show { display: block; }

.fen {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: var(--muted);
  word-break: break-all; user-select: all;
}

details > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

a { color: var(--accent); }

/* --- Top bar + settings popover --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.config-wrap { position: relative; flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid #33333a;
  border-radius: 999px;
  padding: 4px 4px 4px 12px;
  font-size: 12px;
}
.user-chip[hidden] { display: none; }
.user-email {
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip .cfg-btn { font-size: 12px; padding: 5px 10px; }
.cfg-btn {
  font-size: 18px;
  line-height: 1;
  padding: 8px 11px;
}
.cfg-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid #33333a;
  border-radius: 10px;
  padding: 10px;
  z-index: 50;
  min-width: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.cfg-sep {
  height: 1px;
  background: #33333a;
  margin: 10px -10px;
}
.cfg-hint {
  font-size: 12px;
  color: var(--muted);
  margin: -4px 0 8px 0;
}
.cfg-linked-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.cfg-linked-rows:empty {
  display: none;
}
.cfg-linked-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
}
.cfg-linked-row .cfg-linked-source {
  color: var(--muted);
  min-width: 70px;
  font-size: 12px;
}
.cfg-linked-row .cfg-linked-username {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.cfg-linked-row .cfg-linked-remove {
  background: transparent;
  border: 1px solid #44444c;
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.cfg-linked-row .cfg-linked-remove:hover {
  color: var(--bad);
  border-color: var(--bad);
}
.cfg-linked-add {
  display: flex;
  gap: 6px;
  align-items: center;
}
.cfg-linked-add select,
.cfg-linked-add input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #33333a;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
}
.cfg-linked-add select { min-width: 80px; }
.cfg-linked-add input { flex: 1; min-width: 0; }
.cfg-linked-add button {
  background: var(--accent);
  color: #0d2030;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.cfg-linked-add button:hover { filter: brightness(1.08); }
.cfg-linked-add button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.cfg-linked-err {
  color: var(--bad);
  font-size: 12px;
  margin-top: 6px;
}
.cfg-linked-err[hidden] { display: none; }
.cfg-pop[hidden] { display: none; }
.cfg-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.cfg-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: flex-start;
  margin-bottom: 6px;
}
.cfg-opt:last-child { margin-bottom: 0; }
.cfg-opt.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.cfg-prev {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.cfg-prev img {
  max-width: 24px; max-height: 24px;
  width: auto; height: auto;
  object-fit: contain;
  image-rendering: pixelated;
}
.piece-img {
  width: 80%; height: 80%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

/* --- Analysis mode: eval bar + lines panel ---
   The eval bar runs horizontally along the top of the board, with the
   magnifying-glass / analysis toggle anchored at its right edge. */
.board-area {
  display: block;
}
.eval-bar {
  flex: 1 1 auto;
  height: 22px;
  background: #1a1a1f;
  border: 1px solid #44444d;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
}
.eval-bar[hidden] { display: none; }
/* eval-fill represents White's portion of the bar, growing from the
   left edge (or from the right when the board is flipped). */
.eval-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 50%;
  background: linear-gradient(to right, #fafafa, #e6e6e6);
  transition: width 0.35s ease;
}
.eval-bar.flipped .eval-fill {
  left: auto;
  right: 0;
  background: linear-gradient(to left, #fafafa, #e6e6e6);
}
.eval-bar.mate-w .eval-fill { background: linear-gradient(to right, #84e09a, #c0f0ce); }
.eval-bar.mate-b .eval-fill { background: linear-gradient(to right, #ff7a7a, #ffb0b0); }
.eval-bar.flipped.mate-w .eval-fill { background: linear-gradient(to left, #84e09a, #c0f0ce); }
.eval-bar.flipped.mate-b .eval-fill { background: linear-gradient(to left, #ff7a7a, #ffb0b0); }
.eval-text {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
  z-index: 2;
  padding: 0 7px;
}
.eval-text.left  { left: 0; }
.eval-text.right { right: 0; }
.eval-text.on-white { color: #1a1a1a; }
.eval-text.on-black { color: #f0f0f0; }

/* Icon button (magnifier) — sized to match the text buttons in .controls */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 9px;
  line-height: 1;
}
.icon-btn svg {
  display: block;
  width: 14px;
  height: 14px;
}

/* Analysis panel — compact list of top-N Stockfish lines.
   Each row is "eval | moves"; clicking a move replays the line and
   triggers a fresh multipv search from that position. */
.analysis-panel[hidden] { display: none; }
.ana-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ana-line {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  align-items: baseline;
  background: var(--panel-2);
  border: 1px solid #393941;
  border-radius: 6px;
  padding: 5px 8px;
}
.ana-line.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.ana-line .ana-eval {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}
.ana-line .ana-eval.positive { color: var(--good); }
.ana-line .ana-eval.negative { color: var(--bad); }
.ana-line .ana-moves {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  word-spacing: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ana-line .ana-move {
  cursor: pointer;
  padding: 0 3px;
  border-radius: 3px;
  display: inline-block;
}
.ana-line .ana-move:hover { background: rgba(124, 196, 255, 0.18); }
.ana-line .ana-move.active { background: var(--accent); color: #0b1f30; font-weight: 600; }
.ana-empty { color: var(--muted); font-style: italic; font-size: 12px; padding: 4px 0; }
.ana-status { color: var(--muted); font-size: 12px; padding: 4px 2px; }

/* When analysis mode is active, the three "regular" right-column panels
   step aside so the analysis panel + board fill the view. */
body.analysis-active #panel-analyse,
body.analysis-active #panel-current,
body.analysis-active #panel-mistakes { display: none; }

/* Magnifier/analysis-toggle button visual state. */
#btn-analysis-mode.active {
  background: var(--accent);
  color: #0b1f30;
  border-color: var(--accent);
}

/* --- Mobile-responsive overrides ---
   Activates roughly at phone widths. The board should fill the
   viewport, the resize handle is hidden (touch users can't easily
   use it), and the puzzle/game rows reflow to a denser layout so
   nothing overflows horizontally. */
@media (max-width: 600px) {
  .app {
    padding: 14px 10px 36px;
  }
  h1 { font-size: 18px; }
  .sub { font-size: 12px; margin-bottom: 14px; }
  /* Allow the topbar to wrap on very narrow screens so the user chip
     and gear can drop below the title rather than overflow. */
  .topbar { gap: 8px; flex-wrap: wrap; }
  .cfg-btn { padding: 8px 11px; font-size: 16px; min-height: 40px; min-width: 40px; }
  /* Truncate the email more aggressively on phones so the chip + gear
     stay within the viewport even when both are visible. */
  .user-email { max-width: 110px; font-size: 11px; }

  .layout {
    gap: 14px;
  }

  /* The board takes the full available width on phones. The saved
     --board-size from desktop sessions is ignored thanks to the !important
     override on width below. */
  .board-wrap {
    width: 100% !important;
    grid-template-columns: 14px 1fr;
    grid-template-rows: auto 1fr 16px;
    gap: 2px;
    display: grid;
  }
  .rank-labels, .file-labels { font-size: 9px; }
  .rank-labels { padding-right: 2px; }

  /* The drag-to-resize handle is mouse-oriented; hide it on touch
     viewports so it doesn't sit on top of the bottom-right square. */
  .resize-handle { display: none; }

  .board-top-bar {
    gap: 6px;
    min-height: 28px;
  }
  .eval-bar { height: 18px; }

  /* Panels: tighten padding so they don't eat horizontal space. */
  .panel { padding: 10px 12px; border-radius: 8px; }
  .panel h2 { font-size: 11px; margin-bottom: 10px; }

  /* The moves-panel sits above the board on mobile (the layout
     already collapses to a single column at 900px). Keep its
     max-height in check so it doesn't dominate the screen. */
  .moves-panel { position: static; }
  .move-history { max-height: 180px; }

  /* The analyse form already collapses to 1fr at 480px. Buttons in
     the controls row stay tappable; iOS guideline is ~44px tall. */
  button {
    padding: 10px 14px;
    font-size: 14px;
    min-height: 40px;
  }
  .controls { gap: 8px; }
  .controls button { flex: 0 1 auto; }
  /* Form-grid buttons (Analyse / Sync / Train) should stretch full-
     width when the form collapses to 1fr — easier to tap and matches
     the stacked input widths above. */
  .form-grid button { width: 100%; }

  /* Auto-next toggle: bump the visible track and the surrounding tap
     area so it's reliable to flip on touchscreens. */
  .auto-next { padding: 6px 4px; font-size: 13px; }
  .toggle-track { width: 36px; height: 20px; }
  .toggle-thumb { width: 16px; height: 16px; }
  .auto-next input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

  /* Icon buttons (flip / analysis toggle) at the top of the board need
     a comfortable tap target. Match the iOS 40-44px minimum. */
  .icon-btn { padding: 9px 11px; min-height: 36px; min-width: 36px; }
  .icon-btn svg { width: 16px; height: 16px; }

  /* Puzzle-list rows: collapse the 6-column grid to a 3-row layout
     where the swing + side-dot + checkmark sit on the first row, the
     meta line spans the second row, and the last-attempt badge + game
     link share the third row. This keeps the row readable at 360px
     without truncating. */
  .puzzle-list { max-height: 320px; }
  .puzzle-item {
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas:
      "rank dot swing link"
      "meta meta meta meta"
      "last last last link";
    column-gap: 8px;
    row-gap: 2px;
    padding: 8px;
    font-size: 13px;
  }
  .puzzle-item .rank        { grid-area: rank; }
  .puzzle-item .side-dot    { grid-area: dot; }
  .puzzle-item .swing       { grid-area: swing; }
  .puzzle-item .meta        { grid-area: meta; font-size: 11px; white-space: normal; }
  .puzzle-item .last-attempt { grid-area: last; justify-self: start; }
  .puzzle-item .puzzle-game-link { grid-area: link; font-size: 11px; }

  /* By-game rows: same treatment - collapse to a wrappable layout.
     Column count must match the rendered children:
     date | result-badge | opp | tc | mistake-count = 5 columns. */
  .game-row-header {
    grid-template-columns: auto auto 1fr auto auto;
    column-gap: 8px;
    row-gap: 2px;
    padding: 8px;
    font-size: 12px;
  }
  .game-row .tc { font-size: 10px; }
  .game-row .mistake-count { font-size: 11px; }
  /* Let the opponent column shrink below its content width so the
     trailing result / time-control / mistake-count columns stay visible. */
  .game-row .opp { min-width: 0; }
  /* Column count must match the rendered children:
     grank | ply | swing | played | last-attempt | game-link | side-dot
     = 7 columns. */
  .game-puzzle-item {
    grid-template-columns: auto auto auto 1fr auto auto auto;
    column-gap: 6px;
    padding: 6px;
    font-size: 11px;
  }
  /* Let the played-move column shrink below its content width so the
     trailing side-dot / link / last-attempt columns stay visible. */
  .game-puzzle-item .played { min-width: 0; }
  .game-puzzle-item .last-attempt { font-size: 10px; padding: 1px 4px; }

  /* View-toggle row: keep the segmented control and result filter on
     one line if possible, but allow wrap. */
  .view-toggle-row { gap: 6px; }
  .view-toggle button { padding: 6px 10px; font-size: 12px; }
  .by-game-result-filter { padding: 6px 8px; }
  .ranked-filter { padding: 6px 8px; }

  /* Game focus header (back-to-games breadcrumb) should wrap nicely. */
  .game-focus-header { padding: 6px; font-size: 11px; }

  /* Squares - the clamp() in font-size is already viewport-friendly,
     but on very narrow screens the lower bound is too tall, so trim it. */
  .square { font-size: clamp(22px, 10vw, 44px); }

  /* Status / feedback lines */
  .status { font-size: 13px; }
  .feedback { font-size: 12px; padding: 8px 10px; }

  /* Settings popover: keep within viewport. clamp() caps the width on
     very narrow screens so the popover never extends past the right
     edge or pushes the page into horizontal scroll. */
  .cfg-pop {
    right: 0;
    min-width: 170px;
    max-width: calc(100vw - 20px);
    width: max-content;
  }
  .cfg-linked-add { flex-wrap: wrap; }
  .cfg-linked-add select { width: 100%; min-width: 0; }
  .cfg-linked-add input { width: 100%; min-width: 0; flex: 1 1 100%; }
  .cfg-linked-add button { width: 100%; }

  /* Form-grid inputs stretch full-width when stacked. */
  .form-grid { grid-template-columns: 1fr; gap: 8px; }
  input[type="text"], select {
    max-width: none;
    flex: 1 1 auto;
    width: 100%;
  }
  /* Number inputs in the form-grid should match the text inputs in
     touch-friendly height. */
  .form-grid input[type="number"] {
    padding: 10px 9px;
    font-size: 14px;
  }
  /* Inline FEN row stays single-line; the cancel button keeps the same
     tap target as other controls on this width. */
  .fen-import-row { flex-wrap: wrap; }
  .fen-import-row input[type="text"] { font-size: 13px; padding: 8px 8px; }
}

/* Extra-small phones (iPhone SE / 320px). The board must still fit and
   the topbar must not push the page into horizontal scroll. */
@media (max-width: 380px) {
  .app { padding: 12px 8px 32px; }
  h1 { font-size: 16px; }
  .user-email { display: none; }
  .panel { padding: 9px 10px; }
  .controls { gap: 6px; }
  .controls button { padding: 9px 11px; font-size: 13px; }
}

/* ----- Dashboard panel ------------------------------------------------ */
#panel-dashboard .dash-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
#panel-dashboard .dash-stat {
  background: var(--panel-2, #2a2a32);
  border: 1px solid #44444d;
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  min-width: 0;
}
#panel-dashboard .dash-stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
}
#panel-dashboard .dash-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 4px;
}
#panel-dashboard .dash-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}
#panel-dashboard .dash-empty {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}
#panel-dashboard .dash-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  #panel-dashboard .dash-grid { grid-template-columns: repeat(2, 1fr); }
  #panel-dashboard .dash-stat-value { font-size: 18px; }
}

/* --- Promotion picker overlay --- */
#promo-picker {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#promo-picker[hidden] { display: none; }
#promo-picker-inner {
  background: var(--bg2, #2a2a2a);
  border: 1px solid var(--border, #444);
  border-radius: 10px;
  padding: 20px 24px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.promo-label {
  font-size: 13px;
  color: var(--muted, #888);
  margin-bottom: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#promo-choices {
  display: flex;
  gap: 12px;
}
.promo-btn {
  width: 64px;
  height: 64px;
  background: var(--bg3, #333);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 42px;
  line-height: 64px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.promo-btn:hover {
  border-color: var(--accent, #7cc4ff);
  background: var(--bg4, #3a3a3a);
}
.promo-btn img { width: 48px; height: 48px; }


/* ----------------------------------------------------------------------
   Page split (mvp_specs.md 1): shared site nav + standalone dashboard /
   profile pages. The trainer keeps its existing layout untouched.
   ---------------------------------------------------------------------- */
.site-nav { display: flex; gap: 4px; margin: 2px 0 14px; flex-wrap: wrap; }
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.site-nav a:hover { color: var(--text); background: var(--panel-2); }
.site-nav a.active {
  color: var(--text);
  background: var(--panel);
  border-color: #33333a;
  font-weight: 600;
}
.page-narrow { max-width: 900px; }

/* Password/email inputs (profile page) reuse the text-input look. */
input[type="password"], input[type="email"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #44444d;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
}
.form-col { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.form-col input { width: 100%; max-width: none; }
.ok-text { color: var(--good); font-size: 12px; margin-top: 6px; }

/* Profile page rows */
.profile-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.profile-label { color: var(--muted); min-width: 90px; font-size: 12px; }
.linked-remove { font-size: 12px; padding: 4px 8px; margin-left: auto; }

/* Dashboard page: auto-sync status, weaknesses card, libraries table */
.sync-running { color: var(--accent); }
.wk-row + .wk-row { margin-top: 8px; }
.wk-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.wk-bar { height: 8px; background: #1a1a1f; border-radius: 4px; overflow: hidden; }
.wk-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.lib-table-wrap { overflow-x: auto; }
.lib-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lib-table th, .lib-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid #33333a;
  white-space: nowrap;
}
.lib-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lib-table tr:last-child td { border-bottom: none; }


/* ----------------------------------------------------------------------
   Trainer UI refactor: collapsible Find-player panel, wrapping action
   rows, puzzle prev/next, mistakes-panel header button.
   ---------------------------------------------------------------------- */
.panel.collapsible { padding-top: 10px; }
.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
}
.panel-toggle:hover { background: none; }
.panel-toggle h2 { margin: 0; }
.panel-toggle .chev {
  color: var(--muted);
  font-size: 13px;
  transition: transform 0.15s ease;
}
.panel-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.panel-body { margin-top: 10px; }
.panel-body[hidden] { display: none; }

/* Wrapping replacement for the analyse form's rigid grid. */
.form-flex { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-flex > div { min-width: 0; }
.form-flex input[type="text"] { max-width: 160px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.panel-h2-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-h2-row h2 { margin-bottom: 0; }
.panel-h2-row button { flex: 0 0 auto; }

/* Unified analysis tree: exploration moves (not part of the real game)
   are tinted so the trunk/game line stays visually distinct. */
.tree-mv.tree-explore { color: var(--accent); }

/* Profile: per-account preferred time controls */
.tc-row { gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tc-pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid #44444d;
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  user-select: none;
  margin-bottom: 0;
}
.tc-pill input[type="checkbox"] { display: none; }
.tc-pill:has(input:checked) {
  color: var(--accent);
  background: rgba(124, 196, 255, 0.12);
  border-color: var(--accent);
}
.tc-pill:hover { border-color: #66666f; color: var(--text); }
.tc-pill:has(input:checked):hover { color: var(--accent); }
.tc-badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tc-badge {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid #44444d;
  border-radius: 999px;
  padding: 1px 7px;
}
.linked-edit { font-size: 12px; padding: 4px 8px; margin-left: auto; }
.linked-edit + .linked-remove { margin-left: 0; }

/* Games page */
.games-table .res-win  { color: var(--good); }
.games-table .res-loss { color: var(--bad); }
.games-table .res-draw { color: var(--warn); }
.games-table .muted-cell { color: var(--muted); font-size: 11px; }
.games-table .game-links a { white-space: nowrap; }
.meta-line { color: var(--muted); font-size: 12px; margin-top: 10px; }
