:root {
  --bg: #eef1f4;
  --paper: #fbfcfd;
  --ink: #1a1f27;
  --muted: #5c6775;
  --line: #d5dbe3;
  --accent: #0f6e6a;
  --accent-soft: #d8efed;
  --sidebar: #141a22;
  --sidebar-ink: #d7dee8;
  --sidebar-muted: #8b97a8;
  --code-bg: #f0f3f7;
  --diagram-bg: #f7f9fb;
  --shadow: 0 18px 50px rgba(20, 30, 40, 0.08);
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Manrope", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.7;
}

.shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 1.5rem 1.1rem 2rem;
}

.brand {
  display: block;
  color: #fff;
  text-decoration: none;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-sub {
  margin: 0.35rem 0 1.4rem;
  color: var(--sidebar-muted);
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.4;
}

.toc { display: flex; flex-direction: column; gap: 0.15rem; }
.toc a {
  color: var(--sidebar-ink);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.86rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  line-height: 1.35;
}
.toc a:hover { background: rgba(255,255,255,0.06); }
.toc a.active { background: var(--accent); color: #fff; }
.toc .part {
  margin: 1rem 0 0.35rem;
  padding: 0 0.55rem;
  color: var(--sidebar-muted);
  font-family: var(--sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
}
.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.chapter {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 2.2rem 2.4rem 2.6rem;
  box-shadow: var(--shadow);
}

.chapter h1 {
  font-family: var(--sans);
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin: 0 0 1.2rem;
}
.chapter h2 {
  font-family: var(--sans);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  margin: 2.2rem 0 0.8rem;
  padding-top: 0.4rem;
}
.chapter h3 {
  font-family: var(--sans);
  font-size: 1.08rem;
  margin: 1.6rem 0 0.55rem;
}

.chapter p { margin: 0.85rem 0; }
.chapter li { margin: 0.25rem 0; }
.chapter blockquote {
  margin: 1.2rem 0;
  padding: 0.2rem 0 0.2rem 1rem;
  border-left: 3px solid var(--accent);
  color: #243040;
  font-style: italic;
}
.chapter hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2rem 0;
}

.chapter table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.95rem;
  margin: 1.1rem 0 1.4rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(20, 30, 40, 0.03);
}
.chapter th, .chapter td {
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 0.85rem;
  text-align: left;
  vertical-align: top;
}
.chapter tr:last-child td { border-bottom: 0; }
.chapter th {
  background: var(--accent-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #163a38;
}
.chapter td:first-child {
  font-family: var(--sans);
  font-weight: 600;
  color: #243040;
  width: 42%;
}
.chapter table + p,
.chapter p + table { margin-top: 1rem; }

.chapter code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.chapter pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  overflow: auto;
  font-size: 0.86rem;
  line-height: 1.5;
}
.chapter pre code { background: transparent; padding: 0; }

.chapter pre.diagram {
  background: var(--diagram-bg);
  border: 1px dashed #b7c2cf;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #2a3441;
}

.chapter img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.2rem auto;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.75rem;
}

.chapter .mermaid {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  margin: 1.2rem 0;
  overflow: auto;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.25rem;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.pager a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.pager a:hover { text-decoration: underline; }

/* Home */
body.home { background: linear-gradient(165deg, #e8eef2 0%, #f7fafb 45%, #e7f2f1 100%); }
.hero {
  max-width: 880px;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 2rem;
}
.eyebrow {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--accent);
  margin: 0 0 0.8rem;
}
.hero h1 {
  font-family: var(--sans);
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 0 0 1rem;
}
.lede {
  max-width: 34rem;
  font-size: 1.2rem;
  color: var(--muted);
  margin: 0 0 1.5rem;
}
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-family: var(--sans);
  font-weight: 700;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
}
.index {
  max-width: 880px;
  margin: 0 auto 3rem;
  padding: 0 1.5rem;
  display: grid;
  gap: 0.55rem;
}
.index-part {
  margin: 1.6rem 0 0.4rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.index-card {
  display: block;
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 600;
  transition: transform .15s ease, border-color .15s ease;
}
.index-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}
.site-footer {
  text-align: center;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 1rem 1rem 2.5rem;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 20;
    transform: translateX(-105%);
    transition: transform .2s ease;
    width: min(86vw, 320px);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .menu-btn { display: inline-block; }
  .chapter { padding: 1.4rem 1.1rem 2rem; border-radius: 14px; }
  body { font-size: 17px; }
}
