/* ==========================================================================
   Chess Coach - one hand-written stylesheet, no build step, no externals.

   Layout is fluid first: everything sizes off the container, the board sizes
   off its own width (container query), and wide tables either scroll in their
   own box or reflow into cards. Colour is token-driven, so the light theme is
   a token swap and nothing else.
   ========================================================================== */

/* --- 1. Tokens ----------------------------------------------------------- */

:root {
  color-scheme: dark;

  /* Surfaces, from the page ground upwards. */
  --bg: #12161c;
  --bg-soft: #161b23;
  --surface: #1a212a;
  --surface-2: #202832;
  --surface-3: #27313d;
  --line: #2b3440;
  --line-strong: #3a4654;

  /* Ink. */
  --text: #e8edf4;
  --text-2: #b6c2d1;
  --muted: #8695a8;
  --on-accent: #0b1017;

  /* Accent + the three semantic colours the app has always spoken in:
     amber = the move you played / a repeat, green = the better move / good,
     red = the punishment / bad. They double as text, so they sit lighter than
     a pure chart palette would; wherever all three appear at once they are
     backed by a second encoding (arrow texture, a label, a glyph). */
  --accent: #7ba9f5;
  --accent-dim: #3d5f96;
  --accent-soft: rgba(123, 169, 245, 0.14);

  --amber: #e9a13a;
  --amber-soft: rgba(233, 161, 58, 0.13);
  --green: #3fc98f;
  --green-soft: rgba(63, 201, 143, 0.13);
  --red: #f0605c;
  --red-soft: rgba(240, 96, 92, 0.13);

  /* Board. The board and the eval bar keep one palette in both themes: the
     squares and the two piece colours are the subject, not the chrome. */
  --sq-light: #c3cdda;
  --sq-dark: #64758a;
  --piece-white: #fbfdff;
  --piece-black: #0e1319;
  --piece-rim-w: #0d1218;
  --piece-rim-b: rgba(255, 255, 255, 0.4);

  /* Rhythm: a 4px scale used everywhere, plus the page gutter. */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --pad: 1.5rem;

  /* Type scale. */
  --t--2: 0.6875rem;
  --t--1: 0.8125rem;
  --t-0: 0.9375rem;
  --t-1: 1.0625rem;
  --t-2: 1.25rem;
  --t-3: clamp(1.35rem, 1.1rem + 1.1vw, 1.75rem);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.8);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;

    --bg: #f4f6f9;
    --bg-soft: #eef1f6;
    --surface: #ffffff;
    --surface-2: #f2f5f9;
    --surface-3: #e7ecf3;
    --line: #dde3ec;
    --line-strong: #c3ccd9;

    --text: #161c25;
    --text-2: #3d4855;
    --muted: #63707f;
    --on-accent: #ffffff;

    --accent: #2f62c4;
    --accent-dim: #9db6e4;
    --accent-soft: rgba(47, 98, 196, 0.1);

    --amber: #9a6410;
    --amber-soft: rgba(154, 100, 16, 0.12);
    --green: #10795a;
    --green-soft: rgba(16, 121, 90, 0.12);
    --red: #c33630;
    --red-soft: rgba(195, 54, 48, 0.1);

    --shadow: 0 1px 2px rgba(20, 30, 45, 0.08), 0 10px 24px -18px rgba(20, 30, 45, 0.45);
  }
}

/* --- 2. Base ------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Several elements are toggled with the `hidden` attribute from JS, and a
   layout rule (display: flex/grid/block) would otherwise win over it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t-0);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h2 { font-size: var(--t-3); }
h3 { font-size: var(--t-2); }
h4 {
  font-size: var(--t--1);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-color: currentColor; }

strong { font-weight: 650; color: var(--text); }

ul { margin: 0 0 var(--s3); padding-left: 1.1rem; }
li { margin-bottom: var(--s1); }

/* --- 3. Page frame ------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s3) var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
}

.brand {
  margin: 0;
  font-size: var(--t-0);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand a {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  text-decoration: none;
}
.brand-mark {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  overflow: hidden;
  flex: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: var(--s1);
  flex-wrap: wrap;
  margin-left: auto;
}
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--s3);
  border-radius: 999px;
  color: var(--text-2);
  font-size: var(--t--1);
  text-decoration: none;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.here { background: var(--accent-soft); color: var(--accent); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s6) var(--pad) var(--s7);
}

.site-foot {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s4) var(--pad) var(--s5);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}
/* Static, in the flow: a fixed badge sooner or later sits on top of a button
   on a small screen. */
.version {
  font-size: var(--t--2);
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

/* --- 4. Page head + sections --------------------------------------------- */

.page-head { margin-bottom: var(--s6); }
.page-head h2 { margin-bottom: var(--s2); }
.eyebrow {
  font-size: var(--t--2);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s2);
}
.lede {
  color: var(--text-2);
  max-width: 62ch;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s4);
  margin: 0;
  color: var(--muted);
  font-size: var(--t--1);
}
.meta strong { color: var(--text); font-variant-numeric: tabular-nums; }

.section { margin-bottom: var(--s7); }
.section > h3 { margin-bottom: var(--s2); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
  box-shadow: var(--shadow);
}

.hint {
  color: var(--muted);
  font-size: var(--t--1);
}
.hint a { color: var(--text-2); }

.error {
  display: flex;
  gap: var(--s2);
  align-items: flex-start;
  border: 1px solid color-mix(in srgb, var(--red) 45%, transparent);
  background: var(--red-soft);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  font-size: var(--t--1);
  margin-bottom: var(--s4);
}

/* --- 5. Controls --------------------------------------------------------- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--t--1);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
button:hover,
.btn:hover { background: var(--surface-3); border-color: var(--muted); }
button:active,
.btn:active { transform: translateY(1px); }
button:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  background: var(--surface-2);
  border-color: var(--line);
}

:where(button, .btn, input, select, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 85%, var(--text));
  border-color: transparent;
}

.btn-quiet {
  background: transparent;
  border-color: var(--line);
  color: var(--text-2);
  font-weight: 500;
}
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--t--1); }

/* Square icon buttons - the board transport controls. */
.btn-icon {
  min-width: 44px;
  padding: 0 var(--s2);
  font-variant-numeric: tabular-nums;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

input[type="text"],
input[type="number"],
select {
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--t-0);
}
input::placeholder { color: var(--muted); }
input:focus,
select:focus { border-color: var(--accent); outline: none; }
select {
  appearance: none;
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1.05rem center, right 0.75rem center;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}

.field { margin-bottom: var(--s4); }
.field > label,
.field-label {
  display: block;
  margin-bottom: var(--s2);
  font-size: var(--t--1);
  font-weight: 600;
  color: var(--text-2);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  font-size: var(--t--1);
  color: var(--text-2);
  cursor: pointer;
}
.check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}
.check input:disabled { cursor: not-allowed; }
.check:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }

/* --- 6. Tables ----------------------------------------------------------- */

/* Every table lives in one of these: wide data scrolls in its own box rather
   than pushing the page sideways. */
.table-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
  /* Shadows at whichever edge still has content behind it, so a table that is
     wider than the phone says so instead of hiding its last columns. */
  background:
    linear-gradient(to right, var(--surface) 40%, rgba(0, 0, 0, 0)) left center / 2.5rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 40%, rgba(0, 0, 0, 0)) right center / 2.5rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0)) left center / 1.1rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0)) right center / 1.1rem 100% no-repeat scroll,
    var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t--1);
}

th, td {
  padding: var(--s3);
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--t--2);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
tbody tr:last-child td,
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* Numbers read as numbers. */
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.name { white-space: normal; min-width: 11rem; color: var(--text); font-weight: 600; }
td.name .sub {
  display: block;
  margin-top: 1px;
  font-size: var(--t--2);
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* A rate is easier to compare as a length than as a number, so it gets both. */
td.rate { min-width: 6.5rem; }
.rate-value { display: block; font-weight: 600; }
.meter {
  display: block;
  height: 4px;
  margin-top: 5px;
  margin-left: auto;
  width: 4.5rem;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter > span { display: block; height: 100%; border-radius: 2px; }
.meter.bad > span { background: var(--red); }
.meter.good > span { background: var(--green); }

td.played-san { font-family: var(--mono); color: var(--amber); font-weight: 600; }
td.better-move { font-family: var(--mono); }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }

.empty { color: var(--muted); font-style: italic; white-space: normal; }

/* A position you have reached more than once - the same amber as everywhere
   else, with the glyph doing the talking as well as the colour. */
td.repeat-cell { color: var(--amber); font-weight: 700; }
td.blunder-cp { color: var(--red); font-weight: 600; }

/* --- 7. Board ------------------------------------------------------------ */

/* The wrap is the geometry: a square box that never exceeds its column. The
   arrows SVG is inset:0 over it, so anything drawn in the 8x8 viewBox lands on
   the matching square at any size. The ring is a shadow, not a border, so it
   costs no layout and cannot push the overlay out of alignment. */
.board-wrap {
  position: relative;
  width: 100%;
  max-width: min(var(--board-max, 30rem), 100%);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line-strong), var(--shadow);
  container-type: inline-size;
  touch-action: manipulation;
}

/* Before a game or puzzle is loaded the grid is empty - say so rather than
   showing an unexplained empty box. */
.board:empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--surface-2);
}
.board:empty::after {
  content: "No position on the board yet.";
  color: var(--muted);
  font-size: var(--t--1);
  padding: var(--s4);
  text-align: center;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }

/* Pieces are one filled glyph set, coloured by side, so a white piece is a
   solid shape rather than a hollow outline that vanishes on a dark square. */
.pc {
  font-size: 1.9rem;          /* fallback where container units are missing */
  font-size: 8.6cqi;
  line-height: 1;
  pointer-events: none;
}
.pc.w {
  color: var(--piece-white);
  /* A rim on all four sides: the solid white glyph would otherwise dissolve
     into a light square. */
  text-shadow:
    0.5px 0 var(--piece-rim-w), -0.5px 0 var(--piece-rim-w),
    0 0.5px var(--piece-rim-w), 0 -0.5px var(--piece-rim-w),
    0 1px 2px rgba(8, 12, 18, 0.35);
}
.pc.b {
  color: var(--piece-black);
  text-shadow: 0 0 1px var(--piece-rim-b);
}

.coord {
  position: absolute;
  font-size: 0.5rem;
  font-size: 2.3cqi;
  font-weight: 700;
  line-height: 1;
  opacity: 0.55;
  pointer-events: none;
}
.sq.light .coord { color: #3d4855; }
.sq.dark .coord { color: #f2f5f9; }
.coord.file { right: 4%; bottom: 4%; }
.coord.rank { left: 4%; top: 4%; }

/* Selection / last move / revealed answer. Amber is the default (the move you
   played, a square you picked up); good/bad recolour it. */
.board .sq.marked::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 max(3px, 0.9cqi) var(--amber);
  background: var(--amber-soft);
}
.board .sq.marked.good::after {
  box-shadow: inset 0 0 0 max(3px, 0.9cqi) var(--green);
  background: var(--green-soft);
}
.board .sq.marked.bad::after {
  box-shadow: inset 0 0 0 max(3px, 0.9cqi) var(--red);
  background: var(--red-soft);
}

.board-interactive .sq { cursor: pointer; }

.arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
/* Three arrows can be on the board at once, so each carries a texture as well
   as a colour: solid played, dashed better, dotted punishment. */
.arrow { stroke-width: 0.13; fill: none; opacity: 0.9; stroke-linecap: round; }
.arrow.played { stroke: var(--amber); }
.arrow.better { stroke: var(--green); stroke-dasharray: 0.3 0.18; }
.arrow.refute { stroke: var(--red); stroke-dasharray: 0.04 0.16; }
.arrowhead.played { fill: var(--amber); }
.arrowhead.better { fill: var(--green); }
.arrowhead.refute { fill: var(--red); }

/* --- 8. Viewer layout ---------------------------------------------------- */

.viewer {
  display: grid;
  gap: var(--s5);
  align-items: start;
  margin-bottom: var(--s6);
}
.viewer-main { min-width: 0; }
.viewer-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.board-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s3);
}
.board-toolbar .field-label { margin: 0; flex: none; }
.board-toolbar select { flex: 1 1 auto; min-width: 0; }

.viewer-controls {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s3);
  flex-wrap: wrap;
}

.legend {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s3);
  font-size: var(--t--1);
  color: var(--muted);
}
.legend .check { min-height: 32px; }
.key {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
}
.key::before {
  content: "";
  width: 1.15rem;
  height: 0;
  border-top-width: 3px;
  border-top-style: solid;
  border-radius: 2px;
}
.key.played { color: var(--amber); }
.key.played::before { border-color: var(--amber); }
.key.better { color: var(--green); }
.key.better::before { border-color: var(--green); border-top-style: dashed; }
.key.refute { color: var(--red); }
.key.refute::before { border-color: var(--red); border-top-style: dotted; }

.move-info {
  font-size: var(--t-1);
  font-weight: 600;
  margin: 0;
  min-height: 1.5em;
}
.better-move { color: var(--green); font-weight: 600; }
.ply {
  margin: 0;
  font-size: var(--t--1);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#ply-counter { color: var(--text); font-weight: 600; }

/* Eval bar: the whole bar is black's, the fill is white's share of it. */
.eval-bar {
  position: relative;
  width: 100%;
  height: 0.85rem;
  border-radius: 999px;
  background: var(--piece-black);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  /* Black on the left, white's share filled from the left - the same reading
     as an eval bar anywhere else. */
  overflow: hidden;
}
.eval-fill {
  height: 100%;
  width: 50%;
  background: var(--piece-white);
  transition: width 0.2s ease;
}
.eval-bar::after {              /* the even mark */
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--accent);
  opacity: 0.7;
}
#eval-label { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

.graph-block { margin-top: var(--s5); }
.eval-graph {
  display: block;
  width: 100%;
  height: 110px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}
.eval-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.eval-dot {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.eval-axis { stroke: var(--line-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.eval-blunder {
  fill: none;
  stroke: var(--red);
  stroke-width: 8;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.eval-cursor {
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.65;
}

/* --- 9. Filter bar ------------------------------------------------------- */

.filters {
  display: grid;
  gap: var(--s3);
  margin-bottom: var(--s5);
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--s3);
}
.filter {
  display: grid;
  gap: var(--s1);
  min-width: 0;
  font-size: var(--t--2);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.filter select {
  font-size: var(--t--1);
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
}
.filter-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s2) var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--line);
}
.filter-actions #filter-count { flex: 1 1 12rem; }
.filter-actions #drill-link { margin-left: auto; }

/* --- 10. Drill ----------------------------------------------------------- */

/* play.js rewrites this element's className wholesale, so its spacing has to
   come from the parent, not from a second class on the element. */
.viewer-main > .to-move { margin-top: var(--s4); }
.to-move {
  margin: 0;
  font-size: var(--t-1);
  font-weight: 650;
}
.to-move.good { color: var(--green); }
.to-move.bad { color: var(--red); }

.feedback {
  margin: 0;
  min-height: 3.2em;
  font-size: var(--t-0);
  color: var(--text-2);
}
.feedback.good { color: var(--green); font-weight: 600; }
.feedback.bad { color: var(--red); font-weight: 600; }
.feedback.hint { color: var(--muted); }

.repeat-banner {
  margin: 0;
  padding: var(--s3);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--amber);
  background: var(--amber-soft);
  color: var(--amber);
  font-size: var(--t--1);
  font-weight: 600;
}

/* The two reveal buttons have deliberately different weight: the nudge is a
   quiet outline, the answer is a solid button that ends the puzzle. */
.reveal-actions {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s3);
}
#played-btn {
  border-color: color-mix(in srgb, var(--amber) 45%, transparent);
  color: var(--amber);
  background: transparent;
  font-weight: 500;
}
#played-btn:hover:not(:disabled) { background: var(--amber-soft); }
#reveal-btn {
  border-color: color-mix(in srgb, var(--green) 55%, transparent);
  background: var(--green-soft);
  color: var(--green);
}
#reveal-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--green) 22%, transparent);
}

#solution { display: grid; gap: var(--s3); }

/* Same shape, different weight: the nudge is a thin amber note, the answer is
   a filled green panel. */
.played-block,
.best-block {
  border-radius: var(--radius-sm);
  padding: var(--s3);
  font-size: var(--t--1);
}
.played-block {
  border: 1px dashed color-mix(in srgb, var(--amber) 50%, transparent);
  background: transparent;
}
.best-block {
  border: 1px solid color-mix(in srgb, var(--green) 40%, transparent);
  background: var(--green-soft);
}
.block-label {
  display: block;
  font-size: var(--t--2);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin-bottom: var(--s1);
}
.played-block .block-label { color: var(--amber); }
.best-block .block-label { color: var(--green); }
.best-block .btn { background: var(--surface); border-color: var(--line-strong); }
.best-move-line {
  font-size: var(--t-2);
  font-weight: 700;
  color: var(--green);
  margin: 0 0 var(--s2);
  font-family: var(--mono);
}
.played-move { font-family: var(--mono); font-weight: 700; color: var(--amber); }

.occ-head {
  margin: var(--s3) 0 0;
  color: var(--amber);
  font-weight: 600;
  font-size: var(--t--1);
}
.occurrences {
  margin: var(--s2) 0 0;
  padding-left: 1.1rem;
  font-size: var(--t--1);
  color: var(--text-2);
}

/* Drill record: headline numbers first, tables under them. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s3);
}
.stat-value {
  display: block;
  font-size: var(--t-2);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.15;
}
.stat-label {
  display: block;
  margin-top: var(--s1);
  font-size: var(--t--2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
#stats h4 { margin: var(--s5) 0 var(--s2); }
#stats .table-wrap + h4 { margin-top: var(--s5); }

/* --- 11. Sparring -------------------------------------------------------- */

#profile h4 { margin-bottom: var(--s2); color: var(--text); font-size: var(--t-1);
  letter-spacing: -0.01em; text-transform: none; }
.profile-list {
  display: grid;
  gap: var(--s1);
  margin: 0 0 var(--s3);
  font-size: var(--t--1);
}
.profile-list > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3);
  padding-bottom: var(--s1);
  border-bottom: 1px solid var(--line);
}
.profile-list > div:last-child { border-bottom: none; }
.profile-list dt { color: var(--muted); }
.profile-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.movelist {
  font-family: var(--mono);
  font-size: var(--t--1);
  line-height: 1.7;
  color: var(--text-2);
  word-spacing: 0.1em;
  margin: 0;
  max-height: 16rem;
  overflow-y: auto;
}
.origin-note {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  color: var(--text-2);
  font-size: var(--t--1);
}

/* --- 12. Form + status --------------------------------------------------- */

.form-card { max-width: 34rem; }
.field-note { margin: var(--s2) 0 0; }
.page-note { margin-top: var(--s5); max-width: 62ch; }
.form-card .btn-row { margin-top: var(--s5); }
.inline-field {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}
.inline-field input[type="number"] { width: 6.5rem; flex: none; }

progress {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 0.75rem;
  border: none;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.status-message {
  font-size: var(--t-1);
  color: var(--text-2);
  margin-bottom: var(--s4);
  min-height: 3em;
}
.spinner {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: var(--s2);
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  vertical-align: -0.05rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  * { scroll-behavior: auto !important; }
}

/* --- 13. Responsive ------------------------------------------------------ */

/* Two openings tables side by side once there is room for both. */
@media (min-width: 1000px) {
  .duo { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); align-items: start; }
  .duo > .section { margin-bottom: var(--s7); }
}

@media (min-width: 900px) {
  /* The board takes as much of its column as it can so the panel beside it
     doesn't drift away from it. */
  :root { --board-max: 34rem; }
  .viewer {
    grid-template-columns: minmax(0, 1fr) minmax(16rem, 21rem);
    gap: var(--s6);
  }
}

@media (max-width: 899px) {
  .board-wrap { margin-inline: auto; }
}

/* Phones: tighter gutter, and the board runs edge to edge so a square stays a
   44px+ tap target on a 360px screen. */
@media (max-width: 600px) {
  :root { --pad: 1rem; --s6: 1.5rem; --s7: 2rem; }

  .container { padding-top: var(--s5); }
  .board-wrap {
    width: auto;
    max-width: none;
    margin-inline: calc(var(--pad) * -1);
    border-radius: 0;
    box-shadow: 0 0 0 1px var(--line-strong);
  }
  .viewer-controls button { flex: 1 1 3rem; }
  .btn-row > button,
  .btn-row > .btn { flex: 1 1 auto; }
  .filter-actions #drill-link { margin-left: 0; width: 100%; }
  .movelist { max-height: 10rem; }
  th, td { padding: var(--s2) var(--s3); }
}

/* The mistake table is nine columns of mixed text and numbers; below this it
   stops being a table and becomes one card per mistake. */
@media (max-width: 700px) {
  #blunder-table,
  #blunder-table tbody,
  #blunder-table tr,
  #blunder-table td { display: block; width: auto; }
  #blunder-table thead { display: none; }
  #blunder-table tr {
    padding: var(--s3);
    border-bottom: 1px solid var(--line);
  }
  #blunder-table tr:last-child { border-bottom: none; }
  #blunder-table td {
    border: none;
    padding: 0.15rem 0;
    white-space: normal;
    text-align: left;
    display: flex;
    justify-content: space-between;
    gap: var(--s3);
    font-variant-numeric: tabular-nums;
  }
  #blunder-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--t--2);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    flex: none;
  }
  #blunder-table td:empty { display: none; }
  #blunder-table td.empty { display: block; }
  #blunder-table tbody tr:hover td,
  #blunder-table tr.clickable:hover td { background: none; }
  #blunder-table tr.clickable:hover { background: var(--accent-soft); }
}

/* Explanation blocks in the drill: the same amber / green language as the
   board arrows, plus a neutral card for the alternatives. */
.alt-block {
  border-left: 3px solid var(--line-strong);
  padding: var(--s3) var(--s4);
  margin-top: var(--s3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.alt-block .alt { margin: var(--s3) 0 var(--s1); }
.points { margin: var(--s1) 0; padding-left: 1.1rem; color: var(--text-2); }
.points li { margin-bottom: 2px; }
.line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--t--1);
  color: var(--muted);
  margin: var(--s1) 0 0;
  overflow-wrap: anywhere;
}
