/* Depends on: base.css, viewport.css. */

/* ============================================================
   SECTION 3 — bento grid, in two scroll-steps: step 0 shows
   lena-1.avif full-viewport with a caption over it, step 1 crossfades
   into the grid (which has been visible in the markup, laid out at
   its final size, the entire time — see .s3-bento-wrap below).
   ============================================================ */
#slide-s3 {
  background: #fc658e;
  color: var(--paper);

  /* Reserves room for the 2-line caption below the header, so the hero
     photo's own top offset (see .s3-hero) can be computed from it
     instead of guessed as a raw percentage. Matches .s3-caption's own
     font-size clamp() exactly, ×2.6 (2 lines at line-height 1.3), plus
     a flat 0.5rem margin for descenders — so the reservation scales
     with the SAME breakpoints the caption's own text does, rather than
     drifting out of sync with it the way a plain vh value would on a
     short-but-wide (e.g. landscape phone) viewport. */
  --s3-caption-h: clamp(3.36rem, calc(6.76vw + 0.5rem), 5.7rem);
  /* -50% again, from 1vh (itself -50% from the original 2vh). Used
     consistently everywhere a gap around the caption is needed
     (header-to-caption, caption-to-hero, and the bento grid's own
     centering reservation below), so changing it here is the one edit
     that shrinks all of them together rather than needing to touch
     several matching values. */
  --s3-caption-gap: 0.5vh;

  /* Flower wallpaper knobs — see .s3-flowers further down for how
     these are used. +25% over the original clamp(70px, 7vw, 120px);
     size and spacing aren't decoupled here, so this also grows the
     flowers themselves by the same 25% — no asset-level way to spread
     them out without that, short of the padded-tile technique Section
     2 uses to split the two apart. */
  --s3-flower-tile: clamp(87.5px, 8.75vw, 150px);
  --s3-flower-ink: rgba(233, 223, 201, 0.16); /* --paper-2 at low opacity, so it reads as texture on the gradient rather than a second layer of content */
}
.s3-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Vertically centers .s3-bento-wrap in whatever's LEFT after this
     padding — so it has to reserve the same header + caption + gap
     space .s3-hero's own top: reserves (see below), or the grid's
     centered position would ignore the caption entirely and land
     underneath/overlapping it once step 1 reveals the grid. This is
     the "lower the bento grid" fix: pushing the padding down pushes
     where centering starts from, which pushes the grid itself down
     with it. */
  padding-top: calc(
    var(--header-h) + var(--s3-caption-gap) + var(--s3-caption-h) +
      var(--s3-caption-gap)
  );
  /* The reservation is given back at step 1 — see the rule just below. */
  transition: padding-top 0.9s var(--ease);
}
/* At step 1 the caption is gone (the grid carries its sentence now), so
   the room set aside for it above is room the grid can have. Without
   this the grid stayed pushed down past a caption that was no longer
   there, and on a short window its bottom row ran off the screen. It
   eases over the same 0.9s the grid takes to fade and scale in, so the
   move is part of that one reveal rather than a jump of its own.

   Specificity (an id, an attribute and a class) puts this above the
   narrow-screen `.s3-stage` padding further down the file as well, so
   the reservation is returned on a phone too — where the stage scrolls,
   and every pixel of it is a pixel less to scroll through. */
#slide-s3[data-step="1"] .s3-stage {
  padding-top: var(--header-h);
}

/* ---- step 0: the full-viewport hero photo + caption ------------ */
/* .s3-flowers/.s3-hero/.s3-caption are siblings of .s3-stage (see the
   comment on them in index.html), positioned against .slide-inner's
   plain box instead — .s3-stage's own padding-top:var(--header-h)
   would otherwise double-count the header's height the moment
   anything nested inside it also added var(--header-h) to its own
   offset, which is exactly the bug this sidesteps. Every top: value
   below is a literal, unambiguous distance from the slide's true top
   edge — nothing here relies on padding-edge semantics. */

/* A second <img> at the same URL .area-a's own photo already uses
   below — same request, so the browser serves it from its HTTP cache
   rather than fetching twice. Kept as a plain img (not literally
   re-parenting .area-a's own element) because .s3-bento's responsive
   breakpoints (it collapses to a single stacked column under 900px)
   make a true shared-element morph far more fragile than the crossfade
   this does instead: the photo shrinks/fades away here while the real
   grid — see .s3-bento-wrap — grows/fades in underneath it, reading as
   one continuous "minimizing into place" even though nothing is
   actually moving between two positions. */
.s3-hero {
  position: absolute;
  /* Below the caption, which is itself below the header — see
     .s3-caption's own top: for the first two terms of this sum. */
  top: calc(
    var(--header-h) + var(--s3-caption-gap) + var(--s3-caption-h) +
      var(--s3-caption-gap)
  );
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.9s var(--ease);
}
.s3-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#slide-s3[data-step="1"] .s3-hero {
  opacity: 0;
}

/* Belongs to step 0 only. It sits at a fixed spot below the header
   over the hero photo — and then goes when the grid arrives, because
   the grid carries the very same sentence in its own box (see
   .s3-support-line further down). Showing it in both places at once
   said the same thing twice and left the grid squeezed under a caption
   it was repeating. The space the caption occupies is still reserved
   either way while the photo is still on screen: --s3-caption-h is what
   positions that photo. Once the photo has gone too, the stage hands
   the space back to the grid — see the step-1 rule on .s3-stage. */
.s3-caption {
  position: absolute;
  z-index: 4;
  left: 50%;
  /* The header's own height, so the caption starts exactly where the
     header ends, plus a clear gap so it doesn't sit flush against it. */
  top: calc(var(--header-h) + var(--s3-caption-gap));
  transform: translateX(-50%);
  width: 90vw;
  text-align: center;
  font-family: var(--display);
  font-weight: 800;
  color: var(--burgundy);
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  line-height: 1.3;
  letter-spacing: 0.01em;
  /* Matched to the hero photo's own fade just above, so the caption and
     the picture it belongs to leave together. */
  opacity: 1;
  transition: opacity 0.9s var(--ease);
}
.s3-caption-line {
  display: block;
}
#slide-s3[data-step="1"] .s3-caption {
  opacity: 0;
}

/* ---- flower wallpaper --------------------------------------------
   5 flat, single-color, fully-filled naive flower motifs (petals as
   overlapping circles/ellipses fused into one solid silhouette — no
   outline, no gradient, no "drippy" tails), tiled as 5 independent
   mask layers so the repeat doesn't read as one motif stamped
   mechanically. Same stencil technique as the header logo and Section
   2's wallpaper: each file is flat #0bbbef, used as a mask over one
   solid fill rather than recoloured directly.

   No separate padded "_tile" asset here, unlike Section 2's — each
   flower's own viewBox already carries its margin baked in (currently
   about 2/3 of the tile is empty space per motif, so it draws at
   roughly a third of --s3-flower-tile), one self-contained file per
   motif. That margin is what makes the motif's SIZE independent of
   --s3-flower-tile's SPACING: shrinking or growing a flower means
   regenerating that one file with a different viewBox-to-motif ratio
   (see the generation notes if it needs redoing), not touching this
   custom property, which only ever changes the spacing between
   flowers, not the flowers themselves. */
.s3-flowers {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: var(--s3-flower-ink);
  -webkit-mask-image: url("../assets/images/s3/flower_1.svg"),
    url("../assets/images/s3/flower_2.svg"), url("../assets/images/s3/flower_3.svg"),
    url("../assets/images/s3/flower_4.svg"), url("../assets/images/s3/flower_5.svg");
  mask-image: url("../assets/images/s3/flower_1.svg"),
    url("../assets/images/s3/flower_2.svg"), url("../assets/images/s3/flower_3.svg"),
    url("../assets/images/s3/flower_4.svg"), url("../assets/images/s3/flower_5.svg");
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  -webkit-mask-size: var(--s3-flower-tile) var(--s3-flower-tile);
  mask-size: var(--s3-flower-tile) var(--s3-flower-tile);
  /* Five different offsets (as fractions of the tile) so the 5 motifs
     interleave into one varied pattern instead of stacking on top of
     each other or lining up into an obvious repeating row. */
  -webkit-mask-position:
    0 0,
    calc(var(--s3-flower-tile) * 0.5) calc(var(--s3-flower-tile) * 0.2),
    calc(var(--s3-flower-tile) * 0.2) calc(var(--s3-flower-tile) * 0.6),
    calc(var(--s3-flower-tile) * 0.7) calc(var(--s3-flower-tile) * 0.7),
    calc(var(--s3-flower-tile) * 0.85) calc(var(--s3-flower-tile) * 0.35);
  mask-position:
    0 0,
    calc(var(--s3-flower-tile) * 0.5) calc(var(--s3-flower-tile) * 0.2),
    calc(var(--s3-flower-tile) * 0.2) calc(var(--s3-flower-tile) * 0.6),
    calc(var(--s3-flower-tile) * 0.7) calc(var(--s3-flower-tile) * 0.7),
    calc(var(--s3-flower-tile) * 0.85) calc(var(--s3-flower-tile) * 0.35);
}

/* ---- step 1: the grid itself ------------------------------------ */
/* The reveal (opacity/scale) lives on this wrapper, not on .s3-bento
   itself, on purpose: .s3-bento already owns a `transform` for the
   unrelated on-scroll "wiggle" nudge below (.wiggling), and stacking a
   second transform-based animation on the very same property would
   have the two fight over it. Wrapping keeps them on separate elements
   so neither ever overwrites the other. */
.s3-bento-wrap {
  opacity: 0;
  transform: scale(0.82);
  transition:
    opacity 0.9s var(--ease),
    transform 0.9s var(--ease);
}
#slide-s3[data-step="1"] .s3-bento-wrap {
  opacity: 1;
  transform: scale(1);
}

.s3-bento {
  width: 88vw;
  /* top row (a/b) is 20% shorter than the bottom row; gap is unchanged,
     so the grid's own total height shrinks accordingly — it just stays
     centered in .s3-stage like before, nothing else to do for that. */
  height: calc(82vh * 13 / 15);
  max-width: 1400px;
  max-height: calc(840px * 13 / 15);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 0.8fr 0.8fr 1fr;
  grid-template-areas:
    "a a a b b b"
    "a a a b b b"
    "text text cta cta qr qr";
  gap: 1.1vw;
  transition: transform 0.5s ease;
}
.s3-bento.wiggling {
  animation: s3wiggle 0.8s ease;
}
@keyframes s3wiggle {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-0.8%);
  }
  70% {
    transform: translateX(0.8%);
  }
}

.bento-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
}
.bento-cell.img {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(
    --ink
  ); /* fallback fill while --cell-bg loads, or if it fails */
}
/* The real photo is shown at its natural aspect ratio, always at the
   cell's full width (never stretched to force-fill the box) — so when
   its height doesn't reach the top and bottom of the box, that band
   would otherwise just show empty background. This pseudo-element
   fills it with a clipped, blurred copy of the SAME photo.

   A pseudo-element can't reference a sibling <img>'s src directly, so
   it reads a --cell-bg custom property, which js/section-3.js fills in
   from that very <img> — see the note there, which also covers why
   this is NOT written as an inline style in the markup (a relative
   url() in a custom property resolves against the stylesheet using it,
   not against the page, so it pointed at css/assets/... and silently
   resolved to nothing). */
.bento-cell.img::before {
  content: "";
  position: absolute;
  inset: -6%; /* oversized so the blur's own soft edge doesn't show at the box's hard edge */
  z-index: 0;
  background-image: var(--cell-bg);
  background-size: cover;
  background-position: center;
  filter: blur(24px) brightness(0.7);
}
.bento-cell.img img {
  position: relative;
  z-index: 1;
  /* Always the cell's full width. Height then follows from the photo's
     own ratio, which means one of two things happens: the photo is
     shorter than the box and leaves a band above and below it — which
     is what the blurred fill behind it is for — or it is taller, and
     the box crops it top and bottom (the cell centres it, so the crop
     is even). Filling the width is the normal, intended look; the fill
     is the safety net for when the photo cannot manage it.

     Deliberately NOT object-fit:contain, which would fit the whole
     photo inside the box and leave the fill showing down both sides on
     these wide, short cells — that turns the exception into the rule. */
  width: 100%;
  height: auto;
  display: block;
}

.area-a {
  grid-area: a;
}
.area-b {
  grid-area: b;
}
/* Two zones side by side: instructional text on the left, a white
   "quiet zone" square holding the actual QR code on the right — a QR
   code needs real contrast margin around it to stay scannable, so
   .qr-code-square below KEEPS its white fill rather than sitting
   directly on this cell's own background, even though that background
   itself is now pink rather than paper-2. */
.area-qr {
  grid-area: qr;
  background: #fc658e;
  display: flex;
}
.qr-text-zone {
  flex: 1 1 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.4vw;
  text-align: center;
}
.qr-text-zone p {
  font-family: var(--display); font-weight:800;
  color: var(--burgundy);
  font-size: clamp(1.1rem, 2.4vw, 1.8rem);
  line-height: 1.15;
  letter-spacing: 0.01em;
}
.qr-code-zone {
  flex: 1 1 50%;
  background: #fc658e;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2vw;
}
.qr-code-square {
  width: min(80%, 100%);
  aspect-ratio: 1/1;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8em;
}
.qr-code-square img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* The support line, in its own bento box. Static: it used to be a
   marquee running a second, different sentence past this box, which
   meant the text could only ever be read a few words at a time and the
   box was in constant motion next to five still ones. It now holds the
   SAME sentence the caption shows over the hero photo at step 0 — the
   grid replaces that caption rather than appearing beneath it (see the
   step-1 rule on .s3-caption above), so the line is on screen exactly
   once either way. */
.area-text {
  grid-area: text;
  background: var(--burgundy);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0.9em;
}
.s3-support-line {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  /* Small, and sized off the viewport rather than the box: this cell is
     only two of the grid's six columns wide, and the whole sentence has
     to fit inside it without scrolling or being clipped. */
  font-size: clamp(0.85rem, 1.5vw, 1.45rem);
  line-height: 1.2;
  letter-spacing: 0.01em;
  /* Pink on the burgundy cell: the same pairing the CTA pill uses. */
  color: #fc658e;
  text-align: center;
  text-wrap: balance;
}

/* the CTA is a bento box too — a photo tile with the button sitting on top of it */
.area-cta {
  grid-area: cta;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* the box-scale hover lives only on the CTA tile, not the other bento
     boxes */
  will-change: transform;
  transition:
    transform 0.4s var(--ease),
    box-shadow 0.4s ease,
    z-index 0s;
}
.area-cta:hover {
  transform: scale(1.035);
  z-index: 5;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.4);
}
.area-cta img {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.area-cta::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(20, 15, 12, 0.4);
  z-index: 1;
}
.area-cta .cta-label {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  font-family: var(--display); font-weight:800;
  font-size: clamp(1rem, 1.6vw, 1.3rem);
  letter-spacing: 0.02em;
  /* Pink text on the burgundy pill: 3.76:1 resting, 5.48:1 on the
     --burgundy-dark hover background below — both clear WCAG AA's 3:1
     large/bold-text floor, so unlike the caption this one's fine. */
  color: #fc658e;
  background: var(--burgundy);
  border: none;
  border-radius: 999px;
  padding: 0.8em;
  transition:
    background 0.25s ease,
    transform 0.25s var(--ease);
}
.area-cta:hover .cta-label {
  background: var(--burgundy-dark);
  transform: scale(1.05);
}
/* The clip wrapper has to carry NO padding of its own (same reasoning
   as .s1-panel-link-inner in section-1.css) — if overflow:hidden sat on
   the padded .cta-label instead, the clip line would sit at the outer
   edge of the padding rather than flush with the text, leaving a
   padding-sized sliver where the outgoing/incoming copy stayed visible
   (this is why the effect looked broken here but fine in section 1). */
.cta-label-inner {
  position: relative;
  display: inline-flex;
  overflow: hidden;
}
/* Two identical copies of the label. The 2nd copy stays in normal flow
   and is what actually gives .cta-label-track its size (well-defined,
   no auto-sizing ambiguity). The 1st copy is absolutely positioned with
   inset:0, which pins its box to EXACTLY the same size as the 2nd copy
   — so a translateX(±100%) on either one always lands flush against
   the other, edge to edge, with no gap and no overlap. At rest the 1st
   copy sits one label-width to the left (hidden by .cta-label-inner's
   overflow:hidden) while the 2nd sits visible in place; on hover they
   swap — the 2nd exits right, the 1st enters from the left. */
.cta-label-track {
  position: relative;
  display: inline-flex;
}
.cta-label-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  white-space: nowrap;
  transition: transform 0.4s var(--ease);
}
.cta-label-text:nth-child(1) {
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
}
.cta-label-text:nth-child(2) {
  transform: translateX(0%);
}
.area-cta:hover .cta-label-text:nth-child(1) {
  transform: translateX(0%);
}
.area-cta:hover .cta-label-text:nth-child(2) {
  transform: translateX(100%);
}
.cta-label-arrow {
  width: 0.9em;
  height: 0.9em;
  flex: none;
  stroke: currentColor;
}

/* narrow / mobile: drop the spanning bento layout for a single column of stacked rectangles */
@media (max-width: 900px) {
  /* touch-action:pan-y overrides body's touch-action:none (base.css,
     needed so our own JS drives section-to-section swipe navigation)
     specifically for this scrollable area, so a vertical drag here
     scrolls the stacked bento boxes natively instead of being blocked —
     see the matching findScrollableAncestor() check in the touchend
     handler (scroll-engine.js), which lets that native scroll happen
     before treating a swipe as a section-change gesture. */
  .s3-stage {
    /* Same reservation as the desktop rule above — this stage is
       top-anchored (align-items:flex-start) rather than centered on
       narrow screens, so without it the grid would start right under
       the header and directly under the caption sitting there too. */
    padding: calc(
        var(--header-h) + var(--s3-caption-gap) + var(--s3-caption-h) +
          var(--s3-caption-gap)
      )
      4vw 3vh;
    align-items: flex-start;
    overflow-y: auto;
    touch-action: pan-y;
  }
  .s3-bento {
    width: 100%;
    height: auto;
    max-height: none;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-template-areas: none;
    /* max-content rather than 1fr: with an auto-height grid, 1fr rows
       *should* still size to each row's own content, but that "should"
       turned out to be exactly where the stray gaps under the shorter
       16:9 boxes were coming from — max-content leaves no ambiguity,
       each row is sized to exactly its one item's own height. */
    grid-auto-rows: max-content;
    gap: 3vw;
  }
  /* 16/9 rather than a square — roughly half as tall as before for a
     given width (9/16 ≈ 0.56, close to the "just halve the height"
     ask), so all 6 boxes actually fit on a normal phone screen (tested
     against an iPhone 13's 390×844 viewport) without an excessive
     scroll. Applies to every box, QR code included, for a uniform stack. */
  .bento-cell {
    grid-area: auto !important;
    aspect-ratio: 16/9;
  }
  .area-cta:hover {
    transform: none;
    box-shadow: none;
  }
  /* The support-line box doesn't follow the shared 16:9 — it's sized to
     its own (bigger, on mobile) text instead of an arbitrary ratio, with
     just enough padding to read as "slightly bigger than the text". */
  .area-text {
    aspect-ratio: auto;
    padding: 1rem 4%;
  }
  /* A full-width box here rather than two of six columns, so the line
     can be read at a comfortable size instead of the small one the
     narrow desktop cell forces. */
  .s3-support-line {
    font-size: clamp(1.1rem, 4.4vw, 1.8rem);
  }

  /* ---- the QR box comes out on mobile ----
     Scanning a QR code off the very screen you are holding is not
     something anyone can do, so on a phone the box is dead weight in a
     stack that already has to be scrolled. The CTA box directly above
     it links to the same collection, which is the thing to tap here. */
  .area-qr {
    display: none;
  }

  /* ---- no invisible scrolling during the hero step ----
     This stage is a native scroller on mobile, and it is scrollable
     from the moment the page lays out — including through step 0, when
     it is completely hidden behind the hero photo. So the very swipe
     that was meant to bring the grid IN was also, invisibly, flicking
     that hidden stack of boxes down — and the grid then faded in
     already scrolled to its last box. Closing the scroller until the
     grid is actually the thing on screen means that swipe has nothing
     to scroll and is read as what it was: a step change. */
  #slide-s3[data-step="0"] .s3-stage {
    overflow-y: hidden;
    touch-action: none;
  }

  /* ---- room for a caption that runs to three lines ----
     --s3-caption-h reserves the space the caption is drawn in, and both
     the hero photo's top edge and this stage's padding are measured off
     it. The reservation is two lines' worth, which is what the caption
     sets to on a desktop — on a phone the second sentence wraps and it
     needs three, so the last line was being drawn over the top of the
     photo. One more line of the caption's own type, added to the
     reservation, moves everything below it down by exactly that much. */
  #slide-s3 {
    --s3-caption-h: calc(
      clamp(3.36rem, calc(6.76vw + 0.5rem), 5.7rem) + 1.3 *
        clamp(1.1rem, 2.6vw, 2rem)
    );
  }
}
