# Mega menu

> A marketing site’s header whose sections drop a full-width panel of captioned links and a featured card, morphing from one section to the next.

The header of Tessera, a made-up analytics product, over one of its blog posts. Products, Resources and Blog each drop a white panel the width of the site: columns captioned in small grey capitals, each link an outlined icon tile, a bold title and two grey lines, with a badge where there is news, and a tinted card on the right with a drawn picture, a glass play button and a full-width button. A soft band glides behind the link under the pointer and its tile lifts; the page underneath dims. Moving to another section morphs the panel’s height and slides its content the way the pointer went. The play button opens a small player. On a phone the nav folds into a menu button and a sheet of accordions. Light and dark.

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

Category: Navigation.

## Anatomy

1. **Brand**: The pixel mark and the product’s name, a link home.
2. **Section trigger**: A disclosure button with a chevron that flips while its panel is open. The pointer opens it after a short rest; a click, Enter or Space toggles it.
3. **Panel**: The full width of the site under the header. Its height follows the section in view and morphs when another opens.
4. **Column caption**: A small grey label in capitals naming each column; the list of links below is labelled by it.
5. **Link**: An icon tile, a bold title and two lines in grey. Under the pointer or the focus, a soft band glides behind it and its tile lifts.
6. **Badge**: An outlined tag after a title, for news such as hiring or a new feature.
7. **Featured card**: A tinted card with a title, a line, a drawn picture with a glass play button, and a full-width button.
8. **Scrim**: A soft grey gradient over the page while a panel is open; a press on it closes the panel.

## Properties

### Featured card (`NavSection.featured · video`)

1. **None (default)**: Columns alone, across the panel’s full width.
2. **Card**: A tinted card on the right with a title, a line, a drawn picture and a full-width button.
3. **Card with a video**: With `video: true`, a glass play button on the picture opens a small player.

Add a card only when one thing in the section is worth more than another link: a release, an app, a session. Add the video only when there is something to watch.

### Badge (`MenuLink.badge`)

1. **None (default)**: Most links: the title and its line.
2. **Badge**: An outlined tag after the title, for news: New, Live today, a version.

Keep it for news that will be old in a few weeks, one or two per panel. Take it off when the news is over.

## When to use

- A marketing site with more pages than a header can list: products, resources and company pages grouped into a few sections, each with a line on what is behind it.
- Sections people browse rather than search: an icon, a title and two lines help them pick the page before they open it.
- Room to promote one thing per section, such as a release, an app or a video, beside the links rather than in a banner.
- Headers that must also work on a phone, where the same sections fold into a sheet of accordions.

## When not to use

- An app’s own navigation between a handful of views. Use tabs or a sidebar; a panel that covers the page slows down frequent moves.
- Commands or settings, such as Edit, Share or Delete. Use a menu button with role="menu"; these are links to pages.
- Fewer than four pages per section. Use a simple dropdown list; a full-width panel for three links is mostly empty space.
- Deep trees of pages. Use a sidebar or a site map; a mega menu holds one level under each section.

### Section vs. link

**Section**
- A group of pages that need a line each to tell apart.
- A button with a chevron that opens a panel; it goes nowhere itself.
- Products, Resources, Blog.

**Link**
- One page, known by its name.
- An ordinary link in the header, with no chevron and no panel.
- Pricing, Docs, Changelog.

### Hover intent

- **Opening**: the pointer rests 140 ms on a trigger before its panel opens, so crossing the header on the way to the page opens nothing.
- **Switching**: once a panel is open, 60 ms on another trigger morphs it into that section, the content sliding the way the pointer went.
- **Closing**: the panel waits 280 ms after the pointer leaves the header and the panel, so a short slip outside doesn’t close it.
- **Clicks and touch**: a click toggles a section; a click just after the pointer opened it keeps it open. Touch ignores hover and opens on the tap.

### On a phone

Under 760 px of site width the nav folds into a menu button, and a sheet lists the same items, with each section as an accordion of its links. The featured cards are left out of the sheet, so anything a card promotes should also be a link in one of the columns.

## Do’s and don’ts

- **Do**: Give every link a short title and one line on what is behind it, so people pick the page before they open it.
- **Don’t**: Fill the lines with the same filler, or the title again. The pages look alike until they are opened.
- **Do**: Badge the one link with news, so it stands out from a calm column.
- **Don’t**: Badge every link. When everything is new, nothing is.
- **Caution**: The phone’s sheet has no featured cards: link what a card promotes from a column too, or phones never see it.
- **Don’t**: Pour a whole section into one long column. Split it into two captioned groups of three or four, or move it to a page of its own.

## Content

A panel is scanned, not read: the caption sorts, the title names, the line tells.

- **Section labels of one word**: Products, Resources, Blog.
- **Captions as short nouns** in sentence case: the stylesheet draws them in capitals, and screen readers get the words as written.
- **Titles of two or three words**, the same as the heading of the page they open.
- **One sentence under each title**, short enough for two lines, about what people will find there.
- **Badges of a word or two**: `New`, `Live today`, `v4`.
- **The card’s button names what happens**: `See what’s new`, `Get the app`, `Watch the session`.

## Installation

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

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

Or copy all the source files below into one folder of your project. Either way it needs React 19 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 { MegaMenu } from './mega-menu';

export function SiteHeader() {
  return (
    <MegaMenu
      brand="Tessera"
      onNavigate={(target) => console.log('Go to', target.href)}
      onOpenChange={(section) => console.log('Open', section)}
      onPlay={(featured) => console.log('Play', featured.title)}
      autoplay={false}
    />
  );
}
```

## States

- **Closed**: The header over an article, nothing open.
- **Resources open**: Two columns of four links and the featured card with its video.
- **Link under the pointer**: The band behind Customer stories and its tile lifted with a shadow.
- **Products**: Three links per column, so the panel is shorter; Automations carries a New badge.
- **Blog**: Topics and series, with a live badge on Office hours and a session to watch.
- **Video player**: The play button opens a small modal player over the site; the picture moves until paused.
- **Dark**: The same panel by night: near-black surfaces, the pictures unchanged.
- **Phone**: Under 760 px the nav folds into a menu button.
- **Phone menu**: The sheet lists every item; sections are accordions, with Log in and Get started below.
- **Phone section open**: Resources expanded in the sheet, its links with their tiles and two lines.

## Examples

### Products panel

The shorter Products panel open with Integrations under the pointer, and the app card without a video.

```tsx
import { MegaMenu } from './mega-menu';

export function ProductsPanel() {
  return <MegaMenu autoplay={false} defaultState={{ open: 'products', hover: 'integrations' }} />;
}
```

### Docs header

A documentation site’s header with its own items: a single Guides section of two columns and no featured card, so the links take the full width.

```tsx
import { MegaMenu, type NavItem } from './mega-menu';

const DOCS_NAV: NavItem[] = [
  {
    id: 'guides',
    label: 'Guides',
    columns: [
      {
        id: 'start',
        caption: 'Get started',
        links: [
          {
            id: 'quickstart',
            title: 'Quickstart',
            text: 'Send your first event and see it on a chart in five minutes.',
            icon: 'rocket',
          },
          {
            id: 'concepts',
            title: 'Core concepts',
            text: 'Events, properties, cohorts and boards, and how they fit together.',
            icon: 'book',
          },
        ],
      },
      {
        id: 'build',
        caption: 'Build',
        links: [
          {
            id: 'sdks',
            title: 'SDKs',
            text: 'Libraries for the browser, iOS, Android and six server languages.',
            icon: 'code',
            badge: 'v4',
          },
          {
            id: 'webhooks',
            title: 'Webhooks',
            text: 'Get a request when a threshold is crossed or a report is ready.',
            icon: 'plug',
          },
        ],
      },
    ],
  },
  { id: 'reference', label: 'API reference', href: '#reference' },
  { id: 'status', label: 'Status', href: '#status' },
];

export function DocsHeader() {
  return (
    <MegaMenu
      autoplay={false}
      brand="Fieldnote"
      items={DOCS_NAV}
      defaultState={{ open: 'guides', hover: 'sdks' }}
    />
  );
}
```

### Phone sheet

The header at phone width with its menu open and the Blog section expanded.

```tsx
import { MegaMenu } from './mega-menu';

export function PhoneSheet() {
  return (
    <div style={{ maxWidth: 390, margin: '0 auto' }}>
      <MegaMenu autoplay={false} defaultState={{ sheet: true, expanded: 'blog' }} />
    </div>
  );
}
```

### Release video

Dark, with the Blog panel open and the session playing in the player.

```tsx
import { MegaMenu } from './mega-menu';

export function ReleaseVideo() {
  return (
    <MegaMenu autoplay={false} colorScheme="dark" defaultState={{ open: 'blog', video: true }} />
  );
}
```

## How it works

- The header’s items are data: plain links, and sections with columns of links and an optional featured card. Every section’s content is drawn once, as a pane in the panel, so moving between them only changes which pane is current.
- The panes before the open one wait to its left and the ones after to its right. Opening another section slides the old pane out and the new one in from the side it came from, and the panel’s height follows the new pane: it is measured, and a ResizeObserver keeps it right when the text reflows.
- Opening from closed fades the panel in without moving its height or its panes; only a switch between two open sections morphs, so the first open stays quick.
- Hover intent: the pointer has to rest 140 ms on a trigger to open its panel, 60 ms to switch once one is open, and the panel waits 280 ms after the pointer leaves the header and panel before it closes. A click right after the pointer opened it keeps it open.
- One band per panel sits behind the links. It moves to the link under the pointer or the focus with `translate`, `width` and `height` on a springy curve, and appears in place, with no flight, when it was hidden.
- The featured pictures are SVG scenes drawn for each section. In the player their bars grow, their lines draw themselves and the cards drift, all CSS animations that Pause holds.
- Under 760 px of site width, a container query swaps the nav for a menu button whose three bars turn into a cross; the sheet lists the same items, with the sections as accordions that open by animating `grid-template-rows`.
- While on screen and untouched, a demo pointer opens Resources, glides across its links, switches to Products and then Blog, and closes; on a phone it opens the sheet and two sections. Any real input hands it over; it comes back after 8 s of quiet.

## API reference

- **items** (`NavItem[]`, default `Features, Products, Resources, Blog, Pricing, Docs`): The header’s items: a link (id, label, href), or a section with columns of links (icon, title, text, optional badge) and an optional featured card (title, text, scene, cta, video).
- **brand** (`string`, default `'Tessera'`): The product’s name beside the mark, also used in the article under the header.
- **defaultState** (`MegaMenuState`): Opens locked in a moment, with the demo off: the open section, the link under the pointer, the player, the phone’s sheet and its expanded section.
- **onNavigate** (`(target: NavTarget) => void`): Called with the id, label and href of any link followed: in a panel, the header, the sheet or the page.
- **onOpenChange** (`(section: string | null) => void`): Called with a section’s id when its panel opens, and with null when it closes.
- **onPlay** (`(featured: Featured) => void`): Called when a featured card’s play button opens the player.
- **autoplay** (`boolean`, default `true`): While on screen and untouched, a demo pointer shows the main interactions. Any real input stops it.
- **colorScheme** (`'light' | 'dark' | 'system'`): Light or dark colours, or the reader’s; without it, the page’s color-scheme.
- **className** (`string`): Classes for the stage.

## Accessibility

### Disclosure, not a menu

Each section’s trigger is a button with `aria-expanded` and `aria-controls`, and its panel holds plain lists of links, each list labelled by its column’s caption, in the panel and in the phone’s sheet alike. There is no `role="menu"`: these are links to pages, and screen readers keep their usual link commands. Panes not in view are inert.

### Keyboard

- Enter or Space toggles a section; ↓ opens it and moves to its first link.
- ← and → move along the header, Home and End to its ends.
- In a panel, ↑ and ↓ walk the links, the play button and the card’s button; ↑ from the first goes back to the trigger.
- Escape closes the panel and returns the focus to its trigger; tabbing out of the header and the panel closes it too.

### Content on hover

Nothing needs hover: a click or a key opens every section. A panel the pointer opened stays while the pointer moves onto it and closes 280 ms after it leaves, so it can be read without chasing it. Escape anywhere on the page closes it without moving the pointer, and the focus stays where it was unless it was in the panel (WCAG 1.4.13, Content on hover or focus).

### Announcements and motion

- A polite live region says which section opened or closed, and which link was followed.
- The player is a modal dialog: the focus moves into it, Tab stays inside, and closing it puts the focus back on the play button.
- Under reduced motion nothing slides, glides or animates, and the demo pointer never plays.
- Triggers are 36 px tall and links far taller, above the 24 × 24 px minimum (WCAG 2.5.8, AA).

### Contrast

In both schemes, words reach 4.5:1 on the surface they sit on (WCAG 1.4.3), and the chevrons, the card button’s among them, reach 3:1 (WCAG 1.4.11). The painted pictures keep their own colours.

### In this build

- The sections follow the disclosure pattern for navigation: each trigger is a button with aria-expanded and aria-controls pointing at its pane, and the panes are lists of ordinary links labelled by their column’s caption. Panes not in view are inert.
- Enter or Space toggles a section; ↓ opens it and moves to its first link; ← and → move along the header, Home and End to its ends. Inside a panel, ↑ and ↓ walk the links, the play button and the card’s button, and ↑ from the first goes back to the trigger.
- Escape closes the panel and returns the focus to its trigger; tabbing out of the header and its panel, or pressing outside them, closes it too. A polite live region says which section opened or closed, and which link was followed.
- The player is a modal dialog labelled by its title: the focus moves to its close button, Tab stays inside, and Escape or a press outside closes it and puts the focus back on the play button.
- On a phone the menu button and each section’s row are disclosure buttons with aria-expanded; Escape closes the sheet. Every control shows a focus ring; under reduced motion nothing slides, glides or animates and the demo never plays. The demo pointer is decorative.

## Source

### mega-menu/mega-menu.tsx

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

'use client';

import {
  useEffect,
  useEffectEvent,
  useId,
  useLayoutEffect,
  useRef,
  useState,
  type FocusEvent,
  type KeyboardEvent,
  type MouseEvent,
  type PointerEvent,
} from 'react';
import { NAV, isSection, type Featured, type NavItem, type NavSection } from './data';
import { DemoPointer, runDemo, type Point } from './demo-pointer';
import { Glyph, Icon, Mark, Scene } from './glyphs';
import styles from './mega-menu.module.css';
import { useAutoplay } from './use-autoplay';

export type { Featured, MenuColumn, MenuLink, NavItem } from './data';

/** A moment to open in, locked, with the demo off. */
export type MegaMenuState = {
  /** The section whose panel is open, on a wide header. */
  open?: string | null;
  /** The link under the pointer, in the open panel. */
  hover?: string | null;
  /** The open section's video player. */
  video?: boolean;
  /** The phone's menu sheet. */
  sheet?: boolean;
  /** The section expanded in the phone's sheet. */
  expanded?: string | null;
};

/** What a host is told when a link is followed. */
export type NavTarget = { id: string; label: string; href?: string };

type Props = {
  /** The header's items: links, and sections with a panel. */
  items?: NavItem[];
  /** The product's name, beside the mark. */
  brand?: string;
  defaultState?: MegaMenuState;
  autoplay?: boolean;
  colorScheme?: 'light' | 'dark' | 'system';
  className?: string;
  /** A link was followed: a panel's, the header's or the page's. */
  onNavigate?: (target: NavTarget) => void;
  /** A panel opened (its section's id) or closed (null). */
  onOpenChange?: (section: string | null) => void;
  /** A featured card's video started. */
  onPlay?: (featured: Featured) => void;
};

/** How long the pointer rests on a trigger before its panel opens, and leaves before it closes. */
const OPEN_DELAY = 140;
const SWITCH_DELAY = 60;
const CLOSE_DELAY = 280;

/** Under this width of header, the nav folds into the menu button (matches the stylesheet). */
const NARROW = 760;

const TOC = ['Introduction', 'Why we rebuilt it', 'What changed', 'Sharing a board', 'What’s next'];

export function MegaMenu({
  items = NAV,
  brand = 'Tessera',
  defaultState,
  autoplay = true,
  colorScheme,
  className = '',
  onNavigate,
  onOpenChange,
  onPlay,
}: Props) {
  const uid = useId().replace(/[^a-zA-Z0-9-]/g, '');
  const { ref: root, playing, take } = useAutoplay<HTMLDivElement>(8000);
  const locked = defaultState !== undefined;
  const s = defaultState ?? {};
  const sections = items.filter(isSection);

  // `last` keeps the panes in place while the panel is closed; `morph` is set while one open
  // panel turns into another, the only time the height and the panes animate.
  const [menu, setMenu] = useState(() => ({
    open: s.open ?? null,
    last: s.open ?? sections[0]?.id ?? null,
    morph: false,
  }));
  const open = menu.open;
  const [hover, setHover] = useState<string | null>(s.hover ?? null);
  const [video, setVideo] = useState<string | null>(s.video ? (s.open ?? null) : null);
  const [paused, setPaused] = useState(false);
  const [sheet, setSheet] = useState(!!s.sheet);
  const [expanded, setExpanded] = useState<string | null>(s.expanded ?? null);
  const [toc, setToc] = useState(0);
  const [live, setLive] = useState('');
  const [height, setHeight] = useState<number | null>(null);

  const top = useRef<HTMLDivElement>(null);
  const panes = useRef(new Map<string, HTMLDivElement>());
  const player = useRef<HTMLDivElement>(null);
  const pointer = useRef<HTMLSpanElement>(null);
  const timers = useRef({ open: 0, close: 0 });
  const hoverOpened = useRef(0);
  const focusFirst = useRef<string | null>(null);
  const focusPlayer = useRef(false);
  const pressedAt = useRef(0);
  /** Whether the reader has moved, pressed or typed here: the demo's and defaultState's panels
   * are not theirs to dismiss from elsewhere on the page. */
  const acted = useRef(false);

  const say = (text: string) => setLive(text);
  const labelOf = (id: string | null) => items.find((item) => item.id === id)?.label ?? '';

  /** Opens a section's panel, or closes it with null. */
  const change = (next: string | null) => {
    window.clearTimeout(timers.current.open);
    window.clearTimeout(timers.current.close);
    setMenu((m) =>
      m.open === next ? m : { open: next, last: next ?? m.last, morph: m.open !== null && !!next },
    );
    if (next !== open) setHover(null);
  };

  // Tell the host and the live region, after the change has drawn.
  const opened = useRef(open);
  const announce = useEffectEvent((now: string | null) => {
    onOpenChange?.(now);
    say(now ? `${labelOf(now)} menu, expanded` : 'Menu collapsed');
  });
  useEffect(() => {
    if (opened.current === open) return;
    opened.current = open;
    announce(open);
  }, [open]);

  // The panel is as tall as the pane in view, followed as it changes size.
  const shown = open ?? menu.last;
  useLayoutEffect(() => {
    const pane = shown ? panes.current.get(shown) : undefined;
    if (!pane) return;
    const measure = () => setHeight(pane.offsetHeight);
    measure();
    const observer = new ResizeObserver(measure);
    observer.observe(pane);
    return () => observer.disconnect();
  }, [shown]);

  // The hover band glides to the link under the pointer; it appears in place when it was hidden.
  useLayoutEffect(() => {
    panes.current.forEach((pane, id) => {
      const band = pane.querySelector<HTMLElement>('[data-band]');
      if (!band) return;
      const link =
        hover && id === open ? pane.querySelector<HTMLElement>(`[data-link="${hover}"]`) : null;
      if (!link) {
        band.dataset.on = 'false';
        return;
      }
      const was = band.dataset.on === 'true';
      if (!was) band.style.transition = 'none';
      band.style.translate = `${link.offsetLeft}px ${link.offsetTop}px`;
      band.style.width = `${link.offsetWidth}px`;
      band.style.height = `${link.offsetHeight}px`;
      if (!was) {
        void band.offsetWidth;
        band.style.transition = '';
      }
      band.dataset.on = 'true';
    });
  }, [hover, open, height]);

  // Opening with ↓ puts the focus on the panel's first link once it can take it.
  useEffect(() => {
    const id = focusFirst.current;
    if (!id || id !== open) return;
    focusFirst.current = null;
    panes.current.get(id)?.querySelector<HTMLElement>('[data-item]')?.focus();
  }, [open]);

  // A press outside the header and its panel closes the panel.
  useEffect(() => {
    if (!open || video) return;
    const onDown = (event: globalThis.PointerEvent) => {
      if (!top.current?.contains(event.target as Node)) change(null);
    };
    document.addEventListener('pointerdown', onDown);
    return () => document.removeEventListener('pointerdown', onDown);
  });

  // Escape anywhere on the page closes a panel the reader opened, even with the pointer while the
  // focus was elsewhere (WCAG 1.4.13). The header's own keys go first: they mark the event handled.
  // The focus moves back to the trigger only when it was inside the panel.
  useEffect(() => {
    if (!open || video) return;
    const onKey = (event: globalThis.KeyboardEvent) => {
      if (event.key !== 'Escape' || event.defaultPrevented || !acted.current) return;
      event.preventDefault();
      const inside = top.current?.contains(document.activeElement) ?? false;
      change(null);
      if (inside) triggerOf(open)?.focus();
    };
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  });

  // The player takes the focus when opened by hand, and gives it back to its play button.
  useEffect(() => {
    if (!video || !focusPlayer.current) return;
    focusPlayer.current = false;
    player.current?.querySelector<HTMLElement>('[data-close]')?.focus();
  }, [video]);

  useEffect(
    () => () => {
      window.clearTimeout(timers.current.open);
      window.clearTimeout(timers.current.close);
    },
    [],
  );

  const follow = (target: NavTarget) => {
    onNavigate?.(target);
    say(`Opened ${target.label}`);
  };

  const triggerOf = (id: string) =>
    top.current?.querySelector<HTMLElement>(`[data-trigger="${id}"]`) ?? null;

  const playVideo = (section: NavSection) => {
    if (!section.featured) return;
    focusPlayer.current = true;
    setPaused(false);
    setVideo(section.id);
    onPlay?.(section.featured);
    say(`Playing ${section.featured.title}`);
  };

  const closeVideo = () => {
    const id = video;
    setVideo(null);
    say('Video closed');
    if (id) {
      window.requestAnimationFrame(() =>
        panes.current.get(id)?.querySelector<HTMLElement>('[data-play]')?.focus(),
      );
    }
  };

  const toggleSheet = (next = !sheet) => {
    setSheet(next);
    if (!next) setExpanded(null);
    say(next ? 'Menu open' : 'Menu closed');
  };

  // ---- Pointer and keyboard on the header -------------------------------------------------------

  const enterTrigger = (event: PointerEvent, id: string) => {
    if (event.pointerType === 'touch') return;
    window.clearTimeout(timers.current.open);
    window.clearTimeout(timers.current.close);
    if (open === id) return;
    timers.current.open = window.setTimeout(
      () => {
        hoverOpened.current = Date.now();
        change(id);
      },
      open ? SWITCH_DELAY : OPEN_DELAY,
    );
  };

  const clickTrigger = (id: string) => {
    // A click right after the pointer opened it keeps it open rather than closing it again.
    if (open === id && Date.now() - hoverOpened.current < 600) return;
    change(open === id ? null : id);
  };

  const leaveTop = (event: PointerEvent) => {
    window.clearTimeout(timers.current.open);
    if (event.pointerType === 'touch' || !open || video) return;
    timers.current.close = window.setTimeout(() => change(null), CLOSE_DELAY);
  };

  const onTopKey = (event: KeyboardEvent<HTMLDivElement>) => {
    const target = event.target as HTMLElement;
    const { key } = event;
    if (key === 'Escape') {
      if (open) {
        event.preventDefault();
        const id = open;
        change(null);
        triggerOf(id)?.focus();
      } else if (sheet) {
        event.preventDefault();
        toggleSheet(false);
        top.current?.querySelector<HTMLElement>('[data-menu-button]')?.focus();
      }
      return;
    }
    // Along the bar: ← and → move between its items, Home and End to either end.
    if (target.closest('[data-bar]')) {
      const bar = [...(top.current?.querySelectorAll<HTMLElement>('[data-bar]') ?? [])];
      const at = bar.indexOf(target);
      const to =
        key === 'ArrowRight'
          ? (at + 1) % bar.length
          : key === 'ArrowLeft'
            ? (at - 1 + bar.length) % bar.length
            : key === 'Home'
              ? 0
              : key === 'End'
                ? bar.length - 1
                : -1;
      if (to >= 0) {
        event.preventDefault();
        bar[to].focus();
        return;
      }
      const id = target.dataset.trigger;
      if (id && key === 'ArrowDown') {
        event.preventDefault();
        focusFirst.current = id;
        if (open === id) {
          focusFirst.current = null;
          panes.current.get(id)?.querySelector<HTMLElement>('[data-item]')?.focus();
        } else change(id);
      }
      return;
    }
    // Inside a panel: ↑ and ↓ walk its links, the card's button and the play button.
    const pane = target.closest<HTMLElement>('[data-pane]');
    if (pane && open) {
      const list = [...pane.querySelectorAll<HTMLElement>('[data-item]')];
      const at = list.indexOf(target);
      if (at < 0) return;
      let to = -1;
      if (key === 'ArrowDown') to = Math.min(at + 1, list.length - 1);
      else if (key === 'ArrowUp') to = at - 1;
      else if (key === 'Home') to = 0;
      else if (key === 'End') to = list.length - 1;
      else return;
      event.preventDefault();
      if (to < 0) triggerOf(open)?.focus();
      else list[to].focus();
    }
  };

  // Tabbing out of the header and its panel closes the panel.
  const onTopBlur = (event: FocusEvent<HTMLDivElement>) => {
    const next = event.relatedTarget as Node | null;
    if (!open || !next || video) return;
    if (!event.currentTarget.contains(next)) change(null);
  };

  const linkClick = (event: MouseEvent, target: NavTarget) => {
    event.preventDefault();
    follow(target);
    change(null);
    if (sheet) toggleSheet(false);
  };

  // ---- The demo ---------------------------------------------------------------------------------

  const demo = autoplay && !locked && playing;
  const dirty = useEffectEvent(() => open !== null || sheet || video !== null || hover !== null);
  const demoSet = useEffectEvent(
    (what: 'open' | 'hover' | 'sheet' | 'expand', id: string | null) => {
      if (what === 'open') change(id);
      else if (what === 'hover') setHover(id);
      else if (what === 'sheet') toggleSheet(id !== null);
      else {
        setExpanded(id);
        if (id) say(`${labelOf(id)}, expanded`);
      }
    },
  );
  // When the reader takes over by pressing or typing, what they pressed decides; when they only
  // moved the pointer in, the demo's panel closes behind it.
  const demoClear = useEffectEvent(() => {
    if (Date.now() - pressedAt.current < 400) return;
    change(null);
    setHover(null);
    setSheet(false);
    setExpanded(null);
    setVideo(null);
  });

  useEffect(() => {
    const stage = root.current;
    const arrow = pointer.current;
    if (!demo || !stage || !arrow) return;
    const find = (selector: string) => stage.querySelector<HTMLElement>(selector);
    const on = (element: Element | null, fx = 0.5, fy = 0.5): Point => {
      const frame = stage.getBoundingClientRect();
      const scale = frame.width / stage.offsetWidth || 1;
      const rect = element?.getBoundingClientRect() ?? frame;
      return {
        x: (rect.left + rect.width * fx - frame.left) / scale,
        y: (rect.top + rect.height * fy - frame.top) / scale,
      };
    };
    const stop = runDemo(stage, arrow, async ({ wait, glide, glyph }) => {
      const link = (section: string, id: string) =>
        find(`[data-pane="${section}"] [data-link="${id}"]`);
      /** Glides over a section's links, one after the other. */
      const sweep = async (section: string, ids: string[], rest: number) => {
        for (const id of ids) {
          const element = link(section, id);
          if (!element) continue;
          await glide(on(element, 0.62, 0.55), 520);
          glyph('hand');
          demoSet('hover', id);
          await wait(rest);
        }
      };
      const toTrigger = async (id: string, ms: number) => {
        glyph('arrow');
        demoSet('hover', null);
        await glide(on(find(`[data-trigger="${id}"]`), 0.45, 0.55), ms);
        glyph('hand');
        await wait(SWITCH_DELAY + 80);
        demoSet('open', id);
        await wait(520);
      };
      const has = (id: string) => sections.some((section) => section.id === id);
      for (;;) {
        if (dirty()) {
          demoClear();
          await wait(500);
        }
        await wait(900);
        if (stage.querySelector<HTMLElement>('[data-site]')!.offsetWidth < NARROW) {
          // The phone: the sheet, two sections in turn, then closed.
          await glide(on(find('[data-menu-button]')), 800);
          glyph('hand');
          await wait(200);
          demoSet('sheet', 'open');
          await wait(700);
          for (const id of sections.slice(1, 3).map((section) => section.id)) {
            const button = find(`[data-accordion="${id}"]`);
            if (!button) continue;
            glyph('arrow');
            await glide(on(button, 0.3), 600);
            glyph('hand');
            await wait(200);
            demoSet('expand', id);
            await wait(1900);
          }
          await glide(on(find('[data-menu-button]')), 700);
          await wait(200);
          demoSet('sheet', null);
          glyph('arrow');
          await glide(on(stage, 0.8, 0.9), 800);
          await wait(1800);
          continue;
        }
        const resources = has('resources') ? 'resources' : sections[0]?.id;
        if (!resources) return;
        await toTrigger(resources, 800);
        const first = sections.find((section) => section.id === resources)!;
        const ids = first.columns.flatMap((column) => column.links.map((l) => l.id));
        await sweep(resources, ids.slice(0, 3), 700);
        await sweep(resources, ids.slice(5, 6), 1100);
        // Across to the other sections: the panel morphs, the content slides the way it went.
        for (const section of sections.filter((section) => section.id !== resources)) {
          await toTrigger(section.id, 760);
          const more = section.columns.flatMap((column) => column.links.map((l) => l.id));
          await sweep(section.id, [more[0], more[more.length > 3 ? 3 : 1]], 750);
        }
        glyph('arrow');
        demoSet('hover', null);
        await glide(on(stage, 0.42, 0.96), 900);
        demoSet('open', null);
        await wait(2200);
      }
    });
    return () => {
      stop();
      demoClear();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [demo, root]);

  // ---- Drawing ----------------------------------------------------------------------------------

  const openIndex = sections.findIndex((section) => section.id === shown);
  const videoSection = sections.find((section) => section.id === video);

  return (
    <div
      ref={root}
      className={`${styles.root} ${className}`}
      data-part="stage"
      data-color-scheme={colorScheme}
      onPointerDownCapture={() => {
        pressedAt.current = Date.now();
        acted.current = true;
        take();
      }}
      onKeyDownCapture={() => {
        pressedAt.current = Date.now();
        acted.current = true;
        take();
      }}
      onWheel={take}
      onPointerMove={(event) => {
        if (event.pointerType !== 'touch') {
          acted.current = true;
          take();
        }
      }}
    >
      <div className={styles.window} data-part="window">
        <div className={styles.chrome} aria-hidden="true">
          <span />
          <span />
          <span />
        </div>
        <div className={styles.site} data-site="">
          <div
            ref={top}
            className={styles.top}
            onPointerEnter={() => window.clearTimeout(timers.current.close)}
            onPointerLeave={leaveTop}
            onKeyDown={onTopKey}
            onBlur={onTopBlur}
          >
            <header className={styles.header} data-part="header">
              <a
                className={styles.brand}
                href="#top"
                data-part="brand"
                onClick={(event) => linkClick(event, { id: 'home', label: brand, href: '#top' })}
              >
                <Mark />
                <span>{brand}</span>
              </a>
              <nav className={styles.nav} aria-label="Main">
                <ul className={styles.bar}>
                  {items.map((item) =>
                    isSection(item) ? (
                      <li key={item.id}>
                        <button
                          type="button"
                          className={styles.trigger}
                          data-bar=""
                          data-trigger={item.id}
                          data-part="trigger"
                          aria-expanded={open === item.id}
                          aria-controls={`${uid}-pane-${item.id}`}
                          onPointerEnter={(event) => enterTrigger(event, item.id)}
                          onPointerLeave={() => window.clearTimeout(timers.current.open)}
                          onClick={() => clickTrigger(item.id)}
                        >
                          {item.label}
                          <span className={styles.chevron}>
                            <Glyph name="chevron-down" size={16} />
                          </span>
                        </button>
                      </li>
                    ) : (
                      <li key={item.id}>
                        <a
                          className={styles.trigger}
                          href={item.href ?? '#'}
                          data-bar=""
                          onPointerEnter={(event) => {
                            if (event.pointerType === 'touch' || !open) return;
                            window.clearTimeout(timers.current.open);
                            timers.current.open = window.setTimeout(
                              () => change(null),
                              CLOSE_DELAY,
                            );
                          }}
                          onClick={(event) =>
                            linkClick(event, { id: item.id, label: item.label, href: item.href })
                          }
                        >
                          {item.label}
                        </a>
                      </li>
                    ),
                  )}
                </ul>
              </nav>
              <div className={styles.actions}>
                <a
                  className={styles.login}
                  href="#login"
                  onClick={(event) =>
                    linkClick(event, { id: 'login', label: 'Log in', href: '#login' })
                  }
                >
                  Log in
                </a>
                <a
                  className={styles.cta}
                  href="#signup"
                  onClick={(event) =>
                    linkClick(event, { id: 'signup', label: 'Get started', href: '#signup' })
                  }
                >
                  Get started
                </a>
              </div>
              <button
                type="button"
                className={styles.menuButton}
                data-menu-button=""
                data-part="menu-button"
                aria-expanded={sheet}
                aria-controls={`${uid}-sheet`}
                aria-label="Menu"
                onClick={() => toggleSheet()}
              >
                <span className={styles.burger} data-open={sheet || undefined} aria-hidden="true">
                  <span />
                  <span />
                  <span />
                </span>
              </button>
            </header>

            <div
              className={styles.panel}
              data-part="panel"
              data-open={open ? '' : undefined}
              data-morph={menu.morph ? '' : undefined}
              style={height ? { height } : undefined}
            >
              {sections.map((section, index) => {
                const current = section.id === shown;
                const pos = current ? 'current' : index < openIndex ? 'before' : 'after';
                return (
                  <div
                    key={section.id}
                    ref={(element) => {
                      if (element) panes.current.set(section.id, element);
                      else panes.current.delete(section.id);
                    }}
                    id={`${uid}-pane-${section.id}`}
                    className={styles.pane}
                    data-pane={section.id}
                    data-pos={pos}
                    data-solo={section.featured ? undefined : ''}
                    inert={!current || !open}
                  >
                    <div className={styles.columns} onPointerLeave={() => setHover(null)}>
                      <span className={styles.band} data-band="" aria-hidden="true" />
                      {section.columns.map((column) => (
                        <div key={column.id} className={styles.column}>
                          <p
                            id={`${uid}-${section.id}-${column.id}`}
                            className={styles.caption}
                            data-part="caption"
                          >
                            {column.caption}
                          </p>
                          <ul
                            className={styles.links}
                            aria-labelledby={`${uid}-${section.id}-${column.id}`}
                          >
                            {column.links.map((link) => (
                              <li key={link.id}>
                                <a
                                  className={styles.link}
                                  href={link.href ?? `#${link.id}`}
                                  data-item=""
                                  data-link={link.id}
                                  data-part="link"
                                  data-hover={hover === link.id && current ? '' : undefined}
                                  onPointerEnter={(event) => {
                                    if (event.pointerType !== 'touch') setHover(link.id);
                                  }}
                                  onFocus={() => setHover(link.id)}
                                  onClick={(event) =>
                                    linkClick(event, {
                                      id: link.id,
                                      label: link.title,
                                      href: link.href,
                                    })
                                  }
                                >
                                  <span className={styles.tile} data-part="tile">
                                    <Icon name={link.icon} />
                                  </span>
                                  <span className={styles.linkBody}>
                                    <span className={styles.linkTitle}>
                                      {link.title}
                                      {link.badge && (
                                        <span className={styles.badge} data-part="badge">
                                          {link.badge}
                                        </span>
                                      )}
                                    </span>
                                    <span className={styles.linkText}>{link.text}</span>
                                  </span>
                                </a>
                              </li>
                            ))}
                          </ul>
                        </div>
                      ))}
                    </div>
                    {section.featured && (
                      <aside
                        className={styles.featured}
                        data-part="featured"
                        aria-label={section.featured.title}
                        onPointerEnter={() => setHover(null)}
                      >
                        <p className={styles.featuredTitle}>{section.featured.title}</p>
                        <p className={styles.featuredText}>{section.featured.text}</p>
                        <div className={styles.picture}>
                          <Scene name={section.featured.scene} uid={uid} />
                          {section.featured.video && (
                            <button
                              type="button"
                              className={styles.play}
                              data-item=""
                              data-play=""
                              data-part="play"
                              aria-label={`Play the video: ${section.featured.title}`}
                              aria-haspopup="dialog"
                              onClick={() => playVideo(section)}
                            >
                              <Glyph name="play" size={20} />
                            </button>
                          )}
                        </div>
                        <a
                          className={styles.more}
                          href={section.featured.href ?? '#new'}
                          data-item=""
                          data-part="more"
                          onClick={(event) =>
                            linkClick(event, {
                              id: `${section.id}-featured`,
                              label: section.featured!.cta,
                              href: section.featured!.href,
                            })
                          }
                        >
                          {section.featured.cta}
                          <Glyph name="chevron-right" size={16} />
                        </a>
                      </aside>
                    )}
                  </div>
                );
              })}
            </div>
          </div>

          {/* The page under the header, dimmed while a panel is open. */}
          <div className={styles.page} data-part="page">
            <article className={styles.article}>
              <p className={styles.eyebrow}>Product update · 6 min read</p>
              <h2 className={styles.headline}>Live dashboards, one year in</h2>
              <p>
                A year ago, a board in {brand} was a page you refreshed. Today every chart listens
                to the events behind it and redraws the moment they change, so the number on the
                wall is the number right now.
              </p>
              <p>
                We rebuilt the query engine, the chart renderer and the way boards are shared. Most
                of it is invisible: queries run closer to your data, and only the bars that moved
                are drawn again. Read the{' '}
                <a
                  href="#notes"
                  onClick={(event) =>
                    linkClick(event, { id: 'notes', label: 'release notes', href: '#notes' })
                  }
                >
                  release notes
                </a>{' '}
                or start with the{' '}
                <a
                  href="#tour"
                  onClick={(event) =>
                    linkClick(event, { id: 'tour', label: 'five-minute tour', href: '#tour' })
                  }
                >
                  five-minute tour
                </a>
                .
              </p>
              <p>
                Boards now open in under a second for most teams, and the ones with a hundred charts
                no longer stall the tab.
              </p>
              <p>
                Below is what changed, why we changed it and how to move your own boards across.
                Nothing breaks if you wait: old boards keep working until you open them in the new
                editor.
              </p>
            </article>
            <nav className={styles.toc} aria-label="On this page">
              <ul>
                {TOC.map((label, index) => (
                  <li key={label}>
                    <a
                      href={`#section-${index}`}
                      aria-current={toc === index ? 'location' : undefined}
                      onClick={(event) => {
                        event.preventDefault();
                        setToc(index);
                        follow({ id: `section-${index}`, label, href: `#section-${index}` });
                      }}
                    >
                      {label}
                    </a>
                  </li>
                ))}
              </ul>
            </nav>
          </div>
          <div
            className={styles.scrim}
            data-open={open ? '' : undefined}
            data-part="scrim"
            aria-hidden="true"
          />

          {/* The phone's menu: the same items, the sections as accordions. */}
          <div
            id={`${uid}-sheet`}
            className={styles.sheet}
            data-open={sheet ? '' : undefined}
            data-part="sheet"
            inert={!sheet}
            onKeyDown={(event) => {
              if (event.key !== 'Escape') return;
              event.preventDefault();
              toggleSheet(false);
              root.current?.querySelector<HTMLElement>('[data-menu-button]')?.focus();
            }}
          >
            <nav aria-label="Main">
              <ul className={styles.sheetList}>
                {items.map((item) => {
                  if (!isSection(item)) {
                    return (
                      <li key={item.id}>
                        <a
                          className={styles.sheetRow}
                          href={item.href ?? '#'}
                          onClick={(event) =>
                            linkClick(event, { id: item.id, label: item.label, href: item.href })
                          }
                        >
                          {item.label}
                        </a>
                      </li>
                    );
                  }
                  const on = expanded === item.id;
                  return (
                    <li key={item.id}>
                      <button
                        type="button"
                        className={styles.sheetRow}
                        data-accordion={item.id}
                        data-part="accordion"
                        aria-expanded={on}
                        aria-controls={`${uid}-acc-${item.id}`}
                        onClick={() => {
                          setExpanded(on ? null : item.id);
                          say(`${item.label}, ${on ? 'collapsed' : 'expanded'}`);
                        }}
                      >
                        {item.label}
                        <span className={styles.chevron}>
                          <Glyph name="chevron-down" size={18} />
                        </span>
                      </button>
                      <div
                        id={`${uid}-acc-${item.id}`}
                        className={styles.fold}
                        data-open={on ? '' : undefined}
                        inert={!on}
                      >
                        <div className={styles.foldInner}>
                          {item.columns.map((column) => (
                            <div key={column.id} className={styles.sheetColumn}>
                              <p
                                id={`${uid}-sheet-${item.id}-${column.id}`}
                                className={styles.caption}
                              >
                                {column.caption}
                              </p>
                              <ul
                                className={styles.links}
                                aria-labelledby={`${uid}-sheet-${item.id}-${column.id}`}
                              >
                                {column.links.map((link) => (
                                  <li key={link.id}>
                                    <a
                                      className={styles.sheetLink}
                                      href={link.href ?? `#${link.id}`}
                                      onClick={(event) =>
                                        linkClick(event, {
                                          id: link.id,
                                          label: link.title,
                                          href: link.href,
                                        })
                                      }
                                    >
                                      <span className={styles.tile}>
                                        <Icon name={link.icon} />
                                      </span>
                                      <span className={styles.linkBody}>
                                        <span className={styles.linkTitle}>
                                          {link.title}
                                          {link.badge && (
                                            <span className={styles.badge}>{link.badge}</span>
                                          )}
                                        </span>
                                        <span className={styles.linkText}>{link.text}</span>
                                      </span>
                                    </a>
                                  </li>
                                ))}
                              </ul>
                            </div>
                          ))}
                        </div>
                      </div>
                    </li>
                  );
                })}
              </ul>
            </nav>
            <div className={styles.sheetActions}>
              <a
                className={styles.more}
                href="#login"
                onClick={(event) =>
                  linkClick(event, { id: 'login', label: 'Log in', href: '#login' })
                }
              >
                Log in
              </a>
              <a
                className={styles.cta}
                href="#signup"
                onClick={(event) =>
                  linkClick(event, { id: 'signup', label: 'Get started', href: '#signup' })
                }
              >
                Get started
              </a>
            </div>
          </div>

          {videoSection?.featured && (
            <div
              className={styles.playerScrim}
              onPointerDown={(event) => {
                if (event.target === event.currentTarget) closeVideo();
              }}
            >
              <div
                ref={player}
                className={styles.player}
                role="dialog"
                aria-modal="true"
                aria-labelledby={`${uid}-player-title`}
                data-part="player"
                data-paused={paused ? '' : undefined}
                onKeyDown={(event) => {
                  if (event.key === 'Escape') {
                    event.preventDefault();
                    event.stopPropagation();
                    closeVideo();
                    return;
                  }
                  if (event.key !== 'Tab') return;
                  const list = [...event.currentTarget.querySelectorAll<HTMLElement>('button')];
                  const at = list.indexOf(document.activeElement as HTMLElement);
                  const to = event.shiftKey
                    ? (at - 1 + list.length) % list.length
                    : (at + 1) % list.length;
                  event.preventDefault();
                  list[to].focus();
                }}
              >
                <div className={styles.playerHead}>
                  <p id={`${uid}-player-title`} className={styles.featuredTitle}>
                    {videoSection.featured.title}
                  </p>
                  <button
                    type="button"
                    className={styles.iconButton}
                    data-close=""
                    aria-label="Close the video"
                    onClick={closeVideo}
                  >
                    <Glyph name="close" size={18} />
                  </button>
                </div>
                <div className={styles.screen}>
                  <Scene name={videoSection.featured.scene} uid={`${uid}-player`} moving />
                </div>
                <div className={styles.controls}>
                  <button
                    type="button"
                    className={styles.iconButton}
                    aria-label={paused ? 'Play' : 'Pause'}
                    onClick={() => {
                      setPaused(!paused);
                      say(paused ? 'Playing' : 'Paused');
                    }}
                  >
                    <Glyph name={paused ? 'play' : 'pause'} size={16} />
                  </button>
                  <span className={styles.track} aria-hidden="true">
                    <span className={styles.progress} />
                  </span>
                  <span className={styles.time}>12:04</span>
                </div>
              </div>
            </div>
          )}
        </div>
      </div>

      <p className={styles.srOnly} role="status">
        {live}
      </p>

      <div className={styles.pointerLayer}>
        <DemoPointer
          ref={pointer}
          className={styles.pointer}
          arrowClass={styles.arrow}
          handClass={styles.hand}
        />
      </div>
    </div>
  );
}
```

### mega-menu/mega-menu.module.css

```css
/* Mega menu (mega-menu.tsx): a marketing site's header in a browser window on a hatched stage. A
   section of the header drops a full-width panel of captioned columns and a featured card; the
   page under it dims. Under 760 px of site the nav folds into a menu button and a sheet.

   Colours are the tokens below, light-dark(light, dark) where the two differ: the component takes
   the color-scheme it inherits from the page, or the one its colorScheme prop sets
   (data-color-scheme). The featured pictures are painted scenes and keep their colours. Words
   reach 4.5:1 on their surface and the chevrons (--ink-4) 3:1, in both schemes. */

.root {
  --stage: #f4f4f5;
  --hatch: #e6e6e9;
  --window: #fcfcfc;
  --window-edge: #e4e4e7;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --band: #f4f4f5;
  --ink: #181d27;
  --ink-2: #535862;
  --ink-3: #717680;
  --ink-4: #8b8f98;
  --line: #e9eaeb;
  --edge: #d5d7da;
  --tile: #ffffff;
  --shadow: rgb(10 13 18 / 0.05);
  --shadow-2: rgb(10 13 18 / 0.1);
  --scrim-top: rgb(10 13 18 / 0.17);
  --scrim-bottom: rgb(10 13 18 / 0.07);
  --accent: #181d27;
  --accent-ink: #ffffff;
  --player: #ffffff;
  --player-scrim: rgb(10 13 18 / 0.5);
  /* The same on both schemes. */
  --focus: #5b8cff;
  --red: #ff5f57;
  --amber: #febc2e;
  --green: #28c840;
  --pointer: #1c1c1e;
  --pointer-edge: #fff;
  --pointer-shadow: rgb(0 0 0 / 0.3);
  --sans: var(--body, Inter, ui-sans-serif, system-ui, sans-serif);
  --spring: cubic-bezier(0.22, 1.18, 0.36, 1);
  --glide: cubic-bezier(0.3, 1.2, 0.4, 1);
}
@supports (color: light-dark(#fff, #000)) {
  .root {
    --stage: light-dark(#f4f4f5, #101012);
    --hatch: light-dark(#e6e6e9, #1c1c20);
    --window: light-dark(#fcfcfc, #17171a);
    --window-edge: light-dark(#e4e4e7, #2a2a2f);
    --surface: light-dark(#ffffff, #0c0e12);
    --surface-2: light-dark(#f7f7f8, #14171c);
    --band: light-dark(#f4f4f5, #171a20);
    --ink: light-dark(#181d27, #f5f5f6);
    --ink-2: light-dark(#535862, #a4a7ae);
    --ink-3: light-dark(#717680, #85888e);
    --ink-4: light-dark(#8b8f98, #61656c);
    --line: light-dark(#e9eaeb, #22262f);
    --edge: light-dark(#d5d7da, #373a41);
    --tile: light-dark(#ffffff, #0c0e12);
    --shadow: light-dark(rgb(10 13 18 / 0.05), rgb(0 0 0 / 0.4));
    --shadow-2: light-dark(rgb(10 13 18 / 0.1), rgb(0 0 0 / 0.6));
    --scrim-top: light-dark(rgb(10 13 18 / 0.17), rgb(0 0 0 / 0.6));
    --scrim-bottom: light-dark(rgb(10 13 18 / 0.07), rgb(0 0 0 / 0.38));
    --accent: light-dark(#181d27, #f5f5f6);
    --accent-ink: light-dark(#ffffff, #0c0e12);
    --player: light-dark(#ffffff, #14171c);
    --player-scrim: light-dark(rgb(10 13 18 / 0.5), rgb(0 0 0 / 0.66));
  }
}
.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 {
  position: relative;
  width: 100%;
  padding: clamp(10px, 4%, 40px) 0 0 clamp(10px, 4%, 40px);
  overflow: hidden;
  overflow: clip;
  border-radius: 18px;
  background:
    repeating-linear-gradient(-45deg, var(--hatch) 0 1px, transparent 1px 10px), var(--stage);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.root *,
.root *::before,
.root *::after {
  box-sizing: border-box;
}
.root :where(p, ul, h2) {
  margin: 0;
}
.root :where(ul) {
  padding: 0;
  list-style: none;
}
.root :where(a, button) {
  color: inherit;
  font: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.root :where(button) {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}
.root :where(a, button):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- The window -------------------------------------------------------------------------------- */

.window {
  position: relative;
  border: 1px solid var(--window-edge);
  border-right: 0;
  border-bottom: 0;
  border-radius: 14px 0 0 0;
  padding: 0 0 0 8px;
  background: var(--window);
  box-shadow: 0 1px 3px var(--shadow);
}
.chrome {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 38px;
  padding-left: 8px;
}
.chrome span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
}
.chrome span:nth-child(2) {
  background: var(--amber);
}
.chrome span:nth-child(3) {
  background: var(--green);
}

.site {
  position: relative;
  container: site / inline-size;
  min-height: 690px;
  overflow: hidden;
  overflow: clip;
  border: 1px solid var(--line);
  border-right: 0;
  border-bottom: 0;
  border-radius: 10px 0 0 0;
  background: var(--surface);
}
.header,
.pane,
.page,
.sheet {
  --gutter: clamp(16px, 4.2cqi, 64px);
}

/* ---- The header -------------------------------------------------------------------------------- */

.top {
  position: relative;
  z-index: 3;
}
.header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  height: 72px;
  padding: 0 var(--gutter);
  background: var(--surface);
}
.brand {
  display: inline-flex;
  flex: none;
  gap: 8px;
  align-items: center;
  margin-right: 22px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand svg {
  width: 24px;
  height: 24px;
}
.nav {
  min-width: 0;
}
.bar {
  display: flex;
  gap: 2px;
  align-items: center;
}
.trigger {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.chevron {
  display: inline-flex;
  color: var(--ink-4);
  transition: rotate 0.35s var(--spring);
}
[aria-expanded='true'] > .chevron {
  rotate: 180deg;
  color: var(--ink-3);
}
.actions {
  display: flex;
  flex: none;
  gap: 4px;
  align-items: center;
  margin-left: auto;
}
.login {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 600;
}
.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 1px 2px var(--shadow);
}
.menuButton {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: auto;
  margin-right: -8px;
  border-radius: 8px;
  color: var(--ink);
}
.burger {
  position: relative;
  width: 20px;
  height: 14px;
}
.burger span {
  position: absolute;
  left: 0;
  width: 20px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transition:
    translate 0.3s var(--spring),
    rotate 0.3s var(--spring),
    opacity 0.2s ease;
}
.burger span:nth-child(1) {
  top: 0;
}
.burger span:nth-child(2) {
  top: 6px;
}
.burger span:nth-child(3) {
  top: 12px;
}
.burger[data-open] span:nth-child(1) {
  translate: 0 6px;
  rotate: 45deg;
}
.burger[data-open] span:nth-child(2) {
  opacity: 0;
}
.burger[data-open] span:nth-child(3) {
  translate: 0 -6px;
  rotate: -45deg;
}

@media (hover: hover) {
  .trigger:hover,
  .login:hover {
    color: var(--ink-2);
  }
  .trigger:hover > .chevron {
    color: var(--ink-3);
  }
}

/* ---- The panel --------------------------------------------------------------------------------- */

.panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  overflow: hidden;
  overflow: clip;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 12px 16px -4px var(--shadow);
  opacity: 0;
  translate: 0 -6px;
  visibility: hidden;
  transition:
    opacity 0.18s ease,
    translate 0.3s var(--spring),
    visibility 0s linear 0.3s;
}
.panel[data-open] {
  opacity: 1;
  translate: 0 0;
  visibility: visible;
  transition:
    opacity 0.2s ease,
    translate 0.35s var(--spring),
    visibility 0s;
}
.panel[data-open][data-morph] {
  transition:
    opacity 0.2s ease,
    translate 0.35s var(--spring),
    height 0.45s var(--spring);
}

.pane {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(244px, 30cqi, 380px);
  gap: clamp(24px, 4cqi, 56px);
  padding: 36px var(--gutter) 40px;
  opacity: 0;
  translate: var(--from, 0) 0;
  visibility: hidden;
}
.pane[data-solo] {
  grid-template-columns: minmax(0, 1fr);
}
.pane[data-pos='before'] {
  --from: -72px;
}
.pane[data-pos='after'] {
  --from: 72px;
}
.pane[data-pos='current'] {
  position: relative;
  opacity: 1;
  translate: 0 0;
  visibility: visible;
}
.panel[data-morph] .pane {
  transition:
    translate 0.45s var(--spring),
    opacity 0.22s ease,
    visibility 0s linear 0.45s;
}
.panel[data-morph] .pane[data-pos='current'] {
  transition:
    translate 0.45s var(--spring),
    opacity 0.3s ease 0.06s,
    visibility 0s;
}

.columns {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 clamp(12px, 2.5cqi, 40px);
  align-content: start;
}
.column {
  display: grid;
  align-content: start;
  gap: 10px;
}
.caption {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 18px;
  text-transform: uppercase;
}
.links {
  display: grid;
  gap: 4px;
}
.band {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 10px;
  background: var(--band);
  opacity: 0;
  pointer-events: none;
  transition:
    translate 0.38s var(--glide),
    width 0.38s var(--glide),
    height 0.38s var(--glide),
    opacity 0.2s ease;
}
.band[data-on='true'] {
  opacity: 1;
}
.link {
  position: relative;
  display: flex;
  gap: clamp(12px, 1.4cqi, 16px);
  align-items: flex-start;
  margin-left: -12px;
  padding: 12px;
  border-radius: 10px;
}
.tile {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink-2);
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    translate 0.3s var(--spring),
    box-shadow 0.3s ease,
    color 0.2s ease;
}
.tile svg {
  width: 20px;
  height: 20px;
}
.link[data-hover] .tile {
  translate: 0 -2px;
  color: var(--ink);
  box-shadow:
    0 6px 10px -3px var(--shadow-2),
    0 2px 4px -2px var(--shadow-2);
}
.linkBody {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.linkTitle {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  align-items: center;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
}
.linkText {
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
}
.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 1px 2px var(--shadow);
}

.featured {
  display: flex;
  flex-direction: column;
  align-self: start;
  margin: -12px calc(var(--gutter) * -0.4) -12px 0;
  padding: 24px;
  border-radius: 16px;
  background: var(--surface-2);
}
.featuredTitle {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
}
.featuredText {
  margin-top: 4px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
}
.picture {
  position: relative;
  margin-top: 20px;
  overflow: hidden;
  border-radius: 10px;
  aspect-ratio: 16 / 11;
}
.scene {
  display: block;
  width: 100%;
  height: 100%;
}
.play {
  position: absolute;
  left: 7%;
  bottom: 9%;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid rgb(255 255 255 / 0.55);
  border-radius: 18px;
  background: rgb(255 255 255 / 0.26);
  color: #fff;
  box-shadow:
    0 8px 18px -6px rgb(40 10 10 / 0.35),
    inset 0 1px 0 rgb(255 255 255 / 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition:
    scale 0.3s var(--spring),
    background-color 0.2s ease;
}
.play svg {
  translate: 1px 0;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.2));
}
.more {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  height: 40px;
  margin-top: 20px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 1px 2px var(--shadow);
}
.more svg {
  color: var(--ink-4);
}
@media (hover: hover) {
  .play:hover {
    scale: 1.06;
    background-color: rgb(255 255 255 / 0.36);
  }
  .more:hover {
    background: var(--surface-2);
  }
}

/* ---- The page under it ------------------------------------------------------------------------- */

.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  gap: clamp(24px, 6cqi, 96px);
  padding: 40px var(--gutter) 56px;
}
.article {
  display: grid;
  gap: 18px;
  align-content: start;
  max-width: 640px;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 28px;
}
.eyebrow {
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
}
.headline {
  margin: -10px 0 6px;
  color: var(--ink);
  font-size: clamp(26px, 4cqi, 36px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.article a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--ink-4);
  text-underline-offset: 3px;
}
.toc ul {
  display: grid;
  gap: 14px;
  padding-top: 64px;
}
.toc a {
  color: var(--ink-3);
  font-size: 15px;
  font-weight: 600;
}
.toc a[aria-current] {
  color: var(--ink);
}
.scrim {
  position: absolute;
  inset: 72px 0 0;
  z-index: 2;
  background: linear-gradient(to bottom, var(--scrim-top), var(--scrim-bottom) 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.scrim[data-open] {
  opacity: 1;
}

/* ---- The phone's sheet ------------------------------------------------------------------------- */

.sheet {
  position: absolute;
  inset: 72px 0 0;
  z-index: 4;
  display: none;
  flex-direction: column;
  gap: 24px;
  padding: 8px var(--gutter) 24px;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: var(--surface);
  opacity: 0;
  translate: 0 -8px;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    translate 0.35s var(--spring),
    visibility 0s linear 0.35s;
}
.sheet[data-open] {
  opacity: 1;
  translate: 0 0;
  visibility: visible;
  transition:
    opacity 0.2s ease,
    translate 0.35s var(--spring),
    visibility 0s;
}
.sheetList > li {
  border-bottom: 1px solid var(--line);
}
.sheetRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 52px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
}
.fold {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.4s var(--spring);
}
.fold[data-open] {
  grid-template-rows: 1fr;
}
.foldInner {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}
.fold[data-open] .foldInner {
  padding-bottom: 16px;
}
.sheetColumn {
  display: grid;
  gap: 6px;
}
.sheetLink {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
  border-radius: 8px;
}
.sheetLink .tile {
  width: 36px;
  height: 36px;
}
.sheetLink .tile svg {
  width: 18px;
  height: 18px;
}
.sheetLink .linkTitle {
  font-size: 14px;
  line-height: 20px;
}
.sheetLink .linkText {
  font-size: 13px;
  line-height: 18px;
}
.sheetActions {
  display: grid;
  gap: 10px;
}
.sheetActions .more {
  margin: 0;
}

/* ---- The player -------------------------------------------------------------------------------- */

.playerScrim {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--player-scrim);
  animation: fade 0.2s ease;
}
.player {
  display: grid;
  gap: 12px;
  width: min(560px, 100%);
  padding: 16px;
  border-radius: 16px;
  background: var(--player);
  box-shadow: 0 24px 48px -12px rgb(0 0 0 / 0.35);
  animation: rise 0.4s var(--spring);
}
.playerHead,
.controls {
  display: flex;
  gap: 12px;
  align-items: center;
}
.playerHead p {
  flex: 1;
}
.iconButton {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--ink-2);
}
@media (hover: hover) {
  .iconButton:hover {
    background: var(--band);
    color: var(--ink);
  }
}
.screen {
  overflow: hidden;
  border-radius: 10px;
  aspect-ratio: 16 / 10;
}
.track {
  position: relative;
  flex: 1;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--line);
}
.progress {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background: var(--accent);
  transform-origin: left;
  animation: progress 12s linear infinite;
}
.time {
  color: var(--ink-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.player[data-paused] .progress,
.player[data-paused] .grow,
.player[data-paused] .draw,
.player[data-paused] .bob {
  animation-play-state: paused;
}

/* The pictures' moving parts, in the player. */
.grow {
  transform-box: fill-box;
  transform-origin: bottom;
  animation: grow 2.8s var(--spring) infinite alternate;
}
.draw {
  animation: draw 3.2s ease-in-out infinite;
}
.bob {
  animation: bob 4s ease-in-out infinite alternate;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    scale: 0.96;
    translate: 0 8px;
  }
}
@keyframes progress {
  from {
    scale: 0 1;
  }
  to {
    scale: 1 1;
  }
}
@keyframes grow {
  from {
    scale: 1 0.35;
  }
  to {
    scale: 1 1;
  }
}
@keyframes draw {
  0% {
    stroke-dashoffset: 1;
  }
  60%,
  100% {
    stroke-dashoffset: 0;
  }
}
@keyframes bob {
  to {
    translate: 0 -4px;
  }
}

/* ---- Narrow sites: the menu button and its sheet ----------------------------------------------- */

@container site (max-width: 959px) {
  .login {
    display: none;
  }
  .linkText {
    font-size: 13px;
    line-height: 19px;
  }
  .page {
    grid-template-columns: minmax(0, 1fr) 160px;
  }
}
@container site (max-width: 759px) {
  .header {
    height: 64px;
  }
  .nav,
  .actions,
  .panel,
  .scrim {
    display: none;
  }
  .menuButton {
    display: grid;
  }
  .sheet {
    display: flex;
    inset: 64px 0 0;
  }
  .page {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 28px;
  }
  .toc {
    display: none;
  }
  .article {
    gap: 14px;
    font-size: 15px;
    line-height: 24px;
  }
}

/* ---- The demo's pointer ------------------------------------------------------------------------ */

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

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

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel[data-open],
  .panel[data-morph] .pane,
  .band,
  .tile,
  .chevron,
  .burger span,
  .sheet,
  .fold,
  .scrim,
  .play {
    transition: none !important;
  }
  .playerScrim,
  .player,
  .progress,
  .grow,
  .draw,
  .bob {
    animation: none;
  }
}
```

### mega-menu/data.ts

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

import type { IconName, SceneName } from './glyphs';

/*
 * What the header shows: plain links, and sections that open a panel of columns with a featured
 * card. The defaults are a made-up analytics product's site, Tessera.
 */

/** One entry in a panel: an icon tile, a title, two lines on it and an optional badge. */
export type MenuLink = {
  id: string;
  title: string;
  text: string;
  icon: IconName;
  badge?: string;
  href?: string;
};

/** A captioned column of links. */
export type MenuColumn = { id: string; caption: string; links: MenuLink[] };

/** The tinted card at the right of a panel; `video` puts a play button on its picture. */
export type Featured = {
  title: string;
  text: string;
  scene: SceneName;
  cta: string;
  href?: string;
  video?: boolean;
};

/** A header item: a plain link, or a section with a panel. */
export type NavItem =
  | { id: string; label: string; href?: string }
  | { id: string; label: string; columns: MenuColumn[]; featured?: Featured };

export type NavSection = Extract<NavItem, { columns: MenuColumn[] }>;

export const isSection = (item: NavItem): item is NavSection => 'columns' in item;

export const NAV: NavItem[] = [
  { id: 'features', label: 'Features', href: '#features' },
  {
    id: 'products',
    label: 'Products',
    columns: [
      {
        id: 'platform',
        caption: 'Platform',
        links: [
          {
            id: 'analytics',
            title: 'Analytics',
            text: 'Every event and funnel, and who came back next week.',
            icon: 'chart',
          },
          {
            id: 'dashboards',
            title: 'Dashboards',
            text: 'Boards the whole team can read, updated as data moves.',
            icon: 'layout',
          },
          {
            id: 'automations',
            title: 'Automations',
            text: 'Ping a channel or open a ticket when a number moves.',
            icon: 'bolt',
            badge: 'New',
          },
        ],
      },
      {
        id: 'developers',
        caption: 'Developers',
        links: [
          {
            id: 'api',
            title: 'API reference',
            text: 'Every endpoint, with examples and a sandbox to try.',
            icon: 'terminal',
          },
          {
            id: 'integrations',
            title: 'Integrations',
            text: 'Your warehouse, your CRM and forty other sources.',
            icon: 'plug',
          },
          {
            id: 'security',
            title: 'Security',
            text: 'Single sign-on, audit logs and data in your region.',
            icon: 'shield',
          },
        ],
      },
    ],
    featured: {
      title: 'Tessera on your phone',
      text: 'Your boards in your pocket, with an alert when a number moves.',
      scene: 'phone',
      cta: 'Get the app',
    },
  },
  {
    id: 'resources',
    label: 'Resources',
    columns: [
      {
        id: 'resources',
        caption: 'Resources',
        links: [
          {
            id: 'blog',
            title: 'Blog',
            text: 'Product news, release notes and long reads from the team.',
            icon: 'book',
          },
          {
            id: 'stories',
            title: 'Customer stories',
            text: 'How teams moved their reporting onto one canvas.',
            icon: 'smile',
          },
          {
            id: 'tutorials',
            title: 'Video tutorials',
            text: 'Short walkthroughs, from a first chart to a shared board.',
            icon: 'play',
          },
          {
            id: 'docs',
            title: 'Documentation',
            text: 'Guides, reference and recipes for every release.',
            icon: 'code',
          },
        ],
      },
      {
        id: 'company',
        caption: 'Company',
        links: [
          {
            id: 'about',
            title: 'About us',
            text: 'Where we started, what we believe and what’s next.',
            icon: 'flag',
          },
          {
            id: 'careers',
            title: 'Careers',
            text: 'We’re looking for curious people. Work from anywhere.',
            icon: 'briefcase',
            badge: 'We’re hiring!',
          },
          {
            id: 'community',
            title: 'Community',
            text: 'The forum, monthly office hours and other builders.',
            icon: 'chat',
          },
          {
            id: 'legal',
            title: 'Legal',
            text: 'Licences, privacy policy and terms, in plain words.',
            icon: 'scale',
          },
        ],
      },
    ],
    featured: {
      title: 'Introducing live dashboards',
      text: 'We’ve rebuilt boards from the ground up. Turn raw events into charts that update live.',
      scene: 'dashboard',
      cta: 'See what’s new',
      video: true,
    },
  },
  {
    id: 'blog',
    label: 'Blog',
    columns: [
      {
        id: 'topics',
        caption: 'Topics',
        links: [
          {
            id: 'engineering',
            title: 'Engineering',
            text: 'Querying a billion events in under a second.',
            icon: 'terminal',
          },
          {
            id: 'design',
            title: 'Design',
            text: 'Charts, colour and type, from the team that draws them.',
            icon: 'pen',
          },
          {
            id: 'guides',
            title: 'Guides',
            text: 'Metrics worth tracking and boards worth sharing.',
            icon: 'compass',
          },
        ],
      },
      {
        id: 'series',
        caption: 'Series',
        links: [
          {
            id: 'office-hours',
            title: 'Office hours',
            text: 'A monthly hour of questions with the people who build it.',
            icon: 'mic',
            badge: 'Live today',
          },
          {
            id: 'field-notes',
            title: 'Field notes',
            text: 'Customers on the one chart that changed a decision.',
            icon: 'bulb',
          },
          {
            id: 'changelog',
            title: 'Changelog',
            text: 'Everything we shipped, fixed or improved this month.',
            icon: 'rocket',
          },
        ],
      },
    ],
    featured: {
      title: 'Drawing a better bar chart',
      text: 'A twelve-minute session from our design team on spacing, labels and colour.',
      scene: 'studio',
      cta: 'Watch the session',
      video: true,
    },
  },
  { id: 'pricing', label: 'Pricing', href: '#pricing' },
  { id: 'docs', label: 'Docs', href: '#docs' },
];
```

### mega-menu/glyphs.tsx

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

'use client';

import styles from './mega-menu.module.css';

/*
 * The drawings: line icons for the tiles, the header's small glyphs, the brand's pixel mark, and
 * the featured cards' pictures. The pictures are painted scenes, so they keep their colours in
 * both schemes; in the player their bars and lines move (classes in mega-menu.module.css).
 */

export type IconName =
  | 'book'
  | 'smile'
  | 'play'
  | 'code'
  | 'flag'
  | 'briefcase'
  | 'chat'
  | 'scale'
  | 'chart'
  | 'layout'
  | 'bolt'
  | 'terminal'
  | 'plug'
  | 'shield'
  | 'pen'
  | 'compass'
  | 'mic'
  | 'bulb'
  | 'rocket';

const PATHS: Record<IconName, string> = {
  book: 'M12 6.6C10.4 5.4 8 4.8 4.5 4.8v12.6c3.5 0 5.9.6 7.5 1.8 1.6-1.2 4-1.8 7.5-1.8V4.8c-3.5 0-5.9.6-7.5 1.8zM12 6.6v12.6',
  smile:
    'M12 20a8 8 0 1 0-7-4.2L4 20l4.2-1A8 8 0 0 0 12 20zM9 13.4c.8.9 1.8 1.3 3 1.3s2.2-.4 3-1.3M9.3 10h.01M14.7 10h.01',
  play: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM10.2 8.8v6.4l5-3.2z',
  code: 'M14 4.5l-4 15M8 8l-4 4 4 4M16 8l4 4-4 4',
  flag: 'M5.5 21V4M5.5 4.5h11.5l-2.2 4 2.2 4H5.5',
  briefcase:
    'M5 7.5h14a2 2 0 0 1 2 2V18a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V9.5a2 2 0 0 1 2-2zM9 7.5V6a1.5 1.5 0 0 1 1.5-1.5h3A1.5 1.5 0 0 1 15 6v1.5M3 12.8h18M12 12v2',
  chat: 'M16 8.5h2.5A2.5 2.5 0 0 1 21 11v7.5l-2.6-2.1H12a2.5 2.5 0 0 1-2.5-2.5v-.6M5.5 3.5h8A2.5 2.5 0 0 1 16 6v4.5a2.5 2.5 0 0 1-2.5 2.5H7.3L3 16.3V6a2.5 2.5 0 0 1 2.5-2.5z',
  scale:
    'M12 4v16M8 20h8M5 7.2h14M12 4.5l-7 2.7M12 4.5l7 2.7M5 7.2l-3 6a3 3 0 0 0 6 0zM19 7.2l-3 6a3 3 0 0 0 6 0z',
  chart: 'M4 20h16M7 16.5v-5M12 16.5V6.5M17 16.5v-8',
  layout:
    'M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zM3 9.5h18M9.5 9.5V20',
  bolt: 'M13.5 3L5 13.5h6.5L10.5 21 19 10.5h-6.5z',
  terminal:
    'M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zM7.5 9.5l3 2.5-3 2.5M13 15h4',
  plug: 'M9 3v4M15 3v4M7 7h10v3.5a5 5 0 0 1-10 0zM12 15.5V21',
  shield: 'M12 3l7 3v5.5c0 4.4-3 7.8-7 9.5-4-1.7-7-5.1-7-9.5V6zM9 12l2 2 4-4',
  pen: 'M14.5 5.5l4 4M4 20l1-4.6L15.6 4.8a1.6 1.6 0 0 1 2.3 0l1.3 1.3a1.6 1.6 0 0 1 0 2.3L8.6 19z',
  compass: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM15.6 8.4l-2 5.2-5.2 2 2-5.2z',
  mic: 'M12 3a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V6a3 3 0 0 1 3-3zM5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21',
  bulb: 'M9.2 18h5.6M10.2 21h3.6M12 3a6 6 0 0 0-3.6 10.8c.6.5 1 1.2 1 2v.2h5.2v-.2c0-.8.4-1.5 1-2A6 6 0 0 0 12 3z',
  rocket:
    'M14 15.5l-5.5-5.5C10 6 13.5 3.6 20.4 3.6 20.4 10.5 18 14 14 15.5zM8.5 10H5l2.6-3.4H11M14 15.5V19l3.4-2.6V13M15.3 8.7h.01M5.5 15.5c-1.2.7-1.8 2.2-2 4.5 2.3-.2 3.8-.8 4.5-2',
};

/** A line icon for a tile, drawn in the current colour. */
export function Icon({ name, size = 20 }: { name: IconName; size?: number }) {
  return (
    <svg
      viewBox="0 0 24 24"
      width={size}
      height={size}
      fill="none"
      stroke="currentColor"
      strokeWidth="1.6"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d={PATHS[name]} />
    </svg>
  );
}

type GlyphName = 'chevron-down' | 'chevron-right' | 'close' | 'menu' | 'play' | 'pause';

/** The header's and the player's small glyphs. */
export function Glyph({ name, size = 16 }: { name: GlyphName; size?: number }) {
  const solid = name === 'play' || name === 'pause';
  const d = {
    'chevron-down': 'M6 9l6 6 6-6',
    'chevron-right': 'M9 6l6 6-6 6',
    close: 'M6 6l12 12M18 6L6 18',
    menu: 'M4 7h16M4 12h16M4 17h16',
    play: 'M8 5.2v13.6a.8.8 0 0 0 1.2.7l10.6-6.8a.8.8 0 0 0 0-1.4L9.2 4.5a.8.8 0 0 0-1.2.7z',
    pause: 'M7 5h3.2v14H7zM13.8 5H17v14h-3.2z',
  }[name];
  return (
    <svg
      viewBox="0 0 24 24"
      width={size}
      height={size}
      fill={solid ? 'currentColor' : 'none'}
      stroke={solid ? 'none' : 'currentColor'}
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d={d} />
    </svg>
  );
}

/** The brand's mark: pixels fading out from one corner, in the current colour. */
export function Mark({ size = 24 }: { size?: number }) {
  // Column, row and strength of each pixel on a 6 × 6 grid.
  const cells: [number, number, number][] = [
    [4, 0, 1],
    [5, 0, 0.55],
    [3, 1, 0.35],
    [4, 1, 0.8],
    [5, 1, 1],
    [2, 2, 0.25],
    [3, 2, 0.6],
    [4, 2, 0.3],
    [1, 3, 0.3],
    [2, 3, 0.75],
    [0, 4, 0.55],
    [1, 4, 1],
    [2, 4, 0.4],
    [0, 5, 1],
    [1, 5, 0.65],
  ];
  return (
    <svg viewBox="0 0 24 24" width={size} height={size} fill="currentColor" aria-hidden="true">
      {cells.map(([x, y, o]) => (
        <rect key={`${x}-${y}`} x={x * 4} y={y * 4} width="4" height="4" opacity={o} />
      ))}
    </svg>
  );
}

export type SceneName = 'dashboard' | 'phone' | 'studio';

/**
 * A featured card's picture, 320 × 200. `moving` sets its bars and lines going, for the player.
 * Each scene draws its own gradient under an id made unique by `uid`.
 */
export function Scene({ name, uid, moving }: { name: SceneName; uid: string; moving?: boolean }) {
  const g = `${uid}-${name}`;
  const grow = moving ? styles.grow : undefined;
  const draw = moving ? styles.draw : undefined;
  const bob = moving ? styles.bob : undefined;
  return (
    <svg
      viewBox="0 0 320 200"
      preserveAspectRatio="xMidYMid slice"
      className={styles.scene}
      aria-hidden="true"
    >
      {name === 'dashboard' && (
        <>
          <defs>
            <linearGradient id={`${g}-bg`} x1="0" y1="0" x2="1" y2="1">
              <stop offset="0" stopColor="#f6dcd3" />
              <stop offset="1" stopColor="#e9a9a4" />
            </linearGradient>
          </defs>
          <rect width="320" height="200" fill={`url(#${g}-bg)`} />
          <circle cx="44" cy="26" r="46" fill="#f9e9e1" opacity="0.7" />
          <circle cx="296" cy="188" r="64" fill="#de8f8d" opacity="0.45" />
          <rect x="30" y="118" width="40" height="64" rx="4" fill="#efc2b7" />
          <rect x="36" y="128" width="28" height="4" rx="2" fill="#e3a69c" />
          <rect x="36" y="138" width="20" height="4" rx="2" fill="#e3a69c" />
          {/* The board. */}
          <g className={bob}>
            <rect x="96" y="34" width="196" height="134" rx="10" fill="#fff" />
            <rect x="96" y="34" width="196" height="134" rx="10" fill="none" stroke="#f0d3cd" />
            <circle cx="110" cy="48" r="3" fill="#f2b8b0" />
            <circle cx="120" cy="48" r="3" fill="#f6d2a2" />
            <circle cx="130" cy="48" r="3" fill="#bfe0c9" />
            <rect x="108" y="62" width="54" height="6" rx="3" fill="#2b2f3a" />
            <rect x="108" y="73" width="34" height="5" rx="2.5" fill="#c9ccd3" />
            {[0, 1, 2, 3, 4, 5, 6].map((i) => (
              <rect
                key={i}
                className={grow}
                style={{ animationDelay: `${i * -0.35}s` }}
                x={110 + i * 15}
                y={152 - [26, 40, 32, 54, 46, 62, 70][i]}
                width="9"
                height={[26, 40, 32, 54, 46, 62, 70][i]}
                rx="2.5"
                fill={i === 6 ? '#e2574c' : '#f2b8b0'}
              />
            ))}
            <rect x="222" y="62" width="58" height="92" rx="6" fill="#fbf1ee" />
            <circle cx="251" cy="94" r="18" fill="none" stroke="#f2d6d1" strokeWidth="7" />
            <circle
              cx="251"
              cy="94"
              r="18"
              fill="none"
              stroke="#e2574c"
              strokeWidth="7"
              strokeDasharray="78 200"
              strokeLinecap="round"
              transform="rotate(-90 251 94)"
            />
            <rect x="232" y="124" width="38" height="5" rx="2.5" fill="#2b2f3a" />
            <rect x="236" y="135" width="30" height="4" rx="2" fill="#c9ccd3" />
          </g>
          <path
            className={draw}
            d="M104 130c14-6 24 4 38-6s22-22 36-16 18 2 30-14"
            fill="none"
            stroke="#2b2f3a"
            strokeWidth="2.5"
            strokeLinecap="round"
            pathLength={1}
            strokeDasharray="1"
            opacity="0.85"
          />
        </>
      )}
      {name === 'phone' && (
        <>
          <defs>
            <linearGradient id={`${g}-bg`} x1="0" y1="0" x2="1" y2="1">
              <stop offset="0" stopColor="#d9f0e6" />
              <stop offset="1" stopColor="#9fd4c0" />
            </linearGradient>
          </defs>
          <rect width="320" height="200" fill={`url(#${g}-bg)`} />
          <circle cx="270" cy="40" r="52" fill="#e9f7f1" opacity="0.7" />
          <circle cx="40" cy="190" r="60" fill="#86c7ad" opacity="0.45" />
          <g className={bob}>
            <rect x="118" y="18" width="92" height="190" rx="18" fill="#1d2630" />
            <rect x="124" y="24" width="80" height="178" rx="13" fill="#f7faf9" />
            <rect x="150" y="30" width="28" height="6" rx="3" fill="#1d2630" />
            <rect x="132" y="48" width="40" height="5" rx="2.5" fill="#1d2630" />
            <rect x="132" y="58" width="26" height="4" rx="2" fill="#a9b4b0" />
            <rect x="132" y="70" width="64" height="44" rx="6" fill="#e6f4ee" />
            <path
              className={draw}
              d="M136 104l9-8 8 4 10-12 9 5 10-13"
              fill="none"
              stroke="#1f8a62"
              strokeWidth="2.2"
              strokeLinecap="round"
              strokeLinejoin="round"
              pathLength={1}
              strokeDasharray="1"
            />
            <rect x="132" y="122" width="30" height="30" rx="6" fill="#e6f4ee" />
            <rect x="166" y="122" width="30" height="30" rx="6" fill="#fdf0dc" />
            <rect x="137" y="140" width="18" height="5" rx="2.5" fill="#1f8a62" />
            <rect x="171" y="140" width="18" height="5" rx="2.5" fill="#c9862b" />
          </g>
          {/* The alert. */}
          <g className={bob} style={{ animationDelay: '-1.2s' }}>
            <rect x="194" y="96" width="98" height="36" rx="9" fill="#fff" />
            <circle cx="210" cy="114" r="7" fill="#1f8a62" />
            <rect x="222" y="106" width="56" height="5" rx="2.5" fill="#1d2630" />
            <rect x="222" y="116" width="40" height="4" rx="2" fill="#a9b4b0" />
          </g>
        </>
      )}
      {name === 'studio' && (
        <>
          <defs>
            <linearGradient id={`${g}-bg`} x1="0" y1="0" x2="1" y2="1">
              <stop offset="0" stopColor="#e7e2fb" />
              <stop offset="1" stopColor="#bdb0ef" />
            </linearGradient>
          </defs>
          <rect width="320" height="200" fill={`url(#${g}-bg)`} />
          <circle cx="60" cy="40" r="54" fill="#f3f0fd" opacity="0.6" />
          <circle cx="300" cy="170" r="56" fill="#a796e6" opacity="0.4" />
          {/* A sheet with a chart being drawn, a pencil and a ruler. */}
          <g className={bob}>
            <g transform="rotate(-6 160 104)">
              <rect x="74" y="30" width="172" height="140" rx="6" fill="#fffdf8" />
              <path d="M96 150h128M96 150V52" stroke="#d6d0e8" strokeWidth="1.5" />
              {[0, 1, 2, 3, 4].map((i) => (
                <rect
                  key={i}
                  className={grow}
                  style={{ animationDelay: `${i * -0.4}s` }}
                  x={108 + i * 22}
                  y={150 - [34, 58, 46, 74, 88][i]}
                  width="14"
                  height={[34, 58, 46, 74, 88][i]}
                  rx="3"
                  fill={i === 4 ? '#5b46d6' : '#c8bdf4'}
                />
              ))}
              <path
                className={draw}
                d="M112 108c18-6 30-26 52-26s34-14 54-34"
                fill="none"
                stroke="#2c2448"
                strokeWidth="2"
                strokeLinecap="round"
                strokeDasharray="1"
                pathLength={1}
              />
            </g>
          </g>
          <g transform="rotate(38 252 70)">
            <rect x="200" y="64" width="96" height="11" rx="2" fill="#f2c14e" />
            <path d="M296 64l14 5.5-14 5.5z" fill="#f4dcb0" />
            <path d="M306 67.5l4 2-4 2z" fill="#2c2448" />
            <rect x="192" y="64" width="10" height="11" rx="2" fill="#e88b8b" />
          </g>
          <rect x="26" y="150" width="110" height="16" rx="3" fill="#f6f2e6" />
          {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => (
            <rect
              key={i}
              x={34 + i * 10}
              y="150"
              width="1.5"
              height={i % 5 === 0 ? 8 : 5}
              fill="#9a8fb8"
            />
          ))}
        </>
      )}
    </svg>
  );
}
```

### mega-menu/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. 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 (mega-menu.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 what it can press. It is
 * decorative: what it does shows on the menu 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>
  );
}
```

### mega-menu/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 not while the reader is using it. `take()` hands it to the reader; it
 * takes back over `idle` ms after their last input.
 */
export function useAutoplay<T extends HTMLElement>(idle = 6000) {
  const ref = useRef<T>(null);
  const [visible, setVisible] = useState(false);
  const [reduced, setReduced] = useState(true);
  const [taken, setTaken] = useState(false);
  const timer = useRef(0);

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

  const take = useCallback(() => {
    setTaken(true);
    window.clearTimeout(timer.current);
    timer.current = window.setTimeout(() => setTaken(false), idle);
  }, [idle]);
  useEffect(() => () => window.clearTimeout(timer.current), []);

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