/*
 * Motion that never shows at first paint (docs/design/motion.md): interface
 * feedback (hover, press and focus transitions, the header shadow's fade),
 * the scroll reveal, glow, magnet, the word reveal, icons and tilt. Same
 * "motion" layer, same keys and the same order as before the split; the
 * tokens and keyframes it shares are in motion-core.css.
 *
 * Linked right after motion-core.css with media="print" (not
 * render-blocking); site.js switches it to "all" when the document is
 * complete, in the same step that requests motion.js, and a <noscript> copy
 * covers visits without JS. Nothing here can show or shift before that:
 * every rule is a transition, a hover, press or focus state, a custom
 * property for a delay, or a hidden state that needs html.js-motion (set by
 * motion.js, which only loads after this file is on) or the pointer-only
 * .hero__glow (added by motion-desktop.js). Until the switch, hover
 * movement is instant.
 */

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    /* ---- Interface feedback (no key): header, button, menu, FAQ, card links ---- */
    .site-header::after {
      transition: opacity var(--motion-base) var(--ease-out);
    }

    .site-header__logo img,
    .btn__arrow,
    .site-nav__chevron,
    .faq__question::before,
    .faq__question::after,
    .tile__arrow {
      transition: transform var(--motion-base) var(--ease-out);
    }

    .btn {
      transition: transform var(--motion-fast) var(--ease-out);
    }

    .btn:not(.btn--link):hover {
      transform: translateY(-2px);
    }

    .btn:not(.btn--link):active {
      transform: translateY(1px) scale(0.98);
      transition-duration: 80ms;
    }

    .btn:is(:hover, :focus-visible) .btn__arrow {
      transform: translateX(5px);
    }

    .btn--back:is(:hover, :focus-visible) .btn__arrow {
      transform: scaleX(-1) translateX(5px);
    }

    .nav-toggle__icon,
    .nav-toggle__icon::before,
    .nav-toggle__icon::after {
      transition: transform var(--motion-base) var(--ease-out), opacity var(--motion-base) var(--ease-out);
    }

    a.tile:is(:hover, :focus-visible) .tile__arrow {
      transform: translate(3px, -3px);
    }

    /* fx:reveal ---- Scroll reveal: sections and cards below the fold fade and rise once
       (motion.js tags them data-reveal and adds is-in in view). Cards stagger by position
       (capped at 6). The case study chip, the featured member's text and the count-up
       follow their card or section. */
    [data-reveal] {
      transition: opacity var(--motion-reveal) var(--ease-out), transform var(--motion-reveal) var(--ease-out);
      transition-delay: calc(var(--i, 0) * var(--motion-stagger));
    }

    [data-reveal]:nth-child(2) {
      --i: 1;
    }

    [data-reveal]:nth-child(3) {
      --i: 2;
    }

    [data-reveal]:nth-child(4) {
      --i: 3;
    }

    [data-reveal]:nth-child(5) {
      --i: 4;
    }

    [data-reveal]:nth-child(6) {
      --i: 5;
    }

    [data-reveal]:nth-child(n + 7) {
      --i: 6;
    }

    :is(.container, .story__chapter)[data-reveal] {
      --i: 0;
    }

    html.js-motion[data-fx~="reveal"] [data-reveal]:not(.is-in) {
      opacity: 0;
      transform: translateY(var(--motion-rise));
    }

    /* /fx:reveal */

    /* fx:glow ---- Cursor glow in the hero (pointer devices only): motion-desktop.js adds
       .hero__glow to .hero__shapes and moves it with one transform per frame. */
    html[data-fx~="glow"] .hero__glow {
      position: absolute;
      top: -16rem;
      left: -16rem;
      width: 32rem;
      height: 32rem;
      border-radius: 50%;
      background: radial-gradient(circle, var(--color-brand-glow-strong), var(--color-brand-clear) 62%);
      opacity: 0;
      transition: opacity 500ms var(--ease-out);
      will-change: transform;
      pointer-events: none;
    }

    html[data-fx~="glow"] .hero__glow.is-on {
      opacity: 1;
    }
    /* /fx:glow */

    /* fx:magnet ---- Magnetic button (pointer devices, motion-desktop.js writes an inline
       translate; this smooths the lean and the settle). */
    html[data-fx~="magnet"] .btn {
      transition: transform var(--motion-fast) var(--ease-out), translate 160ms var(--ease-out);
    }
    /* /fx:magnet */

    /* fx:lines ---- (the word spans' display is in motion-core.css) When the section
       reveals the words rise and fade in reading order, 45ms apart (90ms on the statement,
       whose band box stays put and whose button follows the words). */
    html[data-fx~="lines"] :is(.w, .statement--words .statement__actions) {
      transition: opacity var(--motion-reveal) var(--ease-out), transform var(--motion-reveal) var(--ease-out);
      transition-delay: calc(var(--w, 0) * var(--w-step, 45ms) + 120ms);
    }

    .statement--words {
      --w-step: 90ms;
    }

    .statement--words .statement__actions {
      --w: 13;
    }

    html.js-motion[data-fx~="lines"] [data-reveal]:not(.is-in) :is(.w, .statement--words .statement__actions) {
      opacity: 0;
      transform: translateY(0.45em);
    }

    html.js-motion[data-fx~="lines"] [data-reveal]:not(.is-in):has(> .statement--words) {
      opacity: 1;
      transform: none;
    }

    .w:nth-child(2) {
      --w: 1;
    }

    .w:nth-child(3) {
      --w: 2;
    }

    .w:nth-child(4) {
      --w: 3;
    }

    .w:nth-child(5) {
      --w: 4;
    }

    .w:nth-child(6) {
      --w: 5;
    }

    .w:nth-child(7) {
      --w: 6;
    }

    .w:nth-child(8) {
      --w: 7;
    }

    .w:nth-child(9) {
      --w: 8;
    }

    .w:nth-child(10) {
      --w: 9;
    }

    .w:nth-child(11) {
      --w: 10;
    }

    .w:nth-child(12) {
      --w: 11;
    }

    .w:nth-child(n + 13) {
      --w: 12;
    }
    /* /fx:lines */

    /* fx:icons ---- Icons pop in after their card reveals: the icon cards' discs (tier pages),
       scale and a small turn, from the same observer. */
    html[data-fx~="icons"] .icon-card__icon {
      transition: transform var(--motion-reveal) var(--ease-pop);
      transition-delay: calc(var(--i, 0) * var(--motion-stagger) + 160ms);
    }

    html.js-motion[data-fx~="icons"] .icon-card[data-reveal]:not(.is-in) .icon-card__icon {
      transform: scale(0.6) rotate(-8deg);
    }
    /* /fx:icons */

    /* fx:tilt ---- Playful cards: team cards
       (About) settle from the reveal into their tilt and straighten and lift on hover or focus;
       feeling cards (About) come in tilted and lift and tilt on hover or press; the icons
       wiggle once. The team card flip turns over 620ms (instant without the key). */
    html[data-fx~="tilt"] :is(.team-card, .feel-card) {
      transition: opacity var(--motion-reveal) var(--ease-out), transform var(--motion-base) var(--ease-pop);
    }

    html[data-fx~="tilt"] :is(.team-card, .feel-card)[data-reveal] {
      transition-duration: var(--motion-reveal);
      transition-delay: calc(var(--i, 0) * var(--motion-stagger));
    }

    html[data-fx~="tilt"] .team-card:is(:hover, :focus-within) {
      transform: translateY(-6px) rotate(0deg);
    }

    html[data-fx~="tilt"] .feel-card:is(:hover, :active) {
      transform: translateY(-8px) rotate(-1.5deg);
    }

    html[data-fx~="tilt"] .feel-card:nth-child(even):is(:hover, :active) {
      transform: translateY(-8px) rotate(1.5deg);
    }

    html[data-fx~="tilt"] :is(.team-card, .feel-card):is(:hover, :focus-within, :active) {
      transition-duration: var(--motion-base);
      transition-delay: 0s;
    }

    html.js-motion[data-fx~="tilt"] .feel-card[data-reveal]:not(.is-in) {
      transform: translateY(var(--motion-rise)) rotate(-3deg);
    }

    html[data-fx~="tilt"] .feel-card:is(:hover, :active) .feel-card__icon {
      animation: motion-wiggle 600ms var(--ease-out);
    }

    html[data-fx~="tilt"] .team-card__inner {
      transition: transform 620ms var(--ease-out);
    }
    /* /fx:tilt */
  }

  @keyframes motion-wiggle {
    25% {
      transform: rotate(-8deg);
    }

    75% {
      transform: rotate(8deg);
    }
  }

}
