@layer reset, tokens, base, components, client;
@layer reset {
*, ::before, ::after, ::backdrop { box-sizing: border-box; margin: 0; padding: 0;
  border: 0 solid var(--border); }
html { line-height: 1.5; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; tab-size: 4;
  font-family: var(--font-sans); -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }
a { color: inherit; text-decoration: inherit; }
b, strong { font-weight: var(--font-weight-semibold); }
code, kbd, samp, pre { font-family: var(--font-mono); font-size: 1em; }
small { font-size: 80%; }
table { text-indent: 0; border-color: inherit; border-collapse: collapse; }
ol, ul, menu { list-style: none; }
img, svg, video, canvas { display: block; vertical-align: middle; }
img, video { max-width: 100%; height: auto; }
button, input, select, optgroup, textarea, ::file-selector-button {
  font: inherit; font-feature-settings: inherit; letter-spacing: inherit; color: inherit;
  border-radius: 0; background-color: transparent; opacity: 1; }
::placeholder { opacity: 1; color: var(--muted-foreground); }
textarea { resize: vertical; }
[hidden]:where(:not([hidden='until-found'])) { display: none !important; }
}
@layer tokens {
:root {
  color-scheme: light dark;
  /* Three grounds (spec/ui.md 3): the page, the panels on it (cards,
     dialogs, menus) and the chrome around it (the sidebar, the phone's top
     bar, a strip of tabs).  A white page with grey chrome; in the dark the
     page and its panels share one ground and the chrome is darker. */
  --background: light-dark(#ffffff, #19191c);
  --foreground: light-dark(#171717, #ededed);
  --card: light-dark(#ffffff, #19191c);
  --card-foreground: light-dark(#171717, #ededed);
  --popover: light-dark(#ffffff, #19191c);
  --popover-foreground: light-dark(#171717, #ededed);
  --chrome: light-dark(#f6f6f7, #111113);
  --chrome-border: light-dark(#0000000f, #ffffff12);
  /* The main button is ink: the text colour as its fill. */
  --primary: light-dark(#171717, #ededed);
  --primary-foreground: light-dark(#ffffff, #19191c);
  --secondary: light-dark(#f3f3f4, #222226);
  --secondary-foreground: light-dark(#171717, #ededed);
  --muted: light-dark(#f3f3f4, #222226);
  /* One grey for quieter text: the text colour at 72 %, at least 6.5:1 on
     every ground in both schemes. */
  --muted-foreground: color-mix(in oklab, var(--foreground) 72%, transparent);
  /* Under a pointer (shadcn's accent) and while pressed: tints of the text
     colour, so they show on every ground. */
  --accent: light-dark(#0000000d, #ffffff0f);
  --accent-foreground: light-dark(#171717, #ededed);
  --pressed: light-dark(color-mix(in oklab, var(--foreground) 8%, transparent),
                        color-mix(in oklab, var(--foreground) 10%, transparent));
  /* A group inside a panel stands on this instead of a frame of its own. */
  --soft: color-mix(in oklab, var(--foreground) 5%, transparent);
  /* One thin edge for controls and panels, and a stronger one beside it. */
  --border: light-dark(#0000001f, #ffffff24);
  --border-strong: light-dark(color-mix(in oklab, var(--foreground) 26%, transparent),
                              color-mix(in oklab, var(--foreground) 30%, transparent));
  /* The edge of a field, a box to tick and a switch, where the edge is all
     there is of the control: 3:1 on the page and the chrome (WCAG 1.4.11). */
  --input: light-dark(color-mix(in oklab, var(--foreground) 50%, transparent),
                      color-mix(in oklab, var(--foreground) 40%, transparent));
  --input-background: light-dark(#ffffff, #141417);
  /* The accent, only for focus, for what is on, for what is selected and
     for where a dragged thing will drop. */
  --highlight: light-dark(#005ff2, #47a8ff);
  --highlight-foreground: light-dark(#ffffff, #19191c);
  --highlight-soft: light-dark(#f0f7ff, #06193a);
  --ring: var(--highlight);
  /* The dim behind a modal dialog, deeper in the dark, where a faint one
     would not read as a dim. */
  --overlay: light-dark(#00000066, #0000008a);
  /* A chart's line (spec/ui.md 3): 4.4:1 on the light card, 4.8:1 on the dark. */
  --chart-1: light-dark(#2a78d6, #3987e5);

  /* Status: the strong colour, text on it, and a tinted background.  The
     strong colour is also the text on the tinted background, at least 4.5:1
     there and on the page. */
  --info: light-dark(#005ff2, #47a8ff);
  --info-foreground: light-dark(#ffffff, #19191c);
  --info-soft: light-dark(#f0f7ff, #06193a);
  --success: light-dark(#107d32, #00ac3a);
  --success-foreground: light-dark(#ffffff, #19191c);
  --success-soft: light-dark(#ecf6ef, #0b2615);
  --warning: light-dark(#aa4d00, #ffae00);
  --warning-foreground: light-dark(#ffffff, #19191c);
  --warning-soft: light-dark(#fff4e5, #2e1d05);
  --destructive: light-dark(#d8001b, #ff565f);
  --destructive-foreground: light-dark(#ffffff, #19191c);
  --destructive-soft: light-dark(#ffeeef, #330a11);

  --font-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
    monospace;
  /* Meta text 0.75rem on 1rem; controls 0.875rem on 1.25rem; running text
     0.875rem on 1.375rem. */
  --text-xs: 0.75rem; --text-xs--line-height: calc(1 / 0.75);
  --text-sm: 0.875rem; --text-sm--line-height: calc(1.25 / 0.875);
  --text-running: 0.875rem; --text-running--line-height: calc(1.375 / 0.875);
  --text-base: 1rem; --text-base--line-height: 1.5;
  --text-lg: 1.125rem; --text-lg--line-height: calc(1.75 / 1.125);
  --text-xl: 1.25rem; --text-xl--line-height: calc(1.75 / 1.25);
  --text-2xl: 1.5rem; --text-2xl--line-height: calc(2 / 1.5);
  --text-3xl: 1.875rem; --text-3xl--line-height: calc(2.25 / 1.875);
  --font-weight-normal: 400; --font-weight-medium: 500;
  --font-weight-semibold: 600; --font-weight-bold: 700;

  --spacing: 0.25rem;
  /* Two radii: a control's and a panel's.  A part inside a padded control
     or menu takes the control's less its inset (-sm). */
  --radius: 0.75rem;
  --radius-sm: calc(var(--radius-md) - 0.125rem);
  --radius-md: 0.5rem;
  --radius-lg: var(--radius);
  --radius-xl: var(--radius);
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  /* A panel on the page: barely lifted in the light, flat in the dark. */
  --shadow-panel: 0 1px 2px light-dark(rgb(0 0 0 / 0.04), transparent),
    0 2px 8px light-dark(rgb(0 0 0 / 0.03), transparent);

  --control-height: 2.25rem;
  --control-height-sm: 2rem;
  --control-height-lg: 2.5rem;
  --control-font-size: var(--text-sm);
  /* A gap in the ground's colour, then the accent, so the ring shows on
     every ground and beside every edge. */
  --focus-ring: 0 0 0 2px var(--background), 0 0 0 4px var(--ring);
  /* Its twin inside a box that fills its row or strip, where a ring
     outside would be cut off. */
  --focus-ring-inset: inset 0 0 0 2px var(--ring);

  /* One easing for every change of state; no overshoot, which flickers on
     colours.  Sheets open slower, and what closes leaves quicker. */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration: 200ms;
  --duration-sheet: 280ms;
  --duration-close: 160ms;

  --z-sticky: 40;
  --z-dropdown: 50;
  --z-dialog: 100;
  --z-toast: 110;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }
/* A finger needs a bigger target than a mouse, and a phone zooms into text
   under 16px when it gets focus. */
@media (pointer: coarse) {
  :root {
    --control-height: 2.75rem;
    --control-height-sm: 2.5rem;
    --control-height-lg: 3rem;
    --control-font-size: var(--text-base);
  }
}
@media (prefers-reduced-motion: reduce) {
  :root { --duration-fast: 0ms; --duration: 0ms; --duration-sheet: 0ms; --duration-close: 0ms; }
}
}
@layer base {
body { min-height: 100dvh; background-color: var(--background); color: var(--foreground);
  font-size: var(--text-running); line-height: var(--text-running--line-height);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; }
h1 { font-size: var(--text-2xl); line-height: var(--text-2xl--line-height);
  font-weight: var(--font-weight-semibold); letter-spacing: -0.025em; }
h2 { font-size: var(--text-xl); line-height: var(--text-xl--line-height);
  font-weight: var(--font-weight-semibold); letter-spacing: -0.0125em; }
h3 { font-size: var(--text-lg); line-height: var(--text-lg--line-height);
  font-weight: var(--font-weight-semibold); }
h4 { font-size: var(--text-base); font-weight: var(--font-weight-semibold); }
h1, h2, h3, h4 { text-wrap: balance; }
p { text-wrap: pretty; }
a:not([class]) { text-decoration-line: underline; text-underline-offset: 4px; }
code:not([class]) { border-radius: var(--radius-sm); background-color: var(--muted);
  padding: 0.1em 0.3em; font-size: 0.875em; }
button:not(:disabled), [role='button']:not(:disabled) { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
::selection { background-color: color-mix(in oklab, var(--highlight) 20%, transparent); }
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important; transition-duration: 0.01ms !important;
    scroll-behavior: auto !important; }
}
}
@layer components {

/* icon: Lucide */

.tun-icon {
  width: calc(var(--spacing) * 4);
  height: calc(var(--spacing) * 4);
  flex-shrink: 0;
  pointer-events: none;
  &[data-size='xs'] { width: calc(var(--spacing) * 3); height: calc(var(--spacing) * 3); }
  &[data-size='sm'] { width: calc(var(--spacing) * 3.5); height: calc(var(--spacing) * 3.5); }
  &[data-size='lg'] { width: calc(var(--spacing) * 5); height: calc(var(--spacing) * 5); }
  &[data-size='xl'] { width: calc(var(--spacing) * 6); height: calc(var(--spacing) * 6); }
}

/* button: Basecoat button (Vega) */

.tun-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: calc(var(--spacing) * 1.5);
  height: var(--control-height);
  padding-inline: calc(var(--spacing) * 2.5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background-clip: padding-box;
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  outline: none;
  transition-property: color, background-color, border-color, box-shadow, translate;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { box-shadow: var(--focus-ring); }
  /* Pressed shows at once, and eases back when let go. */
  &:active { transition-duration: 0s; }
  &:active:not([aria-haspopup]) { translate: 0 1px; }
  &:disabled, &[aria-disabled='true'] { pointer-events: none; opacity: 0.5; }
  & .tun-icon:not([data-size]) {
    width: calc(var(--spacing) * 4);
    height: calc(var(--spacing) * 4);
  }
  &:has(> [data-icon='start']) { padding-left: calc(var(--spacing) * 2); }
  &:has(> [data-icon='end']) { padding-right: calc(var(--spacing) * 2); }

  &[data-size='xs'] {
    height: calc(var(--spacing) * 6);
    gap: var(--spacing);
    padding-inline: calc(var(--spacing) * 2);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 3);
      height: calc(var(--spacing) * 3);
    }
  }
  &[data-size='sm'] {
    height: var(--control-height-sm);
    gap: var(--spacing);
  }
  &:is([data-size='xs'], [data-size='sm']) {
    &:has(> [data-icon='start']) { padding-left: calc(var(--spacing) * 1.5); }
    &:has(> [data-icon='end']) { padding-right: calc(var(--spacing) * 1.5); }
  }
  &[data-size='lg'] { height: var(--control-height-lg); }
  &[data-size='icon'] { width: var(--control-height); padding: 0; }
  &[data-size='icon-xs'] {
    width: calc(var(--spacing) * 6);
    height: calc(var(--spacing) * 6);
    padding: 0;
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 3);
      height: calc(var(--spacing) * 3);
    }
  }
  &[data-size='icon-sm'] {
    width: var(--control-height-sm);
    height: var(--control-height-sm);
    padding: 0;
  }
  &[data-size='icon-lg'] {
    width: var(--control-height-lg);
    height: var(--control-height-lg);
    padding: 0;
  }
  /* A shortcut's keys show where a keyboard is likely, and an icon button
     then grows to hold them beside its icon. */
  & > [data-tun-shortcut] { display: none; }
  @media (min-width: 48rem) {
    & > [data-tun-shortcut] { display: inline-flex; }
    &[data-size^='icon']:has(> [data-tun-shortcut]) {
      width: auto;
      padding-inline: calc(var(--spacing) * 2);
    }
  }
  /* The sizes under a control's height stay small on a touch screen, so an
     invisible area around them takes the finger: as high as a control
     there (44px), and at least as wide. */
  @media (pointer: coarse) {
    &:is([data-size='xs'], [data-size='sm'], [data-size='icon-xs'], [data-size='icon-sm']) {
      position: relative;
      &::before {
        content: '';
        position: absolute;
        inset: min(0px, calc(50% - var(--control-height) / 2));
      }
    }
  }

  /* Under a pointer and while pressed, a tint of the text colour is laid
     over the button's own ground, so every variant answers the same way. */
  &:not([data-variant='primary']) {
    @media (hover: hover) {
      &:not([data-variant='link']):hover {
        background-image: linear-gradient(var(--accent), var(--accent));
      }
    }
    &:is(:active, [aria-expanded='true'], [aria-pressed='true'], [aria-current='page']) {
      background-image: linear-gradient(var(--pressed), var(--pressed));
    }
  }
  &[data-variant='primary'] {
    background-color: var(--primary);
    color: var(--primary-foreground);
    @media (hover: hover) {
      &:hover { background-color: color-mix(in oklab, var(--primary) 82%, var(--background)); }
    }
    &:active { background-color: color-mix(in oklab, var(--primary) 68%, var(--background)); }
  }
  &[data-variant='secondary'] {
    background-color: var(--secondary);
    color: var(--secondary-foreground);
  }
  /* Outline, and destructive with red words on the same ground and frame. */
  &:is([data-variant='outline'], [data-variant='destructive']) {
    border-color: var(--border);
    background-color: var(--background);
    color: var(--foreground);
    @media (hover: hover) {
      &:hover { border-color: var(--border-strong); }
    }
    &:is(:active, [aria-expanded='true'], [aria-pressed='true'], [aria-current='page']) {
      border-color: var(--border-strong);
    }
  }
  &[data-variant='destructive'] { color: var(--destructive); }
  &[data-variant='ghost'] { color: var(--foreground); }
  /* A button that is only an icon needs no box: no frame and no ground at
     rest, so a row of them is not a row of boxes and the filled button
     stands out.  Chosen, it keeps them; a pointer and a press still show. */
  &[data-size^='icon'][data-variant='outline']:not([aria-expanded='true'], [aria-pressed='true'],
                                                   [aria-current='page']) {
    border-color: transparent;
    background-color: transparent;
  }
  &[data-variant='link'] {
    color: var(--primary);
    text-underline-offset: 4px;
    @media (hover: hover) {
      &:hover { text-decoration-line: underline; }
    }
  }
}

/* button-group: Basecoat button group (Vega) */

.tun-button-group {
  isolation: isolate;
  display: inline-flex;
  width: fit-content;
  align-items: stretch;
  /* A focused part's ring is drawn over its neighbours. */
  & > :focus-visible { position: relative; z-index: 1; }
  /* The parts of a group share one frame, so an outline icon button in a
     group keeps its frame and ground. */
  & > .tun-button[data-size^='icon'][data-variant='outline'] {
    border-color: var(--border);
    background-color: var(--background);
  }
  &:has(> .tun-button-group) { gap: calc(var(--spacing) * 2); }
  & > .tun-button-group-separator {
    flex-shrink: 0;
    align-self: stretch;
    width: 1px;
    margin-block: 1px;
    background-color: var(--border);
  }
  /* On a filled primary button the line is a shade of the button itself. */
  &:has(> [data-variant='primary']) > .tun-button-group-separator {
    background-color: color-mix(in oklab, var(--primary), var(--primary-foreground) 25%);
  }
  /* Text between the buttons, such as which page is shown. */
  & > :is(span, label, output):not([class]) {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    padding-inline: calc(var(--spacing) * 2.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--muted);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
  }

  &:not([data-orientation='vertical']) {
    & > :not(:first-child) {
      border-start-start-radius: 0;
      border-end-start-radius: 0;
      border-inline-start-width: 0;
    }
    & > :not(:last-child) {
      border-start-end-radius: 0;
      border-end-end-radius: 0;
    }
  }
  &[data-orientation='vertical'] {
    flex-direction: column;
    & > .tun-button-group-separator {
      width: auto;
      height: 1px;
      margin-block: 0;
      margin-inline: 1px;
    }
    & > :not(:first-child) {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
      border-top-width: 0;
    }
    & > :not(:last-child) {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }
}

/* link: shadcn/ui typography (link), Basecoat's look */

.tun-link {
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-weight: var(--font-weight-medium);
  text-decoration-line: underline;
  text-decoration-color: color-mix(in oklab, currentColor 40%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition-property: color, text-decoration-color;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  @media (hover: hover) {
    &:hover { text-decoration-color: currentColor; }
  }
  &:active { background-color: var(--pressed); transition-duration: 0s; }
  &[data-variant='muted'] {
    color: var(--muted-foreground);
    font-weight: inherit;
    @media (hover: hover) {
      &:hover { color: var(--foreground); }
    }
  }
  & > .tun-icon {
    display: inline-block;
    width: 0.875em;
    height: 0.875em;
    margin-inline-start: 0.125em;
    vertical-align: -0.0625em;
  }
  /* Read by screen readers, not shown. */
  & > .tun-link-hint {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* kbd: Basecoat kbd (Vega) */

.tun-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing);
  width: fit-content;
  min-width: calc(var(--spacing) * 5);
  height: calc(var(--spacing) * 5);
  padding-inline: var(--spacing);
  border-radius: var(--radius-sm);
  background-color: var(--muted);
  /* --muted-foreground on --muted is 4.3:1 in the light scheme; a little of
     the text colour brings it over AA's 4.5:1. */
  color: color-mix(in oklab, var(--muted-foreground), var(--foreground) 20%);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  line-height: var(--text-xs--line-height);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  vertical-align: middle;
  pointer-events: none;
  user-select: none;
  & .tun-icon:not([data-size]) {
    width: calc(var(--spacing) * 3);
    height: calc(var(--spacing) * 3);
  }
  /* Keys pressed together: the outer KBD only lines them up. */
  &:has(> .tun-kbd) {
    min-width: 0;
    height: auto;
    padding: 0;
    background-color: transparent;
    color: inherit;
  }
}

/* badge: Basecoat badge (Vega) with Tun's status colours, as soft tones */

.tun-badge {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: var(--spacing);
  width: fit-content;
  height: calc(var(--spacing) * 5);
  padding: calc(var(--spacing) * 0.5) calc(var(--spacing) * 2);
  overflow: hidden;
  border-radius: var(--radius-full);
  /* A tone tints; it never fills or frames. */
  background-color: var(--muted);
  color: var(--foreground);
  font-size: var(--text-xs);
  line-height: var(--text-xs--line-height);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  vertical-align: middle;
  & > .tun-icon {
    width: calc(var(--spacing) * 3);
    height: calc(var(--spacing) * 3);
  }
  &:has(> .tun-icon:first-child) { padding-inline-start: calc(var(--spacing) * 1.5); }
  &[data-variant='info'] { background-color: var(--info-soft); color: var(--info); }
  &[data-variant='success'] { background-color: var(--success-soft); color: var(--success); }
  &[data-variant='warning'] { background-color: var(--warning-soft); color: var(--warning); }
  &[data-variant='destructive'] {
    background-color: var(--destructive-soft);
    color: var(--destructive);
  }
}

/* avatar: Basecoat avatar (Vega) */

.tun-avatar {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: calc(var(--spacing) * 8);
  height: calc(var(--spacing) * 8);
  border-radius: var(--radius-full);
  vertical-align: middle;
  user-select: none;
  /* A hairline that keeps a light photo apart from a light page. */
  &::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid color-mix(in oklab, var(--foreground) 10%, transparent);
    border-radius: inherit;
    pointer-events: none;
  }
  &[data-size='sm'] { width: calc(var(--spacing) * 6); height: calc(var(--spacing) * 6); }
  &[data-size='lg'] { width: calc(var(--spacing) * 10); height: calc(var(--spacing) * 10); }
  & > .tun-avatar-initials {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background-color: var(--muted);
    /* --muted-foreground on --muted is 4.3:1 in the light scheme. */
    color: color-mix(in oklab, var(--muted-foreground), var(--foreground) 20%);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
  }
  &[data-size='sm'] > .tun-avatar-initials {
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
  }
  /* The photo covers the initials, which show if it does not load. */
  & > .tun-avatar-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
  }

  &[data-group] {
    width: auto;
    height: auto;
    border-radius: 0;
    &::after { content: none; }
    /* Overlapping only as far as the initials stay whole. */
    & > .tun-avatar {
      box-shadow: 0 0 0 2px var(--background);
      &:not(:last-child) { margin-inline-end: calc(var(--spacing) * -1.5); }
      & > .tun-avatar-initials {
        font-size: var(--text-xs);
        line-height: var(--text-xs--line-height);
      }
    }
    & > [data-size='sm'] {
      &:not(:last-child) { margin-inline-end: calc(var(--spacing) * -0.75); }
      /* Two letters fit beside the next avatar only at 10px. */
      & > .tun-avatar-initials { font-size: 0.625rem; }
    }
    & > [data-size='lg'] {
      &:not(:last-child) { margin-inline-end: calc(var(--spacing) * -2); }
      & > .tun-avatar-initials {
        font-size: var(--text-sm);
        line-height: var(--text-sm--line-height);
      }
    }
  }
}

/* field: GOV.UK form group, label, hint and error message; Basecoat field (Vega) */

.tun-field {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2);
  min-width: 0;
  max-width: 40rem;
  & > .tun-field-label {
    width: fit-content;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    &[data-hidden] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
    }
  }
  & .tun-field-optional {
    color: var(--muted-foreground);
    font-weight: var(--font-weight-normal);
  }
  & > .tun-field-hint { margin-top: calc(var(--spacing) * -1); }
  &:has(:is(input, select, textarea):disabled) > .tun-field-label { opacity: 0.5; }
  & .tun-field-hint {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-field-error {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 1.5);
    color: var(--destructive);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    & > .tun-icon { margin-top: calc((1lh - var(--spacing) * 3.5) / 2); }
  }
  & .tun-field-error-prefix {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
}

/* text-input: Basecoat input (Vega); GOV.UK text input, its widths and its behaviour */

.tun-text-input {
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--control-height);
  padding: var(--spacing) calc(var(--spacing) * 2.5);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
  &::placeholder { color: var(--muted-foreground); }
  &:read-only:not(:disabled) {
    background-color: color-mix(in oklab, var(--muted) 60%, transparent);
    box-shadow: none;
  }
  /* GOV.UK's fixed widths: the characters, the padding and the border, and
     one character more for the browser's autofill icon. */
  &[data-width='2'] { max-width: calc(3ch + var(--spacing) * 5 + 2px); }
  &[data-width='3'] { max-width: calc(4ch + var(--spacing) * 5 + 2px); }
  &[data-width='4'] { max-width: calc(5ch + var(--spacing) * 5 + 2px); }
  &[data-width='5'] { max-width: calc(6ch + var(--spacing) * 5 + 2px); }
  &[data-width='10'] { max-width: calc(11ch + var(--spacing) * 5 + 2px); }
  &[data-width='20'] { max-width: calc(21ch + var(--spacing) * 5 + 2px); }
  &[data-width='30'] { max-width: calc(31ch + var(--spacing) * 5 + 2px); }
  /* A date has a known length too, and the browser's calendar button. */
  &[type='date'] { max-width: calc(12ch + var(--spacing) * 11 + 2px); }
}

/* combobox: WAI-ARIA combobox pattern (list autocomplete); Basecoat combobox (Vega), its look */

.tun-combobox {
  display: flex;
  align-items: flex-start;
  gap: calc(var(--spacing) * 2);
  & .tun-combobox-control { position: relative; flex: 1; min-width: 0; }
  & > .tun-button { flex: none; }
  /* A popover in the top layer, so no card or dialog around the field cuts
     it off; the script places it under the field, or above it. */
  & .tun-combobox-listbox {
    position: fixed;
    inset: auto;
    max-height: min(18rem, 50dvh);
    margin: 0;
    padding: var(--spacing);
    border: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    list-style: none;
    border-radius: var(--radius-lg);
    background-color: var(--popover);
    color: var(--popover-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    /* Closed, and leaving: a little below its place, faded. */
    opacity: 0;
    translate: 0 var(--spacing);
    transition-property: opacity, translate, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
    &:not(:popover-open) { pointer-events: none; }
    &:popover-open {
      opacity: 1;
      translate: none;
      transition-duration: var(--duration-fast);
      @starting-style { opacity: 0; translate: 0 var(--spacing); }
    }
  }
  & .tun-combobox-option, & .tun-combobox-none {
    display: flex;
    min-height: var(--control-height-sm);
    align-items: center;
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    overflow-wrap: anywhere;
    @media (pointer: coarse) { min-height: var(--control-height); }
    &[hidden] { display: none; }
  }
  & .tun-combobox-option {
    cursor: default;
    user-select: none;
    &[aria-selected='true'] { background-color: var(--accent); color: var(--accent-foreground); }
    @media (hover: hover) {
      &:hover { background-color: var(--accent); color: var(--accent-foreground); }
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  & .tun-combobox-none { color: var(--muted-foreground); }
}

/* textarea: Basecoat textarea (Vega); GOV.UK textarea */

.tun-textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: calc(var(--spacing) * 16);
  padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2.5);
  line-height: var(--text-base--line-height);
  resize: vertical;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
  &::placeholder { color: var(--muted-foreground); }
  &:read-only:not(:disabled) {
    background-color: color-mix(in oklab, var(--muted) 60%, transparent);
    box-shadow: none;
  }
}

/* select: Basecoat native select (Vega); GOV.UK select */

.tun-select {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  & > select {
    appearance: none;
    display: block;
    width: 100%;
    min-width: 0;
    height: var(--control-height);
    padding: var(--spacing) calc(var(--spacing) * 9) var(--spacing) calc(var(--spacing) * 2.5);
    text-overflow: ellipsis;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
    & option, & optgroup { background-color: Canvas; color: CanvasText; }
    &:has(> option[value='']:checked) { color: var(--muted-foreground); }
  }
  & > .tun-icon {
    position: absolute;
    top: 50%;
    right: calc(var(--spacing) * 2.5);
    translate: 0 -50%;
    color: var(--muted-foreground);
  }
  &:has(> select:disabled) > .tun-icon { opacity: 0.5; }
}

/* fieldset: GOV.UK fieldset; Basecoat fieldset (Vega) */

.tun-fieldset {
  min-width: 0;
  max-width: 40rem;
  & > .tun-fieldset-legend {
    max-width: 100%;
    margin-bottom: calc(var(--spacing) * 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
  }
  &[data-size='section'] > .tun-fieldset-legend {
    margin-bottom: calc(var(--spacing) * 4);
    font-size: var(--text-lg);
    line-height: var(--text-lg--line-height);
    font-weight: var(--font-weight-semibold);
  }
  &[data-size='page'] > .tun-fieldset-legend { margin-bottom: calc(var(--spacing) * 6); }
  &:not([data-size='default']) > .tun-fieldset-legend:has(+ .tun-fieldset-hint) {
    margin-bottom: calc(var(--spacing) * 2);
  }
  & .tun-fieldset-optional {
    color: var(--muted-foreground);
    font-weight: var(--font-weight-normal);
  }
  & > .tun-fieldset-hint, & > .tun-fieldset-error { margin-bottom: calc(var(--spacing) * 2); }
  &[data-size='page'] > .tun-fieldset-hint { margin-bottom: calc(var(--spacing) * 4); }
  &[data-size='section'] > .tun-fieldset-hint { margin-bottom: calc(var(--spacing) * 4); }
  & > .tun-fieldset-body {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 6);
  }
  &:disabled > .tun-fieldset-legend { opacity: 0.5; }
  & .tun-fieldset-hint {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-fieldset-error {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 1.5);
    color: var(--destructive);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    & > .tun-icon { margin-top: calc((1lh - var(--spacing) * 3.5) / 2); }
  }
  & .tun-fieldset-error-prefix {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
}

/* checkbox: Basecoat checkbox (Vega); GOV.UK checkboxes with one item */

.tun-checkbox {
  display: flex;
  flex-direction: column;
  min-width: 0;
  --tun-choice-size: calc(var(--spacing) * 4);
  @media (pointer: coarse) { --tun-choice-size: calc(var(--spacing) * 5); }
  & .tun-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 2.5);
    width: fit-content;
    max-width: 100%;
    padding-block: calc((var(--control-height) - 1lh) / 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    cursor: pointer;
    touch-action: manipulation;
    &:has(> :disabled) { cursor: not-allowed; color: var(--muted-foreground); }
  }
  & .tun-checkbox-input {
    appearance: none;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: var(--tun-choice-size);
    height: var(--tun-choice-size);
    margin-top: calc((1lh - var(--tun-choice-size)) / 2);
    border: 1px solid var(--input);
    background-color: var(--input-background);
    outline: none;
    cursor: inherit;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    /* What is on takes the accent. */
    &:checked { border-color: var(--highlight); background-color: var(--highlight);
      color: var(--highlight-foreground); }
    &:focus-visible { box-shadow: var(--focus-ring); }
    &[aria-invalid='true']:not(:checked) { border-color: var(--destructive); }
    &[aria-invalid='true'] { box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent)); }
    &:disabled { opacity: 0.5; }
  }
  & .tun-checkbox-hint {
    margin-top: calc((1lh - var(--control-height)) / 2 + var(--spacing) * 0.5);
    padding-left: calc(var(--tun-choice-size) + var(--spacing) * 2.5);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-checkbox-input {
    border-radius: var(--radius-sm);
    /* The tick is two borders of a box turned 45 degrees (GOV.UK), so it
       takes the colour of the text in both themes. */
    &:checked::after {
      content: '';
      width: 56%;
      height: 30%;
      border: solid currentColor;
      border-width: 0 0 2px 2px;
      translate: 0 -20%;
      rotate: -45deg;
    }
  }
  & .tun-checkbox-hint {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-checkbox-error {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 1.5);
    color: var(--destructive);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    & > .tun-icon { margin-top: calc((1lh - var(--spacing) * 3.5) / 2); }
  }
  & .tun-checkbox-error-prefix {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
  & > .tun-checkbox-error { margin-bottom: calc(var(--spacing) * 0.5); }
}

/* checkboxes: GOV.UK checkboxes; Basecoat checkbox (Vega) */

.tun-checkboxes {
  display: flex;
  flex-direction: column;
  &[data-inline] { flex-direction: row; flex-wrap: wrap; column-gap: calc(var(--spacing) * 6); }
  & > .tun-checkbox:has(> .tun-checkbox-hint):not(:last-child) {
    padding-bottom: calc(var(--spacing) * 2);
  }
  &[data-invalid] .tun-checkbox-input:not(:checked) { border-color: var(--destructive); }
}

/* radios: GOV.UK radios; Basecoat radio group (Vega) */

.tun-radios {
  display: flex;
  flex-direction: column;
  &[data-inline] { flex-direction: row; flex-wrap: wrap; column-gap: calc(var(--spacing) * 6); }
  & > .tun-radios-item { display: flex; flex-direction: column; min-width: 0; }
  & > .tun-radios-item:has(> .tun-radios-hint):not(:last-child) {
    padding-bottom: calc(var(--spacing) * 2);
  }
  --tun-choice-size: calc(var(--spacing) * 4);
  @media (pointer: coarse) { --tun-choice-size: calc(var(--spacing) * 5); }
  & .tun-radios-label {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 2.5);
    width: fit-content;
    max-width: 100%;
    padding-block: calc((var(--control-height) - 1lh) / 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    cursor: pointer;
    touch-action: manipulation;
    &:has(> :disabled) { cursor: not-allowed; color: var(--muted-foreground); }
  }
  & .tun-radios-input {
    appearance: none;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: var(--tun-choice-size);
    height: var(--tun-choice-size);
    margin-top: calc((1lh - var(--tun-choice-size)) / 2);
    border: 1px solid var(--input);
    background-color: var(--input-background);
    outline: none;
    cursor: inherit;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    /* What is on takes the accent. */
    &:checked { border-color: var(--highlight); background-color: var(--highlight);
      color: var(--highlight-foreground); }
    &:focus-visible { box-shadow: var(--focus-ring); }
    &[aria-invalid='true']:not(:checked) { border-color: var(--destructive); }
    &[aria-invalid='true'] { box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent)); }
    &:disabled { opacity: 0.5; }
  }
  & .tun-radios-hint {
    margin-top: calc((1lh - var(--control-height)) / 2 + var(--spacing) * 0.5);
    padding-left: calc(var(--tun-choice-size) + var(--spacing) * 2.5);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-radios-input {
    border-radius: var(--radius-full);
    &:checked::before {
      content: '';
      width: calc(var(--tun-choice-size) / 2);
      height: calc(var(--tun-choice-size) / 2);
      border-radius: var(--radius-full);
      background-color: currentColor;
    }
  }
  &[data-invalid] .tun-radios-input { border-color: var(--destructive); }
}

/* switch: Basecoat switch (Vega); a checkbox with role switch */

.tun-switch {
  --tun-switch-width: calc(var(--spacing) * 8);
  --tun-switch-thumb: calc(var(--spacing) * 4);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: calc(var(--spacing) * 4);
  max-width: 40rem;
  @media (pointer: coarse) {
    --tun-switch-width: calc(var(--spacing) * 11);
    --tun-switch-thumb: calc(var(--spacing) * 5.5);
  }
  & > .tun-switch-label {
    grid-column: 1;
    padding-block: calc((var(--control-height) - 1lh) / 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    touch-action: manipulation;
  }
  & > .tun-switch-description {
    grid-column: 1;
    margin-top: calc((1lh - var(--control-height)) / 2);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & > .tun-switch-input {
    grid-column: 2;
    grid-row: 1 / span 2;
    appearance: none;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    width: var(--tun-switch-width);
    height: calc(var(--tun-switch-thumb) + 2.4px);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    background-color: var(--input);
    outline: none;
    cursor: pointer;
    transition-property: background-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &::before {
      content: '';
      display: block;
      width: var(--tun-switch-thumb);
      height: var(--tun-switch-thumb);
      border-radius: var(--radius-full);
      background-color: light-dark(var(--background), var(--foreground));
      pointer-events: none;
      transition: translate var(--duration) var(--ease);
    }
    &:checked { background-color: var(--highlight); }
    &:checked::before {
      translate: calc(var(--tun-switch-width) - var(--tun-switch-thumb) - 2px) 0;
      background-color: var(--highlight-foreground);
    }
    &:focus-visible { box-shadow: var(--focus-ring); }
    &:disabled { cursor: not-allowed; opacity: 0.5; }
  }
  &:has(> :disabled) > :is(.tun-switch-label, .tun-switch-description) { opacity: 0.5; }
  &:has(> :disabled) > .tun-switch-label { cursor: not-allowed; }
}

/* input-group: Basecoat input group (Vega); GOV.UK text input prefix and suffix */

.tun-input-group {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  height: var(--control-height);
  overflow: hidden;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-within { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &:has(> [aria-invalid='true']) {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:has(> :disabled) { cursor: not-allowed; opacity: 0.5; }
  & > .tun-input-group-control {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding-inline: calc(var(--spacing) * 2.5);
    border: 0;
    background-color: transparent;
    font-size: var(--control-font-size);
    outline: none;
    &::placeholder { color: var(--muted-foreground); }
    &:disabled { cursor: not-allowed; }
  }
  & > .tun-input-group-addon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    user-select: none;
    &:first-child { padding-left: calc(var(--spacing) * 2.5); }
    &:last-child { padding-right: calc(var(--spacing) * 2.5); }
  }
  & > .tun-input-group-addon:first-child + .tun-input-group-control {
    padding-left: calc(var(--spacing) * 1.5);
  }
  & > .tun-input-group-control:has(+ .tun-input-group-addon) {
    padding-right: calc(var(--spacing) * 1.5);
  }
  &[data-width] { width: fit-content; max-width: 100%; }
  &[data-width='2'] > .tun-input-group-control { width: calc(3ch + var(--spacing) * 4); }
  &[data-width='3'] > .tun-input-group-control { width: calc(4ch + var(--spacing) * 4); }
  &[data-width='4'] > .tun-input-group-control { width: calc(5ch + var(--spacing) * 4); }
  &[data-width='5'] > .tun-input-group-control { width: calc(6ch + var(--spacing) * 4); }
  &[data-width='10'] > .tun-input-group-control { width: calc(11ch + var(--spacing) * 4); }
  &[data-width='20'] > .tun-input-group-control { width: calc(21ch + var(--spacing) * 4); }
  &[data-width='30'] > .tun-input-group-control { width: calc(31ch + var(--spacing) * 4); }
}

/* error-summary: GOV.UK error summary; Designsystemet's wording; Basecoat alert (Vega) */

.tun-error-summary {
  max-width: 40rem;
  padding: calc(var(--spacing) * 4);
  border: 1px solid color-mix(in oklab, var(--destructive) 50%, var(--border));
  border-radius: var(--radius-lg);
  background-color: var(--card);
  color: var(--card-foreground);
  outline: none;
  &:focus-visible { box-shadow: var(--focus-ring); }
  & > .tun-error-summary-alert {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: calc(var(--spacing) * 3);
    & > .tun-icon {
      grid-row: 1 / span 2;
      margin-top: calc((1lh - 1rem) / 2);
      color: var(--destructive);
    }
  }
  & .tun-error-summary-title {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
    font-weight: var(--font-weight-semibold);
    color: var(--destructive);
  }
  & .tun-error-summary-body {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    margin-top: calc(var(--spacing) * 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-error-summary-list {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-error-summary-list a {
    color: var(--destructive);
    font-weight: var(--font-weight-medium);
    text-decoration-line: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
    @media (hover: hover) { &:hover { text-decoration-thickness: 2px; } }
    &:active { background-color: var(--pressed); }
  }
}

/* form-actions: GOV.UK button group; Basecoat button (Vega) */

.tun-form-actions {
  container-type: inline-size;
  & > .tun-form-actions-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: calc(var(--spacing) * 3);
  }
  & .tun-button { width: 100%; }
  & .tun-form-actions-cancel {
    display: inline-flex;
    align-self: center;
    align-items: center;
    min-height: var(--control-height);
    padding-inline: calc(var(--spacing) * 2);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    text-decoration-line: underline;
    text-underline-offset: 4px;
    @media (hover: hover) { &:hover { text-decoration-thickness: 2px; } }
    &:active { background-color: var(--pressed); }
  }
  @container (min-width: 30rem) {
    & > .tun-form-actions-row { flex-direction: row; flex-wrap: wrap; align-items: center; }
    & .tun-button { width: auto; }
  }
}

/* date-input: The owner's rules for an admin application, 2026-11 (the date field); WAI-ARIA date
picker dialog pattern; Basecoat input (Vega), its look */

.tun-date-input {
  position: relative;
  display: flex;
  width: 100%;
  /* A date as the longest language writes it, and the calendar's button. */
  max-width: calc(12ch + var(--spacing) * 5 + var(--control-height) + 2px);
  & .tun-date-input-control { font-variant-numeric: tabular-nums; }
  & .tun-date-input-open {
    display: none;
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0;
    align-items: center;
    justify-content: center;
    width: var(--control-height);
    border: 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background-color: transparent;
    color: var(--muted-foreground);
    outline: none;
    cursor: pointer;
    touch-action: manipulation;
    transition-property: background-color, color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    & .tun-icon { width: calc(var(--spacing) * 4); height: calc(var(--spacing) * 4); }
    &:focus-visible { box-shadow: var(--focus-ring-inset); }
    @media (hover: hover) { &:hover { background-color: var(--accent); color: var(--foreground); } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    &:disabled { cursor: not-allowed; opacity: 0.5; }
  }
  /* The calendar's button only where a script opens it. */
  @media (scripting: enabled) {
    & .tun-date-input-open { display: inline-flex; }
    & .tun-date-input-control { padding-inline-end: var(--control-height); }
  }

  /* The calendar: a popover under the field that rises a little as it fades
     in and sinks as it leaves. */
  & .tun-date-input-calendar {
    position: fixed;
    width: 20rem;
    max-width: calc(100vw - var(--spacing) * 4);
    max-height: calc(100dvh - var(--spacing) * 4);
    margin: auto;
    padding: calc(var(--spacing) * 3);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--popover);
    color: var(--popover-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    outline: none;
    opacity: 0;
    translate: 0 var(--spacing);
    transition-property: opacity, translate, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
    &:not(:popover-open) { pointer-events: none; }
    &:popover-open {
      opacity: 1;
      translate: none;
      transition-duration: var(--duration-fast);
      @starting-style { opacity: 0; translate: 0 var(--spacing); }
    }
    &::backdrop { background-color: transparent; }
    /* On a phone a floating sheet at the bottom, over the dim. */
    @media (max-width: 39.99rem) {
      inset: auto calc(var(--spacing) * 3) calc(var(--spacing) * 3 + env(safe-area-inset-bottom));
      width: auto;
      max-width: none;
      max-height: 85dvh;
      margin: 0;
      padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2) calc(var(--spacing) * 3);
      border-radius: var(--radius-xl);
      translate: 0 calc(var(--spacing) * 6);
      &:popover-open {
        transition-duration: var(--duration);
        @starting-style { opacity: 0; translate: 0 calc(var(--spacing) * 6); }
      }
      &::backdrop {
        background-color: var(--overlay);
        opacity: 0;
        transition-property: opacity, display, overlay;
        transition-duration: var(--duration-close);
        transition-timing-function: var(--ease);
        transition-behavior: allow-discrete;
      }
      &:popover-open::backdrop {
        opacity: 1;
        transition-duration: var(--duration);
        @starting-style { opacity: 0; }
      }
    }
  }
  /* Under the field where the browser can anchor it; the script places it
     elsewhere. */
  @media (min-width: 40rem) {
    @supports (anchor-scope: all) and (position-try-fallbacks: flip-block) {
      anchor-scope: --tun-date-input;
      anchor-name: --tun-date-input;
      & .tun-date-input-calendar {
        position-anchor: --tun-date-input;
        position-area: block-end span-inline-end;
        position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
        inset: auto;
        margin: var(--spacing) 0;
      }
    }
  }
  & .tun-date-input-calendar-head {
    display: flex;
    align-items: center;
    gap: var(--spacing);
    margin-bottom: calc(var(--spacing) * 2);
  }
  & .tun-date-input-calendar-title {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-semibold);
    text-wrap: nowrap;
  }
  & .tun-date-input-calendar-close {
    display: none;
    @media (max-width: 39.99rem) { display: block; }
  }
  & .tun-date-input-grid {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    & th {
      padding-block: var(--spacing);
      color: var(--muted-foreground);
      font-size: var(--text-xs);
      line-height: var(--text-xs--line-height);
      font-weight: var(--font-weight-normal);
      text-align: center;
    }
  }
  /* A day.  Today has a frame and the chosen day the ink fill, at the
     weight and size of the others: choosing moves nothing. */
  & .tun-date-input-day {
    height: calc(var(--spacing) * 10);
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    text-align: center;
    cursor: pointer;
    user-select: none;
    outline: none;
    touch-action: manipulation;
    transition-property: background-color, color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    @media (pointer: coarse) { height: calc(var(--spacing) * 11); }
    &[data-outside] { color: var(--muted-foreground); }
    &[aria-current='date'] { border-color: var(--border-strong); }
    &[aria-selected='true'] { background-color: var(--primary); color: var(--primary-foreground); }
    /* A day that cannot be chosen: faded and struck through, as in the
       source; 0.4 keeps the number legible. */
    &[aria-disabled='true'] { cursor: not-allowed; opacity: 0.4; text-decoration: line-through; }
    &:focus-visible { box-shadow: var(--focus-ring-inset); }
    @media (hover: hover) {
      &:hover:not([aria-disabled='true'], [aria-selected='true']) {
        background-color: var(--accent);
      }
    }
    &:active:not([aria-disabled='true'], [aria-selected='true']) {
      background-color: var(--pressed);
      transition-duration: 0s;
    }
  }
  & .tun-date-input-quick {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 2);
    margin-top: calc(var(--spacing) * 3);
  }
}

/* time-input: The owner's rules for an admin application, 2026-11 (the time field, without its
picker); Basecoat input (Vega), its look */

.tun-time-input { font-variant-numeric: tabular-nums; }

/* money-input: The owner's rules for an admin application, 2026-11 (amounts); Basecoat input group
(Vega), its look */

.tun-money-input {
  & > .tun-input-group-control { text-align: end; font-variant-numeric: tabular-nums; }
}

/* table: Basecoat table (Vega); dense rows that scroll on a phone after the owner's rules
for an admin application, 2026-11 */

.tun-table {
  container: tun-table / inline-size;
  width: 100%;
  /* The rows' own box scrolls sideways, never the page.  A soft shadow at
     an edge says there is more beyond it: the two covers scroll with the
     rows and hide the shadows at the very start and end. */
  & .tun-table-box {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    /* Literal sizes: the covers are wider than the shadows they hide. */
    background:
      linear-gradient(to right, var(--card) 30%, transparent) left / 2.5rem 100% no-repeat local,
      linear-gradient(to left, var(--card) 30%, transparent) right / 2.5rem 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%,
                      color-mix(in oklab, var(--foreground) 16%, transparent), transparent)
        left / 0.875rem 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%,
                      color-mix(in oklab, var(--foreground) 16%, transparent), transparent)
        right / 0.875rem 100% no-repeat scroll;
    background-color: var(--card);
  }
  & table {
    width: 100%;
    caption-side: top;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-variant-numeric: tabular-nums;
  }
  /* The caption is the table's title, above it as GOV.UK places it. */
  & caption {
    margin-bottom: calc(var(--spacing) * 3);
    color: var(--muted-foreground);
    font-weight: var(--font-weight-medium);
    text-align: start;
  }
  & caption[data-hidden] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  & thead tr, & tbody tr { border-bottom: 1px solid var(--border); }
  & tbody tr {
    transition: background-color var(--duration-fast) var(--ease);
    &:last-child { border-bottom: 0; }
  }
  & tfoot {
    border-top: 1px solid var(--border);
    background-color: color-mix(in oklab, var(--muted) 50%, transparent);
    font-weight: var(--font-weight-medium);
  }
  & th {
    height: calc(var(--spacing) * 10);
    padding-inline: calc(var(--spacing) * 2);
    color: var(--foreground);
    font-weight: var(--font-weight-medium);
    text-align: start;
    vertical-align: middle;
    white-space: nowrap;
  }
  & td {
    padding: calc(var(--spacing) * 2);
    vertical-align: middle;
    white-space: nowrap;
  }
  & :is(th, td)[data-align='end'] { text-align: end; }
  & .tun-table-sort {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing);
    border-radius: var(--radius-sm);
    text-decoration: none;
    & .tun-icon {
      width: calc(var(--spacing) * 3.5);
      height: calc(var(--spacing) * 3.5);
      color: var(--muted-foreground);
    }
    @media (hover: hover) {
      &:hover { text-decoration-line: underline; text-underline-offset: 4px; }
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  & th[aria-sort] .tun-table-sort .tun-icon { color: var(--foreground); }
  & :is(th, td)[data-align='center'] { text-align: center; }
  /* :min shrinks a column to its content, for dates, numbers and actions. */
  & th[data-width='min'] { width: 1%; }
  & th[data-width='sm'] { width: 6rem; }
  & th[data-width='md'] { width: 10rem; }
  & th[data-width='lg'] { width: 16rem; }
  & td[data-wrap] { min-width: 12rem; white-space: normal; }
  & .tun-table-empty td {
    padding-block: calc(var(--spacing) * 8);
    color: var(--muted-foreground);
    text-align: center;
    white-space: normal;
  }
  /* What the empty row says stays in the box's visible part, however wide
     the columns make the row. */
  & .tun-table-empty-text {
    position: sticky;
    inset-inline-start: calc(var(--spacing) * 2);
    max-width: calc(100cqi - var(--spacing) * 4);
  }
  @media (hover: hover) {
    & tbody tr:not(.tun-table-empty):hover { background-color: var(--accent); }
  }
  /* A row that opens a record answers while its link is pressed, and only
     then: pressing a control in the row presses the control. */
  & tbody tr[data-link]:has(.tun-table-row-link:active) {
    background-color: var(--pressed);
    transition-duration: 0s;
  }

  /* A row with a link: the first cell's link covers the whole row, so the
     row is one target and the link's text is its name. */
  & tr[data-link] {
    position: relative;
    & :is(a, button, input, select, textarea, label):not(.tun-table-row-link) {
      position: relative;
      z-index: 1;
    }
    @media (hover: hover) {
      &:hover .tun-table-row-link { text-decoration-line: underline; }
    }
  }
  & .tun-table-row-link {
    font-weight: var(--font-weight-medium);
    text-underline-offset: 4px;
    outline: none;
    &::after { content: ''; position: absolute; inset: 0; }
    /* The row fills its box, so its ring is drawn inside it. */
    &:focus-visible::after { box-shadow: var(--focus-ring-inset); }
  }
  /* A finger finds a row that leads somewhere. */
  @media (pointer: coarse) {
    & tbody tr[data-link] td { padding-block: calc(var(--spacing) * 3); }
  }

  /* A phone: the rows' box is one panel, and the first column's text keeps
     to two lines and half the box, so the next columns start in sight. */
  @container tun-table (width < 36rem) {
    & .tun-table-box {
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-panel);
    }
    & caption { padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2) 0; margin: 0; }
    & .tun-table-lead {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
      /* Its own width up to the cap: a short name never wraps, and where the
         columns do not fit then, the box scrolls. */
      width: max-content;
      max-width: min(16rem, 50cqi);
      white-space: normal;
      overflow-wrap: anywhere;
    }
    & td[data-wrap] { min-width: 10rem; }
    & :is(th, td)[data-narrow='false'] { display: none; }
  }
  /* An empty state brings its own space. */
  & .tun-table-empty td:has(.tun-empty-state) { padding: 0; }
}

/* summary-list: GOV.UK summary list, Basecoat look */

.tun-summary-list {
  container: tun-summary-list / inline-size;
  /* The facts are set apart by space alone, no line or box between them:
     one column on a phone, two from 30rem (a column is at least half the
     row less the gap, and at least 14rem). */
  display: grid;
  grid-template-columns: repeat(auto-fit,
                                minmax(max(14rem, calc((100% - var(--spacing) * 8) / 2)), 1fr));
  column-gap: calc(var(--spacing) * 8);
  row-gap: calc(var(--spacing) * 3);
  width: 100%;
  font-size: var(--text-running);
  line-height: var(--text-running--line-height);
  /* On a phone the label stands beside the value, the action under it.
     The label's column is the same in every row, so the values line up:
     10rem holds a label of about 20 characters, or half the row after the
     gap when that is less (spec/ui.md 6, summary-list). */
  & .tun-summary-list-row {
    display: grid;
    grid-template-columns: min(10rem, calc((100% - var(--spacing) * 4) / 2)) minmax(0, 1fr);
    grid-template-areas: 'key value' '. action';
    align-items: baseline;
    column-gap: calc(var(--spacing) * 4);
    row-gap: var(--spacing);
    min-width: 0;
  }
  /* A label longer than its column breaks, with a hyphen where the
     language has one, and never runs into its value. */
  & .tun-summary-list-key {
    grid-area: key;
    min-width: 0;
    color: var(--muted-foreground);
    hyphens: auto;
    overflow-wrap: break-word;
  }
  & .tun-summary-list-value {
    grid-area: value;
    min-width: 0;
    overflow-wrap: anywhere;
    & > p + p { margin-top: var(--spacing); }
  }
  & .tun-summary-list-action {
    grid-area: action;
    & a {
      font-weight: var(--font-weight-medium);
      text-decoration-line: underline;
      text-decoration-color: color-mix(in oklab, currentColor 40%, transparent);
      text-underline-offset: 4px;
      border-radius: var(--radius-sm);
      @media (hover: hover) {
        &:hover { text-decoration-color: currentColor; }
      }
      &:active { background-color: var(--pressed); }
    }
  }
  /* In two columns a fact's label stands above its value, its action
     beside the label. */
  @container tun-summary-list (width >= 30rem) {
    & .tun-summary-list-row {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: 'key action' 'value value';
      align-content: start;
      row-gap: calc(var(--spacing) * 0.5);
    }
    & .tun-summary-list-action { text-align: end; }
  }
  & .tun-summary-list-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* card: Basecoat card (Vega) */

.tun-card {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 6);
  padding-block: calc(var(--spacing) * 6);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background-color: var(--card);
  color: var(--card-foreground);
  font-size: var(--text-running);
  line-height: var(--text-running--line-height);
  box-shadow: var(--shadow-panel);
  & .tun-card-header {
    display: grid;
    grid-auto-rows: min-content;
    align-items: start;
    gap: var(--spacing);
    padding-inline: calc(var(--spacing) * 6);
    &:has(> .tun-card-action) { grid-template-columns: minmax(0, 1fr) auto; }
  }
  & .tun-card-title {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
    font-weight: var(--font-weight-medium);
    letter-spacing: normal;
  }
  & .tun-card-description { color: var(--muted-foreground); }
  & .tun-card-action {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    justify-self: end;
  }
  /* The card hides what overflows it, so a long word (a link in a message)
     breaks rather than being cut off on a phone. */
  & .tun-card-content { padding-inline: calc(var(--spacing) * 6); overflow-wrap: anywhere; }
  & .tun-card-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    padding-inline: calc(var(--spacing) * 6);
  }

  &[data-size='sm'] {
    gap: calc(var(--spacing) * 4);
    padding-block: calc(var(--spacing) * 4);
    & :is(.tun-card-header, .tun-card-content, .tun-card-footer) {
      padding-inline: calc(var(--spacing) * 4);
    }
    & .tun-card-title {
      font-size: var(--text-sm);
      line-height: var(--text-sm--line-height);
    }
  }

  /* A card that is a link: the title's link covers the card. */
  &[data-variant='link'] {
    position: relative;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    & :is(a, button, input, select, textarea, label):not(.tun-card-link) {
      position: relative;
      z-index: 1;
    }
    /* A tint of the text colour over the card's ground, as a button has. */
    @media (hover: hover) {
      &:hover {
        border-color: var(--border-strong);
        background-image: linear-gradient(var(--accent), var(--accent));
      }
    }
    /* Pressed, unless the press is on a control of its own. */
    &:active:not(:has(:is(a, button, input, select, textarea, label):not(.tun-card-link):active)) {
      background-image: linear-gradient(var(--pressed), var(--pressed));
      transition-duration: 0s;
    }
    &:has(.tun-card-link:focus-visible) { box-shadow: var(--focus-ring); }
  }
  & .tun-card-link {
    outline: none;
    &::after { content: ''; position: absolute; inset: 0; }
  }
}

/* stat: shadcn/ui dashboard cards, Basecoat card (Vega) */

.tun-stat {
  display: flex;
  flex: 1 1 11rem;
  flex-direction: column;
  align-self: stretch;
  gap: var(--spacing);
  min-width: 0;
  padding: calc(var(--spacing) * 5);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background-color: var(--card);
  color: var(--card-foreground);
  box-shadow: var(--shadow-panel);
  & .tun-stat-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(var(--spacing) * 2);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
  }
  & .tun-stat-value {
    font-size: var(--text-2xl);
    line-height: var(--text-2xl--line-height);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.025em;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
  }
  & .tun-stat-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: calc(var(--spacing) * 1.5);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
  }
  & .tun-stat-change {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing);
    font-weight: var(--font-weight-medium);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    &[data-variant='success'] { color: var(--success); }
    &[data-variant='destructive'] { color: var(--destructive); }
    &[data-variant='neutral'] { color: var(--foreground); }
  }
}

/* empty-state: Basecoat empty (Vega) */

.tun-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--spacing) * 4);
  width: 100%;
  min-width: 0;
  padding: calc(var(--spacing) * 8) calc(var(--spacing) * 4);
  border-radius: var(--radius-lg);
  text-align: center;
  text-wrap: balance;
  white-space: normal;
  &[data-variant='outline'] { border: 1px dashed var(--border); }
  & .tun-empty-state-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    max-width: 24rem;
  }
  & .tun-empty-state-media {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 12);
    height: calc(var(--spacing) * 12);
    margin-bottom: calc(var(--spacing) * 2);
    border-radius: var(--radius-full);
    background-color: var(--muted);
    color: var(--foreground);
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 6);
      height: calc(var(--spacing) * 6);
    }
  }
  & .tun-empty-state-title {
    color: var(--foreground);
    font-size: var(--text-lg);
    line-height: var(--text-lg--line-height);
    font-weight: var(--font-weight-medium);
    letter-spacing: -0.0125em;
  }
  & .tun-empty-state-description {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: 1.625;
  }
  & .tun-empty-state-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: calc(var(--spacing) * 2);
  }
  @media (min-width: 40rem) {
    & { padding: calc(var(--spacing) * 12); }
  }
}

/* pagination: Basecoat pagination (Vega); wording from Designsystemet */

.tun-pagination {
  container: tun-pagination / inline-size;
  width: 100%;
  & .tun-pagination-list {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing);
  }
  & .tun-pagination-page .tun-button {
    width: auto;
    min-width: var(--control-height);
    padding-inline: calc(var(--spacing) * 2);
    font-variant-numeric: tabular-nums;
  }
  & .tun-pagination-gap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--control-height);
    height: var(--control-height);
    color: var(--muted-foreground);
  }
  & .tun-pagination-status {
    display: none;
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  & .tun-pagination-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  @container tun-pagination (width < 30rem) {
    & .tun-pagination-list { justify-content: space-between; }
    & :is(.tun-pagination-page, .tun-pagination-gap) { display: none; }
    & .tun-pagination-status { display: block; }
  }
}

/* timeline: shadcn/ui activity feed, Basecoat look */

.tun-timeline {
  display: flex;
  flex-direction: column;
  font-size: var(--text-running);
  line-height: var(--text-running--line-height);
  & .tun-timeline-entry {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: calc(var(--spacing) * 3);
    padding-bottom: calc(var(--spacing) * 6);
    &:last-child { padding-bottom: 0; }
    /* The line from this entry's marker down to the next one's. */
    &:not(:last-child)::before {
      content: '';
      position: absolute;
      top: calc(var(--spacing) * 9);
      bottom: var(--spacing);
      inset-inline-start: calc(var(--spacing) * 4 - 0.5px);
      width: 1px;
      background-color: var(--border);
    }
  }
  & .tun-timeline-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 8);
    height: calc(var(--spacing) * 8);
    border-radius: var(--radius-full);
    background-color: var(--muted);
    color: var(--muted-foreground);
    &[data-variant='success'] { background-color: var(--success-soft); color: var(--success); }
    &[data-variant='info'] { background-color: var(--info-soft); color: var(--info); }
    &[data-variant='warning'] { background-color: var(--warning-soft); color: var(--warning); }
    &[data-variant='destructive'] {
      background-color: var(--destructive-soft);
      color: var(--destructive);
    }
  }
  & .tun-timeline-dot {
    width: calc(var(--spacing) * 2);
    height: calc(var(--spacing) * 2);
    border-radius: var(--radius-full);
    background-color: currentColor;
  }
  & .tun-timeline-body {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 0.5);
    min-width: 0;
    padding-top: calc(var(--spacing) * 1.5);
  }
  & .tun-timeline-text { overflow-wrap: anywhere; }
  & .tun-timeline-actor { font-weight: var(--font-weight-medium); }
  & .tun-timeline-time {
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-variant-numeric: tabular-nums;
  }
  & .tun-timeline-detail {
    margin-top: calc(var(--spacing) * 1.5);
    padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: color-mix(in oklab, var(--muted) 40%, transparent);
    overflow-wrap: anywhere;
  }
}

/* code-block: shadcn/ui code block, Basecoat look */

.tun-code-block {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: color-mix(in oklab, var(--muted) 60%, transparent);
  & .tun-code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(var(--spacing) * 2);
    min-height: calc(var(--spacing) * 10);
    padding-inline: calc(var(--spacing) * 4) calc(var(--spacing) * 1);
    border-bottom: 1px solid var(--border);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
  }
  & .tun-code-block-pre {
    overflow-x: auto;
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.7;
    tab-size: 2;
  }
  &[data-wrap] .tun-code-block-pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  & .tun-code-block-tools {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
  }
  /* Without a header the button stands beside the text, so text that
     scrolls sideways never runs under it. */
  &:has(> .tun-code-block-tools) { display: flex; align-items: flex-start; }
  & > .tun-code-block-pre { flex: 1; min-width: 0; }
  & > .tun-code-block-tools {
    position: relative;
    flex-shrink: 0;
    padding: calc(var(--spacing) * 1.5);
    & .tun-code-block-status {
      position: absolute;
      top: 50%;
      inset-inline-end: 100%;
      translate: 0 -50%;
      white-space: nowrap;
    }
    & .tun-code-block-status:not(:empty) {
      padding: calc(var(--spacing) * 0.5) calc(var(--spacing) * 2);
      border-radius: var(--radius-sm);
      background-color: var(--background);
      box-shadow: var(--shadow-xs);
    }
  }
  & .tun-code-block-status {
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
  }
  & [data-tun-copy] {
    & .tun-icon[data-state='done'] { display: none; }
    &[data-copied] .tun-icon[data-state='done'] { display: block; color: var(--success); }
    &[data-copied] .tun-icon[data-state='idle'] { display: none; }
  }
}

/* line-chart: shadcn/ui charts (look), drawn as plain SVG by Tun */

.tun-line-chart {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 3);
  width: 100%;
  min-width: 0;
  margin: 0;
  & .tun-line-chart-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: calc(var(--spacing) * 2);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
  }
  & .tun-line-chart-last {
    color: var(--foreground);
    font-weight: var(--font-weight-semibold);
    font-variant-numeric: tabular-nums;
  }
  & .tun-line-chart-body {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: 12rem auto;
    column-gap: calc(var(--spacing) * 2);
    row-gap: calc(var(--spacing) * 2);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-variant-numeric: tabular-nums;
  }
  /* The tick labels: items of no height, spread from the top to the
     bottom, stand where the evenly spaced gridlines are. */
  & .tun-line-chart-y {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
    & > span { display: flex; align-items: center; height: 0; white-space: nowrap; }
  }
  & .tun-line-chart-x {
    grid-column: 2;
    display: flex;
    justify-content: space-between;
    & > span { display: flex; justify-content: center; width: 0; white-space: nowrap; }
    & > span:first-child { justify-content: flex-start; }
    & > span:last-child:not(:first-child) { justify-content: flex-end; }
    & > span:only-child { justify-content: center; margin-inline: auto; }
  }
  & .tun-line-chart-plot {
    position: relative;
    min-width: 0;
    border-radius: var(--radius-sm);
    touch-action: pan-y;
    &:focus-visible { outline: none; box-shadow: var(--focus-ring); }
    & svg {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      overflow: visible;
    }
  }
  & .tun-line-chart-gridline { stroke: var(--border); stroke-width: 1px; }
  & .tun-line-chart-stroke {
    fill: none;
    stroke: var(--chart-1);
    stroke-width: 2px;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
  }
  & .tun-line-chart-wash { fill: color-mix(in oklab, var(--chart-1) 10%, transparent); }
  & .tun-line-chart-dot {
    fill: var(--chart-1);
    stroke: var(--card);
    stroke-width: 2px;
  }
  & .tun-line-chart-crosshair {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: var(--muted-foreground);
    pointer-events: none;
  }
  & .tun-line-chart-tooltip {
    position: absolute;
    top: 0;
    z-index: var(--z-dropdown);
    display: flex;
    flex-direction: column;
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2.5);
    border-radius: var(--radius-md);
    background-color: var(--popover);
    color: var(--muted-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    white-space: nowrap;
    pointer-events: none;
    &[hidden] { display: none; }
    & strong { color: var(--popover-foreground); font-weight: var(--font-weight-semibold); }
  }
  & .tun-line-chart-live {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  & .tun-line-chart-empty {
    display: grid;
    place-items: center;
    height: 12rem;
    margin: 0;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
  }
  & .tun-line-chart-table > summary {
    width: fit-content;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    cursor: pointer;
  }
  & .tun-line-chart-table[open] > summary { margin-block-end: calc(var(--spacing) * 2); }
}

/* sparkline: shadcn/ui charts (look), drawn as plain SVG by Tun */

.tun-sparkline {
  display: inline-block;
  width: 6rem;
  height: 1lh;
  overflow: visible;
  vertical-align: middle;
  & path {
    fill: none;
    stroke: var(--chart-1);
    stroke-width: 1.5px;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
  }
  /* A single point is a path of no length, whose round cap is a dot. */
  & path[data-dot] { stroke-width: 4px; }
}

/* alert: Basecoat alert (Vega), with Tun's status colours */

.tun-alert {
  /* The status variants set these two; the default variant does not use them. */
  --tun-alert-tone: var(--foreground);
  --tun-alert-soft: var(--card);
  display: flex;
  align-items: flex-start;
  gap: calc(var(--spacing) * 2.5);
  width: 100%;
  padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--card);
  color: var(--card-foreground);
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  text-align: start;
  & > .tun-icon {
    /* Centres the 16px icon on the first 20px line of text. */
    translate: 0 calc(var(--spacing) * 0.5);
    color: currentColor;
  }
  & .tun-alert-content {
    display: grid;
    flex: 1;
    min-width: 0;
    justify-items: start;
    gap: calc(var(--spacing) * 0.5);
  }
  & .tun-alert-title {
    font-weight: var(--font-weight-medium);
    overflow-wrap: break-word;
  }
  & .tun-alert-description {
    color: var(--muted-foreground);
    text-wrap: pretty;
    overflow-wrap: break-word;
    & p + p, & p + ul, & ul + p { margin-top: calc(var(--spacing) * 2); }
    & ul { padding-left: calc(var(--spacing) * 4); list-style: disc; }
    & a {
      color: inherit;
      text-decoration-line: underline;
      text-underline-offset: 3px;
      &:active { background-color: var(--pressed); }
    }
  }
  & .tun-alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 2);
    margin-top: calc(var(--spacing) * 2.5);
  }

  /* Status variants: a tinted background, the tone on icon and border, and
     text mixed from the tone and the foreground, which keeps at least 6:1
     against the tint in both themes (the pure tone on the tint does not:
     destructive is 4.4:1 in the light theme). */
  &[data-variant='info'] { --tun-alert-tone: var(--info); --tun-alert-soft: var(--info-soft); }
  &[data-variant='success'] {
    --tun-alert-tone: var(--success);
    --tun-alert-soft: var(--success-soft);
  }
  &[data-variant='warning'] {
    --tun-alert-tone: var(--warning);
    --tun-alert-soft: var(--warning-soft);
  }
  &[data-variant='destructive'] {
    --tun-alert-tone: var(--destructive);
    --tun-alert-soft: var(--destructive-soft);
  }
  &:not([data-variant='default']) {
    border-color: color-mix(in oklab, var(--tun-alert-tone) 30%, transparent);
    /* The soft tints are strong in the dark theme; mixing in the card
       colour calms them and only raises the contrast of the text. */
    background-color: light-dark(var(--tun-alert-soft),
                                 color-mix(in oklab, var(--tun-alert-soft) 60%, var(--card)));
    color: color-mix(in oklab, var(--tun-alert-tone) 80%, var(--foreground));
    & > .tun-icon { color: var(--tun-alert-tone); }
    & .tun-alert-description {
      color: color-mix(in oklab, var(--tun-alert-tone) 55%, var(--foreground));
    }
  }
}

/* flash: Basecoat alert (Vega); GOV.UK notification banner (a message after an action) */

.tun-flash {
  --tun-flash-tone: var(--success);
  --tun-flash-soft: var(--success-soft);
  display: flex;
  align-items: flex-start;
  gap: calc(var(--spacing) * 2.5);
  width: 100%;
  padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 3);
  border: 1px solid color-mix(in oklab, var(--tun-flash-tone) 30%, transparent);
  border-radius: var(--radius-lg);
  background-color: light-dark(var(--tun-flash-soft),
                               color-mix(in oklab, var(--tun-flash-soft) 60%, var(--card)));
  color: color-mix(in oklab, var(--tun-flash-tone) 80%, var(--foreground));
  box-shadow: var(--shadow-panel);
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  font-weight: var(--font-weight-medium);
  &[data-variant='info'] { --tun-flash-tone: var(--info); --tun-flash-soft: var(--info-soft); }
  &[data-variant='warning'] {
    --tun-flash-tone: var(--warning);
    --tun-flash-soft: var(--warning-soft);
  }
  &[data-variant='destructive'] {
    --tun-flash-tone: var(--destructive);
    --tun-flash-soft: var(--destructive-soft);
  }
  & > .tun-icon {
    translate: 0 calc(var(--spacing) * 0.5);
    color: var(--tun-flash-tone);
  }
  & .tun-flash-message {
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
    text-wrap: pretty;
    & a {
      color: inherit;
      text-decoration-line: underline;
      text-underline-offset: 3px;
      &:active { background-color: var(--pressed); }
    }
  }
  /* The close button keeps its full touch target but does not make the bar
     taller than a line of text with its padding. */
  & > [data-tun-flash-close] {
    margin-block: calc((var(--control-height) - var(--text-sm) * var(--text-sm--line-height))
                       / -2);
    margin-inline-end: calc(var(--spacing) * -1.5);
    color: inherit;
    @media (hover: hover) {
      &:hover { background-color: color-mix(in oklab, var(--tun-flash-tone) 15%, transparent); }
    }
    &:active { background-color: color-mix(in oklab, var(--tun-flash-tone) 25%, transparent); }
  }
  /* A toast where scripts run, from the first paint: over the page, not in
     its flow; the script lifts it into the top layer, over a dialog too. */
  @media (scripting: enabled) {
    &:not([data-placement='page']) {
      position: fixed;
      z-index: var(--z-toast);
      inset: auto calc(var(--spacing) * 4) calc(var(--spacing) * 4 + env(safe-area-inset-bottom));
      width: auto;
      height: auto;
      margin: 0;
      overflow: visible;
      box-shadow: 0 0 0 1px var(--border), var(--shadow-lg);
      transition-property: opacity, translate;
      transition-duration: var(--duration);
      transition-timing-function: var(--ease);
      @starting-style { opacity: 0; translate: 0 calc(var(--spacing) * 2); }
      &[data-tun-leaving] {
        opacity: 0;
        translate: 0 calc(var(--spacing) * 2);
        transition-duration: var(--duration-close);
      }
      @media (min-width: 40rem) {
        inset: calc(var(--spacing) * 4) calc(var(--spacing) * 4) auto auto;
        width: min(25rem, calc(100% - var(--spacing) * 8));
      }
    }
  }
}

/* confirm-panel: GOV.UK warning text and confirmation; Basecoat alert dialog (Vega) */

.tun-confirm-panel {
  container-type: inline-size;
  display: grid;
  gap: calc(var(--spacing) * 4);
  /* A width rather than max-width: a confirmation reads best at about the
     measure of a GOV.UK two-thirds column, also in a wide parent. */
  width: min(100%, 40rem);
  padding: calc(var(--spacing) * 5);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background-color: var(--card);
  color: var(--card-foreground);
  box-shadow: var(--shadow-panel);
  & .tun-confirm-panel-header {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
  }
  & .tun-confirm-panel-icon {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 10);
    height: calc(var(--spacing) * 10);
    border-radius: var(--radius-full);
    background-color: var(--muted);
    color: var(--foreground);
    & .tun-icon { width: calc(var(--spacing) * 5); height: calc(var(--spacing) * 5); }
  }
  &[data-variant='destructive'] .tun-confirm-panel-icon {
    background-color: var(--destructive-soft);
    color: var(--destructive);
  }
  & .tun-confirm-panel-title {
    font-size: var(--text-lg);
    line-height: var(--text-lg--line-height);
    font-weight: var(--font-weight-semibold);
    overflow-wrap: break-word;
  }
  & .tun-confirm-panel-body {
    display: grid;
    gap: calc(var(--spacing) * 3);
    color: var(--muted-foreground);
    font-size: var(--text-running);
    line-height: var(--text-running--line-height);
    text-wrap: pretty;
    overflow-wrap: break-word;
    & strong { color: var(--foreground); }
  }
  /* GOV.UK warning text: a bold sentence behind a round exclamation mark. */
  & .tun-confirm-panel-warning {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-semibold);
  }
  & .tun-confirm-panel-mark {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 7);
    height: calc(var(--spacing) * 7);
    border: 2px solid var(--foreground);
    border-radius: var(--radius-full);
    background-color: var(--foreground);
    color: var(--background);
    font-size: var(--text-base);
    line-height: 1;
    font-weight: var(--font-weight-bold);
    user-select: none;
    forced-color-adjust: none;
    @media (forced-colors: active) {
      border-color: CanvasText;
      background-color: Canvas;
      color: CanvasText;
    }
  }
  & .tun-confirm-panel-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  & .tun-confirm-panel-actions {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    padding-top: calc(var(--spacing) * 1);
  }
  @container (min-width: 28rem) {
    & .tun-confirm-panel-actions { flex-direction: row; flex-wrap: wrap; }
  }
}

/* progress: Basecoat progress (Vega), on the built-in <progress> element */

.tun-progress {
  display: grid;
  gap: calc(var(--spacing) * 2);
  width: 100%;
  & .tun-progress-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    column-gap: calc(var(--spacing) * 3);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-progress-label { font-weight: var(--font-weight-medium); }
  & .tun-progress-value {
    margin-inline-start: auto;
    color: var(--muted-foreground);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  & progress {
    display: block;
    appearance: none;
    width: 100%;
    height: calc(var(--spacing) * 1.5);
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-full);
    background-color: var(--muted);
    color: var(--primary);
  }
  & progress::-webkit-progress-bar { background-color: var(--muted); }
  & progress::-webkit-progress-value {
    border-radius: var(--radius-full);
    background-color: var(--primary);
    transition: inline-size var(--duration) var(--ease);
  }
  & progress::-moz-progress-bar {
    border-radius: var(--radius-full);
    background-color: var(--primary);
  }
  /* Indeterminate: a short bar that slides across.  Under reduced motion it
     stands still as stripes over the whole track instead. */
  & progress:indeterminate {
    background-image: linear-gradient(var(--primary), var(--primary));
    background-repeat: no-repeat;
    background-size: 40% 100%;
    background-position: 50% 0;
    /* A loop keeps an even easing of its own; --ease is for a change of state. */
    animation: tun-progress-slide 1.5s ease-in-out infinite;
    @media (prefers-reduced-motion: reduce) {
      background-image: repeating-linear-gradient(
        -45deg, color-mix(in oklab, var(--primary) 35%, transparent) 0 6px, transparent 6px 12px);
      background-size: auto;
    }
  }
  & progress:indeterminate::-webkit-progress-bar { background-color: transparent; }
  & progress:indeterminate::-moz-progress-bar { background-color: transparent; }
}
@keyframes tun-progress-slide {
  from { background-position: -70% 0; }
  to { background-position: 170% 0; }
}

/* spinner: Basecoat spinner (Lucide loader-circle) */

.tun-spinner {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--spacing) * 2);
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  & .tun-icon {
    animation: tun-spinner-spin 0.8s linear infinite;
  }
  &[data-size='sm'] .tun-icon { width: calc(var(--spacing) * 3); height: calc(var(--spacing) * 3); }
  &[data-size='lg'] .tun-icon { width: calc(var(--spacing) * 6); height: calc(var(--spacing) * 6); }
  &[data-size='xl'] .tun-icon { width: calc(var(--spacing) * 8); height: calc(var(--spacing) * 8); }
  & .tun-spinner-text { color: var(--muted-foreground); }
  & .tun-spinner-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
@keyframes tun-spinner-spin {
  to { rotate: 1turn; }
}

/* skeleton: Basecoat skeleton (Vega) */

.tun-skeleton {
  /* The height keywords set this; a circle uses it for its width too. */
  --tun-skeleton-height: calc(var(--spacing) * 4);
  display: block;
  width: 100%;
  max-width: 100%;
  height: var(--tun-skeleton-height);
  border-radius: var(--radius-md);
  background-color: var(--muted);
  animation: tun-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  &[data-shape='block'] {
    --tun-skeleton-height: calc(var(--spacing) * 24);
    border-radius: var(--radius-lg);
  }
  &[data-shape='circle'] {
    --tun-skeleton-height: calc(var(--spacing) * 10);
    flex-shrink: 0;
    width: var(--tun-skeleton-height);
    border-radius: var(--radius-full);
  }
  &[data-width='three-quarters'] { width: 75%; }
  &[data-width='two-thirds'] { width: 66.667%; }
  &[data-width='half'] { width: 50%; }
  &[data-width='third'] { width: 33.333%; }
  &[data-width='quarter'] { width: 25%; }
  &[data-width='xs'] { width: 3rem; }
  &[data-width='sm'] { width: 5rem; }
  &[data-width='md'] { width: 8rem; }
  &[data-width='lg'] { width: 12rem; }
  &[data-width='xl'] { width: 16rem; }
  &[data-height='xs'] { --tun-skeleton-height: calc(var(--spacing) * 3); }
  &[data-height='sm'] { --tun-skeleton-height: calc(var(--spacing) * 4); }
  &[data-height='md'] { --tun-skeleton-height: calc(var(--spacing) * 6); }
  &[data-height='lg'] { --tun-skeleton-height: calc(var(--spacing) * 10); }
  &[data-height='xl'] { --tun-skeleton-height: calc(var(--spacing) * 24); }
  &[data-height='2xl'] { --tun-skeleton-height: calc(var(--spacing) * 40); }

  &[data-shape='group'] {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    height: auto;
    border-radius: 0;
    background-color: transparent;
    animation: none;
    &[data-direction='row'] {
      flex-direction: row;
      align-items: center;
      gap: calc(var(--spacing) * 3);
    }
    /* A group in a row takes the room left beside its fixed shapes. */
    &[data-direction='row'] > [data-shape='group'] { flex: 1; min-width: 0; }
  }
  & .tun-skeleton-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
@keyframes tun-skeleton-pulse {
  50% { opacity: 0.5; }
}

/* dialog: Basecoat dialog and alert dialog (Vega) */

.tun-dialog {
  --tun-dialog-padding: calc(var(--spacing) * 4);
  /* A strip of the page shows above the highest dialog, so it reads as
     over the page. */
  --tun-dialog-strip: calc(var(--spacing) * 8);
  /* The window less what a keyboard covers (the script's
     --tun-visual-top and --tun-visual-bottom) and the strip. */
  --tun-dialog-max-height: calc(100% - var(--tun-visual-top, 0px)
                                - var(--tun-visual-bottom, 0px) - var(--tun-dialog-strip));
  /* On a phone the dialog is a sheet along the bottom edge of the part of
     the window the keyboard leaves. */
  inset-block: var(--tun-visual-top, 0px) var(--tun-visual-bottom, 0px);
  width: 100%;
  max-width: 100%;
  max-height: var(--tun-dialog-max-height);
  margin: auto 0 0;
  padding: var(--tun-dialog-padding);
  padding-bottom: max(var(--tun-dialog-padding), env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background-color: var(--popover);
  color: var(--popover-foreground);
  font-size: var(--text-running);
  line-height: var(--text-running--line-height);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-lg);
  /* Opening focuses a control in it; a ring around the whole of it would
     only be noise. */
  outline: none;
  /* Closed, and leaving: below the window.  A transition takes the
     duration of the state it goes to, so leaving is --duration-close. */
  translate: 0 100%;
  transition-property: opacity, translate, display, overlay;
  transition-duration: var(--duration-close);
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
  &:not([open]) { pointer-events: none; }
  &[open] {
    display: flex;
    translate: none;
    transition-duration: var(--duration-sheet);
    @starting-style { translate: 0 100%; }
  }
  &[open], & > .tun-dialog-form {
    flex-direction: column;
    gap: calc(var(--spacing) * 5);
    min-height: 0;
  }
  & > .tun-dialog-form { display: flex; flex: 1; }
  /* The page behind dims in one fade, darker while the dialog opens and
     lighter while it closes, never a second layer across it. */
  &::backdrop {
    background-color: var(--overlay);
    opacity: 0;
    transition-property: opacity, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
  }
  &[open]::backdrop {
    opacity: 1;
    transition-duration: var(--duration);
    @starting-style { opacity: 0; }
  }

  & .tun-dialog-header {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: calc(var(--spacing) * 1.5);
    padding-inline-end: calc(var(--spacing) * 10);
  }
  & .tun-dialog-title {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
    font-weight: var(--font-weight-medium);
    letter-spacing: normal;
    overflow-wrap: anywhere;
  }
  & .tun-dialog-description { color: var(--muted-foreground); }
  /* Only the body scrolls, between the header and the footer; the inset
     keeps the focus rings of its fields from being cut off. */
  & .tun-dialog-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: calc(var(--spacing) * -1);
    padding: var(--spacing);
    & > * + * { margin-top: calc(var(--spacing) * 3); }
  }
  /* On a phone the buttons share one row, the step last. */
  & .tun-dialog-footer {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 2);
    & > * { flex: 1 1 auto; }
  }
  & .tun-dialog-close {
    position: absolute;
    top: calc(var(--spacing) * 3);
    right: calc(var(--spacing) * 3);
  }

  &:is([data-variant='confirm'], [data-variant='destructive']) {
    & .tun-dialog-header { padding-inline-end: 0; }
    & .tun-dialog-title { font-size: var(--text-lg); line-height: var(--text-lg--line-height); }
  }
  & .tun-dialog-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 12);
    height: calc(var(--spacing) * 12);
    margin-bottom: calc(var(--spacing) * 2);
    border-radius: var(--radius-lg);
    background-color: var(--muted);
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 6);
      height: calc(var(--spacing) * 6);
    }
  }
  &[data-variant='destructive'] .tun-dialog-icon {
    background-color: var(--destructive-soft);
    color: var(--destructive);
  }

  /* A dialog to type in fills the phone from the start, so the keyboard
     moves only its bottom edge and never pushes its top off the screen. */
  @media (max-width: 39.99rem) {
    &:has(textarea, [role='combobox'], input:not([type='checkbox'], [type='radio'],
                                                [type='hidden'], [type='file'], [type='submit'],
                                                [type='button'], [type='reset'], [type='image'],
                                                [type='range'], [type='color'])) {
      height: var(--tun-dialog-max-height);
    }
  }

  /* From 40rem it is centred, and rises a little as it fades in. */
  @media (min-width: 40rem) {
    --tun-dialog-padding: calc(var(--spacing) * 6);
    width: calc(100% - var(--spacing) * 8);
    max-width: 28rem;
    margin: auto;
    border-radius: var(--radius-xl);
    opacity: 0;
    translate: 0 calc(var(--spacing) * 2);
    & .tun-dialog-close { top: calc(var(--spacing) * 4); right: calc(var(--spacing) * 4); }
    &[open] {
      opacity: 1;
      translate: none;
      transition-duration: var(--duration);
      @starting-style { opacity: 0; translate: 0 calc(var(--spacing) * 2); }
    }
    & .tun-dialog-footer {
      justify-content: flex-end;
      & > * { flex: none; }
    }
    /* A fixed box whatever it holds, so what changes inside as one types
       never moves its edges (spec/ui.md 6.4): 40rem by 36rem, less where
       the window is smaller. */
    &[data-size='large'] {
      width: min(40rem, calc(100% - var(--spacing) * 8));
      max-width: none;
      height: min(36rem, calc(100dvh - var(--spacing) * 16));
    }
    &:is([data-variant='confirm'], [data-variant='destructive']) {
      max-width: 32rem;
      & .tun-dialog-header:has(.tun-dialog-icon) {
        display: grid;
        grid-template-columns: auto 1fr;
        column-gap: calc(var(--spacing) * 5);
        & .tun-dialog-icon { grid-row: span 2; margin-bottom: 0; }
        & > :not(.tun-dialog-icon) { grid-column: 2; }
      }
    }
  }
}

/* confirm-dialog: Basecoat alert dialog (Vega); GOV.UK confirmation (the question names the record) */

.tun-confirm-dialog {
  /* Only the dialog inside it takes room, once it is open. */
  display: contents;
}

/* dropdown-menu: Basecoat dropdown menu (Vega), on the Popover API */

.tun-dropdown-menu {
  display: inline-flex;
  & .tun-dropdown-menu-content {
    min-width: 8rem;
    width: max-content;
    max-width: min(20rem, calc(100vw - var(--spacing) * 4));
    max-height: min(24rem, calc(100dvh - var(--spacing) * 4));
    margin: auto;
    padding: var(--spacing);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--popover);
    color: var(--popover-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    outline: none;
    /* Closed, and leaving: a little below its place, faded. */
    opacity: 0;
    translate: 0 var(--spacing);
    transition-property: opacity, translate, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
    &:not(:popover-open) { pointer-events: none; }
    &:popover-open {
      opacity: 1;
      translate: none;
      transition-duration: var(--duration-fast);
      @starting-style { opacity: 0; translate: 0 var(--spacing); }
    }
  }
  /* Under its button where the browser can anchor it; the script places it
     elsewhere, and without either the browser centres it on the screen. */
  @supports (anchor-scope: all) and (position-try-fallbacks: flip-block) {
    anchor-scope: --tun-dropdown-menu;
    & > .tun-button { anchor-name: --tun-dropdown-menu; }
    & .tun-dropdown-menu-content {
      position-anchor: --tun-dropdown-menu;
      position-area: block-end span-inline-end;
      position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
      inset: auto;
      margin: var(--spacing) 0;
      min-width: max(8rem, anchor-size(width));
    }
    &[data-align='end'] .tun-dropdown-menu-content {
      position-area: block-end span-inline-start;
    }
  }

  & .tun-dropdown-menu-item {
    display: flex;
    width: 100%;
    min-height: var(--control-height-sm);
    align-items: center;
    gap: calc(var(--spacing) * 2);
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    text-align: start;
    text-decoration: none;
    user-select: none;
    outline: none;
    &:focus { background-color: var(--accent); color: var(--accent-foreground); }
    @media (hover: hover) {
      &:hover { background-color: var(--accent); color: var(--accent-foreground); }
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    &:disabled, &[aria-disabled='true'] { pointer-events: none; opacity: 0.5; }
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
      color: var(--muted-foreground);
    }
    &[data-variant='destructive'] {
      color: var(--destructive);
      & .tun-icon { color: var(--destructive); }
      &:focus {
        background-color: light-dark(color-mix(in oklab, var(--destructive) 10%, transparent),
                                     color-mix(in oklab, var(--destructive) 20%, transparent));
        color: var(--destructive);
      }
      @media (hover: hover) {
        &:hover {
          background-color: light-dark(color-mix(in oklab, var(--destructive) 10%, transparent),
                                       color-mix(in oklab, var(--destructive) 20%, transparent));
        }
      }
    }
    @media (pointer: coarse) { min-height: var(--control-height); }
  }
  & .tun-dropdown-menu-text { flex: 1; min-width: 0; }
  & .tun-dropdown-menu-shortcut {
    margin-inline-start: auto;
    padding-inline-start: calc(var(--spacing) * 4);
    color: var(--muted-foreground);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
  }
  & .tun-dropdown-menu-heading {
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
  }
  & .tun-dropdown-menu-separator {
    height: 1px;
    margin: var(--spacing) calc(var(--spacing) * -1);
    background-color: var(--border);
  }
}

/* tooltip: Basecoat tooltip (Vega) */

.tun-tooltip {
  position: relative;
  display: inline-flex;
  & .tun-tooltip-content {
    position: absolute;
    z-index: var(--z-dropdown);
    bottom: 100%;
    left: 50%;
    width: max-content;
    max-width: min(16rem, calc(100vw - var(--spacing) * 4));
    margin-bottom: calc(var(--spacing) * 1.5);
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 3);
    border-radius: var(--radius-md);
    background-color: var(--foreground);
    color: var(--background);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-normal);
    text-align: start;
    white-space: normal;
    /* Where it stands (centred on its button), and hidden a little below
       it, faded, from where it rises. */
    --tun-tooltip-x: -50%;
    --tun-tooltip-y: 0px;
    visibility: hidden;
    opacity: 0;
    translate: var(--tun-tooltip-x) calc(var(--tun-tooltip-y) + var(--spacing));
    transition-property: opacity, translate, visibility;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
  }
  &[data-side='bottom'] .tun-tooltip-content {
    top: 100%;
    bottom: auto;
    margin: calc(var(--spacing) * 1.5) 0 0;
  }
  &:is([data-side='left'], [data-side='right']) .tun-tooltip-content {
    top: 50%;
    bottom: auto;
    margin: 0;
    --tun-tooltip-x: 0px;
    --tun-tooltip-y: -50%;
  }
  &[data-side='left'] .tun-tooltip-content {
    right: 100%;
    left: auto;
    margin-right: calc(var(--spacing) * 1.5);
  }
  &[data-side='right'] .tun-tooltip-content {
    left: 100%;
    margin-left: calc(var(--spacing) * 1.5);
  }
  /* Anchored where the browser can: fixed to the window, so it can never
     widen the page, and turned to another side when it does not fit. */
  @supports (anchor-scope: all) and (position-try-fallbacks: flip-block) {
    anchor-scope: --tun-tooltip;
    & > :first-child { anchor-name: --tun-tooltip; }
    &[data-side] .tun-tooltip-content {
      position: fixed;
      position-anchor: --tun-tooltip;
      inset: auto;
      margin: calc(var(--spacing) * 1.5);
      --tun-tooltip-x: 0px;
      --tun-tooltip-y: 0px;
    }
    &[data-side='top'] .tun-tooltip-content {
      position-area: top;
      position-try-fallbacks: top span-right, top span-left, flip-block,
        bottom span-right, bottom span-left;
    }
    &[data-side='bottom'] .tun-tooltip-content {
      position-area: bottom;
      position-try-fallbacks: bottom span-right, bottom span-left, flip-block,
        top span-right, top span-left;
    }
    &[data-side='left'] .tun-tooltip-content {
      position-area: left;
      position-try-fallbacks: flip-inline, top, bottom;
    }
    &[data-side='right'] .tun-tooltip-content {
      position-area: right;
      position-try-fallbacks: flip-inline, top, bottom;
    }
  }
  /* Hover only where there is a pointer that hovers: on a touch screen a tap
     would leave it standing. */
  @media (hover: hover) {
    &:not([data-dismissed]):hover .tun-tooltip-content {
      visibility: visible;
      opacity: 1;
      translate: var(--tun-tooltip-x) var(--tun-tooltip-y);
      transition-duration: var(--duration-fast);
    }
  }
  &:not([data-dismissed]):has(:focus-visible) .tun-tooltip-content {
    visibility: visible;
    opacity: 1;
    translate: var(--tun-tooltip-x) var(--tun-tooltip-y);
    transition-duration: var(--duration-fast);
  }
}

/* accordion: Basecoat accordion (Vega), on <details> */

.tun-accordion {
  display: flex;
  width: 100%;
  flex-direction: column;
  & .tun-accordion-item:not(:last-child) { border-bottom: 1px solid var(--border); }
  & .tun-accordion-trigger {
    display: flex;
    min-height: var(--control-height);
    align-items: flex-start;
    justify-content: space-between;
    gap: calc(var(--spacing) * 4);
    /* Room inside the focus ring, without moving the text off its edge. */
    margin-inline: calc(var(--spacing) * -2);
    padding: calc(var(--spacing) * 4) calc(var(--spacing) * 2);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    text-align: start;
    list-style: none;
    cursor: pointer;
    outline: none;
    transition-property: box-shadow, border-color, background-color;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &::-webkit-details-marker { display: none; }
    &:focus-visible { box-shadow: var(--focus-ring); }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    @media (hover: hover) {
      &:hover .tun-accordion-title {
        text-decoration-line: underline;
        text-underline-offset: 4px;
      }
    }
    & .tun-icon {
      margin-top: calc(var(--spacing) * 0.5);
      color: var(--muted-foreground);
      transition: rotate var(--duration) var(--ease);
    }
  }
  & .tun-accordion-item[open] > .tun-accordion-trigger .tun-icon { rotate: 180deg; }
  & .tun-accordion-content {
    padding-bottom: calc(var(--spacing) * 4);
    font-size: var(--text-running);
    line-height: var(--text-running--line-height);
    & > * + * { margin-top: calc(var(--spacing) * 3); }
  }
  /* An opening item's content rises and fades in, by opacity and
     translate alone; its room opens at once, so nothing around it slides.
     Closing is at once.  An animation, not a transition: the content has
     no earlier style to move from when [open] starts to match. */
  @media (prefers-reduced-motion: no-preference) {
    & .tun-accordion-item[open] > .tun-accordion-content {
      animation: tun-accordion-open var(--duration) var(--ease) backwards;
    }
  }
}

@keyframes tun-accordion-open {
  from { opacity: 0; translate: 0 var(--spacing); }
}

/* tabs: Basecoat tabs (Vega); without JavaScript as GOV.UK tabs */

.tun-tabs {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: calc(var(--spacing) * 2);
  /* A strip in a frame on whatever ground it stands on: the page, a card
     or the chrome. */
  & .tun-tabs-list {
    display: flex;
    width: fit-content;
    max-width: 100%;
    height: var(--control-height);
    align-items: center;
    gap: 2px;
    padding: 2px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--muted-foreground);
    scrollbar-width: none;
    & li { display: flex; height: 100%; flex: 1 0 auto; }
  }
  & .tun-tabs-tab {
    position: relative;
    display: inline-flex;
    height: 100%;
    flex: 1 0 auto;
    align-items: center;
    justify-content: center;
    gap: calc(var(--spacing) * 1.5);
    padding: var(--spacing) calc(var(--spacing) * 2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    text-decoration: none;
    outline: none;
    transition-property: color, background-color, box-shadow, border-color;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    @media (hover: hover) { &:hover { color: var(--foreground); } }
    &:focus-visible { box-shadow: var(--focus-ring); }
    & .tun-icon:not([data-size]) {
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
    }
    &:has(> .tun-icon:first-child) { padding-inline-start: calc(var(--spacing) * 1.5); }
    /* The chosen tab shows by its ground and frame, at the weight and size
       of the others, so choosing one moves nothing. */
    &:is([aria-selected='true'], [aria-current='page']) {
      border-color: var(--border);
      background-color: var(--secondary);
      color: var(--foreground);
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  &[data-variant='line'] {
    & .tun-tabs-list {
      width: 100%;
      gap: var(--spacing);
      padding: 0;
      border: 0;
      border-radius: 0;
      box-shadow: inset 0 -1px var(--border);
      /* Each tab its own width, side by side from the start of the row. */
      & li { flex-grow: 0; }
    }
    & .tun-tabs-tab {
      flex-grow: 0;
      border-radius: var(--radius-md) var(--radius-md) 0 0;
      &::after {
        content: '';
        position: absolute;
        inset: auto 0 -1px;
        height: 2px;
        background-color: var(--foreground);
        opacity: 0;
        transition: opacity var(--duration-fast) var(--ease);
      }
      &:is([aria-selected='true'], [aria-current='page']) {
        border-color: transparent;
        background-color: transparent;
        box-shadow: none;
        &::after { opacity: 1; }
      }
      &:focus-visible { box-shadow: var(--focus-ring-inset); }
    }
  }
  & .tun-tabs-panel {
    font-size: var(--text-running);
    line-height: var(--text-running--line-height);
    border-radius: var(--radius-sm);
    outline: none;
    &:focus-visible { box-shadow: var(--focus-ring); }
    & > * + * { margin-top: calc(var(--spacing) * 3); }
  }
  & .tun-tabs-heading {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
  }
  /* Without scripts the list cannot switch panels, so every panel shows
     under its own heading instead. */
  @media (scripting: none) {
    & > .tun-tabs-list[role='tablist'] { display: none; }
    & > .tun-tabs-panel + .tun-tabs-panel { margin-top: calc(var(--spacing) * 4); }
  }
  @media (scripting: enabled) {
    & > .tun-tabs-panel[data-selected='false'], & .tun-tabs-heading { display: none; }
  }
}

/* choice-options: Tun's own, after its owner's rules for an admin application, 2026-11 (select with
a search); WAI-ARIA listbox */

.tun-choice-options {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  & .tun-choice-options-option {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    min-height: var(--control-height);
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2.5);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    overflow-wrap: anywhere;
    cursor: default;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    &[hidden] { display: none; }
    /* The active option, the one Enter chooses: the ground of an option
       under a pointer and the frame of what is chosen, at the others'
       weight, size and padding. */
    &[aria-selected='true'] {
      background-color: var(--accent);
      box-shadow: inset 0 0 0 1px var(--border-strong);
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    & > .tun-icon {
      flex: none;
      margin-inline-start: auto;
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
      visibility: hidden;
    }
    /* The chosen option has its check mark. */
    &[data-chosen] > .tun-icon { visibility: visible; }
  }
  @media (hover: hover) {
    & .tun-choice-options-option:hover { background-color: var(--accent); }
  }
  & .tun-choice-options-more, & .tun-choice-options-none {
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 2.5);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    &[hidden] { display: none; }
  }
}

/* choice-input: The owner's rules for an admin application, 2026-11 (select with a search, its
clear button, opening upward); WAI-ARIA combobox and listbox; GOV.UK select */

.tun-choice-input {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 2);
  min-width: 0;
  /* What a script hides once it runs, and what it shows. */
  &[data-tun-ready] > .tun-choice-input-select,
  &[data-tun-ready] > .tun-choice-input-find { display: none; }
  &:not([data-tun-ready]) > .tun-choice-input-control,
  &:not([data-tun-ready]) > .tun-choice-input-popover { display: none; }
  & > .tun-choice-input-select {
    appearance: auto;
    display: block;
    width: 100%;
    min-width: 0;
    height: var(--control-height);
    padding: var(--spacing) calc(var(--spacing) * 2.5);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
  }
  & .tun-choice-input-control { position: relative; min-width: 0; }
  /* The button that reads as a field: the chosen text, else the
     placeholder muted, a chevron at the end. */
  & .tun-choice-input-trigger {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    height: var(--control-height);
    padding: var(--spacing) calc(var(--spacing) * 9) var(--spacing) calc(var(--spacing) * 2.5);
    text-align: start;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
    @media (hover: hover) {
      &:hover:not(:disabled) {
        background-image: linear-gradient(var(--accent), var(--accent));
      }
    }
    &:active:not(:disabled) {
      background-image: linear-gradient(var(--pressed), var(--pressed));
      transition-duration: 0s;
    }
  }
  & .tun-choice-input-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    &[data-empty] { color: var(--muted-foreground); }
  }
  & .tun-choice-input-chevron {
    position: absolute;
    top: 50%;
    inset-inline-end: calc(var(--spacing) * 2.5);
    translate: 0 -50%;
    display: flex;
    color: var(--muted-foreground);
    pointer-events: none;
  }
  /* The clear button, 2rem wide (the control's height on a touch screen),
     inside the field before its chevron. */
  & .tun-choice-input-clear {
    position: absolute;
    top: 50%;
    inset-inline-end: calc(var(--spacing) * 8);
    translate: 0 -50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 8);
    height: calc(var(--spacing) * 8);
    border: 0;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    outline: none;
    touch-action: manipulation;
    transition-property: background-color, color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &[hidden] { display: none; }
    & .tun-icon { width: calc(var(--spacing) * 4); height: calc(var(--spacing) * 4); }
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) {
      &:hover { background-color: var(--accent); color: var(--foreground); }
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    @media (pointer: coarse) {
      width: var(--control-height);
      height: var(--control-height);
    }
  }
  & .tun-choice-input-control:has(> .tun-choice-input-clear:not([hidden]))
    > .tun-choice-input-trigger {
    padding-inline-end: calc(var(--spacing) * 17);
    @media (pointer: coarse) {
      padding-inline-end: calc(var(--spacing) * 9 + var(--control-height));
    }
  }

  /* The list: a popover in the top layer, under the field, or above it
     with the text field last, placed by the script; it rises a little as
     it fades in and sinks as it leaves. */
  & .tun-choice-input-popover {
    position: fixed;
    inset: auto;
    flex-direction: column;
    gap: var(--spacing);
    margin: 0;
    padding: var(--spacing);
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--popover);
    color: var(--popover-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    overflow: hidden;
    opacity: 0;
    translate: 0 var(--spacing);
    transition-property: opacity, translate, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
    &:not(:popover-open) { pointer-events: none; }
    &:popover-open {
      display: flex;
      opacity: 1;
      translate: none;
      transition-duration: var(--duration-fast);
      @starting-style { opacity: 0; translate: 0 var(--spacing); }
    }
    &[data-above] { flex-direction: column-reverse; }
    &::backdrop { background-color: transparent; }
  }
  & .tun-choice-input-header { display: none; }
  & .tun-choice-input-list {
    flex: 1;
    min-height: 0;
    max-height: 18rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* On a phone the list is a floating sheet at the bottom of what a
     keyboard leaves of the window, over the dim, as high from the start
     as it will be, so the text field never moves. */
  @media (max-width: 39.99rem) {
    & .tun-choice-input-popover {
      inset: auto calc(var(--spacing) * 3)
             calc(var(--spacing) * 3
                  + max(var(--tun-visual-bottom, 0px), env(safe-area-inset-bottom)));
      width: auto;
      height: min(24rem, calc(100dvh - var(--tun-visual-top, 0px)
                                - var(--tun-visual-bottom, 0px) - var(--spacing) * 11));
      padding: calc(var(--spacing) * 3);
      gap: calc(var(--spacing) * 2);
      border-radius: var(--radius-xl);
      translate: 0 calc(var(--spacing) * 6);
      &:popover-open {
        transition-duration: var(--duration);
        @starting-style { opacity: 0; translate: 0 calc(var(--spacing) * 6); }
      }
      &[data-above] { flex-direction: column; }
      &::backdrop {
        background-color: var(--overlay);
        opacity: 0;
        transition-property: opacity, display, overlay;
        transition-duration: var(--duration-close);
        transition-timing-function: var(--ease);
        transition-behavior: allow-discrete;
      }
      &:popover-open::backdrop {
        opacity: 1;
        transition-duration: var(--duration);
        @starting-style { opacity: 0; }
      }
    }
    & .tun-choice-input-header {
      display: flex;
      flex: none;
      align-items: center;
      justify-content: space-between;
      gap: calc(var(--spacing) * 2);
      font-size: var(--text-base);
      line-height: var(--text-base--line-height);
      font-weight: var(--font-weight-medium);
    }
    & .tun-choice-input-list { max-height: none; }
  }

  /* Without scripts, an asked choice's «Find» step. */
  & .tun-choice-input-find {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-choice-input-find-row {
    display: flex;
    gap: calc(var(--spacing) * 2);
    & > .tun-text-input { flex: 1; }
    & > .tun-button { flex: none; }
  }
  & .tun-choice-input-found {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-choice-input-find-label {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  /* The form's first submit button, which Enter presses: out of sight, but
     rendered, since some browsers press no default button that is not. */
  & .tun-choice-input-default {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
}

/* list-toolbar: The owner's rules for an admin application, 2026-11 (filter bar and sheet); the
popover and the dialog as Tun's own */

.tun-list-toolbar {
  container: tun-list-toolbar / inline-size;
  & .tun-list-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-list-toolbar-search {
    position: relative;
    flex: 1 1 100%;
    min-width: 0;
    & > .tun-icon {
      position: absolute;
      inset-inline-start: calc(var(--spacing) * 3);
      top: 50%;
      translate: 0 -50%;
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
      color: var(--muted-foreground);
      pointer-events: none;
    }
  }
  & .tun-list-toolbar-search-input {
    width: 100%;
    min-height: var(--control-height);
    padding: 0 calc(var(--spacing) * 3) 0 calc(var(--spacing) * 9);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  color: var(--foreground);
  font-size: var(--control-font-size);
  outline: none;
  transition-property: color, border-color, box-shadow;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  &:focus-visible { border-color: var(--ring); box-shadow: var(--focus-ring); }
  &[aria-invalid='true'] {
    border-color: light-dark(var(--destructive),
                             color-mix(in oklab, var(--destructive) 50%, transparent));
    box-shadow: 0 0 0 3px light-dark(color-mix(in oklab, var(--destructive) 20%, transparent),
                       color-mix(in oklab, var(--destructive) 40%, transparent));
  }
  &:disabled { cursor: not-allowed; opacity: 0.5; }
  }
  & .tun-list-toolbar-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }

  /* On a narrow toolbar the filters are one row under the search that
     scrolls in its own box, so a filter put into use widens only its own
     button and moves nothing below; the padding keeps focus rings whole. */
  & .tun-list-toolbar-filters {
    display: flex;
    flex: 1 1 100%;
    gap: calc(var(--spacing) * 2);
    min-width: 0;
    padding: var(--spacing);
    margin: calc(var(--spacing) * -1);
    overflow-x: auto;
  }
  & .tun-list-toolbar-filter { display: flex; flex: none; }

  /* The sheet is laid open in the row while it is not open as a dialog:
     the filters stand in it as buttons. */
  & .tun-dialog[data-tun-list-toolbar-sheet]:not([open]) {
    display: contents;
    pointer-events: auto;
    font-size: inherit;
    line-height: inherit;
    & > .tun-dialog-header, & > .tun-dialog-close { display: none; }
    & > .tun-dialog-body { display: contents; }
  }
  & .tun-button[data-tun-list-toolbar-fold] { display: none; }
  @container tun-list-toolbar (max-width: 39.99rem) {
    @media (scripting: enabled) {
      & .tun-dialog[data-tun-list-toolbar-sheet]:not([open]) { display: none; }
      & .tun-button[data-tun-list-toolbar-fold] { display: inline-flex; }
    }
  }
  & .tun-list-toolbar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: calc(var(--spacing) * 5);
    height: calc(var(--spacing) * 5);
    padding-inline: calc(var(--spacing) * 1.5);
    border-radius: var(--radius-full);
    background-color: var(--primary);
    color: var(--primary-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-variant-numeric: tabular-nums;
  }

  /* From 40rem the search and the filters share one row that never wraps.
     The search keeps its width while there is room, so a filter put into
     use moves only its own button and what follows it; when the row is
     full the search narrows first, to 12rem, and then the filters scroll
     in their own box. */
  @container tun-list-toolbar (min-width: 40rem) {
    & .tun-list-toolbar-row { flex-wrap: nowrap; }
    /* Shrinking a thousand times as readily as the filters, the search
       gives up its room first. */
    & .tun-list-toolbar-search { flex: 0 1000 24rem; min-width: 12rem; }
    & .tun-list-toolbar-filters { flex: 0 1 auto; }
    & .tun-list-toolbar-reset, & .tun-button[data-tun-list-toolbar-apply] { flex: none; }
  }

  /* A filter's button, and its clear joined to it in one frame.  In use it
     shows by its edge and its words, never by weight or size. */
  & .tun-list-toolbar-filter-control {
    display: inline-flex;
    align-items: stretch;
    height: var(--control-height);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--background);
  }
  & .tun-list-toolbar-filter[data-in-use] .tun-list-toolbar-filter-control {
    border-color: var(--border-strong);
  }
  & .tun-list-toolbar-filter-button {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    padding-inline: calc(var(--spacing) * 3) calc(var(--spacing) * 2.5);
    border: 0;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    touch-action: manipulation;
    transition-property: background-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    & .tun-icon {
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
      color: var(--muted-foreground);
    }
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) { &:hover { background-color: var(--accent); } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  & .tun-list-toolbar-filter[data-in-use] .tun-list-toolbar-filter-button {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  }
  & .tun-list-toolbar-filter-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--spacing) * 8);
    border-inline-start: 1px solid var(--border);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--muted-foreground);
    outline: none;
    touch-action: manipulation;
    transition-property: background-color, color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    & .tun-icon { width: calc(var(--spacing) * 4); height: calc(var(--spacing) * 4); }
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) { &:hover { background-color: var(--accent); color: var(--foreground); } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    @media (pointer: coarse) { width: var(--control-height); }
  }
  & .tun-list-toolbar-filter-heading { display: none; }

  /* A toggle is one button: a box to tick, drawn as the button it is. */
  & .tun-list-toolbar-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    height: var(--control-height);
    padding-inline: calc(var(--spacing) * 3) calc(var(--spacing) * 2.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--background);
    color: var(--foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    & .tun-icon {
      width: calc(var(--spacing) * 4);
      height: calc(var(--spacing) * 4);
      color: var(--muted-foreground);
    }
    & .tun-list-toolbar-toggle-on { display: none; }
    &:has(:checked) {
      border-color: var(--border-strong);
      background-color: var(--secondary);
      & .tun-list-toolbar-toggle-on { display: inline-flex; }
      & .tun-list-toolbar-toggle-off { display: none; }
    }
    &:has(:focus-visible) { box-shadow: var(--focus-ring); }
    @media (hover: hover) { &:hover { background-color: var(--accent); } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  & .tun-list-toolbar-toggle-input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }

  /* «Reset»: words, underlined. */
  & .tun-list-toolbar-reset {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height);
    padding-inline: var(--spacing);
    border-radius: var(--radius-sm);
    color: var(--foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    text-decoration: underline;
    text-underline-offset: 0.2em;
    white-space: nowrap;
    outline: none;
    touch-action: manipulation;
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) { &:hover { text-decoration-thickness: 2px; } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
  }
  /* «Apply» only where no script applies a choice at once. */
  & .tun-button[data-tun-list-toolbar-apply] {
    @media (scripting: enabled) { display: none; }
  }

  /* The choices: a popover under the button that rises a little as it
     fades in, sinks as it leaves. */
  & .tun-list-toolbar-choices {
    position: fixed;
    min-width: 12rem;
    width: max-content;
    max-width: min(22rem, calc(100vw - var(--spacing) * 4));
    max-height: min(28rem, calc(100dvh - var(--spacing) * 4));
    margin: auto;
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--popover);
    color: var(--popover-foreground);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-md);
    outline: none;
    opacity: 0;
    translate: 0 var(--spacing);
    transition-property: opacity, translate, display, overlay;
    transition-duration: var(--duration-close);
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
    &:not(:popover-open) { pointer-events: none; }
    &:popover-open {
      opacity: 1;
      translate: none;
      transition-duration: var(--duration-fast);
      @starting-style { opacity: 0; translate: 0 var(--spacing); }
    }
    &::backdrop { background-color: transparent; }
    & .tun-fieldset-legend {
      margin-bottom: var(--spacing);
      padding-inline-end: calc(var(--spacing) * 8);
    }
    & :is(.tun-radios-label, .tun-checkbox-label) { width: 100%; }
    /* On a phone the popover is a floating sheet at the bottom, over the
       dim, with its own close button. */
    @media (max-width: 39.99rem) {
      /* Above the bottom's safe area, and above a keyboard while one types
         in it (--tun-visual-bottom, written while it is open). */
      inset: auto calc(var(--spacing) * 3)
             calc(var(--spacing) * 3
                  + max(var(--tun-visual-bottom, 0px), env(safe-area-inset-bottom)));
      width: auto;
      min-width: 0;
      max-width: none;
      max-height: 75dvh;
      margin: 0;
      padding: calc(var(--spacing) * 4);
      border-radius: var(--radius-xl);
      translate: 0 calc(var(--spacing) * 6);
      &:popover-open {
        transition-duration: var(--duration);
        @starting-style { opacity: 0; translate: 0 calc(var(--spacing) * 6); }
      }
      &::backdrop {
        background-color: var(--overlay);
        opacity: 0;
        transition-property: opacity, display, overlay;
        transition-duration: var(--duration-close);
        transition-timing-function: var(--ease);
        transition-behavior: allow-discrete;
      }
      &:popover-open::backdrop {
        opacity: 1;
        transition-duration: var(--duration);
        @starting-style { opacity: 0; }
      }
    }
  }
  /* A period: its quick choices, a chosen one by its frame, and its two
     date fields. */
  & .tun-list-toolbar-quick {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-list-toolbar-quick-choice {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height-sm);
    padding-inline: calc(var(--spacing) * 3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--background);
    color: var(--foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    outline: none;
    touch-action: manipulation;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &[aria-current='true'] { border-color: var(--border-strong); background-color: var(--secondary); }
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) { &:hover { background-color: var(--accent); } }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    @media (pointer: coarse) { min-height: var(--control-height); }
  }
  & .tun-list-toolbar-period-fields { display: grid; gap: calc(var(--spacing) * 4); }
  @media (min-width: 40rem) {
    & .tun-list-toolbar-filter:is([data-kind='period'], [data-kind='choice'])
      .tun-list-toolbar-choices { width: 20rem; }
  }
  /* A record to choose: where a script runs, its text field and its list
     in place of the select and the find field. */
  & .tun-list-toolbar-filter[data-tun-ready] .tun-list-toolbar-choices > .tun-field,
  & .tun-list-toolbar-filter[data-tun-ready] .tun-list-toolbar-choice-find { display: none; }
  & .tun-list-toolbar-filter:not([data-tun-ready]) .tun-list-toolbar-choice { display: none; }
  & .tun-list-toolbar-choice {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-list-toolbar-choice-list {
    max-height: 15rem;
    margin: calc(var(--spacing) * -0.5);
    padding: calc(var(--spacing) * 0.5);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  & .tun-list-toolbar-choice-find {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    margin-top: calc(var(--spacing) * 3);
  }
  & .tun-list-toolbar-choice-found {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  /* On a phone the close button stands beside the text field. */
  @media (max-width: 39.99rem) {
    & .tun-list-toolbar-choices .tun-list-toolbar-choice > .tun-text-input {
      width: calc(100% - var(--spacing) * 9);
    }
  }
  & .tun-list-toolbar-choices-close {
    display: none;
    position: absolute;
    top: calc(var(--spacing) * 2);
    inset-inline-end: calc(var(--spacing) * 2);
    @media (max-width: 39.99rem) { display: block; }
  }
  /* Under its button where the browser can anchor it; the script places it
     elsewhere. */
  @media (min-width: 40rem) {
    @supports (anchor-scope: all) and (position-try-fallbacks: flip-block) {
      & .tun-list-toolbar-filter { anchor-scope: --tun-list-toolbar-filter; }
      & .tun-list-toolbar-filter-control { anchor-name: --tun-list-toolbar-filter; }
      & .tun-list-toolbar-choices {
        position-anchor: --tun-list-toolbar-filter;
        position-area: block-end span-inline-end;
        position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
        inset: auto;
        margin: var(--spacing) 0;
        min-width: max(12rem, anchor-size(width));
      }
    }
  }

  /* The «Filters» sheet: a row per filter, its choices under it in place
     of the popover. */
  & .tun-dialog[data-tun-list-toolbar-sheet][open] {
    & .tun-list-toolbar-filters {
      flex-direction: column;
      gap: calc(var(--spacing) * 5);
      padding: 0;
      margin: 0;
      overflow: visible;
    }
    & .tun-list-toolbar-filter { flex-direction: column; align-items: stretch; }
    & .tun-list-toolbar-filter-control { display: none; }
    & .tun-list-toolbar-filter-heading {
      display: flex;
      align-items: center;
      gap: calc(var(--spacing) * 2);
      min-height: var(--control-height);
      font-weight: var(--font-weight-medium);
      & .tun-list-toolbar-filter-value { color: var(--muted-foreground); }
      & .tun-list-toolbar-filter-clear {
        align-self: stretch;
        margin-inline-start: auto;
        border-inline-start: 0;
        border-radius: var(--radius-md);
      }
    }
    & .tun-list-toolbar-choices {
      display: block;
      position: static;
      inset: auto;
      width: auto;
      min-width: 0;
      max-width: none;
      max-height: none;
      margin: 0;
      padding: 0;
      overflow: visible;
      border-radius: 0;
      background-color: transparent;
      box-shadow: none;
      opacity: 1;
      translate: none;
      pointer-events: auto;
      & .tun-fieldset-legend {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
      }
    }
    & .tun-list-toolbar-choices-close { display: none; }
    & .tun-list-toolbar-choices .tun-list-toolbar-choice > .tun-text-input { width: 100%; }
    & .tun-list-toolbar-toggle { align-self: flex-start; }
  }
}

/* board: Tun's own, after GitHub Projects' board and Basecoat card (Vega) */

/* A board fills the height the page leaves it when the app shell gives it
   one (data-tun-fill, spec/ui.md 8): the shell sets --tun-fill-align to
   stretch the columns to that height and --tun-fill-max-height to none, so
   each column's cards take the rest of it.  Elsewhere a column is as tall
   as its cards, up to its own limit. */
.tun-board {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 3);
  min-width: 0;
  /* On a phone, a strip of page under the board, where a finger scrolls
     the page rather than a column's cards. */
  @media (max-width: 40rem) { padding-block-end: calc(var(--spacing) * 12); }
  & .tun-board-message:empty { display: none; }
  /* Where a card went, for screen readers (spec/ui.md 6.1). */
  & .tun-board-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
  /* Side by side, scrolling sideways in their own box; on a phone a column
     is nearly the screen's width, and the next one shows at the edge. */
  & .tun-board-columns {
    display: grid;
    flex: 1 1 auto;
    min-height: 0;
    grid-auto-flow: column;
    grid-auto-columns: minmax(15rem, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: var(--tun-fill-align, start);
    gap: calc(var(--spacing) * 3);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding-block-end: calc(var(--spacing) * 2);
    @media (max-width: 40rem) {
      grid-auto-columns: calc(100% - var(--spacing) * 10);
    }
  }
  /* While a card is dragged the columns do not snap, or each step the
     script scrolls them would be pulled back to the column's start. */
  &[data-tun-board-moving] .tun-board-columns { scroll-snap-type: none; }
  & .tun-board-column {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    padding: calc(var(--spacing) * 2);
    border-radius: var(--radius-lg);
    background-color: var(--muted);
    scroll-snap-align: start;
    transition-property: box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &[data-tun-board-over] { box-shadow: inset 0 0 0 2px var(--ring); }
  }
  & .tun-board-column-header {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    padding: var(--spacing);
  }
  & .tun-board-column-title {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-semibold);
  }
  & .tun-board-column-count {
    min-width: calc(var(--spacing) * 5);
    padding-inline: calc(var(--spacing) * 1.5);
    border-radius: var(--radius-full);
    background-color: var(--background);
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }
  /* A column shows its cards, or, with none, the text that says so.  A long
     column scrolls under its header, showing about ten cards, so what
     follows the board is not far down the page.  The padding keeps a
     card's ring and focus outline inside the scrolling box.  On a phone a
     column instead fills the screen but what must stay in view around it
     when the page is scrolled to its end: the app shell's sticky header
     (3.5rem and its border), the column's padding, heading and gap
     (2.75rem), and below it the columns' padding (0.5rem), the board's
     strip (3rem) and the shell's padding under its content (4rem). */
  & .tun-board-cards {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    max-height: var(--tun-fill-max-height, min(70dvh, 46rem));
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    margin: calc(var(--spacing) * -1);
    padding: var(--spacing);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    @media (max-width: 40rem) {
      max-height: var(--tun-fill-max-height, min(46rem, calc(100dvh - var(--spacing) * 55 - 1px)));
    }
  }
  & .tun-board-empty {
    padding: calc(var(--spacing) * 3) var(--spacing);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
  }
  & .tun-board-column:not(:has(.tun-board-card)) .tun-board-cards { display: none; }
  & .tun-board-column:has(.tun-board-card) .tun-board-empty { display: none; }

  & .tun-board-card {
    position: relative;
    display: grid;
    gap: calc(var(--spacing) * 2);
    padding: calc(var(--spacing) * 3);
    border-radius: var(--radius-md);
    background-color: var(--card);
    color: var(--card-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    box-shadow: 0 0 0 1px var(--border), var(--shadow-panel);
    &:has(.tun-board-card-title:focus-visible) {
      box-shadow: 0 0 0 1px var(--border), var(--focus-ring);
    }
    @media (hover: hover) {
      &:has(a.tun-board-card-title):hover {
        box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-panel);
      }
    }
    /* Pressed on its link: the tint of the text colour over its ground. */
    &:has(a.tun-board-card-title:active) {
      background-image: linear-gradient(var(--pressed), var(--pressed));
    }
  }
  /* A card that can be dragged: a press must not select its text or open
     the phone's menu for its link. */
  &[data-tun-board] .tun-board-card {
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  & .tun-board-card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: calc(var(--spacing) * 2);
  }
  & .tun-board-card-title {
    font-weight: var(--font-weight-medium);
    overflow-wrap: anywhere;
  }
  /* The title's link covers the card; the menu stays above it. */
  & a.tun-board-card-title {
    outline: none;
    &::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
  }
  & .tun-board-card-actions {
    position: relative;
    z-index: 1;
    margin: calc(var(--spacing) * -1.5) calc(var(--spacing) * -1.5) 0 0;
  }
  & .tun-board-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing);
  }
  & .tun-board-card-meta {
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
  }
  & .tun-board-card[data-tun-board-dragging] { opacity: 0.4; }
  /* The copy that follows the pointer; the script sets where. */
  & .tun-board-card[data-tun-board-ghost] {
    position: fixed;
    z-index: var(--z-dropdown);
    margin: 0;
    pointer-events: none;
    cursor: grabbing;
    rotate: 1.5deg;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 15%, transparent),
                var(--shadow-lg);
  }
}

/* file-input: GOV.UK file upload; drag, drop and paste from GOV.UK's multi-file upload pattern */

.tun-file-input {
  display: grid;
  /* One column as wide as the field's, never the control's own width: the
     browser's file control is wider than a 320 px phone's column. */
  grid-template-columns: minmax(0, 1fr);
  gap: calc(var(--spacing) * 2);
  padding: calc(var(--spacing) * 3);
  border: 1px dashed var(--input);
  border-radius: var(--radius-md);
  background-color: var(--input-background);
  transition-property: border-color, background-color;
  transition-duration: var(--duration-fast);
  &[data-dragging] {
    border-color: var(--ring);
    background-color: color-mix(in oklab, var(--accent) 60%, transparent);
  }
  &:has([aria-invalid='true']) { border-color: var(--destructive); }
  /* The browser's control lies transparent over the button and the line
     beside it: a click or a tap there is one on the control, which stays
     the control for the label, the keyboard and a screen reader. */
  & .tun-file-input-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    min-width: 0;
  }
  & .tun-file-input-control {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    opacity: 0;
    font-size: var(--control-font-size);
    cursor: pointer;
  }
  & .tun-file-input-button {
    display: inline-flex;
    flex: none;
    align-items: center;
    height: var(--control-height);
    padding-inline: calc(var(--spacing) * 3);
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    background-color: var(--background);
    color: var(--foreground);
    font-size: var(--control-font-size);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
  }
  & .tun-file-input-picker:has(.tun-file-input-control:focus-visible) .tun-file-input-button {
    box-shadow: var(--focus-ring);
  }
  @media (hover: hover) {
    & .tun-file-input-picker:hover .tun-file-input-button { background-color: var(--accent); }
  }
  & .tun-file-input-picker:active .tun-file-input-button {
    border-color: var(--border-strong);
    background-image: linear-gradient(var(--pressed), var(--pressed));
  }
  & .tun-file-input-status {
    min-width: 0;
    overflow: hidden;
    color: var(--muted-foreground);
    font-size: var(--control-font-size);
    text-overflow: ellipsis;
    white-space: nowrap;
    &[hidden] { display: none; }
  }
  & .tun-file-input-drop, & .tun-file-input-message {
    margin: 0;
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
  }
  & .tun-file-input-message:empty { display: none; }
  & .tun-file-input-message { color: var(--foreground); }
  & .tun-file-input-list {
    display: grid;
    gap: calc(var(--spacing) * 2);
    margin: 0;
    padding: 0;
    list-style: none;
    &:empty { display: none; }
  }
  & .tun-file-input-item {
    display: grid;
    grid-template-columns: calc(var(--spacing) * 12) minmax(0, 1fr) auto;
    align-items: center;
    gap: calc(var(--spacing) * 3);
  }
  & .tun-file-input-preview {
    width: calc(var(--spacing) * 12);
    height: calc(var(--spacing) * 12);
    border-radius: var(--radius-sm);
    background-color: var(--muted);
    object-fit: cover;
  }
  & span.tun-file-input-preview {
    display: grid;
    place-items: center;
    color: var(--muted-foreground);
  }
  & .tun-file-input-name {
    overflow: hidden;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  & .tun-file-input-size {
    display: block;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
  }
}

/* attachments: Designsystemet and Aksel file list; the dialog is the HTML <dialog> */

.tun-attachments {
  display: grid;
  gap: calc(var(--spacing) * 2);
  & .tun-attachments-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(7rem, 30%), 1fr));
    gap: calc(var(--spacing) * 3);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  & .tun-attachments-item { display: grid; gap: var(--spacing); min-width: 0; }
  & .tun-attachments-image, & .tun-attachments-file {
    display: grid;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--muted);
    color: var(--foreground);
    text-decoration: none;
    &:focus-visible { outline: none; box-shadow: var(--focus-ring); }
    @media (hover: hover) {
      &:hover { border-color: var(--border-strong); }
    }
    &:active {
      border-color: var(--border-strong);
      background-image: linear-gradient(var(--pressed), var(--pressed));
    }
  }
  & .tun-attachments-image img { width: 100%; height: 100%; object-fit: cover; }
  & .tun-attachments-file {
    place-content: center;
    justify-items: center;
    gap: var(--spacing);
    font-size: var(--text-xs);
  }
  & .tun-attachments-file-type { font-weight: var(--font-weight-semibold); }
  & .tun-attachments-size { color: var(--muted-foreground); }
  & .tun-attachments-caption {
    overflow: hidden;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  & .tun-attachments-empty { margin: 0; color: var(--muted-foreground); font-size: var(--text-sm); }
}

/* attachments-dialog:  */

.tun-attachments-dialog {
  /* The reset takes every margin away; a modal dialog is centred by its
     auto margins. */
  margin: auto;
  max-width: calc(100vw - var(--spacing) * 4);
  max-height: calc(100dvh - var(--spacing) * 4);
  padding: calc(var(--spacing) * 3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--popover);
  color: var(--popover-foreground);
  box-shadow: var(--shadow-lg);
  &::backdrop { background-color: color-mix(in oklab, black 60%, transparent); }
  &[open] { display: grid; gap: calc(var(--spacing) * 3); }
  & .tun-attachments-full {
    display: block;
    max-width: 100%;
    max-height: calc(100dvh - var(--spacing) * 24);
    margin-inline: auto;
    object-fit: contain;
  }
  & .tun-attachments-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: calc(var(--spacing) * 2);
    font-size: var(--text-sm);
  }
  & .tun-attachments-name { overflow-wrap: anywhere; }
  & .tun-attachments-actions { display: flex; gap: calc(var(--spacing) * 2); }
}

/* markdown: CommonMark 0.31 and GitHub's tables, a subset (spec/ui.md 6.2) */

.tun-markdown {
  container: tun-markdown / inline-size;
  min-width: 0;
  overflow-wrap: anywhere;
  & > * + * { margin-block-start: calc(var(--spacing) * 3); }
  & > * + :is(h2, h3, h4, h5, h6) { margin-block-start: calc(var(--spacing) * 5); }
  & :is(h2, h3, h4, h5, h6) {
    font-weight: var(--font-weight-semibold);
    line-height: 1.4;
  }
  & [data-level='1'] { font-size: var(--text-lg); }
  & [data-level='2'] { font-size: var(--text-base); }
  & :is(ul, ol) { padding-inline-start: 1.5em; }
  & ul { list-style: disc; }
  & ul ul { list-style: circle; }
  & ol { list-style: decimal; }
  & li::marker { color: var(--muted-foreground); }
  & li + li, & li > :is(ul, ol) { margin-block-start: var(--spacing); }
  & strong { font-weight: var(--font-weight-semibold); }
  & em { font-style: italic; }
  & hr { border: 0; border-block-start: 1px solid var(--border); }
  & :not(pre) > code {
    padding: 0.125em 0.375em;
    border-radius: var(--radius-sm);
    background-color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.875em;
  }
  /* Code keeps its lines; its box scrolls instead. */
  & .tun-code-block { overflow-wrap: normal; }
  /* A table's own box scrolls sideways, never the page.  A soft shadow at
     an edge says there is more beyond it: the two covers scroll with the
     rows and hide the shadows at the very start and end, as table's do. */
  & .tun-markdown-table {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    /* Literal sizes: the covers are wider than the shadows they hide. */
    background:
      linear-gradient(to right, var(--card) 30%, transparent) left / 2.5rem 100% no-repeat local,
      linear-gradient(to left, var(--card) 30%, transparent) right / 2.5rem 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%,
                      color-mix(in oklab, var(--foreground) 16%, transparent), transparent)
        left / 0.875rem 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%,
                      color-mix(in oklab, var(--foreground) 16%, transparent), transparent)
        right / 0.875rem 100% no-repeat scroll;
    & table {
      width: 100%;
      border-collapse: collapse;
      font-size: var(--text-sm);
      line-height: var(--text-sm--line-height);
    }
    & :is(th, td) {
      padding: calc(var(--spacing) * 2);
      border-block-end: 1px solid var(--border);
      text-align: start;
      vertical-align: top;
    }
    & th { font-weight: var(--font-weight-medium); }
    & :is(th, td)[data-align='center'] { text-align: center; }
    & :is(th, td)[data-align='end'] { text-align: end; }
  }
  /* Four columns or more keep their columns at every width, a phone's too,
     and their words whole: a cell keeps its own width up to 16rem (the
     cap of table's first column), and three quarters of the text's width,
     so a long one is read without scrolling, and wraps beyond it; where
     the columns do not fit the box scrolls. */
  & .tun-markdown-table[data-wide] {
    overflow-wrap: break-word;
    & td > .tun-markdown-table-value {
      display: block;
      width: max-content;
      max-width: min(16rem, 75cqi);
    }
  }
}

/* graph: Tun, in the look of shadcn/ui's cards and badges; a layered (Sugiyama) layout */

.tun-graph {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 3);
  width: 100%;
  min-width: 0;
  margin: 0;
  container-type: inline-size;
  & > figcaption {
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
  }
  /* The drawing scrolls in its own box; the padding keeps a ring or a
     focus outline inside it. */
  & .tun-graph-scroll {
    display: none;
    max-width: 100%;
    overflow-x: auto;
    padding: calc(var(--spacing) * 1.5);
  }
  /* The list: the gutter of rails beside a column of nodes 12rem to 40rem
     wide; below 12rem the list scrolls in its own box. */
  & .tun-graph-list {
    display: grid;
    grid-template-columns: auto minmax(12rem, 40rem);
    justify-content: start;
    max-width: 100%;
    overflow-x: auto;
    padding-block: calc(var(--spacing) * 1.5);
    padding-inline-end: calc(var(--spacing) * 1.5);
  }
  & .tun-graph-rails {
    height: 100%;
    overflow: visible;
    & path {
      fill: none;
      stroke: var(--muted-foreground);
      stroke-width: 1.5px;
      vector-effect: non-scaling-stroke;
    }
    & :is(circle, polygon) { fill: var(--muted-foreground); }
    & [data-back] path { stroke-dasharray: 4 3; }
  }
  & .tun-graph-list-nodes {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    & .tun-graph-node { width: auto; }
  }
  /* The columns' sizes are those the edges are drawn to (+GRAPH-NODE-WIDTH+
     and the others), so they are written from the same numbers. */
  & .tun-graph-canvas {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 3.0rem;
    width: max-content;
  }
  & .tun-graph-edges {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    & path {
      fill: none;
      stroke: var(--muted-foreground);
      stroke-width: 1.5px;
      vector-effect: non-scaling-stroke;
    }
    & polygon { fill: var(--muted-foreground); }
    & [data-back] path { stroke-dasharray: 4 3; }
  }
  & .tun-graph-layer {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 1.0rem;
    width: 14.0rem;
  }
  & .tun-graph-gap { flex: none; height: 6.5rem; }
  & .tun-graph-loose {
    display: flex;
    flex-wrap: wrap;
    gap: 1.0rem;
  }
  & .tun-graph-node {
    --tun-graph-tone: var(--muted-foreground);
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex: none;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--spacing);
    width: 14.0rem;
    height: 6.5rem;
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3);
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--tun-graph-tone);
    border-radius: var(--radius-md);
    background-color: var(--card);
    color: var(--card-foreground);
    box-shadow: var(--shadow-panel);
    &[data-state='active'] { --tun-graph-tone: var(--info); }
    &[data-state='done'] { --tun-graph-tone: var(--success); }
    &[data-state='waiting'] {
      --tun-graph-tone: var(--warning);
      background-color: var(--warning-soft);
    }
    &:is([data-state='failed'], [data-state='blocked']) {
      --tun-graph-tone: var(--destructive);
      background-color: var(--destructive-soft);
    }
    /* On a tinted box the second line takes the full text colour, for
       contrast. */
    &:is([data-state='waiting'], [data-state='failed'], [data-state='blocked'])
      .tun-graph-line { color: var(--foreground); }
    &[data-live] { box-shadow: 0 0 0 2px var(--info), var(--shadow-sm); }
    &:has(.tun-graph-link:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
    /* Pressed on its link: the tint of the text colour over its ground. */
    &:has(.tun-graph-link:active) {
      background-image: linear-gradient(var(--pressed), var(--pressed));
    }
    & a:not(.tun-graph-link) { position: relative; z-index: 1; }
  }
  /* Up to two lines of title, cut with an ellipsis after the second. */
  & .tun-graph-title {
    display: -webkit-box;
    flex: none;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    overflow-wrap: anywhere;
  }
  /* The title's link covers the box, as a card's does. */
  & .tun-graph-link {
    color: inherit;
    text-decoration: none;
    outline: none;
    &::after { content: ''; position: absolute; inset: 0; }
  }
  & .tun-graph-line {
    display: flex;
    align-items: center;
    gap: var(--spacing);
    min-width: 0;
    overflow: hidden;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    white-space: nowrap;
  }
  & .tun-graph-state {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    &::before {
      content: '';
      width: calc(var(--spacing) * 2);
      height: calc(var(--spacing) * 2);
      border-radius: var(--radius-full);
      background-color: var(--tun-graph-tone);
    }
  }
  & .tun-graph-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    &::before { content: '·'; margin-inline-end: var(--spacing); }
  }
  /* One line of badges: those that wrap to a second are out of sight
     whole, and a badge alone wider than the line ends in an ellipsis.
     Clipped, not hidden, so focus on a hidden badge's link cannot scroll
     the line half into view. */
  & .tun-graph-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing);
    height: calc(var(--spacing) * 5);
    overflow: clip;
    & > .tun-graph-badge-link { min-width: 0; max-width: 100%; }
    & .tun-badge { flex-shrink: 1; min-width: 0; max-width: 100%; }
  }
  & .tun-graph-badge-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  & .tun-graph-badges-cell { display: flex; flex-wrap: wrap; gap: var(--spacing); }
  & .tun-graph-badge-link {
    display: inline-flex;
    border-radius: var(--radius-full);
    text-decoration: none;
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
  }
  & .tun-badge[data-kind='ref'] { font-variant-numeric: tabular-nums; }
  /* Someone working there now.  The pulse is slow enough to read as a
     light, not an alarm, and stops when motion is reduced. */
  & .tun-graph-live {
    flex: none;
    width: calc(var(--spacing) * 1.5);
    height: calc(var(--spacing) * 1.5);
    border-radius: var(--radius-full);
    background-color: currentColor;
    /* A loop keeps an even easing of its own; --ease is for a change of state. */
    animation: tun-graph-pulse 1.6s ease-in-out infinite;
  }
  & .tun-graph-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
    user-select: none;
  }
  & .tun-graph-empty {
    display: grid;
    place-items: center;
    height: 8rem;
    margin: 0;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
  }
  & .tun-graph-table > summary {
    width: fit-content;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    cursor: pointer;
  }
  & .tun-graph-table[open] > summary { margin-block-end: calc(var(--spacing) * 2); }
  /* The figure's own width chooses the form: the list in a narrow box,
     the drawing from 40rem (spec/ui.md 6.3, «Two forms»).  Last, so it
     overrides the forms' own display. */
  @container (min-width: 40rem) {
    & .tun-graph-scroll { display: block; }
    & .tun-graph-list { display: none; }
  }
}
@keyframes tun-graph-pulse {
  50% { opacity: 0.35; }
}

/* search-results: Tun's own, after its owner's rules for an admin application, 2026-11 */

.tun-search-results {
  & .tun-search-results-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  & .tun-search-results-row {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    min-height: 2.75rem;
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2.5);
    border-radius: var(--radius-md);
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    &:focus-visible { outline: none; box-shadow: var(--focus-ring-inset); }
    /* The row Enter opens is chosen: the ground of a row under a pointer
       and the frame of what is chosen, at the others' weight, size and
       padding. */
    &[aria-selected='true'] {
      background-color: var(--accent);
      box-shadow: inset 0 0 0 1px var(--border-strong);
    }
    &:active { background-color: var(--pressed); transition: none; }
  }
  @media (hover: hover) {
    & .tun-search-results-row:hover { background-color: var(--accent); }
  }
  & .tun-search-results-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: calc(var(--spacing) * 8);
    height: calc(var(--spacing) * 8);
    border-radius: var(--radius-md);
    background-color: var(--soft);
    color: var(--muted-foreground);
  }
  & .tun-search-results-text { display: flex; flex-direction: column; min-width: 0; }
  & .tun-search-results-title {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    overflow-wrap: anywhere;
  }
  & .tun-search-results-meta {
    overflow: hidden;
    color: var(--muted-foreground);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* A match inside a word does not split it: a tint of the text colour
     and no padding (the accent is for focus and what is on, spec/ui.md
     2.1). */
  & mark {
    padding: 0;
    background-color: color-mix(in oklab, var(--foreground) 14%, transparent);
    color: inherit;
  }
  & .tun-search-results-empty {
    margin: 0;
    padding: calc(var(--spacing) * 6) calc(var(--spacing) * 3);
    color: var(--muted-foreground);
    text-align: center;
    overflow-wrap: anywhere;
  }
}

/* search-dialog: Tun's own, after its owner's rules for an admin application, 2026-11 */

.tun-search-dialog {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 3);
  height: 100%;
  min-height: 0;
  & .tun-search-dialog-form { flex: none; }
  /* Only the results scroll; the inset keeps the marked row's ring whole. */
  & .tun-search-dialog-results {
    flex: 1;
    min-height: 0;
    margin: calc(var(--spacing) * -0.5);
    padding: calc(var(--spacing) * 0.5);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* push-switch: Basecoat switch (Vega); asking for permission only from a user's tap, as WebKit and
web.dev recommend for Web Push */

.tun-push-switch {
  display: grid;
  gap: calc(var(--spacing) * 2);
  max-width: 40rem;
  & .tun-push-switch-status {
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    max-width: 65ch;
  }
  &[data-state='blocked'] .tun-push-switch-status,
  &[data-state='failed'] .tun-push-switch-status { color: var(--foreground); }
  & [data-tun-push-test] { justify-self: start; }
}

/* cluster: Every Layout cluster, Tailwind's flex utilities */

.tun-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--spacing) * 2);
  min-width: 0;
  &[data-gap='xs'] { gap: var(--spacing); }
  &[data-gap='md'] { gap: calc(var(--spacing) * 4); }
  &[data-gap='lg'] { gap: calc(var(--spacing) * 6); }
  &[data-gap='xl'] { gap: calc(var(--spacing) * 8); }
  &[data-justify='center'] { justify-content: center; }
  &[data-justify='end'] { justify-content: flex-end; }
  &[data-justify='between'] { justify-content: space-between; }
  &[data-align='start'] { align-items: flex-start; }
  &[data-align='end'] { align-items: flex-end; }
  &[data-align='baseline'] { align-items: baseline; }
  &[data-align='stretch'] { align-items: stretch; }
}

/* stack: Every Layout stack, Tailwind's spacing scale */

.tun-stack {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 4);
  min-width: 0;
  &[data-gap='xs'] { gap: var(--spacing); }
  &[data-gap='sm'] { gap: calc(var(--spacing) * 2); }
  &[data-gap='lg'] { gap: calc(var(--spacing) * 6); }
  &[data-gap='xl'] { gap: calc(var(--spacing) * 8); }
}

/* grid: Every Layout grid (auto-fit and minmax) */

.tun-grid {
  --tun-grid-min: 18rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--tun-grid-min), 100%), 1fr));
  gap: calc(var(--spacing) * 4);
  min-width: 0;
  &[data-min='xs'] { --tun-grid-min: 10rem; }
  &[data-min='sm'] { --tun-grid-min: 14rem; }
  &[data-min='lg'] { --tun-grid-min: 24rem; }
  &[data-gap='xs'] { gap: var(--spacing); }
  &[data-gap='sm'] { gap: calc(var(--spacing) * 2); }
  &[data-gap='lg'] { gap: calc(var(--spacing) * 6); }
  &[data-gap='xl'] { gap: calc(var(--spacing) * 8); }
}

/* breadcrumbs: Basecoat breadcrumb (Vega); GOV.UK back link on a phone */

.tun-breadcrumbs {
  container-type: inline-size;
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  color: var(--muted-foreground);
  & a {
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease);
    @media (hover: hover) {
      &:hover { color: var(--foreground); }
    }
    &:active { background-color: var(--pressed); }
  }
  & ol {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    overflow-wrap: anywhere;
  }
  & .tun-breadcrumbs-item,
  & .tun-breadcrumbs-separator {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
  }
  & .tun-breadcrumbs-separator {
    user-select: none;
    & .tun-icon { width: calc(var(--spacing) * 3.5); height: calc(var(--spacing) * 3.5); }
  }
  & [aria-current='page'] { color: var(--foreground); cursor: default; }
  & .tun-breadcrumbs-back {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    min-height: calc(var(--spacing) * 6);
    & .tun-icon { width: calc(var(--spacing) * 3.5); height: calc(var(--spacing) * 3.5); }
  }
  /* A whole trail rarely fits a phone, and the level above is the one
     people go back to.  Without a level above, the trail is all there is. */
  & ol:first-child { display: flex; }
  @container (min-width: 30rem) {
    & ol { display: flex; }
    & .tun-breadcrumbs-back { display: none; }
  }
}

/* nav-list: Basecoat sidebar menu (Vega); GOV.UK service navigation for aria-current */

.tun-nav-list {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 4);
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  & .tun-nav-list-group { display: flex; flex-direction: column; gap: var(--spacing); }
  & ul { display: flex; flex-direction: column; gap: var(--spacing); }
  & .tun-nav-list-heading {
    display: flex;
    align-items: center;
    min-height: calc(var(--spacing) * 8);
    padding-inline: calc(var(--spacing) * 2);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
    color: var(--muted-foreground);
  }
  & .tun-nav-list-link {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    min-height: calc(var(--spacing) * 8);
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--foreground);
    text-decoration: none;
    outline: none;
    transition-property: background-color, border-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) {
      &:hover { background-color: var(--accent); color: var(--accent-foreground); }
    }
    /* The current entry stands out as a panel of the page's ground in its
       frame, at the weight of the others, so marking it moves nothing. */
    &[aria-current] {
      border-color: var(--border);
      background-color: var(--background);
      box-shadow: var(--shadow-xs);
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    & .tun-icon { color: var(--muted-foreground); }
    &[aria-current] .tun-icon { color: var(--foreground); }
  }
  & .tun-nav-list-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  & .tun-nav-list-count {
    flex-shrink: 0;
    min-width: calc(var(--spacing) * 5);
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    font-weight: var(--font-weight-medium);
    font-variant-numeric: tabular-nums;
    text-align: end;
    color: var(--muted-foreground);
  }
  /* A finger needs the bigger target; the text grows with it. */
  @media (pointer: coarse) {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
    & .tun-nav-list-link { min-height: var(--control-height); }
    & .tun-nav-list-link .tun-icon {
      width: calc(var(--spacing) * 5);
      height: calc(var(--spacing) * 5);
    }
    & .tun-nav-list-count { font-size: var(--text-sm); }
  }
}

/* page-header: shadcn/ui dashboard page heading, in Basecoat's tokens; the owner's rules for an
admin application, 2026-11 */

.tun-page-header {
  container: tun-page-header / inline-size;
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 3);
  /* The title and the actions share one row at every width: the actions
     at the right edge, never wrapping; the title wraps beside them. */
  & .tun-page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: calc(var(--spacing) * 4);
  }
  & .tun-page-header-text {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: calc(var(--spacing) * 1.5);
    min-width: 0;
  }
  & .tun-page-header-title {
    font-size: var(--text-2xl);
    line-height: var(--text-2xl--line-height);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.025em;
    /* A word longer than the line breaks with a hyphen where the page's
       language has one for it, else anywhere. */
    hyphens: auto;
    overflow-wrap: anywhere;
  }
  & .tun-page-header-description { color: var(--muted-foreground); max-width: 65ch; }
  & .tun-page-header-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    color: var(--muted-foreground);
  }
  /* The actions stand on the title's first line: a control is as high as
     that line, near enough, so the two are centred on each other. */
  & .tun-page-header-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    min-height: var(--text-2xl--line-height);
  }
  & .tun-page-header-more { display: none; }
  /* A phone: what folds hides from the row and the menu holds it; a filled
     action that must give room shows its icon alone, its words its name. */
  @container tun-page-header (width < 40rem) {
    & .tun-page-header-actions > [data-tun-folded] { display: none; }
    & .tun-page-header-more { display: contents; }
    & .tun-page-header-actions [data-tun-compact] {
      width: var(--control-height);
      padding: 0;
      gap: 0;
      font-size: 0;
    }
  }
  @container tun-page-header (width >= 48rem) {
    & .tun-page-header-title {
      font-size: var(--text-3xl);
      line-height: var(--text-3xl--line-height);
    }
    & .tun-page-header-actions { min-height: var(--text-3xl--line-height); }
  }
}

/* section: Basecoat card header (Vega), without the card */

.tun-section {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) * 4);
  min-width: 0;
  & .tun-section-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: calc(var(--spacing) * 3);
  }
  & .tun-section-text {
    display: flex;
    flex: 1 1 18rem;
    flex-direction: column;
    gap: var(--spacing);
    min-width: 0;
  }
  & .tun-section-title {
    font-size: var(--text-lg);
    line-height: var(--text-lg--line-height);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.0125em;
    overflow-wrap: anywhere;
  }
  & h3.tun-section-title {
    font-size: var(--text-base);
    line-height: var(--text-base--line-height);
  }
  /* The part's live facts, in the look of the page header's. */
  & .tun-section-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    color: var(--muted-foreground);
  }
  & .tun-section-description {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    color: var(--muted-foreground);
    max-width: 65ch;
  }
  & .tun-section-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
  }
}

/* note: Tun's own, after its owner's rules for an admin application, 2026-11 */

.tun-note {
  margin: 0;
  max-width: 65ch;
  font-size: var(--text-sm);
  line-height: var(--text-sm--line-height);
  color: var(--muted-foreground);
  overflow-wrap: break-word;
}

/* section-links: GOV.UK contents list; the owner's rules for an admin application, 2026-11 */

.tun-section-links {
  min-width: 0;
  /* One line that scrolls in its own box.  The box reaches a link's
     padding past the row's edges, so the first link's words line up with
     the page's edge, and keeps 4px inside it, the focus ring's reach, so
     the ring is not cut off. */
  & ul {
    display: flex;
    gap: var(--spacing);
    margin: -4px calc(var(--spacing) * -2.5 - 4px);
    padding: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    white-space: nowrap;
  }
  & li { flex-shrink: 0; }
  & a {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height-sm);
    padding-inline: calc(var(--spacing) * 2.5);
    border-radius: var(--radius-md);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    text-decoration-line: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 2px;
    text-underline-offset: calc(var(--spacing) * 1.5);
    outline: none;
    transition-property: color, background-color, text-decoration-color, box-shadow;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease);
    &:focus-visible { box-shadow: var(--focus-ring); }
    @media (hover: hover) {
      &:hover { background-color: var(--accent); color: var(--foreground); }
    }
    &:active { background-color: var(--pressed); transition-duration: 0s; }
    /* The section in view: the text colour and an underline, at the weight
       and size of the others, so marking it moves nothing. */
    &[aria-current] { color: var(--foreground); text-decoration-color: currentColor; }
    @media (pointer: coarse) { min-height: var(--control-height); }
  }
}

/* app-shell: Basecoat sidebar (Vega); GOV.UK skip link and service navigation */

.tun-app-shell {
  position: relative;
  & .tun-app-shell-skip {
    position: absolute;
    top: calc(var(--spacing) * 2);
    left: calc(var(--spacing) * 2);
    z-index: calc(var(--z-sticky) + 1);
    padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 4);
    border-radius: var(--radius-md);
    background-color: var(--primary);
    color: var(--primary-foreground);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    box-shadow: var(--shadow-lg);
    &:not(:focus) {
      clip-path: inset(50%);
      width: 1px;
      height: 1px;
      padding: 0;
      overflow: hidden;
      white-space: nowrap;
    }
  }

  /* The loading sign (spec/ui.md 4.1): a thin bar across the top of the
     window while a person's htmx request goes unanswered, its short part
     sliding across; under reduced motion it stands still as stripes. */
  & .tun-app-shell-loading {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: var(--z-toast);
    height: 3px;
    overflow: hidden;
    background-color: color-mix(in oklab, var(--primary) 20%, transparent);
    background-image: linear-gradient(var(--primary), var(--primary));
    background-repeat: no-repeat;
    background-size: 40% 100%;
    pointer-events: none;
    /* A loop keeps an even easing of its own; --ease is for a change of state. */
    animation: tun-app-shell-loading 1.2s ease-in-out infinite;
    &[hidden] { display: none; }
    @media (prefers-reduced-motion: reduce) {
      animation: none;
      background-image: repeating-linear-gradient(
        -45deg, var(--primary) 0 6px, transparent 6px 12px);
      background-size: auto;
    }
  }
  & .tun-app-shell-loading-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* The top bar, the sidebar and the phone's menu stand on the chrome
     ground; a focus ring there leaves its gap in that ground. */
  & .tun-app-shell-header {
    --focus-ring: 0 0 0 2px var(--chrome), 0 0 0 4px var(--ring);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    border-bottom: 1px solid var(--chrome-border);
    /* The chrome itself, not a tint: an installed app's theme colour is
       this ground, so the phone's status bar and the bar are one surface. */
    background-color: var(--chrome);
  }
  & .tun-app-shell-bar {
    display: flex;
    align-items: center;
    gap: var(--spacing);
    height: calc(var(--spacing) * 14);
    padding-inline: var(--spacing) calc(var(--spacing) * 4);
  }
  & .tun-app-shell-title {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 2.5);
    min-width: 0;
    padding: var(--spacing);
    border-radius: var(--radius-md);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
  }
  & .tun-app-shell-mark {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: calc(var(--spacing) * 7);
    height: calc(var(--spacing) * 7);
    border-radius: var(--radius-md);
    background-color: var(--primary);
    color: var(--primary-foreground);
    font-size: var(--text-sm);
  }
  & .tun-app-shell-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  & .tun-app-shell-bar > [data-tun-search-open] { margin-inline-start: auto; }

  /* The search's row at the top of the sidebar reads as a field, its keys
     at its end; on a phone the top bar's button stands for it. */
  & .tun-app-shell-search { display: none; }
  & .tun-app-shell-search-row {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    height: var(--control-height);
    padding-inline: calc(var(--spacing) * 2.5) calc(var(--spacing) * 1.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--input-background);
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    text-decoration: none;
    & > .tun-kbd { margin-inline-start: auto; }
    &:focus-visible { outline: none; box-shadow: var(--focus-ring); }
    &:active { background-color: var(--pressed); transition: none; }
  }
  @media (hover: hover) {
    & .tun-app-shell-search-row:hover { border-color: var(--border-strong); }
  }

  /* On a phone the menu is a popover: a panel that slides in from the left
     over a dimmed page, opened by the menu button without any script. */
  & .tun-app-shell-panel {
    position: fixed;
    inset: 0 auto 0 0;
    flex-direction: column;
    width: min(20rem, calc(100vw - calc(var(--spacing) * 12)));
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--chrome-border);
    background-color: var(--chrome);
    color: var(--foreground);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    translate: -100% 0;
    transition: translate var(--duration) var(--ease),
                display var(--duration) allow-discrete,
                overlay var(--duration) allow-discrete;
    &:popover-open {
      display: flex;
      translate: 0 0;
      @starting-style { translate: -100% 0; }
    }
    &::backdrop {
      background-color: var(--overlay);
      opacity: 0;
      transition: opacity var(--duration) var(--ease),
                  display var(--duration) allow-discrete,
                  overlay var(--duration) allow-discrete;
    }
    &:popover-open::backdrop {
      opacity: 1;
      @starting-style { opacity: 0; }
    }
  }
  & .tun-app-shell-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    height: calc(var(--spacing) * 14);
    padding-inline: calc(var(--spacing) * 4) var(--spacing);
    border-bottom: 1px solid var(--chrome-border);
    font-weight: var(--font-weight-semibold);
  }
  & .tun-app-shell-nav {
    flex: 1;
    min-height: 0;
    padding: calc(var(--spacing) * 3);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  & .tun-app-shell-account {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 3);
    flex-shrink: 0;
    padding: calc(var(--spacing) * 4);
    padding-bottom: max(calc(var(--spacing) * 4), env(safe-area-inset-bottom));
    border-top: 1px solid var(--chrome-border);
  }
  & .tun-app-shell-user {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    min-width: 0;
  }
  & .tun-app-shell-avatar {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: calc(var(--spacing) * 9);
    height: calc(var(--spacing) * 9);
    border-radius: var(--radius-full);
    background-color: var(--muted);
    color: var(--muted-foreground);
  }
  & .tun-app-shell-who { display: flex; flex-direction: column; min-width: 0; }
  & .tun-app-shell-signed-in {
    font-size: var(--text-xs);
    line-height: var(--text-xs--line-height);
    color: var(--muted-foreground);
  }
  & .tun-app-shell-name {
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    font-weight: var(--font-weight-medium);
    overflow-wrap: anywhere;
  }
  & .tun-app-shell-logout { display: grid; }

  & .tun-app-shell-main {
    min-width: 0;
    &:focus { outline: none; }
    /* Below the sticky header, a jump to an id lands in view. */
    & [id] { scroll-margin-top: calc(var(--spacing) * 18); }
  }
  & .tun-app-shell-content {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 8);
    width: 100%;
    max-width: 72rem;
    margin-inline: auto;
    padding: calc(var(--spacing) * 6) calc(var(--spacing) * 4) calc(var(--spacing) * 16);
  }
  @media (min-width: 48rem) {
    & .tun-app-shell-content { padding-inline: calc(var(--spacing) * 8); }
  }
  @media (min-width: 64rem) {
    & .tun-app-shell-content {
      padding: calc(var(--spacing) * 10) calc(var(--spacing) * 10) calc(var(--spacing) * 16);
    }
  }
  /* A large screen: a little wider, with more air at the sides. */
  @media (min-width: 90rem) {
    & .tun-app-shell-content { max-width: 84rem; padding-inline: calc(var(--spacing) * 12); }
  }
  @media (min-width: 120rem) {
    & .tun-app-shell-content { padding-inline: calc(var(--spacing) * 16); }
  }
  & .tun-app-shell-content[data-width='narrow'] { max-width: 32rem; }
  /* A page that needs the room, such as a board: the whole width. */
  & .tun-app-shell-content[data-width='wide'] { max-width: none; }
  /* Content that holds an element made to fill (data-tun-fill, a board),
     directly or in stacks, is as tall as the screen under the header, and
     that element takes the height the rest leaves it, at least 20rem: its
     bottom edge shows when the page loads, above a strip of page a finger
     can scroll by.  Each stack on the way grows to pass the height on. */
  & .tun-app-shell-content:has(> [data-tun-fill], > .tun-stack > [data-tun-fill],
                               > .tun-stack > .tun-stack > [data-tun-fill]) {
    min-height: calc(100dvh - var(--spacing) * 14 - 1px);
    padding-block-end: calc(var(--spacing) * 10);
    & > .tun-stack:has(> [data-tun-fill], > .tun-stack > [data-tun-fill]),
    & > .tun-stack > .tun-stack:has(> [data-tun-fill]) { flex-grow: 1; }
    & > [data-tun-fill], & > .tun-stack > [data-tun-fill],
    & > .tun-stack > .tun-stack > [data-tun-fill] {
      flex: 1 1 0;
      min-height: 20rem;
      padding-block-end: 0;
      --tun-fill-align: stretch;
      --tun-fill-max-height: none;
    }
  }

  /* From 64rem the header is a sidebar and the menu stands in it.  A shell
     without a menu keeps its top bar. */
  @media (min-width: 64rem) {
    &:has(.tun-app-shell-panel) {
      display: grid;
      grid-template-columns: 16rem minmax(0, 1fr);
    }
    &:has(.tun-app-shell-panel) .tun-app-shell-header {
      display: flex;
      flex-direction: column;
      height: 100dvh;
      border-bottom: 0;
      border-right: 1px solid var(--chrome-border);
      background-color: var(--chrome);
    }
    & .tun-app-shell-bar { flex-shrink: 0; padding-inline: calc(var(--spacing) * 3); }
    & .tun-app-shell-bar > :is([popovertarget], [data-tun-search-open]) { display: none; }
    & .tun-app-shell-search {
      display: block;
      flex-shrink: 0;
      padding: calc(var(--spacing) * 3) calc(var(--spacing) * 3) 0;
    }
    & .tun-app-shell-panel,
    & .tun-app-shell-panel:popover-open {
      position: static;
      display: flex;
      flex: 1;
      width: auto;
      height: auto;
      min-height: 0;
      border: 0;
      background-color: transparent;
      box-shadow: none;
      translate: none;
      transition: none;
    }
    & .tun-app-shell-panel-head { display: none; }
    & .tun-app-shell-nav { padding-block: var(--spacing); }
    &:has(.tun-app-shell-panel) .tun-app-shell-main [id] {
      scroll-margin-top: calc(var(--spacing) * 4);
    }
    /* Beside the sidebar there is no header above the content. */
    &:has(.tun-app-shell-panel) .tun-app-shell-content:has(> [data-tun-fill],
        > .tun-stack > [data-tun-fill], > .tun-stack > .tun-stack > [data-tun-fill]) {
      min-height: 100dvh;
    }
  }
}
@keyframes tun-app-shell-loading {
  from { background-position: -70% 0; }
  to { background-position: 170% 0; }
}

/* specimen:  */

.tun-specimen {
  min-height: 100dvh;
  & .tun-specimen-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    /* The theme switch follows the title at the start of the row, where a
       toast, at the top right from 40rem, never covers it. */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: calc(var(--spacing) * 4);
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 4);
    border-bottom: 1px solid var(--border);
    background-color: color-mix(in oklab, var(--background) 90%, transparent);
    backdrop-filter: blur(8px);
  }
  & .tun-specimen-title { font-weight: var(--font-weight-semibold); }
  & .tun-specimen-themes {
    display: flex;
    & [aria-pressed='true'] { background-color: var(--muted); }
  }
  & .tun-specimen-body { display: grid; grid-template-columns: minmax(0, 1fr); }
  & .tun-specimen-nav { display: none; }
  & .tun-specimen-jump {
    margin: calc(var(--spacing) * 4) calc(var(--spacing) * 4) 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    & summary {
      padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
      font-size: var(--text-sm);
      font-weight: var(--font-weight-medium);
      cursor: pointer;
    }
    & .tun-specimen-links { padding: 0 calc(var(--spacing) * 4) calc(var(--spacing) * 4); }
  }
  & .tun-specimen-links {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 4);
    font-size: var(--text-sm);
    & h2 {
      margin-bottom: var(--spacing);
      font-size: var(--text-xs);
      line-height: var(--text-xs--line-height);
      font-weight: var(--font-weight-medium);
      color: var(--muted-foreground);
    }
    & a {
      display: block;
      text-decoration: none;
      padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2);
      border-radius: var(--radius-md);
      @media (hover: hover) { &:hover { background-color: var(--accent); } }
      &:active { background-color: var(--pressed); }
      &[aria-current='page'] { background-color: var(--muted); }
    }
  }
  & .tun-specimen-main {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 12);
    width: 100%;
    max-width: 60rem;
    padding: calc(var(--spacing) * 6) calc(var(--spacing) * 4) calc(var(--spacing) * 16);
  }
  & .tun-specimen-component {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 4);
    scroll-margin-top: 4.5rem;
  }
  & .tun-specimen-name { font-family: var(--font-mono); }
  & .tun-specimen-doc { color: var(--muted-foreground); }
  & .tun-specimen-source { font-size: var(--text-xs); color: var(--muted-foreground); }
  & .tun-specimen-example {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    & > h3 {
      padding: calc(var(--spacing) * 2) calc(var(--spacing) * 4);
      border-bottom: 1px solid var(--border);
      background-color: color-mix(in oklab, var(--muted) 50%, transparent);
      font-size: var(--text-sm);
      line-height: var(--text-sm--line-height);
      font-weight: var(--font-weight-medium);
    }
  }
  & .tun-specimen-preview {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    padding: calc(var(--spacing) * 6) calc(var(--spacing) * 4);
    & > * { min-width: 0; }
    &[data-layout='stack'] { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
  }
  & .tun-specimen-code {
    border-top: 1px solid var(--border);
    & summary {
      padding: calc(var(--spacing) * 2) calc(var(--spacing) * 4);
      font-size: var(--text-xs);
      color: var(--muted-foreground);
      cursor: pointer;
    }
    & pre {
      padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
      overflow-x: auto;
      background-color: var(--muted);
      font-size: var(--text-xs);
      line-height: var(--text-xs--line-height);
    }
  }
  & .tun-specimen-error { color: var(--destructive); font-family: var(--font-mono); }
  @media (min-width: 64rem) {
    & .tun-specimen-body { grid-template-columns: 15rem minmax(0, 1fr); }
    & .tun-specimen-jump { display: none; }
    & .tun-specimen-nav {
      display: block;
      position: sticky;
      top: 3.25rem;
      height: calc(100dvh - 3.25rem);
      overflow-y: auto;
      padding: calc(var(--spacing) * 6) calc(var(--spacing) * 3);
      border-right: 1px solid var(--border);
    }
    & .tun-specimen-main { padding-inline: calc(var(--spacing) * 10); }
  }
}
}
