/* ==========================================================
   CMS Section Animations
   ========================================================== 
   CSS keyframes and initial/animated states for page-builder
   section entrance animations.

   Sections with a `data-animation-type` attribute start hidden
   and animate in when the `.cms-animated` class is added (by
   the companion JS `section-animations.js`).

   Respects `prefers-reduced-motion` — animations are disabled
   when the user has that preference set.
   ========================================================== */

/* -- Initial state: hidden ---------------------------------- */
/* stagger keeps the parent visible and fades its children. */
:is(.cms-section, .cms-block)[data-animation-type]:not([data-animation-type="stagger"]):not([data-animation-type="none"]) {
  opacity: 0;
  will-change: opacity, transform;
}

/* -- Animated state: visible -------------------------------- */
/* Same selector weight as the hidden state, plus .cms-animated, so opacity wins. */
:is(.cms-section, .cms-block)[data-animation-type]:not([data-animation-type="stagger"]):not([data-animation-type="none"]).cms-animated {
  opacity: 1;
  transform: none !important;
}

/* -- Per-type initial transforms ----------------------------- */
:is(.cms-section, .cms-block)[data-animation-type="fade-up"] {
  transform: translateY(30px);
}
:is(.cms-section, .cms-block)[data-animation-type="fade-down"] {
  transform: translateY(-30px);
}
:is(.cms-section, .cms-block)[data-animation-type="fade-left"] {
  transform: translateX(30px);
}
:is(.cms-section, .cms-block)[data-animation-type="fade-right"] {
  transform: translateX(-30px);
}
:is(.cms-section, .cms-block)[data-animation-type="zoom-in"] {
  transform: scale(0.9);
}
:is(.cms-section, .cms-block)[data-animation-type="zoom-out"] {
  transform: scale(1.1);
}
:is(.cms-section, .cms-block)[data-animation-type="slide-up"] {
  transform: translateY(60px);
}
:is(.cms-section, .cms-block)[data-animation-type="bounce"] {
  transform: translateY(30px);
}

/* stagger: children, one after another */
.cms-section[data-animation-type="stagger"] .cms-block,
.cms-block[data-animation-type="stagger"] .cms-reveal-item {
  opacity: 0;
  transform: translateY(30px);
}
.cms-section[data-animation-type="stagger"] .cms-block.cms-animated,
.cms-block[data-animation-type="stagger"] .cms-reveal-item.cms-animated {
  opacity: 1;
  transform: none;
}

/* -- Transition (applied via class so it doesn't fire on load) */
:is(.cms-section, .cms-block).cms-animating {
  transition-property: opacity, transform;
}

/* -- Bounce special keyframes -------------------------------- */
@keyframes cms-bounce-in {
  0% {
    opacity: 0;
    transform: translateY(30px);
  }
  60% {
    opacity: 1;
    transform: translateY(-8px);
  }
  80% {
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

:is(.cms-section, .cms-block)[data-animation-type="bounce"].cms-animated {
  animation-name: cms-bounce-in;
  animation-fill-mode: forwards;
}

/* -- Reduced motion and motion token off --------------------- */
@media (prefers-reduced-motion: reduce) {
  :is(.cms-section, .cms-block)[data-animation-type],
  .cms-section[data-animation-type="stagger"] .cms-block,
  .cms-block[data-animation-type="stagger"] .cms-reveal-item,
  :is(.cms-section, .cms-block).cms-animated {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }
}

@container cms-motion style(--motion: off) {
  :is(.cms-section, .cms-block)[data-animation-type],
  .cms-section[data-animation-type="stagger"] .cms-block,
  .cms-block[data-animation-type="stagger"] .cms-reveal-item,
  :is(.cms-section, .cms-block).cms-animated {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }
}
