:root {
  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --bg-code: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --accent: #1e4a6b;
  --accent-soft: #e0f2fe;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 880px);
  gap: 38px;
  max-width: 1220px;
  margin: 0 auto;
  padding: 32px 24px 72px;
}

nav.toc {
  position: sticky;
  top: 24px;
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 13.2px;
}

nav.toc .toc-title {
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px 0;
}

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

nav.toc ul ul {
  padding-left: 12px;
  margin: 2px 0 6px;
}

nav.toc li { margin: 4px 0; }

nav.toc a {
  color: var(--text);
  text-decoration: none;
  display: block;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1.38;
}

nav.toc a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

main { min-width: 0; }

header.doc-header {
  border-bottom: 2px solid var(--accent);
  padding-bottom: 18px;
  margin-bottom: 28px;
}

header.doc-header h1 {
  margin: 0 0 8px 0;
  font-size: 27px;
  line-height: 1.25;
}

header.doc-header .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

h2 {
  margin: 40px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 21px;
  color: var(--accent);
  scroll-margin-top: 20px;
}

h3 {
  margin: 24px 0 10px;
  font-size: 16.5px;
  color: var(--text);
  scroll-margin-top: 20px;
}

p { margin: 10px 0; }
ul, ol { margin: 10px 0; padding-left: 24px; }
li { margin: 6px 0; }

a { color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: 0.89em;
  background: var(--bg-code);
  padding: 1.5px 5px;
  border-radius: 4px;
}

pre {
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.48;
  margin: 14px 0;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  font-size: 14.5px;
}

blockquote p { margin: 4px 0; }

figure {
  margin: 20px 0;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  text-align: center;
}

figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

figcaption {
  margin-top: 10px;
  font-size: 13.2px;
  color: var(--text-muted);
  line-height: 1.45;
}

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

th, td {
  border: 1px solid var(--border-light);
  padding: 8px 11px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--bg-alt);
  font-weight: 600;
}

tbody tr:nth-child(even) { background: #fcfdff; }

math[display="block"] {
  margin: 14px auto;
  padding: 8px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow-x: auto;
}

hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 26px 0;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 20px 16px 48px;
  }
  nav.toc {
    position: static;
    max-height: none;
  }
}

@media print {
  .layout { display: block; max-width: none; padding: 0; }
  nav.toc { display: none; }
  h2, h3 { break-after: avoid; }
  table, pre, figure { break-inside: avoid; }
}
