/* ui-sdk example styles, vercel-labs/ui (Apache-2.0) */
@scope ([data-example]) {
  /* The site sets its own --muted and --accent on every [data-color-scheme] element. */
  :scope,
  [data-color-scheme] {
    --ink: light-dark(#171717, #dedcd7);
    --paper: light-dark(#fff, #141413);
    --surface-1: light-dark(#fff, #1a1a19);
    --surface-2: light-dark(#fff, #212120);
    --surface-3: light-dark(#fff, #282827);
    --line: light-dark(#a2a2a0, #6f6e6b);
    --line-faint: light-dark(#e2e2e0, #3a3937);
    --line-disabled: light-dark(#a8a8a6, #5f5e5b);
    --tint: light-dark(#f4f4f3, #262625);
    --muted: light-dark(#6f6f6c, #9a9893);
    --danger: light-dark(#d60020, #ec7a72);
    --accent: var(--ink);
    --halo: color-mix(in oklab, var(--accent) 22%, transparent);
    --danger-tint: color-mix(in oklab, var(--danger) 9%, var(--surface-2));
    --backdrop: light-dark(rgb(250 250 250 / 0.72), rgb(10 10 10 / 0.72));

    --shadow-drop: 0 2px 3px -1px
      light-dark(color-mix(in oklab, #171717 16%, transparent), #0009);
    --shadow-drop-pressed: 0 1px 1px -1px
      light-dark(color-mix(in oklab, #171717 16%, transparent), #0009);
    --shadow-1:
      0 0 0 1px var(--line),
      0 1px 2px light-dark(color-mix(in oklab, #171717 5%, transparent), #0006);
    --shadow-float:
      0 2px 4px -1px
        light-dark(color-mix(in oklab, #171717 6%, transparent), #0008),
      0 9px 22px -6px
        light-dark(color-mix(in oklab, #171717 16%, transparent), #000c);
    --shadow-2: 0 0 0 1px var(--line), var(--shadow-float);
    --shadow-3:
      0 0 0 1px var(--line),
      0 4px 8px -2px
        light-dark(color-mix(in oklab, #171717 6%, transparent), #0008),
      0 22px 46px -12px
        light-dark(color-mix(in oklab, #171717 26%, transparent), #000e);

    --radius-row: 7px;
    --radius-control: 8px;
    --radius-surface: 10px;
    --radius-popup: 12px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;

    --size-sm: 28px;
    --size: 34px;
    --size-lg: 38px;
    --size-item: 32px;
    --size-icon: 16px;

    --text-xs: 12px;
    --text-sm: 13px;
    --text-md: 14px;
    --text-lg: 16px;
    --mono: var(--font-geist-mono), ui-monospace, "SF Mono", Menlo, monospace;
    --leading: 20px;

    --duration: 0.15s;
  }

  @media (prefers-reduced-motion: reduce) {
    :scope {
      --duration: 0s;
    }
  }
}

@scope ([data-example]) {
  /* ─── Elements ─── */

  :scope {
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-md);
    font-weight: 400;
    line-height: var(--leading);
  }

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

  [data-slot] svg {
    flex-shrink: 0;
    width: var(--size-icon);
    height: var(--size-icon);
  }

  [data-mirror]:is([dir="rtl"], [dir="rtl"] *) {
    scale: -1 1;
  }

  p {
    margin: 0;
  }

  p + p {
    margin-top: var(--space-3);
  }

  a:not([data-slot]) {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--line);
    text-underline-offset: 3px;

    &:hover {
      text-decoration-color: currentColor;
    }
  }

  h3 {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 600;
  }

  button[popover] {
    position: fixed;
    inset: auto var(--space-4) var(--space-4) auto;
    margin: 0;
  }

  fieldset:not([data-slot]) {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  legend:not([data-slot]) {
    margin-bottom: var(--space-2);
    padding: 0;
  }

  legend:not([data-slot]),
  dt,
  th {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 500;
  }

  ul {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-sm);
  }

  li[data-slot="row"] > [data-slot="hint"] {
    margin-inline-start: auto;
  }

  dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-1) var(--space-3);
    margin: 0;
    font-size: var(--text-sm);
  }

  dl > :is(div, [data-slot="row"]) {
    display: contents;
  }

  dd {
    margin: 0;
    overflow-wrap: anywhere;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }

  :is(th, td) {
    height: 40px;
    padding-inline: var(--space-3);
    border-bottom: 1px solid var(--line-faint);
    text-align: start;
  }

  ::placeholder,
  [data-slot="select-value"][data-placeholder] {
    color: var(--muted);
  }

  input[type="range"],
  [data-slot="label"] > input[type="checkbox"] {
    accent-color: var(--ink);
  }

  [data-slot="label"] > input[type="checkbox"] {
    margin: 0;
  }

  input[type="color"] {
    flex: none;
    width: var(--size);
    height: var(--size);
    padding: 3px;
    border: 0;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    cursor: pointer;

    &::-webkit-color-swatch-wrapper {
      padding: 0;
    }

    /* One rule each: a browser drops a whole list holding a pseudo-element it doesn't know. */
    &::-webkit-color-swatch {
      border: 0;
      border-radius: calc(var(--radius-control) - 3px);
    }

    &::-moz-color-swatch {
      border: 0;
      border-radius: calc(var(--radius-control) - 3px);
    }
  }

  svg[data-disabled] {
    color: var(--line-faint);
  }

  /* Two icons in a part: the second shows for the on state. */
  :is(
    [data-slot="checkbox"],
    [data-slot="checkbox-indicator"],
    [data-slot="password-input-toggle"],
    [data-slot="navigation-menu-trigger"],
    li
  ) {
    & > svg + svg {
      display: none;
    }

    &:is(
      [data-checked],
      [data-indeterminate],
      [data-visible],
      [data-met],
      [data-open]
    ) {
      & > svg:has(+ svg) {
        display: none;
      }

      & > svg + svg {
        display: block;
      }
    }
  }

  /* ─── Layout slots ─── */

  /* Every demo sits centered in the preview; its own content stays start-aligned. A demo
     wider than the preview starts at its edge and scrolls, instead of spilling past both. */
  :scope > * {
    align-items: safe center;
  }

  [data-slot="stack"] {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  :is([data-slot="card"], [data-slot="field"], button, label)
    [data-slot="stack"] {
    align-items: flex-start;
    text-align: start;
  }

  [data-slot="stack"]:has(
    > :is([data-slot="stack"], [data-slot="grid"])
      > [data-slot="row"][role="group"],
    > [data-slot="stack"] > [data-slot="grid"] > [data-slot="row"][role="group"]
  ) {
    gap: var(--space-8);
  }

  [data-slot="stack"]:has(
    :is(
      [data-slot="field"],
      [data-slot="field-set"],
      [data-slot="card"],
      [data-variant="card"],
      input:not(
        [type="checkbox"],
        [type="radio"],
        [type="hidden"],
        [type="file"],
        [hidden]
      ),
      textarea,
      select
    )
  ) {
    width: 20rem;
    max-width: 100%;
  }

  /* A demo's own buttons and inputs stay put at the top while the demo below them changes size. */
  :scope:has([data-slot="controls"]) {
    justify-content: flex-start;
  }

  /* The controls sit centered above the demo, on the same axis. */
  [data-slot="stack"]:has(> [data-slot="controls"]) {
    align-items: center;
  }

  [data-slot="controls"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);

    & > input:only-child {
      flex: 1;
    }
  }

  [data-slot="row"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  [data-slot="row"]:has(> [data-slot="stack"]) {
    flex-wrap: nowrap;
    align-items: flex-start;

    & > [data-slot="stack"] {
      flex: 1;
      gap: var(--space-1);
    }

    & > :is([data-slot="checkbox"], [data-slot="radio"]) {
      margin-top: 2px;
    }
  }

  [data-slot="row"][role="radiogroup"] {
    gap: 0;

    & > [data-slot="label"] {
      height: var(--size-sm);
      padding-inline: var(--space-3);
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--ink);
      font-size: var(--text-sm);

      &:first-child {
        border-start-start-radius: var(--radius-control);
        border-end-start-radius: var(--radius-control);
      }

      &:last-child {
        border-start-end-radius: var(--radius-control);
        border-end-end-radius: var(--radius-control);
      }

      & + [data-slot="label"] {
        margin-inline-start: -1px;
      }

      &:hover:not(:has(:checked)) {
        background: var(--tint);
      }

      &:has(:checked) {
        background: var(--ink);
        color: var(--paper);
      }

      &:has(:focus-visible) {
        outline: 3px solid var(--halo);
        outline-offset: 2px;
      }
    }
  }

  [data-slot="grid"] {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  [data-slot="grid"]:has(> [data-slot="row"][role="group"]) {
    grid-template-columns: auto auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);

    & > [data-slot="hint"] {
      text-align: end;
    }
  }

  [data-slot="label"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 500;
  }

  [data-slot="label"]:has(
    > input:not([type="checkbox"], [type="radio"], [type="color"])
  ) {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="label"]:has(> input[type="range"]) {
    display: grid;
    grid-template-columns: 1fr auto;

    & > input {
      grid-column: 1 / -1;
    }
  }

  [data-slot="label"] > select {
    width: auto;
  }

  [data-slot="hint"] {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 400;
  }

  [data-slot="output"] {
    display: block;
    min-height: var(--leading);
    color: var(--muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;

    &:not(:has(*)) {
      white-space: pre-wrap;
    }

    & > span {
      display: block;
    }
  }

  [data-slot="visually-hidden"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  :is([data-slot="card"], [data-slot][data-variant="card"]) {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-3);
    box-sizing: border-box;
    width: 100%;
    padding: var(--space-3);
    border: 0;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    &:is(label, a, button):hover:not(:has([data-checked])) {
      box-shadow: 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:has([data-checked]) {
      background: var(--tint);
      box-shadow: 0 0 0 1px var(--ink);
    }

    & [data-slot="stack"] {
      gap: var(--space-1);
      font-weight: 500;
    }

    & > [data-slot="hint"]:last-child {
      margin-inline-start: auto;
    }
  }

  [data-slot="card"]:has(> [data-slot="initials"]) {
    align-items: center;
    max-width: 24rem;
  }

  [data-slot="scroll"] {
    min-height: 0;
    overflow-y: auto;

    & [data-slot="stack"] {
      align-items: flex-start;
    }
  }

  [data-slot="list"] {
    gap: 0;
    width: 28rem;
    max-width: 100%;
    border-block: 1px solid var(--line-faint);

    & > li {
      padding: var(--space-2) var(--space-3);
    }

    & > li + li {
      border-top: 1px solid var(--line-faint);
    }

    /* A row's action sits at its end, after the item and its details. */
    & > [data-slot="row"] {
      flex-wrap: nowrap;

      & > :last-child:not(:first-child):is(button, [data-slot$="-trigger"]) {
        margin-inline-start: auto;
      }
    }
  }

  [data-slot="log"] {
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    height: 96px;
    margin: 0;
    padding: var(--space-2) 10px;
    overflow-y: auto;
    border-radius: var(--radius-control);
    box-shadow: inset 0 0 0 1px var(--line-faint);
    color: var(--muted);
    font-family: var(--mono);
    font-size: var(--text-xs);
    line-height: var(--leading);
  }

  [data-slot="kbd"] {
    margin-inline-start: auto;
    color: var(--muted);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: 400;
    letter-spacing: 0.04em;
  }

  [data-slot="badge"] {
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
    height: 20px;
    padding-inline: 7px;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-xs);
    font-weight: 500;
  }

  [data-slot="swatch"] {
    display: inline-block;
    flex-shrink: 0;
    width: var(--size-icon);
    height: var(--size-icon);
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ink) 18%, transparent);
  }

  [data-slot="tile"] {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    aspect-ratio: 1;
    border-radius: var(--radius-surface);
    background: var(--tint);
    box-shadow: inset 0 0 0 1px var(--line-faint);
    font-size: 32px;
    font-weight: 500;
    line-height: 1;
  }

  [data-slot="media"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size);
    height: var(--size);
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-xs);
    font-weight: 500;

    &[data-variant="destructive"] {
      background: var(--danger-tint);
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--danger) 40%, transparent);
      color: var(--danger);
    }
  }

  [data-slot="initials"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-xs);
    font-weight: 500;

    [data-open] > & {
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  [data-slot="grip"] {
    display: block;
    flex-shrink: 0;
    width: 40px;
    height: 4px;
    margin-inline: auto;
    border-radius: 999px;
    background: var(--line-faint);
  }

  [data-slot="spinner"] {
    animation: example-spin 800ms linear infinite;
  }

  /* ─── Fields ─── */

  [data-slot="field-label"],
  [data-slot="field-legend"],
  [data-slot="select-label"],
  [data-slot="combobox-label"],
  [data-slot="autocomplete-label"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0;
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: 500;

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  /* Each field is its own selector, not one :is() list, so the browser only
     tries it on matching elements. The list was tried on every element. */
  [data-slot="input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="field-control"]:where(
      :not([type="checkbox"], [type="radio"], [type="range"])
    ):where(
      :not(
        [data-slot="input-group"] *,
        [data-slot="password-input"] *,
        [data-slot="number-input-group"] *,
        [data-slot="combobox-chips"] *
      )
    ),
  [data-slot="textarea"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="combobox-input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="autocomplete-input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="toolbar-input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="color-picker-input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  [data-slot="color-picker-channel-input"]:where(
    :not(
      [data-slot="input-group"] *,
      [data-slot="password-input"] *,
      [data-slot="number-input-group"] *,
      [data-slot="combobox-chips"] *
    )
  ),
  :where(input):not(
      [data-slot],
      [type="checkbox"],
      [type="radio"],
      [type="range"],
      [type="hidden"],
      [type="color"]
    ):where(
      :not(
        [data-slot="input-group"] *,
        [data-slot="password-input"] *,
        [data-slot="number-input-group"] *,
        [data-slot="combobox-chips"] *
      )
    ),
  :where(textarea, select):not([data-slot]):where(
      :not(
        [data-slot="input-group"] *,
        [data-slot="password-input"] *,
        [data-slot="number-input-group"] *,
        [data-slot="combobox-chips"] *
      )
    ),
  :is(
    [data-slot="input-group"],
    [data-slot="password-input"],
    [data-slot="number-input-group"],
    [data-slot="combobox-chips"],
    [data-slot="date-input"],
    [data-slot="time-input"]
  ) {
    box-sizing: border-box;
    width: 20rem;
    min-width: 0;
    max-width: 100%;
    height: var(--size);
    padding-inline: 10px;
    border: 0;
    border-radius: var(--radius-control);
    background-color: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font: inherit;
    font-weight: 400;

    &:hover:not(
        :focus-within,
        :disabled,
        [data-disabled],
        [readonly],
        [data-readonly],
        [data-invalid],
        [aria-invalid="true"]
      ) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:is([readonly], [data-readonly]) {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &:is(:focus-visible, :has(input:focus-visible)) {
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &:is(
      [data-invalid],
      [aria-invalid="true"],
      :has(input[aria-invalid="true"])
    ) {
      box-shadow: inset 0 0 0 1px var(--danger);

      &:is(:focus-visible, :has(input:focus-visible)) {
        outline-color: color-mix(in oklab, var(--danger) 20%, transparent);
      }
    }

    &:is(:disabled, [data-disabled], :has(input:disabled)) {
      background-color: var(--tint);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }
  }

  :is(textarea, [data-slot="textarea"]) {
    display: block;
    height: auto;
    min-height: 80px;
    max-height: 12rem;
    padding-block: var(--space-2);
    resize: vertical;
  }

  select:not([multiple]) {
    padding-inline-end: 34px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f6f6c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-image: light-dark(
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f6f6c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"),
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9893' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    );
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: var(--size-icon);

    &:is([dir="rtl"], [dir="rtl"] *) {
      background-position: left 10px center;
    }
  }

  input[type="file"] {
    padding-inline-start: var(--space-1);

    &::file-selector-button {
      height: 26px;
      margin-inline-end: var(--space-2);
      padding-inline: 10px;
      border: 0;
      border-radius: 5px;
      background: var(--tint);
      color: var(--ink);
      font: inherit;
      font-weight: 500;
    }
  }

  :is(
    [data-slot="input-group"],
    [data-slot="password-input"],
    [data-slot="number-input-group"],
    [data-slot="combobox-chips"]
  ) {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    & input {
      flex: 1;
      min-width: 0;
      height: 100%;
      padding: 0;
      border: 0;
      background: transparent;
      color: var(--ink);
      font: inherit;
      outline: none;

      &::-webkit-search-cancel-button {
        display: none;
      }
    }
  }

  :is(
    [data-slot="input-clear"],
    [data-slot="password-input-toggle"],
    [data-slot="input-group"] > button
  ) {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    width: 24px;
    height: 24px;
    margin-inline-end: -5px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);

    &:hover:not([data-disabled], :disabled) {
      background: var(--tint);
      color: var(--ink);
    }
  }

  :where(div, label):not([data-slot]):has(> svg:first-child + input) {
    position: relative;
    width: 20rem;
    max-width: 100%;

    & > svg {
      position: absolute;
      top: 50%;
      inset-inline-start: 10px;
      color: var(--muted);
      translate: 0 -50%;
      pointer-events: none;
    }

    & > input {
      max-width: none;
      padding-inline-start: 32px;
    }
  }

  /* iOS zooms into a field with text under 16px, so on touch screens every field gets 16px text. */
  @media (pointer: coarse) {
    :is(
      input:not(
        [type="checkbox"],
        [type="radio"],
        [type="range"],
        [type="file"],
        [type="color"],
        [type="hidden"],
        [type="button"],
        [type="submit"],
        [type="reset"]
      ),
      textarea,
      select,
      [contenteditable]:not([contenteditable="false"])
    ) {
      font-size: max(16px, 1em) !important;
    }
  }

  /* ─── Buttons ─── */

  :is(
    [data-slot="button"],
    :where(button):not([data-slot]):where(:not([data-slot="input-group"] > *)),
    [data-slot="menu-trigger"]:where(:not([data-slot="menu-content"] *)),
    [data-slot="popover-trigger"],
    [data-slot="color-picker-eye-dropper"],
    [data-slot="popover-close"]:where(:not(a)),
    [data-slot="select-trigger"],
    [data-slot="select-clear"],
    [data-slot="tooltip-trigger"],
    [data-slot="file-input-trigger"],
    [data-slot="alert-dialog-close"],
    [data-slot="alert-dialog-trigger"],
    [data-slot="dialog-close"],
    [data-slot="dialog-trigger"],
    [data-slot="drawer-close"],
    [data-slot="drawer-trigger"],
    [data-slot="toast-action"],
    [data-slot="toast-close"],
    [data-slot="calendar-next"],
    [data-slot="calendar-previous"],
    [data-slot="carousel-next"],
    [data-slot="carousel-play-toggle"],
    [data-slot="carousel-previous"],
    [data-slot="collapsible-trigger"],
    [data-slot="date-picker-clear"],
    [data-slot="date-picker-preset"],
    [data-slot="date-picker-trigger"],
    [data-slot="pagination-first"],
    [data-slot="pagination-last"],
    [data-slot="pagination-link"],
    [data-slot="pagination-next"],
    [data-slot="pagination-previous"],
    [data-slot="scroll-area-scroll-to-end"],
    [data-slot="toolbar-button"],
    [data-slot="inbox-refresh"],
    [data-slot="pixels-undo"],
    [data-slot="pixels-redo"],
    [data-slot="share-trigger"],
    [data-slot="timer-trigger"],
    [data-slot="timer-done"],
    [data-slot="product-rename"],
    [data-slot="file-list-expand"],
    [data-slot="canvas-action"],
    [data-slot="city-map-arrow"],
    [data-slot="notes-expand"],
    [data-slot="copy"],
    [data-slot="color-reset"],
    [data-slot="image-cropper-rotate"],
    [data-slot="image-cropper-flip"],
    [data-slot="book-bookmark"],
    [data-slot="prices-copyAll"],
    [data-slot="ledger-grid-shortcut"],
    [data-slot="bay-action"],
    [data-slot="tagger-tag"],
    [data-slot="recipe-toggle"],
    [data-slot="cart-trigger"],
    [data-slot="cart-close"],
    [data-slot="invite-trigger"],
    [data-slot="icon-picker-trigger"],
    [data-slot="invite-close"],
    [data-slot="filters-trigger"],
    [data-slot="filters-close"],
    [data-slot="rename-trigger"],
    [data-slot="rename-close"],
    [data-slot="help-trigger"],
    [data-slot="pins-close"],
    [data-slot="callout-target"],
    [data-slot="toasts-add"],
    [data-slot="recipe-action"],
    [data-slot="desktop-action"],
    [data-slot="tag-list-tag"],
    [data-slot="keypad-digit"],
    [data-slot="ring-action"],
    [data-slot="size-picker-item"],
    [data-slot="room-action"],
    [data-slot="thread-action"],
    [data-slot="build-log-jump"],
    [data-slot="mailbox-action"],
    [data-slot="board-reset"],
    [data-slot="map-reset"],
    [data-slot="map-action"],
    [data-slot="contacts-action"],
    [data-slot="notebook-action"],
    [data-slot="notes-undo"],
    [data-slot="notes-redo"],
    [data-slot="notes-fix"],
    [data-slot="notes-clear"],
    [data-slot="notice-close"],
    [data-slot="bold-text-toggle"],
    [data-slot="checkout-next"],
    [data-slot="confirm-button"],
    [data-slot="copy-button"],
    [data-slot="month-next"],
    [data-slot="month-previous"],
    [data-slot="mute-button"],
    [data-slot="save-bar-save"],
    [data-slot="kanban-undo"],
    [data-slot="kanban-redo"],
    [data-slot="rewind-undo"],
    [data-slot="suggestions-accept-all"],
    [data-slot="week-calendar-undo"],
    [data-slot="week-calendar-redo"]
  ) {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    box-sizing: border-box;
    height: var(--size);
    padding-inline: 14px;
    border: 0;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--ink),
      var(--shadow-drop);
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
    cursor: default;
    transition:
      scale 0.1s ease-out,
      box-shadow 0.1s ease-out,
      background-color 0.12s;

    &:is([aria-label], [aria-labelledby]):has(> svg:only-child) {
      width: var(--size);
      padding: 0;
    }

    &[data-size="sm"] {
      height: var(--size-sm);
      padding-inline: 11px;
      border-radius: var(--radius-row);
      font-size: var(--text-sm);

      &:is([aria-label], [aria-labelledby]):has(> svg:only-child) {
        width: var(--size-sm);
      }
    }

    &[data-size="lg"] {
      height: var(--size-lg);
      padding-inline: 18px;

      &:is([aria-label], [aria-labelledby]):has(> svg:only-child) {
        width: var(--size-lg);
      }
    }

    &[data-shape="round"] {
      border-radius: 999px;
    }

    &[data-variant="solid"] {
      background: var(--ink);
      color: var(--paper);
    }

    &[data-variant="secondary"] {
      background: var(--tint);
    }

    &[data-variant="ghost"] {
      background: transparent;
      box-shadow: none;
    }

    &[data-variant="destructive"] {
      color: var(--danger);
    }

    &[data-variant="link"] {
      display: inline;
      height: auto;
      padding: 0;
      background: none;
      box-shadow: none;
      text-decoration: underline;
      text-underline-offset: 3px;
    }

    &:hover:not(
        :disabled,
        [data-disabled],
        [aria-disabled="true"],
        [aria-pressed="true"],
        [data-copied],
        [data-armed]
      ) {
      background: var(--tint);

      &[data-variant="solid"] {
        background: color-mix(in oklab, var(--ink) 86%, var(--paper));
      }

      &[data-variant="secondary"] {
        background: color-mix(in oklab, var(--ink) 7%, var(--tint));
      }

      &[data-variant="destructive"] {
        background: var(--danger-tint);
      }

      &[data-variant="link"] {
        background: none;
      }
    }

    &:active:not(:disabled, [data-disabled], [aria-disabled="true"]) {
      scale: 0.97;

      &:not([data-variant="ghost"], [data-variant="link"]) {
        box-shadow:
          inset 0 0 0 1px var(--ink),
          var(--shadow-drop-pressed);
      }
    }

    &:is([aria-pressed="true"], [data-copied]) {
      background: var(--ink);
      color: var(--paper);
    }

    &:is([aria-pressed="true"], [data-copied], [data-variant="solid"])
      [data-slot="hint"] {
      color: inherit;
      opacity: 0.8;
    }

    &:is(:disabled, [data-disabled], [aria-disabled="true"]) {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);

      &:is([data-variant="ghost"], [data-variant="link"]) {
        background: transparent;
        box-shadow: none;
      }
    }

    &[data-pending] {
      cursor: progress;
    }

    &:not([data-pending]) > [data-slot="spinner"] {
      display: none;
    }
  }

  /* ─── Popups ─── */

  :is(
    [data-slot="menu-content"],
    [data-slot="select-content"],
    [data-slot="combobox-content"],
    [data-slot="autocomplete-content"],
    [data-slot="trigger-menu-content"],
    [data-slot="command"],
    [data-slot="popover-content"],
    [data-slot="hover-card-content"]
  ) {
    box-sizing: border-box;
    min-width: 10rem;
    max-height: var(--available-height);
    overflow-y: auto;
    padding: 5px;
    border: 0;
    border-radius: var(--radius-popup);
    background: var(--surface-2);
    box-shadow:
      inset 0 0 0 1px var(--line),
      var(--shadow-float);
    color: var(--ink);
    font-size: var(--text-md);
    outline: none;
    transform-origin: var(--transform-origin);

    &:has(> [data-slot$="-arrow"]) {
      max-height: none;
      overflow: visible;
    }
  }

  /* The list scrolls, not the popup, so keyboard highlighting keeps the item in view. */
  :is(
    [data-slot="combobox-content"],
    [data-slot="autocomplete-content"],
    [data-slot="trigger-menu-content"]
  ):has(> [data-slot$="-list"]) {
    display: flex;
    flex-direction: column;
    overflow: hidden;

    & > [data-slot$="-list"] {
      flex: 1 1 auto;
      min-height: 0;
      overflow-y: auto;
    }
  }

  :is([data-slot="popover-content"], [data-slot="hover-card-content"]) {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 20rem;
    padding: var(--space-3);
    box-shadow: var(--shadow-2);
  }

  :is(
    [data-slot="popover-arrow"],
    [data-slot="hover-card-arrow"],
    [data-slot="menu-arrow"],
    [data-slot="select-arrow"],
    [data-slot="combobox-arrow"],
    [data-slot="autocomplete-arrow"],
    [data-slot="tooltip-arrow"]
  ) {
    box-sizing: border-box;
    width: 10px;
    height: 10px;
    border: 0 solid var(--line);
    background: var(--surface-2);
    rotate: 45deg;

    &[data-side="bottom"] {
      top: -6px;
      border-top-width: 1px;
      border-left-width: 1px;
    }

    &[data-side="top"] {
      bottom: -6px;
      border-right-width: 1px;
      border-bottom-width: 1px;
    }

    &[data-side="left"] {
      right: -6px;
      border-top-width: 1px;
      border-right-width: 1px;
    }

    &[data-side="right"] {
      left: -6px;
      border-bottom-width: 1px;
      border-left-width: 1px;
    }
  }

  :is(
    [data-slot="alert-dialog-backdrop"],
    [data-slot="dialog-backdrop"],
    [data-slot="drawer-backdrop"]
  ) {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--backdrop);
  }

  /* Popups and backdrops only fade in the animation demos. */
  :scope[data-example$="/animation"]
    :is(
      [data-slot="menu-content"],
      [data-slot="select-content"],
      [data-slot="combobox-content"],
      [data-slot="autocomplete-content"],
      [data-slot="trigger-menu-content"],
      [data-slot="command"],
      [data-slot="popover-content"],
      [data-slot="hover-card-content"],
      [data-slot="alert-dialog-backdrop"],
      [data-slot="dialog-backdrop"],
      [data-slot="drawer-backdrop"]
    ) {
    transition: opacity var(--duration);

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
    }
  }

  :is(
    [data-slot="select-list"],
    [data-slot="combobox-list"],
    [data-slot="autocomplete-list"],
    [data-slot="command-list"],
    [data-slot="trigger-menu-list"]
  ) {
    transition: opacity var(--duration);

    &[aria-busy="true"] {
      opacity: 0.6;
    }
  }

  :is([data-slot="select-group"], [data-slot="listbox-group"]) {
    display: flex;
    flex-direction: column;
  }

  /* ─── Rows ─── */

  :is(
    [data-slot="menu-item"],
    [data-slot="menu-checkbox-item"],
    [data-slot="menu-radio-item"],
    :where([data-slot="menu-content"]) [data-slot="menu-trigger"],
    [data-slot="select-item"],
    [data-slot="select-select-all"],
    [data-slot="combobox-item"],
    [data-slot="combobox-create"],
    [data-slot="combobox-select-all"],
    [data-slot="autocomplete-item"],
    [data-slot="listbox-item"],
    [data-slot="command-item"],
    [data-slot="trigger-menu-item"]
  ) {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-sizing: border-box;
    min-height: var(--size-item);
    padding: 6px 10px;
    border-radius: var(--radius-row);
    font-size: var(--text-md);
    font-weight: 400;
    outline: none;
    cursor: default;
    user-select: none;

    /* An open submenu renders in place after its trigger; the next item keeps its gap. */
    & + &,
    [data-slot="menu-content"] + & {
      margin-top: 1px;
    }

    & svg {
      width: 14px;
      height: 14px;
    }

    & > svg:first-child {
      color: var(--muted);
    }

    &[data-highlighted] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
      color: var(--ink);

      & > svg:first-child {
        color: inherit;
      }

      & :is([data-slot="hint"], [data-slot="badge"]) {
        color: var(--muted);
      }
    }

    /* A disabled item still takes focus, so it keeps a quiet outline but no fill. */
    &[data-disabled] {
      color: var(--line-disabled);

      &[data-highlighted] {
        background: transparent;
        box-shadow: inset 0 0 0 1px var(--line);
        color: var(--line-disabled);
      }
    }

    &[data-destructive] {
      color: var(--danger);

      & > svg:first-child {
        color: inherit;
      }

      &[data-highlighted] {
        background: var(--danger-tint);
        box-shadow: inset 0 0 0 1px var(--danger);
      }
    }

    &[data-pending] {
      cursor: progress;
    }
  }

  :where([data-slot="menu-content"])
    [data-slot="menu-trigger"]
    > svg:last-child {
    margin-inline-start: auto;
    opacity: 0.7;
  }

  :is(
    [data-slot="select-item-indicator"],
    [data-slot="listbox-item-indicator"]
  ) {
    order: 1;
    margin-inline-start: auto;
    padding-inline-start: var(--space-4);

    &:not([data-selected]) {
      visibility: hidden;
    }
  }

  :is(
      [data-slot="select-item-indicator"],
      [data-slot="select-item-icon"],
      [data-slot="listbox-item-indicator"],
      [data-slot="listbox-item-icon"]
    )
    > svg {
    display: block;
  }

  :is(
    [data-slot="menu-group-label"],
    [data-slot="select-group-label"],
    [data-slot="combobox-group-label"],
    [data-slot="autocomplete-group-label"],
    [data-slot="listbox-group-label"],
    [data-slot="command-group-label"],
    [data-slot="trigger-menu-group-label"]
  ) {
    padding: var(--space-2) 10px var(--space-1);
    color: var(--line);
    font-size: 10px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0.2em;
    text-transform: uppercase;
  }

  :is([data-slot="combobox-status"], [data-slot="autocomplete-status"]) {
    padding: 6px 10px;
    color: var(--muted);
    font-size: var(--text-sm);
  }

  :is(
    [data-slot="menu-separator"],
    [data-slot="select-separator"],
    [data-slot="combobox-separator"],
    [data-slot="autocomplete-separator"],
    [data-slot="listbox-separator"],
    [data-slot="command-separator"],
    [data-slot="trigger-menu-separator"]
  ) {
    height: 1px;
    margin: var(--space-1) -4px;
    border: 0;
    background: var(--line-faint);
  }

  :is(
    [data-slot="menu-shortcut"],
    [data-slot="command-shortcut"],
    [data-slot="popover-shortcut"],
    [data-slot="tooltip-shortcut"],
    [data-slot="dialog-shortcut"],
    [data-slot="drawer-shortcut"]
  ) {
    color: var(--line);
    font: inherit;
    font-size: var(--text-xs);
    letter-spacing: 0.04em;
  }

  :is([data-slot="menu-shortcut"], [data-slot="command-shortcut"]) {
    margin-inline-start: auto;
    padding-inline-start: var(--space-4);

    [data-highlighted] > & {
      color: color-mix(in oklab, var(--ink) 60%, var(--surface-2));
    }

    [data-destructive] > & {
      color: color-mix(in oklab, var(--danger) 60%, var(--surface-2));
    }
  }

  :is(
    [data-slot="select-empty"],
    [data-slot="combobox-empty"],
    [data-slot="autocomplete-empty"],
    [data-slot="command-empty"],
    [data-slot="trigger-menu-empty"]
  ) {
    padding: var(--space-3) var(--space-2);
    color: var(--muted);
    font-size: var(--text-sm);
    text-align: center;

    &:empty {
      display: none;
    }
  }
}

/* A drag preview is copied into the body, outside the scope, so the tokens don't reach it. */
[data-drag-preview]:is(
  [data-slot="book-bookmark"],
  [data-slot="kanban-card"],
  [data-slot="outline-item"],
  [data-slot="pages-row"],
  [data-slot="queue-song"],
  [data-slot="sortable-item"],
  [data-slot="tagger-tag"]
) {
  box-shadow:
    0 0 0 1px light-dark(rgb(23 23 23 / 0.12), rgb(222 220 215 / 0.14)),
    0 9px 22px -6px light-dark(rgb(23 23 23 / 0.2), #000c);
  cursor: grabbing;

  &[data-over] {
    background-color: light-dark(#f4f4f3, #262625);
  }

  &[data-drag-count]::after {
    position: absolute;
    top: -8px;
    right: -8px;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    min-width: 20px;
    height: 20px;
    padding-inline: 4px;
    border-radius: 999px;
    background: light-dark(#171717, #dedcd7);
    color: light-dark(#fff, #141413);
    font: 600 11px/1 inherit;
    content: attr(data-drag-count);
  }
}

@keyframes example-spin {
  to {
    rotate: 360deg;
  }
}

@keyframes example-blink {
  50% {
    opacity: 0;
  }
}

@keyframes example-sweep {
  from {
    translate: -100% 0;
  }

  to {
    translate: 250% 0;
  }
}

@keyframes example-progress {
  from {
    scale: 0 1;
  }
}

@scope ([data-example]) {
  [data-slot="accordion"] {
    width: 100%;
    max-width: 28rem;
    margin-inline: auto;
    border-top: 1px solid var(--line-faint);
  }

  /* Opening and closing only grows the demo downward. */
  :scope[data-example^="accordion/"] {
    justify-content: flex-start;
  }

  /* Center the demo's top-level group around an accordion; its text stays start-aligned. */
  :scope > * > :has([data-slot="accordion"]) {
    align-self: center;
    width: 100%;
    max-width: 28rem;
  }

  [data-slot="accordion-item"] {
    border-bottom: 1px solid var(--line-faint);
  }

  [data-slot="accordion-header"] {
    display: flex;
    margin: 0;
    font: inherit;
  }

  [data-slot="accordion-trigger"] {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-2);
    padding: 11px 2px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--ink);
    font: inherit;
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.4;
    text-align: start;
    cursor: default;

    &:focus-visible {
      outline-offset: 0;
    }

    & > svg {
      flex: none;
      order: -1;
      color: color-mix(in oklab, var(--ink) 55%, var(--paper));
      rotate: -90deg;

      &:is([dir="rtl"], [dir="rtl"] *) {
        rotate: 90deg;
      }
    }

    &[data-open] > svg {
      rotate: 0deg;
    }

    & > [data-slot="hint"]:last-child {
      margin-inline-start: auto;
    }

    &:not([data-open]) [data-show="open"],
    &[data-open] [data-show="closed"] {
      display: none;
    }

    &[data-disabled] {
      color: var(--line-disabled);

      & > svg {
        color: var(--line-disabled);
      }
    }
  }

  [data-slot="accordion-panel"] {
    padding-inline: 26px 2px;
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: 400;

    &::after {
      display: block;
      height: 11px;
      content: "";
    }

    & [data-slot="accordion"] {
      max-width: none;
      border-top: 0;
    }

    & [data-slot="accordion-item"]:last-child {
      border-bottom: 0;
    }
  }

  :scope[data-example="accordion/search"] mark {
    border-radius: 3px;
    background: color-mix(in oklab, var(--ink) 14%, var(--surface-1));
    color: inherit;
  }

  /* Only this demo animates; the height transition is what it shows. */
  :scope[data-example="accordion/animation"] {
    & [data-slot="accordion-trigger"] > svg {
      transition: rotate var(--duration);
    }

    & [data-slot="accordion-panel"] {
      box-sizing: border-box;
      height: var(--accordion-panel-height);
      overflow: hidden;
      transition: height calc(var(--duration) * 2) ease-out;

      &:is([data-starting-style], [data-ending-style]) {
        height: 0;
      }
    }
  }
}

@scope ([data-example]) {
  :scope[data-example^="alert-dialog/"] > *,
  :scope[data-example^="alert-dialog/"] > * > [data-slot="stack"] {
    align-items: center;
  }

  [data-slot="alert-dialog-content"] {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    box-sizing: border-box;
    width: min(22rem, calc(100% - 2rem));
    height: fit-content;
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 18px;
    border-radius: var(--radius-popup);
    background: var(--surface-3);
    box-shadow: var(--shadow-3);
    color: var(--ink);
    outline: none;

    &[data-nested-open] {
      translate: 0 -12px;
      scale: 0.97;
    }

    & > [data-slot="stack"] {
      align-items: stretch;
      gap: var(--space-1);
    }

    &
      :has(> [data-slot="alert-dialog-close"]):not(
        [data-slot="alert-dialog-content"]
      ) {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: var(--space-2);
    }

    & [data-slot="hint"][role="alert"] {
      margin: 0;
      color: var(--danger);
    }

    & > [data-slot="grid"] {
      grid-template-columns: 1fr 1fr;
      gap: var(--space-2);
    }

    & [data-slot="alert-dialog-close"][aria-label] {
      position: absolute;
      top: var(--space-3);
      inset-inline-end: var(--space-3);
      width: var(--size-sm);
      height: var(--size-sm);
      padding: 0;
      background: transparent;
      box-shadow: none;
      color: var(--muted);

      &:hover {
        background: var(--tint);
        color: var(--ink);
      }
    }
  }

  [data-slot="alert-dialog-title"] {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 22px;
  }

  [data-slot="alert-dialog-description"] {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-md);
  }

  :scope[data-example="alert-dialog/confirm"]
    :is([data-slot="list"], [data-slot="controls"]) {
    width: 20rem;
  }

  :scope[data-example="alert-dialog/confirm"] [data-slot="list"] {
    & > [data-slot="row"] {
      justify-content: space-between;
      padding-inline-end: var(--space-1);
    }
  }

  /* Only this demo animates; the slide, fade and scale are what it shows. */
  :scope[data-example="alert-dialog/animation"]
    [data-slot="alert-dialog-content"] {
    transition:
      opacity 0.2s,
      translate 0.25s cubic-bezier(0.22, 1, 0.36, 1),
      scale 0.25s cubic-bezier(0.22, 1, 0.36, 1);

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
      translate: 0 16px;
      scale: 0.96;
    }

    &[data-ending-style] {
      transition-duration: 0.15s;
    }
  }
}

@scope ([data-example]) {
  [data-slot="autocomplete-label"] {
    font-weight: 500;

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  [data-slot="autocomplete-input"]::-webkit-search-cancel-button {
    display: none;
  }

  [data-slot="row"]:has(
    > [data-slot="autocomplete-input"],
    > * > [data-slot="autocomplete-input"]
  ) {
    position: relative;
    flex-wrap: nowrap;
    gap: 0;
    width: 20rem;
    max-width: 100%;
    color: var(--muted);

    & > *:has(> [data-slot="autocomplete-input"]) {
      flex: 1;
    }

    & [data-slot="autocomplete-input"] {
      flex: 1;
      max-width: none;
    }

    &:has(
        :is(
          [data-slot="autocomplete-trigger"],
          [data-slot="autocomplete-clear"]
        )
      )
      [data-slot="autocomplete-input"] {
      padding-inline-end: calc(var(--space-2) + 24px);
    }

    &:has([data-slot="autocomplete-trigger"]):has(
        [data-slot="autocomplete-clear"]
      )
      [data-slot="autocomplete-input"] {
      padding-inline-end: calc(var(--space-2) + 48px);
    }

    &
      :is(
        [data-slot="autocomplete-trigger"],
        [data-slot="autocomplete-clear"]
      ) {
      position: absolute;
      inset-block: 0;
      inset-inline-end: 5px;
      margin-block: auto;
    }

    &:has([data-slot="autocomplete-trigger"]) [data-slot="autocomplete-clear"] {
      inset-inline-end: calc(5px + 24px);
    }

    & > svg:first-child {
      position: absolute;
      inset-inline-start: 10px;
      pointer-events: none;
    }

    &:has(> svg:first-child) [data-slot="autocomplete-input"] {
      padding-inline-start: calc(10px + var(--size-icon) + var(--space-2));
    }
  }

  :is([data-slot="autocomplete-trigger"], [data-slot="autocomplete-clear"]) {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: calc(var(--radius-control) - 3px);
    background: transparent;
    color: var(--muted);
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover:not([data-disabled], :disabled) {
      background: var(--tint);
      color: var(--ink);
    }

    &[data-open] {
      color: var(--ink);
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &:is([data-disabled], :disabled) {
      color: var(--line-disabled);
    }
  }

  [data-slot="autocomplete-content"] {
    width: var(--anchor-width);
    max-height: min(18rem, var(--available-height));

    &[data-presentation="sheet"] {
      width: auto;
      height: auto;
      max-height: 85dvh;
      padding: var(--space-2) var(--space-2)
        max(env(safe-area-inset-bottom), var(--space-3));
      scroll-padding-top: 48px;

      & > [data-slot$="-header"] {
        position: sticky;
        top: calc(var(--space-2) * -1);
        z-index: 1;
        padding-block: var(--space-2);
        background: inherit;
      }

      & [data-slot="autocomplete-input"] {
        width: 100%;
        max-width: none;
      }
    }
  }

  [data-slot="autocomplete-item"] {
    &:is(a),
    & > a:not([data-slot]) {
      color: inherit;
      text-decoration: none;
    }

    & > :is([data-slot="hint"], svg):last-child:not(:first-child) {
      margin-inline-start: auto;
    }

    & > svg:last-child:is([dir="rtl"], [dir="rtl"] *) {
      scale: -1 1;
    }

    & > [data-slot="stack"] {
      flex: 1;
      align-items: flex-start;
      gap: 0;
      min-width: 0;
    }
  }

  [data-slot^="autocomplete-"] {
    &:not([data-pending]) > [data-show="pending"],
    &[data-pending] > [data-hide="pending"],
    &:not([data-selected]) > [data-show="selected"],
    &:not([data-disabled]) > [data-show="disabled"],
    &:not([data-highlighted]) > [data-show="highlighted"] {
      display: none;
    }
  }

  [data-slot="autocomplete-item-icon"] {
    display: flex;
    color: var(--muted);

    [data-highlighted] > & {
      color: inherit;
    }
  }

  [data-slot="autocomplete-item-text"] :is(mark, strong) {
    background: none;
    color: inherit;
    font-weight: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }

  [data-slot="autocomplete-status"]:empty {
    padding: 0;
  }

  [data-slot="autocomplete-empty"][data-empty]:empty {
    display: none;
  }

  /* Only this demo animates; the slide and fade are what it shows. */
  :scope[data-example="autocomplete/animation"]
    [data-slot="autocomplete-content"] {
    transition:
      opacity 0.15s,
      translate 0.2s cubic-bezier(0.22, 1, 0.36, 1);

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
      translate: 0 -6px;
    }
  }

  :scope[data-example="autocomplete/positioning"] [data-slot="card"] {
    width: 22rem;
    max-width: 100%;
  }
}

@scope ([data-example]) {
  [data-slot="avatar"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size);
    height: var(--size);
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-1);
    outline: 1px solid var(--line);
    outline-offset: -1px;
    user-select: none;

    &[data-loading-status="loaded"] {
      outline-color: color-mix(in oklab, var(--ink) 12%, transparent);
    }

    &[data-loading-status="error"] {
      background: var(--tint);
    }
  }

  [data-slot="avatar-image"] {
    filter: grayscale(1);
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  [data-slot="avatar-fallback"] {
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 500;
  }
}

@scope ([data-example]) {
  /* Content marked with data-show="pending" or "idle" shows only in that state. */
  [data-slot="button"]:not([data-pending]) [data-show="pending"],
  [data-slot="button"][data-pending] [data-show="idle"] {
    display: none;
  }
}

@scope ([data-example]) {
  /* Months with five or six weeks change the height; top alignment keeps the controls still. */
  :scope[data-example^="calendar/"] {
    justify-content: flex-start;
  }

  [data-slot="calendar"] {
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    width: fit-content;
    max-width: 100%;
    padding: 10px;
    border-radius: var(--radius-popup);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    font-size: var(--text-sm);

    /* The header takes the grid's width rather than widening the calendar for a long heading. */
    & > [data-slot="row"]:first-child:has(> [data-slot="calendar-previous"]) {
      flex-wrap: nowrap;
      justify-content: space-between;
      width: 0;
      min-width: 100%;
      padding-bottom: var(--space-1);
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  :is([data-slot="calendar-previous"], [data-slot="calendar-next"]) {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: var(--radius-row);
    color: var(--muted);

    &:hover:not(:disabled, [data-disabled]) {
      color: var(--ink);
    }

    &:active:not(:disabled, [data-disabled]) {
      scale: none;
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  [data-slot="calendar-heading"] {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 600;
    text-align: center;
    text-wrap: balance;

    &:has(~ [data-slot="select"], ~ * [data-slot="calendar-month-select"]),
    &:has(~ [data-slot="select-trigger"]) {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }

  /* The month and year selects share the header row between Previous and Next. */
  [data-slot="row"]:has(> [data-slot="calendar-month-select"]) {
    flex: 1;
    flex-wrap: nowrap;
    min-width: 0;
  }

  :is([data-slot="calendar-month-select"], [data-slot="calendar-year-select"]) {
    flex: 1;
    min-width: 0;
    width: auto;
    height: var(--size-sm);
  }

  /* Two months side by side, with room between them. */
  [data-slot="row"]:has(
    > [data-slot="calendar-grid"] + [data-slot="calendar-grid"]
  ) {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: var(--space-6);

    /* On a phone the months stack, one above the other. */
    @media (max-width: 40rem) {
      flex-direction: column;
      align-items: center;
      gap: var(--space-4);
    }
  }

  [data-slot="calendar-grid"] {
    width: auto;
    border-collapse: separate;
    border-spacing: 0 2px;

    & :is(th, td) {
      padding: 0;
      border: 0;
    }
  }

  :is([data-slot="calendar-weekday"], [data-slot="calendar-day"]) {
    width: 34px;
    padding: 0;
    border: 0;
    text-align: center;
  }

  [data-slot="calendar-weekday"] {
    height: 28px;
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 400;

    & abbr {
      text-decoration: none;
    }

    & abbr[data-weekend] {
      color: var(--ink);
    }
  }

  [data-slot="calendar-day"] {
    position: relative;
    height: 34px;
    border-radius: var(--radius-row);
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    cursor: default;
    user-select: none;

    &:hover:not(
        [data-outside],
        [data-disabled],
        [data-unavailable],
        [data-selected]
      ) {
      background: var(--tint);
    }

    &[data-today] {
      font-weight: 600;

      &::after {
        position: absolute;
        bottom: 5px;
        left: 50%;
        width: 4px;
        height: 4px;
        margin-left: -2px;
        border-radius: 50%;
        background: currentColor;
        content: "";
      }

      &:has(> [data-slot="stack"])::after {
        display: none;
      }
    }

    &:is([data-outside], [data-disabled]) {
      color: var(--line-disabled);
    }

    &[data-unavailable] {
      color: var(--muted);
      text-decoration: line-through;
    }

    &[data-range-middle] {
      border-radius: 0;
      background: var(--tint);
    }

    &[data-selected]:not(
        [data-range-start],
        [data-range-middle],
        [data-range-end]
      ) {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
      font-weight: 500;
    }

    /* A range reads as one band: tinted between, darker at both ends, rounded on the outside. */
    &:is([data-range-start], [data-range-end]) {
      background: color-mix(in oklab, var(--ink) 14%, var(--surface-1));
      font-weight: 600;
    }

    &[data-range-start]:not([data-range-end]) {
      border-start-end-radius: 0;
      border-end-end-radius: 0;
    }

    &[data-range-end]:not([data-range-start]) {
      border-start-start-radius: 0;
      border-end-start-radius: 0;
    }

    &:focus-visible,
    &[data-selected]:focus-visible {
      outline-offset: -3px;
    }

    & > [data-slot="stack"] {
      align-items: center;
      gap: 0;
      line-height: 1.1;
    }

    & [data-slot="hint"] {
      color: inherit;
      font-size: 10px;
      opacity: 0.7;
    }

    &:is([data-outside], [data-disabled]) [data-slot="hint"] {
      display: none;
    }
  }

  [data-slot="calendar"] [data-slot="select-trigger"] {
    flex: 1;
    width: auto;
    min-width: 0;
  }
}

@scope ([data-example]) {
  [data-slot="carousel"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    width: 24rem;
    max-width: 100%;
    margin-inline: auto;

    & > [data-slot="row"] {
      flex-wrap: nowrap;
      justify-content: center;
    }

    & > [data-slot="controls"] {
      justify-content: center;
      margin-bottom: var(--space-1);
    }
  }

  /* Slides are the same width with or without Previous and Next beside them. */
  [data-slot="carousel"]:not(
    :has(> [data-slot="row"] > [data-slot="carousel-viewport"])
  ) {
    width: calc(24rem - 2 * (var(--size) + var(--space-2)));
  }

  /* Rows under side buttons line up with the slides. */
  [data-slot="carousel"]:has(
      > [data-slot="row"] > [data-slot="carousel-viewport"]
    )
    > [data-slot="row"]:not(:has(> [data-slot="carousel-viewport"])) {
    padding-inline: calc(var(--size) + var(--space-2));
  }

  :scope [data-slot="stack"]:has(> [data-slot="carousel"]) {
    width: calc(24rem - 2 * (var(--size) + var(--space-2)));
    max-width: 100%;
    margin-inline: auto;

    & > [data-slot="carousel"] {
      align-self: stretch;
      width: auto;
      margin-inline: 0;
    }
  }

  :scope
    [data-slot="stack"]:has(
      > [data-slot="carousel"]
        > [data-slot="row"]
        > [data-slot="carousel-viewport"]
    ) {
    width: 24rem;
  }

  [data-slot="carousel-viewport"] {
    border-radius: var(--radius-surface);
    scrollbar-width: none;

    &[data-orientation="vertical"] {
      height: 12rem;

      & [data-slot="carousel-content"] {
        height: 100%;
      }

      & [data-slot="carousel-item"] {
        flex-basis: calc((100% - var(--space-4)) / 2);
      }

      & [data-slot="tile"] {
        height: 100%;
        aspect-ratio: auto;
      }
    }
  }

  [data-slot="carousel-content"] {
    display: flex;
    gap: var(--space-4);

    &[data-orientation="vertical"] {
      flex-direction: column;
    }

    &:has(> [data-slot="carousel-item"] > button) {
      gap: var(--space-2);
    }
  }

  [data-slot="carousel-item"] {
    flex: 0 0 100%;
    min-width: 0;

    &:not([data-in-view]) {
      opacity: 0.4;
    }

    &:has(> button) {
      flex-basis: calc((100% - 3 * var(--space-2)) / 4);
      padding-block: 4px;
    }

    & > button {
      width: 100%;
      height: 3rem;
      padding: 0;
      font-size: var(--text-xs);
      font-variant-numeric: tabular-nums;

      &[aria-pressed="true"] {
        background: var(--ink);
        color: var(--paper);
      }
    }
  }

  [data-slot="carousel-play-toggle"] {
    &[data-playing] > [data-show="stopped"],
    &:not([data-playing]) > [data-show="playing"] {
      display: none;
    }
  }

  [data-slot="carousel-indicator-group"] {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
  }

  [data-slot="carousel-indicator"] {
    flex-shrink: 0;
    box-sizing: border-box;
    width: 8px;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    cursor: default;

    &:hover:not([data-selected]) {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-selected] {
      width: 20px;
      background: var(--ink);
      box-shadow: none;
    }
  }

  [data-slot="bar"] {
    flex: 1;
    height: 4px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line-faint);

    & > * {
      height: 100%;
      background: var(--ink);
      transform-origin: left;
      scale: var(--carousel-progress) 1;

      &:is([dir="rtl"], [dir="rtl"] *) {
        transform-origin: right;
      }
    }
  }

  /* Previous and Next sit on either side of the slides. */
  [data-slot="carousel"] > [data-slot="row"] > [data-slot="carousel-viewport"] {
    flex: 1;
    min-width: 0;
  }

  /* Pages: three slides to a page, with the content's gaps taken out of each basis. */
  :scope[data-example="carousel/pages"] [data-slot="carousel"] {
    width: 32rem;
  }

  :scope[data-example="carousel/pages"] [data-slot="carousel-item"] {
    flex-basis: calc((100% - 2 * var(--space-4)) / 3);
  }

  /* Align: slides narrower than the viewport, so start, center and end look different. */
  :scope[data-example="carousel/align"] [data-slot="carousel-item"] {
    flex-basis: 70%;
  }
}

@scope ([data-example]) {
  [data-slot="checkbox"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);
    cursor: default;

    &:hover:not(
        [data-disabled],
        [data-readonly],
        [data-checked],
        [data-indeterminate]
      ) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:is([data-checked], [data-indeterminate]) {
      background: var(--ink);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &:is([data-invalid], [aria-invalid="true"]) {
      box-shadow: inset 0 0 0 1px var(--danger);
    }

    &[data-readonly]:not([data-checked], [data-indeterminate]) {
      background: var(--tint);
    }

    &[data-readonly]:is([data-checked], [data-indeterminate]) {
      background: var(--muted);
      box-shadow: inset 0 0 0 1px var(--muted);
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &[data-disabled]:is([data-checked], [data-indeterminate]) {
      background: var(--line-disabled);
      box-shadow: inset 0 0 0 1px var(--line-disabled);
    }

    & svg {
      width: 12px;
      height: 12px;
      stroke-width: 2.5;
    }
  }

  [data-slot="checkbox-indicator"] {
    display: grid;
    place-items: center;

    &[data-unchecked] > svg {
      visibility: hidden;
    }
  }

  :scope[data-example="checkbox/indicator"] [data-slot="checkbox-indicator"] {
    transition:
      opacity 0.15s,
      scale 0.15s;

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
      scale: 0.5;
    }
  }

  /* A checkbox with its own content is a choice card. */
  [data-slot="checkbox"]:not(:empty, :has(> [data-slot="checkbox-indicator"])) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    width: auto;
    min-width: var(--size);
    height: auto;
    min-height: var(--size);
    padding: 10px 14px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font: inherit;
    text-align: start;

    &:hover:not([data-disabled], [data-checked]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &[data-checked] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-disabled] {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    & svg {
      width: var(--size-icon);
      height: var(--size-icon);
      stroke-width: 2;
    }

    & > [data-slot="stack"] {
      flex: 1;
      gap: 0;
      font-weight: 500;
    }

    & > svg:last-child:not(:first-child) {
      margin-inline-start: auto;
    }
  }

  [data-slot="checkbox-group"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);

    &[data-disabled] [data-slot="label"] {
      color: var(--line-disabled);
    }

    & > [data-slot="stack"] {
      gap: var(--space-2);
      padding-inline-start: var(--space-6);
    }
  }

  [data-slot="label"]:has(> [data-slot="checkbox"][data-disabled]) {
    color: var(--line-disabled);
  }

  :is(th, td) > [data-slot="checkbox"] {
    vertical-align: middle;
  }
}

@scope ([data-example]) {
  [data-slot="collapsible"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 20rem;
    max-width: 100%;

    & > h3 {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: var(--space-1);
      margin: 0;
      font: inherit;
    }

    &:not([data-open]) [data-show="open"],
    &[data-open] [data-show="closed"] {
      display: none;
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    li > & {
      gap: 0;
    }
  }

  [data-slot="collapsible-trigger"] {
    align-self: flex-start;

    &[data-open] > svg:last-child {
      rotate: 180deg;
    }

    &:is([dir="rtl"], [dir="rtl"] *) > svg:first-child:not(:last-child) {
      scale: -1 1;
    }

    &[data-open] > svg:first-child:not(:last-child) {
      rotate: 90deg;
    }

    &[data-open]:is([dir="rtl"], [dir="rtl"] *)
      > svg:first-child:not(:last-child) {
      rotate: -90deg;
    }

    &[data-variant="ghost"] {
      align-self: stretch;
      justify-content: flex-start;
      height: var(--size-sm);
      padding-inline: var(--space-1);
      border-radius: var(--radius-row);
      font-weight: 400;

      & > svg {
        color: var(--muted);
      }
    }
  }

  [data-slot="collapsible-panel"] {
    font-size: var(--text-sm);
  }

  /* Pinned to the top, so opening only grows the demo downward. */
  :scope:has([data-slot="collapsible"]) {
    justify-content: flex-start;
  }

  /* A card whose header is the trigger. */
  [data-slot="collapsible"][data-variant="card"] {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 22rem;
    padding: 0;

    & > h3 {
      display: block;
    }

    & [data-slot="collapsible-trigger"] {
      align-self: stretch;
      justify-content: space-between;
      width: 100%;
      height: auto;
      padding: var(--space-3);
      border-radius: var(--radius-surface);
      background: transparent;
      box-shadow: none;
      font-weight: 400;
      text-align: start;

      &:hover {
        background: var(--tint);
      }

      &:active {
        scale: none;
        box-shadow: none;
      }

      &[data-open] {
        border-end-start-radius: 0;
        border-end-end-radius: 0;
      }

      & > [data-slot="stack"] {
        gap: 0;

        & > :first-child {
          font-weight: 500;
        }
      }

      & > svg {
        color: var(--muted);
      }
    }

    & [data-slot="collapsible-panel"] {
      margin: 0;
      padding: 0;
      border-top: 1px solid var(--line-faint);
      list-style: none;

      &[hidden] {
        border-top: 0;
      }

      & > :not([data-slot="row"]) {
        margin: 0;
        padding: var(--space-3);
      }

      & > [data-slot="field"] {
        box-sizing: border-box;
        width: 100%;

        & > textarea {
          width: 100%;
        }
      }

      & > [data-slot="stack"] {
        align-items: flex-start;
        gap: var(--space-3);

        & > ul {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: var(--space-2) var(--space-6);
          margin: 0;
          padding: 0;
          list-style: none;
          font-family: var(--mono);
          font-size: var(--text-sm);
        }
      }

      & > ul:not([data-slot]) {
        padding-inline-start: calc(var(--space-3) + 1.25em);
        list-style: disc;
      }

      & > [data-slot="row"] {
        justify-content: space-between;
        padding: var(--space-2) var(--space-3);
        font-variant-numeric: tabular-nums;
      }

      & > [data-slot="row"] + [data-slot="row"] {
        border-top: 1px solid var(--line-faint);
      }
    }
  }

  ul:has([data-slot="collapsible"]) {
    margin: 0;
    padding: 0;
    list-style: none;

    & ul {
      margin: 0;
      margin-inline-start: 14px;
      padding: 0;
      padding-inline-start: 6px;
      border-inline-start: 1px solid var(--line-faint);
      list-style: none;
    }

    & li > [data-slot="row"] {
      min-height: var(--size-sm);
      padding-inline-start: calc(
        var(--space-1) + var(--size-icon) + var(--space-2)
      );
    }
  }

  /* Only this demo animates; the height transition is what it shows. */
  :scope[data-example="collapsible/animation"] {
    & [data-slot="collapsible-trigger"] > svg {
      transition: rotate var(--duration);
    }

    & [data-slot="collapsible-panel"] {
      height: var(--collapsible-panel-height);
      overflow: hidden;
      transition: height calc(var(--duration) * 2) ease-out;

      &:is([data-starting-style], [data-ending-style]) {
        height: 0;
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="color-picker"] {
    --checker: repeating-conic-gradient(
        var(--line-faint) 0 25%,
        var(--surface-1) 0 50%
      )
      0 0 / 8px 8px;

    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 16rem;
    max-width: 100%;

    & > [data-slot="row"] {
      flex-wrap: nowrap;
      gap: var(--space-2);
    }
  }

  [data-slot="color-picker-sliders"] {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
  }

  [data-slot="color-picker"] > [data-slot="row"] > select {
    flex: none;
    width: auto;
  }

  [data-slot="color-picker-area"] {
    height: 10rem;
    border-radius: var(--radius-control);
    background: var(--color-area-background, var(--checker));
    box-shadow: inset 0 0 0 1px var(--line-faint);
    cursor: crosshair;

    &:is([data-disabled], [data-readonly]) {
      cursor: default;
    }

    &[data-disabled] {
      opacity: 0.5;
    }
  }

  [data-slot="color-picker-area-canvas"] {
    border-radius: inherit;
  }

  [data-slot="color-picker-slider"] {
    height: 12px;
    border-radius: 999px;
    background: var(--color-slider-background);
    box-shadow: inset 0 0 0 1px var(--line-faint);

    &[data-channel="alpha"] {
      background: var(--color-slider-background), var(--checker);
    }

    &[data-disabled] {
      opacity: 0.5;
    }

    [data-slot="row"] > & {
      flex: 1;
    }
  }

  :is(
    [data-slot="color-picker-area-thumb"],
    [data-slot="color-picker-slider-thumb"]
  ) {
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--color-picker-color);
    box-shadow:
      0 0 0 1px rgb(0 0 0 / 0.3),
      var(--shadow-drop);
    translate: -50% -50%;

    &:is([dir="rtl"], [dir="rtl"] *) {
      translate: 50% -50%;
    }

    &:focus-visible {
      outline: 3px solid var(--halo);
      outline-offset: 2px;
    }

    &[data-out-of-gamut] {
      border-style: dashed;
    }
  }

  [data-slot="color-picker-slider-thumb"] {
    top: 50%;
    translate: calc(var(--color-slider-thumb-position) * -1) -50%;

    &:is([dir="rtl"], [dir="rtl"] *) {
      translate: var(--color-slider-thumb-position) -50%;
    }
  }

  :is(
    [data-slot="color-picker-swatch"],
    [data-slot="color-picker-swatch-item"]
  ) {
    flex: none;
    box-sizing: border-box;
    width: var(--size);
    height: var(--size);
    padding: 0;
    border: 0;
    border-radius: var(--radius-control);
    background:
      linear-gradient(var(--color-picker-color), var(--color-picker-color)),
      var(--checker);
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.1);
  }

  [data-slot="color-picker-swatches"] {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: var(--space-2);
  }

  [data-slot="color-picker-swatch-item"] {
    width: auto;
    height: auto;
    aspect-ratio: 1;

    &[data-selected] {
      box-shadow:
        inset 0 0 0 1px rgb(0 0 0 / 0.1),
        0 0 0 2px var(--surface-1),
        0 0 0 3.5px var(--ink);
    }

    &:focus-visible {
      outline: 3px solid var(--halo);
      outline-offset: 2px;
    }
  }

  [data-slot="color-picker-input"] {
    width: 100%;
    font-family: var(--mono);
  }

  [data-slot="color-picker-channel-input"] {
    padding-inline: var(--space-2);
    font-variant-numeric: tabular-nums;
  }

  [data-slot="row"]
    :is(
      [data-slot="color-picker-input"],
      [data-slot="color-picker-channel-input"]
    ) {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  [data-slot="color-picker"]:has(> [data-slot="popover-trigger"]) {
    width: auto;
  }

  [data-slot="popover-trigger"]:has(> [data-slot="color-picker-swatch"]) {
    width: var(--size-lg);
    padding: 4px;

    & > [data-slot="color-picker-swatch"] {
      width: 100%;
      height: 100%;
      border-radius: calc(var(--radius-control) - 2px);
    }
  }

  [data-slot="popover-content"]:has([data-slot="color-picker-area"]) {
    width: 16rem;
  }
}

@scope ([data-example]) {
  [data-slot="combobox-label"] {
    font-weight: 500;

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  [data-slot="combobox-input"]::-webkit-search-cancel-button {
    display: none;
  }

  [data-slot="combobox-chips"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    height: auto;
    min-height: var(--size);
    padding: 4px 5px;

    & [data-slot="combobox-input"] {
      flex: 1;
      width: auto;
      min-width: 4rem;
      max-width: none;
      height: 24px;
      padding-inline: var(--space-1);
      border-radius: 0;
      background: transparent;
      box-shadow: none;
      outline: none;
    }
  }

  [data-slot="row"]:has(
    > :is([data-slot="combobox-input"], [data-slot="combobox-chips"]),
    > * > [data-slot="combobox-input"]
  ) {
    position: relative;
    flex-wrap: nowrap;
    gap: 0;
    width: 20rem;
    max-width: 100%;
    color: var(--muted);

    & > *:has(> [data-slot="combobox-input"]) {
      flex: 1;
    }

    & :is([data-slot="combobox-input"], [data-slot="combobox-chips"]) {
      flex: 1;
      max-width: none;
    }

    &:has(:is([data-slot="combobox-trigger"], [data-slot="combobox-clear"]))
      :is([data-slot="combobox-input"], [data-slot="combobox-chips"]) {
      padding-inline-end: calc(var(--space-2) + 24px);
    }

    &:has([data-slot="combobox-trigger"]):has([data-slot="combobox-clear"])
      [data-slot="combobox-input"] {
      padding-inline-end: calc(var(--space-2) + 48px);
    }

    & :is([data-slot="combobox-trigger"], [data-slot="combobox-clear"]) {
      position: absolute;
      inset-block: 0;
      inset-inline-end: 5px;
      margin-block: auto;
    }

    &:has([data-slot="combobox-trigger"]) [data-slot="combobox-clear"] {
      inset-inline-end: calc(5px + 24px);
    }

    & > :is(svg, [data-slot="combobox-value-icon"]):first-child {
      position: absolute;
      inset-inline-start: 10px;
      display: flex;
      pointer-events: none;
    }

    &:has(> :is(svg, [data-slot="combobox-value-icon"]:not(:empty)):first-child)
      [data-slot="combobox-input"] {
      padding-inline-start: calc(10px + var(--size-icon) + var(--space-2));
    }
  }

  /* On its own the trigger reads like a select trigger. */
  [data-slot="combobox-trigger"] {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    box-sizing: border-box;
    min-width: 12rem;
    height: var(--size);
    padding-inline: 10px 8px;
    border: 0;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--ink),
      var(--shadow-drop);
    color: var(--ink);
    font: inherit;
    text-align: start;
    user-select: none;
    cursor: default;

    &:hover:not([data-disabled], :disabled) {
      background: var(--tint);
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &:is([data-disabled], :disabled) {
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    & > svg:last-child {
      color: var(--muted);
    }
  }

  [data-slot="combobox-clear"],
  [data-slot="row"] [data-slot="combobox-trigger"] {
    display: inline-grid;
    place-items: center;
    width: 24px;
    min-width: 0;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: calc(var(--radius-control) - 3px);
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover:not([data-disabled], :disabled) {
      background: var(--tint);
      color: var(--ink);
    }

    &[data-open] {
      color: var(--ink);
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &:is([data-disabled], :disabled) {
      color: var(--line-disabled);
    }

    & > svg:last-child {
      color: inherit;
    }
  }

  [data-slot="combobox-chip"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    box-sizing: border-box;
    height: 24px;
    padding-inline: 8px 4px;
    border-radius: calc(var(--radius-control) - 2px);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-xs);
    white-space: nowrap;
    outline: none;

    &:focus-visible {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-disabled] {
      padding-inline-end: 8px;
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }
  }

  [data-slot="combobox-chip-remove"] {
    display: inline-grid;
    place-items: center;
    width: var(--size-icon);
    height: var(--size-icon);
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
      color: var(--ink);
    }

    &:disabled {
      display: none;
    }

    & svg {
      width: 12px;
      height: 12px;
    }
  }

  [data-slot="combobox-chips-overflow"] {
    padding-inline: var(--space-1);
    color: var(--muted);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  [data-slot="combobox-content"] {
    width: var(--anchor-width);
    max-height: min(18rem, var(--available-height));

    &[data-presentation="sheet"] {
      width: auto;
      height: auto;
      max-height: 85dvh;
      padding: var(--space-2) var(--space-2)
        max(env(safe-area-inset-bottom), var(--space-3));
      scroll-padding-top: 48px;

      & > [data-slot$="-header"] {
        position: sticky;
        top: calc(var(--space-2) * -1);
        z-index: 1;
        padding-block: var(--space-2);
        background: inherit;
      }

      & [data-slot="combobox-input"] {
        width: 100%;
        max-width: none;
      }
    }

    & > [data-slot="row"]:has([data-slot="combobox-input"]) {
      margin-bottom: var(--space-1);
    }
  }

  [data-slot="combobox-content"] > div:not([data-slot]) {
    max-height: min(18rem, calc(var(--available-height) - var(--space-2)));
    overflow-y: auto;
    overscroll-behavior: contain;

    & [data-slot="combobox-list"] {
      position: relative;
    }

    & [data-slot="combobox-item"] {
      position: absolute;
      inset-inline: 0;
      box-sizing: border-box;
    }
  }

  /* A leading box marks items in multi-select lists. */
  :is([data-slot="combobox-item"], [data-slot="combobox-select-all"])
    > span:not([data-slot]):first-child:is(
      :empty,
      :has(> :is(svg, [data-slot="combobox-item-indicator"]))
    ) {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);

    & svg {
      width: 10px;
      height: 10px;
      stroke-width: 3;
    }

    :is([data-selected], [data-checked], [data-indeterminate]) > & {
      background: var(--ink);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    [data-highlighted]:is([data-selected], [data-checked], [data-indeterminate])
      > & {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    & [data-slot="combobox-item-indicator"] {
      margin: 0;
    }
  }

  [data-slot="combobox-select-all"] > span:not([data-slot]):first-child > svg {
    display: none;

    [data-checked] > span > &:first-child,
    [data-indeterminate] > span > &:last-child {
      display: block;
    }
  }

  :is([data-slot="combobox-item"], [data-slot="combobox-create"]) {
    &:is(a),
    & > a:not([data-slot]) {
      color: inherit;
      text-decoration: none;
    }

    & > [data-slot="combobox-item-indicator"],
    & > :is([data-slot="hint"], svg):last-child:not(:first-child) {
      margin-inline-start: auto;
    }

    & > [data-slot="stack"] {
      flex: 1;
      align-items: flex-start;
      gap: 0;
      min-width: 0;
    }

    & > [data-slot="badge"] {
      justify-content: center;
      box-sizing: border-box;
      min-width: 18px;
    }

    &[data-selected] > [data-slot="badge"] {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    & [data-slot="hint"][data-error] {
      color: var(--danger);
    }
  }

  :is([data-slot="combobox"], [data-slot^="combobox-"]) {
    &:not([data-pending]) > [data-show="pending"],
    &[data-pending] > [data-hide="pending"],
    &:not([data-checked]) > [data-show="checked"],
    &[data-checked] > [data-hide="checked"],
    &:not([data-selected]) > [data-show="selected"],
    &:not([data-disabled]) > [data-show="disabled"],
    &:not([data-highlighted]) > [data-show="highlighted"] {
      display: none;
    }
  }

  :is(
    [data-slot="combobox-item-indicator"],
    [data-slot="combobox-item-icon"],
    [data-slot="combobox-value-icon"]
  ) {
    display: flex;

    & svg {
      display: block;
    }
  }

  [data-slot="combobox-item-indicator"] {
    & > svg {
      width: 14px;
      height: 14px;
    }

    &:not([data-selected]) {
      opacity: 0;
    }
  }

  [data-slot="combobox-item-icon"] {
    color: var(--muted);

    [data-highlighted] > & {
      color: inherit;
    }
  }

  [data-slot="combobox-item-text"] {
    & mark {
      background: none;
      color: var(--ink);
      font-weight: 600;
    }

    &[data-matched] {
      color: var(--muted);
    }

    [data-highlighted] > & {
      color: inherit;

      & mark {
        color: inherit;
      }
    }
  }

  [data-slot="combobox-status"]:empty {
    padding: 0;
  }

  :scope[data-example="combobox/animation"] {
    & [data-slot="combobox-item-indicator"] {
      transition: opacity var(--duration);

      &:is([data-starting-style], [data-ending-style]) {
        opacity: 0;
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="command"] {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 24rem;
    max-width: 100%;
    max-height: 20rem;
    overflow: hidden;
    border-radius: var(--radius-popup);
    background: var(--surface-3);
    box-shadow: var(--shadow-3);
    color: var(--ink);

    &:has([data-slot="command-input"]:focus-visible) {
      outline: 3px solid var(--halo);
      outline-offset: 2px;
    }
  }

  [data-slot="stack"]:has(> [data-slot="command"] [data-slot="command-input"]) {
    max-width: 24rem;
  }

  [data-slot="command-input"] {
    box-sizing: border-box;
    flex-shrink: 0;
    width: 100%;
    min-width: 0;
    height: 42px;
    margin: 0;
    padding: 0 var(--space-3);
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: inset 0 -1px 0 var(--line-faint);
    color: inherit;
    font: inherit;
    outline: none;

    &::placeholder {
      color: var(--muted);
    }
  }

  [data-slot="command"] > [data-slot="row"] {
    flex-shrink: 0;
    flex-wrap: nowrap;
    padding-inline: var(--space-3);

    &:has([data-slot="command-input"]) {
      box-shadow: inset 0 -1px 0 var(--line-faint);
      color: var(--muted);

      & [data-slot="command-input"] {
        padding: 0;
        box-shadow: none;
        color: var(--ink);
      }
    }

    &:not(:has([data-slot="command-input"])) {
      gap: var(--space-1);
      padding-block-start: var(--space-2);

      &:not(:has(*)) {
        display: none;
      }
    }
  }

  [data-slot="command-status"] {
    flex-shrink: 0;
    padding: 6px var(--space-3);
    box-shadow: inset 0 -1px 0 var(--line-faint);
    color: var(--muted);
    font-size: var(--text-xs);
  }

  [data-slot="command-empty"] {
    flex-shrink: 0;
  }

  [data-slot="command-list"] {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    padding: 5px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 5px;
    outline: none;

    &:not(:has([data-slot="command-item"])) {
      display: none;
    }

    &[data-has-icons] [data-slot="command-item"]:not([data-has-icon]) {
      padding-inline-start: calc(10px + var(--space-4) + 14px);
    }
  }

  [data-slot="command"] > :has(> [data-slot="command-list"]) {
    position: relative;
    flex: none;
    height: 16rem;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  [data-slot="command-item"] {
    color: inherit;
    text-decoration: none;

    &[aria-posinset] {
      position: absolute;
      inset-inline: 5px;
      height: 32px;
    }

    & > svg,
    & > [data-slot="hint"] {
      margin-inline-start: auto;
    }

    & > svg {
      width: 14px;
      height: 14px;
    }

    &:not([data-pending]) > [data-slot="spinner"],
    &:is(a):not([data-highlighted]) > svg {
      display: none;
    }

    & > strong {
      font-weight: 500;
    }
  }

  [data-slot="command-item-icon"] {
    display: flex;
    margin-inline-start: 0;
    color: var(--muted);

    :is([data-highlighted], [data-disabled]) > & {
      color: inherit;
    }

    & svg {
      width: 14px;
      height: 14px;
    }
  }

  [data-slot="command-item-text"] mark {
    background: none;
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }

  [data-slot="command-item"]:not([data-highlighted])
    [data-slot="command-item-text"][data-matched] {
    color: var(--muted);

    & mark {
      color: var(--ink);
    }
  }

  [data-slot="dialog-content"]:has(> [data-slot="command"]) {
    inset: min(6rem, 10dvh) 0 auto;
    width: min(28rem, 100% - 2rem);
    max-height: 80dvh;
    margin: 0 auto;
    padding: 0;
    overflow: hidden;

    & > [data-slot="dialog-title"] {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    & > [data-slot="command"] {
      width: auto;
      max-width: none;
      border-radius: 0;
      background: none;
      box-shadow: none;
    }
  }
}

@scope ([data-example]) {
  :is([data-slot="date-input"], [data-slot="time-input"]) {
    display: inline-flex;
    align-items: center;
    width: auto;
    padding-inline: 8px;
    font-variant-numeric: tabular-nums;
  }

  /* A field around a date or time takes the input's width, so its description wraps under it. */
  [data-slot="field"]:has(
    > :is([data-slot="date-input"], [data-slot="time-input"])
  ) {
    width: max-content;
    max-width: 20rem;

    & > [data-slot="field-description"] {
      contain: inline-size;
    }
  }

  /* Stacks of date and time fields shrink to their fields, so they stay centered. */
  :scope[data-example^="date-input/"] [data-slot="stack"] {
    width: auto;
  }

  :is([data-slot="date-input-segment"], [data-slot="time-input-segment"]) {
    &[data-type="literal"] {
      padding-inline: 1px;
      color: var(--muted);
      white-space: pre;
    }

    &:not([data-type="literal"]) {
      box-sizing: content-box;
      width: 2ch;
      height: 22px;
      padding: 0 2px;
      border: 0;
      border-radius: 4px;
      background: transparent;
      color: inherit;
      font: inherit;
      text-align: center;
      caret-color: transparent;
      outline: none;

      &::placeholder {
        color: var(--muted);
      }

      &::selection {
        background: transparent;
      }

      &:focus {
        background: var(--ink);
        color: var(--paper);

        &::placeholder {
          color: var(--paper);
        }
      }

      &:disabled {
        color: inherit;
      }
    }

    &[data-type="year"] {
      width: 4ch;
    }

    &[data-type="dayPeriod"] {
      width: 2.6ch;
    }
  }
}

@scope ([data-example]) {
  /* The field sits near the top, centered, with room below for the open calendar inside the preview. */
  :scope[data-example^="date-picker/"] {
    justify-content: flex-start;
    min-height: 26rem;
  }

  :scope:is(
    [data-example="date-picker/presets"],
    [data-example="date-picker/dismissible"],
    [data-example="date-picker/controller"]
  ) {
    min-height: 29rem;
  }

  /* In a field, the picker takes the field's width. */
  [data-slot="field"] > [data-slot="date-picker"] {
    align-self: stretch;

    & > [data-slot="row"]:has(> [data-slot="date-picker-input"]) {
      width: 100%;
    }
  }

  /* A picker inside a stack sits on the stack's center line. */
  [data-slot="stack"]:has(> [data-slot="date-picker"]) {
    align-items: center;
  }

  [data-slot="date-picker"] {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    max-width: 100%;

    /* The row around the inputs and trigger is the field. */
    & > [data-slot="row"]:has(> [data-slot="date-picker-input"]) {
      flex-wrap: nowrap;
      gap: var(--space-1);
      box-sizing: border-box;
      width: 12rem;
      max-width: 100%;
      height: var(--size);
      padding-inline: 0 3px;
      border-radius: var(--radius-control);
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line);

      &:hover {
        box-shadow: inset 0 0 0 1px
          color-mix(in oklab, var(--ink) 45%, var(--surface-1));
      }

      &:has(input:focus-visible) {
        box-shadow: inset 0 0 0 1px var(--ink);
        outline: 3px solid var(--halo);
        outline-offset: 0;
      }
    }

    &
      > [data-slot="row"]:has(
        > [data-slot="date-picker-input"] ~ [data-slot="date-picker-input"]
      ) {
      width: 16rem;
    }

    &:has([aria-invalid="true"]) > [data-slot="row"] {
      box-shadow: inset 0 0 0 1px var(--danger);
    }

    &[data-disabled] > [data-slot="row"] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    &[data-readonly] > [data-slot="row"] {
      background: var(--tint);
    }
  }

  /* The input reaches the field's start edge, so the calendar lines up with the field. */
  [data-slot="date-picker-input"] {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    padding-inline-start: 10px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-variant-numeric: tabular-nums;
    outline: none;

    &::placeholder {
      color: var(--muted);
    }

    &[data-disabled]::placeholder {
      color: var(--line-disabled);
    }
  }

  :is([data-slot="date-picker-trigger"], [data-slot="date-picker-clear"]) {
    width: var(--size-sm);
    height: var(--size-sm);
    padding: 0;
    border-radius: var(--radius-row);
    color: var(--muted);

    &:hover:not(:disabled, [data-disabled]) {
      color: var(--ink);
    }
  }

  [data-slot="date-picker-hint"] {
    min-height: var(--leading);
    color: var(--muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;

    &[data-placeholder] {
      font-size: var(--text-xs);
    }
  }

  [data-slot="date-picker-clear"][data-empty] {
    visibility: hidden;
  }

  [data-slot="date-picker-content"] {
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    max-width: var(--available-width);
    max-height: var(--available-height);
    overflow-y: auto;
    padding: 10px;
    border-radius: var(--radius-popup);
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    font-size: var(--text-sm);
    outline: none;
    transform-origin: var(--transform-origin);

    /* As in Calendar, the header takes the grid's width rather than widening the popup for a long heading. */
    & > [data-slot="row"]:first-child {
      flex-wrap: nowrap;
      justify-content: space-between;
      width: 0;
      min-width: 100%;
      padding-bottom: var(--space-1);
    }

    & > [data-slot="row"]:has(> [data-slot="date-picker-preset"]) {
      gap: var(--space-1);
      padding-top: 6px;
      border-top: 1px solid var(--line-faint);
    }

    /* Messages wrap to the grid's width instead of widening the popup. */
    & > [data-slot="hint"] {
      width: 0;
      min-width: 100%;
      margin: 0;
      padding-top: var(--space-2);
      border-top: 1px solid var(--line-faint);
    }

    & [data-slot="calendar"] {
      padding: 0;
      background: none;
      box-shadow: none;
    }
  }

  [data-slot="date-picker-preset"] {
    height: var(--size-sm);
    padding-inline: 10px;
    border-radius: var(--radius-row);
    font-size: var(--text-sm);

    &[data-selected] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }
}

@scope ([data-example]) {
  /* Stacks and forms take the dialog's width, not the 20rem a stack with a field gets elsewhere. */
  :scope [data-slot="dialog-content"] > :is([data-slot="stack"], form) {
    width: auto;
    max-width: none;
  }

  /* Fields, inputs and text areas take the dialog's width, in a popup or a sheet. */
  :scope
    [data-slot="dialog-content"]
    :is(
      [data-slot="field"],
      [data-slot="field-control"],
      textarea,
      input:not([type="checkbox"], [type="radio"], [type="hidden"])
    ) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
  }

  [data-slot="dialog-content"] {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    box-sizing: border-box;
    width: min(28rem, calc(100% - 2rem));
    height: fit-content;
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 18px;
    border-radius: var(--radius-popup);
    background: var(--surface-3);
    box-shadow: var(--shadow-3);
    color: var(--ink);
    outline: none;

    &[data-nested-open] {
      translate: 0 -12px;
      scale: 0.97;
    }

    /* A sheet spans a phone, and stays a readable width on a wider screen. */
    &[data-presentation="sheet"] {
      position: relative;
      inset: auto;
      width: min(36rem, 100%);
      max-height: none;
      margin: 0 auto;
      border-radius: var(--radius-popup) var(--radius-popup) 0 0;
      --sheet-backdrop: var(--backdrop);
      padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

    & > :is([data-slot="stack"], form) {
      align-items: stretch;
    }

    /* The title and description sit close together; a form spaces its fields. */
    & > [data-slot="stack"]:has(> [data-slot="dialog-title"]) {
      gap: var(--space-1);
    }

    & > [data-slot="row"] {
      justify-content: flex-end;
    }

    /* A long middle section scrolls between a fixed header and actions. */
    & > [data-slot="scroll"] {
      display: flex;
      flex-direction: column;
      gap: var(--space-3);
      min-height: 0;
      max-height: 15rem;
      margin-inline: -18px;
      padding: var(--space-3) 18px;
      overflow-y: auto;
      border-block: 1px solid var(--line-faint);
      color: var(--muted);
      font-size: var(--text-sm);

      & p {
        margin: 0;
      }
    }

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

    & > form {
      display: flex;
      flex-direction: column;
      gap: var(--space-3);

      & > [data-slot="row"] {
        justify-content: flex-end;
        margin-top: var(--space-1);
      }
    }

    /* A question inside the dialog, with its answers at the end. */
    & > [data-slot="row"][role="alert"] {
      justify-content: space-between;
      padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
      border-radius: var(--radius-control);
      background: var(--tint);
      font-size: var(--text-sm);
    }

    /* A setting with its action, like a row in an account page. */
    & > [data-slot="card"] {
      align-items: center;
      justify-content: space-between;
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    & > [data-slot="stack"] > [data-slot="dialog-close"] {
      justify-content: flex-start;
      height: 32px;
      padding-inline: 10px;
      border-radius: var(--radius-row);
      background: transparent;
      box-shadow: none;
      font-weight: 400;

      &:hover {
        background: var(--tint);
        box-shadow: inset 0 0 0 1px var(--ink);
      }

      &:active {
        scale: none;
      }

      &:focus-visible {
        outline-offset: 0;
      }

      & > svg {
        width: 14px;
        height: 14px;
        color: var(--muted);
      }
    }

    & [data-slot="dialog-close"][aria-label] {
      position: absolute;
      top: var(--space-3);
      inset-inline-end: var(--space-3);
      width: var(--size-sm);
      height: var(--size-sm);
      padding: 0;
      background: transparent;
      box-shadow: none;
      color: var(--muted);

      &:hover {
        background: var(--tint);
        color: var(--ink);
      }
    }
  }

  [data-slot="dialog-title"] {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 22px;
  }

  [data-slot="dialog-description"] {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-md);
  }

  [data-slot="dialog-shortcut"] {
    margin-inline-start: var(--space-1);
    color: var(--muted);
    font-size: var(--text-xs);
    letter-spacing: 0.04em;
  }

  /* Only this demo animates the open and close. */
  :scope[data-example="dialog/animation"] {
    & [data-slot="dialog-content"] {
      transition:
        opacity var(--duration),
        translate var(--duration),
        scale var(--duration);

      &:is([data-starting-style], [data-ending-style]) {
        opacity: 0;
        translate: 0 8px;
      }
    }
  }

  [data-slot="dialog-frame"] {
    position: relative;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: min(28rem, 100%);
    height: 16rem;
    overflow: hidden;
    border-radius: var(--radius-surface);
    box-shadow: inset 0 0 0 1px var(--line);

    & :is([data-slot="dialog-backdrop"], [data-slot="dialog-content"]) {
      position: absolute;
    }

    & [data-slot="dialog-content"] {
      width: calc(100% - 2rem);
      max-height: calc(100% - 2rem);
    }
  }
}

@scope ([data-example]) {
  /* Stacks, forms and fields take the sheet's width, not the 20rem a stack with a field gets elsewhere. */
  :scope [data-slot="drawer-content"] > :is([data-slot="stack"], form) {
    width: auto;
    max-width: none;
  }

  :scope
    [data-slot="drawer-content"]
    :is(
      [data-slot="field"],
      [data-slot="field-control"],
      textarea,
      input:not([type="checkbox"], [type="radio"], [type="hidden"])
    ) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
  }

  /* A goal between its decrease and increase buttons. */
  :scope[data-example="drawer/basic"]
    [data-slot="drawer-content"]
    > [data-slot="row"] {
    flex-wrap: nowrap;
    justify-content: space-between;

    & > [data-slot="stack"] {
      flex: 1;
      align-items: center;
      gap: 0;
      text-align: center;

      & > :first-child {
        font-size: 2.5rem;
        font-weight: 600;
        line-height: 1.1;
        font-variant-numeric: tabular-nums;
      }
    }
  }

  [data-slot="drawer-backdrop"] {
    &[data-hidden] {
      display: none;
    }
  }

  [data-slot="drawer-content"] {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    box-sizing: border-box;
    width: 100%;
    max-height: 85dvh;
    padding: 18px;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    background: var(--surface-3);
    box-shadow: var(--shadow-3);
    color: var(--ink);
    outline: none;

    &::after {
      position: absolute;
      background: inherit;
      content: "";
    }

    &:is([data-side="bottom"], [data-side="top"]) {
      max-width: 32rem;
      height: fit-content;
      margin-inline: auto;
    }

    &[data-side="bottom"] {
      border-radius: var(--radius-popup) var(--radius-popup) 0 0;

      &::after {
        inset-inline: 0;
        top: 100%;
        height: 6rem;
        box-shadow:
          -1px 0 0 var(--line),
          1px 0 0 var(--line);
      }
    }

    &[data-side="top"] {
      border-radius: 0 0 var(--radius-popup) var(--radius-popup);

      &::after {
        inset-inline: 0;
        bottom: 100%;
        height: 6rem;
        box-shadow:
          -1px 0 0 var(--line),
          1px 0 0 var(--line);
      }
    }

    &:is([data-side="left"], [data-side="right"]) {
      width: 20rem;
      max-width: 85vw;
      height: 100%;
      max-height: none;
    }

    &[data-side="left"] {
      border-radius: 0 var(--radius-popup) var(--radius-popup) 0;

      &::after {
        inset-block: 0;
        right: 100%;
        width: 6rem;
        box-shadow:
          0 -1px 0 var(--line),
          0 1px 0 var(--line);
      }
    }

    &[data-side="right"] {
      border-radius: var(--radius-popup) 0 0 var(--radius-popup);

      &::after {
        inset-block: 0;
        left: 100%;
        width: 6rem;
        box-shadow:
          0 -1px 0 var(--line),
          0 1px 0 var(--line);
      }
    }

    &[data-snap-point]:not([data-snap-point="content"]) {
      height: calc(100dvh - 3rem);
      max-height: none;
    }

    &[data-nested-open] {
      scale: 0.97;
    }

    &[data-dragging] {
      user-select: none;
    }

    & > :is([data-slot="stack"], form) {
      align-items: stretch;
    }

    /* The title and description sit close together; a form spaces its fields. */
    & > [data-slot="stack"]:has(> [data-slot="drawer-title"]) {
      gap: var(--space-1);
    }

    & > form {
      display: flex;
      flex-direction: column;
      gap: var(--space-3);
    }

    & > [data-slot="stack"]:last-child {
      margin-top: auto;
    }

    & > [data-slot="stack"]:has([data-slot="drawer-close"]) {
      gap: var(--space-2);
    }

    & > [data-slot="row"] {
      justify-content: flex-end;
    }

    /* A long middle section scrolls between a fixed header and actions. */
    & > [data-slot="scroll"] {
      flex: 1;
      min-height: 0;
      max-height: none;
      margin: 0 -18px;
      padding: 0 18px;
      overflow-y: auto;
    }

    & [data-slot="list"] {
      width: auto;
    }

    & [data-slot="drawer-close"][aria-label] {
      position: absolute;
      top: var(--space-3);
      inset-inline-end: var(--space-3);
      width: var(--size-sm);
      height: var(--size-sm);
      padding: 0;
      background: transparent;
      box-shadow: none;
      color: var(--muted);

      &:hover {
        background: var(--tint);
        color: var(--ink);
      }
    }
  }

  [data-slot="drawer-title"] {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 22px;
  }

  [data-slot="drawer-description"] {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-md);
  }

  [data-slot="drawer-handle"] {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    align-items: center;
    gap: var(--space-1);
    margin-inline: auto;
    padding: var(--space-1) var(--space-3);
    border: 0;
    border-radius: var(--radius-row);
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    cursor: default;

    &:empty {
      box-sizing: content-box;
      width: 36px;
      height: 4px;
      padding: var(--space-1);
      background: var(--line-faint);
      background-clip: content-box;
      border-radius: 999px;
    }

    &:hover:empty {
      background-color: var(--line);
    }

    & svg[data-disabled] {
      color: var(--line-disabled);
    }
  }

  /* Release notes long enough to scroll on any screen, between the header and the button. */
  :scope[data-example="drawer/scrollable"]
    [data-slot="drawer-content"]
    > [data-slot="scroll"] {
    max-height: 18rem;
    padding-block: var(--space-3);
    border-block: 1px solid var(--line-faint);
  }

  /* Places behind the directions sheet: whole rows to pick from, the chosen one marked. */
  :scope[data-example="drawer/non-modal"]
    [data-slot="stack"]:has(> [data-slot="list"]) {
    align-items: center;

    & > [data-slot="list"] {
      width: 22rem;
      max-width: 100%;

      & > li {
        padding: 0;
      }

      & button {
        justify-content: space-between;
        width: 100%;
        height: auto;
        padding: var(--space-2) var(--space-3);
        background: transparent;
        box-shadow: none;
        font-weight: 400;

        &:hover {
          background: var(--tint);
        }

        &[aria-pressed="true"] {
          background: var(--tint);
          color: var(--ink);
          font-weight: 600;
        }
      }
    }
  }

  /* The inbox behind the compose sheet: a header the list's width, with its action at the end. */
  :scope[data-example="drawer/outlet"] [data-slot="drawer-outlet"] {
    width: 28rem;
    max-width: 100%;

    & > [data-slot="row"] {
      justify-content: space-between;
      padding: 0 var(--space-3) var(--space-3);
      font-weight: 600;
    }

    & > [data-slot="list"] {
      width: auto;
    }
  }

  [data-slot="drawer-outlet"] {
    display: block;
    transform-origin: top;
  }
}

@scope ([data-example]) {
  [data-slot="field"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 20rem;
    min-width: 0;
    max-width: 100%;

    &:has(> :is([data-slot="checkbox"], [data-slot="switch"])) {
      flex-direction: row;
      align-items: flex-start;

      & > [data-slot="checkbox"] {
        margin-top: 2px;
      }

      & > [data-slot="switch"] {
        margin-top: 0;
      }

      & > [data-slot="stack"] {
        gap: var(--space-1);
      }
    }

    &[data-valid] [data-hide="valid"],
    &:not([data-valid]) [data-show="valid"] {
      display: none;
    }
  }

  /* A legend sits outside the field set's flex gap, so it spaces itself. */
  [data-slot="field-legend"] {
    margin-bottom: var(--space-4);
    font-size: 15px;
    font-weight: 600;
    line-height: 22px;

    &:has(+ [data-slot="field-description"]) {
      margin-bottom: var(--space-1);
    }
  }

  [data-slot="field-description"] {
    display: block;
    margin: 0;
    color: var(--muted);
    font-size: var(--text-sm);
  }

  [data-slot="field-error"] {
    display: block;
    margin: 0;
    color: var(--danger);
    font-size: var(--text-sm);
  }

  [data-slot="field-set"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: 20rem;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
  }

  [data-slot="field-group"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }
}

@scope ([data-example]) {
  [data-slot="file-input"] {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    width: 20rem;
    max-width: 100%;
    min-width: 0;
  }

  [data-slot="file-input-dropzone"] {
    display: flex;
    flex-direction: column;
    align-items: center;
    align-self: stretch;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-8) var(--space-6);
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    text-align: center;
    transition:
      background-color var(--duration),
      box-shadow var(--duration);

    & > svg {
      width: 24px;
      height: 24px;
      margin-bottom: var(--space-2);
      color: var(--muted);
    }

    & > p:not([data-slot]) {
      font-weight: 500;
    }

    & > p + p {
      margin-top: 0;
    }

    & > [data-slot="file-input-trigger"] {
      margin-top: var(--space-3);
    }

    &[data-dragging] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-drag-reject] {
      background: color-mix(in oklab, var(--danger) 9%, var(--surface-2));
      box-shadow: inset 0 0 0 1px var(--danger);
      color: var(--danger);

      & > svg {
        color: inherit;
      }
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);

      & > svg {
        color: inherit;
      }
    }

    &[data-variant="overlay"] {
      position: fixed;
      inset: 0;
      z-index: 50;
      display: none;
      place-content: end center;
      padding: 0 0 var(--space-8);
      border-radius: 0;
      background: none;
      box-shadow: inset 0 0 0 2px var(--ink);
      pointer-events: none;

      &[data-dragging] {
        display: grid;
      }

      & > [data-slot="stack"] {
        flex-direction: row;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-popup);
        background: var(--surface-3);
        box-shadow: var(--shadow-3);
        font-weight: 500;
      }
    }
  }

  /* Page-wide drop: the hint and the upload button share a row above the list. */
  :scope[data-example="file-input/page"]
    [data-slot="file-input"]
    > [data-slot="row"] {
    flex-wrap: nowrap;
    justify-content: center;
    gap: var(--space-3);
  }

  [data-slot="file-input-list"] {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    gap: 1px;
    padding: 5px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    font-size: var(--text-sm);

    &:not(:has([data-slot="file-input-item"])) {
      display: none;
    }
  }

  [data-slot="file-input-item"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    min-height: 32px;
    padding-inline: 10px 4px;
    border-radius: var(--radius-row);

    &:focus-visible {
      outline-offset: -3px;
      background: var(--tint);
    }

    & > svg {
      flex-shrink: 0;
      color: var(--muted);
    }

    & > span:not([data-slot]) {
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    & > [data-slot="hint"] {
      flex-shrink: 0;
      font-size: var(--text-xs);
      font-variant-numeric: tabular-nums;
    }
  }

  [data-slot="file-input-item-remove"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: calc(var(--radius-control) - 2px);
    background: transparent;
    color: var(--muted);
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover:not([data-disabled]) {
      background: var(--tint);
      color: var(--ink);
    }

    &[data-disabled] {
      visibility: hidden;
    }
  }
}

@scope ([data-example]) {
  [data-slot="hover-card-trigger"] {
    border-radius: 4px;
    color: var(--ink);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: var(--line);
    text-underline-offset: 3px;

    &:hover,
    &[data-open] {
      text-decoration-color: var(--ink);
    }
  }

  [data-slot="hover-card-content"] {
    gap: var(--space-1);
    width: 18rem;
    font-size: var(--text-sm);

    & > p:first-of-type,
    & [data-slot="stack"] > p:first-child {
      font-size: var(--text-md);
      font-weight: 600;
    }

    & [data-slot="stack"] {
      gap: var(--space-1);
    }

    & p + p {
      margin-top: 0;
    }

    & p[data-slot="hint"] {
      margin-top: var(--space-1);
    }
  }

  /* Two short selects in one row, and room around the link for a card on any side. */
  :scope[data-example="hover-card/side"] {
    & [data-slot="stack"] {
      width: auto;
    }

    & [data-slot="hover-card-trigger"] {
      margin-block: 6.5rem;
    }

    & [data-slot="select-trigger"] {
      min-width: 8rem;
    }

    & [data-slot="hover-card-content"] {
      width: 15rem;
    }
  }
}

@scope ([data-example]) {
  [data-slot="image-cropper"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 24rem;
    max-width: 100%;

    &[data-mode="frame"] {
      width: 18rem;
    }

    & > [data-slot="row"] {
      flex-wrap: nowrap;
      gap: var(--space-2);
    }
  }

  [data-slot="image-cropper-viewport"] {
    aspect-ratio: var(--image-cropper-aspect-ratio, 32 / 21);
    max-height: 24rem;
    border-radius: var(--radius-surface);
    background: var(--tint);
    box-shadow: inset 0 0 0 1px var(--line-faint);

    &[data-mode="frame"] {
      aspect-ratio: 1;
      padding: var(--space-6);
      background: #0a0a0a;
    }

    &[data-disabled] {
      opacity: 0.5;
    }
  }

  [data-slot="image-cropper-image"] {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  [data-slot="image-cropper-selection"] {
    outline: 1px solid #fff;
    box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.5);

    &[data-shape="circle"] {
      border-radius: 50%;
    }

    &:focus-visible {
      outline: 3px solid #fff;
    }
  }

  [data-slot="image-cropper-grid"] {
    --grid-line: rgb(255 255 255 / 0.6);

    border-radius: inherit;
    background:
      linear-gradient(
        to right,
        transparent calc(100% / 3 - 0.5px),
        var(--grid-line) 0 calc(100% / 3 + 0.5px),
        transparent 0 calc(200% / 3 - 0.5px),
        var(--grid-line) 0 calc(200% / 3 + 0.5px),
        transparent 0
      ),
      linear-gradient(
        to bottom,
        transparent calc(100% / 3 - 0.5px),
        var(--grid-line) 0 calc(100% / 3 + 0.5px),
        transparent 0 calc(200% / 3 - 0.5px),
        var(--grid-line) 0 calc(200% / 3 + 0.5px),
        transparent 0
      );
    opacity: 0;

    &[data-dragging] {
      opacity: 1;
    }
  }

  [data-slot="image-cropper-handle"] {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4);
    translate: -50% -50%;

    &::after {
      content: "";
      position: absolute;
      inset: -12px;
    }

    &:focus-visible {
      outline: 3px solid var(--halo);
      outline-offset: 2px;
    }
  }

  [data-slot="image-cropper-zoom"] {
    flex: 1;
    min-width: 0;
  }

  [data-slot="image-cropper-result"] {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24rem;
    max-width: 100%;
    height: 7rem;
    padding: var(--space-2);
    border-radius: var(--radius-surface);
    background: var(--tint);
    box-shadow: inset 0 0 0 1px var(--line-faint);

    & > img {
      max-width: 100%;
      max-height: 100%;
      border-radius: var(--radius-row);
    }
  }

  [data-slot="image-cropper-avatar"] {
    width: var(--size-lg);
    height: var(--size-lg);
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--line-faint);
  }
}

@scope ([data-example]) {
  [data-slot="input-group"] {
    color: var(--muted);

    /* Text before or after the input reads as part of the value, like https://hollisgrant.com. */
    & > span:has(+ input) {
      margin-inline-end: calc(var(--space-2) * -1);
    }

    & > input + span {
      margin-inline-start: calc(var(--space-2) * -1);
    }
  }

  [data-slot="input-clear"]:not([data-filled]) {
    visibility: hidden;
  }
}

@scope ([data-example]) {
  [data-slot="label"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 500;
  }
}

@scope ([data-example]) {
  [data-slot="listbox"] {
    display: flex;
    flex-direction: column;
    gap: 1px;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    padding: 5px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    color: var(--ink);
    font-size: var(--text-md);

    &[data-readonly] {
      box-shadow: 0 0 0 1px var(--line-faint);
    }

    &[data-disabled] {
      box-shadow: 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    [data-slot="field"] > & {
      width: 100%;
    }
  }

  [data-slot="listbox-item"] {
    position: relative;
    padding-inline-end: 30px;
    color: inherit;
    text-decoration: none;

    &[data-selected] {
      background: color-mix(in oklab, var(--ink) 8%, transparent);
    }

    &[data-highlighted] {
      box-shadow: inset 0 0 0 1px var(--ink);

      &:not([data-selected]) {
        background: var(--tint);
      }
    }

    /* Hover shows where a click lands, quieter than a selection. */
    &:hover:not([data-disabled]) {
      background: color-mix(in oklab, var(--ink) 4%, transparent);

      &[data-selected] {
        background: color-mix(in oklab, var(--ink) 12%, transparent);
      }
    }

    &:focus-visible {
      outline-offset: -3px;
    }

    [data-disabled] > &[data-selected] {
      background: none;
      box-shadow: none;
    }

    & > svg:last-child {
      margin-inline-start: auto;
    }

    &:not([data-selected]) > svg:last-child {
      visibility: hidden;
    }
  }

  [data-slot="listbox-item-indicator"] {
    position: absolute;
    inset-inline-end: 10px;
    display: flex;
    padding: 0;

    & > svg {
      width: 14px;
      height: 14px;
    }
  }

  [data-slot="listbox-item-icon"] {
    display: flex;
    color: var(--muted);

    :is([data-highlighted], [data-selected]) > & {
      color: inherit;
    }
  }

  [data-slot="listbox-group"] {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  /* Horizontal: plain labels, the selected one is a raised pill like a selected tab. */
  [data-slot="listbox"][data-orientation="horizontal"] {
    flex-direction: row;
    gap: 2px;
    width: auto;
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;

    & [data-slot="listbox-item"] {
      justify-content: center;
      min-width: var(--size);
      height: 30px;
      min-height: 0;
      padding: 0 var(--space-3);
      border-radius: var(--radius-control);
      color: var(--muted);
      font-weight: 500;

      &:hover:not([data-disabled], [data-selected]) {
        background: none;
        color: var(--ink);
      }

      &[data-highlighted]:not([data-selected]) {
        background: var(--tint);
        box-shadow: none;
        color: var(--ink);
      }

      &[data-selected] {
        background: var(--surface-1);
        box-shadow:
          inset 0 0 0 1px var(--ink),
          var(--shadow-drop);
        color: var(--ink);
      }

      &[data-disabled] {
        color: var(--line-disabled);
      }

      &:focus-visible {
        outline: 3px solid var(--halo);
        outline-offset: 0;
      }
    }
  }

  /* A long list scrolls inside a fixed height, starting at the selected option. */
  :scope[data-example="listbox/scrollable"] [data-slot="listbox"] {
    max-height: 16rem;
    overflow-y: auto;
    scroll-padding-block: var(--space-8);
  }

  /* The form's buttons sit under the list, at its end. */
  :scope[data-example="listbox/form"] [data-slot="stack"] {
    align-items: stretch;
    width: 20rem;
    max-width: 100%;

    & > form {
      justify-content: flex-end;
    }
  }
}

@scope ([data-example]) {
  /* The trigger sits near the top, centered, with room below for the open menu inside the preview. */
  :scope:is(
    [data-example="menu/basic"],
    [data-example="menu/submenu"],
    [data-example="menu/shortcuts"],
    [data-example="menu/icons"],
    [data-example="menu/checkboxes"],
    [data-example="menu/radio-group"],
    [data-example="menu/disabled"],
    [data-example="menu/animation"]
  ) {
    justify-content: flex-start;
    min-height: 20rem;
  }

  :scope[data-example="menu/disabled"] {
    min-height: 24rem;
  }

  [data-slot="menu-content"] [data-slot="menu-trigger"] {
    &[data-open]:not([data-highlighted]) {
      background: var(--tint);
    }

    & > svg:last-child {
      width: 14px;
      height: 14px;
      margin-inline-start: auto;
      opacity: 0.7;

      &:is([dir="rtl"], [dir="rtl"] *) {
        rotate: 180deg;
      }
    }

    &[data-highlighted] > svg:last-child {
      opacity: 1;
    }
  }

  [data-slot="menu-item"] {
    position: relative;

    & > svg:first-child,
    & > [data-slot="menu-item-icon"] {
      color: var(--muted);
    }

    &:is([data-highlighted], [data-destructive]) > svg:first-child,
    &:is([data-highlighted], [data-destructive])
      > [data-slot="menu-item-icon"] {
      color: inherit;
    }

    &[data-disabled] > svg:first-child {
      color: inherit;
    }

    & > svg:last-child:not(:first-child) {
      margin-inline-start: auto;
    }

    & > [data-slot="stack"] {
      align-items: flex-start;
      gap: 0;
      padding-block: 2px;
    }

    & [data-slot="hint"] {
      font-size: var(--text-xs);
    }
  }

  a[data-slot="menu-item"] {
    color: inherit;
    text-decoration: none;

    & > svg {
      width: 14px;
      height: 14px;
      margin-inline-start: auto;
    }

    &:not([data-highlighted]) > svg {
      visibility: hidden;
    }
  }

  [data-slot="menu-checkbox-item"] {
    position: relative;

    & > svg:first-child {
      color: var(--muted);
    }

    &:is([data-highlighted], [data-checked]) > svg:first-child {
      color: inherit;
    }

    & > svg:last-child:not(:first-child) {
      width: 14px;
      height: 14px;
      margin-inline-start: auto;
    }

    &:not([data-checked]) > svg:last-child:not(:first-child) {
      visibility: hidden;
    }

    &[data-checked] > [data-slot="stack"] {
      font-weight: 500;
    }
  }

  [data-slot="menu-radio-item"] {
    position: relative;

    & > svg:first-child {
      color: var(--muted);
    }

    &:is([data-highlighted], [data-checked]) > svg:first-child {
      color: inherit;
    }

    & > svg:last-child:not(:first-child) {
      width: 14px;
      height: 14px;
      margin-inline-start: auto;
    }

    &:not([data-checked]) > svg:last-child:not(:first-child) {
      visibility: hidden;
    }

    &[data-checked] > [data-slot="stack"] {
      font-weight: 500;
    }
  }

  [data-slot="menu-content"]:has([data-slot="menu-item-indicator"])
    :is(
      [data-slot="menu-item"],
      [data-slot="menu-checkbox-item"],
      [data-slot="menu-radio-item"],
      [data-slot="menu-trigger"],
      [data-slot="menu-group-label"]
    ) {
    position: relative;
    padding-inline-start: 30px;
  }

  [data-slot="menu-item-indicator"] {
    display: grid;
    position: absolute;
    inset-inline-start: 10px;
    place-items: center;
    width: 14px;
    height: 14px;

    &[data-unchecked] {
      visibility: hidden;
    }

    & svg {
      width: 14px;
      height: 14px;
    }

    [data-slot="menu-radio-item"] > & svg:has(> circle:only-child) {
      width: 8px;
      height: 8px;
      fill: currentColor;
    }

    [data-slot="menu-radio-item"] > &:empty::before {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: currentColor;
      content: "";
    }
  }

  [data-slot="menu-item-icon"] {
    display: flex;
  }

  [data-slot="menu-content"] > [data-slot="row"] {
    flex-wrap: nowrap;
    padding: 6px 10px;

    & > [data-slot="stack"] {
      align-items: flex-start;
      gap: 0;
    }
  }

  [data-slot="menu-content"][data-presentation="sheet"] {
    max-height: none;
    border-radius: var(--radius-popup) var(--radius-popup) 0 0;
    padding: var(--space-6) var(--space-2)
      max(env(safe-area-inset-bottom), var(--space-3));

    &::before {
      position: absolute;
      inset-block-start: var(--space-2);
      inset-inline-start: 50%;
      width: 36px;
      height: 4px;
      border-radius: 999px;
      background: var(--line-faint);
      content: "";
      translate: -50% 0;
    }

    &
      :is(
        [data-slot="menu-item"],
        [data-slot="menu-checkbox-item"],
        [data-slot="menu-radio-item"],
        [data-slot="menu-trigger"]
      ) {
      min-height: 40px;
      padding-inline: var(--space-3);
    }

    & [data-slot="menu-content"] {
      min-width: 0;
      padding: 0;
      padding-inline-start: var(--space-6);
      background: none;
      box-shadow: none;
    }

    & [data-slot="menu-trigger"][data-open] > svg:last-child {
      rotate: 90deg;
    }
  }

  [data-slot="menu-context-trigger"] {
    display: grid;
    box-sizing: border-box;
    place-items: center;
    width: 24rem;
    max-width: 100%;
    height: 9rem;
    border: 1px dashed var(--line);
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    color: var(--muted);
    font-size: var(--text-sm);
    text-align: center;
    user-select: none;

    &[data-open] {
      border-color: var(--ink);
      background: var(--tint);
      color: var(--ink);
    }
  }

  ul:has([data-slot="menu-trigger"]) {
    gap: 0;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    list-style: none;

    & > li {
      flex-wrap: nowrap;
      padding-block: var(--space-1);
      padding-inline: var(--space-3) var(--space-1);
    }

    & > li + li {
      border-top: 1px solid var(--line-faint);
    }

    & [data-slot="hint"] {
      margin-inline-start: auto;
    }
  }

  :scope[data-example="menu/animation"] {
    &
      [data-slot="menu-content"][data-presentation="sheet"]
      [data-slot="menu-trigger"]
      > svg:last-child {
      transition: rotate var(--duration);
    }
  }
}

@scope ([data-example]) {
  /* The bar sits near the top, centered, with room below for its open menus inside the preview. */
  :scope[data-example="menubar/demo"] {
    justify-content: flex-start;
    min-height: 22rem;
  }

  [data-slot="menubar"] {
    display: flex;
    align-items: center;
    gap: 2px;
    width: fit-content;
    padding: 3px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    &[data-orientation="vertical"] {
      flex-direction: column;
      align-items: stretch;
      min-width: 8rem;
    }

    &[data-disabled] {
      box-shadow: 0 0 0 1px var(--line-faint);
    }

    & [data-slot="menu-trigger"]:not([data-slot="menu-content"] *) {
      justify-content: flex-start;
      height: var(--size-sm);
      padding-inline: 10px;
      border-radius: var(--radius-row);
      background: transparent;
      box-shadow: none;
      font-weight: 500;

      &:hover {
        background: var(--tint);
      }

      &[data-open] {
        background: var(--tint);
        box-shadow: inset 0 0 0 1px var(--ink);
      }

      &:active {
        scale: none;
      }

      &:focus-visible {
        outline-offset: 0;
      }

      &:is([data-disabled], [aria-disabled="true"], :disabled) {
        background: transparent;
        box-shadow: none;
        color: var(--line-disabled);
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="meter"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="stack"]:has(> [data-slot="meter"]) {
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="meter-label"] {
    font-weight: 500;
  }

  [data-slot="meter-value"] {
    margin-inline-start: auto;
    color: var(--muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  [data-slot="meter-track"] {
    display: flex;
    box-sizing: border-box;
    width: 100%;
    height: 10px;
    overflow: hidden;
    padding: 2px;
    border-radius: 999px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
  }

  [data-slot="meter-indicator"] {
    height: 100%;
    border-radius: 999px;
    background: var(--ink);

    &[data-variant="destructive"] {
      background: var(--danger);
    }
  }
}

@scope ([data-example]) {
  /* The menu sits near the top, centered, with room below for its open panels inside the preview. */
  :scope:is(
    [data-example="navigation-menu/basic"],
    [data-example="navigation-menu/link-component"],
    [data-example="navigation-menu/rtl"],
    [data-example="navigation-menu/vertical"],
    [data-example="navigation-menu/click-only"],
    [data-example="navigation-menu/nested"],
    [data-example="navigation-menu/animation"],
    [data-example="navigation-menu/custom-rendering"]
  ) {
    justify-content: flex-start;
    min-height: 22rem;
  }

  [data-slot="navigation-menu"] {
    position: relative;

    &:not([data-nested]) {
      padding: 3px;
      border-radius: var(--radius-surface);
      background: var(--surface-1);
      box-shadow: var(--shadow-1);
    }
  }

  [data-slot="navigation-menu-list"] {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;

    &[data-orientation="vertical"] {
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: stretch;
      width: 12rem;
    }
  }

  [data-slot="navigation-menu-trigger"],
  [data-slot="navigation-menu-link"]:not(
    [data-slot="navigation-menu-content"] *
  ) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    height: 30px;
    padding-inline: 10px;
    border: 0;
    border-radius: var(--radius-row);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    cursor: default;
    user-select: none;

    &:hover:not([data-disabled]) {
      background: var(--tint);
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &[data-open] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-current] {
      background: var(--tint);
      font-weight: 600;
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    & > svg {
      width: 14px;
      height: 14px;
      opacity: 0.7;
    }

    [data-orientation="vertical"] & {
      justify-content: space-between;
      width: 100%;

      & > svg:is([dir="rtl"], [dir="rtl"] *) {
        rotate: 180deg;
      }
    }
  }

  [data-slot="navigation-menu-trigger"][data-open]:not(
      [data-orientation="vertical"] *
    )
    > svg {
    rotate: 180deg;
  }

  [data-slot="navigation-menu-trigger"]:not([data-disabled])
    [data-show="disabled"],
  [data-slot="navigation-menu-link"]:not([data-current]) [data-show="current"],
  [data-slot="navigation-menu-content"][data-motion] [data-hide="motion"],
  [data-slot="navigation-menu-content"]:not([data-motion="from-end"])
    [data-show="from-end"],
  [data-slot="navigation-menu-content"]:not([data-motion="from-start"])
    [data-show="from-start"] {
    display: none;
  }

  [data-slot="navigation-menu-viewport"] {
    width: var(--viewport-width);
    height: var(--viewport-height);
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-popup);
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    outline: none;
    transform-origin: var(--transform-origin);

    & [data-slot="navigation-menu-content"]:not([popover]) {
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
    }
  }

  [data-slot="navigation-menu-content"] {
    box-sizing: border-box;
    width: max-content;
    max-width: calc(100vw - 3rem);
    max-height: var(--available-height);
    overflow-y: auto;
    padding: 5px;
    color: var(--ink);
    outline: none;

    &[popover] {
      margin: 0;
      border: 0;
      border-radius: var(--radius-popup);
      background: var(--surface-2);
      box-shadow: var(--shadow-2);
      transform-origin: var(--transform-origin);
    }

    & > [data-slot="hint"] {
      padding: var(--space-1) 10px var(--space-2);
    }

    & ul {
      width: 12rem;
      max-width: 100%;
      margin: 0;
      padding: 0;
      list-style: none;

      &:has([data-slot="hint"]):not([data-slot="grid"]) {
        width: 18rem;
      }

      & + ul {
        margin-top: var(--space-1);
        padding-top: var(--space-1);
        border-top: 1px solid var(--line-faint);
      }
    }

    & [data-slot="grid"] {
      gap: 2px;
      width: 30rem;

      &:has([data-variant="featured"]) {
        grid-template-columns: 0.8fr 1fr;
        width: 26rem;
      }

      & > li:has([data-variant="featured"]) {
        grid-row: span 3;
      }

      @media (width < 40rem) {
        &,
        &:has([data-variant="featured"]) {
          grid-template-columns: minmax(0, 1fr);
        }

        & > li:has([data-variant="featured"]) {
          grid-row: auto;
        }
      }
    }
  }

  [data-slot="navigation-menu-content"] [data-slot="navigation-menu-link"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-sizing: border-box;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: var(--radius-row);
    color: inherit;
    text-decoration: none;
    outline: none;
    cursor: default;

    &:is(:hover, :focus-visible) {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-current]:not(:hover, :focus-visible) {
      background: var(--tint);
    }

    &[data-current] {
      font-weight: 500;
    }

    &:has(> [data-slot="hint"]:not([data-show])) {
      flex-direction: column;
      align-items: stretch;
      gap: 2px;
      padding: var(--space-2) 10px;

      & > :first-child {
        font-weight: 500;
      }

      & > [data-slot="hint"] {
        display: -webkit-box;
        overflow: hidden;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }

      &[data-variant="featured"] {
        justify-content: flex-end;
        height: 100%;
        padding: var(--space-4);
        border-radius: var(--radius-control);
        background: var(--tint);

        & > :first-child {
          font-size: 18px;
          font-weight: 600;
          line-height: 24px;
        }

        & > [data-slot="hint"] {
          display: block;
        }
      }
    }
  }

  [data-slot="navigation-menu-link-icon"] {
    display: flex;
    color: var(--muted);

    :is(:hover, :focus-visible) > & {
      color: inherit;
    }

    & svg {
      width: 14px;
      height: 14px;
    }
  }

  /* Only this demo animates; the slide between panels is what it shows. */
  :scope[data-example="navigation-menu/animation"] {
    & [data-slot="navigation-menu-trigger"] > svg {
      transition: rotate var(--duration);
    }

    &
      :is(
        [data-slot="navigation-menu-viewport"],
        [data-slot="navigation-menu-content"]
      ) {
      transition: opacity var(--duration);

      &:is([data-starting-style], [data-ending-style]) {
        opacity: 0;
      }
    }

    & [data-slot="navigation-menu-viewport"][data-variant="slide"] {
      transition-property: opacity, width, height;
      transition-duration: calc(var(--duration) * 3);

      & [data-slot="navigation-menu-content"] {
        transition-property: opacity, translate;
        transition-duration: calc(var(--duration) * 3);

        &:is(
          [data-motion="from-end"][data-starting-style],
          [data-motion="to-end"][data-ending-style]
        ) {
          translate: 4rem 0;
        }

        &:is(
          [data-motion="from-start"][data-starting-style],
          [data-motion="to-start"][data-ending-style]
        ) {
          translate: -4rem 0;
        }

        &:is([dir="rtl"], [dir="rtl"] *):is(
            [data-motion="from-end"][data-starting-style],
            [data-motion="to-end"][data-ending-style]
          ) {
          translate: -4rem 0;
        }

        &:is([dir="rtl"], [dir="rtl"] *):is(
            [data-motion="from-start"][data-starting-style],
            [data-motion="to-start"][data-ending-style]
          ) {
          translate: 4rem 0;
        }
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="number-input"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    &:has(> [data-slot="number-input-scrub-area"] [data-slot="field-label"]) {
      flex-direction: column;
      align-items: stretch;

      & > [data-slot="number-input-scrub-area"] {
        align-self: flex-start;
      }
    }
  }

  [data-slot="number-input-group"] {
    gap: 0;
    width: 20rem;
    max-width: 100%;
    padding: 3px;

    &:not(:has(button)) {
      padding-inline: 10px;
    }
  }

  [data-slot="field"]:has(> [data-slot="number-input"]) {
    width: 20rem;
    max-width: 100%;
  }

  /* Stacks of number fields shrink to their fields, so they stay centered. */
  :scope[data-example^="number-input/"] [data-slot="stack"] {
    width: auto;
  }

  [data-slot="number-input-control"] {
    flex: 1;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0 2px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    text-align: center;
    outline: none;

    &:disabled {
      color: var(--line-disabled);
    }
  }

  :is(
    [data-slot="number-input-decrement"],
    [data-slot="number-input-increment"]
  ) {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    min-width: 28px;
    height: 28px;
    padding: 0 var(--space-1);
    border: 0;
    border-radius: calc(var(--radius-control) - 3px);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: 500;
    user-select: none;
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover:not([data-disabled]) {
      background: var(--tint);
      color: var(--ink);
    }

    &:active:not([data-disabled]) {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
      color: var(--ink);
    }

    &:focus-visible {
      outline-offset: -3px;
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    & svg {
      width: 14px;
      height: 14px;
    }
  }

  [data-slot="number-input-increment"]:not([data-at-bound]) > span,
  [data-slot="number-input-increment"][data-at-bound] > svg:has(+ span) {
    display: none;
  }

  [data-slot="number-input-scrub-area"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--muted);
    cursor: ew-resize;
    user-select: none;

    &[data-orientation="vertical"] {
      cursor: ns-resize;
    }

    &[data-scrubbing] {
      color: var(--ink);
    }

    & [data-slot="field-label"] {
      cursor: inherit;
    }
  }

  [data-slot="number-input-scrub-area-cursor"] {
    margin: -10px 0 0 -10px;
    color: var(--ink);

    & svg {
      width: 20px;
      height: 20px;
    }
  }

  /* A design-tool inspector: a titled card with a 2×2 grid of compact fields, each led by a letter handle. */
  :scope[data-example="number-input/scrub"] {
    & [data-slot="card"] {
      flex-direction: column;
      align-items: stretch;
      width: 16rem;
    }

    & [data-slot="grid"] {
      gap: var(--space-2);
    }

    & [data-slot="number-input-group"] {
      width: auto;
      height: 28px;
      padding: 0 var(--space-2) 0 0;
    }

    & [data-slot="number-input-scrub-area"] {
      flex-shrink: 0;
      justify-content: center;
      align-self: stretch;
      width: 24px;
      font-size: var(--text-xs);
      font-weight: 500;
    }

    & [data-slot="number-input-control"] {
      text-align: start;
    }
  }
}

@scope ([data-example]) {
  [data-slot="otp-input"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }

  /* Each demo, a field or a stack of them, sits centered in the preview. */
  :scope[data-example^="otp-input/"] > * > * {
    align-self: center;
  }

  /* A field around a code takes the code's width, so its label, description and error line up with the slots. */
  [data-slot="field"]:has(> [data-slot="otp-input"]) {
    width: min-content;
  }

  /* The form's fields share one column as wide as the longest code, with the buttons below. */
  :scope[data-example="otp-input/form"] [data-slot="stack"] {
    width: min-content;

    & > form,
    & [data-slot="field"] {
      align-self: stretch;
      width: auto;
    }
  }

  /* Letters display in uppercase without changing the stored value. */
  :scope[data-example="otp-input/pattern"] [data-slot="otp-input-slot"] {
    text-transform: uppercase;
  }

  [data-slot="otp-input-group"] {
    display: flex;
    border-radius: var(--radius-control);

    [data-focused] > & {
      outline: none;
    }
  }

  [data-slot="otp-input-slot"] {
    position: relative;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: var(--size);
    height: var(--size);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: 400;
    font-variant-numeric: tabular-nums;

    & + & {
      margin-inline-start: -1px;
    }

    &:first-child {
      border-start-start-radius: var(--radius-control);
      border-end-start-radius: var(--radius-control);
    }

    &:last-child {
      border-start-end-radius: var(--radius-control);
      border-end-end-radius: var(--radius-control);
    }

    [data-slot="otp-input"]:hover:not(
        [data-focused],
        [data-disabled],
        :has([readonly], [aria-invalid="true"])
      )
      & {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &[data-active] {
      z-index: 1;
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-fake-caret]:empty::after,
    & > span:empty {
      content: "";
      width: 1px;
      height: var(--size-icon);
      background: var(--ink);
      animation: otp-input-caret 1s step-end infinite;
    }

    [data-slot="otp-input"]:has([readonly]) & {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    [data-slot="otp-input"]:has([aria-invalid="true"]) & {
      box-shadow: inset 0 0 0 1px var(--danger);

      &[data-active] {
        outline-color: color-mix(in oklab, var(--danger) 20%, transparent);
      }
    }

    &[data-disabled] {
      background-color: var(--tint);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }
  }

  [data-slot="otp-input-separator"] {
    display: flex;
    color: var(--muted);

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    [data-slot="otp-input-slot"]::after,
    [data-slot="otp-input-slot"] > span {
      animation: none;
    }
  }
}

@keyframes otp-input-caret {
  50% {
    opacity: 0;
  }
}

@scope ([data-example]) {
  /* A table footer: the summary and page size on one line, the pages centered below. */
  :scope[data-example="pagination/total"] {
    & [data-slot="stack"] {
      align-self: center;
      align-items: stretch;
      gap: var(--space-4);
      width: 28rem;
      max-width: 100%;
    }

    & [data-slot="row"] {
      justify-content: space-between;
    }

    & p {
      margin: 0;
      color: var(--muted);
      font-variant-numeric: tabular-nums;
    }

    & [data-slot="label"] {
      font-weight: 400;
      color: var(--muted);
      white-space: nowrap;
    }

    & select {
      width: 4.5rem;
      color: var(--ink);
    }
  }

  [data-slot="pagination-list"] {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* A pill track: the current page widens to name itself, and the steps show the page they go to. */
  :scope[data-example="pagination/render"] {
    & [data-slot="pagination-list"] {
      gap: 2px;
      padding: 3px;
      border-radius: 999px;
      background: var(--tint);
    }

    &
      :is(
        [data-slot="pagination-link"],
        [data-slot="pagination-previous"],
        [data-slot="pagination-next"]
      ) {
      gap: 4px;
      height: 28px;
      min-width: 28px;
      padding-inline: 10px;
      border-radius: 999px;
      background: transparent;
      box-shadow: none;
      color: var(--muted);
      transition:
        background var(--duration),
        color var(--duration);

      &:hover:not([aria-disabled="true"]) {
        color: var(--ink);
      }

      &[aria-current="page"] {
        background: var(--surface-1);
        box-shadow: var(--shadow-drop);
        color: var(--ink);
        font-weight: 500;
      }

      &[aria-disabled="true"] {
        color: var(--line-disabled);
      }

      & > span {
        font-size: var(--text-sm);
        font-variant-numeric: tabular-nums;
      }
    }

    & [data-slot="pagination-ellipsis"] {
      width: 20px;
      height: 28px;
    }
  }

  [data-slot="pagination-item"]:not(:has(*)) {
    padding-inline: var(--space-2);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

  :is(
    [data-slot="pagination-first"],
    [data-slot="pagination-last"],
    [data-slot="pagination-link"],
    [data-slot="pagination-next"],
    [data-slot="pagination-previous"]
  ) {
    min-width: var(--size);
    padding-inline: var(--space-2);
    font-variant-numeric: tabular-nums;
    text-decoration: none;

    &:is([aria-current="page"], [data-current], [data-active]) {
      background: var(--surface-1);
      box-shadow:
        inset 0 0 0 1px var(--ink),
        var(--shadow-drop);
      color: var(--ink);
    }
  }

  :is([data-slot="pagination-previous"], [data-slot="pagination-next"]):has(
    > :not(svg, [data-slot="visually-hidden"])
  ) {
    gap: 6px;
    padding-inline: 10px;
  }

  [data-slot="pagination-ellipsis"] {
    display: inline-grid;
    place-items: center;
    width: var(--size);
    height: var(--size);
    color: var(--muted);
  }

  /* On a phone, a full range fits one line: tighter steps and links, and the custom track drops its step numbers. */
  @media (width < 40rem) {
    [data-slot="pagination-list"] {
      flex-wrap: nowrap;
      gap: 0;
    }

    :is(
      [data-slot="pagination-first"],
      [data-slot="pagination-last"],
      [data-slot="pagination-link"],
      [data-slot="pagination-next"],
      [data-slot="pagination-previous"]
    ) {
      min-width: 30px;
      padding-inline: 4px;
    }

    [data-slot="pagination-ellipsis"] {
      width: 24px;
    }

    :scope[data-example="pagination/render"] {
      &
        :is(
          [data-slot="pagination-link"],
          [data-slot="pagination-previous"],
          [data-slot="pagination-next"]
        ) {
        min-width: 26px;
        padding-inline: 7px;

        & > span {
          display: none;
        }
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="password-input"] {
    gap: var(--space-1);

    &:not([data-capslock]) > svg {
      visibility: hidden;
    }

    & > svg,
    & > span:not([data-slot]) {
      display: flex;
      color: var(--muted);
    }
  }

  [data-slot="password-input-control"][data-visible] {
    font-variant-numeric: slashed-zero;
  }

  [data-slot="password-input-toggle"] {
    &:focus-visible {
      outline-offset: 0;
    }

    &[data-visible] {
      color: var(--ink);
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  [data-slot="field"]:not(:has([data-capslock])) [data-slot="caps-lock"] {
    visibility: hidden;
  }

  [data-slot="caps-lock"] {
    min-height: var(--leading);
    color: var(--muted);
    font-size: var(--text-sm);
  }

  [data-slot="strength"] {
    display: flex;
    gap: var(--space-1);
    width: 20rem;
    max-width: 100%;

    & > * {
      flex: 1;
      height: 4px;
      border-radius: 999px;
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    & > [data-on] {
      background: var(--ink);
      box-shadow: none;
    }
  }
}

@scope ([data-example]) {
  /* The trigger sits near the top, centered, with room below for the open popover inside the preview. */
  :scope:is(
    [data-example="popover/basic"],
    [data-example="popover/form"],
    [data-example="popover/draft"],
    [data-example="popover/modal"],
    [data-example="popover/focus"],
    [data-example="popover/hover"],
    [data-example="popover/controlled"],
    [data-example="popover/shortcut"],
    [data-example="popover/payload"],
    [data-example="popover/animation"],
    [data-example="popover/custom-rendering"],
    [data-example="popover/offsets"],
    [data-example="popover/align"],
    [data-example="popover/anchor"]
  ) {
    justify-content: flex-start;
    min-height: 16rem;
  }

  :scope:is(
    [data-example="popover/basic"],
    [data-example="popover/form"],
    [data-example="popover/focus"],
    [data-example="popover/controlled"],
    [data-example="popover/shortcut"],
    [data-example="popover/anchor"]
  ) {
    min-height: 20rem;
  }

  :scope:is([data-example="popover/draft"], [data-example="popover/modal"]) {
    min-height: 23rem;
  }

  /* Stacks, forms and fields take the popover's width, not the 20rem a stack with a field gets elsewhere. */
  :scope [data-slot="popover-content"] > :is([data-slot="stack"], form) {
    width: auto;
    max-width: none;
  }

  :scope
    [data-slot="popover-content"]
    :is(
      [data-slot="field"],
      [data-slot="field-control"],
      textarea,
      select,
      input:not([type="checkbox"], [type="radio"], [type="hidden"])
    ) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
  }

  [data-slot="popover-content"] {
    gap: var(--space-3);
    box-sizing: border-box;
    width: 18rem;
    max-width: calc(100vw - 2rem);
    padding: var(--space-4);
    font-size: var(--text-sm);

    & > :is([data-slot="stack"], form) {
      align-items: stretch;
    }

    & > form {
      display: flex;
      flex-direction: column;
      gap: var(--space-3);
    }

    & [data-slot="field"] {
      gap: 6px;
    }

    & [data-slot="field-label"] {
      font-size: var(--text-sm);
    }

    & > [data-slot="stack"]:has(> [data-slot="label"]) {
      gap: var(--space-2);
    }

    & textarea {
      min-height: 5rem;
    }

    /* Actions sit at the bottom, aligned to the end, with the primary last. */
    & > [data-slot="row"],
    & > form > [data-slot="row"] {
      justify-content: flex-end;
      margin-top: var(--space-1);
    }

    /* A question inside the popover, with its answers at the end. */
    & > [data-slot="row"][role="alert"] {
      justify-content: space-between;
      padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
      border-radius: var(--radius-control);
      background: var(--tint);
    }

    &[data-presentation="sheet"] {
      width: min(36rem, 100%);
      max-width: none;
      margin: 0 auto;
      border-radius: var(--radius-popup) var(--radius-popup) 0 0;
      padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
      --sheet-backdrop: var(--backdrop);
    }
  }

  [data-slot="popover-title"] {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 20px;
  }

  [data-slot="popover-description"] {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-sm);
  }

  /* The title and description read as one header. */
  [data-slot="popover-title"] + [data-slot="popover-description"] {
    margin-top: calc(var(--space-3) * -1 + 2px);
  }

  a[data-slot="popover-close"] {
    align-self: flex-start;
    color: var(--ink);
    text-underline-offset: 3px;
  }

  [data-slot="popover-trigger"]:not([data-open]) [data-show="open"],
  [data-slot="popover-trigger"][data-open] [data-hide="open"] {
    display: none;
  }

  /* The arrow takes the popover's fill and border. */
  [data-slot="popover-arrow"] {
    background: var(--surface-2);
    border-color: var(--line);
  }

  /* Room around the trigger for the popover on any side. */
  :scope[data-example="popover/arrow"] [data-slot="popover-trigger"] {
    margin-block: 6rem;
  }

  :scope[data-example="popover/placement"] [data-slot="popover-trigger"] {
    margin-block: 6rem;
  }

  /* Each select beside its label, one per line, so the controls fit a phone. */
  :scope:is(
      [data-example="popover/placement"],
      [data-example="popover/modal"],
      [data-example="popover/offsets"]
    )
    [data-slot="controls"] {
    display: grid;
    grid-template-columns: auto auto;
    gap: var(--space-2) var(--space-3);

    & [data-slot="select-label"] {
      justify-self: end;
    }

    & [data-slot="select-trigger"] {
      min-width: 8rem;
    }
  }

  :scope:is(
      [data-example="popover/placement"],
      [data-example="popover/offsets"]
    )
    [data-slot="stack"]:has(> [data-slot="controls"]) {
    width: auto;
  }

  /* The list, with room below its last row for the editor. */
  :scope[data-example="popover/payload"] {
    min-height: 27rem;

    & [data-slot="stack"]:has(> [data-slot="list"]) {
      width: 24rem;
      max-width: 100%;
    }

    & [data-slot="list"] {
      width: 100%;
    }
  }

  /* The search field and its filter button, side by side. */
  :scope[data-example="popover/anchor"]
    [data-slot="row"]:has(> input[type="search"]) {
    flex-wrap: nowrap;
    width: 20rem;
    max-width: 100%;

    & > input {
      flex: 1;
      width: auto;
    }
  }

  [data-slot="popover-frame"] {
    position: relative;
    box-sizing: border-box;
    width: min(28rem, 100%);
    height: 16rem;
    overflow: hidden;
    border-radius: var(--radius-surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }

  [data-slot="popover-corner"] {
    position: absolute;
    right: var(--space-4);
    bottom: var(--space-4);

    & [data-slot="popover-content"] {
      position: absolute;
      right: 0;
      bottom: calc(100% + var(--space-2));
    }
  }
}

@scope ([data-example]) {
  /* The view switch above a file list, one 20rem column; Preferences itself renders as display: contents. */
  :scope[data-example="preferences/basic"] [data-slot="stack"] {
    align-self: center;
    align-items: stretch;
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="files"] {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    border-radius: var(--radius-control);
    box-shadow: inset 0 0 0 1px var(--line);
    list-style: none;

    & > li {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-3);
      padding: var(--space-2) var(--space-3);

      & + li {
        border-top: 1px solid var(--line-faint);
      }
    }
  }

  /* The grid view: tiles with a thumbnail area, two to a row. */
  [data-view="grid"] [data-slot="files"] {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    box-shadow: none;

    & > li {
      flex-direction: column;
      align-items: stretch;
      gap: 2px;
      padding: var(--space-2);
      border-radius: var(--radius-control);
      box-shadow: inset 0 0 0 1px var(--line);

      &::before {
        content: "";
        height: 3.5rem;
        margin-bottom: var(--space-1);
        border-radius: calc(var(--radius-control) - 2px);
        background: var(--tint);
      }

      & + li {
        border-top: 0;
      }

      & > span:first-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="progress"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="stack"]:has(> [data-slot="progress"]) {
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="progress-label"] {
    font-weight: 500;
  }

  [data-slot="progress-value"] {
    margin-inline-start: auto;
    color: var(--muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  [data-slot="progress-track"] {
    display: flex;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 10px;
    overflow: hidden;
    padding: 2px;
    border-radius: 999px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
  }

  [data-slot="progress-indicator"] {
    height: 100%;
    border-radius: 999px;
    background: var(--ink);

    &[data-variant="destructive"] {
      background: var(--danger);
    }

    [data-slot="progress-track"][data-indeterminate] & {
      width: 40%;
      background: linear-gradient(90deg, transparent, var(--ink), transparent);
      animation: progress-sweep 1.2s ease-in-out infinite;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    [data-slot="progress-track"][data-indeterminate]
      [data-slot="progress-indicator"] {
      width: 100%;
      background: color-mix(in oklab, var(--ink) 30%, transparent);
      animation: none;
    }
  }
}

@keyframes progress-sweep {
  from {
    translate: -100% 0;
  }

  to {
    translate: 250% 0;
  }
}

@scope ([data-example]) {
  /* Each demo sits centered; a group of plain radios shrinks to its options, while cards keep their width. */
  :scope[data-example^="radio/"] > * > * {
    align-self: center;
  }

  :scope[data-example^="radio/"]
    :is([data-slot="field"], fieldset, [data-slot="stack"]):has(
      [data-slot="radio-group"]
    ):not(:has([data-slot="card"], [data-slot="radio-group"] > button)) {
    width: max-content;
    max-width: 100%;
  }

  /* The check keeps its space on every card, so moving it never rewraps the text. */
  :scope[data-example="radio/render"]
    [data-slot="radio"]
    > svg:not([data-checked]) {
    visibility: hidden;
  }

  [data-slot="radio-group"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);

    &[data-disabled] [data-slot="label"] {
      color: var(--line-disabled);
    }

    & > [data-slot="label"] {
      font-weight: 400;
    }

    & > [data-slot="label"] > [data-slot="hint"] {
      margin-inline-start: calc(var(--space-1) * -1);
    }
  }

  [data-slot="field-description"] + [data-slot="radio-group"] {
    margin-top: var(--space-1);
  }

  /* Two groups, one under the other. */
  :scope[data-example="radio/disabled"] > * > [data-slot="stack"] {
    gap: var(--space-6);
  }

  /* A choice card keeps its radio at the top end, in line with the title. */
  [data-slot="card"] > [data-slot="radio"] {
    margin-top: 2px;
    margin-inline-start: auto;

    &:focus-visible {
      outline: none;
    }
  }

  [data-slot="card"]:has(> [data-slot="radio"]:focus-visible) {
    outline: 3px solid var(--halo);
    outline-offset: 2px;
  }

  /* A radio in a field of its own sits beside its label and description. */
  [data-slot="field"]:has(> [data-slot="radio"]) {
    flex-direction: row;
    align-items: flex-start;
    width: auto;

    & > [data-slot="radio"] {
      margin-top: 2px;
    }

    & > [data-slot="stack"] {
      gap: var(--space-1);
    }
  }

  [data-slot="radio-group"]:has(> [data-slot="field"]) {
    gap: var(--space-3);
  }

  [data-slot="radio"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    cursor: default;
    transition: box-shadow var(--duration);

    &:hover:not([data-disabled], [data-readonly], [data-checked]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &[data-checked] {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1.5px var(--ink);
    }

    &:is([data-invalid], [aria-invalid="true"]) {
      box-shadow: inset 0 0 0 1px var(--danger);
    }

    &[data-readonly]:not([data-checked]) {
      background: var(--tint);
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &[data-disabled][data-checked] {
      box-shadow: inset 0 0 0 1.5px var(--line-disabled);
    }
  }

  [data-slot="radio-indicator"] {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink);

    &[data-unchecked] {
      visibility: hidden;
    }

    [data-disabled] > & {
      background: var(--line-disabled);
    }
  }

  /* The indicator scales in and out, and a hovered option previews its dot. */
  :scope[data-example="radio/indicator"] [data-slot="radio-indicator"] {
    transition:
      opacity 0.15s,
      scale 0.15s;

    &[data-unchecked] {
      visibility: visible;
      opacity: 0;
      scale: 0.5;
    }

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
      scale: 0.5;
    }

    [data-slot="label"]:hover &[data-unchecked] {
      opacity: 0.3;
      scale: 1;
    }

    @media (prefers-reduced-motion: reduce) {
      transition: none;
    }
  }

  [data-slot="label"]:has(> [data-slot="radio"][data-disabled]) {
    color: var(--line-disabled);
  }

  /* A radio with its own content is a choice card. */
  [data-slot="radio"]:not(:empty, :has(> [data-slot="radio-indicator"])) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    width: auto;
    min-width: var(--size);
    height: auto;
    min-height: var(--size);
    padding: var(--space-3);
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    font: inherit;
    text-align: start;

    &:hover:not([data-disabled], [data-checked]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &[data-checked] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-disabled] {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    & > [data-slot="stack"] {
      flex: 1;
      gap: var(--space-1);
      font-weight: 500;
    }

    &:has(> [data-slot="stack"]) {
      align-items: flex-start;
    }

    & > svg:last-child:not(:first-child) {
      margin-top: 2px;
      margin-inline-start: auto;
    }

    [data-slot="radio-group"]:not([data-variant]) > & {
      width: 100%;
    }
  }
}

@scope ([data-example]) {
  [data-slot="rating"] {
    display: inline-flex;
    gap: 2px;

    &[data-disabled] {
      opacity: 0.6;
    }
  }

  /* The fill is the star's own shape, painted up to --rating-fill from the start edge. */
  [data-slot="rating-item"] {
    --rating-color: var(--ink);
    --rating-direction: to right;

    display: inline-flex;
    color: var(--line);

    &:dir(rtl) {
      --rating-direction: to left;
    }

    &[data-highlighted] {
      --rating-color: var(--muted);
    }

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      background: linear-gradient(
        var(--rating-direction),
        var(--rating-color) calc(var(--rating-fill) * 100%),
        transparent 0
      );
      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E")
        0 0 / 100% 100% no-repeat;
      pointer-events: none;
    }

    & > svg {
      width: 24px;
      height: 24px;
    }
  }

  [data-slot="rating-radio"] {
    border-radius: var(--radius-control);
    cursor: default;

    &:focus-visible {
      outline-offset: 0;
    }
  }
}

@scope ([data-example]) {
  [data-slot="resizable"] {
    box-sizing: border-box;
    width: 28rem;
    max-width: 100%;
    height: 13rem;
    overflow: hidden;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    & & {
      width: auto;
      max-width: none;
      height: 100%;
      border-radius: 0;
      background: none;
      box-shadow: none;
    }
  }

  [data-slot="stack"]:has(> [data-slot="resizable"]) {
    width: 28rem;
    max-width: 100%;
  }

  /* A panel lists its title and content from the top, clipping what no longer fits. */
  [data-slot="resizable-panel"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    box-sizing: border-box;
    padding: var(--space-4);
    overflow: hidden;

    &:has(> [data-slot="resizable"]) {
      padding: 0;
    }

    & > :is(h3, [data-slot="hint"]),
    & li {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    & > h3 + ul {
      margin-top: var(--space-2);
    }

    & li {
      color: var(--muted);
    }

    & li[data-slot="row"] {
      flex-wrap: nowrap;
      height: var(--size-sm);
      color: var(--ink);

      & > span {
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    &[data-collapsed] li[data-slot="row"] > span {
      display: none;
    }
  }

  [data-slot="resizable-handle"] {
    position: relative;
    z-index: 1;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1px;
    background: var(--line);
    outline: none;
    cursor: col-resize;

    &::before {
      position: absolute;
      inset: 0 -5px;
      content: "";
    }

    &[aria-orientation="horizontal"] {
      width: 100%;
      height: 1px;
      cursor: row-resize;

      &::before {
        inset: -5px 0;
      }
    }

    &:is(:hover, [data-hovering], [data-dragging]) {
      background: var(--ink);
    }

    &:focus-visible {
      background: var(--ink);
      box-shadow: 0 0 0 3px var(--halo);
    }

    &[data-disabled] {
      background: var(--line-faint);
      cursor: default;
    }

    & > div {
      flex-shrink: 0;
      box-sizing: border-box;
      width: 8px;
      height: 20px;
      border-radius: 4px;
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line);
    }

    &[aria-orientation="horizontal"] > div {
      width: 20px;
      height: 8px;
    }

    &:is(:hover, [data-hovering], [data-dragging], :focus-visible) > div {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    /* A finger needs a wider target than a pointer. */
    @media (pointer: coarse), (max-width: 40rem) {
      &::before {
        inset: 0 -12px;
      }

      &[aria-orientation="horizontal"]::before {
        inset: -12px 0;
      }

      & > div {
        width: 10px;
        height: 28px;
        border-radius: 5px;
      }

      &[aria-orientation="horizontal"] > div {
        width: 28px;
        height: 10px;
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="scroll-area"] {
    position: relative;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    height: 16rem;
    overflow: hidden;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    [data-slot="row"] > [data-slot="stack"] > & {
      width: 12rem;
    }

    /* Edge fades read the overflow variables, which only the root holds. */
    &
      > :is(
        [data-slot="top-fade"],
        [data-slot="bottom-fade"],
        div:not([data-slot])
      ) {
      --scroll-area-overflow-y-start: inherit;
      --scroll-area-overflow-y-end: inherit;
      position: absolute;
      inset-inline: 0;
      top: 0;
      height: min(2rem, var(--scroll-area-overflow-y-start));
      background: linear-gradient(var(--surface-1), transparent);
      pointer-events: none;
    }

    &
      > :is(
        [data-slot="bottom-fade"],
        div:not([data-slot]) + div:not([data-slot])
      ) {
      top: auto;
      bottom: 0;
      height: min(2rem, var(--scroll-area-overflow-y-end));
      background: linear-gradient(transparent, var(--surface-1));
    }
  }

  [data-slot="stack"]:has(> [data-slot="scroll-area"]) {
    max-width: 100%;
  }

  [data-slot="scroll-area-viewport"] {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    outline-offset: -3px;
  }

  [data-slot="scroll-area-content"] {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);

    & > h3 {
      margin-bottom: var(--space-1);
    }

    & > ul {
      gap: 0;
      font-variant-numeric: tabular-nums;
    }

    & > ul > li {
      padding-block: 6px;
    }

    & > ul > li + li {
      border-top: 1px solid var(--line-faint);
    }

    & > ul > li:has(> [data-slot="hint"]) {
      display: flex;
      flex-direction: column;
      padding-block: var(--space-2);
      font-weight: 500;

      & > [data-slot="hint"] {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    & > article + article {
      margin-top: var(--space-3);
      padding-top: var(--space-3);
      border-top: 1px solid var(--line-faint);
    }

    & > article > h3 {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      margin-bottom: var(--space-1);

      & > [data-slot="hint"] {
        font-size: var(--text-xs);
      }
    }

    &:has(> figure) {
      display: flex;
      gap: var(--space-4);
      width: max-content;
    }

    & > figure {
      margin: 0;

      & > div {
        box-sizing: border-box;
        width: 8rem;
        height: 10rem;
        border-radius: var(--radius-control);
        background: var(--tint);
        box-shadow: inset 0 0 0 1px var(--line-faint);
      }

      & > figcaption {
        padding-top: var(--space-2);
        color: var(--muted);
        font-size: var(--text-xs);
      }
    }

    &:has(> table) {
      padding: 0;
    }

    & > table {
      white-space: nowrap;
      font-variant-numeric: tabular-nums;

      & thead th {
        position: sticky;
        top: 0;
        border-bottom: 0;
        background: var(--surface-1);
        box-shadow: inset 0 -1px var(--line-faint);
      }

      & tbody th {
        color: var(--ink);
      }

      & tr:last-child > * {
        border-bottom: 0;
      }
    }
  }

  [data-slot="scroll-area-scrollbar"] {
    display: flex;
    box-sizing: border-box;
    padding: 2px;
    opacity: 0;
    transition: opacity var(--duration);

    &[data-orientation="vertical"] {
      flex-direction: column;
      width: 10px;
      margin-block: var(--space-1);
    }

    &[data-orientation="horizontal"] {
      height: 10px;
      margin-inline: var(--space-1);
    }

    &[data-visible] {
      opacity: 1;
    }
  }

  [data-slot="scroll-area-thumb"] {
    position: relative;
    border-radius: 999px;
    background: var(--line-faint);

    :is([data-scrolling], [data-hovering]) > & {
      background: var(--line);
    }

    &[data-dragging] {
      background: var(--muted);
    }
  }

  [data-slot="scroll-area-corner"] {
    background: transparent;
  }

  [data-slot="scroll-area"] > [data-slot="hint"] {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding-block: var(--space-2);
    background: linear-gradient(transparent, var(--surface-1) 40%);
    font-size: var(--text-xs);
    text-align: center;
    pointer-events: none;

    [data-slot="scroll-area"]:is(
        [data-at-end],
        :not([data-overflow-x], [data-overflow-y])
      )
      > & {
      display: none;
    }

    [data-slot="scroll-area"][data-at-start] > & > [data-show="more"],
    [data-slot="scroll-area"]:not([data-at-start]) > & > [data-show="start"] {
      display: none;
    }
  }

  /* Four equal swatches fill the row at rest, with gaps as wide as the padding and room for the scrollbar. */
  :scope[data-example="scroll-area/horizontal"] [data-slot="scroll-area"] {
    container-type: inline-size;
    height: auto;

    & [data-slot="scroll-area-content"] {
      padding: var(--space-3) var(--space-3) 22px;
    }

    & ul {
      flex-direction: row;
      gap: var(--space-3);
      width: max-content;
    }

    & li {
      display: flex;
      flex-direction: column;
      gap: 6px;
      width: calc((100cqi - 5 * var(--space-3)) / 4);
      padding: 0;
      border-top: 0;
      color: var(--muted);
      font-size: var(--text-xs);
    }

    & [data-slot="swatch"] {
      width: 100%;
      height: auto;
      aspect-ratio: 1;
      border-radius: var(--radius-control);
    }
  }

  /* Labeled scroll areas side by side, two to a row. */
  :scope:is(
    [data-example="scroll-area/type"],
    [data-example="scroll-area/hide-delay"]
  ) {
    & [data-slot="grid"] {
      align-items: end;
      gap: var(--space-3);
      width: 26rem;
      max-width: 100%;
    }

    & [data-slot="stack"] {
      align-items: stretch;
      gap: var(--space-2);
      min-width: 0;
    }

    & [data-slot="scroll-area"] {
      width: 100%;
      height: 10rem;
    }

    & code {
      color: var(--muted);
      font-family: var(--mono);
      font-size: var(--text-xs);
    }
  }
}

@scope ([data-example]) {
  [data-slot="segmented-control"] {
    position: relative;
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: calc(var(--radius-control) + 2px);
    background: var(--tint);
    isolation: isolate;

    &[data-orientation="vertical"] {
      flex-direction: column;
    }

    [data-slot="field"] > & {
      display: flex;

      &[data-orientation="vertical"] {
        align-self: flex-start;
      }

      &:not([data-orientation="vertical"])
        > [data-slot="segmented-control-item"] {
        flex: 1;
      }
    }

    &[data-disabled] {
      opacity: 0.6;
    }
  }

  [data-slot="segmented-control-item"] {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    cursor: default;

    &:hover:not([data-disabled]) {
      color: var(--ink);
    }

    &[data-checked] {
      color: var(--ink);
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    &:focus-visible {
      outline-offset: 0;
    }
  }

  [data-slot="segmented-control-indicator"] {
    position: absolute;
    top: var(--segmented-control-indicator-top);
    left: var(--segmented-control-indicator-left);
    box-sizing: border-box;
    width: var(--segmented-control-indicator-width);
    height: var(--segmented-control-indicator-height);
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--ink),
      var(--shadow-drop);
    transition-property: top, left, width, height;
    transition-duration: calc(var(--duration) * 2);

    &[data-activation-direction="none"] {
      transition: none;
    }
  }
}

@scope ([data-example]) {
  /* The field sits near the top and centered, with room below for the open list inside the preview. */
  :scope[data-example^="select/"] {
    justify-content: flex-start;
    min-height: 20rem;

    & > * > * {
      align-self: center;
      max-width: 100%;
    }
  }

  :scope:is(
    [data-example="select/controlled"],
    [data-example="select/modal"],
    [data-example="select/align-item"]
  ) {
    min-height: 24rem;
  }

  :scope:is(
    [data-example="select/groups"],
    [data-example="select/scrollable"],
    [data-example="select/typeahead"],
    [data-example="select/search-groups"],
    [data-example="select/searchable"],
    [data-example="select/async-search"],
    [data-example="select/virtualized"],
    [data-example="select/controller"],
    [data-example="select/disabled"],
    [data-example="select/form"]
  ) {
    min-height: 31rem;
  }

  /* The selected item's text lands on the trigger's: the popup's padding plus the item's. */
  :scope[data-example="select/align-item"] [data-slot="select-trigger"] {
    padding-inline-start: 15px;
  }

  /* The controls sit wider than the field, so they wrap only on a phone. */
  :scope[data-example="select/controller"]
    [data-slot="stack"]:has(> [data-slot="controls"]) {
    width: auto;
  }

  /* Each select beside its label, one per line, so the controls fit a phone. */
  :scope[data-example="select/positioning"] {
    min-height: 30rem;

    & [data-slot="controls"] {
      display: grid;
      grid-template-columns: auto auto;
      gap: var(--space-2) var(--space-3);

      & [data-slot="select-label"] {
        justify-self: end;
      }

      & [data-slot="select-trigger"] {
        min-width: 8rem;
      }

      & > [data-slot="label"] {
        grid-column: 2;
      }
    }
  }

  [data-slot="select-label"] {
    font-weight: 500;

    &[data-disabled] {
      color: var(--line-disabled);
    }
  }

  [data-slot="stack"]:has(
    > [data-slot="select-label"],
    > [data-slot="select"] > [data-slot="select-label"]
  ) {
    align-items: stretch;
    gap: var(--space-2);
  }

  /* Field-shaped on top of the shared button look. */
  [data-slot="select-trigger"] {
    justify-content: space-between;
    min-width: 12rem;
    max-width: 100%;
    padding-inline: 10px 8px;
    font-weight: 400;
    text-align: start;

    &:active:not([data-disabled], [data-readonly]) {
      scale: 0.98;
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &:is([data-invalid], [aria-invalid="true"]),
    [data-invalid] > & {
      box-shadow:
        inset 0 0 0 1px var(--danger),
        var(--shadow-drop);
    }

    &[data-readonly] {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line);
    }

    & > svg:last-child {
      color: var(--muted);
    }

    &[data-disabled] > svg:last-child {
      color: inherit;
    }
  }

  [data-slot="select-value"] {
    display: flex;
    flex: 1;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    overflow: hidden;
    text-align: start;
    text-overflow: ellipsis;
    white-space: nowrap;

    &[data-placeholder] {
      color: var(--muted);
    }

    [data-disabled] > & {
      color: inherit;
    }
  }

  [data-slot="select-value-icon"] {
    display: flex;
    color: var(--muted);
  }

  /* A row the keyboard reveals keeps a row of room from the scroller's edges. */
  :is([data-slot="select-content"], [data-slot="select-list"]) {
    scroll-padding-block: var(--space-8);
  }

  [data-slot="select-content"] {
    min-width: max(10rem, var(--anchor-width));
    max-height: min(20rem, var(--available-height));

    &:has(> [data-slot="select-list"]) {
      display: flex;
      flex-direction: column;
      gap: var(--space-1);
      overflow: hidden;
    }

    &[data-presentation="sheet"] {
      --sheet-backdrop: var(--backdrop);
      width: min(36rem, 100%);
      min-width: 0;
      max-width: none;
      max-height: 70dvh;
      margin: 0 auto;
      padding: var(--space-2) var(--space-2)
        max(env(safe-area-inset-bottom), var(--space-4));
      border-radius: var(--radius-popup) var(--radius-popup) 0 0;

      & [data-slot="select-item"] {
        min-height: 40px;
      }
    }
  }

  [data-slot="select-content"]:has(> div > [data-slot="select-list"]) {
    overflow: hidden;

    & > div {
      max-height: calc(var(--available-height) - 10px);
      overflow-y: auto;
      overscroll-behavior: contain;
    }

    & [data-slot="select-list"] > div {
      position: relative;
    }

    & [data-slot="select-item"] {
      position: absolute;
      inset-inline: 0;
    }
  }

  [data-slot="select-list"] {
    min-height: 0;
    overflow-y: auto;
    outline: none;
  }

  [data-slot="select-group"] {
    display: flex;
    flex-direction: column;
  }

  /* The check sits in its own column at the end of each row. */
  :is([data-slot="select-item"], [data-slot="select-select-all"]) {
    position: relative;
    padding-inline-end: 30px;

    &:is([data-selected], [aria-selected="true"]) {
      font-weight: 400;
    }

    &:has(> [data-slot="stack"]) {
      padding-block: var(--space-1);
    }

    & > [data-slot="stack"] {
      gap: 0;
      align-items: flex-start;
    }

    & > [data-slot="hint"] {
      margin-inline-start: auto;
      font-variant-numeric: tabular-nums;
    }
  }

  [data-slot="select-item-indicator"] {
    position: absolute;
    inset-inline-end: 10px;
    display: flex;
    padding: 0;

    & > svg {
      width: 14px;
      height: 14px;
    }
  }

  [data-slot="select-select-all"] {
    & > svg {
      position: absolute;
      inset-inline-end: 10px;
      width: 14px;
      height: 14px;
    }

    &:not([data-checked]) > svg:has(+ svg),
    &:not([data-indeterminate]) > svg + svg {
      display: none;
    }
  }

  [data-slot="select-item-icon"] {
    display: flex;
    color: var(--muted);

    [data-highlighted] > & {
      color: inherit;
    }
  }

  [data-slot="select-item-text"][data-matched] {
    color: var(--muted);

    [data-highlighted] > & {
      color: inherit;
    }

    & :is(mark, b) {
      background: none;
      color: var(--ink);
      font-weight: 600;
    }
  }

  [data-slot="select-input"] {
    box-sizing: border-box;
    flex-shrink: 0;
    width: 100%;
    height: var(--size);
    padding-inline: 10px;
    border: 0;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font: inherit;

    &::placeholder {
      color: var(--muted);
    }

    &:focus-visible {
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  [data-slot="select-content"]
    > [data-slot="row"]:has([data-slot="select-input"]) {
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: var(--space-2);
    height: var(--size);
    padding-inline: 10px;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--muted);

    &:has(:focus-visible) {
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    & [data-slot="select-input"] {
      flex: 1;
      min-width: 0;
      padding: 0;
      border-radius: 0;
      background: transparent;
      box-shadow: none;
      outline: none;
    }
  }

  [data-slot="select-status"] {
    flex-shrink: 0;
    margin-inline: -5px;
    padding: 6px 15px 1px;
    border-top: 1px solid var(--line-faint);
    color: var(--muted);
    font-size: var(--text-xs);

    &:empty {
      display: none;
    }
  }

  /* The clear button sits inside the trigger's end, before the chevron. */
  [data-slot="row"]:has([data-slot="select-clear"]) {
    position: relative;
    flex-wrap: nowrap;

    & [data-slot="select-trigger"] {
      flex: 1;
      padding-inline-end: 8px;
    }

    & [data-slot="select-trigger"] > [data-slot="select-value"] {
      padding-inline-end: 28px;
    }
  }

  [data-slot="select-clear"] {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 32px;
    display: inline-grid;
    place-items: center;
    width: 24px;
    min-width: 0;
    height: 24px;
    margin-block: auto;
    padding: 0;
    border-radius: calc(var(--radius-control) - 3px);
    background: transparent;
    box-shadow: none;
    color: var(--muted);

    &:hover:not([data-disabled], :disabled) {
      background: var(--tint);
      color: var(--ink);
    }

    &:active:not([data-disabled], :disabled) {
      scale: 1;
    }
  }

  [data-slot="select-item"] [data-slot="badge"] {
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;

    [data-selected] > & {
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  [data-slot="select-trigger"] [data-slot="badge"] {
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-inline-start: -4px;
    padding: 0;
    background: var(--ink);
    color: var(--paper);
  }
}

@scope ([data-example]) {
  [data-slot="separator"] {
    flex-shrink: 0;
    border: 0;
    background: var(--line-faint);

    &[data-orientation="horizontal"] {
      width: 100%;
      height: 1px;
    }

    &[data-orientation="vertical"] {
      align-self: stretch;
      width: 1px;
    }
  }

  [data-slot="row"]:has(
    > [data-slot="separator"][data-orientation="horizontal"]
  ) {
    flex-wrap: nowrap;
    gap: var(--space-3);
    width: 20rem;
    max-width: 100%;
    color: var(--muted);
    font-size: var(--text-sm);

    & > [data-slot="separator"] {
      flex: 1;
    }
  }

  [data-slot="row"]:has(
    > [data-slot="separator"][data-orientation="vertical"]
  ) {
    flex-wrap: nowrap;
    align-items: stretch;
    gap: var(--space-4);
  }

  [data-slot="stack"]:has(
    > [data-slot="separator"],
    > [data-slot="row"] > [data-slot="separator"][data-orientation="horizontal"]
  ) {
    align-items: stretch;
    width: 20rem;
    max-width: 100%;

    & > [data-slot="stack"] {
      gap: var(--space-1);
    }
  }

  /* Plan details: each label at the start of its row, its value at the end. */
  :scope[data-example="separator/list"] dd {
    text-align: end;
  }

  /* Profile stats: equal columns, each number over its label. */
  :scope[data-example="separator/menu"] [data-slot="row"] {
    width: 20rem;
    max-width: 100%;

    & > [data-slot="stack"] > :first-child {
      font-size: var(--text-lg);
      font-weight: 600;
      font-variant-numeric: tabular-nums;
    }
  }
}

@scope ([data-example]) {
  [data-slot="slider"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 20rem;
    max-width: 100%;

    &[data-orientation="vertical"] {
      width: auto;
      height: 10rem;
    }

    & > [data-slot="row"] > [data-slot="label"] {
      font-weight: 400;
    }
  }

  :is([data-slot="slider"], [data-slot="field"]:has(> [data-slot="slider"]))
    > [data-slot="row"] {
    justify-content: space-between;
    gap: var(--space-4);
  }

  [data-slot="stack"]:has(> [data-slot="slider"]) {
    align-items: stretch;
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="row"]:has(
    > [data-slot="slider"][data-orientation="vertical"],
    > [data-slot="field"] > [data-slot="slider"][data-orientation="vertical"]
  ) {
    gap: var(--space-8);
  }

  /* A vertical slider's field is as narrow as the slider, with its label centered under it. */
  [data-slot="field"]:has(> [data-slot="slider"][data-orientation="vertical"]) {
    align-items: center;
    width: auto;
  }

  [data-slot="stack"] > form + [data-slot="field"]:has([data-slot="slider"]) {
    padding-top: var(--space-4);
    border-top: 1px solid var(--line-faint);
  }

  [data-slot="slider-value"] {
    color: var(--muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;

    [data-slot="output"] > & {
      display: inline;
    }
  }

  [data-slot="slider-control"] {
    display: flex;
    align-items: center;
    width: 100%;
    height: 20px;
    user-select: none;

    &[data-orientation="vertical"] {
      justify-content: center;
      width: 20px;
      height: 100%;
    }
  }

  /* A 1px rule drawn inside a 2px box, so the 2px range sits centred on it. */
  [data-slot="slider-track"] {
    box-sizing: border-box;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(var(--line), var(--line)) center / 100% 1px
      no-repeat;

    &[data-orientation="vertical"] {
      width: 2px;
      height: 100%;
      background-size: 1px 100%;
    }

    &[data-disabled] {
      background-image: linear-gradient(var(--line-faint), var(--line-faint));
    }
  }

  /* A short line under the track for each step, spread across the thumb's travel. */
  [data-slot="ticks"] {
    display: flex;
    justify-content: space-between;
    height: 5px;
    margin-top: -4px;

    & > span {
      width: 1px;
      background: var(--line);
    }
  }

  [data-slot="slider-indicator"] {
    border-radius: 999px;
    background: var(--ink);

    &[data-disabled] {
      background: var(--line-disabled);
    }
  }

  [data-slot="slider-thumb"] {
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1.5px var(--ink),
      var(--shadow-drop);
    cursor: default;
    transition: box-shadow 0.1s ease-out;

    &:hover:not([data-disabled]) {
      background: var(--tint);
    }

    &[data-dragging] {
      background: var(--tint);
      box-shadow:
        inset 0 0 0 1.5px var(--ink),
        var(--shadow-drop-pressed);
    }

    &:has(:focus-visible) {
      outline: 3px solid var(--halo);
      outline-offset: 2px;
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1.5px var(--line-disabled);
    }
  }

  /* A thumb with a value bubble keeps a lane above the track, so the bubble never covers the label. */
  [data-slot="slider"]:has([data-slot="slider-thumb"] > [data-slot="output"])
    > [data-slot="slider-control"] {
    margin-top: var(--space-6);
  }

  [data-slot="slider-thumb"]
    > :is([data-slot="output"], [data-slot="slider-value"]) {
    position: absolute;
    bottom: calc(100% + var(--space-2));
    inset-inline-start: 50%;
    min-height: 0;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    line-height: 16px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    translate: calc(var(--slider-thumb-position) * -1) 0;

    &:is([dir="rtl"], [dir="rtl"] *) {
      translate: var(--slider-thumb-position) 0;
    }

    [data-slot="slider-thumb"]:is([data-dragging], :has(:focus-visible)) > & {
      opacity: 1;
    }
  }
}

@scope ([data-example]) {
  [data-slot="switch"] {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    box-sizing: border-box;
    width: 38px;
    height: 22px;
    padding: 3px;
    border: 0;
    border-radius: 999px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    cursor: default;
    transition:
      background-color var(--duration),
      box-shadow var(--duration);

    &:hover:not([data-disabled], [data-readonly], [data-checked]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &[data-checked] {
      background: var(--ink);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &:is([data-invalid], [aria-invalid="true"]) {
      box-shadow: inset 0 0 0 1px var(--danger);
    }

    &[data-readonly]:not([data-checked]) {
      background: var(--tint);
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &[data-disabled][data-checked] {
      background: var(--line-disabled);
      box-shadow: inset 0 0 0 1px var(--line-disabled);
    }

    &[data-size="sm"] {
      width: 30px;
      height: 18px;
    }
  }

  [data-slot="switch-thumb"] {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    border-radius: 50%;
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--line),
      0 1px 2px color-mix(in oklab, var(--ink) 10%, transparent);
    color: var(--muted);
    transition: translate var(--duration);

    & > svg {
      width: 10px;
      height: 10px;
      stroke-width: 2.5;
    }

    &[data-checked] {
      translate: 16px 0;
      background: var(--paper);
      box-shadow: var(--shadow-drop);

      &:is([dir="rtl"], [dir="rtl"] *) {
        translate: -16px 0;
      }
    }

    [data-disabled] > & {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    [data-size="sm"] > & {
      width: 12px;
      height: 12px;

      &[data-checked] {
        translate: 12px 0;

        &:is([dir="rtl"], [dir="rtl"] *) {
          translate: -12px 0;
        }
      }
    }
  }

  :is([data-slot="label"], [data-slot="field"]):has(
    [data-slot="switch"][data-disabled]
  ) {
    color: var(--line-disabled);
  }

  /* A switch row: its label at the start and the switch at the end, in a 20rem column. */
  :scope[data-example^="switch/"]
    :is([data-slot="label"], [data-slot="field"], [data-slot="row"]):has(
      > [data-slot="switch"]
    ) {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: var(--space-4);
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
  }

  /* A row with only a label stays compact, so the switch sits close to it; forms keep the full column. */
  :scope[data-example^="switch/"]:not([data-example="switch/form"])
    :is([data-slot="label"], [data-slot="field"], [data-slot="row"]):has(
      > [data-slot="switch"]
    ):not(:has(> [data-slot="stack"], > [data-slot="field-description"])) {
    width: 14rem;
  }

  :scope[data-example^="switch/"]
    [data-slot="stack"]:has(> [data-slot="label"] > [data-slot="switch"]) {
    max-width: 100%;
  }

  :scope[data-example^="switch/"]
    :is([data-slot="field"], [data-slot="row"])
    > [data-slot="stack"]:has(+ [data-slot="switch"]) {
    flex: 1;
    gap: var(--space-1);
  }

  /* A row with a description keeps the switch in line with the label. */
  :scope[data-example^="switch/"]
    :is([data-slot="field"], [data-slot="row"]):has(
      > [data-slot="stack"] + [data-slot="switch"]
    ) {
    align-items: flex-start;
  }

  /* The error's line stays reserved, so Continue never moves as the error shows and hides. */
  :scope[data-example="switch/invalid"]
    [data-slot="field"]:not(:has(> [data-slot="field-error"]))::after {
    content: "\a0";
    font-size: var(--text-sm);
  }

  /* A settings form: its switches, then the actions a step further down. */
  :scope[data-example="switch/form"] form {
    gap: var(--space-6);
  }

  [data-slot="field-set"] > [data-slot="label"]:has(> [data-slot="switch"]) {
    font-weight: 400;
  }

  /* A choice card: the label covers the card, so a click anywhere on it toggles the switch. */
  :scope[data-example="switch/choice-card"] [data-variant="card"] {
    position: relative;

    & [data-slot="field-label"]::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: inherit;
    }

    & > [data-slot="switch"] {
      position: relative;
    }

    &:hover:not(:has([data-checked])) {
      box-shadow: 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }
  }
}

@scope ([data-example]) {
  [data-slot="tabs"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 24rem;
    max-width: 100%;

    &[data-orientation="vertical"] {
      flex-direction: row;
      align-items: flex-start;
      gap: var(--space-2);
    }
  }

  /* A demo with controls above its tabs keeps the tabs' width and still fits a phone. */
  :scope[data-example^="tabs/"] > * > :has(> [data-slot="tabs"]) {
    width: 24rem;
    max-width: 100%;
  }

  /* A list wider than the demo scrolls sideways; the padding keeps focus rings inside it. */
  [data-slot="tabs-list"] {
    position: relative;
    display: flex;
    align-self: flex-start;
    max-width: calc(100% + 6px);
    margin: -3px;
    padding: 3px;
    overflow-x: auto;
    gap: var(--space-1);
    scrollbar-width: none;

    &[data-orientation="vertical"] {
      flex: none;
      flex-direction: column;
      gap: 2px;
    }
  }

  [data-slot="tabs-tab"] {
    position: relative;
    z-index: 1;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: var(--space-2);
    height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    cursor: default;

    &:hover:not([data-disabled]) {
      color: var(--ink);
    }

    &[data-selected] {
      background: var(--surface-1);
      box-shadow:
        inset 0 0 0 1px var(--ink),
        var(--shadow-drop);
      color: var(--ink);
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    &:focus-visible {
      outline-offset: 0;
    }

    &[data-orientation="vertical"] {
      justify-content: flex-start;
      padding-inline: 10px;

      &:hover:not([data-disabled], [data-selected]) {
        background: var(--tint);
      }
    }

    [data-slot="tabs-list"]:has([data-slot="tabs-indicator"])
      > &[data-selected] {
      background: transparent;
      box-shadow: none;
    }

    & > [data-slot="badge"] {
      height: 18px;
      padding-inline: 6px;
      color: var(--muted);
      font-variant-numeric: tabular-nums;
    }
  }

  [data-slot="tabs-tab-icon"] {
    display: flex;
    color: var(--muted);

    [data-selected] > & {
      color: inherit;
    }
  }

  [data-slot="tabs-indicator"] {
    position: absolute;
    top: var(--active-tab-top);
    left: var(--active-tab-left);
    box-sizing: border-box;
    width: var(--active-tab-width);
    height: var(--active-tab-height);
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--ink),
      var(--shadow-drop);
  }

  /* The panel is a framed surface under its list, tall enough for any panel in the demos so switching never jumps. */
  [data-slot="tabs-panel"] {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 6rem;
    padding: var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    color: var(--ink);
    text-wrap: pretty;

    &[data-orientation="vertical"] {
      flex: 1;
      align-self: stretch;
    }

    &[hidden] {
      display: none;
    }

    & > [data-slot="field"],
    & [data-slot="field-control"] {
      width: 100%;
    }
  }

  /* The panels share one framed cell, so they overlap while one slides out and the next slides in. */
  [data-slot="stack"]:has(> [data-slot="tabs-panel"]) {
    display: grid;
    box-sizing: border-box;
    width: 100%;
    min-height: 6rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-surface);
    background: var(--surface-1);

    & > [data-slot="tabs-panel"] {
      grid-area: 1 / 1;
      min-height: 0;
      border: 0;
      border-radius: 0;
      background: none;
    }
  }

  /* The indicator glides in the demos that show it. */
  :scope:is([data-example="tabs/indicator"], [data-example="tabs/animation"]) {
    & [data-slot="tabs-indicator"] {
      transition-property: top, left, width, height;
      transition-duration: calc(var(--duration) * 2);

      &[data-activation-direction="none"] {
        transition: none;
      }
    }
  }

  /* The reply form is the tallest panel, so both panels take its height. */
  :scope[data-example="tabs/keep-mounted"] [data-slot="tabs-panel"] {
    min-height: 9.5rem;
  }

  :scope[data-example="tabs/animation"] {
    & [data-slot="stack"] > [data-slot="tabs-panel"] {
      transition:
        opacity var(--duration),
        translate var(--duration);

      &:is([data-starting-style], [data-ending-style]) {
        opacity: 0;
      }

      &[data-activation-direction="right"][data-starting-style],
      &[data-activation-direction="left"][data-ending-style] {
        translate: 2rem 0;
      }

      &[data-activation-direction="left"][data-starting-style],
      &[data-activation-direction="right"][data-ending-style] {
        translate: -2rem 0;
      }
    }
  }
}

@scope ([data-example]) {
  [data-slot="textarea"] + [data-slot="field-description"] {
    font-variant-numeric: tabular-nums;
  }

  /* A field that holds the growing textarea's maximum height, so its label stays put as it grows. */
  :scope[data-example="textarea/auto-resize"] [data-slot="field"] {
    min-height: calc(12rem + 2.5rem + 2 * var(--space-2));
  }
}

@scope ([data-example]) {
  [data-slot="timeline"] {
    display: flex;
    flex-direction: column;
    width: 22rem;
    max-width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;

    &[data-orientation="horizontal"] {
      flex-direction: row;
      width: auto;
    }

    &[data-busy] {
      opacity: 0.6;
    }
  }

  [data-slot="timeline-item"] {
    position: relative;
    display: grid;
    grid-template-columns: var(--size-icon) 1fr;
    align-content: start;
    column-gap: var(--space-3);
    padding-bottom: var(--space-6);
    border-radius: var(--radius-row);
    outline-offset: var(--space-1);

    & > * {
      grid-column: 2;
    }

    &:last-child,
    &[data-last] {
      padding-bottom: 0;
    }

    [data-orientation="horizontal"] > & {
      grid-template-columns: 1fr;
      row-gap: var(--space-2);
      width: 8rem;
      padding-bottom: 0;
      padding-inline-end: var(--space-4);

      & > * {
        grid-column: 1;
      }
    }
  }

  [data-slot="timeline-marker"] {
    display: grid;
    grid-row: 1;
    grid-column: 1;
    place-items: center;
    align-self: center;
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    border: 2px solid var(--line);
    border-radius: 50%;
    background: var(--paper);
    color: var(--paper);

    & > svg {
      width: 10px;
      height: 10px;
      stroke-width: 3;
    }

    &[data-complete] {
      border-color: var(--ink);
      background: var(--ink);
    }

    &[data-current] {
      border-color: var(--ink);
      box-shadow: 0 0 0 4px var(--halo);
    }

    &[data-upcoming] {
      border-style: dashed;
    }
  }

  [data-slot="timeline-connector"] {
    position: absolute;
    /* In a grid area, an absolute box's offsets start from that area. */
    grid-column: auto;
    top: calc(var(--leading) / 2 + var(--size-icon) / 2 + var(--space-1));
    bottom: var(--space-1);
    inset-inline-start: calc(var(--size-icon) / 2 - 1px);
    width: 2px;
    background: var(--line-faint);

    &[data-complete] {
      background: var(--ink);
    }

    :is(:last-child, [data-last]) > & {
      display: none;
    }

    [data-orientation="horizontal"] > * > & {
      top: calc(var(--size-icon) / 2 - 1px);
      bottom: auto;
      inset-inline: calc(var(--size-icon) + var(--space-1)) var(--space-1);
      width: auto;
      height: 2px;
    }
  }

  [data-slot="timeline-title"] {
    grid-row: 1;
    font-weight: 500;
    line-height: var(--leading);

    [data-orientation="horizontal"] > * > & {
      grid-row: 2;
    }
  }

  [data-slot="timeline-time"] {
    color: var(--muted);
    font-size: var(--text-xs);
  }

  [data-slot="timeline-description"] {
    margin-top: var(--space-1);
    font-size: var(--text-sm);
  }

  [data-slot="timeline-item"] > [data-slot="collapsible-root"] {
    margin-top: var(--space-2);
    width: auto;
  }

  :scope:has([data-slot="timeline"][role="feed"]) {
    justify-content: flex-start;
  }
}

@scope ([data-example]) {
  [data-slot="toast-region"] {
    --dir: -1;
    box-sizing: border-box;
    width: 356px;
    max-width: calc(100vw - 2rem);
    height: var(--toast-front-height);
    margin: var(--space-4);
    padding: 0;
    list-style: none;
    outline: none;

    &[data-side="top"] {
      --dir: 1;
    }

    /* Centered on the page: the default translate already centers it, so a side margin would push it over. */
    &[data-align="center"] {
      margin-inline: 0;
    }

    &[data-expanded] {
      height: calc(
        var(--toast-stack-height) + (var(--toast-count) - 1) * var(--space-3)
      );
    }
  }

  [data-slot="toast"] {
    --y: calc(var(--dir) * var(--toast-index) * var(--space-3));
    position: absolute;
    inset-inline: 0;
    z-index: calc(100 - var(--toast-index));
    display: flex;
    align-items: center;
    gap: var(--space-3);
    box-sizing: border-box;
    overflow: hidden;
    padding: var(--space-4);
    border-radius: var(--radius-popup);
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    height: var(--toast-height);
    font-size: var(--text-md);
    outline-offset: 2px;
    translate: calc(var(--toast-swipe-x, 0px) + var(--exit-x, 0px))
      calc(
        var(--y) + var(--toast-swipe-y, 0px) + var(--exit-y, 0px) *
          var(--slide, 1)
      );
    scale: calc(1 - var(--toast-index) * 0.05);
    transition-property: translate, scale, opacity, height, box-shadow;
    transition-duration: 400ms;
    transition-timing-function: ease;
    -webkit-user-select: none;
    user-select: none;

    /* Covers the content of the toasts behind a collapsed stack, so only the front one reads. */
    &::before {
      content: "";
      position: absolute;
      inset: 0;
      background: inherit;
      opacity: 0;
      pointer-events: none;
      transition: inherit;
    }

    [data-side="bottom"] & {
      bottom: 0;
    }

    [data-side="top"] & {
      top: 0;
    }

    &:not([data-front], [data-expanded]) {
      height: var(--toast-front-height);

      &::before {
        opacity: 1;
      }
    }

    &[data-expanded] {
      --y: calc(
        var(--dir) * (var(--toast-offset) + var(--toast-index) * var(--space-3))
      );
      scale: 1;
      transition-duration: 200ms;
      transition-timing-function: ease-out;
    }

    /* The newest toast slides in from the edge; the ones behind it fade in where they are. */
    &[data-starting-style] {
      transition: none;

      &:not([data-front]) {
        opacity: 0;
      }

      &[data-front] {
        --y: calc(var(--dir) * -100%);
      }
    }

    /* A closing toast slides back out the way it came, or off to the side it was swiped toward. */
    &[data-ending-style] {
      opacity: 0;
      transition-duration: 200ms;
      transition-timing-function: ease-out;

      @media (prefers-reduced-motion: no-preference) {
        --exit-y: calc(var(--dir) * -100%);

        &[data-swipe-direction="left"] {
          --exit-x: -100%;
        }

        &[data-swipe-direction="right"] {
          --exit-x: 100%;
        }
      }

      &:not([data-front], [data-expanded]) {
        --exit-y: 0px;
      }
    }

    &:is([data-swipe-direction="left"], [data-swipe-direction="right"]) {
      --slide: 0;
    }

    &[data-swiping] {
      transition: none;
    }

    @media (prefers-reduced-motion: reduce) {
      transition-property: opacity;
    }

    & > [data-slot="stack"] {
      flex: 1;
      align-items: flex-start;
      gap: 2px;
      min-width: 0;
    }

    /* An icon-only close button, like a dialog's. */
    & [data-slot="toast-close"][aria-label] {
      width: var(--size-sm);
      height: var(--size-sm);
      padding: 0;
      background: transparent;
      box-shadow: none;
      color: var(--muted);

      &:hover {
        background: var(--tint);
        color: var(--ink);
      }
    }

    & > [data-slot="toast-title"] {
      flex: 1;
    }

    & > svg {
      flex-shrink: 0;
      width: var(--size-icon);
      height: var(--size-icon);
      color: var(--muted);
    }

    /* A toast holds one icon per type; the type rules below choose which one shows. */
    & > svg + svg {
      display: block;
    }

    &[data-type="error"] [data-show="error"] {
      color: var(--danger);
    }

    &:not([data-type="success"]) [data-show="success"],
    &:not([data-type="info"]) [data-show="info"],
    &:not([data-type="warning"]) [data-show="warning"],
    &:not([data-type="error"]) [data-show="error"],
    &:not([data-type="loading"]) [data-show="loading"] {
      display: none;
    }

    & [data-show="loading"] {
      animation: example-spin 800ms linear infinite;
    }
  }

  [data-slot="toast-title"] {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 20px;
  }

  [data-slot="toast-description"] {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-sm);
  }

  /* Each select beside its label, one per line, so the controls fit a phone. */
  :scope[data-example="toast/position"] [data-slot="controls"] {
    display: grid;
    grid-template-columns: auto auto;
    gap: var(--space-2) var(--space-3);

    & [data-slot="select-label"] {
      justify-self: end;
    }

    & [data-slot="select-trigger"] {
      min-width: 8rem;
    }
  }

  :scope[data-example="toast/position"]
    [data-slot="stack"]:has(> [data-slot="controls"]) {
    width: auto;
  }

  /* The projects list, with each row's Delete at its end. */
  :scope[data-example="toast/overlay-host"]
    :is([data-slot="list"], [data-slot="controls"]) {
    width: 20rem;
  }

  :scope[data-example="toast/overlay-host"]
    [data-slot="list"]
    > [data-slot="row"] {
    justify-content: space-between;
    padding-inline-end: var(--space-1);
  }
}

@scope ([data-example]) {
  [data-slot="toggle"] {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    box-sizing: border-box;
    min-width: var(--size);
    height: var(--size);
    padding-inline: var(--space-3);
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    box-shadow: none;
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    user-select: none;
    cursor: default;
    transition:
      scale 0.1s ease-out,
      box-shadow 0.1s ease-out,
      background-color 0.12s,
      color 0.12s;

    &:hover:not([data-disabled], [data-pressed]) {
      background: var(--tint);
    }

    &:active:not([data-disabled]) {
      scale: 0.97;
    }

    &[data-pressed] {
      background: var(--ink);
      color: var(--paper);
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    &[data-disabled][data-pressed] {
      background: var(--line-faint);
    }

    &[aria-label]:has(> [data-slot="toggle-icon"]:only-child) {
      width: var(--size);
      padding: 0;
    }

    &:focus-visible {
      position: relative;
      z-index: 1;
    }
  }

  /* A toggle on its own looks like an outline button, and fills in while pressed. */
  [data-slot="toggle"]:not(
    [data-variant="ghost"],
    [data-slot="toggle-group"] *
  ) {
    padding-inline: 14px;
    background: var(--surface-1);
    box-shadow:
      inset 0 0 0 1px var(--ink),
      var(--shadow-drop);

    &:hover:not([data-disabled], [data-pressed]) {
      background: var(--tint);
    }

    &:active:not([data-disabled]) {
      box-shadow:
        inset 0 0 0 1px var(--ink),
        var(--shadow-drop-pressed);
    }

    &[data-pressed] {
      background: var(--ink);
    }

    &[data-disabled] {
      background: var(--surface-1);
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &[data-disabled][data-pressed] {
      background: var(--line-faint);
    }
  }

  [data-slot="toggle-icon"] {
    display: flex;
  }

  [data-pressed] > [data-slot="toggle-icon"][data-variant="fill"] svg {
    fill: currentColor;
  }

  [data-slot="toggle-group"] {
    display: flex;
    gap: 2px;
    width: fit-content;

    &[data-orientation="vertical"] {
      flex-direction: column;
    }

    & [data-slot="toggle"] {
      border-radius: var(--radius-row);
    }
  }

  /* A group outside a toolbar sits on its own track, sized like a menubar or toolbar so it lines up with inputs. */
  [data-slot="toggle-group"]:not([data-slot="toolbar"] *) {
    padding: 3px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    & [data-slot="toggle"] {
      height: var(--size-sm);
      min-width: var(--size-sm);

      /* An icon-only toggle, named by its aria-label, is square. */
      &[aria-label] {
        width: var(--size-sm);
        padding-inline: 0;
      }
    }
  }

  /* Basic: a document's title and details, with its star toggle at the end. */
  :scope[data-example="toggle/basic"] [data-slot="card"] {
    align-items: center;
    width: 20rem;
    max-width: 100%;

    & [data-slot="stack"] {
      flex: 1;
      min-width: 0;
    }
  }
}

@scope ([data-example]) {
  [data-slot="token-input"] {
    width: 20rem;
    max-width: 100%;

    [data-slot="field"] > & {
      width: 100%;
    }
  }

  [data-slot="token-input-editor"] {
    position: relative;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    min-height: 80px;
    padding: var(--space-2) 10px;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    line-height: 24px;

    &:hover:not(:focus-visible, [data-disabled], [data-readonly]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:focus-visible {
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-empty]::before {
      content: attr(aria-placeholder);
      position: absolute;
      color: var(--muted);
      pointer-events: none;
    }

    &[data-readonly] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }

    &[data-disabled] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }

    :is([data-slot="field"], [data-slot="field"] > [data-slot="token-input"])
      > & {
      width: 100%;
    }

    [data-slot="card"] > & {
      width: auto;
      max-width: none;
      min-height: 56px;
      padding: var(--space-3) 14px 0;
      border-radius: 0;
      background: transparent;
      box-shadow: none;
      outline: none;
    }
  }

  /* The prompt card is the field: gray line at rest, ink and halo while typing. */
  [data-slot="card"]:has(> [data-slot="token-input-editor"]) {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 20rem;
    max-width: 100%;
    padding: 0;
    box-shadow: inset 0 0 0 1px var(--line);

    &:hover {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:has(> [data-slot="token-input-editor"]:focus-visible) {
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    & > [data-slot="row"] {
      justify-content: space-between;
      padding: var(--space-2);
    }
  }

  [data-slot="token-input-host"] {
    display: inline-flex;
    vertical-align: bottom;
    white-space: normal;

    & > span:not([data-slot]) {
      display: contents;
    }
  }

  [data-slot="token-input-host"]:has([data-slot="token-input-token"]) {
    display: inline;
  }

  :is(
    [data-slot="token-input-token"],
    [data-slot="token-input-host"]:not(:has([data-slot="token-input-token"]))
  ) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    box-sizing: border-box;
    height: 22px;
    padding-inline: 8px;
    border-radius: calc(var(--radius-control) - 2px);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font-size: var(--text-xs);
    line-height: 20px;
    white-space: nowrap;
    vertical-align: 1px;

    &:has(
      [data-slot="token-input-token-remove"]:not(
        [data-disabled],
        [data-readonly]
      )
    ) {
      padding-inline-end: 3px;
    }

    & > svg {
      width: 14px;
      height: 14px;
      color: var(--muted);
    }

    &[data-token-type="skill"] {
      background: var(--tint);
    }

    &[data-pending] {
      background: var(--tint);
      color: var(--muted);
    }

    &[data-unresolved] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--muted);
    }

    &[data-selected] {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-disabled],
    [data-disabled] > & {
      box-shadow: inset 0 0 0 1px var(--line-faint);
      color: var(--line-disabled);
    }
  }

  [data-slot="token-input-token-remove"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    width: var(--size-icon);
    height: var(--size-icon);
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    cursor: default;
    transition:
      background-color 0.12s,
      color 0.12s;

    &:hover {
      background: var(--tint);
      box-shadow: inset 0 0 0 1px var(--ink);
      color: var(--ink);
    }

    &:is([data-disabled], [data-readonly]) {
      display: none;
    }

    & svg {
      width: 12px;
      height: 12px;
    }
  }
}

@scope ([data-example]) {
  /* The formatting toolbar spans the notes field below it, like an editor's. */
  :scope[data-example="toolbar/controller"]
    [data-slot="stack"]
    > [data-slot="toolbar"] {
    width: 100%;
  }

  /* The zoom toolbar sits near the top, with room below for its open list. */
  :scope[data-example="toolbar/select"] {
    justify-content: flex-start;
    min-height: 16rem;
  }

  [data-slot="toolbar"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    box-sizing: border-box;
    width: fit-content;
    max-width: 100%;
    padding: 3px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);

    &[data-orientation="vertical"] {
      flex-direction: column;
    }

    & :focus-visible {
      position: relative;
      z-index: 1;
      outline-offset: 0;
    }

    &
      :is(
        [data-slot="toolbar-button"],
        [data-slot="toolbar-link"],
        [data-slot="toggle"],
        [data-slot="menu-trigger"],
        [data-slot="select-trigger"]
      ):not(:is([data-slot="menu-content"], [data-slot="select-content"]) *) {
      display: inline-flex;
      flex-shrink: 0;
      align-items: center;
      justify-content: center;
      gap: 6px;
      box-sizing: border-box;
      min-width: var(--size-sm);
      height: var(--size-sm);
      padding-inline: 10px;
      border-radius: var(--radius-row);
      background: transparent;
      box-shadow: none;
      color: var(--ink);
      font-weight: 500;
      text-decoration: none;

      &:is([aria-label], [aria-labelledby]):has(
          > svg:only-child,
          > [data-slot="toggle-icon"]:only-child
        ) {
        width: var(--size-sm);
        padding: 0;
      }

      &:hover:not(:disabled, [data-disabled], [aria-disabled="true"]) {
        background: var(--tint);
      }

      &:active {
        scale: none;
      }

      &:is([data-pressed], [data-open]) {
        background: var(--tint);
        box-shadow: inset 0 0 0 1px var(--ink);
      }

      &:is(:disabled, [data-disabled], [aria-disabled="true"]) {
        background: transparent;
        box-shadow: none;
        color: var(--line-disabled);
      }

      & > svg:last-child:not(:only-child) {
        color: var(--muted);
      }
    }

    & [data-slot="toolbar-link"]:hover {
      text-decoration: underline;
      text-underline-offset: 3px;
    }

    & [data-slot="select-trigger"] {
      justify-content: space-between;
      width: 5.5rem;
      padding-inline: 10px 6px;
      font-variant-numeric: tabular-nums;
    }

    &
      :is([data-slot="toolbar-input"], [data-slot="number-input-group"]):not(
        :focus-visible,
        :has(:focus-visible)
      ) {
      box-shadow: inset 0 0 0 1px var(--line-faint);

      &:hover:not(:disabled, [data-disabled]) {
        box-shadow: inset 0 0 0 1px var(--line);
      }
    }

    & [data-slot="toolbar-input"] {
      width: 9rem;
      height: var(--size-sm);
      border-radius: var(--radius-row);
    }

    & [data-slot="number-input-group"] {
      width: auto;
      height: var(--size-sm);
      padding: 0;
      border-radius: var(--radius-row);

      & [data-slot="number-input-control"] {
        width: 2.5rem;
        flex: none;
      }

      &
        :is(
          [data-slot="number-input-decrement"],
          [data-slot="number-input-increment"]
        ) {
        min-width: 26px;
        height: 26px;
        border-radius: calc(var(--radius-row) - 2px);
      }
    }
  }

  :is(
    [data-slot="toolbar-group"],
    [data-slot="toolbar"] [data-slot="toggle-group"]
  ) {
    display: flex;
    align-items: center;
    gap: 2px;

    &[data-orientation="vertical"] {
      flex-direction: column;
    }
  }

  [data-slot="toolbar-separator"] {
    flex-shrink: 0;
    background: var(--line-faint);

    &[data-orientation="vertical"] {
      width: 1px;
      height: var(--space-4);
      margin-inline: var(--space-1);
    }

    &[data-orientation="horizontal"] {
      width: var(--space-4);
      height: 1px;
      margin-block: var(--space-1);
    }
  }
}

@scope ([data-example]) {
  /* The tooltip grows out of its trigger and fades in, and one that opens at once, in a group, doesn't animate. */
  [data-slot="tooltip-content"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-sizing: border-box;
    width: max-content;
    max-width: min(16rem, var(--available-width));
    padding: 6px 10px;
    border-radius: var(--radius-control);
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    color: var(--ink);
    font-size: var(--text-xs);
    line-height: 16px;
    transform-origin: var(--transform-origin);
    transition:
      opacity 150ms ease-out,
      scale 150ms ease-out;

    &:is([data-starting-style], [data-ending-style]) {
      opacity: 0;
      scale: 0.9;
    }

    &[data-instant] {
      transition: none;
    }

    @media (prefers-reduced-motion: reduce) {
      transition: opacity 150ms ease-out;

      &:is([data-starting-style], [data-ending-style]) {
        scale: none;
      }
    }
  }

  [data-slot="tooltip-shortcut"] {
    margin-inline-start: auto;
  }

  a[data-slot="tooltip-trigger"][data-variant="link"] {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--ink);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: var(--line);
    text-underline-offset: 3px;

    &:hover {
      text-decoration-color: var(--ink);
    }
  }

  [data-slot="row"][role="group"]:has([data-slot="tooltip-trigger"]) {
    gap: var(--space-1);
  }

  [data-slot="grid"]:has([data-level]) {
    display: grid;
    grid-template-columns: repeat(7, var(--space-6));
    gap: var(--space-1);
  }

  [data-slot="tooltip-trigger"][data-level] {
    width: var(--space-6);
    height: var(--space-6);
    padding: 0;
    border-radius: 5px;
    box-shadow: inset 0 0 0 1px var(--line-faint);

    &[data-level="1"] {
      background: color-mix(in oklab, var(--ink) 22%, var(--surface-1));
    }

    &[data-level="2"] {
      background: color-mix(in oklab, var(--ink) 55%, var(--surface-1));
    }

    &[data-level="3"] {
      background: var(--ink);
    }

    &:hover {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &:active {
      scale: none;
    }
  }

  ul:has(> li [data-slot="tooltip-trigger"]) {
    gap: 0;
    box-sizing: border-box;
    width: 16rem;
    max-width: 100%;
    padding: var(--space-1);
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
  }

  ul > li [data-slot="tooltip-trigger"] {
    justify-content: flex-start;
    width: 100%;
    height: auto;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: var(--radius-row);
    background: transparent;
    box-shadow: none;
    font-weight: 400;

    &:hover {
      background: var(--tint);
    }

    &:active {
      scale: none;
      box-shadow: none;
    }

    &:focus-visible {
      outline-offset: -3px;
    }

    & > svg {
      width: 14px;
      height: 14px;
      color: var(--muted);
    }

    & > span {
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  [data-slot="row"]:has(> input):has([data-slot="tooltip-trigger"]) {
    flex-wrap: nowrap;
    width: 20rem;
    max-width: 100%;

    & > input {
      flex: 1;
    }
  }

  [data-slot="row"]:has(> code):has([data-slot="tooltip-trigger"]) > code {
    padding: 6px 10px;
    border-radius: var(--radius-control);
    background: var(--tint);
    font-family: var(--mono);
    font-size: var(--text-sm);
  }

  /* The controls leave room for the tooltip that opens above Export. */
  :scope[data-example="tooltip/controlled"] [data-slot="controls"] {
    margin-bottom: var(--space-8);
  }

  /* The side buttons sit around an empty middle, wide enough for a tooltip that flips into it on a phone. */
  :scope[data-example="tooltip/side"] [data-slot="grid"] {
    grid-template-columns: auto 7rem auto;
    justify-items: center;
    gap: var(--space-2);

    & > :nth-child(1 of :not([data-slot="tooltip-content"])),
    & > :nth-child(4 of :not([data-slot="tooltip-content"])) {
      grid-column: 2;
    }

    & > :nth-child(2 of :not([data-slot="tooltip-content"])) {
      grid-column: 1;
    }

    & > :nth-child(3 of :not([data-slot="tooltip-content"])) {
      grid-column: 3;
    }
  }
}

@scope ([data-example]) {
  /* Trees grow downward as branches open, so the rows above stay put. */
  :scope:has([data-slot="tree"]) {
    justify-content: flex-start;
  }

  [data-slot="tree"] {
    display: flex;
    flex-direction: column;
    gap: 1px;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    padding: 5px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    color: var(--ink);
    font-size: var(--text-md);
  }

  /* A tree under a controls row keeps its width, and narrows with the preview. */
  [data-slot="stack"]:has(> [data-slot="tree"]) {
    width: 20rem;
    max-width: 100%;
  }

  /* Virtualized: the scroller is the panel, and rows sit at their offsets in the tree. */
  [data-slot="scroll"]:has(> [data-slot="tree"]) {
    flex: none;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    height: 288px;
    padding: 5px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    overscroll-behavior: contain;

    & > [data-slot="tree"] {
      display: block;
      position: relative;
      width: auto;
      padding: 0;
      border-radius: 0;
      background: none;
      box-shadow: none;
    }

    & [data-slot="tree-item"] {
      position: absolute;
      inset-inline: 0;
      height: var(--size-item);
      margin: 0;

      & > [data-slot="tree-label"] {
        height: 100%;
      }
    }
  }

  [data-slot="tree-item"] {
    outline: none;

    /* A web label rendered as its child, like a link, sits inside the label element. */
    &:focus-visible > [data-slot="tree-label"],
    &:focus-visible > :not([data-slot]) > [data-slot="tree-label"] {
      box-shadow: inset 0 0 0 1px var(--ink);

      &:not([data-selected], [data-current]) {
        background: var(--tint);
      }
    }
  }

  [data-slot="tree-group"] > [data-slot="tree-item"] {
    margin-top: 1px;
  }

  [data-slot="tree-label"] {
    --tree-indent: calc((var(--tree-level, 1) - 1) * var(--space-4));
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-sizing: border-box;
    min-width: 0;
    height: var(--size-item);
    padding-inline: calc(var(--space-2) + var(--tree-indent)) var(--space-3);
    border-radius: var(--radius-row);
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    cursor: default;
    user-select: none;

    &:not([data-branch]) {
      padding-inline-start: calc(
        var(--space-2) + var(--tree-indent) + var(--size-icon) + var(--space-2)
      );
    }

    &:hover:not([data-disabled], [data-selected], [data-current]) {
      background: color-mix(in oklab, var(--ink) 4%, transparent);
    }

    &:is([data-selected], [data-current]) {
      background: color-mix(in oklab, var(--ink) 8%, transparent);
    }

    &[data-current] {
      font-weight: 500;
    }

    &[data-disabled] {
      color: var(--line-disabled);
    }

    &[data-pending] {
      cursor: progress;
    }

    & > svg {
      flex-shrink: 0;
      width: var(--size-icon);
      height: var(--size-icon);
      color: var(--muted);
    }

    &[data-disabled] > svg {
      color: inherit;
    }

    & > svg + svg,
    &[data-expanded] > svg:has(+ svg) {
      display: none;
    }

    &[data-expanded] > svg + svg {
      display: block;
    }

    & > span:not([data-slot]) {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    &[data-pending] > svg:last-child {
      margin-inline-start: auto;
      animation: tree-spin 1s linear infinite;
    }
  }

  [data-slot="tree-indicator"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    width: var(--size-icon);
    height: var(--size-icon);
    color: var(--muted);

    & > svg {
      width: 14px;
      height: 14px;
    }

    &[data-expanded] {
      rotate: 90deg;
    }

    &:is([dir="rtl"], [dir="rtl"] *) {
      rotate: 180deg;
    }

    &[data-expanded]:is([dir="rtl"], [dir="rtl"] *) {
      rotate: 90deg;
    }

    &[data-disabled] {
      color: inherit;
    }

    &[data-loading] {
      rotate: none;

      & > svg {
        animation: tree-spin 1s linear infinite;
      }
    }

    &[data-failed]:not([data-loading]) {
      rotate: none;
      color: var(--danger);
    }
  }

  :is([data-slot="tree-indicator"], [data-slot="tree-label"]) {
    & > svg[data-show] {
      display: none;
    }

    &[data-loading] > svg[data-show="loading"],
    &[data-failed]:not([data-loading]) > svg[data-show="failed"],
    &:not([data-loading], [data-failed]) > svg[data-show="idle"],
    &[data-pending] > svg[data-show="pending"] {
      display: block;
    }
  }

  [data-slot="tree-checkbox"] {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    box-sizing: border-box;
    width: var(--size-icon);
    height: var(--size-icon);
    border-radius: 4px;
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);

    &:is([data-checked], [data-indeterminate]) {
      background: var(--ink);
      box-shadow: inset 0 0 0 1px var(--ink);

      &::after {
        width: 12px;
        height: 12px;
        background: currentColor;
        content: "";
        mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E")
          center / contain no-repeat;
      }
    }

    &[data-indeterminate]::after {
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
    }

    &[data-disabled] {
      box-shadow: inset 0 0 0 1px var(--line-faint);
    }
  }
}

@keyframes tree-spin {
  to {
    rotate: 360deg;
  }
}

@scope ([data-example]) {
  /* Room below the field for the open list, above the console. */
  :scope:is(
    [data-example="trigger-menu/controlled"],
    [data-example="trigger-menu/controller"]
  ) {
    min-height: 24rem;
  }

  /* Room below the field for the grouped list. */
  :scope[data-example="trigger-menu/custom-items"] {
    min-height: 32rem;
  }

  /* A comment box at the bottom, like a chat composer, with room above it for the list. */
  :scope[data-example="trigger-menu/positioning"] {
    justify-content: flex-end;
  }

  [data-slot="trigger-menu-input"] {
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    min-height: 80px;
    max-height: 12rem;
    padding: var(--space-2) 10px;
    border: 0;
    border-radius: var(--radius-control);
    background: var(--surface-1);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
    font: inherit;
    resize: vertical;

    &::placeholder {
      color: var(--muted);
    }

    &:hover:not(:focus-visible, :disabled, [readonly]) {
      box-shadow: inset 0 0 0 1px
        color-mix(in oklab, var(--ink) 45%, var(--surface-1));
    }

    &:focus-visible {
      outline: 3px solid var(--halo);
      outline-offset: 0;
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &:is(input) {
      min-height: 0;
      height: var(--size);
      padding-block: 0;
    }
  }

  [data-slot="stack"]:has(> [data-slot="trigger-menu-input"]) {
    align-items: stretch;
    width: 20rem;
    max-width: 100%;
  }

  [data-slot="trigger-menu-content"] {
    width: 14rem;
    max-width: calc(100vw - 2rem);
    max-height: min(16rem, var(--available-height));
    scroll-padding-block: 5px;

    &[data-trigger="/"] [data-slot="trigger-menu-item"] {
      font-family: var(--mono);
      font-size: var(--text-sm);
    }
  }

  [data-slot="trigger-menu-item"] {
    & > [data-slot="trigger-menu-item-icon"],
    & > [data-slot="badge"] {
      color: var(--muted);
    }

    & > :is([data-slot="badge"], [data-slot="hint"]) {
      margin-inline-start: auto;
    }

    &[data-highlighted] > [data-slot="trigger-menu-item-icon"] {
      color: inherit;
    }
  }

  [data-slot="trigger-menu-item-icon"] {
    display: flex;

    & svg {
      width: 14px;
      height: 14px;
    }
  }

  [data-slot="trigger-menu-status"],
  [data-slot="trigger-menu-hint"] {
    min-height: var(--leading);
    color: var(--muted);
    font-size: var(--text-sm);
  }

  [data-slot="trigger-menu-hint"] {
    font-variant-numeric: tabular-nums;
  }

  [data-slot="trigger-menu-content"] > [data-slot="trigger-menu-status"] {
    padding: 6px 10px;

    &:empty {
      display: none;
    }
  }
}

@scope ([data-example]) {
  /* Waterfalls grow downward as spans open, so the rows above stay put. */
  :scope:has([data-slot="waterfall"]) {
    justify-content: flex-start;
  }

  [data-slot="waterfall"] {
    display: flex;
    position: relative;
    flex-direction: column;
    box-sizing: border-box;
    width: 36rem;
    max-width: 100%;
    padding: 5px;
    overflow: hidden;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    color: var(--ink);
    font-size: var(--text-md);
  }

  [data-slot="stack"]:has(> [data-slot="waterfall"]) {
    width: 36rem;
    max-width: 100%;
  }

  :is([data-slot="waterfall-header-row"], [data-slot="waterfall-row"]) {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--size-item);
    padding-inline: var(--space-2);
    border-radius: var(--radius-row);
  }

  [data-slot="waterfall-header-row"] {
    color: var(--muted);
    font-size: var(--text-sm);
  }

  [data-slot="waterfall-row"] {
    outline: none;
    cursor: default;
    user-select: none;

    &[hidden] {
      display: none;
    }

    &:hover:not([data-selected]) {
      background: color-mix(in oklab, var(--ink) 4%, transparent);
    }

    &[data-selected] {
      background: color-mix(in oklab, var(--ink) 8%, transparent);
    }

    &:focus-visible {
      box-shadow: inset 0 0 0 1px var(--ink);
    }

    &[data-level="1"] {
      font-weight: 500;
    }
  }

  :is([data-slot="waterfall-column-header"], [data-slot="waterfall-cell"]) {
    flex: none;
    width: 4rem;
  }

  :is(
    [data-slot="waterfall-header-row"] > :first-child,
    [data-slot="waterfall-row-header"]
  ) {
    display: flex;
    flex: 0 1 11rem;
    align-items: center;
    gap: var(--space-1);
    min-width: 6rem;
    overflow: hidden;
    white-space: nowrap;
  }

  [data-slot="waterfall-row-header"] {
    padding-inline-start: calc((var(--waterfall-level) - 1) * var(--space-4));

    &:not([data-branch]) {
      padding-inline-start: calc(
        (var(--waterfall-level) - 1) * var(--space-4) + var(--size-icon) +
          var(--space-1)
      );
    }
  }

  :is(
    [data-slot="waterfall-row-header"],
    [data-slot="waterfall-cell"],
    [data-slot="waterfall-bar"]
  ) {
    align-self: stretch;
    align-content: center;
    border-radius: var(--radius-row);
    outline: none;

    &:focus-visible {
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  [data-slot="waterfall-cell"] {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

  [data-slot="waterfall-indicator"] {
    display: flex;
    color: var(--muted);

    & > svg {
      width: var(--size-icon);
      height: var(--size-icon);
      transition: rotate var(--duration);
    }

    &[data-expanded] > svg {
      rotate: 90deg;
    }

    &:dir(rtl) > svg {
      scale: -1 1;
    }
  }

  /* The bar column and the axis above it share a width, so ticks line up with bars. */
  :is(
    [data-slot="waterfall-header-row"] > :last-child,
    [data-slot="waterfall-bar"]
  ) {
    position: relative;
    flex: 1 1 10rem;
    align-self: stretch;
    min-width: 0;
  }

  [data-slot="waterfall-bar"]::before {
    content: "";
    position: absolute;
    inset-block: 7px;
    inset-inline-start: var(--waterfall-start);
    width: max(var(--waterfall-size), 2px);
    border-radius: 3px;
    background: color-mix(in oklab, var(--accent) 55%, transparent);
  }

  [data-slot="waterfall-row"][data-selected]
    [data-slot="waterfall-bar"]::before {
    background: var(--accent);
  }

  [data-slot="waterfall-axis"] {
    position: relative;
    height: 100%;
    container-type: inline-size;
  }

  /* A narrow axis labels every other tick, or only the first, so labels never meet. */
  @container (width < 16rem) {
    [data-slot="waterfall-tick"]:nth-child(even) {
      color: transparent;
    }
  }

  @container (width < 8rem) {
    [data-slot="waterfall-tick"]:not(:first-child) {
      color: transparent;
    }
  }

  [data-slot="waterfall-tick"] {
    position: absolute;
    inset-block: 0;
    inset-inline-start: var(--waterfall-tick);
    align-content: center;
    padding-inline-start: var(--space-1);
    border-inline-start: 1px solid var(--line-faint);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  /* A mark is a line down every row, with its name at the top. */
  [data-slot="waterfall-mark"] {
    position: absolute;
    top: 0;
    inset-inline-start: var(--waterfall-mark);
    height: 100vh;
    padding-inline-start: var(--space-1);
    border-inline-start: 1px dashed var(--danger);
    color: var(--danger);
    font-size: var(--text-xs);
    white-space: nowrap;
    pointer-events: none;

    &[data-outside] {
      display: none;
    }
  }

  /* Virtualized: the scroller is the panel, and rows sit at their offsets in the waterfall. */
  [data-slot="scroll"]:has(> [data-slot="waterfall"]) {
    flex: none;
    box-sizing: border-box;
    width: 36rem;
    max-width: 100%;
    height: 288px;
    padding: 5px;
    border-radius: var(--radius-surface);
    background: var(--surface-1);
    box-shadow: var(--shadow-1);
    overscroll-behavior: contain;

    & > [data-slot="waterfall"] {
      display: block;
      width: auto;
      padding: 0;
      overflow: visible;
      border-radius: 0;
      background: none;
      box-shadow: none;
    }

    & [data-slot="waterfall-row"] {
      position: absolute;
      inset-inline: 0;
    }
  }
}
