/* css/sections/04-crema.css · beat 4: the cup from above. After the side view at the end of 03, the crema is a circle,
   the site's signature: a concept render (assets/img/crema-macro-*) framed on the cup, its dark surround feathered into
   the stage. js/sections/04-crema.js lays a WebGL2 ripple over it only while the page scrolls. */
@layer sections {
  .s-crema {
    /* the lens: where the cup sits in the render, in fractions of the image width (read by js/sections/04-crema.js too).
       cx, cy = centre of the cup; r = half of the view, so the rim and a little dark show inside the circle */
    --lens-cx: 0.498;
    --lens-cy: 0.468;
    --lens-r: 0.46;
    --circle: min(94vw, 34rem);
    background: var(--color-stage);
    padding-block-start: var(--space-lg);
    overflow-x: clip;
  }
  .s-crema .crema__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--space-xl);
    padding-block-end: var(--space-2xl);
  }
  .s-crema .crema__copy { display: grid; row-gap: var(--space-lg); min-width: 0; }
  .s-crema .crema__text { color: var(--color-ink-2); font-size: var(--text-lead); line-height: var(--leading-lead); max-width: var(--measure-lead); }

  /* phone: the circle first, nearly the full width (it may reach into the gutters), the caption centred under it,
     then the copy */
  .s-crema .crema__pool {
    order: -1;
    position: relative;
    justify-self: start;
    inline-size: var(--circle);
    margin-block: 0;
    margin-inline: calc((100% - var(--circle)) / 2);
  }
  .s-crema .crema__circle {
    position: relative;
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: clip;
    background: var(--color-stage);
    /* a feathered edge: the cup's dark surround melts into the stage, no hard disc */
    -webkit-mask-image: radial-gradient(circle closest-side, var(--mask-ink) 80%, color-mix(in srgb, var(--mask-ink) 70%, transparent) 89%, color-mix(in srgb, var(--mask-ink) 25%, transparent) 96%, transparent 100%);
            mask-image: radial-gradient(circle closest-side, var(--mask-ink) 80%, color-mix(in srgb, var(--mask-ink) 70%, transparent) 89%, color-mix(in srgb, var(--mask-ink) 25%, transparent) 96%, transparent 100%);
  }
  /* the render, scaled and shifted so the cup's centre is the circle's centre */
  .s-crema .crema__lens {
    position: absolute;
    inline-size: calc(100% / (2 * var(--lens-r)));
    max-inline-size: none;
    aspect-ratio: 1;
    inset-inline-start: calc(50% - var(--lens-cx) * 100% / (2 * var(--lens-r)));
    inset-block-start: calc(50% - var(--lens-cy) * 100% / (2 * var(--lens-r)));
  }
  .s-crema .crema__img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; }
  .s-crema .crema__canvas {
    position: absolute; inset: 0; inline-size: 100%; block-size: 100%;
    opacity: 0; transition: opacity var(--dur-long) var(--ease-out);
  }
  .s-crema .crema__canvas.is-ready { opacity: 1; }
  .s-crema .crema__circle .grain { position: absolute; inset: 0; pointer-events: none; }
  /* the caption sits under the circle, centred on it, a small gap below (like 03's caption under the cup) */
  .s-crema .crema__caption { margin-block-start: var(--space-sm); margin-inline: auto; text-align: center; }

  @media (min-width: 40em) and (max-width: 63.99em) {
    .s-crema { --circle: min(76vw, 36rem); }
  }

  @media (min-width: 64em) {
    /* desktop: the copy and the circle share one screen, centred on it (with 03 in motion the circle is already there
       when 03 lets go: see the lead rules below) */
    .s-crema { --circle: min(78svh, 46rem); padding-block-start: 0; }
    .s-crema .crema__inner {
      grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
      column-gap: var(--gap-columns);
      align-items: center;
      min-block-size: 100svh;
      padding-block-end: 0;
    }
    .s-crema .crema__copy { grid-column: 1 / span 4; grid-row: 1; }
    .s-crema .crema__pool { order: 0; grid-column: 6 / -1; grid-row: 1; justify-self: center; inline-size: min(var(--circle), 100%); margin-inline: 0; }
    /* static (no JS, reduced motion): the caption hangs under the circle, centred on it, outside the crema */
    .s-crema .crema__caption {
      position: absolute;
      inset-block-start: 100%;
      inset-inline: 0;
      max-width: none;
      margin: var(--space-sm) 0 0;
    }

    /* with 03 in motion, 04 lies over the last screen of the pour's run as a dissolve, not a slide: 04 starts two
       screens before 03 ends (a static margin set with .is-motion far below the fold: no layout shift; page length
       unchanged) and its first screen is a clear field over 03's stuck stage. The pool is a sticky, screen-tall box
       with the circle at its centre, so the circle stands still on the compositor while js/sections/04-crema.js fades
       it up out of the cup's crema and 03 fades the cup away (js/sections/03-first-pour.js, last 100svh of
       --pour-run). Its second screen is the old 04: the copy comes up in flow, and pool and 03's stage release together */
    .s-first-pour.is-motion + .s-crema {
      margin-block-start: -200svh;
      position: relative;
      z-index: 1;
      background: transparent;
      pointer-events: none;                 /* the clear field must not cover 03's link while the words fade */
    }
    .s-first-pour.is-motion + .s-crema .crema__inner {
      grid-template-rows: 100svh 100svh;
      row-gap: 0;
      min-block-size: 200svh;
    }
    .s-first-pour.is-motion + .s-crema .crema__copy { grid-row: 2; pointer-events: auto; }
    .s-first-pour.is-motion + .s-crema .crema__pool {
      grid-row: 1 / span 2;
      align-self: start;
      position: sticky;
      inset-block-start: 0;
      block-size: 100svh;
      display: grid;
      grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    }
    .s-first-pour.is-motion + .s-crema .crema__circle { grid-row: 2; pointer-events: auto; }
    .s-first-pour.is-motion + .s-crema .crema__caption {
      position: static;
      grid-row: 3;
      align-self: start;
    }
  }
}
