/* Demo project components, copy these into your project.
   Everything below references demo tokens (`--primary`, `--ink-*`, `--motion-*`
   …). Restyle by swapping tokens in `tokens.css`. */

@layer base, tokens, components;

@layer components {
  /* ── Switch ────────────────────────────────────────────────────────────── */

  /* Structure:
   <label class="switch">
     <span class="switch__input-wrapper">
       <input type="checkbox" class="switch__input" />
       <span class="switch__knob"></span>
     </span>
     <span class="switch__label">Label</span>
   </label> */

  .switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }

  .switch__input-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
  }

  .switch__input {
    appearance: none;
    display: block;
    width: 48px;
    height: 28px;
    padding: 0;
    margin: 0;
    background: var(--ink-tertiary);
    border: 0;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--motion-default);
  }

  .switch__input:checked {
    background: var(--green);
  }

  .switch__input:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  .switch__input:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  .switch__knob {
    position: absolute;
    top: 2px;
    inset-inline-start: 2px;
    width: 24px;
    height: 24px;
    background: var(--background-secondary);
    border-radius: var(--radius-full);
    pointer-events: none;
    transition: transform var(--motion-default);
  }

  /* Knob rests at the inline-start edge and slides to the inline-end; --flip
   negates the travel in RTL so it moves toward the correct end. */
  .switch__input:checked + .switch__knob {
    transform: translateX(calc(20px * var(--flip)));
  }

  .switch__label {
    font-size: var(--font-body-small-size);
    color: var(--ink-primary);
    cursor: pointer;
  }

  .switch:has(.switch__input:disabled) .switch__label {
    cursor: not-allowed;
    opacity: 0.5;
  }

  /* ── Checkbox & Radio ──────────────────────────────────────────────────── */

  /* Native inputs styled directly with appearance:none, so forms and screen
   readers work with no JavaScript. Checkbox = square with a checkmark that
   strokes on; radio = circle whose border thickens into a ring. Both share
   sizing, focus, hover, and disabled treatment.

   Structure: the checkbox wraps input + SVG tick in a grid box so the tick
   can overlay the square and animate:
     <label class="checkbox">
       <span class="checkbox__box">
         <input type="checkbox" class="checkbox__input" />
         <svg class="checkbox__check" viewBox="0 0 24 24" fill="none"
              stroke="currentColor" stroke-width="2" stroke-linecap="round"
              stroke-linejoin="round" aria-hidden="true">
           <path d="M5 12l5 5l10 -10" pathLength="1" />
         </svg>
       </span>
       <span class="checkbox__label">Label</span>
     </label>

     <label class="radio">
       <input type="radio" name="group" class="radio__input" />
       <span class="radio__label">Label</span>
     </label> */

  .checkbox,
  .radio {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }

  .checkbox__input,
  .radio__input {
    appearance: none;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin: 0;
    background: transparent;
    border: var(--border-width) solid var(--ink-tertiary);
    cursor: pointer;
    transition:
      background var(--motion-default),
      border-color var(--motion-default),
      border-width var(--motion-default);
  }

  .checkbox__input {
    border-radius: 4px;
  }

  .radio__input {
    border-radius: var(--radius-full);
  }

  .checkbox__input:focus-visible,
  .radio__input:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* Checkmark: an inline SVG overlaid on the box via grid, so the tick can
   stroke itself on (a draw-on animation) instead of just appearing. The
   input and the icon share one grid cell. Declared before the hover/checked
   rules so its lower-specificity input selector stays in ascending order. */
  .checkbox__box {
    display: grid;
    flex-shrink: 0;
  }

  .checkbox__box .checkbox__input,
  .checkbox__check {
    grid-area: 1 / 1;
  }

  /* Icon sizing with our Tabler check path: the svg fills the box (grid
   cell, stretched) so the box size drives everything and the svg keeps its
   native stroke-width 2 (≈1.67px at this size). No padding: the Tabler path's
   own 5→20 bounds give the inset (a path that ran edge-to-edge would need
   padding, ours doesn't). Presentation lives on the <svg> like the other
   inline icons; stroke="currentColor" reads this color. */
  .checkbox__check {
    color: var(--neutral-white);
    pointer-events: none;
  }

  /* pathLength="1" normalises the tick so the 0→1 dash draw covers it exactly. */
  .checkbox__check path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    opacity: 0;
  }

  /* Checked is the state, so the tick is drawn here and the animation only
   plays it on. It used to rely on the animation's forwards fill to hold the
   end values, which left the tick on a checked box at the mercy of the
   animation actually running to completion. */
  .checkbox__input:checked ~ .checkbox__check path {
    stroke-dashoffset: 0;
    opacity: 1;
    animation: checkbox-draw 0.2s ease-out;
  }

  @keyframes checkbox-draw {
    0% {
      stroke-dashoffset: 1;
      opacity: 0;
    }

    10% {
      opacity: 1;
    }

    100% {
      stroke-dashoffset: 0;
      opacity: 1;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .checkbox__input:checked ~ .checkbox__check path {
      animation: none;
    }
  }

  .checkbox__input:disabled,
  .radio__input:disabled {
    cursor: not-allowed;
  }

  /* Dimmed as a unit. The tick is the input's sibling, not its child, so halving
   the input alone washes the fill out from under a tick that stays pure white:
   a disabled checked box came up empty. Dimming the shared cell keeps the two
   in proportion, so the tick reads against its fill at any opacity. */
  .checkbox__box:has(.checkbox__input:disabled:checked) {
    opacity: 0.5;
  }

  /* Checked: checkbox fills with primary; radio grows its border into a solid
   ring (the dot is drawn with border-width, no inner element; box-sizing keeps
   the 20px footprint fixed). */
  .checkbox__input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
  }

  .radio__input:checked {
    border-color: var(--primary);
    border-width: 6px;
  }

  .radio__input:disabled:checked {
    opacity: 0.5;
  }

  /* Disabled and empty: a pale fill takes over from the outline. Opacity alone
   leaves a border-only box as a barely-there outline on a recessed surface,
   where a body still reads as a control that isn't available. Deliberately off
   :checked, whose primary fill IS the state: a grey fill there would make a
   disabled checked option indistinguishable from a disabled empty one. Sits
   between the plain and themed checked rules, where its specificity lands. */
  .checkbox__input:disabled:not(:checked),
  .radio__input:disabled:not(:checked) {
    background: var(--fill-secondary);
    border-color: transparent;
  }

  /* Dark theme: the deep-violet --primary reads as a muddy fill on a dark
   surface, so switch to the lifted --primary-foreground (same swap secondary
   buttons/links use). The checkbox tick then flips dark so it reads as cut out
   of the bright fill, matching the radio, whose transparent centre already
   shows the dark surface as its "dot". */
  :root[data-theme="dark"] .checkbox__input:checked {
    background-color: var(--primary-foreground);
    border-color: var(--primary-foreground);
  }

  :root[data-theme="dark"] .radio__input:checked {
    border-color: var(--primary-foreground);
  }

  :root[data-theme="dark"] .checkbox__check {
    color: var(--background-primary);
  }

  /* Group error: tint the radios red so an invalid group reads at the control, not
   only in the message. The ring (unchecked) and dot (checked) are both drawn with
   border-color, so one override covers both; the :root prefix matches the themed
   :checked specificity and, coming later, wins in light and dark alike. */
  :root .radio-group[aria-invalid="true"] .radio__input {
    border-color: var(--red);
  }

  /* Hover while still unchecked darkens the border, it doesn't fill: the fill is
   the disabled state's now, and a quaternary tint (0.17) against that
   --fill-secondary box (0.20) would be the same box. Same border width, so
   nothing shifts under the pointer. Declared last: higher specificity than the
   :disabled/:checked rules. */
  @media (hover: hover) and (pointer: fine) {
    .checkbox__input:not(:disabled, :checked):hover,
    .radio__input:not(:disabled, :checked):hover {
      border-color: var(--ink-primary);
    }
  }

  /* Radios/checkboxes ship as a group: a vertical stack of options. Radios
   share one input name for mutual exclusion; checkboxes toggle independently. */
  .radio-group,
  .checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .checkbox__label,
  .radio__label {
    font-size: var(--font-body-small-size);
    color: var(--ink-primary);
    cursor: pointer;
  }

  .checkbox:has(:disabled) .checkbox__label,
  .radio:has(:disabled) .radio__label {
    cursor: not-allowed;
    opacity: 0.5;
  }

  /* Group-level hint/error for a radio or checkbox group. Wire to the group via
   aria-describedby (and aria-invalid for the error) so it applies to the whole
   set, not one control. Same caption look as the field hint/error. */
  .radio-group__hint,
  .checkbox-group__hint {
    font-size: var(--font-caption-medium-size);
    line-height: var(--font-caption-medium-lh);
    color: var(--ink-secondary);
  }

  .radio-group__error,
  .checkbox-group__error {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--font-caption-medium-size);
    line-height: var(--font-caption-medium-lh);
    color: var(--red);
  }

  .radio-group__error svg,
  .checkbox-group__error svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
  }

  /* ── Toggle group ──────────────────────────────────────────────────────── */

  /* Segmented control: track is a fill tint over whatever surface it sits on.
   The active segment uses --background-secondary so it matches the elevated
   surface (white in light, lighter-dark in dark), giving the "punched through"
   effect. Uses native radio inputs so no JavaScript is needed for mutual
   exclusion or keyboard nav.

   Place it on a --background-secondary surface (card, sheet) for the effect
   to read correctly.

   Each radio sits just before its label so state flows through the adjacent
   sibling (.toggle-group__radio:checked + .toggle-group__tab), cheaper and
   more compatible than :has(). The radios are visually hidden and out of flow,
   so the flex track lays out only the labels.

   Structure (a single-choice segmented control, a radiogroup, not tabs):
   <div class="toggle-group" role="radiogroup" aria-label="View">
     <input type="radio" name="group" id="t1" class="toggle-group__radio" checked />
     <label class="toggle-group__tab" for="t1"><span class="toggle-group__label">Overview</span></label>
     …
   </div> */

  .toggle-group {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--fill-tertiary);
    border-radius: var(--radius-sm);
  }

  /* Pill variant: fully rounded track (the segments match, below). */
  .toggle-group--pill {
    border-radius: var(--radius-full);
  }

  .toggle-group__tab {
    position: relative;
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    line-height: inherit;
    color: var(--ink-secondary);
    border-radius: 6px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;

    /* Skip the browser's ~300ms double-tap-zoom wait so selection is instant on
     touch (the tab still checks on tap, just without the delay). */
    touch-action: manipulation;
    transition: background var(--motion-default);
  }

  .toggle-group__radio {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    border: 0;
    clip-path: inset(50%);
  }

  /* Base states first, then the higher-specificity interaction states. */

  .toggle-group--pill .toggle-group__tab {
    border-radius: var(--radius-full);
  }

  /* Optional leading icon inside a segment. */
  .toggle-group__tab svg {
    width: 18px;
    height: 18px;
    flex: none;
  }

  /* Selected segment: driven off the checked radio. */
  .toggle-group__radio:checked + .toggle-group__tab {
    background: var(--background-secondary);
    color: var(--ink-primary);
  }

  .toggle-group__radio:disabled + .toggle-group__tab {
    cursor: not-allowed;
    color: var(--ink-tertiary);
    opacity: 0.5;
  }

  .toggle-group__radio:focus-visible + .toggle-group__tab {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
    animation: focus-ring-converge var(--motion-default);
  }

  /* Hover only where a real pointer exists, so it doesn't stick after a tap on
   touch; :active covers the pressed feedback. */
  @media (hover: hover) and (pointer: fine) {
    .toggle-group__radio:not(:checked, :disabled) + .toggle-group__tab:hover {
      background: var(--fill-quaternary-hover);
    }
  }

  .toggle-group__radio:not(:checked, :disabled) + .toggle-group__tab:active {
    background: var(--fill-quaternary-active);
  }

  .toggle-group__radio:checked + .toggle-group__tab:active {
    background: var(--background-secondary-active);
  }

  /* ── Tabs ──────────────────────────────────────────────────────────────── */

  /* Tabbed panels: a tablist with an underline over the active tab, and one panel
   shown below. Real ARIA tabs (tablist/tab/tabpanel), so keyboard nav and panel
   toggling need initTabs() (or the React Tabs), unlike Toggle group, which is a
   CSS-only radiogroup. The list carries a bottom hairline; the active tab paints a
   --primary bar over it via ::after so the indicator sits on that line.

   Structure:
   <div class="tabs">
     <div class="tabs__list" role="tablist" aria-label="…"> role=tab buttons </div>
     <div class="tabs__panel" role="tabpanel" aria-labelledby="…" tabindex="0"> … </div>
   </div> */

  .tabs__list {
    display: flex;
    gap: 0.25rem;
    border-block-end: var(--border-width) solid var(--fill-tertiary);
  }

  .tabs__tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    line-height: inherit;
    color: var(--ink-secondary);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;

    /* Skip the ~300ms double-tap-zoom wait so activation is instant on touch. */
    touch-action: manipulation;
    transition: color var(--motion-default);
  }

  /* Underline indicator: a bar overlapping the list's bottom hairline. Always
   present (transparent) so it fades in rather than popping. */
  .tabs__tab::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    inset-block-end: calc(-1 * var(--border-width));
    height: 2px;
    background: transparent;
    transition: background var(--motion-default);
  }

  .tabs__tab svg {
    width: 18px;
    height: 18px;
    flex: none;
  }

  .tabs__tab[aria-selected="true"] {
    color: var(--ink-primary);
  }

  /* --primary-foreground, not --primary: identical in light, but a brighter
   resaturated lilac in dark, where the flat brand purple reads too dark
   against the surface. */
  .tabs__tab[aria-selected="true"]::after {
    background: var(--primary-foreground);
  }

  .tabs__tab:disabled {
    cursor: not-allowed;
    color: var(--ink-tertiary);
    opacity: 0.5;
  }

  .tabs__tab:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: calc(-1 * var(--focus-ring-width));
    animation: focus-ring-converge var(--motion-default);
  }

  @media (hover: hover) and (pointer: fine) {
    .tabs__tab:not([aria-selected="true"], :disabled):hover {
      color: var(--ink-primary);
    }
  }

  .tabs__panel {
    padding-block-start: 1rem;
  }

  .tabs__panel:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
    animation: focus-ring-converge var(--motion-default);
  }

  /* ── Input ─────────────────────────────────────────────────────────────── */

  /* Text input with optional label, leading/trailing slots, and fill/outline
   variants. The container carries the border and the active state; the <input>
   is chromeless so leading/trailing icons sit flush inside the same box.

   Structure:
   <label class="input">
     <span class="input__label">Label</span>
     <span class="input__container">
       <span class="input__leading">…</span>       (optional)
       <input class="input__element" type="text" />
       <span class="input__trailing">…</span>      (optional)
     </span>
   </label>

   Modifiers on .input__container:
     --fill     , filled surface instead of outline
     --rounded  , pill-shaped
     --invalid  , danger border (red on focus too) */

  .input {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
  }

  .input__label {
    font-size: var(--font-caption-medium-size);
    font-weight: var(--font-caption-medium-weight);
    color: var(--ink-primary);
  }

  .input__label-required {
    margin-inline-start: 0.25rem;
    color: var(--red);
  }

  /* Helper text below the field, wire it to the input with aria-describedby so
   it's announced. Caption size, secondary ink; the .input column gap spaces it. */
  .input__hint {
    font-size: var(--font-caption-medium-size);
    line-height: var(--font-caption-medium-lh);
    color: var(--ink-secondary);
  }

  /* Error message, the invalid counterpart to the hint (red, with an alert
   glyph). Pair with .input__container--invalid + aria-describedby on the input. */
  .input__error {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--font-caption-medium-size);
    line-height: var(--font-caption-medium-lh);
    color: var(--red);
  }

  .input__error svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
  }

  /* Character counter (maxCount): its own trailing-aligned line, tabular so the
   digits don't jitter while typing. Turns danger past the limit, paired with
   aria-invalid on the field. Secondary ink for AA, not tertiary. */
  .input__count {
    align-self: flex-end;
    font-size: var(--font-caption-medium-size);
    line-height: var(--font-caption-medium-lh);
    color: var(--ink-secondary);
    font-variant-numeric: tabular-nums;
  }

  .input__count--over {
    color: var(--red);
  }

  .input__container {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    border: var(--border-width) solid var(--ink-tertiary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);

    /* Whole field reads as a text field: text cursor over the container's
     strips, not just the input. Select and file variants override to pointer. */
    cursor: text;
  }

  /* Whole file field is the click target, so pointer over the container too. */
  .input__container:has(.input__element--file) {
    cursor: pointer;
  }

  /* Active state is the border itself (MD3 outlined field): it turns
   --primary-foreground and a 1px outset shadow doubles it to ~2px on the
   outside, no separate ring, no layout shift. The custom Select trigger mirrors
   this exactly so every field reads the same on focus. */
  .input__container:focus-within {
    border-color: var(--primary-foreground);
    box-shadow: 0 0 0 1px var(--primary-foreground);
  }

  .input__container--fill {
    background: var(--background-primary);
    border-color: transparent;
  }

  .input__container--rounded {
    border-radius: var(--radius-full);
  }

  /* Invalid, either an explicit --invalid modifier, or a field the browser
   itself reports as invalid after the user has interacted (:user-invalid), so
   live constraint validation needs no JS class-toggling. */
  .input__container--invalid,
  .input__container:has(:user-invalid) {
    border-color: var(--red);
  }

  .input__container--invalid:focus-within,
  .input__container:has(:user-invalid):focus-within {
    border-color: var(--red);
    box-shadow: 0 0 0 1px var(--red);
  }

  .input__element {
    flex: 1;
    min-width: 0;

    /* Fill the field height (the container centres its items) so there are no dead
     strips above/below: clicking anywhere hits the input directly, so it focuses
     without a blur/refocus flicker, and the text cursor covers the whole field. */
    align-self: stretch;
    padding: 0 1rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: var(--font-body-small-size);
    line-height: var(--font-body-small-lh);
    outline: none;
    text-overflow: ellipsis;
  }

  .input__element::placeholder {
    /* Placeholder is active text, so ink-secondary for AA (tertiary fails at 3.4:1 in light). */
    color: var(--ink-secondary);
  }

  .input__container:has(.input__element:disabled) {
    color: var(--ink-tertiary);
    opacity: 0.5;
    cursor: not-allowed;
  }

  .input__element:disabled {
    cursor: not-allowed;
  }

  /* File input, the whole field is the click target, so the native picker button
   (::file-selector-button) is plain text, not a surface; the rest of the field
   shows the chosen filename in secondary ink. No focus ring either (rule below),
   the field isn't a text-entry affordance. */
  .input__element--file {
    display: inline-flex;
    align-items: center;

    /* Undo the base align-self: stretch: the file control centres at its content
     height (its field is a click target, not text entry, and has no focus-border
     flicker to fix). */
    align-self: center;
    padding-block: 0;
    color: var(--ink-secondary);
    cursor: pointer;
  }

  .input__element--file::file-selector-button {
    margin-inline-end: 0.5rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--primary-foreground);
    font: inherit;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    cursor: pointer;
  }

  /* Keep the resting border on focus, clicking only opens the file picker. */
  .input__container:has(.input__element--file):focus-within {
    border-color: var(--ink-tertiary);
    box-shadow: none;
  }

  .input__leading,
  .input__trailing {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 0.75rem;
    color: var(--ink-secondary);
  }

  .input__leading + .input__element {
    padding-inline-start: 0;
  }

  .input__element:has(+ .input__trailing) {
    padding-inline-end: 0;
  }

  /* Input Group: a button in an addon slot hugs the field edge, drop the text
   padding so the button's own shape defines the inset. See the Input Group
   component, which composes .input__container with these addon slots. */
  .input__leading:has(.button),
  .input__trailing:has(.button) {
    padding: 4px;
  }

  /* A pill's ends curve away from whatever sits in them, so the 12 that reads
     right against a square field's edge reads tight against this one. Only on the
     side that meets the curve: the gap from the glyph to the text is a gap
     between two pieces of content, and 8 is enough to separate them.

     Icon slots only. A slot holding a button hugs the edge on purpose (the rule
     above), and that is still what it should do here. */
  .input__container--rounded .input__leading:not(:has(.button)) {
    padding-inline: 1rem 0.5rem;
  }

  .input__container--rounded .input__trailing:not(:has(.button)) {
    padding-inline: 0.5rem 1rem;
  }

  /* ── Textarea ──────────────────────────────────────────────────────────── */

  /* Reuses the input shell (label + container + focus/invalid/disabled); the
   container just stretches and the field gets vertical resize.

   Structure:
   <label class="input">
     <span class="input__label">Message</span>
     <span class="input__container input__container--textarea">
       <textarea class="input__element" rows="4"></textarea>
     </span>
   </label> */
  .input__container--textarea {
    align-items: stretch;
    min-height: auto;
  }

  .input__container--textarea .input__element {
    min-height: 96px;
    padding: 0.625rem 1rem;
    resize: vertical;

    /* Grow with content up to the user's manual resize (supported browsers);
     others just keep the fixed min-height + drag handle. */
    field-sizing: content;
  }

  /* ── Native Select ─────────────────────────────────────────────────────── */

  /* Native <select> in the input shell; the UA arrow is removed and our chevron
   is drawn with ::after, so no extra markup.

   Structure:
   <label class="input">
     <span class="input__label">Country</span>
     <span class="input__container input__container--select">
       <select class="input__element"><option>…</option></select>
     </span>
   </label> */
  .input__container--select {
    position: relative;
    cursor: pointer;
  }

  .input__container--select .input__element {
    appearance: none;
    padding-inline-end: 2.5rem;
    cursor: pointer;
  }

  .input__container--select::after {
    content: "";
    position: absolute;
    top: 50%;
    inset-inline-end: 1rem;
    translate: 0 -50%;
    width: 1.25em;
    height: 1.25em;
    background: var(--ink-secondary);
    mask: var(--icon-chevron-down) center / contain no-repeat;
    pointer-events: none;
  }

  /* Kill the browser autofill surface tint, keep our own (often transparent)
   background. The absurd transition duration defers the UA's autofill
   background-color paint indefinitely; text-fill-color keeps our ink. */
  .input__element:-webkit-autofill,
  .input__element:-webkit-autofill:hover,
  .input__element:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--ink-primary);
    transition: background-color 100000s ease-out;
  }

  /* Retint the native search clear (X) to match the theme and give it a real
   target + pointer, like the nav search (WebKit only; Firefox shows none, Esc
   clears). */
  .input__element::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;

    /* 32px hit target (over the 24px WCAG 2.5.8 minimum) with a 20px glyph. Pull it
     4px past the 16px field padding so its bounds sit ~12px from the right edge. */
    width: 2rem;
    height: 2rem;
    margin-inline-end: -0.25rem;
    background: var(--ink-secondary);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6l-12 12'/%3E%3Cpath d='M6 6l12 12'/%3E%3C/svg%3E")
      center / 20px no-repeat;
    cursor: pointer;
  }

  @media (hover: hover) and (pointer: fine) {
    .input__element::-webkit-search-cancel-button:hover {
      background: var(--ink-primary);
    }
  }

  /* ── Select ────────────────────────────────────────────────────────────── */

  /* Custom listbox: a styled trigger + a floating option list, for when the
   native picker's look isn't enough (custom option rendering, a checkmark on
   the selected row). Prefer Native Select when you don't need that. app.js
   (initSelects) wires open/close, selection, and keyboard nav.

   Structure:
   <div class="select" data-select>
     <button class="select__trigger" aria-haspopup="listbox" aria-expanded="false">
       <span class="select__value">Design</span>
       <svg class="select__chevron" …>…</svg>
     </button>
     <ul class="select__list" role="listbox" tabindex="-1" hidden>
       <li class="select__option" role="option" aria-selected="true">Design</li>
       …
     </ul>
   </div> */
  .select {
    position: relative;
  }

  .select__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    min-height: 48px;
    padding: 0 1rem;
    border: var(--border-width) solid var(--ink-tertiary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-body-small-size);
    text-align: start;
    cursor: pointer;
  }

  /* Filled skin: solid surface instead of the outline, mirroring
   .input__container--fill. :where() keeps this at the same low specificity the
   input fill has (0,1,0) so the focus/open border rule below always wins on open,
   just like :focus-within beats --fill on the input. */
  :where(.select--fill) .select__trigger {
    border-color: transparent;
    background: var(--background-primary);
  }

  /* Active border on keyboard focus and while open (focus moves to the list on
   open, so key off aria-expanded to keep the border lit); mirrors the input's
   focus-within, so it uses --primary-foreground to match every other field. */
  .select__trigger:focus-visible,
  .select__trigger[aria-expanded="true"] {
    outline: none;
    border-color: var(--primary-foreground);
    box-shadow: 0 0 0 1px var(--primary-foreground);
  }

  .select__trigger:disabled {
    color: var(--ink-tertiary);
    opacity: 0.5;
    cursor: not-allowed;
  }

  .select__chevron {
    flex-shrink: 0;
    width: 1.25em;
    height: 1.25em;
    color: var(--ink-secondary);
  }

  .select__trigger[aria-expanded="true"] .select__chevron {
    rotate: 180deg;
  }

  .select__list {
    /* Positioned by app.js (positionFloating), which sets left/top/width/max-height.
     Select portals this to <body> and uses position:absolute page coords (below);
     Combobox keeps it in the DOM and overrides to position:fixed so a screen reader
     can follow aria-activedescendant into it (a body portal breaks that). */
    position: absolute;
    z-index: 50;
    max-height: 260px;
    margin: 0;
    padding: 4px;
    overflow-y: auto;

    /* Keep wheel/touch scroll inside the list, don't chain it to the page. */
    overscroll-behavior: contain;

    /* Hide the scrollbar (still scrollable); matches the code blocks' own
     hidden bar. */
    scrollbar-width: none;
    list-style: none;
    background: var(--background-secondary);

    /* Concentric with 8px options: surface = option radius + 4px padding. */
    border-radius: calc(var(--radius-sm) + 4px);

    /* Matches Dropdown Menu: both are a trigger opening a floating list. */
    box-shadow: var(--shadow-md), var(--surface-rim);

    /* The list takes programmatic focus for key handling, but the active option
     (.is-active) is the visible indicator, so no ring on the surface itself. */
    outline: none;

    /* Open-only fade + rise, matching the Dropdown Menu popover. */
    opacity: 0;
    transform: translateY(-4px);
  }

  .select__list::-webkit-scrollbar {
    display: none;
  }

  .select__list[hidden] {
    display: none;
  }

  .select__list:not([hidden]) {
    opacity: 1;
    transform: translateY(0);
    transition:
      opacity 0.15s ease-out,
      transform 0.15s ease-out;
  }

  @starting-style {
    .select__list:not([hidden]) {
      opacity: 0;
      transform: translateY(-4px);
    }
  }

  .select__option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0 0.75rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-body-small-size);
    color: var(--ink-primary);
    cursor: pointer;
  }

  .select__option.is-active {
    background: var(--background-secondary-hover);
  }

  @media (hover: hover) and (pointer: fine) {
    .select__option:hover {
      background: var(--background-secondary-hover);
    }
  }

  /* Selected row is marked by the check mark + surface alone, no weight bump. */

  /* Tabler check on the selected row, tinted to match the row's text. */
  .select__option[aria-selected="true"]::after {
    content: "";
    flex-shrink: 0;
    margin-left: auto;
    width: 1.125em;
    height: 1.125em;
    background: currentcolor;
    mask: var(--icon-check) center / contain no-repeat;
  }

  /* ── Popover ───────────────────────────────────────────────────────────── */

  /* Reusable floating surface built on the native Popover API. Because it lives
   in the top layer it escapes any overflow/stacking context, and popover="auto"
   gives light-dismiss (outside click), Esc, and focus-return for free. app.js
   (positionPopover) places it and keeps it clamped in view on scroll; the
   dropdown menu is the one exception, positioned via CSS anchor positioning
   (below). Open-only fade + rise, matching Dialog; close is instant. */
  .popover {
    position: fixed;
    width: max-content;
    max-width: min(320px, calc(100vw - 16px));
    margin: 0;
    padding: 4px;
    border: 0;

    /* Concentric with 8px items: surface = item radius + 4px padding. */
    border-radius: calc(var(--radius-sm) + 4px);
    background: var(--background-secondary);
    color: var(--ink-primary);
    box-shadow: var(--shadow-md), var(--surface-rim);
    opacity: 0;
    transform: translateY(-4px);
  }

  /* The dropdown menu places itself declaratively with CSS anchor positioning:
   below the invoker, start-aligned, flipping when there's no room. Other popovers
   are positioned by app.js (positionPopover), so this block is menu-only. */
  @supports (position-area: bottom) {
    .menu__list {
      margin-block-start: 4px;
      position-area: block-end span-inline-end;
      position-try-fallbacks:
        flip-block,
        flip-inline,
        flip-block flip-inline;
    }
  }

  .popover:popover-open {
    opacity: 1;
    transform: translateY(0);
    transition:
      opacity 0.15s ease-out,
      transform 0.15s ease-out;
  }

  @starting-style {
    .popover:popover-open {
      opacity: 0;
      transform: translateY(-4px);
    }
  }

  /* Roomier padding for a popover holding prose/controls, rather than the 4px
   used by the menu (where each row supplies its own padding). */
  .popover--panel {
    padding: 1rem;
    font-size: var(--font-body-small-size);
    color: var(--ink-secondary);
  }

  /* ── Dropdown Menu ─────────────────────────────────────────────────────── */

  /* Menu-button pattern: a trigger opens a floating list of actions (role="menu"
   / menuitem) built on the Popover primitive above, as opposed to Select's
   single-value listbox. The native popover owns show/hide/dismiss; app.js
   (initMenus) adds the menu keyboard model (roving arrow focus + type-ahead).

   Structure:
   <div class="menu">
     <button class="menu__trigger" popovertarget="menu-x"
             aria-haspopup="menu" aria-expanded="false">…</button>
     <div class="menu__list popover" id="menu-x" popover role="menu">
       <button class="menu__item" role="menuitem" tabindex="-1">…</button>
       <hr class="menu__separator" />
       <button class="menu__item menu__item--danger" role="menuitem" tabindex="-1">…</button>
     </div>
   </div> */
  .menu {
    display: inline-block;
  }

  .menu__trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0 1rem;
    border: var(--border-width) solid var(--ink-tertiary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-body-small-size);
    cursor: pointer;
  }

  /* Filled skin: same logic as the input and select fills. :where() keeps it at
   0,1,0 so the focus/open border rule below always wins on open. */
  :where(.menu--fill) .menu__trigger {
    border-color: transparent;
    background: var(--background-primary);
  }

  /* Field-styled trigger, so its focus/open border matches Input and Select. */
  .menu__trigger:focus-visible,
  .menu__trigger[aria-expanded="true"] {
    outline: none;
    border-color: var(--primary-foreground);
    box-shadow: 0 0 0 1px var(--primary-foreground);
  }

  .menu__chevron {
    flex-shrink: 0;
    width: 1.25em;
    height: 1.25em;
    color: var(--ink-secondary);
  }

  .menu__trigger[aria-expanded="true"] .menu__chevron {
    rotate: 180deg;
  }

  /* Surface comes from .popover; the menu only sets its width. */
  .menu__list {
    min-width: 220px;
  }

  .menu__item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    min-height: 40px;
    padding: 0 0.75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-body-small-size);
    text-align: start;
    cursor: pointer;
  }

  .menu__item:focus-visible {
    outline: none;
    background: var(--background-secondary-hover);
  }

  .menu__item[disabled] {
    color: var(--ink-tertiary);
    cursor: not-allowed;
  }

  @media (hover: hover) and (pointer: fine) {
    .menu__item:hover {
      background: var(--background-secondary-hover);
    }

    .menu__item[disabled]:hover {
      background: transparent;
    }
  }

  /* Leading glyph; inherits the row color so a danger row tints its icon too. */
  .menu__item-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
  }

  /* Trailing shortcut hint, pushed to the far edge. */
  .menu__shortcut {
    margin-inline-start: auto;
    padding-inline-start: 1rem;

    /* Readable hint text, so ink-secondary to clear AA (tertiary fails at 3.4:1 in light). */
    color: var(--ink-secondary);
    font-size: var(--font-caption-medium-size);
    font-variant-numeric: tabular-nums;
  }

  .menu__item--danger {
    color: var(--red);
  }

  .menu__item--danger:focus-visible {
    background: var(--red-soft-hover);
  }

  @media (hover: hover) and (pointer: fine) {
    .menu__item--danger:hover {
      background: var(--red-soft-hover);
    }
  }

  /* Hairline divider between item groups. */
  .menu__separator {
    height: 1px;
    margin: 4px 0;
    border: 0;
    background: var(--ink-tertiary);
    opacity: 0.4;
  }

  /* ── Button ────────────────────────────────────────────────────────────── */

  /* Structure:
   <button class="button button--{primary|secondary|flat|destructive}
                         [button--icon | button--with-start-icon | button--with-end-icon]">
     [<svg>…</svg>] Label [<svg>…</svg>]
   </button>

   Density is a global knob, set `data-size="xs|sm|md|lg"` on any ancestor
   (root for site-wide, a wrapper for per-section) and the button
   (along with any density-driven component inside) rescales. */

  .button {
    /* Size ladder, sm 40 / md 48 / lg 56, set per data-size below. One var so
     the height and the icon-only square width stay in lockstep; --button-font
     is a var too so a wrapper can re-scale a button group (see the example
     hero, which renders its lg buttons at md scale on mobile). */
    --button-size: 48px;
    --button-font: var(--font-body-small-emphasized-size);
    --button-icon: 1.25em;
    --button-px: 20px;
    --button-gap: 8px; /* 8 at md/lg, tightened to 6 at sm */

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--button-gap);
    height: var(--button-size);
    padding-inline: var(--button-px);
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;

    /* Opt out of the iOS double-tap-zoom gesture (and its ~300ms tap delay) so
     buttons register taps instantly, e.g. the menu button no longer zooms on a
     quick double-tap. */
    touch-action: manipulation;
    font-size: var(--button-font);
    font-weight: var(--font-body-small-emphasized-weight);
    line-height: 1;
    cursor: pointer;
    transition: background var(--motion-default);
  }

  /* xs is the compact control size (32 tall, 14 label) for dense chrome like the
   date-range footer; the icon rides the 14px label at 1.25em (~17.5). */
  [data-size="xs"] .button {
    --button-size: 32px;
    --button-font: var(--font-caption-medium-emphasized-size);
    --button-gap: 6px;
    --button-px: 12px;
  }

  /* sm keeps the md label size (16), so the default 1.25em icon lands at 20 too;
   just tighten the icon gap to 6 on the smaller button. */
  [data-size="sm"] .button {
    --button-size: 40px;
    --button-gap: 6px;
    --button-px: 16px;
  }

  [data-size="lg"] .button {
    --button-size: 56px;
    --button-font: var(--font-body-medium-emphasized-size);
    --button-icon: 24px;
    --button-px: 24px;
  }

  .button svg {
    width: var(--button-icon);
    height: var(--button-icon);
    flex-shrink: 0;
  }

  .button:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* Modifiers, tighten padding on whichever side the icon sits */

  .button--with-start-icon {
    padding-inline-start: calc(var(--button-px) - 4px);
  }

  .button--with-end-icon {
    padding-inline-end: calc(var(--button-px) - 4px);
  }

  /* Icon-only, square, no inline padding */

  .button--icon {
    width: var(--button-size);
    padding-inline: 0;
  }

  /* Skins, hover/active guarded with :not(:disabled) so disabled state wins. */

  /* primary/secondary/flat read the --accent* role, not --primary*: identical to
   the brand by default, but wrapping the button (or any ancestor) in
   [data-color="red|green|blue"] retints all three from one anchor. The
   destructive skin below stays hardwired to red, it's a fixed semantic, not a
   contextual accent. */
  .button--primary {
    background: var(--accent);
    color: var(--accent-on);
  }

  @media (hover: hover) and (pointer: fine) {
    .button--primary:not(:disabled):hover {
      background: var(--accent-hover);
    }
  }

  .button--primary:not(:disabled):active {
    background: var(--accent-active);
  }

  .button--secondary {
    background: var(--accent-soft);
    color: var(--accent-foreground);
  }

  @media (hover: hover) and (pointer: fine) {
    .button--secondary:not(:disabled):hover {
      background: var(--accent-soft-hover);
    }
  }

  .button--secondary:not(:disabled):active {
    background: var(--accent-soft-active);
  }

  .button--flat {
    background: transparent;
    color: var(--accent-foreground);
  }

  @media (hover: hover) and (pointer: fine) {
    .button--flat:not(:disabled):hover {
      background: var(--accent-soft-hover);
    }
  }

  .button--flat:not(:disabled):active {
    background: var(--accent-soft-active);
  }

  .button--destructive {
    background: var(--red-soft);
    color: var(--red);
  }

  @media (hover: hover) and (pointer: fine) {
    .button--destructive:not(:disabled):hover {
      background: var(--red-soft-hover);
    }
  }

  .button--destructive:not(:disabled):active {
    background: var(--red-soft-active);
  }

  /* Foreground: the solid emphasis fill the calendar's selected day + range
   endpoints use (brand --primary-foreground, a brighter lilac in dark) with the
   background as its text, retinting to the region accent inside [data-color]. Used
   on the date-range Apply button so it ties to the selected dates. Deliberately
   not on the Button page: in light it's identical to --primary. */
  .button--foreground {
    background: var(--primary-foreground);
    color: var(--background-secondary);
  }

  [data-color] .button--foreground {
    background: var(--accent);
    color: var(--accent-on);
  }

  /* Hover/active come straight from the foreground tokens, which are theme-aware:
   they lighten in light and darken in dark (see --primary-foreground-hover in
   globals.css). In a data-color region the fill is --accent (mid-tone), so its
   own hover/active lighten as usual. */
  @media (hover: hover) and (pointer: fine) {
    .button--foreground:not(:disabled):hover {
      background: var(--primary-foreground-hover);
    }
  }

  .button--foreground:not(:disabled):active {
    background: var(--primary-foreground-active);
  }

  @media (hover: hover) and (pointer: fine) {
    [data-color] .button--foreground:not(:disabled):hover {
      background: var(--accent-hover);
    }
  }

  [data-color] .button--foreground:not(:disabled):active {
    background: var(--accent-active);
  }

  /* Disabled, fill-quaternary bg for filled skins, transparent for flat.
   Text/icon drop to fill-secondary. Higher specificity via double class. */

  /* Ink, not a fill: the fill ladder's top two rungs are 0.2 and 0.26 alpha, so
     stepping within it cannot look like anything. --ink-tertiary is the quietest
     ink the system has and the first value that actually reads as a word rather
     than a shape where one should be. */
  .button:disabled {
    color: var(--ink-tertiary);
    cursor: not-allowed;

    /* One rung up from the ladder's faintest too, so the face still reads as a
       button under a label that is now ink. */
    background: var(--fill-tertiary);
  }

  .button.button--flat:disabled {
    background: transparent;
  }

  /* Loading, the real Spinner (a nested <svg class="spinner">) overlays the label
   while the button holds its width and keeps its skin color (not the gray
   :disabled look). Using the actual Spinner element (not a pseudo-element) is
   why the in-button loader matches the standalone one exactly. Interaction is
   blocked with aria-disabled + pointer-events, not the disabled attribute, so
   the skin (and the spinner's currentcolor) stay intact. Pair with
   aria-busy="true" and wrap the label in .button__label so it can be hidden.

   <button class="button button--primary button--loading" aria-busy="true"
           aria-disabled="true">
     <span class="button__label">Saving…</span>
     <svg class="spinner" aria-hidden="true" viewBox="0 0 50 50">
       <circle class="spinner__track" cx="25" cy="25" r="20" fill="none" stroke-width="5" />
       <circle class="spinner__arc" cx="25" cy="25" r="20" fill="none" stroke-width="5" />
     </svg>
   </button> */
  .button--loading {
    position: relative;
    pointer-events: none;
  }

  .button--loading .button__label {
    visibility: hidden;
  }

  /* The nested spinner sits centred over the hidden label, sized to it; the
   sizing override lives with the Spinner rules below (after .spinner) so it
   reads as a later, higher-specificity override rather than a descending one. */

  /* Inline-action button (in an Input Group slot) sits a touch tighter than a
   standalone one so it doesn't crowd the field; icon-only buttons stay square. */
  .input__leading .button:not(.button--icon),
  .input__trailing .button:not(.button--icon) {
    padding-inline: 12px;
  }

  /* ── Badge ─────────────────────────────────────────────────────────────── */

  /* Structure:
   <span class="badge badge--{primary|secondary|outline|red|amber|green|blue|fuchsia}
">
     [<svg>…</svg>] Label [<svg>…</svg>]

   An icon just goes in: it takes the gap and the same 8 the label gets, because a
   glyph is drawn to the edges of its box rather than letter-shaped with its own
   side bearings, so there is nothing to pull it in by.
   </span>

   Fixed size, badges don't scale with data-size. */

  .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 20px;
    padding-inline: 8px;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--ink-primary);
    font-family: inherit;
    font-size: var(--font-caption-medium-emphasized-size);
    font-weight: var(--font-caption-medium-weight);
    line-height: 1;
    white-space: nowrap;
  }

  .badge svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
  }

  /* Skins */

  /* Reads --accent, so it's brand by default and retints inside a data-color
   region. For the fixed solid-ink emphasis badge use --neutral. */
  .badge--primary {
    background: var(--accent);
    color: var(--accent-on);
  }

  .badge--neutral {
    background: var(--ink-primary);
    color: var(--background-primary);
  }

  .badge--secondary {
    background: var(--fill-quaternary);
    color: var(--ink-primary);
  }

  .badge--red {
    background: var(--red-soft);
    color: var(--red);
  }

  .badge--amber {
    background: var(--amber-soft);
    color: var(--amber);
  }

  .badge--green {
    background: var(--green-soft);
    color: var(--green);
  }

  .badge--blue {
    background: var(--blue-soft);
    color: var(--blue);
  }

  .badge--fuchsia {
    background: var(--fuchsia-soft);
    color: var(--fuchsia);
  }

  .badge--outline {
    background: transparent;
    color: var(--ink-primary);
    border: var(--border-width) solid var(--fill-secondary);
  }

  /* ── Card ──────────────────────────────────────────────────────────────── */

  /* Surface container. Render as `<div>`, `<a>`, or `<button>`: the anchor
   and button variants get hover/active/focus states automatically.

   Structure:
     <div class="card">
       <img class="card__image" …>                  (optional)
       <div class="card__illustration">…</div>      (optional; alt. to image)
       <div class="card__content">
         <h2 class="card__title">…</h2>
         <p>…</p>
       </div>
     </div>

   Modifiers:
     --horizontal      grid layout with a 6rem image column on the left
     --stretch-image   image fills remaining space (vertical card, fixed height) */

  .card {
    display: block;
    border-radius: var(--radius-md);
    background: var(--background-secondary);
    color: var(--ink-primary);
    overflow: hidden;
    transition: background var(--motion-default);
  }

  /* Interactive: `<a>` and `<button>` get pointer + hover/active/focus.
   Disabled and focus-visible declared first so lower-specificity hover/active
   rules can follow without tripping stylelint's descending-specificity check. */

  a.card,
  button.card {
    cursor: pointer;
    text-decoration: none;
  }

  button.card {
    border: 0;
    padding: 0;
    font: inherit;
    text-align: start;
  }

  button.card:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  a.card:focus-visible,
  button.card:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  @media (hover: hover) and (pointer: fine) {
    a.card:hover,
    button.card:not(:disabled):hover {
      background: var(--background-secondary-hover);
    }
  }

  a.card:active,
  button.card:not(:disabled):active {
    background: var(--background-secondary-active);
  }

  /* ── Slots ── */

  .card__image {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
  }

  /* Illustration wrapper. Pads on three sides so the artwork sits flush with
   card__content on the fourth (bottom in vertical, inline-end in horizontal). */
  .card__illustration {
    padding: 20px 20px 0;
  }

  .card__illustration > * {
    display: block;
    width: 11rem;
    max-width: 100%;
    height: auto;
    margin-inline: auto;
  }

  .card__content {
    padding: 20px;
  }

  .card__title {
    margin: 0;
    font-size: var(--font-body-large-emphasized-size);
    font-weight: var(--font-body-large-emphasized-weight);
    line-height: var(--font-body-large-emphasized-lh);
    letter-spacing: 0;
  }

  .card__content > p {
    margin: 8px 0 16px;
    font-size: var(--font-body-small-size);
    font-weight: var(--font-body-small-weight);
    line-height: var(--font-body-small-lh);
    color: var(--ink-secondary);
  }

  /* Tablet ≥640, pad up and use title-small for the heading. */
  @media (min-width: 640px) {
    .card__illustration {
      padding: 24px 24px 0;
    }

    .card__content {
      padding: 24px;
    }

    .card__title {
      font-size: var(--font-title-small-size);
      font-weight: var(--font-title-small-weight);
      line-height: var(--font-title-small-lh);
    }
  }

  /* ── Chip ──────────────────────────────────────────────────────────────── */

  /* Interactive filter/tag. Two interaction types:
   checkbox (multi-select) and radio (single-select group). Native input
   is visually hidden; the chip surface shows the checked state via
   :has(). Same density knob as button/badge.

   Structure:
     <label class="chip chip--as-checkbox">
       <input type="checkbox" class="chip__input" /> Today
     </label>

     <label class="chip chip--as-radio">
       <input type="radio" name="filter" class="chip__input" /> Today
     </label> */

  .chip {
    --chip-h: 40px;
    --chip-px: 12px;
    --chip-gap: 6px;

    display: inline-flex;
    align-items: center;
    gap: var(--chip-gap);
    min-height: var(--chip-h);
    padding-block: 0;
    padding-inline: var(--chip-px);
    border: var(--border-width) solid var(--fill-secondary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font-family: inherit;
    font-size: calc(var(--font-body-small-emphasized-size) + var(--ds-font-size-addition));
    font-weight: var(--font-body-small-emphasized-weight);
    line-height: 1;
    text-align: start;
    vertical-align: middle;
    -webkit-user-select: none;
    user-select: none;
    transition:
      background var(--motion-default),
      border-color var(--motion-default),
      color var(--motion-default);
  }

  [data-size="xs"] .chip {
    --chip-h: 24px;
    --chip-px: 6px;
    --chip-gap: 4px;
  }

  [data-size="sm"] .chip {
    --chip-h: 32px;
    --chip-px: 8px;
    --chip-gap: 4px;
  }

  [data-size="lg"] .chip {
    --chip-h: 48px;
    --chip-px: 16px;
    --chip-gap: 8px;
  }

  .chip svg {
    width: 1.25em;
    height: 1.25em;
    flex-shrink: 0;
  }

  /* Material 3 leading checkmark on multi-select chips. A CSS mask tints a
   currentColor background into the (Tabler) checkmark shape, so it inherits the
   chip's text color across skins and themes.

   Always rendered so it can animate: collapsed to zero width and faded out
   until checked, with a negative margin cancelling the flex gap so there's no
   phantom space. On check it expands to full width and the label slides right
   to make room: the MD3 filter-chip select motion, CSS-only. */
  .chip--as-checkbox::before {
    content: "";
    width: 0;
    height: 1.125em;
    flex-shrink: 0;
    margin-inline-end: calc(-1 * var(--chip-gap));
    background: currentcolor;
    opacity: 0;
    mask: var(--icon-check) center / contain no-repeat;
    transition:
      width var(--motion-default),
      margin-inline-end var(--motion-default),
      opacity var(--motion-default);
  }

  .chip--as-checkbox:has(input:checked)::before {
    width: 1.125em;
    margin-inline-end: 0;
    opacity: 1;
  }

  @media (prefers-reduced-motion: reduce) {
    .chip--as-checkbox::before {
      transition: none;
    }
  }

  .chip__input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    border: 0;
    clip-path: inset(50%);
  }

  .chip--as-checkbox:not(:has(input:disabled)),
  .chip--as-radio:not(:has(input:disabled)) {
    cursor: pointer;
  }

  @media (hover: hover) and (pointer: fine) {
    .chip--as-checkbox:not(:has(input:disabled, input:checked)):hover,
    .chip--as-radio:not(:has(input:disabled, input:checked)):hover {
      border-color: var(--fill-primary-hover);
    }
  }

  .chip--as-checkbox:not(:has(input:disabled, input:checked)):active,
  .chip--as-radio:not(:has(input:disabled, input:checked)):active {
    border-color: var(--fill-primary-active);
  }

  /* Focus, 3px ring set 1px outside the chip, either on the chip itself or via
   the hidden input */

  .chip:focus-visible,
  .chip:has(:focus-visible) {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
    animation: focus-ring-converge var(--motion-default);
  }

  .chip:has(input:disabled) {
    cursor: not-allowed;
    opacity: 0.5;
  }

  .chip:has(input:checked) {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent-foreground);
  }

  @media (hover: hover) and (pointer: fine) {
    .chip--as-checkbox:has(input:checked):not(:has(input:disabled)):hover {
      background: var(--accent-soft-hover);
    }
  }

  .chip--as-checkbox:has(input:checked):not(:has(input:disabled)):active {
    background: var(--accent-soft-active);
  }

  /* A checked single-select chip is the current choice, it can't be un-picked,
   so it isn't interactive: no pointer (and no hover/active feedback above). */
  .chip--as-radio:has(input:checked):not(:has(input:disabled)) {
    cursor: default;
  }

  /* ── File upload ───────────────────────────────────────────────────────── */

  /* Dashed dropzone wrapping a native file input. The input is a transparent
   full-box overlay (not 1px-clipped), so a click anywhere opens the picker AND a
   dropped file lands on the input, native drag-and-drop with no JS. The Browse
   button is a presentational span raised above the overlay so it shows its own
   hover/active only when the pointer is over the button itself (the click still
   works via the wrapping <label>). The ring shows on :focus-within since the
   input itself is transparent. */
  .file-upload {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    text-align: center;
    border: var(--border-width) dashed var(--ink-tertiary);
    border-radius: var(--radius-md);
    color: var(--ink-secondary);
    cursor: pointer;
    transition:
      border-color var(--motion-default),
      background var(--motion-default);
  }

  .file-upload__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
  }

  .file-upload__icon {
    width: 1.75rem;
    height: 1.75rem;
    color: var(--primary-foreground);
  }

  /* Explicit vertical rhythm (no flex gap): 8px icon→title, title and hint touch,
   16px above the Browse button whether the text above it is the hint or title. */
  .file-upload__title {
    margin-top: 0.5rem;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    color: var(--ink-primary);
  }

  .file-upload__hint {
    font-size: var(--font-caption-medium-size);
    color: var(--ink-secondary);
  }

  /* Presentational Browse button (soft-primary, like button--secondary). Raised
   above the transparent input overlay (z-index) so it receives :hover/:active
   directly; the click still opens the picker because the whole box is a <label>. */
  .file-upload__button {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    height: 40px;
    margin-top: 1rem;
    padding-inline: 16px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary-foreground);
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    line-height: 1;
    transition: background var(--motion-default);
  }

  .file-upload__button:active {
    background: var(--primary-soft-active);
  }

  @media (hover: hover) and (pointer: fine) {
    .file-upload:hover {
      border-color: var(--ink-secondary);
    }

    .file-upload__button:hover {
      background: var(--primary-soft-hover);
    }
  }

  .file-upload:has(:focus-visible) {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  .file-upload:has(:disabled) {
    cursor: not-allowed;
    opacity: 0.5;
  }

  /* ── Error summary ─────────────────────────────────────────────────────── */

  /* Post-submit list of form errors, each a link to its field. Inserted after a
   failed submit and focused (tabindex=-1 + aria-labelledby its heading) so it is
   announced; the links jump to and focus the offending field. Links stay ink so
   they clear AA on the soft-red surface (the red is carried by the icon). */
  .error-summary {
    padding: 1rem;
    border-radius: var(--radius-md);
    background: var(--red-soft);
    color: var(--ink-primary);
  }

  .error-summary__title {
    margin: 0 0 0.25rem;
    font-size: var(--font-body-medium-emphasized-size);
    font-weight: var(--font-body-medium-emphasized-weight);
    line-height: var(--font-body-medium-emphasized-lh);
  }

  .error-summary__list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
    padding-inline-start: 1.5rem;
    font-size: var(--font-body-small-size);
  }

  .error-summary__link {
    color: var(--ink-primary);
    font-weight: 400;
    text-underline-offset: 2px;
  }

  .error-summary__link:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* ── Alert ─────────────────────────────────────────────────────────────── */

  /* Inline status message. The variant sets a soft surface + matching icon
   color; text stays ink for legibility. Title is optional: icon + text alone
   reads fine for a one-liner.

   Structure:
   <div class="alert alert--info" role="status">
     <svg class="alert__icon" …>…</svg>
     <div class="alert__body">
       <p class="alert__title">Heads up</p>
       <p class="alert__text">Message goes here.</p>
     </div>
   </div> */
  .alert {
    display: flex;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    color: var(--ink-primary);
  }

  .alert p {
    margin: 0;
  }

  .alert__icon {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 1px;
  }

  .alert__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  .alert__title {
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
  }

  .alert__text {
    font-size: var(--font-body-small-size);
    color: var(--ink-primary);
  }

  .alert--info {
    background: var(--blue-soft);
  }

  .alert--info .alert__icon {
    color: var(--blue);
  }

  .alert--success {
    background: var(--green-soft);
  }

  .alert--success .alert__icon {
    color: var(--green);
  }

  .alert--warning {
    background: var(--amber-soft);
  }

  .alert--warning .alert__icon {
    color: var(--amber);
  }

  .alert--error {
    background: var(--red-soft);
  }

  .alert--error .alert__icon {
    color: var(--red);
  }

  /* Non-semantic callout: reads --accent, so it follows a data-color region
   (brand by default). Unlike the status variants, its color carries no meaning. */
  .alert--accent {
    background: var(--accent-soft);
  }

  .alert--accent .alert__icon {
    color: var(--accent-foreground);
  }

  /* ── Dialog ────────────────────────────────────────────────────────────── */

  /* Native <dialog>, focus trap, Esc-to-close, and an inert background come for
   free. Open with dialog.showModal(); app.js wires [data-dialog-open="id"] and
   [data-dialog-close], and a click on the backdrop closes it.

   The content column is a scroll area (see Scroll area, whose block this needs
   alongside this one): a modal is capped by the UA's max-height, so long content
   has to scroll somewhere, and routing it through our own bar means it looks the
   same everywhere instead of an overlay bar that hides itself on macOS and a
   permanent gutter on Windows.

   Structure:
   <dialog class="dialog" id="demo-dialog">
     <div class="dialog__inner" data-scroll-area>
       <div class="scroll-area__viewport dialog__scroll">
         <h2 class="dialog__title">Title</h2>
         <p class="dialog__text">Supporting copy.</p>
         <div class="dialog__actions">
           <button class="button button--flat" data-dialog-close>Cancel</button>
           <button class="button button--primary" data-dialog-close>Confirm</button>
         </div>
       </div>
       <div class="scroll-area__bar" aria-hidden="true">
         <div class="scroll-area__thumb"></div>
       </div>
     </div>
   </dialog> */
  .dialog {
    width: min(92vw, 420px);

    /* The UA caps a modal's height, and this keeps the overflow past that cap
     off the dialog itself: the viewport inside scrolls instead, and the corners
     stay clipped over it. */
    overflow: hidden;
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--background-secondary);
    color: var(--ink-primary);
    box-shadow: var(--shadow-lg);

    /* Animate on open only, the transition lives on [open], so removing it
     (close) is instant. @starting-style gives the entry state (fade + rise).
     Progressive enhancement, browsers without @starting-style just pop in. */
    opacity: 0;
    transform: translateY(10px);
  }

  /* display belongs on [open] only: an unconditional one would beat the UA's
   `dialog:not([open]) { display: none }` and leave every dialog on screen. The
   column is what bounds the scrolling viewport inside. */
  .dialog[open] {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateY(0);
    transition:
      opacity 0.2s ease-out,
      transform 0.2s ease-out;
  }

  @starting-style {
    .dialog[open] {
      opacity: 0;
      transform: translateY(10px);
    }
  }

  .dialog::backdrop {
    background: var(--overlay);
    opacity: 0;
  }

  .dialog[open]::backdrop {
    opacity: 1;
    transition: opacity 0.2s ease-out;
  }

  @starting-style {
    .dialog[open]::backdrop {
      opacity: 0;
    }
  }

  /* Scroll-area root: it holds the bar, which is absolutely positioned and so
   needs a parent that doesn't scroll under it. min-height: 0 on both this and
   the viewport is what lets them shrink below their content; a flex item floors
   at content height by default, and either floor would push the overflow back
   out to the dialog. */
  .dialog__inner {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
  }

  /* The content column, and the scrolling viewport: the gap sets the dialog's
   vertical rhythm, and the bar sits in the 24 gutter the padding already
   leaves, so revealing it never reflows the content. Paired with
   .scroll-area__viewport in the markup rather than styled through it, so this
   section stays copyable on its own. */
  .dialog__scroll {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
    padding: 1.5rem;
  }

  /* The column is height-bound now (it scrolls), and a flex item shrinks to fit
   its container by default: a child with a height of its own (an image, a fixed
   block) would be squashed instead of scrolled. Hold them all at their own
   height and let the overflow go to the viewport. */
  .dialog__scroll > * {
    flex-shrink: 0;
  }

  /* Title + description, 1rem apart to match the dialog's vertical rhythm. */
  .dialog__header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  /* Stacked form fields, 1rem between fields; the 1.5rem space above and below
   the group comes from the .dialog__scroll gap. */
  .dialog__form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .dialog__title {
    margin: 0;
    font-size: var(--font-body-large-emphasized-size);
    font-weight: var(--font-body-large-emphasized-weight);
    line-height: var(--font-body-large-emphasized-lh);
  }

  .dialog__text {
    margin: 0;
    font-size: var(--font-body-small-size);
    color: var(--ink-secondary);
  }

  /* Plain footer: just a small lift above the buttons. The 1.5rem separation from
   the content above comes from the .dialog__scroll gap. */
  .dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 0.5rem;
  }

  /* Opt-in footer surface: a full-bleed panel matching the dialog (opaque, so it
   can sit sticky over scrolling content) with a top divider. The negative margins
   cancel .dialog__scroll's padding; the 1.5rem padding restores it inside, giving
   the buttons room below the divider. */
  .dialog__actions--surface {
    margin: 0 -1.5rem -1.5rem;
    padding: 1.5rem;
    background: var(--background-secondary);
    border-top: var(--border-width) solid var(--fill-tertiary);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
  }

  /* ── Sheet ─────────────────────────────────────────────────────────────── */

  /* Edge-anchored panel on native <dialog>: same focus-trap, Esc, and inert
   backdrop as Dialog, and the same data-dialog-open / data-dialog-close wiring
   (app.js). Anchored to the inline-end edge; --left flips it to inline-start.
   Same open-only fade + nudge as Dialog (here on the X axis, toward its edge);
   close is instant.

   Structure:
   <button data-dialog-open="demo-sheet">Open</button>
   <dialog class="sheet" id="demo-sheet">
     <div class="sheet__inner">
       <header class="sheet__header">
         <h2 class="sheet__title">Title</h2>
         <button class="sheet__close" data-dialog-close aria-label="Close">…</button>
       </header>
       <div class="sheet__body" data-scroll-area>
         <div class="scroll-area__viewport sheet__scroll">…</div>
         <div class="scroll-area__bar" aria-hidden="true">
           <div class="scroll-area__thumb"></div>
         </div>
       </div>
     </div>
   </dialog> */
  .sheet {
    inset: 0 0 0 auto;
    width: min(92vw, 400px);
    max-width: none;
    height: auto;
    max-height: none;
    padding: 0;
    border: 0;
    background: var(--background-secondary);
    color: var(--ink-primary);
    box-shadow: var(--shadow-lg);

    /* Slide in fully opaque (no opacity fade) so the panel never goes see-through
       over the darkening backdrop mid-animation. Only the backdrop fades. */
    transform: translateX(256px);
  }

  .sheet--left {
    inset: 0 auto 0 0;
    transform: translateX(-256px);
  }

  .sheet[open] {
    transform: translateX(0);
    transition: transform 0.2s ease-out;
  }

  @starting-style {
    .sheet[open] {
      transform: translateX(256px);
    }

    .sheet--left[open] {
      transform: translateX(-256px);
    }
  }

  .sheet::backdrop {
    background: var(--overlay);
    opacity: 0;
  }

  .sheet[open]::backdrop {
    opacity: 1;
    transition: opacity 0.2s ease-out;
  }

  @starting-style {
    .sheet[open]::backdrop {
      opacity: 0;
    }
  }

  .sheet__inner {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1.25rem 1.5rem;
    border-bottom: var(--border-width) solid var(--fill-tertiary);
  }

  .sheet__title {
    margin: 0;
    font-size: var(--font-body-large-emphasized-size);
    font-weight: var(--font-body-large-emphasized-weight);
    line-height: var(--font-body-large-emphasized-lh);
  }

  .sheet__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-inline-end: -0.5rem;
    border: 0;

    /* Round, like every other icon-only control: the hover surface is the shape
     of the target, and a rounded square read as a different kind of button. */
    border-radius: var(--radius-full);
    background: transparent;

    /* Full ink: it's the one control in the header, and a secondary one read as
     an afterthought beside the title. */
    color: var(--ink-primary);
    cursor: pointer;
    transition: background var(--motion-default);
  }

  @media (hover: hover) and (pointer: fine) {
    .sheet__close:hover {
      background: var(--background-secondary-hover);
    }
  }

  .sheet__close:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  .sheet__close svg {
    width: 20px;
    height: 20px;
  }

  /* The body is a scroll area (see Scroll area, whose block this needs alongside
   this one): the platform bar is hidden and app.js draws the thumb, so a long
   sheet reads the same everywhere instead of an overlay bar that hides itself
   on macOS and a permanent gutter on Windows.

   The body is the scroll-area root and the viewport inside it does the
   scrolling, so the absolutely positioned bar has a parent that doesn't scroll
   under it. min-height: 0 on both is what lets them shrink below their content:
   a flex item floors at content height by default, and either floor would hand
   the scrolling back to the sheet. */
  .sheet__body {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    font-size: var(--font-body-small-size);
    color: var(--ink-secondary);
  }

  /* The viewport carries a sheet-owned class alongside .scroll-area__viewport
   rather than being styled through it, so this section stays copyable on its
   own. The bar sits in the 24 gutter this padding already leaves, so revealing
   it never reflows the content. */
  .sheet__scroll {
    flex: 1;
    min-height: 0;
    padding: 1.5rem;
  }

  /* On open, focus is parked on the panel's scrolling viewport (JS sets tabindex
   -1) so no button shows a stray focus ring, and the arrow keys scroll the
   content. It's only a programmatic focus holder, never ring it. */
  .sheet__inner:focus-visible,
  .dialog__inner:focus-visible,
  .dialog__scroll:focus-visible,
  .sheet__scroll:focus-visible {
    outline: none;
  }

  /* ── Accordion ─────────────────────────────────────────────────────────── */

  /* Native <details>/<summary>, no JS. A summary row with a +/- toggle that
   flips to a minus on open, on an elevated surface.

   Structure:
   <div class="accordion">
     <details class="accordion__item">
       <summary class="accordion__summary">
         Question
         <span class="accordion__toggle">…</span>
       </summary>
       <div class="accordion__body"><p>Answer.</p></div>
     </details>
   </div> */
  .accordion {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .accordion__item {
    overflow: hidden;
    background: var(--background-secondary);
    border-radius: var(--radius-md);
  }

  .accordion__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 64px;
    padding: 16px;
    color: var(--ink-primary);
    font-size: var(--font-body-medium-emphasized-size);
    font-weight: var(--font-body-medium-emphasized-weight);
    list-style: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;

    /* The hover below is the only interactive surface in this component, and it
       was the one that snapped: everything else on a page with an accordion
       (cards, chips, buttons) eases its background over the same duration. */
    transition: background var(--motion-default);
  }

  .accordion__summary::-webkit-details-marker {
    display: none;
  }

  .accordion__summary:focus-visible {
    outline: none;
  }

  /* Hover surface only while collapsed, an open panel's summary shouldn't tint. */
  @media (hover: hover) and (pointer: fine) {
    .accordion__item:not([open]) .accordion__summary:hover {
      background: var(--background-secondary-hover);
    }
  }

  /* Ring the whole item (not just the summary) when focused; converges in like
   the other focus rings. */
  .accordion__item:has(.accordion__summary:focus-visible) {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
    animation: focus-ring-converge var(--motion-default);
  }

  /* +/- toggle on a soft-primary surface. Drawn as two CSS bars (not an inline
   SVG) so the <summary> holds no embedded content, which trips the "interactive
   content in <summary>" audit. The vertical bar hides when the item is open, so
   the plus reads as a minus. */
  .accordion__toggle {
    position: relative;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary-foreground);
  }

  .accordion__toggle::before,
  .accordion__toggle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 11px;
    height: 1.5px;
    border-radius: 1px;
    background: currentcolor;
    translate: -50% -50%;
  }

  .accordion__toggle::after {
    rotate: 90deg;
    transition: opacity var(--motion-default);
  }

  .accordion__item[open] .accordion__toggle::after {
    opacity: 0;
  }

  .accordion__body {
    padding: 0 16px 16px;
    color: var(--ink-secondary);
    font-size: var(--font-body-small-size);
  }

  .accordion__body > :first-child {
    margin-top: 0;
  }

  /* The mirror, plus the case a positional :last-child can't see: an element that
     ships hidden is still the last child, so the one before it is left holding a
     bottom margin on top of the body's own padding. */
  .accordion__body > :last-child,
  .accordion__body > :has(+ [hidden]:last-child) {
    margin-bottom: 0;
  }

  .accordion__body > :last-child {
    margin-bottom: 0;
  }

  /* Animate open/close: interpolate-size lets block-size go to/from auto;
   ::details-content fades + expands. Progressive enhancement: browsers without
   ::details-content just toggle instantly. */
  @media (prefers-reduced-motion: no-preference) {
    .accordion__item {
      interpolate-size: allow-keywords;
    }
  }

  .accordion__item::details-content {
    overflow: hidden;
    block-size: 0;
    opacity: 0;
    transition:
      content-visibility allow-discrete var(--motion-default),
      opacity var(--motion-default),
      block-size var(--motion-default);
  }

  .accordion__item[open]::details-content {
    block-size: auto;
    opacity: 1;
  }

  /* ── Table ─────────────────────────────────────────────────────────────── */

  /* Plain data table. Wrap in .table-wrap so wide tables scroll instead of
   breaking the page.

   Structure:
   <div class="table-wrap">
     <table class="table">
       <thead><tr><th>…</th></tr></thead>
       <tbody><tr><td>…</td></tr></tbody>
     </table>
   </div> */
  .table-wrap {
    overflow-x: auto;
    background: var(--background-secondary);
    border: var(--border-width) solid var(--fill-tertiary);
    border-radius: 12px;
  }

  /* Focusable only when it actually scrolls (JS/React toggle tabindex on overflow),
     so keyboard users can pan a wide table without a stray tab stop on ones that fit. */
  .table-wrap:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 2px;
  }

  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-body-small-size);
  }

  .table th,
  .table td {
    padding: 0.625rem 0.75rem;
    text-align: start;
    border-bottom: var(--border-width) solid var(--fill-tertiary);
  }

  .table th {
    background: var(--fill-quaternary);
    color: var(--ink-primary);
    font-size: var(--font-body-small-size);
    font-weight: var(--font-body-small-emphasized-weight);
    white-space: nowrap;
  }

  .table td {
    color: var(--ink-primary);
  }

  /* Both cell types, not just td: a table with row headers (<th scope="row">) has
     one in every row, so clearing the last row's data cells alone left a line
     under the label column and nothing beside it. */
  .table tbody tr:last-child td,
  .table tbody tr:last-child th {
    border-bottom: 0;
  }

  /* Data table: sortable headers + row selection. Both are progressive
   enhancements over the plain table (initDataTables wires the behaviour); the
   markup degrades to a static table with no JS.

   Sortable column: a <th aria-sort="none"> whose label is a .table__sort button.
   The indicator is a chevron that shows faint on hover, solid when the column is
   the active sort, and flips for ascending. aria-sort is the single source of
   truth, so screen readers announce the state and CSS reads it for the arrow. */
  .table__sort {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
  }

  .table__sort::after {
    content: "";
    width: 1rem;
    height: 1rem;
    background: currentcolor;
    mask: var(--icon-chevron-down) center / contain no-repeat;
    opacity: 0;
    transition: opacity var(--motion-default);
  }

  @media (hover: hover) and (pointer: fine) {
    .table th[aria-sort="none"] .table__sort:hover::after {
      opacity: 0.4;
    }
  }

  .table th[aria-sort="ascending"] .table__sort::after,
  .table th[aria-sort="descending"] .table__sort::after {
    opacity: 1;
  }

  /* Chevron points down for descending; flip it for ascending. */
  .table th[aria-sort="ascending"] .table__sort::after {
    rotate: 180deg;
  }

  .table__sort:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  /* Select column: tight, centred on the checkbox; the header + each row carry a
   .checkbox. A row with its box checked lifts onto the accent-soft surface. */
  .table th.table__select,
  .table td.table__select {
    width: 1px; /* shrink-to-fit; the checkbox sets the real width */
    padding-inline: 0.75rem;
  }

  .table__select .checkbox {
    vertical-align: middle;
  }

  .table tbody tr:has(.checkbox__input:checked) td {
    background: var(--accent-soft);
  }

  /* ── Tooltip ───────────────────────────────────────────────────────────── */

  /* CSS-only label on hover/focus. Wrap a focusable trigger; the bubble shows on
   :hover and :focus-within, so keyboard users get it too.

   Structure:
   <span class="tooltip">
     <button class="button …">Trigger</button>
     <span class="tooltip__bubble" role="tooltip">Label text</span>
   </span> */
  .tooltip {
    display: inline-flex;
  }

  /* Position is set by initTooltips (fixed coords) so the bubble can flip
   above/below and clamp to the viewport. --tt-arrow is the arrow's x within
   the bubble, so it keeps pointing at the trigger even when the bubble shifts. */
  .tooltip__bubble {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    padding: 0.375rem 0.625rem;
    background: var(--ink-primary);
    color: var(--background-primary);
    border-radius: var(--radius-sm);
    font-size: var(--font-caption-medium-size);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--motion-default);
  }

  /* Hoverable once shown (WCAG 1.4.13): the pointer can move onto the bubble to
     read it. Base stays pointer-events:none so a hidden bubble never blocks clicks. */
  .tooltip__bubble.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .tooltip__bubble::after {
    content: "";
    position: absolute;
    border: 5px solid transparent;
  }

  /* --tt-arrow is the offset along the shared edge (x for top/bottom, y for
   left/right), so the arrow keeps pointing at the trigger after clamping. */
  .tooltip__bubble[data-placement="top"]::after {
    top: 100%;
    left: var(--tt-arrow, 50%);
    translate: -50% 0;
    border-top-color: var(--ink-primary);
  }

  .tooltip__bubble[data-placement="bottom"]::after {
    bottom: 100%;
    left: var(--tt-arrow, 50%);
    translate: -50% 0;
    border-bottom-color: var(--ink-primary);
  }

  .tooltip__bubble[data-placement="left"]::after {
    left: 100%;
    top: var(--tt-arrow, 50%);
    translate: 0 -50%;
    border-left-color: var(--ink-primary);
  }

  .tooltip__bubble[data-placement="right"]::after {
    right: 100%;
    top: var(--tt-arrow, 50%);
    translate: 0 -50%;
    border-right-color: var(--ink-primary);
  }

  /* ── Spinner ───────────────────────────────────────────────────────────────
   Indeterminate loading indicator. A faint full-circle track with a solid arc
   on top; the arc grows and shrinks while the whole thing rotates, so the fill
   reads as travelling around the track in one direction. Arc color is
   currentColor, so it inherits its context (button text, ink, etc.); pair with
   a visually-hidden label.

   Mechanism: an <svg> of two concentric <circle>s. The svg spins; the arc
   circle animates stroke-dasharray (the visible dash grows 1→100 then back)
   and stroke-dashoffset (drifts negatively). Because dashoffset walks along the
   path it wraps continuously past the top, so the arc never appears to reverse.
   That is the reason this can't be faked with a conic-gradient, whose sweep can't run
   past 360deg and back seamlessly.

   Structure:
     <svg class="spinner" role="status" aria-label="Loading" viewBox="0 0 50 50">
       <circle class="spinner__track" cx="25" cy="25" r="20" fill="none" stroke-width="5" />
       <circle class="spinner__arc" cx="25" cy="25" r="20" fill="none" stroke-width="5" />
     </svg> */
  .spinner {
    width: 1.5rem;
    height: 1.5rem;
    animation: spinner-rotate 2s linear infinite;
  }

  .spinner--sm {
    width: 1rem;
    height: 1rem;
  }

  .spinner--lg {
    width: 2rem;
    height: 2rem;
  }

  /* In-button loader: the Spinner centred over the hidden label, sized to it. */
  .button--loading .spinner {
    position: absolute;
    width: 1.25em;
    height: 1.25em;
  }

  .spinner__track {
    stroke: color-mix(in oklab, currentcolor 18%, transparent);
  }

  .spinner__arc {
    stroke: currentcolor;
    stroke-dasharray: 1px, 200px;
    transform-origin: center;
    animation: spinner-dash 2s ease-in-out infinite;
  }

  /* The svg rotates via transform (not the `rotate` property, which SVG support
   for is patchy); the arc animates its dash on top. */
  @keyframes spinner-rotate {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes spinner-dash {
    0% {
      stroke-dasharray: 1px, 200px;
      stroke-dashoffset: 0;
    }

    50% {
      stroke-dasharray: 100px, 200px;
      stroke-dashoffset: -15px;
    }

    100% {
      stroke-dasharray: 1px, 200px;
      stroke-dashoffset: -120px;
    }
  }

  /* A spinner conveys ongoing state, so it must not freeze like decorative
   motion. The global guard in globals.css exempts these two selectors from its
   animation clamp (an !important override from this layer could not win), so a
   plain slowed spin is all that's needed here. */
  @media (prefers-reduced-motion: reduce) {
    .spinner,
    .spinner__arc {
      animation-duration: 6s;
      animation-iteration-count: infinite;
    }
  }

  /* ── Skeleton ────────────────────────────────────────────────────────────────
   Purely presentational placeholder for content that hasn't loaded. Size it to
   match the real content (explicit width/height, or let it fill its container)
   so the layout doesn't shift on swap. Calm opacity pulse, not a sweeping
   shimmer, so a screenful of them doesn't distract; the global reduced-motion
   guard settles it to a static block.

   A11y: a skeleton conveys nothing to assistive tech. Mark the loading region
   aria-busy="true" and announce state with a role="status" text (or aria-hidden
   the placeholders). Never let the shapes be the only "loading" signal.

   Structure: <div class="skeleton" style="width: 12rem; height: 1rem"></div> */
  .skeleton {
    display: block;
    background: var(--fill-secondary);
    border-radius: var(--radius-sm);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
  }

  /* Text line: rounded like a run of text, sized to the current font by default
     so it drops into prose without a width. Use width to trim the last line. */
  .skeleton--text {
    height: 0.7em;
    border-radius: var(--radius-full);
  }

  /* Circle: width sets the diameter; aspect-ratio keeps it round (avatars). */
  .skeleton--circle {
    aspect-ratio: 1;
    border-radius: var(--radius-full);
  }

  @keyframes skeleton-pulse {
    50% {
      opacity: 0.4;
    }
  }

  /* Forced colors strips the alpha fill; keep a visible bordered box so the
     placeholder doesn't vanish into the background. */
  @media (forced-colors: active) {
    .skeleton {
      forced-color-adjust: none;
      background: Canvas;
      border: var(--border-width) solid GrayText;
    }
  }

  /* ── Progress ──────────────────────────────────────────────────────────────
   Native <progress> for a task with measurable completion; reach for Spinner
   when progress can't be measured. The track + value have no standard selector,
   so each engine's pseudo-elements are styled separately.

   Structure: <progress class="progress" value="60" max="100" aria-label="Upload"></progress> */
  .progress {
    appearance: none;
    width: 100%;
    height: 8px;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--fill-quaternary);
    overflow: hidden;
  }

  .progress::-webkit-progress-bar {
    background: var(--fill-quaternary);
  }

  .progress::-webkit-progress-value {
    background: var(--primary-foreground);
    border-radius: var(--radius-full);
    transition: inline-size var(--motion-default);
  }

  .progress::-moz-progress-bar {
    background: var(--primary-foreground);
  }

  /* ── Steps ───────────────────────────────────────────────────────────────────
   Numbered progress through a linear, multi-step flow (checkout, wizard). An
   <ol> so the sequence is semantic; the active step carries aria-current="step"
   and finished steps get .is-done. Colors ride --accent, so a [data-color]
   region retints the whole track.

   The connector is split into two halves per step (an outgoing ::after and an
   incoming ::before) that each stop at the indicator's edge, so the line never
   runs under a circle and the indicator needs no opaque fill to hide it. A
   segment reads filled when the step it leaves is done (::after) and the step it
   enters is done or current (::before), so the track fills up to the active step.

   Structure:
   <ol class="steps">
     <li class="steps__step is-done">
       <span class="steps__indicator"><span class="steps__num">1</span></span>
       <span class="steps__label">Cart</span>
     </li>
     <li class="steps__step is-current" aria-current="step">…</li>
     <li class="steps__step">…</li>
   </ol> */
  .steps {
    display: flex;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .steps__step {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    text-align: center;
  }

  /* Connector halves, pinned to the indicator's vertical centre (2rem tall). Each
   stops at the indicator edge (50% ∓ 1rem) so it spans only the gap. */
  .steps__step:not(:last-child)::after,
  .steps__step:not(:first-child)::before {
    content: "";
    position: absolute;
    top: 1rem;
    height: 2px;
    background: var(--fill-tertiary);
  }

  .steps__step:not(:last-child)::after {
    left: calc(50% + 1rem);
    right: 0;
  }

  .steps__step:not(:first-child)::before {
    left: 0;
    right: calc(50% + 1rem);
  }

  /* Filled up to the active step: the half leaving a done step, and the half
   entering a done or current step. */
  .steps__step.is-done::after {
    background: var(--accent);
  }

  .steps__step.is-done::before,
  .steps__step.is-current::before {
    background: var(--accent);
  }

  .steps__indicator {
    position: relative; /* lift above the connector halves */
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-full);
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--fill-tertiary);
    color: var(--ink-tertiary);
    font-size: var(--font-caption-medium-size);
    font-weight: 500;
  }

  .steps__step.is-current .steps__indicator {
    box-shadow: inset 0 0 0 2px var(--accent);
    color: var(--accent-foreground);
  }

  .steps__step.is-done .steps__indicator {
    background: var(--accent);
    box-shadow: none;
    color: var(--accent-on);
  }

  /* Finished steps swap the number for a check (same markup, .is-done on the li). */
  .steps__step.is-done .steps__num {
    display: none;
  }

  .steps__step.is-done .steps__indicator::after {
    content: "";
    width: 1rem;
    height: 1rem;
    background: currentcolor;
    mask: var(--icon-check) center / contain no-repeat;
  }

  .steps__label {
    font-size: var(--font-body-small-size);

    /* Upcoming steps: ink-secondary (not tertiary) so the label clears AA in light. */
    color: var(--ink-secondary);
  }

  .steps__step.is-current .steps__label {
    color: var(--ink-primary);
    font-weight: 500;
  }

  .steps__step.is-done .steps__label {
    color: var(--ink-primary);
  }

  /* ── Link ──────────────────────────────────────────────────────────────────
   Inline text link. --cta for a standalone call-to-action with a trailing
   arrow. Focus ring comes from the shared rule.

   Structure:
   <a class="link" href="#">Read more</a>
   <a class="link link--cta" href="#">See all <svg>…</svg></a> */
  .link {
    color: var(--ink-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;

    /* radius-sm so the focus ring reads rounded, matching the nav/link-list rings. */
    border-radius: var(--radius-sm);
    transition: color var(--motion-default);
  }

  /* A link shifts from wherever it rests rather than changing hue under the
     pointer: this one rests at --ink-primary and dims from there, and the CTA
     below, which rests at the brand colour, dims from that. Moving to the brand
     on hover made the same gesture mean two different things depending on which
     variant you were pointing at, and read as the link becoming a different kind
     of link rather than responding.

     Pressed as well as hover, the same pair the back buttons use: these are
     navigation a reader aims at and presses, and a control that acknowledges the
     pointer but not the press feels half-finished on touch, where hover never
     arrives at all. */
  @media (hover: hover) and (pointer: fine) {
    .link:hover {
      color: var(--ink-primary-hover);
    }
  }

  .link:active {
    color: var(--ink-primary-active);
  }

  .link--cta {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--primary-foreground);
    font-weight: 500;
    text-decoration: none;
  }

  /* Two-part arrow: the stem fades in and the chevron slides on hover, so the
   arrow grows out of the text. Lives here, not in the docs chrome, so the CTA
   works from components.css alone. */
  .link-arrow {
    width: 12px;
    height: 12px;
    overflow: visible;
    flex-shrink: 0;
  }

  .link-arrow__line {
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  }

  .link-arrow__chevron {
    transition: translate 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  }

  /* The colour shifts with the arrow, off the brand rather than off the ink,
   since that is where this variant rests. */
  @media (hover: hover) and (pointer: fine) {
    .link--cta:hover {
      color: var(--primary-foreground-hover);
    }

    .link--cta:hover .link-arrow__line {
      opacity: 1;
    }

    .link--cta:hover .link-arrow__chevron {
      translate: 3px 0;
    }
  }

  .link--cta:active {
    color: var(--primary-foreground-active);
  }

  /* ── Breadcrumb ───────────────────────────────────────────────────────────
   Shows the current page's place in the hierarchy. Use on deep pages so users
   can step back up; skip it at the top level. Last crumb is the current page
   (aria-current), not a link.

   Structure:
   <nav class="breadcrumb" aria-label="Breadcrumb">
     <ol class="breadcrumb__list">
       <li class="breadcrumb__item"><a class="breadcrumb__link" href="#">Home</a></li>
       <li class="breadcrumb__item">
         <span class="breadcrumb__current" aria-current="page">Details</span>
       </li>
     </ol>
   </nav> */
  .breadcrumb__list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--font-body-small-size);
  }

  .breadcrumb__item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
  }

  .breadcrumb__item:not(:first-child)::before {
    content: "";
    width: 1em;
    height: 1em;
    background: var(--ink-tertiary);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6l-6 6'/%3E%3C/svg%3E")
      center / contain no-repeat;
  }

  .breadcrumb__link {
    display: inline-flex;
    align-items: center;
    color: var(--ink-primary);
    text-decoration: none;
    border-radius: 4px;
    transition: color var(--motion-default);
  }

  @media (hover: hover) and (pointer: fine) {
    .breadcrumb__link:hover {
      text-decoration: underline;
    }
  }

  .breadcrumb__current {
    color: var(--ink-secondary);
  }

  /* ── Navigation Menu ───────────────────────────────────────────────────────
   Primary navigation between destinations, e.g. in a header. Unlike Tabs (which
   swap panels within one page), each item is a link to another page, marked
   with aria-current="page". Fixed-height pills with a hover surface and nothing
   else: no pressed state (a link navigates away rather than toggling, and the
   panel links and menu rows are hover-only too) and no fill for the current
   page. Only the keyboard focus ring is added.

   Optional dropdown: give an item a .nav-menu__menu panel and it reveals on
   hover or keyboard focus. The item's own link stays clickable (link-first, no
   chevron); the panel is an extra affordance, not a gate. Items without a panel
   stay plain links. CSS-only; no JS.

   Structure:
   <nav class="nav-menu" aria-label="Main">
     <ul class="nav-menu__list">
       <li class="nav-menu__item">
         <a class="nav-menu__link" href="#" aria-current="page">Overview</a>
         <div class="nav-menu__menu">
           <a class="nav-menu__menu-link" href="#">Dashboard</a>
           <a class="nav-menu__menu-link" href="#">Activity</a>
         </div>
       </li>
       <li class="nav-menu__item"><a class="nav-menu__link" href="#">Reports</a></li>
     </ul>
   </nav> */
  .nav-menu__list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* Fixed-height pill. The height is set rather than left to padding +
   line-height, so every link in a bar is the same box whatever the type metrics
   do; --nav-link-size / --nav-link-px are the two knobs, like the button's. */
  .nav-menu__link {
    --nav-link-size: 48px;
    --nav-link-px: 20px;

    display: inline-flex;
    align-items: center;
    height: var(--nav-link-size);
    padding-inline: var(--nav-link-px);
    border-radius: var(--radius-full);
    font-size: var(--font-body-medium-size);
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink-primary);
    text-decoration: none;
    transition: background var(--motion-default);
  }

  /* Driven off the ITEM, not the link. The panel's 4px hover bridge (::before,
   below) slides across the link's bottom edge while the panel animates open or
   closed, which steals :hover from the link and flickers the surface off and
   back. Hovering anywhere in the item also keeps the trigger marked while its
   panel is open, which is what you want. For an item with no panel this is the
   same box as the link. */
  @media (hover: hover) and (pointer: fine) {
    .nav-menu__item:hover > .nav-menu__link {
      background: var(--background-secondary-hover);
    }
  }

  /* Item wraps the link + its optional dropdown; the panel anchors to it. */
  .nav-menu__item {
    position: relative;
  }

  /* Dropdown panel. Reuses the Popover floating surface (secondary bg + shadow +
   rim), revealed on the item's :hover / :focus-within. */
  .nav-menu__menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;

    /* Size to the longest row; never narrower than the trigger it hangs under. */
    width: max-content;
    min-width: 100%;
    max-width: 16rem;
    margin-top: 4px;
    padding: 4px;

    /* Concentric with 8px rows: surface = row radius + 4px padding. */
    border-radius: calc(var(--radius-sm) + 4px);
    background: var(--background-secondary);
    color: var(--ink-primary);
    box-shadow: var(--shadow-md), var(--surface-rim);

    /* Closed by default. visibility keeps the links out of the tab order while
     hidden; on the open rule it flips instantly so tabbing into the item can
     still enter them, while opacity/transform animate. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition:
      opacity 0.15s ease-out,
      transform 0.15s ease-out,
      visibility 0s linear 0.15s;
  }

  /* Bridge the 4px gap so the pointer never crosses a dead zone travelling from
   the link down into the panel (which would drop the hover and close it). */
  .nav-menu__menu::before {
    content: "";
    position: absolute;
    inset-inline: 0;
    bottom: 100%;
    height: 4px;
  }

  .nav-menu__item:hover .nav-menu__menu,
  .nav-menu__item:focus-within .nav-menu__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition:
      opacity 0.15s ease-out,
      transform 0.15s ease-out;
  }

  /* Esc (see initNavMenus) force-closes an open panel even while focus stays on the
   trigger, which :focus-within would otherwise keep open. Cleared on pointer re-enter
   or when focus leaves the item, so the next hover/focus reopens it. Same specificity
   as the open rule above, so source order wins. */
  .nav-menu__item[data-collapsed] .nav-menu__menu {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
  }

  .nav-menu__menu-link {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-body-small-size);
    font-weight: 500;
    line-height: 1.3;
    color: var(--ink-primary);
    text-decoration: none;
  }

  @media (hover: hover) and (pointer: fine) {
    .nav-menu__menu-link:hover {
      background: var(--background-secondary-hover);
    }
  }

  /* ── Avatar ────────────────────────────────────────────────────────────── */

  /* A user's image, with initials (or a glyph) as the fallback when no image is
   set. Overlap several in an .avatar-group.

   The media (img / glyph) clips itself rather than the .avatar, so a status dot
   can sit on the edge without being masked. Background is an opaque gray (not an
   alpha fill) so overlapping avatars in a group don't bleed through each other.

   Structure:
   <span class="avatar"><img class="avatar__img" src="…" alt="Ada Lovelace" /></span>
   <span class="avatar"><span class="avatar__fallback">AL</span></span> */
  .avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--neutral-gray-3);
    color: var(--ink-secondary);
    font-size: var(--font-body-small-size);
    font-weight: 600;
    -webkit-user-select: none;
    user-select: none;
  }

  .avatar--sm {
    width: 32px;
    height: 32px;
    font-size: var(--font-caption-medium-size);
  }

  .avatar--lg {
    width: 56px;
    height: 56px;
    font-size: var(--font-body-large-size);
  }

  .avatar__img {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
  }

  /* Fills the avatar and clips the glyph to the circle (the .avatar itself no
   longer clips, so the status dot can overflow the edge). */
  .avatar__fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: inherit;
  }

  .avatar__fallback svg {
    width: 50%;
    height: 50%;
  }

  /* Presence dot sitting on the lower edge; the ring punches it out of the
   surface behind. */
  .avatar__status {
    position: absolute;
    inset-inline-end: 1%;
    inset-block-end: 1%;
    width: 28%;
    height: 28%;
    border-radius: var(--radius-full);
    background: var(--green);
    box-shadow: 0 0 0 2px var(--background-secondary);
  }

  /* Overlapping stack: a ring separates neighbours; later avatars sit on top.
   The ring matches the surface behind (elevated --background-secondary), so it
   reads as a seamless gap rather than a visible border. */
  .avatar-group {
    display: inline-flex;
  }

  .avatar-group .avatar {
    box-shadow: 0 0 0 2px var(--background-secondary);
  }

  .avatar-group .avatar + .avatar {
    margin-inline-start: -0.75rem;
  }

  /* Overflow count ("+3") reads a touch smaller than initials. */
  .avatar--count {
    font-size: var(--font-caption-medium-size);
  }

  /* ── Pagination ────────────────────────────────────────────────────────── */

  /* Numbered page navigation. app.js (initPagination) renders a bounded window
   (first + last always shown, the current page ±1, ellipses bridging the gaps)
   from a data-total / data-page seed, and keeps it interactive. The current
   page carries aria-current="page"; the icon-only prev/next carry an aria-label.

   Structure:
   <nav class="pagination" data-pagination data-total="12" data-page="1"
        aria-label="Pagination"></nav> */
  .pagination__list {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .pagination__link {
    /* Tapped in sequence to walk pages. */
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 0.5rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-body-small-size);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--motion-default);
  }

  @media (hover: hover) and (pointer: fine) {
    .pagination__link:hover {
      background: var(--background-secondary-hover);
    }
  }

  /* No offset: the ring sits flush so it isn't clipped by the adjacent buttons. */
  .pagination__link:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
  }

  /* Active page reads as a solid primary chip. It's the current page, not a
   navigation target, so no hover feedback (the :hover pairing just re-asserts the
   chip so it never picks up the grey row hover) and the cursor stays default. */
  .pagination__link[aria-current="page"],
  .pagination__link[aria-current="page"]:hover {
    background: var(--primary);
    color: var(--neutral-white);
    font-weight: 500;
    cursor: default;
  }

  .pagination__link:disabled {
    color: var(--ink-tertiary);
    cursor: not-allowed;
  }

  @media (hover: hover) and (pointer: fine) {
    .pagination__link:disabled:hover {
      background: transparent;
    }
  }

  .pagination__link svg {
    width: 20px;
    height: 20px;
  }

  .pagination__ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;

    /* Signals skipped pages, so ink-secondary for AA (tertiary fails at 3.4:1 in light). */
    color: var(--ink-secondary);
  }

  /* ── Slider ────────────────────────────────────────────────────────────── */

  /* Native <input type="range"> with appearance:none, keyboard, step, and
   min/max come for free. Track + thumb are themed for both engines
   (::-webkit-slider-* and ::-moz-range-*).

   The track fills up to the thumb: Firefox has ::-moz-range-progress natively;
   WebKit/Chrome have no equivalent, so app.js (initSliders) tracks the value in
   --slider-fill and a hard-stop gradient paints the filled portion.

   Structure:
   <input class="slider" type="range" min="0" max="100" value="50" /> */
  .slider {
    --slider-fill: 0%;

    appearance: none;
    width: 100%;
    max-width: 320px;
    height: 28px;
    background: transparent;
    cursor: pointer;
  }

  /* Ring lives on the thumb only (below); suppress the element-level ring so the
   whole bar doesn't also outline. */
  .slider:focus-visible {
    outline: none;
  }

  .slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: var(--radius-full);
    background: linear-gradient(
      to right,
      var(--primary-foreground) var(--slider-fill),
      var(--fill-tertiary) var(--slider-fill)
    );
  }

  .slider::-moz-range-track {
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--fill-tertiary);
  }

  .slider::-moz-range-progress {
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--primary-foreground);
  }

  .slider::-webkit-slider-thumb {
    appearance: none;
    width: 28px;
    height: 28px;

    /* Centre the 28px thumb on the 6px track: (28 − 6) / 2 = 11px. */
    margin-top: -11px;
    border: 2px solid var(--background-secondary);
    border-radius: var(--radius-full);
    background: var(--primary-foreground);
    box-shadow: var(--shadow-sm);
  }

  .slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border: 2px solid var(--background-secondary);
    border-radius: var(--radius-full);
    background: var(--primary-foreground);
    box-shadow: var(--shadow-sm);
  }

  .slider:focus-visible::-webkit-slider-thumb {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
    animation: focus-ring-converge var(--motion-default);
  }

  .slider:focus-visible::-moz-range-thumb {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
    animation: focus-ring-converge var(--motion-default);
  }

  .slider:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  /* Optional wrapper: a label on the inline-start and a live value on the
   inline-end, above the track. app.js (initSliders) keeps the <output> in sync.

   Structure:
   <div class="slider-field">
     <div class="slider-field__header">
       <label class="slider-field__label" for="x">Volume</label>
       <output class="slider-field__value" for="x">50</output>
     </div>
     <input class="slider" type="range" id="x" min="0" max="100" value="50" />
   </div> */
  .slider-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    max-width: 320px;
  }

  .slider-field__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    font-size: var(--font-body-small-size);
  }

  .slider-field__label {
    color: var(--ink-primary);
  }

  .slider-field__value {
    color: var(--ink-secondary);
    font-variant-numeric: tabular-nums;
  }

  /* Dim the label + value alongside a disabled track. */
  .slider-field:has(.slider:disabled) .slider-field__label,
  .slider-field:has(.slider:disabled) .slider-field__value {
    opacity: 0.5;
  }

  /* ── Slider range ──────────────────────────────────────────────────────── */

  /* Two-handle range: two native <input type="range"> stacked on one track, so
   each thumb keeps native keyboard, touch and screen-reader behaviour and only
   the "handles can't cross" rule is ours (app.js, initSliderRanges).

   Why stacked natives rather than a custom control: a div-based range means
   re-implementing role="slider" twice, aria-valuemin/max/now, and arrow/Home/End
   on both thumbs. Natives give all of that, and each input keeps its own
   accessible name, so a screen reader reads "Minimum" and "Maximum" rather than
   two unlabelled numbers.

   The inputs are transparent and pointer-transparent EXCEPT their thumbs, so a
   drag lands on the thumb you grabbed and a click on the bare track doesn't jump
   the wrong handle. The track and the filled middle are painted on the wrapper
   from --slider-range-from/--slider-range-to, both set by the script as 0-1
   ratios.

   The two inputs travel sub-tracks a thumb short of the bar, offset from each
   other by that thumb (see .slider-range__input), so equal values put the
   handles edge to edge instead of one on top of the other. Nothing has to raise
   a buried thumb, because there isn't one.

   Structure:
   <div class="slider-range" data-slider-range>
     <input class="slider-range__input" type="range" min="0" max="100" value="20"
            aria-label="Minimum" />
     <input class="slider-range__input" type="range" min="0" max="100" value="80"
            aria-label="Maximum" />
   </div> */
  .slider-range {
    /* Handle positions as 0-1 ratios, not percentages: the stops below have to
     do arithmetic with them (see --slider-range-thumb). Set by the script. */
    --slider-range-from: 0;
    --slider-range-to: 1;
    --slider-range-thumb: 28px;

    position: relative;
    width: 100%;
    max-width: 320px;
    height: var(--slider-range-thumb);
  }

  /* The track, and the filled segment between the handles, on one gradient: two
   hard stops, so there's no third element to keep in sync.

   The stops are where the thumb CENTRES sit, which is not the plain ratio: each
   input owns a sub-track one thumb short of the full width (below), so a centre
   travels from half a thumb in to half a thumb short of that sub-track's end.
   The upper handle's sub-track starts one thumb further along, hence its extra
   offset, and that offset is exactly what keeps the two handles edge to edge
   instead of stacked when they hold the same value. */
  .slider-range::before {
    --slider-range-half: calc(var(--slider-range-thumb) / 2);
    --slider-range-span: calc(100% - var(--slider-range-thumb) * 2);
    --slider-range-low: calc(
      var(--slider-range-half) + var(--slider-range-span) * var(--slider-range-from)
    );
    --slider-range-high: calc(
      var(--slider-range-half) + var(--slider-range-thumb) + var(--slider-range-span) *
        var(--slider-range-to)
    );

    content: "";
    position: absolute;
    top: 50%;
    inset-inline: 0;
    height: 6px;
    border-radius: var(--radius-full);
    translate: 0 -50%;
    background: linear-gradient(
      to right,
      var(--fill-tertiary) var(--slider-range-low),
      var(--primary-foreground) var(--slider-range-low),
      var(--primary-foreground) var(--slider-range-high),
      var(--fill-tertiary) var(--slider-range-high)
    );
  }

  /* Each input is inset by a thumb width at one end, so its thumb travels a
   sub-track rather than the whole bar: the lower one stops a thumb short of the
   right edge, the upper one starts a thumb in from the left. Two equal values
   then land the thumbs exactly one thumb apart, touching rather than stacked,
   and neither input's reported value changes: only where its own track begins
   and ends. */
  .slider-range__input {
    position: absolute;
    inset-block: 0;
    inset-inline: 0 var(--slider-range-thumb);
    height: var(--slider-range-thumb);
    margin: 0;
    appearance: none;
    background: transparent;

    /* The input is a click-through overlay; only its thumb takes the pointer, so
     the two stacked inputs never steal each other's drags. */
    pointer-events: none;
  }

  .slider-range__input:focus-visible {
    outline: none;
  }

  /* Tracks stay invisible: the wrapper paints the one both handles ride on. */
  .slider-range__input::-webkit-slider-runnable-track {
    height: 6px;
    background: transparent;
  }

  .slider-range__input::-moz-range-track {
    height: 6px;
    background: transparent;
  }

  .slider-range__input:last-of-type {
    inset-inline: var(--slider-range-thumb) 0;
  }

  .slider-range__input::-webkit-slider-thumb {
    appearance: none;
    width: var(--slider-range-thumb);
    height: var(--slider-range-thumb);

    /* Centre the thumb on the 6px track: (28 − 6) / 2 = 11px. */
    margin-top: -11px;
    border: 2px solid var(--background-secondary);
    border-radius: var(--radius-full);
    background: var(--primary-foreground);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    pointer-events: auto;
  }

  .slider-range__input::-moz-range-thumb {
    width: var(--slider-range-thumb);
    height: var(--slider-range-thumb);
    border: 2px solid var(--background-secondary);
    border-radius: var(--radius-full);
    background: var(--primary-foreground);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    pointer-events: auto;
  }

  .slider-range__input:active::-webkit-slider-thumb {
    cursor: grabbing;
  }

  .slider-range__input:active::-moz-range-thumb {
    cursor: grabbing;
  }

  .slider-range__input:focus-visible::-webkit-slider-thumb {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
    animation: focus-ring-converge var(--motion-default);
  }

  .slider-range__input:focus-visible::-moz-range-thumb {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
    animation: focus-ring-converge var(--motion-default);
  }

  .slider-range:has(:disabled) {
    cursor: not-allowed;
    opacity: 0.5;
  }

  /* ── Combobox ──────────────────────────────────────────────────────────── */

  /* A text field that filters a listbox: Select with type-to-filter. Reuses the
   Input shell for the field and the Select popup (.select__list / .select__option)
   for the menu, so only the wrapper, the chevron, and the "no results" row are
   new here. JS (initComboboxes) owns filtering + the keyboard model.

   <div class="combobox" data-combobox>
     <div class="input__container combobox__control">
       <input class="input__element" type="text" role="combobox"
              aria-expanded="false" aria-autocomplete="list" aria-controls="cb-list" />
       <span class="input__trailing combobox__chevron" aria-hidden="true"><svg…></span>
     </div>
     <ul class="select__list" id="cb-list" role="listbox" tabindex="-1" hidden>
       <li class="select__option" role="option">…</li>
       <li class="combobox__empty" hidden>No results</li>
     </ul>
   </div> */
  .combobox {
    position: relative;

    /* When focus scrolls the field toward the top (mobile), leave room for the
     sticky nav so it isn't tucked behind it. */
    scroll-margin-top: calc(var(--nav-h, 56px) + 0.75rem);
  }

  /* The control is a shared .input__container (inline-flex, shrinks to content).
   Stretch it to the combobox width so it lines up with the full-width dropdown. */
  .combobox__control {
    width: 100%;
  }

  /* Options set display:flex, which beats the [hidden] UA rule, so the JS
   filter's option.hidden = true wouldn't actually hide the row without this. */
  .select__option[hidden] {
    display: none;
  }

  .combobox__chevron {
    transition: rotate var(--motion-default);
  }

  .combobox__chevron svg {
    width: 1.25em;
    height: 1.25em;
    color: var(--ink-secondary);
  }

  /* Flip the chevron while the listbox is open (aria-expanded lives on the input). */
  .combobox:has([role="combobox"][aria-expanded="true"]) .combobox__chevron {
    rotate: 180deg;
  }

  /* "No results" row, shown by JS when the filter matches nothing. */
  .combobox__empty {
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    font-size: var(--font-body-small-size);
    color: var(--ink-secondary);
  }

  .combobox__empty[hidden] {
    display: none;
  }

  /* ── Empty state ───────────────────────────────────────────────────────── */

  /* Centred placeholder for "no results" / "nothing here yet". The icon badge
   reuses the primary-soft recipe (same as the Card / settings icon); actions are
   ordinary Buttons.

   <div class="empty">
     <span class="empty__icon" aria-hidden="true"><svg…></span>
     <h3 class="empty__title">No results</h3>
     <p class="empty__text">…</p>
     <div class="empty__actions"><button class="button …">…</button></div>
   </div> */
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    max-width: 22rem;
    margin-inline: auto;
    padding: 2rem 1rem;
  }

  .empty__icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary-foreground);
  }

  .empty__icon svg {
    width: 24px;
    height: 24px;
  }

  .empty__title {
    margin: 0;
    font-size: var(--font-body-large-emphasized-size);
    line-height: var(--font-body-large-emphasized-lh);
    font-weight: var(--font-body-large-emphasized-weight);
    color: var(--ink-primary);
  }

  .empty__text {
    margin: 0;
    font-size: var(--font-body-small-size);
    line-height: var(--font-body-small-lh);
    font-weight: var(--font-body-small-weight);
    color: var(--ink-secondary);
  }

  .empty__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
  }

  /* ── Separator ─────────────────────────────────────────────────────────── */

  /* A hairline rule between content. Horizontal is semantic:
       <hr class="separator" />
   Vertical goes in a flex row and needs the role, since <hr> can't be vertical:
       <div class="separator separator--vertical" role="separator"
            aria-orientation="vertical"></div> */
  .separator {
    flex-shrink: 0;
    width: 100%;
    height: 1px;
    margin: 0;
    border: 0;
    background: var(--fill-tertiary);
  }

  .separator--vertical {
    width: 1px;
    height: auto;
    align-self: stretch;
  }

  /* ── Calendar ──────────────────────────────────────────────────────────── */

  /* A month grid for choosing a date. JS (initCalendars) fills [data-cal-days]
   with day buttons, populates the month/year selects, and wires nav + keyboard
   (arrows, Home/End, PageUp/Dn). Capped at 31 Dec of the current year. Drop it in
   a Popover with data-cal-target="#field" for a date picker.

   <div class="calendar" data-calendar data-cal-value="2026-08-12">
     <div class="calendar__head">
       <button class="calendar__nav" data-cal-prev>‹</button>
       <div class="calendar__period">
         <span class="calendar__select"><select data-cal-month></select></span>
         <span class="calendar__select"><select data-cal-year></select></span>
       </div>
       <button class="calendar__nav" data-cal-next>›</button>
     </div>
     <div class="calendar__weekdays" aria-hidden="true">…</div>
     <div class="calendar__days" data-cal-days></div>
   </div> */
  .calendar {
    width: max-content;
    padding: var(--space-8);
    background: var(--background-secondary);
    border: var(--border-width) solid var(--fill-tertiary);
    border-radius: var(--radius-md);

    /* It's a control, not a document: no text I-beam over day/weekday labels,
       and no drag-selecting the numbers. */
    -webkit-user-select: none;
    user-select: none;
  }

  /* Inside a Popover the popover is the surface: drop the border, and go
   transparent so the popover's shadow + light rim (top/sides in dark) show
   instead of being painted over by the calendar's own background. */
  .popover .calendar {
    border: 0;
    background: transparent;
  }

  .calendar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
  }

  /* Month + year native <select>s. Compact and borderless (no 48px field shell),
   with a custom chevron; the platform keeps the dropdown + keyboard. */
  .calendar__period {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;

    /* DOM/tab order is prev, next, month, year; order keeps the
     visual as prev, month/year, next (see .calendar__nav + .calendar__nav). */
    order: 1;
  }

  .calendar__select {
    position: relative;
    display: inline-flex;
    align-items: center;
  }

  .calendar__select select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0.25rem 1.5rem 0.25rem 0.5rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    cursor: pointer;
  }

  @media (hover: hover) and (pointer: fine) {
    .calendar__select select:hover {
      background: var(--background-secondary-hover);
    }
  }

  /* Surface stays pointer-driven (hover only). Native selects match
   :focus-visible on click too, so a ring would flash on open and a focus fill
   would linger after the dropdown closes, so focus carries neither here. */
  .calendar__select select:focus-visible {
    outline: none;
  }

  /* Chevron: ink-secondary; dims further when disabled. */
  .calendar__select::after {
    content: "";
    position: absolute;
    right: 0.375rem;
    top: 50%;
    translate: 0 -50%;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    color: var(--ink-secondary);
    background: currentcolor;
    mask: var(--icon-chevron-down) center / contain no-repeat;
  }

  .calendar__select:has(select:disabled)::after {
    color: var(--ink-tertiary);
  }

  .calendar__nav {
    /* Held down to page through months. */
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    cursor: pointer;
  }

  .calendar__nav:disabled {
    color: var(--ink-tertiary);
    cursor: not-allowed;
  }

  .calendar__nav svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  @media (hover: hover) and (pointer: fine) {
    .calendar__nav:hover {
      background: var(--background-secondary-hover);
    }
  }

  .calendar__nav:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* The next button (second consecutive nav) sits visually on the right even
   though it comes second in the DOM/tab order (prev, next, month, year). */
  .calendar__nav + .calendar__nav {
    order: 2;
  }

  /* The month is a role="grid" of role="row"s (weekday columnheaders + week rows).
   Rows are real grids (not display:contents): a role="row" with display:contents
   gets dropped from the a11y tree in Safari/VoiceOver, malforming the grid so it
   reads cells linearly. Each row lays out its own 7 columns; the grid just stacks
   them. Visually identical to one 7-column grid with 2px gaps. */
  .calendar__days {
    display: grid;
    gap: 2px;
  }

  .calendar__weekdays,
  .calendar__week {
    display: grid;
    grid-template-columns: repeat(7, 2rem);
    gap: 2px;
  }

  /* gridcell wrapper around each day button (the button is the focusable, the
   cell is grid structure); it's the 2rem grid track holding the 2rem button. */
  .calendar__cell {
    display: grid;
    place-items: center;
  }

  .calendar__weekday {
    display: grid;
    place-items: center;
    height: 1.75rem;
    font-size: var(--font-caption-medium-size);

    /* Column headers are read, so ink-secondary to clear AA (tertiary fails at 3.4:1 in light). */
    color: var(--ink-secondary);
  }

  .calendar__day {
    /* Two taps in a row land on neighbouring days often enough to zoom. */
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-primary);
    font: inherit;
    font-size: var(--font-caption-medium-size);
    cursor: pointer;
  }

  @media (hover: hover) and (pointer: fine) {
    .calendar__day:not(.is-selected, .is-outside):hover {
      background: var(--background-secondary-hover);
    }
  }

  /* Day cells sit tight in the grid, so the ring hugs them (no offset) and skips
   the global converge animation (no pulse). */
  .calendar__day:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: 0;
    animation: none;
  }

  /* Neighbouring-month days read quieter and are inert (rendered as non-button
     divs, aria-hidden), so a faint fill tint is fine: WCAG exempts inactive text. */
  .calendar__day.is-outside {
    color: var(--fill-primary);
    cursor: default;
  }

  /* Out-of-range leading cells: hold the column, show and do nothing. */
  .calendar__day.is-empty {
    visibility: hidden;
  }

  /* Today wears the hover surface at rest; the selected day is filled (and wins
   over today's surface since it's declared later). */
  .calendar__day.is-today {
    background: var(--background-secondary-hover);
  }

  .calendar__day.is-selected {
    background: var(--primary-foreground);
    color: var(--background-secondary);
    font-weight: 500;
  }

  /* Range calendar (Date range). Kept in the Calendar banner above so Copy CSS
   pulls the whole calendar family in one go.
   Two months side by side (stacking to one column when cramped) for picking a
   start + end date. initDateRanges drives it; markup degrades to two static
   month grids. The endpoints match the single calendar's selected day (neutral,
   accent only inside a data-color region) and the days between wear a soft band
   drawn on the gridcell, bridged across the 2px column gaps with a left box-shadow
   so it reads continuous. */
  .calendar__months {
    display: flex;
    flex-direction: column;
    gap: var(--space-16);
  }

  @media (min-width: 640px) {
    .calendar--range .calendar__months {
      flex-direction: row;
    }
  }

  .calendar__month {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* prev/label/next row per month; a spacer opposite the nav keeps the label
   optically centred (prev is on the first month, next on the second). */
  .calendar__caption {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2rem;
  }

  .calendar__caption-label {
    flex: 1;
    text-align: center;
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    color: var(--ink-primary);
  }

  .calendar__nav-spacer {
    width: 2rem;
    flex: none;
  }

  /* Soft band on every day in the range (endpoints included). is-range sits on the
   gridcell; each week row becomes one rounded pill, capped where the range starts/
   ends or where it meets the week edge, so a multi-week range reads as one pill per
   row. The band is --accent-soft (the same soft surface as a secondary button), so
   it's the brand tint by default, flips per theme, and retints inside a data-color
   region for free. Endpoints stay on the solid --primary-foreground. */
  .calendar__cell.is-range {
    background: var(--accent-soft);
  }

  /* Bridge the 2px column gap, but only between two adjacent in-range cells
   (mid-band) so a cap never bleeds into the gap. */
  .is-range + .calendar__cell.is-range {
    box-shadow: -2px 0 0 0 var(--accent-soft);
  }

  /* Left cap: first in-range cell of a row (range start, or a week that opens
   mid-range). Right cap: last in-range cell of a row (range end, or a week that
   runs to its edge). */
  .calendar__week > .calendar__cell.is-range:first-child,
  .calendar__week > :not(.is-range) + .calendar__cell.is-range {
    border-start-start-radius: var(--radius-sm);
    border-end-start-radius: var(--radius-sm);
  }

  .calendar__week > .calendar__cell.is-range:last-child,
  .calendar__week > .calendar__cell.is-range:has(+ :not(.is-range)) {
    border-start-end-radius: var(--radius-sm);
    border-end-end-radius: var(--radius-sm);
  }

  .calendar__day.is-range-start,
  .calendar__day.is-range-end {
    background: var(--primary-foreground);
    color: var(--background-secondary);
    font-weight: 500;
  }

  /* Keep endpoints filled on hover (the generic day-hover surface would otherwise
   paint over them). */
  @media (hover: hover) and (pointer: fine) {
    .calendar__day.is-range-start:hover,
    .calendar__day.is-range-end:hover {
      background: var(--primary-foreground);
    }
  }

  /* The soft band already retints per region (it rides --accent-soft). The solid
   endpoints + the single calendar's selected day are on --primary-foreground, so
   pull them onto --accent inside a data-color region to match. (In a neutral region
   --accent resolves back to neutral ink, so it stays neutral there.) */
  [data-color] .calendar__day.is-selected,
  [data-color] .calendar__day.is-range-start,
  [data-color] .calendar__day.is-range-end {
    background: var(--accent);
    color: var(--accent-on);
  }

  @media (hover: hover) and (pointer: fine) {
    [data-color] .calendar__day.is-range-start:hover,
    [data-color] .calendar__day.is-range-end:hover {
      background: var(--accent);
    }
  }

  /* Calendar in a Popover = date picker. The popover is just the surface (shadow
   + rounding); the calendar fills it edge to edge, so drop the popover padding. */
  .popover--calendar {
    padding: 0;
    border-radius: var(--radius-md);
  }

  /* Range footer: a full-bleed divider (negative margins cancel the calendar's own
   padding so the line runs edge to edge), Clear on the left, Cancel + Apply on the
   right. Wrap it in data-size="xs" in the markup to scale the buttons down. */
  .calendar__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: var(--space-8) calc(-1 * var(--space-8)) calc(-1 * var(--space-8));
    padding: var(--space-8);
    border-top: var(--border-width) solid var(--fill-tertiary);
  }

  .calendar__footer-actions {
    display: flex;
    gap: 0.5rem;
  }

  /* Clear is a low-priority action, so soften its flat states one tier below the
   default (--accent-soft, 0.23/0.27 which reads heavy in neutral grey) to the
   quaternary tier: hover 0.17, active 0.21. */
  @media (hover: hover) and (pointer: fine) {
    .calendar__footer .button--flat:not(:disabled):hover {
      background: var(--fill-quaternary-hover);
    }
  }

  .calendar__footer .button--flat:not(:disabled):active {
    background: var(--fill-quaternary-active);
  }

  /* ── Number field ──────────────────────────────────────────────────────── */

  /* An <input> flanked by −/+ steppers: type a value directly or step it. Built on
   the Input field, so it inherits the label/hint/error slots and the focus border.
   JS (initNumberFields) reads min/max/step off the input, steps on click and
   Arrow Up/Down, press-and-hold repeats, clamps on blur, and disables a stepper
   once its bound is reached.

   Bounds live in data-min / data-max / data-step on the input: min/max/step
   aren't valid attributes on a type=text input.

   The label is a sibling with `for`, not a wrapper: a <label> wrapping the input
   *and* the two steppers is a label for three controls.

   <div class="input number-field" data-number-field>
     <label class="input__label" for="qty">Quantity</label>
     <span class="input__container number-field__control">
       <button class="number-field__step" type="button" data-step="-1" aria-label="Decrease">−</button>
       <input class="input__element number-field__input" id="qty" type="text" inputmode="numeric"
              value="1" data-min="0" data-max="10" data-step="1" />
       <button class="number-field__step" type="button" data-step="1" aria-label="Increase">+</button>
     </span>
   </div> */

  /* Size scale, one number per size: --number-field-size is the field's outer
   height, and a stepper is that less the two borders, which makes the strip square
   (38 on the default 40 field) so the surface inside it can sit the same distance
   from every edge.

   The corner is the Input's, so the field matches the ones beside it in a form; a
   page that puts it in a row of pill buttons rounds it there (see the product
   page). */
  .number-field__control {
    min-height: var(--number-field-size);
    padding: 0;
  }

  /* A stepper doesn't light the whole field. The field's border says "text goes
   here", and the trigger it inherits from Input is :focus-within, which any of
   the three controls satisfies, so pressing + or − lit the field as though the
   value were being typed. Only the value cell brings it back; a stepper shows its
   own round ring inside its circle, which is its focus indicator. */
  .number-field__control:focus-within:not(:has(.number-field__input:focus)) {
    border-color: var(--ink-tertiary);
    box-shadow: none;
  }

  /* The stepper keeps the full strip as its hit area, but every state it shows is a
   32 box drawn inside that (::before below): nothing reaches the field's corners,
   it works as well on the pill as on a rectangle, and the target stays the whole
   strip rather than shrinking to the surface. There are no dividers between the
   three parts either: they are one control, and rules between them only chop it
   up. */
  .number-field__step {
    /* Repeat-tapping a stepper on a phone is the whole point of it, and two taps
     in the same spot is also the double-tap-zoom gesture, so counting up zoomed
     the page instead. Opting out also drops the ~300ms wait before the tap
     registers, the same as .button. */
    touch-action: manipulation;
    display: inline-flex;
    position: relative;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    align-self: stretch;
    width: calc(var(--number-field-size) - 2 * var(--border-width));
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink-primary);
    cursor: pointer;
  }

  /* 4 in from the strip on every side, rather than a fixed square: min-height is
   the field's outer size, so the strip inside its borders is 38 tall and 40 wide,
   and a square surface left 4 at the sides but 3 above and below. Insets keep the
   breathing room even at every size too, which is why there's nothing to restate
   for --sm and --lg.

   Rounded rather than a circle: it sits inside a field whose own corners are
   curved, and a squarer surface fills the strip instead of leaving a crescent of
   it above and below. Its corner is the field's less the inset, so the two curves
   stay parallel. */
  .number-field__step::before {
    content: "";
    position: absolute;
    inset: var(--space-4);
    border-radius: calc(var(--radius-sm) - var(--space-4));
    transition: background var(--motion-default);
  }

  /* Positioned, so the glyph paints over the circle behind it. */
  .number-field__step svg {
    position: relative;
    width: 20px;
    height: 20px;
  }

  /* Typing in the value is a text field like any other, so the field itself shows
   focus the way an Input does (the container's own :focus-within border, which is
   why nothing cancels it here). A stepper adds its own ring inside the circle, so
   which of the three has focus still reads. */
  .number-field__step:focus-visible {
    /* The transparent outline keeps a visible ring in forced colors; the ring
     itself is drawn on the circle. */
    outline: calc(var(--border-width) * 2) solid transparent;
    animation: none;
  }

  /* Inset via box-shadow so the ring follows the circle exactly (an inset outline
   shrinks its own radius and stops matching it). */
  .number-field__step:focus-visible::before {
    box-shadow: inset 0 0 0 calc(var(--border-width) * 2) var(--primary-foreground);
  }

  .number-field__step:disabled {
    color: var(--fill-secondary);
    cursor: not-allowed;
  }

  @media (hover: hover) and (pointer: fine) {
    .number-field__step:not(:disabled):hover::before {
      background: var(--fill-quaternary-hover);
    }
  }

  .number-field__step:not(:disabled):active::before {
    background: var(--fill-quaternary-active);
  }

  /* The field hugs its content rather than filling a fixed width. */
  .number-field {
    --number-field-size: 40px;

    width: fit-content;
  }

  .number-field--sm {
    --number-field-size: 32px;
  }

  .number-field--lg {
    --number-field-size: 48px;
  }

  /* Value reads centred, tabular so digits don't jitter. field-sizing lets it grow
   with the number (supported browsers); min-width keeps a button-width floor so it
   starts aligned, and a max-width stops runaway growth. */
  .number-field__input {
    flex: 0 1 auto;
    width: auto;

    /* Matches the field height so the value cell is a square minimum, like the
     steppers; it grows past this as digits are added. Padding leaves room for two
     digits, so growth kicks in at the third. */
    min-width: 2.5rem;
    max-width: 12ch;
    padding-inline: 0.5rem;
    field-sizing: content;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* Smaller 32px variant: tighter value floor and side padding. */
  .number-field--sm .number-field__input {
    min-width: 2rem;
    padding-inline: 0.25rem;
  }

  /* Larger 48px variant: body-medium text and a wider value floor. */
  .number-field--lg .number-field__input {
    min-width: 3rem;
    padding-inline: 0.75rem;
    font-size: var(--font-body-medium-size);
    line-height: var(--font-body-medium-lh);
  }

  /* ── Item ──────────────────────────────────────────────────────────────── */

  /* A compact horizontal row on an elevated surface: media + content
   (title/description) + actions. Where Card is a standalone surface, Item is the
   repeating line you stack into a list (settings, files, nav, results). Make the
   whole row a link/button by using <a class="item"> / <button class="item">. Stack
   rows in one .item-group surface, dividing them with .item-separator.

   <a class="item" href="…">
     <span class="item__media">…icon…</span>
     <span class="item__content">
       <span class="item__title">Getting started</span>
       <span class="item__description">Set up the project</span>
     </span>
     <span class="item__actions">…chevron…</span>
   </a> */
  .item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    background: var(--background-secondary);
    color: var(--ink-primary);
    text-decoration: none;
    transition: background var(--motion-default);
  }

  /* Recessed skin for a row sitting on a secondary (elevated) surface, where the
   default white row wouldn't read. Fills with the page's recessed background. */
  .item--muted {
    background: var(--background-primary);
  }

  /* Interactive rows (<a>/<button>) get hover/active surfaces and a focus ring. */
  @media (hover: hover) and (pointer: fine) {
    a.item:hover,
    button.item:hover {
      background: var(--background-secondary-hover);
    }
  }

  a.item:active,
  button.item:active {
    background: var(--background-secondary-active);
  }

  /* An interactive muted row stays in the recessed (background-primary) family on
   hover rather than jumping to the plain surface hover. */
  @media (hover: hover) and (pointer: fine) {
    a.item--muted:hover,
    button.item--muted:hover {
      background: var(--background-primary-hover);
    }
  }

  a.item--muted:active,
  button.item--muted:active {
    background: var(--background-primary-active);
  }

  a.item:focus-visible,
  button.item:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* Leading slot. The icon circle takes its tint from inline soft/accent vars. */
  .item__media {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
  }

  .item__media svg {
    width: 24px;
    height: 24px;
  }

  /* Smaller media for denser rows (e.g. grouped lists). */
  .item__media--sm {
    width: 32px;
    height: 32px;
  }

  .item__media--sm svg {
    width: 20px;
    height: 20px;
  }

  /* Title + optional description, taking the free space. */
  .item__content {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
  }

  .item__title {
    margin: 0; /* reset in case the slot is a heading/<p> rather than a span */
    font-size: var(--font-body-small-emphasized-size);
    font-weight: var(--font-body-small-emphasized-weight);
    color: var(--ink-primary);
  }

  /* Secondary line, so ink-secondary (not tertiary) to clear AA in light. */
  .item__description {
    margin: 0;
    font-size: var(--font-body-small-size);
    color: var(--ink-secondary);
  }

  /* Trailing controls (button, chevron); ink-tertiary tints a bare chevron. */
  .item__actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink-tertiary);
  }

  .item__actions svg {
    width: 20px;
    height: 20px;
  }

  /* A bare trailing chevron (direct svg, not a button) is nudged past the padding
   so its visible stroke optically lands on the content edge, iOS-style. */
  .item__actions > svg {
    margin-right: -4px;
  }

  /* Roomier row where the description spans the full width on a second line,
   below both the media and the trailing chevron (not tucked under the title).
   Switches to a grid and promotes .item__content's children into it with
   display:contents, so the same markup as a plain .item works unchanged. */
  .item--block {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px 12px;
    padding: 24px;
  }

  .item--block .item__content {
    display: contents;
  }

  .item--block .item__title {
    grid-column: 2;
    grid-row: 1;
    font-size: var(--font-body-medium-emphasized-size);
    line-height: var(--font-body-medium-emphasized-lh);
    font-weight: var(--font-body-medium-emphasized-weight);
  }

  .item--block .item__actions {
    grid-column: 3;
    grid-row: 1;
  }

  .item--block .item__description {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  /* Stack rows into one surface: the group owns the background and rounding, so
   nested rows go transparent and square, and .item-separator hairlines divide them. */
  .item-group {
    display: flex;
    overflow: hidden;
    flex-direction: column;
    border-radius: var(--radius-md);
    background: var(--background-secondary);
  }

  /* Denser rows in a list: 12px top/bottom with the 32px media gives a 56px row. */
  .item-group .item {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    border-radius: 0;
    background: transparent;
  }

  /* Inset to line up with the row text: left clears the padding + media + gap,
   right stops one padding-width in. (Media is the --sm 32px used in groups.) */
  .item-separator {
    height: var(--border-width);
    margin: 0 1rem 0 calc(1rem + 32px + 0.75rem);
    border: 0;
    background: var(--fill-tertiary);
  }

  /* ── Scroll area ───────────────────────────────────────────────────────── */

  /* A scroll container whose scrollbar is a real element rather than the
   platform's own, so it can be styled and revealed the way the rest of the
   system's affordances are: a pill thumb that fades in when the pointer is over
   the area (or while it's scrolling), darkens under the pointer, and darkens
   again while dragged.

   Why not just style the native bar: `::-webkit-scrollbar` gets you the shape,
   but scrollbars are composited separately and Chrome won't reliably repaint the
   thumb when the container's :hover flips, so reveal-on-hover fails
   intermittently and lingers after the pointer leaves. A DOM thumb is
   deterministic. The trade is that this needs JS (initScrollAreas in app.js) to
   size and place the thumb.

   The viewport stays a real scroll container, so keyboard scrolling, wheel and
   touch momentum, find-in-page and scroll anchoring all keep working, only the
   bar is ours. It needs no tabindex: the content's own focusable controls are
   reachable by tab, and focusing one scrolls it into view.

   Structure:
     <div class="scroll-area" data-scroll-area>
       <div class="scroll-area__viewport">…content…</div>
       <div class="scroll-area__bar" aria-hidden="true">
         <div class="scroll-area__thumb"></div>
       </div>
     </div>

   Give the VIEWPORT its height (max-height, height, or a flex context); the
   component doesn't assume one. */
  .scroll-area {
    position: relative;
  }

  /* No height here on purpose: the consumer sizes the VIEWPORT (max-height,
   height, or a flex/grid context). Setting height: 100% would resolve to auto
   against a parent that only has a max-height, and nothing would scroll. */
  .scroll-area__viewport {
    overflow-y: auto;

    /* Hide the platform bar; ours replaces it. */
    scrollbar-width: none;
  }

  .scroll-area__viewport::-webkit-scrollbar {
    display: none;
  }

  /* The bar reserves its own width via the viewport's padding (set by the
   consumer), not by taking layout space here: it's absolutely positioned, so
   revealing it never reflows the content. */
  .scroll-area__bar {
    position: absolute;
    z-index: 1;

    /* Inset from both ends so the thumb never runs into a rounded corner on the
     surface it sits over. The JS reads the bar's own height, so the track and
     thumb sizing follow this automatically. */
    top: 6px;
    bottom: 6px;

    /* 2 off the end edge too, so the pill isn't kissing the surface's side. */
    inset-inline-end: 2px;
    width: 10px;
    opacity: 0;
    transition: opacity var(--motion-default);
  }

  /* Revealed by pointer presence over the area, and while it's actually
   scrolling (JS sets is-scrolling), so a wheel or keyboard scroll shows the
   position even with the pointer elsewhere. Both are dropped when the content
   fits: JS marks the area [data-scrollable="false"] and the bar stays out. */
  @media (hover: hover) and (pointer: fine) {
    .scroll-area:hover > .scroll-area__bar {
      opacity: 1;
    }
  }

  .scroll-area.is-scrolling > .scroll-area__bar,
  .scroll-area.is-dragging > .scroll-area__bar {
    opacity: 1;
  }

  .scroll-area[data-scrollable="false"] > .scroll-area__bar {
    opacity: 0;
    pointer-events: none;
  }

  /* Top and height come from JS. The transparent border insets the pill: 2px
   each side leaves a 6px pill inside the full 10px grab target. */
  .scroll-area__thumb {
    position: absolute;
    inset-inline: 0;
    border: 2px solid transparent;
    border-radius: var(--radius-full);
    background: var(--fill-secondary);
    background-clip: content-box;
    cursor: default;
  }

  @media (hover: hover) and (pointer: fine) {
    .scroll-area__thumb:hover {
      background: var(--fill-primary);
      background-clip: content-box;
    }
  }

  .scroll-area.is-dragging .scroll-area__thumb {
    background: var(--ink-tertiary);
    background-clip: content-box;
  }

  /* Reduced motion: the fade is decoration, the thumb still appears. */
  @media (prefers-reduced-motion: reduce) {
    .scroll-area__bar {
      transition: none;
    }
  }

  /* ── Carousel ──────────────────────────────────────────────────────────── */

  /* A horizontal, snapping slider of items with prev/next controls. app.js
   (initCarousel) owns the position: it translates the track, drags it with the
   pointer (mouse and touch) with a rubber-band past the ends, settles on release
   (a drag past 30% of the viewport commits, so does a quick one of any length,
   and anything else comes back), wires the buttons + keyboard (←/→), disables a
   control at each end, and announces the current slide.

   --carousel-cols sets how many items show at once (default 1); --carousel-gap
   the space between them. The item flex-basis subtracts the gaps so N items fit
   exactly. Override the vars on the root (or per breakpoint) for a multi-up view.
   --carousel-slide times the settle, and app.js reads it from the root.

   Under a finger (hover:none and pointer:coarse) the viewport is a native scroll
   container with snap points instead, so the swipe is the platform's own momentum
   and rubber band rather than a reimplementation of them. The controls, the
   thumbnails, the status and carousel:goto all behave the same either way.

   The set has ends, always: prev disables on the first slide and next on the last,
   and .carousel__control:disabled is the greyed end state (the product page hides
   them there instead, since they're a hint over a photograph rather than chrome).
   There is no wrap. One was built and taken out again: a cycle means carrying the
   slide you've left round to the far side while it's off screen, which a scroll
   container can't do at all and a track of two can't do without a visible jump, so
   it also had to clone the set to make room. Two engines and a set that lies about
   its length, to save an end a thumbnail rail already tells you about.

   Any element inside the root with data-carousel-goto="<index>" jumps to that
   slide, and carries aria-current="true" while it's the current one — that's how
   a thumbnail rail or a row of dots hooks up, without its own JS. (React's
   <Carousel /> takes a `nav` render prop instead: there the current index is
   already state, so it is handed over rather than written onto the DOM.) The root also
   listens for a `carousel:goto` (detail: { index, animate }) from a page that has
   to move it — `animate: false` places the slide rather than sliding to it, which
   is what a reset wants.

   A set of one takes no drag at all: there is nowhere to go, so there is no
   resistance to feel and the press stays whatever the page made it (a link, a
   dialog, a photograph opening larger).

   Slides can be hidden ([hidden]) and the carousel sits them out: they're not
   counted, not landed on, and not stops. A page that shows or hides them, or
   turns the loop on or off, then fires `carousel:refresh` on the root, which
   re-measures and rebuilds the loop's copies from what the slides hold now.

   <div class="carousel" data-carousel aria-roledescription="carousel" aria-label="…">
     <button class="carousel__control carousel__control--prev" …>…</button>
     <div class="carousel__viewport">
       <ul class="carousel__track">
         <li class="carousel__item" role="group" aria-roledescription="slide">…</li>
       </ul>
     </div>
     <button class="carousel__control carousel__control--next" …>…</button>
   </div> */
  .carousel {
    --carousel-gap: 1rem;
    --carousel-cols: 1;

    /* The settle: how the track travels after a release, a button, or a jump.
     app.js reads it off the root, so a page can retime one carousel without
     touching the engine. Long and eased at both ends, which is what stops a snap
     from reading as a click into place; the same timing for a flick as for a
     button, so the slide arrives the same way however it was asked for. */
    --carousel-slide: 500ms ease-in-out;

    display: flex;
    align-items: center;
    gap: 1rem;
  }

  /* Reduced motion: the move still happens, the position of the track is the
   information, but without the glide. */
  @media (prefers-reduced-motion: reduce) {
    .carousel {
      --carousel-slide: 1ms linear;
    }
  }

  /* The window. On a pointer the track inside is moved by JS (initCarousel) via a
   translate3d transform, so overflow is simply clipped, and touch-action pan-y
   lets the page still scroll vertically while horizontal drags belong to the
   carousel. */
  .carousel__viewport {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    touch-action: pan-y;
  }

  /* Under a finger it is a scroll container instead, and the swipe is the
   platform's: its momentum, its rubber band at the ends, its snap curve. A
   transform engine has to reimplement all three from a pointer's position and a
   clock, and the approximation is what a thumb notices. app.js reads the same
   media query and hands the movement over (it scrolls rather than transforms, and
   its drag doesn't arm), so the arrows, the thumbnails and the status keep
   working the same way.

   No bar: the slides themselves say where you are, and the platforms that use
   this are the ones with overlay scrollbars anyway. */
  @media (hover: none) and (pointer: coarse) {
    .carousel__viewport {
      overflow-x: auto;
      scroll-snap-type: x mandatory;
      scrollbar-width: none;

      /* Both axes belong to the browser now: it is scrolling either way. */
      touch-action: pan-x pan-y;
    }

    .carousel__viewport::-webkit-scrollbar {
      display: none;
    }

    /* Start, because that is where the transform engine aligns a slide too (each
     item's own offsetLeft), so the arrows and the thumbnails land on the same
     position the swipe snaps to. */
    .carousel__item {
      scroll-snap-align: start;
    }
  }

  /* Suppress text/image selection during a drag. */
  .carousel__viewport.is-dragging {
    user-select: none;
  }

  .carousel__track {
    display: flex;
    gap: var(--carousel-gap);
    margin: 0;
    padding: 0;
    list-style: none;
    will-change: transform;
  }

  /* Basis subtracts the shared gaps so exactly --carousel-cols items span the
   viewport. grow/shrink 0 so each keeps its width and the track can overflow. */
  .carousel__item {
    flex: 0 0 calc((100% - (var(--carousel-cols) - 1) * var(--carousel-gap)) / var(--carousel-cols));
    min-width: 0;
  }

  /* Round icon buttons flanking the viewport, vertically centred by the flex row. */
  .carousel__control {
    /* Tapped repeatedly to walk a set, so it can't be a double-tap zoom. */
    touch-action: manipulation;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: var(--border-width) solid var(--fill-tertiary);
    border-radius: var(--radius-full);
    background: var(--background-secondary);
    color: var(--ink-primary);
    cursor: pointer;
    transition:
      background var(--motion-default),
      border-color var(--motion-default);
  }

  .carousel__control svg {
    width: 18px;
    height: 18px;
  }

  @media (hover: hover) and (pointer: fine) {
    .carousel__control:not(:disabled):hover {
      background: var(--background-secondary-hover);
    }
  }

  .carousel__control:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* Reached the end on that side. Keeps the resting surface so it doesn't read as
   a filled CTA; only the icon + border fade. No hover feedback. */
  .carousel__control:disabled {
    border-color: var(--fill-tertiary);
    color: var(--fill-secondary);
    cursor: not-allowed;
  }

  .carousel__control:not(:disabled):active {
    background: var(--background-secondary-active);
  }

  /* ── Toast ─────────────────────────────────────────────────────────────────
   A brief message that appears over the page, then fades on its own. One reused
   pill rather than a stack: a second message replaces the first, so the corner
   never fills up. Typed toasts take a leading icon in the matching semantic
   color (the same glyphs the Alert component uses); the loading type takes the
   ring spinner instead and holds until its promise settles.

   The pill is aria-hidden and the message is announced through a separate
   visually-hidden live region (polite, or assertive for error/warning), so a
   reader gets the text once rather than racing the animation.

   Structure:
     <div class="toast" data-type="success" aria-hidden="true">
       <span class="toast__icon"><svg …/></span>
       <span class="toast__text">Changes saved</span>
     </div> */
  .toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%) translateY(1rem);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;

    /* % (not 100vw) resolves against the viewport minus any scrollbar, so a wide
     toast can't itself trigger a horizontal scrollbar. */
    max-width: calc(100% - 2rem);
    padding: 0.75rem 1.25rem;
    background: var(--background-secondary);
    color: var(--ink-primary);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg), var(--surface-rim);
    font-size: var(--font-caption-medium-size);
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition:
      opacity 0.18s ease,
      transform 0.18s ease;
    z-index: var(--z-toast);
  }

  .toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  /* Leading icon carries its own optical space, tighten the left, like badge. */
  .toast:has(.toast__icon svg) {
    padding-left: 16px;
  }

  .toast__icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
  }

  /* An untyped toast still renders the span; collapse it so the gap doesn't
   open in front of text that has no icon. */
  .toast__icon:empty {
    display: none;
  }

  .toast__icon svg {
    width: 100%;
    height: 100%;
  }

  .toast[data-type="success"] .toast__icon {
    color: var(--green);
  }

  .toast[data-type="info"] .toast__icon {
    color: var(--blue);
  }

  .toast[data-type="warning"] .toast__icon {
    color: var(--amber);
  }

  .toast[data-type="error"] .toast__icon {
    color: var(--red);
  }

  /* No colour of its own: a removal is neither good news nor bad, so the glyph
   sits at the text's own weight and the shape carries the whole meaning. */
  .toast[data-type="removed"] .toast__icon,
  .toast[data-type="loading"] .toast__icon {
    color: var(--ink-secondary);
  }

  /* Ring spinner for the loading type, the same grow/shrink dash as the Spinner
   component. Kept as its own selectors rather than reusing .spinner so a toast
   stays one self-contained block to copy.
   Rendered as <svg class="toast__spinner"><circle .-track/><circle .-arc/></svg>. */
  .toast__spinner {
    /* ~75% of the icon slot so it optically matches the other glyphs' inset
     circles (their paths sit inside a 24 viewBox), not the full box. */
    width: 0.85rem;
    height: 0.85rem;
    animation: toast-spin 2s linear infinite;
  }

  .toast__spinner-track {
    stroke: color-mix(in oklab, currentcolor 18%, transparent);
  }

  .toast__spinner-arc {
    stroke: currentcolor;
    stroke-dasharray: 1px, 200px;
    transform-origin: center;
    animation: toast-spin-dash 2s ease-in-out infinite;
  }

  /* Both elements carry data-motion-essential, so the reduced-motion guard in
   globals.css leaves them running: an in-flight promise still needs to read as
   in flight. Slow them the way the Spinner component does. */
  @media (prefers-reduced-motion: reduce) {
    .toast__spinner,
    .toast__spinner-arc {
      animation-duration: 6s;
    }
  }

  @keyframes toast-spin {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes toast-spin-dash {
    0% {
      stroke-dasharray: 1px, 200px;
      stroke-dashoffset: 0;
    }

    50% {
      stroke-dasharray: 100px, 200px;
      stroke-dashoffset: -15px;
    }

    100% {
      stroke-dasharray: 1px, 200px;
      stroke-dashoffset: -120px;
    }
  }

  /* ── Forced colors (Windows High Contrast) ─────────────────────────────────
   The forced palette strips backgrounds, shadows and masks, so any state or
   surface shown only by a fill/shadow disappears. Restore it with system colors
   and real borders/outlines. `forced-color-adjust: none` is used where a painted
   fill must survive (checked controls, the slider/progress bars); it's always
   paired with system colors so the user's palette is still respected. This block
   sits at the end of the layer so its overrides win over each component's rules. */
  @media (forced-colors: active) {
    /* Switch: outline the track, fill it on when checked, keep the knob solid. */
    .switch__input {
      border: var(--border-width) solid ButtonBorder;
    }

    .switch__input:checked {
      forced-color-adjust: none;
      background: Highlight;
    }

    .switch__knob {
      background: ButtonText;
    }

    .switch__input:checked + .switch__knob {
      background: HighlightText;
    }

    /* Checkbox: the painted checked fill would vanish otherwise. */
    .checkbox__input:checked {
      forced-color-adjust: none;
      background: Highlight;
      border-color: Highlight;
    }

    .checkbox__check {
      color: HighlightText;
    }

    /* Radio: keep the ring + transparent centre (its border-width dot) rather than
     a solid fill, so the checked state still reads as a radio with a dot. */
    .radio__input:checked {
      forced-color-adjust: none;
      border-color: Highlight;
    }

    /* Disabled and empty: the pale fill is dropped in this mode, so the outline
     comes back or the box would have no edge at all. */
    .checkbox__input:disabled:not(:checked),
    .radio__input:disabled:not(:checked) {
      border-color: GrayText;
    }

    /* Alert icons keep their semantic color (set on the SVG; opt out so the
     forced palette doesn't remap it). */
    .alert__icon {
      forced-color-adjust: none;
    }

    /* Avatar presence dot: a background-only circle with a box-shadow ring, so
     both halves are stripped. Keep the fill and swap the ring for a real
     border, or the dot vanishes entirely. */
    .avatar__status {
      forced-color-adjust: none;
      background: Highlight;
      border: var(--border-width) solid Canvas;
      box-shadow: none;
    }

    /* Focus affordances built from box-shadow (input, custom select, menu trigger)
     disappear, so substitute a real outline, which forced-colors always renders. */
    .input__container:focus-within,
    .select__trigger:focus-visible,
    .select__trigger[aria-expanded="true"],
    .menu__trigger:focus-visible,
    .menu__trigger[aria-expanded="true"] {
      outline: 2px solid Highlight;
      outline-offset: 1px;
    }

    /* Active/selected states (active option, focused menu item, selected tab,
     current page, selected day) show only by a background tint the forced palette
     strips; restate each as a system selection so the choice stays distinguishable
     (this also restores menu-item keyboard focus). (Chip is separate below: its
     hover/active variants need pinning too.) */
    .select__option:hover,
    .select__option.is-active,
    .menu__item:focus-visible,
    .toggle-group__radio:checked + .toggle-group__tab,
    .pagination__link[aria-current="page"],
    .pagination__link[aria-current="page"]:hover,
    .calendar__day.is-selected,
    .calendar__day.is-range-start,
    .calendar__day.is-range-end {
      forced-color-adjust: none;
      background: Highlight;
      color: HighlightText;
    }

    /* Checked chip: pin base plus hover/active to the system selection. Because
     forced-color-adjust:none keeps the painted fill, it also exposes the token
     hover/active tints, so the hover/active states must be restated (selectors
     mirror the base rules to win on source order) or a light tint lands under
     HighlightText and the label becomes unreadable. */
    .chip:has(input:checked),
    .chip--as-checkbox:has(input:checked):not(:has(input:disabled)):hover,
    .chip--as-checkbox:has(input:checked):not(:has(input:disabled)):active {
      forced-color-adjust: none;
      background: Highlight;
      color: HighlightText;
    }

    /* Today carries only a faint fill; keep a border so it still reads as marked. */
    .calendar__day.is-today {
      border: var(--border-width) solid ButtonText;
    }

    /* Steps: rings and accent fills are stripped, so outline every indicator and
     pin the current/done states to system colors; keep the connectors visible. */
    .steps__indicator {
      forced-color-adjust: none;
      border: 2px solid ButtonBorder;
      box-shadow: none;
      color: CanvasText;
    }

    .steps__step.is-current .steps__indicator {
      border-color: Highlight;
      color: Highlight;
    }

    .steps__step.is-done .steps__indicator {
      background: Highlight;
      border-color: Highlight;
      color: HighlightText;
    }

    .steps__step::before,
    .steps__step::after {
      forced-color-adjust: none;
      background: CanvasText;
    }

    /* Surfaces (alert, card, popover, accordion rows, tooltip) lose their
     background, so add a CanvasText border to keep the container boundary visible
     (the same neutral structural line as the separator/avatar/sheet, and more
     reliably visible than the button-specific ButtonBorder). */
    .alert,
    .error-summary,
    .card,
    .popover,
    .accordion__item,
    .tooltip__bubble,
    .select__list,
    .nav-menu__menu,
    .dialog,
    .toggle-group {
      border: var(--border-width) solid CanvasText;
    }

    /* Controls and pills lose their painted fill/border, so outline each with its
     own text color (currentColor) so the border agrees with the label: buttons
     (incl. dialog/empty actions), badges (meaning is the text, not the tint), and
     pagination page/prev/next buttons (transparent otherwise, so they'd float). */
    .button,
    .badge {
      border: var(--border-width) solid currentcolor;
    }

    /* Pagination page/prev/next: currentColor doesn't reliably render as a border
     on these transparent <button>s in the forced palette, so use the explicit
     ButtonBorder system color. */
    .pagination__link {
      border: var(--border-width) solid ButtonBorder;
    }

    /* Hover feedback: the token background swap is stripped, so mark the hovered
     button's border as a system selection (the theme's accent, e.g. brown). */
    .button:hover {
      border-color: Highlight;
    }

    /* Avatar: its gray surface is stripped, leaving the initials/icon floating.
     A CanvasText ring restores the circle and reads reliably (ButtonBorder can be
     faint). Not a Highlight fill: that would look "selected" and isn't a neutral
     placeholder surface. */
    .avatar {
      border: var(--border-width) solid CanvasText;
    }

    /* Separators (standalone, the menu/dropdown divider, and the breadcrumb chevron)
     draw with a background fill the forced palette strips; use a text-color line
     so they stay visible. Force full opacity since the menu divider is a faint 0.4,
     and the breadcrumb chevron is otherwise a dim GrayText. */
    .separator,
    .menu__separator,
    .breadcrumb__item:not(:first-child)::before {
      background: CanvasText;
      opacity: 1;
    }

    /* The native-select dropdown chevron and the search clear (X) are masks tinted
     faint --ink-secondary, which dims in the forced palette; paint them CanvasText
     (incl. the X hover, which is otherwise an invisible --ink-primary map). */
    .input__container--select::after,
    .input__element::-webkit-search-cancel-button,
    .input__element::-webkit-search-cancel-button:hover {
      background: CanvasText;
    }

    /* Active tab underline: the ::after bar loses its --primary fill, so repaint it
     with the system Highlight so the current tab still reads as selected. */
    .tabs__tab[aria-selected="true"]::after {
      forced-color-adjust: none;
      background: Highlight;
    }

    /* Sheet: the edge shadow separating it from the page is gone; border only the
     inner edge (the other three sides sit at the viewport). Positioned by physical
     inset, so the right-anchored default borders its left edge, and .sheet--left
     its right. */
    .sheet {
      border-left: var(--border-width) solid CanvasText;
    }

    .sheet--left {
      border-left: 0;
      border-right: var(--border-width) solid CanvasText;
    }

    /* Slider: the token fill/shadow vanish, leaving no visible bar. Repaint it like
     Progress: Highlight for the filled portion on an empty (Canvas) outlined track.
     WebKit draws the fill via the --slider-fill gradient; Firefox uses
     -moz-range-progress. */
    .slider::-webkit-slider-runnable-track {
      forced-color-adjust: none;
      background: linear-gradient(
        to right,
        Highlight var(--slider-fill),
        Canvas var(--slider-fill)
      );
      border: var(--border-width) solid ButtonText;
    }

    .slider::-moz-range-track {
      forced-color-adjust: none;
      background: Canvas;
      border: var(--border-width) solid ButtonText;
    }

    .slider::-moz-range-progress {
      forced-color-adjust: none;
      background: Highlight;
    }

    /* Thumb is the accent handle (like --primary-foreground normally): Highlight
     to match the fill, with a Canvas ring so it stays distinct on the filled part.
     Split per-engine: grouping ::-webkit- with ::-moz- in one list makes each
     browser treat the whole rule as invalid and drop it. */
    .slider::-webkit-slider-thumb {
      forced-color-adjust: none;
      background: Highlight;
      border-color: Canvas;
    }

    .slider::-moz-range-thumb {
      forced-color-adjust: none;
      background: Highlight;
      border-color: Canvas;
    }

    /* Progress: track and value fills both vanish, leaving nothing. Outline the
     track and mark the filled value as a system selection so the bar reads. */
    .progress {
      forced-color-adjust: none;
      background: Canvas;
      border: var(--border-width) solid ButtonText;
    }

    .progress::-webkit-progress-bar {
      forced-color-adjust: none;
      background: Canvas;
    }

    .progress::-webkit-progress-value {
      forced-color-adjust: none;
      background: Highlight;
    }

    .progress::-moz-progress-bar {
      forced-color-adjust: none;
      background: Highlight;
    }

    /* Spinner: the faint track drops out in the forced palette, so pin both
     strokes to CanvasText (the dash animation still conveys motion on the arc). */
    .spinner__track,
    .spinner__arc {
      forced-color-adjust: none;
      stroke: CanvasText;
    }

    .spinner__track {
      stroke: GrayText;
    }

    /* Carousel: a reached-the-end control drops to GrayText so it still reads. */
    .carousel__control:disabled {
      color: GrayText;
      border-color: GrayText;
    }

    /* Toast pops up on its own surface, which the forced palette strips; a
     CanvasText border keeps it a visible, delineated notification. */
    .toast {
      border: var(--border-width) solid CanvasText;
    }

    /* Keep the typed toast icon's semantic color (like the Alert icons). The
     color is set on this wrapper span, so the forced palette would remap it to a
     system color and the SVG would inherit that; opt out to preserve it. */
    .toast__icon {
      forced-color-adjust: none;
    }

    /* Toast promise spinner: the faint track drops out in the forced palette, so
     pin both strokes so the ring + arc still read (arc CanvasText, track dimmer). */
    .toast__spinner-arc {
      forced-color-adjust: none;
      stroke: CanvasText;
    }

    .toast__spinner-track {
      forced-color-adjust: none;
      stroke: GrayText;
    }
  }
}
