# Motion

Motion communicates state change, not decoration. Durations and easing live in DTCG motion tokens (contract C3). `bundle.css` consumes `--sv-motion-transition-*` for transitions and pairs `--sv-motion-duration-*` with `--sv-motion-easing-*` for keyframed motion; there are no `var()` fallbacks and no keyword easing shims.

## Principles

- **Functional:** Motion shows open/close, press feedback, or progress — never ambient loops except spinner, shimmer, and caret (documented).
- **Short:** Most UI motion is 125–240ms. Loops use dedicated cycle tokens.
- **Interruptible:** Opening animations cancel if the user dismisses early; prefer opacity over long transforms on reduce.
- **Respect preference:** `prefers-reduced-motion: reduce` and `[data-motion="reduced"]` collapse movement; opacity/colour may keep a fast fade where noted in C3.

## Token table (standard → reduced)

| CSS variable | Standard | Reduced (`prefers-reduced-motion` / `[data-motion="reduced"]`) |
| --- | --- | --- |
| `--sv-motion-duration-instant` | 0ms | 0ms |
| `--sv-motion-duration-fast` | 150ms | 150ms (opacity/colour only) |
| `--sv-motion-duration-fast-exit` | 125ms | 125ms |
| `--sv-motion-duration-press` | 160ms | 0ms |
| `--sv-motion-duration-moderate` | 200ms | 0ms |
| `--sv-motion-duration-slow` | 240ms | 0ms |
| `--sv-motion-duration-toast-enter` / `-toast-exit` | 220ms / 160ms | 0ms |
| `--sv-motion-duration-list-insert` | 180ms | 0ms |
| `--sv-motion-duration-spinner-cycle` | 800ms | 0ms (static glyph) |
| `--sv-motion-duration-caret-blink` | 1000ms | 0ms |
| `--sv-motion-duration-shimmer-cycle` | 2200ms | 0ms |
| `--sv-motion-easing-standard` | cubic-bezier(0.23, 1, 0.32, 1) | same |
| `--sv-motion-easing-panel` | cubic-bezier(0.32, 0.72, 0, 1) | same |
| `--sv-motion-easing-linear` | cubic-bezier(0, 0, 1, 1) | same |

Semantic transitions: `--sv-motion-transition-feedback`, `-press`, `-popover-enter`, `-popover-exit`, `-disclosure`, `-panel`, `-toast-enter`, `-toast-exit`, `-list-insert` — each resolves to `<duration> <easing> 0ms` with reduced durations from the table above.

DTCG paths: `motion.duration.*`, `motion.easing.*`, `motion.transition.*`, `motion.primitive.duration.*`, `motion.primitive.easing.*`.

## When to use each transition

| Token | Use |
| --- | --- |
| `transition-feedback` | Hover, colour, border on buttons, rows, tabs |
| `transition-press` | Scale on press (`transform`) |
| `transition-popover-enter` / `-exit` | Menus, popovers, combobox popups |
| `transition-disclosure` | Chevron rotation, expand/collapse headers |
| `transition-panel` | Details overlay slide + fade (16px) |
| `transition-toast-enter` / `-exit` | Toast stack |
| `transition-list-insert` | New row fade from 4px above |

## Enter / exit asymmetry

Exits are often faster (popover 150ms in / 125ms out) so dismiss feels responsive. Panel and toast use paired enter/exit durations from the table.

## Movement vs feedback

**Feedback:** opacity, colour, border, scale ≤ 0.98 — allowed under reduced motion only when duration token stays at fast colour fade.

**Movement:** translate, slide, shimmer sweep, spinner rotation — disabled under reduced motion (`animation: none`, no transform transition).

## Loops

| Loop | Token | Reduced behaviour |
| --- | --- | --- |
| Spinner (8-step) | `--sv-motion-duration-spinner-cycle` | Static frame |
| Skeleton shimmer | `--sv-motion-duration-shimmer-cycle` | Solid fill |
| Streaming caret | `--sv-motion-duration-caret-blink` | Steady visible caret |

WCAG 2.3.3 and 2.2.2: loops longer than 5s must be pausable or stoppable; spinner/shimmer/caret are decorative progress — they stop when reduced motion is on or when the async action completes.

## Platform mapping

- **CSS:** `transition` / `animation` with the variables above.
- **Desktop / native:** Map duration ms and cubic-bezier control points to the toolkit animation spec; keep the same semantic names in design docs.
- **VS Code webview:** Same CSS file; respect `prefers-reduced-motion` from the host OS.

## Desktop app (what ships)

Measured from the Kotlin app's `CodeMotion.kt`. The app has three named durations and one shared easing set, not the CSS token ladder above. Every one collapses to 0 when the toolkit's motion flag is off.

| App name | Duration | Used for | Nearest token |
| --- | --- | --- | --- |
| `QUICK` | 120ms | Item tint (hover, press, selected pill), tooltip, icon swap, status-mark shape morph | `fast` 150ms |
| `STEADY` | 180ms | Tab content crossfade, unfold and fold, modal arrival (fade plus scale from 0.94), list item placement and fade-in, message entrance | `list-insert` 180ms, `moderate` 200ms |
| `PANEL` | 240ms | Panes and sidebar width | `slow` 240ms |
| Pop-in | scale from 0.97 | Menus and cards that appear in place | none (press scale is 0.98) |
| Message entrance | 180ms, scale 0.97 to 1, 12px rise | A new transcript entry | none |
| Press | 160ms, scale 0.98 | `FactoryButton` and icon buttons | `press` 160ms (matches) |
| Spinner | 800ms linear, infinite | Running indicator | `spinner-cycle` (matches) |
| Shimmer | 1400ms linear plus a rest delay | Skeleton rows | `shimmer-cycle` 2200ms |
| Tooltip delay | 300ms | Hover only | — |

Easing: standard is `cubic-bezier(0.23, 1, 0.32, 1)` (matches). Panel, unfold, fold and placement use the toolkit's in-out curve `cubic-bezier(0.645, 0.045, 0.355, 1)`, not `easing.panel` (0.32, 0.72, 0, 1).

**Drift (the system value stays authoritative).**

- Tint and hover run 120ms where the system says 150ms; panel easing differs; shimmer is 1400ms where the system says 2200ms.
- Reduced motion is not wired to the operating system. The gating code exists and is exercised only in a test; the capability flag is hard-coded on, so the Running spinner and the button press scale ignore the OS setting. The app also zeroes the short colour fades that the system keeps, and keeps spinners turning where the system shows a static glyph.
- Popovers and menus have no enter or exit motion. The modal has no exit (the toolkit's dialog cannot animate out); the system closes over 150ms. Toasts, the streaming caret blink and the panel slide-and-fade have no app counterpart.
- About ten `tween` literals between 155 and 540ms (plus 1500ms and 5000ms decorative loops on the logo, orb and turning mark) sit outside `CodeMotion`.

**Decision for the next token pass:** adopt 120 / 180 / 240 as the desktop motion ladder, or move the app to 150 / 200 / 240.
