/* =========================================================================
   EXHALE: the scroll-paced layer for the case studies.
   Nothing here runs on a timer. The page is inked in at the reader's own
   tempo: a rule draws under a section heading, a specimen plate completes
   itself as it arrives. Additive only. Without JS, and under
   prefers-reduced-motion, --p is 1 and every figure is already finished.
   ========================================================================= */

[data-exhale] {
  /* Written by exhale.js: 0 before the element enters, 1 once it is read. */
  --p: 1;
  /* Stagger across the drawing, as a fraction of --p. */
  --ink-step: 0.055;
  --ink-span: 0.42;
}

/* ---------- 1. the rule inks itself under a section heading -------------- */

.case-block[data-exhale] .case-h2 {
  position: relative;
}

.case-block[data-exhale] .case-h2::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -1px;
  height: 1px;
  background: var(--ink);
  opacity: 0.5;
  transform: scaleX(clamp(0, var(--p), 1));
  transform-origin: left center;
  pointer-events: none;
}

/* the section number comes up to full ink with its rule */
.case-block[data-exhale] .case-h2 .n {
  opacity: clamp(0.35, calc(0.35 + 0.65 * var(--p)), 1);
}

/* ---------- 2. the wordmark is written left to right --------------------
   A soft leading edge, not a guillotine: a hard clip cut the d in half and
   read as a broken image rather than a drawing. Scoped to .js so a page with
   scripting off never carries a mask at all, and dropped once the ink is
   finished (exhale.js adds .is-inked) because a persistent mask costs the
   wordmark its subpixel antialiasing for no gain.
   ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
  .js .plate[data-exhale] .plate-brand__type .big {
    --ink-edge: calc(clamp(0, var(--p), 1) * 200%);
    -webkit-mask-image: linear-gradient(to right, #000 calc(var(--ink-edge) - 60%), transparent var(--ink-edge));
    mask-image: linear-gradient(to right, #000 calc(var(--ink-edge) - 60%), transparent var(--ink-edge));
  }

  .js .plate[data-exhale].is-inked .plate-brand__type .big {
    -webkit-mask-image: none;
    mask-image: none;
  }
}

/* ---------- 3. the palette chips settle in, one after another ----------- */

.plate[data-exhale] .plate-brand__swatches span {
  --q: clamp(0, calc((var(--p) - var(--i, 0) * var(--ink-step)) / var(--ink-span)), 1);
  opacity: clamp(0, calc(var(--q) * 2.2), 1);
  transform: translateY(calc(5px * (1 - var(--q))));
}

.plate-brand__swatches span:nth-child(1) { --i: 0; }
.plate-brand__swatches span:nth-child(2) { --i: 1; }
.plate-brand__swatches span:nth-child(3) { --i: 2; }
.plate-brand__swatches span:nth-child(4) { --i: 3; }
.plate-brand__swatches span:nth-child(5) { --i: 4; }
.plate-brand__swatches span:nth-child(6) { --i: 5; }
.plate-brand__swatches span:nth-child(7) { --i: 6; }
.plate-brand__swatches span:nth-child(8) { --i: 7; }

/* ---------- 4. the tonal ramp fills from the dark end ------------------- */

.plate[data-exhale] .plate-system__ramp span {
  --q: clamp(0, calc((var(--p) - var(--i, 0) * var(--ink-step)) / var(--ink-span)), 1);
  opacity: clamp(0, calc(var(--q) * 2.4), 1);
  transform: scaleY(calc(0.68 + 0.32 * var(--q)));
  transform-origin: bottom center;
}

.plate-system__ramp span:nth-child(1) { --i: 0; }
.plate-system__ramp span:nth-child(2) { --i: 1; }
.plate-system__ramp span:nth-child(3) { --i: 2; }
.plate-system__ramp span:nth-child(4) { --i: 3; }
.plate-system__ramp span:nth-child(5) { --i: 4; }
.plate-system__ramp span:nth-child(6) { --i: 5; }
.plate-system__ramp span:nth-child(7) { --i: 6; }
.plate-system__ramp span:nth-child(8) { --i: 7; }
.plate-system__ramp span:nth-child(9) { --i: 8; }
.plate-system__ramp span:nth-child(10) { --i: 9; }

/* ---------- 5. the type ramp arrives last, line by line ----------------- */

.plate[data-exhale] .plate-system__type > div {
  --q: clamp(0, calc((var(--p) - var(--i, 0) * var(--ink-step)) / var(--ink-span)), 1);
  opacity: clamp(0, calc(var(--q) * 1.8), 1);
  transform: translateY(calc(4px * (1 - var(--q))));
}

.plate-system__type > div:nth-child(1) { --i: 6; }
.plate-system__type > div:nth-child(2) { --i: 7; }
.plate-system__type > div:nth-child(3) { --i: 8; }
.plate-system__type > div:nth-child(4) { --i: 9; }

/* ---------- 6. the campaign frames arrive one after another ------------- */

.plate[data-exhale] .plate-campaign > div {
  --q: clamp(0, calc((var(--p) - var(--i, 0) * var(--ink-step) * 1.6) / var(--ink-span)), 1);
  opacity: clamp(0, calc(var(--q) * 2), 1);
  transform: translateY(calc(8px * (1 - var(--q))));
}

.plate-campaign > div:nth-child(1) { --i: 0; }
.plate-campaign > div:nth-child(2) { --i: 1; }
.plate-campaign > div:nth-child(3) { --i: 2; }
.plate-campaign > div:nth-child(4) { --i: 3; }

/* ---------- the quiet after ---------------------------------------------
   No looping, no autoplay: the drawing happens once, while the reader is
   passing, and then it is simply a finished plate. Under reduced motion the
   page is complete on arrival: there is nothing to wait for.
   ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  [data-exhale] {
    --p: 1 !important;
  }
}
