:root {
  --doc-sidebar-w: 260px;
  --doc-toc-w: 220px;
  --doc-nav-h: 56px;
  --doc-content-max: 720px;
  --doc-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

.doc-body {
  background: var(--background);
  color: var(--foreground);
  font-size: var(--text-base);
  line-height: 1.7;
}

/* ── Top nav ───────────────────────────────────────── */
.doc-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--doc-nav-h);
  padding: 0 1.25rem;
  background: color-mix(in oklab, var(--background) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.doc-nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--foreground);
  text-decoration: none;
  font-family: 'Bricolage Grotesque', sans-serif;
}

.doc-nav-brand .brand-icon {
  width: 18px;
  height: 18px;
  stroke: var(--brand);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doc-nav-brand .wordmark { font-size: var(--text-base); letter-spacing: -0.01em; }
.doc-nav-brand .wordmark strong { font-weight: 700; color: var(--brand); }

.doc-nav-divider { color: var(--muted-foreground); margin: 0 0.25rem; }
.doc-nav-section { color: var(--muted-foreground); font-size: var(--text-sm); font-weight: 500; }

.doc-nav-spacer { flex: 1; }

.doc-search {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  padding: 0 0.75rem;
  min-width: 200px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  cursor: pointer;
  font-family: inherit;
}

.doc-search:hover { border-color: var(--border-strong); color: var(--foreground); }
.doc-search kbd {
  margin-left: auto;
  padding: 1px 6px;
  font-size: 11px;
  font-family: var(--doc-mono);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted-foreground);
}

@media (max-width: 820px) {
  .doc-nav { gap: 0.4rem; padding: 0 1rem; }
  .doc-nav > * { flex-shrink: 0; }

  .doc-search {
    min-width: 0;
    width: 32px;
    padding: 0;
    justify-content: center;
    background: transparent;
    border: 0;
  }
  .doc-search:hover { background: var(--secondary); }
  .doc-search span, .doc-search kbd { display: none; }

  .doc-nav-lang > summary {
    width: 32px;
    padding: 0;
    justify-content: center;
    gap: 0;
  }
  .doc-nav-lang-text,
  .doc-nav-lang-chevron { display: none; }
  .doc-nav-lang > summary > .doc-nav-lang-globe { display: inline-block; }
}

.doc-nav-github {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--muted-foreground);
  border-radius: var(--radius);
}
.doc-nav-github:hover { color: var(--foreground); background: var(--secondary); }

.doc-nav-lang {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.doc-nav-lang > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.65rem;
  height: 32px;
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}
.doc-nav-lang > summary::-webkit-details-marker { display: none; }
.doc-nav-lang > summary::marker { display: none; content: ''; }
.doc-nav-lang > summary:hover { color: var(--foreground); background: var(--secondary); }

/* Globe icon hidden on desktop (text label is enough — mobile media query
   above re-enables it). */
.doc-nav-lang-globe { display: none; }

.doc-nav-lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  min-width: 160px;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 60;
}
.doc-nav-lang-menu a {
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  text-decoration: none;
}
.doc-nav-lang-menu a:hover { color: var(--foreground); background: var(--secondary); }
.doc-nav-lang-menu a.is-active { color: var(--brand); background: var(--brand-soft); }

/* ── Mobile content header (breadcrumb + hamburger) ── */
.doc-mobile-header {
  display: none;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
  padding: 0 1rem;
  background: color-mix(in oklab, var(--background) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--doc-nav-h);
  z-index: 40;
}

.doc-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: -6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--foreground);
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
}
.doc-menu-btn:hover { background: var(--secondary); }

.doc-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  overflow: hidden;
  white-space: nowrap;
}
.doc-breadcrumb-group {
  color: var(--muted-foreground);
  flex-shrink: 0;
}
.doc-breadcrumb-sep {
  color: var(--muted-foreground);
  opacity: 0.5;
  flex-shrink: 0;
}
.doc-breadcrumb-current {
  color: var(--foreground);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ── Sidebar backdrop (mobile drawer) ──────────────── */
.doc-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.doc-sidebar-backdrop:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

.doc-sidebar-close {
  display: none;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted-foreground);
  border-radius: var(--radius);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.doc-sidebar-close:hover { color: var(--foreground); background: var(--secondary); }

/* ── Shell ─────────────────────────────────────────── */
.doc-shell {
  display: grid;
  grid-template-columns: var(--doc-sidebar-w) minmax(0, 1fr);
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Sidebar ───────────────────────────────────────── */
.doc-sidebar {
  position: sticky;
  top: var(--doc-nav-h);
  align-self: start;
  height: calc(100vh - var(--doc-nav-h));
  padding: 1.5rem 0.5rem 2rem 1.25rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.doc-sidebar-inner { display: flex; flex-direction: column; gap: 1.5rem; }

.doc-group { display: flex; flex-direction: column; gap: 2px; }

.doc-group-label {
  padding: 0 0.625rem;
  margin-bottom: 0.4rem;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.doc-link {
  display: block;
  padding: 0.35rem 0.625rem;
  border-radius: 6px;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: color 120ms, background 120ms;
}

.doc-link:hover { color: var(--foreground); background: var(--secondary); }

.doc-link.is-active {
  color: var(--brand);
  background: var(--brand-soft);
  font-weight: 500;
}

/* ── Main ──────────────────────────────────────────── */
.doc-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--doc-toc-w);
  gap: 3rem;
  padding: 3rem 2.5rem 5rem;
}

@media (max-width: 1100px) {
  .doc-main { grid-template-columns: minmax(0, 1fr); }
  .doc-toc { display: none; }
}

@media (max-width: 820px) {
  .doc-mobile-header { display: flex; }
  .doc-shell { grid-template-columns: 1fr; }
  .doc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(320px, 84vw);
    padding: 3rem 1rem 2rem 1.25rem;
    background: var(--card);
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    overflow-y: auto;
  }
  .doc-sidebar.is-open { transform: translateX(0); }
  .doc-sidebar-close { display: inline-flex; }
  .doc-main { padding: 1rem 1.25rem 3rem; }
  .doc-header { margin-bottom: 1.5rem; padding-bottom: 1rem; }
}

.doc-article { max-width: var(--doc-content-max); min-width: 0; }

.doc-header { margin-bottom: 2.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.doc-eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 0.75rem;
}
.doc-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: var(--text-4xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--foreground);
}
.doc-subtitle {
  margin-top: 0.75rem;
  font-size: var(--text-lg);
  color: var(--muted-foreground);
  line-height: 1.55;
}

/* ── Content typography ────────────────────────────── */
.doc-content { font-size: var(--text-base); color: var(--foreground); }
.doc-content > * + * { margin-top: 1.1rem; }
.doc-content h2 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-top: 2.75rem;
  padding-top: 0.5rem;
  scroll-margin-top: calc(var(--doc-nav-h) + 12px);
}
.doc-content h3 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: var(--text-xl);
  font-weight: 600;
  margin-top: 2rem;
  scroll-margin-top: calc(var(--doc-nav-h) + 12px);
}
.doc-content h4 { font-size: var(--text-base); font-weight: 600; margin-top: 1.5rem; }

.doc-content p { line-height: 1.75; color: var(--foreground); }
.doc-content a {
  color: var(--brand);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--brand) 40%, transparent);
  text-underline-offset: 3px;
}
.doc-content a:hover { text-decoration-color: var(--brand); }

.doc-content ul, .doc-content ol { padding-left: 1.5rem; line-height: 1.75; }
.doc-content li + li { margin-top: 0.35rem; }

.doc-content strong { color: var(--foreground); font-weight: 600; }
.doc-content em { font-style: italic; color: var(--foreground); }

.doc-content code:not(pre code) {
  font-family: var(--doc-mono);
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: color-mix(in oklab, var(--brand) 80%, var(--foreground) 20%);
}

.doc-content pre {
  padding: 1rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--doc-mono);
  font-size: 13px;
  line-height: 1.6;
}
.doc-content pre code { color: var(--foreground); background: transparent; border: 0; padding: 0; }

.code-block-wrap {
  position: relative;
}
.code-block-wrap .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--muted-foreground);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: color 120ms;
}
.code-block-wrap .copy-btn:hover { color: var(--foreground); }
.code-block-wrap .copy-btn.is-copied { color: var(--ui-teal); }

.doc-content blockquote {
  border-left: 3px solid var(--brand);
  padding: 0.25rem 0 0.25rem 1rem;
  color: var(--muted-foreground);
}

.doc-content hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.doc-content th, .doc-content td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.doc-content th { color: var(--muted-foreground); font-weight: 600; background: var(--secondary); }

.doc-content kbd {
  display: inline-block;
  font-family: var(--doc-mono);
  font-size: 0.85em;
  padding: 1px 7px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--secondary);
  color: var(--foreground);
  white-space: nowrap;
  line-height: 1.5;
}

.shortcut-table {
  table-layout: auto;
}
.shortcut-table th:first-child, .shortcut-table td:first-child { width: 55%; }
.shortcut-table td:not(:first-child) kbd { min-width: 3.5ch; text-align: center; }

/* ── Search overlay ────────────────────────────────── */
.doc-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12vh;
}
.doc-search-overlay[hidden] { display: none; }

.doc-search-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--background) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.doc-search-modal {
  position: relative;
  width: min(560px, calc(100% - 2rem));
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.doc-search-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted-foreground);
}

.doc-search-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--foreground);
  font-size: var(--text-base);
  font-family: inherit;
  padding: 0;
}

.doc-search-input::placeholder { color: var(--muted-foreground); }

.doc-search-esc {
  padding: 2px 8px;
  font-size: 11px;
  font-family: var(--doc-mono);
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted-foreground);
  cursor: pointer;
}

.doc-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0.4rem 0.5rem;
  min-height: 60px;
}

.doc-search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--foreground);
  text-decoration: none;
}

.doc-search-result:hover,
.doc-search-result.is-focused {
  background: var(--brand-soft);
  color: var(--brand);
}

.doc-search-result-title {
  font-size: var(--text-sm);
  font-weight: 500;
}

.doc-search-result-desc {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.doc-search-result.is-focused .doc-search-result-desc { color: color-mix(in oklab, var(--brand) 60%, var(--muted-foreground)); }

.doc-search-result-group {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin-bottom: 2px;
}

.doc-search-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}

.doc-search-footer {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--muted-foreground);
}
.doc-search-footer kbd {
  padding: 1px 5px;
  font-size: 10px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--doc-mono);
  margin-right: 3px;
}

/* ── Callouts ──────────────────────────────────────── */
.callout {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  background: color-mix(in oklab, var(--card) 60%, transparent);
}
.callout + * { margin-top: 1.1rem; }
.callout-title { font-weight: 600; margin-bottom: 0.35rem; font-size: var(--text-sm); }
.callout-body { color: var(--foreground); font-size: var(--text-sm); line-height: 1.65; }
.callout-body > * + * { margin-top: 0.5rem; }
.callout-body code:not(pre code) { font-size: 0.85em; }

.callout--note    { border-left-color: var(--ui-blue);  }
.callout--note .callout-title  { color: var(--ui-blue); }
.callout--tip     { border-left-color: var(--ui-teal);  }
.callout--tip .callout-title   { color: var(--ui-teal); }
.callout--warning { border-left-color: var(--ui-amber); }
.callout--warning .callout-title { color: var(--ui-amber); }
.callout--danger  { border-left-color: var(--ui-red);   }
.callout--danger .callout-title  { color: var(--ui-red); }

/* ── Pagination ────────────────────────────────────── */
.doc-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.doc-pag-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 120ms, background 120ms;
}
.doc-pag-link:hover { border-color: var(--border-strong); background: var(--secondary); }
.doc-pag-prev { grid-column: 1; }
.doc-pag-next { grid-column: 2; align-items: flex-end; text-align: right; }
.doc-pag-dir { font-size: var(--text-xs); color: var(--muted-foreground); }
.doc-pag-title { font-size: var(--text-sm); font-weight: 600; color: var(--foreground); }

/* ── TOC ───────────────────────────────────────────── */
.doc-toc {
  position: sticky;
  top: calc(var(--doc-nav-h) + 2rem);
  align-self: start;
  max-height: calc(100vh - var(--doc-nav-h) - 4rem);
  overflow-y: auto;
  font-size: var(--text-sm);
}
.doc-toc-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin-bottom: 0.75rem;
}
.doc-toc-list { display: flex; flex-direction: column; gap: 2px; }
.doc-toc-list a {
  display: block;
  padding: 0.25rem 0.6rem;
  border-left: 2px solid transparent;
  color: var(--muted-foreground);
  text-decoration: none;
  line-height: 1.5;
  transition: color 120ms, border-color 120ms;
}
.doc-toc-list a.is-h3 { padding-left: 1.35rem; font-size: 13px; }
.doc-toc-list a:hover { color: var(--foreground); }
.doc-toc-list a.is-active {
  color: var(--brand);
  border-left-color: var(--brand);
}

/* ── Docs home (card grid) ─────────────────────────── */
.doc-home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.doc-home-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  background: color-mix(in oklab, var(--card) 50%, transparent);
  transition: border-color 120ms, background 120ms, transform 120ms;
}
.doc-home-card:hover {
  border-color: var(--brand-tint);
  background: color-mix(in oklab, var(--card) 80%, transparent);
  transform: translateY(-1px);
}
.doc-home-card-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.doc-home-card-desc { color: var(--muted-foreground); font-size: var(--text-sm); }
