# Crowd hero

> A landing-page hero over a walking crowd, three people in it picked out in colour, tagged and linked as they walk.

A light hero for a product about people finding each other. Under the navigation, a wide band of small grey people walks across a ground plane, sharp in the middle and blurred near and far, its edges fading into the page. Three of them are lit in green, red and blue, each with a tracking box, a name tag and a role, tied together by thin lines that follow them as they walk; every few seconds one highlight moves on to someone else. Click a person to pick them out, or press Show others. Below, the headline, a short paragraph and two buttons.

A React component by Bruno Delorence: https://brunodelorence.com/components/crowd-hero. MIT License, Copyright (c) 2026 Bruno Delorence.

Category: Motion.

## Anatomy

1. **Navigation**: The mark at the left, the links centred, Sign in at the right, 4.7 % of the hero’s width down to their middle. The links hide under 640 px.
2. **Crowd band**: The full-width canvas, 26.7 % of the hero’s width tall (at least 250 px). Its sides and bottom fade into the page.
3. **Tracking box**: A 1 px box in the slot’s colour around a highlighted person, moved with them every frame.
4. **Name tag**: The person’s name in small monospaced capitals, white on the slot’s colour, sitting on the box’s top edge.
5. **Role**: Under the box, in the slot’s colour: what they do and at what stage.
6. **Crowd controls**: Pause or play the walk, and Show others: the keyboard’s way to move the highlights.
7. **Headline**: An h2 of 4.4 % of the hero’s width, regular weight, two lines on a wide hero.
8. **Paragraph**: The promise in two or three lines, in a column 28.5 % of the hero wide.
9. **Primary button**: The one action that matters, dark and round.
10. **Secondary button**: The lighter way in, beside it.

## When to use

- The first screen of a product about people finding each other: founders and backers, mentors, hiring, a community.
- A hero that should say “someone here is for you” without a photo: the crowd is drawn, so it never needs licences or model releases.
- A landing page with room for a wide band: from about 360 px up, the band always takes the full width.

## When not to use

- Pages that must stay still or light: the crowd is a canvas animating every frame while on screen. Use a static picture.
- A real directory of people. The highlighted people are illustrations with invented names; show real profiles in a list or cards.
- More than one per page, or below the fold: it is a first-screen moment, and two crowds compete.
- Products with nothing to do with people meeting: the picture would promise something the page doesn’t.

### The crowd

- **Drawn, not filmed**: every person is a procedural silhouette with a walk cycle, so the picture is yours and costs a few kilobytes.
- **Depth of field**: sharp in a band across the middle, blurred near and far, so the eye goes to the highlighted people.
- **The same crowd every time** for a given `seed`, so screenshots and docs stay stable.
- **A wider hero shows more people, not bigger ones**: every size follows the band’s height.

### Motion and pausing

- **It walks only while on screen** and the tab is visible; scrolled away, it stops drawing.
- **A pause button** stops it at any time; the walk is more than five seconds of motion beside text.
- **With reduced motion** the crowd starts paused, and the highlights move only on Show others or a click, at once; play still starts the walk, as the reader’s choice.
- **`rotate={0}`** keeps the highlights on the same people until the reader moves them.

## Do’s and don’ts

- **Do**: Give the highlights names and roles that tell the story: who they are, and why they matter to the reader.
- **Don’t**: Label them generically (User 1, Member). The tags are the point of the picture; empty ones make it a crowd and nothing more.
- **Do**: Keep the headline to two lines on a wide hero, the paragraph to three.
- **Don’t**: Write a headline that runs to four lines: it pushes the buttons down and fights the crowd for attention.

## Content

The words are the headline, the paragraph, the two buttons, the navigation, and the names and roles on the tags.

- **A headline about the reader**, in sentence case with a full stop: `Your first believer is already walking past you.`
- **Buttons that say what happens**: `Get introduced`, `Browse founders`; no “Learn more”.
- **Tags as a name and an initial**, `Noor A.`, and a role as `what · stage`: `Investor · Series A`, `Founder · Health`.
- **Invented people**, unless they agreed to be on the page.

## Installation

Install it with the shadcn CLI, into components/crowd-hero of any React project:

```sh
npx shadcn@latest add https://brunodelorence.com/r/crowd-hero.json
```

Or add the registry to components.json once, as a namespace that coding agents and the shadcn MCP server search by name:

```json
{
  "registries": {
    "@brunodelorence": "https://brunodelorence.com/r/{name}.json"
  }
}
```

```sh
npx shadcn@latest add @brunodelorence/crowd-hero
```

Or copy all the source files below into one folder of your project. Either way it needs React 19.2 and a bundler with CSS Modules (Next.js, Vite).

It has a dark colour scheme. Its colours are CSS light-dark() pairs, kept inside @supports so that builds which rewrite light-dark() for older browsers leave them alone: it follows your page’s color-scheme (light unless the page sets one) or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.

## Usage

```tsx
import { CrowdHero } from './crowd-hero';

export function Home() {
  return (
    <CrowdHero
      headline="Your first believer is already walking past you."
      primaryLabel="Get introduced"
      onPrimary={() => location.assign('/intro')}
      secondaryLabel="Browse founders"
      onSecondary={() => location.assign('/founders')}
      autoplay={false}
    />
  );
}
```

## States

- **Walking**: The default: the crowd walks, and every 6 s one highlight moves on to someone else, the three a third of that apart.
- **Paused**: After the pause button, or with `paused`: the crowd stands where it was and the button turns to play. Show others and a click still work.
- **Dark**: With `colorScheme="dark"`: a near-black field and a light grey crowd; the three colours stay.
- **Narrow**: At 390 px the band keeps the full width and 250 px of height, the links go, and the text stacks under it.

## How it works

- The crowd is one canvas. Each person is a procedural side-view silhouette: a round head, a torso leaning forward, legs and arms as round-capped strokes in two segments; the legs swing ±0.42 rad on opposite phases with the knee folding on the forward swing, the arms ±0.36 rad against them, and the body bobs 1.2 % of its height twice a stride. A stride is 12 frames plus a standing pose.
- People walk 1–1.5 m/s on a ground plane, mostly across the view (within ±0.55 rad of it), at depths 3.5 to 10.4 m from a camera about 11 m up: far ones are drawn 2.3 times smaller, higher in the band and slower across it. Off one side they come back on the other; at the near and far ends they turn. Each frame they are sorted far to near.
- Depth of field: the focal plane is at 6.3 m, and the blur grows with the distance from it in 1/z, like a lens’s circle of confusion, up to about 7 px at the near edge. Nothing is blurred while it plays: the walk is pre-drawn into 14 sprite sheets, one per depth band, each at its size and blur (the canvas blur filter, or a ring of faint copies where there is none).
- Every size follows the band’s height (the focal length is 0.473 of it), so a wider hero shows more people, about 0.22 per square metre of visible ground, not bigger ones. The band is 26.7 % of the hero’s width tall, at least 250 px, and fades out at the sides (13 %) and the bottom with a CSS mask.
- Three slots, green, red and blue, each hold a person near focus and in the middle of the band, at least a sixth of its width from the others. The colour is a gradient sprite (green to amber, red through orange to violet, blue to pink) cross-faded over 600 ms; every 6 s one slot moves on, the three a third of that apart, or sooner if their person drifts to the edge. Thin lines join the three and each to two people in grey.
- The tags are HTML over the canvas, moved every frame to their person’s box: the name in 9–11 px monospaced capitals on the slot’s colour, the role under the box. They fade in with @starting-style and out over 600 ms.
- Hovering a person boxes them; clicking or tapping takes the highlight that has been up longest to them. Show others moves all three. The walk stops off screen, in a hidden tab, and on the pause button; under reduced motion it starts paused, and play starts it only as the reader’s choice.
- The layout is in container query units, measured on a 1440 px hero: 6 % side margins, a 4.4 % headline beside a 28.5 % column for the paragraph and the buttons. Under 640 px the links hide and the text stacks.
- While on screen and untouched, a demo pointer picks someone out of the crowd and then presses Show others, in a loop; any input from the reader stops it.

## API reference

- **headline** (`ReactNode`): The headline, an h2.
- **lede** (`ReactNode`): The paragraph beside the headline.
- **primaryLabel** (`string`, default `'Get introduced'`): The dark button’s words.
- **onPrimary** (`() => void`): What the dark button does.
- **secondaryLabel** (`string`, default `'Browse founders'`): The light button’s words.
- **onSecondary** (`() => void`): What the light button does.
- **links** (`string[]`): The navigation’s links, by name; hidden on a hero under 640 px.
- **profiles** (`{ name: string; role: string }[]`): Who the highlighted people are: each new highlight takes the next one.
- **rotate** (`number`, default `6`): Seconds each highlight stays on one person before moving on; 0 keeps them until the reader moves them.
- **paused** (`boolean`, default `false`): Starts with the crowd stopped, as a still for docs and screenshots; the play button starts it.
- **seed** (`number`, default `7`): The crowd’s arrangement: the same seed draws the same crowd.
- **onHighlight** (`(profiles: Profile[]) => void`): Called with the highlighted profiles whenever one changes.
- **autoplay** (`boolean`, default `true`): While on screen and untouched, a demo pointer picks people out of the crowd; any input from the reader stops it.
- **colorScheme** (`'light' | 'dark' | 'system'`): Light or dark colours, or the reader’s; without it, the page’s color-scheme.
- **className** (`string`): Classes for the hero’s root.

## Accessibility

### Keyboard

- Tab reaches the links, Sign in, the pause button, Show others and the two buttons, in that order.
- Show others does with the keyboard what a click on a person does with the pointer: it moves the highlights.
- Every control has a visible focus ring.

### Screen readers

- The canvas is an image with a short description of the scene; the tags over it are hidden from screen readers.
- A visually hidden line lists the three people highlighted now; Show others and a click announce the new ones in a polite live region.
- The pause button is named by what it does: “Pause the crowd”, then “Play the crowd”.

### Motion

The walk can be paused at any time (WCAG 2.2.2), stops off screen and in a hidden tab, and starts paused under reduced motion. Nothing flashes: highlights fade over 600 ms.

### Colour and contrast

The tags are white on green, red and blue fills of 4.5 : 1 or more, and the roles are 4.5 : 1 on the page in both schemes (WCAG 1.4.3). The three colours tell the highlights apart, but each also has its name, so nothing rests on colour alone (1.4.1).

### In this build

- The crowd is a canvas with role="img" and a short description; the tags over it are hidden from screen readers, and a visually hidden line names the three people highlighted now.
- Show others is the keyboard’s way to move the highlights; it and a click announce the new people in a polite live region.
- A pause button stops the walk at any time (WCAG 2.2.2); it also stops off screen and in a hidden tab, and starts paused under reduced motion, where highlights change at once.
- Every control is a real button with a visible focus ring; the tags’ white names are 4.5 : 1 or more on their fills, and the roles 4.5 : 1 on the page in both schemes.

## Source

### crowd-hero/crowd-hero.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import {
  useEffect,
  useEffectEvent,
  useRef,
  useState,
  type MouseEvent as ReactMouseEvent,
  type PointerEvent as ReactPointerEvent,
  type ReactNode,
} from 'react';
import { Crowd, SLOT_COUNT } from './crowd';
import { DemoPointer, runDemo, type Point } from './demo-pointer';
import { Mark, Pause, Play, Shuffle } from './glyphs';
import { useAutoplay } from './use-autoplay';
import styles from './crowd-hero.module.css';

/*
 * Crowd hero: a landing-page hero whose picture is a crowd. A wide band of small grey people walks
 * across a ground plane under the navigation, sharp in the middle and blurred near and far, its
 * edges fading into the page. Three of them are picked out in colour, green, red and blue, each
 * with a tracking box, a name tag and a role, and tied together by thin lines that follow them as
 * they walk. Every few seconds one of the three highlights moves on to someone else. Below, the
 * headline, a short paragraph and two buttons.
 *
 * - The crowd is one canvas, drawn by crowd.ts from sprite sheets figure.ts paints: a procedural
 *   walk cycle, one sheet per depth band at its size and blur. The tags are HTML over it, moved
 *   each frame to their person's box, so their words stay crisp and selectable by tests.
 * - Hovering a person draws a box around them; clicking or tapping one moves the oldest highlight
 *   to them. Show others moves all three at once; the pause button stops the crowd (the walk is
 *   more than five seconds of motion beside text, WCAG 2.2.2).
 * - The crowd only walks while on screen and the tab is visible; under reduced motion it stands
 *   still (paused: play starts it, as the reader's choice), and the highlights change only when
 *   asked, without the fade.
 * - While on screen and untouched, a demo pointer picks someone out of the crowd, then presses
 *   Show others. The reader's first input stops it for good.
 */

export type Profile = { name: string; role: string };

/** Who the highlights are, in the order the tags take them. */
export const PROFILES: Profile[] = [
  { name: 'Ilse V.', role: 'Angel · Pre-seed' },
  { name: 'Tomás R.', role: 'Founder · Climate' },
  { name: 'Noor A.', role: 'Investor · Series A' },
  { name: 'Kenji O.', role: 'Founder · Health' },
  { name: 'Maëlle D.', role: 'Investor · Seed' },
  { name: 'Ravi P.', role: 'Founder · Fintech' },
  { name: 'Sade K.', role: 'Angel · Hardware' },
  { name: 'Lucas M.', role: 'Founder · Edtech' },
  { name: 'Yara S.', role: 'Investor · Growth' },
];

const LINKS = ['Founders', 'Backers', 'Circles', 'Journal'];
const SLOT_NAMES = ['green', 'red', 'blue'] as const;

type Tag = { key: number; slot: number; person: number; profile: Profile; out: boolean };
type By = 'start' | 'auto' | 'reader' | 'demo';

export function CrowdHero({
  headline = 'Your first believer is already walking past you.',
  lede = 'Most of the people who would back you never hear your name. We map the quiet links between founders, angels and funds, so the right one slows down, turns around and asks to hear more.',
  primaryLabel = 'Get introduced',
  secondaryLabel = 'Browse founders',
  onPrimary,
  onSecondary,
  links = LINKS,
  profiles = PROFILES,
  rotate = 6,
  paused = false,
  seed = 7,
  onHighlight,
  autoplay = true,
  colorScheme,
  className = '',
}: {
  /** The headline, an h2. */
  headline?: ReactNode;
  /** The paragraph beside it. */
  lede?: ReactNode;
  /** The dark button's words, and what it does. */
  primaryLabel?: string;
  onPrimary?: () => void;
  /** The light button's words, and what it does. */
  secondaryLabel?: string;
  onSecondary?: () => void;
  /** The navigation's links, by name; hidden on a narrow stage. */
  links?: string[];
  /** Who the highlighted people are: each new highlight takes the next one. */
  profiles?: Profile[];
  /** Seconds each highlight stays on one person before moving on; 0 keeps them until asked. */
  rotate?: number;
  /** Starts with the crowd stopped, as a still for docs and screenshots; play starts it. */
  paused?: boolean;
  /** The crowd's arrangement: the same seed draws the same crowd. */
  seed?: number;
  /** Called with the three highlighted profiles whenever one changes. */
  onHighlight?: (profiles: Profile[]) => void;
  /** While on screen and untouched, a demo pointer picks people out of the crowd. */
  autoplay?: boolean;
  /** Light or dark colours, or the reader's ('system'); without it, the page's color-scheme. */
  colorScheme?: 'light' | 'dark' | 'system';
  className?: string;
}) {
  const { ref: root, playing, take } = useAutoplay<HTMLDivElement>();
  const band = useRef<HTMLDivElement>(null);
  const canvas = useRef<HTMLCanvasElement>(null);
  const shuffle = useRef<HTMLButtonElement>(null);
  const pointer = useRef<HTMLSpanElement>(null);
  const crowd = useRef<Crowd | null>(null);
  const tagElements = useRef(new Map<number, HTMLDivElement>());
  const active = useRef<(Profile | null)[]>(Array(SLOT_COUNT).fill(null));
  const tagKey = useRef(0);
  const nextProfile = useRef(0);
  const runningRef = useRef(false);
  /** Off screen nothing is drawn: a page of stills only paints the ones in view. */
  const shownRef = useRef(false);
  const timers = useRef(new Set<number>());

  const [tags, setTags] = useState<Tag[]>([]);
  const [stopped, setStopped] = useState(paused);
  const [onScreen, setOnScreen] = useState(false);
  const [hovering, setHovering] = useState(false);
  const [message, setMessage] = useState('');
  const running = onScreen && !stopped;

  /** Repeats are made to differ, so screen readers announce them again. */
  const announce = (text: string) => setMessage((now) => (now === text ? `${text} ` : text));

  /** Moves a tag to its person's box. */
  const place = (element: HTMLDivElement) => {
    const engine = crowd.current;
    if (!engine) return;
    const box = engine.box(Number(element.dataset.person));
    element.style.transform = `translate(${box.x.toFixed(1)}px, ${box.y.toFixed(1)}px)`;
    element.style.width = `${box.w.toFixed(1)}px`;
    element.style.height = `${box.h.toFixed(1)}px`;
  };

  const draw = () => {
    if (!shownRef.current) return;
    const engine = crowd.current;
    const ctx = canvas.current?.getContext('2d');
    if (!engine || !ctx) return;
    engine.draw(ctx);
    tagElements.current.forEach(place);
  };

  /** A frame now, for a crowd that is standing still. */
  const redraw = () => {
    if (!runningRef.current) requestAnimationFrame(draw);
  };

  /** Moves slot `slot` to person `index` (−1: one the crowd picks); returns the new profile. */
  const hop = (slot: number, index: number, by: By): Profile | null => {
    const engine = crowd.current;
    if (!engine || !profiles.length) return null;
    const before = engine.slots[slot].person;
    // A highlight the reader chose stays longer; the first three leave one after another.
    const hold =
      rotate <= 0
        ? Infinity
        : by === 'start'
          ? rotate * ((slot + 1) / SLOT_COUNT) + 0.8
          : by === 'auto'
            ? rotate
            : rotate * 1.6;
    const person = engine.hop(slot, index, hold, !runningRef.current);
    if (person < 0 || person === before) return null;
    const profile = profiles[nextProfile.current % profiles.length];
    nextProfile.current += 1;
    tagKey.current += 1;
    const key = tagKey.current;
    setTags((now) => [
      ...now.map((tag) =>
        !tag.out && (tag.slot === slot || tag.person === person) ? { ...tag, out: true } : tag,
      ),
      { key, slot, person, profile, out: false },
    ]);
    const timer = window.setTimeout(() => {
      timers.current.delete(timer);
      setTags((now) => now.filter((tag) => !tag.out));
    }, 700);
    timers.current.add(timer);
    active.current = active.current.map((now, index) => (index === slot ? profile : now));
    // A person handed over from another slot leaves that slot empty.
    engine.slots.forEach((other, index) => {
      if (other.person < 0) active.current[index] = null;
    });
    onHighlight?.(active.current.filter((now): now is Profile => now !== null));
    redraw();
    return profile;
  };

  const hopFromEffect = useEffectEvent(hop);
  const drawFromEffect = useEffectEvent(draw);

  // The engine, its canvas size, and the theme's grey, kept in step with the band and the page.
  useEffect(() => {
    const element = band.current;
    const surface = canvas.current;
    const stage = root.current;
    if (!element || !surface || !stage) return;
    const engine = new Crowd(seed);
    crowd.current = engine;
    const size = () => {
      const dpr = Math.min(2, window.devicePixelRatio || 1);
      const width = element.clientWidth;
      const height = element.clientHeight;
      surface.width = Math.round(width * dpr);
      surface.height = Math.round(height * dpr);
      engine.resize(width, height, dpr);
    };
    const ink = () => engine.setInk(getComputedStyle(surface).color);
    size();
    ink();
    for (let slot = 0; slot < SLOT_COUNT; slot += 1) hopFromEffect(slot, -1, 'start');
    drawFromEffect();

    const observer = new ResizeObserver(() => {
      size();
      drawFromEffect();
    });
    observer.observe(element);
    // A theme toggle on the page or on the component, or the system's scheme, changes the grey.
    const retheme = () => {
      if (ink() && !runningRef.current) drawFromEffect();
    };
    const mutations = new MutationObserver(retheme);
    for (const target of [document.documentElement, document.body, stage])
      mutations.observe(target, { attributes: true });
    const scheme = window.matchMedia('(prefers-color-scheme: dark)');
    scheme.addEventListener('change', retheme);
    const pending = timers.current;
    return () => {
      observer.disconnect();
      mutations.disconnect();
      scheme.removeEventListener('change', retheme);
      pending.forEach((timer) => window.clearTimeout(timer));
      pending.clear();
      crowd.current = null;
      setTags([]);
    };
  }, [seed, root]);

  // On screen, the tab visible, and the reader's motion preference.
  useEffect(() => {
    const element = root.current;
    if (!element) return;
    let visible = false;
    const update = () => setOnScreen(visible && !document.hidden);
    const observer = new IntersectionObserver(([entry]) => {
      visible = entry.isIntersecting;
      shownRef.current = visible;
      update();
      if (visible) drawFromEffect();
    });
    observer.observe(element);
    document.addEventListener('visibilitychange', update);
    const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
    // Reduced motion starts the crowd stopped; play still starts it, as the reader's choice.
    const readMotion = () => {
      if (motion.matches) setStopped(true);
    };
    readMotion();
    motion.addEventListener('change', readMotion);
    return () => {
      observer.disconnect();
      document.removeEventListener('visibilitychange', update);
      motion.removeEventListener('change', readMotion);
    };
  }, [root]);

  // The walk: one step and one frame per animation frame, while it runs.
  useEffect(() => {
    runningRef.current = running;
    const engine = crowd.current;
    const surface = canvas.current;
    if (!running || !engine || !surface) return;
    let last = performance.now();
    let frames = 0;
    let raf = 0;
    const tick = (now: number) => {
      // A long gap (a dropped frame, a tab coming back) is taken as one short step.
      engine.step(Math.min(0.05, (now - last) / 1000));
      last = now;
      for (const slot of engine.due()) hopFromEffect(slot, -1, 'auto');
      frames += 1;
      if (frames % 30 === 0) engine.setInk(getComputedStyle(surface).color);
      drawFromEffect();
      raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [running]);

  /** A pointer's place in the band's own px (the lab may draw the stage scaled). */
  const inBand = (event: { clientX: number; clientY: number }): Point | null => {
    const element = band.current;
    if (!element) return null;
    const rect = element.getBoundingClientRect();
    const scale = rect.width / element.clientWidth || 1;
    return { x: (event.clientX - rect.left) / scale, y: (event.clientY - rect.top) / scale };
  };

  const onBandMove = (event: ReactPointerEvent) => {
    const engine = crowd.current;
    const at = inBand(event);
    if (!engine || !at || event.pointerType === 'touch') return;
    const index = engine.hit(at.x, at.y);
    if (index === engine.hovered) return;
    engine.hovered = index;
    setHovering(index >= 0);
    redraw();
  };
  const onBandLeave = () => {
    const engine = crowd.current;
    if (!engine || engine.hovered < 0) return;
    engine.hovered = -1;
    setHovering(false);
    redraw();
  };

  /** The person clicked takes the highlight that has been up longest. */
  const choose = (index: number, by: By) => {
    const engine = crowd.current;
    if (!engine) return;
    const lit = engine.slots.findIndex((slot) => slot.person === index);
    if (lit >= 0) {
      engine.hop(lit, index, rotate > 0 ? rotate * 1.6 : Infinity, true);
      return;
    }
    let oldest = 0;
    engine.slots.forEach((slot, i) => {
      if (slot.until < engine.slots[oldest].until) oldest = i;
    });
    const profile = hop(oldest, index, by);
    if (profile && by === 'reader') announce(`${profile.name}, ${profile.role}, highlighted`);
  };

  const onBandClick = (event: ReactMouseEvent) => {
    const engine = crowd.current;
    const at = inBand(event);
    if (!engine || !at) return;
    const index = engine.hit(at.x, at.y);
    if (index >= 0) choose(index, 'reader');
  };

  const cycle = (by: By) => {
    const chosen: Profile[] = [];
    for (let slot = 0; slot < SLOT_COUNT; slot += 1) {
      const profile = hop(slot, -1, by);
      if (profile) chosen.push(profile);
    }
    if (by === 'reader' && chosen.length)
      announce(
        `Now highlighted: ${chosen.map((profile) => `${profile.name}, ${profile.role}`).join('; ')}`,
      );
  };

  // The demo: the pointer picks someone out of the crowd, then asks for three others.
  const demoAct = useEffectEvent(
    (act: { pick: number } | { hover: number } | { cycle: true } | { leave: true }) => {
      const engine = crowd.current;
      if (!engine) return;
      if ('pick' in act) choose(act.pick, 'demo');
      else if ('cycle' in act) cycle('demo');
      else {
        engine.hovered = 'hover' in act ? act.hover : -1;
        redraw();
      }
    },
  );
  const demoPick = useEffectEvent(() => crowd.current?.pick() ?? -1);
  const demoBox = useEffectEvent((index: number, ahead: number) =>
    crowd.current?.box(index, ahead),
  );
  const demo = autoplay && !paused && playing;
  useEffect(() => {
    const stage = root.current;
    const arrow = pointer.current;
    const area = band.current;
    if (!demo || !stage || !arrow || !area) return;
    const stop = runDemo(stage, arrow, async ({ wait, glide, glyph }) => {
      /** A point in the band's px, or an element's middle, in the stage's px. */
      const frame = () => {
        const rect = stage.getBoundingClientRect();
        return { rect, scale: rect.width / stage.offsetWidth || 1 };
      };
      const fromBand = (x: number, y: number): Point => {
        const { rect, scale } = frame();
        const inner = area.getBoundingClientRect();
        return { x: (inner.left - rect.left) / scale + x, y: (inner.top - rect.top) / scale + y };
      };
      const middleOf = (element: Element): Point => {
        const { rect, scale } = frame();
        const box = element.getBoundingClientRect();
        return {
          x: (box.left + box.width / 2 - rect.left) / scale,
          y: (box.top + box.height / 2 - rect.top) / scale,
        };
      };
      await glide(fromBand(area.clientWidth * 0.62, area.clientHeight * 1.15), 700);
      for (;;) {
        await wait(1500);
        const person = demoPick();
        // Aimed at where they will be when the pointer gets there.
        const box = person >= 0 ? demoBox(person, 0.9) : undefined;
        if (box) {
          await glide(fromBand(box.x + box.w / 2, box.y + box.h * 0.45), 900);
          glyph('hand');
          demoAct({ hover: person });
          await wait(280);
          demoAct({ pick: person });
          demoAct({ leave: true });
          await wait(700);
          glyph('arrow');
          await glide(fromBand(area.clientWidth * 0.7, area.clientHeight * 1.12), 800);
          await wait(2600);
        }
        const button = shuffle.current;
        if (button) {
          await glide(middleOf(button), 900);
          glyph('hand');
          await wait(300);
          demoAct({ cycle: true });
          await wait(700);
          glyph('arrow');
          await glide(fromBand(area.clientWidth * 0.4, area.clientHeight * 1.2), 900);
          await wait(3400);
        }
      }
    });
    return () => {
      stop();
      demoAct({ leave: true });
    };
  }, [demo, root]);

  const current = tags.filter((tag) => !tag.out);

  return (
    <div
      ref={root}
      className={`${styles.root} ${className}`}
      data-part="hero"
      data-color-scheme={colorScheme}
      onPointerDownCapture={take}
      onKeyDownCapture={take}
      onPointerMove={(event) => {
        if (event.pointerType !== 'touch') take();
      }}
    >
      <header className={styles.nav} data-part="nav">
        <span className={styles.mark} data-part="mark">
          <Mark className={styles.markGlyph} />
        </span>
        {/* Buttons, not links: the hero is a specimen, with nowhere of its own to go. */}
        <nav className={styles.links} aria-label="Main">
          {links.map((link) => (
            <button key={link} type="button" className={styles.link}>
              {link}
            </button>
          ))}
        </nav>
        <button type="button" className={styles.signIn}>
          Sign in
        </button>
      </header>

      <div className={styles.band} data-part="crowd">
        {/* The pointer's way into the crowd; the keyboard's is Show others, below. */}
        {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
        <div
          ref={band}
          className={styles.field}
          data-hovering={hovering}
          onPointerMove={onBandMove}
          onPointerLeave={onBandLeave}
          onClick={onBandClick}
        >
          <canvas
            ref={canvas}
            className={styles.canvas}
            role="img"
            aria-label="A crowd of people walking. Three of them are highlighted in colour, with name tags, and linked by thin lines."
          />
          <div className={styles.tracks} aria-hidden="true">
            {tags.map((tag) => (
              <div
                key={tag.key}
                ref={(element) => {
                  if (!element) return;
                  tagElements.current.set(tag.key, element);
                  place(element);
                  return () => {
                    tagElements.current.delete(tag.key);
                  };
                }}
                className={styles.tracker}
                data-part="tracker"
                data-slot={SLOT_NAMES[tag.slot]}
                data-out={tag.out}
                data-person={tag.person}
              >
                <span className={styles.name} data-part="tag">
                  {tag.profile.name}
                </span>
                <span className={styles.role} data-part="role">
                  {tag.profile.role}
                </span>
              </div>
            ))}
          </div>
        </div>
        <div className={styles.controls} data-part="controls">
          <button
            type="button"
            className={styles.control}
            aria-label={stopped ? 'Play the crowd' : 'Pause the crowd'}
            data-part="pause"
            onClick={() => setStopped((now) => !now)}
          >
            {stopped ? <Play className={styles.glyph} /> : <Pause className={styles.glyph} />}
          </button>
          <button
            ref={shuffle}
            type="button"
            className={`${styles.control} ${styles.shuffle}`}
            data-part="shuffle"
            onClick={() => cycle('reader')}
          >
            <Shuffle className={styles.glyph} />
            Show others
          </button>
        </div>
        <p className={styles.hidden}>
          {current.length
            ? `Highlighted: ${current.map((tag) => `${tag.profile.name}, ${tag.profile.role}`).join('; ')}.`
            : ''}
        </p>
      </div>

      <div className={styles.copy} data-part="copy">
        <h2 className={styles.headline} data-part="headline">
          {headline}
        </h2>
        <div className={styles.aside}>
          <p className={styles.lede} data-part="lede">
            {lede}
          </p>
          <div className={styles.actions}>
            <button
              type="button"
              className={styles.primary}
              data-part="primary"
              onClick={onPrimary}
            >
              {primaryLabel}
            </button>
            <button
              type="button"
              className={styles.secondary}
              data-part="secondary"
              onClick={onSecondary}
            >
              {secondaryLabel}
            </button>
          </div>
        </div>
      </div>

      <p className={styles.hidden} aria-live="polite">
        {message}
      </p>
      <div className={styles.pointerLayer} aria-hidden="true">
        <DemoPointer
          ref={pointer}
          className={styles.pointer}
          arrowClass={styles.arrow}
          handClass={styles.hand}
        />
      </div>
    </div>
  );
}
```

### crowd-hero/crowd-hero.module.css

```css
/* Crowd hero (crowd-hero.tsx): a light landing-page hero. The navigation on top, a full-width band
   of a walking crowd under it, and the headline with its paragraph and buttons below.

   Sizes. The hero scales with its own width (container query units, cqi: 1cqi is 1% of it),
   measured on a 1440 px-wide hero: 6cqi side margins (86 px), the navigation 4.7cqi down to its
   middle, the crowd band 26.7cqi tall (385 px), the headline 4.4cqi (63 px) with a 28.5cqi column
   beside it for the paragraph and the buttons. Under 640 px the links go and the text stacks;
   the band keeps the full width and at least 250 px of height.

   Colours are the tokens below, light-dark(light, dark) where the two differ: the component takes
   the color-scheme it inherits from the page, or the one its colorScheme prop sets. The canvas
   reads its grey from --crowd through its own `color`. */

.root {
  --page: light-dark(#f3f3f3, #0b0b0c);
  /* The pale light the crowd stands in. */
  --glow: light-dark(#fbfbfb, #161618);
  --ink: light-dark(#141415, #f1f1f2);
  --muted: light-dark(#5e5e63, #a3a3a9);
  --crowd: light-dark(#3c3c40, #c6c6cc);
  --soft: light-dark(#e3e3e5, #232326);
  --soft-hover: light-dark(#d9d9dc, #2d2d31);
  --primary: light-dark(#121213, #f1f1f2);
  --primary-hover: light-dark(#2a2a2d, #d9d9dc);
  --on-primary: light-dark(#fff, #111);
  --chip: light-dark(rgb(255 255 255 / 0.78), rgb(28 28 31 / 0.78));
  --chip-edge: light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1));
  /* The three highlights: the tag's fill (white words on it, 4.5 : 1 or more), and the role's
     words on the page (4.5 : 1 on either). */
  --green: #0a8541;
  --red: #d31c47;
  --blue: #2f4de6;
  --green-ink: light-dark(#0a7a3c, #46d684);
  --red-ink: light-dark(#c81a43, #ff7590);
  --blue-ink: light-dark(#2c48d8, #8fa3ff);
  --focus: #387bff;
  --pointer: #1c1c1e;
  --pointer-edge: #fff;
  --pointer-shadow: rgb(0 0 0 / 0.25);

  position: relative;
  container-type: inline-size;
  overflow: clip;
  padding-bottom: clamp(36px, 7.3cqi, 110px);
  border-radius: 14px;
  background: var(--page);
  color: var(--ink);
  font-family: var(--body, Inter, Arial, sans-serif);
  -webkit-tap-highlight-color: transparent;
}
.root[data-color-scheme='light'] {
  color-scheme: light;
}
.root[data-color-scheme='dark'] {
  color-scheme: dark;
}
.root[data-color-scheme='system'] {
  color-scheme: light dark;
}

.root :focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* The navigation: the mark at the left, the links in the middle, Sign in at the right. */
.nav {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(14px, 3.35cqi, 48px) clamp(20px, 6cqi, 88px) 0;
}
.mark {
  display: grid;
  place-items: center;
  width: clamp(28px, 2.6cqi, 40px);
  height: clamp(28px, 2.6cqi, 40px);
  margin-left: -6px;
  color: var(--ink);
}
.markGlyph {
  width: clamp(18px, 1.6cqi, 24px);
  height: clamp(18px, 1.6cqi, 24px);
}
.links {
  position: absolute;
  left: 50%;
  display: flex;
  gap: clamp(18px, 2.5cqi, 40px);
  transform: translateX(-50%);
}
.link {
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: clamp(13px, 1.05cqi, 16px);
  line-height: 1.5;
  cursor: pointer;
}
.link:hover {
  color: var(--muted);
}
.signIn,
.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease;
}
.signIn {
  height: clamp(32px, 2.7cqi, 40px);
  padding: 0 clamp(12px, 1.25cqi, 18px);
  background: var(--soft);
  color: var(--ink);
  font-size: clamp(13px, 1.05cqi, 16px);
}
.signIn:hover,
.secondary:hover {
  background: var(--soft-hover);
}

/* The crowd band: full width, its canvas fading out at both sides and the bottom. */
.band {
  position: relative;
  height: max(250px, 26.7cqi);
  margin-top: clamp(8px, 2cqi, 30px);
  background: radial-gradient(52% 58% at 50% 46%, var(--glow), transparent 100%);
}
.field {
  position: absolute;
  inset: 0;
  touch-action: manipulation;
}
.field[data-hovering='true'] {
  cursor: pointer;
}
.canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  color: var(--crowd);
  mask-image:
    linear-gradient(90deg, transparent, #000 13%, #000 87%, transparent),
    linear-gradient(180deg, transparent, #000 8%, #000 80%, transparent);
  mask-composite: intersect;
}
.tracks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* A tracking box around a highlighted person, its name tag on top and its role under it. It
   fades in over 600 ms as the colour comes into the person, and out as it leaves. */
.tracker {
  --c: var(--green);
  --c-ink: var(--green-ink);
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  border: 1px solid var(--c);
  opacity: 1;
  transition: opacity 600ms ease;
  will-change: transform;
}
@starting-style {
  .tracker {
    opacity: 0;
  }
}
.tracker[data-out='true'] {
  opacity: 0;
}
.tracker[data-slot='red'] {
  --c: var(--red);
  --c-ink: var(--red-ink);
}
.tracker[data-slot='blue'] {
  --c: var(--blue);
  --c-ink: var(--blue-ink);
}
.name,
.role {
  position: absolute;
  left: -1px;
  white-space: nowrap;
  font-size: clamp(9px, 0.72cqi, 11px);
  line-height: 1;
}
.name {
  bottom: calc(100% + 1px);
  padding: 0.32em 0.5em 0.28em;
  background: var(--c);
  color: #fff;
  font-family: var(--mono, JetBrains, ui-monospace, monospace);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.role {
  top: calc(100% + 0.45em);
  color: var(--c-ink);
}

/* The crowd's two controls, quiet chips at the band's lower right. */
.controls {
  position: absolute;
  right: clamp(20px, 6cqi, 88px);
  bottom: clamp(4px, 1cqi, 14px);
  display: flex;
  gap: 6px;
}
.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 32px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--chip-edge);
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background-color 160ms ease;
}
.control:hover {
  background: var(--soft);
}
.shuffle {
  padding-inline: 10px 12px;
}
.glyph {
  width: 14px;
  height: 14px;
  flex: none;
}

/* The headline at the left; the paragraph and the buttons in a column at the right. */
.copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28.5cqi;
  column-gap: 6cqi;
  align-items: start;
  margin-top: clamp(20px, 7.5cqi, 110px);
  padding: 0 clamp(20px, 6cqi, 88px);
}
.headline {
  margin: 0;
  max-width: 14em;
  font-size: clamp(30px, 4.4cqi, 72px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.aside {
  padding-top: 0.7cqi;
}
.lede {
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 1.12cqi, 17px);
  line-height: 1.5;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(8px, 0.9cqi, 14px);
  margin-top: clamp(14px, 1.7cqi, 26px);
}
.primary,
.secondary {
  height: clamp(36px, 2.9cqi, 46px);
  padding: 0 clamp(12px, 1.4cqi, 22px);
  font-size: clamp(12.5px, 1.08cqi, 16px);
}
.primary {
  background: var(--primary);
  color: var(--on-primary);
}
.primary:hover {
  background: var(--primary-hover);
}
.secondary {
  background: var(--soft);
  color: var(--ink);
}

@container (max-width: 640px) {
  .links {
    display: none;
  }
  .copy {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 16px;
    margin-top: 20px;
  }
  .aside {
    padding-top: 0;
  }
}

/* The demo pointer, over everything; one of its glyphs shows at a time. */
.pointerLayer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.pointer {
  width: 24px;
  height: 24px;
}
.hand {
  visibility: hidden;
}
.pointer[data-glyph='hand'] .arrow {
  visibility: hidden;
}
.pointer[data-glyph='hand'] .hand {
  visibility: visible;
}

.hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .tracker {
    transition: none;
  }
}
```

### crowd-hero/crowd.ts

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

import { FRAMES, STANDING, makeSheet, type Sheet } from './figure';

/*
 * The crowd: people walking on a ground plane seen from above and in front, projected, depth
 * sorted and drawn on one canvas, with three of them highlighted in colour and tied together.
 *
 * - The world is in metres. A person is about 1.75 tall and walks 1–1.5 m/s, mostly across the
 *   view (headings within ±0.55 rad of the x axis), wandering a little; a stride is 1.45 m.
 *   They spread over depths 3.8 to 10.4 m from a camera about 11 m up, so far people are drawn
 *   2.3 times smaller than near ones and higher in the band, and move slower across it. Leaving
 *   the view on one side they come back on the other; at the near and far ends they turn.
 * - Every size comes from the band's height (the focal length is 0.473 of it), so a wide band
 *   shows more people, not bigger ones: about 0.3 people per square metre of visible ground.
 * - Depth of field: the focal plane is at 6.3 m, and the blur grows with the distance from it in
 *   1/z, as a lens's circle of confusion does: near people blur most, far ones a little less, a
 *   band in the middle stays sharp. The people are stamped from 14 sheets, one per depth band,
 *   each already at its size and blur (figure.ts).
 * - Highlights: each of three slots (green, red, blue) holds one person in the focal band,
 *   painted with its gradient, cross-fading over 600 ms when the slot moves to someone else, and
 *   tied by thin lines to the other two and to two people in grey.
 */

export type Point = { x: number; y: number };
export type Box = { x: number; y: number; w: number; h: number };

type Person = {
  wx: number;
  z: number;
  /** Walking +x (1) or −x (−1), and the angle off that axis, into depth. */
  dir: 1 | -1;
  heading: number;
  speed: number;
  phase: number;
  /** Height and build, as factors; tone is the grey's opacity. */
  tall: number;
  build: number;
  tone: number;
  idle: boolean;
  /** The highlight: how much of the colour shows (0–1), where it is heading, and which slot. */
  glow: number;
  glowTo: number;
  slot: number;
  colour: number;
  /** The two people in grey this one is tied to while highlighted. */
  ties: number[];
};

export const SLOT_COUNT = 3;

/** The three highlight gradients, head to feet, and the colour of each slot's lines. */
const PAINT = [
  ['#2bd068', '#5cc853', '#f4a53b'],
  ['#ff4e6b', '#ff8340', '#8a5cf2'],
  ['#3758ff', '#5b78ff', '#ea6ad6'],
];
const LINE = ['#1fae5b', '#ee3b5d', '#3d5cff'];

const Z_MIN = 3.8;
const Z_MAX = 10.4;
const FOCUS = 6.3;
const HEIGHT = 1.75;
const STRIDE = 1.45;
/** Lengths as shares of the band's height: focal length, camera height × focal length, horizon. */
const FOCAL = 0.473;
const CAMERA = 5.11;
const HORIZON = -0.306;
/** The blur in px is this share of the band's height times the distance from focus in 1/z. */
const BLUR = 0.26;
/** Within this distance in 1/z of the focal plane, people stay sharp. */
const SHARP = 0.012;
const BANDS = 14;
const DENSITY = 0.3;
/** The cross-fade of a highlight, in seconds. */
const FADE = 0.6;

/** A small seeded generator, so a seed always makes the same crowd. */
function generator(seed: number) {
  let a = seed >>> 0 || 1;
  return () => {
    a = (a + 0x6d2b79f5) >>> 0;
    let t = a;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

export class Crowd {
  people: Person[] = [];
  /** How many of `people` are in the scene now (the band's size sets it). */
  count = 0;
  hovered = -1;
  slots: { person: number; until: number }[] = Array.from({ length: SLOT_COUNT }, () => ({
    person: -1,
    until: 0,
  }));
  time = 0;
  private random: () => number;
  private width = 0;
  private height = 0;
  private dpr = 1;
  private ink = '';
  private grey: (Sheet & { iz: number; boost: number })[] = [];
  private colours: Sheet[] = [];
  private builtFor = '';

  constructor(seed: number) {
    this.random = generator(seed);
  }

  private get focal() {
    return this.height * FOCAL;
  }

  /** Half the visible width of the ground at depth z, in metres, plus a person's width. */
  private halfWidth(z: number) {
    return ((this.width / 2) * z) / this.focal + 0.9;
  }

  /** The band's size in CSS px and the device pixel ratio; adds people a wider band needs. */
  resize(width: number, height: number, dpr: number) {
    this.width = width;
    this.height = height;
    this.dpr = dpr;
    if (!width || !height) return;
    const area = (width / this.focal) * ((Z_MAX ** 2 - Z_MIN ** 2) / 2);
    this.count = Math.max(24, Math.min(140, Math.round(area * DENSITY)));
    while (this.people.length < this.count) this.people.push(this.spawn());
  }

  /** The grey the crowd is drawn in (the theme's), as a CSS colour. */
  setInk(ink: string) {
    if (ink === this.ink) return false;
    this.ink = ink;
    return true;
  }

  private spawn(): Person {
    const r = this.random;
    const z = Math.sqrt(Z_MIN ** 2 + r() * (Z_MAX ** 2 - Z_MIN ** 2));
    return {
      z,
      wx: (r() * 2 - 1) * this.halfWidth(z),
      dir: r() < 0.5 ? 1 : -1,
      heading: (r() - 0.5) * 0.9,
      speed: 1 + r() * 0.5,
      phase: r(),
      tall: 0.92 + r() * 0.16,
      build: 0.9 + r() * 0.25,
      tone: 0.62 + r() * 0.36,
      idle: r() < 0.06,
      glow: 0,
      glowTo: 0,
      slot: -1,
      colour: 0,
      ties: [],
    };
  }

  /**
   * The sheets for the current size, ink and pixel ratio, made on the first frame drawn with them
   * (a crowd that never comes on screen never makes any); skipped when nothing changed.
   */
  private build() {
    const key = `${Math.round(this.height)}|${this.dpr}|${this.ink}`;
    if (!this.ink || !this.height || key === this.builtFor) return;
    this.builtFor = key;
    const near = 1 / (Z_MIN - 0.2);
    const far = 1 / (Z_MAX + 0.2);
    this.grey = Array.from({ length: BANDS }, (_, index) => {
      const iz = far + ((near - far) * index) / (BANDS - 1);
      const tall = HEIGHT * this.focal * iz * this.dpr;
      const blur = this.blurAt(iz);
      // A blur spreads a thin shape thin: blurred people are drawn a little more opaque.
      return { iz, boost: 1 + blur * 0.14, ...makeSheet(tall, blur * this.dpr, this.ink) };
    });
    // Highlighted people stay near focus: sharp, drawn a little larger than they show.
    const tall = ((HEIGHT * this.focal) / (FOCUS - 1.5)) * this.dpr * 1.1;
    this.colours = PAINT.map((paint) => makeSheet(tall, 0, paint));
  }

  /** The blur, in CSS px, at inverse depth iz. */
  private blurAt(iz: number) {
    const off = Math.max(0, Math.abs(iz - 1 / FOCUS) - SHARP);
    return BLUR * this.height * off;
  }

  /** Where a person stands on screen: the feet, and the height drawn, in CSS px. */
  project(index: number, ahead = 0) {
    const p = this.people[index];
    let { wx, z } = p;
    if (ahead && !p.idle) {
      wx += Math.cos(p.heading) * p.dir * p.speed * ahead;
      z += Math.sin(p.heading) * p.speed * ahead;
    }
    const f = this.focal;
    return {
      x: this.width / 2 + (wx * f) / z,
      y: this.height * HORIZON + (this.height * CAMERA) / z,
      s: (HEIGHT * p.tall * f) / z,
    };
  }

  /** The tracking box around a person, in CSS px; `ahead` seconds from now if given. */
  box(index: number, ahead = 0): Box {
    const { x, y, s } = this.project(index, ahead);
    const w = s * 0.44 * this.people[index].build;
    return { x: x - w / 2, y: y - s * 1.0, w, h: s * 1.05 };
  }

  /** Advances the walk by dt seconds. */
  step(dt: number) {
    this.time += dt;
    const fade = dt / FADE;
    for (let i = 0; i < this.people.length; i += 1) {
      const p = this.people[i];
      if (p.glow !== p.glowTo)
        p.glow =
          p.glow < p.glowTo ? Math.min(p.glowTo, p.glow + fade) : Math.max(p.glowTo, p.glow - fade);
      if (p.idle) continue;
      p.wx += Math.cos(p.heading) * p.dir * p.speed * dt;
      p.z += Math.sin(p.heading) * p.speed * dt;
      p.phase = (p.phase + (p.speed * dt) / STRIDE) % 1;
      p.heading = Math.max(-0.55, Math.min(0.55, p.heading + (this.random() - 0.5) * dt * 0.5));
      // The far and near ends turn people back; the sides send them round to the other side.
      if (p.z < Z_MIN || p.z > Z_MAX) {
        p.z = Math.max(Z_MIN, Math.min(Z_MAX, p.z));
        p.heading = -p.heading;
      }
      const half = this.halfWidth(p.z);
      if (p.wx > half) p.wx = -half;
      else if (p.wx < -half) p.wx = half;
    }
  }

  /** The slots due to move: their time is up, or their person is drifting out of the middle. */
  due(): number[] {
    const due: number[] = [];
    this.slots.forEach((slot, index) => {
      if (slot.person < 0) return due.push(index);
      const { x } = this.project(slot.person);
      const p = this.people[slot.person];
      if (
        this.time >= slot.until ||
        x < this.width * 0.08 ||
        x > this.width * 0.92 ||
        p.z < FOCUS - 2.2 ||
        p.z > FOCUS + 2.8
      )
        due.push(index);
    });
    // Two highlights walking into each other: the older one moves on.
    const near = Math.max(this.width * 0.07, 50);
    for (let a = 0; a < this.slots.length; a += 1)
      for (let b = a + 1; b < this.slots.length; b += 1) {
        const [sa, sb] = [this.slots[a], this.slots[b]];
        if (sa.person < 0 || sb.person < 0) continue;
        const pa = this.project(sa.person);
        const pb = this.project(sb.person);
        if (Math.hypot(pa.x - pb.x, pa.y - pb.y) > near) continue;
        const older = sa.until < sb.until ? a : b;
        if (!due.includes(older)) due.push(older);
      }
    return due;
  }

  private visible(index: number) {
    const { x } = this.project(index);
    return x > 0 && x < this.width;
  }

  /** Someone to highlight: near focus, in the middle, apart from the other highlights. */
  pick(): number {
    const lo = this.width * (this.width < 600 ? 0.14 : 0.16);
    const hi = this.width - lo;
    const apart = Math.max(this.width * 0.16, 90);
    const taken = this.slots.map((slot) => slot.person).filter((person) => person >= 0);
    const ok = (i: number, spread: boolean) => {
      const p = this.people[i];
      if (p.slot >= 0 || p.glow > 0.05 || p.idle) return false;
      if (p.z < FOCUS - 1.3 || p.z > FOCUS + 1.6) return false;
      const { x, y } = this.project(i);
      if (x < lo || x > hi) return false;
      return (
        !spread ||
        taken.every((other) => {
          const o = this.project(other);
          return Math.hypot(o.x - x, (o.y - y) * 1.5) > apart;
        })
      );
    };
    for (const spread of [true, false]) {
      const options: number[] = [];
      for (let i = 0; i < this.count; i += 1) if (ok(i, spread)) options.push(i);
      if (options.length) return options[Math.floor(this.random() * options.length)];
    }
    return -1;
  }

  /**
   * Moves slot `slot` to person `index` (or to one it picks), holding them for `hold` seconds.
   * `instant` skips the cross-fade (a still crowd). Returns the person, or −1.
   */
  hop(slot: number, index: number, hold: number, instant: boolean): number {
    const next = index >= 0 ? index : this.pick();
    if (next < 0) return -1;
    const old = this.slots[slot].person;
    if (old === next) {
      this.slots[slot].until = this.time + hold;
      return next;
    }
    if (old >= 0) {
      const p = this.people[old];
      p.glowTo = 0;
      p.slot = -1;
      if (instant) p.glow = 0;
    }
    // Someone already lit in another slot is handed over to this one.
    const p = this.people[next];
    if (p.slot >= 0 && p.slot !== slot) this.slots[p.slot].person = -1;
    p.slot = slot;
    p.colour = slot;
    p.glowTo = 1;
    if (instant) p.glow = 1;
    p.ties = this.tiesFor(next);
    this.slots[slot] = { person: next, until: this.time + hold };
    return next;
  }

  /** Two people in grey a fair way off, to draw lines to. */
  private tiesFor(index: number) {
    const from = this.project(index);
    const options: number[] = [];
    for (let i = 0; i < this.count; i += 1) {
      if (i === index || this.people[i].slot >= 0) continue;
      const { x, y } = this.project(i);
      const d = Math.hypot(x - from.x, y - from.y);
      if (d > this.width * 0.1 && d < this.width * 0.45 && x > 0 && x < this.width) options.push(i);
    }
    const ties: number[] = [];
    while (ties.length < 2 && options.length)
      ties.push(options.splice(Math.floor(this.random() * options.length), 1)[0]);
    return ties;
  }

  /** The person under a point in CSS px, nearest first; −1 for none. */
  hit(x: number, y: number) {
    let best = -1;
    let bestZ = Infinity;
    for (let i = 0; i < this.people.length; i += 1) {
      if (i >= this.count && this.people[i].slot < 0) continue;
      const b = this.box(i);
      const pad = 3;
      if (x < b.x - pad || x > b.x + b.w + pad || y < b.y - pad || y > b.y + b.h + pad) continue;
      if (this.people[i].z < bestZ) {
        bestZ = this.people[i].z;
        best = i;
      }
    }
    return best;
  }

  /** Draws the whole scene on `ctx`, a canvas the band's size times the pixel ratio. */
  draw(ctx: CanvasRenderingContext2D) {
    const k = this.dpr;
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.globalAlpha = 1;
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    this.build();
    if (!this.grey.length) return;
    const order: number[] = [];
    for (let i = 0; i < this.people.length; i += 1)
      if (i < this.count || this.people[i].glow > 0) order.push(i);
    // Far to near, so nearer people cover farther ones.
    order.sort((a, b) => this.people[b].z - this.people[a].z);
    const near = 1 / (Z_MIN - 0.2);
    const far = 1 / (Z_MAX + 0.2);

    for (const i of order) {
      const p = this.people[i];
      const { x, y, s } = this.project(i);
      if (x < -s || x > this.width + s || y - s > this.height + s) continue;
      const frame = p.idle ? STANDING : Math.floor(p.phase * FRAMES) % FRAMES;
      const band = Math.round(((1 / p.z - far) / (near - far)) * (BANDS - 1));
      const sheet = this.grey[Math.max(0, Math.min(BANDS - 1, band))];
      const sprite = sheet.frames[frame];
      if (!sprite) continue;
      const scale = (s * k) / sheet.height;
      const lit = p.glow;
      if (lit < 1) {
        ctx.globalAlpha = i === this.hovered ? 1 : Math.min(1, p.tone * sheet.boost);
        ctx.setTransform(p.dir * scale * p.build, 0, 0, scale, x * k, y * k);
        ctx.drawImage(sprite.canvas, -sprite.ox, -sprite.oy);
      }
      if (lit > 0) {
        const colour = this.colours[p.colour];
        const lead = colour?.frames[frame];
        if (!colour || !lead) continue;
        const scaled = (s * k) / colour.height;
        ctx.globalAlpha = lit;
        ctx.setTransform(p.dir * scaled * p.build, 0, 0, scaled, x * k, y * k);
        ctx.drawImage(lead.canvas, -lead.ox, -lead.oy);
      }
    }

    // The ties: between the lit people, and from each to its two in grey.
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.lineWidth = Math.max(1, k * 0.8);
    const lit = order.filter((i) => this.people[i].glow > 0);
    const centre = (i: number) => {
      const { x, y, s } = this.project(i);
      return { x: x * k, y: (y - s * 0.55) * k };
    };
    for (let a = 0; a < lit.length; a += 1) {
      const pa = this.people[lit[a]];
      const ca = centre(lit[a]);
      for (let b = a + 1; b < lit.length; b += 1) {
        const pb = this.people[lit[b]];
        if (pa.colour === pb.colour) continue;
        const cb = centre(lit[b]);
        const gradient = ctx.createLinearGradient(ca.x, ca.y, cb.x, cb.y);
        gradient.addColorStop(0, LINE[pa.colour]);
        gradient.addColorStop(1, LINE[pb.colour]);
        ctx.strokeStyle = gradient;
        ctx.globalAlpha = 0.5 * Math.min(pa.glow, pb.glow);
        ctx.beginPath();
        ctx.moveTo(ca.x, ca.y);
        ctx.lineTo(cb.x, cb.y);
        ctx.stroke();
      }
      ctx.strokeStyle = LINE[pa.colour];
      ctx.globalAlpha = 0.32 * pa.glow;
      for (const tie of pa.ties) {
        if (!this.visible(tie)) continue;
        const ct = centre(tie);
        ctx.beginPath();
        ctx.moveTo(ca.x, ca.y);
        ctx.lineTo(ct.x, ct.y);
        ctx.stroke();
      }
    }

    // The person under the pointer gets a thin box in the crowd's ink.
    if (this.hovered >= 0 && this.people[this.hovered].glow < 0.5) {
      const b = this.box(this.hovered);
      ctx.globalAlpha = 0.7;
      ctx.strokeStyle = this.ink;
      ctx.lineWidth = k;
      ctx.strokeRect(
        Math.round(b.x * k) + 0.5,
        Math.round(b.y * k) + 0.5,
        Math.round(b.w * k),
        Math.round(b.h * k),
      );
    }
    ctx.globalAlpha = 1;
  }
}
```

### crowd-hero/figure.ts

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

/*
 * One walking person, drawn procedurally, and the sprite sheets the crowd is stamped from.
 *
 * - The figure is a side-view silhouette one `height` tall, its feet at the origin, facing +x: a
 *   round head, a torso that leans a little forward, and two legs and two arms as thick round-capped
 *   strokes, each a thigh and a shin (an upper arm and a forearm). The legs swing ±0.42 rad on
 *   opposite phases, the knee folding while the leg travels forward; the arms swing ±0.36 rad
 *   against the legs; the body bobs 1.2% of its height twice a cycle.
 * - A sheet is FRAMES frames of one stride plus a standing pose, at one size and one blur. The
 *   crowd keeps a sheet per depth band, so every stamp is already the right size and softness and a
 *   frame costs one drawImage per person; nothing is blurred while it plays.
 * - The blur is the canvas filter where the browser has it; elsewhere a ring of faint offset copies
 *   stands in for it.
 */

/** Frames in one stride; the sheet's last frame, at this index, is the standing pose. */
export const FRAMES = 12;
export const STANDING = FRAMES;

export type Sprite = {
  canvas: HTMLCanvasElement;
  /** The feet, in the sprite's px. */
  ox: number;
  oy: number;
};

/** A sheet: the frames of one size and blur. */
export type Sheet = { height: number; frames: Sprite[] };

const TAU = Math.PI * 2;

/** Whether the 2D context applies CSS filters, read once. */
let filterWorks: boolean | null = null;
function canFilter(ctx: CanvasRenderingContext2D) {
  if (filterWorks === null) {
    ctx.filter = 'blur(2px)';
    filterWorks = ctx.filter === 'blur(2px)';
    ctx.filter = 'none';
  }
  return filterWorks;
}

/** A thigh and a shin (or an upper arm and a forearm) from (x, y); angles from straight down. */
function limb(
  ctx: CanvasRenderingContext2D,
  x: number,
  y: number,
  upper: number,
  upperLength: number,
  lower: number,
  lowerLength: number,
  width: number,
  foot = 0,
) {
  const jx = x + Math.sin(upper) * upperLength;
  const jy = y + Math.cos(upper) * upperLength;
  const ex = jx + Math.sin(lower) * lowerLength;
  const ey = jy + Math.cos(lower) * lowerLength;
  ctx.lineWidth = width;
  ctx.beginPath();
  ctx.moveTo(x, y);
  ctx.lineTo(jx, jy);
  ctx.lineTo(ex, ey);
  // A foot is a short stub forward from the ankle, flat to the ground.
  if (foot) ctx.lineTo(ex + foot, ey);
  ctx.stroke();
}

/** The figure at `phase` (0–1 of a stride), feet at the origin, in the context's current style. */
export function drawFigure(
  ctx: CanvasRenderingContext2D,
  height: number,
  phase: number,
  standing: boolean,
) {
  const s = height;
  const p = phase * TAU;
  const swing = standing ? 0.03 : 0.42;
  const bob = standing ? 0 : -0.012 * s * (1 - Math.abs(Math.cos(p)));
  const hip = { x: 0, y: -0.5 * s + bob };
  const shoulder = { x: 0.012 * s, y: -0.785 * s + bob };
  ctx.lineCap = 'round';
  ctx.lineJoin = 'round';

  // Both legs, the far one first; the knee folds while its leg travels forward (cos > 0).
  for (const side of [1, 0]) {
    const q = p + side * Math.PI;
    const thigh = swing * Math.sin(q);
    const fold = standing ? 0.04 : 0.12 + 0.62 * Math.max(0, Math.cos(q)) ** 1.4;
    limb(ctx, hip.x, hip.y, thigh, 0.245 * s, thigh - fold, 0.245 * s, 0.085 * s, 0.05 * s);
  }
  // Torso: wider at the shoulders, a little forward of the hips.
  ctx.lineWidth = 0.05 * s;
  ctx.beginPath();
  ctx.moveTo(shoulder.x - 0.075 * s, shoulder.y - 0.025 * s);
  ctx.lineTo(shoulder.x + 0.078 * s, shoulder.y - 0.025 * s);
  ctx.lineTo(hip.x + 0.07 * s, hip.y + 0.02 * s);
  ctx.lineTo(hip.x - 0.072 * s, hip.y + 0.02 * s);
  ctx.closePath();
  ctx.fill();
  ctx.stroke();
  // Head, over a short neck.
  ctx.lineWidth = 0.05 * s;
  ctx.beginPath();
  ctx.moveTo(shoulder.x + 0.01 * s, shoulder.y);
  ctx.lineTo(shoulder.x + 0.016 * s, shoulder.y - 0.06 * s);
  ctx.stroke();
  ctx.beginPath();
  ctx.arc(shoulder.x + 0.02 * s, -0.9 * s + bob, 0.07 * s, 0, TAU);
  ctx.fill();
  // Arms swing against the legs, elbows bent a little forward.
  for (const side of [1, 0]) {
    const upper = -0.36 * Math.sin(p + side * Math.PI) * (standing ? 0.1 : 1);
    limb(
      ctx,
      shoulder.x,
      shoulder.y + 0.01 * s,
      upper,
      0.17 * s,
      upper + 0.32,
      0.155 * s,
      0.062 * s,
    );
  }
}

/**
 * The frames of one size and blur. `paint` is a colour, or the stops of a top-to-bottom gradient
 * (the highlighted people).
 */
export function makeSheet(height: number, blur: number, paint: string | string[]): Sheet {
  // Crowds of the same size and theme (a page of docs) share their sheets.
  const key = `${height.toFixed(1)}|${blur.toFixed(2)}|${String(paint)}`;
  const kept = cache.get(key);
  if (kept) return kept;
  const sheet = paintSheet(height, blur, paint);
  cache.set(key, sheet);
  if (cache.size > CACHE) cache.delete(cache.keys().next().value as string);
  return sheet;
}

/** The sheets made so far, oldest first; a few crowds' worth. */
const cache = new Map<string, Sheet>();
const CACHE = 120;

function paintSheet(height: number, blur: number, paint: string | string[]): Sheet {
  const pad = Math.ceil(blur * 2.4 + height * 0.08 + 2);
  const width = Math.ceil(height * 0.8 + pad * 2);
  const tall = Math.ceil(height * 1.06 + pad * 2);
  const ox = width / 2;
  const oy = tall - pad - height * 0.045;
  const frames: Sprite[] = [];
  const scratch = document.createElement('canvas');
  scratch.width = width;
  scratch.height = tall;
  const draft = scratch.getContext('2d');
  if (!draft) return { height, frames };

  for (let frame = 0; frame <= FRAMES; frame += 1) {
    draft.globalCompositeOperation = 'source-over';
    draft.clearRect(0, 0, width, tall);
    draft.setTransform(1, 0, 0, 1, ox, oy);
    draft.fillStyle = '#000';
    draft.strokeStyle = '#000';
    drawFigure(draft, height, frame / FRAMES, frame === STANDING);
    draft.setTransform(1, 0, 0, 1, 0, 0);
    // The colour goes into the shape just drawn.
    draft.globalCompositeOperation = 'source-in';
    if (typeof paint === 'string') draft.fillStyle = paint;
    else {
      const gradient = draft.createLinearGradient(0, oy - height, 0, oy);
      paint.forEach((stop, index) => gradient.addColorStop(index / (paint.length - 1), stop));
      draft.fillStyle = gradient;
    }
    draft.fillRect(0, 0, width, tall);

    const canvas = document.createElement('canvas');
    canvas.width = width;
    canvas.height = tall;
    const ctx = canvas.getContext('2d');
    if (!ctx) continue;
    if (blur < 0.35) ctx.drawImage(scratch, 0, 0);
    else if (canFilter(ctx)) {
      ctx.filter = `blur(${blur.toFixed(2)}px)`;
      ctx.drawImage(scratch, 0, 0);
      ctx.filter = 'none';
    } else {
      // Two rings of faint copies around the middle one, about as wide as the blur.
      const copies: [number, number, number][] = [[0, 0, 0.3]];
      for (let i = 0; i < 8; i += 1) {
        const a = (i / 8) * TAU;
        copies.push([Math.cos(a) * blur, Math.sin(a) * blur, 0.12]);
        copies.push([Math.cos(a + 0.4) * blur * 0.5, Math.sin(a + 0.4) * blur * 0.5, 0.2]);
      }
      for (const [dx, dy, alpha] of copies) {
        ctx.globalAlpha = alpha;
        ctx.drawImage(scratch, dx, dy);
      }
      ctx.globalAlpha = 1;
    }
    frames.push({ canvas, ox, oy });
  }
  return { height, frames };
}
```

### crowd-hero/glyphs.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

/*
 * The hero's glyphs, drawn for it: the logo mark (four dots, three close and one stepping away,
 * as a person leaving a group to meet someone), and the crowd's controls, pause, play and shuffle.
 * All in currentColor, decorative: the controls carry their own names.
 */

type Glyph = { className?: string };

export function Mark({ className }: Glyph) {
  return (
    <svg className={className} viewBox="0 0 24 24" aria-hidden="true" focusable="false">
      <circle cx="5" cy="5" r="2.6" fill="currentColor" />
      <circle cx="12" cy="5" r="2.6" fill="currentColor" />
      <circle cx="5" cy="12" r="2.6" fill="currentColor" />
      <circle cx="18.5" cy="18.5" r="2.6" fill="currentColor" />
    </svg>
  );
}

export function Pause({ className }: Glyph) {
  return (
    <svg className={className} viewBox="0 0 16 16" aria-hidden="true" focusable="false">
      <rect x="4" y="3" width="2.6" height="10" rx="1" fill="currentColor" />
      <rect x="9.4" y="3" width="2.6" height="10" rx="1" fill="currentColor" />
    </svg>
  );
}

export function Play({ className }: Glyph) {
  return (
    <svg className={className} viewBox="0 0 16 16" aria-hidden="true" focusable="false">
      <path
        d="M5 3.4v9.2c0 .6.7 1 1.2.6l6.9-4.6c.4-.3.4-1 0-1.2L6.2 2.8c-.5-.4-1.2 0-1.2.6z"
        fill="currentColor"
      />
    </svg>
  );
}

export function Shuffle({ className }: Glyph) {
  return (
    <svg className={className} viewBox="0 0 16 16" aria-hidden="true" focusable="false">
      <g
        fill="none"
        stroke="currentColor"
        strokeWidth="1.5"
        strokeLinecap="round"
        strokeLinejoin="round"
      >
        <path d="M2 4.5h2.2c1.4 0 2.2.6 3 1.8l1.6 3.4c.8 1.2 1.6 1.8 3 1.8H14" />
        <path d="M2 11.5h2.2c1 0 1.7-.3 2.3-.9M9.5 5.4c.6-.6 1.3-.9 2.3-.9H14" />
        <path d="M12 2.5l2 2-2 2M12 9.5l2 2-2 2" />
      </g>
    </svg>
  );
}
```

### crowd-hero/demo-pointer.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import type { CSSProperties, Ref } from 'react';

/*
 * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or
 * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends
 * the step in progress at once: its promise rejects, which ends the script right there, and the
 * pointer fades out.
 *
 * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame.
 * The points of the flight are handed to whoever wants to move along with it (nothing here uses
 * them yet). The arrow and the hand are HTML boxes
 * that swap by their visibility: a change of style inside an SVG would lay the SVG out again.
 */

export type Point = { x: number; y: number };

/** A glide's path and timing, for an animation that plays along with it. */
export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };

export type Demo = {
  /** Resolves after `ms`. */
  wait: (ms: number) => Promise<void>;
  /** Glides the pointer to `to`, in the stage's own px, in `ms`; `along` gets the flight. */
  glide: (to: Point, ms: number, along?: (flight: Flight) => void) => Promise<void>;
  /** Shows the arrow, or the hand a link shows. */
  glyph: (name: 'arrow' | 'hand') => void;
};

/** What a stopped demo's pending step rejects with. */
class Stopped extends Error {}

/** Where the arrow's tip is, as shares of its box: the point the pointer stands on. */
const TIP: Point = { x: 0.15, y: 0.1 };

/** How many points a flight is drawn through. */
const SAMPLES = 24;

/** Plays `script` with the pointer over `stage`; returns the function that stops it. */
export function runDemo(
  stage: HTMLElement,
  pointer: HTMLElement,
  script: (demo: Demo) => Promise<void>,
): () => void {
  let alive = true;
  let flight: Animation | null = null;
  // The stylesheet sizes the pointer from the stage's width; its tip is where it stands.
  const tip = { x: pointer.offsetWidth * TIP.x, y: pointer.offsetHeight * TIP.y };
  const place = ({ x, y }: Point) => `translate(${x - tip.x}px, ${y - tip.y}px)`;
  const timers = new Set<number>();
  const pending = new Set<() => void>();
  // The pointer comes in from the lower right.
  let at: Point = { x: stage.offsetWidth * 0.8, y: stage.offsetHeight * 0.9 };

  /** Settles like `promise`, or rejects as soon as the demo stops. */
  const step = (promise: Promise<unknown>) =>
    new Promise<void>((resolve, reject) => {
      if (!alive) return reject(new Stopped());
      const cancel = () => reject(new Stopped());
      pending.add(cancel);
      promise.then(
        () => {
          pending.delete(cancel);
          if (alive) resolve();
        },
        () => {
          pending.delete(cancel);
          reject(new Stopped());
        },
      );
    });

  const wait = (ms: number) =>
    step(
      new Promise<void>((resolve) => {
        const timer = window.setTimeout(() => {
          timers.delete(timer);
          resolve();
        }, ms);
        timers.add(timer);
      }),
    );

  const glide: Demo['glide'] = (to, ms, along) => {
    const from = at;
    at = to;
    const dx = to.x - from.x;
    const dy = to.y - from.y;
    // A gentle curve, as a hand moves: the control point sits off the straight line.
    const bend = { x: (from.x + to.x) / 2 - dy * 0.18, y: (from.y + to.y) / 2 + dx * 0.18 };
    const points: Point[] = [];
    for (let i = 0; i <= SAMPLES; i += 1) {
      const t = i / SAMPLES;
      const u = 1 - t;
      points.push({
        x: u * u * from.x + 2 * u * t * bend.x + t * t * to.x,
        y: u * u * from.y + 2 * u * t * bend.y + t * t * to.y,
      });
    }
    const timing: KeyframeAnimationOptions = {
      duration: ms,
      easing: 'cubic-bezier(0.45, 0, 0.25, 1)',
    };
    flight?.cancel();
    // Where it rests once the flight is over.
    pointer.style.transform = place(to);
    flight = pointer.animate(
      points.map((point) => ({ transform: place(point) })),
      timing,
    );
    along?.({ points, timing });
    return step(flight.finished);
  };

  const glyph: Demo['glyph'] = (name) => {
    pointer.dataset.glyph = name;
  };

  pointer.dataset.glyph = 'arrow';
  pointer.style.transform = place(at);
  pointer.style.opacity = '1';
  script({ wait, glide, glyph }).catch((error: unknown) => {
    if (!(error instanceof Stopped)) throw error;
  });

  return () => {
    if (!alive) return;
    alive = false;
    timers.forEach((timer) => window.clearTimeout(timer));
    flight?.cancel();
    pending.forEach((cancel) => cancel());
    pointer.style.opacity = '0';
  };
}

/**
 * The pointer's box: it moves, on a layer of its own. Its size comes from its class, its colours
 * from the stage's tokens (crowd-hero.module.css).
 */
const POINTER: CSSProperties = {
  position: 'absolute',
  top: 0,
  left: 0,
  zIndex: 2,
  display: 'block',
  pointerEvents: 'none',
  opacity: 0,
  transition: 'opacity 0.3s ease',
  filter: 'drop-shadow(0 1px 1.5px var(--pointer-shadow))',
  willChange: 'transform',
};

/** One glyph over the other, each filling the box. */
const GLYPH: CSSProperties = { position: 'absolute', inset: 0, display: 'block' };
const DRAWING: CSSProperties = {
  display: 'block',
  width: '100%',
  height: '100%',
  overflow: 'visible',
};
/** The arrow is dark on a white edge, the hand white on a dark one, as the system draws them. */
const ARROW: CSSProperties = { fill: 'var(--pointer)', stroke: 'var(--pointer-edge)' };
const HAND: CSSProperties = { fill: 'var(--pointer-edge)', stroke: 'var(--pointer)' };

/**
 * The pointer the demo moves around: an arrow, or a pointing hand over a control. It is
 * decorative: what it does shows on the control itself. The stylesheet shows one glyph at a time,
 * from the box's data-glyph.
 */
export function DemoPointer({
  ref,
  className,
  arrowClass,
  handClass,
}: {
  ref: Ref<HTMLSpanElement>;
  className?: string;
  arrowClass?: string;
  handClass?: string;
}) {
  return (
    <span ref={ref} className={className} style={POINTER} aria-hidden="true">
      <span className={arrowClass} style={GLYPH}>
        <svg viewBox="0 0 20 20" style={DRAWING}>
          <path
            d="M3 2v14.5l3.6-3.3 2.6 5.6 2.4-1.1-2.6-5.5h5.2z"
            style={ARROW}
            strokeWidth="1.3"
            strokeLinejoin="round"
          />
        </svg>
      </span>
      <span className={handClass} style={GLYPH}>
        <svg viewBox="0 0 20 20" style={DRAWING}>
          {/* The tip of the finger sits where the arrow's tip is. */}
          <path
            d="M6.4 3.3c0-.8.6-1.4 1.3-1.4S9 2.5 9 3.3v5.5c.2-.5.6-.8 1.2-.8.7 0 1.2.5 1.2 1.2v.5c.2-.5.6-.8 1.2-.8.7 0 1.2.5 1.2 1.2v.7c.2-.4.6-.7 1.1-.7.7 0 1.2.5 1.2 1.2v3.5c0 2.8-1.9 4.9-4.6 4.9h-1.2c-1.8 0-3.1-.8-4.1-2.3l-2.6-3.9c-.4-.6-.2-1.3.4-1.7.6-.3 1.3-.2 1.7.4l.6.9z"
            style={HAND}
            strokeWidth="1.1"
            strokeLinejoin="round"
            transform="translate(-4.7 0.1)"
          />
        </svg>
      </span>
    </span>
  );
}
```

### crowd-hero/use-autoplay.ts

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import { useCallback, useEffect, useRef, useState } from 'react';

/*
 * When a demo may play on its own: while part of it is on screen and the tab is visible, never
 * under reduced motion, and never again once the reader has used it: `take()` hands it to the
 * reader for good (until the component mounts again), so it can't come back on its own.
 */
export function useAutoplay<T extends HTMLElement>() {
  const ref = useRef<T>(null);
  const [visible, setVisible] = useState(false);
  const [reduced, setReduced] = useState(true);
  const [taken, setTaken] = useState(false);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    let onScreen = false;
    const update = () => setVisible(onScreen && !document.hidden);
    const observer = new IntersectionObserver(
      ([entry]) => {
        onScreen = entry.isIntersecting;
        update();
      },
      { threshold: 0.3 },
    );
    observer.observe(element);
    document.addEventListener('visibilitychange', update);
    const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
    const readMotion = () => setReduced(motion.matches);
    readMotion();
    motion.addEventListener('change', readMotion);
    return () => {
      observer.disconnect();
      document.removeEventListener('visibilitychange', update);
      motion.removeEventListener('change', readMotion);
    };
  }, []);

  const take = useCallback(() => setTaken(true), []);

  return { ref, take, playing: visible && !reduced && !taken };
}
```