/* css/sections/03-first-pour.css · G2 · the first pour: portal from the basket, match-cut, extraction on canvas (D03)
   v2 restyle: no section ground (the studio shows through; js/sections/03-first-pour.js stands the beam on the stream),
   the footage runs the full stage height and feathers into the black on every side, beats in large italic serif,
   brass hairlines. The frame-scrub logic is unchanged. */
@layer sections {

  /* ---------- shared ---------- */
  .s-first-pour {
    --p-brass: var(--color-brass);
    --p-brass-hi: var(--color-brass-hi);
    --p-brass-lo: var(--color-brass-lo);
    --p-serif: "Instrument Serif", var(--font-display);
    background: transparent;
    padding-block-start: var(--gap-a);
  }
  .pour__frame {
    position: relative;
    aspect-ratio: 720 / 1000;
  }
  .pour__media {
    position: absolute;
    inset: 0;
    overflow: clip;
    background: var(--color-stage);
  }
  .pour__poster,
  .pour__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .pour__poster { object-fit: cover; }
  /* warm grade: the concept footage has cold blue glints on the basket; pull them toward the Kiln palette */
  .pour__poster,
  .pour__canvas { filter: sepia(0.42) saturate(0.94) hue-rotate(-6deg) brightness(0.96); }
  .pour__media::after {                     /* the frame melts into the stage: no hard rectangle in the dark */
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 var(--space-2xl) var(--space-md) var(--color-stage);
  }
  .pour__media .grain,
  .pour__media .vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }
  .pour__caption { margin-block-start: var(--space-sm); }

  /* the pour lands in the cup: a concept render cross-faded over f-159 at the end of the scene (JS inserts it from
     <template data-cup>; static mode never shows it). Same box, same cover crop as the canvas; JS shifts it so the
     two streams share one x, and eases its scale and opacity */
  .pour__cup {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    /* the stream comes out of the dark and the table falls away: no hard top or bottom edge on the render */
    -webkit-mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 16%, var(--mask-ink) 84%, transparent);
    mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 16%, var(--mask-ink) 84%, transparent);
  }
  .pour__cup-img {
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    object-position: 50% 50%;
  }

  .pour__beats {
    display: grid;
    gap: var(--space-lg);
    margin: 0;
  }
  .pour__beat {
    position: relative;
    font-family: var(--p-serif);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.375rem, 1rem + 1.6vw, 2.25rem);
    line-height: 1.12;
    letter-spacing: -0.01em;
    color: var(--color-ink);
    max-width: 22ch;
    text-wrap: pretty;
  }
  .pour__beat .link { font-style: italic; }

  /* ---------- static: no JS, reduced motion, data-static (default) ---------- */
  .pour__machine,
  .pour__dim,
  .pour__bezel,
  .pour__canvas,
  .pour__scale { display: none; }

  .pour__stage {
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--gutter);
    display: grid;
    grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
    column-gap: var(--gap-columns);
    row-gap: var(--space-xl);
    align-items: center;
  }
  .s-first-pour:not(.is-motion) { padding-block-end: var(--space-xl); }
  .pour__portal,
  .pour__copy { grid-column: 1 / -1; min-width: 0; margin: 0; }
  .s-first-pour:not(.is-motion) .pour__portal { width: 100%; max-width: calc(80svh * 0.72); justify-self: center; }
  /* v2 static (no JS, reduced motion): the poster feathers into the black on every side, never a box on the studio */
  .s-first-pour:not(.is-motion) .pour__media {
    background: transparent;
    -webkit-mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 14%, var(--mask-ink) 82%, transparent),
                        linear-gradient(to right, transparent, var(--mask-ink) 16%, var(--mask-ink) 84%, transparent);
            mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 14%, var(--mask-ink) 82%, transparent),
                        linear-gradient(to right, transparent, var(--mask-ink) 16%, var(--mask-ink) 84%, transparent);
    -webkit-mask-composite: source-in;
            mask-composite: intersect;
  }
  .s-first-pour:not(.is-motion) .pour__media::after { content: none; }
  .s-first-pour:not(.is-motion) .pour__caption { text-align: center; max-width: none; }

  @media (min-width: 64em) {
    .pour__portal { grid-column: 7 / -1; grid-row: 1; }
    .pour__copy { grid-column: 1 / 6; grid-row: 1; }
  }

  /* ---------- motion: shared ---------- */
  /* the pin is CSS: a sticky stage over a reserved run (desktop 4 screens, phone 3.2). Sticky never moves the
     stage in layout, so the pin adds no layout shift (a GSAP pin flips to position: fixed and Chrome counts it as
     CLS ≈ 1 at each end); js/sections/03-first-pour.js scrubs over exactly this run, read from the layout */
  .s-first-pour.is-motion { --pour-run: 540svh; }   /* desktop: the last 100svh are shared with 04, which slides over it (04-crema.css) */
  .s-first-pour.is-motion::after { content: ""; display: block; height: var(--pour-run); }
  .s-first-pour.is-motion .pour__stage {
    display: block;
    position: sticky;
    inset-block-start: 0;   /* never stuck together with the 05 stage (sloplint 56 reads them as two stacked headers) */
    max-width: none;
    margin: 0;
    padding: 0;
    height: 100svh;
    overflow: clip;
    background: transparent;   /* v2: the studio's beam and motes stand behind the footage */
  }
  .s-first-pour.is-motion .pour__machine {
    display: block;
    position: absolute;
    inset: 0;
  }
  .s-first-pour.is-motion .pour__machine-img {
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    object-position: 50% 50%;
  }
  .s-first-pour.is-motion .pour__dim {
    display: block;
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 70% 80% at 55% 45%, color-mix(in srgb, var(--color-stage) 70%, transparent), var(--color-stage) 80%);
    opacity: 0.55;
  }
  .s-first-pour.is-motion .pour__canvas {
    display: block;
    opacity: 0;
    transition: opacity var(--dur-short) var(--ease-out);
  }
  .s-first-pour.is-motion .pour__canvas.is-ready { opacity: 1; }
  .s-first-pour.is-motion .pour__media {
    -webkit-mask-image: radial-gradient(circle var(--r, 0px) at var(--x, 50%) var(--y, 50%), var(--mask-ink) calc(100% - var(--feather, 0px)), transparent 100%);
    mask-image: radial-gradient(circle var(--r, 0px) at var(--x, 50%) var(--y, 50%), var(--mask-ink) calc(100% - var(--feather, 0px)), transparent 100%);
  }
  .s-first-pour.is-motion .pour__bezel {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
  }
  .pour__ring {
    fill: none;
    stroke: color-mix(in srgb, var(--p-brass-hi) 70%, transparent);
    stroke-width: 1;
  }
  .s-first-pour.is-motion .pour__scale { display: block; }
  .pour__scale {
    position: absolute;
    background: color-mix(in srgb, var(--p-brass-lo) 70%, transparent);
  }
  .pour__scale i,
  .pour__scale b {
    position: absolute;
    display: block;
  }
  .pour__scale i { background: var(--p-brass); }
  .pour__scale b { background: var(--p-brass-hi); }

  /* beats: one lit, the others still readable (muted 7.29:1); the dash carries the state, not colour alone */
  .s-first-pour.is-motion .pour__beat {
    color: var(--color-muted);
    padding-inline-start: calc(var(--space-lg) + var(--space-sm));
    transition: color calc(var(--dur-long) * 2 / 3) var(--ease-out);
  }
  .s-first-pour.is-motion .pour__beat::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 0.56em;
    width: var(--space-lg);
    height: 1px;
    background: var(--p-brass-hi);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform calc(var(--dur-long) * 2 / 3) var(--ease-out);
  }
  .s-first-pour.is-motion .pour__beat.is-active {
    color: var(--color-ink);
    transition-duration: var(--dur-long);
  }
  .s-first-pour.is-motion .pour__beat.is-active::before {
    transform: scaleX(1);
    transition-duration: var(--dur-long);
  }

  /* ---------- motion: desktop (pinned, portal over the photograph) ---------- */
  @media (min-width: 64em) {
    .s-first-pour.is-motion .pour__machine {
      -webkit-mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 12%);
      mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 12%);
    }
    /* the climax fills the stage height; its edges dissolve into the stage through the mask, never a box */
    .s-first-pour.is-motion .pour__portal {
      --pour-cap: 0px;   /* v2: the footage runs the full stage height; the caption sits on its feathered foot */
      position: absolute;
      left: var(--pour-x, 40%);
      top: var(--pour-y, 0px);
      width: min(64vw, calc((100svh - var(--pour-cap)) * 1.05), 44rem);   /* 720 px source: cover scale ≤ 0.98, ≤ 1.1 with the iris zoom or the push */
    }
    .s-first-pour.is-motion .pour__frame {
      aspect-ratio: auto;
      height: calc(100svh - var(--pour-cap));
    }
    .s-first-pour.is-motion .pour__media {
      -webkit-mask-image: radial-gradient(var(--r, 0px) var(--ry, 0px) at var(--x, 50%) var(--y, 50%), var(--mask-ink) calc(100% - var(--feather, 0px)), color-mix(in srgb, var(--mask-ink) 40%, transparent) calc(100% - var(--feather, 0px) * 0.45), transparent 100%);
      mask-image: radial-gradient(var(--r, 0px) var(--ry, 0px) at var(--x, 50%) var(--y, 50%), var(--mask-ink) calc(100% - var(--feather, 0px)), color-mix(in srgb, var(--mask-ink) 40%, transparent) calc(100% - var(--feather, 0px) * 0.45), transparent 100%);
    }
    .s-first-pour.is-motion .pour__media::after { content: none; }
    .s-first-pour.is-motion .pour__caption {
      position: absolute;
      inset-inline: 0;
      inset-block-end: var(--space-xl);
      margin: 0;
      width: 100%;
      max-width: none;
      text-align: center;
    }
    .s-first-pour.is-motion .pour__copy {
      position: absolute;
      inset: 0;
      max-width: var(--container);
      margin-inline: auto;
      padding-inline: var(--gutter);
      display: grid;
      grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
      column-gap: var(--gap-columns);
      align-items: center;
      pointer-events: none;
    }
    .s-first-pour.is-motion .pour__text {
      grid-column: 1 / 6;
      position: relative;
      padding-inline-start: var(--space-xl);
      pointer-events: auto;
    }

    /* beats as a type scale: every beat is set in Archivo 300 at display size and keeps its line breaks; the lit
       one shows at full size, the others are scaled down and muted. JS stacks them absolutely (.is-sized) in a list
       whose height is reserved for the tallest state and moves them with transforms only: no reflow, no CLS */
    .s-first-pour.is-motion .pour__beat {
      font-family: var(--p-serif);
      font-style: italic;
      font-weight: 400;
      font-size: clamp(2.75rem, 0.6rem + 3.6vw, 4.5rem);
      line-height: 1;
      letter-spacing: -0.015em;
      max-width: none;
      transform-origin: 0 0;
      transition-property: color, transform;
    }
    .s-first-pour.is-motion .pour__beat::before { top: 0.55em; }
    .s-first-pour.is-motion .pour__beats.is-sized {
      display: block;
      position: relative;
      height: var(--beats-h, auto);
    }
    .s-first-pour.is-motion .pour__beats.is-sized .pour__beat {
      position: absolute;
      inset-inline: 0;
      top: 0;
    }
    .s-first-pour.is-motion .pour__scale {
      inset-block: 0;
      inset-inline-start: 0;
      width: 1px;
    }
    .s-first-pour.is-motion .pour__scale i {
      left: 0;
      top: 0;
      width: var(--space-xs);
      height: 1px;
      transform: translateY(var(--ty, 0px));
      transition: transform var(--dur-long) var(--ease-out);
    }
    .s-first-pour.is-motion .pour__scale b {
      left: 0;
      top: 0;
      width: 1px;
      height: 100%;
      transform: scaleY(var(--f, 0));
      transform-origin: top;
      transition: transform var(--dur-long) var(--ease-out);   /* the ticks move when a beat grows: the marker follows */
    }
  }

  /* ---------- motion: phone and tablet (one pin, footage on top, words below) ---------- */
  @media (max-width: 63.99em) {
    .s-first-pour.is-motion { --pour-run: 350svh; }
    .s-first-pour.is-motion .pour__stage {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      --ph: 56svh;   /* v2: the serif beats need a little more room under the footage */
    }
    .s-first-pour.is-motion .pour__machine {
      inset: 0 0 auto;
      height: var(--ph);
    }
    .s-first-pour.is-motion .pour__machine,
    .s-first-pour.is-motion .pour__frame {
      -webkit-mask-image: linear-gradient(to bottom, var(--mask-ink) 82%, transparent);
      mask-image: linear-gradient(to bottom, var(--mask-ink) 82%, transparent);
    }
    .s-first-pour.is-motion .pour__portal {
      position: relative;
      flex: none;
    }
    .s-first-pour.is-motion .pour__portal .pour__frame {
      aspect-ratio: auto;
      height: var(--ph);
      width: 100%;
    }
    .s-first-pour.is-motion .pour__media {
      -webkit-mask-image: none;
      mask-image: none;
      clip-path: circle(var(--r, 0px) at var(--x, 50%) var(--y, 50%));
    }
    .pour__media::after { box-shadow: inset 0 0 var(--space-xl) 0 var(--color-stage); }
    /* phone: the circle has opened past every corner, so the render feathers its own sides into the stage */
    .s-first-pour.is-motion .pour__cup {
      -webkit-mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 14%, var(--mask-ink) 80%, transparent), linear-gradient(to right, transparent, var(--mask-ink) 14%, var(--mask-ink) 86%, transparent);
      mask-image: linear-gradient(to bottom, transparent, var(--mask-ink) 14%, var(--mask-ink) 80%, transparent), linear-gradient(to right, transparent, var(--mask-ink) 14%, var(--mask-ink) 86%, transparent);
      -webkit-mask-composite: source-in;
      mask-composite: intersect;
    }
    .s-first-pour.is-motion .pour__caption {
      padding-inline: var(--gutter);
      margin-block-start: var(--space-xs);
    }
    .s-first-pour.is-motion .pour__copy {
      flex: 1;
      min-height: 0;
      padding: var(--space-md) var(--gutter) var(--space-lg);
    }
    .s-first-pour.is-motion .pour__text { position: relative; padding-block-start: var(--space-lg); }
    .s-first-pour.is-motion .pour__scale {
      inset-inline: 0;
      top: 0;
      height: 1px;
    }
    .s-first-pour.is-motion .pour__scale i {
      top: 0;
      left: calc(var(--t, 0) * 100%);
      width: 1px;
      height: var(--space-xs);
    }
    .s-first-pour.is-motion .pour__scale i:nth-child(2) { --t: 0.1329; }
    .s-first-pour.is-motion .pour__scale i:nth-child(3) { --t: 0.8291; }   /* f-132 of 159: beat 3 */
    .s-first-pour.is-motion .pour__scale b {
      top: 0;
      left: 0;
      width: 100%;
      height: 1px;
      transform: scaleX(var(--f, 0));
      transform-origin: left;
    }
    .s-first-pour.is-motion .pour__beats { gap: var(--space-sm); }
  }
  @media (max-width: 63.99em) and (max-height: 700px) {
    .s-first-pour.is-motion .pour__stage { --ph: 46svh; }
  }
  /* landscape phones: a stacked pin would push beats 2 and 3 below the screen; footage left, words right */
  @media (max-width: 63.99em) and (orientation: landscape) and (max-height: 500px) {
    .s-first-pour.is-motion .pour__stage {
      display: grid;
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
      align-items: center;
      --ph: calc(100svh - var(--space-xl));
    }
    .s-first-pour.is-motion .pour__machine {           /* the photograph stays in the footage column: the words sit on the stage */
      inset: 0 auto 0 0;
      width: 50%;
      height: auto;
      overflow: clip;
    }
    .s-first-pour.is-motion .pour__machine-img { object-position: 84% 50%; }
    .s-first-pour.is-motion .pour__machine,
    .s-first-pour.is-motion .pour__frame {
      -webkit-mask-image: linear-gradient(to bottom, var(--mask-ink) 82%, transparent), linear-gradient(to right, var(--mask-ink) 78%, transparent);
      mask-image: linear-gradient(to bottom, var(--mask-ink) 82%, transparent), linear-gradient(to right, var(--mask-ink) 78%, transparent);
      -webkit-mask-composite: source-in;
      mask-composite: intersect;
    }
    .s-first-pour.is-motion .pour__portal { grid-column: 1; grid-row: 1; align-self: start; }
    .s-first-pour.is-motion .pour__copy {
      grid-column: 2;
      grid-row: 1;
      padding: var(--space-sm) var(--gutter) var(--space-sm) var(--space-md);
    }
    .s-first-pour.is-motion .pour__beats { gap: var(--space-xs); }
    .s-first-pour.is-motion .pour__text { padding-block-start: var(--space-md); }
  }
}
