/* ===== Motion pack (refs: dedicapag galaxy, flores noche, carta correo) ===== */

body.not-loaded .page > *:not(.atlas-panel):not(.atlas-panel-backdrop):not(.mem-modal):not(.page-veil),
body.not-loaded .ani-helper {
  opacity: 0;
  transform: translateY(18px);
}

body.is-ready .page > *:not(.atlas-panel):not(.atlas-panel-backdrop):not(.mem-modal):not(.page-veil) {
  animation: riseIn 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}
body.is-ready .page > *:not(.atlas-panel):not(.atlas-panel-backdrop):not(.mem-modal):nth-child(1) { animation-delay: 0.05s; }
body.is-ready .page > *:not(.atlas-panel):not(.atlas-panel-backdrop):not(.mem-modal):nth-child(2) { animation-delay: 0.15s; }
body.is-ready .ani-helper {
  animation: riseIn 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.35s both;
}

/* Paneles/modales NUNCA heredan riseIn: el fill-mode "both" dejaba
   opacity:1 + transform:none y el modal del mapa quedaba trabado. */
.atlas-panel,
.atlas-panel-backdrop,
.mem-modal,
.page-veil {
  animation: none !important;
}

/* Capítulos fullscreen: sin fade-up que rompe el stage */
body.is-immersive.not-loaded .page > *,
body.is-immersive.not-loaded .ani-helper {
  opacity: 1;
  transform: none;
}
body.is-immersive.is-ready .page > * {
  animation: none;
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(22px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Shooting stars on global bg */
.shooting-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}
.shooting-layer i {
  position: absolute;
  width: 90px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, #fff, rgba(201,184,232,0.2));
  border-radius: 2px;
  opacity: 0;
  transform: rotate(-35deg);
  animation: shoot 5.5s linear infinite;
}
.shooting-layer i:nth-child(1) { top: 12%; left: 70%; animation-delay: 0.5s; }
.shooting-layer i:nth-child(2) { top: 28%; left: 20%; animation-delay: 2.2s; width: 70px; }
.shooting-layer i:nth-child(3) { top: 55%; left: 55%; animation-delay: 3.8s; width: 110px; }
@keyframes shoot {
  0% { opacity: 0; transform: translateX(0) translateY(0) rotate(-35deg); }
  5% { opacity: 1; }
  25% { opacity: 0; transform: translateX(-220px) translateY(140px) rotate(-35deg); }
  100% { opacity: 0; }
}

/* Floating hearts (subtle, cumpleaños) */
.heart-rain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.heart-rain span {
  position: absolute;
  bottom: -40px;
  color: rgba(201, 123, 168, 0.35);
  font-size: 1rem;
  animation: heartFloat 12s linear infinite;
}
@keyframes heartFloat {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.7; }
  100% { transform: translateY(-110vh) rotate(25deg); opacity: 0; }
}

/* Envelope carta (ref: correo) */
.mail-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
}
.mail-prompt {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 0;
  color: var(--text-hi);
  animation: softPulse 2s ease-in-out infinite;
}
@keyframes softPulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}
.envelope {
  position: relative;
  width: min(260px, 70vw);
  height: 160px;
  cursor: pointer;
  perspective: 900px;
  border: 0;
  background: transparent;
  padding: 0;
}
.envelope .env-body {
  position: absolute;
  inset: 40px 0 0;
  background: linear-gradient(160deg, #f7e9f2, #e8d5f5);
  border-radius: 0 0 1rem 1rem;
  box-shadow: 0 16px 40px rgba(125, 95, 170, 0.25);
  z-index: 2;
}
.envelope .env-flap {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 90px;
  background: linear-gradient(180deg, #c9b8e8, #b07eb8);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  transform-origin: top center;
  transition: transform 0.9s cubic-bezier(0.65, 0, 0.35, 1);
  z-index: 3;
  box-shadow: 0 8px 20px rgba(155,126,200,0.3);
}
.envelope .env-letter {
  position: absolute;
  left: 10%; right: 10%;
  bottom: 28px;
  height: 70%;
  background: #fff;
  border-radius: 0.5rem;
  z-index: 1;
  transform: translateY(20%);
  transition: transform 1s cubic-bezier(0.22, 1, 0.36, 1) 0.25s;
  box-shadow: 0 8px 24px rgba(61,47,79,0.12);
  display: grid;
  place-items: center;
  font-size: 2rem;
}
.envelope .env-heart {
  position: absolute;
  left: 50%;
  top: 55%;
  transform: translate(-50%, -50%);
  z-index: 4;
  font-size: 1.4rem;
  transition: opacity 0.4s ease;
}
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.open .env-letter { transform: translateY(-55%); }
.envelope.open .env-heart { opacity: 0; }
.envelope:not(.open):hover { transform: translateY(-4px); }
.finger-hint {
  width: 28px;
  height: 28px;
  margin-top: -0.5rem;
  animation: tapHint 1.4s ease-in-out infinite;
}
@keyframes tapHint {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50% { transform: translateY(6px); opacity: 1; }
}

/* Flores amarillas (ref: alexx.dev) — ver flores.css en Cap. Sol */

/* Galaxy canvas spiral */
.galaxy-sky {
  isolation: isolate;
}
.galaxy-sky canvas.galaxy-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.galaxy-star {
  z-index: 3;
  transition: transform 0.45s cubic-bezier(0.34, 1.5, 0.64, 1), filter 0.45s ease;
}
.galaxy-star:active {
  transform: translate(-50%, -50%) scale(1.55);
}
.galaxy-star.lit::after {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 233, 168, 0.5);
  animation: ringOut 0.7s ease-out forwards;
}
@keyframes ringOut {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}

/* Modal memoria cinematográfico */
.star-modal[open] {
  animation: modalPop 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
}
@keyframes modalPop {
  from { opacity: 0; transform: scale(0.88) translateY(16px); }
  to { opacity: 1; transform: none; }
}
.star-modal img {
  animation: kenBurns 10s ease-in-out infinite alternate;
}

.atlas-node.current .atlas-node-ring {
  animation: nodePop 0.7s cubic-bezier(0.34, 1.5, 0.64, 1);
}
@keyframes nodePop {
  from { transform: scale(0.5); }
  to { transform: scale(1); }
}

/* Reward / carta */
.reward-box.pop-in,
.carta.pop-in {
  animation: rewardIn 0.85s cubic-bezier(0.22, 1, 0.36, 1);
}
.frase-magica {
  background: linear-gradient(120deg, #9b7ec8, #c97ba8, #9b7ec8);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shineText 4s linear infinite;
}
@keyframes shineText {
  to { background-position: 200% center; }
}

/* ===== View Transitions (multipágina, navegación cross-document) =====
   El page-veil (data-veil, aventura.js) sigue siendo el fallback: en
   navegadores sin soporte esto simplemente no aplica y el veil de
   siempre sigue funcionando solo. */
@view-transition {
  navigation: auto;
}

.ani-avatar { view-transition-name: ani-avatar; }
main h1 { view-transition-name: page-title; }

::view-transition-old(ani-avatar),
::view-transition-new(ani-avatar) {
  animation-duration: 0.5s;
  animation-timing-function: var(--ease-out-expo);
}
::view-transition-old(page-title),
::view-transition-new(page-title) {
  animation-duration: 0.6s;
  animation-timing-function: var(--ease-out-expo);
}

@media (prefers-reduced-motion: reduce) {
  .shooting-layer, .heart-rain, .flower .bloom, .frase-magica { animation: none !important; }
  body.not-loaded .page > * { opacity: 1; transform: none; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}
