# Password reels

> A sign-up card with a combination lock for an icon: each password rule met spins the next number reel to a green tick.

A white card with a back chevron, a dark squircle icon holding four number reels, the title Set your password, a real password field with a padlock, a disabled Create account button and a line of small print. The first character opens a checklist: at least 8 characters, a number, an uppercase letter, a symbol. Each rule met turns green, and the next reel from the left spins to a tick, whichever rule it was. With all four met the button turns solid, the padlock closes and turns green, and the list folds into one Strong password row. Deleting unwinds it all.

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

Category: Inputs.

## Anatomy

1. **Card**: A form, 360 px wide with a 22 px radius. Its height is carried by a sheet behind it, so its contents never lay out again.
2. **Back**: A 31 px squircle with a chevron, which calls `onBack`. The `back` prop replaces it; `null` leaves it out.
3. **Icon**: A dark 106 px squircle with 9 px of bezel around the window. Dark in both schemes. Hidden from screen readers.
4. **Reel**: One of four drums, 22 px wide, each with its own perspective. The rows above and below the middle lean away because they really are on a cylinder.
5. **Title**: The heading of the card, 23 px medium, centred.
6. **Field**: A real password input, 39 px tall with a 14 px radius and `autoComplete="new-password"`. Its padlock opens and closes with the state.
7. **Lock**: Grey with the shackle lifted; green and closed with every rule met.
8. **Create account**: The submit button, disabled until every rule passes: a hairline outline, then a solid fill.
9. **Terms**: The small print: a slot, in 13 px. The default sentence is plain text, so link your own pages by passing them in.

## Properties

### Rules (`rules`)

1. **Four (default)**: The default: length, a number, an uppercase letter, a symbol. One reel for each rule.
2. **Two**: A shorter list. The reels fill in step, two for each rule met.

There are always four reels, because that is what the icon draws. With another number of rules they fill in proportion, and all four are ticks only when every rule is met.

## When to use

- The step of a sign-up where someone chooses a password, when the card has nothing else to do: one field, one button.
- A product that wants this moment to feel like a small object working, since the reels are the whole point of the card.
- Rules that can be checked as the person types, so each one can answer straight away.

## When not to use

- Signing in. An existing password has no rules to meet, and the checklist would tell an onlooker nothing useful.
- A form with other fields around the password. Use a plain field with the rules under it; the card and its icon need the space.
- Rules that need the server, such as “not used before”. Those answers arrive late and can’t turn a reel on a keystroke.
- More than five or six rules: the card gets tall and four reels no longer map to anything a reader can follow.

### The sequence

- **First character**: the card grows on a spring in 0.6 s, and the rows blur in from the top, 55 ms apart.
- **A rule met**: its disc fills, its words turn from the left in 0.35 s, and the next reel from the left turns five faces to a tick in 0.62 s.
- **Every rule met**: the button turns solid at once. After 0.55 s, when the last reel has landed, the padlock closes and the list leaves from the bottom up, 50 ms apart.
- **Then**: the card folds in 0.24 s with no spring, and “Strong password” blurs in.
- **Deleting**: every step runs backwards. A reel unwinds from the right, and the list comes back as soon as a rule is lost.

### What the reels mean

- **They count, they don’t name**: a reel doesn’t stand for a rule. The first rule met turns the first reel, whichever rule it was.
- **They are decoration**: nothing depends on seeing them. The checklist carries the same information in words.

## Do’s and don’ts

- **Do**: Write each rule as a short noun phrase that reads well with a tick beside it: A number.
- **Don’t**: Write sentences. A row is one line, and anything longer is cut with an ellipsis.
- **Do**: Pass your own terms with real links to your own pages.
- **Don’t**: Log the value from `onChange`, or put it in analytics. Keep it in memory until the form is sent.

## Content

The words are the title, the placeholder, the rules, the strong row, the button and the terms.

- **The title** says what to do: `Set your password`.
- **Rules** say what is needed, in sentence case with no full stop: `At least 8 characters`.
- **The strong row** says the outcome in two words: `Strong password`.
- **The button** names what comes next, not the field: `Create account`.

## Installation

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

```sh
npx shadcn@latest add https://brunodelorence.com/r/password-reels.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/password-reels
```

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 { PasswordReels } from './password-reels';

export function SignUpStep({ createAccount, goBack }) {
  return (
    <PasswordReels
      onSubmit={createAccount}
      onBack={goBack}
      terms={
        <>
          By continuing you agree to our <a href="/terms">terms</a>.
        </>
      }
      autoplay={false}
    />
  );
}
```

## States

- **Empty**: No checklist yet. The reels read 6 2 8 9 and the button is an outline.
- **Typing**: One rule met: its row is green, and the first reel shows a tick.
- **Almost there**: Three rules met, three ticks. The button stays disabled.
- **Strong password**: Every rule met: four ticks, a closed green padlock, a solid button, and one row in place of the list.
- **Dark**: With `colorScheme="dark"`: a graphite card and a light button; the icon doesn’t change.

## How it works

- Each reel is a real drum in CSS 3D: faces 30° apart on a 68 px radius under a 320 px perspective, set back by its radius so the front face keeps its size. The rows above and below the middle lean away and shorten because they are on a cylinder. Each reel has its own perspective, so all four are seen straight on.
- A turn is five faces and one CSS transition of the `rotate` property, which the compositor runs. Timed frame by frame, it covers a face every 33 ms at the start, reaches its mark at 0.3 s, goes 13% of a face past at 0.37 s and is back by 0.62 s; that curve is written as a `linear()` easing. Several reels turning at once (a pasted password) start 70 ms apart.
- The motion blur is a filter on the reel’s own 22 px box, up to 0.9 px for the first 0.38 s of a turn and removed afterwards. The shading never moves: a vertical gradient over the window goes from 94% black at the edges to clear across the middle 16%, so a numeral dims as it rolls away. Under it each reel has an elliptical glow, and between them are black ratchet teeth 3 px apart.
- The numerals are one stroke each on a 12 × 20 grid, drawn in SVG, so they are the same condensed shapes on every system with no font to load.
- The card never lays out as it grows. `--extra` is the height the rows need (135 px for four rules, 50 px for the strong row): the button and terms slide down by it with `translate`, the card slides up by half to stay centred, and only a childless sheet behind them changes height.
- Growing is a spring with a 7% overshoot, at its peak after 0.2 s and settled in 0.6 s. Folding is 0.24 s with no overshoot, after a 0.15 s wait.
- Rows blur in from 4 px over 0.24 s, top first and 55 ms apart; they leave over 0.16 s, bottom first and 50 ms apart. A rule’s words turn green from the left in 0.35 s by sliding a gradient clipped to the text, with a soft edge.
- When the last rule is met the button changes at once. The padlock closes and the list folds 0.55 s later, once the last reel has landed; losing a rule undoes that straight away.
- The value lives in the input and in the caller’s state. It is not logged or stored, and the live region says only which rules changed. While on screen and untouched, a demo pointer clicks the field, types a sample phrase over 5 s, holds, and deletes it about every 13 s; the field never takes the real focus, and any input from the reader stops the demo and clears the phrase.

## API reference

- **value** (`string`): The password, when the caller holds it. Passing it also turns the demo off.
- **defaultValue** (`string`, default `''`): Where an uncontrolled field starts; anything but empty turns the demo off.
- **onChange** (`(value: string) => void`): Called on every change the reader makes. The demo’s typing does not call it.
- **onSubmit** (`(value: string) => void`): Called with the password when the form is sent, which only works with every rule met.
- **rules** (`PasswordRule[]`, default `DEFAULT_RULES`): Each is { id, label, test(value) }. The default is length 8, a number, an uppercase letter and a symbol. There are always four reels: with another number of rules they fill in proportion.
- **title** (`ReactNode`, default `'Set your password'`): The card’s heading.
- **label** (`string`, default `'Password'`): The field’s label, visually hidden.
- **placeholder** (`string`, default `'Your password'`): The hint in the empty field.
- **submitLabel** (`string`, default `'Create account'`): The button’s words.
- **strongLabel** (`string`, default `'Strong password'`): What the single row says with every rule met; it is announced too.
- **name** (`string`, default `'password'`): The input’s name in the form.
- **onBack** (`() => void`): Called by the default back button, which does nothing without it.
- **back** (`ReactNode`): Takes the place of the default back button; null leaves it out.
- **terms** (`ReactNode`, default `A plain sentence, with no links`): The small print under the button; null leaves it out.
- **autoplay** (`boolean`, default `true`): Plays the demo while on screen and untouched, in an uncontrolled, empty field. Never under reduced motion.
- **colorScheme** (`'light' | 'dark' | 'system'`): Forces a scheme; without it the page’s color-scheme decides. The icon stays dark.
- **className** (`string`): Added to the stage.

## Accessibility

### Focus and keyboard

- Tab goes from Back to the field, then to the button once it is enabled. Enter in the field sends the form only with every rule met.
- The field’s edge darkens on focus, and the buttons show a 2 px ring on keyboard focus.

### Screen readers

- The field has a real label and is described by the rules, so they are read out on arrival, even before the list is on screen.
- A polite live region says what changed once typing rests for 0.7 s, such as “A number: met. 2 of 4 met.”, and never the value.
- Each rule’s row ends in a hidden “met” or “not met”, since the green is only colour. The reels, the padlock and the demo pointer are hidden.

### Password managers

It is an ordinary `type="password"` input with `autoComplete="new-password"` in a real form, so managers can offer and fill a password; pasting turns several reels at once, 70 ms apart.

### Motion

With reduced motion the reels jump to their faces with no spin or blur, the card changes height at once, and rows only fade in 0.15 s. The demo does not play.

### In this build

- A real form with a labelled `type="password"` input and `autoComplete="new-password"`, so password managers work; the button is natively disabled until every rule passes, and Enter sends only then.
- The field is described by the rules (or by the strong row once it shows), so they are read on arrival, even before the list appears.
- A polite live region says what changed once typing rests for 0.7 s, such as “A number: met. 2 of 4 met.”, and never the value. It stays quiet while the demo plays.
- Each row ends in a hidden “met” or “not met”, since green alone says nothing to some readers. The reels, the padlock and the demo pointer are hidden from assistive technology.
- Rule, placeholder and terms text reach 4.5:1 on the card in both schemes.
- With reduced motion the reels jump to their faces, the card changes height at once, and rows only fade in 0.15 s; the demo does not play.

## Source

### password-reels/password-reels.tsx

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

'use client';

import {
  useEffect,
  useEffectEvent,
  useId,
  useMemo,
  useRef,
  useState,
  type CSSProperties,
  type ChangeEvent,
  type FormEvent,
  type ReactNode,
} from 'react';
import { DemoPointer, runDemo, type Point } from './demo-pointer';
import { Chevron, Numeral, Padlock, ReelTick, RuleTick } from './reels';
import { useAutoplay } from './use-autoplay';
import styles from './password-reels.module.css';

/*
 * Password reels: a sign-up card whose icon is a combination lock of four number reels. Typing
 * opens a checklist under the field; each rule met turns green and spins the next reel from the
 * left to a green tick, whichever rule it was. With all of them met the button turns solid, the
 * field's padlock closes, and the checklist folds into one “Strong password” row. Deleting
 * unwinds it all.
 *
 * - Each reel is a real drum: faces 30° apart on a 68 px radius in CSS 3D, so the rows above and
 *   below the middle lean away and shorten by themselves. Turning it is one transition of the
 *   `rotate` property, which the compositor runs; the shading is a still overlay above it.
 * - The card never lays out as it grows: the button and the terms slide by `translate`, the card
 *   slides up by half to stay centred, and only its childless sheet changes height.
 * - The value stays in the input and in the caller's hands: it is not logged, stored or announced.
 */

export type PasswordRule = {
  /** A stable key. */
  id: string;
  /** What the row says. */
  label: string;
  /** Whether a value meets it. It is called on every change, so keep it quick. */
  test: (value: string) => boolean;
};

export const DEFAULT_RULES: PasswordRule[] = [
  { id: 'length', label: 'At least 8 characters', test: (value) => [...value].length >= 8 },
  { id: 'number', label: 'A number', test: (value) => /\p{N}/u.test(value) },
  { id: 'uppercase', label: 'An uppercase letter', test: (value) => /\p{Lu}/u.test(value) },
  { id: 'symbol', label: 'A symbol', test: (value) => /[^\p{L}\p{N}\s]/u.test(value) },
];

export type PasswordReelsProps = {
  /** The password, when the caller holds it. It also turns the demo off. */
  value?: string;
  /** Where an uncontrolled field starts; anything but empty turns the demo off. */
  defaultValue?: string;
  onChange?: (value: string) => void;
  /** Called with the password when the form is sent, which only works with every rule met. */
  onSubmit?: (value: string) => void;
  rules?: PasswordRule[];
  title?: ReactNode;
  /** The field's name for a screen reader; it is the field's label, visually hidden. */
  label?: string;
  placeholder?: string;
  submitLabel?: string;
  /** What the single row says with every rule met. */
  strongLabel?: string;
  /** The input's name in the form. */
  name?: string;
  onBack?: () => void;
  /** Takes the place of the default back button; null leaves it out. */
  back?: ReactNode;
  /** The small print under the button; null leaves it out. */
  terms?: ReactNode;
  autoplay?: boolean;
  colorScheme?: 'light' | 'dark' | 'system';
  className?: string;
};

/** The reels, top to bottom from the tick; the last but one is the middle at rest. */
const STRIPS = [
  ['tick', '3', '7', '1', '5', '6', '7'],
  ['tick', '4', '9', '4', '9', '2', '3'],
  ['tick', '5', '1', '7', '3', '8', '9'],
  ['tick', '6', '3', '0', '7', '9', '0'],
];
const STEP = 30;
const RADIUS = 68;
/** The tick is this many faces round from the digit at rest. */
const TURN = 5;
/** Between reels, when one change turns several: pasting a password. */
const REEL_STAGGER = 70;
/** The spin's blur: the fast first third of its 620 ms. */
const BLUR_MS = 380;
/** From the last rule met to the padlock and the fold: the last reel has landed by then. */
const LAND_MS = 550;
/** How long the state rests before it is announced, so typing doesn't talk over itself. */
const ANNOUNCE_MS = 700;

const ROW = 29;
const LIST_EXTRA = 19;
const STRONG_EXTRA = 50;

/** A phrase that shows the rules being met one at a time; `at` is the ms after the previous key. */
const SAMPLE = 'dEmotext9!';
const KEY_GAPS = [0, 560, 290, 290, 290, 290, 290, 290, 1000, 1250];
const DELETE_GAP = 240;

export function PasswordReels({
  value,
  defaultValue = '',
  onChange,
  onSubmit,
  rules = DEFAULT_RULES,
  title = 'Set your password',
  label = 'Password',
  placeholder = 'Your password',
  submitLabel = 'Create account',
  strongLabel = 'Strong password',
  name = 'password',
  onBack,
  back,
  terms = 'You acknowledge that you have read, and agree to, our Terms of Service and our Privacy Policy.',
  autoplay = true,
  colorScheme,
  className = '',
}: PasswordReelsProps) {
  const { ref: root, playing, take } = useAutoplay<HTMLDivElement>();
  const [draft, setDraft] = useState(defaultValue);
  const [demoFocus, setDemoFocus] = useState(false);
  const current = value ?? draft;

  const met = useMemo(() => rules.map((rule) => rule.test(current)), [rules, current]);
  const metCount = met.filter(Boolean).length;
  const allMet = rules.length > 0 && metCount === rules.length;
  // Four reels whatever the number of rules: they fill in step, and all four at the end.
  const on = rules.length ? Math.floor((metCount * STRIPS.length) / rules.length) : 0;

  const [landed, setLanded] = useState(allMet);
  useEffect(() => {
    if (!allMet) return;
    const timer = window.setTimeout(() => setLanded(true), LAND_MS);
    return () => {
      window.clearTimeout(timer);
      setLanded(false);
    };
  }, [allMet]);
  const strong = allMet && landed;
  const state = strong ? 'strong' : current ? 'list' : 'empty';
  const extra = {
    empty: 0,
    list: rules.length * ROW + LIST_EXTRA,
    strong: STRONG_EXTRA,
  }[state];
  const extraMost = Math.max(rules.length * ROW + LIST_EXTRA, STRONG_EXTRA);

  // The reels turn here rather than through React: a change of target keeps the running transition
  // going from where the drum is, and only the reels that change get a blur and a delay.
  const reels = useRef<(HTMLSpanElement | null)[]>([]);
  const [startOn] = useState(on);
  const shown = useRef(startOn);
  useEffect(() => {
    const before = shown.current;
    if (before === on) return;
    shown.current = on;
    const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    for (let index = Math.min(before, on); index < Math.max(before, on); index += 1) {
      const reel = reels.current[index];
      const drum = reel?.firstElementChild as HTMLElement | null | undefined;
      if (!reel || !drum) continue;
      const order = on > before ? index - before : before - 1 - index;
      const delay = order * REEL_STAGGER;
      drum.style.transitionDelay = `${delay}ms`;
      drum.style.rotate = `x ${index < on ? -TURN * STEP : 0}deg`;
      if (!reduced) {
        reel.animate(
          [
            { filter: 'blur(0)' },
            { filter: 'blur(0.9px)', offset: 0.14 },
            { filter: 'blur(0.8px)', offset: 0.45 },
            { filter: 'blur(0)' },
          ],
          { duration: BLUR_MS, delay },
        );
      }
    }
  }, [on]);

  // The demo: the pointer clicks into the field and moves off, the phrase is typed, it holds on
  // the strong row, and it is deleted. 14.6 s a round. The field never takes the real focus.
  const [message, setMessage] = useState('');
  const uncontrolled = value === undefined;
  const demo = autoplay && playing && uncontrolled && !defaultValue;
  const pointer = useRef<HTMLSpanElement>(null);
  const field = useRef<HTMLDivElement>(null);
  const demoType = useEffectEvent((text: string) => setDraft(text));
  const demoRing = useEffectEvent((focused: boolean) => setDemoFocus(focused));
  useEffect(() => {
    const stage = root.current;
    const arrow = pointer.current;
    if (!demo || !stage || !arrow) return;
    const away = (): Point => ({ x: stage.offsetWidth * 0.86, y: stage.offsetHeight * 0.56 });
    const onField = (): Point => {
      const frame = stage.getBoundingClientRect();
      const scale = frame.width / stage.offsetWidth || 1;
      const box = field.current?.getBoundingClientRect();
      if (!box) return away();
      return {
        x: (box.left - frame.left + box.width * 0.62) / scale,
        y: (box.top - frame.top + box.height / 2) / scale,
      };
    };
    const stop = runDemo(stage, arrow, async ({ wait, glide, glyph }) => {
      await glide(away(), 500);
      for (;;) {
        await wait(500);
        await glide(onField(), 620);
        glyph('text');
        await wait(260);
        demoRing(true);
        await wait(180);
        glyph('arrow');
        await glide(away(), 560);
        for (let count = 1; count <= SAMPLE.length; count += 1) {
          await wait(KEY_GAPS[count - 1]);
          demoType(SAMPLE.slice(0, count));
        }
        await wait(2200);
        for (let count = SAMPLE.length - 1; count >= 0; count -= 1) {
          demoType(SAMPLE.slice(0, count));
          await wait(DELETE_GAP);
        }
        await wait(700);
        demoRing(false);
        await wait(900);
      }
    });
    return () => {
      stop();
      // The reader starts from an empty field, not from the demo's phrase.
      demoType('');
      demoRing(false);
    };
  }, [demo, root]);

  // What changed, once typing rests; never the value, and not while the demo plays.
  const said = useRef<boolean[]>(met);
  const announce = useEffectEvent(() => {
    if (demo) {
      said.current = met;
      return;
    }
    const gained = rules.filter((_, index) => met[index] && !said.current[index]);
    const lost = rules.filter((_, index) => !met[index] && said.current[index]);
    said.current = met;
    if (!gained.length && !lost.length) return;
    const parts = [
      ...gained.map((rule) => `${rule.label}: met.`),
      ...lost.map((rule) => `${rule.label}: not met.`),
    ];
    setMessage(
      allMet
        ? `${parts.join(' ')} ${strongLabel}.`
        : `${parts.join(' ')} ${metCount} of ${rules.length} met.`,
    );
  });
  useEffect(() => {
    const timer = window.setTimeout(announce, ANNOUNCE_MS);
    return () => window.clearTimeout(timer);
  }, [met]);

  const inputId = useId();
  const listId = useId();
  const strongId = useId();

  const onInput = (event: ChangeEvent<HTMLInputElement>) => {
    if (uncontrolled) setDraft(event.target.value);
    onChange?.(event.target.value);
  };
  const send = (event: FormEvent) => {
    event.preventDefault();
    if (allMet) onSubmit?.(current);
  };

  return (
    <div
      ref={root}
      className={`${styles.root} ${className}`}
      data-part="stage"
      data-state={state}
      data-color-scheme={colorScheme}
      style={{ '--extra': `${extra}px`, '--extra-most': `${extraMost}px` } as CSSProperties}
      onPointerDownCapture={take}
      onKeyDownCapture={take}
      onPointerMove={(event) => {
        if (event.pointerType !== 'touch') take();
      }}
    >
      <form className={styles.card} data-part="card" onSubmit={send} noValidate>
        <div className={styles.sheet} />

        {back === undefined ? (
          <button
            type="button"
            className={styles.back}
            data-part="back"
            aria-label="Back"
            onClick={onBack}
          >
            <Chevron />
          </button>
        ) : (
          back
        )}

        <div className={styles.icon} data-part="icon" aria-hidden="true">
          <div className={styles.window} data-part="reels">
            {STRIPS.map((strip, index) => (
              <span
                key={index}
                ref={(element) => {
                  reels.current[index] = element;
                }}
                className={styles.reel}
                data-part="reel"
              >
                <span
                  className={styles.drum}
                  style={{ rotate: `x ${index < startOn ? -TURN * STEP : 0}deg` }}
                >
                  {strip.map((glyph, row) => {
                    // The tick is first in the strip and the furthest round: five faces up.
                    const face = TURN - row;
                    return (
                      <span
                        key={row}
                        className={styles.face}
                        style={{ transform: `rotateX(${face * STEP}deg) translateZ(${RADIUS}px)` }}
                      >
                        {glyph === 'tick' ? (
                          <ReelTick className={styles.tick} />
                        ) : (
                          <Numeral value={glyph} className={styles.numeral} />
                        )}
                      </span>
                    );
                  })}
                </span>
              </span>
            ))}
            <span className={styles.teeth} />
            <span className={styles.shade} />
          </div>
        </div>

        <h3 className={styles.title} data-part="title">
          {title}
        </h3>

        <div
          ref={field}
          className={styles.field}
          data-part="field"
          data-demo-focus={demoFocus || undefined}
        >
          <label className={styles.hidden} htmlFor={inputId}>
            {label}
          </label>
          <input
            id={inputId}
            className={styles.input}
            data-part="input"
            type="password"
            name={name}
            autoComplete="new-password"
            autoCapitalize="none"
            autoCorrect="off"
            spellCheck={false}
            placeholder={placeholder}
            value={current}
            onChange={onInput}
            aria-describedby={strong ? strongId : listId}
          />
          <span className={styles.lock} data-part="lock" aria-hidden="true">
            <Padlock shackleClass={styles.shackle} />
          </span>
        </div>

        <div className={styles.below}>
          <ul id={listId} className={styles.rules} data-part="rules" aria-label="Password rules">
            {rules.map((rule, index) => (
              <li
                key={rule.id}
                className={styles.rule}
                data-part="rule"
                data-met={met[index] || undefined}
                style={{ '--i': index, '--ri': rules.length - 1 - index } as CSSProperties}
              >
                <span className={styles.disc} aria-hidden="true">
                  <RuleTick className={styles.discTick} />
                </span>
                <span className={styles.label}>{rule.label}</span>
                <span className={styles.hidden}>{met[index] ? ' met' : ' not met'}</span>
              </li>
            ))}
          </ul>
          <p id={strongId} className={styles.strong} data-part="strong">
            <span className={styles.disc} aria-hidden="true">
              <RuleTick className={styles.discTick} />
            </span>
            <span className={styles.label}>{strongLabel}</span>
          </p>
        </div>

        <div className={styles.tail}>
          <button type="submit" className={styles.submit} data-part="submit" disabled={!allMet}>
            {submitLabel}
          </button>
          {terms === null ? null : (
            <p className={styles.terms} data-part="terms">
              {terms}
            </p>
          )}
        </div>
      </form>

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

### password-reels/password-reels.module.css

```css
/* Password reels (password-reels.tsx): a sign-up card on a pale stage. Its icon is a dark squircle
   with four number reels; a checklist opens under the field as it is typed in.

   Sizes are px: a 360 px card with a 22 px radius and 30 px sides, a 106 px icon with 9 px of
   bezel, a 39 px field and a 39 px button 14 px round, rows 29 px apart.

   The card's own layout never changes. --extra is the height the rows need: the tail slides down
   by it, the card up by half of it, and the sheet behind them (a box with no children) grows by it.

   The reels are dark in both schemes: the object doesn't change colour at night, the page does. */

.root {
  --stage: #f7f7f7;
  --sheet: #fdfdfd;
  --sheet-edge: rgb(0 0 0 / 0.045);
  --sheet-shadow: rgb(0 0 0 / 0.035);
  --ink: #2a2a2d;
  --muted: #75757b;
  --back: #f3f3f3;
  --back-hover: #ececec;
  --back-ink: #66666b;
  --field-edge: #ececee;
  --field-edge-focus: #8a8a90;
  --field-edge-demo: #d6d6d9;
  --field: #fdfdfd;
  --lock: #848486;
  --disc: #fdfdfd;
  --disc-edge: #f0f0f1;
  --good: #1c8550;
  --good-fill: #2e9d61;
  --good-ink: #fff;
  --solid: #27282c;
  --solid-hover: #3a3b40;
  --solid-ink: #fff;
  --off-ink: #85858a;
  --off-edge: #f0f0f1;
  --focus: #6b6b72;
  --pointer: #111;
  --pointer-edge: #fff;
  --pointer-shadow: rgb(0 0 0 / 0.25);
  /* The card's growth: a spring with a 7% overshoot, at its peak after 0.2 s. */
  --grow: linear(
    0,
    0.105,
    0.328,
    0.569,
    0.774,
    0.922,
    1.012,
    1.056,
    1.068,
    1.061,
    1.046,
    1.03,
    1.016,
    1.006,
    0.999,
    0.996,
    0.995,
    0.996,
    0.997,
    0.998,
    0.999,
    1
  );
  /* A reel's turn: fast from the start, on its mark at 0.3 s, past it by 13% of a face, back. */
  --spin: linear(
    0,
    0.22 5.3%,
    0.4 10.6%,
    0.6 16%,
    0.7 21.4%,
    0.8 26.8%,
    0.88 32.2%,
    0.94 37.6%,
    0.97 43%,
    1.008 48.4%,
    1.02 53.7%,
    1.026 59%,
    1.018 69%,
    1.006 80.6%,
    1
  );
  --settle: cubic-bezier(0.3, 0.7, 0.2, 1);
  --pop: cubic-bezier(0.34, 1.6, 0.64, 1);

  position: relative;
  isolation: isolate;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  /* Room for the card at its tallest, which grows half up and half down. */
  padding: calc(var(--extra-most) / 2 + 28px) 12px;
  overflow: clip;
  border-radius: 18px;
  background: var(--stage);
  color: var(--ink);
  font:
    400 15px / 20px -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Inter,
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@supports (color: light-dark(#fff, #000)) {
  .root {
    --stage: light-dark(#f7f7f7, #0e0e10);
    --sheet: light-dark(#fdfdfd, #18181b);
    --sheet-edge: light-dark(rgb(0 0 0 / 0.045), rgb(255 255 255 / 0.07));
    --sheet-shadow: light-dark(rgb(0 0 0 / 0.035), rgb(0 0 0 / 0.3));
    --ink: light-dark(#2a2a2d, #ececee);
    --muted: light-dark(#75757b, #9a9aa1);
    --back: light-dark(#f3f3f3, #26262a);
    --back-hover: light-dark(#ececec, #2f2f34);
    --back-ink: light-dark(#66666b, #b0b0b6);
    --field-edge: light-dark(#ececee, #2c2c31);
    --field-edge-focus: light-dark(#8a8a90, #77777e);
    --field-edge-demo: light-dark(#d6d6d9, #3c3c42);
    --field: light-dark(#fdfdfd, #1c1c20);
    --lock: light-dark(#848486, #85858c);
    --disc: light-dark(#fdfdfd, #1c1c20);
    --disc-edge: light-dark(#f0f0f1, #2c2c31);
    --good: light-dark(#1c8550, #52c98a);
    --good-fill: light-dark(#2e9d61, #2e9d61);
    --solid: light-dark(#27282c, #ececee);
    --solid-hover: light-dark(#3a3b40, #fff);
    --solid-ink: light-dark(#fff, #18181b);
    --off-ink: light-dark(#85858a, #77777e);
    --off-edge: light-dark(#f0f0f1, #2a2a2f);
    --focus: light-dark(#6b6b72, #a0a0a7);
  }
}
.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;
}

.card {
  position: relative;
  box-sizing: border-box;
  width: min(360px, 100%);
  padding: 47px 30px 33px;
  translate: 0 calc(var(--extra) / -2);
  transition: translate 0.6s var(--grow);
}
.sheet {
  position: absolute;
  inset: 0 0 auto;
  z-index: -1;
  height: calc(100% + var(--extra));
  border-radius: 22px;
  background: var(--sheet);
  box-shadow:
    0 0 0 1px var(--sheet-edge),
    0 4px 14px var(--sheet-shadow);
  transition: height 0.6s var(--grow);
}
.tail {
  translate: 0 var(--extra);
  transition: translate 0.6s var(--grow);
}
/* Folding is quicker, with no spring, and waits for the rows to start leaving. */
.root[data-state='strong'] .card,
.root[data-state='strong'] .tail,
.root[data-state='empty'] .card,
.root[data-state='empty'] .tail {
  transition: translate 0.24s var(--settle) 0.15s;
}
.root[data-state='strong'] .sheet,
.root[data-state='empty'] .sheet {
  transition: height 0.24s var(--settle) 0.15s;
}

.back {
  position: absolute;
  top: 18px;
  left: 18px;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--back);
  color: var(--back-ink);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.back:hover {
  background: var(--back-hover);
}
.back:focus-visible,
.submit:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* The icon: a bezel around a window. */
.icon {
  width: 106px;
  height: 106px;
  margin: 0 auto;
  padding: 9px;
  box-sizing: border-box;
  border-radius: 25px;
  background: linear-gradient(#383838, #2a2a2a);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    inset 0 -1px 0 rgb(0 0 0 / 0.35),
    0 10px 18px -4px rgb(0 0 0 / 0.28),
    0 2px 5px rgb(0 0 0 / 0.16);
}
.window {
  position: relative;
  display: flex;
  height: 100%;
  overflow: hidden;
  border-radius: 13px;
  background: #050505;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.55);
}

/* A reel: its own perspective, so each is seen straight on, and the glow of its lit middle. */
.reel {
  position: relative;
  flex: 1;
  overflow: hidden;
  perspective: 320px;
  background: radial-gradient(ellipse 70% 60% at 50% 50%, #4e4e4e, #2a2a2a 60%, #121212 100%);
}
.drum {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  /* Set back by its radius, so the face in front is drawn at its own size. */
  translate: 0 0 -68px;
  transition: rotate 0.62s var(--spin);
}
.face {
  position: absolute;
  top: -17px;
  left: -11px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 34px;
  backface-visibility: hidden;
}
.numeral {
  width: 12px;
  height: 21px;
  color: #d2d2d2;
}
.tick {
  width: 15px;
  height: 13px;
  margin-top: -3px;
  color: #5fd56d;
}

/* The ratchets between the reels, on top of them: black teeth, 3 px apart, 4 px wide. */
.teeth {
  --teeth: repeating-linear-gradient(#000 0 1.7px, rgb(58 58 58 / 0.75) 1.7px 3px);

  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    var(--teeth) 20px 0 / 4px 100% no-repeat,
    var(--teeth) 42px 0 / 4px 100% no-repeat,
    var(--teeth) 64px 0 / 4px 100% no-repeat;
}
/* The cylinder's shading: still, over everything; the drum turns under it. */
.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    rgb(0 0 0 / 0.94) 0,
    rgb(0 0 0 / 0.7) 8%,
    rgb(0 0 0 / 0.42) 20%,
    rgb(0 0 0 / 0.14) 33%,
    transparent 42%,
    transparent 58%,
    rgb(0 0 0 / 0.14) 67%,
    rgb(0 0 0 / 0.42) 80%,
    rgb(0 0 0 / 0.7) 92%,
    rgb(0 0 0 / 0.94) 100%
  );
  box-shadow: inset 0 0 5px 1px rgb(0 0 0 / 0.6);
  border-radius: inherit;
}

.title {
  margin: 14px 0 22px;
  color: var(--ink);
  font-size: 23px;
  font-weight: 500;
  line-height: 28px;
  text-align: center;
}

.field {
  position: relative;
  height: 39px;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}
.input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0 40px 0 14px;
  border: 1px solid var(--field-edge);
  border-radius: inherit;
  outline: none;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  /* The size of the dots; the placeholder has its own. */
  font-size: 21px;
  letter-spacing: 0;
  transition: border-color 0.15s ease;
}
.input::placeholder {
  color: var(--muted);
  font-size: 15px;
  opacity: 1;
  letter-spacing: 0;
}
.input::-ms-reveal {
  display: none;
}
.field[data-demo-focus] .input {
  border-color: var(--field-edge-demo);
}
.input:focus {
  border-color: var(--field-edge-focus);
}
.lock {
  position: absolute;
  top: 50%;
  right: 12px;
  display: block;
  height: 23px;
  margin-top: -11.5px;
  color: var(--lock);
  pointer-events: none;
  transition: color 0.2s ease;
}
.lock svg {
  display: block;
  width: 18.4px;
  height: 23px;
}
.shackle {
  transform: translateY(-2.2px);
  transition: transform 0.26s var(--pop);
}
.root[data-state='strong'] .lock {
  color: var(--good-fill);
}
.root[data-state='strong'] .shackle {
  transform: none;
}

/* The space under the field: a marker in the flow, its rows laid over the gap that opens. */
.below {
  position: relative;
  height: 19px;
}
.rules {
  position: absolute;
  inset: 11px 0 auto;
  margin: 0;
  padding: 0;
  list-style: none;
  visibility: hidden;
  transition: visibility 0s linear 0.35s;
}
.root[data-state='list'] .rules {
  visibility: visible;
  transition-delay: 0s;
}
.rule,
.strong {
  display: flex;
  align-items: center;
  gap: 11px;
  height: 29px;
  margin: 0;
  white-space: nowrap;
}
/* A row comes in from a blur, top one first; it leaves the same way, the bottom one first. */
.rule {
  opacity: 0;
  filter: blur(4px);
  translate: 0 -3px;
  transition:
    opacity 0.16s ease calc(var(--ri) * 50ms),
    filter 0.16s ease calc(var(--ri) * 50ms),
    translate 0.16s ease calc(var(--ri) * 50ms);
}
.root[data-state='list'] .rule {
  opacity: 1;
  filter: none;
  translate: none;
  transition:
    opacity 0.24s ease calc(100ms + var(--i) * 55ms),
    filter 0.24s ease calc(100ms + var(--i) * 55ms),
    translate 0.24s ease calc(100ms + var(--i) * 55ms);
}
.strong {
  position: absolute;
  inset: 21px 0 auto;
  opacity: 0;
  filter: blur(4px);
  visibility: hidden;
  transition:
    opacity 0.1s ease,
    filter 0.1s ease,
    visibility 0s linear 0.1s;
}
.root[data-state='strong'] .strong {
  opacity: 1;
  filter: none;
  visibility: visible;
  transition:
    opacity 0.24s ease 0.26s,
    filter 0.24s ease 0.26s,
    visibility 0s linear 0.26s;
}

.disc {
  position: relative;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--disc);
  box-shadow: inset 0 0 0 1px var(--disc-edge);
}
.disc::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--good-fill);
  opacity: 0;
  scale: 0.4;
  transition:
    opacity 0.16s ease,
    scale 0.16s ease;
}
.discTick {
  position: absolute;
  inset: 0;
  width: 20px;
  height: 20px;
  color: var(--good-ink);
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.12s ease;
}
.rule[data-met] .disc::before,
.strong .disc::before {
  opacity: 1;
  scale: 1;
  transition:
    opacity 0.12s ease,
    scale 0.28s var(--pop);
}
.rule[data-met] .discTick,
.strong .discTick {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.2s ease 0.08s;
}

/* A rule's words turn from left to right, with a soft edge, in 0.35 s. */
.label {
  overflow: hidden;
  text-overflow: ellipsis;
  color: transparent;
  letter-spacing: 0.012em;
  background: linear-gradient(90deg, var(--good) 45.45%, var(--muted) 54.55%) 100% 0 / 220% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  transition: background-position 0.35s linear;
}
.rule[data-met] .label,
.strong .label {
  background-position: 0 0;
}

.submit {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 39px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--solid);
  color: var(--solid-ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}
.submit:hover:not(:disabled) {
  background: var(--solid-hover);
}
.submit:disabled {
  border-color: var(--off-edge);
  background: var(--sheet);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
  color: var(--off-ink);
  cursor: not-allowed;
}
.terms {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
  text-align: center;
}

.pointerLayer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
.pointer {
  width: 24px;
  height: 24px;
}
.text {
  visibility: hidden;
}
.pointer[data-glyph='text'] .arrow {
  visibility: hidden;
}
.pointer[data-glyph='text'] .text {
  visibility: visible;
}

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

@media (max-width: 420px) {
  .root {
    padding-inline: 8px;
  }
  .card {
    padding-inline: 22px;
  }
}

@media (forced-colors: active) {
  .label {
    background: none;
    color: CanvasText;
  }
  .rule[data-met] .disc,
  .strong .disc {
    background: Highlight;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drum,
  .card,
  .tail,
  .sheet,
  .root[data-state] .card,
  .root[data-state] .tail,
  .root[data-state] .sheet,
  .shackle,
  .label,
  .disc::before,
  .rule[data-met] .disc::before,
  .discTick,
  .rule[data-met] .discTick,
  .strong .disc::before,
  .strong .discTick {
    transition: none;
  }
  .rule,
  .root[data-state='list'] .rule,
  .strong,
  .root[data-state='strong'] .strong {
    filter: none;
    translate: none;
    transition:
      opacity 0.15s linear,
      visibility 0s linear;
  }
  .rule,
  .strong {
    transition-delay: 0s;
  }
}
```

### password-reels/reels.tsx

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

/*
 * The drawn pieces: the condensed numerals of the reels (one stroke each, the same on every
 * system, so no font is needed), the green tick, the chevron, the padlock and the rule's tick.
 */

/** Stroke paths on a 12 × 20 grid. */
const NUMERALS: Record<string, string> = {
  '0': 'M6 1.6C3 1.6 1.6 3 1.6 5.6v8.8c0 2.6 1.4 4 4.4 4s4.4-1.4 4.4-4V5.6c0-2.6-1.4-4-4.4-4z',
  '1': 'M2.8 5.2 7.2 1.8V20',
  '2': 'M1.7 6.2C1.7 3.2 3.2 1.6 6 1.6s4.3 1.5 4.3 4.2c0 2-1 3.5-2.5 5.4l-5.8 7.3H11',
  '3': 'M1.6 5.6C1.8 3 3.4 1.6 6 1.6s4.3 1.5 4.3 4.1-1.7 4.1-4.9 4.1c3.5 0 5.1 1.5 5.1 4.4s-1.8 4.2-4.5 4.2-4.3-1.4-4.5-4',
  '4': 'M8.5 20V2.2L1.5 14.4H11.8',
  '5': 'M10.2 1.6H3.1l-.6 8.2c.9-1 2.1-1.5 3.5-1.5 2.9 0 4.4 2 4.4 5.1s-1.6 5-4.4 5c-2.5 0-4-1.4-4.4-3.8',
  '6': 'M9.8 3.2C9 2.2 7.8 1.6 6.4 1.6c-3.2 0-4.8 2.6-4.8 8.4v4c0 2.9 1.7 4.4 4.4 4.4s4.4-1.6 4.4-4.5-1.6-4.5-4.2-4.5c-2 0-3.7 1-4.6 2.9',
  '7': 'M.6 1.6h10.8L5 20',
  '8': 'M6 9.6c-2.7 0-4.2-1.5-4.2-4S3.3 1.6 6 1.6s4.2 1.5 4.2 4-1.5 4-4.2 4zm0 0c-3 0-4.6 1.6-4.6 4.4s1.6 4.4 4.6 4.4 4.6-1.6 4.6-4.4-1.6-4.4-4.6-4.4z',
};

export function Numeral({ value, className }: { value: string; className?: string }) {
  return (
    <svg className={className} viewBox="0 0 12 20" fill="none" stroke="currentColor">
      <path
        d={value === '9' ? NUMERALS['6'] : NUMERALS[value]}
        strokeWidth="3.1"
        transform={value === '9' ? 'rotate(180 6 10)' : undefined}
      />
    </svg>
  );
}

export function ReelTick({ className }: { className?: string }) {
  return (
    <svg className={className} viewBox="0 0 16 14" fill="none" stroke="currentColor">
      <path d="M1.6 7.2 6 11.6 14.6 1.8" strokeWidth="3" />
    </svg>
  );
}

export function RuleTick({ className }: { className?: string }) {
  return (
    <svg className={className} viewBox="0 0 20 20" fill="none" stroke="currentColor">
      <path
        d="m5.9 10.3 2.9 2.9 5.4-6"
        pathLength="1"
        strokeWidth="1.8"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

export function Chevron() {
  return (
    <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor">
      <path d="M10 3 5 8l5 5" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

/** The shackle is lifted clear of the body until the stylesheet lowers it. */
export function Padlock({ shackleClass }: { shackleClass?: string }) {
  return (
    <svg viewBox="0 0 16 20" width="16" height="20" fill="currentColor">
      <path
        className={shackleClass}
        d="M4.6 10V6.4a3.4 3.4 0 0 1 6.8 0V10"
        fill="none"
        stroke="currentColor"
        strokeWidth="1.6"
      />
      <rect x="2" y="9.4" width="12" height="8.6" rx="2" />
    </svg>
  );
}
```

### password-reels/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 };
}
```

### password-reels/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 text cursor 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 text cursor a field shows. */
  glyph: (name: 'arrow' | 'text') => 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 (password-reels.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, and so is the text cursor: a dark line over a wider white one. */
const ARROW: CSSProperties = { fill: 'var(--pointer)', stroke: 'var(--pointer-edge)' };
const BEAM = 'M7 3c1.8 0 3 .7 3 2v10c0 1.3-1.2 2-3 2M13 3c-1.8 0-3 .7-3 2v10c0 1.3 1.2 2 3 2';

/**
 * The pointer the demo moves around: an arrow, or a text cursor over a field. 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,
  textClass,
}: {
  ref: Ref<HTMLSpanElement>;
  className?: string;
  arrowClass?: string;
  textClass?: 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={textClass} style={GLYPH}>
        <svg viewBox="0 0 20 20" style={DRAWING}>
          {/* The middle of the cursor sits where the arrow's tip is. */}
          <g fill="none" strokeLinecap="round" transform="translate(-7 -8)">
            <path d={BEAM} stroke="var(--pointer-edge)" strokeWidth="3" />
            <path d={BEAM} stroke="var(--pointer)" strokeWidth="1.3" />
          </g>
        </svg>
      </span>
    </span>
  );
}
```