/* --------------------------------------------------------------------
 * NODX docs site — single hand-written stylesheet.
 * Light/dark via prefers-color-scheme, manual override via [data-theme].
 * No external fonts, no external CSS, no build step.
 * ------------------------------------------------------------------ */

:root {
  --bg:          #fbfaf7;
  --bg-soft:     #f1efe9;
  --bg-elev:    #ffffff;
  --text:        #1a1a1c;
  --muted:       #5a5a63;
  --rule:        #d9d4ca;
  --rule-strong: #c5bfb1;
  --accent:      #0f766e;
  --accent-soft: #d6f0ec;
  --warn:        #b45309;
  --code-bg:     #f3f0e8;
  --code-text:   #1a1a1c;
  --link:        #0a5f57;

  --radius:      8px;
  --radius-lg:   14px;
  --gap:         1rem;
  --sidebar-w:   260px;
  --outline-w:   220px;

  --serif: ui-serif, "Iowan Old Style", "Apple Garamond", Cambria, "Times New Roman", Times, serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #14171a;
    --bg-soft:     #1c2024;
    --bg-elev:     #22272c;
    --text:        #e8e6df;
    --muted:       #9aa0a6;
    --rule:        #2a2f35;
    --rule-strong: #3a4047;
    --accent:      #5ed3c4;
    --accent-soft: #1e3530;
    --warn:        #d59060;
    --code-bg:     #1b1f23;
    --code-text:   #e8e6df;
    --link:        #7be3d3;
  }
}

[data-theme="dark"] {
  --bg:          #14171a;
  --bg-soft:     #1c2024;
  --bg-elev:     #22272c;
  --text:        #e8e6df;
  --muted:       #9aa0a6;
  --rule:        #2a2f35;
  --rule-strong: #3a4047;
  --accent:      #5ed3c4;
  --accent-soft: #1e3530;
  --warn:        #d59060;
  --code-bg:     #1b1f23;
  --code-text:   #e8e6df;
  --link:        #7be3d3;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; text-underline-offset: 2px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- Skip link ---------------- */
.skip-link {
  position: absolute; left: -1000px; top: 0;
  background: var(--accent); color: var(--bg-elev);
  padding: 0.5rem 1rem; border-radius: 0 0 var(--radius) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: saturate(180%) blur(12px);
}
.topbar__inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--text); font-weight: 700; font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  display: inline-block;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  flex-shrink: 0;
}
.brand__tag {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.topnav {
  margin-left: auto;
  display: flex; gap: 1.25rem;
  font-size: 0.95rem;
}
.topnav a { color: var(--text); }
.topnav a.is-active { color: var(--accent); }
.topnav__github::after { content: " ↗"; color: var(--muted); }

.theme-toggle, .nav-toggle {
  background: none; border: 1px solid var(--rule);
  border-radius: var(--radius);
  width: 36px; height: 36px;
  font-size: 1rem; color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover, .nav-toggle:hover { background: var(--bg-soft); }
.nav-toggle { display: none; }

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

/* ---------------- Sidebar ---------------- */
.sidebar {
  position: sticky; top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 1.5rem 1rem 2rem 0;
  border-right: 1px solid var(--rule);
}
.sidebar nav h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1.25rem 0 0.4rem;
  font-weight: 600;
}
.sidebar nav ol {
  list-style: none; padding: 0; margin: 0;
}
.sidebar nav li { margin: 0; }
.sidebar nav a {
  display: block;
  padding: 0.35rem 0.6rem;
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.sidebar nav a:hover { background: var(--bg-soft); text-decoration: none; }
.sidebar nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.search { position: relative; margin-bottom: 0.4rem; }
.search input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search__results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  list-style: none; padding: 4px; margin: 0;
  max-height: 360px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  z-index: 40;
}
.search__results li { margin: 0; }
.search__results a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.92rem;
}
.search__results a:hover, .search__results a.is-active {
  background: var(--bg-soft);
  text-decoration: none;
}
.search__results small { color: var(--muted); display: block; margin-top: 2px; }

/* ---------------- Content ---------------- */
.content {
  padding: 2rem 2.25rem;
  min-width: 0;
}
.prose {
  max-width: 820px;
  margin: 0 auto;
  font-size: 1.02rem;
}
.prose h1 {
  font-family: var(--serif);
  font-size: 2rem;
  line-height: 1.2;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
}
.prose h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  margin: 2.4rem 0 0.8rem;
  border-top: 1px solid var(--rule);
  padding-top: 1.6rem;
}
.prose h3 {
  font-size: 1.15rem;
  margin: 1.8rem 0 0.6rem;
}
.prose h4 { font-size: 1rem; margin: 1.4rem 0 0.4rem; }
.prose p { margin: 0.8rem 0; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.2rem 0; }
.prose code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 1px 5px;
  border: 1px solid var(--rule);
}
.prose pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.55;
  margin: 1rem 0;
}
.prose pre code { background: transparent; padding: 0; border: 0; }

.prose blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: 1rem 0;
  padding: 0.7rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text);
}
.prose blockquote p:first-child { margin-top: 0; }
.prose blockquote p:last-child { margin-bottom: 0; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.94rem;
}
.prose th, .prose td {
  border-bottom: 1px solid var(--rule);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.prose th {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--rule-strong);
  font-weight: 600;
}
.prose tbody tr:hover { background: var(--bg-soft); }

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

.prose .anchor {
  margin-left: 0.4rem;
  color: var(--muted);
  opacity: 0;
  font-size: 0.85em;
  transition: opacity 0.15s ease;
}
.prose h1:hover .anchor,
.prose h2:hover .anchor,
.prose h3:hover .anchor,
.prose h4:hover .anchor { opacity: 1; }

/* ---------------- Pager ---------------- */
.pager {
  max-width: 820px;
  margin: 3rem auto 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--rule);
  padding-top: 1.5rem;
}
.pager a {
  display: inline-flex; flex-direction: column;
  padding: 0.7rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  max-width: 45%;
  font-size: 0.85rem;
  color: var(--muted);
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a span {
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  margin-top: 2px;
}
.pager__next { text-align: right; margin-left: auto; }

.content__footer {
  max-width: 820px; margin: 3rem auto 0;
  border-top: 1px solid var(--rule);
  padding-top: 1.5rem;
  color: var(--muted); font-size: 0.9rem;
}
.content__meta { display: flex; justify-content: space-between; gap: 1rem; }

/* ---------------- Outline ---------------- */
.outline {
  position: sticky; top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 2rem 0 2rem 1.5rem;
  font-size: 0.9rem;
}
.outline__title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.6rem;
  font-weight: 600;
}
.outline ol {
  list-style: none; padding: 0; margin: 0;
  border-left: 1px solid var(--rule);
}
.outline li[data-level="3"] { padding-left: 1rem; }
.outline li[data-level="4"] { padding-left: 2rem; }
.outline a {
  display: block;
  padding: 0.2rem 0 0.2rem 0.75rem;
  color: var(--muted);
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.outline a:hover, .outline a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  text-decoration: none;
}

/* ---------------- Landing hero (home) ---------------- */
.hero {
  max-width: 820px; margin: 0 auto 2rem;
  text-align: left;
  padding: 0;
}
.hero h1 {
  font-family: var(--serif);
  font-size: 2.6rem;
  line-height: 1.1;
  margin: 0 0 0.6rem;
  letter-spacing: -0.02em;
}
.hero .hero__lede {
  font-size: 1.2rem;
  color: var(--muted);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}
.hero__cta {
  display: flex; flex-wrap: wrap; gap: 0.6rem;
  margin: 1rem 0 2rem;
}
.cta-primary, .cta-ghost {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  border: 1px solid var(--accent);
  font-size: 0.95rem;
}
.cta-primary { background: var(--accent); color: var(--bg); }
.cta-primary:hover { background: var(--link); text-decoration: none; }
.cta-ghost { color: var(--accent); background: transparent; }
.cta-ghost:hover { background: var(--accent-soft); text-decoration: none; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  max-width: 820px;
  margin: 0 auto 2.5rem;
}
.feature {
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  background: var(--bg-elev);
}
.feature h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.feature p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.code-tabs {
  max-width: 820px;
  margin: 0 auto 2rem;
}
.code-tabs h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  margin: 2.2rem 0 0.6rem;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .outline { display: none; }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: 0 1rem; }
  .sidebar {
    position: fixed;
    top: 56px; left: 0; right: 0; bottom: auto;
    background: var(--bg);
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    max-height: 60vh;
    transform: translateY(-110%);
    transition: transform 0.18s ease;
    padding: 1rem 1rem 1.5rem;
    z-index: 30;
    height: auto;
  }
  body.nav-open .sidebar { transform: translateY(0); }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topnav { display: none; }
  .content { padding: 1.25rem 0.5rem 2rem; }
}

/* ---------------- Misc ---------------- */
.tag {
  display: inline-block;
  padding: 1px 8px;
  font-size: 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  color: var(--muted);
  background: var(--bg-soft);
}
.tag-enforced { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.tag-reserved { color: var(--warn); border-color: var(--warn); background: transparent; }
