/* Motion wave 2, M2: inner-page heroes (03-MOTION-SPEC.md 4.2, 4.4, 6.5, 9.2, 11).
   Extends motion.css, scene-bento.css and hero-layouts.css; never repeats them.
   Rules:
   - everything here runs only under html.motion-ok and never on Still pages;
   - entrance additions (rows light, tiles and tiers ring, ticks draw, connectors draw, tag
     chips pop) run once, after the existing entrance, on Medium and Light pages. Each one
     ends on the static design (fill none, or an end keyframe equal to the design);
   - ambient loops (floating tags, hero image drift, offset float card, dark glow) run on
     Medium pages only (spec 11: Light has no loops). motion2-heroes.js adds .m2h-amb to the
     hero once its entrance has finished (1.6s) and toggles .m2h-view while the hero is on
     screen; off screen every loop is paused. The first keyframe of each loop is the static
     design, so a loop that never starts looks exactly like today's build;
   - phones keep one ambient loop per hero (the floating tags); image drift from 768px, the
     float card and the dark glow from 1024px;
   - reduced motion and "Pause animations" remove all of it (motion.css, plus the guard at
     the end); transform, translate, scale, opacity and stroke-dashoffset only. */

/* ================================================================ Entrance additions (once) */
/* rows (and person, map rows): the values light in order once the rows have landed. A
   Lavender wash behind each row fades in and out; at rest it is invisible. It waits for
   .m2h-seen (motion2-heroes.js, first time the card is on screen), so on phones, where the
   card sits below the fold, it plays when the card is reached (--m2h-t0 shortens the wait
   then, as the card entrance has already run). */
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] .scene__row { position: relative; isolation: isolate; }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] .scene__row::before {
	content: ""; position: absolute; z-index: -1; inset: -6px -10px; border-radius: 10px;
	background: var(--c-lav-soft); opacity: 0; pointer-events: none;
}
html.motion-ok body:not([data-motion="still"]) .hero [data-scene].m2h-seen .scene__row::before {
	animation: m2h-wash 1000ms var(--ease-in-out) calc(1150ms + var(--m2h-t0, 0ms) + var(--i, 0) * 130ms) 1 none;
}
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] .scene__row + .scene__row::before { top: 6px; }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] .scene__rows.hl-rows2 .scene__row.is-c2-top::before { top: -6px; }

/* index and tiers: a soft Brand Blue ring steps through the tiles once (the selected tier
   keeps its own fill and ring, so it is skipped). */
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] :is(.scene__tile, .scene__tier:not(.is-on)) { position: relative; }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] :is(.scene__tile, .scene__tier:not(.is-on))::after {
	content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
	box-shadow: inset 0 0 0 1.5px rgba(1, 14, 208, .32); opacity: 0;
}
html.motion-ok body:not([data-motion="still"]) .hero [data-scene].m2h-seen :is(.scene__tile, .scene__tier:not(.is-on))::after {
	animation: m2h-wash 700ms var(--ease-in-out) calc(1250ms + var(--m2h-t0, 0ms) + var(--i, 0) * 180ms) 1 none;
}

/* checks, flow connectors and tag chips run with the card entrance at load. When the card
   is first reached late (phones: it sits below the fold), motion2-heroes.js adds .m2h-late
   just before it enters the viewport and they replay under a second keyframe name, so they
   play as the card arrives instead of off screen. */
/* checks (scene list, offset float checks, floating tag dots): the check glyph draws after
   its tile pops (path length of the check icon is about 17.7). */
html.motion-ok body:not([data-motion="still"]) .hero [data-scene="checks"] .scene__tick .ico path,
html.motion-ok body:not([data-motion="still"]) .hero .hl-float__tick .ico path,
html.motion-ok body:not([data-motion="still"]) .hero .ftag__dot .ico path {
	stroke-dasharray: 18; animation: m2h-draw 450ms var(--ease-out-quart) both;
}
html.motion-ok body:not([data-motion="still"]) .hero [data-scene="checks"] .scene__tick .ico path { animation-delay: calc(640ms + var(--i, 0) * 70ms); }
html.motion-ok body:not([data-motion="still"]) .hero .hl-float__tick .ico path { animation-delay: 900ms; }
html.motion-ok body:not([data-motion="still"]) .hero .hl-float--checks li:nth-child(2) .hl-float__tick .ico path { animation-delay: 980ms; }
html.motion-ok body:not([data-motion="still"]) .hero .hl-float--checks li:nth-child(3) .hl-float__tick .ico path { animation-delay: 1060ms; }
html.motion-ok body:not([data-motion="still"]) .hero .ftag__dot .ico path { animation-delay: 720ms; }

/* flow: the short connector between two steps draws down as the next step arrives. */
html.motion-ok body:not([data-motion="still"]) .hero [data-scene="flow"] .scene__step + .scene__step::before {
	transform-origin: 50% 0; animation: m2h-grow-y 500ms var(--ease-out-quart) calc(460ms + var(--i, 0) * 120ms) both;
}

/* Tag chips under a scene card (rows, flow, checks and others): pop in a 40ms chip stagger
   after the card contents. */
html.motion-ok body:not([data-motion="still"]) .hero [data-scene] .scene__tags li {
	animation: m2h-pop 500ms var(--ease-spring-ui) calc(760ms + var(--n, 0) * 40ms) both;
}
.hero [data-scene] .scene__tags li:nth-child(2) { --n: 1; }
.hero [data-scene] .scene__tags li:nth-child(3) { --n: 2; }
.hero [data-scene] .scene__tags li:nth-child(4) { --n: 3; }
.hero [data-scene] .scene__tags li:nth-child(n + 5) { --n: 4; }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene="checks"].m2h-late .scene__tick .ico path { animation-name: m2h-draw2; animation-delay: calc(200ms + var(--i, 0) * 70ms); }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene="flow"].m2h-late .scene__step + .scene__step::before { animation-name: m2h-grow-y2; animation-delay: calc(100ms + var(--i, 0) * 120ms); }
html.motion-ok body:not([data-motion="still"]) .hero [data-scene].m2h-late .scene__tags li { animation-name: m2h-pop2; animation-delay: calc(300ms + var(--n, 0) * 40ms); }

/* Count-up (motion2-heroes.js): the animated copy keeps the final width, so nothing moves. */
.m2h-n { display: inline-block; white-space: nowrap; }

/* ================================================================ Ambient loops (Medium pages) */
/* Floating tags drift 5px, out of phase. The entrance (opacity and transform) has ended
   when .m2h-amb arrives, so replacing it holds the same static state. */
html.motion-ok body[data-motion="medium"] .hero.m2h-amb .ftag {
	animation: m2h-float 5.2s var(--ease-in-out) 0s infinite alternate both var(--m2h-ps, paused);
}
html.motion-ok body[data-motion="medium"] .hero.m2h-amb .ftag--mr,
html.motion-ok body[data-motion="medium"] .hero.m2h-amb .hl-ftag--br,
html.motion-ok body[data-motion="medium"] .hero.m2h-amb .ftag--type2 { animation-duration: 6.2s; animation-delay: .9s; }
html.motion-ok body[data-motion="medium"] .hero.m2h-amb .ftag--bl { animation-duration: 5.7s; animation-delay: 1.7s; }

@media (min-width: 768px) {
	/* Hero image: a very slow drift (as the bento lead), clipped to its rounded inset. Not on
	   case study imagery (spec 6.5), not on the editorial layout (spec 4.4: no image motion)
	   and not on dark heroes, where the glow is the slow layer (at most three loops at once). */
	html.motion-ok body[data-motion="medium"]:not([data-page-type="case"]) .hero.m2h-amb:not(.hero--editorial):not(.on-dark) .imgcard--hero .imgcard__frame > picture { overflow: hidden; border-radius: 14px; }
	html.motion-ok body[data-motion="medium"]:not([data-page-type="case"]) .hero.m2h-amb:not(.hero--editorial):not(.on-dark) .imgcard--hero .imgcard__frame > picture > img {
		animation: m2h-drift 7s var(--ease-in-out) 0s infinite alternate both var(--m2h-ps, paused);
	}
}
@media (min-width: 1024px) {
	/* Offset layout: the facts or checks card floating over the image drifts 4px. */
	html.motion-ok body[data-motion="medium"] .hero.m2h-amb .hl-float {
		animation: m2h-float4 6.6s var(--ease-in-out) .5s infinite alternate both var(--m2h-ps, paused);
	}
	/* Dark heroes (dark, darkc, dark scene): a soft Lavender glow drifts behind the visual. */
	html.motion-ok body[data-motion="medium"] .hero.on-dark.m2h-amb { position: relative; isolation: isolate; overflow: clip; }
	html.motion-ok body[data-motion="medium"] .hero.on-dark.m2h-amb::before {
		content: ""; position: absolute; z-index: -1; top: 50%; left: 72%; width: 960px; height: 960px;
		margin: -480px 0 0 -480px; border-radius: 50%; pointer-events: none;
		background: radial-gradient(closest-side, rgba(131, 138, 236, .16), rgba(131, 138, 236, .06) 55%, rgba(131, 138, 236, 0));
		opacity: 0; animation: m2h-glow 8s var(--ease-in-out) 0s infinite both var(--m2h-ps, paused);
	}
	html.motion-ok body[data-motion="medium"] .hero.on-dark.hero--centered.m2h-amb::before { left: 50%; top: 34%; }
	html.motion-ok body[data-motion="medium"] .hero.on-dark.hero--scene-flip.m2h-amb::before { left: 28%; }
}

/* Loops only while the hero is on screen: every loop above takes its play state from this
   variable (inherited by the tags, image, float card and the glow layer). */
.hero.m2h-amb { --m2h-ps: paused; }
.hero.m2h-amb.m2h-view { --m2h-ps: running; }

@keyframes m2h-wash { 0% { opacity: 0; } 40% { opacity: 1; } 100% { opacity: 0; } }
@keyframes m2h-draw { from { stroke-dashoffset: 18; } to { stroke-dashoffset: 0; } }
@keyframes m2h-draw2 { from { stroke-dashoffset: 18; } to { stroke-dashoffset: 0; } }
@keyframes m2h-grow-y { from { transform: scaleY(0); } to { transform: none; } }
@keyframes m2h-grow-y2 { from { transform: scaleY(0); } to { transform: none; } }
@keyframes m2h-pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes m2h-pop2 { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes m2h-float { from { transform: none; } to { transform: translateY(-5px); } }
@keyframes m2h-float4 { from { transform: none; } to { transform: translateY(-4px); } }
@keyframes m2h-drift { from { transform: none; } to { transform: scale(1.03) translateY(-6px); } }
@keyframes m2h-glow {
	0% { opacity: 0; transform: none; }
	50% { opacity: 1; transform: translate(-48px, 24px); }
	100% { opacity: 0; transform: none; }
}

/* ================================================================ Reduced motion, print */
@media (prefers-reduced-motion: reduce) {
	.hero .scene__row::before, .hero .scene__tile::after, .hero .scene__tier::after, .hero.m2h-amb::before,
	.hero .ico path, .hero .scene__step::before, .hero .scene__tags li, .hero .hl-float,
	.hero .imgcard__frame > picture > img { animation: none !important; }
}
@media print {
	.hero.m2h-amb::before { display: none; }
}

/* Final QA wave (X1, item 9): phones run one ambient loop per hero (MOTION.md). The first tag
   keeps its float; the other tags hold their rest state (B4-02, B4-04 ran two or three). */
@media (max-width: 767px) {
	html.motion-ok body[data-motion="medium"] .hero.m2h-amb .ftag:not(.ftag--tl):not(.ftag--type1) { animation: none; }
}
