/* =========================================================
   Lor Criber — page-level layouts (home + book detail)
   ========================================================= */

/* ---------------- Hero ---------------- */

.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  align-items: center;
  gap: clamp(2rem, 5vw, 4.5rem);
  padding-block: clamp(3rem, 8vw, 6.5rem) clamp(3rem, 7vw, 5.5rem);
}

.hero::before {
  content: '';
  position: absolute;
  top: -30%;
  right: -10%;
  z-index: -1;
  width: 60vw;
  height: 60vw;
  max-width: 780px;
  max-height: 780px;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 16%, transparent),
    transparent 62%
  );
  filter: blur(20px);
  animation: drift 22s var(--ease-out) infinite alternate;
  pointer-events: none;
}

@keyframes drift {
  to {
    transform: translate3d(-6%, 5%, 0) scale(1.12);
  }
}

.hero__title {
  margin-bottom: 1.25rem;
}

/* Word-by-word entrance, staggered from JS */
.hero__title .word {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.5em);
  animation: word-up 0.85s var(--ease-out) forwards;
  animation-delay: var(--d, 0ms);
}

@keyframes word-up {
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hero__title .word {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

.hero__title em {
  font-style: italic;
  color: var(--accent);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 2rem;
}

.hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(1.5rem, 4vw, 3rem);
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}

.stat__num {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
}

.stat__label {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* Fanned stack of covers — each layer parallaxes at its own rate */
.hero__stack {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(320px, 46vw, 520px);
  perspective: 1400px;
}

.hero__stack .cover {
  container-type: inline-size;
  position: absolute;
  width: clamp(130px, 19vw, 200px);
  transform: translate3d(var(--x, 0), var(--y, 0), 0) rotate(var(--r, 0deg));
  transition: transform var(--dur-slow) var(--ease-out);
}

.hero__stack .cover:nth-child(1) {
  --x: -80%;
  --y: 2%;
  --r: -12deg;
  z-index: 1;
  filter: brightness(0.88);
}

.hero__stack .cover:nth-child(2) {
  --x: 0%;
  --y: -12%;
  --r: 1deg;
  z-index: 3;
}

.hero__stack .cover:nth-child(3) {
  --x: 78%;
  --y: 6%;
  --r: 13deg;
  z-index: 2;
  filter: brightness(0.92);
}

/* Exactly two covers: the three-cover offsets above would hang the pair off to
   the left, so they get their own balanced spread. The published title leads. */
.hero__stack .cover:first-child:nth-last-child(2) {
  --x: -42%;
  --y: -4%;
  --r: -8deg;
  z-index: 3;
  filter: none;
}

.hero__stack .cover:first-child:nth-last-child(2) ~ .cover {
  --x: 42%;
  --y: 4%;
  --r: 9deg;
  z-index: 2;
  filter: brightness(0.92);
}

/* A lone cover sits centred and upright — the fan needs siblings to read.
   Declared after the nth-child rules so it wins on source order. */
.hero__stack .cover:only-child {
  --x: 0%;
  --y: 0%;
  --r: 0deg;
  width: clamp(180px, 26vw, 300px);
  filter: none;
}

.hero__stack .cover:hover {
  z-index: 4;
  transform: translate3d(var(--x, 0), calc(var(--y, 0%) - 14px), 0) rotate(0deg)
    scale(1.05);
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero__stack {
    order: -1;
    min-height: 300px;
  }
}

/* ---------------- Marquee strip ---------------- */

.marquee {
  padding-block: 1rem;
  border-block: 1px solid var(--line);
  background: var(--bg-sunken);
  overflow: hidden;
  white-space: nowrap;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}

.marquee__track {
  display: inline-flex;
  gap: 3rem;
  animation: marquee 38s linear infinite;
}

.marquee:hover .marquee__track {
  animation-play-state: paused;
}

.marquee span {
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-style: italic;
  color: var(--ink-muted);
}

@keyframes marquee {
  to {
    transform: translateX(-50%);
  }
}

/* ---------------- Author section ---------------- */

.author {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  align-items: center;
  gap: clamp(2rem, 5vw, 4rem);
  padding: clamp(2rem, 5vw, 3.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

.author__portrait {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--accent-2), var(--accent));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.author__portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.author__portrait span {
  font-family: var(--font-display);
  font-size: clamp(3rem, 9vw, 6rem);
  color: rgb(255 255 255 / 92%);
  letter-spacing: -0.04em;
}

.author__portrait::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -40deg,
    rgb(255 255 255 / 6%) 0 3px,
    transparent 3px 8px
  );
}

.author__portrait:has(img)::after {
  content: none;
}

.author__socials {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.75rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-soft);
  transition: transform var(--dur) var(--ease-spring), color var(--dur-fast),
    border-color var(--dur-fast);
}

.icon-btn:hover {
  transform: translateY(-4px);
  color: var(--accent);
  border-color: var(--accent);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 820px) {
  .author {
    grid-template-columns: 1fr;
  }

  .author__portrait {
    max-width: 260px;
  }
}

/* ---------------- Newsletter ---------------- */

.newsletter {
  padding: clamp(2rem, 5vw, 3.5rem);
  border-radius: var(--radius-lg);
  background: var(--ink);
  color: var(--bg);
  text-align: center;
}

.newsletter h2 {
  margin-bottom: 0.75rem;
}

.newsletter p {
  max-width: 48ch;
  margin-inline: auto;
  color: color-mix(in srgb, var(--bg) 72%, transparent);
}

.newsletter__form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  max-width: 460px;
  margin: 2rem auto 0;
}

.newsletter__form input {
  flex: 1 1 220px;
  padding: 0.9rem 1.25rem;
  border: 1px solid color-mix(in srgb, var(--bg) 24%, transparent);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--bg) 8%, transparent);
  color: var(--bg);
}

.newsletter__form input::placeholder {
  color: color-mix(in srgb, var(--bg) 50%, transparent);
}

.newsletter__form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* =========================================================
   Book detail page
   ========================================================= */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  height: 3px;
  width: 100%;
  transform: scaleX(var(--p, 0));
  transform-origin: left;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: transform 90ms linear;
}

.book-hero {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: clamp(2rem, 5vw, 4rem);
  padding-block: clamp(2rem, 5vw, 4rem);
}

.book-hero__media {
  container-type: inline-size;
  position: sticky;
  top: calc(var(--header-h) + 2rem);
  align-self: start;
  perspective: 1200px;
}

.book-hero__media .cover {
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform var(--dur) var(--ease-out);
  will-change: transform;
}

.book-hero__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: var(--step--1);
  color: var(--ink-muted);
}

.book-hero__meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.book-hero__meta svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.75;
}

.book-hero h1 {
  font-size: var(--step-3);
  margin-bottom: 0.5rem;
}

.book-hero__tagline {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

/* Purchase panel */
.buy-panel {
  display: grid;
  gap: 0.9rem;
  margin-top: 2rem;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.buy-panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.buy-panel__label {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.buy-option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.buy-option__info strong {
  display: block;
  font-size: var(--step-0);
}

.buy-option__info small {
  color: var(--ink-muted);
}

.buy-panel__note {
  font-size: 0.78rem;
  color: var(--ink-muted);
  text-align: center;
}

@media (max-width: 820px) {
  .book-hero {
    grid-template-columns: 1fr;
  }

  .book-hero__media {
    position: static;
    max-width: 240px;
  }
}

/* Synopsis */
.prose p + p {
  margin-top: 1.15em;
}

.prose {
  max-width: var(--measure);
  color: var(--ink-soft);
  font-size: var(--step-0);
  line-height: 1.75;
}

.prose--dropcap > p:first-of-type::first-letter {
  float: left;
  margin: 0.05em 0.12em 0 0;
  font-family: var(--font-display);
  font-size: 3.2em;
  line-height: 0.82;
  color: var(--accent);
}

.excerpt {
  position: relative;
  max-width: var(--measure);
  margin-top: 2.5rem;
  padding: 2rem 2rem 2rem 3.5rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg-sunken);
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-style: italic;
  line-height: 1.5;
  white-space: pre-line;
}

.excerpt::before {
  content: '\201C';
  position: absolute;
  top: 0.1em;
  left: 0.35rem;
  font-family: var(--font-display);
  font-size: 4rem;
  line-height: 1;
  color: var(--accent);
  opacity: 0.35;
}

/* Details table */
.details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  overflow: hidden;
}

.details div {
  padding: 1.15rem 1.25rem;
  background: var(--bg-elevated);
  transition: background-color var(--dur-fast);
}

.details div:hover {
  background: var(--bg-sunken);
}

.details dt {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.details dd {
  margin: 0.35rem 0 0;
  font-weight: 500;
}

/* Reviews layout */
.reviews {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: clamp(2rem, 4vw, 3.5rem);
  align-items: start;
}

.reviews__summary {
  position: sticky;
  top: calc(var(--header-h) + 2rem);
  padding: 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  text-align: center;
}

.reviews__score {
  font-family: var(--font-display);
  font-size: var(--step-4);
  line-height: 1;
  letter-spacing: -0.04em;
}

.reviews__bars {
  display: grid;
  gap: 0.4rem;
  margin-top: 1.5rem;
  text-align: left;
}

.bar-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr 2rem;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.bar {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--gold);
  transition: width 900ms var(--ease-out);
}

.reviews__list {
  display: grid;
  gap: 1rem;
}

.review-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.75rem;
  padding: 1.5rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.review-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 820px) {
  .reviews {
    grid-template-columns: 1fr;
  }

  .reviews__summary {
    position: static;
  }

  .review-form__row {
    grid-template-columns: 1fr;
  }
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--ink-muted);
  transition: color var(--dur-fast);
}

.back-link svg {
  width: 15px;
  height: 15px;
  transition: transform var(--dur) var(--ease-spring);
}

.back-link:hover {
  color: var(--accent);
}

.back-link:hover svg {
  transform: translateX(-4px);
}

/* Not-found state */
.not-found {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1rem;
  min-height: 60svh;
  text-align: center;
}

/* Empty catalogue state */
.empty-state {
  grid-column: 1 / -1;
  padding: 4rem 1rem;
  text-align: center;
  color: var(--ink-muted);
}

/* =========================================================
   Escritos — shelf
   ========================================================= */

.writings-head {
  max-width: var(--wrap-narrow);
}

.writing-shelf {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(1.5rem, 5vw, 4rem);
  margin-top: clamp(2.5rem, 6vw, 4.5rem);
}

.writing-card__link {
  display: block;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: translate var(--dur) var(--ease-out);
}

.writing-card__link:hover,
.writing-card__link:focus-visible {
  translate: 0 -8px;
}

/* ---- The closed book ---- */

.writing-card__book {
  position: relative;
  display: block;
  width: clamp(150px, 20vw, 230px);
  aspect-ratio: 5 / 7;
  perspective: 1100px;
}

.writing-card__face {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: clamp(1.1rem, 2vw, 1.6rem) clamp(0.9rem, 1.6vw, 1.3rem) clamp(1.1rem, 2vw, 1.6rem)
    clamp(1.4rem, 2.4vw, 1.9rem);
  border-radius: 4px 10px 10px 4px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 14%), transparent 55%),
    var(--accent-book, var(--accent));
  box-shadow: var(--shadow-cover);
  color: #fff;
  transform-origin: left center;
  transition:
    transform var(--dur-slow) var(--ease-out),
    box-shadow var(--dur-slow) var(--ease-out);
}

/* The spine strip and the paper edge sell the object as a book. */
.writing-card__spine {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 3;
  width: 12px;
  border-radius: 4px 0 0 4px;
  background: linear-gradient(90deg, rgb(0 0 0 / 32%), rgb(0 0 0 / 6%));
  pointer-events: none;
}

.writing-card__pages {
  position: absolute;
  z-index: 0;
  top: 5px;
  bottom: 5px;
  right: -7px;
  width: 8px;
  border-radius: 0 3px 3px 0;
  background: repeating-linear-gradient(to right, #f6efe6 0 1px, #d9cdbe 1px 2px);
  box-shadow: var(--shadow-sm);
}

.writing-card__tag {
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.85;
}

.writing-card__title {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 0.9rem + 0.6vw, 1.45rem);
  line-height: 1.18;
  text-wrap: balance;
}

.writing-card__rule {
  display: block;
  width: 30px;
  height: 1px;
  margin-top: auto;
  background: rgb(255 255 255 / 55%);
}

.writing-card__author {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.9;
}

/* The cover cracks open a few degrees on hover — the promise of the reader. */
@media (hover: hover) and (pointer: fine) {
  .writing-card__link:hover .writing-card__face,
  .writing-card__link:focus-visible .writing-card__face {
    transform: rotateY(-26deg);
    box-shadow: var(--shadow-lg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .writing-card__link,
  .writing-card__face {
    transition: none;
  }

  .writing-card__link:hover {
    translate: none;
  }

  .writing-card__link:hover .writing-card__face {
    transform: none;
  }
}

/* =========================================================
   Escritos — flipbook reader
   ========================================================= */

.reader-view {
  padding-block: clamp(1.25rem, 3vw, 2.5rem) clamp(2rem, 5vw, 4rem);
  /* A leaf mid-turn swings past the book; it must not widen the page. */
  overflow-x: clip;
}

.flipbook {
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 2.5vw, 1.75rem);
  width: min(100% - 2 * var(--gutter), var(--wrap));
  margin-inline: auto;
}

.flipbook__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.flipbook__close {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--ink-soft);
  font: inherit;
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.flipbook__close:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.flipbook__close svg {
  width: 18px;
  height: 18px;
}

.flipbook__now {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem;
  text-align: right;
}

.flipbook__now-title {
  font-family: var(--font-display);
  font-size: var(--step-1);
}

.flipbook__now-meta {
  font-size: var(--step--1);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Stage and book ---- */

.flipbook__stage {
  display: grid;
  place-items: center;
}

/* The frame is exactly the size of the book, so the page arrows can sit in
   its corners without knowing anything about the 3D inside. */
.flipbook__frame {
  position: relative;
  width: min(100%, calc(min(70svh, 620px) * 10 / 7));
  aspect-ratio: 10 / 7;
  perspective: 2600px;
  perspective-origin: 50% 40%;
}

.flipbook[data-mode='single'] .flipbook__frame {
  width: min(100%, calc(min(66svh, 560px) * 5 / 7));
  aspect-ratio: 5 / 7;
}

/* Pagination is measured, so the book has no pages for a frame or two. */
.flipbook:not([data-ready]) .flipbook__stage {
  opacity: 0;
}

.flipbook[data-ready] .flipbook__stage {
  animation: flipbook-in var(--dur-slow) var(--ease-out) both;
}

@keyframes flipbook-in {
  from {
    opacity: 0;
    scale: 0.98;
  }

  to {
    opacity: 1;
    scale: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flipbook[data-ready] .flipbook__stage {
    animation: none;
  }
}

.flipbook__book {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  border-radius: 6px;
  background: var(--bg-sunken);
  box-shadow: var(--shadow-lg);
}

.flipbook__spine {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 26px;
  translate: -50% 0;
  z-index: 60;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgb(0 0 0 / 0%) 0%,
    rgb(0 0 0 / 16%) 42%,
    rgb(0 0 0 / 22%) 50%,
    rgb(0 0 0 / 16%) 58%,
    rgb(0 0 0 / 0%) 100%
  );
}

.flipbook[data-mode='single'] .flipbook__spine {
  display: none;
}

.flipbook__board {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
}

.flipbook__board--left {
  left: 0;
}

.flipbook__board--right {
  left: 50%;
}

.flipbook[data-mode='single'] .flipbook__board {
  display: none;
}

.flipbook__leaves {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

/* ---- Leaves ---- */

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 900ms var(--ease-out);
}

.flipbook[data-mode='single'] .leaf {
  left: 0;
  width: 100%;
}

.leaf.is-flipped {
  transform: rotateY(-180deg);
}

.leaf__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
}

.leaf__face--back {
  transform: rotateY(180deg);
}

/* A turning leaf catches light on the way over. */
.leaf__face::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 900ms var(--ease-out);
  background: linear-gradient(90deg, rgb(0 0 0 / 15%), transparent 13%);
}

.flipbook[data-mode='single'] .leaf__face::after {
  background: linear-gradient(90deg, rgb(0 0 0 / 15%), transparent 9%);
}

.leaf:not(.is-flipped) .leaf__face--front::after {
  opacity: 1;
}

.leaf.is-flipped .leaf__face--back::after {
  opacity: 1;
  background: linear-gradient(270deg, rgb(0 0 0 / 15%), transparent 13%);
}

/* Jumping with the keyboard or rebuilding on resize should not animate. */
.flipbook__book[data-instant] .leaf,
.flipbook__book[data-instant] .leaf__face::after {
  transition: none;
}

/* ---- Pages ---- */

.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(1.25rem, 2.6vw, 2.4rem) clamp(1.1rem, 2.4vw, 2.2rem);
  background:
    radial-gradient(60% 100% at 0% 50%, rgb(0 0 0 / 5%), transparent 60%),
    var(--bg-elevated);
  color: var(--ink);
}

.leaf__face--back .page,
.flipbook__board--left .page {
  background:
    radial-gradient(60% 100% at 100% 50%, rgb(0 0 0 / 5%), transparent 60%),
    var(--bg-elevated);
}

.page__body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  font-size: clamp(0.9rem, 0.86rem + 0.22vw, 1.02rem);
  line-height: 1.72;
  color: var(--ink-soft);
  hyphens: auto;
}

.page__body > * + * {
  margin-top: 0.9em;
}

.page__body h3 {
  font-family: var(--font-display);
  font-size: 1.12em;
  line-height: 1.3;
  color: var(--ink);
  margin-top: 1.4em;
}

.page__body > h3:first-child {
  margin-top: 0;
}

/* A stanza: its line breaks are part of the poem. */
.page__body .verse {
  white-space: pre-line;
  hyphens: none;
}

.page__body blockquote {
  margin-inline: 0;
  padding-left: 0.9em;
  border-left: 2px solid var(--accent-book, var(--accent));
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05em;
  color: var(--ink);
}

.page__foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.page__running {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Title page */

.page--title .page__body,
.page--end .page__body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.7rem;
  text-align: center;
  overflow: visible;
}

.page__tag {
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-book, var(--accent));
}

.page--title h2 {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
  line-height: 1.12;
  text-wrap: balance;
  color: var(--ink);
}

.page__subtitle {
  max-width: 26ch;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-muted);
}

.page__rule {
  width: 56px;
  height: 1px;
  margin-block: 0.6rem;
  background: var(--line-strong);
}

.page__byline {
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
}

.page__meta {
  font-size: var(--step--1);
  color: var(--ink-muted);
}

.page__fin {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.6rem);
  color: var(--ink);
}

.page--blank {
  background: var(--bg-elevated);
}

/* The measuring page is a real page that never paints. */
.flipbook__measure {
  left: 50%;
  width: 50%;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

.flipbook[data-mode='single'] .flipbook__measure {
  left: 0;
  width: 100%;
}

/* ---- Page arrows ----

   They live in the corners of the open book, over the paper, so turning a
   page happens where the page is rather than in a toolbar underneath it. */

.flipbook__nav {
  position: absolute;
  z-index: 70;
  bottom: clamp(0.9rem, 1.8vw, 1.5rem);
  display: grid;
  place-items: center;
  width: clamp(38px, 4vw, 44px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--ink-soft);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    opacity var(--dur) var(--ease-out),
    scale var(--dur-fast) var(--ease-spring);
}

.flipbook__nav[data-dir='prev'] {
  left: clamp(0.9rem, 1.8vw, 1.5rem);
}

.flipbook__nav[data-dir='next'] {
  right: clamp(0.9rem, 1.8vw, 1.5rem);
}

.flipbook__nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  scale: 1.08;
}

.flipbook__nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.flipbook__nav svg {
  width: 19px;
  height: 19px;
}

/* Keep the running head and the page number clear of the arrows. */
.flipbook__board--left .page__foot,
.leaf__face--back .page__foot {
  padding-left: clamp(2.6rem, 5vw, 3.4rem);
}

.flipbook__board--right .page__foot,
.leaf__face--front .page__foot {
  padding-right: clamp(2.6rem, 5vw, 3.4rem);
}

.flipbook[data-mode='single'] .page__foot {
  padding-inline: clamp(2.6rem, 9vw, 3.4rem);
}

@media (prefers-reduced-motion: reduce) {
  .leaf,
  .leaf__face::after {
    transition: none;
  }
}
