:root {
  --paper: #e9e3d6; --paper-2: #dcd5c4; --ink: #2f2d29; --ink-soft: #5d5850; --thread: #a8483a;
  --bubble: #f6f2e8; --shadow: 0 1px 0 rgba(47, 45, 41, .12), 0 6px 18px rgba(47, 45, 41, .14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); overflow: hidden; }
body { font: 17px/1.45 Georgia, "Iowan Old Style", "Palatino Linotype", serif; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--thread); outline-offset: 3px; }

#through { position: fixed; inset: 0; }
.bar { position: absolute; z-index: 5; top: 0; left: 0; right: 0; display: flex; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); pointer-events: none; }
.quiet { pointer-events: auto; background: none; border: 0; padding: 6px 2px; color: var(--ink-soft); text-decoration: none;
  font-size: 15px; letter-spacing: .02em; }
.quiet:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
#through[data-scene="cave"] .quiet, #through[data-scene="shed"] .quiet { color: #c9bfae; }

.stage { position: absolute; inset: 0; }
#world { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
/* The sheet: paper grain and a soft vignette over every scene. */
.sheet { position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at 50% 46%, transparent 55%, rgba(38, 32, 26, .28) 100%), var(--grain);
  background-size: 100% 100%, 160px 160px; mix-blend-mode: multiply; opacity: .22;
  box-shadow: inset 0 0 calc(var(--breath, 0) * 180px) rgba(38, 32, 26, calc(var(--breath, 0) * .9)); } /* a breath: the world narrows to what is near */
#through[data-scene="cave"]:not([data-mode="profile"]) .sheet, #through[data-scene="cave"] .sheet, #through[data-scene="shed"] .sheet { opacity: .45;
  background: radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(10, 8, 6, .5) 100%), var(--grain); background-size: 100% 100%, 160px 160px; }
.veil { position: absolute; inset: 0; pointer-events: none; background: #f7f2e6; opacity: 0; }
.veil[data-tone="dark"] { background: #0e0c0a; }

/* One utterance, held near whoever said it. */
.say { position: absolute; z-index: 4; left: 0; top: 0; max-width: min(300px, 72vw); padding: 9px 13px 10px;
  background: var(--bubble); border: 1.5px solid var(--ink); border-radius: 14px 14px 14px 4px; box-shadow: var(--shadow);
  font-size: 16px; line-height: 1.35; pointer-events: none; transition: opacity .25s; }
.say p { margin: 0; }
.say::after { content: ""; position: absolute; left: var(--tail, 20px); bottom: -8px; width: 12px; height: 12px; background: var(--bubble);
  border-right: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); transform: translateX(-6px) rotate(45deg); }
.say.below::after { bottom: auto; top: -8px; transform: translateX(-6px) rotate(-135deg); }
.say.side::after, .say.caption::after { display: none; }
.say.thought { font-style: italic; border-style: dashed; border-radius: 16px; background: rgba(246, 242, 232, .94); }
.say.thought::after { width: 7px; height: 7px; border-radius: 50%; border: 1.5px dashed var(--ink); bottom: -13px; transform: translateX(-4px); }
.say.below.thought::after { top: -13px; bottom: auto; }
.say.fresh { animation: say-in .22s ease-out; }
@keyframes say-in { from { opacity: 0; translate: 0 4px; } }

.prompt { position: absolute; z-index: 3; left: 0; top: 0; padding: 3px 10px 4px; border-radius: 999px; background: rgba(47, 45, 41, .78);
  color: #f3eee3; font-size: 14px; white-space: nowrap; pointer-events: none; letter-spacing: .01em; }

.title-card { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; transition: opacity 2.4s ease; }
.title-card p { margin: 0 0 18vh; font-size: clamp(34px, 7vw, 64px); letter-spacing: .12em; color: #d9cdb7; font-style: italic; }
.title-card.gone { opacity: 0; }
.title-card[hidden] { display: none; }

.ending { position: absolute; z-index: 6; left: 50%; top: 50%; translate: -50% -50%; width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 80px); overflow: auto; padding: 26px 28px 22px; background: rgba(246, 242, 232, .96);
  border: 1.5px solid var(--ink); border-radius: 6px; box-shadow: var(--shadow); }
.ending h2 { margin: 0 0 10px; font-weight: normal; font-style: italic; font-size: 26px; }
.ending p { margin: 0 0 12px; }
.ending ul { margin: 0 0 18px; padding: 0; list-style: none; color: var(--ink-soft); }
.ending li { margin: 0 0 6px; padding-left: 16px; position: relative; }
.ending li::before { content: "·"; position: absolute; left: 3px; color: var(--thread); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .button { text-decoration: none; background: none; border: 1.5px solid var(--ink); border-radius: 999px; padding: 6px 16px; }
.row button, dialog button { background: none; border: 1.5px solid var(--ink); border-radius: 999px; padding: 6px 16px; }
.row button:hover, dialog button:hover { background: var(--ink); color: var(--paper); }

dialog { width: min(520px, calc(100vw - 32px)); border: 1.5px solid var(--ink); border-radius: 6px; background: var(--bubble); color: var(--ink);
  padding: 22px 26px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(233, 227, 214, .6); }
dialog h2 { margin: 0 0 10px; font-weight: normal; font-style: italic; }
dialog p { margin: 0 0 12px; }
.small { font-size: 14px; color: var(--ink-soft); }

.no-webgl { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--paper); }
.no-webgl[hidden] { display: none; }

/* Touch: held arrows on the left, two verbs on the right. */
.pads { display: none; position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; justify-content: space-between; align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); pointer-events: none; }
.pads button { pointer-events: auto; width: 54px; height: 54px; border-radius: 50%; border: 1.5px solid rgba(47, 45, 41, .55);
  background: rgba(246, 242, 232, .72); color: var(--ink); font-size: 18px; touch-action: none; user-select: none; -webkit-user-select: none; }
.pads button.held { background: rgba(47, 45, 41, .72); color: var(--paper); }
.dpad { display: grid; grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(2, 54px); gap: 6px; }
.dpad [data-hold="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-hold="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-hold="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-hold="right"] { grid-column: 3; grid-row: 2; }
.acts { display: grid; grid-template-columns: repeat(2, 66px); gap: 10px; }
.acts button { width: 66px; height: 66px; font-size: 15px; font-style: italic; }
@media (pointer: coarse) { .pads { display: flex; } }
#through.touch .pads { display: flex; }

select, input { font: inherit; }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
.switch-controls { position: absolute; z-index: 5; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%;
  translate: -50% 0; width: min(680px, calc(100% - 24px)); padding: 10px; background: var(--bubble);
  border: 1px solid var(--ink); border-radius: 6px; }
.switch-controls[hidden] { display: none; }
.switch-controls p { margin: 0 0 8px; font-size: 14px; }
.switch-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.switch-actions button { min-height: 44px; padding: 6px 12px; border: 1px solid var(--ink); border-radius: 6px; background: var(--paper); }
.switch-actions [aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.scan-current { outline: 3px solid var(--thread); outline-offset: 3px; }
#through.switching .pads { display: none; }
#through.switching .stage { bottom: var(--switch-height, 180px); }
@media (max-width: 360px) {
  .pads { padding-left: 8px; padding-right: 8px; }
  .dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); gap: 4px; }
  .dpad button { width: 44px; height: 44px; }
  .acts { grid-template-columns: repeat(2, 60px); gap: 6px; }
  .acts button { width: 60px; height: 60px; }
}

#journal { width: min(760px, calc(100vw - 32px)); }
#folio[hidden] { display: none; }
#folio { border-bottom: 1px solid var(--ink-soft); padding-bottom: 18px; margin-bottom: 24px; }
#folio h4 { margin: 18px 0 8px; }
.folio-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
#folio button { min-height: 44px; white-space: normal; text-align: left; }
.journal-layout { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(0, 2fr); gap: 24px; }
#journal-list { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
#journal button { min-height: 44px; white-space: normal; }
#journal-list button { text-align: left; }
#journal-list [aria-current="true"] { text-decoration: underline; text-underline-offset: 4px; }
#journal-entry { min-width: 0; line-height: 1.6; }
#journal-entry h3 { margin-top: 0; }
#journal-entry h4 { margin: 20px 0 4px; font-size: 1em; }
#journal-entry p { margin-top: 4px; }
@media (max-width: 560px) {
  .journal-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  #journal-list { flex-direction: row; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .say.fresh { animation: none; }
  .title-card { transition: none; }
}

/* The memory games (colour-ui.js, song-ui.js): /clarity's page, over the game, in colour. */
dialog.memory { width: min(620px, calc(100vw - 20px)); text-align: center; touch-action: manipulation; }
.memory-round { margin: 0 0 6px; font-size: 13px; letter-spacing: .08em; color: var(--ink-soft); min-height: 1em; }
.memory-beat { font-style: italic; }
.memory-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0 4px; }
.memory-row button { min-height: 44px; min-width: 96px; }
.memory-field { width: min(320px, 70vw); aspect-ratio: 4 / 3; margin: 10px auto; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.memory-fog { background: radial-gradient(#cfcac0, #a9a49a); animation: memory-fog 1.4s ease-in forwards; }
.memory-fog.short { aspect-ratio: 4 / 1; }
@keyframes memory-fog { from { opacity: 0; } to { opacity: 1; } }
.memory-match { display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap; }
.memory-wheel { touch-action: none; border-radius: 50%; cursor: crosshair; }
.memory-wheel:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
.memory-side { display: grid; gap: 12px; justify-items: center; min-width: 180px; }
.memory-side label { display: grid; gap: 6px; }
.memory-strip { -webkit-appearance: none; appearance: none; width: 200px; height: 34px; border-radius: 17px; border: 1px solid rgba(0,0,0,.25); touch-action: none; }
.memory-strip::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%; background: #f1ece0; border: 3px solid #2f2d29; }
.memory-strip::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #f1ece0; border: 3px solid #2f2d29; }
.memory-swatch { width: 72px; height: 72px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.memory-swatch.big { width: min(150px, 36vw); height: min(150px, 36vw); }
.memory-pair { margin: 0; display: grid; gap: 6px; justify-items: center; }
.memory-pair figcaption { font-size: 14px; color: var(--ink-soft); }
.memory-score { font-size: 34px; margin: 6px 0 0; }
.memory-line { font-style: italic; max-width: 440px; margin: 8px auto; }
.memory-whisper { font-style: italic; color: var(--ink-soft); min-height: 1.3em; }
.small-pairs { align-items: center; margin: 6px 0; }
.small-pairs .memory-swatch { width: 44px; height: 44px; }
.perches { display: grid; gap: 8px; width: min(420px, 86vw); margin: 10px auto; }
.perch { position: relative; height: 46px; border-radius: 23px !important; border: 1.5px solid var(--ink); background: none;
  margin-left: calc((1 - var(--k)) * 18%); margin-right: calc(var(--k) * 18%); touch-action: none; }
.perch::after { content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 3px; background: #6b5845; border-radius: 2px; }
.perch-bird { position: absolute; left: 50%; top: 4px; width: 22px; height: 16px; border-radius: 50% 60% 40% 50%; background: #5a8ae0; opacity: .25; translate: -50% 0; z-index: 1; transition: opacity .12s, translate .12s; }
.perch.singing { background: rgba(90, 138, 224, .18); }
.perch.singing .perch-bird { opacity: 1; translate: -50% -4px; }
.perch:disabled { opacity: 1; cursor: default; }
.memory-dots { min-height: 1.4em; letter-spacing: .1em; }
@media (max-width: 480px) { dialog.memory { padding: 16px 12px; } .memory-strip { width: 170px; } }
.perch-fill { position: absolute; left: 8px; bottom: 5px; height: 4px; width: 0; border-radius: 2px; background: #5a8ae0; opacity: .8; }
.perch.singing .perch-fill { animation: perch-hold .5s linear forwards; }
.perch.long { background: rgba(90, 138, 224, .32); }
@keyframes perch-hold { to { width: calc(100% - 16px); } }
/* Keeping your place (keep-ui.js). */
.keep { border-top: 1px solid rgba(47, 45, 41, .25); margin-top: 10px; padding-top: 6px; }
.keep h3 { margin: 4px 0; font-weight: normal; font-style: italic; }
.keep .row { margin: 6px 0; }
.keep-code { width: 100%; box-sizing: border-box; font: 12px/1.3 monospace; }

/* Bearings in tabs (bearings-tabs.js). */
#bearings .tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid rgba(47, 45, 41, .25); margin: 0 0 14px; }
#bearings [role="tab"] { border: none; border-radius: 6px 6px 0 0; padding: 8px 12px; background: none; font-size: 15px; color: var(--ink-soft); margin-bottom: -1px; border-bottom: 2px solid transparent; }
#bearings [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
#bearings [role="tab"]:hover { background: rgba(47, 45, 41, .06); color: var(--ink); }
#bearings .panel[hidden] { display: none; }
#bearings .calm { font-style: italic; margin-bottom: 14px; }
#bearings .first { display: grid; gap: 10px; margin: 0 0 16px; }
#bearings .first button { text-align: left; border-radius: 8px; padding: 12px 16px; font-size: 17px; }
#bearings .first button.primary { background: var(--ink); color: var(--paper); text-align: center; }
#bearings .first button .small { font-size: 14px; }
#bearings .first button:hover .small { color: inherit; }
#bearings .keys b { font-weight: normal; border: 1px solid rgba(47, 45, 41, .35); border-radius: 4px; padding: 0 5px; }
#bearings button.link { border: none; padding: 0; background: none; text-decoration: underline; color: inherit; font: inherit; }
#bearings button.link:hover { background: none; color: var(--ink); }
#bearings .footer-links { margin: 18px 0 0; }
#bearings .restart-row { margin-top: 18px; }
@media (max-width: 480px) { #bearings [role="tab"] { padding: 7px 7px; font-size: 14px; } }
#bearings #said-lately { margin: 0 0 12px; }
#bearings #said-lately summary { cursor: pointer; color: var(--ink-soft); font-size: 15px; }
#bearings .said { max-height: 38vh; overflow-y: auto; margin: 8px 0 0; padding-left: 1.2em; font-size: 15px; }
#bearings .said li { margin: 0 0 7px; }
#bearings .said li.thought { font-style: italic; }
/* The birdsong: the perches rest while the bird sings; a wrong note shows on its perch. */
.perches.listening .perch { cursor: default; opacity: .78; }
.perch.wrong { background: rgba(120, 60, 50, .35); outline: 2px solid rgba(150, 70, 55, .7); }
/* Keep your place online: its own card on the first Bearings tab, not a footnote. */
.online-here { border: 1.5px solid var(--ink); border-radius: 10px; padding: 12px 16px; margin: 0 0 14px; background: rgba(255, 255, 255, .35); }
.online-here h3 { margin: 0 0 4px; font-style: normal; font-size: 17px; }
.online-here p { margin: 6px 0; }
.online-here .button.primary { display: inline-block; background: var(--ink); color: var(--paper); border-radius: 8px; padding: 10px 16px; text-decoration: none; font-size: 16px; }
.online-here .button.primary:hover, .online-here .button.primary:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* The closing: a quiet skip, then the title over the dark. */
.coda-skip { position: absolute; right: 14px; bottom: 14px; z-index: 6; background: none; border: 0; color: rgba(233, 227, 214, .55); font: italic 14px/1 serif; cursor: pointer; }
.coda-skip:hover, .coda-skip:focus-visible { color: rgba(233, 227, 214, .9); }
.coda-end { position: absolute; inset: 0; z-index: 7; display: grid; place-content: center; justify-items: center; gap: 28px; }
.coda-end[hidden] { display: none; }
.coda-end h2 { margin: 0; font-weight: normal; font-style: italic; letter-spacing: .12em; font-size: clamp(34px, 7vw, 64px); color: #d9cdb7; animation: coda-title 3s ease; }
.coda-end .row button { background: none; color: #e9e3d6; border: 1.5px solid rgba(233, 227, 214, .6); border-radius: 999px; padding: 8px 18px; font: inherit; cursor: pointer; }
.coda-end .row button:hover, .coda-end .row button:focus-visible { border-color: #e9e3d6; }
@keyframes coda-title { from { opacity: 0; } }
#ending .row button.primary { background: var(--ink); color: var(--paper); }
#through[data-coda] .bar, #through[data-coda] .pads { visibility: hidden; } /* the closing is not played */
#bearings .carrying { margin: 0 0 14px; font-style: italic; }
/* The remembered skies, cut in while the drawing takes its colour (skies-ui.js). */
.sky-card { position: absolute; inset: 9% 7% 16%; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .7s ease;
  background: linear-gradient(to bottom, var(--top, #fff), var(--low, #ddd)); box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
  clip-path: polygon(0 2%, 8% 0, 23% 1.5%, 41% .2%, 60% 1.8%, 78% .4%, 100% 1.6%, 99.2% 30%, 100% 62%, 99.4% 98%, 82% 100%, 60% 98.6%, 38% 100%, 17% 98.4%, 0 99.4%, .8% 64%, 0 31%); }
.sky-card.on { opacity: 1; animation: sky-drift 2.8s ease-out; }
.sky-card .sky-place { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 38%; }
@keyframes sky-drift { from { transform: scale(1.04); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .sky-card.on { animation: none; } }
/* Breath, seen (render/breath-fx.js): over the picture, under words and prompts. */
.breath-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; }
#world { transform-origin: 50% 60%; }
/* Close handling of the little backstage flap; no code or destination is labelled. */
.wooden-flap { display: block; position: relative; width: 150px; height: 135px; margin: 20px auto;
  border: 5px solid #514132; border-radius: 2px; background: repeating-linear-gradient(4deg, #877052 0 13px, #7b654b 14px 16px);
  box-shadow: 5px 6px 0 #31291f; transform-origin: top; touch-action: none; user-select: none; }
.wooden-flap:hover { background-color: #877052; }
.wooden-flap.pressed { transform: perspective(240px) rotateX(-8deg); }
.wooden-flap.held { transform: perspective(240px) rotateX(-18deg); outline: 2px solid #c4ad87; }
.flap-bird { position: absolute; width: 55px; height: 40px; left: 44px; top: 44px; background: #211b15;
  clip-path: polygon(0 65%, 30% 50%, 40% 0, 55% 48%, 82% 36%, 100% 52%, 85% 61%, 68% 84%, 15% 85%); }
.flap-memory .memory-dots { overflow-wrap: anywhere; }
