/* One layout for every width: the reading column with each chapter's graphic
   pinned full screen and its passages rising over it as cards. */
:root {
  --story-viewport-height: 100svh;
  --story-panel-height: 100svh;
}

html {
  scroll-snap-type: none;
  overscroll-behavior-x: none;
}

body,
.scrolly,
.chapter,
.text,
.step {
  min-inline-size: 0;
}

.graphic {
  height: var(--story-viewport-height);
  scroll-snap-align: none;
}

.gbody {
  overflow: visible;
}

.beats,
.beat,
.beatcap {
  display: none;
}

.step {
  overflow-wrap: break-word;
}

/* Give the three operations enough reading room to follow their animation. */
.chapter[data-ch="1"] .step[data-s="method"] ol li {
  padding-block: 8px;
  margin-bottom: 1em;
}
.chapter[data-ch="1"] .step[data-s="method"] ol li p { margin: 0; }
.chapter[data-ch="1"] .step[data-s="method"] ol li p + p { margin-top: .7em; }

.step .cipher,
.step code,
.step a {
  overflow-wrap: anywhere;
}

.table-wrap {
  max-inline-size: 100%;
  overscroll-behavior-x: contain;
}

figure,
figure img {
  max-inline-size: 100%;
}

/* Every width shares one flow: the graphic fills the screen and holds while
the passages that explain it rise over its lower part, one at a time. */
:root { --story-panel-height: 100dvh; }
.scrolly { --story-gutter: 24px; padding-inline: var(--story-gutter); }
.chapter { display: block; position: relative; }
.chapter > .text { max-width: none; padding-block: 24px 40px; }
/* A chapter heading sits well clear of the rule above it. */
.chapter + .chapter > .text.text-before:has(h2, h3) { padding-top: 56px; }
.chapter:first-child .text { padding-top: 24px; }
.step { min-height: 0; max-width: 640px; margin-inline: auto; padding-bottom: 32px; scroll-margin-top: 24px; }
.step + .step { padding-top: 16px; }

.gbody { min-height: 0; overflow: visible; }
.gbody canvas { flex: 1 1 0; min-height: 0; }
.sub:empty { display: none; }

/* Each graphic fills the screen and holds while the passages that explain
it rise over its lower part one at a time, news-graphic style. */
.chapter.pinned-chapter > .pin { position: relative; }
.chapter.pinned-chapter > .pin > .graphic {
  position: sticky;
  top: 0;
  z-index: 1;
  width: auto;
  max-width: none;
  height: 100vh;
  height: 100svh;
  min-height: 0;
  margin-inline: calc(-1 * var(--story-gutter));
  padding: max(10px, env(safe-area-inset-top, 0px)) var(--story-gutter) var(--card-space);
  border: 0;
  background: var(--room);
  --card-space: 42svh;
}
/* On a wide screen the drawing keeps the reading column's width, centred. */
.chapter.pinned-chapter > .pin > .graphic > .gbody { width: 100%; max-width: 720px; margin-inline: auto; }
.chapter.pinned-chapter > .pin > .text {
  display: flow-root; /* keeps the last card's spacing inside the pinned run */
  position: relative;
  z-index: 2;
  margin-top: -38svh;
  /* The graphic holds on the plain cipher for a screen's worth of scrolling
  after the introduction has gone, then the first card rises into view. */
  padding-block: 66svh 0;
  pointer-events: none;
}
.chapter.pinned-chapter > .text.text-before { padding-bottom: 0; }
.chapter.pinned-chapter > .text.text-before > .step { padding-bottom: 8px; }
.pinned-chapter .pin .step { padding: 0; }
.pinned-chapter .pin .step + .step { padding-top: 0; }
.pinned-chapter .pin .step ol { padding: 0; margin: 0; }
.pinned-chapter .pin .step ul { margin: 0; }
.chapter.pinned-chapter > .pin .step ol > li { list-style: none; padding: 0; margin: 0; }
/* Every passage in the pinned run is one card, spaced a screen apart.
The graphic's "Step n of 3" line carries the numbering here. */
.pinned-chapter .pin > .text :is(.step [data-walk-stage], .step[data-walk-stage]) {
  display: block;
  margin: 0 auto 64svh;
  padding: 16px 18px;
  max-width: 560px;
  border: 1px solid var(--veil-2);
  border-radius: 0;
  background: var(--card-bg, #fff);
  box-shadow: 0 6px 24px rgb(0 0 0 / 8%);
  pointer-events: auto;
  will-change: opacity;
}
.pinned-chapter .pin > .text .step > p[data-walk-stage]:last-child,
.pinned-chapter .pin > .text > .step[data-walk-stage]:last-child { margin-bottom: 72svh; }
/* After the last card, the next section comes up to meet the graphic: the
passage holds a little longer, and the text rises over the empty part of
the panel (--walk-tail, measured by the script) before pushing it. */
.pinned-chapter .pin > .text .step > p[data-walk-stage]:last-child,
.pinned-chapter .pin > .text > .step[data-walk-stage]:last-child { margin-bottom: calc(var(--walk-tail, 0px) + 60svh); }
.chapter.pinned-chapter > .text.text-after { position: relative; z-index: 3; background: var(--room); margin-top: calc(-1 * var(--walk-tail, 0px)); padding-top: 0; }
.chapter.pinned-chapter + .chapter > .text.text-before { position: relative; z-index: 3; background: var(--room); margin-top: calc(-1 * var(--walk-tail-prev, 0px)); }
.chapter[style*="--walk-tail-prev"] > .text.text-before { padding-top: 0; }
.pinned-chapter .pin > .text > .step[data-walk-stage] p + p { margin-top: .7em; }
.pinned-chapter .pin .step p:last-child, .pinned-chapter .pin .step li:last-child { margin-bottom: 0; }
.pinned-chapter .pin .step p { margin: 0; }
.pinned-chapter .pin [data-walk-stage]::before, .pinned-chapter .pin .step[data-walk-stage]::before { display: none; }
.pinned-chapter .cw-controls,
.pinned-chapter .cw-swipe-hint { display: none; }
.pinned-chapter .cw { padding: 8px 0 4px; gap: 8px; }
.pinned-chapter .cw-scene { container-type: size; }
.pinned-chapter .cw-source-letter,
.pinned-chapter .cw-card { width: min(100%, 44px); height: clamp(32px, calc((100cqh - 78px) / 3), 46px); }
.pinned-chapter .cw-source-grid { gap: clamp(8px, 4cqh, 16px) 14px; --cw-src-w: clamp(30px, calc((100cqh - 78px) / 3 * .95), 44px); }
.pinned-chapter .cw-grid { gap: clamp(6px, 3cqh, 12px) 5px; }
.pinned-chapter .cw-source-letter,
.pinned-chapter .cw-face { font-size: clamp(20px, 6.5cqw, 28px); }
.pinned-chapter .cw-word { font-size: clamp(10.5px, 3cqw, 12.5px); }
.pinned-chapter .cw-prayer { font-size: clamp(17px, 5cqw, 21px); max-width: 32ch; }
.pinned-chapter .cw-single { width: 64px; height: 72px; font-size: 44px; }
.pinned-chapter .cw[data-compact] .cw-single { width: 36px; height: 40px; font-size: 26px; }
@media (max-width: 360px) {
  .scrolly { --story-gutter: 20px; }
}
/* A mouse wheel covers ground faster than a thumb, so wide screens set the
   cards further apart and each stage stays on screen longer. */
@media (min-width: 901px) {
  .pinned-chapter .pin > .text :is(.step [data-walk-stage], .step[data-walk-stage]) { margin-bottom: 100svh; }
}
/* A short phone screen keeps the chart readable by giving the cards a little
   less room and setting them in a slightly smaller size. */
@media (max-width: 900px) and (max-height: 640px) and (orientation: portrait) {
  .chapter.pinned-chapter > .pin > .graphic { --card-space: 36svh; }
  .chapter.pinned-chapter > .pin > .text { margin-top: -32svh; }
  .pinned-chapter .pin > .text :is(.step [data-walk-stage], .step[data-walk-stage]) {
    padding: 12px 14px;
    font-size: .9375rem;
    line-height: 1.6;
  }
}
@media (max-width: 900px) and (orientation: landscape) {
  .chapter.pinned-chapter > .pin > .graphic { --card-space: 30svh; }
  .chapter.pinned-chapter > .pin > .text { margin-top: -26svh; padding-top: 52svh; }
  .pinned-chapter .cw { padding-top: 4px; gap: 4px; }
  .pinned-chapter .cw-legend { display: none; }
  .pinned-chapter .cw-source-letter,
  .pinned-chapter .cw-card { height: clamp(22px, calc((100cqh - 58px) / 3), 40px); }
  .pinned-chapter .cw-face, .pinned-chapter .cw-source-letter { font-size: 18px; }
  .pinned-chapter .cw-word { font-size: 10.5px; }
  .pinned-chapter .cw-pair { gap: 2px; }
  .pinned-chapter .cw-source-grid, .pinned-chapter .cw-grid { gap: 3px 5px; }
  .pinned-chapter .cw-source-grid { --cw-src-w: clamp(22px, calc((100cqh - 58px) / 3 * .95), 38px); }
  .pinned-chapter .cw-prayer { font-size: 16px; line-height: 1.4; max-width: 46ch; }
  .pinned-chapter .cw-single { width: 48px; height: 54px; font-size: 34px; }
}
