/*! leafturn 0.7.0 | UNLICENSED, see its LICENSE | generated by leafturn-build: do not edit */
/* leafturn — the reader's stylesheet.

   Every selector starts with `.story-reader` (the layer, its parts, the host's open control and
   the scroll lock), so nothing else on a page changes. The whole look comes from the `--sr-*`
   tokens: neutral defaults sit on `:where(…)` just below, at zero specificity, and a host sets
   its own on `.story-reader` (and `.story-reader-open`). Outside that block every colour, font
   and timing is a `var(--sr-*)` (`test/styles.test.ts`). Sizes and sides are logical
   properties; the exceptions are named where they stand.

   Two directions (0.5.0): the text's (`dir`, on the layer and on every text container the
   reader builds) and the book's binding (`data-sr-binding`: `left`, a left-to-right book, or
   `right`, a right-to-left one — its spine on the right, its cover on the left, forward to the
   left). The page area is physical: the pages and their leaves are held left-to-right, so their
   logical sides read as left and right under any `dir`, and every rule that depends on the
   binding says so with `[data-sr-binding='right']`. The bars run the way the book does.

   One leaf on a tall box; two leaves (a spread) once the box is wide enough (the `spreadRatio`
   option). Pictures are always contained, never cropped, and text is never clipped: an area
   that cannot fit scrolls. Reduced motion — the visitor's, or `reducedMotion: 'force'` — makes
   every change instant. */

:where(.story-reader, .story-reader-open) {
  /* The palette. Text pairs meet WCAG 2.1 AA (4.5:1) (`test/styles.test.ts`). */
  --sr-desk: #e8e8e5;
  --sr-paper: #ffffff;
  --sr-ink: #1f1f1f;
  --sr-soft: #545454;
  --sr-accent: #2b5876;
  --sr-on-accent: #ffffff;
  --sr-edge: #dcdcd8;
  --sr-line: #d2d2ce;
  --sr-track: #d2d2ce;
  --sr-rule: #c4c4bf;
  --sr-art-bg: #f0f0ed;
  /* An `r, g, b` triplet, for the shadows. */
  --sr-shade: 0, 0, 0;
  --sr-open-hover: var(--sr-art-bg);
  /* Type. */
  --sr-font-body: Georgia, 'Times New Roman', serif;
  --sr-font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sr-leading: 1.55;
  /* The next-page button. */
  --sr-next-bg: var(--sr-accent);
  --sr-next-ink: var(--sr-on-accent);
  --sr-next-border: var(--sr-accent);
  --sr-next-shadow: 0 4px 12px rgba(var(--sr-shade), 0.2);
  /* A chapter's numeral, atop its first scene (`data-reader-chapter-numeral`). */
  --sr-numeral-ink: var(--sr-accent);
  --sr-numeral-font: var(--sr-font-body);
  --sr-numeral-size: 26px;
  --sr-numeral-box-size: clamp(30px, 5.6cqh, 44px);
  --sr-numeral-style: italic;
  --sr-numeral-caps: normal;
  --sr-numeral-tracking: 0;
  /* The ending's heading. */
  --sr-ending-ink: var(--sr-accent);
  /* The page-edge stacks (raised by `data-edge-*` below). */
  --sr-stack-right: 1px 0 0 var(--sr-edge);
  --sr-stack-left: -1px 0 0 var(--sr-edge);
  /* Timings. The engines read these to know when a turn has ended. */
  --sr-slide-ms: 280ms;
  --sr-fade-ms: 400ms;
  --sr-turn-ms: 600ms;
  --sr-meter-ms: 280ms;
  /* The paper turn: its shading (`r, g, b` triplets — the shadow on the page uncovered and the
     crease, the glint where the bend meets the light, the lifted sheet's cast shadow), the plain
     back of a single leaf, a tap turn's length and the hover lift's. */
  --sr-paper-fold: var(--sr-shade);
  --sr-paper-glint: 255, 255, 255;
  --sr-paper-cast: var(--sr-shade);
  --sr-paper-back: var(--sr-art-bg);
  --sr-paper-ms: 520ms;
  --sr-paper-lift-ms: 260ms;
  /* The stage layout (`layout: 'stage'`): the desk the pages lie on and its optional glow and
     vignette (`r, g, b` triplets, each with its strength), the words and controls of its bar on
     the desk, the page slider, the pages' shadow on the desk, the air around the pages, the
     arrows beside them, and the pages' entrance. */
  --sr-stage-desk: #262626;
  --sr-stage-glow: 255, 255, 255;
  --sr-stage-glow-alpha: 0;
  --sr-stage-rim: 0, 0, 0;
  --sr-stage-rim-alpha: 0.45;
  --sr-stage-ink: #f2f2f2;
  --sr-stage-soft: #c4c4c4;
  --sr-stage-btn: #333333;
  --sr-stage-btn-hover: #404040;
  --sr-stage-btn-line: #5c5c5c;
  --sr-stage-track: #4d4d4d;
  --sr-stage-meter: #9cc3df;
  --sr-stage-cast: var(--sr-shade);
  --sr-stage-air-block: clamp(12px, 3.5vh, 44px);
  --sr-stage-air-inline: clamp(10px, 3.5vw, 72px);
  --sr-stage-arrow: 48px;
  --sr-stage-arrow-gap: clamp(14px, 1.5vw, 26px);
  --sr-stage-in-ms: 380ms;
  /* Not for a host to set: the reader writes these on the layer and the slider as it goes —
     the open pages' box (the arrows beside them) and the slider's filled share. */
  --sr-book-left: 0px;
  --sr-book-right: 100%;
  --sr-book-mid: 50%;
  --sr-slider-fill: 0%;
}

/* --- the host's open control --- */

.story-reader-open {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-block-size: 48px;
  margin-block: 0.25rem 1.5rem;
  margin-inline: 0;
  padding-block: 0;
  padding-inline: 22px;
  border: 2px solid var(--sr-accent);
  border-radius: 999px;
  background: var(--sr-paper);
  color: var(--sr-accent);
  font-family: var(--sr-font-ui);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

/* An author `display` beats the UA `[hidden]` rule: the control stays out of sight until the
   reader is mounted. */
.story-reader-open[hidden] {
  display: none;
}

/* The expand-corners mark, drawn: no icon file, no glyph. */
.story-reader-open::before {
  content: '';
  flex: 0 0 auto;
  inline-size: 18px;
  block-size: 18px;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 0 / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 100% / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 100% / 2px 7px no-repeat;
}

.story-reader-open:hover {
  background: var(--sr-open-hover);
}

.story-reader-open:focus-visible {
  outline: 3px solid var(--sr-accent);
  outline-offset: 3px;
}

/* The page behind is locked while the layer is open. */
.story-reader-locked,
.story-reader-locked body {
  overflow: hidden;
}

/* --- the layer --- */

.story-reader {
  position: fixed;
  inset-block: 0;
  inset-inline: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  block-size: 100vh;
  block-size: 100dvh;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
  background: var(--sr-desk);
  color: var(--sr-ink);
  font-family: var(--sr-font-body);
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
}

.story-reader:focus {
  outline: none;
}

.story-reader [hidden] {
  display: none !important;
}

/* --- the bars --- */

.story-reader-bar {
  flex: 0 0 auto;
  direction: ltr;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 0;
  padding-inline: 14px;
  font-family: var(--sr-font-ui);
}

/* The bars follow the book, not the text: previous on the side the earlier pages lie, next on
   the other. Their words carry the text's own `dir`. */
.story-reader[data-sr-binding='right'] .story-reader-bar {
  direction: rtl;
}

.story-reader-top {
  block-size: 60px;
}

.story-reader-bottom {
  block-size: 76px;
}

.story-reader-title {
  flex: 1 1 auto;
  min-inline-size: 0;
  margin: 0;
  overflow: hidden;
  color: var(--sr-soft);
  font-size: 14px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-reader-spacer {
  flex: 0 0 44px;
  inline-size: 44px;
  block-size: 44px;
}

.story-reader-btn {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 48px;
  block-size: 48px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--sr-line);
  border-radius: 999px;
  background: var(--sr-paper);
  color: var(--sr-ink);
  box-shadow: 0 2px 10px rgba(var(--sr-shade), 0.1);
  cursor: pointer;
}

.story-reader-close {
  inline-size: 44px;
  block-size: 44px;
}

.story-reader-next {
  border-color: var(--sr-next-border);
  background: var(--sr-next-bg);
  color: var(--sr-next-ink);
  box-shadow: var(--sr-next-shadow);
}

.story-reader-btn:disabled {
  border-color: var(--sr-line);
  background: transparent;
  color: var(--sr-soft);
  box-shadow: none;
  opacity: 0.5;
  cursor: default;
}

.story-reader-btn:focus-visible,
.story-reader-again:focus-visible,
.story-reader-text:focus-visible {
  outline: 3px solid var(--sr-accent);
  outline-offset: 3px;
}

.story-reader-icon {
  position: relative;
  direction: ltr;
  display: block;
  inline-size: 20px;
  block-size: 20px;
}

/* The icons are drawn around their box's centre, in a box held left-to-right whatever the bar's
   direction, so their logical sides are physical; the chevrons point the way their page lies. */
.story-reader-icon-close::before,
.story-reader-icon-close::after {
  content: '';
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  inline-size: 18px;
  block-size: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
}

.story-reader-icon-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.story-reader-icon-prev::before,
.story-reader-icon-next::before {
  content: '';
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  inline-size: 10px;
  block-size: 10px;
  border: solid currentColor;
  border-block-width: 0 2px;
  border-inline-width: 2px 0;
  transform: translate(-25%, -50%) rotate(45deg);
}

.story-reader-icon-next::before {
  border-block-width: 2px 0;
  border-inline-width: 0 2px;
  transform: translate(-75%, -50%) rotate(45deg);
}

/* Under right binding the next page lies to the left: next points left, previous right. */
.story-reader[data-sr-binding='right'] .story-reader-icon-prev::before {
  border-block-width: 2px 0;
  border-inline-width: 0 2px;
  transform: translate(-75%, -50%) rotate(45deg);
}

.story-reader[data-sr-binding='right'] .story-reader-icon-next::before {
  border-block-width: 0 2px;
  border-inline-width: 2px 0;
  transform: translate(-25%, -50%) rotate(45deg);
}

.story-reader-progress {
  flex: 1 1 auto;
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.story-reader-count {
  margin: 0;
  color: var(--sr-soft);
  font-size: 15px;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
}

.story-reader-meter {
  inline-size: min(240px, 70%);
  block-size: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--sr-track);
}

/* The script sets the fill's `width`; the transition names that property. */
.story-reader-meter-fill {
  inline-size: 0;
  block-size: 100%;
  border-radius: 2px;
  background: var(--sr-accent);
  transition: width var(--sr-meter-ms) ease-out;
}

.story-reader-live {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

/* --- the stage and its pages --- */

.story-reader-stage {
  position: relative;
  flex: 1 1 auto;
  min-block-size: 0;
  margin-block: 0;
  margin-inline: 12px;
  container-type: size;
  perspective: 1800px;
  /* Horizontal swipes are the reader's; vertical drags scroll a long text area; pinch-zoom
     stays the browser's. */
  touch-action: pan-y pinch-zoom;
}

/* The page area is physical: the leaves sit left then right, and their sides are left and right,
   under any text direction (their text containers carry the text's own `dir`). */
.story-reader-page {
  position: absolute;
  inset-block: 0;
  inset-inline: 0;
  direction: ltr;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.story-reader-measure {
  visibility: hidden;
  pointer-events: none;
}

.story-reader-leaf {
  position: relative;
  box-sizing: border-box;
  direction: ltr;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  min-block-size: 0;
  background: var(--sr-paper);
}

/* One leaf: the picture on top, the text below; the spine on its left (on its right under right
   binding, below). */
.story-reader-leaf-single {
  flex: 1 1 auto;
  max-inline-size: 44rem;
  padding-block: 22px 18px;
  padding-inline: 22px;
  border-start-start-radius: 4px;
  border-start-end-radius: 12px;
  border-end-end-radius: 12px;
  border-end-start-radius: 4px;
  box-shadow:
    var(--sr-stack-right),
    0 8px 24px rgba(var(--sr-shade), 0.1);
}

.story-reader[data-sr-binding='right'] .story-reader-leaf-single {
  border-start-start-radius: 12px;
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  border-end-start-radius: 12px;
  box-shadow:
    var(--sr-stack-left),
    0 8px 24px rgba(var(--sr-shade), 0.1);
}

/* A spread: two leaves meeting at a soft spine shadow. */
.story-reader[data-mode='spread'] .story-reader-stage {
  margin-block: 0 4px;
  margin-inline: 24px;
}

.story-reader-leaf-left,
.story-reader-leaf-right {
  flex: 0 1 auto;
  inline-size: 50%;
  inline-size: min(50cqw, max(82cqh, 48cqw));
  padding-block: clamp(14px, 7cqh, 64px);
  padding-inline: clamp(18px, 4.5cqw, 68px);
}

.story-reader-leaf-left {
  border-start-start-radius: 12px;
  border-start-end-radius: 2px;
  border-end-end-radius: 2px;
  border-end-start-radius: 12px;
  box-shadow:
    var(--sr-stack-left),
    0 12px 34px rgba(var(--sr-shade), 0.12);
}

.story-reader-leaf-right {
  border-start-start-radius: 2px;
  border-start-end-radius: 12px;
  border-end-end-radius: 12px;
  border-end-start-radius: 2px;
  box-shadow:
    var(--sr-stack-right),
    0 12px 34px rgba(var(--sr-shade), 0.12);
}

.story-reader-leaf-left::after,
.story-reader-leaf-right::before {
  content: '';
  position: absolute;
  inset-block: 0;
  inline-size: 40px;
  pointer-events: none;
}

.story-reader-leaf-left::after {
  inset-inline-end: 0;
  background: linear-gradient(to left, rgba(var(--sr-shade), 0.1), rgba(var(--sr-shade), 0));
}

.story-reader-leaf-right::before {
  inset-inline-start: 0;
  background: linear-gradient(to right, rgba(var(--sr-shade), 0.08), rgba(var(--sr-shade), 0));
}

/* The cover sits alone, like a closed keepsake: on the right leaf of a left-bound book, on the
   left one of a right-bound book; the other leaf is the blank. */
.story-reader-page[data-kind='cover'] .story-reader-leaf-blank {
  visibility: hidden;
}

.story-reader-leaf-art {
  align-items: center;
  justify-content: center;
}

/* The page-edge stacks, physical: `data-edge-*` follow the progress — pages read on the left of a
   left-bound book and still to read on the right, the other way round under right binding (the
   reader writes which). */
.story-reader[data-edge-right='1'] {
  --sr-stack-right: 1px 0 0 var(--sr-edge), 2px 0 0 var(--sr-paper), 3px 0 0 var(--sr-edge);
}

.story-reader[data-edge-right='2'] {
  --sr-stack-right:
    1px 0 0 var(--sr-edge), 2px 0 0 var(--sr-paper), 3px 0 0 var(--sr-edge),
    4px 0 0 var(--sr-paper), 5px 0 0 var(--sr-line);
}

.story-reader[data-edge-right='3'] {
  --sr-stack-right:
    1px 0 0 var(--sr-edge), 2px 0 0 var(--sr-paper), 3px 0 0 var(--sr-edge),
    4px 0 0 var(--sr-paper), 5px 0 0 var(--sr-line), 6px 0 0 var(--sr-paper),
    7px 0 0 var(--sr-track);
}

.story-reader[data-edge-left='1'] {
  --sr-stack-left: -1px 0 0 var(--sr-edge), -2px 0 0 var(--sr-paper), -3px 0 0 var(--sr-edge);
}

.story-reader[data-edge-left='2'] {
  --sr-stack-left:
    -1px 0 0 var(--sr-edge), -2px 0 0 var(--sr-paper), -3px 0 0 var(--sr-edge),
    -4px 0 0 var(--sr-paper), -5px 0 0 var(--sr-line);
}

.story-reader[data-edge-left='3'] {
  --sr-stack-left:
    -1px 0 0 var(--sr-edge), -2px 0 0 var(--sr-paper), -3px 0 0 var(--sr-edge),
    -4px 0 0 var(--sr-paper), -5px 0 0 var(--sr-line), -6px 0 0 var(--sr-paper),
    -7px 0 0 var(--sr-track);
}

/* --- pictures: always the whole picture --- */

.story-reader-art {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 100%;
  min-block-size: 0;
  max-block-size: 55%;
  margin-block: 0 16px;
  margin-inline: 0;
}

.story-reader-art-fixed {
  block-size: 55%;
}

.story-reader-leaf-left .story-reader-art,
.story-reader-leaf-right .story-reader-art {
  flex: 1 1 auto;
  block-size: 100%;
  max-block-size: none;
  margin: 0;
}

/* A picture with text below it on the same leaf (the cover): on the right leaf of a left-bound
   spread, the left one of a right-bound spread. */
.story-reader-leaf-right .story-reader-art:not(:last-child),
.story-reader[data-sr-binding='right'] .story-reader-leaf-left .story-reader-art:not(:last-child) {
  flex: 0 1 auto;
  block-size: auto;
  max-block-size: 55%;
  margin-block: 0 14px;
  margin-inline: 0;
}

.story-reader .story-reader-art > * {
  margin: 0;
}

.story-reader .story-reader-art > img {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: 100%;
  margin: 0;
  object-fit: contain;
  border-radius: 4px;
  background: var(--sr-art-bg);
  box-shadow: 0 4px 16px rgba(var(--sr-shade), 0.16);
}

/* A drag that starts on a picture turns the page (FUR-329): inside the layer — the real pages
   and every turn's clones — a picture is never the browser's own drag, its long-press callout
   or a selection, and its frame is not selected. Text stays selectable; touch-action, and so
   pinch-zoom, is the stage's. */
.story-reader img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.story-reader .story-reader-art {
  -webkit-user-select: none;
  user-select: none;
}

/* --- text --- */

/* `overflow-y`: `overflow-block` is not yet in every browser. */
.story-reader-text {
  flex: 1 1 auto;
  box-sizing: border-box;
  inline-size: 100%;
  max-inline-size: 36em;
  min-block-size: 0;
  margin-block: 0;
  margin-inline: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* A scroll container starts its own touch-action: as on the stage, vertical pans scroll it and
     a horizontal one is the reader's (a swipe, a held page), never the browser's. */
  touch-action: pan-y pinch-zoom;
  font-size: 19px;
  line-height: var(--sr-leading);
}

.story-reader[data-mode='spread'] .story-reader-text {
  font-size: clamp(16px, calc(1.6cqh + 8px), 20px);
}

.story-reader-text p {
  margin-block: 0 0.85em;
  margin-inline: 0;
}

.story-reader-text p:last-child {
  margin-block-end: 0;
}

/* Centred blocks keep every line reachable when they overflow: auto margins, never
   `justify-content: center`, which would push the top out of reach. */
.story-reader-cover-text,
.story-reader-dedication,
.story-reader-interlude,
.story-reader-ending,
.story-reader-opener-box {
  display: flex;
  flex-direction: column;
  text-align: center;
}

.story-reader .story-reader-text.story-reader-dedication > :first-child,
.story-reader .story-reader-text.story-reader-interlude > :first-child,
.story-reader .story-reader-text.story-reader-ending > :first-child,
.story-reader .story-reader-text.story-reader-opener-box > :first-child {
  margin-block-start: auto;
}

.story-reader .story-reader-text.story-reader-dedication > :last-child,
.story-reader .story-reader-text.story-reader-interlude > :last-child,
.story-reader .story-reader-text.story-reader-ending > :last-child,
.story-reader .story-reader-text.story-reader-opener-box > :last-child {
  margin-block-end: auto;
}

/* The cover's picture and title sit together in the middle of their leaf. */
.story-reader-page[data-kind='cover'] .story-reader-leaf {
  justify-content: center;
}

.story-reader-page[data-kind='cover'] .story-reader-leaf-right .story-reader-art:not(:last-child),
.story-reader[data-sr-binding='right']
  .story-reader-page[data-kind='cover']
  .story-reader-leaf-left
  .story-reader-art:not(:last-child) {
  max-block-size: 62%;
}

/* A spread's text starts a little way down its leaf, as a printed page does: the right leaf of a
   left-bound book, the left one of a right-bound book (whose right leaf holds the art, an opener
   or the ornament instead, and so no such space). */
.story-reader[data-mode='spread']
  .story-reader-page[data-kind='scene']
  .story-reader-leaf-right
  > .story-reader-text,
.story-reader[data-sr-binding='right'][data-mode='spread']
  .story-reader-page[data-kind='scene']
  .story-reader-leaf-left
  > .story-reader-text {
  padding-block-start: clamp(0px, 5cqh, 56px);
}

.story-reader[data-sr-binding='right'][data-mode='spread']
  .story-reader-page[data-kind='scene']
  .story-reader-leaf-right
  > .story-reader-text {
  padding-block-start: 0;
}

.story-reader[data-mode='spread'] .story-reader-bottom {
  justify-content: center;
  gap: 40px;
}

.story-reader[data-mode='spread'] .story-reader-progress {
  flex: 0 1 260px;
}

.story-reader-cover-text {
  flex: 0 1 auto;
}

.story-reader .story-reader-cover-text [data-reader-part='title'] {
  margin-block: 0 6px;
  margin-inline: 0;
  font-size: clamp(22px, 4cqh, 30px);
  line-height: 1.2;
}

/* A cover note before the title (a label), and one after it (a note). */
.story-reader .story-reader-cover-text .story-reader-kicker {
  align-self: center;
  margin-block: 0 10px;
  margin-inline: 0;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.story-reader .story-reader-cover-text .story-reader-note {
  max-inline-size: none;
  margin-block: 4px 8px;
  margin-inline: 0;
  color: var(--sr-soft);
  font-size: 16px;
  line-height: 1.45;
}

.story-reader-hint {
  margin-block: 6px 0;
  margin-inline: 0;
  color: var(--sr-soft);
  font-family: var(--sr-font-ui);
  font-size: 16px;
}

.story-reader .story-reader-dedication .story-reader-dedication-heading {
  margin-block: 0 14px;
  margin-inline: 0;
  font-size: clamp(22px, 3.4cqh, 28px);
  font-style: italic;
  font-weight: 400;
  color: var(--sr-accent);
}

.story-reader .story-reader-dedication p {
  font-style: italic;
}

/* A chapter opens with its numeral and title atop its first scene. */
.story-reader .story-reader-opener {
  margin-block: 0 16px;
  margin-inline: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
}

.story-reader .story-reader-opener [data-reader-chapter-numeral] {
  display: block;
  margin-block-end: 4px;
  color: var(--sr-numeral-ink);
  font-family: var(--sr-numeral-font);
  font-size: var(--sr-numeral-size);
  font-style: var(--sr-numeral-style);
  font-variant-caps: var(--sr-numeral-caps);
  font-weight: 400;
  letter-spacing: var(--sr-numeral-tracking);
  text-transform: none;
}

.story-reader .story-reader-opener::after {
  content: '';
  display: block;
  inline-size: 56px;
  block-size: 1px;
  margin-block: 12px 0;
  margin-inline: auto;
  background: var(--sr-rule);
}

.story-reader-opener-box .story-reader-opener {
  font-size: clamp(22px, 3.6cqh, 28px);
}

.story-reader-opener-box .story-reader-opener [data-reader-chapter-numeral] {
  font-size: var(--sr-numeral-box-size);
}

.story-reader-continued {
  margin-block: 0 10px;
  margin-inline: 0;
  color: var(--sr-soft);
  font-family: var(--sr-font-ui);
  font-size: 16px;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
}

/* A quiet mark on a text-only scene's first leaf (the left of a left-bound spread, the right of a
   right-bound one). */
.story-reader-ornament {
  position: relative;
  inline-size: 72px;
  block-size: 1px;
  margin: auto;
  background: var(--sr-rule);
}

.story-reader-ornament::after {
  content: '';
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  inline-size: 7px;
  block-size: 7px;
  border: 1px solid var(--sr-rule);
  background: var(--sr-paper);
  transform: translate(-50%, -50%) rotate(45deg);
}

/* --- the ending --- */

.story-reader-ending-heading {
  margin: 0;
  color: var(--sr-ending-ink);
  font-size: clamp(26px, 4.4cqh, 34px);
  font-style: italic;
  font-weight: 400;
  line-height: 1.2;
}

.story-reader-ending-heading::after {
  content: '';
  display: block;
  inline-size: 48px;
  block-size: 1px;
  margin-block: 16px 0;
  margin-inline: auto;
  background: var(--sr-rule);
}

.story-reader-echo {
  margin-block: 16px 0;
  margin-inline: 0;
  color: var(--sr-soft);
  font-size: 17px;
  font-style: italic;
}

.story-reader .story-reader-ending [data-reader-part='credit'] {
  margin-block: 12px 0;
  margin-inline: 0;
  color: var(--sr-soft);
  font-size: 16px;
}

.story-reader-again {
  align-self: center;
  min-block-size: 48px;
  margin-block-start: 26px;
  padding-block: 0;
  padding-inline: 28px;
  border: none;
  border-radius: 999px;
  background: var(--sr-accent);
  color: var(--sr-on-accent);
  font-family: var(--sr-font-ui);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* A host's own call to action (`ending-action`), cloned after "Read again": the host's classes
   style it; the reader gives it only its place and its distance from the button above. */
.story-reader-ending-action {
  align-self: center;
  margin-block-start: 18px;
}

/* --- short boxes (a phone held sideways): slimmer bars. `max-height`: a media feature, there
   is no logical one yet. --- */

@media (max-height: 520px) {
  .story-reader-top {
    block-size: 48px;
  }

  .story-reader-bottom {
    block-size: 54px;
    justify-content: center;
    gap: 24px;
  }

  .story-reader-progress {
    flex: 0 1 auto;
    flex-direction: row;
    gap: 14px;
  }

  .story-reader-meter {
    inline-size: 140px;
  }

  .story-reader-btn {
    inline-size: 44px;
    block-size: 44px;
  }

  .story-reader-leaf-single {
    padding-block: 14px;
    padding-inline: 18px;
  }
}

/* --- turning (the engines set `data-anim` / `data-dir` on the layer and the classes on the two
   pages): a quiet slide, a crossfade, and the cover's first turn around the spine. The
   horizontal moves follow the binding: next comes in from the right of a left-bound book and
   from the left of a right-bound one. --- */

@keyframes story-reader-in-next {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes story-reader-out-next {
  from {
    opacity: 1;
    transform: none;
  }
  to {
    opacity: 0;
    transform: translateX(-24px);
  }
}

@keyframes story-reader-in-prev {
  from {
    opacity: 0;
    transform: translateX(-24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes story-reader-out-prev {
  from {
    opacity: 1;
    transform: none;
  }
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

@keyframes story-reader-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes story-reader-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes story-reader-turn-out {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(-110deg);
    opacity: 0;
  }
}

/* The same turn around a spine on the right (right binding). */
@keyframes story-reader-turn-out-right {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(110deg);
    opacity: 0;
  }
}

.story-reader[data-anim='slide'][data-dir='next'] .story-reader-entering {
  animation: story-reader-in-next var(--sr-slide-ms) ease-out both;
}

.story-reader[data-anim='slide'][data-dir='next'] .story-reader-leaving {
  animation: story-reader-out-next var(--sr-slide-ms) ease-out both;
}

.story-reader[data-anim='slide'][data-dir='prev'] .story-reader-entering {
  animation: story-reader-in-prev var(--sr-slide-ms) ease-out both;
}

.story-reader[data-anim='slide'][data-dir='prev'] .story-reader-leaving {
  animation: story-reader-out-prev var(--sr-slide-ms) ease-out both;
}

/* Right binding: the next page comes in from the left, so each direction takes the other's moves. */
.story-reader[data-sr-binding='right'][data-anim='slide'][data-dir='next'] .story-reader-entering {
  animation: story-reader-in-prev var(--sr-slide-ms) ease-out both;
}

.story-reader[data-sr-binding='right'][data-anim='slide'][data-dir='next'] .story-reader-leaving {
  animation: story-reader-out-prev var(--sr-slide-ms) ease-out both;
}

.story-reader[data-sr-binding='right'][data-anim='slide'][data-dir='prev'] .story-reader-entering {
  animation: story-reader-in-next var(--sr-slide-ms) ease-out both;
}

.story-reader[data-sr-binding='right'][data-anim='slide'][data-dir='prev'] .story-reader-leaving {
  animation: story-reader-out-next var(--sr-slide-ms) ease-out both;
}

.story-reader[data-anim='fade'] .story-reader-entering {
  animation: story-reader-fade-in var(--sr-fade-ms) ease-out both;
}

.story-reader[data-anim='fade'] .story-reader-leaving {
  animation: story-reader-fade-out var(--sr-fade-ms) ease-out both;
}

.story-reader[data-anim='turn'] .story-reader-leaving {
  z-index: 2;
  pointer-events: none;
}

/* The cover's leaf turns about the spine: on its left in a left-bound book (`left center`, the
   right leaf of a spread), on its right in a right-bound one (`right center`, the left leaf). */
.story-reader[data-anim='turn'] .story-reader-leaving .story-reader-leaf-single,
.story-reader[data-anim='turn'] .story-reader-leaving .story-reader-leaf-right {
  transform-origin: left center;
  animation: story-reader-turn-out var(--sr-turn-ms) cubic-bezier(0.4, 0, 0.2, 1) both;
}

.story-reader[data-sr-binding='right'][data-anim='turn']
  .story-reader-leaving
  .story-reader-leaf-single,
.story-reader[data-sr-binding='right'][data-anim='turn']
  .story-reader-leaving
  .story-reader-leaf-left {
  transform-origin: right center;
  animation: story-reader-turn-out-right var(--sr-turn-ms) cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Its blank leaf (the right one, under right binding) stays where it is. */
.story-reader[data-sr-binding='right'][data-anim='turn']
  .story-reader-leaving
  .story-reader-leaf-right {
  animation-name: none;
}

.story-reader[data-anim='turn'] .story-reader-entering {
  animation: story-reader-fade-in var(--sr-turn-ms) ease-out both;
}

/* --- the paper turn (`turn: 'paper'`): one host over the stage while a page turns, is held or
   has a corner lifted; nothing at rest. Its geometry is drawn inline, frame by frame, from the
   stage's box (`engines/paper.ts`). --- */

.story-reader-paper,
.story-reader-paper-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.story-reader-paper {
  z-index: 2;
}

.story-reader-paper * {
  pointer-events: none;
}

.story-reader-paper-flap {
  transform-origin: 0 0;
  will-change: transform, clip-path;
}

.story-reader-paper-under,
.story-reader-paper-front,
.story-reader-paper-flapshade {
  will-change: clip-path;
}

/* The back of a single leaf: the same paper, a shade deeper toward its outer edge (the leaf's
   corners, mirrored). Held left-to-right like the leaves (it lies outside them, on the stage), so
   its corners are physical under any text direction: `to left` and the round left corners are the
   outer edge of a left-bound book's mirrored leaf; under right binding the outer edge is its
   right. */
.story-reader-paper-back {
  position: absolute;
  direction: ltr;
  background: linear-gradient(to left, var(--sr-paper), var(--sr-paper-back));
  border-start-start-radius: 12px;
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  border-end-start-radius: 12px;
}

.story-reader[data-sr-binding='right'] .story-reader-paper-back {
  background: linear-gradient(to right, var(--sr-paper), var(--sr-paper-back));
  border-start-start-radius: 4px;
  border-start-end-radius: 12px;
  border-end-end-radius: 12px;
  border-end-start-radius: 4px;
}

/* The inside of the cover is paper too, whatever the page at rest hides. */
.story-reader-paper-flap .story-reader-page .story-reader-leaf-blank {
  visibility: visible;
}

/* A page held by the pointer is not text to select; a lifted corner can be taken. */
.story-reader[data-drag] {
  cursor: grabbing;
  -webkit-user-select: none;
  user-select: none;
}

.story-reader[data-peel] .story-reader-stage {
  cursor: grab;
}

/* --- the stage layout (`layout: 'stage'`): the pages as large as the screen allows, with a
   little air, on a desk; one bar below them — the progress over a page slider, the full-screen
   toggle and close — and, with a fine pointer and the room, the arrows beside the pages (on a
   touch screen or a short one they stay in the bar). The lone cover sits in the middle of a
   spread, as a closed cover does; the paper turn slides the spread to its place as it opens.
   The classic layout above is untouched by all of it. --- */

@keyframes story-reader-stage-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.story-reader[data-sr-layout='stage'] {
  background:
    radial-gradient(
      ellipse 72% 68% at 50% 46%,
      rgba(var(--sr-stage-glow), var(--sr-stage-glow-alpha)),
      rgba(var(--sr-stage-glow), calc(var(--sr-stage-glow-alpha) * 0.35)) 48%,
      rgba(var(--sr-stage-glow), 0) 75%
    ),
    radial-gradient(
      ellipse 120% 110% at 50% 44%,
      rgba(var(--sr-stage-rim), 0) 42%,
      rgba(var(--sr-stage-rim), var(--sr-stage-rim-alpha)) 100%
    ),
    var(--sr-stage-desk);
}

.story-reader[data-sr-layout='stage'] .story-reader-stage {
  margin-block: var(--sr-stage-air-block) clamp(6px, 1.4vh, 18px);
  margin-inline: var(--sr-stage-air-inline);
  animation: story-reader-stage-in var(--sr-stage-in-ms) cubic-bezier(0.22, 0.61, 0.36, 1) backwards;
}

/* Two 3:4 pages as tall as the stage, narrower only when the width runs out. */
.story-reader[data-sr-layout='stage'] .story-reader-leaf-left,
.story-reader[data-sr-layout='stage'] .story-reader-leaf-right {
  inline-size: min(50cqw, 75cqh);
  padding-block: clamp(14px, 6.5cqh, 64px);
  padding-inline: clamp(18px, 4.2cqh, 52px);
}

/* The leaves are lifted off the desk by a shadow below and outward, never across the spine. */
.story-reader[data-sr-layout='stage'] .story-reader-leaf-left {
  box-shadow:
    var(--sr-stack-left),
    -14px 20px 38px -14px rgba(var(--sr-stage-cast), 0.7),
    0 30px 60px -28px rgba(var(--sr-stage-cast), 0.8);
}

.story-reader[data-sr-layout='stage'] .story-reader-leaf-right {
  box-shadow:
    var(--sr-stack-right),
    14px 20px 38px -14px rgba(var(--sr-stage-cast), 0.7),
    0 30px 60px -28px rgba(var(--sr-stage-cast), 0.8);
}

.story-reader[data-sr-layout='stage'] .story-reader-leaf-single {
  flex: 0 1 auto;
  inline-size: min(100cqw, 75cqh);
  max-inline-size: none;
  box-shadow:
    var(--sr-stack-right),
    0 20px 44px -16px rgba(var(--sr-stage-cast), 0.75);
}

.story-reader[data-sr-layout='stage'][data-sr-binding='right'] .story-reader-leaf-single {
  box-shadow:
    var(--sr-stack-left),
    0 20px 44px -16px rgba(var(--sr-stage-cast), 0.75);
}

/* The gutter: the paper's own shade at the spine, deepest in the fold. */
.story-reader[data-sr-layout='stage'] .story-reader-leaf-left::after {
  inline-size: 12%;
  background: linear-gradient(
    to left,
    rgba(var(--sr-paper-fold), 0.26),
    rgba(var(--sr-paper-fold), 0.1) 16%,
    rgba(var(--sr-paper-fold), 0.03) 55%,
    rgba(var(--sr-paper-fold), 0)
  );
}

.story-reader[data-sr-layout='stage'] .story-reader-leaf-right::before {
  inline-size: 9%;
  background: linear-gradient(
    to right,
    rgba(var(--sr-paper-fold), 0.2),
    rgba(var(--sr-paper-fold), 0.07) 22%,
    rgba(var(--sr-paper-fold), 0)
  );
}

/* One large page (a portrait screen): the type grows with the page. */
.story-reader[data-sr-layout='stage'][data-mode='single'] .story-reader-text {
  font-size: clamp(19px, min(2.7cqw, 1.45cqh), 28px);
}

/* A lone cover sits in the middle of the spread: half a leaf left of its place in a left-bound
   book (its cover on the right leaf), half a leaf right in a right-bound one. */
.story-reader[data-sr-layout='stage'][data-mode='spread']
  .story-reader-stage
  > .story-reader-page[data-kind='cover'] {
  transform: translateX(calc(-0.5 * min(50cqw, 75cqh)));
  transform: translateX(round(calc(-0.5 * min(50cqw, 75cqh)), 1px));
}

.story-reader[data-sr-layout='stage'][data-sr-binding='right'][data-mode='spread']
  .story-reader-stage
  > .story-reader-page[data-kind='cover'] {
  transform: translateX(calc(0.5 * min(50cqw, 75cqh)));
  transform: translateX(round(calc(0.5 * min(50cqw, 75cqh)), 1px));
}

/* --- the stage's bar --- */

.story-reader[data-sr-layout='stage'] .story-reader-bottom {
  block-size: 72px;
  gap: 10px;
  padding-inline: 16px;
  justify-content: flex-start;
  color: var(--sr-stage-ink);
}

.story-reader[data-sr-layout='stage'] .story-reader-progress {
  flex: 1 1 auto;
  gap: 0;
}

/* The label over the slider, never in the way of a click on it. */
.story-reader[data-sr-layout='stage'] .story-reader-count {
  position: relative;
  z-index: 1;
  margin-block: 0 -12px;
  color: var(--sr-stage-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.story-reader-slot {
  display: flex;
  align-items: center;
  inline-size: min(440px, 100%);
  min-inline-size: 60px;
}

.story-reader-tools {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

/* The slider: a thin rounded track filled up to the reader's place; its handle shows while it
   is in use. (`[type='range']`: outranks a host's rule for its text fields.) */
.story-reader .story-reader-slider[type='range'] {
  box-sizing: border-box;
  inline-size: 100%;
  block-size: 44px;
  min-block-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.story-reader-slider::-webkit-slider-runnable-track {
  block-size: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--sr-stage-meter) var(--sr-slider-fill),
    var(--sr-stage-track) var(--sr-slider-fill)
  );
}

.story-reader-slider::-moz-range-track {
  block-size: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--sr-stage-meter) var(--sr-slider-fill),
    var(--sr-stage-track) var(--sr-slider-fill)
  );
}

/* Under right binding the slider runs right to left (the reader gives it `dir="rtl"`): it fills
   from the right. */
.story-reader[data-sr-binding='right'] .story-reader-slider::-webkit-slider-runnable-track {
  background: linear-gradient(
    to left,
    var(--sr-stage-meter) var(--sr-slider-fill),
    var(--sr-stage-track) var(--sr-slider-fill)
  );
}

.story-reader[data-sr-binding='right'] .story-reader-slider::-moz-range-track {
  background: linear-gradient(
    to left,
    var(--sr-stage-meter) var(--sr-slider-fill),
    var(--sr-stage-track) var(--sr-slider-fill)
  );
}

.story-reader-slider::-webkit-slider-thumb {
  inline-size: 16px;
  block-size: 16px;
  margin-block-start: -6px;
  border: 3px solid var(--sr-paper);
  border-radius: 50%;
  background: var(--sr-stage-meter);
  box-shadow: 0 2px 6px rgba(var(--sr-stage-cast), 0.5);
  opacity: 0;
  transition: opacity var(--sr-meter-ms) ease-out;
  -webkit-appearance: none;
  appearance: none;
}

.story-reader-slider::-moz-range-thumb {
  inline-size: 10px;
  block-size: 10px;
  border: 3px solid var(--sr-paper);
  border-radius: 50%;
  background: var(--sr-stage-meter);
  box-shadow: 0 2px 6px rgba(var(--sr-stage-cast), 0.5);
  opacity: 0;
  transition: opacity var(--sr-meter-ms) ease-out;
}

.story-reader-slider:hover::-webkit-slider-thumb,
.story-reader-slider:active::-webkit-slider-thumb,
.story-reader-slider:focus-visible::-webkit-slider-thumb {
  opacity: 1;
}

.story-reader-slider:hover::-moz-range-thumb,
.story-reader-slider:active::-moz-range-thumb,
.story-reader-slider:focus-visible::-moz-range-thumb {
  opacity: 1;
}

.story-reader .story-reader-slider[type='range']:focus {
  outline: none;
}

.story-reader .story-reader-slider[type='range']:focus-visible {
  outline: 2px solid var(--sr-stage-ink);
  outline-offset: 2px;
  border-radius: 6px;
}

/* The bar's round buttons on the desk: previous on paper, next in the accent, full screen and
   close in a quiet wash. */
.story-reader[data-sr-layout='stage'] .story-reader-btn {
  inline-size: 44px;
  block-size: 44px;
  border-color: var(--sr-stage-btn-line);
  background: var(--sr-stage-btn);
  color: var(--sr-stage-ink);
  box-shadow: none;
}

.story-reader[data-sr-layout='stage'] .story-reader-btn:hover {
  background: var(--sr-stage-btn-hover);
}

.story-reader[data-sr-layout='stage'] .story-reader-prev {
  border-color: var(--sr-line);
  background: var(--sr-paper);
  color: var(--sr-ink);
  box-shadow: 0 6px 18px rgba(var(--sr-stage-cast), 0.45);
}

.story-reader[data-sr-layout='stage'] .story-reader-next {
  border-color: var(--sr-next-border);
  background: var(--sr-next-bg);
  color: var(--sr-next-ink);
  box-shadow: 0 6px 18px rgba(var(--sr-stage-cast), 0.5);
}

.story-reader[data-sr-layout='stage'] .story-reader-btn:disabled {
  border-color: var(--sr-stage-btn-line);
  background: transparent;
  color: var(--sr-stage-soft);
  box-shadow: none;
  opacity: 0.4;
}

.story-reader[data-sr-layout='stage'] .story-reader-btn:focus-visible {
  outline: 3px solid var(--sr-stage-meter);
  outline-offset: 3px;
}

/* Full screen: four corner marks pointing out; while full screen, pointing in. Drawn: no icon
   file, no glyph. */
.story-reader-icon-fs::before {
  content: '';
  position: absolute;
  inset: 1px;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 0 / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 100% / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 100% / 2px 7px no-repeat;
}

.story-reader[data-fullscreen] .story-reader-icon-fs::before {
  background:
    linear-gradient(currentColor, currentColor) 0 5px / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 5px 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% 5px / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) calc(100% - 5px) 0 / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 0 calc(100% - 5px) / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 5px 100% / 2px 7px no-repeat,
    linear-gradient(currentColor, currentColor) 100% calc(100% - 5px) / 7px 2px no-repeat,
    linear-gradient(currentColor, currentColor) calc(100% - 5px) 100% / 2px 7px no-repeat;
}

/* A wide screen with a fine pointer: the arrows sit beside the pages, centred on them
   (`--sr-book-*`, written by the reader), with room kept for them; the bar centres the progress.
   `min-width` / `min-height`: media features, there are no logical ones yet. The arrows' `left`
   is physical, like the `--sr-book-*` measurements it is made of: previous beside the book's
   left edge and next beside its right in a left-bound book, the other way round in a
   right-bound one. */
@media (min-width: 700px) and (min-height: 521px) and (hover: hover) and (pointer: fine) {
  .story-reader[data-sr-layout='stage'] .story-reader-stage {
    margin-inline: max(
      var(--sr-stage-air-inline),
      calc(var(--sr-stage-arrow) + 2 * var(--sr-stage-arrow-gap))
    );
  }

  .story-reader[data-sr-layout='stage'] .story-reader-bottom {
    display: grid;
    grid-template-columns: 1fr minmax(200px, 440px) 1fr;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-progress {
    grid-column: 2;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-tools {
    grid-column: 3;
    justify-self: end;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-prev,
  .story-reader[data-sr-layout='stage'] .story-reader-next {
    position: absolute;
    z-index: 3;
    inset-block-start: var(--sr-book-mid);
    inline-size: var(--sr-stage-arrow);
    block-size: var(--sr-stage-arrow);
    transform: translateY(-50%);
  }

  .story-reader[data-sr-layout='stage'] .story-reader-prev,
  .story-reader[data-sr-layout='stage'][data-sr-binding='right'] .story-reader-next {
    left: max(8px, calc(var(--sr-book-left) - var(--sr-stage-arrow-gap) - var(--sr-stage-arrow)));
  }

  .story-reader[data-sr-layout='stage'] .story-reader-next,
  .story-reader[data-sr-layout='stage'][data-sr-binding='right'] .story-reader-prev {
    left: min(
      calc(100% - 8px - var(--sr-stage-arrow)),
      calc(var(--sr-book-right) + var(--sr-stage-arrow-gap))
    );
  }

  .story-reader[data-sr-layout='stage'] .story-reader-prev:disabled,
  .story-reader[data-sr-layout='stage'] .story-reader-next:disabled {
    visibility: hidden;
  }
}

/* A short screen (a phone held sideways): a slimmer bar, the label beside the slider. */
@media (max-height: 520px) {
  .story-reader[data-sr-layout='stage'] .story-reader-bottom {
    block-size: 56px;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-progress {
    flex-direction: row;
    justify-content: center;
    gap: 14px;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-count {
    margin: 0;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-stage {
    margin-block-start: clamp(8px, 3vh, 16px);
  }
}

/* A short, wide screen: the pages widen past 3:4 to fill it rather than leave empty bands. */
@media (max-height: 520px) and (min-aspect-ratio: 3/2) {
  .story-reader[data-sr-layout='stage'] .story-reader-leaf-left,
  .story-reader[data-sr-layout='stage'] .story-reader-leaf-right {
    inline-size: min(50cqw, 120cqh);
    padding-block: clamp(10px, 5cqh, 28px);
    padding-inline: clamp(16px, 4cqh, 28px);
  }

  .story-reader[data-sr-layout='stage'][data-mode='spread']
    .story-reader-stage
    > .story-reader-page[data-kind='cover'] {
    transform: translateX(calc(-0.5 * min(50cqw, 120cqh)));
    transform: translateX(round(calc(-0.5 * min(50cqw, 120cqh)), 1px));
  }

  .story-reader[data-sr-layout='stage'][data-sr-binding='right'][data-mode='spread']
    .story-reader-stage
    > .story-reader-page[data-kind='cover'] {
    transform: translateX(calc(0.5 * min(50cqw, 120cqh)));
    transform: translateX(round(calc(0.5 * min(50cqw, 120cqh)), 1px));
  }
}

/* A narrow screen (a phone): everything a little tighter. */
@media (max-width: 699px) {
  .story-reader[data-sr-layout='stage'] .story-reader-bottom {
    gap: 6px;
    padding-inline: 8px;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-tools {
    gap: 4px;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-slot {
    min-inline-size: 40px;
  }

  .story-reader[data-sr-layout='stage'] .story-reader-stage {
    margin-block: clamp(10px, 3vh, 28px) 0;
    margin-inline: clamp(10px, 3.5vw, 20px);
  }
}

/* Reduced motion — the visitor's preference, or the host's `reducedMotion: 'force'`. */
@media (prefers-reduced-motion: reduce) {
  .story-reader *,
  .story-reader *::before,
  .story-reader *::after {
    animation: none !important;
    transition: none !important;
  }
}

.story-reader[data-sr-motion='reduce'] *,
.story-reader[data-sr-motion='reduce'] *::before,
.story-reader[data-sr-motion='reduce'] *::after {
  animation: none !important;
  transition: none !important;
}
