@layer gallery {
  :where([data-gallery="document"]) {
    --gallery-code-comment: #6b7280;
    --gallery-code-keyword: #7c3aed;
    --gallery-code-constant: #0369a1;
    --gallery-code-symbol: #a16207;
    --gallery-code-string: #047857;
    --gallery-code-number: #c2410c;
    --gallery-code-variable: #be123c;
    background: var(--nk-color-canvas);
    color: var(--nk-color-foreground);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family:
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      "Segoe UI",
      sans-serif;
  }

  @media (prefers-color-scheme: dark) {
    :where([data-gallery="document"]:not([data-theme])) {
      --gallery-code-comment: #9ca3af;
      --gallery-code-keyword: #c4b5fd;
      --gallery-code-constant: #7dd3fc;
      --gallery-code-symbol: #fde68a;
      --gallery-code-string: #6ee7b7;
      --gallery-code-number: #fdba74;
      --gallery-code-variable: #fda4af;
    }
  }

  :where([data-gallery="document"][data-theme="dark"]) {
    --gallery-code-comment: #9ca3af;
    --gallery-code-keyword: #c4b5fd;
    --gallery-code-constant: #7dd3fc;
    --gallery-code-symbol: #fde68a;
    --gallery-code-string: #6ee7b7;
    --gallery-code-number: #fdba74;
    --gallery-code-variable: #fda4af;
  }

  :where([data-gallery="body"]) {
    min-height: 100vh;
    margin: 0;
    background: inherit;
    color: inherit;
  }

  :where([data-gallery="brand-row"]) {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
  }

  :where([data-gallery="brand"]) {
    color: inherit;
    font-size: 1.1rem;
    font-weight: 650;
    line-height: 1.1;
    text-decoration: none;
  }

  :where([data-gallery="brand-version"]) {
    flex: none;
    text-decoration: none;
  }

  :where(
    [data-gallery="navigation"] > [data-slot="app-navigation-header"]
  ) {
    padding-inline: calc(var(--nk-space) * 3);
  }

  :where([data-gallery="filter"]) {
    inline-size: 100%;
  }

  :where([data-gallery="theme-switcher"] [data-nk="appearance-picker"]) {
    inline-size: 100%;
  }

  :where([data-gallery="main"]) {
    min-width: 0;
    padding: clamp(1.5rem, 4vw, 4.5rem);
  }

  :where([data-gallery="page"]) {
    display: grid;
    gap: 3rem;
    width: min(100%, 75rem);
    margin-inline: auto;
  }

  :where(
    [data-gallery="page-header"],
    [data-gallery="foundation-header"],
    [data-gallery="component-header"],
    [data-gallery="composition-header"]
  ) > [data-slot="page-header-title"] {
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: -0.04em;
    line-height: 1;
  }

  :where([data-gallery="introduction"]) {
    display: grid;
    gap: 2.5rem;
    max-width: 48rem;
  }

  :where([data-gallery="guide"]) {
    display: grid;
    gap: 2.75rem;
    max-width: 52rem;
  }

  :where([data-gallery="empty"]) {
    margin: 0;
    color: color-mix(in srgb, currentColor 62%, transparent);
  }

  :where([data-gallery="color-scale"]) {
    display: grid;
    gap: 0.75rem;
    min-width: 0;
    margin: 0;
  }

  :where([data-gallery="color-scale"] figcaption) {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
  }

  :where([data-gallery="color-scale"] figcaption code) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: var(--nk-text-xs);
  }

  :where([data-gallery="color-swatches"]) {
    display: grid;
    grid-template-columns: repeat(11, minmax(3rem, 1fr));
    min-width: max-content;
  }

  :where([data-gallery="color-swatch"]) {
    display: grid;
    gap: 0.4rem;
    min-width: 3rem;
    text-align: center;
  }

  :where([data-gallery="color-chip"]) {
    display: block;
    min-height: 4rem;
    background: var(--gallery-color);
    border: var(--nk-border-width) solid color-mix(in oklab, currentColor 16%, transparent);
  }

  :where([data-gallery="color-swatch"] code) {
    font-size: var(--nk-text-xs);
  }

  :where(
    [data-gallery="example"][data-gallery-example="color-poles"]
      [data-gallery="color-swatch"]
  ) {
    min-width: 8rem;
  }

  :where([data-gallery="title-specimen"]) {
    display: grid;
    gap: 0.4rem;
    min-width: 0;
    margin: 0;
  }
  
  :where([data-gallery="title-specimen"] figcaption) {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
  }
  
  :where([data-gallery="title-specimen"] figcaption code),
  :where([data-gallery="title-specimen"] small) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: var(--nk-text-xs);
  }
  
  :where([data-gallery="title-specimen"] [data-gallery="title-specimen-text"]) {
    margin: 0;
    line-height: var(--nk-leading-tight);
  }
  
  :where([data-gallery-title-role="page"] [data-gallery="title-specimen-text"]) {
    font-size: var(--nk-title-page-size);
    font-weight: var(--nk-title-page-weight);
  }
  
  :where([data-gallery-title-role="section"] [data-gallery="title-specimen-text"]) {
    font-size: var(--nk-title-section-size);
    font-weight: var(--nk-title-section-weight);
  }
  
  :where([data-gallery-title-role="surface"] [data-gallery="title-specimen-text"]) {
    font-size: var(--nk-title-surface-size);
    font-weight: var(--nk-title-surface-weight);
  }
  
  :where([data-gallery-title-role="compact"] [data-gallery="title-specimen-text"]) {
    font-size: var(--nk-title-compact-size);
    font-weight: var(--nk-title-compact-weight);
  }
  
  :where([data-gallery="type-chip"]) {
    margin: 0;
    font-family: var(--gallery-type-font, var(--nk-font-sans));
    font-size: var(--gallery-type-size, var(--nk-text-base));
    font-weight: var(--gallery-type-weight, var(--nk-font-weight-normal));
    line-height: var(--gallery-type-leading, var(--nk-leading-normal));
  }

  :where([data-gallery="depth"]) {
    display: grid;
    gap: 0.75rem;
    min-width: 0;
    margin: 0;
  }
  
  :where([data-gallery="depth-chip"]) {
    display: block;
    min-height: 4rem;
    background: var(--nk-color-surface);
    border: var(--nk-border-width) solid var(--nk-color-border);
    border-radius: var(--nk-radius-lg);
    box-shadow: var(--gallery-shadow);
  }
  
  :where([data-gallery="depth"] figcaption) {
    display: grid;
    gap: 0.15rem;
  }
  
  :where([data-gallery="depth"] figcaption code),
  :where([data-gallery="depth"] figcaption small) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: var(--nk-text-xs);
  }

  :where([data-gallery="radius-chip"]) {
    display: block;
    min-height: 4rem;
    background: var(--nk-color-surface);
    border: var(--nk-border-width) solid var(--nk-color-border);
    border-radius: var(--gallery-radius);
  }

  :where([data-gallery="motion-chip"]) {
    display: flex;
    align-items: center;
    min-height: 4rem;
    padding-inline: 0.75rem;
    background: var(--nk-color-surface);
    border: var(--nk-border-width) solid var(--nk-color-border);
    border-radius: var(--nk-radius-lg);
  }

  :where([data-gallery="motion-chip-handle"]) {
    width: 1rem;
    height: 1rem;
    background: var(--nk-color-primary);
    border-radius: var(--nk-radius-full);
    animation: gallery-motion-sweep 1.6s var(--nk-ease) infinite alternate;
    animation-duration: calc(var(--gallery-duration) * 8);
  }

  @keyframes gallery-motion-sweep {
    to {
      translate: min(14rem, 30cqi) 0;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    :where([data-gallery="motion-chip-handle"]) {
      animation: none;
      translate: min(14rem, 30cqi) 0;
    }
  }

  :where([data-gallery="motion-ease"]) {
    display: grid;
    place-items: center;
    min-height: 4rem;
    background: var(--nk-color-surface);
    border: var(--nk-border-width) solid var(--nk-color-border);
    border-radius: var(--nk-radius-lg);
  }

  :where([data-gallery="motion-ease"] code) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: var(--nk-text-xs);
  }

  :where([data-gallery="measure-list"]) {
    display: grid;
    gap: 1.25rem;
    min-width: 0;
  }

  :where([data-gallery="measure"]) {
    display: grid;
    gap: 0.6rem;
    min-width: 0;
  }

  :where([data-gallery="measure-label"]) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
  }

  :where([data-gallery="measure-track"]) {
    display: flex;
    align-items: end;
    min-height: 1rem;
  }

  :where([data-gallery="measure-bar"]) {
    display: block;
    width: var(--gallery-measure);
    min-width: 1px;
    height: 1rem;
    background: var(--nk-color-primary);
    border-radius: var(--nk-radius-xs);
  }

  :where([data-gallery-measure-axis="height"] [data-gallery="measure-track"]) {
    min-height: 4rem;
  }

  :where([data-gallery-measure-axis="height"] [data-gallery="measure-bar"]) {
    width: 8rem;
    height: var(--gallery-measure);
    min-height: 1px;
  }

  :where([data-gallery="section"]) {
    display: grid;
    gap: 1.75rem;
    scroll-margin-block-start: 2rem;
  }

  :where([data-gallery="section"] + [data-gallery="section"]) {
    padding-block-start: 2.5rem;
    border-block-start: 1px solid
      color-mix(in srgb, currentColor 14%, transparent);
  }

  :where([data-gallery="section-header"]) {
    display: grid;
    gap: 0.45rem;
    max-width: 48rem;
  }

  :where([data-gallery="section-header"] > *) {
    margin: 0;
  }

  :where([data-gallery="section-header"] h2) {
    font-size: 1.35rem;
    line-height: 1.25;
    text-wrap: balance;
  }

  :where([data-gallery="section-header"] p) {
    color: color-mix(in srgb, currentColor 68%, transparent);
    line-height: 1.55;
    text-wrap: pretty;
  }

  :where([data-gallery="example"]) {
    display: grid;
    gap: 1rem;
    scroll-margin-block-start: 2rem;
  }

  :where([data-gallery="example"] + [data-gallery="example"]) {
    padding-block-start: 1.5rem;
    border-block-start: 1px solid
      color-mix(in srgb, currentColor 10%, transparent);
  }

  :where([data-gallery="example-header"]) {
    display: grid;
    gap: 0.35rem;
    max-width: 48rem;
  }

  :where([data-gallery="example-header"] > *) {
    margin: 0;
  }

  :where([data-gallery="example-header"] h3) {
    font-size: 1rem;
    line-height: 1.35;
  }

  :where([data-gallery="example-header"] > p) {
    color: color-mix(in srgb, currentColor 65%, transparent);
    font-size: 0.9rem;
    line-height: 1.5;
    text-wrap: pretty;
  }

  :where([data-gallery="reference-sections"]) {
    display: grid;
    gap: 2.5rem;
    max-width: 60rem;
    margin-block-start: 3rem;
    padding-block-start: 2.5rem;
    border-block-start: 1px solid
      color-mix(in srgb, currentColor 20%, transparent);
  }

  :where([data-gallery="reference"]) {
    display: grid;
    gap: 1rem;
    scroll-margin-block-start: 2rem;
  }

  :where([data-gallery="reference-header"]) {
    display: grid;
    gap: 0.35rem;
  }

  :where([data-gallery="reference-header"] > *) {
    margin: 0;
  }

  :where([data-gallery="reference-header"] h2) {
    font-size: 1.2rem;
    line-height: 1.25;
  }

  :where([data-gallery="reference-header"] p) {
    color: color-mix(in srgb, currentColor 68%, transparent);
    line-height: 1.55;
    text-wrap: pretty;
  }

  :where([data-gallery="reference-source"]) {
    font-size: 0.8rem;
  }

  :where([data-gallery-reference="system-rules"]) {
    gap: 0.75rem;
    font-size: 0.875rem;
  }

  :where([data-gallery-reference="system-rules"] [data-gallery="reference-header"] h2) {
    font-size: 1rem;
  }

  :where([data-gallery="reference-details"] summary) {
    cursor: pointer;
    font-weight: 650;
  }

  :where([data-gallery="reference-details"][open] summary) {
    margin-block-end: 0.75rem;
  }

  :where(
    [data-gallery="reference"] ul,
    [data-gallery="reference"] ol
  ) {
    display: grid;
    gap: 0.6rem;
    margin-block: 0;
    padding-inline-start: 1.25rem;
    line-height: 1.6;
  }

  :where([data-gallery="reference-fields"]) {
    display: grid;
    margin-block: 0;
    line-height: 1.6;
  }

  :where([data-gallery="reference-fields"] > div) {
    display: grid;
    gap: 0.3rem;
    padding-block: 0.9rem;
    border-block-start: 1px solid
      color-mix(in srgb, currentColor 12%, transparent);
  }

  :where([data-gallery="reference-fields"] dt) {
    font-weight: 650;
  }

  :where([data-gallery="reference-fields"] dd) {
    min-width: 0;
    margin: 0;
    color: color-mix(in srgb, currentColor 82%, transparent);
  }

  :where([data-gallery="contract-options"]) {
    gap: 0.35rem;
  }

  @media (min-width: 48rem) {
    :where([data-gallery="reference-fields"] > div) {
      grid-template-columns: minmax(10rem, 0.4fr) minmax(0, 1fr);
      gap: 1.5rem;
    }
  }

  :where([data-gallery="reference-pattern"]) {
    display: grid;
    gap: 0.5rem;
  }

  :where([data-gallery="reference-pattern"] + [data-gallery="reference-pattern"]) {
    margin-block-start: 1.25rem;
  }

  :where([data-gallery="reference-pattern"] h3) {
    margin: 0;
    font-size: 1rem;
  }

  :where([data-gallery="reference"] code) {
    overflow-wrap: anywhere;
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
  }

  :where([data-gallery="command-palette-dialog-preview"]) {
    inline-size: min(100%, 32rem);
  }

  :where(
    [data-gallery="command-palette-dialog-preview"]
      > [data-slot="command-palette-panel"]
  ) {
    position: static;
    inset: auto;
    margin: 0;
  }

  :where([data-gallery="command-palette-preview-input"]) {
    flex: 1 1 auto;
    min-inline-size: 0;
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: 0.9rem;
  }

  :where([data-gallery="notes"]) {
    display: grid;
    gap: 0.3rem;
    margin: 0.25rem 0 0;
    color: color-mix(in srgb, currentColor 65%, transparent);
    font-size: 0.8rem;
  }

  :where([data-gallery="notes"] > div) {
    display: grid;
    grid-template-columns: 4rem minmax(0, 1fr);
    gap: 0.5rem;
  }

  :where([data-gallery="notes"] dt) {
    font-weight: 650;
  }

  :where([data-gallery="notes"] dd) {
    min-width: 0;
    margin: 0;
  }

  :where([data-gallery="notes"] code) {
    overflow-wrap: anywhere;
    color: inherit;
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  }

  :where([data-gallery="example-tabs"]) {
    min-width: 0;
  }

  :where([data-gallery="responsive-preview"]) {
    min-width: 0;
  }

  :where([data-gallery="preview-toolbar"]) {
    margin-block-end: 0.75rem;
  }

  :where([data-gallery="preview-measurement"] strong) {
    font-size: 0.75rem;
  }

  :where([data-gallery="preview-measurement"] output) {
    min-inline-size: 10rem;
    color: color-mix(in srgb, currentColor 68%, transparent);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
  }

  :where([data-gallery="preview-controls"] input[type="range"]) {
    inline-size: min(14rem, 36vw);
  }

  :where([data-gallery="preview-track"]) {
    position: relative;
    min-width: 0;
  }

  /* `--gallery-preview-width` is the emulated viewport width, so the divider
     border has to sit outside it rather than eat a pixel of the iframe. */
  :where([data-gallery="preview-frame"]) {
    box-sizing: content-box;
    min-width: 0;
    max-inline-size: 100%;
    inline-size: min(100%, var(--gallery-preview-width, 100%));
    border-inline-end: 1px solid
      color-mix(in srgb, currentColor 28%, transparent);
  }

  :where(
    [data-gallery="responsive-preview"][data-gallery-preview-mode="constrained"]
      [data-gallery="preview-frame"]
  ) {
    inline-size: min(100%, var(--gallery-preview-width, 40rem));
  }

  :where([data-gallery="preview-iframe"]) {
    display: block;
    inline-size: 100%;
    min-block-size: 12rem;
    block-size: 20rem;
    box-sizing: border-box;
    border: 0;
    background: var(--nk-color-canvas);
  }

  :where([data-gallery="preview-handle"]) {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: calc(
      min(100%, var(--gallery-preview-width, 100%)) - 1.375rem
    );
    display: grid;
    inline-size: 2.75rem;
    block-size: 3.5rem;
    place-items: center;
    box-sizing: border-box;
    border: 1px solid color-mix(in srgb, currentColor 24%, transparent);
    border-radius: var(--nk-radius-sm);
    color: inherit;
    background: var(--nk-color-canvas);
    cursor: ew-resize;
    touch-action: none;
    transform: translateY(-50%);
  }

  :where([data-gallery="preview-handle"]::before) {
    width: 0.2rem;
    height: 1.5rem;
    border-inline: 1px solid currentColor;
    content: "";
    opacity: 0.55;
  }

  :where([data-gallery="preview-handle"]:focus-visible) {
    outline: 2px solid var(--nk-color-primary);
    outline-offset: 2px;
  }

  :where([data-gallery="preview-body"]) {
    min-width: 0;
    margin: 0;
    padding: 1rem;
    background: var(--nk-color-canvas);
    color: var(--nk-color-foreground);
  }

  :where([data-gallery="preview-body"] > [data-gallery="example"]) {
    width: 100%;
    margin: 0;
  }

  :where(
    [data-gallery="example-tabs"] > [data-slot="tabs-panel"]
  ) {
    min-width: 0;
  }

  :where([data-gallery="code-sample"]) {
    min-width: 0;
    overflow: hidden;
    color: inherit;
    background: color-mix(in srgb, currentColor 3%, transparent);
  }

  :where([data-gallery="code-toolbar"]) {
    padding: 0.65rem 0.8rem;
    border-block-end: 1px solid
      color-mix(in srgb, currentColor 12%, transparent);
  }

  :where([data-gallery="code-toolbar"] strong) {
    flex: none;
    font-size: 0.75rem;
  }

  :where([data-gallery="code-path"]) {
    min-width: 0;
    overflow: hidden;
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :where([data-gallery-code-status]) {
    min-inline-size: 7.5rem;
    color: color-mix(in srgb, currentColor 68%, transparent);
    font-size: 0.75rem;
    text-align: end;
    white-space: nowrap;
  }

  :where([data-gallery="code-sample"][data-gallery-code-state="copied"])
    :where([data-gallery-code-status]) {
    color: var(--nk-color-success-content);
  }

  :where([data-gallery="code-sample"][data-gallery-code-state="error"])
    :where([data-gallery-code-status]) {
    color: var(--nk-color-destructive-content);
  }

  :where([data-gallery="code-source"]) {
    max-height: 32rem;
    margin: 0;
    overflow: auto;
    padding: 1rem;
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.65;
    font-variant-ligatures: none;
    tab-size: 2;
  }

  :where([data-gallery="code-source"] > code) {
    display: block;
    width: max-content;
    min-width: 100%;
  }

  :where([data-gallery-token="comment"]) {
    color: var(--gallery-code-comment);
    font-style: italic;
  }

  :where([data-gallery-token="keyword"]) {
    color: var(--gallery-code-keyword);
    font-weight: 650;
  }

  :where([data-gallery-token="constant"]) {
    color: var(--gallery-code-constant);
  }

  :where([data-gallery-token="symbol"]) {
    color: var(--gallery-code-symbol);
  }

  :where([data-gallery-token="string"]) {
    color: var(--gallery-code-string);
  }

  :where([data-gallery-token="number"]) {
    color: var(--gallery-code-number);
  }

  :where([data-gallery-token="variable"]) {
    color: var(--gallery-code-variable);
  }

  :where([data-gallery="example-canvas"]) {
    min-width: 0;
  }

  :where([data-gallery-navigation-preview]) {
    inline-size: min(100%, 19rem);
    min-block-size: 18rem;
    max-block-size: 32rem;
    background: var(--nk-app-shell-sidebar-background);
  }

  :where([data-gallery-shell-preview]) {
    --nk-app-shell-sidebar-width: 13rem;
    --nk-app-shell-topbar-height: 3rem;

    inline-size: 100%;
    block-size: 32rem;
    min-block-size: 32rem;
    overflow: clip;
  }

  :where(
    [data-gallery-shell-preview] > [data-slot="app-shell-sidebar"]
  ) {
    block-size: 100%;
  }

  :where([data-gallery-shell-preview] > [data-slot="app-shell-main"]) {
    overflow: auto;
    overscroll-behavior: contain;
  }

  :where([data-gallery="app-shell-main"]) {
    min-block-size: 100%;
    padding: 1.5rem;
  }

  :where(
    [data-gallery="example"][data-gallery-mode="constrained"]
      [data-gallery="example-canvas"]
  ) {
    width: min(100%, 40rem);
  }

  :where(
    [data-gallery="example"][data-gallery-mode="full-width"]
      [data-gallery="example-canvas"]
  ) {
    width: 100%;
  }

  :where(
    [data-gallery="example"][data-gallery-layout="stack"]
      [data-gallery="example-canvas"]
  ) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  /* Stack canvases stretch broad children like PageHeader and Field.
     Intrinsic atoms keep their own width, matching the layout-sizing
     taxonomy, including triggers that join the canvas flex through a
     display: contents overlay root. */
  :where(
    [data-gallery="example"][data-gallery-layout="stack"]
      [data-gallery="example-canvas"]
      > :is(
        [data-nk="button"],
        [data-nk="button-group"],
        [data-nk="badge"],
        [data-nk="avatar"],
        [data-nk="avatar-stack"],
        [data-nk="switch"]
      ),
    [data-gallery="example"][data-gallery-layout="stack"]
      [data-gallery="example-canvas"]
      > :is([data-nk="dialog"], [data-nk="sheet"], [data-nk="button-to"])
      > [data-nk="button"]
  ) {
    align-self: flex-start;
  }

  :where(
    [data-gallery="example"][data-gallery-layout="row"]
      [data-gallery="example-canvas"]
  ) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
  }

  :where(
    [data-gallery="example"][data-gallery-layout="matrix"]
      [data-gallery="example-canvas"]
  ) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr));
    align-items: start;
    gap: 1.25rem;
  }

  /* Compact matrices survey many small samples at once. Inside the 40rem
     constrained canvas the 20rem boundary-state tracks fit only one column,
     so dense grids such as the badge color matrix keep the narrow tracks. */
  :where(
    [data-gallery="example"][data-gallery-layout="matrix"][data-gallery-density="compact"]
      [data-gallery="example-canvas"]
  ) {
    grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr));
  }

  :where(
    [data-gallery="example"][data-gallery-density="compact"]
      [data-gallery="example-canvas"]
  ) {
    gap: 0.75rem;
  }

  /* Badge-only grids demonstrate track counts without making Badge look like
     a full-width component. Grid's stretch default remains unchanged. */
  :where(
    #gallery-grid-breakpoints,
    [id^="gallery-grid-cols-"]
  ) {
    justify-items: start;
  }

  /* The canvas is the parent that owns available width: cap previews at the
     canvas so component-owned pressure behavior (scrolling groups,
     truncating labels, wrapping toolbars) engages instead of content
     painting over neighbouring samples or the page gutter. */
  :where(
    [data-gallery="example-canvas"] > *,
    [data-gallery="sample-content"] > *
  ) {
    max-inline-size: 100%;
  }

  /* Deliberate horizontal-pressure demos scroll inside their own canvas
     or sample cell instead of stretching the page. */
  :where(
    [data-gallery="example"][data-gallery-scroll="true"]
      :is([data-gallery="example-canvas"], [data-gallery="sample-content"])
  ) {
    overflow-x: auto;
  }

  /* Toast regions position their list at the viewport corner. Previews keep
     the list in flow so every example is visible inside its own canvas
     rather than stacking at the bottom-right of the screen. */
  :where(
    [data-gallery="example-canvas"] [data-nk="toast"] > [data-slot="toast-list"]
  ) {
    position: static;
    inline-size: min(26rem, 100%);
  }

  :where([data-gallery="sample"]) {
    display: grid;
    align-content: start;
    gap: 0.7rem;
    min-width: 0;
    margin: 0;
  }

  :where([data-gallery="sample"] figcaption) {
    display: grid;
    gap: 0.15rem;
    line-height: 1.35;
  }

  :where([data-gallery="sample"] figcaption strong) {
    font-size: 0.85rem;
    font-weight: 650;
  }

  :where([data-gallery="sample"] figcaption small) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: 0.75rem;
  }

  :where([data-gallery="sample-content"]) {
    min-width: 0;
  }

  :where([data-gallery="composition-header"]) {
    max-width: 54rem;
  }

  :where([data-gallery="composition-states"]) {
    margin-block-start: 0.5rem;
  }

  :where([data-gallery="composition-surface"][data-gallery-mobile="true"]) {
    width: min(100%, 20rem);
  }

  :where([data-gallery="composition-surface"] turbo-frame) {
    display: block;
  }

  :where([data-gallery="composition-surface"] form) {
    display: grid;
    gap: 1.25rem;
  }

  :where([data-gallery="composition-surface"] form > a) {
    color: inherit;
    font-size: 0.875rem;
    text-underline-offset: 0.2em;
  }

  :where([data-gallery="composition-progress"]) {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 0;
    color: color-mix(in srgb, currentColor 58%, transparent);
    font-size: 0.75rem;
    list-style: none;
  }

  :where(
    [data-gallery="composition-progress"] li[aria-current="step"],
    [data-gallery="composition-progress"] li[data-complete="true"]
  ) {
    color: inherit;
    font-weight: 700;
  }

  :where([data-gallery="composition-summary"]) {
    display: grid;
    grid-template-columns: minmax(7rem, auto) minmax(0, 1fr);
    gap: 0.6rem 1rem;
    margin: 1rem 0;
  }

  :where([data-gallery="composition-summary"] dt) {
    color: color-mix(in srgb, currentColor 62%, transparent);
    font-size: 0.875rem;
    font-weight: 650;
  }

  :where([data-gallery="composition-summary"] dd) {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
  }

  @media (max-width: 48rem) {
    :where([data-gallery-code-status]) {
      min-inline-size: 0;
    }

    :where([data-gallery="composition-progress"]) {
      grid-template-columns: minmax(0, 1fr);
    }

    :where([data-gallery="composition-summary"]) {
      grid-template-columns: minmax(0, 1fr);
      gap: 0.2rem;
    }

    :where([data-gallery="composition-summary"] dd + dt) {
      margin-block-start: 0.6rem;
    }
  }
}
