# Consist planner

> A high-speed train’s pre-departure screen: the sixteen cars on one track, each car’s seat map, six figures and the car sequence.

An operations screen for one sixteen-car bullet-train set before it leaves Tokyo for Shin-Osaka. The sidebar holds the terminal, search, the sets, a watchlist and the next departure. The planner card shows the consist’s service and route, power, crew, load, position, ETA and the next thing to fix, then a line drawing of the train: the car in focus centred on the rails, its neighbours fading at the edges, the long nose cars at both ends. Under it is that car’s seat map, booked, free, selected or kept for luggage, and below that a strip of car cards with silhouettes and load bars. Step through the cars and the train slides along the track.

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

Category: Dashboards.

## Anatomy

1. **Sidebar**: Terminal picker, search (press /), navigation with the planner’s sets, a watchlist with coloured dots, the next departure with its readiness and the signed-in user. Under 1000 px it is a drawer.
2. **Consist header**: The set (H-12), its service, route and departure, the pre-departure check pill, and reset and full screen.
3. **Figures**: Six cells: power, crew, load, position, ETA and the next action in amber. Three columns under 900 px, two under 560.
4. **Train**: Every car side by side on one track, 77% of the viewer wide each; the strip slides to centre the car in focus and fades the neighbours at the edges.
5. **Seat map**: The car’s seats as a grid: A to E across a 3 + 2 car, the aisle a 12 px gap. Booked, free (dashed), selected (blue) or luggage (red).
6. **Car card**: One per car in the sequence: number, status dot, a silhouette, the code, seats booked and a load bar. The car in focus is outlined in blue, a car with a fault in amber.

## Properties

### Car in focus (`defaultCar`)

1. **01**: The lead car: the nose, 65 seats.
2. **04 (default)**: An ordinary 3 + 2 car near the front.
3. **09**: A premier car in 2 + 2, in the middle of the set.

Open on the car the person came for: the one named in an alert, a ticket or a link. Without one, open on the first car with seats to work on.

## When to use

- Checking one train before it leaves: which cars it runs with, how full each one is, and what still has to be fixed.
- A seat-level task inside a car, such as holding seats for a group or moving passengers out of a car with a fault.
- Fixed-formation trains, where the car order is known and every car has a seat plan: high-speed sets, intercity units.
- An operations desk where people work through the day on a wide screen, and still need to glance at it on a phone.

## When not to use

- Selling tickets to passengers. A booking flow needs fares, one seat per traveller and a checkout; this is a staff view of the whole car.
- Freight trains or wagons without seats. Show the car sequence with loads and weights instead of a seat map.
- Watching many trains at once. Use a timetable board or a line diagram; this planner looks at one consist at a time.
- Live tracking while the train runs. The figures here are a plan before departure, not a feed.

### Layout

- **Wide**: sidebar at 252 px, the main column beside it, the six figures in one row.
- **Under 1000 px of its own width** the sidebar becomes a drawer behind a menu button; Escape or the scrim closes it.
- **On a phone** the figures fold to two columns, and the seat map and the car cards scroll inside their own boxes, so the page never scrolls sideways.

### Moving through the train

- **Prev and next** step one car; the train slides 700 ms and the car in focus brightens.
- **A car card** jumps to that car; the arrows move along the cards, Home and End go to the ends.
- **The alert pill** and **Validate consist** go to the car with the open defect.
- **Reset** puts back the opening car and selection.

## Do’s and don’ts

- **Do**: Draw the cars in their real order, with the nose cars at both ends, and say which end leads.
- **Don’t**: Tell seat states by colour alone in the words around the map. Each seat names its state (“Seat 7C, booked, selected”), and free seats are dashed, not only lighter.
- **Do**: Keep amber for what needs doing before departure: the check pill, the next action, the faulty car.

## Content

The words are operational: codes, times and counts, short enough for one line each.

- **Car numbers with two digits** (`04`) and the car code beside them (`M-1204`), the same in the viewer, the caption and the card.
- **Seat counts as booked of total** (`92 / 98 seats`), with the percentage only in the caption.
- **The next action as a verb** (`Fix HVAC in car 05`) and its deadline under it.

## Installation

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

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

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 { ConsistPlanner } from './consist-planner';

export function DeparturePlanner() {
  return (
    <ConsistPlanner
      defaultCar={4}
      onCarChange={(car) => console.log('car', car)}
      onSeatToggle={(car, seat, selected) => console.log(car, seat, selected)}
      autoplay={false}
    />
  );
}
```

## States

- **Car 04 in focus**: The opening state: an ordinary car, 92 of 98 seats booked, seat 7C selected.
- **Car with a fault**: Car 05 carries the HVAC defect: amber dot and outline on its card, and the alert pill above the train.
- **Premier car**: Cars 08 to 10 seat 2 + 2, so the map has four rows, A to D, and a gold line under the windows.
- **Lead car**: Car 01, with the long nose to the left and no car before it; 13 rows, no luggage space.
- **Dark**: With `colorScheme="dark"`: graphite panels, the train in dim grey lines, the stripe and the selection still blue.

## How it works

- The viewer is a camera on the whole train: 16 cars (and a stretch of bare track at each end) stand side by side, each 77% of the viewer wide, and the strip moves by translateX(50% − (car + 1.5) × 77%) over 700 ms on cubic-bezier(0.65, 0, 0.25, 1). The cars beside the one in focus drop to 40% opacity in 500 ms, and a mask fades the strip to nothing over its outer 13%.
- Each car is one SVG on a 1027 × 250 grid: a 1000-unit body and 27 units of gangway shared with the next car, so the cars meet at their bellows and their rails and 40 sleepers per car join into one track. The track height follows the viewer’s width with a container unit: 0.77 × 0.2434 × its width.
- The nose car draws its front 330 units out into a long, low curve with a canopy set into it and the livery stripe sweeping down to the tip; the tail car is the same drawing mirrored. Ordinary cars have a ribbon window band with one window per seat row, a plug door at each end and the stripe below; premier cars add a gold line, cars 05 and 13 a pantograph on a roof fairing.
- Strokes stay 1 px at every scale (vector-effect: non-scaling-stroke), so the same drawing is the 700 px car on the rails and the 116 px silhouette on a card, which leaves out the windows and the small parts.
- The seat map is a grid of rows A to E across a 3 + 2 car (A to D in a 2 + 2 premier car), the aisle a 12 px gap. Seats share the width from 44 down to 28 px each, then the map scrolls in its own box. Bookings come from a seeded generator, so server and browser agree.
- Layout follows the component’s own width: a ResizeObserver turns the 252 px sidebar into a drawer under 1000 px (260 ms slide, Escape or the scrim closes it), and container queries fold the six figures to three columns under 900 px and two under 560. The car cards, 138 px each, scroll and snap in their strip, which follows the car in focus.
- While on screen and untouched, a demo pointer steps to car 05, picks two seats, jumps to a premier car, steps back and returns to car 04, then puts its seats back. Any input of the reader’s stops it for good; with reduced motion it does not play and the train jumps instead of sliding.
- Every colour is a token on the root, light-dark() where the two schemes differ: graphite panels and dim grey lines at night, pale greys by day; the stripe and the selection stay blue, faults amber, luggage red.

## API reference

- **defaultCar** (`number`, default `4`): The car in focus at first, 1 to 16.
- **onCarChange** (`(car: number) => void`): Called with the car number when the car in focus changes.
- **onSeatToggle** (`(car: number, seat: string, selected: boolean) => void`): Called when a seat is selected or cleared, with its car and its number ("7C").
- **autoplay** (`boolean`, default `true`): While on screen and untouched, a demo pointer steps through cars and seats; 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`): A class for the root.

## Accessibility

### Keyboard

- The seat map is one tab stop: the arrows move between seats, Home and End go along a row (with Ctrl, to the corners), Enter or Space toggles a seat.
- The car cards are one tab stop too: the arrows change the car and follow it with the focus.
- The service tabs move with the arrows; the terminal menu opens with Enter and closes with Escape; `/` goes to the search.

### Screen readers

- Each seat is a toggle button named with its number, window, booked or free, and selected; luggage spaces are named and disabled.
- A polite live region says the new car and its load (“Car 05 of 16, M-1205: 72 of 88 seats booked. Open defect: HVAC degraded.”) or the seat toggled.
- The train drawing is hidden from screen readers: the counter and the caption say the same in words.

### Motion

With reduced motion the train jumps to the car without sliding, the drawer appears at once and the demo does not play.

### In this build

- The seat map is a grid with one tab stop: the arrows move between seats, Home and End along a row (with Ctrl, to the corners), Enter or Space toggles. Each seat is a toggle button named with its number, window, booked or free and selected; luggage spaces are named and disabled.
- The car cards are one tab stop: the arrows, Home and End change the car and move the focus with it. Prev and next are buttons, disabled at the ends.
- A polite live region says the new car and its load, any open defect, or the seat toggled; Validate consist says what it found.
- The service tabs are a tablist moved with the arrows; the terminal picker is a menu of radio items that closes with Escape; “/” goes to the search.
- Under 1000 px the sidebar is a drawer: inert while closed, it takes the focus when opened and gives it back to the menu button; Escape closes it.
- The train drawing and the silhouettes are hidden from screen readers; the counter and the caption say the same in words. Every control shows a focus ring.
- With reduced motion the train and the drawer move at once and the demo does not play.

## Source

### consist-planner/consist-planner.tsx

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

'use client';

import {
  useEffect,
  useEffectEvent,
  useId,
  useLayoutEffect,
  useRef,
  useState,
  type CSSProperties,
  type KeyboardEvent as ReactKeyboardEvent,
} from 'react';
import {
  CARS,
  CATEGORIES,
  LAYOUTS,
  SEATS,
  START_CAR,
  START_SEATS,
  TERMINALS,
  WATCHLIST,
  bookedIn,
  capacity,
  type Seat,
} from './data';
import { DemoPointer, runDemo, type Point } from './demo-pointer';
import { Icon, type IconName } from './icons';
import { CarArt, Track } from './train-art';
import { useAutoplay } from './use-autoplay';
import styles from './consist-planner.module.css';

/*
 * Consist planner: an operations screen for one sixteen-car high-speed set before it leaves.
 * A sidebar (terminal, search, navigation, watchlist, the next departure), a page header with
 * the draft and validation actions, service tabs, and the planner card: the consist's header,
 * six figures, the car viewer with that car's seat map, and the car sequence.
 *
 * - The viewer is a camera on the whole train: the sixteen cars stand side by side on one track,
 *   each 77% of the viewer wide, and the strip slides (transform only, 700 ms) to centre the car
 *   in focus. The cars beside it show at the edges, faded by a mask and dimmed.
 * - The seat map is that car's seats as a grid (rows A to E across a 3 + 2 car, A to D in a
 *   premier car, the aisle as a gap), booked, free, selected or luggage. Seats are toggle
 *   buttons; the arrows move between them (one tab stop), Enter or Space toggles.
 * - Prev and next, the car cards (arrows move along them too), Validate (which goes to the car
 *   with an open defect) and the watchlist all change the car; a polite live region says the car
 *   and its load, or the seat toggled.
 * - Layout follows the component's own width (a ResizeObserver for the sidebar, container
 *   queries for the rest): under 1000 px the sidebar becomes a drawer behind a menu button; the
 *   figures fold to three, then two columns; the seat map and the car cards scroll inside their
 *   own boxes, so a phone never scrolls sideways.
 * - While on screen and untouched, a demo pointer steps through the cars, picks seats and a car
 *   card; any input from the reader stops it for good.
 */

/** Below this width (px) the sidebar is a drawer. */
const DRAWER_BELOW = 1000;

const NAV: { id: string; label: string; icon: IconName }[] = [
  { id: 'home', label: 'Home', icon: 'home' },
  { id: 'planner', label: 'Consist Planner', icon: 'train' },
  { id: 'fleet', label: 'Fleet Inventory', icon: 'grid' },
  { id: 'platforms', label: 'Platform Board', icon: 'box' },
  { id: 'routes', label: 'Routes & Timetables', icon: 'route' },
  { id: 'line', label: 'Line Control', icon: 'signal' },
  { id: 'depot', label: 'Depot Maintenance', icon: 'wrench' },
  { id: 'reports', label: 'Reports', icon: 'chart' },
];
const SETS = ['H-12', 'H-14', 'H-17'];

const pad = (n: number) => String(n).padStart(2, '0');
const percent = (part: number, whole: number) => Math.round((part / whole) * 100);

/** What a car's seat is, in words, for its name. */
function seatName(seat: Seat, selected: boolean, byWindow: boolean) {
  if (seat.luggage) return `${seat.id}, luggage space`;
  const parts = [`Seat ${seat.id}`];
  if (byWindow) parts.push('window');
  parts.push(seat.booked ? 'booked' : 'free');
  if (selected) parts.push('selected');
  return parts.join(', ');
}

export function ConsistPlanner({
  defaultCar = START_CAR,
  onCarChange,
  onSeatToggle,
  autoplay = true,
  colorScheme,
  className = '',
}: {
  /** The car in focus at first, 1 to 16. */
  defaultCar?: number;
  /** Called with the car number (1 to 16) when the car in focus changes. */
  onCarChange?: (car: number) => void;
  /** Called when a seat is selected or cleared, with the car number and the seat ("7C"). */
  onSeatToggle?: (car: number, seat: string, selected: boolean) => void;
  /** While on screen and untouched, a demo pointer steps through cars and seats. */
  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 start = Math.min(CARS.length, Math.max(1, Math.round(defaultCar))) - 1;
  const [car, setCar] = useState(start);
  const [selected, setSelected] = useState<Record<number, string[]>>(START_SEATS);
  const [cursor, setCursor] = useState({ row: 2, col: 6 });
  const [tab, setTab] = useState('express');
  const [terminal, setTerminal] = useState(0);
  const [terminalOpen, setTerminalOpen] = useState(false);
  const [nav, setNav] = useState('planner');
  const [set, setSet] = useState(SETS[0]);
  const [query, setQuery] = useState('');
  const [narrow, setNarrow] = useState(false);
  const [drawer, setDrawer] = useState(false);
  const [validated, setValidated] = useState(false);
  const [saved, setSaved] = useState(false);
  const [full, setFull] = useState(false);
  const [message, setMessage] = useState('');

  const id = useId();
  const card = useRef<HTMLElement>(null);
  const sidebar = useRef<HTMLElement>(null);
  const menuButton = useRef<HTMLButtonElement>(null);
  const terminalButton = useRef<HTMLButtonElement>(null);
  const terminalMenu = useRef<HTMLDivElement>(null);
  const searchField = useRef<HTMLInputElement>(null);
  const seatButtons = useRef(new Map<string, HTMLButtonElement>());
  const carButtons = useRef<(HTMLButtonElement | null)[]>([]);
  const tabButtons = useRef<(HTMLButtonElement | null)[]>([]);
  const strip = useRef<HTMLOListElement>(null);
  const seatScroll = useRef<HTMLDivElement>(null);
  const prevButton = useRef<HTMLButtonElement>(null);
  const nextButton = useRef<HTMLButtonElement>(null);
  const pointer = useRef<HTMLSpanElement>(null);
  const savedTimer = useRef(0);

  const current = CARS[car];
  const layout = LAYOUTS[current.kind];
  const seats = SEATS[car];
  const picked = selected[current.n] ?? [];
  const booked = bookedIn(car);
  const places = capacity(car);
  const totalPlaces = CARS.reduce((sum, _, index) => sum + capacity(index), 0);
  const totalBooked = CARS.reduce((sum, _, index) => sum + bookedIn(index), 0);
  const alertCar = CARS.find((each) => each.alert);

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

  const carWords = (index: number) => {
    const each = CARS[index];
    const alert = each.alert ? ` Open defect: ${each.alert}.` : '';
    return `Car ${pad(each.n)} of ${CARS.length}, ${each.code}: ${bookedIn(index)} of ${capacity(index)} seats booked.${alert}`;
  };

  const goCar = (index: number, say = true) => {
    const next = Math.max(0, Math.min(CARS.length - 1, index));
    if (next === car) return;
    setCar(next);
    // The roving seat goes back to the first seat, which every car has.
    setCursor({ row: 0, col: 0 });
    seatScroll.current?.scrollTo({ left: 0 });
    onCarChange?.(CARS[next].n);
    if (say) announce(carWords(next));
  };

  const toggleSeat = (seat: Seat) => {
    if (seat.luggage) return;
    const on = !picked.includes(seat.id);
    setSelected((now) => {
      const list = now[current.n] ?? [];
      return {
        ...now,
        [current.n]: on ? [...list, seat.id] : list.filter((each) => each !== seat.id),
      };
    });
    onSeatToggle?.(current.n, seat.id, on);
    announce(`Seat ${seat.id} ${on ? 'selected' : 'cleared'}, ${seat.booked ? 'booked' : 'free'}.`);
  };

  const reset = () => {
    setCar(START_CAR - 1);
    setSelected(START_SEATS);
    setCursor({ row: 2, col: 6 });
    setValidated(false);
    if (car !== START_CAR - 1) onCarChange?.(START_CAR);
    announce(`Consist reset. ${carWords(START_CAR - 1)}`);
  };

  const validate = () => {
    setValidated(true);
    if (!alertCar) return announce('Consist validated: no open issues.');
    goCar(alertCar.n - 1, false);
    announce(
      `Validation found 1 issue: ${alertCar.alert} in car ${pad(alertCar.n)}. Showing car ${pad(alertCar.n)}.`,
    );
  };

  const saveDraft = () => {
    setSaved(true);
    announce('Draft saved.');
    window.clearTimeout(savedTimer.current);
    savedTimer.current = window.setTimeout(() => setSaved(false), 2000);
  };
  useEffect(() => () => window.clearTimeout(savedTimer.current), []);

  const toggleFull = () => {
    const element = card.current;
    if (!element) return;
    if (document.fullscreenElement) void document.exitFullscreen();
    else element.requestFullscreen?.().catch(() => {});
  };
  useEffect(() => {
    const update = () => setFull(document.fullscreenElement === card.current);
    document.addEventListener('fullscreenchange', update);
    return () => document.removeEventListener('fullscreenchange', update);
  }, []);

  // The sidebar's mode follows the component's own width, not the window's.
  useLayoutEffect(() => {
    const element = root.current;
    if (!element) return;
    const observer = new ResizeObserver(([entry]) => {
      const isNarrow = entry.contentRect.width < DRAWER_BELOW;
      setNarrow(isNarrow);
      if (!isNarrow) setDrawer(false);
    });
    observer.observe(element);
    return () => observer.disconnect();
  }, [root]);

  // The drawer takes the focus when it opens, and gives it back to the menu button.
  const drawerWas = useRef(false);
  useEffect(() => {
    if (drawer) sidebar.current?.querySelector<HTMLElement>('button, input')?.focus();
    else if (drawerWas.current) menuButton.current?.focus();
    drawerWas.current = drawer;
  }, [drawer]);

  // Keep the car in focus in view in the sequence strip, scrolling only the strip itself.
  useEffect(() => {
    const list = strip.current;
    const button = carButtons.current[car];
    if (!list || !button) return;
    const item = button.parentElement as HTMLElement;
    const left = item.offsetLeft - list.offsetLeft;
    const right = left + item.offsetWidth;
    const smooth = !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (left < list.scrollLeft + 8 || right > list.scrollLeft + list.clientWidth - 8) {
      list.scrollTo({
        left: left - (list.clientWidth - item.offsetWidth) / 2,
        behavior: smooth ? 'smooth' : 'auto',
      });
    }
  }, [car]);

  // A press outside the terminal menu closes it.
  useEffect(() => {
    if (!terminalOpen) return;
    const onDown = (event: PointerEvent) => {
      const target = event.target as Node;
      if (terminalMenu.current?.contains(target) || terminalButton.current?.contains(target))
        return;
      setTerminalOpen(false);
    };
    document.addEventListener('pointerdown', onDown);
    terminalMenu.current?.querySelector<HTMLElement>('[aria-checked="true"]')?.focus();
    return () => document.removeEventListener('pointerdown', onDown);
  }, [terminalOpen]);

  const onTerminalKey = (event: ReactKeyboardEvent) => {
    const items = [...(terminalMenu.current?.querySelectorAll<HTMLElement>('[role]') ?? [])];
    const at = items.indexOf(document.activeElement as HTMLElement);
    if (event.key === 'Escape') {
      event.preventDefault();
      setTerminalOpen(false);
      terminalButton.current?.focus();
    } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
      event.preventDefault();
      const step = event.key === 'ArrowDown' ? 1 : -1;
      items[(at + step + items.length) % items.length]?.focus();
    } else if (event.key === 'Tab') setTerminalOpen(false);
  };

  // "/" anywhere in the planner (outside a field) goes to the search, as the hint says.
  const onRootKey = (event: ReactKeyboardEvent) => {
    const target = event.target as HTMLElement;
    if (event.key === 'Escape' && drawer) {
      setDrawer(false);
      return;
    }
    if (event.key !== '/' || target.closest('input, textarea')) return;
    event.preventDefault();
    if (narrow) setDrawer(true);
    window.setTimeout(() => searchField.current?.focus(), 0);
  };

  const onSeatKey = (event: ReactKeyboardEvent) => {
    const rows = layout.letters.length;
    const cols = current.rows;
    let { row, col } = cursor;
    switch (event.key) {
      case 'ArrowRight':
        col = Math.min(cols - 1, col + 1);
        break;
      case 'ArrowLeft':
        col = Math.max(0, col - 1);
        break;
      case 'ArrowDown':
        row = Math.min(rows - 1, row + 1);
        break;
      case 'ArrowUp':
        row = Math.max(0, row - 1);
        break;
      case 'Home':
        col = 0;
        if (event.ctrlKey) row = 0;
        break;
      case 'End':
        col = cols - 1;
        if (event.ctrlKey) row = rows - 1;
        break;
      default:
        return;
    }
    event.preventDefault();
    setCursor({ row, col });
    seatButtons.current.get(`${col + 1}${layout.letters[row]}`)?.focus();
  };

  const onCarKey = (event: ReactKeyboardEvent, index: number) => {
    const to =
      event.key === 'ArrowRight'
        ? index + 1
        : event.key === 'ArrowLeft'
          ? index - 1
          : event.key === 'Home'
            ? 0
            : event.key === 'End'
              ? CARS.length - 1
              : null;
    if (to === null) return;
    event.preventDefault();
    const next = Math.max(0, Math.min(CARS.length - 1, to));
    goCar(next);
    carButtons.current[next]?.focus();
  };

  const onTabKey = (event: ReactKeyboardEvent, index: number) => {
    const count = CATEGORIES.length;
    const to =
      event.key === 'ArrowRight'
        ? (index + 1) % count
        : event.key === 'ArrowLeft'
          ? (index - 1 + count) % count
          : event.key === 'Home'
            ? 0
            : event.key === 'End'
              ? count - 1
              : null;
    if (to === null) return;
    event.preventDefault();
    setTab(CATEGORIES[to].id);
    tabButtons.current[to]?.focus();
  };

  // The demo: next car, two seats, a car card, back, and home to car 04; in a loop.
  const demoAct = useEffectEvent((act: { car: number } | { step: 1 | -1 } | { seat: string }) => {
    if ('car' in act) goCar(act.car);
    else if ('step' in act) goCar(car + act.step);
    else {
      const seat = SEATS[car].find((each) => each.id === act.seat);
      if (seat) toggleSeat(seat);
    }
  });
  const demo = autoplay && playing;
  useEffect(() => {
    const stage = root.current;
    const arrow = pointer.current;
    if (!demo || !stage || !arrow) return;
    const stop = runDemo(stage, arrow, async ({ wait, glide, glyph }) => {
      /** The middle of an element, in the stage's own px. */
      const at = (element: Element | null | undefined, dx = 0, dy = 0): Point => {
        const frame = stage.getBoundingClientRect();
        const scale = frame.width / stage.offsetWidth || 1;
        if (!element) return { x: stage.offsetWidth * 0.6, y: stage.offsetHeight * 0.5 };
        const rect = element.getBoundingClientRect();
        return {
          x: (rect.left + rect.width / 2 - frame.left) / scale + dx,
          y: (rect.top + rect.height / 2 - frame.top) / scale + dy,
        };
      };
      const press = async (element: Element | null | undefined, ms = 700) => {
        await glide(at(element, 3, 4), ms);
        glyph('hand');
        await wait(220);
      };
      const rest = async (ms: number) => {
        glyph('arrow');
        await wait(ms);
      };
      for (;;) {
        await wait(1400);
        await press(nextButton.current, 900);
        demoAct({ step: 1 });
        await rest(1500);
        await press(seatButtons.current.get('3B'), 800);
        demoAct({ seat: '3B' });
        await rest(700);
        await press(seatButtons.current.get('6D'), 520);
        demoAct({ seat: '6D' });
        await rest(1300);
        await press(carButtons.current[7], 900);
        demoAct({ car: 7 });
        await rest(1700);
        await press(prevButton.current, 900);
        demoAct({ step: -1 });
        await rest(1400);
        await press(carButtons.current[START_CAR - 1], 800);
        demoAct({ car: START_CAR - 1 });
        await rest(1200);
        await glide(at(stage.querySelector('[data-part="train"]'), 120, 30), 900);
        await wait(1600);
        // Car 05's two seats again, so the loop leaves the plan as it found it.
        await press(nextButton.current, 900);
        demoAct({ step: 1 });
        await rest(900);
        await press(seatButtons.current.get('3B'), 700);
        demoAct({ seat: '3B' });
        await rest(500);
        await press(seatButtons.current.get('6D'), 500);
        demoAct({ seat: '6D' });
        await rest(900);
        await press(prevButton.current, 800);
        demoAct({ step: -1 });
        await rest(1200);
      }
    });
    return stop;
  }, [demo, root]);

  const matches = (label: string) => label.toLowerCase().includes(query.trim().toLowerCase());
  const navShown = NAV.filter((item) => matches(item.label));
  const sideHidden = narrow && !drawer;
  const terminalNow = TERMINALS[terminal];
  const category = CATEGORIES.find((each) => each.id === tab) ?? CATEGORIES[1];
  const firstSeat = `${cursor.col + 1}${layout.letters[cursor.row]}`;
  const neighbour = (index: number) =>
    index >= 0 && index < CARS.length ? `${pad(CARS[index].n)} ${CARS[index].code}` : '';

  return (
    // The keys here only catch what bubbles from the controls inside: Escape and "/".
    // eslint-disable-next-line jsx-a11y/no-static-element-interactions
    <div
      ref={root}
      className={`${styles.root} ${className}`}
      data-color-scheme={colorScheme}
      data-narrow={narrow}
      data-drawer={drawer}
      data-part="root"
      onPointerDownCapture={take}
      onKeyDownCapture={take}
      onWheelCapture={take}
      onKeyDown={onRootKey}
    >
      <aside
        ref={sidebar}
        id={`${id}-side`}
        className={styles.side}
        aria-label="Sidebar"
        inert={sideHidden}
        data-part="sidebar"
      >
        <div className={styles.brand}>
          <span className={styles.logo}>
            <Icon name="mark" />
          </span>
          <span className={styles.brandText}>
            <strong>Senro Desk</strong>
            <span>High-speed operations</span>
          </span>
          {narrow && (
            <button
              type="button"
              className={styles.iconButton}
              aria-label="Close menu"
              onClick={() => setDrawer(false)}
            >
              <Icon name="close" />
            </button>
          )}
        </div>

        <div className={styles.eyebrow} id={`${id}-terminal`}>
          Terminal
        </div>
        <div className={styles.terminalWrap}>
          <button
            ref={terminalButton}
            type="button"
            className={styles.terminal}
            aria-haspopup="menu"
            aria-expanded={terminalOpen}
            aria-controls={`${id}-terminals`}
            aria-labelledby={`${id}-terminal ${id}-terminal-name`}
            onClick={() => setTerminalOpen((open) => !open)}
            data-part="terminal"
          >
            <span className={styles.terminalPin}>
              <Icon name="pin" />
            </span>
            <span className={styles.terminalText} id={`${id}-terminal-name`}>
              <strong>{terminalNow.name}</strong>
              <span>{terminalNow.division}</span>
            </span>
            <Icon name="updown" className={styles.muted} />
          </button>
          {terminalOpen && (
            // The focus goes to its items, never to the menu itself.
            // eslint-disable-next-line jsx-a11y/interactive-supports-focus
            <div
              ref={terminalMenu}
              id={`${id}-terminals`}
              role="menu"
              aria-label="Terminal"
              className={styles.menu}
              onKeyDown={onTerminalKey}
            >
              {TERMINALS.map((each, index) => (
                <button
                  key={each.id}
                  type="button"
                  role="menuitemradio"
                  aria-checked={index === terminal}
                  tabIndex={-1}
                  className={styles.menuItem}
                  onClick={() => {
                    setTerminal(index);
                    setTerminalOpen(false);
                    terminalButton.current?.focus();
                  }}
                >
                  <strong>{each.name}</strong>
                  <span>{each.division}</span>
                </button>
              ))}
            </div>
          )}
        </div>

        <label className={styles.search}>
          <Icon name="search" className={styles.muted} />
          <input
            ref={searchField}
            type="search"
            placeholder="Search"
            aria-label="Search the menu"
            value={query}
            onChange={(event) => setQuery(event.target.value)}
            onKeyDown={(event) => {
              if (event.key === 'Escape' && query) {
                event.stopPropagation();
                setQuery('');
              }
            }}
          />
          <kbd aria-hidden="true">/</kbd>
        </label>

        <nav className={styles.nav} aria-label="Main">
          <ul>
            {navShown.map((item) => {
              const on = nav === item.id;
              if (item.id === 'planner')
                return (
                  <li key={item.id} className={styles.group}>
                    <button
                      type="button"
                      className={styles.navItem}
                      aria-current={on ? 'page' : undefined}
                      onClick={() => setNav(item.id)}
                    >
                      <Icon name={item.icon} />
                      <span>{item.label}</span>
                      <Icon name="chevron-down" className={styles.chev} />
                    </button>
                    <ul aria-label="Sets">
                      {SETS.map((each) => (
                        <li key={each}>
                          <button
                            type="button"
                            className={styles.setItem}
                            aria-current={each === set ? 'true' : undefined}
                            onClick={() => setSet(each)}
                          >
                            <span className={styles.setDot} aria-hidden="true" />
                            {each}
                          </button>
                        </li>
                      ))}
                    </ul>
                  </li>
                );
              return (
                <li key={item.id}>
                  <button
                    type="button"
                    className={styles.navItem}
                    aria-current={on ? 'page' : undefined}
                    onClick={() => setNav(item.id)}
                  >
                    <Icon name={item.icon} />
                    <span>{item.label}</span>
                    <Icon name="chevron-right" className={styles.chev} />
                  </button>
                </li>
              );
            })}
          </ul>
          {navShown.length === 0 && <p className={styles.empty}>No pages match “{query}”.</p>}
        </nav>

        <section className={styles.watch} aria-labelledby={`${id}-watch`}>
          <h3 className={styles.eyebrow} id={`${id}-watch`}>
            Watchlist
          </h3>
          <ul>
            {WATCHLIST.map((item) => (
              <li key={item.text}>
                <span className={styles.dot} data-tone={item.tone} aria-hidden="true" />
                {item.text}
              </li>
            ))}
          </ul>
        </section>

        <ul className={styles.utility}>
          {(
            [
              ['settings', 'Settings', 'gear'],
              ['help', 'Help', 'help'],
            ] as const
          ).map(([key, label, icon]) => (
            <li key={key}>
              <button
                type="button"
                className={styles.navItem}
                aria-current={nav === key ? 'page' : undefined}
                onClick={() => setNav(key)}
              >
                <Icon name={icon} />
                <span>{label}</span>
              </button>
            </li>
          ))}
        </ul>

        <section className={styles.next} aria-label="Next departure" data-part="next-departure">
          <div className={styles.nextTop}>
            <span className={styles.nextTag}>Next departure</span>
            <span className={styles.mono}>14:40</span>
          </div>
          <strong>H-12 · Kazehaya 23</strong>
          <span className={styles.muted}>Track 18 · readiness 83%</span>
          <span
            className={styles.bar}
            role="meter"
            aria-label="Readiness"
            aria-valuemin={0}
            aria-valuemax={100}
            aria-valuenow={83}
          >
            <span style={{ width: '83%' }} />
          </span>
          <span className={styles.amber}>2 items need review</span>
        </section>

        <div className={styles.user}>
          <span className={styles.avatar} aria-hidden="true">
            HM
          </span>
          <span className={styles.userText}>
            <strong>Haruka Mori</strong>
            <span>Operations manager</span>
          </span>
        </div>
      </aside>

      {narrow && drawer && (
        <div className={styles.scrim} aria-hidden="true" onClick={() => setDrawer(false)} />
      )}

      <main className={styles.main}>
        {narrow && (
          <div className={styles.topbar}>
            <button
              ref={menuButton}
              type="button"
              className={styles.iconButton}
              aria-label="Open menu"
              aria-expanded={drawer}
              aria-controls={`${id}-side`}
              onClick={() => setDrawer(true)}
            >
              <Icon name="menu" />
            </button>
            <span className={styles.logo}>
              <Icon name="mark" />
            </span>
            <strong>Senro Desk</strong>
          </div>
        )}

        <header className={styles.header}>
          <div>
            <nav aria-label="Breadcrumb" className={styles.crumbs}>
              <ol>
                <li>Home</li>
                <li aria-current="page">Consist Planner</li>
              </ol>
            </nav>
            <h2 className={styles.title}>Consist Planner</h2>
            <p className={styles.subtitle}>
              Car occupancy, seat map and pre-departure checks for high-speed services.
            </p>
          </div>
          <div className={styles.actions}>
            <button type="button" className={styles.button} onClick={saveDraft}>
              <Icon name={saved ? 'check' : 'save'} />
              {saved ? 'Draft saved' : 'Save draft'}
            </button>
            <button
              type="button"
              className={`${styles.button} ${styles.primary}`}
              onClick={validate}
              data-part="validate"
            >
              <Icon name="check" />
              Validate consist
            </button>
          </div>
        </header>

        <div className={styles.tabsScroll}>
          <div role="tablist" aria-label="Services" className={styles.tabs} data-part="tabs">
            {CATEGORIES.map((each, index) => (
              <button
                key={each.id}
                ref={(element) => {
                  tabButtons.current[index] = element;
                }}
                type="button"
                role="tab"
                id={`${id}-tab-${each.id}`}
                aria-selected={each.id === tab}
                aria-controls={`${id}-panel`}
                tabIndex={each.id === tab ? 0 : -1}
                className={styles.tab}
                onClick={() => setTab(each.id)}
                onKeyDown={(event) => onTabKey(event, index)}
              >
                {each.label}
                <span className={styles.count}>{each.count}</span>
              </button>
            ))}
          </div>
        </div>

        <section
          ref={card}
          id={`${id}-panel`}
          role="tabpanel"
          aria-labelledby={`${id}-tab-${tab}`}
          className={styles.planner}
          data-part="planner"
        >
          <div className={styles.consist} data-part="consist-header">
            <div className={styles.consistId}>
              <span className={styles.eyebrow}>{category.label} consist</span>
              <strong>H-12</strong>
            </div>
            <dl className={styles.facts}>
              <div>
                <dt>Service</dt>
                <dd>Kazehaya 23</dd>
              </div>
              <div>
                <dt>Route</dt>
                <dd>Tokyo → Shin-Osaka</dd>
              </div>
              <div>
                <dt>Departure</dt>
                <dd>14:40 · Track 18</dd>
              </div>
            </dl>
            <span className={styles.pill} data-part="check-pill">
              <span className={styles.dot} data-tone="amber" aria-hidden="true" />
              {validated && alertCar ? `1 issue · car ${pad(alertCar.n)}` : 'Pre-departure check'}
            </span>
            <div className={styles.tools}>
              <button
                type="button"
                className={styles.iconButton}
                aria-label="Reset consist"
                title="Reset consist"
                onClick={reset}
              >
                <Icon name="reset" />
              </button>
              <button
                type="button"
                className={styles.iconButton}
                aria-label={full ? 'Exit full screen' : 'Full screen'}
                title={full ? 'Exit full screen' : 'Full screen'}
                onClick={toggleFull}
              >
                <Icon name={full ? 'collapse' : 'expand'} />
              </button>
            </div>
          </div>

          <dl className={styles.kpis} data-part="kpis">
            <div>
              <dt>
                <span className={styles.dot} data-tone="green" aria-hidden="true" />
                Power
              </dt>
              <dd>14 motor cars</dd>
              <dd className={styles.muted}>Pantographs 05 · 13 up</dd>
            </div>
            <div>
              <dt>Crew</dt>
              <dd>Kenji Arai</dd>
              <dd className={styles.muted}>Conductor · Yui Takeda</dd>
            </div>
            <div>
              <dt>Load</dt>
              <dd>
                {totalBooked.toLocaleString('en-US')} / {totalPlaces.toLocaleString('en-US')} seats
              </dd>
              <dd className={styles.muted}>{totalPlaces - totalBooked} seats free</dd>
            </div>
            <div>
              <dt>Position</dt>
              <dd>Tokyo · track 18</dd>
              <dd className={styles.muted}>Boarding opens 14:28</dd>
            </div>
            <div>
              <dt>ETA</dt>
              <dd>Shin-Osaka 17:05</dd>
              <dd className={styles.muted}>2 h 25 min run</dd>
            </div>
            <div>
              <dt>Next action</dt>
              <dd className={styles.amber}>Fix HVAC in car 05</dd>
              <dd className={styles.muted}>Before 14:30</dd>
            </div>
          </dl>

          <div className={styles.viewer} data-part="viewer">
            <div className={styles.viewerBar}>
              <ul className={styles.legend} aria-label="Legend">
                <li>
                  <span data-swatch="selected" aria-hidden="true" />
                  Selected seat
                </li>
                <li>
                  <span data-swatch="booked" aria-hidden="true" />
                  Booked
                </li>
                <li>
                  <span data-swatch="free" aria-hidden="true" />
                  Free
                </li>
                <li>
                  <span data-swatch="luggage" aria-hidden="true" />
                  Luggage
                </li>
              </ul>
              <div className={styles.viewerNav}>
                {alertCar && (
                  <button
                    type="button"
                    className={styles.pill}
                    onClick={() => goCar(alertCar.n - 1)}
                    aria-label={`Go to car ${pad(alertCar.n)}: ${alertCar.alert}`}
                  >
                    <span className={styles.dot} data-tone="amber" aria-hidden="true" />
                    {pad(alertCar.n)} · {alertCar.alert}
                  </button>
                )}
                <span className={styles.counter} data-part="counter">
                  Car {pad(current.n)} of {CARS.length} · {current.code}
                </span>
                <span className={styles.step}>
                  <button
                    ref={prevButton}
                    type="button"
                    className={styles.iconButton}
                    aria-label="Previous car"
                    disabled={car === 0}
                    onClick={() => goCar(car - 1)}
                  >
                    <Icon name="chevron-left" />
                  </button>
                  <button
                    ref={nextButton}
                    type="button"
                    className={styles.iconButton}
                    aria-label="Next car"
                    disabled={car === CARS.length - 1}
                    onClick={() => goCar(car + 1)}
                  >
                    <Icon name="chevron-right" />
                  </button>
                </span>
              </div>
            </div>

            <div className={styles.train} data-part="train" aria-hidden="true">
              <div className={styles.strip} style={{ '--i': car } as CSSProperties}>
                {[-1, ...CARS.map((_, index) => index), CARS.length].map((slot) => (
                  <div
                    key={slot}
                    className={styles.slot}
                    style={{ '--k': slot + 1 } as CSSProperties}
                    data-current={slot === car}
                  >
                    {slot < 0 || slot >= CARS.length ? (
                      <svg viewBox="0 0 1027 250" className={styles.art}>
                        <Track />
                      </svg>
                    ) : (
                      <CarArt car={CARS[slot]} className={styles.art} />
                    )}
                  </div>
                ))}
              </div>
            </div>

            <div ref={seatScroll} className={styles.seatScroll} data-part="seat-map">
              {/* One seat is the grid's tab stop (a roving tabindex), not the grid itself. */}
              {/* eslint-disable-next-line jsx-a11y/interactive-supports-focus */}
              <div
                role="grid"
                aria-label={`Seat map, car ${pad(current.n)}, ${current.code}`}
                aria-rowcount={layout.letters.length}
                aria-colcount={current.rows}
                className={styles.seats}
                style={{ '--cols': current.rows } as CSSProperties}
                onKeyDown={onSeatKey}
              >
                {layout.letters.map((letter, rowIndex) => (
                  <div
                    key={letter}
                    role="row"
                    className={styles.seatRow}
                    data-aisle={rowIndex === layout.aisle || undefined}
                  >
                    {seats
                      .filter((seat) => seat.letter === letter)
                      .map((seat) => {
                        const on = picked.includes(seat.id);
                        const byWindow = rowIndex === 0 || rowIndex === layout.letters.length - 1;
                        return (
                          <div key={seat.id} role="gridcell">
                            <button
                              ref={(element) => {
                                if (element) seatButtons.current.set(seat.id, element);
                                else seatButtons.current.delete(seat.id);
                              }}
                              type="button"
                              className={styles.seat}
                              data-state={
                                seat.luggage
                                  ? 'luggage'
                                  : on
                                    ? 'selected'
                                    : seat.booked
                                      ? 'booked'
                                      : 'free'
                              }
                              aria-pressed={seat.luggage ? undefined : on}
                              aria-disabled={seat.luggage || undefined}
                              aria-label={seatName(seat, on, byWindow)}
                              tabIndex={seat.id === firstSeat ? 0 : -1}
                              onFocus={() => setCursor({ row: rowIndex, col: seat.row - 1 })}
                              onClick={() => toggleSeat(seat)}
                            >
                              {seat.luggage ? '' : seat.id}
                            </button>
                          </div>
                        );
                      })}
                  </div>
                ))}
              </div>
            </div>

            <p className={styles.caption} data-part="caption">
              <span className={styles.side2} aria-hidden="true">
                {neighbour(car - 1)}
              </span>
              <span className={styles.captionMain}>
                <span>{pad(current.n)}</span>
                <span className={styles.blue}>{current.code}</span>
                <span className={styles.dot} data-tone="blue" aria-hidden="true" />
                <span>
                  {booked} of {places} seats booked · {percent(booked, places)}%
                  {picked.length > 0 && ` · ${picked.length} selected`}
                </span>
              </span>
              <span className={styles.side2} aria-hidden="true">
                {neighbour(car + 1)}
              </span>
            </p>
          </div>

          <div className={styles.sequence} data-part="sequence">
            <div className={styles.sequenceHead}>
              <h3 id={`${id}-sequence`}>Car sequence</h3>
              <p className={styles.muted}>
                Lead car at the Shin-Osaka end · car {pad(current.n)} in focus · use ‹ › or pick a
                car.
              </p>
              <span className={styles.blue}>Selected · {current.code}</span>
            </div>
            <ol ref={strip} className={styles.cars} aria-labelledby={`${id}-sequence`}>
              {CARS.map((each, index) => {
                const on = index === car;
                const load = bookedIn(index);
                const total = capacity(index);
                const kind =
                  each.kind === 'lead'
                    ? 'Lead car'
                    : each.kind === 'tail'
                      ? 'Tail car'
                      : each.kind === 'premier'
                        ? 'Premier'
                        : null;
                return (
                  <li key={each.n}>
                    <button
                      ref={(element) => {
                        carButtons.current[index] = element;
                      }}
                      type="button"
                      className={styles.carCard}
                      aria-current={on ? 'true' : undefined}
                      aria-label={`Car ${pad(each.n)}, ${each.code}${kind ? `, ${kind}` : ''}, ${load} of ${total} seats booked${each.alert ? `, ${each.alert}` : ''}`}
                      data-alert={each.alert ? true : undefined}
                      tabIndex={on ? 0 : -1}
                      onClick={() => goCar(index)}
                      onKeyDown={(event) => onCarKey(event, index)}
                      data-part="car-card"
                    >
                      <span className={styles.cardTop}>
                        <span>{pad(each.n)}</span>
                        <span
                          className={styles.dot}
                          data-tone={each.alert ? 'amber' : on ? 'blue' : 'grey'}
                        />
                      </span>
                      <CarArt car={each} mini className={styles.mini} />
                      <strong>{each.code}</strong>
                      <span className={styles.muted}>
                        {kind ? `${kind} · ` : ''}
                        {load} / {total}
                        {kind ? '' : ' seats'}
                      </span>
                      <span className={styles.cardBar}>
                        <span style={{ width: `${percent(load, total)}%` }} />
                      </span>
                    </button>
                  </li>
                );
              })}
            </ol>
          </div>
        </section>
      </main>

      <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}
          handClass={styles.hand}
        />
      </div>
    </div>
  );
}
```

### consist-planner/consist-planner.module.css

```css
/* Consist planner (consist-planner.tsx): an operations screen in graphite at night and in pale
   greys by day, blue for the selection and the actions, amber for what needs doing, red for
   luggage spaces and faults. The train is drawn in 1 px lines with one blue livery stripe.

   Colours are the tokens below, light-dark(light, dark) where the two differ: the planner takes
   the color-scheme it inherits from the page, or the one its colorScheme prop sets.

   Layout. The sidebar's mode comes from the script (data-narrow, under 1000 px of the
   component's own width: a drawer); everything else from container queries on the main column
   and the viewer: the six figures fold to three columns under 900 px and two under 560, the seat
   map and the car cards scroll inside their own boxes.

   Motion. Only transform and opacity move: the train strip slides 700 ms on
   cubic-bezier(0.65, 0, 0.25, 1), the cars beside the one in focus dim in 500 ms, the drawer
   slides in 260 ms. With reduced motion all of it is immediate. */

.root {
  --bg: #fff;
  --side: #f7f7f8;
  --panel: #fbfbfc;
  --viewer: #f2f3f5;
  --card: #fff;
  --card-on: #f1f5ff;
  --group: #f0f1f3;
  --chip: #fff;
  --chip-on: #e9ebef;
  --hover: #eceef1;
  --pop: #fff;
  --line: #e6e7ea;
  --line-2: #dcdee2;
  --ink: #17181b;
  --ink-2: #3a3c42;
  --muted: #696c74;
  --blue: #2f6bff;
  --blue-ink: #2257d6;
  --blue-soft: #e5edff;
  --amber: #a35f00;
  --amber-dot: #e8950f;
  --amber-soft: #fdf0d8;
  --red: #e25b5b;
  --red-dot: #e04848;
  --green: #1f9d55;
  --grey-dot: #a9acb3;
  --track: #e1e3e7;
  --seat-booked: #e2e4e8;
  --seat-ink: #2b2d33;
  --seat-free: #9b9ea6;
  --car-fill: #fdfdfe;
  --car-line: #8b8f98;
  --car-detail: #b4b7be;
  --car-band: #e5e7eb;
  --glass: #f6f7f9;
  --stripe: #2f6bff;
  --premier: #c7962c;
  --rail: #b9bcc3;
  --sleeper: #d9dbe0;
  --shadow: rgb(16 18 24 / 0.12);
  --scrim: rgb(10 12 16 / 0.35);
  --focus: #2f6bff;
  /* The demo's pointer looks like the system's, on both schemes. */
  --pointer: #1c1c1e;
  --pointer-edge: #fff;
  --pointer-shadow: rgb(0 0 0 / 0.25);
  --pitch: 0.77;

  position: relative;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  width: 100%;
  overflow: hidden;
  overflow: clip;
  border-radius: 16px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  font-size: 13px;
  line-height: 18px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-align: left;
}
@supports (color: light-dark(#fff, #000)) {
  .root {
    --bg: light-dark(#fff, #0e0f11);
    --side: light-dark(#f7f7f8, #111214);
    --panel: light-dark(#fbfbfc, #151619);
    --viewer: light-dark(#f2f3f5, #101113);
    --card: light-dark(#fff, #17181b);
    --card-on: light-dark(#f1f5ff, #1c1f27);
    --group: light-dark(#f0f1f3, #16171a);
    --chip: light-dark(#fff, #1b1c20);
    --chip-on: light-dark(#e9ebef, #25262b);
    --hover: light-dark(#eceef1, #1e1f23);
    --pop: light-dark(#fff, #1d1e22);
    --line: light-dark(#e6e7ea, #222327);
    --line-2: light-dark(#dcdee2, #2c2d32);
    --ink: light-dark(#17181b, #ececee);
    --ink-2: light-dark(#3a3c42, #c6c7cc);
    --muted: light-dark(#696c74, #8b8d94);
    --blue: light-dark(#2f6bff, #3f7bff);
    --blue-ink: light-dark(#2257d6, #7aa2ff);
    --blue-soft: light-dark(#e5edff, #172440);
    --amber: light-dark(#a35f00, #f2a93b);
    --amber-dot: light-dark(#e8950f, #f2a93b);
    --amber-soft: light-dark(#fdf0d8, #2e2312);
    --red: light-dark(#e25b5b, #e46464);
    --red-dot: light-dark(#e04848, #ef5b5b);
    --green: light-dark(#1f9d55, #3ccf7a);
    --grey-dot: light-dark(#a9acb3, #5d5f66);
    --track: light-dark(#e1e3e7, #2a2b30);
    --seat-booked: light-dark(#e2e4e8, #26272c);
    --seat-ink: light-dark(#2b2d33, #d6d7db);
    --seat-free: light-dark(#9b9ea6, #5c5e65);
    --car-fill: light-dark(#fdfdfe, #15161a);
    --car-line: light-dark(#8b8f98, #5d6069);
    --car-detail: light-dark(#b4b7be, #3b3d44);
    --car-band: light-dark(#e5e7eb, #0c0d0f);
    --glass: light-dark(#f6f7f9, #1c1e23);
    --stripe: light-dark(#2f6bff, #3a6fe6);
    --premier: light-dark(#c7962c, #b98a2a);
    --rail: light-dark(#b9bcc3, #3a3c42);
    --sleeper: light-dark(#d9dbe0, #222428);
    --shadow: light-dark(rgb(16 18 24 / 0.12), rgb(0 0 0 / 0.5));
    --scrim: light-dark(rgb(10 12 16 / 0.35), rgb(0 0 0 / 0.55));
    --focus: light-dark(#2f6bff, #6f9bff);
  }
}
.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[data-narrow='true'] {
  grid-template-columns: minmax(0, 1fr);
}
.root *,
.root *::before,
.root *::after {
  box-sizing: border-box;
}
.root button,
.root input {
  font: inherit;
  color: inherit;
}
.root button {
  cursor: pointer;
}
.root ul,
.root ol,
.root dl,
.root dd,
.root p,
.root h2,
.root h3 {
  margin: 0;
  padding: 0;
}
.root ul,
.root ol {
  list-style: none;
}
.root :focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}
.amber {
  color: var(--amber);
}
.blue {
  color: var(--blue-ink);
}
.mono,
.eyebrow,
.counter,
.nextTag {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
.eyebrow {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 14px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.dot {
  display: inline-block;
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grey-dot);
}
.dot[data-tone='red'] {
  background: var(--red-dot);
}
.dot[data-tone='amber'] {
  background: var(--amber-dot);
}
.dot[data-tone='green'] {
  background: var(--green);
}
.dot[data-tone='blue'] {
  background: var(--blue);
}

.iconButton {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--chip);
  color: var(--ink-2);
  transition: background-color 0.15s ease;
}
.iconButton svg {
  width: 17px;
  height: 17px;
}
.iconButton:hover:not(:disabled) {
  background: var(--hover);
}
.iconButton:disabled {
  opacity: 0.4;
  cursor: default;
}

/* The sidebar. */
.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 16px 12px 12px;
  border-right: 1px solid var(--line);
  background: var(--side);
}
.root[data-narrow='true'] .side {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 5;
  width: min(288px, 88%);
  overflow-y: auto;
  box-shadow: 0 0 40px var(--shadow);
  transform: translateX(-104%);
  visibility: hidden;
  transition:
    transform 0.26s cubic-bezier(0.3, 0, 0.2, 1),
    visibility 0s linear 0.26s;
}
.root[data-narrow='true'][data-drawer='true'] .side {
  transform: none;
  visibility: visible;
  transition: transform 0.26s cubic-bezier(0.3, 0, 0.2, 1);
}
.scrim {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: var(--scrim);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px 4px;
}
.logo {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--bg);
}
.logo svg {
  width: 22px;
  height: 22px;
}
.brandText {
  display: grid;
  flex: 1;
  min-width: 0;
}
.brandText strong {
  font-size: 15px;
  font-weight: 600;
  line-height: 19px;
}
.brandText span {
  color: var(--muted);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  line-height: 13px;
  text-transform: uppercase;
}
.side > .eyebrow {
  margin: 4px 4px -6px;
}
.terminalWrap {
  position: relative;
}
.terminal {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px 8px 8px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: var(--chip);
  text-align: left;
}
.terminal:hover {
  background: var(--hover);
}
.terminalPin {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue-ink);
}
.terminalText {
  display: grid;
  flex: 1;
  min-width: 0;
}
.terminalText strong,
.menuItem strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.terminalText span,
.menuItem span {
  color: var(--muted);
  font-size: 12px;
}
.terminal > svg {
  width: 16px;
  height: 16px;
}
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 3;
  display: grid;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: var(--pop);
  box-shadow: 0 10px 30px var(--shadow);
}
.menuItem {
  display: grid;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.menuItem:hover,
.menuItem:focus-visible {
  background: var(--hover);
}
.menuItem[aria-checked='true'] {
  background: var(--chip-on);
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--chip);
}
.search:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.search svg {
  flex: none;
  width: 16px;
  height: 16px;
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  outline: none;
  font-size: 13px;
}
.search input::placeholder {
  color: var(--muted);
}
.search input::-webkit-search-cancel-button {
  display: none;
}
.search kbd {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  color: var(--muted);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px;
}
.nav > ul {
  display: grid;
  gap: 2px;
}
.navItem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  text-align: left;
}
.navItem svg {
  flex: none;
  width: 17px;
  height: 17px;
  color: var(--muted);
}
.navItem span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.navItem .chev {
  width: 15px;
  height: 15px;
}
.navItem:hover {
  background: var(--hover);
}
.navItem[aria-current='page'] {
  color: var(--ink);
  font-weight: 500;
}
.navItem[aria-current='page'] svg:first-child {
  color: var(--ink);
}
.group {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--group);
}
.group ul {
  display: grid;
  gap: 1px;
  padding: 2px 0 2px;
}
.setItem {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
}
.setItem:hover {
  background: var(--hover);
}
.setItem[aria-current='true'] {
  background: var(--chip-on);
  color: var(--ink);
  font-weight: 600;
}
.setDot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--grey-dot);
}
.setItem[aria-current='true'] .setDot {
  background: var(--blue);
}
.empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12.5px;
}
.watch {
  display: grid;
  gap: 4px;
  padding: 12px 6px 0;
  border-top: 1px solid var(--line);
}
.watch ul {
  display: grid;
}
.watch li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 30px;
  padding: 0 4px;
  color: var(--ink-2);
  font-size: 13px;
}
.utility {
  display: grid;
  gap: 2px;
  margin-top: auto !important;
}
.next {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.next strong {
  font-size: 13.5px;
  font-weight: 600;
}
.next > span {
  font-size: 12.5px;
}
.nextTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.nextTag {
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--blue-soft);
  color: var(--blue-ink);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.bar {
  display: block;
  height: 5px;
  margin: 2px 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--track);
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}
.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
}
.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue-ink);
  font-size: 12px;
  font-weight: 600;
}
.userText {
  display: grid;
}
.userText strong {
  font-size: 13px;
  font-weight: 600;
}
.userText span {
  color: var(--muted);
  font-size: 12px;
}

/* The main column. */
.main {
  container: main / inline-size;
  min-width: 0;
  padding: 20px 22px 22px;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 15px;
}
.topbar .logo {
  width: 30px;
  height: 30px;
}
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 20px;
}
.crumbs ol {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.crumbs li + li::before {
  content: '/';
  margin-right: 8px;
  opacity: 0.6;
}
.crumbs [aria-current] {
  color: var(--ink);
  font-weight: 500;
}
.title {
  margin-top: 10px !important;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 28px;
}
.subtitle {
  margin-top: 4px !important;
  color: var(--muted);
  font-size: 13px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--chip);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}
.button svg {
  width: 16px;
  height: 16px;
}
.button:hover {
  background: var(--hover);
}
.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff !important;
}
.primary:hover {
  background: var(--blue-ink);
}

.tabsScroll {
  margin: 18px -2px 16px;
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted) !important;
  font-size: 14px;
  white-space: nowrap;
}
.tab:hover {
  color: var(--ink) !important;
}
.tab[aria-selected='true'] {
  background: var(--chip-on);
  color: var(--ink) !important;
  font-weight: 500;
}
.count {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--hover);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.tab[aria-selected='true'] .count {
  background: var(--blue-soft);
  color: var(--blue-ink);
}

/* The planner card. */
.planner {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.planner:fullscreen {
  overflow: auto;
  border-radius: 0;
}
.consist {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 28px;
  padding: 14px 18px;
}
.consistId {
  display: grid;
  gap: 2px;
  padding-right: 26px;
  border-right: 1px solid var(--line);
}
.consistId strong {
  font-size: 19px;
  font-weight: 600;
  line-height: 24px;
}
.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 36px;
}
.facts dt,
.kpis dt {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}
.facts dd {
  margin-top: 3px;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: var(--amber-soft);
  color: var(--amber) !important;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}
button.pill:hover {
  filter: brightness(1.08);
}
.tools {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.kpis > div {
  display: grid;
  align-content: start;
  gap: 3px;
  min-width: 0;
  padding: 12px 18px 13px;
  border-left: 1px solid var(--line);
}
.kpis > div:first-child {
  border-left: 0;
}
.kpis dd {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpis dd.muted {
  font-size: 12px;
  font-weight: 400;
}
@container main (width < 900px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .kpis > div:nth-child(3n + 1) {
    border-left: 0;
  }
  .kpis > div:nth-child(n + 4) {
    border-top: 1px solid var(--line);
  }
}
@container main (width < 560px) {
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpis > div {
    padding: 10px 12px;
  }
  .kpis dd {
    white-space: normal;
  }
  .kpis > div:nth-child(3n + 1) {
    border-left: 1px solid var(--line);
  }
  .kpis > div:nth-child(2n + 1) {
    border-left: 0;
  }
  .kpis > div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }
  .consist {
    padding: 12px;
  }
  .consistId {
    padding-right: 0;
    border-right: 0;
  }
  .facts {
    gap: 8px 20px;
  }
  .tools {
    margin-left: 0;
  }
  .main {
    padding: 14px 12px 14px;
  }
}

/* The car viewer. */
.viewer {
  container: viewer / inline-size;
  margin: 0 10px;
  padding: 12px 16px 10px;
  border-radius: 12px;
  background: var(--viewer);
}
.viewerBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  color: var(--muted);
  font-size: 12.5px;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 7px;
}
.legend [data-swatch] {
  width: 14px;
  height: 10px;
  border-radius: 3px;
}
.legend [data-swatch='selected'] {
  background: var(--blue);
}
.legend [data-swatch='booked'] {
  background: var(--seat-booked);
  box-shadow: inset 0 0 0 1px var(--line-2);
}
.legend [data-swatch='free'] {
  border: 1px dashed var(--seat-free);
}
.legend [data-swatch='luggage'] {
  border: 1px dashed var(--red);
}
.viewerNav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}
.counter {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.step {
  display: flex;
  gap: 6px;
}

/* The train: a strip of every car, 77% of the viewer wide each, slid to centre the one in focus.
   It bleeds to the viewer's edges, where a mask fades the neighbours out. */
.train {
  position: relative;
  height: calc(var(--pitch) * 0.2434 * (100cqw + 32px));
  margin: 16px -16px 8px;
  overflow: hidden;
  mask-image: linear-gradient(90deg, transparent, #000 13%, #000 87%, transparent);
}
.strip {
  position: absolute;
  inset: 0;
  transform: translateX(calc(50% - (var(--i) + 1.5) * var(--pitch) * 100%));
  transition: transform 0.7s cubic-bezier(0.65, 0, 0.25, 1);
}
.slot {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--k) * var(--pitch) * 100%);
  width: calc(var(--pitch) * 100%);
  opacity: 0.4;
  transition: opacity 0.5s ease;
}
.slot[data-current='true'] {
  opacity: 1;
}
.art {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.art *,
.mini * {
  vector-effect: non-scaling-stroke;
  stroke-width: 1;
}
.body,
.under {
  fill: var(--car-fill);
  stroke: var(--car-line);
}
.under {
  stroke: var(--car-detail);
}
.band,
.canopy,
.wheel {
  fill: var(--car-band);
  stroke: var(--car-line);
}
.glass {
  fill: var(--glass);
  stroke: var(--car-line);
}
.door {
  fill: none;
  stroke: var(--car-line);
}
.detail {
  fill: none;
  stroke: var(--car-detail);
}
.stripe {
  fill: var(--stripe);
}
.premier {
  fill: var(--premier);
}
.lamp {
  fill: var(--car-line);
}
.rail {
  fill: var(--rail);
}
.sleeper {
  fill: var(--sleeper);
}

/* The seat map: rows of seats along the car, the aisle a gap; it scrolls in its own box. */
.seatScroll {
  margin: 0 -16px;
  padding: 6px 16px 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.seats {
  display: grid;
  gap: 4px;
}
/* Seats share the width down to 28 px each (20 rows fit a 640 px map), and the map scrolls
   in its own box below that. */
.seatRow {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(28px, 44px));
  justify-content: center;
  gap: 4px;
}
.seatRow[data-aisle] {
  margin-top: 12px;
}
.seat {
  display: grid;
  place-items: center;
  width: 100%;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--seat-booked);
  color: var(--seat-ink) !important;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}
.seat[data-state='free'] {
  border: 1px dashed var(--seat-free);
  background: transparent;
  color: var(--muted) !important;
}
.seat[data-state='selected'] {
  background: var(--blue);
  color: #fff !important;
}
.seat[data-state='luggage'] {
  background: var(--red);
  cursor: default;
}
.seat:not([data-state='luggage']):not([data-state='selected']):hover {
  border-color: var(--blue);
}
@container viewer (width < 760px) {
  .seat {
    font-size: 11px;
    letter-spacing: -0.02em;
  }
}
.caption {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 8px !important;
  color: var(--muted);
  font-size: 12.5px;
}
.captionMain {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  text-align: center;
}
.side2 {
  overflow: hidden;
  opacity: 0.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side2:last-child {
  text-align: right;
}
@container viewer (width < 560px) {
  /* On a phone the car in focus takes more of the width, so it is not drawn too small. */
  .train {
    --pitch: 0.9;
  }
  .caption {
    grid-template-columns: 1fr;
  }
  .side2 {
    display: none;
  }
  .viewer {
    padding-inline: 12px;
  }
}

/* The car sequence. */
.sequence {
  padding: 14px 18px 16px;
}
.sequenceHead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-bottom: 10px;
}
.sequenceHead h3 {
  font-size: 15px;
  font-weight: 600;
}
.sequenceHead p {
  font-size: 12.5px;
}
.sequenceHead > span {
  margin-left: auto;
  font-size: 12.5px;
}
.cars {
  display: grid;
  grid-auto-columns: 138px;
  grid-auto-flow: column;
  gap: 10px;
  margin: 0 -4px;
  padding: 4px 4px 8px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.cars li {
  scroll-snap-align: start;
}
.carCard {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 11px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  text-align: left;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;
}
.carCard:hover {
  border-color: var(--line-2);
  background: var(--hover);
}
.carCard[data-alert] {
  border-color: var(--amber-dot);
}
.carCard[aria-current='true'] {
  border-color: var(--blue);
  background: var(--card-on);
  box-shadow: inset 0 0 0 1px var(--blue);
}
.cardTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.mini {
  display: block;
  width: 100%;
  height: 26px;
  margin: 4px 0 6px;
}
.carCard strong {
  font-size: 13px;
  font-weight: 600;
}
.carCard > .muted {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cardBar {
  display: block;
  height: 3px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--track);
}
.cardBar > span {
  display: block;
  height: 100%;
  background: var(--blue);
}
.carCard[data-alert] .cardBar > span {
  background: var(--amber-dot);
}

/* The demo pointer, over everything; one of its glyphs shows at a time. */
.pointerLayer {
  position: absolute;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}
.pointer {
  width: 22px;
  height: 22px;
}
.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) {
  .strip,
  .slot,
  .side,
  .root[data-narrow='true'] .side,
  .root[data-narrow='true'][data-drawer='true'] .side,
  .carCard,
  .seat {
    transition: none;
  }
}
```

### consist-planner/train-art.tsx

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

import type { Car } from './data';
import styles from './consist-planner.module.css';

/*
 * The cars, drawn as lines: a side view of each car of a high-speed set on a 1027 × 250 grid.
 * The body is 1000 units long (x 14 to 1013) and the 27 units left over hold the gangway
 * bellows, half at each end, so cars laid side by side at the grid's width meet at their
 * gangways and their rails join into one track.
 *
 * - The ordinary car: a smooth body with soft roof shoulders, a ribbon of windows (one per seat
 *   row) in a dark band, a plug door at each end, the livery stripe under the band, the skirt
 *   hiding most of two bogies.
 * - The nose car: the same body with its front 330 units drawn out into a long, low nose, its
 *   canopy set into the curve and the stripe sweeping down to the tip. The lead car points
 *   left; the tail car is the same drawing mirrored.
 * - The premier car adds a thin gold line under its windows; cars with a pantograph carry it on
 *   a roof fairing.
 *
 * Strokes keep 1 px whatever the scale (vector-effect in the stylesheet), so the same drawing is
 * the big car in the viewer and the 110 px silhouette on the car cards (mini: no windows, no
 * track, no small parts).
 */

const W = 1027;
const ROOF = 34;
const FLOOR = 192;

/** The lead car's outline: the nose to the left, roof shoulder at the far end. */
const NOSE_BODY = `M1013 64C1013 44 1001 ${ROOF} 979 ${ROOF}L360 ${ROOF}C262 ${ROOF} 170 66 92 124C50 155 16 170 14 182C13 189 18 ${FLOOR} 28 ${FLOOR}L1013 ${FLOOR}Z`;
const BOX_BODY = `M14 ${FLOOR}V64C14 44 26 ${ROOF} 48 ${ROOF}H979C1001 ${ROOF} 1013 44 1013 64V${FLOOR}Z`;
const NOSE_STRIPE = 'M1013 124H360C250 124 150 140 64 170L58 177C150 150 250 133 360 133H1013Z';
const CANOPY = 'M222 72C258 60 296 52 336 51L338 72C298 74 262 80 228 88Z';

/** Windows evenly along the band, one per seat row. */
function windows(from: number, to: number, count: number) {
  const pitch = (to - from) / count;
  const width = Math.min(30, pitch - 9);
  return Array.from({ length: count }, (_, index) => (
    <rect
      key={index}
      className={styles.glass}
      x={from + index * pitch + (pitch - width) / 2}
      y={83}
      width={width}
      height={20}
      rx={3}
    />
  ));
}

function Bogie({ x, mini }: { x: number; mini: boolean }) {
  return (
    <g>
      <rect className={styles.under} x={x - 66} y={194} width={132} height={15} rx={5} />
      {[-42, 42].map((dx) => (
        <g key={dx}>
          <circle className={styles.wheel} cx={x + dx} cy={207} r={15} />
          {!mini && <circle className={styles.detail} cx={x + dx} cy={207} r={4} />}
        </g>
      ))}
      {!mini && <rect className={styles.detail} x={x - 10} y={198} width={20} height={8} rx={2} />}
    </g>
  );
}

function Pantograph() {
  return (
    <g>
      <rect className={styles.body} x={430} y={26} width={166} height={9} rx={4} />
      <path className={styles.detail} d="M496 26 L540 9 L508 0" />
      <path className={styles.detail} d="M484 0H532" strokeWidth={2} />
    </g>
  );
}

/** One gangway's half: the bellows between this car and the next. */
const Gangway = ({ x }: { x: number }) => (
  <rect className={styles.band} x={x} y={64} width={14} height={118} rx={2} />
);

/** The track under one car's length: two rails as one line, and 40 sleepers. */
export function Track() {
  return (
    <g>
      <rect className={styles.rail} x={0} y={222} width={W} height={5} />
      {Array.from({ length: 40 }, (_, index) => (
        <rect
          key={index}
          className={styles.sleeper}
          x={index * (W / 40) + 6}
          y={230}
          width={14}
          height={7}
          rx={1}
        />
      ))}
    </g>
  );
}

/** The drawing of a nose car, nose to the left (the tail car mirrors it). */
function NoseCar({ car, mini }: { car: Car; mini: boolean }) {
  return (
    <g>
      <Gangway x={1013} />
      <path className={styles.body} d={NOSE_BODY} />
      {!mini && <path className={styles.detail} d="M380 46H987M80 166H1013" />}
      <rect className={styles.band} x={390} y={78} width={567} height={30} rx={8} />
      {!mini && windows(402, 948, car.rows)}
      <path className={styles.canopy} d={CANOPY} />
      <path className={styles.stripe} d={NOSE_STRIPE} />
      {!mini && (
        <>
          <rect className={styles.door} x={354} y={58} width={24} height={128} rx={4} />
          <rect className={styles.door} x={971} y={58} width={28} height={128} rx={4} />
          <rect className={styles.glass} x={978} y={70} width={14} height={26} rx={3} />
          <ellipse
            className={styles.lamp}
            cx={156}
            cy={128}
            rx={12}
            ry={3.5}
            transform="rotate(-16 156 128)"
          />
        </>
      )}
      <Bogie x={330} mini={mini} />
      <Bogie x={877} mini={mini} />
    </g>
  );
}

function BoxCar({ car, mini }: { car: Car; mini: boolean }) {
  return (
    <g>
      <Gangway x={0} />
      <Gangway x={1013} />
      {car.pantograph && <Pantograph />}
      <path className={styles.body} d={BOX_BODY} />
      {!mini && <path className={styles.detail} d="M40 46H987M14 166H1013" />}
      <rect className={styles.band} x={68} y={78} width={891} height={30} rx={8} />
      {!mini && windows(80, 947, car.rows)}
      {car.kind === 'premier' && (
        <rect className={styles.premier} x={68} y={113} width={891} height={2.5} />
      )}
      <rect className={styles.stripe} x={14} y={124} width={999} height={9} />
      {!mini && (
        <>
          <rect className={styles.door} x={28} y={58} width={28} height={128} rx={4} />
          <rect className={styles.door} x={971} y={58} width={28} height={128} rx={4} />
          <rect className={styles.glass} x={35} y={70} width={14} height={26} rx={3} />
          <rect className={styles.glass} x={978} y={70} width={14} height={26} rx={3} />
          <rect className={styles.under} x={290} y={192} width={180} height={11} rx={2} />
          <rect className={styles.under} x={556} y={192} width={180} height={11} rx={2} />
        </>
      )}
      <Bogie x={150} mini={mini} />
      <Bogie x={877} mini={mini} />
    </g>
  );
}

/** One car's drawing; `mini` is the silhouette on a car card. */
export function CarArt({
  car,
  mini = false,
  className,
}: {
  car: Car;
  mini?: boolean;
  className?: string;
}) {
  const nose = car.kind === 'lead' || car.kind === 'tail';
  return (
    <svg
      className={className}
      viewBox={mini ? `0 24 ${W} 200` : `0 0 ${W} 250`}
      preserveAspectRatio="xMidYMid meet"
      aria-hidden="true"
      focusable="false"
    >
      {nose ? (
        <g transform={car.kind === 'tail' ? `matrix(-1 0 0 1 ${W} 0)` : undefined}>
          <NoseCar car={car} mini={mini} />
        </g>
      ) : (
        <BoxCar car={car} mini={mini} />
      )}
      {!mini && <Track />}
    </svg>
  );
}
```

### consist-planner/data.ts

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

/*
 * The consist the planner shows: one sixteen-car high-speed set, H-12, on the 14:40 Kazehaya 23
 * from Tokyo to Shin-Osaka. Each car has a kind (the two nose cars, ordinary cars in a 3 + 2
 * layout, premier cars in 2 + 2), a number of seat rows, its luggage spaces and its bookings.
 *
 * The bookings are drawn from a seeded generator, so every render (server and browser) gets the
 * same seat map without storing 1,400 seats by hand.
 */

export type CarKind = 'lead' | 'ordinary' | 'premier' | 'tail';

export type Car = {
  /** 1 to 16, from the Shin-Osaka end. */
  n: number;
  code: string;
  kind: CarKind;
  /** Seat rows along the car: 1 to rows. */
  rows: number;
  /** Seats that are luggage spaces instead, as "20D". */
  luggage: string[];
  /** The share of seats booked. */
  load: number;
  /** A pantograph on the roof. */
  pantograph?: boolean;
  /** An open defect, shown in amber. */
  alert?: string;
};

/** The seat letters across the car, window to window, and where the aisle falls (before index). */
export const LAYOUTS: Record<CarKind, { letters: string[]; aisle: number }> = {
  lead: { letters: ['A', 'B', 'C', 'D', 'E'], aisle: 3 },
  ordinary: { letters: ['A', 'B', 'C', 'D', 'E'], aisle: 3 },
  tail: { letters: ['A', 'B', 'C', 'D', 'E'], aisle: 3 },
  premier: { letters: ['A', 'B', 'C', 'D'], aisle: 2 },
};

const ordinary = (n: number, rows: number, load: number, extra: Partial<Car> = {}): Car => ({
  n,
  code: `M-12${String(n).padStart(2, '0')}`,
  kind: 'ordinary',
  rows,
  // The last row's two-seat side is the space for oversized bags.
  luggage: [`${rows}D`, `${rows}E`],
  load,
  ...extra,
});

const premier = (n: number, load: number): Car => ({
  n,
  code: `P-12${String(n).padStart(2, '0')}`,
  kind: 'premier',
  rows: 17,
  luggage: ['17C', '17D'],
  load,
});

export const CARS: Car[] = [
  { n: 1, code: 'Tc-1201', kind: 'lead', rows: 13, luggage: [], load: 0.86 },
  ordinary(2, 20, 0.92),
  ordinary(3, 20, 0.9),
  ordinary(4, 20, 0.94),
  ordinary(5, 18, 0.82, { pantograph: true, alert: 'HVAC degraded' }),
  ordinary(6, 20, 0.88),
  ordinary(7, 20, 0.95),
  premier(8, 0.72),
  premier(9, 0.76),
  premier(10, 0.66),
  ordinary(11, 18, 0.9),
  ordinary(12, 20, 0.93),
  ordinary(13, 20, 0.89, { pantograph: true }),
  ordinary(14, 20, 0.91),
  ordinary(15, 20, 0.87),
  { n: 16, code: 'Tc-1216', kind: 'tail', rows: 16, luggage: ['16D', '16E'], load: 0.8 },
];

/** The car the planner opens on, and the seat already picked in it. */
export const START_CAR = 4;
export const START_SEATS: Record<number, string[]> = { 4: ['7C'] };

/** A small seeded generator (a 32-bit mix), so bookings are the same on every render. */
function seeded(seed: number) {
  let s = seed >>> 0;
  return () => {
    s = (s + 0x6d2b79f5) >>> 0;
    let t = s;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

export type Seat = { id: string; row: number; letter: string; luggage: boolean; booked: boolean };

/** Every place in a car, row by row: its seats, booked or free, and its luggage spaces. */
export function seatsOf(car: Car): Seat[] {
  const { letters } = LAYOUTS[car.kind];
  const random = seeded(car.n * 977 + 13);
  const seats: Seat[] = [];
  for (let row = 1; row <= car.rows; row += 1) {
    for (const letter of letters) {
      const id = `${row}${letter}`;
      seats.push({ id, row, letter, luggage: car.luggage.includes(id), booked: false });
    }
  }
  const places = seats.filter((seat) => !seat.luggage);
  const booked = Math.round(places.length * car.load);
  // Shuffle the places with the seed and book the first ones.
  const order = places.map((seat) => ({ seat, key: random() }));
  order.sort((a, b) => a.key - b.key);
  order.slice(0, booked).forEach(({ seat }) => (seat.booked = true));
  return seats;
}

export const SEATS: Seat[][] = CARS.map(seatsOf);

export const capacity = (index: number) => SEATS[index].filter((seat) => !seat.luggage).length;
export const bookedIn = (index: number) => SEATS[index].filter((seat) => seat.booked).length;

export const CATEGORIES = [
  { id: 'all', label: 'All services', count: 31 },
  { id: 'express', label: 'Express', count: 8 },
  { id: 'semi', label: 'Semi-fast', count: 10 },
  { id: 'stopping', label: 'All-stop', count: 9 },
  { id: 'out', label: 'Out of service', count: 4 },
];

export const TERMINALS = [
  { id: 'tokyo', name: 'Tokyo Terminal', division: 'Kanto division' },
  { id: 'nagoya', name: 'Nagoya Terminal', division: 'Chubu division' },
  { id: 'osaka', name: 'Shin-Osaka Terminal', division: 'Kansai division' },
];

export const WATCHLIST: { text: string; tone: 'red' | 'amber' }[] = [
  { text: 'H-09 · Brake test', tone: 'red' },
  { text: 'H-21 · Track conflict', tone: 'red' },
  { text: 'H-17 · Late cleaning', tone: 'amber' },
];
```

### consist-planner/icons.tsx

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

/*
 * The planner's icons, drawn on a 20-unit grid in 1.5-unit strokes of the current colour, so each
 * takes its control's colour in both schemes. All are decorative: the control beside them names
 * what it does.
 */

export type IconName =
  | 'mark'
  | 'pin'
  | 'updown'
  | 'search'
  | 'home'
  | 'train'
  | 'grid'
  | 'box'
  | 'route'
  | 'signal'
  | 'wrench'
  | 'chart'
  | 'gear'
  | 'help'
  | 'chevron-right'
  | 'chevron-down'
  | 'chevron-left'
  | 'save'
  | 'check'
  | 'reset'
  | 'expand'
  | 'collapse'
  | 'menu'
  | 'close';

const PATHS: Record<IconName, string> = {
  // The app's mark: a nose seen from the side over a rail.
  mark: 'M3 13.5c2.2-4.6 6-7 11.4-7H17v7zM3 16h14M6 13.5h11',
  pin: 'M10 17.5s5.5-5 5.5-9.2a5.5 5.5 0 0 0-11 0c0 4.2 5.5 9.2 5.5 9.2zM10 10.3a2 2 0 1 0 0-4 2 2 0 0 0 0 4z',
  updown: 'M6.5 7.5 10 4l3.5 3.5M6.5 12.5 10 16l3.5-3.5',
  search: 'M9 15a6 6 0 1 0 0-12 6 6 0 0 0 0 12zM13.5 13.5 17 17',
  home: 'M3.5 9 10 3.5 16.5 9v7a1 1 0 0 1-1 1H12v-5H8v5H4.5a1 1 0 0 1-1-1z',
  train:
    'M5.5 3.5h9a1.5 1.5 0 0 1 1.5 1.5v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a1.5 1.5 0 0 1 1.5-1.5zM4 9.5h12M7 12.3h.1M13 12.3h.1M7 15l-1.5 2.5M13 15l1.5 2.5',
  grid: 'M3.5 3.5h5v5h-5zM11.5 3.5h5v5h-5zM3.5 11.5h5v5h-5zM11.5 11.5h5v5h-5z',
  box: 'M10 2.8 16.5 6.4v7.2L10 17.2l-6.5-3.6V6.4zM3.5 6.4 10 10l6.5-3.6M10 10v7.2',
  route:
    'M5 7.5a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM15 16.5a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM5 7.5v1.5a3 3 0 0 0 3 3h4a3 3 0 0 1 3 3v-2',
  signal:
    'M10 11.3a1.3 1.3 0 1 0 0-2.6 1.3 1.3 0 0 0 0 2.6zM6.8 6.8a4.5 4.5 0 0 0 0 6.4M13.2 6.8a4.5 4.5 0 0 1 0 6.4M4.3 4.3a8 8 0 0 0 0 11.4M15.7 4.3a8 8 0 0 1 0 11.4',
  wrench:
    'M12.8 3.2a4 4 0 0 0-4.6 5.4L3.5 13.3a1.6 1.6 0 0 0 2.2 2.2l4.7-4.7a4 4 0 0 0 5.4-4.6l-2.4 2.4-2.2-.4-.4-2.2z',
  chart: 'M3.5 3.5h13v13h-13zM7 13.5V11M10 13.5V7.5M13 13.5V9.5',
  gear: 'M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM10 2.5v2M10 15.5v2M2.5 10h2M15.5 10h2M4.7 4.7l1.4 1.4M13.9 13.9l1.4 1.4M4.7 15.3l1.4-1.4M13.9 6.1l1.4-1.4',
  help: 'M10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM8 8a2 2 0 1 1 2.8 1.8c-.5.3-.8.7-.8 1.3v.4M10 14h.01',
  'chevron-right': 'M8 5l5 5-5 5',
  'chevron-down': 'M5 8l5 5 5-5',
  'chevron-left': 'M12 5l-5 5 5 5',
  save: 'M4.5 3.5h9l3 3v9a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-11a1 1 0 0 1 1-1zM6.5 3.5v4h6v-4M6.5 16.5v-5h7v5',
  check: 'M10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM7 10.2l2 2 4-4.2',
  reset: 'M4 10a6 6 0 1 0 1.8-4.3M4 3.5v3h3',
  expand: 'M3.5 7.5v-4h4M12.5 3.5h4v4M16.5 12.5v4h-4M7.5 16.5h-4v-4',
  collapse: 'M7.5 3.5v4h-4M16.5 7.5h-4v-4M12.5 16.5v-4h4M3.5 12.5h4v4',
  menu: 'M3.5 6h13M3.5 10h13M3.5 14h13',
  close: 'M5 5l10 10M15 5 5 15',
};

export function Icon({ name, className }: { name: IconName; className?: string }) {
  return (
    <svg
      className={className}
      viewBox="0 0 20 20"
      width="20"
      height="20"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.5"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
      focusable="false"
    >
      <path d={PATHS[name]} />
    </svg>
  );
}
```

### consist-planner/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 (consist-planner.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>
  );
}
```

### consist-planner/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();
      },
      // The dashboard is taller than a phone screen: a tenth of it in view is enough.
      { threshold: 0.1 },
    );
    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 };
}
```