/* TechGelato — motion layer (tokens + choreography). Motion only: no colour, type or layout.
   Works together with motion.js, which adds the data-tg-* hooks at runtime.
   Entrances use the individual transform properties (translate / scale) and keyframes, so they
   never overwrite a `transform` or a `transition` declared by site.css / home.css.
   Nothing here hides content unless motion.js has set html.motion-ready AND tagged the element. */

/* ---------------------------------------------------------------- 1. tokens */
:root {
  /* Easings */
  --tg-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --tg-ease-in: cubic-bezier(0.5, 0, 0.9, 0.3);
  --tg-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --tg-ease-back-out: cubic-bezier(0, 0, 0.3, 1.4);
  --tg-ease-anticipate: cubic-bezier(0.65, -0.25, 0.44, 1.3);

  /* Springs: cubic-bezier fallbacks first, linear() versions in the @supports block below */
  --tg-spring-gentle: cubic-bezier(0.22, 1, 0.36, 1);
  --tg-spring-quick: cubic-bezier(0.2, 0.9, 0.3, 1.15);
  --tg-spring-bouncy: cubic-bezier(0, 0, 0.3, 1.4);

  /* Durations */
  --tg-dur-instant: 90ms;
  --tg-dur-fast: 180ms;
  --tg-dur-base: 250ms;
  --tg-dur-medium: 400ms;
  --tg-dur-slow: 640ms;
  --tg-dur-page: 280ms;
  --tg-dur-loop: 1400ms;
  --tg-dur-marquee: 36s;
  --tg-dur-spring-gentle: 420ms;
  --tg-dur-spring-quick: 480ms;
  --tg-dur-spring-bouncy: 640ms;

  /* Stagger */
  --tg-stagger: 50ms;
  --tg-stagger-tight: 30ms;
  --tg-stagger-max: 300ms;
  --tg-follow: 100ms;

  /* Distances and amounts */
  --tg-rise-s: 12px;
  --tg-rise-m: 24px;
  --tg-rise-l: 48px;
  --tg-scale-in: 0.92;
  --tg-scale-hover: 1.03;
  --tg-scale-press: 0.97;
  --tg-squash-x: 1.04;
  --tg-squash-y: 0.94;
  --tg-stretch-x: 0.98;
  --tg-stretch-y: 1.05;
  --tg-tilt-max: 6deg;
  --tg-tilt-perspective: 900px;
  --tg-wobble: 2deg;
  --tg-lift: -6px;
}

@supports (transition-timing-function: linear(0, 1)) {
  :root {
    /* gentle: damping ratio 0.85, overshoot < 1% */
    --tg-spring-gentle: linear(0, 0.047, 0.154, 0.287, 0.423, 0.549, 0.659, 0.75, 0.822, 0.879, 0.921, 0.951, 0.973, 0.987, 0.996, 1.002, 1.005, 1.006, 1.006, 1.006, 1.005, 1.004, 1.003, 1.003, 1);
    /* quick: damping ratio 0.70, overshoot about 4.6% */
    --tg-spring-quick: linear(0, 0.061, 0.201, 0.372, 0.543, 0.694, 0.816, 0.908, 0.973, 1.013, 1.036, 1.045, 1.045, 1.04, 1.033, 1.025, 1.018, 1.011, 1.006, 1.003, 1, 0.999, 0.998, 0.998, 1);
    /* bouncy: damping ratio 0.55, overshoot about 12.6%, one visible rebound */
    --tg-spring-bouncy: linear(0, 0.071, 0.239, 0.447, 0.653, 0.83, 0.966, 1.057, 1.108, 1.126, 1.121, 1.102, 1.076, 1.049, 1.026, 1.008, 0.995, 0.987, 0.984, 0.984, 0.987, 0.99, 0.993, 0.996, 0.999, 1, 1.001, 1.002, 1);
  }
}

@media (max-width: 720px) {
  :root {
    --tg-rise-m: 16px;
    --tg-rise-l: 28px;
    --tg-stagger: 40ms;
    --tg-dur-slow: 520ms;
  }
}

/* ------------------------------------------------------------- 2. keyframes */
/* "to" is always left out: every animation ends on the element's own resting style. */
@keyframes tg-fade { from { opacity: 0; } }
@keyframes tg-rise { from { opacity: 0; translate: 0 var(--tg-rise-m); } }
@keyframes tg-rise-s { from { opacity: 0; translate: 0 var(--tg-rise-s); } }
@keyframes tg-row { from { opacity: 0; translate: 0 8px; } }
@keyframes tg-pop { from { scale: var(--tg-scale-in); } }

/* A machine being put down on the counter: falls a little (spring passes the floor and comes
   back), squashes at contact, stretches, settles. */
@keyframes tg-drop { from { translate: 0 calc(var(--tg-rise-m) * -1); } }
@keyframes tg-squash {
  0% { scale: var(--tg-scale-in); }
  32% { scale: var(--tg-squash-x) 0.95; }
  58% { scale: 0.985 1.03; }
  80% { scale: 1.005 0.996; }
  100% { scale: 1 1; }
}

/* press / release */
@keyframes tg-press { to { scale: var(--tg-squash-x) var(--tg-squash-y); } }
@keyframes tg-release {
  0% { scale: var(--tg-squash-x) var(--tg-squash-y); }
  30% { scale: var(--tg-stretch-x) var(--tg-stretch-y); }
  60% { scale: 1.01 0.99; }
  100% { scale: 1 1; }
}

/* gallery */
@keyframes tg-hold { from, to { opacity: 0; } }
@keyframes tg-swap-out { to { opacity: 0; scale: 0.98; } }
@keyframes tg-swap-in { from { opacity: 0; scale: 1.04; translate: calc(var(--tg-dir, 1) * 16px) 0; } }
@keyframes tg-breathe { from { translate: 0 0; scale: 1; } to { translate: 0 -5px; scale: 1.008; } }

/* chrome */
@keyframes tg-mega-in { from { opacity: 0; translate: 0 -8px; scale: 1 0.98; } }
@keyframes tg-field { from { scale: 0.985; } }
@keyframes tg-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -5px 0; }
  40% { translate: 4px 0; }
  60% { translate: -3px 0; }
  80% { translate: 2px 0; }
}

/* page transition */
@keyframes tg-vt-out { to { opacity: 0; } }
@keyframes tg-vt-in { from { opacity: 0; translate: 0 8px; } }

/* ------------------------------------------------- everything below moves */
@media (prefers-reduced-motion: no-preference) {

  /* ---------------------------------------------- 3. page to page (3.6) */
  @view-transition { navigation: auto; }

  ::view-transition-old(root) { animation: tg-vt-out 120ms var(--tg-ease-in) both; }
  ::view-transition-new(root) { animation: tg-vt-in 240ms var(--tg-ease-out) 80ms both; }

  /* the frame of the site stays still */
  :where(header.top, .top) { view-transition-name: tg-header; }
  ::view-transition-group(tg-header) { animation-duration: 0s; }
  ::view-transition-old(tg-header) { display: none; }
  ::view-transition-new(tg-header) { animation: none; }

  /* tile photo -> product photo. The product image carries the name; motion.js moves the
     name onto the clicked tile's photo (and off #shot) so it is always unique per page. */
  :where(#shot) { view-transition-name: tg-machine; }
  ::view-transition-group(tg-machine) {
    animation-duration: var(--tg-dur-medium);
    animation-timing-function: var(--tg-ease-in-out);
  }
  ::view-transition-old(tg-machine),
  ::view-transition-new(tg-machine) {
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation-duration: var(--tg-dur-medium);
  }

  /* browsers with no view transitions at all: one short fade of the content, nothing else */
  @supports not (view-transition-name: none) {
    :where(main) { animation: tg-fade var(--tg-dur-fast) var(--tg-ease-out) backwards; }
  }

  /* ------------------------------------------ 4. on load, above the fold */
  /* Pure CSS (no JS needed, nothing can stay hidden): the stylesheet is render-blocking, so
     these start with the first paint. Zero specificity: any rule of site.css/home.css wins. */
  :where(.page-head h1, .product h1, [data-motion~="hero-title"]) {
    animation: tg-rise var(--tg-dur-medium) var(--tg-ease-out) backwards;
  }
  :where(.page-head .lede, .product .lede, [data-motion~="hero-text"]) {
    animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) var(--tg-follow) backwards;
  }
  :where([data-motion~="hero-actions"]) {
    animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) 180ms backwards;
  }
  /* the machine of a product page lands */
  :where(#shot):not([data-tg-s]) {
    transform-origin: 50% 100%;
    animation:
      tg-drop var(--tg-dur-spring-bouncy) var(--tg-spring-bouncy) backwards,
      tg-squash var(--tg-dur-spring-bouncy) var(--tg-ease-out) backwards,
      tg-fade var(--tg-dur-fast) var(--tg-ease-out) backwards;
  }
  /* arriving through a view transition: the transition is the entrance, do not stack a second */
  :where(html:active-view-transition, html.tg-arrived) :where(.page-head h1, .product h1, .page-head .lede, .product .lede, [data-motion~="hero-title"], [data-motion~="hero-text"], [data-motion~="hero-actions"]),
  :where(html:active-view-transition, html.tg-arrived) :where(#shot):not([data-tg-s]) {
    animation: none;
  }

  /* --------------------------------------- 5. scroll-in (hooks set by JS) */
  /* hidden-before-reveal: only with JS running, only on elements JS found below the fold */
  html.motion-ready [data-tg-s="wait"] { opacity: 0; }

  [data-tg-s="in"] {
    will-change: transform, opacity;
    animation: tg-rise var(--tg-dur-medium) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  [data-tg-s="in"][data-tg="rise-s"] {
    animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  [data-tg-s="in"][data-tg="row"] {
    animation: tg-row var(--tg-dur-fast) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  [data-tg-s="in"][data-tg="fade"] {
    animation: tg-fade var(--tg-dur-fast) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  [data-tg-s="in"][data-tg="pop"] {
    animation:
      tg-pop var(--tg-dur-spring-quick) var(--tg-spring-quick) var(--tg-d, 0ms) backwards,
      tg-fade var(--tg-dur-fast) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  /* visible from the start (found in view at load): transform only, opacity is never touched */
  [data-tg-s="in"][data-tg="pop-t"] {
    animation: tg-pop var(--tg-dur-spring-quick) var(--tg-spring-quick) var(--tg-d, 0ms) backwards;
  }

  /* machine photos */
  [data-tg-photo] { transform-origin: 50% 100%; }
  [data-tg-photo][data-tg-s="land"] {
    will-change: transform, opacity;
    animation:
      tg-drop var(--tg-dur-spring-bouncy) var(--tg-spring-bouncy) var(--tg-d, 0ms) backwards,
      tg-squash var(--tg-dur-spring-bouncy) var(--tg-ease-out) var(--tg-d, 0ms) backwards,
      tg-fade var(--tg-dur-fast) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  /* already on screen when the script started: same landing, no fade */
  [data-tg-photo][data-tg-s="settle"] {
    will-change: transform;
    animation:
      tg-drop var(--tg-dur-spring-bouncy) var(--tg-spring-bouncy) var(--tg-d, 0ms) backwards,
      tg-squash var(--tg-dur-spring-bouncy) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }
  /* deep rows of long lists: the light version */
  [data-tg-photo][data-tg-s="lite"] {
    will-change: transform, opacity;
    animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) var(--tg-d, 0ms) backwards;
  }

  /* ---------------------------------------------------- 6. press feedback */
  [data-tg-press] { transform-origin: 50% 100%; }
  [data-tg-press="down"] { animation: tg-press var(--tg-dur-instant) var(--tg-ease-out) forwards; }
  [data-tg-press="up"] { animation: tg-release var(--tg-dur-medium) var(--tg-ease-out); }

  /* --------------------------------------------------- 7. product gallery */
  [data-tg-breathe] { animation: tg-breathe 2800ms var(--tg-ease-in-out) infinite alternate; }
  [data-tg-breathe="paused"] { animation-play-state: paused; }
  /* tg-hold ends by itself: if the script stopped here the photo would still come back */
  [data-tg-swap="wait"] { animation: tg-hold 1600ms linear; }
  [data-tg-swap="in"] {
    will-change: transform, opacity;
    animation: tg-swap-in var(--tg-dur-medium) var(--tg-ease-out) 80ms backwards;
  }
  .tg-ghost[data-tg-swap="out"] { animation: tg-swap-out 150ms var(--tg-ease-in) forwards; }
  [data-tg-pop] { animation: tg-pop var(--tg-dur-spring-quick) var(--tg-spring-quick); }

  /* ------------------------------------------------------- 8. site chrome */
  /* mega menu: panel drops in, items follow by column (--tg-i is set by JS, 0 without it),
     the line pictures are the one springy thing */
  .has-mega:hover > .mega,
  .has-mega.open > .mega {
    transform-origin: 50% 0;
    animation: tg-mega-in var(--tg-dur-base) var(--tg-ease-out) backwards;
  }
  .has-mega:hover > .mega a,
  .has-mega.open > .mega a {
    animation: tg-row var(--tg-dur-fast) var(--tg-ease-out) calc(60ms + var(--tg-i, 0) * 40ms) backwards;
  }
  .has-mega:hover > .mega img,
  .has-mega.open > .mega img {
    animation: tg-pop var(--tg-dur-spring-quick) var(--tg-spring-quick) calc(120ms + var(--tg-i, 0) * 40ms) backwards;
  }

  /* sticky header settles once the page has moved under it */
  :where(.top .brand) {
    transform-origin: 0 50%;
    transition: scale var(--tg-dur-spring-quick) var(--tg-spring-quick);
  }
  html.tg-scrolled :where(.top .brand) { scale: 0.94; }

  /* FAQ: the answer comes out of its question */
  :where(main) details[open] > :not(summary) {
    animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) backwards;
  }

  /* forms: a field acknowledges focus; the error line rises; invalid fields shake once */
  :where(.form) :where(input, textarea, select):focus {
    animation: tg-field var(--tg-dur-base) var(--tg-ease-back-out);
  }
  .form-err:not([hidden]) { animation: tg-rise-s var(--tg-dur-base) var(--tg-ease-out) backwards; }
  [data-tg-shake] { animation: tg-shake 320ms var(--tg-ease-out); }
}

/* --------------------------------------------------- 9. reduced motion */
/* Everything visible, nothing transformed, no loops, no view transitions. All moving rules
   above already sit inside no-preference; this block also neutralises hooks left by JS. */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  [data-tg-s], [data-tg-photo], [data-tg-press], [data-tg-breathe], [data-tg-swap], [data-tg-pop], [data-tg-shake] {
    opacity: 1 !important;
    animation: none !important;
    translate: none !important;
    scale: none !important;
    will-change: auto !important;
  }
  [data-tg-photo] { transform: none !important; }
  .tg-ghost { display: none !important; }
}

@media print {
  [data-tg-s], [data-tg-swap] { opacity: 1 !important; animation: none !important; }
  .tg-ghost { display: none !important; }
}
