/* ============================================================
   The letter story (see js/story.js): a storybook "window" that plays
   the letter being folded, sealed, flown to Ipoh and opened.
   ============================================================ */
.story {
  /* as wide as fits, but never taller than the screen */
  --story-w: min(96vw, 820px, calc((100vh - 10rem) * 1.2308));
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  /* full screen width, so anything flying off the side is clipped at the
     edge of the screen rather than at an invisible box */
  width: calc(100% + 2.5rem);
  margin-inline: -1.25rem;
  overflow-x: clip;
}

@supports (height: 100dvh) {
  .story { --story-w: min(96vw, 820px, calc((100dvh - 10rem) * 1.2308)); }
}

.story-svg {
  display: block;
  width: var(--story-w);
  height: auto;
  aspect-ratio: 800 / 650;
  /* no box of its own — the scenes sit straight on the page background,
     and the plane can fly past the edges of the drawing */
  overflow: visible;
}

.story-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: var(--story-w);
}

.story-caption {
  flex: 1;
  min-height: 1.6em;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--plum);
  text-align: left;
  opacity: 0;
}

.story-caption.show { animation: storyCaptionIn 0.5s ease forwards; }

@keyframes storyCaptionIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.story-skip {
  flex: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--purple);
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid rgba(178, 141, 255, 0.5);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.story-skip:hover { transform: translateY(-2px); background: #fff; }
.story-skip:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; }

/* svg bits that need a CSS transform origin / box */
.st-scene { opacity: 0; }
.pan { transform-box: fill-box; }
#envFlap { transform-box: fill-box; transform-origin: 50% 0%; }
#envSeal,
.pop { transform-box: fill-box; transform-origin: 50% 50%; }
#letterG { filter: drop-shadow(0 3px 4px rgba(90, 40, 90, 0.25)); }
#envBig { filter: drop-shadow(0 8px 10px rgba(120, 60, 110, 0.25)); }
#plane { filter: drop-shadow(0 6px 6px rgba(90, 40, 110, 0.22)); }

.pulse {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: mapPulse 1.6s ease-out infinite;
}

@keyframes mapPulse {
  0% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(2.4); opacity: 0; }
}

@media (max-width: 480px) {
  .story-caption { font-size: 0.92rem; }
  .story-bar { gap: 0.6rem; }
}

/* the paper plane: the top wing flutters, little air streaks flow behind */
#pwTop {
  transform-box: fill-box;
  transform-origin: 100% 100%;
  animation: wingFlutter 0.5s ease-in-out infinite alternate;
}

@keyframes wingFlutter {
  from { transform: rotate(0deg) scaleY(1); }
  to { transform: rotate(-7deg) scaleY(0.9); }
}

.streak {
  stroke-dasharray: 12 16;
  animation: streakFlow 0.45s linear infinite;
}
.streak.s2 { animation-duration: 0.55s; }
.streak.s3 { animation-duration: 0.4s; }

@keyframes streakFlow {
  to { stroke-dashoffset: -28; }
}

@media (prefers-reduced-motion: reduce) {
  #pwTop, .streak { animation: none; }
}
