/* =========================================================================
   Mercer Animate
   Scroll-reveal utilities for the mercer-template only.
   Enqueued (front end only) by americanbeacon_enqueue_mercer_animate() in functions.php,
   gated by americanbeacon_is_mercer_template(). Plain CSS: not part of the Mix build.

   Usage (Block → Advanced → Additional CSS class(es)):
     m-anim                     fadeInUp on scroll (default effect)
     m-anim m-delay-2           same, 2 beats later (2 × .25s = .5s)
     m-stagger                  on a parent (Columns, Group, Buttons): children
                                animate in order, 0 / .25 / .5 / .75s …
     m-anim m-fadeInLeft        swap the effect
     m-stagger m-growUp         children grow up from their bottom edge, in turn (bar / ramp rows)
     m-stagger m-on-load        animate immediately (hero), not on scroll
   Theme block styles (is-style-fadeInUp, etc.) also pick up m-delay-* /
   m-stagger timing on this template.
   ========================================================================= */

/* Per-element values. Non-inheriting so a delay on a parent never leaks into nested blocks. */
@property --m-delay { syntax: '*'; inherits: false; }
@property --m-i     { syntax: '*'; inherits: false; }

/* ---------- Timing tokens ----------
   Tuned to the custom Mercer blocks (bft/process-timeline: .5s duration, .25s steps).
   Change these once and every Mercer animation follows. */
:root {
  --m-dur:   .5s;
  --m-ease:  cubic-bezier(.22, .61, .36, 1); /* ease-out: entrances settle rather than drift */
  --m-step:  .25s;   /* one delay "beat" */
  --m-start: 0s;     /* group offset added before per-item delays (inherits) */

  /* Default effect = fadeInUp, same 20px travel as the theme keyframe */
  --m-x: 0px;
  --m-y: 20px;
  --m-s: 1;
  --m-sy: 1;   /* extra vertical scale, used by m-growUp */
}

/* One keyframe drives every effect; the effect classes only change the start frame.
   No "to" frame: it settles to the element's own styles, so hover transforms keep working. */
@keyframes m-in {
  from {
    opacity: 0;
    transform: translate3d(var(--m-x), var(--m-y), 0) scale(var(--m-s)) scaleY(var(--m-sy));
  }
}

/* ---------- Engine ----------
   .m-js is set in <head> by americanbeacon_mercer_animate_flag() in functions.php. Without JS (or in the editor)
   nothing is hidden. */
.m-js :is(.m-anim, .m-stagger > :not(.m-skip)):not(.is-visible) {
  opacity: 0;
}

.m-js :is(.m-anim, .m-stagger > :not(.m-skip)).is-visible {
  animation-name: m-in;
  animation-duration: var(--m-dur);
  animation-timing-function: var(--m-ease);
  animation-delay: calc(var(--m-start) + var(--m-delay, calc(var(--m-i, 0) * var(--m-step))));
  /* backwards = hold the start frame during the delay, then release.
     Unlike the theme's fill-mode:both, this won't lock transform after the
     animation, so .hover-up still lifts. */
  animation-fill-mode: backwards;
}

/* ---------- Effects (modifiers; put on the element or on an m-stagger parent) ---------- */
.m-fadeInUp    { --m-x: 0px;   --m-y: 20px;  --m-s: 1; --m-sy: 1; }
.m-fadeInDown  { --m-x: 0px;   --m-y: -20px; --m-s: 1; --m-sy: 1; }
.m-fadeInLeft  { --m-x: -50px; --m-y: 0px;   --m-s: 1; --m-sy: 1; }  /* enters from the left, like theme fadeInLeft */
.m-fadeInRight { --m-x: 50px;  --m-y: 0px;   --m-s: 1; --m-sy: 1; }
.m-growFade    { --m-x: 0px;   --m-y: 0px;   --m-s: .85; --m-sy: 1; }
.m-growUp      { --m-x: 0px;   --m-y: 0px;   --m-s: 1;   --m-sy: .35; }  /* grows in height from the bottom */
.m-fade        { --m-x: 0px;   --m-y: 0px;   --m-s: 1; --m-sy: 1; }

/* m-growUp grows from the bottom edge (on the element, or each child of a stagger group) */
.m-anim.m-growUp,
.m-stagger.m-growUp > * { transform-origin: 50% 100%; }

/* ---------- Duration / cadence ---------- */
.m-fast        { --m-dur: .35s; }
.m-slow        { --m-dur: .8s; }
.m-step-tight  { --m-step: .09s; }   /* tight card-grid cadence from the prototype */

/* ---------- Delays (per element, in beats of --m-step) ---------- */
.m-delay-0 { --m-delay: 0s; }
.m-delay-1 { --m-delay: calc(1 * var(--m-step)); }
.m-delay-2 { --m-delay: calc(2 * var(--m-step)); }
.m-delay-3 { --m-delay: calc(3 * var(--m-step)); }
.m-delay-4 { --m-delay: calc(4 * var(--m-step)); }
.m-delay-5 { --m-delay: calc(5 * var(--m-step)); }
.m-delay-6 { --m-delay: calc(6 * var(--m-step)); }
.m-delay-7 { --m-delay: calc(7 * var(--m-step)); }
.m-delay-8 { --m-delay: calc(8 * var(--m-step)); }

/* ---------- Group offset (put on a parent: shifts everything inside it) ---------- */
.m-start-1 { --m-start: calc(1 * var(--m-step)); }
.m-start-2 { --m-start: calc(2 * var(--m-step)); }
.m-start-3 { --m-start: calc(3 * var(--m-step)); }
.m-start-4 { --m-start: calc(4 * var(--m-step)); }

/* =========================================================================
   Bridge: theme block styles (is-style-fadeInUp / fadeInLeft / fadeInRight /
   growFade / moveUp) on this template.
   - Same theme keyframes; Mercer timing tokens, delay classes and stagger apply.
   - Mercer's observer is the single trigger, so the theme observer's
     animate__* classes are ignored until .is-visible lands. One threshold, one timing.
   - Selectors outrank the theme's .wp-site-blocks:not(...) rules (0,4,0).
   ========================================================================= */
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout)
  :is(.is-style-fadeInUp, .is-style-fadeInLeft, .is-style-fadeInRight, .is-style-growFade, .is-style-moveUp) {
  animation-duration: var(--m-dur);
  animation-timing-function: var(--m-ease);
  animation-delay: calc(var(--m-start) + var(--m-delay, calc(var(--m-i, 0) * var(--m-step))));
  animation-fill-mode: both; /* theme hidden state needs it; see note on hover below */
}
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout)
  :is(.is-style-fadeInUp, .is-style-fadeInLeft, .is-style-fadeInRight, .is-style-growFade, .is-style-moveUp):not(.is-visible) {
  animation-name: none;
}
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout) .is-style-fadeInUp.is-visible    { animation-name: fadeInUp; }
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout) .is-style-fadeInLeft.is-visible  { animation-name: fadeInLeft; }
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout) .is-style-fadeInRight.is-visible { animation-name: fadeInRight; }
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout) .is-style-growFade.is-visible    { animation-name: growFade; }
html.m-js body.page-template-mercer-template .wp-site-blocks:not(.block-editor-block-list__layout) .is-style-moveUp.is-visible      { animation-name: moveUp; }

/* No JS / script failed to load: don't leave theme-styled blocks invisible */
html:not(.m-js) body.page-template-mercer-template .wp-site-blocks
  :is(.is-style-fadeInUp, .is-style-fadeInLeft, .is-style-fadeInRight, .is-style-growFade, .is-style-moveUp) {
  opacity: 1;
  transform: none;
}

/* ---------- Reduced motion: show everything, animate nothing ---------- */
@media (prefers-reduced-motion: reduce) {
  .m-js :is(.m-anim, .m-stagger > *) {
    opacity: 1 !important;
    animation: none !important;
  }
  body.page-template-mercer-template .wp-site-blocks
    :is(.is-style-fadeInUp, .is-style-fadeInLeft, .is-style-fadeInRight, .is-style-growFade, .is-style-moveUp) {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
}
