/* The Ferryman's Notes: one scene, seen from low in the moored ferry. The slip is pinned across
   the middle, the key hangs in its lit niche above, and a caption runs along the gunwale below. */

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

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

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

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

[hidden] {
  display: none !important;
}

/* ---------- the scene ---------- */

:root {
  --side: 272px;
}

.play {
  --ink-line: var(--ak-choice-selected-ink);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "band"
    "slip"
    "caption";
  row-gap: 6px;
  padding:
    calc(var(--ac-status-h, 64px) + 4px)
    max(4px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom))
    max(4px, env(safe-area-inset-left));
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, linear-gradient(rgba(13, 10, 11, 0.78), rgba(13, 10, 11, 0.78)), url("./art/boathouse-from-the-boat.jpg"));
  background-size: cover;
  background-position: center top;
  touch-action: manipulation;
  overflow: hidden;
}

:root.ac-lights-up .play {
  background-image: linear-gradient(rgba(13, 10, 11, 0.42), rgba(13, 10, 11, 0.42)), url("./art/boathouse-from-the-boat.jpg");
}

/* The candle's wax-yellow pool climbing the planks from the bow thwart. */
.candle-pool {
  position: fixed;
  left: -18vmin;
  bottom: -16vmin;
  width: 80vmin;
  height: 80vmin;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--ak-accent) 24%, transparent) 0%, transparent 66%);
  pointer-events: none;
  z-index: 0;
  /* --lit falls as candles go out, so the scene darkens with the score. */
  opacity: var(--lit, 1);
  transition: opacity 1600ms ease;
}

.band,
.slip-area,
.caption,
.ledger {
  position: relative;
  z-index: 1;
}

/* ---------- the band: tabs, key in its niche, hint ---------- */

.band {
  grid-area: band;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "left niche hint";
  align-items: center;
  column-gap: 6px;
  min-height: 0;
}

.band-left {
  grid-area: left;
  display: flex;
  align-items: center;
  gap: 4px;
}

.logo {
  position: fixed;
  z-index: 30;
  top: max(14px, calc(env(safe-area-inset-top) + 4px));
  left: var(--logo-x, 50%);
  display: block;
  width: var(--logo-w, 72px);
  height: auto;
  max-height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
}

.logo.is-cramped {
  position: static;
  width: 44px;
  height: auto;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  gap: 5px;
}

/* How far through tonight's notes: under the tabs, always in view. */
.tabs-note {
  grid-column: 1 / -1;
  /* Sized by the tabs above it, never wider. */
  contain: inline-size;
  margin: 0;
  color: var(--ak-ink);
  font-size: 15px;
  font-style: italic;
  line-height: 1.1;
  text-shadow: 0 1px 2px var(--ak-bg);
}

/* Small paper labels pinned along the top. The lit one is the slip on the wall. */
.tab {
  position: relative;
  min-width: 48px;
  height: 48px;
  padding: 6px 8px 0;
  border: 1px solid var(--ak-choice-border);
  border-radius: var(--ak-radius);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-family: var(--ak-font-display);
  font-size: 20px;
  line-height: 1;
  rotate: -1.5deg;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* How far along each slip is: marks pencilled out of all, or "read". */
.tab-count {
  font-family: var(--ak-font-body);
  font-size: 13px;
  font-style: italic;
  line-height: 1;
}

.tab:nth-child(2) {
  rotate: 1deg;
}

.tab:nth-child(3) {
  rotate: -0.5deg;
}

.tab::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ak-ink-muted);
  translate: -50% 0;
}

.tab.is-active {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
  translate: 0 3px;
}

.tab.is-active::before {
  background: var(--ak-accent);
}

.tab-tick {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
}

.niche {
  grid-area: niche;
  position: relative;
  justify-self: center;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 170px;
  height: 80px;
}

.niche::before {
  content: "";
  position: absolute;
  inset: -10px -18px;
  border-radius: 50% 50% 8px 8px / 60% 60% 8px 8px;
  background: radial-gradient(ellipse at 50% 55%, color-mix(in srgb, var(--ak-accent) 30%, transparent) 0%, transparent 70%);
  pointer-events: none;
}

.key {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
}

.key {
  display: flex;
  align-items: center;
  gap: 4px;
}

.key-art {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  min-width: 52px;
}

.key-art > img,
.key-art > svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.65));
}

/* The rule on a paper tag hung from the key's nail: it stays for as long as the slip is on the wall. */
.key-tag {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 46px;
  padding: 8px 5px 5px;
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  font-family: var(--ak-font-body);
  font-size: 18px;
  font-style: italic;
  line-height: 1;
  rotate: 4deg;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.55);
}

.key-tag::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ak-choice-selected-ink);
  translate: -50% 0;
}

.key-tag b {
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-style: normal;
  font-weight: 400;
}

:root.ac-lights-up .key img,
:root.ac-lights-up .key svg {
  filter: brightness(1.18) contrast(1.1) drop-shadow(0 6px 8px rgba(0, 0, 0, 0.65));
}

/* The hint ladder's pointer rung rings the key. It stays until the next move. */
.niche.is-pointed::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 3px solid var(--ak-accent);
  border-radius: 50%;
  pointer-events: none;
}

.hint {
  grid-area: hint;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  min-height: 48px;
  padding: 4px 6px;
  border: 1px dashed var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  rotate: 1.5deg;
}

.hint-word {
  font-family: var(--ak-font-display);
  font-size: 20px;
  line-height: 1.1;
}

.hint-step {
  font-size: 14px;
  font-style: italic;
  color: var(--ak-ink-muted);
}

.hint:disabled {
  cursor: default;
  opacity: 0.7;
}

/* ---------- the slip ---------- */

.slip-area {
  grid-area: slip;
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
}

.slip-area.is-pinned-left {
  place-items: start;
}

.slip {
  --cw: 44px;
  --ch: 44px;
  --gap: 9px;
  --slash: 13px;
  --row-gap: 3px;
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  padding: 18px 8px 14px;
  background: url("./art/foxed-slip.png") center / 100% 100% no-repeat;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6));
  touch-action: manipulation;
}

.row {
  display: flex;
  gap: var(--gap);
  height: var(--ch);
}

.word {
  position: relative;
  display: flex;
}

/* Each word sits on its own pencil baseline, so the breaks between words read at a glance. */
.word::before {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 0;
  height: 2px;
  background: var(--ink-line);
  opacity: 0.55;
  pointer-events: none;
}

.word.cont::after {
  content: "";
  position: absolute;
  top: 50%;
  right: calc(var(--gap) * -0.8);
  width: calc(var(--gap) * 0.6);
  height: 2px;
  background: var(--ink-line);
}

.slash {
  display: block;
  width: var(--slash);
  height: 100%;
  color: var(--ink-line);
}

.slash svg {
  width: 100%;
  height: 100%;
}

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--cw);
  height: var(--ch);
  margin: 0;
  /* The whole cell is the tap target; the inked letter sits inside it, with paper around it,
     so the slip reads as letters written on a page rather than a grid of boxes. */
  padding: 2px 3px;
  border: 0;
  border-radius: 0;
  background: none;
}

/* The pencilled guess, in soft graphite on the paper strip above the glyph. */
.cell .g {
  flex: 0 0 44%;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-line);
  border-bottom: 0;
  background: var(--ak-choice-selected-bg);
  color: color-mix(in srgb, var(--ak-choice-selected-ink) 80%, var(--ak-choice-selected-bg));
  font-family: var(--ak-font-body);
  font-style: italic;
  font-weight: 400;
  font-size: calc(var(--ch) * 0.37);
  line-height: 1;
  transition: font-weight 600ms ease, color 600ms ease;
  transition-delay: var(--d, 0ms);
}

/* The cipher letter or pigpen shape, in a large ink cell. */
.cell .c {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-line);
  border-top: 0;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-family: var(--ak-font-display);
  font-size: calc(var(--cw) * 0.48);
  line-height: 1;
}

.cell .pp {
  width: 80%;
  height: 80%;
  max-height: calc(var(--ch) * 0.54);
}

.cell.is-match .c {
  background: var(--ak-choice-border);
  box-shadow: inset 0 -4px 0 var(--ak-accent);
}

.cell.is-selected {
  z-index: 2;
  box-shadow: 0 0 0 2px var(--ak-choice-selected-ink), 0 0 0 5px var(--ak-accent);
}

/* Solved: the pencil darkens to ink, left to right. */
.cell.is-inked .g {
  font-style: normal;
  font-weight: 600;
  color: var(--ak-choice-selected-ink);
}

.slip.is-solved .cell {
  cursor: default;
}

:root.ac-lights-up .cell .c {
  background: var(--ak-bg);
  color: var(--ak-ink);
}

:root.ac-lights-up .cell .g {
  color: var(--ak-choice-selected-ink);
  font-weight: 600;
}

/* ---------- the caption along the gunwale ---------- */

.caption {
  grid-area: caption;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 62px;
  padding: 5px 4px 5px 14px;
  border-top: 1px solid var(--ak-outline);
  background: var(--ak-bg);
}

.caption-inner {
  display: flow-root;
}

.caption-line {
  margin: 0;
  color: var(--ak-ink);
  font-size: 19px;
  font-style: italic;
  line-height: 1.24;
}

/* The bow-post's marsh bird, cut from the scene itself. It tilts its head when a letter settles. */
.heron {
  float: right;
  margin: 0 0 0 8px;
  shape-outside: inset(0 0 0 0);
  width: 60px;
  height: 58px;
  background-image: url("./art/boathouse-from-the-boat.jpg");
  background-size: 323px 430px;
  background-position: -255px -113px;
  -webkit-mask-image: radial-gradient(ellipse 62% 64% at 58% 46%, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse 62% 64% at 58% 46%, #000 62%, transparent 100%);
  transform-origin: 70% 100%;
  filter: brightness(1.35);
}

.heron.is-low {
  transform: translateY(5px) rotate(-9deg);
}

/* ---------- the tray of plain letters ---------- */

.tray {
  position: fixed;
  left: max(6px, env(safe-area-inset-left));
  right: max(6px, env(safe-area-inset-right));
  z-index: 31;
  padding: 8px;
  border: 1px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
}

.tray[data-at="top"] {
  top: calc(var(--ac-status-h, 64px) + 4px);
}

.tray[data-at="bottom"] {
  bottom: max(6px, env(safe-area-inset-bottom));
}

.tray-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  margin-bottom: 6px;
}

.tray-mark {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--ak-outline);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-family: var(--ak-font-display);
  font-size: 22px;
}

.tray-mark .pp {
  width: 70%;
  height: 70%;
}

.tray-say {
  flex: 1 1 auto;
  margin: 0;
  font-size: 18px;
  font-style: italic;
  line-height: 1.2;
}

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

.tkey {
  min-width: 44px;
  min-height: 48px;
  padding: 0;
  border: 1px solid var(--ak-choice-border);
  border-radius: var(--ak-radius);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-family: var(--ak-font-display);
  font-size: 24px;
}

.tkey.is-used {
  color: var(--ak-ink-muted);
  border-style: dashed;
}

/* Each tray key: its letter, and on the pigpen slip the pen it is written as. */
.tkey {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.tk-letter {
  line-height: 1;
}

.tk-shape {
  display: none;
}

.tray.is-pigpen .tkey[data-letter] {
  font-size: 18px;
}

.tray.is-pigpen .tk-shape {
  display: block;
  width: 22px;
  height: 22px;
}

.tray.is-pigpen .tk-pp {
  width: 100%;
  height: 100%;
}

/* The pigpen tray is laid out as the oar's four grids: a grid, a dotted grid, an X, a dotted X. */
.tray.is-pigpen .tray-keys {
  grid-template-columns: repeat(3, minmax(0, 1fr)) 12px repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, 48px) 8px repeat(3, 48px) auto;
}

.tray.is-pigpen .tkey[data-letter] {
  grid-column: var(--pc-p);
  grid-row: var(--pr-p);
}

.tray.is-pigpen .tkey-erase {
  grid-column: 1 / span 3;
  grid-row: 8;
}

.tray.is-pigpen .tkey-fill {
  grid-column: 5 / span 3;
  grid-row: 8;
}

/* The first night counts for you: the keys going back from the ringed letter carry their step. */
.tkey[data-step] {
  position: relative;
}

.tkey.is-his {
  padding-right: 12px;
}

.tkey.is-his[data-step]::after {
  font-family: var(--ak-font-display);
  font-size: 16px;
}

.tkey[data-step]::after {
  content: attr(data-step);
  position: absolute;
  top: 2px;
  right: 4px;
  font-family: var(--ak-font-body);
  font-size: 15px;
  font-style: normal;
  color: var(--ak-accent);
}

/* The clock slip: the cipher letter itself, ringed in the tray as the place to start counting back. */
.tkey.is-from {
  outline: 3px dashed var(--ak-accent);
  outline-offset: -4px;
}

.tkey.is-current {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
}

.tkey-erase {
  grid-column: span 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--ak-font-body);
  font-size: 17px;
  font-style: italic;
}

.tkey-erase svg {
  width: 22px;
  height: 22px;
}

.tkey-erase:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Close, in the tray's header row. */
.tkey-done {
  flex: 0 0 auto;
  min-width: 72px;
  font-family: var(--ak-font-body);
  font-size: 17px;
  font-style: italic;
  background: transparent;
  border-style: dashed;
}

/* Fill the rest by the key: a paper label, waiting until three marks are pencilled by hand. */
.tkey-fill {
  grid-column: 1 / -1;
  padding: 2px 8px;
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
  font-family: var(--ak-font-body);
  font-size: 18px;
  font-style: italic;
  line-height: 1.1;
}

.tkey-fill:disabled {
  background: transparent;
  color: var(--ak-ink-muted);
  border-color: var(--ak-choice-border);
  border-style: dashed;
  cursor: default;
}

/* ---------- the key, looked at closely ---------- */

.zoom {
  position: fixed;
  left: max(6px, env(safe-area-inset-left));
  right: max(6px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 31;
  max-height: calc(100dvh - var(--ac-status-h, 64px) - 12px);
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
}

/* The narrator's line across the top; the picture and the rule side by side; Back below. */
.zoom-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  grid-template-areas:
    "say close"
    "art how";
  gap: 8px 12px;
  align-items: start;
}

.zoom[data-kind="pigpen"] .zoom-card {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "say close"
    "how how"
    "art art";
}

.zoom-say {
  grid-area: say;
  align-self: center;
}

.zoom-art {
  grid-area: art;
  position: relative;
  width: 92px;
  height: 92px;
  background: radial-gradient(circle, color-mix(in srgb, var(--ak-accent) 22%, transparent), transparent 70%);
}

.zoom-art > img,
.zoom-art > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* The oar's four grids, copied out large enough to read every pen. */
.zoom[data-kind="pigpen"] .zoom-art {
  justify-self: center;
  width: min(100%, 250px);
  height: auto;
  aspect-ratio: 1;
  padding: 6px;
  background: var(--ak-choice-selected-bg);
}

.zoom-how {
  grid-area: how;
}

.zoom-close {
  grid-area: close;
  justify-self: end;
  align-self: start;
}

/* The key spelled out beside the picture: the rule, and one worked example. */
.zoom-how {
  width: 100%;
  color: var(--ak-ink);
  font-size: 18px;
  line-height: 1.28;
}

.zoom-how p {
  margin: 0 0 8px;
}

.zoom-how p:last-child {
  margin-bottom: 0;
}

.count-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin: 0 0 8px;
}

.count-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 26px;
  padding: 3px 2px 2px;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border: 1px solid var(--ak-choice-border);
}

.count-tile b {
  font-family: var(--ak-font-display);
  font-size: 20px;
  font-weight: 400;
  line-height: 1.1;
}

.count-tile i {
  font-size: 12px;
  line-height: 1.1;
}

.count-tile.is-mark {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
}

.zoom-say {
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--ak-outline);
  color: var(--ak-ink-muted);
  font-size: 18px;
  font-style: italic;
  line-height: 1.25;
}

/* His alphabet under the plain one: a cipher table in two halves of thirteen. */
.cipher-table {
  display: grid;
  gap: 4px;
  margin: 0 0 8px;
}

.ct-half {
  border: 1px solid var(--ak-choice-border);
}

.ct-row {
  display: grid;
  grid-template-columns: 34px repeat(13, minmax(0, 1fr));
  align-items: center;
  text-align: center;
}

.ct-row b {
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.3;
}

.ct-name {
  font-size: 12px;
  font-style: italic;
  color: var(--ak-ink-muted);
}

.ct-his {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
}

.ct-his .ct-name {
  color: var(--ak-choice-selected-ink);
}

.zoom-close {
  min-height: 48px;
  min-width: 64px;
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  font-style: italic;
}

/* The carved oar, with its four grids copied out large beside it. */
.oar-zoom {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  gap: 6px;
}

.oar-pic {
  position: relative;
  flex: 0 0 30%;
  min-height: 0;
}

.oar-pic img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.oar-chart {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  background: var(--ak-choice-selected-bg);
}

.oar-chart .chart {
  width: 100%;
  height: 100%;
}

.chart-wide {
  display: none;
}

.chart-line {
  fill: none;
  stroke: var(--ak-choice-selected-ink);
  stroke-width: 2.4;
}

.chart-letter {
  fill: var(--ak-choice-selected-ink);
  font-family: var(--ak-font-display);
  font-size: 17px;
}

.chart-dot {
  fill: var(--ak-choice-selected-ink);
}

/* Drawn keys for later nights: a tide clock and a hook plank in the kit's own colours. */
.drawn-key {
  overflow: visible;
}

.clock-rim {
  fill: var(--ak-surface);
  stroke: var(--ak-accent);
  stroke-width: 3;
}

.clock-face {
  fill: var(--ak-choice-selected-bg);
}

.clock-num {
  fill: var(--ak-choice-selected-ink);
  font-family: var(--ak-font-display);
  font-size: 13px;
}

.clock-hand {
  stroke: var(--ak-choice-selected-ink);
  stroke-width: 3.2;
  stroke-linecap: round;
}

.clock-hub {
  fill: var(--ak-accent);
  stroke: var(--ak-choice-selected-ink);
  stroke-width: 1.5;
}

.hook-plank {
  fill: var(--ak-surface);
  stroke: var(--ak-outline);
  stroke-width: 2;
}

.hook-letter {
  fill: var(--ak-accent);
  font-family: var(--ak-font-display);
  font-size: 22px;
}

.hook-letter.is-faded {
  opacity: 0.16;
}

.hook-iron {
  fill: none;
  stroke: var(--ak-ink-muted);
  stroke-width: 5;
  stroke-linecap: round;
}

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

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

.guide-ring {
  position: fixed;
  border: 3px solid var(--ak-accent);
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--ak-bg);
}

.guide-arrow {
  position: fixed;
  width: 40px;
  height: 56px;
  color: var(--ak-accent);
  filter: drop-shadow(0 0 2px var(--ak-bg)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.9));
}

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

/* ---------- the boat ledger ---------- */

.ledger {
  grid-row: 1 / 3;
  grid-column: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 4px;
}

/* The ending: the ledger page takes the whole scene above the caption, upright or sideways. */
.play.is-ledger {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "ledger"
    "caption";
  padding-top: max(12px, env(safe-area-inset-top));
}

.play.is-ledger .band,
.play.is-ledger .slip-area {
  display: none;
}

.play.is-ledger .ledger {
  grid-area: ledger;
}

.play.is-ledger .caption .caption-line {
  font-size: 20px;
}

/* The entry he would have written himself, and the pencilled line beside it. */
.ledger-entry {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid currentColor;
}

.ledger-who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: 22px;
}

.ledger-dots {
  flex: 1 1 auto;
  border-bottom: 2px dotted currentColor;
  translate: 0 -5px;
}

.ledger-boat {
  margin: 6px 0 0;
  text-align: right;
  font-size: 20px;
  font-style: italic;
  rotate: -1.5deg;
}

.ledger-page {
  width: min(100%, 720px);
  max-height: 100%;
  overflow-y: auto;
  padding: 16px 18px 12px;
  border-left: 6px double var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.65);
}

.ledger-head {
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid currentColor;
  font-family: var(--ak-font-display);
  font-size: 22px;
}

.ledger-slips {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ledger-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.ledger-thumb {
  display: block;
  width: 52px;
  height: auto;
  rotate: -3deg;
}

.ledger-row:nth-child(2) .ledger-thumb {
  rotate: 2deg;
}

.ledger-text {
  min-width: 0;
}

.ledger-num {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: 15px;
}

.ledger-line {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

/* ---------- sideways: the scene on the left, the slip on the right ---------- */

@media (orientation: landscape) {
  .play {
    grid-template-columns: var(--side) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "band slip"
      "caption slip";
    column-gap: 10px;
    row-gap: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left), calc((100vw - 1180px) / 2));
    padding-right: max(8px, env(safe-area-inset-right), calc((100vw - 1180px) / 2));
  }

  .band {
    margin-top: calc(var(--ac-status-h, 64px) - 2px);
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "tabs hint"
      "niche logo";
    row-gap: 6px;
  }

  .band-left {
    display: contents;
  }

  .logo,
  .logo.is-cramped {
    position: static;
    grid-area: logo;
    align-self: center;
    width: 74px;
    height: auto;
    max-height: none;
  }

  .tabs {
    grid-area: tabs;
  }

  .niche {
    justify-self: start;
    width: 168px;
    max-width: none;
    height: 80px;
    margin-left: 4px;
  }

  .caption {
    justify-content: flex-end;
    min-height: 0;
    overflow-y: auto;
    border-top: 0;
    border-bottom: 1px solid var(--ak-outline);
  }

  .caption .caption-line {
    font-size: 19px;
    line-height: 1.22;
  }

  /* Sideways the tray takes the scene's own column on the left, so the whole note on the right stays
     in view while letters are chosen: five keys across, six rows, the instruction in two short lines. */
  /* The key panel takes the same column as the tray, so the slip on the right stays whole. */
  .zoom {
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left), calc((100vw - 1180px) / 2));
    right: auto;
    width: var(--side);
    max-height: none;
  }

  .zoom-card {
    grid-template-columns: 64px minmax(0, 1fr) auto;
    grid-template-areas:
      "say say close"
      "art how how";
  }

  .zoom-art {
    width: 64px;
    height: 64px;
  }

  .zoom[data-kind="pigpen"] .zoom-art {
    width: min(100%, 186px);
  }

  .ct-row {
    grid-template-columns: 26px repeat(13, minmax(0, 1fr));
  }

  .ct-row b {
    font-size: 16px;
  }

  .tray[data-at="side"] {
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left), calc((100vw - 1180px) / 2));
    right: auto;
    width: var(--side);
    display: flex;
    flex-direction: column;
  }

  .tray[data-at="side"] .tray-head {
    min-height: 0;
    margin-bottom: 4px;
  }

  .tray[data-at="side"] .tray-say {
    font-size: 19px;
    line-height: 1.15;
  }

  .tray[data-at="side"] .tray-keys,
  .tray[data-at="side"].is-pigpen .tray-keys {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: 48px;
    flex: 1 1 auto;
    align-content: start;
  }

  /* The pigpen keys keep their pens, in alphabet order here rather than the oar's four grids. */
  .tray[data-at="side"].is-pigpen .tkey[data-letter],
  .tray[data-at="side"].is-pigpen .tkey-erase,
  .tray[data-at="side"].is-pigpen .tkey-fill {
    grid-column: auto;
    grid-row: auto;
  }

  .tray[data-at="side"] .tkey-erase,
  .tray[data-at="side"] .tkey-fill,
  .tray[data-at="side"].is-pigpen .tkey-erase,
  .tray[data-at="side"].is-pigpen .tkey-fill {
    grid-column: span 2;
  }

  .tray[data-at="side"] .tkey-fill {
    font-size: 15px;
  }

  .tray[data-at="side"] .tkey-done {
    min-width: 58px;
    padding: 0 4px;
    font-size: 16px;
  }

  .tray[data-at="side"] .tray-head {
    gap: 8px;
  }

  /* Sideways the cells are as large as the height allows, so each tile gives its paper margin back
     to the letters: a larger pencil strip and larger letters. */
  .cell {
    padding: 1px 1px;
  }

  .cell .g {
    flex-basis: 47%;
    font-size: calc(var(--ch) * 0.43);
  }

  .cell .c {
    font-size: calc(var(--cw) * 0.52);
  }

  .ledger {
    grid-row: 1 / 3;
    grid-column: 2;
  }

  .chart-square {
    display: none;
  }

  .chart-wide {
    display: block;
  }

  /* Sideways the three slips sit side by side on the page. */
  .ledger-slips {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .ledger-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .ledger-thumb {
    width: 34px;
  }

  .ledger-line {
    font-size: 16px;
  }
}

/* A narrow phone upright: the niche is too slim for the picture and its tag side by side, so the tag
   hangs over the picture's lower corner, clear of the clock's hand, the painted word and the carving. */
@media (orientation: portrait) and (max-width: 380px) {
  .key-tag {
    position: absolute;
    right: -8px;
    bottom: -10px;
    z-index: 1;
  }
}

/* A short phone held upright: the key's niche gives the slip a little more room. */
@media (orientation: portrait) and (max-height: 800px) {
  .niche {
    height: 60px;
  }

  .caption-line {
    font-size: 18px;
  }
}

/* Upright on a wide screen: the same layout, centred. */
@media (orientation: portrait) and (min-width: 620px) {
  .play {
    padding-left: calc((100vw - 600px) / 2);
    padding-right: calc((100vw - 600px) / 2);
  }

  .tray {
    left: calc((100vw - 600px) / 2);
    right: calc((100vw - 600px) / 2);
  }
}

/* ---------- motion, only when it is welcome ---------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .candle-pool {
    animation: candle 3.6s ease-in-out infinite alternate;
  }

  :root:not(.ac-still) .candle-pool.is-steady {
    animation: none;
    opacity: var(--lit, 1);
  }

  :root:not(.ac-still) .cell .g.is-fresh {
    animation: pencil 620ms ease-out;
  }

  :root:not(.ac-still) .heron {
    transition: transform 900ms ease;
  }

  :root:not(.ac-still) .heron.is-nod {
    animation: nod 1100ms ease-in-out;
  }

  :root:not(.ac-still) .slip.is-settling {
    animation: settle 1200ms ease-out;
  }

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

  /* The key sways on its nail when the player needs to look at it: a hint, a wrong reading, the first move. */
  :root:not(.ac-still) .niche.is-pointed .key-art > img,
  :root:not(.ac-still) .niche.is-pointed .key-art > svg {
    transform-origin: 50% 4%;
    animation: sway 2800ms ease-in-out infinite;
  }

  :root:not(.ac-still) .niche.is-pointed .clock-hand {
    transform-box: view-box;
    transform-origin: 50px 50px;
    animation: hand 2800ms ease-in-out infinite;
  }

  :root:not(.ac-still) .niche.is-pointed::after {
    animation: ring 1800ms ease-in-out infinite;
  }

  :root:not(.ac-still) .tray {
    animation: fade 260ms ease-out;
  }

  :root:not(.ac-still) .zoom {
    animation: fade 420ms ease-out;
  }

  :root:not(.ac-still) .ledger-page {
    transform-origin: left center;
    animation: page-turn 1100ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  :root:not(.ac-still) .ledger-who {
    animation: fade 700ms ease-out both;
    animation-delay: 1700ms;
  }

  :root:not(.ac-still) .ledger-boat {
    animation: fade 1200ms ease-out both;
    animation-delay: 2400ms;
  }

  :root:not(.ac-still) .ledger-row {
    animation: pin 900ms ease-out both;
    animation-delay: calc(300ms + var(--n, 0) * 450ms);
  }
}

@keyframes candle {
  0% { opacity: calc(var(--lit, 1) * 0.78); }
  45% { opacity: calc(var(--lit, 1) * 0.92); }
  100% { opacity: var(--lit, 1); }
}

@keyframes pencil {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

@keyframes nod {
  0% { transform: none; }
  40% { transform: rotate(5deg); }
  100% { transform: none; }
}

@keyframes settle {
  0% { transform: translateY(-3px) scale(1.012); }
  100% { transform: none; }
}

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

/* A page turning over, flat to the screen: it narrows to its spine and opens out again. */
@keyframes page-turn {
  0% { transform: scaleX(0.04); opacity: 0.3; }
  55% { opacity: 1; }
  100% { transform: none; opacity: 1; }
}

@keyframes sway {
  0%, 100% { rotate: -2.5deg; }
  50% { rotate: 2.5deg; }
}

@keyframes hand {
  0%, 80%, 100% { rotate: 0deg; }
  86% { rotate: 6deg; }
  92% { rotate: -2deg; }
}

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

@keyframes pin {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- the opening: the ferryman's letter ----------
   start.js draws the opening and the instructions; this dresses both as one foxed letter in
   candlelight, sealed in the same red wax as his thumbprint. The doubled ids outrank start.js's own
   rules without touching its file. */

html body #activity-start.site-shriversify {
  --letter-paper:
    linear-gradient(color-mix(in srgb, var(--ak-choice-selected-bg) 78%, transparent), color-mix(in srgb, var(--ak-choice-selected-bg) 78%, transparent)),
    url("./art/foxed-slip.png");
  --letter-glow: 0 0 70px color-mix(in srgb, var(--ak-accent) 30%, transparent), 0 26px 50px rgba(0, 0, 0, 0.65);
}

html body #activity-start.site-shriversify .ak-scene {
  gap: var(--ak-space-5);
}

/* The opening lines, written on the letter and lit by the candle. */
html body #activity-start.site-shriversify .ak-scene-lines {
  position: relative;
  max-width: min(36ch, 92vw);
  padding: 30px 26px 52px;
  background: var(--letter-paper);
  background-size: auto, 100% 100%;
  box-shadow: var(--letter-glow);
  rotate: -1deg;
}

html body #activity-start.site-shriversify .ak-scene-line {
  color: var(--ak-choice-selected-ink);
  font-family: var(--ak-font-body);
  font-size: clamp(20px, 5vw, 26px);
  font-style: italic;
  font-weight: 500;
  line-height: 1.32;
  text-shadow: none;
}

/* The round wax seal, pressed into the foot of the letter. */
html body #activity-start.site-shriversify .ak-scene-lines::after,
html body #activity-start.site-shriversify .ak-sheet::after {
  content: "";
  position: absolute;
  right: 18px;
  bottom: -18px;
  width: 58px;
  height: 58px;
  border-radius: 48% 52% 50% 50% / 52% 47% 53% 48%;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 46%, color-mix(in srgb, var(--ak-accent-2) 60%, black) 47% 52%, transparent 53%),
    radial-gradient(circle at 36% 32%, color-mix(in srgb, var(--ak-accent-2) 70%, white) 0, var(--ak-accent-2) 42%, color-mix(in srgb, var(--ak-accent-2) 55%, black) 100%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.55);
  rotate: 12deg;
}

/* The instructions are the same letter, read in full. */
html body #activity-start.site-shriversify .ak-sheet {
  border: 0;
  background: var(--letter-paper);
  background-size: auto, 100% 100%;
  color: var(--ak-choice-selected-ink);
  box-shadow: var(--letter-glow);
}

html body #activity-start.site-shriversify .ak-sheet::after {
  bottom: auto;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
}

html body #activity-start.site-shriversify .ak-sheet :is(.ak-tagline, .ak-badge, .ak-label, .ak-body, .ak-first, .ak-first-label, li, p, h2) {
  color: var(--ak-choice-selected-ink);
}

html body #activity-start.site-shriversify .ak-sheet :is(.ak-tagline, .ak-badge) {
  color: color-mix(in srgb, var(--ak-choice-selected-ink) 72%, var(--ak-choice-selected-bg));
}

html body #activity-start.site-shriversify .ak-sheet .ak-head,
html body #activity-start.site-shriversify .ak-sheet .ak-first {
  border-color: color-mix(in srgb, var(--ak-choice-selected-ink) 45%, transparent);
}

/* The button that opens it is a wax seal too: dark red wax, bone letters. */
html body #activity-start.site-shriversify .ak-go {
  border-color: color-mix(in srgb, var(--ak-accent-2) 60%, black);
  background:
    radial-gradient(circle at 36% 30%, color-mix(in srgb, var(--ak-accent-2) 72%, white) 0, var(--ak-accent-2) 45%, color-mix(in srgb, var(--ak-accent-2) 55%, black) 100%);
  color: var(--ak-ink);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
}

/* A phone on its side: the letter runs wider and its lines smaller, so it reads without a long scroll. */
@media (orientation: landscape) and (max-height: 520px) {
  html body #activity-start.site-shriversify .ak-scene-lines {
    max-width: min(62ch, 88vw);
    padding: 20px 30px 34px;
    gap: 6px;
  }

  html body #activity-start.site-shriversify .ak-scene-line {
    font-size: 19px;
  }
}

/* The square chart is the one the key panel shows, upright or sideways. */
.zoom-art .chart-square {
  display: block;
  width: 100%;
  height: 100%;
}
