/* ========== demo: the hero's demo block (self-contained: #demo in the page, this file, assets/demo.js) ==========
   Round 9 (from round 8's concept B): the story rail. A frameless sheet of a captured Canadian Tire search row plays the extension's
   flow (the pointer clicks the mitre saw's line, the pop-out opens, then Activate and Swap are pressed in it). Beside
   the sheet is the rail: the whole story as a permanent list of five lines (the step buttons), and under it the
   counter each step pays into. The step on screen is lit; the ones done stay done; the rest wait, readable.
   The sheet is laid out at a desktop width (900px wide; 470 or 500 tall) and scaled to fit.
   The block draws from three attributes (demo.js):
     data-s, the sheet: 0 the row with its lines · 1 the pop-out is open · 2 activated · 3 the swap offer · 4 swapped
       · 6 the row, every card the swap covers fully stacked (the end frame)
     data-c, the step on screen (1 to 5; 0 none) · data-p, how many payouts the counter has had (0 to 3): the reels'
     stop · data-l, how many payouts have landed: the pile's layers and the rail's markers (it follows data-p as the
     tens reel stops) */

.demo { --d-press: 110ms; --d-land: 260ms; --d-glide: 440ms; --d-lag: 70ms; --d-lens-in: 420ms; --d-lens-out: 260ms;
  --e-stop: cubic-bezier(0.2, 0, 0, 1); --e-land: cubic-bezier(0.16, 1, 0.3, 1);
  grid-column: 1 / -1; margin: var(--space-xs) 0 0; min-width: 0; width: 100%; container-type: inline-size; }
.demo .x { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- the stage: the sheet, and the rail beside it ---------- */
.demo .stage { --vh: 470; --fs: clamp(2.75rem, 5.4cqw, 5.25rem); --rs: clamp(1rem, 1.5cqw, 1.3rem); display: grid; grid-template-columns: minmax(0, 1fr) minmax(17rem, 0.4fr); grid-template-areas: "win rail"; gap: var(--space-md) var(--space-s32); align-items: start; color: var(--color-accent-ink); }
.demo .win { grid-area: win; position: relative; overflow: hidden; aspect-ratio: 900 / var(--vh); border-radius: var(--radius-key); background: var(--color-ct-page); container-type: inline-size; }
/* the sheet at its design size, scaled to the window's width */
.demo .view { --pu: 1px; position: absolute; left: 0; top: 0; width: 900px; height: calc(var(--vh) * 1px); overflow: hidden; transform: scale(tan(atan2(100cqw, 900px))); transform-origin: 0 0; background: var(--color-ct-page); container-type: size; }
/* with scripts off the camera rests on the whole row; demo.js takes the transform over (.on) */
.demo .cam { position: absolute; left: 50%; top: 0; width: calc(var(--sw) * 1px); margin-left: calc(var(--sw) * -0.5px); transform-origin: 50% 0; transform: scale(min(tan(atan2(100cqw, calc(var(--sw) * 1px))), tan(atan2(100cqh, calc(var(--sh) * 1px))))); }
.demo.on .cam { left: 0; margin-left: 0; transform-origin: 0 0; }
.demo .rail { grid-area: rail; display: grid; align-content: start; min-width: 0; }

/* ---------- the story: five lines, one a step, always all on screen (a phone shows the lit one). Each line is the button
   for its step (a still of it). A line's marker is the layer its step adds to the counter's pile: a solid outline for
   what you'd earn and for the offer to activate, a dashed one for the swap, three bars for the full pile; the offers
   step adds none and shows the offer glyph the pop-out's rows use. A marker fills green as its step pays and the last
   turns gold; the track down the left joins one marker to the next and fills as the step plays (none under the last
   line). The step on screen sits on a deeper cobalt plate. Waiting lines stay readable (soft white). ---------- */
.demo .story { list-style: none; margin: 0; padding: 0; display: grid; }
.demo .step { position: relative; display: grid; grid-template-columns: 2rem minmax(0, 1fr); align-items: start; gap: 0 var(--space-sm); min-height: 44px; padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-xs); border-radius: var(--radius-key); color: var(--color-accent-soft); font-family: var(--font-display); font-synthesis: none; font-stretch: 108%; font-weight: 700; font-size: var(--rs); line-height: 1.4; letter-spacing: -0.01em; }
/* the step's word is its button; the button reaches over the whole line (its ::after), so the line is what you press */
.demo .beat { margin: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.demo .beat::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.demo .beat:focus-visible { outline: 0; }
.demo .step:has(.beat:focus-visible) { outline: 3px solid var(--color-focus-on-accent); outline-offset: 0; }
.demo .ln { margin: 0; text-wrap: balance; }
.demo .k { font-weight: 900; font-stretch: 118%; }
.demo .k.wm { font-style: italic; font-stretch: 125%; letter-spacing: -0.03em; padding-right: 0.06em; }
.demo .step:hover { color: var(--color-accent-ink); }
.demo .mk { width: 2rem; height: 1lh; overflow: visible; }
.demo .mk .ly, .demo .pile .ly { fill: none; stroke: var(--color-accent-ink); transition: fill var(--d-land) linear, stroke var(--d-land) linear; }
.demo .mk-offer svg { stroke: var(--color-accent-ink); color: var(--color-accent-ink); }
.demo .track { position: absolute; left: calc(var(--space-xs) + 1rem - 1px); top: calc(var(--space-xs) + 1.4 * var(--rs)); bottom: calc(var(--space-xs) * -1 + 2px); width: 2px; background: var(--color-accent-line); }
.demo .track::after { content: ""; position: absolute; inset: 0; background: var(--color-accent-ink); transform: scaleY(0); transform-origin: 50% 0; }
.demo .story li:last-child .track { display: none; }
/* the step on screen: white words on the deeper cobalt plate */
.demo[data-c="1"] .step:nth-child(1), .demo[data-c="2"] .step:nth-child(2), .demo[data-c="3"] .step:nth-child(3), .demo[data-c="4"] .step:nth-child(4), .demo[data-c="5"] .step:nth-child(5) { background: var(--color-accent-deep); color: var(--color-accent-ink); }
/* done: the steps before the one on screen keep white words and a full track */
.demo:is([data-c="2"], [data-c="3"], [data-c="4"], [data-c="5"]) .step:nth-child(1), .demo:is([data-c="3"], [data-c="4"], [data-c="5"]) .step:nth-child(2), .demo:is([data-c="4"], [data-c="5"]) .step:nth-child(3), .demo:is([data-c="5"]) .step:nth-child(4) { color: var(--color-accent-ink); }
.demo:is([data-c="2"], [data-c="3"], [data-c="4"], [data-c="5"]) .step:nth-child(1) .track::after, .demo:is([data-c="3"], [data-c="4"], [data-c="5"]) .step:nth-child(2) .track::after, .demo:is([data-c="4"], [data-c="5"]) .step:nth-child(3) .track::after, .demo:is([data-c="5"]) .step:nth-child(4) .track::after { transform: none; }
.demo .step.run .track::after { animation: d-track var(--d) linear both; }
/* paid: the marker of a step that has paid fills green (what you'd earn, the activated offer, the swap); the last
   line's marker and badge word turn gold when it is on screen, the pile being gold by then */
.demo:is([data-l="1"], [data-l="2"], [data-l="3"]) .step:nth-child(1) .ly, .demo:is([data-l="2"], [data-l="3"]) .step:nth-child(3) .ly, .demo[data-l="3"] .step:nth-child(4) .ly { fill: var(--sm-money-on-brand); stroke: var(--sm-money-on-brand); stroke-dasharray: none; }
.demo[data-c="5"] .step:nth-child(5) .ly { fill: var(--sm-accent); stroke: var(--sm-accent); }
.demo[data-c="5"] .k.wm { color: var(--sm-accent); }

/* ---------- the counter: what the step lines pay into. Four slot reels ($ 5 0 . 0 0) and the coin pile. ----------
   Each reel is a strip (0 to 9 four times); data-p stops each on its digit, further down the strip at each payout, so a
   payout spins every reel forward. They land right to left, cents first and the tens last (demo.js runs the spin: it
   gets going, cruises, brakes, runs a third of a cell past its digit and comes back; this file holds where each one
   stops). Each reel window fades at its top and bottom edge like a drum, so the digits rolling through are never cut
   hard. Before the first payout the counter is unseen. The amount is the have-now green and stays green at the end:
   gold is the pile (from the moment $50 lands after the swap) and the badge word. */
.demo .score { position: relative; display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: 0 var(--space-sm); margin-top: var(--space-sm); padding: var(--space-xs) var(--space-sm) 0 var(--space-xs); font-family: var(--sm-font); }
.demo .score > * { grid-column: 2; }
.demo[data-p="0"] .score { opacity: 0; }
.demo .tally { position: relative; display: flex; align-items: center; gap: var(--space-md); }
.demo .fig { display: flex; align-items: flex-start; margin: 0; font-weight: 700; line-height: 1; color: var(--sm-money-on-brand); }
.demo .cur { margin-top: calc(var(--fs) * 0.12); margin-right: var(--space-3xs); font-size: calc(var(--fs) * 0.5); }
.demo .pt { margin-top: calc(var(--fs) * 0.12); font-size: calc(var(--fs) * 0.5); }
.demo .rl { --at: 0; display: block; flex: none; height: 1.04em; overflow: hidden; font-size: var(--fs); letter-spacing: -0.03em; mask-image: linear-gradient(transparent, var(--color-ink) 13%, var(--color-ink) 87%, transparent); }
.demo .rl-2, .demo .rl-3 { margin-top: calc(var(--fs) * 0.12); font-size: calc(var(--fs) * 0.5); }
.demo .strip { display: flex; flex-direction: column; transform: translateY(calc(var(--at) * -1.04em)); }
.demo .strip .c { display: block; height: 1.04em; line-height: 1.04em; min-width: 0.6em; text-align: center; }
.demo[data-p="1"] .rl { --at: var(--i1); }
.demo[data-p="2"] .rl { --at: var(--i2); }
.demo[data-p="3"] .rl { --at: var(--i3); }
.demo .pile { flex: none; width: calc(var(--fs) * 0.82); height: auto; overflow: visible; }
.demo .pile .ly { stroke-width: 3; }
.demo:is([data-l="1"], [data-l="2"]) .pile .ly-0, .demo[data-l="2"] .pile .ly-1 { fill: var(--sm-money-on-brand); stroke: var(--sm-money-on-brand); }
.demo[data-l="3"] .pile .ly { fill: var(--sm-accent); stroke: var(--sm-accent); stroke-dasharray: none; }
.demo .unit { margin-top: var(--space-xs); font-size: var(--text-sm); font-weight: 700; line-height: 1.3; }
.demo .unit .on { display: block; font-weight: 400; color: var(--color-accent-soft); }

/* ---------- the hit: a damage number. The figure a click earns is born at the button the pointer pressed and flies to
   where the value lands (demo.js moves it, in the figure's pixels, only while the piece plays), with a small label
   under it: "+$20.00 / CT Money" on Activate; on Swap "20x / on Power Tools", then "+$20.00 / CT Money". The amount
   also pops off the counter as its reels land. The wordmark's lettering in have-now mint with a solid ink edge, so it
   reads on the white pop-out, the grey dim and the cobalt: no glow, no burst. ---------- */
.demo { position: relative; }
.demo .hits { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.demo .hit { position: absolute; left: 0; top: 0; }
.demo .hit b { display: block; translate: -50% -50%; padding-right: 0.06em; font-family: var(--font-display); font-synthesis: none; font-style: italic; font-stretch: 125%; font-weight: 900; font-size: var(--hf, 40px); line-height: 1; letter-spacing: -0.03em; white-space: nowrap; color: var(--sm-money-on-brand); -webkit-text-stroke: 0.16em var(--color-ink); paint-order: stroke fill; }
.demo .hit .hv, .demo .hit .hl { display: block; text-align: center; }
/* what the figure is: small, in the same lettering and edge, under it */
.demo .hit .hl { font-size: max(0.36em, 12px); letter-spacing: 0; margin-top: 0.12em; }
/* the counter's: it pops on the figure's top edge, clear of the coin pile, and does not rise (the rail's last line is
   just above it); a phone leaves it out, as the flying hit lands on the counter there */
.demo .fig { position: relative; }
.demo .hit--cash { left: 0; top: 0; }
.demo .hit--cash b { translate: 0 -100%; font-size: calc(var(--fs) * 0.34); animation: d-cash 700ms linear both; }
@container (max-width: 560px) { .demo .hit--cash { display: none; } }
@keyframes d-cash { from { opacity: 0; transform: scale(0.3); animation-timing-function: cubic-bezier(0.2, 0, 0, 1); } 15% { opacity: 1; transform: scale(1.3); animation-timing-function: cubic-bezier(0.3, 0, 0.3, 1); } 27% { transform: scale(0.94); } 36% { transform: none; } 66% { opacity: 1; } to { opacity: 0; transform: none; } }

/* ---------- the title band: a solid ink band across the window's top (the shots frame what is under it), one short title
   a step, arriving as the step starts. After Activate and Swap (data-s 2 and 4) it says what the click did. ---------- */
.demo .tt { position: absolute; left: 0; right: 0; top: 0; z-index: 7; height: clamp(2rem, 6.4cqw, 3.25rem); background: var(--color-ink); pointer-events: none; }
.demo .tt p { position: absolute; inset: 0 auto 0 0; display: flex; align-items: center; margin: 0; padding-inline: var(--space-sm); font-family: var(--font-display); font-synthesis: none; font-stretch: 125%; font-weight: 800; font-size: clamp(0.95rem, 2.9cqw, 1.5rem); line-height: 1; letter-spacing: -0.01em; white-space: nowrap; color: var(--sm-on-brand); opacity: 0; visibility: hidden; translate: -0.4em 0; }
.demo .tt .bw { font-style: italic; color: var(--color-signal); }
/* the longest titles step down on a phone so they fit the band */
.demo .tt :is(.tt4, .tt5) { font-size: clamp(0.75rem, 3.9cqw, 1.5rem); }
.demo[data-c="1"] .tt1, .demo[data-c="2"] .tt2, .demo[data-c="3"]:not([data-s="2"]) .tt3, .demo[data-c="3"][data-s="2"] .tt3d,
.demo[data-c="4"]:not([data-s="4"]) .tt4, .demo[data-c="4"][data-s="4"] .tt4d, .demo[data-c="5"] .tt5 { opacity: 1; visibility: visible; translate: none; }
.demo .tt { --d-tt: 150ms; --d-tt-in: 240ms; }
.demo.live .tt p { transition: opacity var(--d-tt) ease-in, translate var(--d-tt) ease-in, visibility 0s var(--d-tt); }
.demo.live[data-c="1"] .tt1, .demo.live[data-c="2"] .tt2, .demo.live[data-c="3"]:not([data-s="2"]) .tt3, .demo.live[data-c="3"][data-s="2"] .tt3d,
.demo.live[data-c="4"]:not([data-s="4"]) .tt4, .demo.live[data-c="4"][data-s="4"] .tt4d, .demo.live[data-c="5"] .tt5 { transition: opacity var(--d-tt-in) var(--e-stop) var(--d-tt), translate var(--d-tt-in) var(--e-stop) var(--d-tt), visibility 0s var(--d-tt); }

/* ---------- the captured page ---------- */
.demo .scene { --img: url("./ct/page-h.webp"); position: relative; width: calc(var(--w) * 1px); height: calc(var(--h) * 1px); background: var(--color-ct-page); color: var(--color-ink); }
.demo .seg, .demo .band::before { background: var(--img) calc(var(--x, 0) * -1px) calc(var(--y) * -1px) / calc(var(--W) * 1px) auto no-repeat; }
.demo .seg { height: calc(var(--h) * 1px); }
.demo .col { width: calc(var(--w) * 1px); }
/* white under the stretched row: at some zoom levels the browser draws that row a little short */
.demo .band { position: relative; z-index: 1; height: calc(var(--h) * 1px); background: var(--color-ct-page); }
.demo .band::before { content: ""; position: absolute; inset: 0 0 auto; height: 1px; transform: scaleY(var(--h)); transform-origin: 0 0; }
.demo .lslot { position: absolute; top: var(--space-3xs); left: calc(var(--sx) * 1px); width: calc(var(--sw) * 1px); }
.demo .hero-slot { z-index: 2; }
.demo .hero-line { position: relative; }
/* which state of a line and of the pop-out shows. c = the line as it rests, o = the line with its pop-out open. */
.demo:is([data-s="0"], [data-s="1"]) .ls:not(.hero-line) .c0, .demo:is([data-s="2"], [data-s="3"]) .ls:not(.hero-line) .c1, .demo:is([data-s="4"], [data-s="5"], [data-s="6"]) .ls:not(.hero-line) .c2 { display: block; }
.demo[data-s="0"] .hero-line > .c0, .demo[data-s="1"] .hero-line > .o0, .demo:is([data-s="2"], [data-s="3"]) .hero-line > .o1, .demo:is([data-s="4"], [data-s="5"]) .hero-line > .o2, .demo[data-s="6"] .hero-line > .c2 { display: block; }
.demo[data-s="1"] .p0, .demo:is([data-s="2"], [data-s="3"]) .p1, .demo:is([data-s="4"], [data-s="5"]) .p2 { display: block; }
/* the pop-out opens from the line, left edges together, 4px under it and 320px wide, as popover.ts places it */
.demo .pops { position: absolute; left: 0; top: calc(100% + 4px); z-index: 5; width: 320px; }

/* ---------- the lens: the window dimmed with a flat ink scrim, one square-cornered hole round the thing that matters ----------
   demo.js cuts the hole out of its mask (in the window's pixels) and adds .lit. No blur and no gradient: the dimmed page
   stays readable as context, the thing in the hole stays exactly as sharp as the rest. It sits under the pointer. */
.demo .lens { position: absolute; inset: 0; z-index: 4; pointer-events: none; opacity: 0; background: var(--color-scrim);
  mask-image: linear-gradient(var(--color-ink) 0 0), linear-gradient(var(--color-ink) 0 0); mask-repeat: no-repeat; mask-composite: exclude; mask-position: 0 0, 50% 50%; mask-size: 100% 100%, 0 0; }
.demo.lit .lens { opacity: 1; }
.demo.deep .lens { background: var(--color-ink); }

/* ---------- the pointer, in the window's own pixels. x moves on the outer box and y on the inner one, each with
   its own easing, so its path bends ---------- */
.demo .cursor { position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none; transform: translateX(calc(var(--cx, 0) * 1px)); }
/* demo.js adds the pointer; it shows only while the piece plays, and not over the gold */
.demo:not(.live) .cursor, .demo:is([data-s="5"], [data-s="6"]) .cursor { visibility: hidden; }
.demo .cursor .arrow { display: block; transform: translateY(calc(var(--cy, 0) * 1px)); }
.demo .cursor svg { width: calc(var(--pu) * 30); height: calc(var(--pu) * 30); margin: calc(var(--pu) * -3) 0 0 calc(var(--pu) * -6); fill: var(--color-ink); stroke: var(--color-surface); stroke-width: 1.5; stroke-linejoin: round; transform-origin: 20% 10%; }
.demo .cursor .ring { position: absolute; left: calc(var(--pu) * -24); top: calc(var(--pu) * -24); width: calc(var(--pu) * 48); height: calc(var(--pu) * 48); border-radius: 50%; border: calc(var(--pu) * 3) solid var(--color-accent); background: var(--color-ring); opacity: 0; }


/* ---------- motion: only while the piece is playing (.live). A still has none. ---------- */
.demo.live .cam:not(.cut) { transition: transform var(--cam-d, 480ms) var(--e-stop); }
.demo.live .cursor { transition: transform var(--d-glide) cubic-bezier(0.45, 0, 0.25, 1); }
.demo.live .cursor .arrow { transition: transform var(--d-glide) cubic-bezier(0.3, 0.55, 0.3, 1); }
.demo .cursor.click .ring { animation: d-ring 520ms var(--e-land); }
.demo .cursor.click svg { animation: d-press 240ms var(--e-land); }
/* the lines arrive one after the other when the demo starts */
.demo.live .scene .lslot > .ls { transition: opacity var(--d-land) var(--e-stop), transform var(--d-land) var(--e-stop); }
.js .demo.pre .scene .lslot > .ls { opacity: 0; transform: translateY(8px); }   /* .pre is set by demo.js as it starts to play */
.demo.live .scene .lslot:nth-child(2) > .ls { transition-delay: var(--d-lag); }
.demo.live .scene .lslot:nth-child(3) > .ls { transition-delay: calc(var(--d-lag) * 2); }
.demo.live .scene .lslot:nth-child(4) > .ls { transition-delay: calc(var(--d-lag) * 3); }
.demo.live[data-s="1"] .p0 { transform-origin: 24px 0; animation: d-open 200ms var(--e-stop) both; }
.demo.flat .pops > .x { animation: none; }   /* demo.js, for the instant it measures the pop-out */
/* the lens dims in slowly and evenly, lifts faster, and its hole glides when it moves */
.demo.live .lens { transition-property: opacity, mask-position, mask-size; transition-duration: var(--d-lens-out), var(--d-glide), var(--d-glide); transition-timing-function: cubic-bezier(0.4, 0, 1, 1), var(--e-stop), var(--e-stop); }
.demo.live.lit .lens { transition-duration: var(--d-lens-in), var(--d-glide), var(--d-glide); transition-timing-function: cubic-bezier(0.45, 0, 0.55, 1), var(--e-stop), var(--e-stop); }
.demo.live .lens.snap { transition: none; }
.demo.live .step { transition: background-color var(--d-land) linear, color var(--d-land) linear; }
.demo.live .score { transition: opacity var(--d-land) linear; }
/* a payout lands: as the tens reel stops, the step's coin layer drops 24px onto the pile (a hard stop) and the pile
   gives once under it; the step's marker drops into its row the same way. At the swap's payout the pile turns gold and
   its three layers drop in, bottom first, and the amount takes one firm beat. No glow, no burst. */
.demo.live[data-l="1"] .pile .ly-0, .demo.live[data-l="2"] .pile .ly-1, .demo.live[data-l="3"] .pile .ly { transform-box: fill-box; animation: d-coin 230ms cubic-bezier(0.55, 0, 1, 0.45) both; }
.demo.live[data-l="3"] .pile .ly { animation-name: d-gold; }
.demo.live[data-l="3"] .pile .ly-1 { animation-delay: 90ms; transition-delay: 90ms; }
.demo.live[data-l="3"] .pile .ly-2 { animation-delay: 180ms; transition-delay: 180ms; }
.demo.live:is([data-l="1"], [data-l="3"]) .pile { transform-origin: 50% 100%; animation: d-give 220ms var(--e-stop) 230ms both; }
.demo.live[data-l="2"] .pile { transform-origin: 50% 100%; animation: d-give2 220ms var(--e-stop) 230ms both; }
.demo.live[data-l="3"] .pile { animation-delay: 410ms; }
.demo.live[data-l="3"] .fig { transform-origin: 0 70%; animation: d-beat 260ms var(--e-stop) 410ms both; }
.demo.live[data-l="1"] .step:nth-child(1) .mk, .demo.live[data-l="2"] .step:nth-child(3) .mk, .demo.live[data-l="3"] .step:nth-child(4) .mk, .demo.live[data-c="5"] .step:nth-child(5) .mk { animation: d-coin 230ms cubic-bezier(0.55, 0, 1, 0.45) both; }
/* the row's lines when they turn gold */
.demo.live[data-s="6"] .lslot .c2 { transform-origin: 0 50%; animation: d-land var(--d-land) var(--e-land) var(--d-lag) both; }
.demo.live[data-s="6"] .lslot:nth-child(2) .c2 { animation-delay: calc(var(--d-lag) * 2); }
.demo.live[data-s="6"] .lslot:nth-child(3) .c2 { animation-delay: calc(var(--d-lag) * 3); }
.demo.live[data-s="6"] .lslot:nth-child(4) .c2 { animation-delay: calc(var(--d-lag) * 4); }
@keyframes d-coin { from { transform: translateY(-24px); opacity: 0; } 35% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes d-gold { from { transform: translateY(-24px); opacity: 0; } 35% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes d-give { 40% { transform: scaleY(0.9); } to { transform: none; } }
@keyframes d-give2 { 40% { transform: scaleY(0.9); } to { transform: none; } }
@keyframes d-beat { 40% { transform: scale(1.06); } to { transform: none; } }
@keyframes d-land { from { transform: scale(0.82); opacity: 0; } 35% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes d-open { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes d-ring { from { opacity: 0.9; transform: scale(0.2); } to { opacity: 0; transform: scale(1.5); } }
@keyframes d-press { 40% { transform: scale(0.84); } }
@keyframes d-track { from { transform: scaleY(0); } to { transform: none; } }

/* ---------- under the window: the note, Pause and Replay ---------- */
.demo .below { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-xs) var(--space-lg); margin-top: var(--space-xs); }
.demo figcaption { padding-top: var(--space-sm); font-size: var(--text-xs); line-height: 1.5; color: var(--color-accent-soft); max-width: 96ch; }
.demo .ctls { display: flex; flex: none; }
.no-js .demo .ctls { display: none; }
.cut .demo .ctls { display: none; }   /* ?cut: the page as a video frame, where Pause and Replay would be dead controls */
.demo .ctl { min-height: 44px; padding: var(--space-sm) 0 var(--space-xs) var(--space-md); font: inherit; font-size: var(--text-sm); font-weight: 700; line-height: 1.2; color: var(--color-accent-soft); background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.18em; -webkit-tap-highlight-color: transparent; }
.demo .ctl:hover { color: var(--color-accent-ink); }
.demo .ctl:disabled { opacity: 0.5; cursor: default; }
/* Pause shows while the piece plays (it reads Play while held); Replay always */
.demo .pause .on-held, .demo .pause[aria-pressed="true"] .on-run { display: none; }
.demo .pause[aria-pressed="true"] .on-held { display: inline; }
.demo:not(.live) .pause, .demo.live .again { display: none; }

/* ---------- sizes ---------- */
/* the whole block in the first screen: no wider than the viewport's height allows. Beside the rail, demo.js makes the
   sheet as tall as the rail (--vh), so their bottom edges meet. */
@media (min-width: 48.01rem) { .demo { max-width: max(44rem, calc((100svh - 17rem) * 1.95)); } }
/* a short window beside the rail (a 768px-tall laptop): the lines sit closer, so the note stays in the first screen */
@media (min-width: 48.01rem) and (max-height: 800px) {
  .demo .step { padding-block: var(--space-2xs); }
  .demo .track { top: calc(var(--space-2xs) + 1.4 * var(--rs)); bottom: calc(var(--space-2xs) * -1 + 2px); }
}
/* a narrower block: the rail under the sheet, the story beside the counter */
@container (max-width: 860px) {
  .demo .stage { --vh: 430; --fs: clamp(2.75rem, 8cqw, 4rem); --rs: clamp(1rem, 2.4cqw, 1.2rem); grid-template-columns: minmax(0, 1fr); grid-template-areas: "win" "rail"; }
  .demo .rail { grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: var(--space-lg); }
  .demo .score { margin-top: 0; padding: 0 0 var(--space-s10); }
}
/* a phone: the compact rail. One band under a tall sheet: the line on screen (the five share one place, so the band
   never jumps), and the counter under it in one row. No progress bar. */
@container (max-width: 560px) {
  .demo .stage { --vh: 840; --fs: clamp(2.25rem, 11cqw, 2.75rem); --rs: 1rem; gap: var(--space-xs); }
  .demo .rail { grid-template-columns: minmax(0, 1fr); gap: 0; padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-xs); border-radius: var(--radius-key); background: var(--color-accent-deep); }
  .demo .story { grid-template-areas: "one"; }
  .demo .step { grid-area: one; visibility: hidden; background: none; padding: 0 0 0 var(--space-3xs); color: var(--color-accent-ink); }
  .demo[data-c="0"] .step:nth-child(1), .demo[data-c="1"] .step:nth-child(1), .demo[data-c="2"] .step:nth-child(2), .demo[data-c="3"] .step:nth-child(3), .demo[data-c="4"] .step:nth-child(4), .demo[data-c="5"] .step:nth-child(5) { visibility: visible; background: none; }
  .demo .track { display: none; }
  .demo .score { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); margin-top: var(--space-xs); padding: 0 0 0 var(--space-3xs); }
  .demo .tally { gap: var(--space-sm); }
  .demo .unit { margin: 0; font-size: var(--text-xs); text-align: right; }
  .demo .below { gap: var(--space-sm); }
  .demo figcaption { padding-top: var(--space-xs); }
}
@media (prefers-reduced-motion: reduce) {
  .demo .ctls { display: none; }   /* nothing plays: the block holds the end frame, and each step line shows its step as a still */
}
/* ========== demo: end ========== */
