/* docs.css: the shared docs-site layout, owned by Squire (kit/docs/).
 *
 * Layout only. Every color and type choice comes from a WayneUI token, held behind a --dk-* alias so a
 * repo can retheme without touching this file. The builder stamps one page per doc; this file makes those
 * pages read like a book instead of a form. No gradients, no glow, one hairline where a line is enough.
 *
 * Theme resolution mirrors WayneUI: the :root block is the light default, :root[data-theme="dark"] serves an
 * explicit dark choice (WayneUI writes data-theme from the reader's saved preference), and the
 * prefers-color-scheme query below serves readers who never chose, unless the root element carries
 * data-theme="light". Each block declares color-scheme so form controls and scrollbars follow the theme.
 * The hex fallbacks apply only when WayneUI is absent, and every text pair meets WCAG AA contrast in both
 * themes.
 */

:root {
  color-scheme: light;
  --dk-bg: var(--wsu-surface, #ffffff);
  --dk-ink: var(--wsu-text, #18181b);
  --dk-muted: var(--wsu-text-muted, #3f3f46);
  --dk-rule: var(--wsu-border, #d4d4d8);
  --dk-accent: var(--wsu-brand, #0c5449);
  --dk-on-accent: var(--wsu-on-brand, #ffffff);
  --dk-note: var(--wsu-info, #0e5a7d);
  --dk-tip: var(--wsu-success, #0f5132);
  --dk-warning: var(--wsu-warning, #634d00);
  --dk-danger: var(--wsu-danger, #9b1c2e);
  --dk-code-bg: var(--wsu-surface-sunken, #fafafa);
  --dk-display: var(--wsu-font-family-display, Georgia, "Times New Roman", serif);
  --dk-mono: var(--wsu-font-family-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  --dk-radius: var(--wsu-radius-box, 0.75rem);
  --dk-focus: var(--wsu-focus-ring, #0c5449);
  --dk-focus-w: var(--wsu-size-focus-ring-width, 0.1875rem);
  --dk-focus-o: var(--wsu-size-focus-ring-offset, 0.125rem);
  --dk-sidebar: 16rem;
  --dk-prose-max: 46rem;
  --dk-gap: var(--wsu-space-6, 1.5rem);
}

/* Dark fallbacks for the color aliases, in the same order WayneUI resolves them. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --dk-bg: var(--wsu-surface, #18181b);
  --dk-ink: var(--wsu-text, #f4f4f5);
  --dk-muted: var(--wsu-text-muted, #a1a1aa);
  --dk-rule: var(--wsu-border, #3f3f46);
  --dk-accent: var(--wsu-brand, #5eead4);
  --dk-on-accent: var(--wsu-on-brand, #18181b);
  --dk-note: var(--wsu-info, #7dd3fc);
  --dk-tip: var(--wsu-success, #86efac);
  --dk-warning: var(--wsu-warning, #fcd34d);
  --dk-danger: var(--wsu-danger, #fca5a5);
  --dk-code-bg: var(--wsu-surface-sunken, #27272a);
  --dk-focus: var(--wsu-focus-ring, #5eead4);
}

/* Readers who never chose a theme: follow the system setting, unless the root element says light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --dk-bg: var(--wsu-surface, #18181b);
    --dk-ink: var(--wsu-text, #f4f4f5);
    --dk-muted: var(--wsu-text-muted, #a1a1aa);
    --dk-rule: var(--wsu-border, #3f3f46);
    --dk-accent: var(--wsu-brand, #5eead4);
    --dk-on-accent: var(--wsu-on-brand, #18181b);
    --dk-note: var(--wsu-info, #7dd3fc);
    --dk-tip: var(--wsu-success, #86efac);
    --dk-warning: var(--wsu-warning, #fcd34d);
    --dk-danger: var(--wsu-danger, #fca5a5);
    --dk-code-bg: var(--wsu-surface-sunken, #27272a);
    --dk-focus: var(--wsu-focus-ring, #5eead4);
  }
}

.docs-header,
.docs-layout,
.docs-footer {
  max-width: 100rem;
  margin-inline: auto;
}

.docs-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--dk-gap);
  padding: var(--dk-gap);
  border-bottom: 1px solid var(--dk-rule);
}

.docs-header__brand {
  font-family: var(--dk-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--dk-ink);
  text-decoration: none;
}

.docs-header__home {
  color: var(--dk-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.docs-layout {
  padding: var(--dk-gap);
}

.docs-menu {
  margin-bottom: var(--dk-gap);
}

.docs-menu summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--dk-ink);
  padding: 0.5rem 0;
}

.docs-nav--sidebar {
  display: none;
}

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

.docs-nav__list .docs-nav__list {
  margin-left: 1rem;
}

.docs-nav__label {
  display: block;
  margin-top: 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dk-muted);
}

.docs-nav a {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: var(--dk-radius);
  color: var(--dk-ink);
  text-decoration: none;
}

.docs-nav a:hover {
  background: var(--dk-code-bg);
  color: var(--dk-accent);
}

.docs-nav a[aria-current="page"] {
  background: var(--dk-accent);
  color: var(--dk-on-accent);
}

.docs-content {
  min-width: 0;
}

.docs-article {
  max-width: var(--dk-prose-max);
  font-family: var(--dk-display);
  line-height: 1.7;
  color: var(--dk-ink);
}

.docs-article h1,
.docs-article h2,
.docs-article h3 {
  line-height: 1.25;
  scroll-margin-top: var(--dk-gap);
  /* A backstop for a long word on a phone: hyphenate it rather than push the page sideways. */
  overflow-wrap: break-word;
  hyphens: auto;
}

.docs-article h1 {
  font-size: 2rem;
  margin: 0 0 1rem;
}

.docs-article h2 {
  font-size: 1.5rem;
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--dk-rule);
}

.docs-article h3 {
  font-size: 1.2rem;
  margin: 1.5rem 0 0.5rem;
}

.docs-article p {
  margin: 0 0 1rem;
}

.docs-article a {
  color: var(--dk-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.docs-heading-link {
  margin-left: 0.4em;
  opacity: 0;
  color: var(--dk-accent);
  text-decoration: none;
}

.docs-article h1:hover .docs-heading-link,
.docs-article h2:hover .docs-heading-link,
.docs-article h3:hover .docs-heading-link,
.docs-heading-link:focus-visible {
  opacity: 1;
}

/* The builder wraps the heading's last word and its "#" in .docs-heading-tail, the word (or code span, or
 * emphasis) in an element of its own. Only the seam between the word and the "#" holds, so a narrow heading
 * wraps before the word and never leaves the "#" alone on a line, while a word too long for any line still
 * breaks or hyphenates instead of pushing the page sideways. */
.docs-heading-tail {
  white-space: nowrap;
}

.docs-heading-tail > * {
  white-space: normal;
}

/* The page title's "#" is the page's own address, and a theme's big title can fill a line with one word, which
 * would leave no room for it. So at every width it steps out of the line as a 1px clipped box: it takes no room
 * and cannot widen the page. Keyboard focus still lands on it and shows it right after the last word. */
.docs-article h1 .docs-heading-link:not(:focus-visible) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.docs-article h1 .docs-heading-link:focus-visible {
  position: absolute;
}

/* Phones, narrow windows and touch screens: every heading's "#" does the same, so none adds a line and none is
 * an invisible trap under a thumb. */
@media (max-width: 40rem), (hover: none) {
  .docs-heading-link:not(:focus-visible) {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: 0;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .docs-heading-link:focus-visible {
    position: absolute;
  }
}

.docs-article code {
  font-family: var(--dk-mono);
  font-size: 0.9em;
  background: var(--dk-code-bg);
  border-radius: calc(var(--dk-radius) / 2);
  padding: 0.1em 0.35em;
}

.docs-copy {
  position: relative;
}

.docs-copy__button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-family: var(--dk-mono);
  font-size: 0.75rem;
  color: var(--dk-ink);
  background: var(--dk-bg);
  border: 1px solid var(--dk-rule);
  border-radius: calc(var(--dk-radius) / 2);
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  /* One line, always: docs.js lets Copied or Failed widen the button only where it stays clear of the code;
     over the code it keeps its resting width and swaps a word that does not fit for a mark. */
  white-space: nowrap;
}

.docs-copy__button:hover {
  color: var(--dk-accent);
  border-color: var(--dk-accent);
}

.docs-copy__status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Images. WayneUI's reset makes every image a block, which stacks a README's badge row or icon row into
 * a column. In the article an image sits in the line again, centered on the text, the way a README
 * renders. An image alone in its paragraph (a hero, a diagram), or followed only by a <sub> credit,
 * stays a block. */
.docs-article img {
  display: inline-block;
  vertical-align: middle;
}

.docs-article p > img:only-child,
.docs-article p > a:only-child > img:only-child,
.docs-article p > img:first-child:has(+ sub:last-child),
.docs-article p > a:first-child:has(+ sub:last-child) > img:only-child {
  display: block;
}

/* An image row: a paragraph or block holding two or more images or linked images and nothing else
 * (badges, the README cast row). It stays inline, so align="center" still centers it; balanced lines
 * keep a lone icon off the last line, and each image gets the same room on every side. CSS cannot see
 * text nodes, so a row like this with loose words in it lays out the same way, which is harmless. */
.docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) {
  text-wrap: balance;
}

.docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > :is(img, a) {
  display: inline-block;
  margin: 0.25rem 0.125rem;
  vertical-align: middle;
}

.docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > a {
  border-radius: 0.5rem;
}

.docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > a > img {
  display: block;
}

/* A tile row: a list whose every item is one image or one linked image (a cast list) lays out as
 * wrapping 4rem tiles, no bullets, even gaps. */
.docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
  padding: 0;
  list-style: none;
}

.docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li {
  margin: 0;
}

.docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li > a {
  display: block;
  border-radius: 0.875rem;
}

.docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li img {
  display: block;
  width: 4rem;
  height: auto;
}

/* A linked image in either row answers the pointer with one accent hairline around the tile, and lifts
 * a little for readers who allow motion. Keyboard focus keeps the kit's full ring, on the same corners. */
.docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > a:hover:not(:focus-visible),
.docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li > a:hover:not(:focus-visible) {
  outline: 1px solid var(--dk-accent);
  outline-offset: var(--dk-focus-o);
}

@media (prefers-reduced-motion: no-preference) {
  .docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > a,
  .docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li > a {
    transition: transform 160ms ease;
  }

  .docs-article :is(p, div):has(> :is(img, a) + :is(img, a)):has(> img, > a > img):not(:has(> :not(img, a), > a > :not(img), > a > img ~ *)) > a:is(:hover, :focus-visible),
  .docs-article ul:has(> li > img, > li > a > img):not(:has(> li > :not(img, a), > li > :is(img, a) ~ *, > li > a > :not(img), > li > a > img ~ *)) > li > a:is(:hover, :focus-visible) {
    transform: translateY(-2px);
  }
}

.docs-article pre {
  background: var(--dk-code-bg);
  border: 1px solid var(--dk-rule);
  border-radius: var(--dk-radius);
  padding: 1rem;
  overflow-x: auto;
}

.docs-article pre code {
  background: none;
  padding: 0;
}

.docs-callout {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--dk-rule);
  border-radius: var(--dk-radius);
  background: var(--dk-code-bg);
}

.docs-callout__label {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.docs-callout p:last-child {
  margin-bottom: 0;
}

.docs-callout--note {
  border-left-color: var(--dk-note);
}

.docs-callout--note .docs-callout__label {
  color: var(--dk-note);
}

.docs-callout--tip {
  border-left-color: var(--dk-tip);
}

.docs-callout--tip .docs-callout__label {
  color: var(--dk-tip);
}

.docs-callout--warning {
  border-left-color: var(--dk-warning);
}

.docs-callout--warning .docs-callout__label {
  color: var(--dk-warning);
}

.docs-callout--danger {
  border-left-color: var(--dk-danger);
}

.docs-callout--danger .docs-callout__label {
  color: var(--dk-danger);
}

/* Code tabs: without JavaScript every panel stays visible under its label; the kit adds a tablist above. */
.docs-tabs {
  margin: 0 0 1rem;
}

.docs-tabs__tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.docs-tabs__tab {
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-family: var(--dk-mono);
  font-size: 0.85rem;
  color: var(--dk-muted);
  background: var(--dk-code-bg);
  border: 1px solid var(--dk-rule);
  border-radius: calc(var(--dk-radius) / 2);
  cursor: pointer;
}

.docs-tabs__tab:hover {
  color: var(--dk-accent);
  border-color: var(--dk-accent);
}

.docs-tabs__tab[aria-selected="true"] {
  color: var(--dk-ink);
  font-weight: 700;
  background: var(--dk-bg);
  border-color: var(--dk-accent);
  box-shadow: inset 0 -2px 0 var(--dk-accent);
}

.docs-tabs__label {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dk-muted);
}

.docs-tabs__panel {
  margin-bottom: 1rem;
}

.docs-tabs__panel:last-child {
  margin-bottom: 0;
}

.docs-tabs [hidden] {
  display: none;
}

.docs-table {
  overflow-x: auto;
  margin: 1rem 0;
}

.docs-article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.docs-article th,
.docs-article td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--dk-rule);
}

/* Inline code in a header cell borrows the cell's own colors, so it keeps the
 * header text's contrast in light and dark themes. */
.docs-article th code {
  color: inherit;
  background: none;
}

.docs-toc {
  margin-top: var(--dk-gap);
  max-width: var(--dk-prose-max);
}

.docs-toc__title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dk-muted);
  margin: 0 0 0.5rem;
}

.docs-toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--dk-rule);
}

/* A page built before sub-items carried the base class still styles them: --sub alone matches too. */
.docs-toc__item a,
.docs-toc__item--sub a {
  position: relative;
  display: block;
  padding: 0.25rem 0.75rem;
  color: var(--dk-muted);
  text-decoration: none;
}

.docs-toc__item a:hover,
.docs-toc__item--sub a:hover {
  color: var(--dk-accent);
}

.docs-toc__item--sub a {
  padding-left: 1.5rem;
}

/* The section in view. docs.js marks its link with aria-current="true" and .is-current as the reader scrolls;
 * without the script nothing is marked and the list reads as before. The marker is a short accent bar laid over
 * the list's rule, so it shows on any theme that keeps the rule, light or dark. */
.docs-toc__item a::before,
.docs-toc__item--sub a::before {
  content: "";
  position: absolute;
  inset-block: 0.3rem;
  inset-inline-start: -2px;
  inline-size: 3px;
  border-radius: 3px;
  background: var(--dk-accent);
  opacity: 0;
  transform: scaleY(0.3);
}

.docs-toc__item a:is(.is-current, [aria-current="true"]),
.docs-toc__item--sub a:is(.is-current, [aria-current="true"]) {
  color: var(--dk-ink);
}

.docs-toc__item a:is(.is-current, [aria-current="true"])::before,
.docs-toc__item--sub a:is(.is-current, [aria-current="true"])::before {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  .docs-toc__item a,
  .docs-toc__item--sub a {
    transition: color 160ms ease;
  }

  .docs-toc__item a::before,
  .docs-toc__item--sub a::before {
    transition: opacity 160ms ease, transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

/* High contrast drops the bar's color, so the current link says it with an underline instead. */
@media (forced-colors: active) {
  .docs-toc__item a:is(.is-current, [aria-current="true"]),
  .docs-toc__item--sub a:is(.is-current, [aria-current="true"]) {
    text-decoration: underline;
  }
}

.docs-pager {
  display: flex;
  justify-content: space-between;
  gap: var(--dk-gap);
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--dk-rule);
}

.docs-pager__link {
  display: block;
  max-width: 50%;
  color: var(--dk-ink);
  text-decoration: none;
}

.docs-pager__link--next {
  text-align: right;
}

.docs-pager__dir {
  display: block;
  font-size: 0.8rem;
  color: var(--dk-muted);
}

.docs-pager__title {
  color: var(--dk-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.docs-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--dk-gap);
  padding: var(--dk-gap);
  border-top: 1px solid var(--dk-rule);
  color: var(--dk-muted);
  font-size: 0.9rem;
}

.docs-footer a {
  color: var(--dk-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

:where(a, button, summary, [tabindex]):focus-visible {
  outline: var(--dk-focus-w) solid var(--dk-focus);
  outline-offset: var(--dk-focus-o);
}

@media (min-width: 760px) {
  .docs-menu {
    display: none;
  }

  .docs-nav--sidebar {
    display: block;
  }

  .docs-layout {
    display: grid;
    grid-template-columns: var(--dk-sidebar) minmax(0, 1fr);
    gap: var(--dk-gap);
    align-items: start;
  }

  .docs-nav--sidebar {
    grid-column: 1;
    grid-row: 1;
  }

  .docs-content {
    grid-column: 2;
    grid-row: 1;
  }

  .docs-toc {
    grid-column: 2;
    grid-row: 2;
    margin-top: 0;
  }
}

@media (min-width: 1200px) {
  .docs-layout--toc {
    grid-template-columns: var(--dk-sidebar) minmax(0, 1fr) 16rem;
  }

  .docs-layout--toc .docs-toc {
    grid-column: 3;
    grid-row: 1;
    position: sticky;
    top: var(--dk-gap);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .docs-menu,
  .docs-nav,
  .docs-toc,
  .docs-pager,
  .docs-header__home,
  .docs-heading-link,
  .docs-tabs__tablist {
    display: none !important;
  }

  /* A printed page shows every tab's example, labeled, like the no-JavaScript view. */
  .docs-tabs__panel[hidden],
  .docs-tabs__label[hidden] {
    display: block !important;
  }

  .docs-layout {
    display: block;
  }
}
