@font-face {
  font-family: "Shadows Into Light";
  src: url("/fonts/shadows-into-light.woff2") format("woff2");
  font-display: swap;
}

:root {
  --text: #f4f2ee;
  --muted: rgba(244, 242, 238, 0.68);
  --glass: rgba(22, 22, 20, 0.55);
  --glass-line: rgba(255, 255, 255, 0.14);
  --field: rgba(255, 255, 255, 0.1);
  --accent: #7fb069;
  --light-square: #ebd9b4;
  --dark-square: #a87b56;
  --last-move: rgba(255, 214, 79, 0.45);

  --brilliant: #7c5cff;
  --only_move: #3b82f6;
  --best: #4f9a3a;
  --good: #86b45f;
  --book: #a07c58;
  --forced: #7b8594;
  --inaccuracy: #e2b33a;
  --mistake: #e8832a;
  --blunder: #d23c32;
  color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }

html, body { min-height: 100%; }
/* While a list or a game loads, the page holds still. A page that had a scroll bar keeps its space, so nothing shifts. */
html.scroll-locked { overflow: hidden; }
html.scroll-locked.scroll-gutter { scrollbar-gutter: stable; }

body {
  margin: 0;
  background: #1b1b19;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }

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

/* The photo, blurred and darkened, behind everything. A real image element
   rather than a CSS background, so reader extensions do not drop it. */
.backdrop {
  position: fixed;
  inset: -40px;
  z-index: -1;
  width: calc(100% + 80px);
  height: calc(100% + 80px);
  max-width: none;
  object-fit: cover;
  filter: blur(10px) brightness(0.55);
  pointer-events: none;
}

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

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  color: #10200a;
  font-weight: 600;
}

button:hover { filter: brightness(1.1); }

button.ghost {
  background: transparent;
  color: var(--text);
  font-weight: 400;
  padding: 0.35rem 0.6rem;
}

button.ghost:hover { background: var(--field); filter: none; }

button.link {
  background: none;
  padding: 0;
  color: inherit;
  font-weight: 400;
  text-decoration: underline;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.icon {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------ home */

.home {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem 4rem;
}

/* No card at all: the content sits straight on the photo. */
.card {
  width: min(40rem, 100%);
  padding: 1.75rem 2.25rem 2.25rem;
  /* The title's size: large, shrinking with narrow screens so it never overflows. The subtitle tucks up by it. */
  --title-size: min(11.9rem, 16.5vw);
}

.card h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  text-align: center;
  font-family: "Shadows Into Light", "Segoe Print", cursive;
  font-size: var(--title-size);
  font-weight: 400;
  white-space: nowrap;
  /* Wider than the form below it: centered on the form, spilling out evenly on both sides. */
  display: flex;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
  line-height: 1.2;
}

/* The subtitle, in the title's hand, tucks up under the title: in front of the lettering's tails,
   kept readable by a dark shadow around the letters. */
.subtitle {
  position: relative;
  z-index: 2;
  margin: calc(var(--title-size) * -0.16) 0 1.7rem;
  text-align: center;
  font-family: "Shadows Into Light", "Segoe Print", cursive;
  font-size: 1.65rem;
  line-height: 1.25;
  color: rgba(244, 242, 238, 0.85);
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.95), 0 0 12px rgba(0, 0, 0, 0.85), 0 0 24px rgba(0, 0, 0, 0.6);
}
/* Lines break between the two parts, never inside one. */
.subtitle > span { display: inline-block; white-space: nowrap; }

/* Lookup running: the title becomes a spinning wheel (drawn on .title-canvas) and everything else fades.
   The game list comes back with a small rise, together with the form. */
.card > :not(h1) { transition: opacity 0.45s ease, transform 0.45s ease; }
.card.busy > :not(h1) { opacity: 0; pointer-events: none; }
.card.busy > .games { transform: translateY(0.75rem); }

/* With results showing, the title leads back to the start: the whole card fades out and back in. */
.card { transition: opacity 0.3s ease; }
.card.resetting { opacity: 0; }
.card.wide h1:not(.spinning) { cursor: pointer; }
/* Opening a game: the whole card goes, title too; the board in the middle takes over. */
.card.opening, .card.opening > * { opacity: 0; pointer-events: none; }
.card h1.waiting { animation: title-wait 1.4s ease-in-out infinite; }
@keyframes title-wait { 50% { opacity: 0.45; } }
/* The beta tag hangs off the top right of the title, clear of the lettering.
   It fades with the lettering when the title becomes the wheel. */
.title-wrap { position: relative; }
.beta {
  position: absolute;
  z-index: 1;
  right: calc(var(--title-size) * -0.12);
  bottom: 84%;
  transform: rotate(-6deg);
  padding: 0.3em 0.6em 0.3em 0.75em;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  font-family: system-ui, sans-serif;
  font-size: clamp(0.72rem, 0.095em, 1.1rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #10140d;
  white-space: nowrap;
}
.title-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 5; pointer-events: none; }

/* Submitting an empty box: a short shake. */
input[name="query"].nudge { animation: nudge 0.45s ease; border-color: var(--accent); }
@keyframes nudge {
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}
@media (prefers-reduced-motion: reduce) {
  input[name="query"].nudge { animation: none; }
}

/* The review button sits inside the search box, at its right end. */
.query-field { position: relative; }
.submit-button {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  aspect-ratio: 1.25;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 0 10px 10px 0;
}
.submit-button .icon { width: 1.15rem; height: 1.15rem; fill: currentColor; stroke-width: 1.5; }
.submit-button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

input[name="query"] {
  width: 100%;
  padding: 0.8rem 4.4rem 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--glass-line);
  background: var(--field);
  font-size: 1.1rem;
}

/* The hint in the empty box is written in the title's hand; what is typed stays plain, to read back easily. */
input[name="query"]::placeholder {
  color: var(--muted);
  font-family: "Shadows Into Light", "Segoe Print", cursive;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
input[name="query"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

/* Site switch: a segmented toggle built on radio buttons. */
.toggle {
  display: inline-flex;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
}

.toggle label { position: relative; cursor: pointer; }

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle span {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.toggle input:checked + span {
  background: rgba(255, 255, 255, 0.92);
  color: #161615;
  font-weight: 600;
}

.toggle input:focus-visible + span { outline: 2px solid var(--accent); }

.site-icon { width: 1.25rem; height: 1.25rem; object-fit: contain; }
/* The pawn artwork has more empty space around it than the Lichess mark. */
.site-icon[src$="chesscom.svg"] { transform: scale(1.3); }

/* The Lichess mark is white: dark when its option is selected. */
.toggle input:checked + span img[src$="lichess.svg"] { filter: brightness(0); }

/* With the notify switch hidden, the site switch sits alone under the box, centered. */
.row:has(> .switch[hidden]) { justify-content: center; }

/* Notify me: an on and off switch where the review button used to be. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  -webkit-user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative;
  flex: none;
  width: 2.6rem;
  height: 1.5rem;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: rgba(0, 0, 0, 0.25);
  transition: background 0.2s, border-color 0.2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(1.1rem); background: #fff; }
.switch input:checked ~ span:last-child { color: var(--text); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Opening a game: the game plays through on a board in the middle of the screen, the progress under it. */
.progress-box {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1rem;
  animation: progress-in 0.35s ease both;
}
@keyframes progress-in { from { opacity: 0; } }
.progress-box .progress-board { width: min(22rem, 78vw, 52dvh); }
.progress-meter { width: min(22rem, 78vw, 52dvh); display: flex; flex-direction: column; gap: 0.4rem; }
.progress-count {
  min-height: 1.3em;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.progress-bar {
  position: relative;
  height: 0.9rem;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: rgba(0, 0, 0, 0.35);
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--done, 0%);
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.6s ease;
}
/* Nothing to count yet: a short stretch of light sweeps along the bar. */
.progress-bar.waiting .progress-fill { width: 30%; transition: none; animation: progress-sweep 1.4s ease-in-out infinite; }
@keyframes progress-sweep { from { left: -30%; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .progress-bar.waiting .progress-fill { animation: none; left: 0; width: 100%; opacity: 0.35; }
}
.progress-stale { margin: 0; max-width: 22rem; text-align: center; color: var(--muted); }
.progress-stale:empty { display: none; }
.progress-cancel { position: absolute; top: 1rem; right: 1rem; }

.status { margin: 1rem 0 0; color: var(--muted); }
.status:empty { display: none; }

.games {
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 0.75rem;
}
/* A page holds 24 games, so only column counts that divide 24 are used: every row
   is full. Each step needs tiles of at least 10.5rem with the gaps between them. */
@container (min-width: 33rem) { .games { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@container (min-width: 44.25rem) { .games { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container (min-width: 66.75rem) { .games { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* With games to show the card grows, so the boards can be large. */
.card.wide { width: min(72rem, 100%); container-type: inline-size; }

/* One game: the board is the tile, with a little text underneath. */
button.game {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  min-width: 0;
  padding: 0.4rem 0.4rem 0.5rem;
  border-radius: 10px;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-weight: 400;
}

button.game:hover { background: rgba(255, 255, 255, 0.1); filter: none; }

.tile-board { position: relative; display: block; }

.mini-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.mini-board .square { display: block; }



.tile-result { flex: none; padding-left: 0.4rem; font-size: 0.74rem; font-weight: 700; }
.tile-result.win { color: var(--good); }
.tile-result.loss { color: var(--blunder); }
.tile-result.draw { color: var(--muted); }

/* Reviewed: a small tick on the board's top right corner, named on hover. */
.reviewed-badge {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: rgba(20, 20, 18, 0.85);
  color: var(--good);
}
.reviewed-badge .icon { width: 0.8rem; height: 0.8rem; stroke-width: 3; }
.reviewed-badge::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: rgba(20, 20, 18, 0.92);
  color: var(--text);
  font-size: 0.72rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.reviewed-badge:hover::after { opacity: 1; }

.tile-opponent { display: flex; align-items: baseline; gap: 0.35rem; min-width: 0; font-size: 0.88rem; white-space: nowrap; }
.tile-opponent strong { min-width: 0; overflow: hidden; }
.tile-opponent .muted { flex: none; }
.tile-details { display: flex; align-items: center; gap: 0.3rem; color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.tile-meta { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 0.3rem; overflow: hidden; }
/* A small tile drops the move count, so the date and result still fit. */
button.game { container-type: inline-size; }
@container (max-width: 13.5rem) { .tile-moves { display: none; } }
.speed-icon { flex: none; width: 0.95rem; height: 0.95rem; }

.pager { display: flex; justify-content: center; align-items: center; gap: 1.25rem; margin-top: 0.9rem; }
.pager button:disabled { opacity: 0.35; cursor: default; }

/* Messages glide up from the bottom edge as a bar across the whole screen, over the footer links, and leave the same way. */
.toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 1rem 1.4rem calc(1rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--glass-line);
  background: #222220;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transform: translateY(110%);
  transition: transform 0.38s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.shown { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 0.78rem;
}

.legal {
  max-width: min(34rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  background: #222220;
  color: var(--text);
  font-size: 0.9rem;
}

.bottom-links { display: flex; gap: 1rem; }

/* Settings: a preview strip, then one row of choices per option. */
.settings { width: min(40rem, calc(100vw - 2rem)); max-width: none; }

.preview {
  container-type: inline-size;
  display: flex;
  justify-content: center;
  padding: 1.4rem 0 0.6rem;
}

.preview .square { width: 12.5cqw; height: 12.5cqw; }
.preview .square:first-child { border-radius: 6px 0 0 6px; }
.preview .square:last-child { border-radius: 0 6px 6px 0; }

.settings-options { display: flex; flex-direction: column; gap: 0.9rem; margin: 0.5rem 0 1.2rem; }

.choices { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.choices legend { padding: 0; margin-bottom: 0.35rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.choices label { position: relative; cursor: pointer; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }

.choices label > span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--field);
  color: var(--text);
  font-size: 0.88rem;
}

.choices label:hover > span { background: rgba(255, 255, 255, 0.18); }
.choices input:checked + span { background: rgba(255, 255, 255, 0.92); color: #161615; font-weight: 600; }
.choices input:focus-visible + span { outline: 2px solid var(--accent); }
.choice-piece { width: 1.5rem; height: 1.5rem; margin: -0.2rem 0 -0.2rem -0.3rem; }

.swatch {
  width: 1.1rem;
  height: 1.1rem;
  margin-left: -0.3rem;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--a) 50%, var(--b) 50%);
}
.swatch[data-swatch="walnut"] { --a: #ebd9b4; --b: #a87b56; }
.swatch[data-swatch="sage"] { --a: #e2e6cf; --b: #7f9a68; }
.swatch[data-swatch="ocean"] { --a: #e1e8ee; --b: #6f8ea8; }
.swatch[data-swatch="stone"] { --a: #dedad2; --b: #8d877c; }
.swatch[data-swatch="dusk"] { --a: #cfc8dd; --b: #7b6f9c; }

.report { width: min(30rem, calc(100vw - 2rem)); max-width: none; }

/* Game report: the opening, then one table with a column per player. */
.report-opening { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.1rem; }
.report-opening p { margin: 0; }
.opening-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; font-size: 1rem; }
.eco { padding: 0.05rem 0.4rem; border-radius: 5px; background: var(--field); color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.report-opening .history { margin-top: 0.2rem; color: var(--muted); font-size: 0.85rem; line-height: 1.45; }

.report-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.report-table thead th { width: 29%; padding: 0 0.2rem 0.5rem; vertical-align: bottom; font-weight: 600; text-align: center; }
.report-table thead strong { display: block; overflow-wrap: anywhere; font-size: 0.88rem; line-height: 1.25; }
.report-table .marks { display: flex; justify-content: center; align-items: center; gap: 0.3rem; min-height: 1.2rem; margin-bottom: 0.15rem; }
.report-table th[scope="row"] { padding: 0.35rem 0; text-align: left; font-weight: 500; white-space: nowrap; }
.report-table td { padding: 0.35rem 0.2rem; text-align: center; font-weight: 700; }
.report-table tbody tr { border-top: 1px solid var(--glass-line); }
.report-table tbody tr.help-row { border-top: 0; }
.report-stats b { font-size: 1.2rem; }
.report-stats td { vertical-align: top; }
.report-stats th[scope="row"] { vertical-align: top; padding-top: 0.55rem; padding-right: 0.4rem; white-space: normal; }
.report-table th .symbol { display: inline-flex; justify-content: center; width: 1.3rem; margin-right: 0.45rem; }
.report-table tr.none th { color: var(--muted); }
.report-table tr.none .symbol { opacity: 0.45; }
.report-table tr.section { border-top: 0; }
.report-table tr.section th { padding: 1.3rem 0 0.35rem; text-align: left; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.help-row td { padding: 0 0 0.7rem; text-align: left; font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.help-row p { margin: 0; line-height: 1.45; }
.report h2:focus { outline: none; }

.help-button {
  display: inline-grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  margin-left: 0.4rem;
  padding: 0;
  border-radius: 50%;
  background: var(--field);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: 0.1rem;
}
.help-button:hover { background: rgba(255, 255, 255, 0.2); color: var(--text); filter: none; }
.help-button[aria-expanded="true"] { background: rgba(255, 255, 255, 0.9); color: #161615; }

/* Label definitions: symbol and name, with what it means underneath. */
.label-help { margin: 0; }
.label-help dt { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.55rem; color: var(--text); font-weight: 500; }
.label-help dt:first-child { margin-top: 0; }
.label-help dt .symbol { display: inline-flex; justify-content: center; width: 1.3rem; }
.label-help dd { margin: 0.1rem 0 0 1.6rem; line-height: 1.4; }

/* Played rating range: low and high at the ends, the dot at the best guess. */
.range { display: block; width: min(80%, 6rem); margin: 0.35rem auto 0; }
.range-track { position: relative; display: block; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.25); }
.range-track i { position: absolute; top: 50%; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--text); transform: translate(-50%, -50%); }
.range-ends { display: flex; justify-content: space-between; margin-top: 0.25rem; font-size: 0.7rem; font-weight: 500; color: var(--muted); }

/* Window title with a close button that stays in reach while the window scrolls. */
.dialog-head {
  position: sticky;
  top: -1.5rem;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: -1.5rem -1.5rem 0.6rem;
  padding: 0.9rem 0.8rem 0.6rem 1.5rem;
  background: #222220;
}
.legal .dialog-head h2 { margin: 0; }
.dialog-head h2:focus { outline: none; }
.dialog-head form { margin: 0; }
.dialog-close { padding: 0.45rem; }

.dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.dialog-actions form { margin: 0; }

.legal::backdrop { background: rgba(0, 0, 0, 0.6); }
.legal h2 { margin-top: 0; font-size: 1.15rem; }
.legal h3 { font-size: 1rem; }
.legal ul { padding-left: 1.2rem; }

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

.review {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

.board {
  --size: min(calc(100vw - 2rem), calc(100dvh - 2rem));
  width: var(--size);
  height: var(--size);
  flex: none;
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  container-type: size;
  user-select: none;
  touch-action: none;
}

.square.corner-tl { border-top-left-radius: 6px; }
.square.corner-tr { border-top-right-radius: 6px; }
.square.corner-bl { border-bottom-left-radius: 6px; }
.square.corner-br { border-bottom-right-radius: 6px; }
.square.selected { box-shadow: inset 0 0 0 0.6cqw rgba(255, 214, 79, 0.85); }
.square.dragging img { opacity: 0.25; }

/* Legal moves for the selected piece. */
.square.target::after {
  content: "";
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.28);
}

.square.capture-target::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 0.8cqw solid rgba(20, 20, 20, 0.28);
}

.drag-piece {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10;
  pointer-events: none;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.4));
}

.square { position: relative; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.last::before { content: ""; position: absolute; inset: 0; background: var(--last-move); }

.square img { position: absolute; inset: 0; width: 100%; height: 100%; }

.coord {
  position: absolute;
  font-size: 2.2cqw;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
}

.square.light .coord { color: var(--dark-square); }
.square.dark .coord { color: var(--light-square); }
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }

/* Move label on the destination square. The default is a rounded tile that
   overhangs the corner; the settings switch shape, size and position. */
.badge {
  --s: var(--badge-scale, 1);
  position: absolute;
  top: calc(-1.6cqw * var(--s));
  right: calc(-1.6cqw * var(--s));
  z-index: 3;
  display: grid;
  place-items: center;
  width: calc(5.8cqw * var(--s));
  height: calc(5.8cqw * var(--s));
  border-radius: calc(1.6cqw * var(--s));
  border: calc(0.35cqw * var(--s)) solid rgba(10, 10, 10, 0.75);
  color: #fff;
  font-size: calc(2.7cqw * var(--s));
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 55%);
  box-shadow: 0 0.5cqw 1.4cqw rgba(0, 0, 0, 0.55);
  animation: badge-in 0.18s ease-out;
}

:root[data-label-size="small"] { --badge-scale: 0.8; }
:root[data-label-size="large"] { --badge-scale: 1.25; }

:root[data-label-position="inside"] .badge { top: 0.5cqw; right: 0.5cqw; }

/* Sticker: a round label with a white rim. */
:root[data-label-style="sticker"] .badge {
  border-radius: 50%;
  border-color: #fff;
  box-shadow: 0 0.4cqw 1cqw rgba(0, 0, 0, 0.45);
}

/* Flat: a plain round label, no rim and no shine. */
:root[data-label-style="flat"] .badge {
  border: 0;
  border-radius: 50%;
  background-image: none;
  text-shadow: none;
  box-shadow: 0 0.25cqw 0.7cqw rgba(0, 0, 0, 0.35);
}

/* Outline: a dark round label with the color as ring and symbol. */
:root[data-label-style="outline"] .badge {
  border-radius: 50%;
  border-color: var(--label);
  background-color: rgba(18, 18, 18, 0.88);
  background-image: none;
  color: var(--label);
  text-shadow: none;
  box-shadow: 0 0.3cqw 0.9cqw rgba(0, 0, 0, 0.45);
}

/* Corner: a colored triangle filling the corner of the square itself. */
:root[data-label-style="corner"] .badge {
  top: 0;
  right: 0;
  width: calc(7cqw * var(--s));
  height: calc(7cqw * var(--s));
  padding: calc(0.5cqw * var(--s)) calc(0.6cqw * var(--s));
  place-items: start end;
  border: 0;
  border-radius: 0;
  background-image: none;
  box-shadow: none;
  font-size: calc(2.3cqw * var(--s));
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
:root[data-label-style="corner"] .badge .icon { width: 50%; height: 50%; }
:root[data-label-style="corner"] .square.corner-tr .badge { border-top-right-radius: 6px; }

/* Color only: no symbol, so the label can be smaller. */
:root[data-symbols="none"]:not([data-label-style="corner"]) .badge {
  width: calc(3.4cqw * var(--s));
  height: calc(3.4cqw * var(--s));
  top: calc(-0.9cqw * var(--s));
  right: calc(-0.9cqw * var(--s));
}
:root[data-symbols="none"][data-label-position="inside"]:not([data-label-style="corner"]) .badge { top: 0.8cqw; right: 0.8cqw; }
:root[data-symbols="none"][data-label-style="corner"] .badge { width: calc(4.5cqw * var(--s)); height: calc(4.5cqw * var(--s)); }
.symbol:empty { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--label); }

/* Optional: the destination square takes the label color instead of the usual highlight. */
.square.last.tint::before { background: color-mix(in srgb, var(--label) 58%, transparent); }

/* Board colors. */
:root[data-board="sage"] { --light-square: #e2e6cf; --dark-square: #7f9a68; }
:root[data-board="ocean"] { --light-square: #e1e8ee; --dark-square: #6f8ea8; }
:root[data-board="stone"] { --light-square: #dedad2; --dark-square: #8d877c; }
:root[data-board="dusk"] { --light-square: #cfc8dd; --dark-square: #7b6f9c; }

/* A diagnosis drawn on the board: arrows and rings over the position before the mistake. */
:root {
  --mark-played: #f0a73a;
  --mark-reply: #e0483e;
  --mark-better: #63b84d;
  --mark-guard: #4ea3e6;
  --mark-loose: #e0483e;
}

.board-marks { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; overflow: visible; }
.mark-arrow { opacity: 0.92; }
.mark-arrow.reply, .mark-arrow.attack { fill: var(--mark-reply); }
.mark-arrow.better, .mark-arrow.move, .mark-arrow.hits { fill: var(--mark-better); }
.mark-arrow.guard { fill: var(--mark-guard); }
.mark-ring { fill: none; stroke: var(--mark-loose); stroke-width: 0.055; stroke-linecap: round; opacity: 0.95; }
.mark-ring.prize { stroke: var(--mark-better); }
.mark-ring.saved { stroke: var(--mark-guard); }
/* The opponent's moves in a replayed line: the same marks in the opponent's color. */
.mark-arrow.move.foe, .mark-arrow.hits.foe { fill: var(--mark-reply); }
.mark-ring.prize.foe { stroke: var(--mark-reply); }
/* The move label, lifted above the marks. */
.label-holder { position: absolute; z-index: 5; width: 12.5%; height: 12.5%; pointer-events: none; }
:root[data-label-style="corner"] .label-holder.corner-tr .badge { border-top-right-radius: 6px; }

/* The move panel: the game as a graph, the move, two sentences, and then
   lines to watch on the board. */
.review .move-info { gap: 0.5rem; scrollbar-width: thin; }
/* Too much for the panel scrolls; nothing is squeezed. */
.review .move-info > * { flex-shrink: 0; }
.move-name { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.reason strong { color: color-mix(in srgb, var(--label, var(--text)) 62%, #fff); }
.next-time strong { color: var(--accent); }

/* What a move does, as chips. Chips with marks on the board invite pointing at them. */
.facts { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.fact { padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--field); font-size: 0.85rem; }
.fact.has-marks { cursor: default; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--mark-better) 55%, transparent); }
.fact.has-marks:hover { background: color-mix(in srgb, var(--mark-better) 24%, transparent); }
.board-marks .dim { opacity: 0.12; }

/* Lines to watch: each plays by itself on the board. */
.replay { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.5rem 0.6rem; border-radius: 10px; background: var(--field); }
.replay.active { box-shadow: inset 0 0 0 1px var(--glass-line); background: rgba(255, 255, 255, 0.14); }
.replay-head { display: flex; align-items: center; gap: 0.5rem; }
.replay-head .muted { margin-left: auto; font-size: 0.85rem; }
.play-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #10140d;
}
.play-button .icon { width: 1rem; height: 1rem; fill: currentColor; }
.replay-moves { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.replay-moves .chip { font-size: 0.85rem; }
.replay .facts { min-height: 1.75rem; }

/* The game graph: White's winning chances over the whole game. */
.graph {
  position: relative;
  flex: none;
  height: 4.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: none;
}
.graph svg { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; }
.graph-area { fill: rgba(244, 242, 238, 0.8); }
.graph-line { fill: none; stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.graph-middle { stroke: rgba(128, 128, 128, 0.75); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.graph-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--label);
  box-shadow: 0 0 0 2px #1c1c1a;
  pointer-events: none;
}
.graph-cursor, .graph-hover { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; pointer-events: none; }
.graph-cursor { background: var(--accent); }
.graph-hover { width: 1px; background: rgba(128, 128, 128, 0.9); }
.graph-tip {
  position: absolute;
  top: 0.25rem;
  z-index: 2;
  display: flex;
  gap: 0.5rem;
  margin: 0 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: #111110;
  color: var(--text);
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
}
.graph-tip span { color: var(--muted); }

@media (max-width: 699px) {
  /* Under the board there is no panel behind the text, only the page's
     background picture: the move panel gets its own dark glass to stay readable. */
  .review .move-info {
    padding: 0.65rem 0.75rem;
    border-radius: 12px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .graph { height: 3.25rem; }
  .move-name { font-size: 1.15rem; }
}

.report-causes th[scope="row"] { white-space: normal; }

/* Pawn promotion: four pieces over a dimmed board. */
.board { position: relative; }

.promotion {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 6px;
}

.promotion button {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  padding: 0;
  border-radius: 50%;
  background: rgba(245, 243, 238, 0.92);
  box-shadow: 0 0.4cqw 1.2cqw rgba(0, 0, 0, 0.5);
  transition: border-radius 0.15s, background 0.15s;
}

.promotion button:hover, .promotion button:focus-visible { border-radius: 12%; background: #fff; filter: none; }
.promotion img { width: 100%; height: 100%; display: block; }

@keyframes badge-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.badge .icon { width: 64%; height: 64%; stroke-width: 3; }
.badge.best .icon { fill: currentColor; stroke-width: 1.5; }
.badge.brilliant .icon, .symbol.brilliant .icon,
.badge.only_move .icon, .symbol.only_move .icon { fill: currentColor; stroke-width: 1.2; }

.badge, .tag { background-color: var(--label); }
.brilliant { --label: var(--brilliant); }
.only_move { --label: var(--only_move); }
.best { --label: var(--best); }
.good { --label: var(--good); }
.book { --label: var(--book); }
.forced { --label: var(--forced); }
.inaccuracy { --label: var(--inaccuracy); }
.mistake { --label: var(--mistake); }
.blunder { --label: var(--blunder); }

.panel {
  width: min(var(--panel, 40rem), 100%);
  padding: 1rem 1.25rem;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.panel-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.panel-top button { white-space: nowrap; }
.panel-actions { display: flex; gap: 0.25rem; }
.icon-button { display: grid; place-items: center; }
.icon-button .icon { width: 1.25rem; height: 1.25rem; }
.panel h2 { margin: 0; font-size: 1.05rem; }
.panel p { margin: 0; }

.move-info {
  min-height: 6.5rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--field);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.note { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; }
.note > span { flex: 1 1 12rem; }
.note-icon { flex: none; width: 1.05rem; height: 1.05rem; color: var(--muted); }
.note .small-button { margin-left: auto; }

.move-title { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; }

.move-info h3 { margin: 0.5rem 0 0; font-size: 0.85rem; font-weight: 600; color: var(--muted); }

.suggestion {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.suggestion-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.suggestion-head .small-button { margin-left: auto; }

.small-button {
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
}

.small-button:hover { background: rgba(255, 255, 255, 0.2); filter: none; }

details { margin-top: 0.35rem; font-size: 0.9rem; }
details summary { cursor: pointer; color: var(--accent); }
details ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
details li { margin: 0.15rem 0; }

.nav-area { position: relative; }

/* While a line of your own is shown, the way back floats just above the step
   buttons, over the bottom of the move details, so nothing else moves. */
.explore-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 1.1rem);
  z-index: 3;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.explore-bar button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}
.explore-bar .icon { width: 1.1rem; height: 1.1rem; }
/* Room to scroll the details clear of the floating button (a spacer, so the box itself keeps its size). */
.review.exploring .move-info::after { content: ""; flex: none; height: 3.2rem; }

.variation { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  font-weight: 500;
}

.chip:hover { background: rgba(255, 255, 255, 0.2); filter: none; }
.chip.active { background: rgba(255, 255, 255, 0.3); }

.tag {
  border: 1px solid rgba(10, 10, 10, 0.5);
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.nav { display: flex; gap: 0.4rem; }

.nav button {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0.45rem;
  background: var(--field);
  color: var(--text);
}

.nav button:hover { background: rgba(255, 255, 255, 0.2); filter: none; }

.moves {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 16rem;
  font-variant-numeric: tabular-nums;
}

.moves li { display: grid; grid-template-columns: 2.5rem 1fr 1fr; align-items: center; }
.moves .number { color: var(--muted); }

.moves .move {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1px;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  text-align: left;
}

.moves .move:hover { background: var(--field); filter: none; }
.moves .move.active { background: rgba(255, 255, 255, 0.22); }

.symbol { display: inline-flex; font-size: 0.75rem; font-weight: 800; color: var(--label); }
.symbol .icon { width: 0.95rem; height: 0.95rem; }
.symbol.best .icon { fill: currentColor; stroke-width: 1.5; }

/* The board with a player bar above and below it, and the eval bar on its left. */
.board-area {
  --eval-w: 0.55rem;
  display: grid;
  grid-template-columns: var(--eval-w) auto;
  column-gap: 0.35rem;
  row-gap: 0.4rem;
  flex: none;
}
#player-top { grid-column: 2; grid-row: 1; }
.board-area .board { grid-column: 2; grid-row: 2; }
#player-bottom { grid-column: 2; grid-row: 3; }

.eval-bar {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: #262624;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #efece6;
  transition: height 0.35s ease;
}

.eval-bar.flipped .eval-fill { top: 0; bottom: auto; }
.eval-bar::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(128, 128, 128, 0.7); }

.player-bar {
  height: var(--bar, 2rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  min-width: 0;
  padding: 0 0.15rem;
  font-size: 0.92rem;
}

.player-name { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.player-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side { flex: none; width: 0.75rem; height: 0.75rem; border-radius: 3px; }
.side.white { background: #f4f2ee; }
.side.black { background: #1b1b19; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4); }
.crown { flex: none; width: 1.1rem; height: 1.1rem; fill: #f2c14e; stroke: #f2c14e; stroke-width: 1; }
.draw { flex: none; font-size: 0.78rem; color: var(--muted); }

.opening { font-weight: 600; }

/* Phones and narrow windows: everything fits on one screen, nothing scrolls
   but the move details. Top to bottom: buttons, board with the players,
   a sideways strip of moves, the move details, then the step buttons. */
@media (max-width: 699px) {
  .review {
    --bar: 1.8rem;
    --board: min(calc(100vw - 1.8rem), calc(100dvh - 19.5rem));
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }
  .board { --size: var(--board); }
  .board-area { order: 1; align-self: center; --eval-w: 0.45rem; }
  .panel { display: contents; }
  .panel-top { order: 0; }
  .moves {
    order: 3;
    flex: none;
    display: flex;
    gap: 0.15rem;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  .moves::-webkit-scrollbar { display: none; }
  .moves li { display: flex; align-items: center; flex: none; }
  .moves .number { padding: 0 0.15rem 0 0.45rem; font-size: 0.8rem; }
  .moves .move { gap: 0.3rem; white-space: nowrap; }
  .move-info { order: 4; flex: 1 1 0; min-height: 0; overflow-y: auto; }
  .nav-area { order: 5; flex: none; }
  .nav button { padding: 0.65rem; }
}

/* Anything wider, including a desktop window that is taller than it is wide:
   the board fills the height and the panel sits beside it. */
@media (min-width: 700px) {
  .review {
    --panel: clamp(17rem, 30vw, 26rem);
    --bar: 2rem;
    --bars: calc(2 * var(--bar) + 0.8rem);
    --board: min(calc(100dvh - 2rem - var(--bars)), calc(100vw - var(--panel) - 4rem));
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  .board { --size: var(--board); }
  /* As tall as the board and its player bars, unless that is too short for the panel's contents. */
  .panel { height: calc(var(--board) + var(--bars)); min-height: min-content; overflow-y: auto; }
  /* The move details and the move list split the panel in fixed shares, so the
     move buttons between them never shift. Long details scroll inside their box. */
  .panel > * { flex-shrink: 0; }
  .panel > .move-info { flex: 1 1 0; min-height: 5rem; overflow-y: auto; }
  .panel > .moves { max-height: none; flex: 1 1 0; min-height: 7rem; }
}

/* Short screens such as a phone on its side: the panel boxes may get smaller
   so the panel still fits next to the board. */
@media (min-width: 700px) and (max-height: 560px) {
  .panel > .move-info { min-height: 3rem; }
  .panel > .moves { min-height: 3rem; }
}

/* Phones: the site switch takes a full row, the notify switch sits centered under it. */
@media (max-width: 480px) {
  .row { flex-direction: column; align-items: stretch; }
  .toggle { display: flex; }
  .toggle label { flex: 1; }
  .toggle span { width: 100%; justify-content: center; }
  .switch { align-self: center; }
  .subtitle { font-size: 1.4rem; }
  .card { padding: 1.25rem 1rem 1.5rem; }
  .games { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 0.4rem; }
  button.game { padding: 0.25rem 0.25rem 0.4rem; }
  .tile-moves { display: none; }
  /* The list runs under the footer while scrolling: keep the footer readable. */
  .bottom-bar { background: linear-gradient(transparent, rgba(0, 0, 0, 0.85) 45%); padding-top: 1.4rem; }
}
