/*
 * learn-chess - mobile first.
 *
 * Design language: a calm light surface, white cards with generous padding,
 * icon-led list rows, pill buttons, one accent colour used sparingly.
 * Dark mode mirrors the same structure rather than inverting it crudely.
 */

:root {
  --bg: #fefefe;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --surface-3: #eceff3;
  --line: #e4e7ec;
  --line-soft: #eff1f4;
  --text: #14171c;
  --text-2: #3b414b;
  --muted: #6b7280;

  --accent: #1f6feb;
  --accent-press: #1858c4;
  --accent-soft: #e8f0fe;
  --accent-ink: #ffffff;

  --good: #0f9d76;
  --good-soft: #e6f6f1;
  --bad: #e04a4a;
  --bad-soft: #fdecec;
  --warn: #d98324;
  --warn-soft: #fdf2e3;

  --sq-light: #ebdfc6;
  --sq-dark: #7b6a4f;
  --piece-white: #fbf7ef;
  --piece-black: #17140f;
  --piece-edge-dark: #2b2620;
  --piece-edge-light: rgba(248, 245, 238, 0.85);

  --radius: 16px;
  --radius-sm: 12px;
  --tabbar: 64px;
  --shadow: 0 1px 2px rgba(20, 24, 32, 0.05), 0 1px 3px rgba(20, 24, 32, 0.04);
}

/* Dark tokens are declared twice on purpose: once for the system preference
   (unless the user has explicitly chosen light), and once for an explicit
   choice, so the in-app switch wins in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --bg: #1a1a1d;
    --surface: #232327;
    --surface-2: #2a2a2f;
    --surface-3: #33333a;
    --line: #35353d;
    --line-soft: #2c2c32;
    --text: #f4f5f7;
    --text-2: #d8dade;
    --muted: #a4a8ae;

    --accent: #6ea8ff;
    --accent-press: #5a97f5;
    --accent-soft: #3a4459;
    --accent-ink: #14171c;

    --good: #4cd4a8;
    --good-soft: #2f4741;
    --bad: #ff7b7b;
    --bad-soft: #4d3737;
    --warn: #edb35c;
    --warn-soft: #4b4030;

    --shadow: none;
  }
}

:root[data-scheme="dark"] {
    --bg: #1a1a1d;
    --surface: #232327;
    --surface-2: #2a2a2f;
    --surface-3: #33333a;
    --line: #35353d;
    --line-soft: #2c2c32;
    --text: #f4f5f7;
    --text-2: #d8dade;
    --muted: #a4a8ae;

    --accent: #6ea8ff;
    --accent-press: #5a97f5;
    --accent-soft: #3a4459;
    --accent-ink: #14171c;

    --good: #4cd4a8;
    --good-soft: #2f4741;
    --bad: #ff7b7b;
    --bad-soft: #4d3737;
    --warn: #edb35c;
    --warn-soft: #4b4030;

    --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px 28px;
}

h1 { font-size: 1.6rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.02rem; font-weight: 600; margin: 0 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 6px; }
p  { margin: 0 0 12px; color: var(--text-2); }
p:last-child { margin-bottom: 0; }
a  { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* ------------------------------- layout ------------------------------- */

.screen-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 2px 18px;
}
.screen-head p { margin: 3px 0 0; color: var(--muted); font-size: 0.92rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }

/* ------------------------------ buttons ------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
.btn.danger { color: var(--bad); border-color: var(--line); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.done { color: var(--good); border-color: var(--line); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.small { padding: 7px 14px; font-size: 0.85rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.danger { color: var(--muted); border: none; background: transparent; box-shadow: none; font-size: 1.3rem; }
.icon-btn.danger:hover { color: var(--bad); }
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-sm { width: 17px; height: 17px; }

.hidden-file { display: none; }

/* -------------------------------- tabs -------------------------------- */

#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
}
.tab .icon { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab.active .tab-label { font-weight: 600; }

/* ----------------------------- list rows ------------------------------ */

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.list-row:first-child { padding-top: 0; }
.list-row:last-child { border-bottom: none; padding-bottom: 0; }

.row-icon {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: var(--surface-3);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.row-icon.accent { background: var(--accent-soft); color: var(--accent); }
.row-icon.good { background: var(--good-soft); color: var(--good); }
.row-icon.warn { background: var(--warn-soft); color: var(--warn); }
.row-icon.bad { background: var(--bad-soft); color: var(--bad); }

.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 0.96rem; font-weight: 600; color: var(--text); letter-spacing: -0.005em; }
.row-sub {
  font-size: 0.84rem;
  color: var(--muted);
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row-action { flex-shrink: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.chevron { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }

/* ------------------------------- streak ------------------------------- */

.streak-card { display: block; }
.streak-main { display: flex; align-items: center; gap: 16px; }
.streak-ring { position: relative; width: 76px; height: 76px; flex-shrink: 0; }
.streak-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.streak-ring .track { stroke: var(--surface-3); }
.streak-ring .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.streak-ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  line-height: 1;
}
.streak-number { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.streak-unit { font-size: 0.62rem; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.06em; }
.streak-copy { flex: 1; min-width: 0; }
.streak-head { font-size: 1.02rem; font-weight: 600; margin-bottom: 2px; }

.strip { display: flex; gap: 4px; margin-top: 18px; }
.strip-day { flex: 1; height: 30px; border-radius: 6px; background: var(--surface-3); }
.strip-day.level-1 { background: color-mix(in srgb, var(--accent) 28%, var(--surface-3)); }
.strip-day.level-2 { background: color-mix(in srgb, var(--accent) 60%, var(--surface-3)); }
.strip-day.level-3 { background: var(--accent); }
.strip-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 0.72rem; color: var(--muted); }

/* ----------------------------- challenges ----------------------------- */

.challenge {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.challenge:first-child { padding-top: 0; }
.challenge:last-child { border-bottom: none; padding-bottom: 0; }
.challenge-check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: transparent;
}
.challenge.done .challenge-check { background: var(--good); border-color: var(--good); color: #fff; }
.challenge-body { flex: 1; min-width: 0; }
.challenge-label { font-size: 0.95rem; font-weight: 500; }
.challenge.done .challenge-label { color: var(--muted); }
.challenge-track { height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 7px; }
.challenge-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }
.challenge.done .challenge-fill { background: var(--good); }
.challenge-count { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }
.progress-fill.strong { background: var(--good); }
.progress-fill.mid { background: var(--warn); }
.progress-fill.weak { background: var(--bad); }
.progress-fill.thin { background: var(--surface-3); }

/* -------------------------------- misc -------------------------------- */

.pill {
  background: var(--surface-3);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.tip { font-size: 1rem; line-height: 1.55; color: var(--text-2); }

.banner {
  display: flex; align-items: center; gap: 14px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.banner .row-icon { background: var(--surface); color: var(--accent); }

/* ------------------------------ lessons ------------------------------- */

.track-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.lesson-title { font-size: 0.96rem; font-weight: 600; }
.lesson-row.done .lesson-title { color: var(--muted); }
.lesson-meta { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.lesson p { font-size: 1rem; line-height: 1.6; color: var(--text-2); }
.bullets { margin: 0 0 16px; padding-left: 22px; color: var(--text-2); }
.bullets li { margin-bottom: 8px; }
.takeaways { color: var(--text-2); }

/* ------------------------------- board -------------------------------- */

.board-wrap { position: relative; margin: 4px 0; }
.board-host { margin: 14px 0; }

.board {
  display: grid;
  /* minmax(0,1fr) so a tall piece cannot inflate its row above an equal share */
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 2px 10px rgba(20, 20, 40, 0.09);
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }

.sq[data-show-file="1"]::after {
  content: attr(data-file);
  position: absolute; right: 4px; bottom: 1px;
  font-size: 0.56rem; font-weight: 700; opacity: 0.5;
  color: var(--piece-black);
}
.sq.dark[data-show-file="1"]::after { color: var(--sq-light); }
.sq[data-show-rank="1"]::before {
  content: attr(data-rank);
  position: absolute; left: 4px; top: 1px;
  font-size: 0.56rem; font-weight: 700; opacity: 0.5;
  color: var(--piece-black);
}
.sq.dark[data-show-rank="1"]::before { color: var(--sq-light); }

/* Pieces are SVG so every device gets the same set. Fill and outline come
   from custom properties, so a theme recolours them with no markup change. */
.piece {
  width: 100%; height: 100%;
  display: block;
  box-sizing: border-box;
  padding: 4.5%;
  pointer-events: none;
  filter: drop-shadow(0 1.5px 1.5px rgba(0, 0, 0, 0.25));
}
.pc { width: 100%; height: 100%; display: block; }
.pc-body path {
  fill: var(--pc-fill);
  stroke: var(--pc-stroke);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.pc-line { fill: none; stroke: var(--pc-stroke); stroke-width: 1.4; stroke-linecap: round; }
.pc-dot { fill: var(--pc-stroke); }

.piece.white { --pc-fill: var(--piece-white); --pc-stroke: var(--piece-edge-dark); }
.piece.black { --pc-fill: var(--piece-black); --pc-stroke: var(--piece-edge-light); }

.piece.dragging {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  transform: scale(1.15);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.sq.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.sq.last-from, .sq.last-to { background-image: linear-gradient(rgba(31, 111, 235, 0.24), rgba(31, 111, 235, 0.24)); }
.sq.in-check { background-image: radial-gradient(circle, rgba(224, 74, 74, 0.85) 12%, transparent 72%); }
.sq.mark-hint { box-shadow: inset 0 0 0 3px var(--good); }
.sq.mark-good { background-image: linear-gradient(rgba(15, 157, 118, 0.38), rgba(15, 157, 118, 0.38)); }
.sq.mark-bad  { background-image: linear-gradient(rgba(224, 74, 74, 0.38), rgba(224, 74, 74, 0.38)); }

.sq.target::after {
  content: '';
  position: absolute;
  width: 27%; height: 27%;
  border-radius: 50%;
  background: rgba(20, 18, 14, 0.26);
}
.sq.dark.target::after { background: rgba(255, 255, 255, 0.3); }
.sq.target-capture { box-shadow: inset 0 0 0 4px rgba(20, 18, 14, 0.24); }
.sq.dark.target-capture { box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.26); }

/* board themes -------------------------------------------------------- */

body[data-board="forest"] { --sq-light: #eeeed2; --sq-dark: #769656; --piece-white: #ffffff; --piece-black: #262421; }
body[data-board="slate"]  { --sq-light: #dee3ea; --sq-dark: #6f8199; --piece-white: #fbfdff; --piece-black: #1f262f; }
body[data-board="ink"]    { --sq-light: #d8d4cd; --sq-dark: #4a4a4a; --piece-white: #fbf9f5; --piece-black: #17171a; }

.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.theme-option {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
}
.theme-option.active { border-color: var(--accent); background: var(--accent-soft); }
.theme-name { font-size: 0.88rem; font-weight: 600; margin-top: 9px; }
.theme-swatch {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 8px;
  overflow: hidden;
}
.theme-swatch i { display: block; }

/* promotion ------------------------------------------------------------ */

.promo {
  position: absolute; inset: 0;
  background: rgba(15, 15, 20, 0.86);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  border-radius: 10px;
  z-index: 40;
}
.promo-title { color: #fff; font-size: 0.9rem; font-weight: 500; }
.promo-row { display: flex; gap: 10px; }
.promo-btn {
  width: 62px; height: 62px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--sq-light);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 4px;
}
.promo-cancel { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 0.85rem; cursor: pointer; font-family: inherit; }

/* ------------------------------ puzzles ------------------------------- */

.prompt-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.prompt-text { font-size: 1.02rem; font-weight: 500; margin: 0; color: var(--text); }

.status { min-height: 22px; font-size: 0.94rem; font-weight: 500; margin: 4px 0 12px; color: var(--text-2); }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }

.idea {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 14px;
}
.idea h3 { color: var(--accent); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.idea p { font-size: 0.94rem; line-height: 1.55; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.coach {
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 12px 0;
}
.coach p { color: var(--text); }

/* ----------------------------- examples ------------------------------- */

.example {
  margin: 18px 0 22px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.example-board { max-width: 380px; margin: 0 auto; }
.example-controls { display: flex; gap: 7px; justify-content: center; margin-top: 12px; }
.step {
  min-width: 46px; height: 42px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
  cursor: pointer;
}
.step:hover { background: var(--surface-3); }
.step.wide { min-width: 78px; font-size: 0.9rem; font-weight: 500; }
.step:disabled { opacity: 0.35; }

.example-moves, .movelist {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 12px;
  max-height: 180px;
  overflow-y: auto;
}
.move-chip {
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text-2);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}
.move-chip.current { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.move-chip.blunder { color: var(--bad); background: var(--bad-soft); }
.move-chip.mistake { color: var(--warn); background: var(--warn-soft); }
.move-chip.inaccuracy { color: var(--muted); }
.example-caption { margin-top: 12px; font-size: 0.9rem; color: var(--muted); line-height: 1.5; }

/* -------------------------------- play -------------------------------- */

.move-pair {
  display: inline-flex; gap: 6px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}
.move-num { color: var(--muted); }

/* ------------------------------- review ------------------------------- */

.review-players { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 1rem; }
.review-controls { margin: 12px 0; display: flex; flex-direction: column; gap: 12px; }
.review-moves { max-height: 150px; }

.speed-row { display: flex; align-items: center; gap: 8px; justify-content: center; flex-wrap: wrap; }
.speed-label { font-size: 0.82rem; color: var(--muted); }

.pgn-input, .text-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.92rem;
  margin-bottom: 12px;
}
.pgn-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.text-input:focus, .pgn-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.move-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.move-big { font-size: 1.3rem; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.verdict { font-size: 0.94rem; margin-bottom: 4px; }
.verdict.blunder strong { color: var(--bad); }
.verdict.mistake strong { color: var(--warn); }
.verdict.inaccuracy strong { color: var(--muted); }
.verdict.ok strong { color: var(--good); }

.accuracy-row { display: flex; align-items: center; gap: 14px; margin: 14px 0; }
.accuracy-value {
  font-size: 1.9rem; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}

.summary { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.summary-item {
  flex: 1;
  min-width: 90px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.summary-item strong { display: block; font-size: 1.4rem; font-weight: 700; color: var(--text); }
.summary-item.blunder strong { color: var(--bad); }
.summary-item.mistake strong { color: var(--warn); }
.summary-item.inaccuracy strong { color: var(--muted); }

.game-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  padding: 13px 0;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.game-row:last-child { border-bottom: none; }
.game-body { flex: 1; min-width: 0; background: none; border: none; color: inherit; font-family: inherit; text-align: left; padding: 0; cursor: pointer; }
.game-players { font-weight: 600; font-size: 0.94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-outcome {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700;
  flex-shrink: 0;
}
.game-outcome.won { background: var(--good-soft); color: var(--good); }
.game-outcome.lost { background: var(--bad-soft); color: var(--bad); }
.game-outcome.drew { background: var(--surface-3); color: var(--muted); }
.fetch-results { margin-top: 10px; }

/* ------------------------------- coach -------------------------------- */

.finding {
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}
.finding:first-child { padding-top: 0; }
.finding:last-child { border-bottom: none; padding-bottom: 0; }
.finding p { margin-bottom: 10px; color: var(--text); }
.finding.good p { color: var(--good); }

.theme-stats { display: flex; flex-direction: column; gap: 14px; }
.theme-stat { display: block; }
.theme-stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.theme-stat-name { font-size: 0.92rem; font-weight: 500; }

.opening-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.opening-row:last-child { border-bottom: none; padding-bottom: 0; }
.opening-name { font-size: 0.93rem; font-weight: 500; }

/* ------------------------------ settings ------------------------------ */

.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.setting:last-of-type { border-bottom: none; }
.setting-label { font-size: 0.95rem; font-weight: 500; }
.setting input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); flex-shrink: 0; }
.setting input[type="time"] { width: auto; margin: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { font-size: 0.79rem; color: var(--muted); margin-top: 2px; }

/* ------------------------------- toast -------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(20, 20, 40, 0.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --------------------------- replay controls -------------------------- */

.transport-row { display: flex; gap: 8px; justify-content: center; align-items: center; }
.transport {
  min-width: 48px; height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.transport:hover { background: var(--surface-2); }
.transport.play {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  min-width: 62px;
}
.transport.play:hover { background: var(--accent-press); }

.replay-caption {
  display: flex; align-items: baseline; gap: 8px;
  padding: 10px 2px 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.replay-num { color: var(--muted); font-size: 0.9rem; }
.replay-move { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.replay-mark { font-weight: 700; }
.replay-mark.blunder { color: var(--bad); }
.replay-mark.mistake { color: var(--warn); }
.replay-mark.inaccuracy { color: var(--muted); }
.replay-progress { margin-left: auto; color: var(--muted); font-size: 0.82rem; }

.better {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--good-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 8px 0;
}
.better-move {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  color: var(--good);
  font-size: 1rem;
}

.empty { text-align: center; padding: 8px 0 4px; }
.empty .row-icon { margin: 0 auto 12px; width: 48px; height: 48px; border-radius: 14px; }
.empty p { margin-bottom: 14px; }

/* Replay mode: strip the page back to the board so a screen recording is clean. */
body.replay-mode { background: #0d0d0f; padding-bottom: 0; }
body.replay-mode #tabbar,
body.replay-mode .screen-head,
body.replay-mode .card:not(.player-card),
body.replay-mode .player-card .review-info,
body.replay-mode .player-card .analysis,
body.replay-mode .player-card .movelist,
body.replay-mode .player-card .speed-row,
body.replay-mode .player-card .row.wrap { display: none !important; }

body.replay-mode #app { max-width: 100%; padding: 0; }
body.replay-mode .player-card {
  position: fixed; inset: 0;
  margin: 0; border: none; border-radius: 0;
  background: #0d0d0f;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  padding: 18px;
  box-shadow: none;
}
body.replay-mode .board-host { width: min(94vw, 94vh, 620px); margin: 0; }
body.replay-mode .replay-caption { color: #f2f2f5; justify-content: center; width: min(94vw, 94vh, 620px); }
body.replay-mode .replay-num, body.replay-mode .replay-progress { color: #9a9aa6; }
body.replay-mode .review-controls { margin: 0; }

.cinema-exit {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  z-index: 120;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.12);
  color: #fff;
  padding: 9px 18px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

/* -------------------------------- sync -------------------------------- */

.sync-code {
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 12px 0;
  text-align: center;
}
.sync-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  word-break: break-all;
  color: var(--text);
}

/* ------------------------------- clocks ------------------------------- */

.clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  min-height: 0;
}
.clock-row:empty { display: none; }
.clock-name { font-size: 0.88rem; font-weight: 500; color: var(--muted); }
.clock-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.32rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px 14px;
  letter-spacing: -0.01em;
}
.clock-time.active { color: var(--text); background: var(--accent-soft); }
.clock-time.low { color: var(--bad); }
.clock-time.active.low { background: var(--bad-soft); }
