/* Motion for scroll-driven sections (trust banner, About page). Markup comes from snippets/motion.php; assets/motion.js sets
 * --pp-p (0 = entering the viewport, 1 = settled) and --pp-b (0 = centre at the bottom, 1 = card midpoint) on each
 * [data-pp-motion] section. Gears turn by (p - 1) × --turn, so they settle at 0. Petals open from their --d and are fully
 * open at --pp-b = 1.
 * Without JS, or with reduced motion, --pp-p stays 1 and everything shows its final layout. */

.pp-motion {
  --pp-p: 1;
  --pp-b: 1;
  --pp-c: 1;
  --pp-gear: clamp(16rem, 55cqi, 44rem);
  --pp-flower: var(--pp-gear);
  container-type: inline-size;
  position: relative;
  overflow-x: clip;
  padding: 4rem 1.5rem;
  background: #f6f6f6;
}

/* About: the sections are transparent and sit on one wrapper (.pp-about-stack, see about_page.php). Its gradient runs from
 * white at the top, through warm ivory, back to white at the bottom, so there are no section edges to see. */
.pp-motion.pp-about {
  background: transparent;
}

/* Botanical artwork fades out over a short band at its section's top and bottom, so stems meet the neighbouring gears with
 * no hard line, and never reach over them (they are clipped to the section). Gears are not faded or clipped vertically:
 * their sections let them draw past the top and bottom edges. */
.pp-about--botany .pp-motion__bg {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 5%, #000 95%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 5%, #000 95%, transparent 100%);
}

.pp-about:not(.pp-about--botany) .pp-motion__bg {
  overflow-y: visible;
}

/* The top card starts level with the gallery's first product image: the theme's main padding and content margin above
 * the About stack are removed here, and the stack pulls up to the same line (its card has a 4rem top padding). The bottom
 * padding of main and the spacer and empty group after the stack are removed too, so the last card ends at the footer
 * with only its own section padding. */
.pp-about-page .wp-site-blocks > main { padding-top: 0 !important; padding-bottom: 0 !important; }
.pp-about-page main > .entry-content ~ .wp-block-spacer,
.pp-about-page main > .entry-content ~ .wp-block-group { display: none; }
.pp-about-page .entry-content { margin-top: 0; }
.pp-about-page .pp-about-stack { margin-top: -13px; }
/* Above 720px the gallery's top gap grows with width (it is fluid), so the pull-up follows it between 1024px and 1440px. */
@media (min-width: 721px) {
  .pp-about-page .pp-about-stack { margin-top: clamp(-29px, calc(-28px + (100vw - 1024px) * 0.036), -13px); }
}

/* Cards sit above every section's artwork, so gears that reach past their section never draw over a card. */
.pp-about .pp-motion__card {
  z-index: 1;
}

/* A short card (Why Us) is solid over more of the scroll: its opacity reaches 1 at a quarter of the progress, so it is
 * solid once its top is about 60% of the way up the screen. Scoped with the section class so it beats the base fade rule. */
.pp-motion.pp-about--short.is-animated .pp-motion__card {
  opacity: min(calc(var(--pp-p) * 4), 1);
}

.pp-about-page .pp-about-stack {
  position: relative;
  width: 100vw;
  left: calc(50% - 50vw);
  /* Clips at the stack's edges, which are white, so no flower is cut off along a section boundary. */
  overflow: clip;
  background: linear-gradient(to bottom, #fff 0%, #F9F7F3 14%, #F9F7F3 86%, #fff 100%);
}

.pp-motion__bg {
  position: absolute;
  inset: 0;
  overflow-x: visible;
  overflow-y: clip;
  pointer-events: none;
}

/* Gears: --x is the centre in gear widths from the section centre. Each wheel is one gear wide, so its left edge is
 * its centre minus half a width. */
.pp-motion__gear {
  --x: 0;
  --turn: 0deg;
  position: absolute;
  top: 50%;
  left: calc(50% + var(--pp-gear) * (var(--x) - 0.5));
  width: var(--pp-gear);
  height: auto;
  margin-top: calc(var(--pp-gear) / -2);
  fill: none;
  stroke: #b5b5b5;
  opacity: 0.72;
}

.pp-motion__gear *,
.pp-motion__flower * {
  vector-effect: non-scaling-stroke;
  stroke-width: 1px;
}

.pp-motion__pivot {
  fill: #b5b5b5;
  stroke: none;
}

.pp-motion.is-animated .pp-motion__gear {
  transform: rotate(calc((var(--pp-p) - 1) * var(--turn)));
}

/* Flowers: petals are drawn from the flower head, so they bloom outward and the flower never rotates. Stems run past the
 * box, so overflow shows. --k (set per flower) scales its bloom rate. */
.pp-motion__flower {
  position: absolute;
  width: var(--s);
  height: auto;
  overflow: visible;
  fill: none;
  stroke: #A39383;
  opacity: 0.8;
}

.pp-motion__bud {
  transform-box: view-box;
  transform-origin: 50% 50%;
}

/* Petals and stamen threads draw their outline out from the head, like the stems, so each one grows from the stem and
 * then blooms. A petal starts at --d and is fully drawn when the bloom (--pp-b × --k, the card's midpoint for k = 1) reaches 1. */
.pp-motion__petal {
  vector-effect: none;
  stroke-width: 0.6px;
  stroke-dasharray: 1px;
  stroke-dashoffset: 0;
}

/* Stamen dots wait for --ready (once --pp-p passes 0.5), so none grows before its section is well into view. Petals and
 * stems are timed by is-blooming (see below), not by scroll. */
.pp-motion.is-animated {
  --ready: clamp(0, (var(--pp-p) - 0.5) * 4, 1);
}

/* Petals and stamens bloom on their own once their flower comes into view (is-blooming, set by the observer in motion.php),
 * so no scroll speed can rush them. Each opens after its --d and takes 3.5 seconds. Until then it is hidden. */
.pp-motion.is-animated .pp-motion__petal {
  stroke-dashoffset: 1px;
  fill-opacity: 0;
}

.pp-motion.is-animated.is-blooming .pp-motion__petal {
  animation: pp-bloom calc(2.84s / var(--k, 1)) cubic-bezier(0.3, 0, 0.2, 1) both;
  animation-delay: calc(0.51s + var(--d) * 1.01s);
}

@keyframes pp-bloom {
  from { stroke-dashoffset: 1px; fill-opacity: 0; }
  to { stroke-dashoffset: 0; fill-opacity: 1; }
}

/* Solid petals are filled with the page colour, so they hide the contours behind them. The fill fades in with the outline. */
.pp-motion__petal--solid { fill: #F9F7F3; }
.pp-motion__head { fill: #F9F7F3; stroke: none; }

/* Stamen tips are dots: they grow in place with the bloom. */
.pp-motion__dot {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

.pp-motion.is-animated .pp-motion__dot {
  transform: scale(calc(clamp(0, (var(--pp-b) * var(--k, 1) - var(--d)) / (1 - var(--d)), 1) * var(--ready)));
}

/* The bud swells from the head as the stem reaches it, and is gone by the time the petals have opened. */
.pp-motion.is-animated .pp-motion__bud {
  transform: scale(0);
  opacity: 0;
}

.pp-motion.is-animated.is-blooming .pp-motion__bud {
  animation: pp-bud 1.21s ease-in-out both;
  animation-delay: calc(var(--d) * 1.01s + 0.15s);
}

@keyframes pp-bud {
  0% { transform: scale(0); opacity: 1; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* Stems and leaves: the outline draws in from its first point (dash offset over pathLength 1). Stems start at their base,
 * so they grow up to the head. Not non-scaling, so the dash follows the path. Without JS the outline is complete. */
.pp-motion__stem,
.pp-motion__leaf {
  vector-effect: none;
  stroke-width: 0.35px;
  stroke-dasharray: 1px;
  stroke-dashoffset: 0;
}

/* Stems, leaves and buds grow once, when their flower comes into view (is-blooming), like the petals. Nothing they do
 * reverses when the page is scrolled back, so a flower never ungrows. */
.pp-motion.is-animated .pp-motion__stem,
.pp-motion.is-animated .pp-motion__leaf {
  stroke-dashoffset: 1px;
}

.pp-motion.is-animated.is-blooming .pp-motion__stem {
  animation: pp-grow 0.81s ease-in-out both;
  animation-delay: calc(var(--d) * 1.01s);
}

.pp-motion.is-animated.is-blooming .pp-motion__leaf {
  animation: pp-grow 0.81s ease-in-out both;
  animation-delay: calc(var(--d) * 1.01s + 0.1s);
}

@keyframes pp-grow {
  from { stroke-dashoffset: 1px; }
  to { stroke-dashoffset: 0; }
}

/* Card: rises and fades in with the section's progress. */
.pp-motion__card {
  position: relative;
  max-width: 42rem;
  margin: 0 auto;
  padding: 2.5rem 2.25rem;
  background: #fff;
  border: 1px solid #e8e8e4;
  border-radius: 10px;
}

.pp-motion.is-animated .pp-motion__card {
  opacity: min(var(--pp-p), 1);
  transform: translate3d(0, calc((1 - min(var(--pp-p), 1)) * 2.5rem), 0);
}

@media (max-width: 720px) {
  .pp-motion {
    --pp-gear: 9.5rem;
    --pp-flower: 14rem;
    padding: 3rem 1rem;
  }

  .pp-motion__card {
    padding: 1.75rem 1.25rem;
  }
}

/* About botany: where each piece sits (its size and bloom speed are set inline). The second botanical section is mirrored. */
.pp-botany--lily { left: -16%; top: 2%; }
.pp-botany--blossom { right: -3%; top: -6%; }
.pp-botany--tulip { right: 1%; bottom: -8%; }
.pp-botany--small { right: 6%; top: 40%; }
.pp-botany--small-left { left: 6%; top: 60%; }
.pp-about--mirror .pp-motion__bg { transform: scaleX(-1); }
/* The mirrored section's left-side flowers (its right-side pieces, flipped) sit clear of the card: pushed out, the blossom
 * a little smaller, and the tulip lower. Values are offsets in the unflipped box, so a larger negative right moves outward. */
@media (min-width: 721px) {
  .pp-about--mirror .pp-botany--blossom { right: -4%; width: calc(var(--s) * 0.7); }
  .pp-about--mirror .pp-botany--small { right: -4%; }
  .pp-about--mirror .pp-botany--tulip { right: -4%; bottom: -16%; width: calc(var(--s) * 0.85); }
  /* The lily stays on screen and as close to the card as it can: the card is 746px wide (42rem plus padding), so its width
   * is capped to the space beside it, and its inner edge sits 16px from the card. It never crosses the viewport edge. */
  .pp-botany--lily {
    --lw: clamp(120px, calc(50% - 304px), var(--s));
    width: var(--lw);
    left: 16px;
  }
  /* The small flower under the lily takes the same gutter, up to 40% larger than before, so the left side fills out. */
  .pp-botany--small-left {
    --sw: clamp(120px, calc(50% - 404px), calc(var(--s) * 1.4));
    width: var(--sw);
    left: max(16px, calc(50% - 388px - var(--sw)));
  }
}

/* Phones: the card covers most of the width, so the botany sits in the bands above and below it, and the botanical
 * sections get taller bands to hold it. */
@media (max-width: 720px) {
  .pp-about--botany { padding-top: 8rem; padding-bottom: 8rem; }
  .pp-botany--lily { left: -22%; top: -2%; }
  .pp-botany--blossom { right: -18%; top: -2%; }
  .pp-botany--tulip { right: 6%; bottom: -3%; }
  .pp-botany--small { right: 4%; top: 40%; }
}
