/* The slots remain in document flow so deep links always land on the same leaf. */
.passages-ready [data-leaf="profile"] .chapter-surface {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100lvh;
}
.passages-ready .author-profile { display: grid; flex: 1 0 auto; }
.passages-ready .works.wrap,
.passages-ready .guestbook.wrap {
  min-height: 100vh;
  min-height: 100lvh;
}
@media (min-width: 721px) and (max-width: 1020px) and (orientation: portrait) {
  .passages-ready .guestbook { --desk-height: max(100lvh, 780px); }
  .passages-ready .guest-scenery::before {
    height: min(100%, var(--desk-height));
    background-position: center, right top;
    background-size: auto, max(100%, calc(var(--desk-height) * 1.5)) auto;
  }
  .passages-ready .guestbook::after {
    background-position: right bottom;
    background-size: max(100%, calc(var(--desk-height) * 1.5)) auto;
  }
}

/* Both sticky surfaces already cover the entire turn before scrolling starts.
   Their slots keep their original heights and hash positions throughout. */
.passages-ready {
  --cover-length: 220vh;
  --turn-span: 100vh;
}
@supports (height: 100svh) {
  .passages-ready { --cover-length: 220svh; --turn-span: 100svh; }
}
.passages-ready main > [data-leaf="opening"] { height: var(--cover-length); }
.passages-ready main > [data-leaf="opening"] .opening.ready {
  height: calc(var(--cover-length) + max(500px, var(--turn-span)));
  z-index: 0;
}
@media (max-height: 500px) {
  .passages-ready main > [data-leaf="opening"] .opening.ready {
    height: calc(var(--cover-length) + max(320px, var(--turn-span)));
  }
}
.passages-ready main > #profile { display: flow-root; }
.passages-ready main > #profile > .profile-pin-track {
  margin-top: calc(0px - var(--turn-span));
  pointer-events: none;
}
.passages-ready main > #profile > .profile-pin-track::after {
  content: "";
  display: block;
  height: var(--turn-span);
}
.passages-ready main > #profile > .profile-pin-track > .chapter-surface {
  position: sticky;
  top: 0;
  z-index: 1;
  pointer-events: auto;
}
.passages-ready main > #profile.profile-ahead > .profile-pin-track > .chapter-surface {
  clip-path: inset(0 100% 0 0);
}
.chapter-optics {
  position: fixed;
  z-index: 8;
  inset: 0 0 auto;
  height: 100vh;
  height: 100lvh;
  pointer-events: none;
  overflow: hidden;
}
.chapter-optics[hidden] { display: none; }
.chapter-optics canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce), print {
  .chapter-optics { display: none; }
}

/* The edge belongs to the incoming sheet, just above its top. It casts a
   shadow on the preceding chapter and disappears as the new page lands.
   Keep the slot free of transforms so the atlas and cover links can pin. */
@media screen and (prefers-reduced-motion: no-preference) {
  main > :is(#journey, #works, #guestbook) {
    position: relative;
  }
  #journey {
    --paper-lip: linear-gradient(90deg, #79a4b2, #c0d8d5 41%, #507b8e 84%, #abc5c6);
    --paper-shade: #0b23375c;
  }
  #works {
    --paper-lip: linear-gradient(90deg, #916946, #d1a572 32%, #f4d5a3 49%, #926c48 75%, #cfa477);
    --paper-shade: #09191fd4;
  }
  #guestbook {
    --paper-lip: linear-gradient(90deg, #bba789, #f5ebd5 29%, #d5c3a3 72%, #eee0c4);
    --paper-shade: #382c23a6;
  }
  main > :is(#journey, #works, #guestbook)::before {
    content: "";
    position: absolute;
    z-index: 3;
    inset: auto 0 100%;
    height: clamp(20px, 3.8vh, 44px);
    pointer-events: none;
    background:
      var(--paper-lip) bottom / 100% 2px no-repeat,
      linear-gradient(to top, var(--paper-shade), transparent 92%);
  }
  @supports (animation-timeline: view()) {
    main > :is(#journey, #works, #guestbook)::before {
      animation: chapter-edge-light 1s linear both;
      animation-timeline: view(block);
    }
    @keyframes chapter-edge-light {
      0%, 100% { opacity: .25; }
      25%, 75% { opacity: 1; }
    }
  }
}
