:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1f2328;
  --text-muted: #5b6470;
  --border: #e6e3dc;
  --code-bg: #f3f1ec;
  --accent: #b8521a;
  --accent-soft: #fbe9dc;
  --diagram-bg: #f9f9f7;
  --max-content: 760px;
  --sidebar-w: 240px;
  --break: 820px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

body {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 4rem;
}

.sidebar__home {
  display: block;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  color: var(--text);
  text-decoration: none;
  padding: .4rem .6rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  border-left: 3px solid transparent;
}
.sidebar__home:hover { background: var(--accent-soft); }
.sidebar__home.is-active,
.sidebar__home[aria-current="page"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.sidebar__list { list-style: none; padding: 0; margin: 0; }
.sidebar__list li { margin: .15rem 0; }
.sidebar__list a {
  display: block;
  padding: .4rem .6rem;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 0 4px 4px 0;
  font-size: .94rem;
  line-height: 1.4;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.sidebar__list a:hover { background: var(--accent-soft); color: var(--text); }
.sidebar__list a.is-active,
.sidebar__list a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 500;
}

.content {
  max-width: var(--max-content);
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  /* grid items default to min-width: auto (= min-content). Long unbreakable
     code lines would force the column wider than the viewport. Pin to 0 so
     children must scroll inside themselves instead of busting the layout. */
  min-width: 0;
}

.prev-next {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: .92rem;
  min-height: 1.5em;
}
.prev-next__link {
  color: var(--accent);
  text-decoration: none;
  padding: .4rem .6rem;
  border-radius: 4px;
  transition: background-color .12s ease;
  max-width: 48%;
}
.prev-next__link:hover { background: var(--accent-soft); }
.prev-next__placeholder { display: inline-block; }
.prev-next--top {
  border-bottom: 1px solid var(--border);
  padding-bottom: .75rem;
  margin: 0 0 1.5rem;
}
.prev-next--bottom {
  border-top: 1px solid var(--border);
  padding-top: .75rem;
  margin: 2.5rem 0 0;
}

.nav-toggle {
  display: none;
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .65rem;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}

h1 {
  border-bottom: 1px solid var(--border);
  padding-bottom: .35rem;
  letter-spacing: -.01em;
  margin-top: 0;
}
h2 { margin-top: 2rem; letter-spacing: -.005em; }
.meta { color: var(--text-muted); font-size: .9rem; }

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

code {
  background: var(--code-bg);
  color: var(--text);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: .92em;
  font-family: var(--font-mono);
}
:not(pre) > code[class*="language-"] {
  background: var(--code-bg);
  color: var(--text);
  padding: 1px 5px;
}

pre.diagram {
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: .9rem;
  line-height: 1.4;
  font-family: var(--font-mono);
  background: var(--diagram-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

figure.diagram {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--diagram-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
figure.diagram svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}
figure.diagram figcaption {
  margin-top: .75rem;
  font-size: .85rem;
  color: var(--text-muted);
  text-align: left;
  line-height: 1.5;
}
pre[class*="language-"] {
  font-size: .9rem;
  line-height: 1.4;
  border-radius: 6px;
  max-width: 100%;
  overflow-x: auto;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 15;
    width: min(280px, 80vw);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .25);
    z-index: 10;
  }

  .nav-toggle { display: inline-block; }
  .content { padding-top: 3.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
