/* ==========================================================================
   Galaxy Star - motion
   --------------------------------------------------------------------------
   The movement on the shop pages: a 3D entrance for the hero, a 3D lift under
   the pointer for tiles and product cards, and a scroll reveal for everything
   below the fold.

   Three rules this file keeps to, because each one has broken a shop before:

   1. Nothing is hidden unless JavaScript has said it is safe to hide it.
      Every reveal rule is scoped to .js-motion, a class motion.js puts on <html>
      once it is running. With scripting off, or motion.js failing to load, the
      page is simply still - never blank. A shop that shows nothing because a
      script 404'd is worse than a shop that does not move.

   2. Only transform and opacity are animated. Width, height, top and left are
      not touched anywhere below. Animating those forces the browser to lay the
      page out again on every frame, which is what makes a phone heat up and a
      scroll stutter.

   3. prefers-reduced-motion turns all of it off, not just the big parts. Some
      people get motion sickness from a card that slides in from below, and
      "reduced" has to mean reduced.

   Loaded after style.css, so anything here wins on equal specificity.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. The reveal
   --------------------------------------------------------------------------
   Driven off the real class names rather than a data attribute, so the same
   rules work on the shop grid and the product page without every page having
   to be marked up by hand. motion.js watches this identical list.
   -------------------------------------------------------------------------- */

.js-motion .cat-tile,
.js-motion .pcard,
.js-motion .section__head,
.js-motion .stat {
  opacity: 0;
  transform: perspective(900px) translate3d(0, 26px, 0) rotateX(4deg);
  transform-origin: 50% 100%;
  transition:
    opacity .62s cubic-bezier(.22, .68, .32, 1),
    transform .62s cubic-bezier(.22, .68, .32, 1);
  transition-delay: var(--motion-delay, 0ms);
}

.js-motion .cat-tile.is-in,
.js-motion .pcard.is-in,
.js-motion .section__head.is-in,
.js-motion .stat.is-in {
  opacity: 1;
  transform: perspective(900px) translate3d(0, 0, 0) rotateX(0deg);
}

/* Headings carry text, and 4 degrees of turn on a line of words reads as a
   rendering fault rather than as movement. They rise, they do not turn. */
.js-motion .section__head,
.js-motion .stat {
  transform: perspective(900px) translate3d(0, 18px, 0);
}

.js-motion .section__head.is-in,
.js-motion .stat.is-in {
  transform: perspective(900px) translate3d(0, 0, 0);
}

/* Anything a page marks up by hand still works, for a one-off. */
.js-motion [data-motion="rise"] {
  opacity: 0;
  transform: perspective(900px) translate3d(0, 26px, 0) rotateX(4deg);
  transform-origin: 50% 100%;
  transition:
    opacity .62s cubic-bezier(.22, .68, .32, 1),
    transform .62s cubic-bezier(.22, .68, .32, 1);
  transition-delay: var(--motion-delay, 0ms);
}

.js-motion [data-motion="rise"].is-in {
  opacity: 1;
  transform: perspective(900px) translate3d(0, 0, 0) rotateX(0deg);
}

.js-motion [data-motion="fade"] {
  opacity: 0;
  transform: translate3d(0, 16px, 0);
  transition:
    opacity .6s ease,
    transform .6s cubic-bezier(.22, .68, .32, 1);
  transition-delay: var(--motion-delay, 0ms);
}

.js-motion [data-motion="fade"].is-in {
  opacity: 1;
  transform: none;
}

.js-motion [data-motion="scale"] {
  opacity: 0;
  transform: perspective(800px) scale3d(.94, .94, 1);
  transition:
    opacity .6s cubic-bezier(.22, .68, .32, 1),
    transform .6s cubic-bezier(.22, .68, .32, 1);
  transition-delay: var(--motion-delay, 0ms);
}

.js-motion [data-motion="scale"].is-in {
  opacity: 1;
  transform: perspective(800px) scale3d(1, 1, 1);
}

/*
  On a narrow screen the hero is one column and already fills the view, so
  waiting for it to scroll into view would mean it never plays. It plays on
  load instead - see motion.js - and only the reveal distances are shortened.
*/
@media (max-width: 760px) {
  .js-motion .cat-tile,
  .js-motion .pcard,
  .js-motion .section__head,
  .js-motion .stat,
  .js-motion [data-motion] {
    transition-duration: .45s;
  }
  .js-motion .cat-tile,
  .js-motion .pcard,
  .js-motion [data-motion="rise"] {
    transform: perspective(900px) translate3d(0, 18px, 0);
  }
  .js-motion .cat-tile.is-in,
  .js-motion .pcard.is-in,
  .js-motion [data-motion="rise"].is-in {
    transform: perspective(900px) translate3d(0, 0, 0);
  }
}

/* --------------------------------------------------------------------------
   2. The hero, in 3D
   -------------------------------------------------------------------------- */

.js-motion .hero__grid {
  perspective: 1200px;
  perspective-origin: 50% 40%;
}

/*
  The picture stands up out of the page. perspective is on the parent so this
  is a real 3D rotation rather than a flattened scale, which is the whole
  difference between a shoe sitting on a shelf and a card being turned.
*/
.js-motion .hero__art {
  transform-style: preserve-3d;
  transform: perspective(1400px) rotateY(-9deg) rotateX(4deg) translate3d(0, 0, 0);
  transition: transform .8s cubic-bezier(.2, .7, .3, 1);
  will-change: transform;
}

.js-motion .hero__art img {
  transform: translateZ(28px);
  transition: transform .8s cubic-bezier(.2, .7, .3, 1);
}

/* The gentle bob. transform only, so it stays on the compositor. */
.js-motion .hero__art.is-floating {
  animation: gs-float 6.5s ease-in-out infinite;
}

@keyframes gs-float {
  0%, 100% { transform: perspective(1400px) rotateY(-9deg) rotateX(4deg) translate3d(0, 0, 0); }
  50%      { transform: perspective(1400px) rotateY(-5deg)  rotateX(1deg) translate3d(0, -14px, 0); }
}

/* Text steps in one after another. */
.js-motion .hero__title,
.js-motion .hero__text,
.js-motion .hero__cta,
.js-motion .hero__badges {
  opacity: 0;
  transform: perspective(1000px) translate3d(0, 22px, 0) rotateX(5deg);
  transform-origin: 0% 100%;
  transition:
    opacity .7s cubic-bezier(.22, .68, .32, 1),
    transform .7s cubic-bezier(.22, .68, .32, 1);
}

.js-motion .hero__title.is-in { transition-delay: 60ms; }
.js-motion .hero__text.is-in  { transition-delay: 170ms; }
.js-motion .hero__cta.is-in   { transition-delay: 280ms; }
.js-motion .hero__badges.is-in { transition-delay: 390ms; }

.js-motion .hero__title.is-in,
.js-motion .hero__text.is-in,
.js-motion .hero__cta.is-in,
.js-motion .hero__badges.is-in {
  opacity: 1;
  transform: perspective(1000px) translate3d(0, 0, 0) rotateX(0deg);
}

@media (max-width: 860px) {
  /* Turned back to face the reader once the picture is under the text. */
  .js-motion .hero__art,
  .js-motion .hero__art.is-floating {
    animation: none;
    transform: perspective(1200px) rotateX(3deg);
  }
  .js-motion .hero__art img { transform: translateZ(16px); }
}

/* --------------------------------------------------------------------------
   3. 3D under the pointer
   --------------------------------------------------------------------------
   Only where there is a real pointer. On a phone this whole block is off, which
   matters: a tilt that only responds to a finger is a finger dragging the card
   around, and it fights the scroll.
   -------------------------------------------------------------------------- */

@media (hover: hover) and (pointer: fine) {
  .js-motion .cat-tile,
  .js-motion .pcard {
    transform-style: preserve-3d;
    /* --tilt-x and --tilt-y are written by motion.js; 0 means "not hovered". */
    transform: perspective(800px)
               rotateX(calc(var(--tilt-y, 0) * -1deg))
               rotateY(calc(var(--tilt-x, 0) * 1deg))
               translate3d(0, 0, 0);
    transition: transform .45s cubic-bezier(.2, .7, .3, 1), box-shadow .45s ease;
  }

  .js-motion .cat-tile:hover,
  .js-motion .pcard:hover {
    transform: perspective(800px)
               rotateX(calc(var(--tilt-y, 0) * -1deg))
               rotateY(calc(var(--tilt-x, 0) * 1deg))
               translate3d(0, -8px, 26px);
    box-shadow: 0 22px 44px -18px rgba(180, 40, 90, .38);
  }

  /* The picture inside leans a little further than the card it sits on, which
     is what gives the depth rather than a single flat card tilting. */
  .js-motion .cat-tile__img,
  .js-motion .pcard__img,
  .js-motion .pcard img {
    transform: translate3d(0, 0, 18px) scale(1.04);
    transition: transform .45s cubic-bezier(.2, .7, .3, 1);
  }

  .js-motion .cat-tile:hover .cat-tile__img,
  .js-motion .pcard:hover .pcard__img,
  .js-motion .pcard:hover img {
    transform: translate3d(0, 0, 40px) scale(1.07);
  }

  .js-motion .cat-tile__body,
  .js-motion .pcard__body {
    transform: translate3d(0, 0, 22px);
    transition: transform .45s cubic-bezier(.2, .7, .3, 1);
  }
}

/* --------------------------------------------------------------------------
   4. The bits that move on their own
   -------------------------------------------------------------------------- */

/*
  A slow drift on the soft pink panels. Two of them, out of step, so the page
  does not pulse. Very low amplitude: enough that a still screenshot looks
  wrong in a way you cannot quite name, not enough to notice as motion.
*/
.js-motion .section--pink::before,
.js-motion .hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(closest-side, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 70%),
    radial-gradient(closest-side, rgba(214, 51, 108, .07), rgba(214, 51, 108, 0) 70%);
  background-repeat: no-repeat;
  background-size: 46% 60%, 40% 52%;
  background-position: 12% 18%, 88% 78%;
  animation: gs-drift 26s ease-in-out infinite alternate;
  will-change: background-position;
}

.js-motion .section--pink { position: relative; overflow: hidden; }
.js-motion .hero { position: relative; overflow: hidden; }

@keyframes gs-drift {
  0%   { background-position: 10% 16%, 90% 80%; }
  100% { background-position: 22% 30%, 76% 66%; }
}

/* A badge that lifts a little on its own, staggered. */
.js-motion .hero__badge {
  transition: transform .4s cubic-bezier(.2, .7, .3, 1);
}

@media (hover: hover) and (pointer: fine) {
  .js-motion .hero__badge:hover {
    transform: translate3d(0, -4px, 0);
  }
}

/* The count-down numbers tick rather than jump. */
.js-motion .countdown__num {
  display: inline-block;
  transition: transform .35s cubic-bezier(.2, .7, .3, 1);
}

/* --------------------------------------------------------------------------
   5. Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  /*
    Set to visible, not just "animation: none". A rule above has these at
    opacity 0 while waiting to be revealed, and cancelling the animation would
    leave them at 0 - the exact blank page rule 1 exists to prevent.
  */
  .js-motion [data-motion],
  .js-motion .hero__title,
  .js-motion .hero__text,
  .js-motion .hero__cta,
  .js-motion .hero__badges {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }

  .js-motion .hero__art,
  .js-motion .hero__art img,
  .js-motion .cat-tile,
  .js-motion .pcard,
  .js-motion .cat-tile__img,
  .js-motion .pcard img,
  .js-motion .cat-tile__body,
  .js-motion .pcard__body,
  .js-motion .section--pink::before,
  .js-motion .hero::after,
  .js-motion .hero__badge,
  .js-motion .countdown__num {
    transform: none !important;
    animation: none !important;
    transition: none !important;
    will-change: auto !important;
  }
}

/* Very low power: keep the reveal, drop the ambient loops that never stop. */
@media (prefers-reduced-motion: reduce) and (prefers-contrast: more) {
  .js-motion [data-motion] { transition: opacity .2s linear !important; }
}

/* Print: none of this belongs on paper. */
@media print {
  .js-motion * {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
