# Accessibility

Phantom targets WCAG 2.2 AA for the interface without changing its visual
direction (Kuro theme, vermillion accent, rounded sheet).

## What is covered

### Contrast

Token contrast is tested automatically: `frontend/src/utils/__tests__/contrast.spec.ts`
parses the colour tokens of both themes (`styles/tokens-dark*.css` and
`styles/tokens-light*.css`) and fails the build if any pair drops below
AA, or if the light theme misses a token the dark one defines.

| Pair | Before | After | Rule |
|---|---|---|---|
| `--fg-faint` on `--surface-3` (worst surface) | 3.20 | 4.62 (`#858585`) | 4.5:1 text |
| `--fg-faint` on `--bg` | 3.94 | 5.69 | 4.5:1 text |
| `--fg-subtle` on `--surface-3` | 5.07 | 5.76 (`#969696`, keeps the step above faint) | 4.5:1 text |
| Focus ring `--focus` on `--surface-3` | 2.33 (55% alpha) | 3.60 (80% alpha) | 3:1 non-text |
| White on accent buttons | 3.46 (`--accent`) | 4.75 (`--accent-solid #cf4028`) | 4.5:1 text |
| White on danger buttons | 2.73 (`--err`) | 4.87 (`--danger-solid #c2493a`) | 4.5:1 text |
| `--fg`, `--fg-muted`, accent, ok, warn, err, severities on every surface | ≥ 4.92 | unchanged | 4.5:1 text |

`--accent` and `--err` stay as they were for text, marks and rings. The
two `-solid` tokens are used only behind white text on filled buttons and
badges.

The light theme (Shiro) is held to the same rules, with HTTP method,
syntax and tag colours added to the text set. Its weakest pairs, all on
`--surface-3`: `--accent` 4.56, `--sev-high` 4.86, `--tag-orange` 4.58,
`--fg-faint` 5.25; the focus ring 3.47; white on `--accent-solid` 5.39.

### Keyboard

- Every control is a native button, link or input, or a reka-ui primitive
  with keyboard support.
- Arrow keys, Home and End move through the rail and the sidebar lists
  (vault list, proxy tools, saved views); typing in a field is never
  intercepted (`composables/useArrowNavigation.ts`, `utils/rovingFocus.ts`).
- Escape closes only the innermost layer: popovers, menus and listboxes
  handle it first, then the palette, then the finding inspector.
- Docked panels and the command palette return focus to the control that
  opened them (`composables/useReturnFocus.ts`), including panels opened
  from shortcuts.
- What can be dragged to reorder can be moved from the keyboard too:
  Alt+Left and Alt+Right on a focused History column header or Repeater
  tab move it one place; report sections take Alt+Up and Alt+Down.
- Focus rings use `--focus` everywhere (`:focus-visible`, 2px, offset 2px).
- Every shortcut is declared once in `utils/shortcuts.ts`; the rail
  tooltips, the palette and the **Keyboard shortcuts** sheet read their
  keys from it. Press `?` outside a text field, or pick Keyboard shortcuts
  in the palette, to see them all with a filter.

### Screen readers

- Landmarks: the vault column is a `nav` whose vaults are a list, the
  channel list is a labelled `aside` with its modules in a `nav`, the
  sidebar is a labelled `aside`, the sheet is `main`; tool lists are
  labelled `nav`s.
- **Skip to content** is the first stop of Tab and moves focus to `main`,
  past the vault column and the channel list.
- One `h1` per page, empty states included (the "Select a target" kind
  of message is the page's `h1` until something is picked). Pages whose
  title is an editable field (payload collection, tag) carry a visually
  hidden `h1`.
- A control's name starts with its visible text: a vault tile is named
  by its initials then the vault's name, and buttons that add a hint do
  so after their visible label.
- Form fields name their controls: `PFormField` gives its label an id and
  the input, select and textarea atoms inside take it as
  `aria-labelledby` (`composables/useFieldLabel.ts`); a select outside a
  field takes a `label`.
- Icon-only buttons have accessible names (`PIconButton` uses its tooltip;
  every switch is labelled).
- Toasts, live counters and the find count are `aria-live="polite"`.
- Loading skeletons are `role="status"` with `aria-busy` and the
  placeholder blocks are `aria-hidden`.
- History and Intruder results are `role="grid"` with rows, column headers
  (`aria-sort`), `gridcell`s, `aria-rowindex` and `aria-selected`; the
  findings table uses `role="table"`.
- The command palette is a labelled dialog with a combobox and listbox,
  using `aria-activedescendant` for the highlighted command.
- Docked panels are reka dialogs with `aria-modal` false, labelled by
  their title and description.

### Motion

`prefers-reduced-motion: reduce` shortens every CSS transition and
animation to a single near-instant run (sheens and pulses stop), and
motion-v animations follow the system setting (`MotionConfig
reduced-motion="user"`).

### Pointer targets

Interactive controls are at least 24×24 px. Visually smaller controls
(colour swatches, chip remove buttons, fold chevrons, switches) keep their
look and get an invisible hit area around them.

## How to test

- `npm test` runs the contrast suite, the focus helper tests and an axe
  run (`src/components/__tests__/a11y.spec.ts`): components are mounted
  into a DOM and axe-core fails the test on any violation except colour
  contrast, which the contrast suite covers. A deliberately broken
  component in the same file proves the check is not vacuous.
- The full sweep, in a development build: run `phantomA11ySweep()` in the
  browser console. It opens every page in both themes, then the command
  palette and every create dialog, and runs axe-core over the whole
  document each time, colour contrast included, returning the rules each
  state breaks (`src/utils/a11ySweep.ts`). It only navigates and opens
  dialogs. The last run: 48 states, no violation.
- Keyboard only: Tab through each page; arrows in the rail and sidebar;
  open the palette (Ctrl/Cmd+K) and a docked panel, press Escape, and
  check focus returns.
- Screen reader: NVDA or VoiceOver over History (grid navigation), the
  command palette and a docked panel.
- Reduced motion: enable it in the OS and check that pulses and sheens
  stop.

## Known gaps

- The message editor is a textarea under a highlighted overlay; screen
  readers read the textarea only, and its line numbers and find are not
  available there (native find works).
- Virtualized grids expose only the rendered rows; `aria-rowcount` gives
  the total.
- Charts (Timeline) have no text alternative beyond their counts.
- The axe run of `npm test` covers a set of components (sign-in,
  Repeater Fields, Sequencer report, history presets, segmented control,
  form fields, the vault column and channel list); whole pages are
  covered by the sweep above, which needs a running app.
