:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: rgba(255, 252, 245, 0.92);
  --surface-strong: #fffaf1;
  --ink: #1f1b17;
  --muted: #6b6258;
  --line: rgba(31, 27, 23, 0.12);
  --accent: #0d5f52;
  --accent-soft: rgba(13, 95, 82, 0.08);
  --code: #f3eee4;
  --overlay: rgba(18, 20, 24, 0.82);
  --shadow: rgba(31, 27, 23, 0.08);
}
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --surface: rgba(23, 28, 32, 0.9);
  --surface-strong: #1a2126;
  --ink: #f3efe7;
  --muted: #b6ada1;
  --line: rgba(243, 239, 231, 0.12);
  --accent: #72cbb9;
  --accent-soft: rgba(114, 203, 185, 0.12);
  --code: #20262c;
  --overlay: rgba(3, 6, 10, 0.9);
  --shadow: rgba(0, 0, 0, 0.3);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(13,95,82,0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(176,109,47,0.12), transparent 22%),
    linear-gradient(180deg, #f7f1e7 0%, #f1e8db 100%);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
}
.theme-toggle {
  position: fixed;
  right: 20px;
  top: 18px;
  z-index: 40;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 16px 40px var(--shadow);
}
.site-nav, .content-shell {
  background: var(--surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 16px 40px var(--shadow);
}
.site-nav {
  position: sticky;
  top: 24px;
  align-self: start;
  padding: 20px 18px;
}
.site-nav-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.site-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.site-nav li {
  margin: 0;
  color: var(--muted);
}
.site-nav li.group {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.site-nav li a {
  display: block;
  padding: 7px 10px;
  border-radius: 10px;
}
.site-nav li.current a,
.site-nav li a:hover {
  background: var(--accent-soft);
  text-decoration: none;
}
.content-shell {
  overflow: hidden;
}
.content-header {
  padding: 28px 34px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,250,241,0.96), rgba(255,250,241,0.72));
}
.content-header .eyebrow {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.content-header h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1.05;
}
.content-body {
  padding: 10px 34px 40px;
  font-size: 1.03rem;
  line-height: 1.72;
}
.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4 { line-height: 1.15; margin-top: 1.6em; }
.content-body p,
.content-body ul,
.content-body ol,
.content-body blockquote,
.content-body table,
.content-body pre { margin: 1em 0; }
.content-body code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  background: var(--code);
  padding: 0.15em 0.35em;
  border-radius: 6px;
  font-size: 0.94em;
}
.content-body pre {
  background: #1d232a;
  color: #f3f5f7;
  padding: 16px;
  border-radius: 16px;
  overflow-x: auto;
}
.content-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.content-body blockquote {
  padding: 14px 18px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
}
.content-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.96rem;
}
.content-body th,
.content-body td {
  border: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
.content-body th {
  background: var(--surface-strong);
}
.content-body img { max-width: 100%; }
.content-body img,
.content-body .mermaid {
  cursor: zoom-in;
}
.diagram-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: var(--overlay);
}
.diagram-overlay.open {
  display: flex;
}
.diagram-overlay-panel {
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  overflow: auto;
  padding: 20px;
  background: var(--surface-strong);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px var(--shadow);
}
.diagram-overlay-panel img,
.diagram-overlay-panel svg {
  max-width: 100%;
  height: auto;
}
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .site-nav {
    position: static;
  }
  .content-header,
  .content-body {
    padding-left: 22px;
    padding-right: 22px;
  }
}
