/* Henry — a small design system for responsive web apps.
   Classless by default. Write semantic HTML and link this file.
   Layers: tokens → reset → base → components → utilities.
   Project CSS outside any layer always wins.
   MIT License, (c) 2026 Henry Poydar. */

@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,400..700;1,14..32,400..700&display=swap");

@layer tokens, reset, base, components, utilities;

/* ---------------------------------------------------------------- tokens */

@layer tokens {
  :root {
    /* Type */
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: clamp(1.5rem, 1.2rem + 1.2vw, 1.875rem);
    --text-3xl: clamp(1.875rem, 1.3rem + 2.4vw, 2.75rem);

    --leading-tight: 1.15;
    --leading-snug: 1.3;
    --leading-normal: 1.5;

    --tracking-tight: -0.02em;
    --tracking-normal: 0;

    --weight-normal: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-heading: 650;

    /* Spacing, 4px grid */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Background patterns */
    --pattern-size: var(--space-2);
    --pattern-stroke: 1px;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Shadow: only for things that float */
    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.06), 0 1px 3px oklch(0% 0 0 / 0.08);
    --shadow-md: 0 4px 12px oklch(0% 0 0 / 0.08), 0 1px 3px oklch(0% 0 0 / 0.06);
    --shadow-lg: 0 12px 32px oklch(0% 0 0 / 0.12), 0 2px 6px oklch(0% 0 0 / 0.06);

    /* Motion */
    --duration-fast: 100ms;
    --duration-normal: 200ms;
    --ease: cubic-bezier(0.2, 0, 0, 1);

    /* Layout */
    --container-max: 72rem;
    --container-narrow: 40rem;
    --sidebar-width: 16rem;
    --sidebar-width-compact: 13rem;
    --gutter: clamp(var(--space-4), 4vw, var(--space-8));

    /* Gray ramp */
    --gray-50:  oklch(98.2% 0.003 85);
    --gray-100: oklch(95.8% 0.004 91);
    --gray-200: oklch(93% 0.005 95);
    --gray-300: oklch(89.5% 0.006 95);
    --gray-400: oklch(72% 0 0);
    --gray-500: oklch(58% 0 0);
    --gray-600: oklch(46% 0 0);
    --gray-700: oklch(40% 0 0);
    --gray-800: oklch(30% 0 0);
    --gray-900: oklch(22% 0 0);
    --gray-950: oklch(17.5% 0.008 286);

    /* Accent ramp: Steady ultramarine, oklch(52% 0.26 275), stepped the way runsteady.com does it */
    --accent-50:  oklch(98% 0.0325 275);
    --accent-100: oklch(95% 0.065 275);
    --accent-200: oklch(90% 0.13 275);
    --accent-300: oklch(85% 0.26 275);
    --accent-400: oklch(75% 0.26 275);
    --accent-500: oklch(55% 0.26 275);
    --accent-600: oklch(50% 0.26 275);
    --accent-700: oklch(35% 0.173 275);
    --accent-800: oklch(25% 0.13 275);
    --accent-900: oklch(21% 0.13 275);

    /* Status ramps */
    --success-100: oklch(95% 0.04 155);
    --success-500: oklch(62% 0.15 155);
    --success-700: oklch(44% 0.12 155);
    --warning-100: oklch(96% 0.05 75);
    --warning-500: oklch(76% 0.16 68);
    --warning-700: oklch(48% 0.13 60);
    --danger-100: oklch(95% 0.035 22);
    --danger-500: oklch(60% 0.2 22);
    --danger-700: oklch(45% 0.17 22);

    /* Semantic aliases, light */
    --color-bg: var(--gray-100);
    --color-bg-raised: var(--gray-50);
    --color-bg-subtle: var(--gray-200);
    --color-bg-muted: var(--gray-300);
    --color-bg-emphasis: var(--gray-950);
    --color-bg-emphasis-hover: var(--gray-800);
    --color-bg-emphasis-active: var(--gray-700);

    --color-fg: var(--gray-950);
    --color-fg-muted: var(--gray-600);
    --color-fg-subtle: var(--gray-500);
    --color-fg-on-emphasis: white;

    --color-border: oklch(17.5% 0.008 286 / 0.14);
    --color-border-strong: oklch(17.5% 0.008 286 / 0.3);

    --color-accent: var(--accent-500);
    --color-accent-hover: var(--accent-600);
    --color-accent-active: var(--accent-700);
    --color-accent-subtle: var(--accent-100);
    --color-accent-fg: white;

    --color-success: var(--success-500);
    --color-success-subtle: var(--success-100);
    --color-success-fg: var(--success-700);
    --color-warning: var(--warning-500);
    --color-warning-subtle: var(--warning-100);
    --color-warning-fg: var(--warning-700);
    --color-danger: var(--danger-500);
    --color-danger-subtle: var(--danger-100);
    --color-danger-fg: var(--danger-700);

    --color-pattern: oklch(0% 0 0 / 0.0575);

    --color-focus: var(--accent-500);

    color-scheme: light;
  }

  /* Desktop monitors, 90rem and up: use the extra width */
  @media (min-width: 90rem) {
    :root {
      --container-max: 80rem;
      --gutter: clamp(var(--space-8), 3vw, var(--space-12));
    }
  }

  /* Dark: follows the OS unless data-theme says otherwise */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --color-bg: var(--gray-950);
      --color-bg-raised: var(--gray-900);
      --color-bg-subtle: oklch(13% 0.005 286);
      --color-bg-muted: var(--gray-800);
      --color-bg-emphasis: var(--gray-50);
      --color-bg-emphasis-hover: var(--gray-200);
      --color-bg-emphasis-active: var(--gray-300);

      --color-fg: var(--gray-50);
      --color-fg-muted: var(--gray-400);
      --color-fg-subtle: var(--gray-500);
      --color-fg-on-emphasis: var(--gray-950);

      --color-border: var(--gray-800);
      --color-border-strong: var(--gray-700);

      --color-accent: var(--accent-400);
      --color-accent-hover: var(--accent-300);
      --color-accent-active: var(--accent-200);
      --color-accent-subtle: var(--accent-800);
      --color-accent-fg: var(--gray-950);

      --color-success-subtle: oklch(26% 0.06 155);
      --color-success-fg: oklch(80% 0.15 155);
      --color-warning-subtle: oklch(28% 0.07 70);
      --color-warning-fg: oklch(84% 0.15 75);
      --color-danger-subtle: oklch(27% 0.08 22);
      --color-danger-fg: oklch(80% 0.14 22);

      --color-pattern: oklch(100% 0 0 / 0.075);

      --color-focus: var(--accent-400);

      --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.4);
      --shadow-md: 0 4px 12px oklch(0% 0 0 / 0.5);
      --shadow-lg: 0 12px 32px oklch(0% 0 0 / 0.6);

      color-scheme: dark;
    }
  }

  :root[data-theme="dark"] {
    --color-bg: var(--gray-950);
    --color-bg-raised: var(--gray-900);
    --color-bg-subtle: oklch(13% 0.005 286);
    --color-bg-muted: var(--gray-800);
    --color-bg-emphasis: var(--gray-50);
    --color-bg-emphasis-hover: var(--gray-200);
    --color-bg-emphasis-active: var(--gray-300);

    --color-fg: var(--gray-50);
    --color-fg-muted: var(--gray-400);
    --color-fg-subtle: var(--gray-500);
    --color-fg-on-emphasis: var(--gray-950);

    --color-border: var(--gray-800);
    --color-border-strong: var(--gray-700);

    --color-accent: var(--accent-400);
    --color-accent-hover: var(--accent-300);
    --color-accent-active: var(--accent-200);
    --color-accent-subtle: var(--accent-800);
    --color-accent-fg: var(--gray-950);

    --color-success-subtle: oklch(26% 0.06 155);
    --color-success-fg: oklch(80% 0.15 155);
    --color-warning-subtle: oklch(28% 0.07 70);
    --color-warning-fg: oklch(84% 0.15 75);
    --color-danger-subtle: oklch(27% 0.08 22);
    --color-danger-fg: oklch(80% 0.14 22);

    --color-pattern: oklch(100% 0 0 / 0.075);

    --color-focus: var(--accent-400);

    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.4);
    --shadow-md: 0 4px 12px oklch(0% 0 0 / 0.5);
    --shadow-lg: 0 12px 32px oklch(0% 0 0 / 0.6);

    color-scheme: dark;
  }
}

/* ----------------------------------------------------------------- reset */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; }
  body { min-height: 100dvh; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { background: none; border: none; padding: 0; cursor: pointer; }
  h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; text-wrap: balance; }
  p { text-wrap: pretty; }
  ul, ol { padding-inline-start: 1.25em; }
  a { color: inherit; }
  table { border-collapse: collapse; border-spacing: 0; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  }
}

/* ------------------------------------------------------------------ base */

@layer base {
  /* Document */
  body {
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
    color: var(--color-fg);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
  }

  :focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
  }

  ::selection {
    background: var(--color-accent-subtle);
  }

  /* Landmarks. header + main + footer is a page. Add aside for an app shell. */
  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "header" "main" "footer";
  }
  body > header { grid-area: header; }
  body > main   { grid-area: main; min-width: 0; }
  body > footer { grid-area: footer; }
  body > aside  { grid-area: aside; min-width: 0; }

  body:has(> aside) {
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "header" "aside" "main" "footer";
  }

  /* Breakpoints. Phone: below 48rem. Tablet: 48rem. Laptop: 64rem. Desktop: 90rem.
     Custom properties don't work in media queries, so these are literal. */
  @media (min-width: 48rem) {
    body:has(> aside) {
      grid-template-columns: var(--sidebar-width-compact) minmax(0, 1fr);
      grid-template-rows: auto 1fr auto;
      grid-template-areas: "header header" "aside main" "footer footer";
    }
  }
  @media (min-width: 64rem) {
    body:has(> aside) { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  }

  body > header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-6);
    padding: var(--space-3) var(--gutter);
    border-block-end: 1px solid var(--color-border);
  }
  body > header :is(h1, h2, p) {
    margin: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    line-height: inherit;
  }

  body > main {
    padding: var(--space-8) var(--gutter);
  }

  body > footer {
    padding: var(--space-6) var(--gutter);
    font-size: var(--text-sm);
    color: var(--color-fg-muted);
    border-block-start: 1px solid var(--color-border);
  }

  /* Phone: the sidebar is a scrolling strip of links under the header */
  body > aside {
    padding: var(--space-2) var(--gutter);
    background: var(--color-bg-subtle);
  }
  /* Tablet and up: a sidebar beside the content, pinned while the page scrolls */
  @media (min-width: 48rem) {
    body > aside {
      padding: var(--space-6) var(--space-3);
    }
    body > aside > nav {
      position: sticky;
      top: var(--space-6);
    }
  }
  @media (min-width: 64rem) {
    body > aside { padding-inline: var(--space-4); }
  }

  /* Headings: medium weight, tight leading, no bold */
  h1, h2, h3, h4, h5, h6 {
    font-weight: var(--weight-heading);
    line-height: var(--leading-snug);
    margin-block: var(--space-8) var(--space-3);
  }
  h1 { font-size: var(--text-2xl); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }
  h2 { font-size: var(--text-xl); letter-spacing: var(--tracking-tight); }
  h3 { font-size: var(--text-lg); }
  h4 { font-size: var(--text-md); }
  h5 { font-size: var(--text-sm); }
  h6 { font-size: var(--text-xs); color: var(--color-fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }

  :is(h1, h2, h3, h4, h5, h6):first-child { margin-block-start: 0; }

  /* Page title with a tagline. Use for heroes and page headers. */
  hgroup { margin-block-end: var(--space-8); }
  hgroup h1 { font-size: var(--text-3xl); margin: 0; }
  hgroup :is(h2, h3) { margin: 0; }
  hgroup p { margin-block: var(--space-3) 0; font-size: var(--text-lg); color: var(--color-fg-muted); }
  :is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) { margin-block-start: 0; }

  /* Flow */
  p, ul, ol, dl, pre, blockquote, figure, table, hr, details, fieldset {
    margin-block-end: var(--space-4);
  }
  :is(p, ul, ol, dl, pre, blockquote, figure, table, details, fieldset):last-child {
    margin-block-end: 0;
  }

  /* Inline */
  a {
    color: var(--color-accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
    text-decoration-color: color-mix(in oklch, currentColor 40%, transparent);
    transition: color var(--duration-fast) var(--ease);
  }
  a:hover { color: var(--color-accent-hover); text-decoration-color: currentColor; }

  strong, b { font-weight: var(--weight-semibold); }
  small { font-size: var(--text-sm); color: var(--color-fg-muted); }
  abbr[title] { text-decoration: underline dotted; text-underline-offset: 0.15em; cursor: help; }
  mark { background: var(--color-warning-subtle); color: inherit; padding: 0 0.2em; border-radius: var(--radius-sm); }

  code, kbd, samp {
    font-family: var(--font-mono);
    font-size: 0.875em;
  }
  code {
    background: var(--color-bg-muted);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-sm);
  }
  kbd {
    padding: 0.125em 0.375em;
    border: 1px solid var(--color-border-strong);
    border-block-end-width: 2px;
    border-radius: var(--radius-sm);
    font-size: 0.8em;
  }
  pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.6;
    padding: var(--space-4);
    background: var(--color-bg-subtle);
    border-radius: var(--radius-md);
    overflow-x: auto;
  }
  pre code { background: none; padding: 0; font-size: inherit; }

  /* Icons: Phosphor (phosphoricons.com), regular weight, pasted as inline SVG.
     Mark decorative icons aria-hidden="true" and label the button or link instead. */
  svg[aria-hidden="true"] {
    display: inline-block;
    width: 1.25em;
    height: 1.25em;
    fill: currentColor;
    vertical-align: -0.3em;
    flex-shrink: 0;
  }

  /* Blocks */
  ul, ol { padding-inline-start: 1.5em; }
  li { margin-block-end: var(--space-1); }
  li > :is(ul, ol) { margin-block: var(--space-1) 0; }
  nav ul, nav ol { list-style: none; padding: 0; margin: 0; }

  dt { font-weight: var(--weight-medium); }
  dd { color: var(--color-fg-muted); margin-block-end: var(--space-2); }

  blockquote {
    padding-inline-start: var(--space-4);
    border-inline-start: 3px solid var(--color-border-strong);
    color: var(--color-fg-muted);
  }
  blockquote cite { display: block; margin-block-start: var(--space-2); font-size: var(--text-sm); font-style: normal; }

  hr {
    border: 0;
    border-block-start: 1px solid var(--color-border);
    margin-block: var(--space-8);
  }

  figure { overflow-x: auto; }
  figcaption { margin-block-start: var(--space-2); font-size: var(--text-sm); color: var(--color-fg-muted); }
  img, video { border-radius: var(--radius-lg); }

  /* Navigation */
  nav ul { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); }
  nav li { margin: 0; }
  nav a {
    color: var(--color-fg-muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-decoration: none;
  }
  nav a:hover, nav a[aria-current] { color: var(--color-fg); }

  aside nav {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    scrollbar-width: none;
  }
  aside nav ul { flex-wrap: nowrap; gap: var(--space-1); }
  aside nav a {
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
  }
  aside nav a svg { color: var(--color-fg-subtle); }
  aside nav a:hover { background: var(--color-bg-muted); }
  aside nav a[aria-current] { background: var(--color-bg-muted); color: var(--color-fg); }
  aside nav h2, aside nav h3 {
    display: none;
    font-size: var(--text-xs);
    color: var(--color-fg-subtle);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-block: var(--space-6) var(--space-2);
    padding-inline: var(--space-3);
  }
  @media (min-width: 48rem) {
    aside nav { display: block; overflow: visible; }
    aside nav ul { flex-direction: column; }
    aside nav :is(h2, h3) { display: block; }
  }

  /* Table: horizontal hairlines only */
  table {
    width: 100%;
    font-size: var(--text-sm);
    text-align: start;
  }
  caption {
    caption-side: top;
    text-align: start;
    margin-block-end: var(--space-2);
    color: var(--color-fg-muted);
  }
  th {
    text-align: start;
    font-weight: var(--weight-medium);
    color: var(--color-fg-muted);
    padding: var(--space-2) var(--space-3);
    border-block-end: 1px solid var(--color-border);
    white-space: nowrap;
  }
  td {
    padding: var(--space-3);
    border-block-end: 1px solid var(--color-border);
    vertical-align: top;
  }
  figure > table :is(th, td) { white-space: nowrap; } /* the figure scrolls, so cells don't wrap */
  th:first-child, td:first-child { padding-inline-start: 0; }
  th:last-child, td:last-child { padding-inline-end: 0; }
  tbody tr:hover td { background: var(--color-bg-subtle); }

  /* Forms */
  label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    margin-block-end: var(--space-1);
  }
  label:has(> input[type="checkbox"], > input[type="radio"]) {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-md);
    font-weight: var(--weight-normal);
    margin-block-end: var(--space-2);
  }

  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="submit"], [type="button"], [type="reset"]),
  textarea,
  select {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    line-height: var(--leading-normal);
    color: var(--color-fg);
    background: var(--color-bg-raised);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    margin-block-end: var(--space-4);
    transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
  }
  label > :is(input, textarea, select) { margin-block-start: var(--space-1); }

  :is(input, textarea, select):focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
  }
  ::placeholder { color: var(--color-fg-subtle); }

  textarea { resize: vertical; min-height: 6rem; }

  select:not([multiple], [size]) {
    appearance: none;
    padding-inline-end: var(--space-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%23888'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");
    background-size: 1rem;
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
  }

  input[type="checkbox"], input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--color-accent);
    flex-shrink: 0;
  }
  input[type="range"], progress { accent-color: var(--color-accent); width: 100%; }

  input[type="checkbox"][role="switch"] {
    appearance: none;
    width: 2.25rem;
    height: 1.25rem;
    border-radius: var(--radius-full);
    background: var(--color-border-strong);
    position: relative;
    transition: background var(--duration-fast) var(--ease);
  }
  input[type="checkbox"][role="switch"]::before {
    content: "";
    position: absolute;
    inset: 2px auto 2px 2px;
    width: calc(1.25rem - 4px);
    border-radius: var(--radius-full);
    background: white;
    box-shadow: var(--shadow-sm);
    transition: translate var(--duration-fast) var(--ease);
  }
  input[type="checkbox"][role="switch"]:checked { background: var(--color-accent); }
  input[type="checkbox"][role="switch"]:checked::before { translate: 1rem 0; }

  input[type="file"] { font-size: var(--text-sm); margin-block-end: var(--space-4); }
  ::file-selector-button {
    margin-inline-end: var(--space-3);
    padding: var(--space-1) var(--space-3);
    font: inherit;
    font-weight: var(--weight-medium);
    color: var(--color-fg);
    background: var(--color-bg-raised);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    cursor: pointer;
  }

  /* Help text under a control */
  :is(input, textarea, select) + small {
    display: block;
    margin-block: calc(var(--space-3) * -1) var(--space-4);
  }

  [aria-invalid="true"] {
    border-color: var(--color-danger) !important;
  }
  [aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px var(--color-danger-subtle); }
  [aria-invalid="true"] + small { color: var(--color-danger-fg); }

  :is(input, textarea, select, button, [role="button"]):disabled,
  [role="button"][aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
  }

  fieldset { border: 0; padding: 0; min-width: 0; }
  legend {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    padding: 0;
    margin-block-end: var(--space-2);
  }

  /* Buttons. Bare button is primary and ink-colored; the accent is for links, focus, and state.
     Variants live in the components layer. */
  button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1.25;
    color: var(--color-fg-on-emphasis);
    background: var(--color-bg-emphasis);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
  }
  :is(button, [role="button"]):has(> svg:only-child) { padding: var(--space-2); }
  :is(button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"]):hover { background: var(--color-bg-emphasis-hover); color: var(--color-fg-on-emphasis); }
  :is(button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"]):active { background: var(--color-bg-emphasis-active); }

  /* Touch: bigger targets on coarse pointers, whatever the screen width */
  @media (pointer: coarse) {
    :is(button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"]):not(.small),
    nav a {
      min-height: 2.75rem;
    }
    nav a { display: inline-flex; align-items: center; }
    input[type="checkbox"]:not([role="switch"]), input[type="radio"] { width: 1.25rem; height: 1.25rem; }
    label:has(> input[type="checkbox"], > input[type="radio"]) { min-height: 2.75rem; margin-block-end: 0; }
  }

  /* Disclosure */
  details {
    border-block-end: 1px solid var(--color-border);
  }
  summary {
    cursor: pointer;
    font-weight: var(--weight-medium);
    padding-block: var(--space-3);
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
  }
  summary::-webkit-details-marker { display: none; }
  summary::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-inline-end: 1.5px solid var(--color-fg-subtle);
    border-block-end: 1.5px solid var(--color-fg-subtle);
    rotate: 45deg;
    margin-block-end: 0.2rem;
    transition: rotate var(--duration-fast) var(--ease);
    flex-shrink: 0;
  }
  details[open] > summary::after { rotate: 225deg; margin-block-end: -0.2rem; }
  details > :not(summary) { margin-block-end: var(--space-4); }
  details > :not(summary):last-child { margin-block-end: var(--space-4); }

  /* Optional phone menu: a native disclosure with navigation in the page header. */
  body > header:has(> details > nav) {
    position: relative;
    gap: 0;
  }
  body > header:has(> details > nav) > :is(h1, h2, p) {
    display: flex;
    align-items: center;
    min-height: var(--space-10);
    padding-inline-end: calc(var(--space-16) * 2);
  }
  body > header > details:has(> nav) {
    width: 100%;
    margin: 0;
    border: 0;
  }
  body > header > details:has(> nav) > summary {
    position: absolute;
    inset-block-start: var(--space-3);
    inset-inline-end: var(--gutter);
    min-height: var(--space-10);
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
  }
  body > header > details:has(> nav) > summary::after { content: none; }
  body > header > details[open]:has(> nav) > summary { background: var(--color-bg-muted); }
  body > header > details > nav {
    margin: var(--space-3) 0 0;
  }
  body > header > details > nav ul { flex-direction: column; gap: var(--space-1); }
  body > header > details > nav a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    white-space: normal;
  }
  body > header > details > nav a:is(:hover, [aria-current]) { background: var(--color-bg-muted); }
  body > header > details > nav h3 {
    margin: var(--space-4) var(--space-3) var(--space-2);
    font-size: var(--text-xs);
    color: var(--color-fg-muted);
  }
  @media (width < 48rem) {
    /* Keep layout utilities from revealing the desktop navigation. */
    body > header:has(> details > nav) > nav,
    body:has(> header > details > nav) > aside { display: none !important; }
  }

  @media (pointer: coarse) {
    body > header > details:has(> nav) > summary {
      min-height: calc(var(--space-10) + var(--space-1));
    }
    body > header:has(> details > nav) > :is(h1, h2, p) {
      min-height: calc(var(--space-10) + var(--space-1));
    }
  }
  @media (min-width: 48rem) {
    body > header:has(> details > nav) { gap: var(--space-3) var(--space-6); }
    body > header:has(> details > nav) > :is(h1, h2, p) {
      min-height: 0;
      padding-inline-end: 0;
    }
    body > header > details:has(> nav) { display: none; }
    body > header:has(> details > nav) > nav { display: flex; }
    body:has(> header > details > nav) > aside { display: block; }
  }

  /* Dialog */
  dialog {
    margin: auto; /* reset zeroes margins; this restores centering */
    width: min(32rem, calc(100% - 2 * var(--gutter)));
    padding: var(--space-6);
    color: var(--color-fg);
    background: var(--color-bg-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
  }
  dialog::backdrop { background: oklch(0% 0 0 / 0.4); }
  dialog > header { margin-block-end: var(--space-4); }
  dialog > header :is(h1, h2, h3) { margin: 0; font-size: var(--text-lg); }
  dialog > header p { margin: 0; color: var(--color-fg-muted); font-size: var(--text-sm); }
  dialog > footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-block-start: var(--space-6);
  }
}

/* ------------------------------------------------------------ components */
/* Things HTML has no element for. An element for a thing that stands alone,
   a class for a modifier. Three custom elements and eight classes, no more.
   The custom elements are unregistered: valid HTML, no JavaScript, styled here. */

@layer components {
  /* Button variants */
  :is(button, [role="button"], input[type="submit"], input[type="button"], input[type="reset"]).secondary {
    color: var(--color-fg);
    background: var(--color-bg-raised);
    border-color: var(--color-border-strong);
  }
  :is(button, [role="button"]).secondary:hover { background: var(--color-bg-subtle); }
  :is(button, [role="button"]).secondary:active { background: var(--color-bg-muted); }

  :is(button, [role="button"]).ghost {
    color: var(--color-fg-muted);
    background: transparent;
  }
  :is(button, [role="button"]).ghost:hover { color: var(--color-fg); background: var(--color-bg-muted); }

  :is(button, [role="button"], input[type="submit"]).danger {
    color: white;
    background: var(--color-danger);
  }
  :is(button, [role="button"]).danger:hover { background: var(--danger-700); }

  :is(button, [role="button"]).small {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
  }

  /* Badge: an inline status label */
  .badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125em 0.5em;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.5;
    color: var(--color-fg-muted);
    background: var(--color-bg-muted);
    border-radius: var(--radius-sm);
    white-space: nowrap;
  }
  .badge.success { color: var(--color-success-fg); background: var(--color-success-subtle); }
  .badge.warning { color: var(--color-warning-fg); background: var(--color-warning-subtle); }
  .badge.danger  { color: var(--color-danger-fg);  background: var(--color-danger-subtle); }

  /* Tabs: a nav with the current item underlined */
  .tabs ul {
    gap: 0;
    border-block-end: 1px solid var(--color-border);
  }
  .tabs a {
    display: block;
    padding: var(--space-2) var(--space-3);
    margin-block-end: -1px;
    border-block-end: 2px solid transparent;
  }
  .tabs a[aria-current] {
    color: var(--color-fg);
    border-color: var(--color-fg);
  }

  /* Card: a raised surface with optional header and footer. No border, no shadow. */
  ui-card {
    display: block;
    padding: var(--space-5);
    background: var(--color-bg-raised);
    border-radius: var(--radius-lg);
    margin-block-end: var(--space-4);
  }
  ui-card > header { margin-block-end: var(--space-3); }
  ui-card > header :is(h1, h2, h3, h4) { margin: 0; font-size: var(--text-lg); }
  ui-card > header p { margin: 0; color: var(--color-fg-muted); font-size: var(--text-sm); }
  ui-card > footer { margin-block-start: var(--space-4); font-size: var(--text-sm); color: var(--color-fg-muted); }

  /* Toast: a floating status message */
  ui-toast {
    display: block;
    position: fixed;
    inset-block-end: var(--space-6);
    inset-inline-end: var(--space-6);
    z-index: 100;
    max-width: min(24rem, calc(100% - 2 * var(--space-6)));
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--color-fg-on-emphasis);
    background: var(--color-bg-emphasis);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
  }
  ui-toast a, ui-toast button { color: inherit; }

  /* Empty state: nothing here yet */
  ui-empty {
    display: block;
    padding: var(--space-12) var(--space-6);
    text-align: center;
    background: var(--color-bg-subtle);
    border-radius: var(--radius-lg);
  }
  ui-empty :is(h2, h3) { margin: 0 0 var(--space-2); font-size: var(--text-lg); }
  ui-empty p { color: var(--color-fg-muted); max-width: 32rem; margin-inline: auto; }
  ui-empty p:last-child { margin-block-start: var(--space-4); }
}

/* ------------------------------------------------------------- utilities */
/* Layout helpers and optional background patterns. */

@layer utilities {
  .container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
  }
  .container.narrow { max-width: var(--container-narrow); }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 16rem), 100%), 1fr));
    gap: var(--gap, var(--space-4));
  }
  .grid > * { margin: 0; min-width: 0; }

  .stack { display: flex; flex-direction: column; gap: var(--gap, var(--space-4)); }
  .stack > * { margin: 0; }

  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap, var(--space-3));
  }
  .cluster > * { margin: 0; }
  .cluster.between { justify-content: space-between; }

  /* Decorative textures preserve the surface color and content opacity. */
  .pattern-dots {
    background-image: radial-gradient(circle, var(--color-pattern) var(--pattern-stroke), transparent var(--pattern-stroke));
    background-size: var(--pattern-size) var(--pattern-size);
    background-repeat: repeat;
  }

  .pattern-grid {
    background-image:
      linear-gradient(var(--color-pattern) var(--pattern-stroke), transparent var(--pattern-stroke)),
      linear-gradient(90deg, var(--color-pattern) var(--pattern-stroke), transparent var(--pattern-stroke));
    background-size: var(--pattern-size) var(--pattern-size);
    background-repeat: repeat;
  }

  .pattern-diagonal {
    background-image: repeating-linear-gradient(135deg, var(--color-pattern) 0 var(--pattern-stroke), transparent var(--pattern-stroke) var(--pattern-size));
    background-size: auto;
    background-repeat: repeat;
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
