.main-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: default;
}

#imageContainer #mainImage.fade-out {
  animation: envelopeClose 0.22s ease-in forwards;
}

#imageContainer #mainImage.fade-in {
  animation: envelopeOpen 0.13s ease-out both;
}

.welcome-text.animate__fadeOut,
#finalContainer.animate__fadeIn,
#imageContainer.animate__fadeOut,
#main-text-container.animate__fadeIn {
  animation-duration: 0.5s;
}

@keyframes envelopeClose {
  to { opacity: 0; transform: scale(0.96); }
}

@keyframes envelopeOpen {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}


/* Animación del contenedor final */

.container-fade-in {
  animation: containerFadeIn 1s ease-in-out forwards;
}

@keyframes containerFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}


.scene {
  position: sticky;
  top: 0;
  z-index: 2;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  perspective: 1000px;
}

.envelope-scroll-track {
  position: relative;
  height: 200vh;
}

.envelope-scroll-track.is-open {
  display: none;
}

.image-container {
  position: absolute;
  inset: 0;
  z-index: 2;
}

#imageContainer {
  max-width: none;
}

.image-container > .vh-100 {
  height: 100% !important;
}

.envelope-scroll-prompt {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: clamp(18px, 4vh, 34px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: rgba(255, 255, 255, 0.8);
  font-family: Lora, serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: auto;
  border: 0;
  background: transparent;
  padding: 6px 10px;
  cursor: pointer;
}

.envelope-scroll-arrow {
  width: 18px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: envelopePromptArrow 1.6s ease-in-out infinite;
}

.envelope-scroll-icon {
  width: 18px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
}

.envelope-scroll-wheel {
  animation: envelopePromptWheel 1.6s ease-in-out infinite;
}

.envelope-scroll-prompt.is-hidden {
  opacity: 0;
  visibility: hidden;
}

@keyframes envelopePromptArrow {
  0%, 100% { transform: translateY(2px); opacity: 0.65; }
  50% { transform: translateY(-2px); opacity: 1; }
}

@keyframes envelopePromptWheel {
  0%, 100% { transform: translateY(0); opacity: 0.65; }
  50% { transform: translateY(3px); opacity: 1; }
}

.final-container {
  position: absolute;
  inset: 0;
  z-index: 1;

  transform: translateZ(-1000px) scale(0.5);
}

#finalContainer {
  position: relative;
}

@media (min-width: 992px) {
  #imageContainer #mainImage {
    max-width: 40vw;
    max-height: 62vh;
  }
}

@media (min-width: 1200px) and (min-height: 800px) {
  #imageContainer > .vh-100 {
    padding-top: clamp(3.5rem, 8vh, 5rem) !important;
    padding-bottom: 1.5rem !important;
  }

  #imageContainer h1.welcome-text {
    margin-bottom: 1rem !important;
  }

  #imageContainer h5.welcome-text {
    margin-bottom: 0.75rem !important;
  }

  #imageContainer h6.welcome-text {
    margin-bottom: 1rem !important;
  }

  #imageContainer #mainImage {
    max-height: 48vh;
    margin-bottom: 0.75rem !important;
  }

  .envelope-scroll-prompt {
    position: static;
    margin-top: -0.25rem;
    transform: none;
  }
}

@media (min-width: 1200px) and (min-height: 760px) and (max-height: 799px) {
  #imageContainer > .vh-100 {
    justify-content: flex-start !important;
    padding-top: clamp(3rem, 7vh, 3.5rem) !important;
    padding-bottom: 1rem !important;
  }

  #imageContainer h1.welcome-text {
    font-size: 44px !important;
    line-height: 50px !important;
    margin-bottom: 1rem !important;
  }

  #imageContainer h5.welcome-text {
    margin-bottom: 0.75rem !important;
  }

  #imageContainer h6.welcome-text {
    margin-bottom: 1rem !important;
  }

  #imageContainer #mainImage {
    max-height: 42vh;
    margin-bottom: 0.5rem !important;
  }

  .envelope-scroll-prompt {
    position: static;
    margin-top: -0.25rem;
    transform: none;
  }
}

/* Mantiene la portada completa en tablets y ventanas de poca altura. */
@media (min-width: 768px) and (max-width: 1199.98px) and (max-height: 759px) {
  #imageContainer > .vh-100 {
    padding-top: 32px !important;
    padding-bottom: 112px !important;
  }

  #imageContainer h1.welcome-text,
  #imageContainer h6.welcome-text {
    margin-bottom: 24px !important;
  }

  #imageContainer h5.welcome-text {
    margin-bottom: 16px !important;
  }

  #imageContainer #mainImage {
    max-height: max(0px, calc(100dvh - 420px));
    margin-bottom: 0 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .envelope-scroll-arrow,
  .envelope-scroll-wheel {
    animation: none;
  }
}

/* Controles de apertura sin alterar las dimensiones del sobre. */
#imageContainer #mainImage { cursor: pointer; }
.envelope-scroll-prompt:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 4px;
}
.envelope-scroll-prompt:disabled { cursor: wait; }
#imageContainer.is-loading #mainImage {
  animation: envelopeLoadingPulse 1.2s ease-in-out infinite;
}
#imageContainer.is-loading .envelope-scroll-arrow,
#imageContainer.is-loading .envelope-scroll-icon { visibility: hidden; }
@keyframes envelopeLoadingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.78; }
}
@media (prefers-reduced-motion: reduce) {
  #imageContainer.is-loading #mainImage { animation: none; }
}

/* Reserva espacio para el control de apertura en móviles de poca altura. */
@media (max-width: 767.98px) and (max-height: 700px) {
  #imageContainer > .vh-100 {
    padding: 20px 24px 110px !important;
  }
  #imageContainer h1.welcome-text {
    font-size: 34px !important;
    line-height: 39px !important;
    margin-bottom: 16px !important;
  }
  #imageContainer h5.welcome-text,
  #imageContainer h6.welcome-text { margin-bottom: 12px !important; }
  #imageContainer #mainImage {
    max-height: max(80px, calc(100dvh - 330px));
    width: auto;
    margin-bottom: 0 !important;
    object-fit: contain;
  }
}

/* Mantener las dimensiones evita saltos mientras llega el primer fotograma. */
#imageContainer #mainImage.envelope-preparing { opacity: 0; animation: none; }
.envelope-initial-loader {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 65%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(260px, 80vw);
  color: #C0C5CC;
  font: 0.75rem Lora, serif;
  text-align: center;
  cursor: pointer;
}
.envelope-initial-loader[hidden] { display: none; }
.envelope-loader-ring {
  width: 26px;
  height: 26px;
  border: 2px solid rgba(192, 197, 204, 0.25);
  border-top-color: #C0C5CC;
  border-radius: 50%;
  animation: envelopeLoaderSpin 0.9s linear infinite;
}
@keyframes envelopeLoaderSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .envelope-loader-ring { animation: none; }
}

/* Los puntos mantienen su espacio para que el texto no salte al animarse. */
.envelope-loading-dots { display: inline-flex; width: 1.2em; }
.envelope-loading-dots > span {
  display: inline-block;
  animation: envelopeLoadingDot 1.2s ease-in-out infinite;
}
.envelope-loading-dots > span:nth-child(2) { animation-delay: 0.2s; }
.envelope-loading-dots > span:nth-child(3) { animation-delay: 0.4s; }
@keyframes envelopeLoadingDot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .envelope-loading-dots > span { animation: none; }
}
