/* The hero's After purchase tile: its contents arrive (user request of 16 November 2026,
   with four changes to the tile itself: "le tout doit être animé l'apparition, je te
   laisse voir comment"). One source for the homepage's hero and for the tile's Stageshow
   scene (`After` in product-ui/src/heroes/commerce-grid/index.tsx), which films the
   poster this play ends on.

   What plays, once, when the hero arrives. The tile opens on its ground and its name.
   The retailer's message arrives from its tail's corner; after the time it takes to read
   it, the customer's yes arrives from its own; then the three channels the message can
   travel by come up one after the other, left to right. 2.7s, and the tile is the filmed
   poster. Nothing else moves, nothing moves once it has played, and it does not loop.

   How it is built. Every piece that plays carries a class of this sheet:
     .haf__ask    the retailer's message
     .haf__yes    the customer's yes
     .haf__chip   a channel (--n: 0, 1, 2)
   In the scene they are the interface's own elements (the kit's bubbles). On the page
   they are pictures of those elements, filmed alone (see "The page" below), set over a
   plate of the hero filmed without them. The root, .haf, is marked data-play: "ready"
   holds the first frame, "on" plays, anything else is the poster's frame. */

.haf {
  /* The clock, from the moment the play starts (--haf-lead is the page's wait when no script times it) */
  --haf-lead: 0s;
  --haf-ask-at: calc(var(--haf-lead) + .15s);
  --haf-yes-at: calc(var(--haf-ask-at) + 1.1s);
  --haf-chips-at: calc(var(--haf-yes-at) + .65s);
  --haf-gap: .09s;
  --haf-end: calc(var(--haf-chips-at) + 2 * var(--haf-gap) + .6s);
  /* The kit's curve for an arrival from nowhere: a quick start and a long, soft landing, no rebound */
  --haf-arrive: cubic-bezier(.22, 1, .36, 1);
  /* How far a piece rises into its place */
  --haf-rise: 8px;
}

/* How a piece arrives. What is animated is one registered number, --haf-in, from 0 to 1,
   and the piece's place, size and opacity are computed from it, as claim-play.css and
   agent-cast.css move their pieces: animated in the usual way (opacity, translate, scale),
   a piece is drawn on a sheet of its own for as long as it moves and steps a fraction of a
   pixel when the play ends. Computed from a number, it is drawn afresh where it stands and
   lands exactly. Do not go back to animating opacity, translate or scale directly. */
@property --haf-in { syntax: '<number>'; inherits: false; initial-value: 1; }
/* Until its moment a piece is not in the picture at all */
@keyframes haf-in { from { --haf-in: 0; visibility: hidden; } }
/* Nothing: its end is the end of the play (hero-after.js listens for it) */
@keyframes haf-clock { to { visibility: visible; } }

/* A bubble grows from the corner its tail is on */
.haf__ask { transform-origin: 0 100%; }
.haf__yes { transform-origin: 100% 100%; }

@media (prefers-reduced-motion: no-preference) {
  .haf:is([data-play='ready'], [data-play='on']) { animation: haf-clock var(--haf-end) linear both; }
  /* The two messages: each rises into its place and grows a little from its tail's corner, as the kit's bubble arrives */
  .haf:is([data-play='ready'], [data-play='on']) :is(.haf__ask, .haf__yes) {
    opacity: var(--haf-in, 1); translate: 0 calc((1 - var(--haf-in, 1)) * var(--haf-rise)); scale: calc(.94 + .06 * var(--haf-in, 1));
    animation: haf-in .55s var(--haf-arrive) var(--haf-ask-at) both;
  }
  .haf:is([data-play='ready'], [data-play='on']) .haf__yes { animation-duration: .5s; animation-delay: var(--haf-yes-at); }
  /* The channels come up whole, one after the other in reading order */
  .haf:is([data-play='ready'], [data-play='on']) .haf__chip {
    opacity: var(--haf-in, 1); translate: 0 calc((1 - var(--haf-in, 1)) * var(--haf-rise));
    animation: haf-in .6s var(--haf-arrive) calc(var(--haf-chips-at) + var(--n, 0) * var(--haf-gap)) both;
  }
  /* The first frame, held until the hero is looked at. The rules above set `animation` whole,
     which would start each piece again: this one has to win over them. */
  .haf[data-play='ready'], .haf[data-play='ready'] * { animation-play-state: paused !important; }
}

/* ---- The page ----
   The homepage's hero is one filmed picture of five tiles. Wide, the page shows its plate
   (product-ui/renders/h-hero-plate-<language>-wide.webp: the hero filmed with this tile
   holding only its ground and its name) and, over the tile, this layer: pictures of the
   pieces named above, filmed alone with their own shadows, the size of the tile and where
   the tile puts them, so nothing here is redrawn by hand and no word is written (the page
   does not load the picture's face). They are one file of three pictures, one under the
   other: the three channels together, the message, the yes
   (renders/h-hero-after-<language>-wide.webp, made by product-ui/export-after.py, which
   proves that the plate and the pieces together are the filmed poster).

   The layer is in the page's own markup and marked data-play="on", so it plays by this
   stylesheet alone, a second after the page opens (--haf-lead), by which time the hero has
   risen into the page. hero-after.js only chooses a better moment (the pictures arrived,
   the message's place in the window) and gives the page the whole poster where a piece
   cannot be had.
   With reduced motion the pieces are simply there. The phone composition of the hero has
   no After purchase tile, and no layer. */
.haf--page {
  position: absolute; left: calc(426 / 1200 * 100%); top: calc(392 / 668 * 100%); width: calc(414 / 1200 * 100%); height: calc(276 / 668 * 100%);
  overflow: hidden; pointer-events: none;
  --haf-lead: 1.1s;
  /* 8 of the tile's 276 pixels: a piece here is as tall as the tile */
  --haf-rise: calc(8 / 276 * 100%);
}
.haf--page[hidden] { display: none; }
/* A piece: a window the size of the tile onto its own third of the file (--k: which one) */
.haf--page > span { position: absolute; inset: 0; overflow: hidden; }
.haf--page > span > img { position: absolute; left: 0; top: calc(var(--k, 0) * -100%); display: block; width: 100%; height: 300%; max-width: none; }
.haf--page .haf__ask { --k: 1; }
.haf--page .haf__yes { --k: 2; }
/* The three channels are one picture, the first of the file, so it stands on the tile's own pixels
   with no offset; each channel shows its own column of it, from --l to --r of the tile's 414 pixels
   (the columns meet in the middle of the gaps between the chips, which are the same in every
   language). So the three always stand on one line. A picture a channel, each at its own offset in
   the file, was set on the screen's pixels on its own: where the hero is under 1200px across, the
   three stood up to a pixel and a half apart in height (found by the fresh-eye review). Do not give
   each channel a picture of its own again. */
.haf--page .haf__chip { --k: 0; clip-path: inset(0 calc((414 - var(--r)) / 414 * 100%) 0 calc(var(--l) / 414 * 100%)); }
.haf--page .haf__chip:nth-child(3) { --l: 0; --r: 160.06; }
.haf--page .haf__chip:nth-child(4) { --l: 160.06; --r: 281.03; }
.haf--page .haf__chip:nth-child(5) { --l: 281.03; --r: 414; }
/* Each bubble's tail corner, in the tile's pixels (414 x 276): the message's bottom left and the yes's
   bottom right, the same in every language (export-after.py holds the seven to these figures) */
.haf--page .haf__ask { transform-origin: calc(22 / 414 * 100%) calc(126.31 / 276 * 100%); }
.haf--page .haf__yes { transform-origin: calc(392 / 414 * 100%) calc(168.25 / 276 * 100%); }
/* Below 900px the hero shows its phone composition (home.css), which has no such tile */
@media (max-width: 900px) { .haf--page { display: none; } }
/* A change of language opens the page as it was left: nothing arrives again (redesign.css) */
html.lang-swap .haf--page, html.lang-swap .haf--page * { animation: none !important; }
