/* Tokens. The diagram SVGs of beautiful_mermaid read --line, --muted, --accent, --surface and
   --border, so the site defines them too, and the diagrams follow the theme. */
:root {
  color-scheme: light dark;
  --page-bg: #fbfaf7;
  --page-fg: #1d1c1a;
  --muted: #5d5a54;
  --line: #d9d4c9;
  --border: #e2ded5;
  --surface: #f2efe8;
  --accent: #9a6b12;
  --accent-soft: #f6ead1;
  --note: #2f6fb3;
  --tip: #2e7d4f;
  --important: #7c4dbd;
  --warning: #9a6b12;
  --caution: #b3402f;
  --ok: #2e7d4f;
  --danger: #b3402f;
  /* Layer colors of the explainer palette, from the foil-gold top layer to the slate base. */
  --s0: #8a5a0b;
  --s1: #9a6b12;
  --s2: #a97f2a;
  --s3: #8c7a4f;
  --s4: #6f6a5c;
  --s5: #5b6b73;
  --s6: #4b6a86;
  --s7: #44608f;
  --s8: #4a5578;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page-bg: #151412;
    --page-fg: #ece9e2;
    --muted: #a8a399;
    --line: #47443e;
    --border: #2e2c28;
    --surface: #1e1d1a;
    --accent: #d9a441;
    --accent-soft: #3a2e17;
    --note: #6ea8e8;
    --tip: #6cc08f;
    --important: #b48ef0;
    --warning: #d9a441;
    --caution: #ec7d6c;
    --ok: #6cc08f;
    --danger: #ec7d6c;
    --s0: #e0b050;
    --s1: #d9a441;
    --s2: #cfa060;
    --s3: #bba67a;
    --s4: #a8a399;
    --s5: #93a8b3;
    --s6: #86a7c6;
    --s7: #8aa3d4;
    --s8: #9aa3c8;
  }
}

:root[data-theme="dark"] {
  --page-bg: #151412;
  --page-fg: #ece9e2;
  --muted: #a8a399;
  --line: #47443e;
  --border: #2e2c28;
  --surface: #1e1d1a;
  --accent: #d9a441;
  --accent-soft: #3a2e17;
  --note: #6ea8e8;
  --tip: #6cc08f;
  --important: #b48ef0;
  --warning: #d9a441;
  --caution: #ec7d6c;
  --ok: #6cc08f;
  --danger: #ec7d6c;
  --s0: #e0b050;
  --s1: #d9a441;
  --s2: #cfa060;
  --s3: #bba67a;
  --s4: #a8a399;
  --s5: #93a8b3;
  --s6: #86a7c6;
  --s7: #8aa3d4;
  --s8: #9aa3c8;
}

/* Base */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--page-fg);
  font-family: var(--font-sans);
  line-height: 1.6;
}

a {
  color: var(--accent);
}

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

:not(pre) > code {
  overflow-wrap: anywhere;
  background: var(--surface);
  border-radius: 4px;
  padding: 0.1em 0.3em;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  overflow-x: auto;
}

/* Shiki writes both themes as CSS variables. */
.shiki,
.shiki span {
  color: var(--shiki-light);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .shiki,
  :root:not([data-theme="light"]) .shiki span {
    color: var(--shiki-dark);
  }
}

:root[data-theme="dark"] .shiki,
:root[data-theme="dark"] .shiki span {
  color: var(--shiki-dark);
}

table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.95em;
}

[role="region"] {
  overflow-x: auto;
}

th,
td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}

tr:first-child th,
tr:first-child td {
  background: var(--surface);
  font-weight: 600;
}

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

/* Frame */

.skip-link {
  position: absolute;
  left: -999px;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
}

.site-header,
.site-footer,
main {
  max-width: 76rem;
  margin: 0 auto;
  padding: 16px;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--page-fg);
  font-weight: 700;
  text-decoration: none;
}

.site-links {
  display: flex;
  gap: 16px;
}

.site-links a {
  color: var(--muted);
  text-decoration: none;
}

.site-links a.current,
.site-links a:hover {
  color: var(--page-fg);
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Islands. Each mount is empty without JavaScript, so it takes no space. */

#site-search {
  position: relative;
  margin-left: auto;
}

.search input {
  width: 16rem;
  max-width: 60vw;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-bg);
  color: var(--page-fg);
  font: inherit;
}

.search-results {
  position: absolute;
  right: 0;
  z-index: 10;
  width: 22rem;
  max-width: calc(100vw - 32px);
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.search-results li a {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 8px;
  color: var(--page-fg);
  text-decoration: none;
}

.search-results li.selected a,
.search-results li a:hover {
  background: var(--surface);
}

.search-results small,
.search-empty {
  color: var(--muted);
}

.search-empty {
  padding: 6px 8px;
}

.theme-toggle,
.menu-toggle {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-bg);
  color: var(--page-fg);
  font: inherit;
  cursor: pointer;
}

.menu-toggle {
  display: none;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
}

.theme-icon {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

.theme-system {
  --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='2' y='3' width='20' height='14' rx='2'/><path d='M8 21h8M12 17v4'/></svg>");
}

.theme-light {
  --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><circle cx='12' cy='12' r='4'/><path d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/></svg>");
}

.theme-dark {
  --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'><path d='M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z'/></svg>");
}

/* The copy button of a code block. The islands wrap each block in div.code-block. */

.code-block {
  position: relative;
  margin: 1em 0;
}

.code-block > pre {
  margin: 0;
}

.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page-bg);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.copy-button::before {
  content: "";
  width: 1rem;
  height: 1rem;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
  --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'><rect x='9' y='9' width='12' height='12' rx='2'/><path d='M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1'/></svg>");
}

.copy-button[data-state="copied"] {
  color: var(--ok);
}

.copy-button[data-state="copied"]::before {
  --icon: url("data:image/svg+xml,<svg 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'><path d='M20 6L9 17l-5-5'/></svg>");
}

.copy-button[data-state="failed"] {
  color: var(--danger);
}

.copy-button::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 50%;
  right: calc(100% + 6px);
  transform: translateY(-50%);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--page-fg);
  color: var(--page-bg);
  font: 600 0.75rem/1.4 var(--font-sans);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.code-block:hover .copy-button,
.copy-button:focus-visible,
.copy-button:not([data-state="idle"])[data-state] {
  opacity: 1;
}

.copy-button:hover::after,
.copy-button:focus-visible::after,
.copy-button:not([data-state="idle"])[data-state]::after {
  opacity: 1;
}

@media (hover: none) {
  .copy-button {
    opacity: 1;
  }
}

/* A narrow screen shows the menu button. The main links stay visible without JavaScript. */

@media (max-width: 760px) {
  .menu-toggle {
    display: inline-block;
  }

  .site-header {
    gap: 8px 16px;
  }

  #site-theme {
    margin-left: auto;
  }

  #site-search {
    order: 3;
    margin-left: 0;
    width: 100%;
  }

  .search input {
    width: 100%;
    max-width: none;
  }

  .site-links {
    order: 4;
  }

  :root[data-js] .site-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 8px;
  }

  :root[data-js][data-nav-open] .site-links {
    display: flex;
  }
}

/* Landing page and articles */

.hero h1 {
  font-size: clamp(2rem, 6vw, 3.25rem);
  margin-bottom: 0.25em;
}

.article-list {
  list-style: none;
  padding: 0;
}

.article-card {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.article-meta {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Docs pages */

.docs-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

@media (min-width: 900px) {
  .docs-layout {
    grid-template-columns: 14rem minmax(0, 1fr);
  }
}

@media (min-width: 1200px) {
  .docs-layout {
    grid-template-columns: 14rem minmax(0, 1fr) 12rem;
  }
}

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

.docs-sidebar li,
.docs-toc li {
  margin: 2px 0;
}

.docs-sidebar .depth-1,
.docs-toc .depth-1 {
  padding-left: 12px;
}

.docs-sidebar .depth-2 {
  padding-left: 24px;
}

.docs-sidebar a,
.docs-toc a {
  color: var(--muted);
  text-decoration: none;
}

.docs-sidebar a.current,
.docs-sidebar a:hover,
.docs-toc a:hover {
  color: var(--page-fg);
}

.docs-toc a[aria-current] {
  color: var(--accent);
  font-weight: 600;
}

.docs-sidebar a.current {
  font-weight: 600;
}

.nav-label {
  display: block;
  margin: 12px 0 4px;
  color: var(--page-fg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.docs-rail {
  display: none;
}

@media (min-width: 1200px) {
  .docs-rail {
    display: block;
    position: sticky;
    top: 16px;
    align-self: start;
    font-size: 0.875rem;
  }
}

.page-source {
  margin-top: 32px;
  font-size: 0.875rem;
}

/* Building blocks */

.status-banner {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
}

.badge {
  display: inline-block;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0 6px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.callout {
  --callout: var(--note);
  border-left: 4px solid var(--callout);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  margin: 1em 0;
  padding: 4px 16px;
}

.callout.tip {
  --callout: var(--tip);
}

.callout.important {
  --callout: var(--important);
}

.callout.warning {
  --callout: var(--warning);
}

.callout.caution {
  --callout: var(--caution);
}

.callout-label {
  color: var(--callout);
  font-weight: 700;
}

.diagram {
  margin: 1.5em 0;
  overflow-x: auto;
}

/* The diagram SVG sets its own white --bg and dark --fg. Use the page colors. */
.diagram svg {
  max-width: none;
  --bg: transparent !important;
  --fg: var(--page-fg) !important;
}

.layer-stack {
  margin: 1.5em 0;
}

.layer-stack ol {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: layer;
}

.layer-stack li {
  display: grid;
  grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr);
  gap: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  margin: 4px 0;
  padding: 6px 12px;
}

.layer-stack li:nth-child(1) { border-left-color: var(--s0); }
.layer-stack li:nth-child(2) { border-left-color: var(--s1); }
.layer-stack li:nth-child(3) { border-left-color: var(--s2); }
.layer-stack li:nth-child(4) { border-left-color: var(--s3); }
.layer-stack li:nth-child(5) { border-left-color: var(--s4); }
.layer-stack li:nth-child(6) { border-left-color: var(--s5); }
.layer-stack li:nth-child(7) { border-left-color: var(--s6); }
.layer-stack li:nth-child(8) { border-left-color: var(--s7); }
.layer-stack li:nth-child(n + 9) { border-left-color: var(--s8); }

.layer-name {
  font-weight: 600;
}

.layer-detail {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

@media (max-width: 520px) {
  .layer-stack li {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
}

/* Version trees (design D22). The deploy fills the banner of an older or unreleased version; a build
   writes it empty, and an empty banner takes no space. */
.version-banner:empty {
  display: none;
}

.version-banner {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--page-fg);
  text-align: center;
}

.version-banner p {
  margin: 0;
}

.version-select {
  font: inherit;
  color: var(--page-fg);
  background: var(--page-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
}
