/*
 * Construct kit: the look of every app an agent builds.
 *
 * Plain HTML looks right on its own: buttons, fields, tables, dialogs and
 * details are styled as they are. Classes add the rest (card, stat, badge,
 * stack, row, grid...), and kit.js adds the few things HTML can't do
 * (charts, dither, tabs, toasts, calendar, kanban, icons).
 *
 * Three looks share every component: <html data-theme="jelly|ink|riso">,
 * with data-mode="light|dark" (the system's when left out, or written
 * together as data-theme="ink-dark") and
 * data-tint="blue|mint|lilac|peach|lemon|rose|sea" for the accent.
 *
 * Everything sits in layers, so an app's own CSS always wins.
 */
@layer kit.reset, kit.theme, kit.base, kit.components, kit.utilities;

@font-face { font-family: "Inter"; src: url("fonts/inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Bricolage Grotesque"; src: url("fonts/bricolage-grotesque.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }
@font-face { font-family: "Doto"; src: url("fonts/doto.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

/* ------------------------------------------------------------------ */
/* Theme                                                               */
/* ------------------------------------------------------------------ */
@layer kit.theme {
  :root {
    color-scheme: light dark;

    /* The accent is the agent's tint, in OKLCH so every theme can set its own lightness and strength. */
    --tint-h: 250;
    --tint-c: 0.075;
    --tint-l: 0;

    /* Status colours, the same idea in every theme. */
    --good: light-dark(#137438, #4ade80);
    --good-soft: light-dark(#e7f5ec, #13281b);
    --warn: light-dark(#a24b08, #fbbf24);
    --warn-soft: light-dark(#fdf3e2, #2e2410);
    --bad: light-dark(#b42318, #fda29b);
    --bad-soft: light-dark(#fdecea, #34191a);

    --ease: cubic-bezier(0.2, 0, 0, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --fast: 140ms;
    --slow: 240ms;

    --text-xs: 12px;
    --text-sm: 13px;
    --text-md: 15px;
    --text-lg: 17px;
  }
  /* data-mode="dark", or one attribute for both: data-theme="ink-dark". */
  :root:is([data-mode="light"], [data-theme$="-light"]) { color-scheme: light; }
  :root:is([data-mode="dark"], [data-theme$="-dark"]) { color-scheme: dark; }

  /* The accent, re-derived wherever a theme or tint is set, so a tinted card or event recolours on its own. */
  :root, [data-theme], [data-tint] {
    --accent: light-dark(oklch(calc(var(--accent-l) + var(--tint-l)) calc(var(--tint-c) * var(--accent-k)) var(--tint-h)), oklch(var(--accent-l-dark) calc(var(--tint-c) * var(--accent-k-dark)) var(--tint-h)));
    --accent-soft: light-dark(oklch(var(--soft-l) calc(var(--tint-c) * var(--soft-k)) var(--tint-h)), oklch(var(--soft-l-dark) calc(var(--tint-c) * var(--soft-k-dark)) var(--tint-h)));
    --accent-ink: light-dark(oklch(var(--ink-l) calc(var(--tint-c) * var(--ink-k)) var(--tint-h)), oklch(var(--ink-l-dark) calc(var(--tint-c) * var(--ink-k-dark)) var(--tint-h)));
  }

  /* Data colours, in a fixed order checked for colour-blind readers. One series uses the accent instead. */
  :root {
    --series-1: light-dark(#2a78d6, #3987e5);
    --series-2: light-dark(#eb6834, #d95926);
    --series-3: light-dark(#1baf7a, #199e70);
    --series-4: light-dark(#eda100, #c98500);
    --series-5: light-dark(#e87ba4, #d55181);
    --series-6: light-dark(#008300, #008300);
    --series-7: light-dark(#6250d6, #9085e9);
    --series-8: light-dark(#e34948, #e66767);
  }

  [data-tint="blue"] { --tint-h: 250; --tint-c: 0.075; --tint-l: 0; }
  [data-tint="mint"] { --tint-h: 165; --tint-c: 0.08; --tint-l: 0.02; }
  [data-tint="lilac"] { --tint-h: 300; --tint-c: 0.085; --tint-l: 0; }
  [data-tint="peach"] { --tint-h: 50; --tint-c: 0.09; --tint-l: 0.03; }
  [data-tint="lemon"] { --tint-h: 98; --tint-c: 0.1; --tint-l: 0.1; }
  [data-tint="rose"] { --tint-h: 10; --tint-c: 0.09; --tint-l: 0; }
  [data-tint="sea"] { --tint-h: 215; --tint-c: 0.075; --tint-l: 0.01; }

  /* Jelly: Construct's own. Warm paper, white surfaces, soft hairlines, pill buttons. */
  :root,
  [data-theme^="jelly"] {
    --paper: light-dark(#fffefa, #111110);
    --surface: light-dark(#ffffff, #1a1a19);
    --sunken: light-dark(#f4f2ee, #171716);
    --ink: light-dark(#1c1917, #f5f5f4);
    --muted: light-dark(#6b6764, #a8a5a1);
    --faint: light-dark(#7a7571, #8a8783);
    --line: light-dark(rgb(28 25 23 / 0.1), rgb(255 255 255 / 0.1));
    --line-strong: light-dark(rgb(28 25 23 / 0.18), rgb(255 255 255 / 0.18));

    --accent-l: 0.76; --accent-k: 1; --accent-l-dark: 0.78; --accent-k-dark: 1;
    --soft-l: 0.955; --soft-k: 0.28; --soft-l-dark: 0.27; --soft-k-dark: 0.45;
    --ink-l: 0.37; --ink-k: 1.15; --ink-l-dark: 0.85; --ink-k-dark: 0.9;

    --font-display: "Bricolage Grotesque", "Inter", ui-sans-serif, system-ui, sans-serif;
    --font-text: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --display-weight: 600;
    --display-tracking: -0.03em;

    --r-button: 999px;
    --r-field: 12px;
    --r-card: 20px;
    --r-small: 8px;

    --border: 0 0 0 1px var(--line);
    --field-border: inset 0 0 0 1px var(--line-strong);
    --shadow-card: 0 0 0 1px var(--line), 0 1px 2px rgb(0 0 0 / 0.04);
    --shadow-pop: 0 0 0 1px var(--line), 0 16px 40px -12px light-dark(rgb(31 61 102 / 0.24), rgb(0 0 0 / 0.6));

    --primary: var(--ink);
    --on-primary: var(--paper);

    /* Dither: the size of one dot and the dot pattern kit.js draws with. */
    --dither-cell: 2px;
    --dither-pattern: bayer8;
  }

  /* Ink: one-bit. Newsprint and black, ruled borders, square corners, the tint as a single spot colour. */
  [data-theme^="ink"] {
    --paper: light-dark(#f1eee6, #0f0f0e);
    --surface: light-dark(#f1eee6, #0f0f0e);
    --sunken: light-dark(#e6e2d7, #1b1b19);
    --ink: light-dark(#121211, #ece9df);
    --muted: light-dark(#55524c, #a9a59a);
    --faint: light-dark(#6f6b63, #85817a);
    --line: light-dark(rgb(18 18 17 / 0.85), rgb(236 233 223 / 0.8));
    --line-strong: var(--ink);

    --accent-l: 0.64; --accent-k: 2; --accent-l-dark: 0.74; --accent-k-dark: 1.8;
    --soft-l: 0.9; --soft-k: 0.6; --soft-l-dark: 0.3; --soft-k-dark: 0.8;
    --ink-l: 0.33; --ink-k: 1.4; --ink-l-dark: 0.86; --ink-k-dark: 1.2;

    --font-display: "Doto", "JetBrains Mono", ui-monospace, monospace;
    --font-text: "Inter", ui-sans-serif, system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --display-weight: 800;
    --display-tracking: -0.01em;

    --r-button: 4px;
    --r-field: 4px;
    --r-card: 6px;
    --r-small: 3px;

    --border: 0 0 0 1px var(--line);
    --field-border: inset 0 0 0 1px var(--ink);
    --shadow-card: 0 0 0 1px var(--line);
    --shadow-pop: 0 0 0 1px var(--ink), 4px 4px 0 0 var(--ink);

    --primary: var(--ink);
    --on-primary: var(--paper);

    --dither-cell: 2px;
    --dither-pattern: bayer4;
  }

  /* Riso: two inks on cream stock. Deep blue for words, the tint as the second ink, halftone dots for fills. */
  [data-theme^="riso"] {
    --paper: light-dark(#f6efe0, #161a26);
    --surface: light-dark(#fbf6ea, #1c2130);
    --sunken: light-dark(#efe6d2, #121521);
    --ink: light-dark(#1f2f5c, #f1e8d4);
    --muted: light-dark(#5a6382, #b3ad9e);
    --faint: light-dark(#656b82, #8f8a7c);
    --line: light-dark(rgb(31 47 92 / 0.16), rgb(241 232 212 / 0.14));
    --line-strong: light-dark(rgb(31 47 92 / 0.32), rgb(241 232 212 / 0.28));

    --accent-l: 0.68; --accent-k: 2.3; --accent-l-dark: 0.76; --accent-k-dark: 2.1;
    --soft-l: 0.92; --soft-k: 0.7; --soft-l-dark: 0.32; --soft-k-dark: 1.1;
    --ink-l: 0.42; --ink-k: 2; --ink-l-dark: 0.86; --ink-k-dark: 1.4;

    --font-display: "Bricolage Grotesque", "Inter", ui-sans-serif, system-ui, sans-serif;
    --font-text: "Inter", ui-sans-serif, system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --display-weight: 800;
    --display-tracking: -0.045em;

    --r-button: 999px;
    --r-field: 10px;
    --r-card: 14px;
    --r-small: 6px;

    --border: 0 0 0 1.5px var(--line-strong);
    --field-border: inset 0 0 0 1.5px var(--line-strong);
    --shadow-card: 0 0 0 1.5px var(--line-strong);
    --shadow-pop: 0 0 0 1.5px var(--line-strong), 0 14px 0 -8px var(--accent);

    --primary: var(--ink);
    --on-primary: var(--paper);

    --dither-cell: 3px;
    --dither-pattern: halftone;
  }
}

/* ------------------------------------------------------------------ */
/* Reset and plain HTML                                                */
/* ------------------------------------------------------------------ */
@layer kit.reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, svg, video, canvas, picture { display: block; max-width: 100%; }
  img, video { height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
  :disabled { cursor: not-allowed; }
  [hidden] { display: none !important; }
}

@layer kit.base {
  html {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-text);
    font-size: var(--text-md);
    line-height: 1.55;
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    accent-color: var(--accent-ink);
    scrollbar-color: var(--line-strong) transparent;
  }
  body { min-height: 100dvh; background: var(--paper); }
  ::selection { background: var(--accent-soft); color: var(--accent-ink); }

  h1, h2, h3, h4 { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); line-height: 1.12; text-wrap: balance; font-variation-settings: "opsz" 96; }
  h1 { font-size: clamp(28px, 4.2vw, 40px); }
  h2 { font-size: 24px; }
  h3 { font-size: 18px; letter-spacing: -0.015em; }
  h4 { font-size: var(--text-md); font-family: var(--font-text); font-weight: 600; letter-spacing: 0; }
  /* Dot-matrix type only at title sizes; small titles stay in the text face. */
  [data-theme^="ink"] :is(h3, .sidebar > :is(h1, h2, strong):first-child, .app-bar > :is(h1, h2, strong)) { font-family: var(--font-text); font-weight: 700; letter-spacing: -0.02em; }
  /* Riso prints big titles in two inks, the second a hair out of register. */
  [data-theme^="riso"] :is(h1, .hero h1) { text-shadow: 0.035em 0.03em 0 color-mix(in oklab, var(--accent) 60%, transparent); }
  p, li, dd, figcaption { text-wrap: pretty; }
  small { font-size: var(--text-sm); color: var(--muted); }
  strong, b { font-weight: 600; }
  a { color: var(--accent-ink); text-decoration-line: underline; text-decoration-color: color-mix(in oklab, currentColor 35%, transparent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
  a:hover { text-decoration-color: currentColor; }
  hr { border: 0; border-top: 1px solid var(--line); }
  mark { background: var(--accent-soft); color: var(--accent-ink); border-radius: 3px; padding: 0 2px; }
  blockquote { border-left: 2px solid var(--accent); padding-left: 14px; color: var(--muted); }
  ul, ol { padding-left: 1.25em; }
  li + li { margin-top: 0.25em; }
  code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.88em; }
  code { background: var(--sunken); border-radius: 5px; padding: 0.1em 0.35em; }
  kbd { display: inline-block; min-width: 1.6em; padding: 0.05em 0.4em; border-radius: 5px; background: var(--surface); box-shadow: inset 0 -1px 0 var(--line-strong), 0 0 0 1px var(--line); text-align: center; font-size: 0.8em; }
  pre { background: var(--sunken); border-radius: var(--r-small); padding: 12px 14px; overflow-x: auto; line-height: 1.5; }
  pre code { background: none; padding: 0; }
  figure { display: grid; gap: 8px; }
  figcaption { font-size: var(--text-sm); color: var(--muted); }
  :focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

  /* Buttons. A plain <button> is the quiet one; .primary, .accent, .ghost and .danger change its weight. */
  button, .button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 18px; border: 0; border-radius: var(--r-button);
    background: var(--surface); color: var(--ink); box-shadow: var(--field-border);
    font-size: var(--text-md); font-weight: 500; line-height: 1; white-space: nowrap; text-decoration: none;
    transition: background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
    -webkit-tap-highlight-color: transparent; user-select: none;
  }
  :is(button, .button):hover { background: var(--sunken); }
  :is(button, .button):active:not(:disabled) { transform: scale(0.97); }
  :is(button, .button):disabled, .button[aria-disabled="true"] { opacity: 0.45; }
  :is(button, .button).primary { background: var(--primary); color: var(--on-primary); box-shadow: none; }
  :is(button, .button).primary:hover { background: color-mix(in oklab, var(--primary) 86%, var(--paper)); }
  :is(button, .button).accent { background: var(--accent); color: oklch(0.22 calc(var(--tint-c) * 1.2) var(--tint-h)); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35); }
  :is(button, .button).accent:hover { background: color-mix(in oklab, var(--accent) 88%, var(--ink)); }
  :is(button, .button).ghost { background: transparent; box-shadow: none; color: var(--muted); }
  :is(button, .button).ghost:hover { background: var(--sunken); color: var(--ink); }
  :is(button, .button).danger { background: var(--bad); color: var(--paper); box-shadow: none; }
  :is(button, .button).small { height: 32px; padding: 0 12px; font-size: var(--text-sm); gap: 6px; }
  :is(button, .button).large { height: 48px; padding: 0 24px; font-size: var(--text-lg); }
  :is(button, .button).icon { width: 40px; padding: 0; }
  :is(button, .button).icon.small { width: 32px; }
  :is(button, .button).block { width: 100%; }
  :is(button, .button)[aria-busy="true"] { color: transparent; position: relative; pointer-events: none; }
  :is(button, .button)[aria-busy="true"]::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; animation: kit-spin 0.8s linear infinite; }
  :is(button, .button).primary[aria-busy="true"]::after { border-color: var(--on-primary) transparent var(--on-primary) transparent; }

  /* Fields. Wrap a control in its <label> and the words sit above it; <small> under it helps, .error under it explains. */
  label:has(> :is(input, select, textarea):not([type="checkbox"], [type="radio"], [type="range"])) { display: grid; gap: 6px; font-size: var(--text-sm); font-weight: 500; }
  label :is(small, .error) { font-weight: 400; }
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="submit"], [type="button"], [type="reset"], [type="image"], [type="hidden"]), select, textarea {
    width: 100%; min-height: 40px; padding: 8px 12px; border: 0; border-radius: var(--r-field);
    background: var(--surface); color: var(--ink); box-shadow: var(--field-border);
    font-size: var(--text-md); font-weight: 400; line-height: 1.4; outline: none;
    transition: box-shadow var(--fast) var(--ease);
  }
  textarea { min-height: 88px; resize: vertical; field-sizing: content; max-height: 320px; }
  select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23888' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
  :is(input, select, textarea)::placeholder { color: var(--faint); }
  :is(input, select, textarea):focus-visible { box-shadow: inset 0 0 0 1.5px var(--accent-ink), 0 0 0 4px var(--accent-soft); outline: none; }
  :is(input, select, textarea):user-invalid, :is(input, select, textarea)[aria-invalid="true"] { box-shadow: inset 0 0 0 1.5px var(--bad), 0 0 0 4px var(--bad-soft); }
  :is(input, select, textarea):disabled { opacity: 0.55; background: var(--sunken); }
  .error { color: var(--bad); font-size: var(--text-sm); }
  input[type="search"] { padding-left: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23888' stroke-width='1.8' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='m20 20-4.2-4.2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 12px center; }
  input[type="search"]::-webkit-search-cancel-button { appearance: none; }
  input[type="color"] { width: 40px; height: 40px; padding: 4px; border: 0; border-radius: var(--r-field); background: var(--surface); box-shadow: var(--field-border); }
  input[type="file"] { font-size: var(--text-sm); color: var(--muted); }
  input[type="file"]::file-selector-button { height: 32px; margin-right: 10px; padding: 0 12px; border: 0; border-radius: var(--r-button); background: var(--sunken); color: var(--ink); font-weight: 500; cursor: pointer; }
  fieldset { border: 0; padding: 0; display: grid; gap: 10px; min-width: 0; }
  legend { font-size: var(--text-sm); font-weight: 600; margin-bottom: 4px; padding: 0; }
  @media (pointer: coarse) {
    input:not([type="checkbox"], [type="radio"], [type="range"]), select, textarea { font-size: 16px; }
  }

  /* Checkboxes, radios and switches (role="switch" on a checkbox). */
  label:has(> input:is([type="checkbox"], [type="radio"])) { display: inline-flex; align-items: center; gap: 10px; font-size: var(--text-md); cursor: pointer; min-height: 32px; }
  input:is([type="checkbox"], [type="radio"]) {
    appearance: none; flex: none; display: inline-grid; place-content: center; width: 20px; height: 20px; margin: 0;
    border-radius: 6px; background: var(--surface); box-shadow: var(--field-border); cursor: pointer;
    transition: background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
  }
  input[type="radio"] { border-radius: 50%; }
  input[type="checkbox"]::before { content: ""; width: 12px; height: 12px; background: var(--on-primary); clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 26%, 86% 12%, 38% 72%); transform: scale(0); transition: transform var(--fast) var(--ease-out); }
  input[type="radio"]::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--on-primary); transform: scale(0); transition: transform var(--fast) var(--ease-out); }
  input:is([type="checkbox"], [type="radio"]):checked { background: var(--primary); box-shadow: none; }
  input:is([type="checkbox"], [type="radio"]):checked::before { transform: scale(1); }
  input[type="checkbox"]:indeterminate { background: var(--primary); box-shadow: none; }
  input[type="checkbox"]:indeterminate::before { clip-path: none; height: 2px; width: 10px; transform: scale(1); }
  input[type="checkbox"][role="switch"] { width: 36px; height: 22px; border-radius: 999px; place-content: center start; padding: 3px; background: var(--line-strong); box-shadow: none; }
  input[type="checkbox"][role="switch"]::before { clip-path: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; transform: none; box-shadow: 0 1px 2px rgb(0 0 0 / 0.2); transition: translate var(--slow) var(--ease-out); }
  input[type="checkbox"][role="switch"]:checked { background: var(--primary); }
  input[type="checkbox"][role="switch"]:checked::before { translate: 14px 0; background: var(--on-primary); }
  [data-theme^="ink"] input[type="checkbox"][role="switch"]::before { border-radius: 2px; }
  [data-theme^="ink"] input[type="checkbox"][role="switch"] { border-radius: 3px; }

  /* Range: kit.js keeps --value up to date so the filled part follows the thumb. */
  input[type="range"] { appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; --value: 50%; }
  input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: linear-gradient(to right, var(--primary) var(--value), var(--line-strong) var(--value)); }
  input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: linear-gradient(to right, var(--primary) var(--value), var(--line-strong) var(--value)); }
  input[type="range"]::-webkit-slider-thumb { appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong), 0 2px 6px rgb(0 0 0 / 0.16); transition: transform var(--fast) var(--ease); }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong), 0 2px 6px rgb(0 0 0 / 0.16); }
  input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }

  /* Progress and meter: a solid fill over a dotted, still-to-go track. */
  progress, meter { appearance: none; display: block; width: 100%; height: 8px; border: 0; border-radius: 999px; overflow: hidden; background: transparent; }
  progress::-webkit-progress-bar { background: conic-gradient(var(--line-strong) 25%, transparent 0 50%, var(--line-strong) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); border-radius: 999px; }
  progress { background: conic-gradient(var(--line-strong) 25%, transparent 0 50%, var(--line-strong) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); }
  progress::-webkit-progress-value { background: var(--accent-ink); border-radius: 999px; transition: width var(--slow) var(--ease); }
  progress::-moz-progress-bar { background: var(--accent-ink); border-radius: 999px; }
  progress:indeterminate::-webkit-progress-bar { background: conic-gradient(var(--accent-ink) 25%, transparent 0 50%, var(--accent-ink) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); animation: kit-march 1.2s linear infinite; }
  meter::-webkit-meter-bar { background: var(--sunken); border: 0; border-radius: 999px; height: 8px; }
  meter::-webkit-meter-optimum-value { background: var(--good); border-radius: 999px; }
  meter::-webkit-meter-suboptimum-value { background: var(--warn); border-radius: 999px; }
  meter::-webkit-meter-even-less-good-value { background: var(--bad); border-radius: 999px; }
  [data-theme^="ink"] :is(progress, meter), [data-theme^="ink"] progress::-webkit-progress-bar, [data-theme^="ink"] progress::-webkit-progress-value { border-radius: 2px; }
  [data-theme^="ink"] progress { box-shadow: inset 0 0 0 1px var(--ink); height: 10px; }

  /* Tables: hairline rows, quiet headers, numbers lined up. Wrap a wide one in .table-scroll. */
  table { width: 100%; border-collapse: collapse; font-size: var(--text-md); font-variant-numeric: tabular-nums; }
  th { text-align: left; font-size: var(--text-sm); font-weight: 500; color: var(--muted); }
  th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
  :is(th, td):first-child { padding-left: 4px; }
  :is(th, td):last-child { padding-right: 4px; }
  tbody tr { transition: background-color var(--fast) var(--ease); }
  tbody tr:hover { background: color-mix(in oklab, var(--sunken) 70%, transparent); }
  tbody tr:last-child :is(td, th) { border-bottom: 0; }
  tr[aria-selected="true"] { background: var(--accent-soft); }
  :is(th, td).num, :is(th, td)[data-num] { text-align: right; font-variant-numeric: tabular-nums; }
  caption { caption-side: bottom; padding-top: 10px; font-size: var(--text-sm); color: var(--muted); text-align: left; }

  /* Dialogs. <dialog> opens with showModal() or a button with commandfor="id" command="show-modal". */
  dialog {
    margin: auto; width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 24px; border: 0; border-radius: calc(var(--r-card) + 4px);
    background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); overflow: auto;
  }
  dialog[open] { animation: kit-rise var(--slow) var(--ease-out); }
  dialog::backdrop { background: color-mix(in oklab, var(--ink) 22%, transparent); }
  [data-theme^="ink"] dialog::backdrop { background: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0) 0 0 / 4px 4px; opacity: 0.35; }
  dialog > :is(h2, h3):first-child { margin-bottom: 8px; }
  dialog footer, dialog form[method="dialog"]:last-child { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
  dialog.sheet { margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(420px, 100vw); border-radius: var(--r-card) 0 0 var(--r-card); }
  dialog.sheet[open] { animation: kit-slide var(--slow) var(--ease-out); }
  @media (max-width: 640px) {
    dialog { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: calc(var(--r-card) + 4px) calc(var(--r-card) + 4px) 0 0; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
    dialog.sheet { height: auto; max-height: 85dvh; border-radius: calc(var(--r-card) + 4px) calc(var(--r-card) + 4px) 0 0; }
  }

  /* Disclosure and accordions: <details name="same"> opens one at a time. */
  details { border-bottom: 1px solid var(--line); }
  summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; cursor: pointer; font-weight: 500; list-style: none; }
  summary::-webkit-details-marker { display: none; }
  summary::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); rotate: 45deg; translate: 0 -2px; transition: rotate var(--slow) var(--ease); }
  details[open] > summary::after { rotate: 225deg; translate: 0 2px; }
  details > :not(summary) { padding-bottom: 14px; color: var(--muted); }
  details::details-content { block-size: 0; overflow: clip; transition: block-size var(--slow) var(--ease), content-visibility var(--slow) allow-discrete; }
  details[open]::details-content { block-size: auto; }
  @supports (interpolate-size: allow-keywords) { :root { interpolate-size: allow-keywords; } }

  /* Popovers: a [popover] next to the button with popovertarget opens anchored below it where anchor positioning exists. */
  [popover] {
    padding: 6px; border: 0; border-radius: calc(var(--r-small) + 6px); min-width: 180px;
    background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop);
  }
  @supports (position-area: block-end) {
    [popover]:not(dialog, .toast) { margin: 6px 0; position-area: block-end span-inline-end; position-try-fallbacks: flip-block, flip-inline; }
  }
  [popover]:popover-open { animation: kit-pop var(--fast) var(--ease-out); }
}

@keyframes kit-spin { to { rotate: 360deg; } }
@keyframes kit-march { to { background-position: calc(var(--dither-cell) * 8) 0; } }
@keyframes kit-rise { from { opacity: 0; translate: 0 8px; scale: 0.98; } }
@keyframes kit-pop { from { opacity: 0; scale: 0.96; } }
@keyframes kit-slide { from { translate: 24px 0; opacity: 0; } }
@keyframes kit-fade { from { opacity: 0; } }
@keyframes kit-breathe { 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ------------------------------------------------------------------ */
/* Components                                                          */
/* ------------------------------------------------------------------ */
@layer kit.components {
  /* Layout: .stack piles things up, .row lines them up and wraps, .grid tiles them. --gap and --min tune them. */
  .stack { display: flex; flex-direction: column; gap: var(--gap, 16px); }
  .stack.tight { --gap: 8px; }
  .stack.loose { --gap: 32px; }
  .row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, 10px); }
  .row.spread { justify-content: space-between; }
  .row.end { justify-content: flex-end; }
  .row.top { align-items: flex-start; }
  .row.nowrap { flex-wrap: nowrap; }
  .grow { flex: 1 1 0; min-width: 0; }
  /* Small things keep their own width when a column lays them out. */
  :is(.stack, .card, .hero, .kanban article, ui-kanban article, figure):not(.empty) > :is(.badge, .chip, .avatar, .avatars, button, .button, .segmented) { align-self: flex-start; justify-self: start; }
  .grid { display: grid; gap: var(--gap, 16px); grid-template-columns: repeat(auto-fill, minmax(min(var(--min, 240px), 100%), 1fr)); }
  .split { display: grid; gap: var(--gap, 24px); grid-template-columns: minmax(0, 1fr); }
  @media (min-width: 840px) {
    .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .split.aside { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  }

  /* The app: <body class="app"> with a <nav class="sidebar"> and a <main class="page">. Without a sidebar, <main class="page"> alone. */
  .app { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100dvh; }
  @media (min-width: 840px) { .app:has(> .sidebar) { grid-template-columns: 248px minmax(0, 1fr); } }
  .page { width: 100%; max-width: var(--page, 980px); margin: 0 auto; padding: 32px 24px 72px; display: flex; flex-direction: column; gap: var(--gap, 24px); }
  .page.wide { --page: 1240px; }
  .page.narrow { --page: 640px; }
  @media (max-width: 640px) { .page { padding: 20px 16px 96px; } }
  .page > header:not(.hero) { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
  .page > header:not(.hero) p { color: var(--muted); }

  .sidebar { display: flex; flex-direction: column; gap: 4px; padding: 14px 12px; background: var(--sunken); }
  .sidebar > :is(h1, h2, strong):first-child { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); font-size: 19px; padding: 6px 10px 14px; }
  @media (min-width: 840px) { .sidebar { position: sticky; top: 0; height: 100dvh; overflow-y: auto; } }
  @media (max-width: 839px) {
    .sidebar { flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; gap: 2px; position: sticky; top: 0; z-index: 10; }
    .sidebar > :is(h1, h2, strong):first-child { padding: 0 10px 0 4px; font-size: 17px; white-space: nowrap; }
    .sidebar .nav { flex-direction: row; }
    .sidebar .push { display: none; }
  }
  [data-theme^="ink"] .sidebar { background: var(--paper); box-shadow: 1px 0 0 var(--ink); }

  .app-bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; background: color-mix(in oklab, var(--paper) 85%, transparent); backdrop-filter: blur(12px); box-shadow: 0 1px 0 var(--line); }
  .app-bar > :is(h1, h2, strong) { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .nav { display: flex; flex-direction: column; gap: 2px; padding: 0; margin: 0; list-style: none; }
  /* After .nav, whose margin would otherwise undo it on a <ul class="nav push">. */
  .push { margin-top: auto; }
  .nav li + li { margin: 0; }
  .nav a, .nav button { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: var(--text-md); font-weight: 500; white-space: nowrap; background: transparent; box-shadow: none; justify-content: flex-start; width: 100%; }
  .nav :is(a, button):hover { background: color-mix(in oklab, var(--ink) 5%, transparent); color: var(--ink); }
  .nav [aria-current="page"], .nav [aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }
  .nav .badge { margin-left: auto; }
  [data-theme^="ink"] .nav [aria-current] { background: var(--ink); color: var(--paper); box-shadow: none; }

  /* A bar of four or five places at the bottom of a phone app. */
  .tabbar { position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; justify-content: space-around; padding: 6px 8px max(6px, env(safe-area-inset-bottom)); background: color-mix(in oklab, var(--surface) 88%, transparent); backdrop-filter: blur(14px); box-shadow: 0 -1px 0 var(--line); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; min-width: 64px; padding: 6px 4px; border-radius: 12px; font-size: 11px; font-weight: 500; color: var(--muted); text-decoration: none; }
  .tabbar a[aria-current] { color: var(--accent-ink); }
  .tabbar a[aria-current] ui-icon { background: var(--accent-soft); border-radius: 999px; }

  /* Surfaces */
  .card { display: flex; flex-direction: column; gap: var(--gap, 12px); padding: 20px; border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow-card); min-width: 0; }
  .card.flat { background: var(--sunken); box-shadow: none; }
  .card.tight { padding: 14px; }
  a.card { color: inherit; text-decoration: none; transition: box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease); }
  a.card:hover { box-shadow: var(--shadow-pop); }
  a.card:active { transform: scale(0.99); }
  .card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .card > header > :is(h2, h3, h4) { font-size: var(--text-md); font-family: var(--font-text); font-weight: 600; letter-spacing: 0; }
  .card > footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
  .card.media { padding: 0; overflow: hidden; }
  .card.media > :is(img, ui-dither, .cover) { aspect-ratio: 16 / 10; width: 100%; object-fit: cover; }
  .card.media > :not(img, ui-dither, .cover) { padding: 0 18px; }
  .card.media > :last-child:not(img, ui-dither, .cover) { padding-bottom: 18px; }
  .well { padding: 16px; border-radius: var(--r-card); background: var(--sunken); }
  .glass { background: color-mix(in oklab, var(--surface) 82%, transparent); backdrop-filter: blur(16px) saturate(1.2); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.5), var(--shadow-pop); }

  /* Numbers that matter. <div class="stat"><span>Label</span><strong>42</strong><small class="up">+8%</small></div> */
  .stat { display: grid; gap: 2px; align-content: start; min-width: 0; }
  .stat > span { font-size: var(--text-sm); color: var(--muted); }
  .stat > strong { font-family: var(--font-text); font-weight: 600; font-size: 30px; letter-spacing: -0.025em; line-height: 1.15; }
  .stat.lead > strong { font-size: 52px; letter-spacing: -0.035em; }
  .stat > ui-chart.spark { margin-top: 6px; }
  .stat > small { font-size: var(--text-sm); color: var(--muted); }
  .stat .up, .up { color: var(--good); }
  .stat .down, .down { color: var(--bad); }
  :is(.up, .down):not(.badge)::before { content: "↑ "; }
  .down:not(.badge)::before { content: "↓ "; }
  .card.stat { padding: 18px 20px; }

  /* Badges and chips */
  .badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); font-size: var(--text-xs); font-weight: 500; line-height: 1; white-space: nowrap; vertical-align: middle; font-variant-numeric: tabular-nums; }
  .badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
  .badge.good { background: var(--good-soft); color: var(--good); }
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
  .badge.bad { background: var(--bad-soft); color: var(--bad); }
  .badge.solid { background: var(--primary); color: var(--on-primary); }
  .badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  [data-theme^="ink"] .badge { border-radius: 3px; box-shadow: inset 0 0 0 1px currentColor; background: transparent; }
  [data-theme^="ink"] .badge.solid { background: var(--ink); color: var(--paper); }
  .chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; background: var(--surface); box-shadow: var(--field-border); font-size: var(--text-sm); font-weight: 500; white-space: nowrap; color: var(--ink); text-decoration: none; }
  .chip:has(> button:last-child) { padding-right: 4px; }
  .chip > button { width: 22px; height: 22px; padding: 0; border-radius: 50%; background: transparent; box-shadow: none; color: var(--muted); font-size: 14px; }
  .chip > button:hover { background: var(--sunken); color: var(--ink); }
  :is(button, a).chip[aria-pressed="true"], :is(button, a).chip[aria-current] { background: var(--primary); color: var(--on-primary); box-shadow: none; }
  [data-theme^="ink"] .chip { border-radius: 3px; }

  /* People */
  .avatar { --size: 32px; display: inline-grid; place-items: center; flex: none; width: var(--size); height: var(--size); border-radius: 50%; overflow: hidden; background: var(--accent-soft); color: var(--accent-ink); font-size: calc(var(--size) * 0.4); font-weight: 600; text-transform: uppercase; line-height: 1; user-select: none; }
  .avatar.small { --size: 24px; }
  .avatar.large { --size: 48px; }
  .avatar > :is(img, ui-dither) { width: 100%; height: 100%; object-fit: cover; }
  [data-theme^="ink"] .avatar { border-radius: 4px; box-shadow: inset 0 0 0 1px var(--ink); }
  .avatars { display: inline-flex; }
  .avatars > .avatar { box-shadow: 0 0 0 2px var(--paper); }
  .avatars > .avatar + .avatar { margin-left: calc(var(--size) * -0.18); }

  /* Lists of things: <ul class="list"><li>…</li></ul>. A row can hold an avatar, .grow text and trailing bits. */
  .list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
  .list > li { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 2px; border-bottom: 1px solid var(--line); margin: 0; }
  .list > li:last-child { border-bottom: 0; }
  .list > li > a:only-child, .list > li > a.grow { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
  .list > li :is(p, small) { color: var(--muted); font-size: var(--text-sm); }
  .list > li :is(strong, b) + :is(p, small) { display: block; }
  .card > .list { margin: -6px 0; }

  /* Key and value pairs */
  .kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0; }
  .kv dt { color: var(--muted); font-size: var(--text-sm); padding-top: 1px; }
  .kv dd { margin: 0; }

  /* Tabs: <ui-tabs> with buttons, then one <section> per button. */
  ui-tabs { display: flex; flex-direction: column; gap: 16px; }
  ui-tabs > [role="tablist"], .segmented { display: inline-flex; align-self: flex-start; max-width: 100%; overflow-x: auto; gap: 2px; padding: 3px; border-radius: calc(var(--r-field) + 3px); background: var(--sunken); }
  ui-tabs [role="tab"], .segmented label { height: 32px; padding: 0 14px; border-radius: var(--r-field); background: transparent; box-shadow: none; color: var(--muted); font-size: var(--text-sm); font-weight: 500; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; cursor: pointer; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
  ui-tabs [role="tab"]:hover, .segmented label:hover { background: transparent; color: var(--ink); }
  ui-tabs [role="tab"][aria-selected="true"], .segmented label:has(:checked) { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgb(0 0 0 / 0.06); }
  .segmented input { position: absolute; opacity: 0; pointer-events: none; }
  .segmented label:has(:focus-visible) { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
  ui-tabs.line > [role="tablist"] { background: transparent; padding: 0; gap: 18px; border-radius: 0; box-shadow: inset 0 -1px 0 var(--line); width: 100%; }
  ui-tabs.line [role="tab"] { padding: 0; height: 40px; border-radius: 0; }
  ui-tabs.line [role="tab"][aria-selected="true"] { box-shadow: inset 0 -2px 0 var(--ink); background: transparent; }
  [data-theme^="ink"] :is(ui-tabs:not(.line) > [role="tablist"], .segmented) { background: transparent; box-shadow: inset 0 0 0 1px var(--ink); }
  [data-theme^="ink"] :is(ui-tabs:not(.line) [role="tab"][aria-selected="true"], .segmented label:has(:checked)) { background: var(--ink); color: var(--paper); box-shadow: none; }

  /* Where you are and where to go next */
  .breadcrumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; list-style: none; padding: 0; margin: 0; font-size: var(--text-sm); color: var(--muted); }
  .breadcrumbs li { margin: 0; display: flex; align-items: center; gap: 6px; }
  .breadcrumbs li + li::before { content: "/"; color: var(--faint); }
  .breadcrumbs a { color: var(--muted); text-decoration: none; }
  .breadcrumbs a:hover { color: var(--ink); }
  .breadcrumbs [aria-current] { color: var(--ink); }
  .pagination { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
  .pagination :is(a, button) { min-width: 36px; height: 36px; padding: 0 10px; border-radius: var(--r-field); display: inline-flex; align-items: center; justify-content: center; background: transparent; box-shadow: none; color: var(--muted); text-decoration: none; font-size: var(--text-sm); }
  .pagination :is(a, button):hover { background: var(--sunken); color: var(--ink); }
  .pagination [aria-current] { background: var(--primary); color: var(--on-primary); }

  .steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0; counter-reset: step; }
  .steps li { flex: 1; display: grid; gap: 8px; margin: 0; counter-increment: step; font-size: var(--text-sm); color: var(--muted); }
  .steps li::before { content: ""; height: 4px; border-radius: 999px; background: var(--line-strong); }
  .steps li.done::before, .steps li[aria-current]::before { background: var(--accent-ink); }
  .steps li[aria-current] { color: var(--ink); font-weight: 500; }

  /* A story in order, like Construct's own trail: dots on a hairline. Mark the live one .now. */
  .timeline { list-style: none; padding: 0; margin: 0; position: relative; display: flex; flex-direction: column; gap: 18px; }
  .timeline::before { content: ""; position: absolute; left: 5px; top: 10px; bottom: 10px; width: 1px; background: var(--line-strong); }
  .timeline > li { position: relative; padding-left: 29px; margin: 0; }
  .timeline > li::before { content: ""; position: absolute; left: 2px; top: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px var(--paper); }
  .timeline > li.now::before { left: 0; top: 6px; width: 11px; height: 11px; background: var(--accent-ink); box-shadow: 0 0 0 4px var(--accent-soft); }
  .timeline > li.need::before { left: 0; top: 6px; width: 11px; height: 11px; background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
  .timeline time { display: block; font-size: var(--text-xs); color: var(--muted); }
  [data-theme^="ink"] .timeline > li::before { border-radius: 1px; }

  /* Feedback */
  .callout { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-card); background: var(--sunken); color: var(--ink); font-size: var(--text-md); }
  .callout :is(strong, b):first-child { display: block; }
  .callout.accent { background: var(--accent-soft); color: var(--accent-ink); }
  .callout.good { background: var(--good-soft); }
  .callout.warn { background: var(--warn-soft); }
  .callout.bad { background: var(--bad-soft); }
  .callout > ui-icon { margin-top: 2px; }
  .callout.good > ui-icon { color: var(--good); }
  .callout.warn > ui-icon { color: var(--warn); }
  .callout.bad > ui-icon { color: var(--bad); }
  [data-theme^="ink"] .callout { box-shadow: inset 0 0 0 1px var(--ink); background: transparent; }

  .toaster { position: fixed; z-index: 1000; inset: auto 0 max(16px, env(safe-area-inset-bottom)) 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
  .toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; min-height: 44px; max-width: min(460px, 100%); padding: 6px 6px 6px 16px; border-radius: 999px; background: var(--ink); color: var(--paper); box-shadow: 0 12px 32px -12px rgb(0 0 0 / 0.4); font-size: var(--text-md); animation: kit-rise var(--slow) var(--ease-out); }
  .toast:not(:has(button)) { padding-right: 16px; }
  .toast button { height: 32px; padding: 0 12px; background: color-mix(in oklab, var(--paper) 14%, transparent); color: var(--paper); box-shadow: none; font-size: var(--text-sm); }
  .toast button:hover { background: color-mix(in oklab, var(--paper) 24%, transparent); }
  .toast.good::before, .toast.bad::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--good); }
  .toast.bad::before { background: var(--bad); }
  .toast.leaving { opacity: 0; translate: 0 6px; transition: opacity var(--fast) var(--ease), translate var(--fast) var(--ease); }
  [data-theme^="ink"] .toast { border-radius: 4px; }

  /* Tooltips: data-tip="Words" on anything focusable. Give icon buttons an aria-label too. */
  [data-tip] { position: relative; }
  [data-tip]::before { content: attr(data-tip); position: absolute; z-index: 50; left: 50%; bottom: calc(100% + 8px); translate: -50% 2px; padding: 5px 9px; border-radius: 8px; background: var(--ink); color: var(--paper); font-size: var(--text-xs); font-weight: 500; line-height: 1.3; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity var(--fast) var(--ease), translate var(--fast) var(--ease); transition-delay: 0s; }
  [data-tip]:is(:hover, :focus-visible)::before { opacity: 1; translate: -50% 0; transition-delay: 400ms; }

  /* Menus: a [popover] with class="menu" holding buttons and links. */
  .menu { display: flex; flex-direction: column; gap: 1px; }
  /* Any display of the kit's outranks the browser hiding a closed popover, so a closed menu says it again. */
  .menu[popover]:not(:popover-open) { display: none; }
  .menu > :is(button, a) { justify-content: flex-start; width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; background: transparent; box-shadow: none; color: var(--ink); font-size: var(--text-md); font-weight: 400; text-decoration: none; }
  .menu > :is(button, a):hover, .menu > :is(button, a):focus-visible { background: var(--sunken); outline: none; }
  .menu > .danger { color: var(--bad); background: transparent; }
  .menu > hr { margin: 4px 6px; }
  .menu > :is(button, a) kbd { margin-left: auto; }

  /* Nothing here yet: a calm picture, one sentence, one way forward. */
  .empty { display: grid; justify-items: center; gap: 10px; padding: 48px 16px; text-align: center; }
  .empty > ui-dither { width: 120px; height: 84px; margin-bottom: 6px; }
  .empty p { color: var(--muted); max-width: 34ch; }
  .empty > :is(button, .button) { margin-top: 8px; }

  /* Loading */
  .skeleton { display: block; min-height: 1em; border-radius: var(--r-small); background: conic-gradient(var(--line-strong) 25%, transparent 0 50%, var(--line-strong) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); animation: kit-breathe 1.6s var(--ease) infinite; }
  .spinner { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid; border-color: var(--muted) transparent var(--muted) transparent; animation: kit-spin 0.8s linear infinite; }

  /* Fields together: .input-group puts a prefix or suffix inside the box; .actions lines up a form's buttons. */
  .input-group { display: flex; align-items: center; min-height: 40px; border-radius: var(--r-field); background: var(--surface); box-shadow: var(--field-border); padding: 0 12px; gap: 8px; }
  .input-group:focus-within { box-shadow: inset 0 0 0 1.5px var(--accent-ink), 0 0 0 4px var(--accent-soft); }
  .input-group > input { box-shadow: none !important; padding-left: 0; padding-right: 0; background: transparent; min-height: 38px; }
  .input-group > :not(input) { color: var(--muted); font-size: var(--text-sm); white-space: nowrap; }
  form.stack .actions, .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

  .dropzone { display: grid; justify-items: center; gap: 6px; padding: 28px 16px; border-radius: var(--r-card); text-align: center; color: var(--muted); font-size: var(--text-sm); cursor: pointer; background: conic-gradient(at 1px 1px, transparent 75%, var(--line-strong) 0) 0 0 / 6px 6px, var(--surface); box-shadow: var(--field-border); transition: background-color var(--fast) var(--ease); }
  .dropzone strong { color: var(--ink); font-size: var(--text-md); }
  .dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
  .dropzone:has(input:focus-visible) { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
  .dropzone.over { background: conic-gradient(at 1px 1px, transparent 75%, var(--accent-ink) 0) 0 0 / 6px 6px, var(--accent-soft); color: var(--accent-ink); }

  .rating { display: inline-flex; flex-direction: row-reverse; gap: 2px; }
  .rating input { position: absolute; opacity: 0; pointer-events: none; }
  .rating label { width: 24px; height: 24px; cursor: pointer; background: var(--line-strong); clip-path: polygon(50% 4%, 61% 37%, 96% 37%, 68% 58%, 79% 92%, 50% 71%, 21% 92%, 32% 58%, 4% 37%, 39% 37%); transition: background-color var(--fast) var(--ease); }
  .rating label:has(:checked), .rating label:has(:checked) ~ label, .rating label:hover, .rating label:hover ~ label { background: var(--accent-ink); }
  .rating label:has(:focus-visible) { outline: 2px solid var(--accent-ink); }

  /* A big, quiet top for a page, with a dithered field behind the words. */
  .hero { position: relative; isolation: isolate; overflow: hidden; display: grid; gap: 10px; padding: 48px 28px; border-radius: calc(var(--r-card) + 4px); background: var(--sunken); }
  .hero > :not(ui-dither) { max-width: min(560px, 58%); }
  .hero > ui-dither:first-child { position: absolute; inset: 0 0 0 auto; z-index: -1; width: 46%; height: 100%; }
  @media (max-width: 640px) {
    .hero { padding: 132px 20px 24px; }
    .hero > :not(ui-dither) { max-width: none; }
    .hero > ui-dither:first-child { inset: 0 0 auto 0; width: 100%; height: 120px; }
  }
  .hero h1 { font-size: clamp(32px, 5.5vw, 56px); }
  .hero p { color: var(--muted); max-width: 46ch; font-size: var(--text-lg); }

  /* Columns of cards. <ui-kanban> adds dragging; without it the cards still read. */
  .kanban, ui-kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 8px; scroll-snap-type: x proximity; }
  :is(.kanban, ui-kanban) > section { flex: 0 0 min(288px, 82vw); display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--r-card); background: var(--sunken); scroll-snap-align: start; min-height: 120px; }
  :is(.kanban, ui-kanban) > section > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 6px 4px; font-size: var(--text-sm); font-weight: 600; }
  :is(.kanban, ui-kanban) article { display: grid; gap: 6px; padding: 12px 14px; border-radius: calc(var(--r-card) - 6px); background: var(--surface); box-shadow: var(--shadow-card); font-size: var(--text-md); }
  ui-kanban article { cursor: grab; touch-action: none; }
  ui-kanban article.dragging { opacity: 0.4; }
  ui-kanban section.over { box-shadow: inset 0 0 0 2px var(--accent); }
  [data-theme^="ink"] :is(.kanban, ui-kanban) > section { background: transparent; box-shadow: inset 0 0 0 1px var(--ink); }

  /* Bars in a list: <ul class="bar-list"><li style="--value: 64%"><span>Label</span><b>1,204</b></li></ul> */
  .bar-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; font-variant-numeric: tabular-nums; }
  .bar-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; margin: 0; font-size: var(--text-md); }
  .bar-list li > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar-list li > b { font-weight: 500; }
  .bar-list li::after { content: ""; grid-column: 1 / -1; height: 6px; border-radius: 999px; background: linear-gradient(var(--accent-ink), var(--accent-ink)) 0 0 / var(--value, 0%) 100% no-repeat, conic-gradient(var(--line-strong) 25%, transparent 0 50%, var(--line-strong) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); }
  [data-theme^="ink"] .bar-list li::after { border-radius: 1px; height: 8px; }

  /* Buttons that belong together sit joined. */
  .buttons { display: inline-flex; isolation: isolate; }
  .buttons > :is(button, .button) { border-radius: 0; }
  .buttons > :is(button, .button) + :is(button, .button) { margin-left: -1px; }
  .buttons > :is(button, .button):first-child { border-radius: var(--r-button) 0 0 var(--r-button); }
  .buttons > :is(button, .button):last-child { border-radius: 0 var(--r-button) var(--r-button) 0; }
  .buttons > :is(button, .button):focus-visible { z-index: 1; }

  /* A tree of folders or topics: nested <ul> with <details> for the branches. */
  .tree, .tree ul { list-style: none; padding: 0; margin: 0; }
  .tree ul { margin-left: 9px; padding-left: 12px; box-shadow: inset 1px 0 0 var(--line); }
  .tree li { margin: 0; }
  .tree details { border: 0; }
  .tree summary { min-height: 34px; flex-direction: row-reverse; justify-content: flex-end; gap: 8px; font-weight: 400; }
  .tree summary::after { rotate: -45deg; translate: 0 0; }
  .tree details[open] > summary::after { rotate: 45deg; translate: 0 -2px; }
  .tree details > :not(summary) { padding-bottom: 0; color: inherit; }
  .tree li > :is(a, span) { display: flex; align-items: center; gap: 8px; min-height: 34px; padding-left: 16px; color: inherit; text-decoration: none; }
  .tree [aria-current] { color: var(--accent-ink); font-weight: 500; }

  /* Colour choices: <div class="swatches"><label data-tint="mint"><input type="radio" name="c" aria-label="Mint"></label>…</div> */
  .swatches { display: flex; flex-wrap: wrap; gap: 8px; }
  .swatches label { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--swatch, var(--accent)); cursor: pointer; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08); transition: box-shadow var(--fast) var(--ease); }
  .swatches input { position: absolute; opacity: 0; pointer-events: none; }
  .swatches label:has(:checked) { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
  .swatches label:has(:focus-visible) { outline: 2px solid var(--accent-ink); outline-offset: 4px; }

  /* Things side by side that scroll sideways and snap, like a carousel without the arrows. */
  .scroller { display: grid; grid-auto-flow: column; grid-auto-columns: min(var(--min, 280px), 82%); gap: var(--gap, 12px); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; overscroll-behavior-x: contain; }
  .scroller > * { scroll-snap-align: start; }

  /* Searchable select from ui-combobox. */
  ui-combobox { display: block; position: relative; }
  .combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px); max-height: 264px; overflow: auto; list-style: none; margin: 0; padding: 6px; border-radius: calc(var(--r-small) + 6px); background: var(--surface); box-shadow: var(--shadow-pop); animation: kit-pop var(--fast) var(--ease-out); }
  .combo-list li { margin: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: var(--text-md); }
  .combo-list li:hover, .combo-list li[aria-selected="true"] { background: var(--sunken); }
  .combo-list li.empty { color: var(--muted); cursor: default; background: none; }

  /* Calendar from ui-calendar. */
  .calendar { display: grid; gap: 10px; }
  .calendar > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .calendar > header h3 { font-size: var(--text-lg); }
  .calendar-names, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .calendar-names span { padding: 2px 0; font-size: var(--text-xs); color: var(--muted); text-align: center; }
  .calendar .day { height: auto; min-height: 76px; padding: 6px; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 3px; border-radius: var(--r-small); background: var(--surface); box-shadow: 0 0 0 1px var(--line); white-space: normal; text-align: left; font-size: var(--text-sm); font-weight: 400; min-width: 0; }
  .calendar .day:hover { background: var(--sunken); }
  .calendar .day .date { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
  .calendar .day[aria-current="date"] .date { background: var(--accent-ink); color: var(--paper); font-weight: 600; }
  .calendar .day[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--accent-ink); }
  .calendar .event { display: block; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-ink); font-size: 11px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .calendar .more { font-size: 11px; color: var(--muted); padding-left: 4px; }
  .calendar .pad { min-height: 0; }
  @media (max-width: 640px) {
    .calendar .day { min-height: 44px; align-items: center; padding: 4px 2px; }
    .calendar .event { width: 6px; height: 6px; padding: 0; border-radius: 50%; font-size: 0; background: var(--accent-ink); }
    .calendar .more { display: none; }
  }
  [data-theme^="ink"] .calendar .day { border-radius: 2px; }

  /* Chart pieces drawn by ui-chart. */
  ui-chart { position: relative; }
  ui-chart:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 6px; border-radius: 6px; }
  ui-chart[type="parts"] { min-height: 0; }
  .chart-svg { display: block; overflow: visible; }
  .chart-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
  .chart-base { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
  .chart-tick { fill: var(--muted); font-size: 12px; font-family: var(--font-text); font-variant-numeric: tabular-nums; }
  .chart-value { fill: var(--ink); font-size: 12px; font-weight: 600; font-family: var(--font-text); font-variant-numeric: tabular-nums; }
  .chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .chart-line.spark { stroke-width: 1.5; }
  .chart-dot { stroke: var(--surface); stroke-width: 2; }
  .chart-cross { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
  .chart-bar { transition: opacity var(--fast) var(--ease); }
  .chart-bar.dim { opacity: 0.45; }
  .chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding-bottom: 12px; font-size: var(--text-xs); color: var(--muted); }
  .chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
  .chart-legend i { width: 10px; height: 10px; border-radius: 3px; }
  .chart-legend i.line { width: 14px; height: 2px; border-radius: 1px; }
  .chart-tip { position: absolute; z-index: 2; pointer-events: none; display: grid; gap: 4px; min-width: 120px; padding: 8px 10px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-pop); font-size: var(--text-xs); }
  .chart-tip small { font-size: var(--text-xs); color: var(--muted); }
  .chart-tip div { display: flex; align-items: center; gap: 8px; }
  .chart-tip i { width: 12px; height: 2px; border-radius: 1px; flex: none; }
  .chart-tip b { font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
  .chart-tip span { color: var(--muted); }
  .chart-parts { display: flex; gap: 2px; height: 12px; border-radius: 999px; overflow: hidden; }
  .chart-parts span { min-width: 3px; }
  .chart-parts-list { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; }
  .chart-parts-list li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 3.2em; align-items: center; gap: 10px; margin: 0; font-size: var(--text-md); }
  .chart-parts-list i { width: 10px; height: 10px; border-radius: 3px; }
  .chart-parts-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chart-parts-list b { font-weight: 500; font-variant-numeric: tabular-nums; }
  .chart-parts-list small { text-align: right; font-variant-numeric: tabular-nums; }
  [data-theme^="ink"] :is(.chart-parts, .chart-legend i, .chart-parts-list i) { border-radius: 1px; }

  /* Dithered fills for your own shapes: .dots-25, .dots-50, .dots-75 in --dot (the accent unless set). */
  .dots-25, .dots-50, .dots-75 { --dot-c: var(--dot, var(--accent-ink)); }
  .dots-25 { background: conic-gradient(at var(--dither-cell) var(--dither-cell), transparent 75%, var(--dot-c) 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); }
  .dots-50 { background: conic-gradient(var(--dot-c) 25%, transparent 0 50%, var(--dot-c) 0 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); }
  .dots-75 { background: conic-gradient(at var(--dither-cell) var(--dither-cell), var(--dot-c) 75%, transparent 0) 0 0 / calc(var(--dither-cell) * 2) calc(var(--dither-cell) * 2); }
  [data-theme^="riso"] .dots-25 { background: radial-gradient(circle, var(--dot-c) 0.9px, transparent 1.4px) 0 0 / 5px 5px, radial-gradient(circle, var(--dot-c) 0.9px, transparent 1.4px) 2.5px 2.5px / 5px 5px; }
  [data-theme^="riso"] .dots-50 { background: radial-gradient(circle, var(--dot-c) 1.3px, transparent 1.8px) 0 0 / 5px 5px, radial-gradient(circle, var(--dot-c) 1.3px, transparent 1.8px) 2.5px 2.5px / 5px 5px; }
  [data-theme^="riso"] .dots-75 { background: radial-gradient(circle, var(--dot-c) 1.75px, transparent 2.2px) 0 0 / 5px 5px, radial-gradient(circle, var(--dot-c) 1.75px, transparent 2.2px) 2.5px 2.5px / 5px 5px; }

  /* Charts and the dither field size themselves from their box. */
  ui-chart { display: block; width: 100%; min-height: 160px; color: var(--ink); }
  ui-chart.spark { min-height: 0; height: 36px; }
  ui-dither { display: block; position: relative; overflow: hidden; isolation: isolate; }
  ui-dither > canvas { position: absolute; inset: 0; z-index: -1; image-rendering: pixelated; }
  ui-icon { display: inline-grid; place-items: center; flex: none; width: var(--icon, 18px); height: var(--icon, 18px); }
  ui-icon > svg { width: 100%; height: 100%; }
  :is(button, .button) > ui-icon { --icon: 18px; }
  :is(button, .button).small > ui-icon { --icon: 16px; }
}

/* ------------------------------------------------------------------ */
/* Utilities                                                           */
/* ------------------------------------------------------------------ */
@layer kit.utilities {
  .muted { color: var(--muted); }
  .faint { color: var(--faint); }
  .display { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); }
  .num { font-variant-numeric: tabular-nums; }
  .mono { font-family: var(--font-mono); letter-spacing: -0.01em; }
  .center { text-align: center; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .full { width: 100%; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .text-sm { font-size: var(--text-sm); }
  .text-lg { font-size: var(--text-lg); }
  .table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
  @media (max-width: 639px) { .hide-phone { display: none !important; } }
  @media (min-width: 640px) { .phone-only { display: none !important; } }
  @media (prefers-contrast: more) {
    :root { --line: var(--line-strong); }
  }
  @media (forced-colors: active) {
    .dots-25, .dots-50, .dots-75, .skeleton, progress { background: CanvasText; }
  }
}
