/*
 * motion.css - motion tokens and the shared motion rules of the theme (plan: MOTION.md, rules: motion-guidelines.md).
 * Loaded on every front-end page right after css/v3b.css (functions.php, aeps_scripts()).
 * Components keep their own transitions in their own files, but take durations and curves from the tokens below.
 *
 *   1. Tokens
 *   2. Press: buttons get a little smaller while pressed
 *   3. Forms: errors and answers fade in
 *   4. Card -> product page: the photo flies
 *   5. Reveal: what the theme used from animate.css (no longer loaded), and the .anima blocks of js/ui.js
 *   6. Reduced motion
 */

/* ========== 1. TOKENS ========== */
:root {
  /* curves */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);      /* appearing, reacting to an action */
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);  /* moving from A to B on screen */
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);       /* only for leaving */
  /* fading out: soft on both ends. --ease-out drops opacity to a third in the first 20% of the time (a blink on a
     160 ms close); this one is still at 90% after 20% and at half in the middle */
  --ease-exit: cubic-bezier(0.4, 0, 0.6, 1);

  /* durations */
  --dur-press: 100ms;
  --dur-fast: 150ms;   /* hover, small elements */
  --dur-base: 200ms;   /* dropdowns, popups, tabs */
  --dur-slow: 300ms;   /* sheets, accordions, big blocks */

  /* closing is about 20% faster than opening */
  --dur-fast-exit: 120ms;
  --dur-base-exit: 160ms;
  --dur-slow-exit: 240ms;

  --stagger: 30ms;
  --stagger-max: 300ms;

  --press-scale: 0.97;
  --press-scale-card: 0.985; /* a big surface: 0.97 of a 560 px card would be a 17 px jump */
}

/* ========== 2. PRESS ========== */
/* The v3b controls (css/v3b.css) with their hover transitions restated on the tokens + the transform of the press.
   Same specificity as in css/v3b.css, this file comes after it. */
.v3b-btn {
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}

.v3b-pill,
.v3b-lang,
.v3b-mm-tog {
  transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}

button.v3b-chip,
a.v3b-chip,
a.v3b-mm-pill {
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}

.v3b-btn:not(:disabled):active,
.v3b-pill:not(:disabled):active,
.v3b-lang:active,
.v3b-mm-tog:active,
button.v3b-chip:not(:disabled):active,
a.v3b-chip:active,
a.v3b-mm-pill:active {
  transform: scale(var(--press-scale));
}

/* Cards that are one big link (a.v3b-glow: homepage categories and news, resources, related products, product guide
   families, series sub-cards). Pressed: a touch smaller at once, back a bit slower; the border glow stays as it is.
   Mouse / trackpad only: on a phone a scroll often starts with the finger on a card, and the card would twitch. */
@media (hover: hover) and (pointer: fine) {
  a.v3b-glow {
    transition: border-color 0.3s, transform var(--dur-fast) var(--ease-out);
  }

  a.v3b-glow:active {
    transform: scale(var(--press-scale-card));
    transition: border-color 0.3s, transform var(--dur-press) var(--ease-out);
  }
}

/* ========== 3. FORMS (Contact Form 7) ========== */
/* An error under a field and CF7's answer box fade in, nothing shakes (guide p.23). CF7 puts a new tip under the field on
   every check, and keeps its answer box at display: none while it sends, so the fade runs again on every answer.
   .cf__ok is the success box of the contact page (css/contact.css, shown by js/contact.js).
   The one pulse of the send button on success is in js/v3b.js (p.22). */
.wpcf7-not-valid-tip {
  animation: motion-tip-in var(--dur-fast) var(--ease-out) backwards;
}

.wpcf7 form .wpcf7-response-output,
.cf__ok {
  animation: motion-fade-in var(--dur-base) var(--ease-out) backwards;
}

@keyframes motion-tip-in {
  from { opacity: 0; transform: translateY(-2px); }
}

@keyframes motion-fade-in {
  from { opacity: 0; }
}

/* ========== 4. CARD -> PRODUCT PAGE ========== */
/* The photo of the clicked product card flies into the photo of the product page (guide p.27). The names are set by the
   inline script of header.php only for that one navigation; the rest of the page cross-fades as before (css/v3b.css, .5 s).
   The flight moves A -> B, so --ease-in-out, as long as the cross-fade. The card and the page crop the photo differently:
   both pictures keep their proportions inside the moving box (contain) instead of being stretched. */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-group(aeps-photo) {
    animation-duration: 0.5s;
    animation-timing-function: var(--ease-in-out);
  }

  ::view-transition-old(aeps-photo),
  ::view-transition-new(aeps-photo) {
    height: 100%;
    object-fit: contain;
  }

  /* arrived by the flight: no fade-in of its own for this page (css/v3b.css "Motion"), the cross-fade already brings it in */
  html.vt-photo main.v3b-pg {
    animation: none;
  }
}

/* ========== 5. REVEAL ========== */
/* animate.css (71 KB on every page) is gone; the theme used three of its classes, kept here under the same names:
     - .animate__animated: the base (length from --animate-duration, css/home.css sets 1.1s; "both" holds the start and end);
     - .animate__fadeIn: the homepage blocks with data-anim="fadeIn" (js/home.js adds the classes, takes them off on animationend);
     - .animate__fadeInUp: no markup uses it now, kept for any left in post content. The stock one moved a block by 100% of its
       height; here it is the 32px rise of the inner pages (css/v3b.css "Motion").
   The homepage's own hpFadeInUp stays in css/home.css. .anima-in: the blocks of js/ui.js (HS2 page, some posts), the same rise. */
.animate__animated {
  animation-duration: var(--animate-duration, 1s);
  animation-fill-mode: both;
}

.animate__fadeIn {
  animation-name: motion-fade;
}

.animate__fadeInUp {
  animation-name: motion-rise;
  animation-timing-function: var(--v3b-ease, cubic-bezier(0.22, 1, 0.36, 1));
}

.anima-in {
  animation: motion-rise 1.1s var(--v3b-ease, cubic-bezier(0.22, 1, 0.36, 1)) backwards;
}

@keyframes motion-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes motion-rise {
  from { opacity: 0; transform: translateY(32px); }
  to { opacity: 1; transform: none; }
}

/* ========== 6. REDUCED MOTION ========== */
/* The visitor asked the system for less motion: everything jumps to its end state at once. Loaders stop too
   (the spinners still show their ring). Focus outlines do not depend on any of this. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}
