/* ═══ Case study screen spread — REUSABLE component ═════════════════
   A fan of phone screens: the centre screen largest and in front, each step out a little
   smaller and tucked behind its neighbour. Optionally sits on a background image, either
   as a rounded tile or as a band that runs the full width of the window.
   Used on: wone.html (full-width band, after the case study feature, copy underneath).

   Behaviour
     · 3 or 5 screens (an odd number, so one sits in the centre). With 5, the outer pair
       drops out when the spread is narrower than ~700px.
     · Frameless screens with rounded corners: export without a status bar
       (explorations/wone-final/_tools/strip_status.py removes one).
     · The first time the spread is seen, the centre screen rises in (cube-motion's rise),
       then the side screens slide out from behind it a pair at a time, nearer pair first.
       No motion under prefers-reduced-motion.
     · Shadows grade with depth: the centre casts the deepest, each step out casts less.

   To add to a case study
     1. In <head>:       <link rel="stylesheet" href="components/cs-spread.css" />
     2. Before </body>:  <script src="components/cs-spread.js" defer></script>
     3. Paste the markup, screens left to right. data-depth is the step out from the centre
        (0 centre, 1 next to it, 2 outer).

   Full-width band on a background image (as on WONE):
     <figure class="cs-spread cs-spread--panel cs-spread--bleed" data-cs-spread aria-label="…">
       <img class="cs-spread-bg" src="…" alt="" loading="lazy" decoding="async" />
       <img class="cs-spread-shot" data-depth="2" src="…" alt="…" loading="lazy" decoding="async" />
       <img class="cs-spread-shot" data-depth="1" src="…" alt="…" loading="lazy" decoding="async" />
       <img class="cs-spread-shot" data-depth="0" src="…" alt="…" loading="lazy" decoding="async" />
       <img class="cs-spread-shot" data-depth="1" src="…" alt="…" loading="lazy" decoding="async" />
       <img class="cs-spread-shot" data-depth="2" src="…" alt="…" loading="lazy" decoding="async" />
     </figure>

   Optional heading and statement under the spread (as on WONE): a block straight after the
   figure, centred on the page background. Both lines are serif: a statement, not body copy.
       <div class="cs-spread-copy">
         <h3 class="cs-spread-title">…</h3>
         <p class="cs-spread-text">…</p>            ← one or more paragraphs
       </div>

   Or over the panel, above the screens: a figcaption straight after the background image
   (before the screens), centred over the top of the panel:
       <figcaption class="cs-spread-head">
         <div class="cs-spread-card">                ← optional frosted glass card
           <h3 class="cs-spread-title">…</h3>
           <p class="cs-spread-text">…</p>
         </div>
       </figcaption>
     Text is ink on the panel. Without the card, the top of the background image must stay
     light behind the copy at every width; the card's white frost removes that worry.
     --spread-text sets the paragraph colour (default the page's mid ink, a step darker on a
     panel). Check it holds 4.5:1 against the darkest part of the image behind it.

   Variants (classes on the figure)
     cs-spread                     screens only, on the page background
     + cs-spread--panel            on a rounded tile filled with the .cs-spread-bg image
     + cs-spread--bleed            the tile becomes a square band, edge to edge of the window.
                                   Place it in a full-width column (not beside a side nav); a
                                   .cs-section holding one stops clipping at the page gutter.

   Per-project settings (custom properties on the figure, e.g. style="--spread-ratio: 9 / 19.5")
     --spread-ratio      width / height of the screen exports (default WONE's 414 / 811)
     --spread-w          centre screen width on wide layouts (default min(290px, 21cqi))
     --spread-panel-bg   panel colour shown until the background image loads
     --spread-bg-pos     object-position of the background image (default centre)
   ═══════════════════════════════════════════════════════════════════ */

/* The spread is its own size container: cqi below is a share of its width. */
.cs-spread {
  --spread-ratio: 414 / 811;
  --spread-w: min(290px, 21cqi);
  /* Overlap between neighbours, as a share of each screen's width. Keep it well past the
     screens' own ~5% side margin, so a button runs clearly behind the next screen instead
     of stopping a hair short of it. */
  --spread-gap: 0.08;
  container-type: inline-size;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 0 clamp(88px, 11vw, 176px);
  padding: 0;
}

/* Straight after a case study feature (components/cs-feature.css), whose own bottom padding
   already leaves room under its corner images: tuck up so the gap matches the rest of the page. */
.cs-feature + .cs-spread { margin-top: calc(-1 * clamp(24px, 4.5vw, 64px)); }

.cs-spread-shot {
  --s: 1;
  position: relative;
  flex: none;
  display: block;
  width: calc(var(--spread-w) * var(--s));
  height: auto;
  aspect-ratio: var(--spread-ratio);
  object-fit: cover;
  object-position: center top;
  margin-inline: calc(var(--spread-w) * var(--s) * var(--spread-gap) * -1);
  /* Round corners: 10% of the width, matched on the vertical axis so they stay circular. No outline. */
  border-radius: 10% / calc(10% * (var(--spread-ratio)));
  background: var(--bg-surface, #E4E2DE);
  box-shadow: 0 40px 70px -42px rgba(14, 13, 11, 0.5);
}
/* An image screen needs no fill: behind a rounded image it only shows as a hairline at the corners. */
img.cs-spread-shot { background: transparent; }
/* A video screen: a div carries the shot (size, corners, shadow, reveal) and clips the video,
   so the video can be zoomed without fighting the shot's own transforms. Add
   cs-spread-shot--trim when the phone video still shows an iOS status bar: it zooms 6% from the
   bottom edge so the bar sits above the screen's top (the home indicator stays put).
   <div class="cs-spread-shot cs-spread-shot--video cs-spread-shot--trim" data-depth="0" role="img" aria-label="…">
     <video src="….mp4" poster="….jpg" autoplay muted loop playsinline aria-hidden="true"></video>
   </div> */
.cs-spread-shot--video { overflow: hidden; background: transparent; }  /* no light edge where the scaled video meets the rounded clip (QA S1, 22 Nov) */
.cs-spread-shot--video video { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.cs-spread-shot--trim video { transform: scale(1.06); transform-origin: 50% 100%; }
.cs-spread-shot[data-depth="0"] { --s: 1;    z-index: 3; }
.cs-spread-shot[data-depth="1"] { --s: 0.82; z-index: 2; }
.cs-spread-shot[data-depth="2"] { --s: 0.75; z-index: 1; }

/* Background panel: the screens sit on a rounded image panel, like the other media cards. */
.cs-spread--panel {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 20px;
  padding-block: clamp(64px, 8.5vw, 132px);
  background: var(--spread-panel-bg, var(--bg-raised, #E4E2DE));
}
.cs-spread-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--spread-bg-pos, 50% 50%);
  pointer-events: none;
}
/* Heading and intro above the screens: the figure wraps so the caption takes a full row of
   its own, with the screens on the row below. */
.cs-spread:has(> .cs-spread-head) { flex-wrap: wrap; }
.cs-spread-head {
  position: relative;
  z-index: 4;
  flex: 0 0 100%;
  margin: 0 0 clamp(40px, 5vw, 72px);
  padding-inline: clamp(20px, 6vw, 48px);
  text-align: center;
  color: var(--ink);
}
/* Heading and statement under the spread, on the page background. The band's own bottom
   margin closes up so the copy reads as its caption; the copy then takes that margin over. */
.cs-spread:has(+ .cs-spread-copy) { margin-bottom: clamp(48px, 5.5vw, 88px); }
.cs-spread-copy {
  max-width: 920px;
  margin: 0 auto clamp(88px, 11vw, 176px);
  text-align: center;
  color: var(--ink);
}
/* Centred lines balance, so a paragraph doesn't end on a stray word or two. */
.cs-spread-copy .cs-spread-text { text-wrap: balance; }
/* Phones: a long centred paragraph is hard to follow, so the copy sits left like the body text. */
@media (max-width: 767px) {
  .cs-spread-copy { text-align: left; }
  .cs-spread-copy .cs-spread-title { margin-inline: 0; }
  .cs-spread-copy .cs-spread-text { text-wrap: pretty; }
}

.cs-spread-title {
  margin: 0 auto;
  max-width: 22ch;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 3.2vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
/* Serif, a size up from body text: the intro reads as a statement rather than a paragraph. */
.cs-spread-text {
  margin: clamp(16px, 1.6vw, 24px) auto 0;
  max-width: 40em;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(19px, 1.55vw, 23px);
  line-height: 1.45;
  letter-spacing: -0.005em;
  color: var(--spread-text, var(--ink-mid));
  text-wrap: pretty;
}
.cs-spread-text + .cs-spread-text { margin-top: 0.7em; }
/* Over a photo, a step darker than mid ink, so body text keeps 4.5:1 on its lighter areas. */
.cs-spread--panel .cs-spread-text { color: var(--spread-text, color-mix(in srgb, var(--ink) 50%, var(--ink-mid))); }

/* Optional frosted glass card around the heading and intro (.cs-spread-card inside the
   figcaption). The white tint and blur keep the copy readable wherever the photo darkens. */
.cs-spread-card {
  max-width: 780px;
  margin-inline: auto;
  padding: clamp(28px, 4cqi, 52px) clamp(22px, 4.5cqi, 60px);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
          backdrop-filter: blur(18px) saturate(140%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cs-spread-card { background: rgba(255, 255, 255, 0.78); }
}
/* Narrow: the panel is tall, so the card runs down over the photo's darker ground; a whiter
   frost keeps the copy above 4.5:1 there. */
@container (max-width: 700px) {
  .cs-spread-card { border-radius: 22px; background: rgba(255, 255, 255, 0.62); }
}

/* On a photo the shadows grade with depth. The centre screen sits furthest off the photo, so it
   casts the deepest, widest shadow; each step out sits closer to it and casts a tighter, lighter
   one. Each also has a soft edge shadow, so a screen reads as sitting over the one behind it. */
.cs-spread--panel .cs-spread-shot[data-depth="0"] { box-shadow: 0 0 32px -6px rgba(10, 14, 8, 0.4), 0 64px 120px -36px rgba(10, 14, 8, 0.72); }
.cs-spread--panel .cs-spread-shot[data-depth="1"] { box-shadow: 0 0 24px -6px rgba(10, 14, 8, 0.3), 0 38px 72px -34px rgba(10, 14, 8, 0.5); }
.cs-spread--panel .cs-spread-shot[data-depth="2"] { box-shadow: 0 0 16px -6px rgba(10, 14, 8, 0.22), 0 20px 40px -26px rgba(10, 14, 8, 0.34); }

/* Full width: the panel runs to the window edges, square cornered. 100vw includes an
   always-visible scrollbar, so cs-spread.js publishes its width as --cs-scrollbar and the
   band stops at the scrollbar instead of causing a sideways scroll. The case study section
   card normally clips at the page gutter, so a section holding one lets its content overflow. */
.cs-spread--bleed {
  margin-inline: calc(50% - 50vw + var(--cs-scrollbar, 0px) / 2);
  border-radius: 0;
}
.cs-section:has(.cs-spread--bleed) { overflow: visible; content-visibility: visible; contain: none; }

/* Narrow: three screens, centre larger, neighbours tucked further behind it. */
@container (max-width: 700px) {
  .cs-spread-shot { --spread-w: 48cqi; --spread-gap: 0.16; }
  .cs-spread-shot[data-depth="2"] { display: none; }
  /* On a panel, keep the outer screens clear of its edges. */
  .cs-spread--panel .cs-spread-shot { --spread-w: 43cqi; }
}

/* One-shot entrance (cs-spread.js): the screens wait hidden until the spread is first seen, then
   the script takes over with cube-motion and removes .is-armed. (.is-in comes from an older copy
   of the script a browser may still have cached: it shows the screens rather than strand them.) */
@media (prefers-reduced-motion: no-preference) {
  .cs-spread.is-armed:not(.is-in) .cs-spread-shot { opacity: 0; }
}
