/**
 * @file
 * The site's motion: one set of tokens and three primitives.
 *
 * Every duration and easing on the site comes from these tokens; no
 * component sets its own timing. Two switches collapse one variable,
 * --biopama-motion: the visitor's "reduce motion" setting and the site
 * store's "Animations: reduced" (akp-motion-reduced on <html>). At 0, the
 * long duration and every travel distance are 0 and the spring is the plain
 * ease, so nothing moves; short fades (quick, base, slow) stay. JavaScript
 * reads the same tokens through biopamaMotion.duration() (js/motion.js).
 *
 * Primitives animate opacity, translate, scale or colour only (never
 * transform or will-change), and are off in print.
 * - .biopama-enter: fade and rise when inserted or when it leaves d-none.
 *   Use it only where the element's own appearance is the event: it replays
 *   when a parent leaves display: none. Exits are instant. Off inside a
 *   [data-biopama-animate-list], whose plugin animates the children.
 * - .biopama-enter-stagger: its first six children enter one after another.
 * - .biopama-saved: a one-shot success glow on a freshly rendered element.
 *
 * Contract (tokens and biopamaMotion): js/motion.js; API.md.
 */

@property --biopama-motion {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

@property --biopama-duration-quick {
  syntax: "<time>";
  inherits: true;
  initial-value: 120ms;
}

@property --biopama-duration-base {
  syntax: "<time>";
  inherits: true;
  initial-value: 200ms;
}

@property --biopama-duration-slow {
  syntax: "<time>";
  inherits: true;
  initial-value: 320ms;
}

@property --biopama-duration-long {
  syntax: "<time>";
  inherits: true;
  initial-value: 600ms;
}

@property --biopama-shift {
  syntax: "<length>";
  inherits: true;
  initial-value: 0.375rem;
}

:root {
  --biopama-motion: 1;
  --biopama-duration-quick: 120ms;
  --biopama-duration-base: 200ms;
  --biopama-duration-slow: 320ms;
  --biopama-duration-long: calc(600ms * var(--biopama-motion));
  --biopama-ease: cubic-bezier(0.2, 0, 0, 1);
  --biopama-ease-spring: linear(0, 0.087 6.25%, 0.274 12.5%, 0.483 18.75%, 0.671 25%, 0.819 31.25%, 0.923 37.5%, 0.988 43.75%, 1.024 50%, 1.038 56.25%, 1.039 62.5%, 1.026 75%, 1.011 87.5%, 1);
  --biopama-shift: calc(0.375rem * var(--biopama-motion));
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --biopama-motion: 0;
    --biopama-ease-spring: var(--biopama-ease);
  }
}

:root.akp-motion-reduced {
  --biopama-motion: 0;
  --biopama-ease-spring: var(--biopama-ease);
}

@media not print {
  .biopama-enter,
  .biopama-enter-stagger > * {
    transition:
      opacity var(--biopama-duration-base) var(--biopama-ease),
      translate var(--biopama-duration-slow) var(--biopama-ease-spring);
  }

  @starting-style {
    .biopama-enter,
    .biopama-enter-stagger > * {
      opacity: 0;
      translate: 0 var(--biopama-shift);
    }
  }

  .biopama-enter-stagger > :nth-child(2) { transition-delay: calc(var(--biopama-duration-quick) / 4 * 1 * var(--biopama-motion)); }
  .biopama-enter-stagger > :nth-child(3) { transition-delay: calc(var(--biopama-duration-quick) / 4 * 2 * var(--biopama-motion)); }
  .biopama-enter-stagger > :nth-child(4) { transition-delay: calc(var(--biopama-duration-quick) / 4 * 3 * var(--biopama-motion)); }
  .biopama-enter-stagger > :nth-child(5) { transition-delay: calc(var(--biopama-duration-quick) / 4 * 4 * var(--biopama-motion)); }
  .biopama-enter-stagger > :nth-child(6) { transition-delay: calc(var(--biopama-duration-quick) / 4 * 5 * var(--biopama-motion)); }

  /* On a Bootstrap button the theme's .btn transition (loaded later, one
     class) would replace the entrance: two classes win, and the button's
     own colour fades stay. */
  .btn.biopama-enter {
    transition:
      opacity var(--biopama-duration-base) var(--biopama-ease),
      translate var(--biopama-duration-slow) var(--biopama-ease-spring),
      color var(--biopama-duration-quick) var(--biopama-ease),
      background-color var(--biopama-duration-quick) var(--biopama-ease),
      border-color var(--biopama-duration-quick) var(--biopama-ease),
      box-shadow var(--biopama-duration-quick) var(--biopama-ease);
  }

  [data-biopama-animate-list] .biopama-enter {
    transition: none;
  }

  .biopama-saved {
    animation: biopama-saved var(--biopama-duration-long) var(--biopama-ease) 1;
  }
}

/*
 * The busy dots: three registered numbers, each a dot's strength, pulsing in
 * turn. A rule draws the dots itself (busy/css/busy.css, the theme's
 * ajax-progress.css) with color-mix() on these numbers and runs
 * biopama-dots for calc(var(--biopama-duration-slow) * 3 *
 * var(--biopama-motion)): at 0 the dots stand still, all three full.
 */
@property --biopama-dot-1 {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

@property --biopama-dot-2 {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

@property --biopama-dot-3 {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

@keyframes biopama-dots {
  0%,
  100% { --biopama-dot-1: 1; --biopama-dot-2: 0.35; --biopama-dot-3: 0.35; }
  33% { --biopama-dot-1: 0.35; --biopama-dot-2: 1; --biopama-dot-3: 0.35; }
  66% { --biopama-dot-1: 0.35; --biopama-dot-2: 0.35; --biopama-dot-3: 1; }
}

@keyframes biopama-saved {
  from {
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-success-rgb), 0.45);
  }

  to {
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-success-rgb), 0);
  }
}
