.pagination-probe {
  position: fixed !important;
  top: 0;
  left: -200vw;
  z-index: -1;
  display: block !important;
  visibility: hidden;
  overflow: hidden;
  pointer-events: none;
}

/* Keep paged layouts at a printed-book proportion and scale them with the
   usable viewport. At a typical 1080p desktop this resolves close to
   900 x 675 for a spread; at 1440p it grows toward 1200 x 900 instead of
   remaining physically small. */
.book-stage {
  width: min(100%, clamp(900px, 100vh, 1200px));
}

.book-spread.single {
  max-width: clamp(450px, 50vh, 600px);
}

.book-page {
  min-height: clamp(675px, 75vh, 900px);
}

.book-spread.single .book-page:nth-child(2),
.book-spread.continuous .book-page:nth-child(2) {
  display: none;
}

.book-spread.continuous {
  margin-inline: auto;
}

.book-spread.continuous .book-page:first-child {
  display: block;
  min-height: auto;
}

.book-page.is-empty {
  color: transparent;
}

.reader-chapter-title,
.reader-back-matter-title {
  width: 100%;
}

.chapter-title-page,
.back-matter-title-page {
  display: grid;
  place-items: center;
  text-align: center;
}

.chapter-title-page .reader-chapter-title,
.back-matter-title-page .reader-back-matter-title {
  max-width: 34rem;
}

.reader-prose {
  text-wrap: pretty;
}

.reader-back-matter-prose {
  margin: 0 0 1.05rem;
  text-wrap: pretty;
}

.reader-back-matter-link {
  margin: .75rem 0 1.2rem;
  text-align: center;
}

.reader-back-matter-link a {
  color: var(--text);
  font-weight: 700;
  text-decoration-thickness: .08em;
  text-underline-offset: .2em;
}

.reader-back-matter-signature {
  margin: 2.25rem 0 0;
  text-align: right;
  font-style: italic;
}

.reader-scene-break {
  min-height: 3.2rem;
  display: grid;
  place-items: center;
  margin: 1.5rem 0;
  color: var(--metal);
  font-size: .85rem;
  letter-spacing: .3em;
}

.reader-scene-break::before,
.reader-scene-break::after {
  content: "";
  width: min(34%, 7rem);
  height: 1px;
  background: var(--border-soft);
}

.reader-scene-break {
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
}

.reader-contents {
  width: 100%;
}

.reader-contents--compact {
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--border-soft);
}

.continuous-page {
  min-height: auto;
}

.reader-continuous-chapter {
  padding-block: 4rem 2rem;
}

.reader-continuous-chapter + .reader-continuous-chapter {
  margin-top: 2rem;
  border-top: 1px solid var(--border-soft);
}

.reader-continuous-chapter .reader-chapter-title {
  margin-bottom: 3rem;
}

.reader-continuous-back-matter {
  margin-top: 2rem;
  padding-block: 4rem 2rem;
  border-top: 1px solid var(--border-soft);
}

.reader-continuous-back-matter .reader-back-matter-title {
  margin-bottom: 3rem;
}

.reader-illustration {
  width: 100%;
  margin: 1.75rem 0;
  display: grid;
  gap: .7rem;
}

.reader-illustration-media {
  display: block;
  width: 100%;
  aspect-ratio: var(--reader-illustration-ratio, 3 / 2);
  border: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface) 82%, var(--page-surface));
  object-fit: contain;
}

.reader-illustration-placeholder {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--metal);
}

.reader-illustration-placeholder::before,
.reader-illustration-placeholder::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 1px solid color-mix(in srgb, var(--metal) 20%, transparent);
  pointer-events: none;
}

.reader-illustration-placeholder::before {
  transform: rotate(45deg) scale(.72);
}

.reader-illustration-placeholder::after {
  inset: 27% 14%;
  border-width: 1px 0;
}

.reader-illustration-placeholder-mark {
  position: relative;
  z-index: 1;
  font-size: clamp(2rem, 7vw, 4.2rem);
  opacity: .72;
}

.reader-illustration figcaption {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
  text-align: center;
}

.illustration-page {
  display: grid;
  place-items: center;
}

.illustration-page .reader-illustration {
  height: 100%;
  margin: 0;
  align-content: center;
}

.illustration-page .reader-illustration-media {
  width: auto;
  max-width: 100%;
  height: calc(clamp(675px, 75vh, 900px) - clamp(118px, 12vw, 158px));
  max-height: 100%;
}

.book-spread.continuous .reader-illustration {
  width: min(100%, 42rem);
  margin: 3rem auto;
}

.book-spread.continuous .reader-illustration--full-page .reader-illustration-media,
.book-spread.continuous .reader-illustration--before-title .reader-illustration-media {
  width: 100%;
  height: auto;
}

.reader-pager {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.reader-page-nav {
  width: 36px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--metal);
}

.reader-page-nav:hover:not(:disabled),
.reader-page-nav:focus-visible {
  border-color: var(--metal);
  color: var(--text);
}

.book-spread.continuous + .pagination-probe + .reader-status .reader-page-nav {
  visibility: hidden;
}

@media (max-width: 980px) {
  .book-stage {
    width: min(100%, 620px);
  }

  .book-spread:not(.continuous) {
    max-width: 460px;
  }

  .book-spread.continuous .book-page:nth-child(2) {
    display: none;
  }
}

@media (max-width: 700px) {
  .book-stage {
    width: 100%;
  }

  .book-spread:not(.continuous) {
    width: min(100%, 430px);
  }

  .book-page {
    min-height: min(675px, 78vh);
  }

  .illustration-page .reader-illustration-media {
    height: calc(min(675px, 78vh) - 96px);
  }

  .reader-status {
    align-items: center;
  }

  .reader-pager {
    min-width: 0;
  }

  [data-reader-position] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reader-continuous-chapter {
    padding-block: 3rem 1.5rem;
  }

  .reader-continuous-back-matter {
    padding-block: 3rem 1.5rem;
  }
}


/* Stable paged Reader geometry */
.book-spread:not(.continuous) {
  aspect-ratio: 4 / 3;
}

.book-spread:not(.continuous) .book-page {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.book-spread.single {
  aspect-ratio: 2 / 3;
}

.contents-continued-heading {
  margin-top: 0 !important;
}

.reader-illustration-media:not(.reader-illustration-placeholder) {
  border: 0;
  background: transparent;
}

.illustration-page {
  overflow: hidden;
}

.illustration-page .reader-illustration {
  width: 100%;
  height: 100%;
  margin: 0;
  align-content: center;
}

.illustration-page .reader-illustration-media {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  border: 0;
  background: transparent;
  object-fit: contain;
}

.reader-illustration-placeholder {
  border: 1px solid var(--border-soft);
}

@media (max-width: 980px) {
  .book-spread:not(.continuous) {
    aspect-ratio: 2 / 3;
  }
}
