/* ============================================================
   HOME STAGE — the Stage block of the home page (site/src/components/HomeStage.astro)
   Requires: tokens.css, page.css, surface.css (.card), button.css
   Moved from our live embed (embed/home-stage-block-embed.html, Figma 18772:84001; block map home-04, 01.12.2026):
   the scene's markup, lines and motion as they are; the card, type, button, pill and colours on the system.

   Layout. Desktop (≥992): one .card, the copy on 4 of its 12 columns (pill and heading on top, the lead on the bottom
   edge), the scene on the other 8, centred on the card's height and kept a button's height clear of the top and
   bottom; the button stacks over the card in the same grid cell, in its top-right corner, a card padding in.
   Up to 991: the copy over the scene, the button under the card, full width, 16 below it (live). Phones (≤767): the
   scene in two tiers — sheet, branches and chips on top, the three ads upright in a row under them.

   The scene is authored in Figma units on a 752 × 281 frame (phones: 430 × 502): --hs-u is one unit against the
   scene's own width (cqi), so it scales as one piece at every width — no fixed sizes inside.
   ============================================================ */

.home-stage { display: grid; }
.home-stage__card,
.home-stage__btn { grid-area: 1 / 1; }

/* ---------- Card: copy + scene ---------- */
.home-stage__card {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--grid-gap);
  overflow: clip; /* the ads rise from under the card's bottom edge */
}
.home-stage__copy {
  grid-column: 1 / span 4;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  /* the scene leans 28 frame units into the gutter by the copy (.home-stage__flow): keep the text clear of it */
  padding-inline-end: var(--space-md);
}
/* The label: the system Chip, filled (.chip--filled, patterns.css), as the slides' labels */
.home-stage__pill { justify-self: start; margin-bottom: var(--space-sm); white-space: nowrap; }
.home-stage__copy h2 { margin: 0; }
/* desktop: on the card's bottom edge, at least the H3 → text gap under the heading */
.home-stage__lead { margin: auto 0 0; padding-top: var(--gap-heading-small); text-wrap: pretty; }

.home-stage__btn {
  justify-self: end;
  align-self: start;
  margin: var(--pad-card-fluid);
  position: relative; /* over the card */
}

.home-stage__art {
  grid-column: 5 / -1;
  grid-row: 1;
  align-self: center;
  /* clear of the button above, the enlarged ads included, as deep a field below */
  margin-block: var(--space-xl);
  container-type: inline-size;
}

/* ---------- Scene ---------- */
.home-stage__scene {
  --hs-u: calc(100cqi / 752);
  position: relative;
  aspect-ratio: 752 / 281;
}
.home-stage__scene > *,
.home-stage__flow > * { position: absolute; }
/* everything but the ads: a little left of the frame, into the gutter by the copy, so the chips keep air from the ads */
.home-stage__flow { inset: 0; translate: calc(-28 * var(--hs-u)) 0; }
.home-stage__scene img { display: block; max-width: none; height: auto; }

.home-stage__lines { left: 0; top: 0; width: 100%; height: 100%; max-width: none; overflow: visible; } /* wider than the frame on phones */
.home-stage__lines path {
  fill: none;
  stroke: var(--color-bg-cta-grey); /* live #464646 (white 13% on the card); one step lighter than the card */
  stroke-width: 4;                   /* frame units: scales with the scene */
  stroke-linecap: butt;              /* a square end meets the chip's edge cleanly */
}
.home-stage__left { left: 0; top: calc(35.56 * var(--hs-u)); width: calc(183 * var(--hs-u)); }

.home-stage__ads {
  left: calc(438 * var(--hs-u)); top: 0; width: calc(299 * var(--hs-u)); height: calc(281 * var(--hs-u));
  /* larger than in Figma, growing mostly to the left over the chips' edge, clear of the card's right side (live) */
  scale: 1.18;
  transform-origin: 78% 50%;
}
/* each ad placed by its centre in stack units (--cx, --cy), turned by --r */
.home-stage__ads > * {
  position: absolute;
  left: calc(var(--cx) * var(--hs-u));
  top: calc(var(--cy) * var(--hs-u));
  translate: -50% -50%;
  rotate: var(--r);
}
/* An ad, rebuilt from the Figma wireframe (FB ad): tinted glass over a real backdrop blur — each ad takes its photo's
   colour (--tint, r g b), thin enough for the blurred ads behind to read through, with a light rim */
.home-stage__ad {
  display: flex;
  flex-direction: column;
  gap: calc(7.591 * var(--hs-u));
  width: calc(154.662 * var(--hs-u));
  padding: calc(7.591 * var(--hs-u));
  border-radius: calc(7.591 * var(--hs-u));
  overflow: hidden;
  color: var(--color-text);
  background-color: rgb(var(--tint) / 0.4);
  box-shadow: inset 0 0 0 calc(1 * var(--hs-u)) var(--color-border-subtle);
  backdrop-filter: blur(calc(32 * var(--hs-u))) saturate(1.4);
}
.home-stage__ad-row { display: flex; align-items: center; gap: calc(7.591 * var(--hs-u)); }
.home-stage__ad-col { display: flex; flex-direction: column; gap: calc(3.795 * var(--hs-u)); }
.home-stage__ad-cta { justify-content: space-between; }
.home-stage__ad-actions { display: flex; justify-content: space-between; }
.home-stage__ad-avatar { width: calc(18.977 * var(--hs-u)); height: calc(18.977 * var(--hs-u)); flex: none; overflow: visible; }
/* the ad's text and buttons as bars: --w × --h frame units; two greys on the glass (live white 20% / 40%) */
.home-stage__bar {
  display: block;
  width: calc(var(--w) * var(--hs-u));
  height: calc(var(--h, 4.744) * var(--hs-u));
  border-radius: calc(var(--h, 4.744) / 2 * var(--hs-u));
  background: var(--color-border-subtle);
}
.home-stage__bar--strong { background: var(--color-glass-scheme-white); }
.home-stage__bar--btn { border-radius: calc(3.795 * var(--hs-u)); }
.home-stage__ad-img {
  display: block;
  width: calc(139.481 * var(--hs-u));
  aspect-ratio: 1;
  border-radius: calc(4 * var(--hs-u));
  object-fit: cover;
}

.home-stage__chip {
  --trunk: 224; /* beat 2: the chips stacked left-aligned at x 224 */
  left: calc(var(--x) * var(--hs-u));
  top: calc(var(--y) * var(--hs-u));
  display: flex;
  align-items: center;
  height: calc(48.94 * var(--hs-u));
  padding: calc(10.125 * var(--hs-u)) calc(12.942 * var(--hs-u)) calc(11.813 * var(--hs-u));
  border-radius: calc(20.25 * var(--hs-u));
  background: var(--color-accent-lime); /* live #F2FD9C («Ad name chip»), no token: the nearest, Accent/Lime */
  color: var(--color-text-inverted);
  font-size: calc(27 * var(--hs-u));
  font-weight: 600;
  line-height: 1;
  letter-spacing: var(--text-btn-ls);
  white-space: nowrap;
}
.home-stage__chip--media { width: calc(158.4 * var(--hs-u)); justify-content: flex-end; }
.home-stage__chip--media img { position: absolute; left: calc(11 * var(--hs-u)); top: calc(2.84 * var(--hs-u)); width: calc(56.3 * var(--hs-u)); }

/* Branch pulse: one short dash, parked before the path's start at rest */
.home-stage__lines .home-stage__pulse {
  stroke: var(--color-accent-lime);
  stroke-dasharray: 0.14 2;
  stroke-dashoffset: 0.14;
}

/* ---------- Up to 991: copy over the scene, the button under the card ---------- */
@media (max-width: 61.9375rem) {
  .home-stage__card { display: flex; flex-direction: column; }
  .home-stage__copy { padding-inline-end: 0; }
  /* the copy over the scene: a reading measure on the lead (live capped it at 36rem) */
  .home-stage__lead { margin-top: 0; max-width: var(--measure-lead); }
  .home-stage__art { width: 100%; margin: var(--gap-heading-block) 0 0; }
  /* the button under the card belongs to it: 8 to the card, 48 to the next block (16 of the tight gap + 32 here) — as the slides' cards (Liliya, 01.12.2026) */
  .home-stage__btn { grid-area: 2 / 1; justify-self: stretch; margin: var(--space-xs) 0 var(--space-md); }
  /* the desktop nudges — the scene into the copy's gutter, the ads 18% larger — have no room here */
  .home-stage__flow { translate: none; }
  .home-stage__ads { left: calc(454 * var(--hs-u)); scale: 1; }
}

/* ---------- Phones: the scene in two tiers ---------- */
@media (max-width: 47.9375rem) {
  /* the card's bottom padding moves inside the scene, so the rising ads are clipped on the card's edge */
  .home-stage__card { padding-bottom: 0; }
  /* 48 from the text to the picture, as a bento card's picture on phones (Liliya, 01.12.2026, docs/layout-rules.md) */
  .home-stage__art { align-self: center; max-width: 21rem; margin-top: var(--space-lg); padding-bottom: var(--pad-card-fluid); overflow: clip; }
  /* the frame is the left group's width (x 0–430); the group lifted by its empty top (y 36), the ads 28 units under
     its bottom (y 273), upright in a row, each over the one before by 17 units */
  .home-stage__scene { --hs-u: calc(100cqi / 430); aspect-ratio: 430 / 502; }
  .home-stage__flow { translate: 0 calc(-36 * var(--hs-u)); overflow: clip; }
  .home-stage__lines { width: calc(752 * var(--hs-u)); height: calc(281 * var(--hs-u)); }
  .home-stage__ads { left: 0; top: calc(265 * var(--hs-u)); width: 100%; height: calc(237.21 * var(--hs-u)); }
  .home-stage__ads > * { top: 50%; rotate: 0deg; }
  .home-stage__ad--1 { left: calc(77.33 * var(--hs-u)); }
  .home-stage__ad--2 { left: 50%; }
  .home-stage__ad--3 { left: calc(352.67 * var(--hs-u)); }
}

/* ---------- Motion: the scroll-in scene (desktop and phones; tablets show the finished layout) ----------
   1 — an empty ad pile (no photos yet) rises from under the card's edge as one straight stack;
   2 — four branches grow out of the sheet one by one, each ending in a chip that pops in at its tip, the chips
       stacked left-aligned;
   3 — a light runs down each branch; as it reaches its chip, the chip flashes, is pushed out to its step (the script
       keeps the branch on it) and fills its field in the ad: Ad account the page name, Media the photo, Ad name the
       headline, UTM the link — each drawn in from the left;
   4 — the stack fans out from its middle card (phones: the outer two slide out to the sides).
   The start state applies only once the script has armed the block ([data-hs-armed]), so without JS the finished
   layout shows; under «reduce motion» none of this applies. Transitions sit on the «in» state only: arming snaps
   to the start. No fades on the ads: an element under full opacity cuts the backdrop blur inside it.
   Timing: a choreographed scene keeps its own timeline (docs/layout-rules.md, «Motion»: «choreographed scenes stay
   per component») — the live starts, lengths, steps and curves below as --hs-* variables; its plain parts take a
   character: the chip pop — Spring's curve, the photo wipe — Reveal, the fan — Open's curve. */
@media (min-width: 62rem) and (prefers-reduced-motion: no-preference),
       (max-width: 47.9375rem) and (prefers-reduced-motion: no-preference) {
  .home-stage {
    /* 1 — the empty pile comes up: quick off the mark, a soft landing (the scene's own) */
    --hs-rise: 0.04s;  --hs-rise-d: 1.12s; --hs-rise-e: cubic-bezier(0.25, 1, 0.5, 1);
    /* 2 — branches grow (the scene's own), then the chips pop in (Spring's curve) */
    --hs-grow: 0.35s;  --hs-grow-d: 1.15s; --hs-grow-st: 0.15s; --hs-grow-e: cubic-bezier(0.4, 0, 0.2, 1);
    --hs-pop: 1.27s;   --hs-pop-d: 0.45s;  --hs-pop-st: 0.15s;  --hs-pop-e: var(--ease-spring);
    /* 3 — lights run down the branches (the scene's own)… */
    --hs-pulse: 1.6s;  --hs-pulse-d: 0.45s; --hs-pulse-st: 0.22s; --hs-pulse-e: cubic-bezier(0.5, 0, 0.9, 0.5);
    /*     …reach the chips: each flashes, steps out, fills its field (the scene's own) */
    --hs-fill: 2.04s;  --hs-fill-d: 0.75s; --hs-fill-st: 0.22s; --hs-fill-e: cubic-bezier(0.33, 1, 0.68, 1);
    /* 4 — the stack fans out (Open's curve, the live 0.7s length) */
    --hs-fan: 2.7s;    --hs-fan-d: 0.7s;   --hs-fan-e: var(--ease-open);
  }

  /* 1 — the empty pile, on the middle card's place (173.65, 126.29), parked under the card's edge */
  [data-hs-armed] .home-stage__ads { translate: 0 calc(380 * var(--hs-u)); }
  [data-hs-armed].is-in .home-stage__ads {
    translate: 0 0;
    transition: translate var(--hs-rise-d) var(--hs-rise-e) var(--hs-rise);
  }
  [data-hs-armed] .home-stage__ads > * {
    translate: calc(-50% + (173.65 - var(--cx)) * var(--hs-u)) calc(-50% + (126.29 - var(--cy)) * var(--hs-u));
    rotate: 0deg;
  }
  /* the photo slot starts empty; the empty ads are plain grey glass and take their photo's colour as it comes in */
  [data-hs-armed] .home-stage__ad-img { clip-path: inset(0 100% 0 0); }
  [data-hs-armed] .home-stage__ad { background-color: var(--color-glass-dark); }

  /* 2 — branches grow; hidden outright until each starts (an undrawn dash still paints its cap as a dot) */
  [data-hs-armed] .home-stage__lines path:not(.home-stage__pulse) { stroke-dasharray: 1; stroke-dashoffset: 1; visibility: hidden; }
  [data-hs-armed].is-in .home-stage__lines path:not(.home-stage__pulse) {
    stroke-dashoffset: 0;
    visibility: visible;
    transition:
      stroke-dashoffset var(--hs-grow-d) var(--hs-grow-e) calc(var(--hs-grow) + var(--i) * var(--hs-grow-st)),
      visibility 0s linear calc(var(--hs-grow) + var(--i) * var(--hs-grow-st));
  }
  [data-hs-armed] .home-stage__chip {
    translate: calc((var(--trunk) - var(--x)) * var(--hs-u)) 0;
    opacity: 0;
    scale: 0.85;
  }
  [data-hs-armed].is-in .home-stage__chip {
    translate: 0 0;
    opacity: 1;
    scale: 1;
    transition:
      opacity var(--hs-pop-d) ease-out calc(var(--hs-pop) + var(--i) * var(--hs-pop-st)),
      scale var(--hs-pop-d) var(--hs-pop-e) calc(var(--hs-pop) + var(--i) * var(--hs-pop-st)),
      translate var(--hs-fill-d) var(--hs-fill-e) calc(var(--hs-fill) + var(--i) * var(--hs-fill-st));
    /* 3 — as its light arrives the chip flashes and is pushed out to its step */
    animation: home-stage-chip-ping 0.7s ease-out calc(var(--hs-fill) + var(--i) * var(--hs-fill-st)) both;
  }

  /* 3 — a light runs down each branch in turn… */
  [data-hs-armed].is-in .home-stage__pulse {
    animation: home-stage-pulse var(--hs-pulse-d) var(--hs-pulse-e) calc(var(--hs-pulse) + var(--i) * var(--hs-pulse-st)) both;
  }
  /* …and its field in the ad fills from the left: Media wipes the photo in (Reveal); the page name, headline and
     link draw in lime and settle back to grey */
  [data-hs-armed].is-in .home-stage__ad-img {
    clip-path: inset(0 0 0 0);
    transition: clip-path var(--duration-reveal) var(--ease-reveal) calc(var(--hs-fill) + var(--hs-fill-st));
  }
  [data-hs-armed].is-in .home-stage__bar--f {
    animation: home-stage-field 0.9s cubic-bezier(0.4, 0, 0.2, 1) calc(var(--hs-fill) + var(--f) * var(--hs-fill-st)) both;
  }

  /* 4 — filled, the stack fans out from its middle card: the back card swings right, the front one left */
  [data-hs-armed].is-in .home-stage__ads > * {
    translate: -50% -50%;
    rotate: var(--r);
    transition:
      translate var(--hs-fan-d) var(--hs-fan-e) var(--hs-fan),
      rotate var(--hs-fan-d) var(--hs-fan-e) var(--hs-fan),
      background-color var(--duration-reveal) var(--ease-reveal) calc(var(--hs-fill) + var(--hs-fill-st));
  }
  [data-hs-armed].is-in .home-stage__ad { background-color: rgb(var(--tint) / 0.4); }
}
/* Phones: beat 4 is a spread, not a fan — the pile stands on the middle ad, the outer two slide out to the sides */
@media (max-width: 47.9375rem) and (prefers-reduced-motion: no-preference) {
  [data-hs-armed] .home-stage__ads { translate: 0 calc(300 * var(--hs-u)); }
  [data-hs-armed]:not(.is-in) .home-stage__ad--1 { translate: calc(-50% + 137.33 * var(--hs-u)) -50%; }
  [data-hs-armed]:not(.is-in) .home-stage__ad--3 { translate: calc(-50% - 137.33 * var(--hs-u)) -50%; }
  [data-hs-armed] .home-stage__ads > *,
  [data-hs-armed].is-in .home-stage__ads > * { rotate: 0deg; }
}

@keyframes home-stage-pulse {
  from { stroke-dashoffset: 0.14; }
  to   { stroke-dashoffset: -1; }
}
/* a field draws in: an inset shadow as wide as the bar sweeps across it in the chip colour, then fades out */
@keyframes home-stage-field {
  0%   { box-shadow: inset 0 0 0 0 var(--color-accent-lime); }
  45%  { box-shadow: inset calc(var(--w) * var(--hs-u)) 0 0 0 var(--color-accent-lime); }
  100% { box-shadow: inset calc(var(--w) * var(--hs-u)) 0 0 0 transparent; }
}
/* the chip flashes light and rings out */
@keyframes home-stage-chip-ping {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent-lime) 60%, transparent); }
  30%  { background-color: var(--color-bg-white); }
  100% { box-shadow: 0 0 0 calc(12 * var(--hs-u)) transparent; }
}

/* the yellow button goes black under the mouse, as live and as the slides' bar (the system's Indigo hover is not this block's) */
@media (hover: hover) { .home-stage__btn.btn-default:hover { background: var(--color-bg); color: var(--color-text); } }

/* the lead in Paragraph SM where the copy sits beside the scene (from 992), as the slides' bar lead (Liliya's review, mx4tp2h4); phones and tablets keep MD, as the slides' cards */
@media (min-width: 62rem) { .home-stage__lead { font-size: var(--text-para-sm-size); line-height: var(--text-para-sm-lh); letter-spacing: var(--text-para-sm-ls); } }
