# Side Reveal Menu

> A menu under the page: the page slides left and shrinks into a card, the menu was underneath, and each link rises as the page's edge passes. A click on the card closes it.

Navigation · menu, side menu, burger, nav, dialog, push menu · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-27
Demo: https://kodza.dev/components/side-reveal-menu/
Source on GitHub: https://github.com/kodza-dev/kodza/tree/main/components/side-reveal-menu

Takes the whole screen (or reacts to the page scroll): give it a page, not a small box.

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-side-reveal-menu.css`](https://kodza.dev/registry/side-reveal-menu/kodza-side-reveal-menu.css) · 18.8 KB
- [`kodza-side-reveal-menu.js`](https://kodza.dev/registry/side-reveal-menu/kodza-side-reveal-menu.js) · 30.3 KB
- [`kodza-side-reveal-menu.html`](https://kodza.dev/registry/side-reveal-menu/kodza-side-reveal-menu.html) · 2.5 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-side-reveal-menu.css https://kodza.dev/registry/side-reveal-menu/kodza-side-reveal-menu.css
curl -fsSL --create-dirs -o kodza/kodza-side-reveal-menu.js https://kodza.dev/registry/side-reveal-menu/kodza-side-reveal-menu.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-side-reveal`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-side-reveal-bg: #0a0a0a` — the menu, under the page
  - `--kz-side-reveal-fg: #f2f2f0`
  - `--kz-side-reveal-muted: rgba(242, 242, 240, 0.62)`
  - `--kz-side-reveal-ink: #0a0a0a` — the Menu button, on the page
  - `--kz-side-reveal-on-ink: #ffffff`
  - `--kz-side-reveal-page: auto` — the page colour while it steps aside; auto = the first background above it
  - `--kz-side-reveal-top: calc(var(--wp-admin--admin-bar--height, 0px) + 20px)` — match your header, so Close lands right where Menu was (below the WordPress admin bar)
  - `--kz-side-reveal-side: 24px`
  - `--kz-side-reveal-width: min(clamp(340px, 40cqw, 560px), calc(100cqw - 56px))` — the menu column; on a phone a strip of the page stays in view
  - `--kz-side-reveal-size: clamp(36px, min(4.6cqw + 8px, calc((100cqh - 300px) / 5.6)), 72px)`
  - `--kz-side-reveal-depth: 0.88` — the page's size once aside
  - `--kz-side-reveal-shadow: 0 32px 80px -24px rgba(0, 0, 0, 0.45)` — under the card, seen on a light menu
  - `--kz-side-reveal-shade: 0.5` — without a page: how dark the page gets under the menu
  - `--kz-side-reveal-duration: 1s`
  - `--kz-side-reveal-ease: cubic-bezier(0.76, 0, 0.24, 1)`
- Attributes:
  - `data-page`
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Keyboard

What each key does, by where the focus is. Keep it working when you adapt the HTML: same elements, same classes.

- On the button (focus in `.kodza-side-reveal__toggle`):
  - `Enter` / `Space`: Opens it on the current link, or the first
- In the menu (focus in `.kodza-side-reveal__panel`):
  - `ArrowDown` / `ArrowUp`: Next or previous link, round and round
  - `Home` / `End`: First or last link
  - `Tab` / `Shift+Tab`: Stays inside the menu, round and round
  - `PageUp` / `PageDown`: Held back, the page behind stays put
- Anywhere, while it's open (while `.kodza-side-reveal__toggle[aria-expanded="true"]` is on the page):
  - `Escape`: Brings the page back, focus back on Menu

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-side-reveal {
    --kz-side-reveal-bg: #f2f2f0;
    --kz-side-reveal-fg: #0a0a0a;
    --kz-side-reveal-muted: rgba(10, 10, 10, 0.62);
    --kz-side-reveal-ink: #f2f2f0;
    --kz-side-reveal-on-ink: #0a0a0a;
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-side-reveal { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-side-reveal-menu.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-side-reveal-menu.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- Where it goes, step by step. (1) Inside the site's header, at its right end, in place of the header's links and burger; keep its call-to-action button. Only the Menu button shows there; the site's own links go in the menu, one kodza-side-reveal__link each, and the info block takes the site's email and social links. (2) If those links were what pushed the header's buttons to the right (an auto margin), give the remaining button group margin-left: auto. (3) Mark the element wrapping the whole site, the page that steps aside, with data-side-reveal-page, or name it on the menu with data-page="#page". It must fill the screen; without one, the menu slides in over the page. (4) Always, last: Close is uncovered at the top right of the screen, so tell it where Menu sits. On .kodza-side-reveal, set --kz-side-reveal-top to the Menu button's distance from the top of the screen and --kz-side-reveal-side to its distance from the right edge, e.g. style="--kz-side-reveal-top: 22px; --kz-side-reveal-side: 22px"; for a header centred at a max width, --kz-side-reveal-side: calc((100vw - 1080px) / 2 + 10px), with that header's max width and inner padding. Skip it and Close shows up in the corner of the screen.
- JS: `kodza/kodza-side-reveal-menu.js`, loaded with `<script src="kodza/kodza-side-reveal-menu.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-side-reveal-menu.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-side-reveal-menu.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.
- Where it goes, step by step. (1) Inside the site's header, at its right end, in place of the header's links and burger; keep its call-to-action button. Only the Menu button shows there; the site's own links go in the menu, one kodza-side-reveal__link each, and the info block takes the site's email and social links. (2) If those links were what pushed the header's buttons to the right (an auto margin), give the remaining button group margin-left: auto. (3) Mark the element wrapping the whole site, the page that steps aside, with data-side-reveal-page, or name it on the menu with data-page="#page". It must fill the screen; without one, the menu slides in over the page. (4) Always, last: Close is uncovered at the top right of the screen, so tell it where Menu sits. On .kodza-side-reveal, set --kz-side-reveal-top to the Menu button's distance from the top of the screen and --kz-side-reveal-side to its distance from the right edge, e.g. style="--kz-side-reveal-top: 22px; --kz-side-reveal-side: 22px"; for a header centred at a max width, --kz-side-reveal-side: calc((100vw - 1080px) / 2 + 10px), with that header's max width and inner padding. Skip it and Close shows up in the corner of the screen.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- This one is inline (it flows like a word): pasted alone, many themes leave it at the edge of the page (block themes, and classic ones like Twenty Twenty-One or Blocksy), so put the Custom HTML block inside a **Group** block to line it up with the text.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-side-reveal-menu', $uri . 'kodza-side-reveal-menu.css', [], filemtime($dir . 'kodza-side-reveal-menu.css'));
    wp_enqueue_script('kodza-side-reveal-menu', $uri . 'kodza-side-reveal-menu.js', [], filemtime($dir . 'kodza-side-reveal-menu.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: it takes the colour of the text around it (or keeps its own monochrome): nothing to point at the theme.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).
- Put it in the site header (Site Editor → Patterns → Header) or anywhere in the page. The page that steps aside is found on its own in block themes and in Astra, GeneratePress, Kadence, OceanWP, Blocksy or Divi; for another wrapper, name it on the menu with data-page=".site". With no wrapper at all (Hello Elementor), the menu slides in over a dimmed page. Close stays below the admin bar.

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above. This one reads the page around it, and a script in the widget runs before the rest of the page exists: put its `<script>` in an HTML widget at the bottom of the page instead.

### Shopify

- Files: `assets/kodza-side-reveal-menu.css` and `assets/kodza-side-reveal-menu.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-side-reveal-menu.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-side-reveal-menu.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.
- Where it goes, step by step. (1) Inside the site's header, at its right end, in place of the header's links and burger; keep its call-to-action button. Only the Menu button shows there; the site's own links go in the menu, one kodza-side-reveal__link each, and the info block takes the site's email and social links. (2) If those links were what pushed the header's buttons to the right (an auto margin), give the remaining button group margin-left: auto. (3) Mark the element wrapping the whole site, the page that steps aside, with data-side-reveal-page, or name it on the menu with data-page="#page". It must fill the screen; without one, the menu slides in over the page. (4) Always, last: Close is uncovered at the top right of the screen, so tell it where Menu sits. On .kodza-side-reveal, set --kz-side-reveal-top to the Menu button's distance from the top of the screen and --kz-side-reveal-side to its distance from the right edge, e.g. style="--kz-side-reveal-top: 22px; --kz-side-reveal-side: 22px"; for a header centred at a max width, --kz-side-reveal-side: calc((100vw - 1080px) / 2 + 10px), with that header's max width and inner padding. Skip it and Close shows up in the corner of the screen.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `SideRevealMenu.tsx` (below), the CSS block under Code saved as `side-reveal-menu.css` and the JS block as `side-reveal-menu.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { SideRevealMenu } from '@/components/kodza/SideRevealMenu';` then `<SideRevealMenu />`. Props: `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-side-reveal-bg': … }}`), `className`, `style` and the other props of its `<div>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './side-reveal-menu.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.
- Built from your data (tabs, rows, options)? Add what the markup is made of to the `key`, as plain values (ids, text, numbers). What the visitor changes (the open tab, the sort, what they type) is the script's: follow it with `onClick` or `onInput` on the root, and change it from your code as a visitor would (click the tab; set the field's value, then dispatch a bubbling `input` event). Fields stay uncontrolled (`defaultValue`, `name`).

```tsx
'use client';
// Kodza — Side Reveal Menu, for React. From https://kodza.dev/components/side-reveal-menu/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: side-reveal-menu.css and side-reveal-menu.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './side-reveal-menu.css';

export type SideRevealMenuProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** the menu, under the page — default: #0a0a0a */
    "--kz-side-reveal-bg"?: string | number;
    /** default: #f2f2f0 */
    "--kz-side-reveal-fg"?: string | number;
    /** default: rgba(242, 242, 240, 0.62) */
    "--kz-side-reveal-muted"?: string | number;
    /** the Menu button, on the page — default: #0a0a0a */
    "--kz-side-reveal-ink"?: string | number;
    /** default: #ffffff */
    "--kz-side-reveal-on-ink"?: string | number;
    /** the page colour while it steps aside; auto = the first background above it — default: auto */
    "--kz-side-reveal-page"?: string | number;
    /** match your header, so Close lands right where Menu was (below the WordPress admin bar) — default: calc(var(--wp-admin--admin-bar--height, 0px) + 20px) */
    "--kz-side-reveal-top"?: string | number;
    /** default: 24px */
    "--kz-side-reveal-side"?: string | number;
    /** the menu column; on a phone a strip of the page stays in view — default: min(clamp(340px, 40cqw, 560px), calc(100cqw - 56px)) */
    "--kz-side-reveal-width"?: string | number;
    /** default: clamp(36px, min(4.6cqw + 8px, calc((100cqh - 300px) / 5.6)), 72px) */
    "--kz-side-reveal-size"?: string | number;
    /** the page's size once aside — default: 0.88 */
    "--kz-side-reveal-depth"?: string | number;
    /** under the card, seen on a light menu — default: 0 32px 80px -24px rgba(0, 0, 0, 0.45) */
    "--kz-side-reveal-shadow"?: string | number;
    /** without a page: how dark the page gets under the menu — default: 0.5 */
    "--kz-side-reveal-shade"?: string | number;
    /** default: 1s */
    "--kz-side-reveal-duration"?: string | number;
    /** default: cubic-bezier(0.76, 0, 0.24, 1) */
    "--kz-side-reveal-ease"?: string | number;
  };
  className?: string;
};

export function SideRevealMenu({ vars, className, style, ...rest }: SideRevealMenuProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-side-reveal", className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, vars, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./side-reveal-menu.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <div key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <button className="kodza-side-reveal__toggle" type="button" aria-haspopup="dialog" aria-expanded="false"><span className="kodza-side-reveal__lines" aria-hidden="true" />Menu</button>
      <div className="kodza-side-reveal__panel" role="dialog" aria-modal="true" aria-label="Menu" tabIndex={-1} hidden>
        <span className="kodza-side-reveal__ground" aria-hidden="true" />
        {' '}
        <span className="kodza-side-reveal__card" aria-hidden="true" />
        {' '}
        <span className="kodza-side-reveal__shade" aria-hidden="true" />
        <div className="kodza-side-reveal__side">
          <div className="kodza-side-reveal__bar">
            <p className="kodza-side-reveal__label">Page on hold.</p>
            <button className="kodza-side-reveal__close" type="button">
              <span className="kodza-side-reveal__cross" aria-hidden="true" />
              <span className="kodza-side-reveal__say">
                <span>Close</span>
              </span>
            </button>
          </div>
          <nav className="kodza-side-reveal__nav" aria-label="Main">
            <a className="kodza-side-reveal__link" href="#">
              <span className="kodza-side-reveal__index">01</span>
              <span className="kodza-side-reveal__mask">
                <span className="kodza-side-reveal__word">Work</span>
              </span>
            </a>
            {' '}
            <a className="kodza-side-reveal__link" href="#">
              <span className="kodza-side-reveal__index">02</span>
              <span className="kodza-side-reveal__mask">
                <span className="kodza-side-reveal__word">Services</span>
              </span>
            </a>
            {' '}
            <a className="kodza-side-reveal__link" href="#">
              <span className="kodza-side-reveal__index">03</span>
              <span className="kodza-side-reveal__mask">
                <span className="kodza-side-reveal__word">Studio</span>
              </span>
            </a>
            {' '}
            <a className="kodza-side-reveal__link" href="#">
              <span className="kodza-side-reveal__index">04</span>
              <span className="kodza-side-reveal__mask">
                <span className="kodza-side-reveal__word">Journal</span>
              </span>
            </a>
            {' '}
            <a className="kodza-side-reveal__link" href="#">
              <span className="kodza-side-reveal__index">05</span>
              <span className="kodza-side-reveal__mask">
                <span className="kodza-side-reveal__word">Contact</span>
              </span>
            </a>
          </nav>
          <div className="kodza-side-reveal__info">
            <div className="kodza-side-reveal__group">
              <p className="kodza-side-reveal__small">New project</p>
              <p>
                <a href="#">studio@example.com</a>
              </p>
            </div>
            <div className="kodza-side-reveal__group">
              <p className="kodza-side-reveal__small">Elsewhere</p>
              <p className="kodza-side-reveal__socials">
                <a href="#">GitHub</a>
                <a href="#">X</a>
                <a href="#">Bluesky</a>
              </p>
            </div>
            <p className="kodza-side-reveal__small">Esc, or click the page.</p>
          </div>
        </div>
      </div>
    </div>
  );
}
```

- Where it goes, step by step. (1) Inside the site's header, at its right end, in place of the header's links and burger; keep its call-to-action button. Only the Menu button shows there; the site's own links go in the menu, one kodza-side-reveal__link each, and the info block takes the site's email and social links. (2) If those links were what pushed the header's buttons to the right (an auto margin), give the remaining button group margin-left: auto. (3) Mark the element wrapping the whole site, the page that steps aside, with data-side-reveal-page, or name it on the menu with data-page="#page". It must fill the screen; without one, the menu slides in over the page. (4) Always, last: Close is uncovered at the top right of the screen, so tell it where Menu sits. On .kodza-side-reveal, set --kz-side-reveal-top to the Menu button's distance from the top of the screen and --kz-side-reveal-side to its distance from the right edge, e.g. style="--kz-side-reveal-top: 22px; --kz-side-reveal-side: 22px"; for a header centred at a max width, --kz-side-reveal-side: calc((100vw - 1080px) / 2 + 10px), with that header's max width and inner padding. Skip it and Close shows up in the corner of the screen.

## Code

```html
<div class="kodza-side-reveal">
  <button class="kodza-side-reveal__toggle" type="button" aria-haspopup="dialog" aria-expanded="false"><span class="kodza-side-reveal__lines" aria-hidden="true"></span>Menu</button>
  <div class="kodza-side-reveal__panel" role="dialog" aria-modal="true" aria-label="Menu" tabindex="-1" hidden>
    <span class="kodza-side-reveal__ground" aria-hidden="true"></span>
    <span class="kodza-side-reveal__card" aria-hidden="true"></span>
    <span class="kodza-side-reveal__shade" aria-hidden="true"></span>
    <div class="kodza-side-reveal__side">
      <div class="kodza-side-reveal__bar">
        <p class="kodza-side-reveal__label">Page on hold.</p>
        <button class="kodza-side-reveal__close" type="button"><span class="kodza-side-reveal__cross" aria-hidden="true"></span><span class="kodza-side-reveal__say"><span>Close</span></span></button>
      </div>
      <nav class="kodza-side-reveal__nav" aria-label="Main">
        <a class="kodza-side-reveal__link" href="#"><span class="kodza-side-reveal__index">01</span><span class="kodza-side-reveal__mask"><span class="kodza-side-reveal__word">Work</span></span></a>
        <a class="kodza-side-reveal__link" href="#"><span class="kodza-side-reveal__index">02</span><span class="kodza-side-reveal__mask"><span class="kodza-side-reveal__word">Services</span></span></a>
        <a class="kodza-side-reveal__link" href="#"><span class="kodza-side-reveal__index">03</span><span class="kodza-side-reveal__mask"><span class="kodza-side-reveal__word">Studio</span></span></a>
        <a class="kodza-side-reveal__link" href="#"><span class="kodza-side-reveal__index">04</span><span class="kodza-side-reveal__mask"><span class="kodza-side-reveal__word">Journal</span></span></a>
        <a class="kodza-side-reveal__link" href="#"><span class="kodza-side-reveal__index">05</span><span class="kodza-side-reveal__mask"><span class="kodza-side-reveal__word">Contact</span></span></a>
      </nav>
      <div class="kodza-side-reveal__info">
        <div class="kodza-side-reveal__group">
          <p class="kodza-side-reveal__small">New project</p>
          <p><a href="#">studio@example.com</a></p>
        </div>
        <div class="kodza-side-reveal__group">
          <p class="kodza-side-reveal__small">Elsewhere</p>
          <p class="kodza-side-reveal__socials"><a href="#">GitHub</a><a href="#">X</a><a href="#">Bluesky</a></p>
        </div>
        <p class="kodza-side-reveal__small">Esc, or click the page.</p>
      </div>
    </div>
  </div>
</div>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Side Reveal Menu
   The page steps aside: it slides to the left and shrinks into a card, and the menu that was
   lying under it all along comes into view on the right. Close is uncovered right where Menu
   was, the links rise as the page's edge goes past them, and a click on the card brings the
   page back. Mark the wrapper of your site with data-side-reveal-page, or name it on the menu
   with data-page="…" (the wrapper of most WordPress themes is found on its own); without one
   the menu slides in over the page.
   Everything is tuned with the --kz-side-reveal-* variables. */
.kodza-side-reveal {
  --kz-side-reveal-bg: #0a0a0a; /* the menu, under the page */
  --kz-side-reveal-fg: #f2f2f0;
  --kz-side-reveal-muted: rgba(242, 242, 240, 0.62);
  --kz-side-reveal-ink: #0a0a0a; /* the Menu button, on the page */
  --kz-side-reveal-on-ink: #ffffff;
  --kz-side-reveal-page: auto; /* the page colour while it steps aside; auto = the first background above it */
  --kz-side-reveal-top: calc(var(--wp-admin--admin-bar--height, 0px) + 20px); /* match your header, so Close lands right where Menu was (below the WordPress admin bar) */
  --kz-side-reveal-side: 24px;
  --kz-side-reveal-width: min(clamp(340px, 40cqw, 560px), calc(100cqw - 56px)); /* the menu column; on a phone a strip of the page stays in view */
  --kz-side-reveal-size: clamp(36px, min(4.6cqw + 8px, calc((100cqh - 300px) / 5.6)), 72px);
  --kz-side-reveal-depth: 0.88; /* the page's size once aside */
  --kz-side-reveal-shadow: 0 32px 80px -24px rgba(0, 0, 0, 0.45); /* under the card, seen on a light menu */
  --kz-side-reveal-shade: 0.5; /* without a page: how dark the page gets under the menu */
  --kz-side-reveal-duration: 1s;
  --kz-side-reveal-ease: cubic-bezier(0.76, 0, 0.24, 1);

  display: inline-block;
}

.kodza-side-reveal__toggle,
.kodza-side-reveal__close {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  margin: 0;
  padding: 0 18px 0 16px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.kodza-side-reveal__toggle {
  background: var(--kz-side-reveal-ink);
  color: var(--kz-side-reveal-on-ink);
}

.kodza-side-reveal__close {
  background: var(--kz-side-reveal-fg);
  color: var(--kz-side-reveal-bg);
}

.kodza-side-reveal__toggle:focus-visible {
  outline: 2px solid var(--kz-side-reveal-ink);
  outline-offset: 3px;
}

.kodza-side-reveal__close:focus-visible,
.kodza-side-reveal__info a:focus-visible {
  outline: 2px solid var(--kz-side-reveal-fg);
  outline-offset: 4px;
}

/* Two lines on the button: they meet and cross as the page leaves, and Close is uncovered with
   them crossed, in the same place */
.kodza-side-reveal__lines,
.kodza-side-reveal__cross {
  position: relative;
  flex: none;
  width: 14px;
  height: 8px;
}

.kodza-side-reveal__lines::before,
.kodza-side-reveal__lines::after,
.kodza-side-reveal__cross::before,
.kodza-side-reveal__cross::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 1.5px;
  border-radius: 1px;
  background: currentColor;
  /* On its own layer: drawn the same way at rest and while turning, so no snap at the end */
  will-change: transform;
}

.kodza-side-reveal__lines::before,
.kodza-side-reveal__cross::before {
  top: 0;
}

.kodza-side-reveal__lines::after,
.kodza-side-reveal__cross::after {
  top: 6px; /* whole pixels: both lines sit on the pixel grid the same way */
}

.kodza-side-reveal__lines::before,
.kodza-side-reveal__lines::after {
  transition: clip-path 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Whole at rest, as an inset: the pointer slides it to a shorter one (from none it would jump) */
.kodza-side-reveal__lines::after {
  clip-path: inset(0 0 0 0);
}

.kodza-side-reveal__toggle:hover .kodza-side-reveal__lines::after {
  clip-path: inset(0 45% 0 0);
}

.kodza-side-reveal__toggle[aria-expanded="true"] .kodza-side-reveal__lines::after {
  clip-path: inset(0 0 0 0);
}

.kodza-side-reveal__cross::before {
  translate: 0 3px;
  rotate: 45deg;
}

.kodza-side-reveal__cross::after {
  translate: 0 -3px;
  rotate: -45deg;
}

/* The word rolls in from below its mask */
.kodza-side-reveal__say {
  display: grid;
  margin: -3px 0;
  padding: 3px 0;
  overflow: hidden;
}

.kodza-side-reveal__say > span {
  display: block;
}

/* The menu: the whole screen, under the page while it is open (over it when there is none) */
.kodza-side-reveal__panel {
  position: fixed;
  inset: 0;
  z-index: 99990;
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: var(--kz-side-reveal-fg);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
  container-type: size;
  -webkit-font-smoothing: antialiased;
}

.kodza-side-reveal__panel[hidden] {
  display: none;
}

.kodza-side-reveal__panel:focus {
  outline: none;
}

.kodza-side-reveal__ground,
.kodza-side-reveal__shade {
  position: absolute;
  inset: 0;
}

.kodza-side-reveal__ground {
  background: var(--kz-side-reveal-bg);
  pointer-events: none;
}

/* The card's shadow: under the page, on the same path (the script places it) */
.kodza-side-reveal__card {
  position: absolute;
  inset: 0;
  box-shadow: var(--kz-side-reveal-shadow);
  pointer-events: none;
}

/* Without a page the menu slides in over it, and the page dims; a click on it closes */
.kodza-side-reveal__shade {
  display: none;
  background: rgba(0, 0, 0, var(--kz-side-reveal-shade));
  cursor: pointer;
}

.kodza-side-reveal__panel.is-flat .kodza-side-reveal__shade {
  display: block;
}

.kodza-side-reveal__panel.is-flat .kodza-side-reveal__ground,
.kodza-side-reveal__panel.is-flat .kodza-side-reveal__card {
  display: none;
}

/* The column on the right: it scrolls on its own on a short screen */
.kodza-side-reveal__side {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-sizing: border-box;
  width: var(--kz-side-reveal-width);
  padding: 0 var(--kz-side-reveal-side) clamp(20px, 4cqh, 36px) clamp(28px, 3.4cqw, 48px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  background: var(--kz-side-reveal-bg);
}

.kodza-side-reveal__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: var(--kz-side-reveal-top);
}

.kodza-side-reveal__label,
.kodza-side-reveal__index,
.kodza-side-reveal__small {
  font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  color: var(--kz-side-reveal-muted);
}

.kodza-side-reveal__label {
  margin: 0;
}

/* The links, big, in the middle of the column */
.kodza-side-reveal__nav {
  display: grid;
  align-content: center;
  justify-items: start;
  padding: 32px 0;
}

.kodza-side-reveal__link {
  display: grid;
  grid-template-columns: 36px max-content;
  align-items: start;
  color: inherit;
  text-decoration: none;
  outline: none;
}

.kodza-side-reveal__index {
  padding-top: calc(var(--kz-side-reveal-size) * 0.14);
  transition: color 0.25s;
}

/* The mask has the size of its word, so its room for descenders (g, j, p, q, y) and its step
   aside are measured on the word */
.kodza-side-reveal__mask {
  display: block;
  margin: -0.06em 0 -0.22em;
  padding: 0.06em 0 0.22em;
  overflow: hidden;
  font-size: var(--kz-side-reveal-size);
  transition: translate 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.kodza-side-reveal__word {
  display: block;
  font-size: var(--kz-side-reveal-size);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.045em;
  white-space: nowrap;
}

/* Pointed at: the word steps aside and its number lights up. A link's focus is drawn on its
   word, so it rises with it instead of waiting there as an empty box */
.kodza-side-reveal__link:hover .kodza-side-reveal__mask,
.kodza-side-reveal__link:focus-visible .kodza-side-reveal__mask {
  translate: 0.14em 0;
}

.kodza-side-reveal__link:hover .kodza-side-reveal__index,
.kodza-side-reveal__link:focus-visible .kodza-side-reveal__index {
  color: var(--kz-side-reveal-fg);
}

.kodza-side-reveal__link:focus-visible .kodza-side-reveal__word {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.12em;
}

.kodza-side-reveal__info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 16px;
}

.kodza-side-reveal__info p {
  margin: 0;
}

.kodza-side-reveal__info > .kodza-side-reveal__small {
  grid-column: 1 / -1;
}

.kodza-side-reveal__group {
  display: grid;
  align-content: start;
  gap: 6px;
}

.kodza-side-reveal__info a {
  color: var(--kz-side-reveal-fg);
  text-decoration: none;
  border-radius: 2px;
}

.kodza-side-reveal__info a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.kodza-side-reveal__socials {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

/* A narrow column: the contact details one under the other */
@container (max-width: 520px) {
  .kodza-side-reveal__info {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-side-reveal__toggle *,
  .kodza-side-reveal__toggle *::before,
  .kodza-side-reveal__toggle *::after,
  .kodza-side-reveal__mask,
  .kodza-side-reveal__index {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

/* Dark site: the menu underneath is paper
.kodza-side-reveal {
  --kz-side-reveal-bg: #f2f2f0;
  --kz-side-reveal-fg: #0a0a0a;
  --kz-side-reveal-muted: rgba(10, 10, 10, 0.62);
  --kz-side-reveal-ink: #f2f2f0;
  --kz-side-reveal-on-ink: #0a0a0a;
}
*/

/* kodza-guard f73aea86c8af — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-side-reveal__toggle):not(#_),
:where(.kodza-side-reveal__close):not(#_) {
  outline: revert;
  outline-offset: revert;
}

:where(.kodza-side-reveal__panel):not(#_) {
  outline: revert;
}

:where(.kodza-side-reveal__group a:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *))):not(#_),
:where(.kodza-side-reveal__socials a:where(:not([class*="kodza-"]))):not(#_) {
  outline: revert;
  outline-offset: revert;
  text-underline-offset: revert;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-side-reveal:not(#_),
.kodza-side-reveal__lines:not(#_),
.kodza-side-reveal__ground:not(#_),
.kodza-side-reveal__card:not(#_),
.kodza-side-reveal__shade:not(#_),
.kodza-side-reveal__bar:not(#_),
.kodza-side-reveal__cross:not(#_),
.kodza-side-reveal__say:not(#_),
.kodza-side-reveal__index:not(#_),
.kodza-side-reveal__mask:not(#_),
.kodza-side-reveal__word:not(#_),
.kodza-side-reveal__info:not(#_),
.kodza-side-reveal__group:not(#_),
.kodza-side-reveal__say span:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
}

.kodza-side-reveal__toggle:not(#_),
.kodza-side-reveal__close:not(#_) {
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  min-height: revert;
}

.kodza-side-reveal__panel:not(#_) {
  box-shadow: revert;
  outline-offset: revert;
}

.kodza-side-reveal__label:not(#_),
.kodza-side-reveal__small:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-style: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-side-reveal__nav:not(#_) {
  border: revert;
  margin: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-side-reveal__link:not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-side-reveal__socials:not(#_),
.kodza-side-reveal__group p:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-side-reveal__group a:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_),
.kodza-side-reveal__socials a:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-side-reveal__label:not(#_):where(:not([hidden])),
.kodza-side-reveal__small:not(#_):where(:not([hidden])),
.kodza-side-reveal__group p:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_):where(:not([hidden])),
.kodza-side-reveal__group a:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_):where(:not([hidden])),
.kodza-side-reveal__socials a:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-side-reveal__label:not(#_):where([hidden]),
.kodza-side-reveal__small:not(#_):where([hidden]),
.kodza-side-reveal__group p:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_):where([hidden]),
.kodza-side-reveal__group a:where(:not([class*="kodza-"]):not(.kodza-side-reveal__group [class*="kodza-"] *)):not(#_):where([hidden]),
.kodza-side-reveal__socials a:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

.kodza-side-reveal__lines:not(#_)::before,
.kodza-side-reveal__lines:not(#_)::after,
.kodza-side-reveal__cross:not(#_)::before,
.kodza-side-reveal__cross:not(#_)::after {
  box-sizing: revert;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-side-reveal__toggle:not(#_),
.kodza-side-reveal__close:not(#_) {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  margin: 0;
  padding: 0 18px 0 16px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.kodza-side-reveal__toggle:not(#_) {
  background: var(--kz-side-reveal-ink);
  color: var(--kz-side-reveal-on-ink);
}

.kodza-side-reveal__close:not(#_) {
  background: var(--kz-side-reveal-fg);
  color: var(--kz-side-reveal-bg);
}

.kodza-side-reveal__toggle:focus-visible:not(#_) {
  outline: 2px solid var(--kz-side-reveal-ink);
  outline-offset: 3px;
}

.kodza-side-reveal__close:focus-visible:not(#_) {
  outline: 2px solid var(--kz-side-reveal-fg);
  outline-offset: 4px;
}

.kodza-side-reveal__info a:focus-visible:not(#_) {
  outline: 2px solid var(--kz-side-reveal-fg);
  outline-offset: 4px;
}

.kodza-side-reveal__panel:focus:not(#_) {
  outline: none;
}

.kodza-side-reveal__label:not(#_),
.kodza-side-reveal__small:not(#_) {
  font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  color: var(--kz-side-reveal-muted);
}

.kodza-side-reveal__label:not(#_) {
  margin: 0;
}

.kodza-side-reveal__nav:not(#_) {
  display: grid;
  padding: 32px 0;
}

.kodza-side-reveal__link:not(#_) {
  display: grid;
  color: inherit;
  text-decoration: none;
  outline: none;
}

.kodza-side-reveal__info p:not(#_) {
  margin: 0;
}

.kodza-side-reveal__info a:not(#_) {
  color: var(--kz-side-reveal-fg);
  text-decoration: none;
  border-radius: 2px;
}

.kodza-side-reveal__info a:hover:not(#_) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.kodza-side-reveal__socials:not(#_) {
  display: flex;
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Side Reveal Menu
// The page marked with data-side-reveal-page steps aside: it slides to the left and shrinks into a
// card, and the menu that was lying under it all along comes into view on the right. Close is
// uncovered right where Menu was, each link rises as the page's edge goes past it, a click on the
// card brings the page back, and closing plays the same timeline backwards, from wherever it is.
// The page only carries a transform while the menu is open, and is put back exactly as it was.
(() => {
  // The two lines that change from one menu of the family to the next
  const NAME = 'side-reveal';
  const VARS = ['bg', 'fg', 'muted', 'top', 'side', 'size', 'width', 'shade', 'shadow'];

  // ---------- Menu engine (begin) ----------
  // The same block in every burger menu of the family (Trapdoor, Fullscreen, Side Reveal...),
  // copied as is. .kodza-NAME__toggle opens .kodza-NAME__panel and the menu's opening plays as
  // one timeline, backwards to close, from wherever it is. While open the panel leaves the menu
  // with its variables (VARS), the page stays put (wheel, swipe, keys), Tab stays inside, Escape
  // closes and the focus goes back to the button. A page that takes part (data-NAME-page,
  // data-page="…" on the menu, or a theme's wrapper) takes its fixed elements along and is put
  // back exactly as it was. Each menu only writes how it moves: see `menu`.
  const SELECTOR = `.kodza-${NAME}`;
  const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
  const RISE = 'cubic-bezier(0.22, 1, 0.36, 1)';
  const SWING = 'cubic-bezier(0.65, 0, 0.35, 1)';
  const BACK = 1.6; // closing replays the opening backwards, this much faster
  const FOCUSABLE = 'a[href], button:not([disabled]), input, select, textarea, [tabindex]:not([tabindex="-1"])';
  const taken = new WeakMap(); // page → how to put it back at once (one menu moves a page at a time)

  const transparent = (color) => !color || color === 'transparent' || /^rgba\(.*,\s*0\)$/.test(color);

  // [time, progress] pairs along a cubic-bezier(): when does the edge pass a given row?
  const curve = (easing) => {
    const n = (easing.match(/-?\d*\.?\d+/g) || []).map(Number);
    const [x1, y1, x2, y2] = n.length === 4 ? n : [0.76, 0, 0.24, 1];
    const at = (s, a, b) => 3 * (1 - s) * (1 - s) * s * a + 3 * (1 - s) * s * s * b + s * s * s;
    return Array.from({ length: 101 }, (_, i) => [at(i / 100, x1, x2), at(i / 100, y1, y2)]);
  };

  // A transform makes the page the containing block of its fixed elements: they are found
  // first, then moved back to where they were on screen (see `rideAlong`)
  const fixedInside = (page) => {
    const found = [];
    const walker = document.createTreeWalker(page, NodeFilter.SHOW_ELEMENT, {
      acceptNode: (el) => {
        const style = getComputedStyle(el);
        if (style.display === 'none') return NodeFilter.FILTER_REJECT;
        if (style.position !== 'fixed') return NodeFilter.FILTER_SKIP;
        found.push({ el, box: el.getBoundingClientRect(), shift: style.translate, inline: el.style.translate, attr: el.hasAttribute('style') });
        return NodeFilter.FILTER_REJECT;
      },
    });
    while (walker.nextNode()) {
      // acceptNode collects them
    }
    return found;
  };

  const rideAlong = (fixed, k) => fixed.forEach((item) => {
    const now = item.el.getBoundingClientRect();
    const [x = 0, y = 0] = item.shift === 'none' ? [] : item.shift.split(' ').map(parseFloat);
    item.el.style.translate = `${x + (item.box.left - now.left) / k}px ${y + (item.box.top - now.top) / k}px`;
  });

  const letGo = (fixed) => fixed.forEach(({ el, inline, attr }) => {
    el.style.translate = inline;
    if (!attr && !el.getAttribute('style')) el.removeAttribute('style');
  });

  // Where the page is, in screen pixels: its box, its scale (a scaled parent changes nothing
  // once divided by `k`), and the part of it that is on screen
  const view = (page) => {
    const r = page.getBoundingClientRect();
    const { clientWidth: vw, clientHeight: vh } = document.documentElement;
    return {
      r,
      k: page.offsetWidth ? r.width / page.offsetWidth : 1,
      top: Math.max(r.top, 0),
      bottom: Math.min(r.bottom, vh),
      left: Math.max(r.left, 0),
      right: Math.min(r.right, vw),
    };
  };

  // One menu. `setup(m)` receives its parts (toggle, panel, closer, links, one, all, css, cut, and
  // while open page, reduced) and returns what the menu does itself:
  //   page    'under' when the menu lies under the page that moves, 'over' when it covers the
  //           page that moves under it; without it the page stays as it is
  //   rig(page)     sets the flat page up for the ride, returns its geometry with `k` (its scale);
  //                 again on resize
  //   frames(g)     the page's keyframes, set again on resize
  //   build(add, mode, g)   the opening, add(el, keyframes, delay, duration, easing, options) per
  //                 animation; mode is 'page', 'flat' (no page found) or 'reduced'
  //   ready(), entry(), key(event), resize(), reset()   optional: before it opens, where the
  //                 keyboard enters, a key of its own (true once handled), after a resize, once closed
  const menu = (root, signal, setup) => {
    const toggle = root.querySelector(`.kodza-${NAME}__toggle`);
    const panel = root.querySelector(`.kodza-${NAME}__panel`);
    if (!toggle || !panel) return;
    const one = (s) => panel.querySelector(s);
    const all = (s) => [...panel.querySelectorAll(s)];
    const closer = one(`.kodza-${NAME}__close`);
    const links = all(`.kodza-${NAME}__link`);
    const home = [panel.parentNode, panel.nextSibling];
    const css = (name) => getComputedStyle(root).getPropertyValue(`--kz-${NAME}-${name}`).trim();

    let state = 'closed'; // closed, opening, open, closing
    let sequence = []; // the opening: animations on one clock, so it can run backwards
    let session = null; // what only lives while the menu is open
    let moving = null; // the page taking part, and what it looked like before
    let reduced = false;
    let run = 0;
    let then = null;

    // The page: named on the menu (data-page="…"), or the marked wrapper around it, or else
    // the wrapper of a WordPress theme (block themes, Astra, GeneratePress, Kadence, OceanWP,
    // Blocksy, Divi…). Without one, the menu plays its sequence without the page
    const findPage = () => {
      let el = null;
      try {
        el = root.dataset.page ? document.querySelector(root.dataset.page) : null;
      } catch {
        el = null;
      }
      el = el || root.closest(`[data-${NAME}-page]`) || document.querySelector(`[data-${NAME}-page]`) || root.closest('.wp-site-blocks, #page, #outer-wrap, #main-container, #page-container');
      if (!el || el === document.body || el === document.documentElement) return null;
      // It has to fill the screen (below the WordPress admin bar): otherwise part of the site, a
      // header outside it or the space under a short page, would be left out of the ride
      const r = el.getBoundingClientRect();
      const bar = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--wp-admin--admin-bar--height')) || 0;
      const { clientWidth: vw, clientHeight: vh } = document.documentElement;
      return r.top <= bar + 1 && r.left <= 1 && r.right >= vw - 1 && r.bottom >= vh - 1 ? el : null;
    };

    // The colour under the page's content, so the menu never shows through it
    const ground = (page) => {
      const own = css('page');
      if (own && own !== 'auto') return own;
      for (let el = page.parentElement; el; el = el.parentElement) {
        const color = getComputedStyle(el).backgroundColor;
        if (!transparent(color)) return color;
      }
      return '#ffffff';
    };

    // A flex or grid page shares its height out among its children: for the ride their sizes
    // are held as they are, so a shorter page box changes nothing inside
    const hold = (page, style) => {
      if (style.display.includes('grid')) {
        page.style.gridTemplateRows = style.gridTemplateRows;
        page.style.gridTemplateColumns = style.gridTemplateColumns;
      } else if (style.display.includes('flex')) {
        const column = style.flexDirection.startsWith('column');
        moving.held = [...page.children].map((el) => {
          const own = getComputedStyle(el);
          const item = { el, flex: el.style.flex, attr: el.hasAttribute('style') };
          el.style.flex = `0 0 ${column ? own.height : own.width}`;
          return item;
        });
      }
    };

    const release = () => {
      moving.held.forEach(({ el, flex, attr }) => {
        el.style.flex = flex;
        if (!attr && !el.getAttribute('style')) el.removeAttribute('style');
      });
      moving.held = [];
      Object.assign(moving.page.style, moving.cut);
    };

    // The page's box ends at `at` (its own pixels from its top) for the ride, the space it
    // leaves kept as margin: what moves below it would stretch the scroll area. Checked on the
    // spot: if that moves anything inside, even with the children held, the page is left as it
    // was. Returns where the box ends
    const cut = (at) => {
      const { page } = moving;
      const full = page.offsetHeight;
      if (at >= full) return full;
      const style = getComputedStyle(page);
      const edges = style.boxSizing === 'border-box' ? 0 : ['paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'].reduce((sum, side) => sum + parseFloat(style[side]), 0);
      const margin = parseFloat(style.marginBottom) || 0;
      const boxes = (els) => els.map((el) => el.getBoundingClientRect()).map((r) => [r.top, r.left, r.width, r.height]);
      const kids = [...page.children];
      const before = boxes(kids);
      const shorten = () => {
        page.style.height = `${Math.max(at - edges, 0)}px`;
        page.style.overflowY = 'clip';
        page.style.marginBottom = `${margin + full - at}px`;
        return boxes(kids).some((box, i) => box.some((n, j) => Math.abs(n - before[i][j]) > 0.5));
      };
      let moved = shorten();
      if (moved && /flex|grid/.test(style.display)) {
        release();
        hold(page, style);
        moved = shorten();
      }
      if (moved) release();
      return moved ? full : at;
    };

    const m = {
      root, toggle, panel, closer, links, one, all, css, cut,
      get page() {
        return moving ? moving.page : null;
      },
      get reduced() {
        return reduced;
      },
    };
    const own = setup(m);

    // With the page untransformed: where its fixed elements are, then the menu's own geometry
    const rig = () => {
      letGo(moving.fixed);
      release();
      moving.fixed = fixedInside(moving.page);
      return own.rig(moving.page);
    };

    // The opening, as one timeline. Every animation gets an end delay that makes it as long as
    // the longest, so running them all backwards is the exact reverse, even halfway through.
    const timeline = (mode, g) => {
      const steps = [];
      const add = (el, frames, delay, duration, easing = RISE, extra = {}) => {
        if (el) steps.push([el, frames, { delay, duration, easing, ...extra }]);
      };
      own.build(add, mode, g);
      const total = Math.max(...steps.map(([, , o]) => o.delay + o.duration));
      return steps.map(([el, frames, o]) => el.animate(frames, { ...o, fill: 'both', endDelay: total - o.delay - o.duration }));
    };

    const play = (forward) => {
      const token = ++run;
      sequence.forEach((animation) => {
        animation.updatePlaybackRate(forward ? 1 : -BACK);
        animation.play();
      });
      Promise.all(sequence.map((animation) => animation.finished)).then(() => {
        if (token !== run) return;
        if (forward) state = 'open';
        else land();
      }, () => {});
    };

    // Closed again: the animations, the borrowed styles and the listeners go, the panel goes home
    const land = () => {
      run++;
      sequence.forEach((animation) => animation.cancel());
      panel.getAnimations({ subtree: true }).forEach((animation) => animation.cancel());
      sequence = [];
      session?.abort();
      session = null;
      if (moving) {
        const { page, saved, attr } = moving;
        letGo(moving.fixed);
        release();
        Object.assign(page.style, saved);
        if (!attr && !page.getAttribute('style')) page.removeAttribute('style');
        if (taken.get(page) === land) taken.delete(page);
        moving = null;
      }
      try {
        if (panel.popover && panel.matches(':popover-open')) panel.hidePopover();
      } catch {
        // no popover support: it was a plain fixed layer
      }
      panel.removeAttribute('popover');
      panel.removeAttribute('style');
      panel.hidden = true;
      if (panel.parentNode !== home[0]) home[0].insertBefore(panel, home[1]?.parentNode === home[0] ? home[1] : null);
      own.reset?.();
      state = 'closed';
      const next = then;
      then = null;
      next?.();
    };

    // While open the page stays put: a wheel or a swipe only scrolls what scrolls in the menu
    const scrollsInside = (target, x, y, dy) => {
      for (let el = target; el instanceof Element && panel.contains(el); el = el.parentElement) {
        const box = el.getBoundingClientRect();
        if (x < box.left || x > box.right || y < box.top || y > box.bottom) continue;
        if (!/(auto|scroll)/.test(getComputedStyle(el).overflowY) || el.scrollHeight <= el.clientHeight + 1) continue;
        if (dy > 0 ? el.scrollTop + el.clientHeight < el.scrollHeight - 1 : el.scrollTop > 0) return true;
      }
      return false;
    };

    // The links you can reach now (a menu with levels hides the others)
    const rows = () => links.filter((link) => link.getClientRects().length && !link.closest('[inert]'));

    const keydown = (event) => {
      if (state === 'closing' || event.defaultPrevented) return;
      if (own.key?.(event)) return;
      if (event.key === 'Escape') {
        event.preventDefault();
        shut();
        return;
      }
      const current = document.activeElement;
      if (event.key === 'Tab') {
        const stops = all(FOCUSABLE).filter((el) => el.getClientRects().length && !el.closest('[inert]'));
        const first = stops[0];
        const last = stops[stops.length - 1];
        const outside = !panel.contains(current) || current === panel;
        if (outside || (event.shiftKey && current === first) || (!event.shiftKey && current === last)) {
          event.preventDefault();
          (event.shiftKey ? last : first)?.focus();
        }
        return;
      }
      const list = rows();
      const i = list.indexOf(current);
      if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
        event.preventDefault();
        const step = event.key === 'ArrowDown' ? 1 : -1;
        list[i < 0 ? (step > 0 ? 0 : list.length - 1) : (i + step + list.length) % list.length]?.focus();
      } else if (event.key === 'Home' || event.key === 'End') {
        event.preventDefault();
        list[event.key === 'Home' ? 0 : list.length - 1]?.focus();
      } else if ([' ', 'PageUp', 'PageDown'].includes(event.key) && !current?.closest?.('button, input, select, textarea')) {
        event.preventDefault();
      }
    };

    const listen = (s) => {
      let last = 0;
      const at = [scrollX, scrollY];
      document.addEventListener('wheel', (event) => {
        if (!scrollsInside(event.target, event.clientX, event.clientY, event.deltaY)) event.preventDefault();
      }, { passive: false, signal: s });
      document.addEventListener('touchstart', (event) => (last = event.touches[0].clientY), { passive: true, signal: s });
      document.addEventListener('touchmove', (event) => {
        const touch = event.touches[0];
        const dy = last - touch.clientY;
        last = touch.clientY;
        if (!scrollsInside(event.target, touch.clientX, touch.clientY, dy)) event.preventDefault();
      }, { passive: false, signal: s });
      document.addEventListener('keydown', keydown, { signal: s });
      // A scrollbar dragged anyway: the page goes back to where it was
      window.addEventListener('scroll', () => {
        if (scrollX !== at[0] || scrollY !== at[1]) window.scrollTo({ left: at[0], top: at[1], behavior: 'instant' });
      }, { signal: s });
      let queued = 0;
      window.addEventListener('resize', () => {
        if (queued) return;
        queued = requestAnimationFrame(() => {
          queued = 0;
          if (s.aborted) return;
          if (moving) {
            const effect = sequence.find((animation) => animation.effect.target === moving.page)?.effect;
            effect?.setKeyframes([]);
            const g = rig();
            effect?.setKeyframes(own.frames(g));
            rideAlong(moving.fixed, g.k);
          }
          own.resize?.();
        });
      }, { signal: s });
      s.addEventListener('abort', () => cancelAnimationFrame(queued));
      // A click on the page that moved aside brings it back
      moving?.page.addEventListener('click', (event) => {
        if (state === 'closing') return;
        event.preventDefault();
        event.stopPropagation();
        shut();
      }, { capture: true, signal: s });
    };

    const enter = (keyboard) => {
      const target = keyboard ? own.entry?.() || links.find((link) => link.getAttribute('aria-current')) || rows()[0] || closer : panel;
      target?.focus({ preventScroll: true });
    };

    const open = (keyboard) => {
      if (state === 'opening' || state === 'open') return;
      toggle.setAttribute('aria-expanded', 'true');
      if (state === 'closing') {
        state = 'opening';
        then = null;
        panel.style.pointerEvents = '';
        play(true);
        enter(keyboard);
        return;
      }
      reduced = motion.matches;
      const page = reduced || !own.page ? null : findPage();
      const under = page && own.page === 'under';
      let g = null;
      if (page) {
        taken.get(page)?.();
        const { transformOrigin, backgroundColor, position, zIndex, height, overflowY, marginBottom, gridTemplateRows, gridTemplateColumns } = page.style;
        moving = { page, saved: { transformOrigin, backgroundColor, position, zIndex }, cut: { height, overflowY, marginBottom, gridTemplateRows, gridTemplateColumns }, attr: page.hasAttribute('style'), fixed: [], held: [] };
        taken.set(page, land);
        g = rig();
        const shown = getComputedStyle(page);
        if (transparent(shown.backgroundColor)) page.style.backgroundColor = ground(page);
        // Under the page: page over panel over the rest of the theme (a header, a sticky bar),
        // under the admin bar
        const still = shown.position === 'static';
        if (under && (!still || ['top', 'right', 'bottom', 'left'].every((side) => shown[side] === 'auto'))) {
          if (still) page.style.position = 'relative';
          page.style.zIndex = '99991';
          panel.style.zIndex = '99990';
        }
      }
      // The panel leaves the menu while open, so the styles of a theme's content (links,
      // paragraphs) never reach it: right under the page, or on top of everything
      VARS.forEach((name) => panel.style.setProperty(`--kz-${NAME}-${name}`, css(name)));
      panel.style.fontFamily = getComputedStyle(root).fontFamily;
      if (under) page.before(panel);
      else document.body.append(panel);
      panel.hidden = false;
      if (!under) {
        try {
          panel.popover = 'manual';
          panel.showPopover();
        } catch {
          // no popover support: a fixed layer over the page
        }
      }
      own.ready?.();
      sequence = timeline(page ? 'page' : reduced ? 'reduced' : 'flat', g);
      if (moving) rideAlong(moving.fixed, g.k);
      session = new AbortController();
      listen(session.signal);
      state = 'opening';
      play(true);
      enter(keyboard);
    };

    const shut = (after) => {
      if (state === 'closed' || state === 'closing') return;
      then = after || null;
      state = 'closing';
      toggle.setAttribute('aria-expanded', 'false');
      toggle.focus({ preventScroll: true });
      // On its way out it lets clicks through: Menu, under it, opens it again from where it is
      panel.style.pointerEvents = 'none';
      play(false);
    };

    // Keyboard (Enter, Space) clicks have no detail: the focus then goes into the menu
    toggle.addEventListener('click', (event) => open(event.detail === 0), { signal });
    closer?.addEventListener('click', () => shut(), { signal });
    // A link to this very page (#section, or just #) closes the menu first, then goes there
    links.forEach((link) => link.addEventListener('click', (event) => {
      const here = link.origin === location.origin && link.pathname === location.pathname && link.search === location.search;
      if (!here || event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
      event.preventDefault();
      const hash = link.hash;
      shut(hash ? () => (location.hash = hash) : null);
    }, { signal }));
    // Back from another page (bfcache): the menu is closed, the page as it was
    window.addEventListener('pageshow', (event) => event.persisted && state !== 'closed' && land(), { signal });

    // Stopped while open: the page is put back at once and the panel goes back in place
    signal.addEventListener('abort', () => {
      then = null;
      if (state !== 'closed') land();
    });
  };
  // ---------- Menu engine (end) ----------

  function mount(root, signal) {
    menu(root, signal, (m) => {
      const { panel, toggle, closer, links, one, all, css } = m;
      const shade = one('.kodza-side-reveal__shade');
      const card = one('.kodza-side-reveal__card');
      const side = one('.kodza-side-reveal__side');
      const cross = one('.kodza-side-reveal__cross');
      const say = one('.kodza-side-reveal__say > span');
      const label = one('.kodza-side-reveal__label');
      const infos = all('.kodza-side-reveal__info > *');
      const lines = toggle.querySelector('.kodza-side-reveal__lines');
      const depth = () => parseFloat(css('depth')) || 0.88;
      // Where the card stops: its right edge meets the menu column
      const stop = () => side.getBoundingClientRect().left;
      let last = null;

      // Without a page the menu comes over it: a click on the dimmed page closes
      shade.addEventListener('click', () => closer?.click(), { signal });

      // The page steps aside from its right edge, at mid-height of what is on screen. Only its
      // visible part shows, so its rounded corners are the screen's; a smaller page never
      // stretches the scroll area
      const rig = (page) => {
        const { r, k, top, bottom, left, right } = view(page);
        const clip = [(top - r.top) / k, (r.right - right) / k, (r.bottom - bottom) / k, (left - r.left) / k];
        page.style.transformOrigin = `${(right - r.left) / k}px ${((top + bottom) / 2 - r.top) / k}px`;
        last = { k, top, bottom, left, right, clip: clip.map((n) => `${Math.max(n, 0)}px`).join(' ') };
        return last;
      };
      const frames = (g) => {
        const s = depth();
        return [
          { transform: 'translateX(0px) scale(1)', clipPath: `inset(${g.clip} round 0px)` },
          { transform: `translateX(${(stop() - g.right) / g.k}px) scale(${s})`, clipPath: `inset(${g.clip} round ${18 / (s * g.k)}px)` },
        ];
      };

      // The card's shadow, under the page: the same box on the same path
      const shadow = (g) => {
        const p = panel.getBoundingClientRect();
        const kp = panel.offsetWidth ? p.width / panel.offsetWidth : 1;
        const w = (g.right - g.left) / kp;
        const s = depth();
        // Its rounded corners where it lands are also written on it: the open state holds without
        // the animation
        Object.assign(card.style, {
          inset: 'auto',
          left: `${(g.left - p.left) / kp}px`,
          top: `${(g.top - p.top) / kp}px`,
          width: `${w}px`,
          height: `${(g.bottom - g.top) / kp}px`,
          transformOrigin: `${w}px 50%`,
          borderRadius: `${18 / (s * kp)}px`,
        });
        return [
          { transform: 'translateX(0px) scale(1)', borderRadius: '0px' },
          { transform: `translateX(${(stop() - g.right) / kp}px) scale(${s})`, borderRadius: `${18 / (s * kp)}px` },
        ];
      };

      // The lines cross on the button, and Close is uncovered with them crossed
      const turn = (el, sign) => {
        const pseudoElement = sign > 0 ? '::before' : '::after';
        return (add) => {
          add(el, [{ translate: '0 0' }, { translate: `0 ${3 * sign}px` }], 0, 200, SWING, { pseudoElement });
          add(el, [{ rotate: '0deg' }, { rotate: `${45 * sign}deg` }], 170, 300, RISE, { pseudoElement });
        };
      };

      const build = (add, mode, g) => {
        if (mode === 'reduced') {
          add(panel, [{ opacity: 0 }, { opacity: 1 }], 0, 180, 'ease');
          return;
        }
        const time = (parseFloat(css('duration')) || 1) * 1000;
        const ease = css('ease') || 'cubic-bezier(0.76, 0, 0.24, 1)';
        const col = side.getBoundingClientRect();

        // The page steps aside and the menu is under it; without one, the column slides in over
        // the dimmed page. Either way an edge goes from `right` to the column's left
        let right = col.right;
        if (mode === 'page') {
          right = g.right;
          add(m.page, frames(g), 0, time, ease);
          add(card, shadow(g), 0, time, ease);
        } else {
          add(shade, [{ opacity: 0 }, { opacity: 1 }], 0, time, ease);
          add(side, [{ transform: 'translateX(100%)' }, { transform: 'translateX(0%)' }], 0, time, ease);
        }

        // When that edge gets past `x` (screen pixels)
        const samples = curve(ease);
        const uncover = (x) => {
          const i = samples.findIndex(([, p]) => right + (col.left - right) * p <= x);
          return (i < 0 ? 1 : samples[i][0]) * time;
        };

        if (lines) [turn(lines, 1), turn(lines, -1)].forEach((go) => go(add));
        if (cross) [turn(cross, 1), turn(cross, -1)].forEach((go) => go(add));
        if (closer) add(say, [{ transform: 'translateY(110%)' }, { transform: 'translateY(0%)' }], uncover(closer.getBoundingClientRect().right) + 80, 600);
        if (label) add(label, [{ opacity: 0, transform: 'translateY(6px)' }, { opacity: 1, transform: 'translateY(0px)' }], uncover(label.getBoundingClientRect().right) + 60, 600);

        // Each word rises from its mask as the edge goes past it, never two at once
        let at = 0;
        links.forEach((link, i) => {
          const box = (link.querySelector('.kodza-side-reveal__mask') || link).getBoundingClientRect();
          at = Math.max(i ? at + 70 : 0, uncover(box.left + box.width / 2) - 120);
          add(link.querySelector('.kodza-side-reveal__word'), [{ transform: 'translateY(135%)' }, { transform: 'translateY(0%)' }], at, 900);
          add(link.querySelector('.kodza-side-reveal__index'), [{ opacity: 0, transform: 'translateY(6px)' }, { opacity: 1, transform: 'translateY(0px)' }], at + 240, 600);
        });
        infos.forEach((info, i) => {
          const from = Math.max(at + 200 + i * 70, uncover(info.getBoundingClientRect().right));
          add(info, [{ opacity: 0, transform: 'translateY(10px)' }, { opacity: 1, transform: 'translateY(0px)' }], from, 650);
        });
      };

      const ready = () => panel.classList.toggle('is-flat', !m.page);
      const resize = () => {
        if (m.page && last) card.getAnimations()[0]?.effect.setKeyframes(shadow(last));
      };
      const reset = () => {
        card.removeAttribute('style');
        panel.classList.remove('is-flat');
      };
      return { page: 'under', rig, frames, build, ready, resize, reset };
    });
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load. Each running root
  // keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
  // component inside another one is saved as written, not half-started, and stopped with it.
  const KODZA = Symbol.for('kodza');
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
  const put = (el, saved) => {
    [...el.attributes].forEach((a) => el.removeAttribute(a.name));
    saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
    el.innerHTML = saved.html;
  };
  // The markup inside a root as written: Kodza components already running in it give back their own
  const written = (root) => {
    const all = [...root.querySelectorAll('*')];
    if (!all.some((el) => el[KODZA])) return root.innerHTML;
    const copy = root.cloneNode(true);
    const twins = copy.querySelectorAll('*');
    let last = null;
    all.forEach((el, i) => {
      if (!el[KODZA] || last?.contains(el)) return;
      last = el;
      put(twins[i], el[KODZA]);
    });
    return copy.innerHTML;
  };
  const init = (scope) => find(scope).forEach((root) => {
    if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
    const controller = new AbortController();
    const saved = { html: written(root), attrs: attrsOf(root), stop: () => destroy(root) };
    instances.set(root, { controller, saved });
    root[KODZA] = saved;
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    // The Kodza components running inside it stop first: once its markup is put back, their own
    // script could not find them any more
    root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
    instance.controller.abort();
    delete root[KODZA];
    put(root, instance.saved);
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
