/* A short, skippable memory prelude before every chapter. */

.scene-prelude {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: max(34px, env(safe-area-inset-top)) 24px max(30px, env(safe-area-inset-bottom));
  overflow: hidden;
  color: #56372f;
  background:
    radial-gradient(circle at 50% 39%, rgba(255, 249, 207, 0.94) 0 9%, rgba(255, 225, 176, 0.55) 29%, transparent 56%),
    linear-gradient(142deg, #f9eedb 0%, #f1d0ad 38%, #e7b596 72%, #d99c7e 100%);
  opacity: 0;
}

.scene-prelude[hidden] {
  display: none !important;
}

.scene-prelude.is-visible {
  animation: scene-prelude-in 520ms cubic-bezier(0.2, 0.62, 0.24, 1) both;
}

.scene-prelude.is-leaving {
  opacity: 1;
  filter: blur(4px);
  pointer-events: none;
  transform: scale(1.012);
  animation: scene-prelude-out 700ms cubic-bezier(0.2, 0.62, 0.24, 1) both !important;
}

.scene-prelude__atmosphere {
  position: absolute;
  inset: -10%;
  pointer-events: none;
  background:
    radial-gradient(circle at 19% 26%, rgba(255, 251, 223, 0.45), transparent 23rem),
    radial-gradient(circle at 83% 76%, rgba(161, 94, 76, 0.16), transparent 29rem),
    repeating-linear-gradient(113deg, transparent 0 55px, rgba(111, 69, 54, 0.035) 56px, transparent 57px 111px);
  transform: scale(1.08);
}

.scene-prelude__atmosphere::before,
.scene-prelude__atmosphere::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(28px);
}

.scene-prelude__atmosphere::before {
  top: 15%;
  left: 50%;
  width: min(48vw, 660px);
  aspect-ratio: 1;
  background: rgba(255, 245, 204, 0.32);
  transform: translateX(-50%);
}

.scene-prelude__atmosphere::after {
  right: 6%;
  bottom: -8%;
  width: min(34vw, 450px);
  aspect-ratio: 1;
  background: rgba(170, 96, 75, 0.12);
}

.scene-prelude__content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(15px, 2.2vh, 25px);
  width: min(100%, 1050px);
  height: 100%;
}

.scene-prelude__prompt {
  max-width: 18em;
  margin: 0;
  color: #50312d;
  font-family: var(--story-display);
  font-size: clamp(27px, 3.8vw, 51px);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.045em;
  text-align: center;
  text-wrap: balance;
  text-shadow: 0 4px 24px rgba(255, 250, 235, 0.58);
  animation: prelude-prompt-in 920ms cubic-bezier(0.16, 0.72, 0.22, 1) both;
}

.scene-prelude__prompt::after {
  content: "";
  display: block;
  width: 48px;
  height: 1px;
  margin: 19px auto 0;
  background: rgba(139, 76, 62, 0.44);
}

.scene-prelude__caption {
  min-height: 1.8em;
  max-width: 24em;
  margin: -2px 0 0;
  color: rgba(105, 62, 52, 0.82);
  font-family: var(--story-hand);
  font-size: clamp(15px, 1.5vw, 20px);
  line-height: 1.65;
  letter-spacing: 0.07em;
  text-align: center;
  text-wrap: balance;
  opacity: 0;
}

.scene-prelude__caption.is-visible {
  animation: prelude-caption-in 560ms cubic-bezier(0.16, 0.72, 0.22, 1) both;
}

.scene-prelude__photo-stage {
  position: relative;
  width: min(780px, 76vw);
  height: min(48svh, 520px);
  min-height: 280px;
  overflow: visible;
}

.scene-prelude__photo {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: visible;
  background: transparent;
  animation: prelude-photo-reveal 1050ms cubic-bezier(0.2, 0.62, 0.24, 1) both;
  transform-origin: center;
}

.scene-prelude__photo.is-mobile {
  animation: none;
  opacity: 1;
}

.scene-prelude__photo.is-outgoing {
  z-index: 1;
  animation: prelude-photo-out 260ms ease both;
}

.scene-prelude__photo img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(76vw, 780px);
  max-height: min(48svh, 520px);
  object-fit: contain;
  object-position: center;
  border-radius: 2px;
  box-shadow: 0 28px 66px rgba(107, 64, 52, 0.28);
}

.scene-prelude__skip {
  position: absolute;
  right: clamp(20px, 4vw, 48px);
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 4;
  min-height: 38px;
  padding: 7px 15px;
  color: rgba(91, 52, 44, 0.74);
  background: rgba(255, 250, 239, 0.22);
  border: 1px solid rgba(109, 61, 50, 0.28);
  border-radius: 999px;
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.08em;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.scene-prelude__skip:hover {
  color: #50312d;
  background: rgba(255, 250, 239, 0.58);
  border-color: rgba(109, 61, 50, 0.5);
}

.scene-prelude :focus-visible {
  outline-color: #8d4d45;
}

@keyframes scene-prelude-in {
  from {
    opacity: 0;
    filter: blur(6px);
    transform: scale(1.01);
  }

  to {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
}

@keyframes scene-prelude-out {
  from {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }

  to {
    opacity: 0;
    filter: blur(4px);
    transform: scale(1.012);
  }
}

@keyframes prelude-prompt-in {
  from {
    opacity: 0;
    translate: 0 18px;
    filter: blur(6px);
  }

  58% {
    opacity: 1;
    filter: blur(1px);
  }

  to {
    opacity: 1;
    translate: 0 0;
    filter: blur(0);
  }
}

@keyframes prelude-caption-in {
  from {
    opacity: 0;
    translate: 0 10px;
    filter: blur(3px);
  }

  to {
    opacity: 1;
    translate: 0 0;
    filter: blur(0);
  }
}

@keyframes prelude-photo-reveal {
  0% {
    opacity: 0;
    translate: 0 12px;
    scale: 0.985;
  }

  55% {
    opacity: 1;
  }

  100% {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}

@keyframes prelude-photo-out {
  from {
    opacity: 1;
    scale: 1;
  }

  to {
    opacity: 0;
    scale: 0.994;
  }
}

@media (max-width: 680px) {
  .scene-prelude {
    padding-inline: 17px;
  }

  .scene-prelude__content {
    gap: clamp(10px, 1.8vh, 18px);
  }

  .scene-prelude__prompt {
    max-width: 12em;
    font-size: clamp(24px, 7.4vw, 34px);
    line-height: 1.42;
  }

  .scene-prelude__prompt::after {
    margin-top: 14px;
  }

  .scene-prelude__caption {
    min-height: 1.7em;
    max-width: 20em;
    font-size: clamp(13px, 4vw, 17px);
    line-height: 1.55;
  }

  .scene-prelude__photo-stage {
    width: min(84vw, 420px);
    height: min(43svh, 410px);
    min-height: 225px;
  }

  .scene-prelude__photo {
    padding: 0;
  }

  .scene-prelude__photo img {
    max-width: min(84vw, 420px);
    max-height: min(43svh, 410px);
    box-shadow: 0 24px 54px rgba(0, 0, 0, 0.34);
  }

  .scene-prelude__skip {
    right: 16px;
    bottom: max(15px, env(safe-area-inset-bottom));
    min-height: 34px;
    padding: 6px 12px;
    font-size: 10px;
  }
}

@media (max-width: 900px) {
  .scene-prelude__atmosphere::before,
  .scene-prelude__atmosphere::after {
    filter: none;
  }

  .scene-prelude.is-visible {
    animation: mobile-prelude-in 360ms ease both;
  }

  .scene-prelude.is-leaving {
    filter: none;
    transform: none;
    animation: mobile-prelude-out 700ms cubic-bezier(0.16, 0.72, 0.22, 1) both !important;
  }

  .scene-prelude__prompt {
    animation: mobile-prelude-copy-in 520ms ease both;
  }

  .scene-prelude__photo {
    will-change: opacity, translate;
  }
}

@keyframes mobile-prelude-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes mobile-prelude-out {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

@keyframes mobile-prelude-copy-in {
  from {
    opacity: 0;
    translate: 0 10px;
  }

  to {
    opacity: 1;
    translate: 0 0;
  }
}

@media (max-height: 650px) {
  .scene-prelude {
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .scene-prelude__content {
    gap: 8px;
  }

  .scene-prelude__prompt {
    font-size: clamp(21px, 5.3vw, 31px);
  }

  .scene-prelude__prompt::after {
    margin-top: 9px;
  }

  .scene-prelude__caption {
    min-height: 1.6em;
    font-size: clamp(12px, 3.8vw, 15px);
  }

  .scene-prelude__photo img {
    max-width: min(80vw, 440px);
    max-height: 40svh;
  }

  .scene-prelude__photo-stage {
    width: min(80vw, 440px);
    height: 40svh;
    min-height: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene-prelude.is-visible,
  .scene-prelude__prompt,
  .scene-prelude__caption,
  .scene-prelude__photo,
  .scene-prelude__photo.is-outgoing {
    animation: none;
  }

  .scene-prelude.is-leaving {
    transition: none;
  }
}
