:root {
  color-scheme: light;
  --bg: #f4f8f0;
  --bg-elevated: #f4f8f0;
  --surface: rgba(24, 49, 32, 0.035);
  --surface-strong: rgba(24, 49, 32, 0.06);
  --text: #162019;
  --muted: #4f6155;
  --faint: #6f8174;
  --border: rgba(22, 35, 26, 0.08);
  --accent: #1e7f43;
  --accent-strong: #166738;
  --accent-soft: rgba(30, 127, 67, 0.09);
  --accent-glow: transparent;
  --shadow: 0 18px 50px rgba(18, 35, 24, 0.08);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0f0c;
  --bg-elevated: #0a0f0c;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-strong: rgba(255, 255, 255, 0.06);
  --text: #f1f5f0;
  --muted: #a5b2a7;
  --faint: #7a867d;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #53d17d;
  --accent-strong: #8ef0aa;
  --accent-soft: rgba(83, 209, 125, 0.12);
  --accent-glow: transparent;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f8f0;
  --bg-elevated: #f4f8f0;
  --surface: rgba(24, 49, 32, 0.035);
  --surface-strong: rgba(24, 49, 32, 0.06);
  --text: #162019;
  --muted: #4f6155;
  --faint: #6f8174;
  --border: rgba(22, 35, 26, 0.08);
  --accent: #1e7f43;
  --accent-strong: #166738;
  --accent-soft: rgba(30, 127, 67, 0.09);
  --accent-glow: transparent;
  --shadow: 0 18px 50px rgba(18, 35, 24, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
  width: 100%;
  padding: 16px max(20px, calc((100% - 1700px) / 2 + 20px)) 0 max(32px, calc((100% - 1700px) / 2 + 32px));
  background: var(--bg);
  overflow: visible;
}

.site-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-bottom: 1px solid var(--border);
  pointer-events: none;
}

:root[data-theme="light"] .site-header {
  background: var(--bg);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.breadcrumb__link {
  color: inherit;
}

.breadcrumb__link:hover,
.breadcrumb__link:focus-visible {
  color: var(--accent-strong);
}

.breadcrumb__current {
  color: var(--text);
}

.content .breadcrumb > *:not(.breadcrumb__current) {
  display: none;
}

.site-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 26px;
  min-width: 0;
}

.site-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.version-menu {
  position: relative;
  flex: 0 0 auto;
  /* Optically center the badge on the title's lowercase-heavy text */
  margin-top: 2px;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
}

.version-badge svg {
  width: 12px;
  height: 12px;
}

.version-badge:hover,
.version-badge:focus-visible {
  color: var(--text);
  background: var(--surface-strong);
}

.version-menu__list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 80;
  min-width: 110px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.version-menu__item {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.version-menu__item:hover,
.version-menu__item:focus-visible {
  color: var(--text);
  background: var(--surface-strong);
}

.version-menu__item.is-current {
  color: var(--accent-strong);
}

.site-title {
  font-size: 1.38rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.site-tabs {
  display: flex;
  align-items: center;
  gap: 30px;
  flex-wrap: wrap;
  padding-left: 0;
  margin-bottom: -1px;
}

.site-tab {
  display: inline-block;
  padding: 0 0 11px;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.site-tab:hover,
.site-tab:focus-visible {
  color: var(--text);
}

.site-tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  /* Match the site title's line box so the toggle centers on it */
  height: calc(1.38rem * 1.1);
}

.github-link {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  transition: color 0.15s ease;
}

.github-link:hover,
.github-link:focus-visible {
  color: var(--accent-strong);
}

.github-link__mark {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  width: 40px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--accent-strong);
}

.theme-icon {
  width: 22px;
  height: 22px;
  display: none;
}

.theme-icon--sun {
  display: block;
}

:root[data-theme="dark"] .theme-icon--sun {
  display: block;
}

:root[data-theme="dark"] .theme-icon--moon {
  display: none;
}

:root[data-theme="light"] .theme-icon--sun {
  display: none;
}

:root[data-theme="light"] .theme-icon--moon {
  display: block;
}

.docs-frame {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 230px;
  gap: 0;
  max-width: 1700px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 20px 16px;
}

.sidebar,
.page-toc,
.content {
  min-width: 0;
}

.sidebar {
  position: relative;
  top: 0;
  align-self: start;
  padding: 12px 16px 0 0;
}

.content {
  max-width: 1010px;
  width: 100%;
  justify-self: center;
  padding: 0 22px 0 18px;
  scroll-padding-top: 28px;
}

body.home-page {
  overflow: auto;
}

@media (min-width: 981px) {
  .home-shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 54px 32px 88px;
  }

  .home-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.85fr);
    gap: 24px;
    align-items: start;
  }

  .home-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 24px;
  }

  .home-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 28px;
  }

  .home-section {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
  }

  .home-note {
    max-width: 44ch;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.8;
  }

  .home-panel {
    padding: 0;
  }
}

.page-toc {
  position: relative;
  top: 0;
  align-self: start;
  padding: 12px 0 0 18px;
}

@media (min-width: 981px) {
  /* min()/max() clamps guard against a transiently wrong --header-height
     (measured before styles applied): the sidebar must never collapse to
     zero height and the sticky offset must never reach mid-viewport. */
  .sidebar {
    position: sticky;
    top: min(calc(var(--header-height, 64px) + 20px), 220px);
    max-height: max(calc(100vh - var(--header-height, 64px) - 20px), 320px);
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .page-toc {
    position: sticky;
    top: min(calc(var(--header-height, 64px) + 20px), 220px);
  }
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
  color: var(--accent-strong);
}

.sidebar-toggle__icon {
  width: 24px;
  height: 24px;
}

.sidebar-backdrop,
.breadcrumb--bar {
  display: none;
}

.nav-group {
  margin-bottom: 18px;
}

.nav-group__title {
  display: block;
  margin: 0 0 10px 12px;
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 0;
  padding: 11px 12px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.4;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link:hover,
.nav-link:focus-visible {
  color: var(--text);
  background: var(--surface);
}

.nav-link.is-active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 700;
}

.nav-group + .nav-group {
  margin-top: 34px;
}

.toc-card {
  padding: 8px 0 0;
}

.toc-title {
  margin: 0 0 12px;
  color: var(--faint);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.toc-link {
  display: block;
  padding: 8px 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.toc-link:hover,
.toc-link:focus-visible {
  color: var(--text);
}

.page-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 24px;
  padding: 16px 0 20px;
}

.page-header__copy {
  max-width: none;
}

/* Pulls a section right up under the page header (e.g. the citation block) */
.page-header + .section--tight {
  margin-top: -38px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 2.4vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 14px;
}

h2 {
  font-size: 1.28rem;
  line-height: 1.2;
  margin-bottom: 14px;
  letter-spacing: -0.015em;
}

h3 {
  font-size: 1rem;
  line-height: 1.3;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.section h3 {
  margin-top: 28px;
}

.section h3:first-child {
  margin-top: 0;
}

.lede {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.8;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.button:hover,
.button:focus-visible {
  background: var(--surface);
}

.button--primary {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-strong);
}

.button--primary:hover,
.button--primary:focus-visible {
  background: rgba(83, 209, 125, 0.18);
}

.section {
  margin-bottom: 18px;
  padding: 8px 0 20px;
  scroll-margin-top: 28px;
}

.section p,
.section li {
  color: var(--muted);
  line-height: 1.8;
}

.section p + p,
.section p + .callout,
.section p + .cards,
.section p + .table-wrap,
.section p + .steps {
  margin-top: 14px;
}

.section pre {
  margin: 16px 0;
}

.section pre + .callout,
.section pre + p {
  margin-top: 16px;
}

.code-block {
  position: relative;
}

.code-block pre {
  margin: 0;
}

.section .code-block {
  margin: 16px 0;
}

.section .code-block + .callout,
.section .code-block + p {
  margin-top: 16px;
}

.code-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #a5b2a7;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.code-copy:hover,
.code-copy:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  color: #ecf7ef;
}

.code-copy.is-copied {
  color: #53d17d;
}

.code-copy svg {
  width: 17px;
  height: 17px;
}

.page-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.cards,
.section-grid {
  display: grid;
  gap: 16px;
}

.cards {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.section-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  padding: 0;
}

.card p {
  color: var(--muted);
  line-height: 1.75;
}

.callout {
  display: grid;
  gap: 4px;
  padding: 0;
  border-left: 1px solid var(--accent);
  padding-left: 16px;
}

.callout p {
  color: var(--muted);
  line-height: 1.8;
}

.page-header .callout {
  margin-top: 14px;
}

.section .callout p + p {
  margin-top: 0;
}

.callout--note {
  border-left-color: #2f6fd0;
}

.callout--note .callout__title {
  color: #2f6fd0;
}

:root[data-theme="dark"] .callout--note {
  border-left-color: #6ab0ff;
}

:root[data-theme="dark"] .callout--note .callout__title {
  color: #6ab0ff;
}

.callout--note .inline-code {
  background: rgba(47, 111, 208, 0.12);
  color: #2f6fd0;
}

:root[data-theme="dark"] .callout--note .inline-code {
  background: rgba(106, 176, 255, 0.14);
  color: #6ab0ff;
}

.callout__title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.section .callout__title {
  color: var(--accent-strong);
}

.callout__title svg {
  width: 17px;
  height: 17px;
}

.steps {
  list-style: none;
  counter-reset: steps;
  padding-left: 0;
  margin: 0;
}

.steps li {
  counter-increment: steps;
  position: relative;
  padding-left: 36px;
}

.steps li::before {
  content: counter(steps) ".";
  position: absolute;
  left: 16px;
  top: 0;
}

.steps li + li {
  margin-top: 10px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid transparent;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

.table th,
.table td {
  padding: 14px 24px 14px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  line-height: 1.65;
}

.table th:last-child,
.table td:last-child {
  padding-right: 0;
}

.table th {
  color: var(--faint);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.table tr:last-child td {
  border-bottom: 0;
}

pre {
  margin: 0;
  padding: 18px;
  overflow-x: auto;
  border-radius: 18px;
  background: #081109;
  color: #ecf7ef;
  border: 1px solid rgba(83, 209, 125, 0.15);
  line-height: 1.8;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

pre code {
  color: inherit;
}

pre code.hljs {
  padding: 0;
  background: transparent;
  color: inherit;
}

pre .hljs-comment,
pre .hljs-quote {
  color: #7d917f;
  font-style: italic;
}

pre .hljs-string {
  color: #a8e6b8;
}

pre .hljs-keyword,
pre .hljs-built_in,
pre .hljs-literal {
  color: #53d17d;
}

pre .hljs-variable,
pre .hljs-template-variable,
pre .hljs-attr,
pre .hljs-attribute {
  color: #9fd0ff;
}

pre .hljs-number {
  color: #ffd28f;
}

pre .hljs-title,
pre .hljs-function .hljs-title,
pre .hljs-meta {
  color: #8ef0aa;
}

.inline-code {
  padding: 0.12rem 0.38rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.doc-figure {
  margin: 16px 0 24px;
}

.page-header + .doc-figure {
  margin-top: -28px;
}

.doc-figure img,
.doc-figure video {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
}

.doc-figure video {
  background: #000;
  display: block;
}

.doc-figure--narrow {
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

.doc-figure--narrow img {
  padding: 18px;
}

.doc-figure--plain img {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.doc-figure figcaption {
  margin-top: 8px;
  color: var(--faint);
  font-size: 0.85rem;
  text-align: center;
}

.param-list {
  margin-top: 16px;
}

.param {
  padding: 14px 0;
}

.param + .param {
  border-top: 1px solid var(--border);
}

.param__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.param__name {
  color: var(--accent-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  font-weight: 700;
}

.param__badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(224, 122, 82, 0.14);
  color: #c96442;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

:root[data-theme="dark"] .param__badge {
  background: rgba(255, 158, 118, 0.14);
  color: #ff9e76;
}

.param__default {
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.section .param__desc {
  margin-top: 4px;
  color: var(--muted);
}

.section .param__desc p {
  margin: 0;
}

.section .param__desc ul {
  margin: 8px 0 0;
  padding-left: 22px;
}

.section .param__desc li + li {
  margin-top: 6px;
}

.api-list {
  display: grid;
  gap: 20px;
  margin-top: 16px;
}

.api-signature {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88rem;
  overflow-x: auto;
  white-space: nowrap;
}

.section .api-signature {
  color: var(--muted);
}

.api-prefix {
  color: var(--faint);
}

.api-name {
  color: var(--accent-strong);
  font-weight: 700;
}

.api-item > p + p {
  margin-top: 8px;
}

.section a {
  color: var(--accent-strong);
}

.section a:hover,
.section a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.section a.path-card:hover,
.section a.path-card:focus-visible {
  text-decoration: none;
}

.path-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  width: 100%;
  margin-top: 24px;
}

.path-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.path-card:hover,
.path-card:focus-visible {
  background: var(--surface);
  border-color: var(--accent);
}

.path-card__title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-strong);
  font-size: 1.05rem;
  font-weight: 800;
}

.path-card__title [aria-hidden] {
  transition: transform 0.15s ease;
}

.path-card:hover .path-card__title [aria-hidden],
.path-card:focus-visible .path-card__title [aria-hidden] {
  transform: translateX(3px);
}

.path-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

/* Input context diagram (context-management.html) */
.ctx-diagram {
  position: relative;
  max-width: 400px;
  margin: 20px auto 24px;
  padding: 44px 18px 18px;
  border: 1.5px solid rgba(235, 135, 50, 0.5);
  border-radius: 16px;
  background: rgba(235, 135, 50, 0.06);
}

.ctx-diagram__title {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 0.78rem;
  font-weight: 800;
  color: #b65c1f;
}

:root[data-theme="dark"] .ctx-diagram__title {
  color: #ffb679;
}

.ctx-group {
  position: relative;
  margin-top: 26px;
  padding: 34px 14px 14px;
  border-radius: 12px;
}

.ctx-group--prev {
  border: 1.5px solid rgba(80, 200, 120, 0.5);
  background: rgba(80, 200, 120, 0.07);
}

.ctx-group--current {
  border: 1.5px solid rgba(80, 160, 230, 0.5);
  background: rgba(80, 160, 230, 0.08);
}

.ctx-group__title {
  position: absolute;
  top: 10px;
  left: 14px;
  font-size: 0.72rem;
  font-weight: 800;
}

.ctx-group--prev .ctx-group__title {
  color: var(--accent-strong);
}

.ctx-group--current .ctx-group__title {
  color: #2f6fd0;
}

:root[data-theme="dark"] .ctx-group--current .ctx-group__title {
  color: #6ab0ff;
}

.ctx-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1.5px solid var(--faint);
  border-radius: 10px;
  background: var(--bg-elevated);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.ctx-box--system {
  background: var(--surface-strong);
}

.ctx-box--temp {
  border-style: dashed;
}

.ctx-role {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--faint);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Vertical connectors between stacked blocks */
.ctx-group .ctx-box + .ctx-box,
.ctx-diagram > .ctx-box + .ctx-group,
.ctx-diagram > .ctx-group + .ctx-group {
  margin-top: 16px;
}

.ctx-group .ctx-box + .ctx-box::before,
.ctx-diagram > .ctx-box + .ctx-group::before,
.ctx-diagram > .ctx-group + .ctx-group::before {
  content: "";
  position: absolute;
  top: -17.5px;
  left: 50%;
  width: 2px;
  height: 17.5px;
  background: var(--faint);
}

/* Action map (participants.html) */
.action-map {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.action-panel {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid;
}

.action-panel--intermediate {
  grid-column: 1 / -1;
  border-color: rgba(80, 160, 230, 0.5);
  background: rgba(80, 160, 230, 0.07);
}

.action-panel--conversation {
  border-color: rgba(235, 135, 50, 0.5);
  background: rgba(235, 135, 50, 0.06);
}

.action-panel--voting {
  border-color: rgba(80, 200, 120, 0.5);
  background: rgba(80, 200, 120, 0.07);
}

.action-panel__title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 800;
}

.action-panel__badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.action-panel--intermediate .action-panel__badge {
  background: rgba(80, 160, 230, 0.14);
  color: #2f6fd0;
}

:root[data-theme="dark"] .action-panel--intermediate .action-panel__badge {
  color: #6ab0ff;
}

.action-panel--conversation .action-panel__badge {
  background: rgba(235, 135, 50, 0.14);
  color: #b65c1f;
}

:root[data-theme="dark"] .action-panel--conversation .action-panel__badge {
  color: #ffb679;
}

.action-panel--voting .action-panel__badge {
  background: rgba(80, 200, 120, 0.14);
  color: var(--accent-strong);
}

.action-item {
  padding: 9px 0;
}

.action-item + .action-item {
  border-top: 1px solid var(--border);
}

.action-item__name {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
}

.action-item__desc {
  margin: 3px 0 0;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--muted);
}

.section .action-map + p {
  margin-top: 16px;
}

@media (max-width: 760px) {
  .action-map {
    grid-template-columns: 1fr;
  }
}

/* Maintainer card (developer.html) */
.maintainer-card {
  display: flex;
  align-items: center;
  gap: 24px;
  margin: -18px 0 20px;
}

.maintainer-art {
  flex: 0 0 auto;
  width: 140px;
  height: 140px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  /* Always the dark-theme look, regardless of the site theme */
  background: #0a0f0c;
  cursor: pointer;
  touch-action: none;
}

.maintainer-name {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.section .maintainer-info p + p {
  margin-top: 2px;
}

.maintainer-affil {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.3;
}

.maintainer-links {
  display: flex;
  gap: 14px;
  margin-top: 12px;
}

.maintainer-links a {
  display: inline-flex;
  color: var(--muted);
  transition: color 0.15s ease;
}

.maintainer-links a:hover,
.maintainer-links a:focus-visible {
  color: var(--accent-strong);
}

.maintainer-links svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 640px) {
  .maintainer-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
}

/* Itinerary demo mimicking the GUI proposal view (itinerary.html) */
.route-demo {
  margin: 20px 0 8px;
  padding: 18px 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.route-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.route-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 120px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
}

.route-stat__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--faint);
}

.route-stat__value {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text);
}

.route-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.route-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 178px;
  padding: 14px 14px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: 0 4px 14px rgba(18, 35, 24, 0.05);
  text-align: center;
}

.route-card__num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-bottom: 6px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.route-card__emoji {
  font-size: 1.5rem;
  line-height: 1.2;
}

.route-card__name {
  margin: 4px 0 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text);
}

.route-card__desc {
  margin: 4px 0 0;
  font-size: 0.7rem;
  line-height: 1.45;
  color: var(--muted);
}

.route-card__meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 8px 0 0;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.route-card__meta svg {
  width: 13px;
  height: 13px;
}

.route-card__meta strong {
  color: var(--text);
}

.route-card__cost {
  margin: 2px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.route-leg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 0 10px;
}

.route-leg__mode {
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
}

.route-leg__arrow {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.route-leg__meta {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--faint);
  white-space: nowrap;
}

.route-more {
  padding: 0 6px;
  color: var(--faint);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 3px;
}

@media (max-width: 760px) {
  /* Keep the chain on one row and let it scroll horizontally */
  .route-chain {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .route-card,
  .route-leg,
  .route-more {
    flex: 0 0 auto;
  }
}

/* Context compaction demos */
.ctx-demo {
  position: relative;
  margin-top: 10px;
  padding: 30px 6px 4px;
}

.ctx-demo__meter {
  position: absolute;
  top: 4px;
  right: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.ctx-demo__stack {
  display: flex;
  flex-direction: column;
  max-width: 250px;
  margin: 0 auto;
  transition: opacity 0.5s ease;
}

/* Loop boundary: the whole stack fades out before the demo restarts */
.ctx-demo__stack.is-faded {
  opacity: 0;
}

.ctx-demo__box {
  overflow: hidden;
  max-height: 40px;
  margin-top: 8px;
  padding: 6px 12px;
  border: 1.5px solid var(--faint);
  border-radius: 8px;
  background: var(--bg-elevated);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  transition: max-height 0.4s ease, margin-top 0.4s ease, padding 0.4s ease,
    opacity 0.4s ease, border-color 0.3s ease, background 0.3s ease;
}

.ctx-demo__box:first-child {
  margin-top: 0;
}

.ctx-demo__box--system {
  background: var(--surface-strong);
}

.ctx-demo__box--current {
  border-color: rgba(80, 160, 230, 0.7);
  background: rgba(80, 160, 230, 0.1);
}

.ctx-demo__box--summary {
  border-color: rgba(235, 135, 50, 0.7);
  background: rgba(235, 135, 50, 0.1);
}

.ctx-demo__box.is-marked {
  border-color: rgba(235, 135, 50, 0.8);
  background: rgba(235, 135, 50, 0.12);
}

/* Token-based truncation cuts through the middle of a turn: only the
   bottom half of the block survives, with a ragged (dashed) top edge */
.ctx-demo__box.is-halved {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  max-height: 17px;
  padding-top: 0;
  border-top-style: dashed;
}

.ctx-demo__box.is-removed,
.ctx-demo__box.is-hidden {
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  opacity: 0;
}

.ctx-demo__label {
  min-height: 2.6em;
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .ctx-demo__box {
    transition: none;
  }
}

/* Workflow demo animations (meeting-workflow.html) */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 760px) {
  .demo-grid {
    grid-template-columns: 1fr;
  }
}

.demo-card {
  display: flex;
  flex-direction: column;
  padding: 14px 16px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.demo-card__name {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.demo-card__desc {
  margin: 6px 0 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--muted);
}

.flow-demo {
  position: relative;
  margin-top: 10px;
  padding: 44px 8px 4px;
}

/* Inside a card grid, pin the stage to the card bottom so the characters
   line up across neighboring cards regardless of description length */
.demo-card .flow-demo,
.demo-card .ctx-demo {
  margin-top: auto;
  padding-top: 48px;
}

.flow-demo--wide {
  margin: 16px 0 6px;
  /* The phase badge gets its own row of clearance above the speech
     bubbles, matching the text-to-animation spacing used in the cards */
  padding: 80px 8px 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.flow-demo__phase {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.flow-demo__phase--conversation {
  background: rgba(235, 135, 50, 0.14);
  color: #b65c1f;
}

:root[data-theme="dark"] .flow-demo__phase--conversation {
  color: #ffb679;
}

.flow-demo__phase--voting {
  background: rgba(80, 200, 120, 0.14);
  color: var(--accent-strong);
}

.flow-demo__stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
}

.flow-actor {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: opacity 0.25s ease;
}

.flow-actor.is-dim {
  opacity: 0.35;
}

.flow-actor__sprite {
  display: block;
  width: 46px;
  height: 46px;
  filter: grayscale(0.35) opacity(0.75);
  transition: filter 0.3s ease, transform 0.3s ease;
  /* Keep the sprite on its own compositing layer so toggling the filter
     doesn't cause a subpixel shift when the layer is promoted/demoted */
  will-change: transform, filter;
  transform: translateZ(0);
}

.flow-actor__sprite svg {
  display: block;
  width: 100%;
  height: 100%;
}

.flow-actor.is-active .flow-actor__sprite {
  filter: none;
  /* Two up-down round trips (4 alternate half-cycles), in step with the
     speech dots' two cycles, then rest */
  animation: flow-hop 0.5s ease-in-out 4 alternate;
}

@keyframes flow-hop {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-4px);
  }
}

.flow-actor__name {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--muted);
  transition: color 0.25s ease;
}

.flow-actor.is-active .flow-actor__name {
  color: var(--accent-strong);
}

.flow-actor__tag {
  min-height: 13px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
}

.flow-actor__bubble {
  position: absolute;
  top: -27px;
  left: 50%;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 6px) scale(0.9);
  /* Springy pop-in, soft fade-out */
  transition: opacity 0.22s ease, transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.flow-actor__bubble.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.flow-actor__bubble--speech {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
}

.flow-actor__bubble--speech i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--muted);
  /* Rest state matches the animation's endpoints so the dots don't snap
     before the stagger delay or after the two cycles finish. The 1s cycle
     matches the speaker's hop period (0.5s alternate). */
  opacity: 0.35;
  animation: flow-speech-dot 1s ease-in-out 2 both;
}

.flow-actor__bubble--speech i:nth-child(2) {
  animation-delay: 0.15s;
}

.flow-actor__bubble--speech i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes flow-speech-dot {
  0%,
  55%,
  100% {
    opacity: 0.35;
    transform: none;
  }
  25% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-actor.is-active .flow-actor__sprite,
  .flow-actor__bubble.is-visible,
  .flow-actor__bubble--speech i {
    animation: none;
  }
}

.flow-actor__bubble--accept,
.flow-actor__bubble--satisfied {
  background: rgba(80, 200, 120, 0.16);
  color: var(--accent-strong);
}

.flow-actor__bubble--reject {
  background: rgba(225, 90, 80, 0.14);
  color: #b3403c;
}

:root[data-theme="dark"] .flow-actor__bubble--reject {
  color: #ff9b94;
}

.flow-actor__bubble--propose {
  background: rgba(235, 135, 50, 0.14);
  color: #b65c1f;
}

:root[data-theme="dark"] .flow-actor__bubble--propose {
  color: #ffb679;
}

.flow-actor__bubble--score {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
}

.flow-demo__arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  color: var(--accent-strong);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.flow-demo__arrows.is-visible {
  opacity: 1;
}

.flow-demo__arrow-path {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.flow-demo__label {
  min-height: 2.6em;
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.flow-demo__label--accept {
  color: var(--accent-strong);
}

.flow-demo__label--reject {
  color: #b3403c;
}

:root[data-theme="dark"] .flow-demo__label--reject {
  color: #ff9b94;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 20px 0 0;
}

.pager__link {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 48%;
  min-width: 0;
  padding: 10px 0;
  color: var(--muted);
  transition: color 0.15s ease;
}

.pager__link:hover,
.pager__link:focus-visible {
  color: var(--accent-strong);
}

.pager__link--next {
  margin-left: auto;
  text-align: right;
}

.pager__link--prev .pager__icon {
  /* The chevron glyph has ~7px of blank space on its left inside the
     viewBox; pull it out so the arrow tip aligns with the content edge */
  margin-left: -7px;
  transition: transform 0.15s ease;
}

.pager__link--next .pager__icon {
  /* Mirror of the prev icon: trim the glyph's blank right side */
  margin-right: -7px;
  transition: transform 0.15s ease;
}

.pager__link--prev:hover .pager__icon {
  transform: translateX(-3px);
}

.pager__link--next:hover .pager__icon {
  transform: translateX(3px);
}

.pager__label {
  font-size: 0.97rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager__icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  /* Optical alignment: lowercase-heavy labels center slightly below the
     geometric middle, so nudge the chevron down to match */
  position: relative;
  top: 1px;
}

@media (max-width: 1280px) {
  .docs-frame {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .page-toc {
    display: none;
  }
}

@media (max-width: 980px) {
  .site-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    padding: 14px 14px 0;
  }

  .site-brand {
    gap: 14px;
  }

  .site-title {
    white-space: normal;
  }

  .site-tabs {
    gap: 18px;
  }

  .docs-frame {
    display: block;
    padding: 0 14px 60px;
  }

  .sidebar {
    position: sticky;
    top: min(var(--header-height, 56px), 220px);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 -14px 12px;
    padding: 10px 14px;
    background: var(--bg);
  }

  .sidebar.is-open {
    z-index: 70;
  }

  .sidebar-toggle {
    display: flex;
    flex: 0 0 auto;
    margin-left: -10px;
  }

  .breadcrumb--bar {
    display: flex;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    white-space: nowrap;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(8, 14, 10, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar.is-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar__nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(300px, 82vw);
    padding: 24px 18px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0.25s ease;
  }

  .sidebar.is-open .sidebar__nav {
    transform: translateX(0);
    visibility: visible;
  }

  .nav-group + .nav-group {
    margin-top: 22px;
  }

  .content {
    padding: 0;
  }

  .section {
    scroll-margin-top: 16px;
  }

  pre {
    padding: 14px;
    border-radius: 14px;
    font-size: 0.88em;
  }

  .page-header {
    flex-direction: column;
    padding-top: 0;
  }

  body {
    min-height: 100vh;
    overflow: auto;
  }

  .home-shell {
    padding: 32px 14px 64px;
  }

  .home-hero,
  .home-grid {
    grid-template-columns: 1fr;
  }

  .cards,
  .section-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-header {
    padding: 14px 14px 0;
  }

  .site-title {
    font-size: 1.1rem;
  }

  .site-tabs {
    max-width: 100%;
    gap: 16px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .site-tab {
    flex: 0 0 auto;
    font-size: 0.94rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  .home-actions .button {
    flex: 1 1 auto;
  }
}
