:root {
  --delay-step: 80ms;
  --anim-duration: 600ms;
  --delay-step-p: 30ms;
  --anim-duration-p: 300ms;
}
html, body {
  font-family: 'Cormorant Garamond', serif;
  background: black;
  color: white;
  height: 100%;
  margin: 0;
}
main { text-align: left; padding: 3rem 1.5rem; }
.container {
  width: min(90%, 650px);
  min-width: min(90%, 650px);
  max-width: 650px;
  margin: 0 auto;
  display: flow-root;
}
h1, h2, h3, h4, h5, h6, p {
  margin: 0 0 2rem 0;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
}
p {
  margin: 0 0 1rem 0;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
}
h1 { font-size: clamp(2rem, 6vw, 4rem); font-weight: 600; line-height: 1.1; }
p { opacity: 0.85; font-size: 1.2rem; line-height: 1.5; }

/* Image styling */
img.story-image {
  display: block;
  max-height: 256px;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto 1rem auto;
  border-radius: 12px;
}

#stage [data-animate="letters"] { visibility: hidden; opacity: 0; }
.fade-letter {
  display: inline;
  opacity: 0;
  filter: blur(1px);
  transform: translateX(.1em);
  animation: letter-in var(--anim-duration) ease forwards;
  animation-delay: calc(var(--i) * var(--delay-step));
  will-change: opacity, transform;
}

p .fade-letter {
  animation-duration: var(--anim-duration-p);
  animation-delay: calc(var(--i) * var(--delay-step-p));
}
@keyframes letter-in {
  from { opacity: 0; filter: blur(1px); transform: translateX(.1em); }
  to   { opacity: 1; filter: blur(0); transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .fade-letter { animation: none; opacity: 1; filter: none; transform: none; }
}

#next {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  text-decoration: underline;
  letter-spacing: .08em;
  font-weight: 600;
}
#next.show { opacity: .9; pointer-events: auto; cursor: pointer; }
#next:active { opacity: 1; }
#next.fade-out-fast {
  opacity: 0 !important;
  pointer-events: none;
  transition: opacity .3s ease !important;
}
#stage.fade-contents {
  opacity: 0;
  transition: opacity 1s ease;
}

/* ---------- Intro overlay ---------- */
#intro {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: grid;
  place-items: center;
  z-index: 9999;
  opacity: 0;
  animation: intro-fade-in 700ms ease forwards;
}
@keyframes intro-fade-in { from { opacity: 0; } to { opacity: 1; } }
/* Fade the entire overlay out over 1s and disable its entrance animation */
#intro.out {
  animation: none !important;               /* cancel intro-fade-in */
  opacity: 0;
  transition: opacity 1000ms ease;
  pointer-events: none;
}

/* Also fade out every intro item uniformly over 1s */
#intro.out .intro-fade {
  animation: none !important;               /* cancel intro-item / intro-btn */
  opacity: 0;
  transform: translateY(0);                 /* ensure no jump */
  filter: blur(0);
  transition: opacity 1000ms ease,          /* smooth fade */
              transform 1000ms ease,
              filter 1000ms ease;
}
.intro-panel {
  width: min(90%, 650px);
  max-width: 650px;
  text-align: left;
  padding: 2rem 1.5rem 5rem;
}

/* Staggered fade-in for intro content */
.intro-fade {
  opacity: 0;
  transform: translateY(6px);
  animation: intro-item 600ms ease forwards;
}
.intro-title { animation-delay: 150ms; }
.intro-text  { animation-delay: 350ms; }
#begin       { animation-delay: 800ms; }

@keyframes intro-item {
  from { opacity: 0; transform: translateY(6px); filter: blur(1px); }
  to   { opacity: 1; transform: translateY(0);  filter: blur(0); }
}

/* BEGIN styled like NEXT */
#begin {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  text-decoration: underline;
  letter-spacing: .08em;
  font-weight: 600;
  background: transparent;
  border: none;
  color: white;
  opacity: .95;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
}
#begin:active { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #intro { animation: none; opacity: 1; }
  .intro-fade { animation: none; opacity: 1; transform: none; }
}

/* Prevent the BEGIN button from shifting */
#begin.intro-fade {
  transform: none;                 /* cancel the translateY from .intro-fade */
  animation: intro-btn 400ms ease forwards;  /* fade only */
}

/* Keep your existing 800ms delay from the #begin rule */
@keyframes intro-btn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
