:root {
  --bg: #e7ebee;
  --surface: #f7f9fa;
  --surface-2: #edf1f3;
  --ink: #16202a;
  --muted: #56636f;
  --line: #cdd5db;
  --accent: #a8680f;
  --accent-strong: #c98a2c;
  --accent-ink: #ffffff;
  --sq-light: #e6dcc6;
  --sq-dark: #6e8597;
  --sq-last: rgba(214, 158, 52, 0.5);
  --sq-selected: rgba(214, 158, 52, 0.78);
  --dot: rgba(22, 32, 42, 0.3);
  --check: #d9483b;
  --eval-white: #f6f4ef;
  --eval-black: #29313a;
  --shadow: 0 1px 2px rgba(22, 32, 42, 0.08), 0 10px 28px rgba(22, 32, 42, 0.1);
  --good: #2f7d44;
  --blunder: #bf3b2c;
  --mistake: #b8620f;
  --inaccuracy: #8c7200;
  --mark-good: rgba(64, 160, 90, 0.6);
  --mark-bad: rgba(217, 72, 59, 0.55);
  --sans: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1418;
    --surface: #161c22;
    --surface-2: #1d252c;
    --ink: #e3e8ec;
    --muted: #93a0ab;
    --line: #29333b;
    --accent: #e3a449;
    --accent-strong: #e3a449;
    --accent-ink: #1b1306;
    --sq-light: #cdc3ac;
    --sq-dark: #577083;
    --dot: rgba(8, 12, 16, 0.38);
    --eval-white: #e8e5de;
    --eval-black: #07090b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
    --good: #6cc486;
    --blunder: #f07a6a;
    --mistake: #f0a04b;
    --inaccuracy: #d9bd4a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --surface: #161c22;
  --surface-2: #1d252c;
  --ink: #e3e8ec;
  --muted: #93a0ab;
  --line: #29333b;
  --accent: #e3a449;
  --accent-strong: #e3a449;
  --accent-ink: #1b1306;
  --sq-light: #cdc3ac;
  --sq-dark: #577083;
  --dot: rgba(8, 12, 16, 0.38);
  --eval-white: #e8e5de;
  --eval-black: #07090b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
  --good: #6cc486;
  --blunder: #f07a6a;
  --mistake: #f0a04b;
  --inaccuracy: #d9bd4a;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Author styles like `display: grid` would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Masthead */
.masthead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.brand { display: flex; align-items: baseline; color: inherit; text-decoration: none; }
.brand:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 4px; border-radius: 4px; }
.masthead .tabs { margin-left: auto; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}
.theme-toggle svg { width: 16px; height: 16px; }
/* Show the icon for the mode the button switches to. */
.theme-toggle .icon-sun { display: none; }
.theme-toggle.is-dark .icon-sun { display: block; }
.theme-toggle.is-dark .icon-moon { display: none; }
.tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tabs a {
  padding: 6px 14px;
  border-radius: 5px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--surface); }
.tabs a:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
@media (max-width: 640px) {
  .masthead { column-gap: 12px; }
  .masthead .tabs { order: 3; width: 100%; margin-left: 0; }
  .tabs { gap: 2px; }
  .tabs a { flex: 1 1 auto; min-width: 0; text-align: center; padding-inline: 4px; font-size: 14px; }
  .theme-toggle { margin-left: auto; }
  .wordmark { white-space: nowrap; }
}
@media (max-width: 480px) {
  /* Icon only, so the name and the switch share a row (the button keeps its aria-label). */
  .theme-toggle { padding: 8px 10px; }
  .theme-toggle span { display: none; }
}
@media (max-width: 380px) {
  .tabs a { padding-inline: 2px; font-size: 13px; }
}
.wordmark {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 850;
  font-stretch: 125%;
  font-variation-settings: "wdth" 125;
  letter-spacing: -0.01em;
  line-height: 1;
  text-wrap: balance;
}
.spec { margin: 0; font: 500 12px/1.4 var(--mono); color: var(--muted); letter-spacing: 0.02em; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 700px) 340px;
  justify-content: center;
  gap: 24px;
  align-items: start;
}
/* After a game, the review becomes a third column on wide screens and
   drops below the board and panel on narrower ones. */
.layout .review { grid-column: 1 / -1; }
@media (min-width: 1300px) {
  .layout.has-review { grid-template-columns: minmax(0, 660px) 330px 300px; }
  .layout.has-review .review { grid-column: auto; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.board-area { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.board-area > * { width: 100%; max-width: min(660px, calc(100vh - 150px)); min-width: 0; }
@media (max-width: 860px) {
  .board-area > * { max-width: 100%; }
}

.player { display: flex; align-items: baseline; gap: 10px; padding-left: 20px; min-height: 24px; }
.player-name { font-weight: 650; font-size: 16px; }
.player-side { font: 500 12px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.player.to-move .player-name::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent-strong);
  vertical-align: 2px;
}

.board-row { display: flex; gap: 8px; }

/* Evaluation bar: the light part is White's share. */
.evalbar {
  position: relative;
  flex: 0 0 12px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--eval-black);
  box-shadow: inset 0 0 0 1px var(--line);
}
.evalbar-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: var(--eval-white);
  transition: height 0.45s ease;
}
.evalbar.white-top .evalbar-fill { top: 0; bottom: auto; }

.board-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before, .sq.selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sq-last);
}
.sq.selected::before { background: var(--sq-selected); }
.sq.check {
  background-image: radial-gradient(circle at center, var(--check) 0%, rgba(217, 72, 59, 0.55) 35%, transparent 72%);
}
.sq.target::after {
  content: "";
  position: absolute;
  inset: 37%;
  border-radius: 50%;
  background: var(--dot);
  z-index: 2;
}
.sq.target.capture::after {
  inset: 3%;
  background: radial-gradient(circle, transparent 62%, var(--dot) 64%);
}
.sq.drop-hover { box-shadow: inset 0 0 0 3px var(--accent-strong); }
.sq.mark-good::before, .sq.mark-bad::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--mark-good);
}
.sq.mark-bad::before { background: var(--mark-bad); }
.sq.ring-danger { box-shadow: inset 0 0 0 3px var(--blunder); }
.sq.ring-chance { box-shadow: inset 0 0 0 3px var(--good); }
.piece { will-change: transform; }
.piece {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-size: 100% 100%;
  pointer-events: none;
}
.board.interactive .sq.own { cursor: grab; }
.sq.dragging .piece { opacity: 0.25; }
.ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background-size: 100% 100%;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.3));
}
.coord {
  position: absolute;
  z-index: 3;
  font: 600 clamp(8px, 1.5vw, 11px)/1 var(--mono);
  pointer-events: none;
}
.coord.rank { top: 3px; left: 3px; }
.coord.file { bottom: 3px; right: 4px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.board-note {
  position: absolute;
  inset: auto 12px 12px 12px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.board-note p { margin: 0; }

.promotion {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(10, 14, 18, 0.45);
  border-radius: 4px;
}
.promotion-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 16px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.promotion-card p { margin: 0; font-weight: 600; }
.promotion-choices { display: flex; gap: 8px; }
.promotion-choices button {
  width: clamp(48px, 11vw, 72px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: var(--sq-light);
  background-size: 100% 100%;
  cursor: pointer;
}
.promotion-choices button:hover { border-color: var(--accent-strong); }

/* Side panel */
.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}

.status-block { display: flex; flex-direction: column; gap: 12px; }
.status { margin: 0; font-size: 20px; font-weight: 650; line-height: 1.25; text-wrap: balance; overflow-wrap: anywhere; }

.readout {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}
.readout > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.readout dt, .move-form label, legend {
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.readout dd {
  margin: 0;
  font: 500 18px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pv {
  margin: 0;
  min-height: 1.5em;
  font: 400 13px/1.5 var(--mono);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.opening-name { margin: 0; font-size: 13px; color: var(--muted); }
.opening-name b { color: var(--ink); font-weight: 600; }
.coach-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.coach-row #hint { margin-left: auto; padding: 6px 12px; }
.coach-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: -4px 0 0; font-size: 12px; color: var(--muted); }
.ring-key { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-left: 4px; }
.ring-key:first-child { margin-left: 0; }
.ring-key.danger { box-shadow: inset 0 0 0 2px var(--blunder); }
.ring-key.chance { box-shadow: inset 0 0 0 2px var(--good); }
.move-form { display: flex; flex-direction: column; gap: 6px; }
.move-form-row { display: flex; gap: 8px; }
.move-form input { flex: 1; font-family: var(--mono); }
.form-error { margin: 0; color: var(--check); font-size: 13px; }

.sheet {
  max-height: 260px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.sheet table { width: 100%; border-collapse: collapse; font: 400 14px/1.4 var(--mono); font-variant-numeric: tabular-nums; }
.sheet th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  padding: 8px 6px 6px;
}
.sheet td { padding: 3px 6px; }
.sheet td:first-child, .sheet th:first-child { width: 3ch; color: var(--muted); text-align: right; padding-right: 12px; }
.sheet tbody tr:nth-child(odd) { background: var(--surface-2); }
.sheet td.current { color: var(--accent); font-weight: 600; }
.sheet .glyph { margin-left: 1px; font-weight: 600; }
.glyph.blunder { color: var(--blunder); }
.glyph.mistake { color: var(--mistake); }
.glyph.inaccuracy { color: var(--inaccuracy); }
.sheet-empty { margin: 0; padding: 10px 6px; color: var(--muted); font-size: 14px; }

.controls { display: flex; flex-direction: column; gap: 14px; }
.segmented { display: flex; flex-wrap: wrap; gap: 0; margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented legend { width: 100%; margin-bottom: 6px; padding: 0; }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 7px 10px;
  border: 1px solid var(--line);
  margin-left: -1px;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
  background: var(--bg);
}
.segmented label:first-of-type span { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type span { border-radius: 0 6px 6px 0; }
.segmented input:checked + span { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.field input, .move-form input {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}
/* Your name, and once names are locked, its password. */
.account { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.account-lock { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.account-lock button { min-width: 7.5em; }
.account-note { margin: 0; font-size: 13px; color: var(--muted); }
.account-note:empty { display: none; }
.account-signed-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}
.account-signed-in p { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.account-signed-in span { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.account-signed-in strong { font-size: 15px; }
.account-options { display: flex; flex-direction: column; gap: 6px; margin: -6px 0 0; padding: 0 2px; border: 0; min-width: 0; }
.account-options .check input:disabled + span { opacity: 0.5; cursor: default; }
.row-tag { margin-left: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.level-picker { margin: 0; padding: 0; border: 0; min-width: 0; }
.level-picker legend { margin-bottom: 6px; padding: 0; }
/* Rows of four beginner levels, three stronger ones, then Summer, Titan and Pinky. */
.levels { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; }
.levels label { position: relative; grid-column: span 3; }
.levels label:nth-child(n + 5) { grid-column: span 4; }
.levels input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.levels span {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}
.levels b {
  font-size: 13px;
  font-weight: 650;
  font-stretch: 85%;
  font-variation-settings: "wdth" 85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.levels small { font: 500 12px/1.2 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.levels input:checked + span { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.levels input:checked + span small { color: inherit; opacity: 0.8; }
.levels input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.levels input:disabled + span { opacity: 0.5; cursor: default; }
.game-note { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#new-game { width: 100%; padding-block: 10px; }
#resign.confirming, #friend-resign.confirming { border-color: var(--blunder); color: var(--blunder); }
button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { border-color: var(--ink); }

.pgn {
  width: 100%;
  min-height: 110px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font: 400 12px/1.5 var(--mono);
  resize: vertical;
}

.footer { color: var(--muted); font-size: 13px; }
.footer p { margin: 0; max-width: 72ch; }
.footer code { font-family: var(--mono); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .evalbar-fill { transition: none; }
}

/* Review */
.review {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}
.review h2 { margin: 0; font-size: 18px; font-weight: 700; }
.review h3 { margin: 4px 0 0; font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.review-progress p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent-strong); transition: width 0.3s ease; }
.review-scores { display: flex; flex-wrap: wrap; gap: 6px 28px; }
.review-score { display: flex; align-items: baseline; gap: 8px; }
.review-rating-note { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.game-rating { margin-left: 6px; color: var(--muted); font-size: 12px; }
.review-accuracy { font: 700 40px/1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.review-accuracy-label { color: var(--muted); font-size: 14px; }
.verdict-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.verdict-counts li {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.verdict-counts li b { font-weight: 700; }
.verdict-counts .blunder b, .chip.blunder { color: var(--blunder); }
.verdict-counts .mistake b, .chip.mistake { color: var(--mistake); }
.verdict-counts .inaccuracy b, .chip.inaccuracy { color: var(--inaccuracy); }
.mistakes { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.mistakes button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font-weight: 400;
  background: var(--bg);
}
.mistakes button[aria-pressed="true"] { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.mistake-move { font: 600 15px/1.3 var(--mono); }
.chip { font: 600 11px/1.6 var(--sans); text-transform: uppercase; letter-spacing: 0.08em; justify-self: end; }
.mistake-better { grid-column: 1 / -1; font-size: 14px; }
.mistake-better b { font-family: var(--mono); color: var(--good); }
.mistake-eval { grid-column: 1 / -1; font: 400 12px/1.4 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.review-empty, .review-error { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.review-viewing {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 14px;
}

/* Learn */
.learn {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}
@media (max-width: 860px) {
  .learn { grid-template-columns: minmax(0, 1fr); }
}
.lesson-list h2 { margin: 0 0 10px; font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.lesson-list ol { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; counter-reset: lesson; }
.lesson-list button {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 0 6px;
  width: 100%;
  padding: 8px 10px;
  border-color: transparent;
  background: transparent;
  text-align: left;
  font-weight: 400;
}
.lesson-list button::before {
  counter-increment: lesson;
  content: counter(lesson);
  grid-row: span 2;
  font: 600 13px/1.5 var(--mono);
  color: var(--muted);
}
.lesson-list button.done::before { content: "✓"; color: var(--good); }
.lesson-list button[aria-current="true"] { background: var(--surface); border-color: var(--line); }
.lesson-list .lesson-name { font-weight: 650; }
.lesson-list .lesson-summary { font-size: 13px; color: var(--muted); }
.lesson {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}
.lesson h2 { margin: 0; font-size: clamp(22px, 3vw, 28px); font-weight: 750; text-wrap: balance; }
.lesson-body { display: flex; flex-direction: column; gap: 10px; max-width: 68ch; }
.lesson-body p { margin: 0; line-height: 1.6; }
.puzzle {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 700px) {
  .puzzle { grid-template-columns: minmax(0, 1fr); }
}
.puzzle-side { display: flex; flex-direction: column; gap: 12px; }
.puzzle-goal { margin: 0; font-weight: 650; font-size: 16px; }
.puzzle-feedback { margin: 0; min-height: 1.5em; line-height: 1.5; }
.puzzle-feedback.right { color: var(--good); }
.puzzle-feedback.wrong { color: var(--blunder); }
.puzzle-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.lesson-nav { display: flex; justify-content: space-between; gap: 8px; }

/* Stats */
.stats { display: flex; flex-direction: column; gap: 18px; max-width: 1120px; width: 100%; margin: 0 auto; }
.stats-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stats-head h2 { margin: 0; font-size: clamp(22px, 3vw, 28px); font-weight: 750; }
.stats-source, .stats-message { margin: 4px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.stats-message { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
}
.tiles > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.tiles dt { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.tiles dd { margin: 0; font: 700 26px/1.1 var(--sans); font-variant-numeric: tabular-nums; }
.tiles dd small { display: block; margin-top: 2px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.data-table th {
  padding: 10px 12px 8px;
  text-align: left;
  white-space: nowrap;
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; }
.data-table td.num { font-family: var(--mono); }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.data-table .player-link { padding: 0; border: 0; background: none; font-weight: 650; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.data-table .empty { padding: 20px 12px; color: var(--muted); white-space: normal; }
.result-win { color: var(--good); font-weight: 600; }
.result-loss { color: var(--blunder); font-weight: 600; }
.provisional { color: var(--muted); font-weight: 400; }
.player-title { margin: 8px 0 0; font-size: 24px; font-weight: 750; }
.stats h4 { margin: 8px 0 -8px; font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
#stats-player { display: flex; flex-direction: column; gap: 14px; }
#stats-back { align-self: flex-start; }
.stats-footnote { margin: 0; max-width: 80ch; color: var(--muted); font-size: 13px; }

/* Home */
.home {
  display: flex;
  flex-direction: column;
  gap: 64px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding-block: 12px 24px;
}
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 56px;
  align-items: center;
}
@media (max-width: 860px) {
  .hero { grid-template-columns: minmax(0, 1fr); gap: 32px; }
}
.eyebrow {
  margin: 0 0 14px;
  font: 600 12px/1.2 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero-title {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(38px, 5.8vw, 68px);
  font-weight: 800;
  font-stretch: 112%;
  font-variation-settings: "wdth" 112;
  line-height: 1.02;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.hero-lede { margin: 20px 0 0; max-width: 52ch; font-size: 18px; line-height: 1.55; color: var(--muted); }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 30px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { border-color: var(--ink); }
.button:focus-visible, .text-link:focus-visible, .feature:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 3px; }
.text-link, .hero-credit a, .credit-list a, .about-links a, .footer a {
  color: var(--ink);
  font-weight: 600;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
.text-link:hover, .hero-credit a:hover, .credit-list a:hover, .about-links a:hover, .footer a:hover { text-decoration-color: currentColor; }
.hero-credit { margin: 28px 0 0; font-size: 14px; color: var(--muted); }
.hero-live { margin: 6px 0 0; font: 500 13px/1.4 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }

.showcase { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.showcase-board { width: 100%; max-width: 460px; }
.showcase .board { box-shadow: var(--shadow), 0 0 0 10px var(--surface), 0 0 0 11px var(--line); border-radius: 2px; }
.showcase figcaption { display: grid; gap: 2px; padding-top: 10px; }
.showcase-move { font: 700 22px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.showcase-title { font-weight: 700; }
.showcase-meta { font-size: 13px; color: var(--muted); max-width: 46ch; }
@media (max-width: 860px) {
  .showcase-board { max-width: 420px; }
}

.home-section { display: flex; flex-direction: column; gap: 22px; }
.home-section h2 {
  margin: 0;
  font-size: clamp(26px, 3.2vw, 36px);
  font-weight: 800;
  font-stretch: 106%;
  font-variation-settings: "wdth" 106;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.section-lede { margin: -10px 0 0; max-width: 65ch; color: var(--muted); }

.steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
@media (max-width: 960px) {
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .steps { grid-template-columns: minmax(0, 1fr); }
}
.steps li { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 2px solid var(--ink); counter-increment: step; }
.steps li::before { content: counter(step, decimal-leading-zero); font: 600 13px/1 var(--mono); color: var(--accent); }
.steps h3 { margin: 0; font-size: 18px; font-weight: 700; }
.steps p { margin: 0; line-height: 1.55; color: var(--muted); }
.steps b { color: var(--ink); font-weight: 650; }
.steps code, .about code { font-family: var(--mono); font-size: 0.92em; color: var(--ink); }

.ladder {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (max-width: 800px) {
  .ladder { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.ladder li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.ladder .rating { font: 700 26px/1 var(--mono); font-variant-numeric: tabular-nums; }
.ladder .name { margin-top: 6px; font-weight: 700; }
.ladder .how { font-size: 13px; line-height: 1.45; color: var(--muted); }
/* On phones the levels read as one list: rating on the left, name and description beside it. */
@media (max-width: 560px) {
  .ladder { grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
  .ladder li {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    column-gap: 12px;
    padding: 12px 14px;
    border: 0;
    border-radius: 0;
    background: none;
  }
  .ladder li + li { border-top: 1px solid var(--line); }
  .ladder .rating { grid-row: span 2; font-size: 20px; align-self: center; }
  .ladder .name { margin-top: 0; }
}

/* Three cards over two. */
.features { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.feature { grid-column: span 2; }
.feature:nth-child(n + 4) { grid-column: span 3; }
@media (max-width: 760px) {
  .features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature, .feature:nth-child(n + 4) { grid-column: auto; }
  .feature:last-child { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .features { grid-template-columns: minmax(0, 1fr); }
}
.feature {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
.feature:hover { border-color: var(--muted); }
.feature h3 { margin: 0; font-size: 20px; font-weight: 750; }
.feature h3::after { content: " →"; color: var(--accent); }
.feature p { margin: 0; line-height: 1.55; color: var(--muted); }

.about-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 760px) {
  .about-grid { grid-template-columns: minmax(0, 1fr); }
}
.about-grid p { margin: 0; line-height: 1.6; max-width: 62ch; }
.about-links { margin: 0; }

.credit-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 24px; margin: 0; }
.credit-list > div { display: flex; flex-direction: column; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.credit-list dt { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.credit-list dd { margin: 0; }
.footer { display: flex; flex-direction: column; gap: 4px; }

/* Rating chart (one series: the player's estimated rating) */
.chart-block { display: flex; flex-direction: column; gap: 12px; }
.chart-sub { margin: 0; font-size: 13px; color: var(--muted); }
.chart {
  position: relative;
  padding: 12px 12px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.chart:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; touch-action: pan-y; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font: 500 11px var(--mono); font-variant-numeric: tabular-nums; }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-dot, .chart .hover-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font: 600 12px var(--mono); }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-tooltip {
  position: absolute;
  z-index: 2;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}
.chart-tooltip b { display: block; font: 700 16px/1.2 var(--mono); color: var(--ink); }
.chart-table summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.chart-table .table-wrap { margin-top: 8px; max-height: 260px; overflow-y: auto; }

/* Badges */
.badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.badge {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.badge-icon { grid-row: span 2; font-size: 26px; line-height: 1; text-align: center; }
.badge-name { font-size: 14px; font-weight: 700; }
.badge-desc { font-size: 12px; line-height: 1.35; color: var(--muted); }
.badge.earned { border-color: var(--accent); }
.badge.earned .badge-icon { color: var(--accent); }
.badge.locked { opacity: 0.55; }
.badge.locked .badge-icon { filter: grayscale(1); }

/* Game viewer */
#stats-game { display: flex; flex-direction: column; gap: 14px; }
#viewer-back { align-self: flex-start; }
.viewer-meta { margin: -6px 0 0; color: var(--muted); }
.viewer { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 760px) {
  .viewer { grid-template-columns: minmax(0, 1fr); }
}
.viewer-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.viewer-controls { display: flex; align-items: center; gap: 6px; }
.viewer-controls button { min-width: 44px; padding-inline: 8px; }
.viewer-position { flex: 1; text-align: center; font: 500 14px var(--mono); font-variant-numeric: tabular-nums; }
.viewer-sheet { max-height: 320px; }
.move-link {
  padding: 1px 4px;
  border: 0;
  border-radius: 4px;
  background: none;
  font: inherit;
  font-weight: 400;
}
.move-link:hover { background: var(--surface-2); }
.move-link.active { background: var(--ink); color: var(--surface); }
.review-progress-text { margin: 0; font-size: 14px; color: var(--muted); }

/* Puzzles */
.trainer {
  display: grid;
  grid-template-columns: minmax(0, 620px) 340px;
  justify-content: center;
  gap: 24px;
  align-items: start;
  width: 100%;
}
@media (max-width: 860px) {
  .trainer { grid-template-columns: minmax(0, 1fr); }
}
.trainer-board { width: 100%; max-width: min(620px, calc(100vh - 150px)); }
@media (max-width: 860px) {
  .trainer-board { max-width: 100%; }
}
.trainer-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}
.trainer-rating { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 10px; }
.trainer-label {
  grid-column: 1 / -1;
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.trainer-number { font: 700 44px/1.1 var(--sans); letter-spacing: -0.02em; }
.trainer-change { font: 600 15px var(--mono); }
.trainer-change.up { color: var(--good); }
.trainer-change.down { color: var(--blunder); }
.trainer-prompt { margin: 0; font-size: 18px; font-weight: 650; }
.trainer-feedback { margin: 0; min-height: 1.5em; line-height: 1.5; overflow-wrap: anywhere; }
.trainer-feedback.right { color: var(--good); }
.trainer-feedback.wrong { color: var(--blunder); }
.trainer-facts { margin: 0; font-size: 14px; color: var(--muted); }
.trainer-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trainer-buttons .primary { grid-column: 1 / -1; padding-block: 10px; }
.trainer-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.trainer-stats > div { display: flex; flex-direction: column; gap: 2px; }
.trainer-stats dt { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.trainer-stats dd { margin: 0; font: 600 20px var(--mono); font-variant-numeric: tabular-nums; }
.trainer-note { margin: 0; font-size: 13px; color: var(--muted); }

/* Installing and offline */
.install-note { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 18px 0 0; font-size: 14px; color: var(--muted); }
.offline-banner {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 14px;
}

/* Friend */
.friend .player { padding-left: 0; }
.friend-lobby, .friend-invite, .friend-game { display: flex; flex-direction: column; gap: 14px; }
.friend-lobby h2, .friend-invite h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.friend-lobby > p:not(.game-note), .friend-invite p { margin: 0; color: var(--muted); font-size: 15px; }
.friend-lobby .game-note { margin: 0; }
.friend-lobby > button, .friend-invite > button { width: 100%; padding-block: 10px; }
.friend-share, .friend-draw { display: flex; flex-direction: column; gap: 6px; }
.friend-draw { flex-direction: row; }
.friend-draw button { flex: 1; }
.friend-share label, .friend-recent h3 {
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.friend-share input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font: 13px var(--mono);
}
.friend-recent h3 { margin: 4px 0 8px; }
.friend-recent ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.friend-recent a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}
.friend-recent a:hover { border-color: var(--muted); }
.friend-recent a span:last-child { color: var(--muted); white-space: nowrap; }

/* Why these moves? */
.why { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.why-title, .why-breakdown h3 {
  margin: 0;
  font: 600 11px/1.2 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.why-moves { display: flex; flex-direction: column; gap: 10px; }
.why-move { display: flex; flex-direction: column; gap: 4px; }
.why-head { margin: 0; display: flex; align-items: baseline; gap: 8px; }
.why-head b { font: 600 15px var(--mono); }
.why-head span { font-size: 12px; color: var(--muted); }
.why-reasons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.why-reasons li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 6px; font-size: 14px; line-height: 1.4; }
.why-icon { font-weight: 800; text-align: center; }
.why-reasons .good .why-icon { color: var(--good); }
.why-reasons .bad .why-icon { color: var(--blunder); }
.why-reasons .neutral .why-icon { color: var(--muted); }
.why-loading { margin: 0; font-size: 13px; color: var(--muted); }
.why-breakdown { display: flex; flex-direction: column; gap: 6px; }
.why-axis { display: flex; justify-content: space-between; margin-left: 84px; margin-right: 92px; font-size: 11px; color: var(--muted); }
.why-terms { display: flex; flex-direction: column; gap: 5px; }
.why-term { display: grid; grid-template-columns: 76px minmax(0, 1fr) 84px; align-items: center; gap: 8px; font-size: 13px; }
.why-term-name { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.why-term-track { position: relative; height: 12px; }
/* The zero line: bars grow from it, towards the side they favour. */
.why-term-track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--line);
}
.why-term-bar { position: absolute; top: 1px; height: 10px; box-sizing: border-box; border: 1px solid var(--muted); }
.why-term-bar.white { left: 50%; background: var(--eval-white); border-left: 0; border-radius: 0 4px 4px 0; }
.why-term-bar.black { right: 50%; background: var(--eval-black); border-right: 0; border-radius: 4px 0 0 4px; }
.why-term-value { font: 500 11px var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.why-term-value span { color: var(--muted); }
.why-note { margin: 0; font-size: 11px; color: var(--muted); }
.review-why { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.review-why .why-head b { font-size: 14px; }

