/* Puzzle analyzr (/puzzleanalyzr/). Builds on app.css: the same paper, the
   same three voices. The one thing borrowed from Chess.com is its board and
   its green Play button: the position is a Chess.com board taped into the
   notebook, because that is where it opens. */

:root {
  --cc-light: oklch(93% 0.035 110);
  --cc-dark: oklch(62% 0.1 133);
  --cc-green: oklch(71% 0.15 132);
  --cc-green-hi: oklch(79% 0.15 128);
  --cc-green-deep: oklch(50% 0.1 140);
  --tape: oklch(91% 0.15 102 / 0.55);
}

.pz-open {
  padding-bottom: var(--s-7);
}

.pz-open__note {
  max-width: 13em;
  font-size: 1.5rem;
  transform: rotate(-2deg);
}

/* ---------- The desk: the position, and what to do with it ---------- */

.desk {
  padding-bottom: var(--s-9);
}

.desk__board {
  grid-column: main;
  max-width: 34rem;
  width: 100%;
}

.desk__panel {
  grid-column: side;
  display: grid;
  gap: var(--s-4);
  align-content: start;
}

.desk__title {
  margin: 0;
  font-size: 2rem;
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.015em;
}

.desk__turn {
  font-size: 1.75rem;
  line-height: 1.1;
  transform: rotate(-1.5deg);
  transform-origin: left center;
}

.desk__flip {
  max-width: 17em;
  font-size: 1.125rem;
  transform: rotate(-0.8deg);
}

.desk__flip[hidden] {
  display: none;
}

.desk__go {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--s-3);
  margin-top: var(--s-2);
}

.desk__go .btn {
  padding: 0 var(--s-3);
}

.desk__go .desk__solve {
  grid-column: 1 / -1;
}

/* .btn and .printout__line set their own display, so hidden ones need saying. */
.desk__go [hidden],
.desk__card [hidden] {
  display: none;
}

.desk__goes {
  margin-top: var(--s-2);
  font-size: var(--text-small);
  color: var(--ink-2);
}

.desk__status {
  min-height: 1.5em;
  font-size: var(--text-small);
  color: var(--ink-2);
}

.desk__status:empty {
  min-height: 0;
}

.desk__status[data-tone='red'] {
  color: var(--red);
}

.desk__card {
  margin-top: var(--s-2);
}

/* The Chess.com board, taped into the notebook like a printed photo. */
.cc-frame {
  position: relative;
  padding: var(--s-3);
  background: var(--card);
  box-shadow: 0 1px 1px var(--shadow), 0 18px 30px -18px var(--shadow);
  transform: rotate(-0.8deg);
}

.cc-frame::before,
.cc-frame::after {
  content: '';
  position: absolute;
  top: -12px;
  z-index: 7;
  width: 92px;
  height: 26px;
  background: var(--tape);
  /* Torn ends on a strip of tape. */
  clip-path: polygon(3% 0, 97% 4%, 100% 30%, 96% 55%, 99% 100%, 2% 96%, 0 70%, 4% 45%, 0 18%);
  pointer-events: none;
}

.cc-frame::before {
  left: -22px;
  transform: rotate(-38deg);
}

.cc-frame::after {
  right: -22px;
  transform: rotate(36deg);
}

.board--cc {
  background: var(--cc-light);
  border: 0;
  border-radius: 3px;
  box-shadow: none;
  overflow: hidden;
}

.board--cc::before {
  background: var(--cc-dark);
}

.board .cc-co {
  /* --x and --y come from app.css's [data-x] and [data-y] rules. */
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 12.5%;
  height: 12.5%;
  padding: 0.5cqi 0.9cqi;
  transform: translate(calc(var(--x, 0) * 100%), calc(var(--y, 0) * 100%));
  font-family: var(--font-book);
  font-size: 2.7cqi;
  font-weight: 800;
  line-height: 1;
}

.board .cc-co--file {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.cc-co.on-light {
  color: var(--cc-dark);
}

.cc-co.on-dark {
  color: var(--cc-light);
}

/* Chess.com's chunky green Play button: it sits on a darker ledge and presses down. */
.btn--cc {
  grid-column: 1 / -1;
  gap: var(--s-3);
  min-height: 60px;
  margin-bottom: 5px;
  border: 0;
  border-radius: 8px;
  background: var(--cc-green);
  color: var(--card);
  font-size: 1.25rem;
  font-weight: 800;
  text-shadow: 0 1px 0 var(--cc-green-deep);
  box-shadow: 0 5px 0 var(--cc-green-deep);
  transition: background-color 120ms var(--ease-out), transform 90ms var(--ease-out), box-shadow 90ms var(--ease-out);
}

.btn--cc:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--cc-green-deep);
}

@media (hover: hover) and (pointer: fine) {
  .btn--cc:hover {
    background: var(--cc-green-hi);
    text-decoration: none;
  }
}

.btn--cc__pawn {
  width: 1.6em;
  height: 1.6em;
  filter: drop-shadow(0 1px 0 var(--cc-green-deep));
}

/* Label .......... value, like a line on a printout. */
.desk__row {
  flex-wrap: nowrap;
  gap: var(--s-2);
}

.desk__dots {
  flex: 1;
  min-width: var(--s-4);
  border-bottom: 1.5px dotted var(--graphite-2);
  transform: translateY(-0.3em);
}

.desk__swap {
  display: grid;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.desk__swap-note {
  font-size: 1.125rem;
  color: var(--graphite);
}

.desk__swap-btns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ---------- Playing on the desk board ---------- */

.desk__play {
  cursor: pointer;
  touch-action: none; /* a drag moves the piece, not the page */
  -webkit-tap-highlight-color: transparent;
}

.desk__play .pc {
  will-change: transform;
  /* A tapped move glides; a drop settles at once (see .is-snap). */
  transition: transform 170ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 160ms var(--ease-out);
}

.desk__play .pc.is-drag {
  z-index: 6;
  transition: none;
  filter: drop-shadow(0 6px 5px oklch(23% 0.025 265 / 0.35));
}

.desk__play .pc.is-snap {
  z-index: 5;
  transition: transform 70ms ease-out;
}

/* Squares: the last move in highlighter, the chosen piece a shade stronger,
   Chess.com's soft dots for where it can go. */
.desk__marks {
  z-index: 1;
  pointer-events: none;
}

.board .dm {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transform: translate(calc(var(--x, 0) * 100%), calc(var(--y, 0) * 100%));
}

.dm--last {
  background: var(--highlight);
  opacity: 0.55;
  mix-blend-mode: multiply;
}

.dm--sel {
  background: var(--highlight);
  opacity: 0.85;
  mix-blend-mode: multiply;
}

.dm--dot {
  background: radial-gradient(circle, oklch(23% 0.025 265 / 0.2) 0 15%, transparent 16%);
}

.dm--ring {
  background: radial-gradient(circle, transparent 0 66%, oklch(23% 0.025 265 / 0.2) 67% 82%, transparent 83%);
}

.dm--hover {
  box-shadow: inset 0 0 0 0.75cqi oklch(100% 0 0 / 0.75);
}

.dm--check {
  background: radial-gradient(circle, oklch(62% 0.24 27 / 0.95) 0, oklch(62% 0.24 27 / 0.55) 35%, transparent 72%);
}

.desk__play .board__ink {
  z-index: 7;
}

.desk__play .board__ink .tone--blue .stroke {
  stroke-width: 1.05;
}

.desk__play .board__ink .tone--red .stroke {
  stroke-width: 0.9;
}

/* The learner's own drawings: over the pieces, under a piece being dragged
   and under the coach's red and blue pen. Hand ink, a little see-through so
   the pieces show through it, with a pale edge so it reads on dark squares. */
.desk__draw {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  /* Each drawing layer gets its own place on the GPU: the stroke being drawn
     (.desk__draw--live, on top) repaints alone, the finished drawings stay put. */
  will-change: transform;
}

.desk__draw.is-hidden {
  visibility: hidden;
}

.desk__draw .dr {
  --tone: var(--blue);
  fill: none;
  stroke: var(--tone);
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.88;
  filter: drop-shadow(0 0 0.35px oklch(99% 0.01 95 / 0.9));
}

.desk__draw .tone--red {
  --tone: var(--red);
}

.desk__draw .tone--green {
  --tone: var(--green);
}

.desk__draw .dr--fill {
  fill: var(--tone);
  stroke: none;
}

/* Pencil: softer, grainy, a little ragged at the edge (the filter is in the drawing's own SVG). */
.desk__draw .dr--pencil {
  opacity: 0.78;
  filter: url(#dr-grain);
}

/* Marker: a wide see-through band that darkens where it crosses itself, like a highlighter. */
.desk__draw .dr--marker {
  opacity: 0.4;
  stroke-linecap: square;
  filter: none;
  mix-blend-mode: multiply;
}

/* Ghost move: a dashed pencil arrow and a see-through piece on the square tried. */
.desk__draw .dr--ghost {
  stroke-width: 1.1;
  stroke-dasharray: 1.8 1.4;
}

.desk__draw .dr-ghost {
  opacity: 0.5;
  filter: grayscale(0.6) drop-shadow(0 0 0.4px var(--tone));
}

/* Tape along a line: the same see-through yellow as the tape holding the board down. */
.desk__draw .dr--tape {
  fill: var(--tape);
  stroke: none;
  opacity: 1;
  filter: none;
}

/* Stickers: a paper disc with a chess-book glyph, or a word on a strip of tape. */
.desk__draw .dr-sticker circle {
  fill: var(--card);
  stroke: var(--rule);
  stroke-width: 0.3;
  filter: drop-shadow(0.2px 0.35px 0.25px oklch(20% 0.02 95 / 0.45));
}

.desk__draw .dr-sticker text,
.desk__draw .dr-word__t {
  stroke: none;
  text-anchor: middle;
}

.desk__draw .dr-sticker text {
  fill: var(--tone);
  font: 700 3.3px var(--font-hand);
}

.desk__draw .tone--ink {
  --tone: var(--ink);
}

.desk__draw .dr-word__tape {
  fill: var(--tape);
  stroke: none;
}

.desk__draw .dr-word__t {
  fill: var(--ink);
  font: 700 1.55px var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.05px;
}

/* Helpers: pencil dots where a piece can go, rings where it takes, red
   "loose" tape on hanging pieces, and a small tally tag on a counted square. */
.desk__aid {
  pointer-events: none;
}

.desk__aid .aid-from {
  fill: var(--highlight);
  opacity: 0.45;
}

.desk__aid .aid-dot {
  fill: var(--graphite);
  opacity: 0.7;
}

.desk__aid .aid-take {
  fill: none;
  stroke: var(--graphite);
  stroke-width: 0.8;
  opacity: 0.7;
}

.desk__aid .aid-loose rect {
  fill: var(--red);
  opacity: 0.9;
}

.desk__aid text {
  text-anchor: middle;
  font: 700 1.9px var(--font-hand);
}

.desk__aid .aid-loose text {
  fill: var(--card);
}

.desk__aid .aid-tally rect {
  fill: var(--card);
  stroke: var(--blue);
  stroke-width: 0.3;
}

.desk__aid .aid-tally text {
  fill: var(--blue);
}

.desk__aid .aid-tally.is-short rect {
  stroke: var(--red);
}

.desk__aid .aid-tally.is-short text {
  fill: var(--red);
}

/* Coach check: a red pen cross on the move that fails, a blue tick when the line holds. */
.desk__aid .aid-coach path,
.desk__aid .aid-coach.is-ok {
  fill: none;
  stroke: var(--red);
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.desk__aid .aid-coach.is-ok {
  stroke: var(--blue);
}

/* Numbered line: each arrow carries its move number in a small paper disc. */
.desk__draw .dr--step {
  stroke-width: 1.3;
}

.desk__draw .dr-num {
  fill: var(--card);
  stroke: var(--tone);
  stroke-width: 0.5;
}

.desk__draw .dr-num__n {
  fill: var(--tone);
  stroke: none;
  font: 700 3.2px var(--font-hand);
  text-anchor: middle;
}

/* While the line plays out, the pieces can't be picked up. */
.desk__play.is-peeking {
  cursor: progress;
}

/* While the pointer is down: an arrow or circle shows where it will land, lighter. */
.desk__draw .is-live {
  opacity: 0.55;
}

.desk__play.is-drawing {
  cursor: crosshair;
}

/* Draw mode on: the frame gets a dashed blue edge, so it's clear a finger draws now. */
.cc-frame:has(.is-drawing) {
  outline: 2px dashed var(--blue);
  outline-offset: 3px;
}

/* Promotion: a small card on the board with the four pieces. */
.desk__promo {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: oklch(23% 0.025 265 / 0.28);
}

.pens__line[hidden],
.pens__coach[hidden],
.pens__sheet[hidden],
.desk__promo[hidden] {
  display: none;
}

.desk__promo-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-1);
  width: 62%;
  padding: var(--s-2) var(--s-3) var(--s-3);
  background: var(--card);
  box-shadow: 0 14px 30px -12px var(--shadow);
  transform: rotate(-1deg);
}

.desk__promo-label {
  grid-column: 1 / -1;
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.125rem;
  color: var(--blue);
}

.desk__promo-pick {
  aspect-ratio: 1;
  padding: 6%;
  border: 0;
  border-radius: 4px;
  background: var(--cc-light);
  cursor: pointer;
}

.desk__promo-pick:nth-of-type(even) {
  background: var(--cc-dark);
}

.desk__promo-pick img {
  width: 100%;
  height: 100%;
}

/* Under the board: the controls, what the board says, the moves so far. */
/* The pens: Draw mode, the tool, the ink, undo, clear, and show or hide. */
.pens {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

/* Move · Faint · Draw: one switch decides whether the board draws and how the drawings show. */
.pens__modes {
  display: flex;
  padding: 2px;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
}

.pens__modebtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 64px;
  justify-content: center;
  padding: 0 12px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--ink);
  font: 600 1rem/1 var(--font-book);
  cursor: pointer;
}

.pens__modebtn .pens__icon {
  width: 20px;
  height: 20px;
}

.pens__modebtn[aria-checked='true'] {
  background: var(--ink);
  color: var(--card);
}

.pens__modebtn[data-mode='draw'][aria-checked='true'] {
  background: var(--blue);
}

.pens__fade {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  font: 600 0.95rem/1 var(--font-hand);
  color: var(--ink);
}

.pens__fade input {
  width: 140px;
  accent-color: var(--blue);
}

.pens__fade-out {
  min-width: 3ch;
  font: 400 0.9rem/1 var(--font-print);
  color: var(--graphite);
}

/* The drawing kit only shows in Draw; display: contents keeps its sets in the row. */
.pens__kit {
  display: contents;
}

.pens__kit[hidden],
.pens__fade[hidden] {
  display: none;
}

.pens__set {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.pens__pick {
  display: grid;
  place-items: center;
  width: 40px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.pens__pick[aria-pressed='true'] {
  background: var(--highlight);
}

/* Every tool and size says its name under its picture, so nobody has to guess (no hover on touch). */
.pens__tools {
  flex-wrap: wrap;
}

.pens__pick--named {
  width: auto;
  min-width: 46px;
  height: auto;
  min-height: 48px;
  padding: 4px 5px 3px;
  gap: 2px;
  grid-template-rows: 24px auto;
}

.pens__name {
  font: 600 0.72rem/1 var(--font-hand);
  color: var(--ink-2);
  white-space: nowrap;
}

.pens__pick--named[aria-pressed='true'] .pens__name {
  color: var(--ink);
}

@media (hover: hover) and (pointer: fine) {
  .pens__pick[aria-pressed='false']:hover {
    background: var(--paper-2);
  }
}

.pens__icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pens__mode .pens__icon {
  width: 20px;
  height: 20px;
}

.pens__mode[aria-pressed='true'] {
  background: var(--blue);
  border-color: var(--blue-deep);
  color: var(--card);
}

.pens__icon--pencil {
  stroke-width: 1.4;
  stroke-dasharray: 2.2 1.1;
}

.pens__icon--ghost {
  stroke-dasharray: 2 1.6;
}

.pens__icon--marker {
  stroke-width: 4.5;
  stroke-linecap: square;
  opacity: 0.55;
}

/* Sizes: three dots, small to big. */
.pens__size {
  border-radius: 50%;
  background: var(--ink);
}

.pens__size--thin {
  width: 5px;
  height: 5px;
}

.pens__size--medium {
  width: 9px;
  height: 9px;
}

.pens__size--thick {
  width: 15px;
  height: 15px;
}

.pens__ink {
  --tone: var(--blue);
}

.pens__ink.tone--red {
  --tone: var(--red);
}

.pens__ink.tone--green {
  --tone: var(--green);
}

.pens__roles .pens__pick {
  width: auto;
  gap: 5px;
  grid-auto-flow: column;
  padding: 0 10px 0 8px;
}

.pens__role {
  font: 600 0.82rem/1 var(--font-hand);
  color: var(--ink);
}

.pens__dot {
  width: 18px;
  height: 18px;
  border-radius: 50% 46% 52% 48%;
  background: var(--tone);
}

.pens__ink[aria-pressed='true'] .pens__dot {
  box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--tone);
}

.pens__act:disabled {
  cursor: default;
  opacity: 0.45;
}

/* Undo, Clear and Show stay together on their own line, Show at the right like Sound. */
.pens__keep {
  display: flex;
  flex: 1 1 100%;
  gap: var(--s-2);
}

.pens__show {
  margin-left: auto;
}

.pens__show[aria-pressed='false'] {
  color: var(--graphite);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.pens__sheet {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--s-2);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.pens__stk {
  min-width: 40px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper, var(--card));
  color: var(--ink);
  font: 700 1.05rem/1 var(--font-hand);
  cursor: pointer;
  rotate: -3deg;
  box-shadow: 0 1px 2px oklch(20% 0.02 95 / 0.25);
}

.pens__stk:nth-child(even) {
  rotate: 2deg;
}

.pens__stk--word {
  border-radius: 2px;
  border-color: transparent;
  background: var(--tape);
  font: 600 0.72rem/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.06em;
}

.pens__stk[aria-pressed='true'] {
  outline: 2.5px solid var(--blue);
  outline-offset: 1px;
}

.pens__help {
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--ink);
  font: 600 0.92rem/1 var(--font-hand);
  cursor: pointer;
}

.pens__help[aria-pressed='true'] {
  background: var(--highlight);
}

.pens__line {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-2) var(--s-3);
  padding: var(--s-2) var(--s-3);
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.pens__coach {
  flex-basis: 100%;
  margin: 0;
  font: 700 1.02rem/1.35 var(--font-hand);
  color: var(--red);
}

.pens__coach.is-ok {
  color: var(--blue);
}

.pens__coach.is-busy {
  color: var(--graphite);
}

.pens__line-label {
  font-family: var(--font-hand);
  color: var(--graphite);
}

.pens__moves {
  flex: 1 1 12ch;
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pens__line-acts {
  display: flex;
  gap: var(--s-2);
}

.pens__hint {
  flex-basis: 100%;
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1rem;
  line-height: 1.3;
  color: var(--graphite);
}

.desk__tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-5);
}

.desk__tools .btn:disabled,
.engine__check:disabled {
  cursor: default;
  opacity: 0.45;
}

.desk__sound {
  margin-left: auto;
}

.desk__sound[aria-pressed='false'] {
  color: var(--graphite);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.desk__say {
  min-height: 1.3em;
  margin: var(--s-3) 0 0;
  font-size: 1.3125rem;
  transform: rotate(-0.6deg);
  transform-origin: left center;
}

.desk__say[data-tone='red'] {
  color: var(--red);
}

.desk__say:empty {
  min-height: 0;
  margin: 0;
}

.desk__moves {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--s-2);
  margin: var(--s-3) 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-hand);
  font-size: 1.125rem;
  color: var(--ink);
}

.desk__moves[hidden] {
  display: none;
}

.desk__moves li {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.desk__moves li.is-later {
  color: var(--graphite-2);
}

.desk__num {
  color: var(--graphite);
}

.desk__moves button {
  min-height: 32px;
  padding: 0 4px;
  border: 0;
  border-radius: 3px;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.desk__moves button .fig {
  width: 1.05em;
  height: 1.05em;
  vertical-align: -0.16em;
}

.desk__moves button[aria-current='step'] {
  background: var(--highlight);
}

/* Stockfish: a pencil line that fills while it downloads, and a button that asks it. */
.engine {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s-2) var(--s-4);
  align-items: center;
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1.5px dashed var(--graphite-2);
}

.engine__load {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.engine__bar {
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: 3px;
  background: var(--paper-2);
  color: var(--blue);
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
}

.engine__bar::-webkit-progress-bar {
  background: var(--paper-2);
}

.engine__bar::-webkit-progress-value {
  background: var(--blue);
  border-radius: 3px;
  transition: width 200ms linear;
}

.engine__bar::-moz-progress-bar {
  background: var(--blue);
  border-radius: 3px;
}

.engine[data-phase='ready'] .engine__bar,
.engine[data-phase='ready'] .engine__bar::-webkit-progress-value {
  background: var(--cc-green);
}

.engine[data-phase='ready'] .engine__bar::-moz-progress-bar {
  background: var(--cc-green);
}

.engine[data-phase='failed'] .engine__state {
  color: var(--red);
}

.engine__state {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--ink-2);
}

.engine__say {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 1.3125rem;
  transform: rotate(-0.6deg);
  transform-origin: left center;
}

.engine__say:empty {
  display: none;
}

.engine__say[data-tone='red'] {
  color: var(--red);
}

.engine__show {
  grid-column: 1 / -1;
  justify-self: start;
}

.engine__show[hidden] {
  display: none;
}

/* Which engine is in use, and the way to change it. */
.engine__which {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-3);
  margin: 0;
  font-size: var(--text-small);
  color: var(--ink-2);
}

.engine__name b {
  color: var(--ink);
}

.engine__pick {
  padding: var(--s-1) 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-family: var(--font-book);
  font-size: var(--text-small);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.engine__pick:hover {
  text-decoration-style: solid;
}

.engine__stop[hidden] {
  display: none;
}

/* ---------- The engine picker (pop-up) ---------- */

.engines {
  width: min(92vw, 40rem);
}

.engines__view[hidden],
.engines__warn[hidden],
.engines__handheld[hidden],
.engines__soon-note[hidden],
.engines__go .btn[hidden] {
  display: none;
}

.engines__handheld {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  margin: 0 var(--s-5) var(--s-4);
  padding: var(--s-3);
  border: 1px dashed var(--graphite-2);
  border-radius: var(--radius);
  font-size: var(--text-small);
  color: var(--ink-2);
}

.engines__group {
  margin: var(--s-4) var(--s-5) var(--s-2);
  font-family: var(--font-print);
  font-size: 0.8125rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.engines__group-note {
  margin: 0 var(--s-5) var(--s-3);
  font-size: var(--text-small);
  line-height: 1.5;
  color: var(--ink-2);
}

.engines__list {
  margin: 0 var(--s-5);
  padding: 0;
  list-style: none;
}

.engines__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px var(--s-3);
  align-items: start;
  padding: var(--s-3) 0;
  border-top: 1px solid var(--rule-soft);
}

.engines__row > p {
  grid-column: 1;
  margin: 0;
}

.engines__row.is-active .engines__name {
  color: var(--blue);
}

.engines__row[data-status='soon'] .engines__name {
  color: var(--ink-2);
}

.engines__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px var(--s-2);
}

.engines__name {
  font-family: var(--font-book);
  font-size: 1.0625rem;
  font-weight: 700;
}

.engines__tag {
  padding: 0 0.45em;
  border: 1px solid var(--graphite-2);
  border-radius: var(--radius);
  font-family: var(--font-print);
  font-size: 0.75rem;
  color: var(--ink-2);
}

.engines__tag--on {
  border-color: var(--blue);
  color: var(--blue);
}

.engines__tag--heavy {
  border-color: var(--red);
  color: var(--red);
}

.engines__about {
  font-size: var(--text-small);
  line-height: 1.45;
  color: var(--ink-2);
}

.engines__credit {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink-2);
  font-style: italic;
}

.engines__meta {
  font-family: var(--font-print);
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.engines__bytes {
  color: var(--ink);
  font-weight: 700;
}

.engines__use {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
  white-space: nowrap;
}

.engines__use:disabled {
  cursor: default;
  opacity: 0.55;
}

.engines__foot {
  margin: var(--s-4) var(--s-5) var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px dashed var(--graphite-2);
  font-size: var(--text-small);
  line-height: 1.5;
  color: var(--ink-2);
}

/* The heavy-download warning: red pen, the size written large, then the second yes. */
.engines__warn {
  padding-bottom: var(--s-5);
}

.engines__flag {
  margin: 0 var(--s-5) var(--s-2);
  font-family: var(--font-print);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--red);
}

.engines__size {
  margin: 0 var(--s-5) var(--s-3);
  font-family: var(--font-hand);
  font-size: 2.5rem;
  line-height: 1;
  color: var(--red);
  transform: rotate(-1.2deg);
  transform-origin: left center;
}

.engines__risks {
  margin: 0 var(--s-5) var(--s-4);
  padding: var(--s-3) var(--s-4) var(--s-3) 1.6em;
  border-left: 3px solid var(--red);
  background: var(--paper-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  line-height: 1.5;
}

.engines__risks li {
  margin-bottom: var(--s-1);
}

.engines__soon-note {
  margin: 0 var(--s-5) var(--s-4);
  font-size: 1.25rem;
  color: var(--blue);
}

.engines__go {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin: 0 var(--s-5);
}

@media (max-width: 30rem) {
  .engines__row {
    grid-template-columns: minmax(0, 1fr);
  }

  .engines__use {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
    margin-top: var(--s-2);
  }
}

/* ---------- Date picker (pop-up) and the paste help sheet ---------- */

/* "Pick a date" and "Where do I find a FEN or PGN?": quiet, underlined prompts. */
.paste__how {
  justify-self: start;
  margin-top: calc(-1 * var(--s-2));
  padding: var(--s-1) 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-family: var(--font-book);
  font-size: var(--text-small);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.paste__how:hover {
  text-decoration-style: solid;
}

/* The puzzle's name, kept covered until tapped: it can give the answer away. */
.desk__reveal {
  padding: 0 0.4em;
  border: 1px dashed var(--graphite-2);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--font-print);
  font-size: inherit;
  cursor: pointer;
}

.desk__reveal:hover {
  border-style: solid;
  color: var(--ink);
}

.desk__reveal.is-shown {
  border-color: transparent;
  background: none;
  color: var(--ink);
  font-weight: 700;
  cursor: default;
}

/* Both pop-ups: a taped index card that fades the page behind it. */
.cal-pop,
.howto {
  width: min(92vw, 34rem);
  max-height: min(86vh, 48rem);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 50px -12px var(--shadow);
  overflow: auto;
  overscroll-behavior: contain;
}

.cal-pop {
  width: min(92vw, 27rem);
}

.cal-pop::backdrop,
.howto::backdrop {
  background: oklch(23% 0.025 265 / 0.42);
  backdrop-filter: blur(2px);
}

.cal-pop[open],
.howto[open] {
  animation: sheet-rise 0.22s var(--ease-out);
}

@keyframes sheet-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.cal-pop__top,
.howto__top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5) var(--s-2);
  background: linear-gradient(var(--card) 70%, transparent);
}

.cal-pop__title {
  margin: 0;
  font-family: var(--font-book);
  font-size: 1.5rem;
  font-weight: 700;
}

.howto__kicker {
  font-family: var(--font-print);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.cal-pop__close,
.howto__close {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.cal__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
  margin: 0 var(--s-5) var(--s-4);
}

.cal__step {
  min-width: 44px;
  padding: 0;
  font-size: 1.375rem;
}

.cal__step:disabled {
  cursor: default;
  opacity: 0.35;
}

.cal__month {
  min-width: 9em;
  font-size: 1.375rem;
  font-weight: 700;
  text-align: center;
}

.cal__jump {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
  font-size: var(--text-small);
  color: var(--ink-2);
}

.cal__jump input {
  height: 40px;
  padding: 0 var(--s-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font-family: var(--font-book);
  font-size: 1rem;
}

.cal__days,
.cal__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  margin: 0 var(--s-5);
  padding: 0;
  list-style: none;
}

.cal__days {
  padding-bottom: var(--s-2);
  border-bottom: 2px solid var(--ink);
  font-family: var(--font-hand);
  font-size: 1rem;
  text-align: center;
  color: var(--graphite);
}

.cal__grid {
  row-gap: var(--s-1);
  padding-top: var(--s-2);
}

.cal__cell {
  aspect-ratio: 5 / 4;
  min-height: 44px;
}

.cal__day {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-2);
  font-family: var(--font-book);
  font-size: 1.25rem;
  font-variant-numeric: lining-nums tabular-nums;
  text-decoration: none;
}

a.cal__day,
button.cal__day {
  cursor: pointer;
}

.cal__day.is-later {
  color: var(--graphite-2);
  opacity: 0.55;
}

.cal__day.is-saved {
  color: var(--ink);
  font-weight: 700;
}

.cal__n {
  position: relative;
  z-index: 1;
  padding: 0 0.15em;
}

/* The puzzle on the board right now: a highlighter swipe across its date. */
.cal__day.is-on .cal__n {
  background: linear-gradient(transparent 18%, var(--highlight) 18%, var(--highlight) 82%, transparent 82%);
}

.cal__loop {
  position: absolute;
  inset: 6% 2%;
  width: 96%;
  height: 88%;
  overflow: visible;
  pointer-events: none;
  stroke-width: 4.2;
  stroke: var(--blue);
}

.cal__day.is-today .cal__loop {
  stroke: var(--red);
}

.cal__king {
  position: absolute;
  right: 4%;
  bottom: 4%;
  width: 34%;
  max-width: 20px;
  height: auto;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  a.cal__day:hover .cal__n {
    text-decoration: underline;
    text-decoration-color: var(--red);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.2em;
  }

  button.cal__day:hover {
    background: var(--paper-2);
  }
}

/* Chess.com or Lichess: a two-way switch under the title. */
.cal-src {
  display: inline-flex;
  margin: 0 var(--s-5) var(--s-4);
  padding: 3px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
}

.cal-src__opt {
  min-height: 36px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font-family: var(--font-book);
  font-size: var(--text-small);
  font-weight: 700;
  cursor: pointer;
}

.cal-src__opt[aria-checked='true'] {
  background: var(--ink);
  color: var(--card);
}

.cal-pop__key[hidden] {
  display: none;
}

.cal__day.is-missing {
  color: var(--graphite-2);
}

.cal-pop__key {
  display: grid;
  gap: var(--s-3);
  margin: var(--s-4) var(--s-5) var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px dashed var(--graphite-2);
  font-size: var(--text-small);
  line-height: 1.5;
  color: var(--ink-2);
}

.cal-pop__key p {
  margin: 0;
  display: flex;
  gap: 0.5em;
}

.cal__sample {
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 2em;
  height: 2em;
  font-family: var(--font-book);
  font-weight: 700;
  color: var(--ink);
}

.cal__sample .stroke {
  stroke: var(--blue);
  stroke-width: 5;
}

.cal__sample--plain {
  color: var(--graphite);
}

/* The FEN/PGN help sheet. */
.howto__title {
  margin: 0 var(--s-5) var(--s-2);
  font-family: var(--font-book);
  font-size: 1.75rem;
  font-weight: 700;
}

.howto__lede {
  margin: 0 var(--s-5) var(--s-4);
  color: var(--ink-2);
}

.howto__part {
  margin: 0 var(--s-5) var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--rule-soft);
}

.howto__part h3 {
  margin: 0 0 var(--s-2);
  font-family: var(--font-book);
  font-size: 1.1875rem;
}

.howto__part p {
  margin: 0 0 var(--s-2);
  line-height: 1.5;
}

.howto__quick {
  color: var(--ink-2);
}

.howto__part ol {
  margin: 0 0 var(--s-2);
  padding-left: 1.3em;
  line-height: 1.5;
}

.howto__part li {
  margin-bottom: var(--s-1);
}

.howto code {
  padding: 0.05em 0.35em;
  background: var(--paper-2);
  border-radius: var(--radius);
  font-family: var(--font-print);
  font-size: 0.9em;
  word-break: break-all;
}

.howto__end {
  margin: 0 var(--s-5) var(--s-5);
  color: var(--ink-2);
}

/* ---------- Paste ---------- */

.paste {
  padding-bottom: var(--s-9);
  row-gap: var(--s-5);
}

.paste__title {
  grid-column: main / end;
}

.paste__main {
  grid-column: main;
  display: grid;
  gap: var(--s-3);
  max-width: 40rem;
}

.paste__label {
  font-size: 1rem;
  font-weight: 600;
}

/* A ruled index card to write the position on. */
.paste__box {
  display: block;
  width: 100%;
  min-height: 8.6rem;
  padding: 0.55rem var(--s-4);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background-color: var(--card);
  background-image: repeating-linear-gradient(transparent 0 calc(1.6rem - 1px), var(--rule-soft) calc(1.6rem - 1px) 1.6rem);
  background-position: 0 0.55rem;
  background-attachment: local;
  color: var(--ink);
  font-family: var(--font-print);
  font-size: 1rem;
  line-height: 1.6rem;
  resize: vertical;
  overflow-wrap: anywhere;
}

.paste__box::placeholder {
  color: var(--graphite-2);
  opacity: 1;
}

.paste__reply {
  min-height: 1.3em;
  transform: rotate(-0.8deg);
  transform-origin: left center;
}

.paste__reply:empty {
  min-height: 0;
}

.paste__go {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}

.paste__go [hidden] {
  display: none;
}

.paste__side {
  grid-column: side;
  padding-top: var(--s-6);
}

.paste__reads .printout__line {
  display: block;
}

.paste__reads b {
  margin-right: 0.4em;
  font-weight: 700;
  color: var(--blue-deep);
}

.paste__reads .printout__line + .printout__line {
  margin-top: var(--s-2);
}

/* ---------- My games: a contact sheet of final positions ---------- */

.played {
  padding-bottom: var(--s-9);
  row-gap: var(--s-5);
}

.played__title {
  grid-column: main / end;
}

.played__main {
  grid-column: main;
  display: grid;
  gap: var(--s-4);
  max-width: 40rem;
}

.played__form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s-3);
}

.played__field {
  flex: 1 1 14rem;
  min-width: 0;
}

.played__submit {
  min-height: 54px;
}

.played__bar {
  margin: 0;
}

.played__bar[hidden] {
  display: none;
}

.played__sheet {
  grid-column: main / end;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: var(--s-6) var(--s-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.played__sheet:empty {
  display: none;
}

.played__card {
  position: relative;
  display: grid;
  gap: var(--s-1);
  padding: var(--s-3) var(--s-3) var(--s-3);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 1px 1px var(--shadow), 0 12px 22px -16px var(--shadow);
  transition: transform 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}

.played__item:nth-child(3n + 1) .played__card {
  transform: rotate(-0.7deg);
}

.played__item:nth-child(3n + 2) .played__card {
  transform: rotate(0.5deg);
}

.played__item:nth-child(3n) .played__card {
  transform: rotate(-0.2deg);
}

@media (hover: hover) and (pointer: fine) {
  .played__item .played__card:hover {
    transform: rotate(0deg) translateY(-3px);
    box-shadow: 0 1px 1px var(--shadow), 0 18px 26px -16px var(--shadow);
  }

  .played__card:hover .played__vs {
    text-decoration: underline;
    text-decoration-color: var(--red);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.2em;
  }
}

.played__card .board {
  margin-bottom: var(--s-2);
}

.played__card .board--cc {
  box-shadow: none;
}

.played__vs {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.played__meta {
  font-family: var(--font-print);
  font-size: 0.8125rem;
  line-height: 1.3;
  color: var(--graphite);
}

/* The result, written by the coach across the corner of the board. */
.played__res {
  position: absolute;
  top: -0.55rem;
  right: -0.35rem;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 0.15em;
  padding: 0 0.3em;
  background: var(--card);
  font-family: var(--font-hand);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  transform: rotate(-6deg);
}

.played__res--win {
  color: var(--blue);
}

.played__res--loss {
  color: var(--red);
}

.played__res--draw {
  color: var(--graphite);
}

.played__tick {
  width: 1.1em;
  height: 1em;
  overflow: visible;
  stroke: currentColor;
  stroke-width: 9;
}

.played__more {
  grid-column: main / end;
}

.played__more:has([hidden]) {
  display: none;
}

/* ---------- Before your first puzzle ---------- */

.pz-setup__tips {
  grid-column: main;
}

.pz-setup__tips p + p {
  margin-top: var(--s-4);
}

.pz-setup__how {
  display: grid;
  gap: var(--s-3);
  max-width: 64ch;
  padding-bottom: var(--s-5);
  color: var(--ink-2);
}

.faq .pz-setup__how p {
  padding-bottom: 0;
}

.pz-setup__bm {
  min-height: 5rem;
  font-size: 0.8125rem;
}

.pz-setup__credit {
  grid-column: main / end;
  max-width: 70ch;
  font-size: var(--text-small);
  color: var(--ink-2);
}

.pz-offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

/* ---------- Narrower screens ---------- */

@media (max-width: 1079px) {
  .desk__board,
  .desk__panel,
  .paste__title,
  .paste__main,
  .paste__side,
  .played__title,
  .played__main,
  .played__sheet,
  .played__more,
  .pz-setup__tips,
  .pz-setup__credit {
    grid-column: 1;
  }

  .desk {
    row-gap: var(--s-6);
  }

  .desk__panel {
    max-width: 38rem;
  }

  .paste__side {
    max-width: 40rem;
    padding-top: var(--s-3);
  }
}

@media (max-width: 699px) {
  .pz-open {
    padding-top: var(--s-6);
    padding-bottom: var(--s-6);
  }

  .desk__title {
    font-size: 1.75rem;
  }

  .desk__go {
    grid-template-columns: minmax(0, 1fr);
  }

  .desk__go .btn:not(.btn--cc) {
    min-height: 52px;
  }

  /* Back, Next, Start over on one row; Flip and Sound under them. */
  .desk__tools {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .desk__tools .btn {
    grid-column: span 2;
    padding: 0 var(--s-2);
  }

  .desk__tools #tool-flip,
  .desk__tools .desk__sound {
    grid-column: span 3;
  }

  .desk__sound {
    margin-left: 0;
  }

  .pens__mode {
    padding: 0 var(--s-3);
  }

  .pens__pick {
    width: 34px;
    height: 40px;
  }

  .pens__pick--named {
    width: auto;
    min-width: 40px;
    height: auto;
  }

  .engine {
    grid-template-columns: minmax(0, 1fr);
  }

  .cal__jump {
    width: 100%;
    margin-left: 0;
  }

  .cal__month {
    flex: 1;
    min-width: 0;
  }

  .cal__day {
    font-size: 1.0625rem;
  }

  .played__sheet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-5) var(--s-4);
  }

  .played__res {
    font-size: 1.125rem;
  }

  .desk,
  .paste,
  .played {
    padding-bottom: var(--s-8);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn--cc,
  .played__card,
  .desk__play .pc {
    transition: none;
  }
}

@media print {
  .pens,
  .desk__tools,
  .engine,
  .desk__go,
  .desk__swap,
  .cal__bar,
  .paste__go,
  .played__form {
    display: none;
  }
}

/* Book page: the board and the learner's notes, set like a page of a chess book. */
.book {
  width: min(94vw, 46rem);
}

.book__page {
  margin: 0 var(--s-5) var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-3);
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  box-shadow: 0 1px 0 var(--rule-soft), 0 10px 24px -18px var(--shadow);
  color: var(--ink);
}

.book__title {
  margin: 0 0 var(--s-4);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--ink);
  font-family: var(--font-book);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: oldstyle-nums;
}

.book__spread {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: var(--s-5);
  align-items: start;
}

@media (max-width: 34rem) {
  .book__spread {
    grid-template-columns: 1fr;
  }
}

.book__fig {
  margin: 0;
}

.book__board {
  position: relative;
  aspect-ratio: 86 / 87;
}

.book__squares {
  display: block;
  width: 100%;
  height: 100%;
}

.book__board .book__ink {
  /* Drawings sit on the 80 by 80 board inside the diagram's margin for the coordinates. */
  inset: calc(100% / 87) auto auto calc(500% / 86);
  width: calc(8000% / 86);
  height: calc(8000% / 87);
  will-change: auto;
}

.book__light {
  fill: oklch(99.5% 0.003 95);
}

.book__dark-bg {
  fill: oklch(99.5% 0.003 95);
}

.book__hatch {
  stroke: var(--ink);
  stroke-width: 0.42;
}

.book__frame {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
}

.book__coord {
  fill: var(--ink-2);
  font: 600 2.9px var(--font-book);
  text-anchor: middle;
}

.book__caption {
  margin-top: var(--s-2);
  font-family: var(--font-book);
  font-style: italic;
  text-align: center;
}

.book__caption::before {
  content: '';
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.45em;
  border: 1.5px solid var(--ink);
  vertical-align: 0.05em;
}

.book__margin {
  display: grid;
  gap: var(--s-2);
  padding-left: var(--s-4);
  border-left: 1px solid var(--rule);
  font-family: var(--font-book);
  font-size: 0.95rem;
  line-height: 1.45;
}

.book__note {
  margin: 0;
}

.book__note--line {
  font-weight: 700;
}

.book__note--empty {
  color: var(--ink-2);
  font-style: italic;
}

.book__label {
  font-family: var(--font-print);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.book__own {
  margin: var(--s-2) 0 0;
  font-family: var(--font-hand);
  font-size: 1.05rem;
  line-height: 1.35;
  color: var(--blue);
  white-space: pre-wrap;
}

.book__foot {
  margin: var(--s-5) 0 0;
  font-family: var(--font-print);
  font-size: 0.7rem;
  color: var(--ink-2);
  text-align: right;
}

.book__tools {
  display: grid;
  gap: var(--s-2);
  padding: 0 var(--s-5) var(--s-5);
}

.book__write {
  font-weight: 600;
}

.book__write span {
  font-weight: 400;
  color: var(--ink-2);
}

.book__textarea {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 1.05rem/1.35 var(--font-hand);
  resize: vertical;
}

.book__go {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.book__say:empty {
  display: none;
}

@media print {
  html.is-printing-book body > *:not(main),
  html.is-printing-book main > *:not(#book-pop),
  html.is-printing-book .book__top,
  html.is-printing-book .book__tools {
    display: none !important;
  }

  html.is-printing-book main {
    padding: 0;
    margin: 0;
  }

  html.is-printing-book .book {
    position: static;
    inset: auto;
    margin: 0;
    width: auto;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    animation: none;
  }

  html.is-printing-book .book::backdrop {
    display: none;
  }

  html.is-printing-book .book__page {
    margin: 0;
    border: 0;
    box-shadow: none;
    background: none;
  }
}

/* The Chess.com app is ahead of the public feed between local midnight and Pacific midnight. */
.desk__ahead {
  margin: var(--s-2) 0 0;
}

/* Set up a position: a board to tap pieces onto, and a tray of pieces under it. */
.setup {
  width: min(94vw, 30rem);
}

.setup__body {
  display: grid;
  gap: var(--s-3);
  padding: 0 var(--s-5) var(--s-5);
}

.setup__lede {
  margin: 0;
  color: var(--ink-2);
}

.setup .setup__side {
  justify-self: start;
  margin: 0;
}

.setup__board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
  touch-action: manipulation;
}

.setup__sq {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: var(--cc-light);
  cursor: pointer;
}

.setup__sq--dark {
  background: var(--cc-dark);
}

.setup__sq img {
  width: 92%;
  height: auto;
  max-height: 92%;
  pointer-events: none;
}

.setup__sq:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
}

.setup__tray {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.setup__pick {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 2px;
  border: 1.5px solid transparent;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.setup__pick img {
  width: 100%;
  max-width: 40px;
  height: auto;
  pointer-events: none;
}

.setup__pick span {
  font-size: 0.7rem;
}

.setup__pick[aria-checked='true'] {
  border-color: var(--ink);
  background: var(--highlight);
}

.setup__pick--rub {
  grid-row: 1 / span 2;
  grid-column: 7;
}

.setup__note {
  min-height: 1.5em;
  margin: 0;
}

.setup__tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.setup__done {
  justify-self: start;
}

@media (prefers-reduced-motion: reduce) {
  .setup[open] {
    animation: none;
  }
}
