/* mgf-common docs explorer — light/clean theme with dark variant.
 * Inspired by Stripe / Linear documentation aesthetics:
 * generous whitespace, clean typography, restrained accent.
 */

:root,
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-code: #f6f8fa;
  --bg-hover: #eef1f4;
  --bg-modal: rgba(31, 35, 40, 0.4);
  --text: #1f2328;
  --text-muted: #57606a;
  --text-dim: #8b949e;
  --border: #d0d7de;
  --border-soft: #e6e8eb;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --accent-text: #ffffff;
  --warn-bg: #fff8c5;
  --warn-text: #7d4e00;
  --kbd-bg: #f6f8fa;
  --kbd-border: #d0d7de;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.04), 0 4px 12px rgba(31, 35, 40, 0.04);
  --shadow-modal: 0 10px 40px rgba(31, 35, 40, 0.2);
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-code: #161b22;
  --bg-hover: #21262d;
  --bg-modal: rgba(0, 0, 0, 0.6);
  --text: #e6edf3;
  --text-muted: #9198a1;
  --text-dim: #6e7681;
  --border: #30363d;
  --border-soft: #21262d;
  --accent: #58a6ff;
  --accent-soft: rgba(56, 139, 253, 0.15);
  --accent-text: #0d1117;
  --warn-bg: #2d2611;
  --warn-text: #d29922;
  --kbd-bg: #161b22;
  --kbd-border: #30363d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 10px 40px rgba(0, 0, 0, 0.6);
}

:root {
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, Monaco,
               Consolas, "Liberation Mono", monospace;
  --header-h: 56px;
  --sidebar-w: 280px;
  --toc-w: 220px;
  --content-max: 880px;
  --content-pad-x: 56px;
  --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern", "liga", "calt";
  text-rendering: optimizeLegibility;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
}

/* ---- Header ---- */

header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
}

.brand { flex-shrink: 0; }

.brand-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.brand-name { font-weight: 600; font-size: 16px; }
.brand-sub { font-size: 13px; color: var(--text-muted); }

.search-wrap {
  flex: 1;
  max-width: 480px;
  position: relative;
}

#search-input {
  width: 100%;
  padding: 8px 14px;
  font-size: 14px;
  font-family: var(--font-body);
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  color: var(--text);
  outline: none;
  transition: border-color 0.1s, background 0.1s;
}

#search-input:focus {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.header-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-soft);
}

/* Sun visible in light mode, moon visible in dark mode. */
:root[data-theme="light"] .icon-moon { display: none; }
:root[data-theme="dark"]  .icon-sun  { display: none; }

/* ---- Search results dropdown ---- */

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px 0;
}

.search-doc {
  border-bottom: 1px solid var(--border-soft);
}

.search-doc:last-child { border-bottom: none; }

.search-doc-header {
  padding: 10px 14px 6px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.search-doc-header:hover,
.search-doc-header.active {
  background: var(--bg-hover);
}

.search-doc-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.search-doc-path {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.search-doc-count {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  font-weight: 500;
}

.search-snippets {
  padding: 0 14px 10px 14px;
}

.search-snippet {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0;
  font-family: var(--font-mono);
  line-height: 1.45;
  padding-left: 10px;
  border-left: 2px solid var(--border-soft);
}

.search-snippet mark {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  padding: 0 2px;
  border-radius: 2px;
}

.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---- Layout ---- */

.layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  flex-shrink: 0;
  width: var(--sidebar-w);
  border-right: 1px solid var(--border-soft);
  background: var(--bg-soft);
  padding: 16px 0;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.sidebar-loading {
  padding: 12px 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.sidebar-group {
  margin-bottom: 6px;
}

.sidebar-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 24px 6px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.05s;
}

.sidebar-group-title:hover { color: var(--text); }

.sidebar-group-caret {
  display: inline-block;
  width: 10px;
  font-size: 10px;
  transition: transform 0.1s;
}

.sidebar-group.collapsed .sidebar-group-caret {
  transform: rotate(-90deg);
}

.sidebar-group-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
  font-weight: normal;
}

.sidebar-group.collapsed .sidebar-group-items,
.sidebar-group.collapsed .sidebar-group-path {
  display: none;
}

.sidebar-group-path {
  padding: 0 24px 4px 24px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  user-select: none;
}

.sidebar-link {
  display: block;
  padding: 6px 24px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast);
}

.sidebar-link:hover { background: var(--bg-hover); }

.sidebar-link.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-link-path {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 1px;
}

/* ---- Main + content ---- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.content {
  flex: 1;
  max-width: var(--content-max);
  padding: 48px var(--content-pad-x) 96px;
  min-width: 0;
  animation: doc-fade-in 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes doc-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Welcome page ---- */

.welcome h1 { margin-top: 0; }

.welcome-section {
  margin-top: 32px;
}

.welcome-section h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px;
  border: none;
  padding: 0;
}

.welcome-paths {
  list-style: none;
  padding: 0;
  margin: 0;
}

.welcome-paths li {
  padding: 12px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  margin-bottom: 8px;
}

.welcome-paths strong {
  color: var(--text);
  margin-right: 6px;
  display: inline-block;
  min-width: 180px;
}

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

.recent-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.recent-list li:last-child { border-bottom: none; }

.recent-list a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.recent-list a:hover { color: var(--accent); }

.recent-path {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-left: 8px;
}

.recent-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.changelog-card {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 4px 20px;
  margin-top: 8px;
}

.changelog-card h3:first-child { margin-top: 14px; }

/* ---- Markdown body styling ---- */

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 600;
  line-height: 1.25;
  margin-top: 28px;
  margin-bottom: 14px;
  scroll-margin-top: calc(var(--header-h) + 12px);
  position: relative;
}

.markdown-body h1 {
  font-size: 28px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 12px;
  margin-top: 0;
}

.markdown-body h2 {
  font-size: 22px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 8px;
  margin-top: 36px;
}

.markdown-body h3 { font-size: 18px; }
.markdown-body h4 { font-size: 16px; }

.heading-anchor {
  position: absolute;
  left: -22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: normal;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
  font-size: 0.85em;
  padding: 0 6px;
}

.markdown-body h1:hover .heading-anchor,
.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor,
.markdown-body h4:hover .heading-anchor {
  opacity: 1;
}

.heading-anchor:hover { color: var(--accent); }

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover { text-decoration: underline; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol {
  margin: 0 0 14px 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 2px 6px;
  background: var(--bg-code);
  border-radius: 4px;
  border: 1px solid var(--border-soft);
}

.markdown-body pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  position: relative;
  margin: 0 0 16px 0;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 9px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s;
  font-family: var(--font-body);
}

.markdown-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--bg-hover); color: var(--text); }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }

.markdown-body table {
  border-collapse: collapse;
  margin: 0 0 16px 0;
  width: 100%;
  font-size: 14px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border-soft);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--bg-soft);
  font-weight: 600;
}

.markdown-body blockquote {
  margin: 0 0 16px 0;
  padding: 0 16px;
  border-left: 4px solid var(--border);
  color: var(--text-muted);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 28px 0;
}

.markdown-body kbd,
.shortcuts kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-radius: 4px;
  box-shadow: inset 0 -1px 0 var(--border);
}

/* ---- Doc-meta strip + nav-footer ---- */

.doc-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-soft);
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 28px;
  border: 1px solid var(--border-soft);
}

.doc-meta-badge {
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doc-meta-sep { color: var(--border); }

.doc-meta-path {
  font-family: var(--font-mono);
  margin-left: auto;
  font-size: 11px;
  opacity: 0.85;
}

/* ---- Status pill (from frontmatter.status) ----
   draft / review / stable get distinct accent colors; anything else
   (archived, deprecated, custom labels) renders in the neutral
   muted palette. Both light and dark themes covered. */

.doc-meta-status {
  font-weight: 600;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.doc-meta-status-draft {
  background: #fff4e6;
  color: #b45309;
  border-color: #fcd9a6;
}

.doc-meta-status-review {
  background: #e6f1ff;
  color: #1758a3;
  border-color: #b3d4f5;
}

.doc-meta-status-stable {
  background: #e7f7ec;
  color: #0f7a3d;
  border-color: #b9e5c8;
}

.doc-meta-status-archived,
.doc-meta-status-deprecated {
  background: var(--bg-hover);
  color: var(--text-muted);
  border-color: var(--border-soft);
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
}

[data-theme="dark"] .doc-meta-status-draft {
  background: rgba(180, 83, 9, 0.18);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.32);
}

[data-theme="dark"] .doc-meta-status-review {
  background: rgba(23, 88, 163, 0.22);
  color: #7eb6ff;
  border-color: rgba(126, 182, 255, 0.32);
}

[data-theme="dark"] .doc-meta-status-stable {
  background: rgba(15, 122, 61, 0.18);
  color: #6ee7a3;
  border-color: rgba(110, 231, 163, 0.32);
}

/* ---- Tag chips (from frontmatter.tags) ----
   Small, monospace, restrained — they're informational, not the
   document's primary identity. Cap-at-6 with "+N more" affordance
   handled in the JS that renders them. */

.doc-meta-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.doc-meta-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
  letter-spacing: 0;
}

.doc-meta-tag-overflow {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-dim);
  background: transparent;
  border-style: dashed;
}

[data-theme="dark"] .doc-meta-tag {
  background: var(--bg-hover);
}

.nav-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
}

.nav-footer-link {
  flex: 1;
  display: block;
  padding: 12px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.1s, background 0.1s;
  min-width: 0;
}

.nav-footer-link:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  text-decoration: none;
}

.nav-footer-link.next { text-align: right; }
.nav-footer-link.disabled { visibility: hidden; }

.nav-footer-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.nav-footer-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- TOC right rail ---- */

.toc {
  flex-shrink: 0;
  width: var(--toc-w);
  padding: 40px 24px 40px 0;
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  font-size: 13px;
}

.toc-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

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

.toc a {
  display: block;
  padding: 3px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: color 0.05s, border-color 0.05s;
}

.toc a:hover { color: var(--text); }

.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.toc .toc-h3 { padding-left: 24px; font-size: 12px; }

/* ---- Modal (keyboard shortcuts) ---- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Author-level `display: flex` above overrides the UA stylesheet's
 * `[hidden] { display: none; }` rule (author beats UA at equal
 * specificity). Without this explicit override, setting
 * `helpModal.hidden = true` in JS doesn't actually hide the modal —
 * the close handler fires but nothing visually happens. */
.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-modal);
  z-index: 1;
}

.modal-panel {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  box-shadow: var(--shadow-modal);
  min-width: 360px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 2;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
}

.modal-close:hover { color: var(--text); background: var(--bg-hover); }

.modal-body { padding: 16px 20px 20px; }

.shortcuts {
  width: 100%;
  border-collapse: collapse;
}

.shortcuts td {
  padding: 6px 8px;
  border: none;
}

.shortcuts td:first-child {
  width: 140px;
  white-space: nowrap;
}

/* ---- Responsive ---- */

@media (max-width: 1100px) {
  .toc { display: none; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 24px 20px 60px; }
  header { padding: 0 16px; gap: 12px; }
  .brand-sub { display: none; }
  .sidebar-toggle { display: none; }
}

/* ---- Sidebar toggle + collapse state ---- */

/* The button shows one of two icons depending on the current sidebar
   state. CSS swaps them; JS only flips a data attribute on <html>. */
.sidebar-toggle .icon-sidebar-closed { display: none; }

:root[data-sidebar="collapsed"] .sidebar-toggle .icon-sidebar-open { display: none; }
:root[data-sidebar="collapsed"] .sidebar-toggle .icon-sidebar-closed { display: inline-block; }

/* When collapsed, the sidebar slides out of the layout entirely.
   The main content gets extra side padding to keep a comfortable
   reading column instead of stretching edge-to-edge. */
:root[data-sidebar="collapsed"] .sidebar {
  display: none;
}

@media (min-width: 1100px) {
  :root[data-sidebar="collapsed"] .content {
    padding-left: max(var(--content-pad-x), calc((100vw - var(--content-max) - var(--toc-w)) / 2));
  }
}

/* ---- Reading-time chip in doc-meta ---- */

.reading-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reading-time::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM8 13A5 5 0 118 3a5 5 0 010 10zm.5-8H7v4l3 2 .75-1.2L8.5 8.3V5z'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM8 13A5 5 0 118 3a5 5 0 010 10zm.5-8H7v4l3 2 .75-1.2L8.5 8.3V5z'/></svg>") center / contain no-repeat;
  opacity: 0.85;
}

/* ---- TOC indent guide polish ---- */

.toc ul ul {
  margin-left: 0;
  padding-left: 0;
  border-left: 1px solid var(--border-soft);
}

.toc ul ul a {
  padding-left: 16px;
}

.toc a {
  border-radius: 0;
  margin: 0;
  padding-block: 4px;
}

.toc a.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

/* ---- Welcome page — grid for path-suggestion cards + bigger hero ---- */

.welcome { max-width: none; }

.welcome h1 {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  border: none;
  padding: 0;
  background: linear-gradient(90deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}

.welcome > p:first-of-type {
  font-size: 17px;
  color: var(--text-muted);
  margin-bottom: 24px;
  max-width: 680px;
}

.welcome-section { margin-top: 40px; }

.welcome-section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 16px;
  border: none;
  padding: 0;
}

.welcome-paths {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.welcome-paths li {
  padding: 16px 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  transition: border-color var(--transition-fast),
              transform var(--transition-fast);
}

.welcome-paths li:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.welcome-paths strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.welcome-paths a {
  color: var(--accent);
  text-decoration: none;
}

.welcome-paths a:hover { text-decoration: underline; }

.recent-list li { padding: 10px 0; }

.recent-list a {
  color: var(--text);
  font-weight: 500;
  transition: color var(--transition-fast);
}

.recent-list a:hover { color: var(--accent); }

/* =====================================================================
 * Print stylesheet — designed for paper, not for ink-jetted webpages.
 *
 * Design intent:
 *   - Reads like a real document, not a screenshot of a webpage.
 *   - Serif body for paper legibility; sans-serif headings for hierarchy
 *     contrast; tabular sans for tables (denser, more rows per page).
 *   - Restrained ornament: hairline rules, no heavy borders, no fills
 *     except a warm off-white on code blocks to keep them distinct.
 *   - Generous whitespace where it pays (above h2/h3, around code) and
 *     compact where it doesn't (lists, table cells).
 *   - Tables: no all-around grid; just a bold header underline + thin
 *     row separators. Header repeats on page break.
 *   - Links: subtle blue, thin underline with offset — readable but not
 *     a sea of underlined text.
 *   - Magogi-specific block: warm brown left rule + small-caps tag, no
 *     fill (saves toner).
 *
 * Forces the light palette regardless of the user's stored theme, so
 * paper output is legible and economical with ink.
 * ===================================================================== */

@media print {
  /* ===== Page setup =====
     A4 with comfortable side margins. The empty `@top-*` / `@bottom-*`
     margin boxes suppress the browser's page-title / URL / page-number
     headers and footers — WHERE THE BROWSER RESPECTS THEM.

     Firefox honours these. Chromium (Chrome/Edge/Brave) currently
     IGNORES margin-box content and instead controls the print
     headers/footers via the print-dialog "Options → Headers and
     footers" checkbox. There is no CSS-only way to suppress those in
     Chromium today — the user must uncheck that option once. */
  @page {
    size: A4;
    margin: 18mm 18mm 20mm 18mm;
    @top-left { content: ""; }
    @top-center { content: ""; }
    @top-right { content: ""; }
    @bottom-left { content: ""; }
    @bottom-center { content: ""; }
    @bottom-right { content: ""; }
  }

  /* ===== Print font system =====
     Body: serif. Reads better than sans at body sizes on paper.
     Headings: sans-serif. Creates clear hierarchy contrast.
     Tables: sans-serif. Tabular numerals + denser per-row footprint.
     Code: monospace stack tuned for print (JetBrains Mono carries thin
     strokes better than SF Mono when printed at 8.5pt). */
  :root,
  :root[data-theme="light"],
  :root[data-theme="dark"] {
    --print-body: "Source Serif 4", "Source Serif Pro", Charter, "Iowan Old Style",
                  "Palatino Linotype", Palatino, "Georgia Pro", Georgia,
                  "Times New Roman", serif;
    --print-display: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont,
                     "Helvetica Neue", Helvetica, Arial, sans-serif;
    --print-mono: "JetBrains Mono", "IBM Plex Mono", "Fira Code", "SF Mono",
                  Menlo, Monaco, Consolas, "Liberation Mono", monospace;

    --print-text: #1a1a1a;
    --print-muted: #5a5a5a;
    --print-dim: #888888;
    --print-rule: #cccccc;
    --print-rule-strong: #1a1a1a;
    --print-link: #1e4a8a;          /* dark blue — readable + classic */
    --print-code-bg: #f7f5ef;       /* warm off-white; survives mono printers as light gray */
    --print-code-border: #d8d3c4;
    --print-magogi: #a35e00;        /* warm brown for the left rule + tag */

    /* Override theme variables too, so leaked declarations also pick up
       print colors instead of dark-mode bg/text. */
    --bg: #ffffff;
    --bg-soft: #ffffff;
    --bg-code: var(--print-code-bg);
    --bg-hover: transparent;
    --text: var(--print-text);
    --text-muted: var(--print-muted);
    --text-dim: var(--print-dim);
    --border: var(--print-rule);
    --border-soft: var(--print-rule);
    --accent: var(--print-link);
    --accent-soft: transparent;
    --shadow: none;
  }

  html, body {
    background: #ffffff !important;
    color: var(--print-text) !important;
    font-family: var(--print-body);
    font-size: 10.5pt;
    line-height: 1.55;
    font-feature-settings: "kern", "liga", "onum";  /* old-style numerals in body */
    /* `economy` = browser may drop backgrounds for ink savings. The user
       can override with the "Background graphics" toggle in the dialog. */
    -webkit-print-color-adjust: economy;
            print-color-adjust: economy;
  }

  /* ===== Hide all app chrome ===== */
  header,
  .sidebar,
  .toc,
  .modal,
  .copy-btn,
  .heading-anchor,
  .nav-footer,
  .search-wrap,
  .search-results,
  .header-actions,
  .icon-btn,
  #help-modal,
  .print-btn,
  .reading-time {
    display: none !important;
  }

  /* ===== Layout reset ===== */
  .layout,
  .main {
    display: block !important;
  }

  .content,
  .markdown-body {
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ===== Title block (the first H1 = document title) =====
     Big sans display weight. Hairline rule above + below to read as a
     proper title block. */
  .markdown-body h1 {
    font-family: var(--print-display);
    font-size: 24pt;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.015em;
    color: #000000 !important;
    margin: 0 0 4pt;
    padding: 0 0 4pt;
    border: none !important;
    page-break-before: avoid;
    page-break-after: avoid;
    break-after: avoid;
  }

  /* ===== Doc-meta strip (status badge + tags + path) =====
     Subtle title-page metadata band: rules above + below, sans, muted. */
  .doc-meta {
    font-family: var(--print-display) !important;
    background: transparent !important;
    border: none !important;
    border-top: 0.5pt solid var(--print-rule) !important;
    border-bottom: 0.5pt solid var(--print-rule) !important;
    border-radius: 0 !important;
    padding: 5pt 0 !important;
    margin: 0 0 16pt !important;
    color: var(--print-muted) !important;
    font-size: 8.5pt;
    page-break-after: avoid;
    break-after: avoid;
    display: flex !important;
    align-items: center;
    gap: 10pt;
  }

  .doc-meta-badge {
    background: transparent !important;
    color: var(--print-text) !important;
    border: none !important;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 !important;
    font-size: 8pt;
  }

  .doc-meta-sep { display: none !important; }

  .doc-meta-path {
    font-family: var(--print-mono) !important;
    margin-left: auto;
    font-size: 8pt;
    color: var(--print-dim) !important;
  }

  /* Status pill (from frontmatter.status) — restrained for print:
     outlined-only, no toner-heavy fill, no color difference between
     draft/review/stable. The label text is enough. */
  .doc-meta-status,
  [class*="doc-meta-status-"] {
    background: transparent !important;
    color: var(--print-text) !important;
    border: 0.5pt solid var(--print-text) !important;
    font-weight: 700 !important;
    font-size: 7.5pt;
    padding: 0.5pt 4pt !important;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-decoration: none !important;
  }

  /* Tag chips — fade to background; small + restrained. */
  .doc-meta-tags {
    font-size: 7.5pt;
    color: var(--print-muted) !important;
  }

  .doc-meta-tag,
  .doc-meta-tag-overflow {
    background: transparent !important;
    border: 0.5pt solid var(--print-rule) !important;
    color: var(--print-muted) !important;
    font-family: var(--print-display) !important;
    padding: 0.5pt 3pt !important;
    font-style: normal !important;
  }

  /* ===== Section headings ===== */
  .markdown-body h2 {
    font-family: var(--print-display);
    font-size: 14.5pt;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.005em;
    color: var(--print-text);
    margin: 22pt 0 8pt;
    padding: 0 0 3pt;
    border: none !important;
    border-bottom: 0.5pt solid var(--print-rule) !important;
    page-break-after: avoid;
    break-after: avoid;
  }

  .markdown-body h3 {
    font-family: var(--print-display);
    font-size: 11.5pt;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.003em;
    color: var(--print-text);
    margin: 16pt 0 5pt;
    page-break-after: avoid;
    break-after: avoid;
  }

  .markdown-body h4 {
    font-family: var(--print-display);
    font-size: 10pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--print-text);
    margin: 12pt 0 4pt;
    page-break-after: avoid;
    break-after: avoid;
  }

  /* ===== Body, lists ===== */
  .markdown-body p {
    margin: 0 0 7pt;
    orphans: 3;
    widows: 3;
  }

  .markdown-body ul,
  .markdown-body ol {
    margin: 0 0 8pt;
    padding-left: 18pt;
  }

  .markdown-body li {
    margin: 2pt 0;
    orphans: 2;
    widows: 2;
  }

  .markdown-body li > p {
    margin: 0 0 3pt;
  }

  .markdown-body li > ul,
  .markdown-body li > ol {
    margin: 3pt 0 4pt;
  }

  /* ===== Links =====
     Dark blue + thin underline with breathing room. */
  .markdown-body a,
  .markdown-body a:visited {
    color: var(--print-link) !important;
    text-decoration: underline;
    text-decoration-thickness: 0.5pt;
    text-underline-offset: 1.5pt;
  }

  /* ===== Inline code ===== */
  .markdown-body code {
    font-family: var(--print-mono);
    background: var(--print-code-bg) !important;
    border: 0.5pt solid var(--print-code-border) !important;
    color: var(--print-text) !important;
    font-size: 0.86em;
    padding: 0.5pt 4pt;
    border-radius: 2pt;
  }

  /* ===== Block code ===== */
  .markdown-body pre {
    font-family: var(--print-mono);
    background: var(--print-code-bg) !important;
    border: 0.5pt solid var(--print-code-border) !important;
    color: var(--print-text) !important;
    font-size: 8.5pt;
    line-height: 1.45;
    padding: 7pt 9pt;
    margin: 7pt 0 10pt;
    border-radius: 3pt;
    page-break-inside: avoid;
    break-inside: avoid;
    overflow: visible !important;
    white-space: pre-wrap;
    word-wrap: break-word;
    /* Tab interpretation — short tabs read better than the 8-wide default. */
    tab-size: 2;
  }

  .markdown-body pre code {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-size: inherit;
    color: inherit !important;
  }

  /* ===== Tables =====
     No outer box, no per-cell grid. Just a strong header underline and
     a thin rule under each row. Sans font + tabular numerals = denser
     content per row, more rows per page. */
  .markdown-body table {
    font-family: var(--print-display);
    font-feature-settings: "tnum", "kern";
    border-collapse: collapse;
    border-spacing: 0;
    margin: 8pt 0 12pt;
    font-size: 9pt;
    width: 100%;
    page-break-inside: auto;
  }

  /* Repeat the header row when a table breaks across pages. */
  .markdown-body thead {
    display: table-header-group;
  }

  .markdown-body th {
    background: transparent !important;
    color: var(--print-text) !important;
    font-weight: 700;
    font-size: 8.5pt;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    padding: 5pt 7pt 4pt 0;
    border: none !important;
    border-bottom: 0.75pt solid var(--print-rule-strong) !important;
    vertical-align: bottom;
  }

  .markdown-body td {
    padding: 4pt 7pt 4pt 0;
    border: none !important;
    border-bottom: 0.25pt solid var(--print-rule) !important;
    vertical-align: top;
    color: var(--print-text) !important;
  }

  .markdown-body tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Code inside table cells: shrink slightly so wrapping doesn't bloat
     row height. */
  .markdown-body td code,
  .markdown-body th code {
    font-size: 0.92em;
    padding: 0 3pt;
  }

  /* ===== Blockquote =====
     Italic body, thin left rule. */
  .markdown-body blockquote {
    margin: 8pt 0 10pt;
    padding-left: 12pt;
    border-left: 1pt solid var(--print-rule) !important;
    color: var(--print-muted) !important;
    font-style: italic;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .markdown-body blockquote p {
    margin-bottom: 4pt;
  }

  /* ===== Horizontal rule =====
     Hairline. Spacing above + below matched. */
  .markdown-body hr {
    border: none !important;
    border-top: 0.5pt solid var(--print-rule) !important;
    margin: 18pt 0;
  }

  /* ===== kbd ===== */
  .markdown-body kbd {
    font-family: var(--print-mono);
    background: var(--print-code-bg) !important;
    border: 0.5pt solid var(--print-code-border) !important;
    color: var(--print-text) !important;
    box-shadow: none !important;
    font-size: 8.5pt;
    padding: 0.5pt 4pt;
    border-radius: 2pt;
  }

  /* ===== Magogi-specific addendum =====
     Restrained for print: warm-brown left rule + small-caps tag, no fill.
     (No-op where .magogi-specific isn't used; harmless.) */
  .markdown-body .magogi-specific {
    background: transparent !important;
    border: none !important;
    border-left: 1.5pt solid var(--print-magogi) !important;
    border-radius: 0 !important;
    padding: 4pt 0 4pt 14pt !important;
    margin: 18pt 0 !important;
    page-break-inside: auto;
  }

  .markdown-body .magogi-specific::before {
    content: "Magogi-specific";
    display: block;
    background: transparent !important;
    color: var(--print-magogi) !important;
    border: none !important;
    font-family: var(--print-display);
    font-size: 8pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 !important;
    margin: 0 0 6pt !important;
    border-radius: 0;
  }

  .markdown-body .magogi-specific h2,
  .markdown-body .magogi-specific h3 {
    color: var(--print-text) !important;
    border-bottom: 0.5pt solid var(--print-rule) !important;
  }

  /* ===== Images ===== */
  .markdown-body img {
    max-width: 100% !important;
    height: auto !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* ===== Belt + braces: catch any remaining theme leakage =====
     If anything we haven't explicitly styled still carries a dark-mode
     bg, make sure it doesn't bleed onto paper. */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }
}
