/*
 * Docs site layout. Loaded after css/domestic.css, unlayered, so it wins
 * where it needs to. It uses only semantic --dui-* tokens, the layout
 * primitives and components, like any consumer would; the base layer
 * provides the look, focus styles, color-scheme and forced-colors handling.
 */

/*
 * The docs opt into the optional self-hosted Inter (css/fonts/inter.css,
 * linked by the page template). css/domestic.css alone makes no font
 * requests; the system stack stays the fallback.
 */
:root {
  --dui-font-body: inter, system-ui, sans-serif;
}

/*
 * Cross-document view transitions: moving between docs pages cross-fades
 * main while the app bar and the Docs sidebar stay in place. CSS only; a
 * browser without support navigates as before. The motion tokens set the
 * duration and easing, so data-motion="none" on the root element gives 0s,
 * and prefers-reduced-motion turns it off (WCAG 2.3.3).
 * https://www.w3.org/TR/css-view-transitions-2/
 * https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@view-transition
 * https://www.w3.org/WAI/WCAG22/Understanding/animation-from-interactions.html
 */
@view-transition {
  navigation: auto;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

.docs-shell > header {
  view-transition-name: docs-header;
}

#docs-nav {
  view-transition-name: docs-nav;
}

::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
  animation-duration: var(--dui-motion-duration-normal);
  animation-timing-function: var(--dui-motion-easing-standard);
}

/* Docs nav rows: muted, no underline; the current page is the filled pill (nav.css). */
.docs-shell [data-nav] a:hover {
  text-decoration-line: none;
}

/*
 * Prose links keep their underline (WCAG 1.4.1) in a softer color, full
 * strength on hover.
 */
.docs-content :is(p, li, dd, td, figcaption) a:not([data-button]) {
  text-decoration-color: color-mix(in oklab, currentcolor var(--dui-border-tint-amount), transparent);
}

.docs-content :is(p, li, dd, td, figcaption) a:not([data-button]):hover {
  text-decoration-color: currentcolor;
}

/* Code blocks: on the raised surface with a hairline. */
.docs-content pre {
  background-color: var(--dui-color-surface-raised);
}

/* Home hero: the value, one primary action, then live renders of three snippets. */
.docs-hero > * + * {
  margin-block-start: var(--dui-space-m);
}

.docs-hero-lead {
  font-size: var(--dui-step-1);
  line-height: var(--dui-line-height-snug);
  text-wrap: balance;
}

.docs-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--dui-space-xs);
}

.docs-hero-preview {
  display: grid;
  gap: var(--dui-space-s);
}

/*
 * The frame is the app shell (css/layout/app-shell.css, <dui-app-shell>):
 * app bar, Docs sidebar, main, "On this page" and footer. The 64rem
 * container queries below are app-shell.css's auxiliary-sidebar breakpoint
 * (a container query cannot read a custom property).
 */
.docs-name {
  color: var(--dui-color-text);
  font-weight: var(--dui-font-weight-heading);
  text-decoration-line: none;
}

/* The theme menu (shown by site.js): a labelled native select, before GitHub at the end of the app bar. */
.docs-theme {
  display: flex;
  align-items: center;
  gap: var(--dui-space-xs);
  margin-inline-start: auto;
  color: var(--dui-color-text-muted);
  font-size: var(--dui-font-size-ui);
}

.docs-theme label {
  font-weight: var(--dui-font-weight-body);
}

/*
 * Narrow app bars: the label is visually hidden (it still names the
 * select), so the app bar keeps one row at 320px (WCAG 1.4.10). Same
 * clipping as css/utilities/visually-hidden.css.
 */
@container dui-app-shell (inline-size < 30rem) {
  .docs-theme label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/*
 * The select sits in the app bar row: no stacked-label gap, and no block
 * padding beyond its control height, so the bar keeps one height in every
 * engine (WebKit draws a select taller than its padding box otherwise).
 */
.docs-theme select {
  inline-size: auto;
  margin-block-start: 0;
  padding-block: 0;
}

.docs-github {
  margin-inline-start: auto;
}

.docs-theme:not([hidden]) + .docs-github {
  margin-inline-start: 0;
}

/*
 * Search (shown by site.js): the button opens the search dialog. It starts
 * the end group of the app bar, so the theme menu after it drops its auto
 * margin. Narrow app bars show the icon alone; the text stays as its
 * accessible name (same clipping as css/utilities/visually-hidden.css).
 */
.docs-search {
  margin-inline-start: auto;
}

.docs-search:not([hidden]) ~ .docs-theme {
  margin-inline-start: 0;
}

.docs-search > button {
  color: var(--dui-color-text-muted);
}

/* The shortcut hint: wide app bars only, so narrow ones keep one row (WCAG 1.4.10). */
.docs-search-kbd {
  margin-inline-start: var(--dui-space-xs);
  font-size: var(--dui-step--1);
}

@container dui-app-shell (inline-size < 64rem) {
  .docs-search-kbd {
    display: none;
  }
}

@container dui-app-shell (inline-size < 30rem) {
  /* The icon-only square of data-button="icon" (button.css). */
  .docs-search > button {
    padding: 0;
  }

  .docs-search-label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/*
 * The search dialog: a command palette. Near the top of the viewport, so
 * the list has room to grow under the field, and the list is in the flow of
 * the dialog (not the absolutely positioned popup of combobox.css), so the
 * dialog's own scrolling never clips it.
 */
.docs-search-dialog {
  margin-block-start: min(12vh, var(--dui-space-3xl));
}

/* The title row: dialog.css's header layout, on a <div> (see site/lib/templates.mjs). */
.docs-search-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--dui-space-m);
}

.docs-search-head > * {
  margin-block: 0;
}

.docs-search-head > h2 {
  font-size: var(--dui-step-2);
}

.docs-search-dialog dui-combobox > [role="listbox"] {
  position: static;
  max-block-size: min(50vh, calc(var(--dui-size-row) * 10));
  box-shadow: none;
  border-color: var(--dui-color-border);
}

.docs-search-message {
  color: var(--dui-color-text-muted);
  font-size: var(--dui-font-size-ui);
}

.docs-search-message:empty {
  display: none;
}

/* Themes page: the preview's radio group, one row. */
.docs-theme-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--dui-space-xs) var(--dui-space-m);
}

/* Skip link: hidden by .visually-hidden until focused, then pinned top-left. */
.skip-link:focus {
  position: absolute;
  inset-block-start: var(--dui-space-s);
  inset-inline-start: var(--dui-space-s);
  z-index: 1;
  padding: var(--dui-space-xs) var(--dui-space-s);
  background-color: var(--dui-color-surface);
  border: var(--dui-border-width) solid var(--dui-color-border-control);
  border-radius: var(--dui-radius-control);
}

.docs-nav-note {
  color: var(--dui-color-text-muted);
  font-size: var(--dui-step--1);
  font-weight: var(--dui-font-weight-body);
}

/* One content column: prose, tables, code and live frames share one right edge. */
.docs-content {
  max-inline-size: var(--dui-measure);
}

/* Token pages: the tables are the content and take all of main ("On this page" is left out). */
.docs-content[data-wide] {
  max-inline-size: none;
}

/* "On this page": a small uppercase label over a plain list of muted in-page links. */
.docs-toc > h2 {
  font-family: var(--dui-font-heading);
  color: var(--dui-color-text-muted);
  font-size: var(--dui-font-size-ui);
  font-weight: var(--dui-font-weight-strong);
  letter-spacing: normal;
  text-transform: uppercase;
}

.docs-toc a {
  color: var(--dui-color-text-muted);
  font-size: var(--dui-font-size-ui);
  text-decoration-line: none;
}

.docs-toc a:hover {
  color: var(--dui-color-text);
  text-decoration-line: underline;
}

.docs-toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.docs-toc li + li {
  margin-block-start: var(--dui-space-2xs);
}

/*
 * Narrow shells: the section links leave the app bar (the sidebar, a
 * drawer from the Menu button, links every page) and "On this page" is
 * left out (its links are the h2s just below).
 */
@container dui-app-shell (inline-size < 64rem) {
  .docs-sections,
  .docs-toc {
    display: none;
  }
}

/*
 * The page footer ends main (app-shell.css scrolls main inside its panel,
 * so a footer outside it would stay on screen): previous and next, then
 * the small print. Previous and next sit at the two ends of the row.
 */
.docs-footer {
  max-inline-size: var(--dui-measure);
  margin-block-start: var(--dui-space-2xl);
  padding-block-start: var(--dui-space-m);
  border-block-start: var(--dui-border-width) solid var(--dui-color-border);
  color: var(--dui-color-text-muted);
}

.docs-footer > [data-pagination] {
  max-inline-size: var(--dui-measure);
  margin-block-end: var(--dui-space-l);
}

.docs-footer > [data-pagination] > ul {
  justify-content: space-between;
}

/*
 * Reflow at 320 CSS pixels (WCAG 1.4.10). Long words and URLs in prose,
 * cells and headings break only where they would overflow (break-word
 * keeps the min-content width, so table columns keep their words whole).
 * The base layer lets links in running text break anywhere and handles
 * inline code (css/base/typography.css); in the docs links keep whole
 * words in prose and headings. In tables
 * (all inside data-scroll="inline" regions) the base layer already keeps
 * whole tokens. Code blocks follow the base layer: they wrap, or scroll
 * as pre[data-scroll~="inline"] with tabindex="0" and a name.
 */
main :is(p, li, dt, dd, td, th, caption, h1, h2, h3, h4) {
  overflow-wrap: break-word;
}

main :is(p, li, dt, dd, h1, h2, h3, h4) a {
  overflow-wrap: break-word;
}

/*
 * The first column of a table names an attribute, token or key: kept on
 * one line where there is room (the table scrolls in its region instead);
 * on narrow screens it wraps, so the Effect column stays in view.
 */
@media (min-width: 30em) {
  main th[scope="row"] code {
    white-space: nowrap;
  }
}

/*
 * Header diagrams (site/assets/diagrams/, site/README.md "Diagrams"): the
 * width of the content column up to 28rem (448×252 at 16px), at its start
 * edge, scaled down with it. currentColor in the files is the muted text
 * colour; everything else is a token.
 */
.docs-diagram {
  margin-inline: 0;
  color: var(--dui-color-text-muted);
}

.docs-diagram svg {
  display: block;
  inline-size: 100%;
  max-inline-size: 28rem;
  block-size: auto;
}

/*
 * Forced colors: system colours by the files' presentation attributes
 * (CSS beats them; no file changes). Lines, outlines and text bars are
 * CanvasText at full opacity; frame, panel and tint fills Canvas; the
 * element's stroke and solid fill Highlight, with HighlightText bars on a
 * solid fill and Highlight bars on its tint. The backdrop stays a veil.
 */
@media (forced-colors: active) {
  .docs-diagram svg {
    forced-color-adjust: none;
  }

  .docs-diagram svg * {
    fill-opacity: 1;
    stroke-opacity: 1;
  }

  .docs-diagram svg :is([stroke="currentColor"], [stroke="var(--dui-color-border)"]) {
    stroke: CanvasText;
  }

  .docs-diagram svg [fill="currentColor"] {
    fill: CanvasText;
  }

  .docs-diagram svg :is([fill="var(--dui-color-surface)"], [fill="var(--dui-color-accent-surface)"]) {
    fill: Canvas;
  }

  .docs-diagram svg :is([fill="var(--dui-color-backdrop)"], [fill="var(--dui-color-backdrop)"] *) {
    fill: Canvas;
    fill-opacity: 0.7;
  }

  .docs-diagram svg [stroke^="var(--dui-color-accent"] {
    stroke: Highlight;
  }

  .docs-diagram svg [fill="var(--dui-color-accent)"] {
    fill: Highlight;
  }

  .docs-diagram svg [fill="var(--dui-color-accent)"] > [fill="var(--dui-color-surface)"] {
    fill: HighlightText;
  }
}

/*
 * Live examples: one frame per snippet, of its render page (live/, with the
 * real CSS). This height holds without JavaScript; site.js fits
 * each frame to its content. Frames that open dialogs, popovers or toasts
 * keep room for them.
 */
.example-frame {
  display: block;
  inline-size: 100%;
  block-size: 14rem;
  border: var(--dui-border-width) solid var(--dui-color-border);
  border-radius: var(--dui-radius-surface);
}

.example-frame[data-tall] {
  min-block-size: 28rem;
}

/* Token filter (shown by site.js). */
.token-filter input {
  display: block;
  inline-size: 100%;
  max-inline-size: calc(var(--dui-size-column-min) * 1.5);
}

.token-filter > * + * {
  margin-block-start: var(--dui-space-2xs);
}

.token-filter-status:empty {
  display: none;
}

/*
 * Token tables keep their words whole and scroll in their region instead.
 * Token names never break.
 */
.token-table :is(td, th) {
  overflow-wrap: normal;
  vertical-align: top;
}

.token-table th[scope="row"] code,
.token-word {
  white-space: nowrap;
}

/*
 * The description is the last column: on a narrow screen the table
 * squeezed it to a word a line, making every row hundreds of pixels tall.
 * Give it room for a short line; the table scrolls in its region instead.
 */
.token-table td:last-child {
  min-inline-size: var(--dui-size-column-min);
}

.token-missing {
  color: var(--dui-color-text-muted);
  font-style: italic;
}

/*
 * Previews. Decorative (aria-hidden): the Light and Dark cells of the row
 * hold the values as text. Each sample sits in a data-color-scheme scope, so the
 * dark one is shown on the dark surface whatever the page scheme. --preview
 * holds the resolved value, never var(), so the dark value is literal too.
 */
.token-sample {
  display: flex;
  align-items: center;
  gap: var(--dui-space-xs);
  padding: var(--dui-space-2xs) var(--dui-space-xs);
  border-radius: var(--dui-radius-control);
}

td > .token-sample + .token-sample {
  margin-block-start: var(--dui-space-2xs);
}

.token-sample > [aria-hidden] {
  flex: none;
}

.token-chip,
.token-preview:is([data-preview="radius"], [data-preview="border-width"], [data-preview="shadow"]) {
  display: block;
  inline-size: var(--dui-size-target);
  block-size: var(--dui-size-target);
  border: var(--dui-border-width) solid var(--dui-color-border-control);
  forced-color-adjust: none;
}

.token-chip {
  background-color: var(--preview);
  border-radius: var(--dui-radius-control);
}

.token-preview[data-preview="radius"] {
  background-color: var(--dui-color-surface-sunken);
  border-radius: var(--preview);
}

.token-preview[data-preview="border-width"] {
  border-width: var(--preview);
  border-color: var(--dui-color-text);
}

.token-preview[data-preview="shadow"] {
  margin: var(--dui-space-2xs);
  background-color: var(--dui-color-surface);
  border-color: var(--dui-color-border);
  box-shadow: var(--preview);
}

/* Length bars, capped at half a sidebar column so they never overflow. */
.token-preview[data-preview="length"] {
  display: block;
  inline-size: min(var(--preview), calc(var(--dui-size-column-min) / 2));
  block-size: var(--dui-space-s);
  background-color: var(--dui-color-text-muted);
  forced-color-adjust: none;
}

.token-preview[data-preview="font-family"] {
  font-family: var(--preview);
}

.token-preview[data-preview="font-size"] {
  font-size: var(--preview);
  line-height: var(--dui-line-height-heading);
}

.token-preview[data-preview="font-weight"] {
  font-weight: var(--preview);
}

.token-preview[data-preview="line-height"] {
  line-height: var(--preview);
}

.token-preview[data-preview="letter-spacing"] {
  letter-spacing: var(--preview);
}
