/* Frost Window Letters — the play screen. A reader's notebook over a pulp-paperback plate:
   thin hand-ruled ink cells for the glass, pen boxes in the margin, orange lamp ink for the
   player's letters. Kit colours and fonts only. */

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art), var(--ak-backdrop-layer, none);
  background-size: var(--ak-bg-size), cover;
  background-position: 0 0, center;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

:root {
  --line: color-mix(in srgb, var(--ak-ink) 62%, transparent);
  --hair: color-mix(in srgb, var(--ak-ink) 30%, transparent);
  --pen-radius: 3px 9px 4px 8px / 8px 4px 9px 3px;
  --edge: clamp(4px, calc((100vw - 356px) / 2), 12px);
  --k: clamp(40px, min(calc((100vw - 2 * var(--edge) - 6 * 5px) / 7), calc((100dvh - 652px) / 4)), 52px);
}

/* The night printed round the page in coarse halftone; grey dawn rises over it at the end. */
.night,
.dawn {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.night {
  background-image: radial-gradient(circle, color-mix(in srgb, var(--ak-ink) 70%, transparent) 1.3px, transparent 1.9px);
  background-size: 6px 6px;
  -webkit-mask-image: radial-gradient(ellipse 70% 62% at 50% 52%, transparent 62%, #000 100%);
  mask-image: radial-gradient(ellipse 70% 62% at 50% 52%, transparent 62%, #000 100%);
}

/* One lamp lit near the clue, and the dark pressing in at the edges of the glasshouse. */
.lamp {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 16% 9%, color-mix(in srgb, var(--ak-accent) 30%, transparent) 0, color-mix(in srgb, var(--ak-accent) 10%, transparent) 18%, transparent 36%),
    radial-gradient(ellipse 82% 76% at 50% 50%, transparent 56%, rgba(14, 10, 8, 0.55) 100%);
}

:root.ac-lights-up .lamp { opacity: 0.3; }
:root.is-dawn .lamp { opacity: 0.35; }

.dawn {
  opacity: 0;
  background: linear-gradient(to top, color-mix(in srgb, var(--ak-ink-muted) 34%, transparent) 0%, color-mix(in srgb, var(--ak-ink-muted) 12%, transparent) 45%, transparent 75%);
}

:root.is-dawn .night { opacity: 0; }
:root.is-dawn .dawn { opacity: 1; }
:root.ac-lights-up .night { opacity: 0.25; }
:root.ac-lights-up body { background-color: var(--ak-surface); }

/* ---------- the page ---------- */

.play {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "pane" "desk";
  row-gap: 4px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(var(--ac-status-h, 72px) + 2px)
    max(var(--edge), env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom))
    max(var(--edge), env(safe-area-inset-left));
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.logo {
  flex: 0 1 auto;
  margin-left: auto;
  height: 36px;
  width: auto;
  min-width: 0;
  max-width: 64px;
  object-fit: contain;
}

/* ---------- the margin row: clue, tabs, hint ---------- */

.head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
}

.clue {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 3px;
  border: 1.5px solid var(--ak-ink);
  border-radius: var(--pen-radius);
  background: var(--ak-surface);
}

.clue img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Tonight's key, written on the vignette in ink. */
.clue-key {
  position: absolute;
  left: 50%;
  bottom: 2px;
  z-index: 1;
  translate: -50% 0;
  padding: 0 3px;
  border: 1px solid var(--ak-ink);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 12px;
  font-weight: 700;
  line-height: 15px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.clue .lens {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 20px;
  height: 20px;
  padding: 2px;
  border-radius: 50%;
  background: var(--ak-bg);
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 2.4;
  stroke-linecap: round;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab,
.hint {
  position: relative;
  background: var(--ak-surface);
  min-width: 48px;
  height: 48px;
  border: 1.5px solid var(--ak-ink);
  border-radius: var(--pen-radius);
  font-family: var(--ak-font-display);
  font-size: 22px;
  line-height: 1;
  color: var(--ak-ink);
}

.tab span { position: relative; z-index: 1; }

.tab.is-on {
  border-width: 2.5px;
  background: var(--ak-surface);
}

/* An orange pen circle round the open note. */
.tab.is-on::after {
  content: '';
  position: absolute;
  inset: 7px 4px;
  border: 2px solid var(--ak-accent);
  border-radius: 48% 52% 45% 55% / 55% 45% 55% 45%;
  rotate: -6deg;
}

.tab .tick {
  position: absolute;
  top: -9px;
  right: -7px;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  padding: 0 12px;
  font-size: 18px;
  border-style: dashed;
}

/* ---------- the window ---------- */

.pane {
  grid-area: pane;
  position: relative;
  min-height: 0;
  padding: 2px 1px;
  /* The window itself: a frosted sheet in a leaded frame, set apart from the room around it.
     The frame is an outline so it takes no room from the 44px marks. */
  outline: 4px double var(--ak-ink);
  background: var(--ak-surface);
  box-shadow: 0 0 0 1px var(--ak-ink-muted), 0 16px 34px rgba(0, 0, 0, 0.35);
  /* Cells never shrink under 44px; on a screen too short for the whole note, the glass scrolls. */
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

.prints {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.rows {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: safe center;
  gap: var(--rg, 4px);
  min-height: 100%;
}

.row {
  display: flex;
  flex: 0 0 auto;
  gap: var(--gap, 14px);
}

.word { display: flex; flex: 0 0 auto; }

.cell {
  position: relative;
  display: grid;
  grid-template-rows: 42% 58%;
  justify-items: center;
  align-items: center;
  width: var(--s, 44px);
  height: var(--s, 44px);
  border: 0;
  background: transparent;
}

/* Words sit on a ruled line, like a note found on the glass, not in boxes. Drawn as a shadow: no extra height. */
.word { box-shadow: inset 0 -1.5px 0 var(--line); }


.guess {
  position: relative;
  align-self: end;
  min-width: 0.6em;
  font-family: var(--ak-font-display);
  font-size: calc(var(--s, 44px) * 0.42);
  line-height: 0.9;
  color: var(--ak-accent);
  -webkit-text-stroke: 1.8px var(--ak-ink);
  paint-order: stroke fill;
}

.cell.is-empty .guess::before {
  content: '';
  display: block;
  width: calc(var(--s, 44px) * 0.36);
  height: 0;
  margin-bottom: 2px;
  border-bottom: 1.5px dotted var(--ak-ink-muted);
}

/* The frost mark: a scratched letter in a round frost ring, never a square like the lamp tiles. */
.mark {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(var(--s, 44px) * 0.54);
  height: calc(var(--s, 44px) * 0.54);
  font-family: var(--ak-font-body);
  font-weight: 600;
  font-size: calc(var(--s, 44px) * 0.38);
  line-height: 1;
  color: var(--ak-ink);
}

.mark::before {
  content: '';
  position: absolute;
  inset: -2px;
  border: 1.5px dotted var(--ak-ink-muted);
  border-radius: 50%;
}

.mark .glyph {
  width: 100%;
  height: 100%;
  fill: var(--ak-ink);
  stroke: var(--ak-ink);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mark .glyph path { fill: none; }

.cell.is-same .mark::before {
  border: 2.5px solid var(--ak-accent);
  border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
}

.cell.is-sel {
  background: var(--ak-surface);
  outline: 2.5px solid var(--ak-ink);
  outline-offset: -1px;
  z-index: 1;
}

/* A failed check scores a pen line under each word that does not read right yet. */
.word { position: relative; }

.word.is-wrong .cell { background: color-mix(in srgb, var(--ak-surface) 80%, transparent); }

.word.is-wrong::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 2px;
  z-index: 2;
  height: 5px;
  border-top: 2px solid var(--ak-ink);
  border-bottom: 2px solid var(--ak-ink);
  pointer-events: none;
}

/* A read note: the frost thins round the marks. */
.rows.is-read .mark { color: var(--ak-ink-muted); }
.rows.is-read .mark .glyph { stroke: var(--ak-ink-muted); fill: var(--ak-ink-muted); }
.rows.is-read .mark::before { border-color: transparent; }
.rows.is-read .cell { border-color: var(--hair); cursor: default; }

/* ---------- fingerprints ---------- */

.print {
  position: absolute;
  width: 34px;
  height: 44px;
  translate: -50% -50%;
  rotate: -8deg;
}

.print svg { display: block; width: 100%; height: 100%; }
.print .pr-glass { fill: var(--ak-ink); opacity: 0.88; }
.print .pr-lines { fill: none; stroke: var(--ak-bg); stroke-width: 1.1; opacity: 0.55; }
.print.is-stranger { width: 38px; height: 50px; rotate: 11deg; }

.breath {
  position: absolute;
  width: 40px;
  height: 52px;
  translate: -50% -50%;
  border: 1.5px dotted var(--ak-ink-muted);
  border-radius: 50%;
  opacity: 0.6;
}

/* ---------- the desk: margin note or letter tray ---------- */

.desk {
  grid-area: desk;
  position: relative;
  height: calc(4 * var(--k) + 3 * 5px);
  min-height: 0;
}

.note {
  position: relative;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 10px;
  border: 1px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
  rotate: -0.6deg;
}

/* The pin. */
.note::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ak-accent);
  translate: -50% 0;
}

.note p { margin: 0; }

.note-head {
  margin-bottom: 6px;
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-variant: small-caps;
  letter-spacing: 0.1em;
}

.note-line {
  font-size: 18px;
  line-height: 1.35;
}

.note-teach {
  font-size: 19px;
  line-height: 1.38;
  font-weight: 500;
}

.note-tip.note-said { margin: 0 0 6px; padding: 0; border: 0; }

.note-tip {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--hair);
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-style: italic;
  line-height: 1.35;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
}

.legend img {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.note .star {
  float: right;
  width: 54px;
  height: 54px;
  margin: -4px -4px 4px 8px;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 2.4;
  stroke-linejoin: round;
  rotate: 8deg;
}

.note .stamp {
  float: right;
  margin: 0 0 8px 10px;
  padding: 6px 12px 5px;
  border: 3px solid var(--ak-accent);
  outline: 1.2px solid var(--ak-accent);
  outline-offset: -7px;
  color: var(--ak-link);
  text-align: center;
  rotate: -9deg;
}

.stamp .stamp-big {
  font-family: var(--ak-font-display);
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stamp .stamp-small {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.pen {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  margin-top: 8px;
  padding: 0 14px;
  border: 1.5px solid var(--ak-ink);
  border-radius: var(--pen-radius);
  font-size: 17px;
  font-weight: 500;
}

.tray {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 5px;
  height: 100%;
}

/* A lamp tile: a square pen cell with the letter in orange ink. */
.key {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1.5px solid var(--ak-ink);
  border-radius: var(--pen-radius);
  background: var(--ak-surface);
  font-family: var(--ak-font-display);
  font-size: calc(var(--k) * 0.58);
  line-height: 1;
  color: var(--ak-accent);
  -webkit-text-stroke: 2px var(--ak-ink);
  paint-order: stroke fill;
}

.key.is-taken {
  background: transparent;
  border-style: dashed;
}

.key.is-taken::after {
  content: '';
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ak-ink-muted);
}

.key.is-mine {
  border-width: 3px;
  box-shadow: inset 0 0 0 2px var(--ak-accent);
}

/* The first key repeats the chosen mark, ringed in orange like the mark on the glass. */
.key-echo {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0;
  border-style: dashed;
  background: transparent;
  color: var(--ak-ink);
  -webkit-text-stroke: 0;
  font-family: var(--ak-font-body);
}

.echo-mark {
  display: grid;
  place-items: center;
  width: calc(var(--k) * 0.56);
  height: calc(var(--k) * 0.56);
  border: 2.5px solid var(--ak-accent);
  border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
  font-size: calc(var(--k) * 0.34);
  font-weight: 600;
  line-height: 1;
}

.echo-mark svg,
.chip svg {
  width: 82%;
  height: 82%;
  fill: var(--ak-ink);
  stroke: var(--ak-ink);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.echo-mark svg path,
.chip svg path { fill: none; }

.echo-is {
  font-size: 12px;
  font-weight: 600;
  font-style: italic;
  line-height: 1.1;
}

.echo-x {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 11px;
  height: 11px;
  fill: none;
  stroke: var(--ak-ink-muted);
  stroke-width: 3;
  stroke-linecap: round;
}

/* Sideways there is room to say it in words above the tray. */
.tray-head {
  display: none;
  margin: 0;
  color: var(--ak-ink);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.2;
}

.chip {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-left: 6px;
  vertical-align: middle;
  border: 2.5px solid var(--ak-accent);
  border-radius: 50%;
  background: var(--ak-surface);
  font-weight: 600;
  font-size: 17px;
}

.key-blank,
.key-done {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  color: var(--ak-ink);
  -webkit-text-stroke: 0;
  font-family: var(--ak-font-body);
  font-size: 11px;
  font-weight: 600;
  background: transparent;
}

.key-blank svg,
.key-done svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- the clue up close ---------- */

.plate {
  position: fixed;
  inset: 0;
  z-index: 33;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(10, 8, 7, 0.72);
}

.plate-sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 520px);
  max-height: calc(100dvh - 2 * max(16px, env(safe-area-inset-top)));
  overflow: auto;
  padding: 18px 18px 12px;
  border: 1px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.55);
  rotate: 0.8deg;
}

.plate-title {
  margin: 0;
  padding-bottom: 6px;
  border-bottom: 3px double var(--ak-outline);
  font-family: var(--ak-font-display);
  font-size: 21px;
  font-weight: 400;
  text-align: center;
}

.plate-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.plate-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.plate-art img { display: block; object-fit: contain; }

.art-frame { position: relative; display: inline-block; line-height: 0; }

.art-tag {
  position: absolute;
  margin: 0;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

/* The reading, pencilled beside the circled point on the thermometer. */
.art-reading {
  left: calc(100% + 10px);
  top: 49%;
  translate: 0 -50%;
  padding: 4px 8px;
  border: 1.5px solid var(--ak-ink);
  border-radius: var(--pen-radius);
  background: var(--ak-surface);
  font-size: 22px;
}

.art-reading::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 12px;
  border-top: 1.5px solid var(--ak-ink);
}

/* A slip pasted over the ringed date, with tonight's word on it. */
.art-slip {
  left: 72.5%;
  top: 54.5%;
  translate: -50% -50%;
  rotate: -7deg;
  padding: 5px 8px;
  border: 2px solid var(--ak-accent);
  background: var(--ak-surface);
  font-size: clamp(12px, 3.4vw, 17px);
  letter-spacing: 0.06em;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}
.plate-caesar img { height: min(46dvh, 340px); width: auto; }
.plate-keyword .art-frame { width: min(100%, 420px, 56dvh); }
.plate-pigpen .art-frame { width: min(42%, 46dvh, 220px); }
.plate-keyword img,
.plate-pigpen img { width: 100%; height: auto; }

.tracing {
  width: min(52%, 50dvh, 260px);
  height: auto;
}

.tracing .bar { stroke: var(--ak-ink); stroke-width: 1.6; stroke-linecap: round; }
.tracing .etch { fill: var(--ak-ink); font-family: var(--ak-font-body); font-size: 15px; font-weight: 600; text-anchor: middle; }
.tracing .bubble { fill: none; stroke: var(--ak-ink); stroke-width: 1.4; }

.plate-note.plate-plain {
  font-style: normal;
  font-weight: 500;
}

.plate-note {
  max-width: 34em;
  margin: 0;
  font-size: 18px;
  font-style: italic;
  line-height: 1.4;
  text-align: center;
}

.plate-close { margin-top: 2px; }

/* ---------- teaching ---------- */

.guide {
  position: fixed;
  inset: 0;
  z-index: 28;
  pointer-events: none;
}

.guide-ring {
  position: fixed;
  border: 3px solid var(--ak-accent);
  border-radius: 50%;
}

.guide-ring.is-wide { border-radius: 14px; }

.guide-arrow {
  position: fixed;
  width: 44px;
  height: 44px;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  rotate: 180deg;
}

.guide-arrow.is-up { rotate: 0deg; }

.guide-float {
  position: fixed;
  z-index: 28;
  margin: 0;
  padding: 12px 16px;
  border: 1.5px solid var(--ak-ink);
  border-radius: 2px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 19px;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* ---------- sideways: the window on one side, the margin on the other ---------- */

@media (orientation: landscape) {
  :root {
    --edge: 6px;
    --k: clamp(40px, calc((100dvh - var(--ac-status-h, 72px) - 32px) / 5), 48px);
  }

  /* The margin (status, note, tray) down the left; the clue row and the window on the right. */
  .play {
    max-width: 1180px;
    grid-template-columns: minmax(0, calc(6 * var(--k) + 5 * 5px)) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "desk head" "desk pane";
    column-gap: 8px;
    row-gap: 4px;
    padding-top: 0;
  }

  .head {
    margin-top: max(6px, env(safe-area-inset-top));
    padding-right: 66px;
  }

  .logo { margin-left: 6px; max-width: 70px; height: 44px; }

  .desk {
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: min(calc(5 * var(--k) + 4 * 5px + 40px), calc(100dvh - var(--ac-status-h, 72px) - 8px));
    margin-top: calc(var(--ac-status-h, 72px) + 2px);
  }

  .desk .note { flex: 1 1 auto; height: auto; min-height: 0; }

  .tray-head:not([hidden]) { display: block; flex: 0 0 auto; }

  .tray {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: repeat(5, minmax(0, 1fr));
    max-height: calc(5 * var(--k) + 4 * 5px);
  }
}

/* ---------- motion: slow, warm, never sudden ---------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .night,
  :root:not(.ac-still) .dawn { transition: opacity 5s ease-in-out; }

  :root:not(.ac-still) .cell.is-inked .guess { animation: ink-settle 1100ms ease-out both; }

  :root:not(.ac-still) .cell.is-settle .guess { animation: thaw-settle 1300ms ease-out var(--d, 0ms) both; }
  :root:not(.ac-still) .cell.is-settle .mark::before { transition: border-color 2.4s ease-out; }
  :root:not(.ac-still) .rows .mark { transition: color 2.4s ease-out; }

  :root:not(.ac-still) .note.is-read .star path {
    stroke-dasharray: 100;
    animation: star-draw 1600ms ease-out 400ms both;
  }

  :root:not(.ac-still) .note.is-dawn .stamp { animation: stamp-land 900ms cubic-bezier(0.22, 1, 0.36, 1) 300ms both; }
  :root:not(.ac-still) .note .note-line,
  :root:not(.ac-still) .note .note-teach { animation: note-fade 700ms ease-out both; }

  :root:not(.ac-still) .tray.is-rising { animation: tray-rise 500ms ease-out both; }
  @keyframes tray-rise { from { opacity: 0; translate: 0 14px; } to { opacity: 1; translate: 0 0; } }

  :root:not(.ac-still) .guide-ring { animation: ring-breathe 2400ms ease-in-out infinite; }

  :root:not(.ac-still) .print:not(.is-stranger) { animation: melt 1400ms ease-out both; }
  :root:not(.ac-still) .print.is-stranger { animation: melt 9000ms ease-in-out 2500ms both; }
  :root:not(.ac-still) .breath { animation: breath 2000ms linear both; }

  :root:not(.ac-still) .plate:not([hidden]) .plate-sheet { animation: note-fade 600ms ease-out both; }

  @keyframes ink-settle {
    0% { opacity: 0; translate: 0 -3px; text-shadow: 0 0 16px var(--ak-accent); }
    60% { opacity: 1; text-shadow: 0 0 10px var(--ak-accent); }
    100% { opacity: 1; translate: 0 0; text-shadow: 0 0 0 transparent; }
  }

  @keyframes thaw-settle {
    0% { translate: 0 -4px; text-shadow: 0 0 14px var(--ak-accent); }
    100% { translate: 0 0; text-shadow: 0 0 0 transparent; }
  }

  @keyframes star-draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }

  @keyframes stamp-land {
    0% { opacity: 0; scale: 1.35; }
    70% { opacity: 1; scale: 0.97; }
    100% { opacity: 1; scale: 1; }
  }

  @keyframes note-fade { from { opacity: 0; } to { opacity: 1; } }

  @keyframes ring-breathe {
    0%, 100% { opacity: 1; scale: 1; }
    50% { opacity: 0.55; scale: 1.06; }
  }

  @keyframes melt { from { opacity: 0; scale: 0.7; } to { opacity: 1; scale: 1; } }

  @keyframes breath { from { opacity: 0; scale: 0.4; } to { opacity: 0.7; scale: 1; } }
}

/* ---------- the clue: frosted over until it is wiped by hand ---------- */

.clue.is-frosted::after,
.clue.is-wiping::after,
.pinned.is-frosted::after,
.pinned.is-wiping::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  /* Frost the picture shows faintly through. */
  background-color: color-mix(in srgb, var(--ak-surface) 80%, transparent);
  background-image: radial-gradient(circle, color-mix(in srgb, var(--ak-ink-muted) 40%, transparent) 1px, transparent 1.6px);
  background-size: 5px 5px;
  pointer-events: none;
}

.clue.is-frosted::before {
  content: 'wipe';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  z-index: 3;
  translate: 0 -50%;
  margin: 0 3px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.pinned.is-frosted .pinned-caption,
.pinned.is-wiping .pinned-caption { position: relative; z-index: 3; padding: 0 4px; background: var(--ak-bg); }

/* The clue pinned in full on the glass, when the note leaves room for it. */
.pinned {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 4px;
  margin: 0 auto 12px;
  padding: 10px 12px 5px;
  border: 1px solid var(--ak-outline);
  background: var(--ak-bg);
  color: var(--ak-ink);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  rotate: -1.5deg;
}

.pinned::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 50%;
  z-index: 4;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ak-accent);
  translate: -50% 0;
}

.pinned img {
  display: block;
  height: calc(var(--pin-h, 140px) - 34px);
  width: auto;
  max-width: 72vw;
  object-fit: contain;
}

.pinned-caption {
  margin: 0;
  font-size: 15px;
  font-style: italic;
  line-height: 1.2;
}

.pen-row { display: flex; flex-wrap: wrap; gap: 0 10px; }

.note.is-hint .note-line { font-size: 17px; line-height: 1.3; }
.note.is-hint .note-rule { font-size: 14px; }
.note.is-hint .pen { margin-top: 6px; padding: 0 11px; font-size: 16px; }

.hint-count {
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-variant: small-caps;
  letter-spacing: 0.08em;
}

.note-tip.note-rule {
  margin-top: 6px;
  padding-top: 6px;
  font-style: normal;
  color: var(--ak-ink);
}

/* ---------- the chrome, fitted to this scene ---------- */

/* The lamp sheet sideways: its three switches in a row, the whole sheet on screen. */
@media (orientation: landscape) and (max-height: 620px) {
  body #activity-chrome-settings.site-shriversify .ac-panel {
    width: min(100%, 620px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 14px 20px 8px;
  }

  body #activity-chrome-settings.site-shriversify .ac-sheet-title { margin-bottom: 6px; padding-bottom: 6px; font-size: 20px; }
  body #activity-chrome-settings.site-shriversify .ac-toggles { flex-direction: row; gap: 14px; }
  body #activity-chrome-settings.site-shriversify .ac-toggle { flex: 1 1 0; }
  body #activity-chrome-settings.site-shriversify .ac-done { margin-top: 6px; }
}

/* The ending: the handwriting line carries the page, the three notes speak in their own words,
   and the record stays small at the foot. */
body #activity-chrome-ending.site-shriversify { justify-content: safe center; }

body #activity-chrome-ending.site-shriversify .ac-card {
  margin: auto 0;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

body #activity-chrome-ending.site-shriversify .ac-verdict { font-size: clamp(24px, 5vw, 32px); line-height: 1.2; }

body #activity-chrome-ending.site-shriversify .ac-lines { color: var(--ak-ink); font-style: normal; text-align: left; }

body #activity-chrome-ending.site-shriversify .ac-line {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 2px solid var(--ak-accent);
  font-family: var(--ak-font-body);
  font-size: 17px;
  line-height: 1.4;
}

body #activity-chrome-ending.site-shriversify .ac-line:last-child {
  margin: 14px 0 0;
  padding: 8px 0 0;
  border-left: 0;
  border-top: 1px dashed var(--ak-outline);
  color: var(--ak-ink-muted);
  font-size: 13px;
  font-style: italic;
  text-align: center;
}

@media (orientation: landscape) and (max-height: 620px) {
  body #activity-chrome-ending.site-shriversify { padding: 8px 72px 8px 16px; }
  body #activity-chrome-ending.site-shriversify .ac-card { width: min(100%, 700px); padding: 14px 24px 8px; }
  body #activity-chrome-ending.site-shriversify .ac-verdict { margin-bottom: 8px; padding-bottom: 8px; font-size: 24px; }
  body #activity-chrome-ending.site-shriversify .ac-line { margin-bottom: 6px; font-size: 15px; line-height: 1.3; }
  body #activity-chrome-ending.site-shriversify .ac-actions { margin-top: 8px; }
}

/* ---------- the opening: the letter on a sheet of paper in the dark ---------- */

html body #activity-start.site-shriversify { box-shadow: inset 0 0 30vmin 10vmin rgba(0, 0, 0, 0.7); }

html body #activity-start.site-shriversify .ak-scene {
  position: relative;
  width: min(calc(100% - 8px), 560px);
  min-height: 0;
  margin: 16px auto;
  padding: 28px 22px 18px;
  gap: 14px;
  border: 1px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-surface);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.55);
  rotate: -0.6deg;
}

html body #activity-start.site-shriversify .ak-scene::before {
  content: '';
  position: absolute;
  top: 9px;
  left: 50%;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
  translate: -50% 0;
}

html body #activity-start.site-shriversify .ak-scene-line { text-shadow: none; }

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .lamp { animation: candle 5200ms ease-in-out infinite alternate; }
  @keyframes candle { from { opacity: 0.86; } to { opacity: 1; } }

  :root:not(.ac-still) .clue.is-wiping::after,
  :root:not(.ac-still) .pinned.is-wiping::after { animation: wipe-frost 750ms ease-in forwards; }
  @keyframes wipe-frost { from { clip-path: inset(0 0 0 0); } to { clip-path: inset(0 0 0 100%); } }
}

:root.ac-lights-up .lamp,
:root.is-dawn .lamp { animation: none; }

/* Sideways the clue sits at the top of the right-hand column, so the lamp moves with it. */
@media (orientation: landscape) {
  .lamp {
    background:
      radial-gradient(circle at 42% 6%, color-mix(in srgb, var(--ak-accent) 28%, transparent) 0, color-mix(in srgb, var(--ak-accent) 9%, transparent) 16%, transparent 32%),
      radial-gradient(ellipse 82% 76% at 50% 50%, transparent 56%, rgba(14, 10, 8, 0.55) 100%);
  }
}

/* Sideways the opening letter lies flat: the words on the left, the wax seal to hand on the right. */
@media (orientation: landscape) and (max-height: 620px) {
  html body #activity-start.site-shriversify .ak-scene {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 28px;
    row-gap: 8px;
    align-items: center;
    width: min(calc(100% - 24px), 800px);
    margin: 12px auto;
    padding: 18px 26px 14px;
    text-align: left;
  }

  html body #activity-start.site-shriversify .ak-scene > .ak-head { grid-column: 1; }
  html body #activity-start.site-shriversify .ak-scene .ak-scene-lines { grid-column: 1; max-width: none; gap: 8px; }
  html body #activity-start.site-shriversify .ak-scene .ak-scene-line { font-size: 18px; line-height: 1.3; }
  html body #activity-start.site-shriversify .ak-scene .ak-scene-actions { grid-column: 2; grid-row: 1 / span 2; }
}
