/* ==========================================================================
   3EBS.PLANET — MOTION LAYER
   Scroll reveals, page transitions, logo loader, product-card media swap.
   Rules: transform/opacity only, CSS-driven, opt-out with reduced motion,
   and nothing here may hide content if the motion script never runs.
   ========================================================================== */

:root {
  --reveal-duration: 560ms;
  --reveal-distance: 20px;
  --reveal-stagger: 70ms;
  --swap-duration: 320ms;
  --page-in-duration: 260ms;
  --page-out-duration: 220ms;
}

/* If the motion script never runs (JS off or a load error), never hide content */
html:not(.js-motion) .reveal {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  /* ---------- Scroll reveal with stagger ---------- */
  .reveal {
    opacity: 0;
    transform: translate3d(0, var(--reveal-distance), 0);
    transition:
      opacity var(--reveal-duration) var(--ease-chrome),
      transform var(--reveal-duration) var(--ease-chrome);
    transition-delay: calc(var(--reveal-i, 0) * var(--reveal-stagger));
  }

  .reveal.is-visible {
    opacity: 1;
    transform: none;
  }

  /* ---------- Page enter (opacity only: never breaks fixed-position UI) ---------- */
  html.js-motion body {
    animation: pageIn var(--page-in-duration) var(--ease-chrome) both;
  }

  @keyframes pageIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  /* ---------- Page leave ----------
     Fades the page's children, not <body> itself: fading body also faded the
     loader that sits inside it, which is why the logo never showed. */
  html.is-leaving body > *:not(.page-loader) {
    opacity: 0;
    transition: opacity var(--page-out-duration) ease-in;
  }

  html.is-leaving body {
    animation: none;
    pointer-events: none;
  }

  /* ---------- Logo loader ---------- */
  .page-loader {
    transition: opacity 200ms ease, visibility 0s linear 200ms;
  }

  .page-loader.is-on {
    transition: opacity 110ms ease;
  }

  .page-loader__bar::after {
    animation: loaderSlide 900ms var(--ease-chrome) infinite;
  }

  @keyframes loaderSlide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(320%); }
  }
}

/* ---------- Logo loader shell ----------
   Shown and hidden here, outside the motion query, so the mark also appears
   for anyone with reduced motion on (it is a static image, not an animation). */
.page-loader {
  opacity: 0;
  visibility: hidden;
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--color-bg);
  pointer-events: none;
}

.page-loader.is-on {
  opacity: 1;
  visibility: visible;
}

.page-loader__mark {
  /* The emblem is a dark chrome mark: on the near-black page background it is
     almost invisible at phone size, which reads as "no logo at all". Lifting
     its brightness keeps the chrome detail and makes it unmistakable. */
  width: clamp(104px, 26vw, 140px);
  height: auto;
  opacity: 0.98;
  filter: brightness(1.85) drop-shadow(0 0 22px rgba(255, 255, 255, 0.16));
}

html[data-theme="light"] .page-loader__mark {
  filter: drop-shadow(0 4px 12px rgba(20, 20, 22, 0.2));
}

.page-loader__bar {
  position: relative;
  width: clamp(132px, 34vw, 190px);
  height: 2px;
  overflow: hidden;
  background: var(--color-border);
}

.page-loader__bar::after {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 34%;
  background: var(--color-ink);
}

/* ---------- Product card media swap ----------
   The front shot clears fast, the second shot fades in over it. Fading both
   at the same speed double-exposes two different photos mid-swap. */
.product-card__img {
  transition:
    transform 300ms var(--ease-chrome),
    opacity var(--swap-duration) var(--ease-chrome);
}

.product-card__img--primary {
  transition:
    transform 300ms var(--ease-chrome),
    opacity 140ms linear;
}

@media (hover: hover) {
  .product-card:hover .product-card__img--primary {
    opacity: 0;
  }
}

.product-card__dots {
  display: none;
}

/* Touch devices get real dots instead of hover-only behaviour */
@media (hover: none), (pointer: coarse) {
  .product-card__dots {
    position: absolute;
    inset-inline: 0;
    bottom: 10px;
    z-index: 3;
    display: flex;
    justify-content: center;
    gap: 7px;
  }

  .product-card__dot {
    width: 7px;
    height: 7px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22);
    cursor: pointer;
  }

  .product-card__dot.is-active {
    background: #fff;
  }

  /* A tap leaves a sticky :hover behind on phones; the dots must win. */
  .product-card:hover .product-card__img--hover {
    opacity: 0;
  }

  .product-card:hover .product-card__img--primary {
    transform: none;
  }

  .product-card.is-swap .product-card__img--primary {
    opacity: 0;
  }

  .product-card.is-swap .product-card__img--hover {
    opacity: 1;
  }
}

/* ---------- Touch devices: instant and light ----------
   A phone tap should not wait on a fade. The mark is painted on the first
   frame and the page changes right after, so the transition reads as a quick
   beat instead of a drag. */
@media (hover: none), (pointer: coarse) {
  :root {
    --page-in-duration: 150ms;
    --page-out-duration: 90ms;
  }

  .page-loader,
  .page-loader.is-on {
    transition: none;
  }

  html.is-leaving body > *:not(.page-loader) {
    opacity: 0;
    transition: none;
  }
}
