:root {
  --paper: #FBE7EB;
  --ink: #5A1030;
  --ink-soft: #84304F;
  --rose: #E4578A;
  --blush: #F7A9C3;
  --desk: #3A0B22;
  --term-text: #FFE5EC;
  --term-dim: #E9A8BF;
  --term-accent: #FF9CC0;
  --chalk: #FFD6E2;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, Monaco, "DejaVu Sans Mono", "Liberation Mono", "JetBrains Mono", monospace;
  --hand: Caveat, "Segoe Print", "Bradley Hand", cursive;
  --hand-2: Mynerve, Caveat, cursive;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  background: var(--paper);
  scrollbar-width: thin;
  scrollbar-color: var(--rose) var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
/* once the camera is over the desk, what shows past the page's ends is desk too */
html.desk { background: var(--desk); }
html::-webkit-scrollbar { width: 10px; }
html::-webkit-scrollbar-track { background: var(--paper); }
html::-webkit-scrollbar-thumb { background: var(--rose); border-radius: 7px; border: 2px solid var(--paper); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--rose); color: #fff; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- the film ---------- */
/* --stage-h is the screen's height with a phone browser's bars tucked away, set by
   the script in px so that neither the bars nor a keyboard can resize the stage. */
#scroll {
  position: relative;
  height: calc(var(--stage-h, 100vh) * var(--screens, 16));
}
#stage {
  position: sticky;
  top: 0;
  height: var(--stage-h, 100vh);
  /* Clipping must not create a scroller: focusing a card must never move the canvas. */
  overflow: clip;
  background: var(--paper);
}
#film {
  display: block;
  width: 100%;
  height: 100%;
}

/* two rulers the script reads: the screen with the browser's bars away, and with them out */
#full,
#fold {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 100vh;
  visibility: hidden;
  pointer-events: none;
}
#full { height: 100lvh; }
#fold { height: 100svh; }

/* shown until the canvas has drawn its first frame */
#boot {
  position: absolute;
  inset: 0 0 auto;
  height: 100vh;
  height: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  font: 600 min(15.6vw, 27.7vh)/1 var(--hand);
  color: var(--ink);
  padding-bottom: 2vh;
  pointer-events: none;
}
/* the tall frame's reel is half as large again */
@media (max-aspect-ratio: 4/5) {
  #boot { font-size: min(27.5vw, 20.4vh); }
}
.ready #boot { display: none; }

/* ---------- the answer terminal (laid out in film units, scaled by JS) ---------- */
/* Transparent card buttons sit precisely on the ink drawing. */
#fortune {
  position: absolute;
  left: 0;
  top: 0;
  width: 1600px;
  transform-origin: 0 0;
  pointer-events: none;
}
#fortune[hidden], #fortune [hidden] { display: none; }
#fortune button {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  color: var(--ink);
  font: 600 42px/1.2 var(--hand);
  background: transparent;
  border: 0;
  border-radius: 9px;
  touch-action: manipulation;
}
#fortune button:focus-visible {
  outline: 3px dashed var(--rose);
  outline-offset: 5px;
}
#fortune-cards {
  position: absolute;
  pointer-events: auto;
  overflow: clip;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
#fortune .fortune-card { padding: 0; transform-origin: center; touch-action: pan-y; cursor: inherit; }
#fortune .fortune-card:disabled { pointer-events: none; }
#fortune-action {
  min-height: 62px;
  padding: 8px 28px;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
/* One unbroken ink stroke, including under descenders such as the p in “keep”. */
#fortune-action::after {
  content: "";
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 3px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 8' preserveAspectRatio='none'%3E%3Cpath d='M2 4 Q28 1 54 4 T106 4 T158 4 T210 4 T262 4 T318 4' fill='none' stroke='%23E4578A' stroke-width='2.8' stroke-linecap='round'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  pointer-events: none;
}
#fortune-action:hover { color: var(--rose); }
#fortune .fortune-nav {
  width: 72px;
  height: 68px;
  font-family: var(--hand);
  transform: translate(-50%, -50%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#fortune .fortune-nav:disabled { opacity: 0.25; cursor: default; }
.tall #fortune button { font-size: 66px; }
.tall #fortune-action { min-height: 160px; padding: 20px 44px; }
.tall #fortune-action::after { left: 44px; right: 44px; bottom: 30px; height: 12px; }
.tall #fortune .fortune-nav { width: 170px; height: 170px; }

#answer {
  position: absolute;
  left: 0;
  top: 0;
  width: 1300px;
  height: 730px;
  transform-origin: 0 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--term-accent) transparent;
  color: var(--term-text);
  font: 27px/1.6 var(--mono);
  opacity: 0;
  visibility: hidden;
}
#answer.on { opacity: 1; visibility: visible; }
#answer ::selection { background: var(--chalk); color: #7A1D49; }

.t {
  margin: 0;
  min-height: 43px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.t.dim { color: var(--term-dim); }
.t.accent { color: var(--term-accent); }

.q {
  margin: 14px 0 16px;
  font: 600 132px/1.08 var(--hand);
  color: var(--term-text);
  text-shadow: 5px 4px 0 rgba(255, 141, 182, 0.38);
  text-wrap: balance;
}
.turn {
  margin: 44px 0 4px;
  font: 600 56px/1.2 var(--hand);
  color: var(--chalk);
  text-wrap: balance;
}

/* A paper aside, pinned beside the reply rather than across the question. */
.end-response {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 40px;
  align-items: start;
  margin: 24px 12px 0 0;
}
.end-reply { min-width: 0; }
.end-response .turn { margin: 0 0 4px; font-size: 50px; }
.voice-note {
  position: relative;
  margin: 12px 0 22px;
  padding: 32px 24px 12px;
  color: var(--ink);
  background: #fff2d9;
  border-radius: 2px 5px 3px 1px;
  box-shadow: 7px 11px 0 rgba(34, 3, 17, 0.16), 0 4px 12px rgba(34, 3, 17, 0.22);
  transform: rotate(2deg);
  transform-origin: 50% 12px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease-out;
  font: 400 30px/1.16 var(--hand-2);
}
.voice-note.visible { visibility: visible; opacity: 1; }
.voice-note p { margin: 0 0 10px; }
.note-pin {
  position: absolute;
  left: calc(50% - 12px);
  top: -8px;
  width: 24px;
  height: 24px;
  border: 2px solid var(--ink);
  border-radius: 48% 52% 46% 54%;
  background: var(--rose);
  box-shadow: 3px 4px 0 rgba(90, 16, 48, 0.24);
}
.note-pin::before {
  content: '';
  position: absolute;
  top: 3px; left: 4px;
  width: 7px; height: 5px;
  border-radius: 50%;
  background: #ffcedc;
  transform: rotate(-28deg);
}
.note-pin::after {
  content: '';
  position: absolute;
  top: 19px; left: 10px;
  width: 2px; height: 10px;
  background: var(--ink);
  transform: rotate(-12deg);
}
#voice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: max(58px, calc(44px / var(--answer-scale, 1)));
  padding: 6px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font: 600 30px/1.2 var(--hand);
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: underline;
  text-decoration-color: var(--rose);
  text-underline-offset: 6px;
}
#voice-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.voice-pause { display: none; }
#voice-toggle[aria-pressed="true"] .voice-play { display: none; }
#voice-toggle[aria-pressed="true"] .voice-pause { display: block; }
#voice-toggle:hover { color: var(--rose); }
#voice-toggle:focus-visible { outline: 2px dashed var(--rose); outline-offset: 3px; }
#voice-toggle:disabled { cursor: wait; }

#log { margin-top: 22px; }

#prompt {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}
#prompt.live { opacity: 1; }
.ps1 { color: var(--term-accent); white-space: nowrap; }
#cavab {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: inherit;
  font: inherit;
  caret-color: var(--term-text);
}
#cavab::placeholder { color: var(--term-dim); opacity: 0.75; }
#prompt:focus-within { box-shadow: 0 3px 0 -1px rgba(255, 156, 192, 0.55); }
#prompt.busy { opacity: 0.6; }

.send {
  flex: none;
  padding: 0 16px;
  border: 0;
  border-radius: 7px;
  background: var(--chalk);
  color: #7A1D49;
  font: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease-out, transform 0.1s ease-out;
}
.send:hover { background: #fff; }
.send:active { transform: translateY(2px); }
.send:focus-visible { outline: 3px solid var(--term-accent); outline-offset: 3px; }
.send:disabled { opacity: 0.5; cursor: default; }

.hint {
  margin: 8px 0 0;
  font-size: 19px;
  color: var(--term-dim);
  opacity: 0;
  transition: opacity 0.25s ease-out;
}
#prompt.live + .hint { opacity: 1; }

/* ---------- the answer terminal in the tall window (portrait screens) ----------
   Still film units: the script sets the box to the taller window and scales it. */
.tall #answer { font-size: 43px; }
.tall .t { min-height: 69px; }
.tall .q {
  margin: 22px 0 28px;
  font-size: 168px;
  text-shadow: 7px 6px 0 rgba(255, 141, 182, 0.38);
}
.tall .turn {
  margin: 62px 0 10px;
  font-size: 84px;
}
.tall .end-response { grid-template-columns: minmax(0, 1fr); gap: 30px; margin: 40px 12px 0 0; }
.tall .end-response .turn { font-size: 78px; }
.tall .voice-note { margin: 12px 12px 18px; padding: 52px 48px 20px; font-size: 58px; line-height: 1.15; transform: rotate(-1deg); }
.tall .note-pin { width: 42px; height: 42px; left: calc(50% - 21px); top: -14px; border-width: 3px; }
.tall .note-pin::before { width: 12px; height: 8px; left: 7px; top: 6px; }
.tall .note-pin::after { top: 35px; left: 18px; height: 16px; width: 3px; }
.tall #voice-toggle { min-height: max(162px, calc(44px / var(--answer-scale, 1))); gap: 20px; font-size: 62px; padding: 12px 8px; }
.tall #voice-toggle svg { width: 48px; height: 48px; }
.tall.compact-ending #answer { font-size: 34px; }
.tall.compact-ending .q { font-size: 132px; margin: 16px 0 20px; }
.tall.compact-ending .end-response { margin-top: 30px; gap: 20px; }
.tall.compact-ending .end-response .turn { font-size: 64px; }
.tall.compact-ending #log { margin-top: 24px; }
.tall.compact-ending .voice-note { padding: 38px 36px 12px; font-size: 44px; }
.tall.compact-ending #voice-toggle { min-height: 100px; font-size: 48px; }
@media (max-height: 500px) {
  html:not(.tall) .end-response { grid-template-columns: minmax(0, 1fr) 460px; gap: 36px; margin-top: 16px; }
  html:not(.tall) .end-response .turn { font-size: 44px; }
  html:not(.tall) .voice-note { margin-top: 6px; padding: 24px 24px 8px; font-size: 28px; }
}
.tall #log { margin-top: 32px; }
/* the prompt keeps a line to itself and the button drops under it, big enough for a thumb */
.tall #prompt {
  flex-wrap: wrap;
  gap: 30px 20px;
}
.tall #cavab {
  flex: 1 0 55%;
  margin: -42px 0;
  padding: 42px 0;
}
/* the focus line sits under the typed line, not under the button */
.tall #prompt:focus-within { box-shadow: none; }
.tall #cavab:focus {
  background: linear-gradient(rgba(255, 156, 192, 0.55), rgba(255, 156, 192, 0.55)) 0 calc(100% - 36px) / 100% 4px no-repeat;
}
.tall .send {
  min-height: 150px;
  margin-left: auto;
  padding: 0 54px;
  border-radius: 12px;
}
.tall .hint {
  margin-top: 14px;
  font-size: 36px;
}

/* ---------- touch ---------- */
@media (pointer: coarse) {
  /* a larger target than the button looks; it stops at the right edge so the terminal never scrolls sideways */
  .send { position: relative; }
  .send::after {
    content: "";
    position: absolute;
    inset: -34px 0 -34px -18px;
  }
  html:not(.tall) #cavab {
    margin: -22px 0;
    padding: 22px 0;
  }
}

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  padding: 14px 20px;
  background: var(--desk);
  color: var(--term-text);
  font: 16px/1.4 var(--mono);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  #prompt, .hint, .send, .voice-note { transition: none; }
}
