* { box-sizing: border-box; }

:root {
  /* Board size: fits phones and desktops automatically */
  --size: min(94vw, 62vh, 560px);
  --light: #e9edcc;
  --dark: #779556;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 8px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.top { text-align: center; }
.top h1 { margin: 4px 0 0; font-size: 1.6rem; }
.tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }

.player-bar {
  width: var(--size);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--card);
  border-radius: 8px;
  font-weight: 600;
}

/* ===== Board ===== */
.board {
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;          /* stops the page scrolling while dragging on phones */
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.square.light { background: var(--light); }
.square.dark  { background: var(--dark); }

/* Highlights */
.square.last-move::before,
.square.selected::before,
.square.check::before {
  content: "";
  position: absolute;
  inset: 0;
}
.square.last-move::before { background: rgba(255, 215, 0, 0.38); }
.square.selected::before  { background: rgba(56, 189, 248, 0.45); }
.square.check::before {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.9) 0%, rgba(239, 68, 68, 0.4) 45%, transparent 75%);
}

/* Legal move dots */
.square.target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
}
.square.target.capture::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: calc(var(--size) / 90) solid rgba(0, 0, 0, 0.25);
}

/* Pieces */
.piece {
  position: relative;
  z-index: 1;
  font-size: calc(var(--size) / 8 * 0.8);
  line-height: 1;
  pointer-events: none;
}
.piece.white {
  color: #ffffff;
  text-shadow: 0 0 2px #000, 0 0 1px #000, 0 2px 3px rgba(0, 0, 0, 0.5);
}
.piece.black {
  color: #1a1a1a;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.5), 0 2px 3px rgba(0, 0, 0, 0.4);
}
.piece.dragging-source { opacity: 0.3; }

/* The piece that follows your finger or mouse while dragging */
.drag-ghost {
  position: fixed;
  z-index: 1000;
  transform: translate(-50%, -50%) scale(1.15);
}

/* Board coordinates (a-h, 1-8) */
.coord {
  position: absolute;
  font-size: max(9px, calc(var(--size) / 48));
  font-weight: 700;
  pointer-events: none;
  z-index: 2;
}
.coord.file { right: 3px; bottom: 1px; }
.coord.rank { left: 3px; top: 1px; }
.square.light .coord { color: var(--dark); }
.square.dark .coord  { color: var(--light); }

/* Status and buttons */
.status {
  width: var(--size);
  text-align: center;
  padding: 10px;
  background: var(--card);
  border-radius: 8px;
  min-height: 44px;
}

.btn {
  background: var(--accent);
  color: #0f172a;
  border: 0;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }

/* ===== Step 4: clocks and pre-moves ===== */

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 6px;
  background: #0f172a;
  color: var(--muted);
  min-width: 70px;
  text-align: center;
}
.clock.active { background: #f8fafc; color: #0f172a; }
.clock.low    { background: #dc2626; color: #ffffff; }

/* Pre-move squares (red tint) */
.square.premove-from::before,
.square.premove-to::before {
  content: "";
  position: absolute;
  inset: 0;
}
.square.premove-from::before { background: rgba(220, 38, 38, 0.25); }
.square.premove-to::before   { background: rgba(220, 38, 38, 0.42); }

/* Keep "selected" and "check" on top of pre-move tints */
.square.selected::before { background: rgba(56, 189, 248, 0.45); }
.square.check::before {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.9) 0%, rgba(239, 68, 68, 0.4) 45%, transparent 75%);
}

/* Ghost piece = where your pre-move will put it */
.piece.ghost { opacity: 0.55; }

/* Numbered badge on pre-move squares */
.premove-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  z-index: 3;
  background: #dc2626;
  color: #ffffff;
  font-size: max(10px, calc(var(--size) / 40));
  font-weight: 700;
  border-radius: 999px;
  min-width: 1.5em;
  height: 1.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Pre-move target dots are red instead of grey */
.square.target.pre::after { background: rgba(220, 38, 38, 0.35); }
.square.target.pre.capture::after {
  background: transparent;
  border-color: rgba(220, 38, 38, 0.5);
}

.premove-info {
  width: var(--size);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.controls {
  width: var(--size);
  display: flex;
  gap: 8px;
}

.select {
  flex: 1;
  background: var(--card);
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px;
  font-size: 1rem;
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.85rem;
  background: #334155;
  color: var(--text);
}
.btn:disabled { opacity: 0.4; cursor: default; }

/* ===== Step 5: physics and motion ===== */

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

/* Captured-pieces tray */
.tray {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-height: 1.2em;
  overflow: hidden;
}
.piece.tray-piece {
  font-size: calc(var(--size) / 8 * 0.42);
  margin-right: -0.12em;
}
.material {
  margin-left: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* A captured piece flying to the tray */
.flyer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  pointer-events: none;
  line-height: 1;
}

/* Board shake on check */
@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.board.shake { animation: board-shake 0.35s ease; }

/* Checkmated king tips over */
.piece.toppled {
  transform-origin: 70% 90%;
  transform: rotate(80deg);
  transition: transform 0.8s cubic-bezier(0.55, 0.05, 0.7, 1.3);
}

/* Pre-move ghosts float gently */
@keyframes ghost-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6%); }
}
.piece.ghost { animation: ghost-float 1.4s ease-in-out infinite; }

/* Lite mode: no motion at all */
body.lite .piece.ghost,
body.lite .board.shake { animation: none; }
body.lite .piece.toppled { transition: none; }

/* ===== Step 8: game review ===== */

.review {
  width: var(--size);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.review[hidden] { display: none; }
.review-btn { width: 100%; }
.review-btn[hidden] { display: none; }

.review-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-card {
  background: var(--card);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.stat-value { font-size: 1.6rem; font-weight: 800; }
.stat-label { font-size: 0.8rem; color: var(--muted); }

.review-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.tag.blunder,    .moment.blunder em    { background: #dc2626; color: #fff; }
.tag.mistake,    .moment.mistake em    { background: #ea580c; color: #fff; }
.tag.inaccuracy, .moment.inaccuracy em { background: #ca8a04; color: #fff; }

.review-graph {
  background: var(--card);
  border-radius: 10px;
  padding: 10px;
}
.review-graph svg { width: 100%; height: 80px; display: block; border-radius: 6px; }
.graph-bg   { fill: #0f172a; }
.graph-area { fill: rgba(248, 250, 252, 0.85); }
.graph-mid  { stroke: #64748b; stroke-width: 0.6; stroke-dasharray: 3 3; }
.graph-line { fill: none; stroke: #f8fafc; stroke-width: 1.2; }
.dot.blunder    { fill: #dc2626; }
.dot.mistake    { fill: #ea580c; }
.dot.inaccuracy { fill: #ca8a04; }
.graph-caption { font-size: 0.75rem; color: var(--muted); margin-top: 6px; text-align: center; }

.review-title { margin: 6px 0 0; font-size: 1rem; }

.moment {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  background: var(--card);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
.moment.active { border-color: var(--accent); }
.moment-head { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.moment em {
  font-style: normal;
  font-size: 0.7rem;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
}
.moment-text { font-size: 0.9rem; color: #cbd5e1; }

/* Review highlights on the board */
.square.review-played::before,
.square.review-best::before {
  content: "";
  position: absolute;
  inset: 0;
}
.square.review-played::before { background: rgba(220, 38, 38, 0.45); }
.square.review-best::before   { background: rgba(34, 197, 94, 0.5); }

/* ===== Step 9: undo, resign, sides ===== */

.game-actions {
  width: var(--size);
  display: flex;
  gap: 8px;
}
.btn.secondary {
  flex: 1;
  background: #334155;
  color: var(--text);
}
.btn.danger {
  background: #dc2626;
  color: #ffffff;
}

/* ===== Step 10: move-by-move review ===== */

.board { position: relative; }

/* Arrows drawn on top of the board */
.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

/* Navigation */
.review-nav { display: flex; align-items: center; gap: 6px; }
.nav-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 42px;
  background: #334155;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}
.nav-btn:disabled { opacity: 0.35; cursor: default; }
.nav-label {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Coach box */
.coach {
  background: var(--card);
  border-radius: 10px;
  padding: 12px;
  border-left: 5px solid #64748b;
}
.coach.best       { border-left-color: #22c55e; }
.coach.good       { border-left-color: #3b82f6; }
.coach.inaccuracy { border-left-color: #ca8a04; }
.coach.mistake    { border-left-color: #ea580c; }
.coach.blunder    { border-left-color: #dc2626; }
.coach-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  margin-bottom: 6px;
}
.coach-side { margin-left: auto; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.coach-text { font-size: 0.95rem; line-height: 1.45; }
.coach-best { margin-top: 6px; font-size: 0.85rem; color: #86efac; }

.badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: #64748b;
}
.badge.best       { background: #16a34a; }
.badge.good       { background: #2563eb; }
.badge.inaccuracy { background: #ca8a04; }
.badge.mistake    { background: #ea580c; }
.badge.blunder    { background: #dc2626; }

/* Move list */
.move-list {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 6px;
  background: var(--card);
  border-radius: 10px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}
.mv-num { color: var(--muted); padding: 4px 2px; font-size: 0.85rem; }
.mv {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 4px 6px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.mv.active { background: var(--accent); color: #0f172a; }
.mv-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.mv-dot.best       { background: #16a34a; }
.mv-dot.inaccuracy { background: #ca8a04; }
.mv-dot.mistake    { background: #ea580c; }
.mv-dot.blunder    { background: #dc2626; }

/* Graph cursor */
.review-graph svg { cursor: pointer; }
.graph-cursor { stroke: var(--accent); stroke-width: 1.4; }

/* ===== Step 11: professional layout, book moves, L-arrows ===== */

/* Header */
.topbar {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 16px 4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.3px;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #0f172a;
  font-size: 1.3rem;
}
.brand-tagline { color: var(--muted); font-size: 0.9rem; }

/* Layout: one column on phones, board + side panel on computers */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 8px 32px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "board" "dock" "side";
  justify-items: center;
  gap: 12px;
}
.board-col {
  grid-area: board;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.review-dock {
  grid-area: dock;
  width: var(--size);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.review-dock[hidden] { display: none; }
.side-col {
  grid-area: side;
  width: var(--size);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.side-col > * { width: 100%; }

@media (min-width: 900px) {
  :root { --size: min(calc(100vh - 210px), 600px, calc(100vw - 440px)); }
  .layout {
    grid-template-columns: auto 360px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "board dock" "board side";
    justify-content: center;
    align-items: start;
    gap: 12px 24px;
  }
  .review-dock, .side-col { width: 360px; }
}

/* Settings card */
.panel {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel-title {
  margin: 0 0 2px;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.panel .controls { width: 100%; }
.panel .select { background: #0f172a; }

/* Opening card in the review */
.opening-card {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
}
.opening-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.opening-name  { font-weight: 700; margin-top: 2px; }

/* New labels: book and excellent */
.coach.book       { border-left-color: #a78b5c; }
.coach.excellent  { border-left-color: #14b8a6; }
.badge.book       { background: #8b6f47; }
.badge.excellent  { background: #0d9488; }
.mv-dot.book      { background: #a78b5c; }
.mv-dot.excellent { background: #14b8a6; }

/* Move list scrolls inside itself (never moves the page) */
.move-list { position: relative; }

/* ===== Step 12: piece artwork and promotion menu ===== */

/* Pieces are now images instead of text symbols */
.piece {
  width: calc(var(--size) / 8 * 0.92);
  height: calc(var(--size) / 8 * 0.92);
  font-size: 0;
  text-shadow: none;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.25));
}
.piece.wK { background-image: url("/static/pieces/wK.svg"); }
.piece.wQ { background-image: url("/static/pieces/wQ.svg"); }
.piece.wR { background-image: url("/static/pieces/wR.svg"); }
.piece.wB { background-image: url("/static/pieces/wB.svg"); }
.piece.wN { background-image: url("/static/pieces/wN.svg"); }
.piece.wP { background-image: url("/static/pieces/wP.svg"); }
.piece.bK { background-image: url("/static/pieces/bK.svg"); }
.piece.bQ { background-image: url("/static/pieces/bQ.svg"); }
.piece.bR { background-image: url("/static/pieces/bR.svg"); }
.piece.bB { background-image: url("/static/pieces/bB.svg"); }
.piece.bN { background-image: url("/static/pieces/bN.svg"); }
.piece.bP { background-image: url("/static/pieces/bP.svg"); }

/* Smaller pieces in the captured trays */
.piece.tray-piece {
  width: calc(var(--size) / 8 * 0.45);
  height: calc(var(--size) / 8 * 0.45);
  margin-right: calc(var(--size) / 8 * -0.16);
  filter: none;
}

/* Promotion menu */
.promo-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.55);
}
.promo-option {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  border: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: background 0.15s, border-radius 0.15s;
}
.promo-option:hover { background: var(--accent); border-radius: 12%; }
.promo-option .piece { width: 88%; height: 88%; }

/* Footer credit */
.site-footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px 24px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.site-footer a { color: var(--muted); }

/* ===== Step 13: bot ladder picker ===== */

.bot-picker {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 2px;
}

.bot-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #0f172a;
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.bot-card:hover { background: #162238; }
.bot-card.selected { border-color: var(--tier); background: #162238; }

.bot-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #0f172a;
  background: var(--tier);
}

.bot-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.bot-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bot-name { font-weight: 700; }
.bot-rating {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--tier);
}
.bot-tier {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.bot-style {
  font-size: 0.8rem;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fine-print { margin: 0; font-size: 0.72rem; color: var(--muted); }

/* ===== Step 14: profile and rating ===== */

.profile-chip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid #334155;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.profile-chip:hover { border-color: var(--accent); }
.profile-rating {
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.game-mode {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
  background: #14532d;
  color: #86efac;
}
.game-mode.casual { background: #334155; color: var(--muted); }

/* ===== Step 15A: profile page ===== */

a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.brand-link { color: var(--text); text-decoration: none; }
.topbar-play { margin-left: auto; padding: 8px 18px; }

.profile-page {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#profile-content { display: flex; flex-direction: column; gap: 14px; }
#profile-content[hidden], #profile-empty[hidden] { display: none; }

.card-block {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
}
.card-block h2 { margin: 0; font-size: 1rem; }
.block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.block-meta { font-size: 0.8rem; color: var(--muted); }
.empty-note { color: var(--muted); margin: 4px 0; font-size: 0.9rem; }

/* Hero */
.profile-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.hero-left { display: flex; align-items: center; gap: 14px; }
.hero-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
}
.hero-name { margin: 0; font-size: 1.5rem; }
.hero-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  margin-top: 4px;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.hero-rating { text-align: right; }
.hero-rating-value {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hero-rating-label { font-size: 0.8rem; color: var(--muted); margin-top: 4px; max-width: 220px; }

/* Stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 700px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-tile {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
}
.stat-tile-value { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-tile-label { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.stat-tile.streak-win .stat-tile-value  { color: #4ade80; }
.stat-tile.streak-loss .stat-tile-value { color: #f87171; }

/* Rating chart */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-grid { stroke: #334155; stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; }
.chart-area { fill: rgba(56, 189, 248, 0.15); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart-dot { fill: var(--accent); }
.chart-dot.last { fill: #f8fafc; stroke: var(--accent); stroke-width: 2; }
.chart-peak { fill: none; stroke: #facc15; stroke-width: 2; }
.chart-peak-label { fill: #facc15; font-size: 11px; font-weight: 700; }

/* Recent form */
.recent-form { display: flex; gap: 6px; flex-wrap: wrap; }
.form-chip {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #0f172a;
}
.form-chip.win  { background: #4ade80; }
.form-chip.loss { background: #f87171; }
.form-chip.draw { background: #94a3b8; }

/* Game history */
.game-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.game-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  background: #0f172a;
  border-radius: 10px;
  padding: 12px;
  border-left: 4px solid #64748b;
}
.game-row.win  { border-left-color: #4ade80; }
.game-row.loss { border-left-color: #f87171; }
@media (min-width: 700px) {
  .game-row { grid-template-columns: 1fr auto auto; align-items: center; }
}
.game-title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.result-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0f172a;
}
.result-badge.win  { background: #4ade80; }
.result-badge.loss { background: #f87171; }
.result-badge.draw { background: #94a3b8; }
.game-meta, .game-opening { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }
.game-opening { color: #cbd5e1; }
.game-numbers {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 120px;
}
@media (min-width: 700px) { .game-numbers { align-items: flex-end; } }
.rating-change { font-weight: 800; font-size: 1rem; color: var(--text); font-variant-numeric: tabular-nums; }
.rating-change.up { color: #4ade80; }
.rating-change.down { color: #f87171; }
.rating-change.casual { font-size: 0.8rem; color: var(--muted); }
.game-actions-row { display: flex; gap: 6px; }
.btn.small.secondary-link { background: #334155; color: var(--text); }

/* ===== Step 15B: analysis and coaching ===== */

.coach-grid, .analysis-section { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 800px) { .coach-grid { grid-template-columns: 1.6fr 1fr; align-items: start; } }

.two-col { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 800px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }

/* Coaching summary */
.insight-list { display: flex; flex-direction: column; gap: 8px; }
.insight {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #0f172a;
  border-radius: 10px;
  padding: 10px 12px;
  border-left: 4px solid #64748b;
}
.insight.strength { border-left-color: #4ade80; }
.insight.focus    { border-left-color: #fb923c; }
.insight.tip      { border-left-color: var(--accent); }
.insight-tag {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  background: #334155;
  color: var(--text);
  margin-top: 1px;
}
.insight.strength .insight-tag { background: #14532d; color: #86efac; }
.insight.focus .insight-tag    { background: #7c2d12; color: #fed7aa; }
.insight.tip .insight-tag      { background: #0c4a6e; color: #bae6fd; }
.insight-text { font-size: 0.92rem; line-height: 1.45; }

.unreviewed-box {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Next challenge */
.challenge-card { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.bot-avatar.large { width: 52px; height: 52px; font-size: 1.4rem; }
.challenge-info { flex: 1; min-width: 0; }
.challenge-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.challenge-name { font-weight: 800; font-size: 1.15rem; }
.challenge-reason { font-size: 0.88rem; color: #cbd5e1; margin-top: 6px; line-height: 1.4; }
.challenge-card .bot-rating { color: var(--tier); }

/* Tables */
.data-table {
  display: grid;
  gap: 0;
  font-size: 0.88rem;
  overflow-x: auto;
}
.data-table .th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 8px 8px;
  border-bottom: 1px solid #334155;
}
.data-table .td {
  padding: 8px;
  border-bottom: 1px solid #1f2b40;
  display: flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.bot-cell, .opening-cell { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tier-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.mini-tag {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
}
.mini-tag.best  { background: #14532d; color: #86efac; }
.mini-tag.worst { background: #7f1d1d; color: #fecaca; }

/* Score bars */
.score-bar {
  position: relative;
  width: 100%;
  min-width: 80px;
  height: 20px;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
}
.score-fill { height: 100%; border-radius: 6px; }
.score-fill.good { background: #16a34a; }
.score-fill.even { background: #ca8a04; }
.score-fill.poor { background: #dc2626; }
.score-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #f8fafc;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Mini tiles */
.mini-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.mini-tile { background: #0f172a; border-radius: 10px; padding: 12px; }
.mini-tile-value { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-tile-label { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.mini-tile.blunder .mini-tile-value    { color: #f87171; }
.mini-tile.mistake .mini-tile-value    { color: #fb923c; }
.mini-tile.inaccuracy .mini-tile-value { color: #facc15; }

.trend { font-size: 0.85rem; margin: 10px 0 0; color: var(--muted); }
.trend.up   { color: #4ade80; }
.trend.down { color: #f87171; }

/* Game phases */
.phase-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 10px;
  align-items: center;
  margin-bottom: 10px;
}
.phase-name { font-weight: 700; font-size: 0.9rem; }
.phase-meta { grid-column: 2; font-size: 0.72rem; color: var(--muted); }

/* ===== Step 16: play button, themes, live moves ===== */

/* Board themes */
body[data-board="brown"]  { --light: #f0d9b5; --dark: #b58863; }
body[data-board="blue"]   { --light: #dee3e6; --dark: #8ca2ad; }
body[data-board="grey"]   { --light: #e6e6e6; --dark: #9a9a9a; }
body[data-board="purple"] { --light: #ece4f4; --dark: #9b86b8; }

/* Play button */
.play-btn {
  padding: 14px 24px;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}
.play-btn:not(:disabled) { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.6); animation: play-pulse 2s infinite; }
@keyframes play-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}
body.lite .play-btn { animation: none; }
.panel .btn.secondary { flex: none; }

/* Locked during a game */
body.in-game .bot-picker { opacity: 0.5; pointer-events: none; }
.select:disabled { opacity: 0.5; cursor: not-allowed; }

/* Live move list */
.live-moves-card[hidden] { display: none; }
.live-moves {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 8px;
  max-height: 160px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}
.lm-num { color: var(--muted); }
.lm { padding: 1px 6px; border-radius: 4px; }
.lm.last { background: var(--accent); color: #0f172a; font-weight: 700; }
.live-moves-empty { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }

/* Three action buttons under the board */
.game-actions .btn { padding: 10px 8px; }

/* ===== Step 17A: NexMate brand theme (from the logo) ===== */

:root {
  --bg: #050b1f;          /* deep navy from the icon */
  --card: #0c1733;
  --card-2: #101f45;
  --line: #1c2c58;
  --text: #e6edff;
  --muted: #8a9cc4;
  --accent: #2f9bff;      /* the logo's bright blue */
  --brand-cyan: #00c2ff;
  --brand-royal: #1d4ed8;
  --brand-gradient: linear-gradient(135deg, #00c2ff 0%, #1d6cf0 55%, #1d4ed8 100%);
}

/* Subtle glow behind the page, echoing the icon */
html, body { background: var(--bg); }
body {
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(29, 108, 240, 0.18), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(0, 194, 255, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* Header logo */
.brand-logo {
  height: 44px;
  width: auto;
  display: block;
}
@media (max-width: 600px) {
  .brand-logo { height: 34px; }
  .brand-tagline { display: none; }
}
.topbar { align-items: center; }

/* Main buttons use the brand gradient */
.btn {
  background: var(--brand-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(29, 108, 240, 0.35);
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn.secondary, .btn.small, .btn.small.secondary-link, .nav-btn {
  background: var(--card-2);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--line);
}
.btn.danger { background: #dc2626; color: #ffffff; border-color: #dc2626; }

/* Cards and panels pick up the navy tone */
.panel, .status, .player-bar, .card-block, .stat-tile, .stat-card,
.opening-card, .coach, .move-list, .review-graph, .moment {
  background: var(--card);
  border: 1px solid var(--line);
}
.select, .panel .select, .bot-card, .game-row, .insight, .mini-tile, .score-bar, .clock {
  background: var(--bg);
}
.select { border-color: var(--line); }
.bot-card:hover, .bot-card.selected { background: var(--card-2); }
.profile-chip { background: var(--card); border-color: var(--line); }

/* Highlights in brand blue */
.clock.active { background: var(--brand-gradient); color: #ffffff; }
.lm.last, .mv.active { background: var(--accent); color: #ffffff; }
.hero-avatar { background: var(--brand-gradient); color: #ffffff; }
.square.selected::before { background: rgba(47, 155, 255, 0.45); }

/* ===== Step 17B: Pre-move Academy ===== */

/* Header navigation */
.nav-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  white-space: nowrap;
}
.nav-link:hover { border-color: var(--accent); }
.topbar .nav-link { margin-left: auto; }
.nav-link + .profile-chip, .nav-link + .topbar-play { margin-left: 10px; }

.academy {
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.academy section[hidden] { display: none; }
#hub { display: flex; flex-direction: column; gap: 14px; }
.academy-hero h1 { margin: 0 0 6px; font-size: 1.6rem; }
.academy-hero p { margin: 0; color: var(--muted); line-height: 1.5; }
.hub-note { margin-top: 10px !important; color: #fbbf24 !important; font-size: 0.85rem; }
.hub-note[hidden] { display: none; }

/* Level cards */
.level-list { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .level-list { grid-template-columns: 1fr 1fr; } }
.level-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.level-card.soon { opacity: 0.6; }
.level-num {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  background: var(--brand-gradient);
  color: #ffffff;
}
.level-card.soon .level-num { background: var(--card-2); color: var(--muted); }
.level-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.level-title { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.level-desc { color: #c3cee8; font-size: 0.9rem; line-height: 1.45; }
.level-stat { font-size: 0.8rem; color: var(--muted); }
.level-info .btn { align-self: flex-start; margin-top: 4px; }
.pill {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--muted);
}
.pill.done { background: #14532d; color: #86efac; }

/* Lesson and quiz */
.lesson { display: flex; flex-direction: column; gap: 12px; max-width: 680px; width: 100%; margin: 0 auto; }
.lesson h2 { margin: 0; font-size: 1.3rem; }
.lesson p { margin: 0; line-height: 1.6; color: #d3dcf2; }
.lesson-steps { display: flex; gap: 6px; }
.lesson-steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--card-2); }
.lesson-steps span.on { background: var(--accent); }
.lesson-nav { display: flex; gap: 8px; justify-content: space-between; margin-top: 6px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  font: inherit;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent); }
.quiz-option:disabled { cursor: default; }
.quiz-option.right { border-color: #22c55e; background: #0f2e1c; }
.quiz-option.wrong { border-color: #dc2626; background: #2e1111; }
.quiz-explain { font-size: 0.9rem; }

/* Drills */
.drill-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.drill-title { font-weight: 800; font-size: 1.1rem; }
.drill-progress { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.drill-body { display: grid; grid-template-columns: 1fr; gap: 14px; justify-items: center; margin-top: 10px; }
@media (min-width: 860px) {
  .drill-body { grid-template-columns: auto 320px; align-items: start; justify-content: center; }
}
.drill-board-col { --size: min(92vw, 60vh, 520px); display: flex; flex-direction: column; gap: 8px; }
.timer { width: var(--size); height: 8px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--brand-gradient); }
.timer-fill.low { background: #dc2626; }
.drill-side { width: min(92vw, 320px); display: flex; flex-direction: column; gap: 10px; }
.drill-prompt {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  line-height: 1.5;
}
.drill-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.drill-answers:empty { display: none; }
.answer-btn {
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  padding: 14px;
  border-radius: 12px;
  border: 2px solid;
  cursor: pointer;
}
.answer-btn.safe   { background: #0f2e1c; border-color: #22c55e; color: #86efac; }
.answer-btn.unsafe { background: #2e1111; border-color: #dc2626; color: #fca5a5; }
.answer-btn:disabled { opacity: 0.5; cursor: default; }
.answer-key { display: block; font-size: 0.7rem; font-weight: 600; opacity: 0.7; }
.drill-feedback {
  border-radius: 12px;
  padding: 12px 14px;
  line-height: 1.5;
  border: 1px solid var(--line);
  background: var(--card);
}
.drill-feedback[hidden] { display: none; }
.drill-feedback.good { border-color: #22c55e; }
.drill-feedback.bad  { border-color: #dc2626; }
.feedback-head { font-weight: 800; margin-bottom: 4px; }
.drill-feedback.good .feedback-head { color: #86efac; }
.drill-feedback.bad .feedback-head  { color: #fca5a5; }
.drill-score { color: var(--muted); font-size: 0.9rem; }

/* Results */
.summary { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; max-width: 560px; margin: 0 auto; width: 100%; }
.summary-score {
  font-size: 3.2rem;
  font-weight: 800;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.summary-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.summary-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.summary p { margin: 0; color: #d3dcf2; line-height: 1.5; }

/* ===== Step 17D: Academy error bar ===== */
.academy-error {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: min(94vw, 560px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #2e1111;
  border: 1px solid #dc2626;
  color: #fecaca;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  line-height: 1.4;
}
.academy-error span { flex: 1; }
.academy-error-close {
  background: none;
  border: 0;
  color: #fecaca;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

/* ===== Step 18: Academy positions on the game page ===== */
.academy-panel[hidden] { display: none; }
.academy-panel { border-color: var(--accent) !important; }
.academy-text { margin: 0; line-height: 1.5; color: #d3dcf2; }
.academy-panel .controls { flex-wrap: wrap; }
.academy-panel .controls .btn { flex: 1; }

/* ===== Step 19: puzzles, and a header that fits phones ===== */

.nav-link + .nav-link { margin-left: 8px; }
.topbar { flex-wrap: wrap; row-gap: 8px; }
@media (max-width: 600px) {
  .nav-link { padding: 6px 10px; font-size: 0.8rem; }
  .profile-chip { padding: 5px 10px; font-size: 0.85rem; }
}

.pz-rating-top { display: flex; align-items: baseline; justify-content: space-between; }
.pz-rating-value {
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.pz-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}
.pz-tab {
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.pz-tab.active { background: var(--brand-gradient); color: #ffffff; }

.pz-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pz-actions .btn { flex: 1; }
#pz-result[hidden] { display: none; }

/* ===== Step 21: Learn ===== */

.track-list { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 860px) { .track-list { grid-template-columns: 1fr 1fr; align-items: start; } }

.track-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.track-card > .btn, .track-card > .pill { align-self: flex-start; }
.track-top { display: flex; align-items: center; gap: 12px; }
.track-titles { display: flex; flex-direction: column; }
.track-title { margin: 0; font-size: 1.15rem; }
.track-card .level-desc { margin: 0; }

.track-progress { display: flex; flex-direction: column; gap: 4px; }
.track-bar { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.track-fill { height: 100%; background: var(--brand-gradient); border-radius: 4px; }

.lesson-list { display: flex; flex-direction: column; gap: 6px; }
.lesson-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.lesson-row:hover { border-color: var(--accent); }
.lesson-mark {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--card-2);
  color: var(--muted);
}
.lesson-row.done .lesson-mark { background: #16a34a; color: #ffffff; }
.lesson-name { flex: 1; font-weight: 600; }
.lesson-meta { font-size: 0.8rem; color: var(--muted); }

.ln-title { margin: 2px 0 8px; font-size: 1.2rem; }
.ln-text { line-height: 1.55; }
#ln-options:empty { display: none; }
#ln-feedback[hidden], #player[hidden], #done[hidden], #hub[hidden] { display: none; }

/* Highlighted squares in lessons */
.square.highlight::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(250, 204, 21, 0.45);
}

/* ===== Step 24: opening trainer ===== */

#op-build[hidden], #op-drill[hidden], #op-feedback[hidden] { display: none; }
#op-build, #op-drill { display: flex; flex-direction: column; gap: 10px; }

.op-opening { font-weight: 700; margin-top: 2px; }
.op-path {
  width: var(--size);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 6px;
  align-items: baseline;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.op-section:empty { display: none; }
.op-section { display: flex; flex-direction: column; gap: 6px; }
.op-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.op-chip {
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.op-chip:hover { border-color: var(--accent); }
.op-chip.mine  { background: var(--brand-gradient); color: #ffffff; border-color: transparent; }
.op-chip.reply { border-color: #3b82f6; }
.op-chip.book  { border-color: #a78b5c; color: #e8d5b5; }
.op-chip.remove { color: #fca5a5; border-color: #7f1d1d; font-weight: 600; }
.op-chip.small-x { padding: 4px 8px; margin-left: -4px; }

/* Repertoire card in the game review */
.rep-card[hidden] { display: none; }
.rep-text { margin-top: 4px; line-height: 1.45; }
.rep-link { display: inline-block; margin-top: 6px; color: var(--accent); font-size: 0.85rem; }
.rep-card.followed { border-color: #16a34a; }
.rep-card.you      { border-color: #ea580c; }
.rep-card.opponent, .rep-card.end { border-color: #3b82f6; }

/* ===== Step 25: board vision ===== */

#vs-hub, #vs-drill, #vs-summary { display: flex; flex-direction: column; gap: 14px; }
#vs-hub[hidden], #vs-drill[hidden], #vs-summary[hidden], #vs-board-wrap[hidden],
#vs-timer[hidden], #vs-feedback[hidden], #vs-big[hidden] { display: none; }

.vs-big {
  margin-top: 8px;
  font-size: 3rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.05em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* No coordinates in "Name the square" */
.board.no-coords .coord { display: none; }

/* Correct and wrong clicks */
@keyframes flash-good { from { box-shadow: inset 0 0 0 100px rgba(34, 197, 94, 0.75); } to { box-shadow: inset 0 0 0 100px rgba(34, 197, 94, 0); } }
@keyframes flash-bad  { from { box-shadow: inset 0 0 0 100px rgba(220, 38, 38, 0.75); } to { box-shadow: inset 0 0 0 100px rgba(220, 38, 38, 0); } }
.square.flash-good { animation: flash-good 0.6s ease-out; }
.square.flash-bad  { animation: flash-bad 0.6s ease-out; }

/* Blindfold: pieces, move dots and the dragged piece are invisible */
.board.blind .piece { opacity: 0; }
.board.blind .square.target::after,
.board.blind .square.selected::before,
.board.blind .square.last-move::before { display: none; }
body.blind-active .drag-ghost { opacity: 0; }

/* Light / dark answer buttons */
.btn.answer-light { background: #f1f5f9; color: #0f172a; }
.btn.answer-dark  { background: #334155; color: #f8fafc; border: 1px solid var(--line); }

/* Link card on the Learn page */
.vision-link {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--text);
}
.vision-link:hover { border-color: var(--accent); }
.vision-link-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.vision-link-go { color: var(--accent); font-weight: 700; white-space: nowrap; }

/* ===== Step 26: coach features ===== */

.coach-bar {
  width: var(--size);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  line-height: 1.45;
}
.coach-bar[hidden] { display: none; }
.coach-bar #coach-text { flex: 1; min-width: 200px; }
.coach-bar-buttons { display: flex; gap: 6px; }
.coach-bar-buttons .btn[hidden] { display: none; }
.coach-bar.check    { border-color: #3b82f6; }
.coach-bar.thinking { border-color: var(--line); color: var(--muted); }
.coach-bar.warn     { border-color: #f59e0b; background: #2a1d07; }

/* The move waiting for confirmation */
.square.pending::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(59, 130, 246, 0.45);
}

/* Toggles that are switched on */
.btn.small.on { background: var(--brand-gradient); color: #ffffff; border-color: transparent; }

#pz-hint-text[hidden] { display: none; }

/* ===== Step 27: game import ===== */
.import-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.import-form .select { flex: 1; min-width: 140px; }
.import-form input.select { flex: 2; }

/* ===== Step 28: conditional pre-moves and pre-move safety ===== */
.premove-info { flex-wrap: wrap; gap: 8px; }
.premove-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.plan-panel {
  width: var(--size);
  max-width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.plan-panel[hidden] { display: none; }
.plan-text { font-size: 0.95rem; line-height: 1.4; }
.plan-rules { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-rule {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.plan-remove {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.7;
}
.plan-remove:hover { opacity: 1; }
.plan-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

#board.planning { box-shadow: 0 0 0 3px var(--accent), 0 0 24px rgba(47, 155, 255, 0.35); }

/* ===== Step 29: XP, streaks and leagues ===== */

/* Top-bar chip */
.xp-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin: 0 4px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.xp-chip[hidden] { display: none; }
.xp-chip:hover { border-color: var(--accent); }
.xp-chip.cold .xp-streak { filter: grayscale(1); opacity: 0.6; }
.xp-chip.done { border-color: #22c55e; }

/* Toasts */
.xp-toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.xp-toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--accent);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: xp-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.4s, transform 0.4s;
}
.xp-toast.xp { color: #7cc4ff; }
.xp-toast.goal { border-color: #22c55e; color: #86efac; }
.xp-toast.streak { border-color: #f97316; color: #fdba74; }
.xp-toast.level { background: var(--brand-gradient); color: #ffffff; border-color: transparent; }
.xp-toast.leaving { opacity: 0; transform: translateY(10px); }
@keyframes xp-in { from { opacity: 0; transform: translateY(16px) scale(0.9); } to { opacity: 1; transform: none; } }
body.lite .xp-toast { animation: none; }

/* Progress section */
.xp-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .xp-stats { grid-template-columns: repeat(2, 1fr); } }
.xp-stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.xp-stat-value { font-size: 1.4rem; font-weight: 800; }
.xp-stat-label { font-size: 0.75rem; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.04em; }
.xp-stat-sub { font-size: 0.8rem; opacity: 0.7; margin-top: 2px; }
.xp-bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); margin-top: 8px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: var(--brand-gradient); border-radius: inherit; }
.xp-goal-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 14px 0 6px; }
.xp-goal-label { font-size: 0.9rem; opacity: 0.8; margin-right: 4px; }

.xp-week { display: flex; gap: 8px; align-items: flex-end; height: 120px; margin: 10px 0 18px; }
.xp-day { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; }
.xp-day-track {
  flex: 1;
  width: 100%;
  max-width: 36px;
  display: flex;
  align-items: flex-end;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  overflow: hidden;
}
.xp-day-bar { width: 100%; background: rgba(47, 155, 255, 0.55); border-radius: 6px 6px 0 0; }
.xp-day.met .xp-day-bar { background: var(--brand-gradient); }
.xp-day-xp { font-size: 0.7rem; opacity: 0.8; min-height: 1em; }
.xp-day-name { font-size: 0.75rem; opacity: 0.7; }

/* League */
.league-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.league-name { margin: 0; font-size: 1.2rem; }
.league-pawn { color: #cbd5e1; }
.league-knight { color: #7cc4ff; }
.league-bishop { color: #a78bfa; }
.league-rook { color: #34d399; }
.league-queen { color: #f472b6; }
.league-king { color: #fbbf24; }
.league-rules { font-size: 0.9rem; opacity: 0.8; margin: 6px 0; }
.league-last { font-size: 0.9rem; padding: 8px 12px; border-radius: 10px; background: var(--card-2); }
.league-last.up { color: #86efac; }
.league-last.down { color: #fca5a5; }
.league-table { list-style: none; padding: 0; margin: 10px 0; display: flex; flex-direction: column; gap: 2px; }
.league-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.92rem;
  background: rgba(255, 255, 255, 0.02);
}
.league-row.up .league-rank { color: #22c55e; }
.league-row.down .league-rank { color: #ef4444; }
.league-row.you { background: rgba(47, 155, 255, 0.15); outline: 1px solid var(--accent); font-weight: 700; }
.league-rank { font-weight: 700; }
.league-xp { font-variant-numeric: tabular-nums; opacity: 0.85; }
.league-line { font-size: 0.72rem; text-align: center; padding: 2px; letter-spacing: 0.05em; text-transform: uppercase; }
.league-line.up { color: #22c55e; }
.league-line.down { color: #ef4444; }

/* ===== Step 30: kids mode and the parent dashboard ===== */

/* Top-bar chip */
.kids-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  margin: 0 4px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid #f59e0b;
  color: #fde68a;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.kids-chip[hidden] { display: none; }
.kids-chip.low { border-color: #ef4444; color: #fca5a5; animation: kids-pulse 1.2s ease-in-out infinite; }
@keyframes kids-pulse { 50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25); } }

/* The friendlier kids look */
body.kids { font-family: "Segoe UI Rounded", "Nunito", "Trebuchet MS", system-ui, sans-serif; }
body.kids .btn { border-radius: 999px; font-size: 1.05rem; padding: 12px 22px; }
body.kids .btn.small { padding: 8px 14px; font-size: 0.95rem; }
body.kids .select { font-size: 1.05rem; padding: 10px 12px; border-radius: 14px; }
body.kids .card-block { border-radius: 22px; }
body.kids a[target="_blank"] { display: none; }

/* Lock screen */
body.kids-locked { overflow: hidden; }
.kids-lock {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(5, 11, 31, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.kids-lock[hidden] { display: none; }
.kids-lock-box {
  width: 100%;
  max-width: 420px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 22px;
}
.kids-lock-icon { font-size: 3.5rem; animation: kids-bounce 1.6s ease-in-out infinite; }
@keyframes kids-bounce { 50% { transform: translateY(-8px) rotate(-6deg); } }
body.lite .kids-lock-icon { animation: none; }
.kids-lock-box h2 { margin: 8px 0; }
.kids-lock-parent { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.kids-lock-label { font-size: 0.85rem; opacity: 0.75; }
.kids-lock-buttons { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.kids-lock-message { min-height: 1.2em; font-size: 0.9rem; color: #fca5a5; }
.kids-pin { width: 140px; letter-spacing: 0.4em; text-align: center; font-size: 1.2rem; }

/* Parent dashboard */
.parent-page { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
#pd-dash { display: flex; flex-direction: column; gap: 16px; }
#pd-dash[hidden] { display: none; }
.pd-pin-row, .pd-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pd-message { min-height: 1.2em; font-size: 0.9rem; color: #fbbf24; margin: 8px 0 0; }
.small-note { font-size: 0.8rem; }
.pd-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.92rem; }
.pd-table th, .pd-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pd-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
.pd-games { display: flex; flex-direction: column; gap: 6px; }
.pd-game { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--card-2); border-radius: 10px; font-size: 0.92rem; }
.pd-game .game-date { margin-left: auto; }
.pd-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
@media (max-width: 640px) { .pd-settings { grid-template-columns: 1fr; } }
.pd-settings label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.pd-settings label.pd-switch { flex-direction: row; align-items: center; gap: 8px; }
.pd-switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* =====================================================================
   Step 32: the Daylight design
   A bright, calm theme; a real app menu (top bar on computers, tab bar
   on phones); captured pieces that are always visible. Phones first.
   ===================================================================== */

:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --card-2: #f1f4f9;
  --line: #e2e7ef;
  --line-strong: #cfd7e3;
  --text: #14213d;
  --muted: #64748b;
  --accent: #1d6cf0;
  --accent-soft: #e8f0fe;
  --brand-gradient: linear-gradient(135deg, #18a6ff 0%, #1d6cf0 60%, #1d4ed8 100%);
  --tray: #e9edf3;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --tabbar-h: 62px;
}

html, body { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: block;
  max-width: none;
  margin: 0 0 6px;
  padding: 0;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1240px;
  height: 64px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 22px;
}
.brand-logo { height: 34px; width: auto; display: block; }
.main-nav { display: flex; align-items: stretch; align-self: stretch; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-right .nav-link,
.topbar .nav-link {
  margin-left: 0;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
}
.topbar-right .nav-link:hover { border-color: var(--accent); color: var(--accent); }
.profile-chip {
  margin-left: 0;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}
.profile-chip:hover { border-color: var(--accent); }
.xp-chip { background: var(--card-2); border-color: var(--line); color: var(--text); margin: 0; }
.xp-chip:hover { border-color: var(--accent); }
.xp-chip.done { border-color: #22c55e; background: #f0fdf4; }
.kids-chip { background: #fffbeb; border-color: #f59e0b; color: var(--warn); margin: 0; }
.kids-chip.low { border-color: #ef4444; color: var(--bad); background: #fef2f2; }

/* Tablets: labels only */
@media (max-width: 1100px) {
  .topbar-inner { gap: 12px; }
  .main-nav .icon { display: none; }
  .nav-item { padding: 0 9px; }
}

/* ---------- Phone tab bar ---------- */
.tabbar, .train-sheet, .train-backdrop { display: none; }

@media (max-width: 760px) {
  .main-nav { display: none; }
  .topbar-inner { height: 56px; padding: 0 12px; gap: 8px; }
  .brand-logo { height: 28px; }
  .topbar-right { gap: 6px; }
  .xp-chip { padding: 5px 10px; font-size: 0.8rem; }
  .xp-chip .xp-today { display: none; }
  .profile-chip { padding: 5px 10px; font-size: 0.82rem; }
  .profile-chip #profile-name { display: none; }
  .kids-chip { padding: 5px 10px; font-size: 0.8rem; }

  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: saturate(1.4) blur(10px);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.05);
  }
  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }
  .tab .icon { width: 24px; height: 24px; }
  .tab.active, .tab.open { color: var(--accent); }
  .tab.active .icon { stroke-width: 2.1; }

  .train-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15, 23, 42, 0.25);
  }
  .train-sheet:not([hidden]) {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
    z-index: 66;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
    animation: sheet-up 0.18s ease-out;
  }
  .train-sheet-title { padding: 8px 12px 4px; font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
  .train-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
  }
  .train-link .icon { width: 22px; height: 22px; color: var(--accent); }
  .train-link span { display: flex; flex-direction: column; }
  .train-link strong { font-size: 0.98rem; }
  .train-link small { color: var(--muted); font-size: 0.8rem; margin-top: 1px; }
  .train-link.active, .train-link:active { background: var(--accent-soft); }
}
@keyframes sheet-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Surfaces ---------- */
.panel, .status, .player-bar, .card-block, .stat-tile, .stat-card,
.opening-card, .coach, .move-list, .review-graph, .moment {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.panel, .card-block { border-radius: 14px; }
.panel-title, .card-block h2 { color: var(--text); }
.panel-title { color: var(--muted); letter-spacing: 0.06em; }
.select, .panel .select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}
.select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.bot-card, .game-row, .insight, .mini-tile, .score-bar { background: var(--card-2); }

/* ---------- Buttons ---------- */
.btn {
  background: var(--brand-gradient);
  color: #ffffff;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(29, 108, 240, 0.25);
}
.btn.secondary, .btn.small, .btn.small.secondary-link, .nav-btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line-strong);
  box-shadow: none;
}
.btn.secondary:hover:not(:disabled), .btn.small:hover:not(:disabled), .nav-btn:hover:not(:disabled) {
  filter: none;
  border-color: var(--accent);
  color: var(--accent);
}
.btn.small.on { background: var(--brand-gradient); color: #ffffff; border-color: transparent; }
.btn.danger { background: #dc2626; color: #ffffff; border-color: #dc2626; }
.btn:disabled { opacity: 0.45; box-shadow: none; }

/* ---------- Game page ---------- */
.board { box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16); border-radius: 8px; }
.player-bar { border-radius: 12px; padding: 8px 12px; gap: 10px; }
.player-info { gap: 10px; flex-wrap: wrap; row-gap: 4px; }
.player-bar .name { font-weight: 700; }
.clock {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 1.25rem;
}
.clock.active { background: var(--brand-gradient); color: #ffffff; border-color: transparent; }
.clock.low { background: #dc2626; color: #ffffff; border-color: #dc2626; }
.status { border-radius: 12px; font-weight: 600; }
.game-mode { background: #dcfce7; color: #166534; }
.game-mode.casual { background: var(--card-2); color: var(--muted); }
.lm.last, .mv.active { background: var(--accent); color: #ffffff; }
.live-moves { color: var(--text); }

/* Captured pieces: a light tray, so dark and light pieces always show */
.tray {
  flex-wrap: nowrap;
  min-height: 26px;
  padding: 2px 8px 2px 6px;
  border-radius: 8px;
  background: var(--tray);
  border: 1px solid #dfe4ec;
}
.tray:empty { background: transparent; border-color: transparent; padding: 0; }
.piece.tray-piece {
  width: 22px;
  height: 22px;
  margin-right: -7px;
  filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.25));
}
.tray .material { margin-left: 12px; color: #475569; font-weight: 700; font-size: 0.82rem; }

/* Bot picker */
.bot-card { border: 1px solid var(--line); }
.bot-card:hover { background: var(--card); border-color: var(--line-strong); }
.bot-card.selected { background: var(--accent-soft); border-color: var(--tier, var(--accent)); }
.bot-style { color: var(--muted); }
.bot-avatar { color: #ffffff; }

/* Review */
.moment-text, .game-opening, .challenge-reason { color: #475569; }
.coach-best { color: var(--good); }
.graph-bg { fill: #334155; }
.promo-option { background: #ffffff; }

/* Coach and plans */
.coach-bar { background: var(--card); border-color: var(--line); }
.coach-bar.warn { background: #fffbeb; border-color: #f59e0b; }
.coach-bar.check { background: var(--accent-soft); }
.plan-panel { background: var(--card); }
.plan-rule { background: var(--card-2); }

/* ---------- Profile and progress ---------- */
.stat-tile.streak-win .stat-tile-value, .rating-change.up, .trend.up { color: #16a34a; }
.stat-tile.streak-loss .stat-tile-value, .rating-change.down, .trend.down { color: #dc2626; }
.chart-grid { stroke: var(--line); }
.chart-area { fill: rgba(29, 108, 240, 0.12); }
.chart-dot.last { fill: #ffffff; }
.chart-peak { stroke: #d97706; }
.chart-peak-label { fill: #b45309; }
.data-table .th { border-bottom-color: var(--line-strong); }
.data-table .td { border-bottom-color: var(--line); }
.insight-tag { background: var(--card); color: var(--muted); }
.insight.strength .insight-tag, .mini-tag.best, .pill.done { background: #dcfce7; color: #166534; }
.insight.focus .insight-tag { background: #ffedd5; color: #9a3412; }
.insight.tip .insight-tag { background: #e0f2fe; color: #075985; }
.mini-tag.worst { background: #fee2e2; color: #991b1b; }
.mini-tile.blunder .mini-tile-value { color: #dc2626; }
.mini-tile.mistake .mini-tile-value { color: #ea580c; }
.mini-tile.inaccuracy .mini-tile-value { color: #ca8a04; }
.btn.small.secondary-link { background: var(--card); color: var(--text); }
.xp-stat { background: var(--card-2); }
.xp-bar { background: #e2e8f0; }
.xp-day-track { background: var(--card-2); }
.xp-day-bar { background: rgba(29, 108, 240, 0.45); }
.xp-toast { background: var(--card); color: var(--text); box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18); }
.xp-toast.xp { color: var(--accent); }
.xp-toast.goal { color: var(--good); }
.xp-toast.streak { color: #c2410c; }
.league-pawn { color: #64748b; }
.league-knight { color: #1d6cf0; }
.league-bishop { color: #7c3aed; }
.league-rook { color: #059669; }
.league-queen { color: #db2777; }
.league-king { color: #d97706; }
.league-last { background: var(--card-2); }
.league-last.up { color: var(--good); }
.league-last.down { color: var(--bad); }
.league-row { background: var(--card-2); }
.league-row.you { background: var(--accent-soft); }
.league-row.up .league-rank, .league-line.up { color: #16a34a; }
.league-row.down .league-rank, .league-line.down { color: #dc2626; }

/* ---------- Learning pages ---------- */
.level-desc, .lesson p, .summary p, .academy-text { color: #334155; }
.hub-note { color: var(--warn) !important; }
.quiz-option.right { background: #f0fdf4; border-color: #22c55e; }
.quiz-option.wrong { background: #fef2f2; border-color: #dc2626; }
.answer-btn.safe { background: #f0fdf4; border-color: #22c55e; color: var(--good); }
.answer-btn.unsafe { background: #fef2f2; border-color: #dc2626; color: var(--bad); }
.drill-feedback.good .feedback-head { color: var(--good); }
.drill-feedback.bad .feedback-head { color: var(--bad); }
.academy-error { background: #fef2f2; border-color: #dc2626; color: #991b1b; box-shadow: var(--shadow-md); }
.academy-error-close { color: #991b1b; }
.op-chip.book { color: #8b6f47; }
.op-chip.remove { color: var(--bad); border-color: #fecaca; }
.btn.answer-light { background: #ffffff; color: var(--text); border: 1px solid var(--line-strong); }

/* ---------- Kids and parents ---------- */
.kids-lock { background: rgba(244, 246, 250, 0.95); }
.kids-lock-message { color: var(--bad); }
.pd-message { color: var(--warn); }

/* ---------- Footer ---------- */
.site-footer { padding: 8px 16px 24px; color: var(--muted); }

/* ---------- Phones: an edge-to-edge board, like a real chess app ---------- */
@media (max-width: 760px) {
  :root { --size: min(100vw, calc(100vh - 290px)); }
  .layout { padding: 0 0 24px; gap: 10px; }
  .board-col { gap: 0; width: 100%; }
  .board { border-radius: 0; box-shadow: none; }
  .player-bar {
    width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    padding: 8px 12px;
  }
  .board-col > .player-bar:first-child { border-bottom: 0; }
  .board-col > .board + .player-bar { border-top: 0; }
  .clock { font-size: 1.15rem; padding: 4px 10px; }
  .game-actions, .premove-info, .coach-bar, .plan-panel { width: calc(100% - 24px); }
  .game-actions { margin-top: 10px; }
  .premove-info { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
  .side-col { width: calc(100% - 24px); }
  .review-dock { width: calc(100% - 24px); }
  .academy, .page, main { scroll-margin-top: 64px; }
}

/* Phones: before a game starts, skip straight from the board to choosing the opponent */
@media (max-width: 760px) {
  body[data-phase="setup"] .game-actions,
  body[data-phase="setup"] .premove-info,
  body[data-phase="setup"] #live-moves-card { display: none; }
}

/* ===== Step 32: accounts ===== */
.signin-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--brand-gradient);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(29, 108, 240, 0.25);
}
.signin-btn:hover { filter: brightness(1.06); }

.auth-page { max-width: 460px; margin: 24px auto 40px; padding: 0 16px; }
.auth-card { padding: 22px; }
.auth-card h2 { margin: 0 0 6px; }
.auth-tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--card-2); border-radius: 12px; }
.auth-tab {
  flex: 1;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.auth-tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form[hidden] { display: none; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; color: var(--text); }
.auth-form .select { width: 100%; padding: 12px; font-size: 1rem; }
.auth-form label.auth-check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--muted); }
.auth-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.auth-lead { margin: 0 0 4px; color: var(--muted); line-height: 1.45; }
.auth-submit { width: 100%; padding: 12px; font-size: 1rem; text-align: center; text-decoration: none; display: block; }
.auth-link { align-self: center; border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.9rem; cursor: pointer; padding: 4px; }
.auth-small { margin: 0; font-size: 0.82rem; color: var(--muted); text-align: center; }
.auth-message { min-height: 1.2em; margin: 10px 0 0; font-size: 0.9rem; color: var(--bad); }
.auth-notice { margin-bottom: 16px; padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }
.auth-notice.good { background: #f0fdf4; color: var(--good); border: 1px solid #bbf7d0; }
.auth-notice.bad { background: #fef2f2; color: var(--bad); border: 1px solid #fecaca; }

.account-block { display: flex; flex-direction: column; gap: 10px; }
.account-block.guest { flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: linear-gradient(135deg, #eff6ff, #ffffff); border-color: #bfdbfe; }
.account-block.guest h2 { margin: 0 0 4px; }
.account-block.guest .empty-note { margin: 0; max-width: 460px; }
.account-text { flex: 1; min-width: 220px; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.account-email { margin: 0; font-weight: 600; }
.account-badge { font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.account-badge.ok { background: #dcfce7; color: #166534; }
.account-badge.todo { background: #fef3c7; color: #92400e; }
.account-password { display: flex; gap: 8px; flex-wrap: wrap; }
.account-password[hidden] { display: none; }
.account-password .select { flex: 1; min-width: 180px; }

@media (max-width: 760px) {
  .signin-btn { padding: 6px 12px; font-size: 0.82rem; }
  .auth-page { margin-top: 12px; }
  .account-block.guest .account-actions { width: 100%; }
  .account-block.guest .account-actions .btn { flex: 1; text-align: center; }
}
