.realm-exploration {
  --field: #0a2328;
  --ink: #eee0c5;
  --accent: #e3bb7f;
  color: var(--ink);
  background: var(--field);
}

.realm-human .realm-exploration { --field: #2a211b; }
.realm-underworld .realm-exploration { --field: #071b23; }
.realm-gate .realm-exploration { --field: #112a29; }
.realm-heaven .realm-exploration { --field: #142426; }

.explore-scene {
  position: relative;
  isolation: isolate;
  display: grid;
  align-items: center;
  min-height: 96svh;
  padding: clamp(4rem, 10vh, 8rem) clamp(1.5rem, 7vw, 8rem);
  overflow: clip;
  border-top: 1px solid #e3bb7f25;
}

.explore-scene::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -20% 0;
  background: var(--static-scenery) center / cover;
  opacity: .24;
  pointer-events: none;
}

.explore-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, var(--field), transparent 24% 72%, var(--field));
  pointer-events: none;
}

.explore-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(16rem, .8fr);
  align-items: center;
  gap: clamp(2rem, 8vw, 8rem);
  width: min(100%, 74rem);
  margin-inline: auto;
}

.explore-reverse .explore-inner { grid-template-columns: minmax(16rem, .8fr) minmax(0, 1.55fr); }
.explore-reverse .explore-art { order: 1; }

.explore-art {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  align-items: center;
  width: 100%;
  min-height: clamp(19rem, 52vw, 31rem);
  margin: 0;
  isolation: isolate;
  background: radial-gradient(ellipse, #eac78c18, transparent 70%);
}

.explore-art::before {
  content: "";
  position: absolute;
  inset: 7% 7% 9%;
  z-index: -1;
  border: 1px solid #e3bb7f36;
}

.explore-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  min-height: 0;
  filter: drop-shadow(0 10px 18px #0007);
}

.explore-subject { grid-area: 1 / 2 / 9 / 13; }
.explore-detail { grid-area: 5 / 1 / 9 / 6; }
.explore-art:has(.explore-detail) .explore-subject { grid-area: 1 / 4 / 8 / 13; }
.explore-pair .explore-art:has(.explore-detail) .explore-subject { grid-area: 1 / 6 / 8 / 13; }
.explore-pair .explore-detail { grid-area: 2 / 1 / 9 / 7; }
.explore-stack .explore-art:has(.explore-detail) .explore-subject { grid-area: 1 / 3 / 6 / 11; }
.explore-stack .explore-detail { grid-area: 6 / 4 / 9 / 10; }
.explore-full .explore-subject { grid-area: 1 / 1 / 9 / 13; }
.explore-full .explore-art { height: clamp(26rem, 70svh, 48rem); }

.explore-copy { max-width: 28rem; }
.explore-kicker {
  color: var(--accent);
  font-size: .75rem;
  letter-spacing: .24em;
}

.explore-copy h2 {
  font: 400 clamp(2.25rem, 5vw, 4.25rem)/1.12 Painting, "Songti SC", serif;
  letter-spacing: .05em;
  margin: .25em 0 .5em;
  color: var(--ink);
}

.explore-copy p:not(.explore-kicker) {
  color: #efe1cb;
  font-size: clamp(.94rem, 1.5vw, 1rem);
  line-height: 1.8;
  margin: .8em 0 0;
}

.explore-copy strong { color: var(--accent); font-weight: 600; }
.explore-copy a { color: var(--accent); text-decoration: underline; text-underline-offset: .25em; }
.explore-copy a:focus-visible { outline: 1px solid currentColor; outline-offset: .35em; }
.explore-copy .explore-next { display: inline-block; margin-top: 1.5rem; }

@media (max-width: 720px) {
  .explore-inner, .explore-reverse .explore-inner { grid-template-columns: minmax(0, 1fr); gap: 1.75rem; }
  .explore-reverse .explore-art { order: 0; }
  .explore-scene { min-height: 88svh; padding-block: 3.75rem; }
  .explore-art { min-height: clamp(16rem, 79vw, 26rem); }
  .explore-full .explore-art { height: 60svh; }
}

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .explore-scene { view-timeline-name: --explore-scene; }
    .explore-scene::before {
      animation: explore-back linear both;
      animation-timeline: --explore-scene;
    }
    .explore-subject {
      animation: explore-subject linear both;
      animation-timeline: --explore-scene;
    }
    .explore-detail {
      animation: explore-detail linear both;
      animation-timeline: --explore-scene;
    }
    .explore-full .explore-subject { animation-name: explore-pullback; }
    .explore-copy {
      animation: explore-copy linear both;
      animation-timeline: --explore-scene;
    }
  }
}

/* Hold the primary image near the center, then let the closer detail pass it. */
@keyframes explore-back {
  from { transform: translateY(-12%); }
  to { transform: translateY(12%); }
}
@keyframes explore-subject {
  0% { transform: translateY(25%) scale(.92); opacity: .25; animation-timing-function: ease-out; }
  39% { transform: translateY(1%) scale(1); opacity: 1; }
  63% { transform: translateY(-1%) scale(1); opacity: 1; animation-timing-function: ease-in; }
  100% { transform: translateY(-23%) scale(1.05); opacity: .25; }
}
@keyframes explore-detail {
  0%, 12% { transform: translateY(46%); opacity: .15; animation-timing-function: ease-out; }
  47% { transform: translateY(2%); opacity: 1; }
  60% { transform: translateY(-2%); opacity: 1; animation-timing-function: ease-in; }
  100% { transform: translateY(-49%); opacity: .15; }
}
@keyframes explore-copy {
  0% { transform: translateY(1.5rem); opacity: .75; animation-timing-function: ease-out; }
  34%, 69% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-1.1rem); opacity: .75; }
}
@keyframes explore-pullback {
  0% { transform: translateY(12%) scale(1.32); opacity: .3; animation-timing-function: ease-out; }
  48%, 72% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-8%) scale(.96); opacity: .6; }
}

.explore-scene:focus-within .explore-copy { animation: none; }

.realm-human .explore-stack .explore-art:has(.explore-detail) .explore-subject {
  grid-area: 1 / 3 / 4 / 11;
}

.realm-human .explore-stack .explore-detail {
  grid-area: 3 / 1 / 9 / 13;
}

.realm-underworld .explore-stack .explore-art:has(.explore-detail) .explore-subject {
  grid-area: 1 / 2 / 4 / 12;
}

.realm-underworld .explore-stack .explore-detail {
  grid-area: 3 / 3 / 9 / 11;
}

/* The original chapter's cutouts each occupy a fixed cell in the final view. */
.realm-reveal {
  --object-count: 3;
  --plate: #10262a;
  position: relative;
  color: #eee0c5;
  background: var(--plate);
}

.realm-human .realm-reveal { --plate: #2a211b; }
.realm-underworld .realm-reveal { --plate: #071b23; }
.realm-gate .realm-reveal { --plate: #112a29; }
.realm-heaven .realm-reveal { --plate: #142426; }

.realm-encounter .realm-reveal,
.realm-underworld .realm-reveal { --object-count: 4; }
.realm-gate .realm-reveal { --object-count: 5; }

.reveal-stage {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(.6rem, 2svh, 1.6rem);
  min-height: 100svh;
  padding: max(4.1rem, calc(env(safe-area-inset-top) + 3.6rem))
    clamp(1rem, 5vw, 4rem) max(.85rem, env(safe-area-inset-bottom));
  background: var(--plate);
  overflow: clip;
}

.reveal-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -16% 0;
  background: linear-gradient(#071b2366, var(--plate)), var(--static-scenery) center / cover;
  opacity: .85;
}

.reveal-heading { text-align: center; }
.reveal-heading p {
  color: #e3bb7f;
  font-size: .76rem;
  letter-spacing: .2em;
}

.reveal-heading h2 {
  margin: .18em 0 0;
  font: 400 clamp(1.45rem, 4.4vw, 3.25rem)/1.22 Painting, "Songti SC", serif;
  text-wrap: balance;
}

.reveal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(.35rem, 1.4svh, 1rem) clamp(.4rem, 2vw, 1.4rem);
  width: min(100%, 65rem);
  min-height: 0;
  margin-inline: auto;
}

.reveal-grid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.reveal-item {
  --art-order: 0;
  --art-step: calc(76% / var(--object-count));
  --art-start: calc(6% + var(--art-order) * var(--art-step));
  --art-end: calc(var(--art-start) + .45 * var(--art-step));
  --label-start: calc(var(--art-start) + .48 * var(--art-step));
  --label-end: calc(var(--art-start) + .75 * var(--art-step));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: .18rem;
  min-width: 0;
  min-height: 0;
  padding: clamp(.2rem, .8svh, .7rem);
  border: 1px solid #e3bb7f30;
  background: radial-gradient(ellipse at 50% 45%, #eac78c14, transparent 72%);
}

.reveal-item:nth-child(2) { --art-order: 1; }
.reveal-item:nth-child(3) { --art-order: 2; }
.reveal-item:nth-child(4) { --art-order: 3; }
.reveal-item:nth-child(5) { --art-order: 4; }

.reveal-image { min-width: 0; min-height: 0; }
.reveal-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px #0008);
}

.reveal-item figcaption, .reveal-hint {
  text-align: center;
  color: #f3d5a7;
  font-size: clamp(.75rem, 2.8vw, 1rem);
  line-height: 1.35;
}

.reveal-hint { margin: 0; font-size: .75rem; }

.explore-map {
  position: relative;
  display: block;
  width: min(100%, 49svh, 22rem);
  min-height: 0;
  margin-inline: auto;
  background: none;
}

.explore-map::before { content: none; }
.explore-map img { height: auto; }
.explore-map-mark {
  position: absolute;
  border: 2px solid #ffe1a8;
  box-shadow: 0 0 0 100vmax #07181b70;
  pointer-events: none;
}

/* The rectangles locate each scene on the same full-width painting. */
.realm-encounter .explore-map-mark { inset: 31% 29% 42%; }
.realm-human .explore-map-mark { inset: 71% 29% 15%; }
.realm-underworld .explore-map-mark { inset: 84% 29% 1%; }
.realm-gate .explore-map-mark { inset: 15% 17% 64%; }
.realm-heaven .explore-map-mark { inset: 1% 13% 86%; }

.explore-map-image { position: relative; overflow: hidden; }
.explore-location .explore-copy { align-self: center; }
.explore-note {
  border-top: 1px solid #e3bb7f45;
  padding-top: .8em;
}

@media (max-width: 760px), (orientation: portrait) {
  .reveal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reveal-grid[data-count="3"] > :last-child,
  .reveal-grid[data-count="5"] > :last-child { grid-column: 1 / -1; width: 50%; justify-self: center; }
  .reveal-heading h2 { max-width: 23rem; margin-inline: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .realm-reveal {
      min-height: calc((var(--object-count) * 95 + 170) * 1svh);
      view-timeline-name: --chapter-reveal;
    }

    .reveal-stage {
      position: sticky;
      top: 0;
      height: 100svh;
    }

    .reveal-stage::before {
      animation: reveal-backdrop linear both;
      animation-timeline: --chapter-reveal;
      animation-range: contain;
    }

    .reveal-item {
      animation: reveal-cell linear both;
      animation-timeline: --chapter-reveal;
      animation-range: contain var(--art-start) contain var(--art-end);
    }

    .reveal-image {
      animation: reveal-image ease-out both;
      animation-timeline: --chapter-reveal;
      animation-range: contain var(--art-start) contain var(--art-end);
    }

    .reveal-item figcaption {
      animation: reveal-caption ease-out both;
      animation-timeline: --chapter-reveal;
      animation-range: contain var(--label-start) contain var(--label-end);
    }
  }
}

/* In static modes every row has room for the art and its caption. */
@supports not (animation-timeline: view()) {
  .reveal-item { min-height: 10rem; }
  .reveal-image { height: 9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal-item { min-height: 10rem; }
  .reveal-image { height: 9rem; }
}

@keyframes reveal-backdrop {
  from { transform: translateY(-8%); }
  to { transform: translateY(10%); }
}
@keyframes reveal-cell {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes reveal-image {
  from { transform: translateY(10%) scale(.83); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes reveal-caption {
  from { transform: translateY(.4em); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.reveal-image picture { display: block; width: 100%; height: 100%; }

.reveal-item figcaption a {
  text-decoration: underline;
  text-decoration-color: #f3d5a780;
  text-underline-offset: .22em;
}

.reveal-item:focus-within,
.reveal-item:focus-within .reveal-image,
.reveal-item:focus-within figcaption { animation: none; }

.explore-crop .explore-art { min-height: clamp(15rem, 40vw, 29rem); }
.explore-crop .explore-art::before { content: none; }
.explore-crop img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 58svh;
  overflow: hidden;
  filter: drop-shadow(0 6px 12px #0008);
}

@media (max-width: 720px) {
  .explore-crop .explore-art { min-height: clamp(12rem, 59vw, 23rem); }
}
