/*
 * Simple Material: classless Material 3 styles for semantic HTML.
 * Theme with data-theme on the html element, or by setting --hue on :root.
 * Variants use data-variant="…".
 * Everything sits in one cascade layer, so any unlayered rule overrides it.
 */

@property --line {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

@property --lift {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

@layer simple-material {
  /* Themes: every colour role below is derived from four settings, in both
     light and dark mode. --hue is the primary hue, --tertiary-hue the
     accent's, --chroma scales how colourful the accents are and --tint how
     strongly the hue tints surfaces, text and outlines. Violet is the default;
     pick another with data-theme on the html element. A select named "theme"
     switches between them. Each theme sets all four, so none leak between
     them. */

  :root,
  :root:has(select[name="theme"] [value="violet"]:checked) {
    --hue: 285;
    --tertiary-hue: calc(var(--hue) + 60);
    --chroma: 1;
    --tint: 1;
  }

  /* Rose with a blue-violet accent */
  :root[data-theme="rose"],
  :root:has(select[name="theme"] [value="rose"]:checked) {
    --hue: 8;
    --tertiary-hue: 296;
    --chroma: 1.1;
    --tint: 1;
  }

  /* Orange with a deep blue accent */
  :root[data-theme="orange"],
  :root:has(select[name="theme"] [value="orange"]:checked) {
    --hue: 54;
    --tertiary-hue: 238;
    --chroma: 0.8;
    --tint: 1;
  }

  /* Moss green and copper, warm surfaces */
  :root[data-theme="olive"],
  :root:has(select[name="theme"] [value="olive"]:checked) {
    --hue: 120;
    --tertiary-hue: 57;
    --chroma: 0.65;
    --tint: 2.5;
  }

  /* Persian green, burnt sienna accent */
  :root[data-theme="teal"],
  :root:has(select[name="theme"] [value="teal"]:checked) {
    --hue: 183;
    --tertiary-hue: 35;
    --chroma: 0.55;
    --tint: 1;
  }

  /* Blue, gold accent, navy surfaces */
  :root[data-theme="navy"],
  :root:has(select[name="theme"] [value="navy"]:checked) {
    --hue: 253;
    --tertiary-hue: 87;
    --chroma: 0.95;
    --tint: 2;
  }

  /* Retro themes: the colours of Windows 98's appearance schemes and Mac OS
     9's Platinum, on the same Material shapes. Instead of a hue each sets
     three colours: --face (the grey of buttons and dialogs), --title (the
     active title bar, or Platinum's variation colour) and --accent (used by
     mark). The Windows values are the ones ReactOS ships for these schemes. */

  /* Windows Standard: silver, navy title bars, teal desktop */
  :root[data-theme="win98"],
  :root:has(select[name="theme"] [value="win98"]:checked) {
    --face: #c0c0c0;
    --title: #000080;
    --accent: #008080;
  }

  /* Rainy Day: blue-grey, slate title bars fading to sky blue */
  :root[data-theme="win98-rainy-day"],
  :root:has(select[name="theme"] [value="win98-rainy-day"]:checked) {
    --face: #8399b1;
    --title: #4f657d;
    --accent: #80b4d0;
  }

  /* Eggplant: sage, green title bars fading to purple */
  :root[data-theme="win98-eggplant"],
  :root:has(select[name="theme"] [value="win98-eggplant"]:checked) {
    --face: #90b0a8;
    --title: #588078;
    --accent: #834b83;
  }

  /* Spruce: mint, green title bars fading to pale blue */
  :root[data-theme="win98-spruce"],
  :root:has(select[name="theme"] [value="win98-spruce"]:checked) {
    --face: #a2c8a9;
    --title: #599764;
    --accent: #98c8e8;
  }

  /* Brick: khaki, maroon title bars fading to copper */
  :root[data-theme="win98-brick"],
  :root:has(select[name="theme"] [value="win98-brick"]:checked) {
    --face: #c2bfa5;
    --title: #800000;
    --accent: #b07440;
  }

  /* Platinum with the Lavender variation, as Mac OS 9 shipped */
  :root[data-theme="macos9"],
  :root:has(select[name="theme"] [value="macos9"]:checked) {
    --face: #dddddd;
    --title: #6363ce;
    --accent: #ffff9c;
  }

  /* Platinum with the Silver variation */
  :root[data-theme="macos9-silver"],
  :root:has(select[name="theme"] [value="macos9-silver"]:checked) {
    --face: #dddddd;
    --title: #737373;
    --accent: #ffff9c;
  }

  /* Roles for the retro themes, from those three colours: surfaces are the
     face, lifted to at least 80% lightness so text keeps its contrast, with
     white fields and pale yellow tooltips; primary is the title colour,
     darkened where needed to read as a link on the face. Neither system had a
     dark mode, so that is invented. Any data-theme starting win98- or macos9-
     gets these roles. A theme select wins over data-theme, as it does for the
     hue settings. Forced colours keep their system colours. */

  @media not (forced-colors: active) {
    :root:is([data-theme|="win98"], [data-theme|="macos9"]):not(
        :has(select[name="theme"])
      ),
    :root:has(
        select[name="theme"] :is([value|="win98"], [value|="macos9"]):checked
      ) {
      --chrome: light-dark(
        oklch(from var(--face) max(l, 0.8) c h),
        oklch(from var(--face) 0.27 calc(c / 2) h)
      );
      --paper: light-dark(#fff, oklch(from var(--face) 0.36 calc(c / 2) h));
      --primary: light-dark(
        oklch(from var(--title) min(l, 0.4) c h),
        oklch(from var(--title) 0.8 min(c, 0.12) h)
      );
      --on-primary: light-dark(
        #fff,
        oklch(from var(--title) 0.25 min(c, 0.1) h)
      );
      --inverse-primary: oklch(from var(--title) min(l, 0.4) c h);
      --primary-container: light-dark(
        oklch(from var(--title) 0.84 min(c, 0.07) h),
        oklch(from var(--title) 0.38 min(c, 0.1) h)
      );
      --on-primary-container: light-dark(
        oklch(from var(--title) 0.3 min(c, 0.12) h),
        oklch(from var(--title) 0.92 min(c, 0.05) h)
      );
      --secondary-container: color-mix(
        in oklab,
        var(--chrome),
        var(--primary) 15%
      );
      --on-secondary-container: light-dark(
        oklch(from var(--title) 0.25 min(c, 0.05) h),
        oklch(from var(--title) 0.92 min(c, 0.03) h)
      );
      --tertiary-container: light-dark(
        oklch(from var(--accent) 0.9 min(c, 0.07) h),
        oklch(from var(--accent) 0.4 min(c, 0.08) h)
      );
      --on-tertiary-container: light-dark(
        oklch(from var(--accent) 0.3 min(c, 0.08) h),
        oklch(from var(--accent) 0.92 min(c, 0.05) h)
      );
      --surface: var(--chrome);
      --surface-low: color-mix(in oklab, var(--chrome), var(--paper) 20%);
      --surface-mid: color-mix(in oklab, var(--chrome), var(--paper) 35%);
      --surface-high: color-mix(in oklab, var(--chrome), var(--paper) 55%);
      --surface-highest: var(--paper);
      --on-surface: light-dark(
        #000,
        oklch(from var(--face) 0.94 calc(c / 4) h)
      );
      --on-surface-variant: light-dark(
        oklch(from var(--face) 0.36 calc(c / 2) h),
        oklch(from var(--face) 0.82 calc(c / 2) h)
      );
      --outline: light-dark(
        oklch(from var(--face) 0.5 calc(c / 2) h),
        oklch(from var(--face) 0.66 calc(c / 2) h)
      );
      --outline-variant: light-dark(
        oklch(from var(--face) 0.64 c h),
        oklch(from var(--face) 0.44 calc(c / 2) h)
      );
      --inverse-surface: #ffffe1;
      --inverse-on-surface: #000;
    }
  }

  /* Tokens */

  :root {
    color-scheme: light dark;
    interpolate-size: allow-keywords;
    --primary: light-dark(
      oklch(47% calc(0.15 * var(--chroma)) var(--hue)),
      oklch(82% calc(0.1 * var(--chroma)) var(--hue))
    );
    --on-primary: light-dark(
      #fff,
      oklch(30% calc(0.1 * var(--chroma)) var(--hue))
    );
    --inverse-primary: light-dark(
      oklch(82% calc(0.1 * var(--chroma)) var(--hue)),
      oklch(47% calc(0.15 * var(--chroma)) var(--hue))
    );
    --primary-container: light-dark(
      oklch(93% calc(0.05 * var(--chroma)) var(--hue)),
      oklch(37% calc(0.11 * var(--chroma)) var(--hue))
    );
    --on-primary-container: light-dark(
      oklch(30% calc(0.1 * var(--chroma)) var(--hue)),
      oklch(93% calc(0.05 * var(--chroma)) var(--hue))
    );
    --secondary-container: light-dark(
      oklch(92% calc(0.03 * var(--chroma)) var(--hue)),
      oklch(36% calc(0.03 * var(--chroma)) var(--hue))
    );
    --on-secondary-container: light-dark(
      oklch(28% calc(0.03 * var(--chroma)) var(--hue)),
      oklch(92% calc(0.03 * var(--chroma)) var(--hue))
    );
    --tertiary-container: light-dark(
      oklch(93% calc(0.05 * var(--chroma)) var(--tertiary-hue)),
      oklch(38% calc(0.07 * var(--chroma)) var(--tertiary-hue))
    );
    --on-tertiary-container: light-dark(
      oklch(30% calc(0.07 * var(--chroma)) var(--tertiary-hue)),
      oklch(93% calc(0.05 * var(--chroma)) var(--tertiary-hue))
    );
    --warning: light-dark(oklch(70% 0.15 75), oklch(82% 0.13 80));
    --error: light-dark(oklch(51% 0.19 28), oklch(80% 0.11 28));
    --on-error: light-dark(#fff, oklch(30% 0.12 28));
    --surface: light-dark(
      oklch(98.5% calc(0.005 * var(--tint)) var(--hue)),
      oklch(17% calc(0.01 * var(--tint)) var(--hue))
    );
    --surface-low: light-dark(
      oklch(96.5% calc(0.008 * var(--tint)) var(--hue)),
      oklch(20% calc(0.012 * var(--tint)) var(--hue))
    );
    --surface-mid: light-dark(
      oklch(95% calc(0.01 * var(--tint)) var(--hue)),
      oklch(22% calc(0.012 * var(--tint)) var(--hue))
    );
    --surface-high: light-dark(
      oklch(93% calc(0.01 * var(--tint)) var(--hue)),
      oklch(25% calc(0.012 * var(--tint)) var(--hue))
    );
    --surface-highest: light-dark(
      oklch(91% calc(0.012 * var(--tint)) var(--hue)),
      oklch(28% calc(0.012 * var(--tint)) var(--hue))
    );
    --on-surface: light-dark(
      oklch(22% calc(0.01 * var(--tint)) var(--hue)),
      oklch(91% calc(0.01 * var(--tint)) var(--hue))
    );
    --on-surface-variant: light-dark(
      oklch(44% calc(0.02 * var(--tint)) var(--hue)),
      oklch(80% calc(0.02 * var(--tint)) var(--hue))
    );
    --outline: light-dark(
      oklch(58% calc(0.02 * var(--tint)) var(--hue)),
      oklch(63% calc(0.02 * var(--tint)) var(--hue))
    );
    --outline-variant: light-dark(
      oklch(83% calc(0.015 * var(--tint)) var(--hue)),
      oklch(40% calc(0.015 * var(--tint)) var(--hue))
    );
    --inverse-surface: light-dark(
      oklch(31% calc(0.01 * var(--tint)) var(--hue)),
      oklch(91% calc(0.01 * var(--tint)) var(--hue))
    );
    --inverse-on-surface: light-dark(
      oklch(95% calc(0.01 * var(--tint)) var(--hue)),
      oklch(31% calc(0.01 * var(--tint)) var(--hue))
    );
    --hover: color-mix(in srgb, var(--on-surface) 8%, transparent);
    --elev-1: 0 1px 2px rgb(0 0 0 / 0.3), 0 1px 3px 1px rgb(0 0 0 / 0.15);
    --elev-2: 0 1px 2px rgb(0 0 0 / 0.3), 0 2px 6px 2px rgb(0 0 0 / 0.15);
    --elev-3: 0 1px 3px rgb(0 0 0 / 0.3), 0 4px 8px 3px rgb(0 0 0 / 0.15);
    --radius: 0.75rem;
    --ease: cubic-bezier(0.2, 0, 0, 1);
    --fast: 150ms;
    --slow: 300ms;
    --check: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
    --font: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
    --label: 500 0.875rem/1.25rem var(--font);
    scroll-behavior: smooth;
    scroll-padding-top: 5rem;
    font: 400 1rem/1.5 var(--font);
    text-size-adjust: 100%;
  }

  *,
  ::before,
  ::after {
    box-sizing: border-box;
  }

  /* Page layout: body > header (app bar), body > nav (side nav), main, footer */

  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    margin: 0;
    background: var(--surface);
    color: var(--on-surface);
  }

  body > a:first-child {
    position: absolute;
    z-index: 3;
    top: 0.75rem;
    left: 0.75rem;
    translate: 0 -200%;
    &:focus {
      translate: 0;
    }
  }

  /* App bar: body > header. A leading button opens the side nav as a drawer on
     narrow screens; the first link is the title. */

  body > header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    min-height: 4rem;
    padding: 0.5rem 1rem;
    background: color-mix(
      in oklab,
      var(--surface),
      var(--surface-mid) var(--lift)
    );
    > * {
      margin: 0;
    }
    > a {
      min-width: 0;
      margin-inline-end: auto;
      overflow: hidden;
      color: var(--on-surface);
      font-size: 1.375rem;
      text-decoration: none;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  /* Phones: keep the app bar on one row; the title gives way first. */
  @media (width < 30rem) {
    body > header {
      flex-wrap: nowrap;
      gap: 0.5rem;
      padding-inline: 0.75rem;
      > a {
        font-size: 1.125rem;
      }
      [data-variant="segmented"] > label,
      [data-variant="segmented"] > label:has(:checked) {
        padding-inline: 0.625rem;
      }
      [data-variant="segmented"] :checked {
        width: 0;
        margin: 0;
        &::before {
          display: none;
        }
      }
    }
  }

  @supports (animation-timeline: scroll()) {
    body > header {
      animation: lift linear both;
      animation-timeline: scroll();
      animation-range: 0 4rem;
    }
  }

  /* Animate a percentage, not a colour: light-dark() inside @keyframes
     resolves against the system theme, not the page's color-scheme. */
  @keyframes lift {
    to {
      --lift: 100%;
    }
  }

  /* Side nav: body > nav, a sticky column on wide screens. On narrow screens a
     nav with popover becomes a modal drawer opened from the app bar. */

  body > nav {
    padding: 0.5rem 0.75rem;
    ul {
      flex-direction: column;
      align-items: stretch;
    }
    ul a {
      justify-content: flex-start;
      min-height: 3rem;
      padding-inline: 1.5rem;
    }
    > button {
      display: flex;
      margin: 0 0 0.5rem auto;
    }
    hr {
      margin: 0.5rem 1rem;
    }
    /* A select, such as a theme picker, is an outlined pill like the links */
    select {
      --accent: transparent;
      min-height: 3rem;
      padding-inline-start: 1.5rem;
      border: 1px solid var(--outline);
      border-radius: 999px;
      background-color: transparent;
      color: var(--on-surface-variant);
      font: var(--label);
      &:focus-visible {
        outline: 3px solid var(--primary);
      }
    }
  }

  @media (width >= 64rem) {
    body:has(> nav) {
      grid-template-columns: 15rem minmax(0, 1fr);
    }
    body > :is(header, footer) {
      grid-column: 1 / -1;
    }
    body > nav {
      position: sticky;
      top: 4rem;
      align-self: start;
      max-height: calc(100dvh - 4rem);
      overflow-y: auto;
    }
    /* Shown in the page rather than as a popover */
    body > nav[popover] {
      display: block;
      inset: 4rem auto auto;
      width: auto;
      margin: 0;
      background: none;
      color: inherit;
      opacity: 1;
      translate: none;
    }
    body:has(> nav[popover]) > header > button:first-child {
      display: none;
    }
  }

  @media (width < 64rem) {
    body > nav[popover] {
      --from: -100% 0;
      inset: 0 auto 0 0;
      width: min(22.5rem, 100vw - 3.5rem);
      height: 100dvh;
      margin: 0;
      padding: 0.75rem;
      border-radius: 0 1rem 1rem 0;
      background: var(--surface-low);
      color: var(--on-surface);
    }
  }

  main {
    width: 100%;
    max-width: 62rem;
    margin-inline: auto;
    padding: 0 1.5rem 3rem;
    > header {
      padding-block: 3rem 2rem;
    }
    > header h1 {
      margin-bottom: 1rem;
      font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem);
    }
    > header p {
      max-width: 40rem;
      color: var(--on-surface-variant);
      font-size: 1.125rem;
    }
    > section {
      padding-block: 2rem;
      border-top: 1px solid var(--outline-variant);
    }
  }

  body > footer {
    padding: 2rem 1.5rem;
    background: var(--surface-mid);
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    text-align: center;
  }

  /* Layout: data-layout = grid (equal columns) | row (natural widths) |
     split (wide + narrow column). All wrap to one column when space runs out. */

  [data-layout] {
    gap: 1rem;
    margin: 0 0 1rem;
    > * {
      margin: 0;
    }
  }
  [data-layout="grid"] {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr));
    > :is(h1, h2, h3, h4, h5, h6, hgroup, p, pre) {
      grid-column: 1 / -1;
    }
  }
  [data-layout="row"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  [data-layout="split"] {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    > * {
      flex: 1 1 14rem;
    }
    > :first-child {
      flex: 2 1 24rem;
    }
  }

  /* Typography */

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 2rem 0 1rem;
    font-weight: 400;
    line-height: 1.25;
    text-wrap: balance;
    &:first-child {
      margin-top: 0;
    }
  }
  h1 {
    font-size: 2.25rem;
  }
  h2 {
    font-size: 1.75rem;
  }
  h3 {
    font-size: 1.375rem;
  }
  h4 {
    font-size: 1.125rem;
  }
  h5 {
    font-size: 1rem;
  }
  h6 {
    font-size: 0.875rem;
  }
  h4,
  h5,
  h6 {
    font-weight: 500;
  }

  p,
  ul,
  ol,
  dl,
  pre,
  blockquote,
  figure,
  address,
  table,
  form,
  fieldset,
  aside,
  main nav {
    margin: 0 0 1rem;
  }

  :where(
      article,
      section,
      aside,
      blockquote,
      dialog,
      fieldset,
      figure,
      li,
      dd,
      td
    )
    > :last-child {
    margin-bottom: 0;
  }

  hgroup > p {
    margin-top: -0.5rem;
    color: var(--on-surface-variant);
  }

  a {
    color: var(--primary);
    text-underline-offset: 0.2em;
    &:hover {
      text-decoration-thickness: 2px;
    }
  }

  /* A linked heading keeps the heading's look, underlined only on hover */
  :is(h1, h2, h3, h4, h5, h6) > a:not(:hover) {
    color: inherit;
    text-decoration: none;
  }

  /* An image in a linked heading is an icon, sized to the text */
  :is(h1, h2, h3, h4, h5, h6) > a > img {
    width: auto;
    height: 0.75em;
    vertical-align: -0.1em;
  }

  :focus-visible,
  :is([data-variant="chips"], [data-variant="segmented"])
    label:has(:focus-visible) {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
  }

  ::selection {
    background: var(--primary-container);
    color: var(--on-primary-container);
  }

  small {
    font-size: 0.75rem;
  }

  code,
  kbd,
  samp,
  pre {
    font-family: var(--mono);
    font-size: 0.875em;
  }

  :not(pre) > code,
  kbd,
  samp {
    padding: 0.125em 0.375em;
    border-radius: 0.25rem;
    background: var(--surface-high);
  }

  kbd {
    box-shadow: inset 0 -2px var(--outline-variant);
  }

  pre {
    padding: 1rem;
    overflow-x: auto;
    border-radius: var(--radius);
    background: var(--surface-mid);
  }

  mark {
    padding: 0 0.25em;
    border-radius: 0.25rem;
    background: var(--tertiary-container);
    color: var(--on-tertiary-container);
  }

  abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
  }

  del {
    color: var(--error);
  }

  ins {
    text-decoration-color: var(--primary);
  }

  blockquote {
    padding-inline-start: 1rem;
    border-inline-start: 4px solid var(--primary);
    font-size: 1.25rem;
  }

  hr {
    margin: 2rem 0;
    border: 0;
    border-top: 1px solid var(--outline-variant);
  }

  address {
    font-style: normal;
  }

  aside {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    background: var(--secondary-container);
    color: var(--on-secondary-container);
  }

  /* Lists: dl is a two-line Material list */

  ul,
  ol {
    padding-inline-start: 1.5rem;
  }

  li::marker {
    color: var(--on-surface-variant);
  }

  dt {
    font-weight: 500;
  }

  dd {
    margin: 0 0 0.75rem;
    color: var(--on-surface-variant);
    font-size: 0.875rem;
  }

  dd + dt {
    padding-top: 0.75rem;
    border-top: 1px solid var(--outline-variant);
  }

  /* Media */

  img,
  video,
  svg {
    max-width: 100%;
    height: auto;
  }

  audio {
    width: 100%;
  }

  figure :is(img, video) {
    display: block;
    border-radius: var(--radius);
  }

  figure:has(> table) {
    overflow-x: auto;
  }

  figcaption {
    margin-top: 0.5rem;
    color: var(--on-surface-variant);
    font-size: 0.875rem;
  }

  /* State layer shared by everything clickable */

  :where(
    button,
    a[data-variant],
    [type="submit"],
    [type="reset"],
    [type="button"],
    summary,
    nav ul a,
    menu a,
    [type="search"] + ul a,
    :is([data-variant="chips"], [data-variant="segmented"]) label
  ) {
    background-color: var(--bg, transparent);
    transition:
      background-color var(--fast),
      border-color var(--fast),
      box-shadow var(--fast),
      color var(--fast),
      border-radius var(--slow) var(--ease);
    &:hover:not(:disabled) {
      background-color: color-mix(
        in srgb,
        var(--bg, transparent),
        currentColor 8%
      );
    }
    &:focus-visible {
      background-color: color-mix(
        in srgb,
        var(--bg, transparent),
        currentColor 12%
      );
    }
  }

  /* Buttons, and pill-shaped links: filled by default;
     data-variant = tonal | elevated | outlined | text | icon | fab | chip */

  button,
  a[data-variant],
  nav ul a,
  [type="submit"],
  [type="reset"],
  [type="button"] {
    --bg: var(--primary);
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.5rem;
    padding: 0 1.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    color: var(--on-primary);
    font: var(--label);
    letter-spacing: 0.1px;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
  }

  /* Ripple: a circle that grows from the centre while pressed */
  :is(button, a[data-variant])::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle, currentColor 50%, transparent 50.5%)
      center / 250% 250% no-repeat;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--slow);
  }
  :is(button, a[data-variant]):active::after {
    opacity: 0.16;
    transition: none;
    animation: ripple var(--slow) var(--ease);
  }
  @keyframes ripple {
    from {
      background-size: 0 0;
    }
  }

  :is(button, a, input)[data-variant="tonal"] {
    --bg: var(--secondary-container);
    color: var(--on-secondary-container);
  }
  :is(button, a, input)[data-variant="elevated"] {
    --bg: var(--surface-low);
    color: var(--primary);
    box-shadow: var(--elev-1);
    &:hover {
      box-shadow: var(--elev-2);
    }
  }
  :is(button, a, input)[data-variant="outlined"] {
    --bg: transparent;
    border-color: var(--outline);
    color: var(--primary);
  }
  :is(button, a, input)[data-variant="text"] {
    --bg: transparent;
    padding-inline: 0.75rem;
    color: var(--primary);
  }
  :is(button, a)[data-variant="icon"] {
    --bg: transparent;
    flex: none;
    width: 2.5rem;
    padding: 0;
    color: var(--on-surface-variant);
    font-size: 1.25rem;
  }
  :is(button, a)[data-variant="fab"] {
    --bg: var(--primary-container);
    min-width: 3.5rem;
    min-height: 3.5rem;
    padding: 0 1rem;
    border-radius: 1rem;
    color: var(--on-primary-container);
    box-shadow: var(--elev-3);
    &[aria-label] {
      font-size: 1.5rem;
    }
  }

  :is(button, [type="submit"], [type="reset"], [type="button"]):disabled,
  a[data-variant][aria-disabled="true"] {
    --bg: color-mix(in srgb, var(--on-surface) 12%, transparent);
    border-color: transparent;
    color: color-mix(in srgb, var(--on-surface) 38%, transparent);
    box-shadow: none;
    cursor: not-allowed;
  }
  button:is(
      [data-variant="text"],
      [data-variant="outlined"],
      [data-variant="icon"]
    ):disabled {
    --bg: transparent;
    border-color: color-mix(in srgb, var(--on-surface) 12%, transparent);
  }

  :disabled {
    cursor: not-allowed;
  }

  ::file-selector-button {
    min-height: 2.5rem;
    margin-inline-end: 1rem;
    padding: 0 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--secondary-container);
    color: var(--on-secondary-container);
    font: var(--label);
    cursor: pointer;
  }

  /* A paragraph or footer of buttons is an action row */
  :is(p, footer, form[method="dialog"]):has(
      > :is(button, a[data-variant], [type="submit"])
    ) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }
  :is(article, dialog) footer,
  form[method="dialog"] {
    justify-content: flex-end;
  }

  /* Badges and tooltips */

  [data-badge] {
    display: inline-grid;
    place-content: center;
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.25rem;
    border-radius: 999px;
    background: var(--error);
    color: var(--on-error);
    font: 500 0.6875rem/1 var(--font);
    &:empty {
      min-width: 0.375rem;
      height: 0.375rem;
      padding: 0;
    }
  }

  [data-variant="icon"] > [data-badge] {
    position: absolute;
    top: 0.25rem;
    inset-inline-end: 0.25rem;
  }

  [data-tooltip] {
    position: relative;
    &::before {
      content: attr(data-tooltip);
      position: absolute;
      bottom: calc(100% + 0.25rem);
      left: 50%;
      z-index: 1;
      padding: 0.25rem 0.5rem;
      border-radius: 0.25rem;
      background: var(--inverse-surface);
      color: var(--inverse-on-surface);
      font: 400 0.75rem/1rem var(--font);
      letter-spacing: 0.4px;
      white-space: nowrap;
      pointer-events: none;
      opacity: 0;
      translate: -50% 0.25rem;
      transition:
        opacity var(--fast),
        translate var(--fast) var(--ease);
    }
    &:is(:hover, :focus-visible)::before {
      opacity: 1;
      translate: -50% 0;
      transition-delay: 0.3s;
    }
  }

  /* Cards: an article, or a section nested in a section (to group anything).
     data-variant = filled | outlined */

  :where(article, section section:not([data-layout], [data-variant="tabs"])) {
    display: flex;
    flex-direction: column;
    margin: 0 0 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--surface-low);
    box-shadow: var(--elev-1);
    > img:first-child {
      width: calc(100% + 2rem);
      max-width: none;
      margin: -1rem -1rem 1rem;
      border-radius: var(--radius) var(--radius) 0 0;
      aspect-ratio: 16 / 9;
      object-fit: cover;
    }
    > :is(h2, h3, h4) {
      margin: 0 0 0.5rem;
    }
    > footer {
      margin-top: auto;
      padding-top: 0.5rem;
    }
  }
  :where(article, section section)[data-variant="filled"] {
    background: var(--surface-highest);
    box-shadow: none;
  }
  :where(article, section section)[data-variant="outlined"] {
    border: 1px solid var(--outline-variant);
    background: var(--surface);
    box-shadow: none;
  }

  /* Forms: labels wrap their control; fields use the filled style */

  label {
    display: grid;
    align-content: start;
    gap: 0.25rem;
    margin-bottom: 1rem;
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    &:focus-within {
      color: var(--primary);
    }
    &:has(:user-invalid) {
      color: var(--error);
    }
    small {
      color: var(--on-surface-variant);
    }
    &:has(:user-invalid) small {
      color: var(--error);
    }
    &:has(> textarea) {
      grid-column: 1 / -1;
    }
    &:has(> :disabled) {
      opacity: 0.38;
    }
  }

  label:has(> :is([type="checkbox"], [type="radio"])) {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: fit-content;
    margin-bottom: 0.5rem;
    color: var(--on-surface);
    font-size: 1rem;
    cursor: pointer;
  }

  fieldset {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(14rem, 100%), 1fr));
    column-gap: 1rem;
    padding: 0.5rem 1rem 1rem;
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius);
  }

  legend {
    padding: 0 0.25rem;
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    font-weight: 500;
  }

  :where(
    input:not(
        [type="checkbox"],
        [type="radio"],
        [type="range"],
        [type="color"],
        [type="file"],
        [type="submit"],
        [type="reset"],
        [type="button"],
        [type="image"]
      ),
    select,
    textarea
  ) {
    width: 100%;
    min-height: 3.5rem;
    padding: 0 1rem;
    border: 0;
    border-bottom: 1px solid var(--on-surface-variant);
    border-radius: 0.25rem 0.25rem 0 0;
    background: linear-gradient(var(--accent, var(--primary)) 0 0) bottom /
      var(--line) 2px no-repeat var(--surface-highest);
    color: var(--on-surface);
    font: 1rem/1.5 var(--font);
    transition: --line var(--slow) var(--ease);
    &:focus {
      --line: 100%;
      outline: none;
    }
    &:user-invalid {
      --accent: var(--error);
      --line: 100%;
      border-bottom-color: var(--error);
    }
  }

  textarea {
    min-height: 7rem;
    padding-block: 1rem;
    resize: vertical;
    field-sizing: content;
  }

  select {
    appearance: none;
    padding-inline-end: 2.75rem;
    background:
      conic-gradient(
          from -45deg at 50% 100%,
          var(--on-surface-variant) 90deg,
          #0000 0
        )
        right 1rem center / 0.625rem 0.3125rem no-repeat,
      linear-gradient(var(--accent, var(--primary)) 0 0) bottom / var(--line)
        2px no-repeat var(--surface-highest);
  }

  input[type="search"] {
    border: 0;
    border-radius: 999px;
    padding-inline: 1.5rem;
    background: var(--surface-high);
    &:focus-visible {
      outline: 3px solid var(--primary);
    }
  }

  /* Search hints: a ul straight after a search input, ideally of links. While
     the field has focus the bar grows into a panel listing them. CSS can't see
     what's typed, so they don't filter. The panel sits behind the bar and is
     clipped to the bar's pill while closed, rather than hidden: Chromium won't
     Tab into links that are hidden as the field loses focus. Hovering it keeps
     it open, as Safari doesn't focus a link that is clicked. */

  :has(> [type="search"] + ul) {
    position: relative;
    z-index: 1;
    transition: filter var(--slow) var(--ease);
  }

  :has(
    > [type="search"]:focus + ul,
    > [type="search"] + ul:hover,
    > [type="search"] + ul :focus-visible
  ) {
    filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.3))
      drop-shadow(0 4px 8px rgb(0 0 0 / 0.15));
  }

  [type="search"]:has(+ ul) {
    position: relative;
    z-index: 1;
    &:focus-visible {
      outline: none;
    }
  }

  [type="search"] + ul {
    position: absolute;
    inset: 0 0 auto;
    margin: 0;
    padding: 3.5rem 0 0.5rem;
    list-style: none;
    border-radius: 1.75rem;
    background: linear-gradient(var(--outline-variant) 0 0) 0 3.5rem / 100% 1px
      no-repeat var(--surface-high);
    clip-path: inset(0 0 calc(100% - 3.5rem) round 1.75rem);
    transition: clip-path var(--slow) var(--ease);
    a {
      --bg: transparent;
      display: grid;
      align-content: center;
      align-items: center;
      column-gap: 1rem;
      min-height: 3.5rem;
      padding: 0.5rem 1.5rem;
      color: var(--on-surface);
      text-decoration: none;
      outline-offset: -3px;
      &:has(> img) {
        grid-template-columns: auto 1fr;
      }
    }
    img {
      width: 2.5rem;
      height: 2.5rem;
      border-radius: 0.5rem;
      object-fit: cover;
    }
    a:has(> small) > img {
      grid-row: span 2;
    }
    small {
      color: var(--on-surface-variant);
      font-size: 0.875rem;
    }
  }

  [type="search"]:focus + ul,
  [type="search"] + ul:is(:hover, :has(:focus-visible)) {
    clip-path: inset(0 round 1.75rem);
  }

  ::placeholder {
    color: var(--on-surface-variant);
  }

  input[type="color"] {
    width: 3.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
  }

  /* Range: an M3 slider. The handle paints both track segments as an outset
     border-image, leaving a gap either side of it (1px over M3's, so a segment
     snapped to device pixels can't peek past the end at min or max). The mask
     rounds the track's corners and makes a stacking context, so the handle can
     sit under the track element that draws the stop dot. Firefox can't layer
     them: no dot there. */

  input[type="range"] {
    --active: var(--primary);
    --inactive: var(--secondary-container);
    --handle: 0.25rem;
    --corner: radial-gradient(closest-side, #000 96%, #0000);
    appearance: none;
    width: 100%;
    height: 3.5rem;
    margin: 0;
    padding: 0 0.375rem;
    background: none;
    cursor: pointer;
    mask:
      var(--corner) 0 calc(50% - 0.25rem) / 1rem 1rem no-repeat,
      var(--corner) 0 calc(50% + 0.25rem) / 1rem 1rem no-repeat,
      var(--corner) 100% calc(50% - 0.25rem) / 1rem 1rem no-repeat,
      var(--corner) 100% calc(50% + 0.25rem) / 1rem 1rem no-repeat,
      linear-gradient(#000 0 0) center / calc(100% - 0.625rem) 100% no-repeat,
      linear-gradient(
        #000 calc(50% - 0.75rem - 1px),
        #0000 0 calc(50% - 0.25rem),
        #000 0 calc(50% + 0.25rem),
        #0000 0 calc(50% + 0.75rem + 1px),
        #000 0
      );
    &:active {
      --handle: 0.125rem;
    }
    &:focus-visible {
      --ring: 3px solid var(--primary);
      outline: none;
    }
    &:disabled {
      --active: color-mix(in srgb, var(--on-surface) 38%, transparent);
      --inactive: color-mix(in srgb, var(--on-surface) 12%, transparent);
    }
  }
  input[type="range"]::-webkit-slider-runnable-track {
    height: 2.75rem;
    background: radial-gradient(closest-side, var(--active) 90%, #0000) right /
      0.25rem 0.25rem no-repeat;
  }
  /* One handle rule per engine: a selector list would drop both */
  input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    position: relative;
    z-index: -1;
    width: var(--handle);
    height: 2.75rem;
    border-radius: 1rem;
    outline: var(--ring, none);
    outline-offset: 2px;
    background: var(--active);
    border-image: linear-gradient(90deg, var(--active) 50%, var(--inactive) 0) 0
      1 / calc(50% - 0.75rem) 200vw / 0 calc(200vw + 0.375rem + 1px);
    transition: width var(--fast) var(--ease);
  }
  input[type="range"]::-moz-range-thumb {
    width: var(--handle);
    height: 2.75rem;
    border: 0;
    border-radius: 1rem;
    outline: var(--ring, none);
    outline-offset: 2px;
    background: var(--active);
    border-image: linear-gradient(90deg, var(--active) 50%, var(--inactive) 0) 0
      1 / calc(50% - 0.75rem) 200vw / 0 calc(200vw + 0.375rem + 1px);
    transition: width var(--fast) var(--ease);
  }

  /* Checkbox, radio and switch (checkbox with role="switch"). Zero specificity,
     so chips and segmented buttons can restyle them simply. */

  :where(input:is([type="checkbox"], [type="radio"])) {
    appearance: none;
    flex: none;
    display: inline-grid;
    place-content: center;
    width: 1.125rem;
    height: 1.125rem;
    margin: 0.1875rem;
    border: 2px solid var(--on-surface-variant);
    border-radius: 2px;
    vertical-align: middle;
    cursor: pointer;
    transition:
      background-color var(--fast),
      border-color var(--fast),
      box-shadow var(--fast),
      width var(--fast) var(--ease),
      margin var(--fast) var(--ease);
    &::before {
      content: "";
      width: 0.75rem;
      height: 0.75rem;
      background: var(--on-primary);
      clip-path: var(--check);
      scale: 0;
      transition:
        scale var(--fast) var(--ease),
        translate var(--slow) var(--ease),
        width var(--slow) var(--ease),
        height var(--slow) var(--ease);
    }
    &:hover {
      box-shadow: 0 0 0 0.6875rem var(--hover);
    }
    &:checked {
      border-color: var(--primary);
    }
    &:checked::before {
      scale: 1;
    }
  }

  :where(input[type="checkbox"]):checked {
    background: var(--primary);
  }

  :where(input[type="radio"]) {
    width: 1.25rem;
    height: 1.25rem;
    margin: 0.125rem;
    border-radius: 50%;
    &::before {
      width: 0.625rem;
      height: 0.625rem;
      border-radius: 50%;
      background: var(--primary);
      clip-path: none;
    }
  }

  :where(input:is([role="switch"], [switch])) {
    place-content: center start;
    width: 3.25rem;
    height: 2rem;
    border-color: var(--outline);
    border-radius: 1rem;
    background: var(--surface-highest);
    &::before {
      width: 1rem;
      height: 1rem;
      border-radius: 50%;
      background: var(--outline);
      clip-path: none;
      scale: 1;
      translate: 0.375rem;
    }
    &:hover {
      box-shadow: none;
    }
    &:hover::before {
      box-shadow: 0 0 0 0.5rem var(--hover);
    }
    &:checked::before {
      width: 1.5rem;
      height: 1.5rem;
      background: var(--on-primary);
      translate: 1.375rem;
    }
  }

  /* Chips and segmented buttons: a fieldset of checkboxes or radios.
     A single button or link with data-variant="chip" is an assist chip. */

  :is([data-variant="chips"], [data-variant="segmented"]) {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0;
    border: 0;
    > legend {
      margin-bottom: 0.5rem;
      padding: 0;
    }
  }

  :is([data-variant="chips"], [data-variant="segmented"]) label,
  :is(button, a)[data-variant="chip"] {
    --bg: transparent;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2rem;
    margin: 0;
    padding: 0 1rem;
    border: 1px solid var(--outline);
    border-radius: 0.5rem;
    color: var(--on-surface-variant);
    font: var(--label);
    cursor: pointer;
  }

  :is([data-variant="chips"], [data-variant="segmented"]) {
    label {
      gap: 0;
    }
    label:has(:checked) {
      --bg: var(--secondary-container);
      padding-inline-start: 0.5rem;
      border-color: transparent;
      color: var(--on-secondary-container);
    }
    /* The checkbox becomes the tick, which slides in when selected */
    input {
      width: 0;
      margin: 0;
      border: 0;
      background: none;
      box-shadow: none;
      outline: none;
      &:checked {
        width: 1.125rem;
        margin-inline-end: 0.5rem;
      }
      &::before {
        width: 0.75rem;
        height: 0.75rem;
        border-radius: 0;
        background: currentColor;
        clip-path: var(--check);
      }
    }
  }

  [data-variant="segmented"] {
    flex-wrap: nowrap;
    gap: 0;
    > label {
      min-height: 2.5rem;
      margin-inline-start: -1px;
      border-radius: 0;
      &:first-of-type {
        margin-inline-start: 0;
        border-start-start-radius: 999px;
        border-end-start-radius: 999px;
      }
      &:last-of-type {
        border-start-end-radius: 999px;
        border-end-end-radius: 999px;
      }
      &:has(:checked) {
        border-color: var(--outline);
      }
    }
  }

  /* Radios named color-scheme switch between light and dark; "auto" follows
     the system */
  :root:has(input[name="color-scheme"][value="light"]:checked) {
    color-scheme: light;
  }
  :root:has(input[name="color-scheme"][value="dark"]:checked) {
    color-scheme: dark;
  }

  /* Progress and meter; progress[data-variant="circular"] is a spinner */

  progress,
  meter {
    appearance: none;
    width: 100%;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: var(--secondary-container);
    vertical-align: middle;
  }
  progress {
    height: 0.25rem;
  }
  progress::-webkit-progress-bar {
    background: none;
  }
  progress::-webkit-progress-value {
    border-radius: 999px;
    background: var(--primary);
    transition: inline-size var(--slow) var(--ease);
  }
  progress::-moz-progress-bar {
    border-radius: 999px;
    background: var(--primary);
  }
  progress:indeterminate {
    background: linear-gradient(var(--primary) 0 0) -150% 0 / 40% 100% no-repeat
      var(--secondary-container);
    animation: indeterminate 1.5s var(--ease) infinite;
  }
  progress:indeterminate::-moz-progress-bar {
    background: none;
  }
  @keyframes indeterminate {
    to {
      background-position-x: 250%;
    }
  }

  progress[data-variant="circular"] {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: conic-gradient(var(--primary) 0 70%, #0000 0);
    mask: radial-gradient(
      farthest-side,
      #0000 calc(100% - 4px),
      #000 calc(100% - 4px)
    );
    animation: spin 1s linear infinite;
  }
  @keyframes spin {
    to {
      rotate: 1turn;
    }
  }

  meter {
    height: 0.5rem;
  }
  meter::-webkit-meter-bar {
    height: 100%;
    border: 0;
    border-radius: 999px;
    background: var(--secondary-container);
  }
  meter::-webkit-meter-optimum-value {
    background: var(--primary);
  }
  meter::-webkit-meter-suboptimum-value {
    background: var(--warning);
  }
  meter::-webkit-meter-even-less-good-value {
    background: var(--error);
  }
  meter::-moz-meter-bar {
    background: var(--primary);
  }
  meter:-moz-meter-sub-optimum::-moz-meter-bar {
    background: var(--warning);
  }
  meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {
    background: var(--error);
  }

  /* Navigation: nav ul = row of pill links (side nav, pagination); nav ol = breadcrumbs */

  nav :is(ul, ol) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  nav ul a {
    --bg: transparent;
    display: flex;
    min-width: 2.5rem;
    padding-inline: 1rem;
    color: var(--on-surface-variant);
    &[aria-current] {
      --bg: var(--secondary-container);
      color: var(--on-secondary-container);
    }
  }

  nav ol {
    li + li::before {
      content: "/" / "";
      margin-inline-end: 0.25rem;
      color: var(--outline);
    }
    [aria-current] {
      color: var(--on-surface);
      text-decoration: none;
    }
  }

  /* Expansion panels: details + summary; same name = only one open.
     Content fades and slides; the panel stays visible while it closes, and
     grows and shrinks where auto heights can be interpolated. */

  details {
    border-bottom: 1px solid var(--outline-variant);
    > :not(summary) {
      margin-inline: 1rem;
      opacity: 0;
      translate: 0 -0.5rem;
      transition:
        opacity var(--slow) var(--ease),
        translate var(--slow) var(--ease);
    }
    &[open] > :not(summary) {
      opacity: 1;
      translate: 0;
    }
    &:not(details + details) {
      border-top: 1px solid var(--outline-variant);
    }
    &::details-content {
      transition: content-visibility var(--slow) allow-discrete;
    }
  }

  @supports (interpolate-size: allow-keywords) {
    details::details-content {
      block-size: 0;
      overflow: hidden;
      transition:
        block-size var(--slow) var(--ease),
        content-visibility var(--slow) allow-discrete;
    }
    details[open]::details-content {
      block-size: auto;
    }
  }

  summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3.5rem;
    padding: 0 1rem;
    font-weight: 500;
    list-style: none;
    cursor: pointer;
    &::-webkit-details-marker {
      display: none;
    }
    &::after {
      content: "";
      flex: none;
      width: 0.5rem;
      height: 0.5rem;
      margin-inline-end: 0.25rem;
      border: solid currentColor;
      border-width: 0 2px 2px 0;
      rotate: 45deg;
      transition: rotate var(--slow) var(--ease);
    }
    [open] > &::after {
      rotate: 225deg;
    }
  }

  /* Tabs: exclusive details inside [data-variant="tabs"]; falls back to an accordion */

  @supports selector(::details-content) {
    [data-variant="tabs"] {
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 1rem;
      > details {
        display: contents;
      }
      > details::details-content {
        order: 1;
        flex-basis: 100%;
        transition: none;
      }
      > [open]::details-content {
        padding-top: 1rem;
      }
      summary {
        flex: 1 0 auto;
        justify-content: center;
        min-height: 3rem;
        border-bottom: 1px solid var(--outline-variant);
        color: var(--on-surface-variant);
        font-size: 0.875rem;
        box-shadow: inset 0 0 #0000;
        &::after {
          content: none;
        }
      }
      [open] > summary {
        color: var(--primary);
        box-shadow: inset 0 -3px var(--primary);
        pointer-events: none;
      }
    }
  }

  /* Overlays: popovers (menus, snackbars, the drawer) and dialogs fade in while
     sliding from --from; modal ones dim the page behind them. */

  :is([popover], dialog) {
    --from: 0 -0.5rem;
    border: 0;
    opacity: 0;
    translate: var(--from);
    transition:
      opacity var(--slow) var(--ease),
      translate var(--slow) var(--ease),
      overlay var(--slow) allow-discrete,
      display var(--slow) allow-discrete;
  }

  :is(:popover-open, dialog[open]) {
    opacity: 1;
    translate: 0;
  }

  ::backdrop {
    background: rgb(0 0 0 / 0);
    transition:
      background-color var(--slow),
      overlay var(--slow) allow-discrete,
      display var(--slow) allow-discrete;
  }

  :is(dialog[open], body > nav:popover-open)::backdrop {
    background: rgb(0 0 0 / 0.32);
  }

  @starting-style {
    :is(:popover-open, dialog[open]) {
      opacity: 0;
      translate: var(--from);
    }
    ::backdrop {
      background: rgb(0 0 0 / 0);
    }
    details[open] > :not(summary) {
      opacity: 0;
      translate: 0 -0.5rem;
    }
  }

  [popover]:not(:popover-open) [popovertargetaction="hide"] {
    display: none;
  }

  menu {
    min-width: 7rem;
    max-width: 17.5rem;
    padding: 0.5rem 0;
    list-style: none;
    border-radius: 0.25rem;
    background: var(--surface-mid);
    color: var(--on-surface);
    box-shadow: var(--elev-2);
    :is(a, button) {
      --bg: transparent;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      width: 100%;
      min-height: 3rem;
      padding: 0 0.75rem;
      border-radius: 0;
      color: var(--on-surface);
      font: 400 0.875rem/1.25rem var(--font);
      text-decoration: none;
    }
    hr {
      margin: 0.5rem 0;
    }
  }

  /* FAB menu: a menu popover with data-variant="fab" placed straight after its
     FAB. The actions stack above it, and the FAB becomes a close button. */
  menu[data-variant="fab"] {
    --from: 0 1rem;
    min-width: 0;
    max-width: none;
    padding: 0;
    overflow: visible;
    background: none;
    box-shadow: none;
    li + li {
      margin-top: 0.5rem;
    }
    :is(a, button) {
      --bg: var(--primary-container);
      gap: 0.75rem;
      min-height: 3.5rem;
      padding: 0 1.5rem 0 1.25rem;
      border-radius: 999px;
      color: var(--on-primary-container);
      font: 500 1rem/1.5rem var(--font);
      box-shadow: var(--elev-2);
    }
  }

  /* While its menu is open the FAB shows a ✕ that turns into place. Only the ✕
     rotates: rotating the button would move the menu's anchor in Chromium. */
  :is(button, a)[data-variant="fab"]:has(+ menu[popover])::before {
    content: "✕" / "";
    position: absolute;
    font-size: 1.5rem;
    opacity: 0;
    rotate: -90deg;
    transition:
      opacity var(--slow) var(--ease),
      rotate var(--slow) var(--ease);
  }

  :is(button, a)[data-variant="fab"]:has(+ menu:popover-open) {
    --bg: var(--primary);
    color: var(--on-primary);
    font-size: 0;
    box-shadow: none;
    &[aria-label] {
      border-radius: 50%;
    }
    &::before {
      opacity: 1;
      rotate: 0deg;
    }
  }

  /* A FAB placed directly in body floats in the bottom corner. Snackbars then
     appear above it rather than covering it. */
  body > :is(button, a)[data-variant="fab"] {
    position: fixed;
    inset-block-end: 1.5rem;
    inset-inline-end: 1.5rem;
    z-index: 2;
  }

  body:has(> :is(button, a)[data-variant="fab"]) output[popover] {
    inset-block-end: 6rem;
  }

  @supports (position-area: block-end) {
    menu[popover] {
      inset: auto;
      margin: 0.25rem 0;
      position-area: block-end span-inline-end;
      position-try-fallbacks: flip-block;
    }
    menu[data-variant="fab"] {
      margin: 0.75rem 0;
      position-area: block-start span-inline-end;
      position-try-fallbacks: flip-inline, flip-block;
    }
  }

  output[popover] {
    --from: 0 1rem;
    inset: auto 1rem 1rem;
    max-width: 42rem;
    margin: 0 auto;
    padding: 0.25rem 0.5rem 0.25rem 1rem;
    border-radius: 0.25rem;
    background: var(--inverse-surface);
    color: var(--inverse-on-surface);
    box-shadow: var(--elev-3);
    font-size: 0.875rem;
    button {
      --bg: transparent;
      color: var(--inverse-primary);
    }
    [data-variant="icon"] {
      color: var(--inverse-on-surface);
    }
  }

  output:popover-open {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  /* Dialogs; data-variant="sheet" docks to the bottom */

  dialog {
    max-width: min(35rem, 100vw - 3rem);
    padding: 1.5rem;
    border-radius: 1.75rem;
    background: var(--surface-high);
    color: var(--on-surface-variant);
    box-shadow: var(--elev-3);
    h2 {
      margin-bottom: 1rem;
      color: var(--on-surface);
      font-size: 1.5rem;
    }
    menu {
      max-width: none;
      padding: 0;
      background: none;
      box-shadow: none;
    }
  }

  dialog[data-variant="sheet"] {
    --from: 0 100%;
    width: 100%;
    max-width: 40rem;
    margin: auto auto 0;
    border-radius: 1.75rem 1.75rem 0 0;
    background: var(--surface-low);
    &::before {
      content: "";
      display: block;
      width: 2rem;
      height: 0.25rem;
      margin: -0.5rem auto 1.5rem;
      border-radius: 999px;
      background: var(--outline);
    }
  }

  /* Tables */

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
  }

  caption {
    padding-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 500;
    text-align: start;
  }

  th,
  td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--outline-variant);
    text-align: start;
  }

  th {
    color: var(--on-surface-variant);
    font-weight: 500;
  }

  tbody tr {
    transition: background-color var(--fast);
    &:hover {
      background: var(--hover);
    }
  }

  tfoot :is(th, td) {
    border-bottom: 0;
    color: var(--on-surface);
    font-weight: 500;
  }

  /* Accessibility */

  @media (prefers-reduced-motion: reduce) {
    :root {
      scroll-behavior: auto;
    }
    *,
    ::before,
    ::after,
    ::backdrop {
      animation-duration: 0s !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0s !important;
    }
  }

  @media (forced-colors: active) {
    :root {
      --primary: Highlight;
      --on-primary: HighlightText;
      --outline: CanvasText;
      --on-surface-variant: CanvasText;
      --surface-highest: Canvas;
      --secondary-container: Canvas;
    }
    input:is([type="checkbox"], [type="radio"]),
    progress,
    meter {
      forced-color-adjust: none;
    }
    input[type="range"] {
      --inactive: GrayText;
    }
    article,
    dialog,
    menu,
    [popover],
    [type="search"] + ul {
      border: 1px solid CanvasText;
    }
  }
}
