:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-subtle: #f0f2f4;
  --text: #17202a;
  --muted: #5b6673;
  --line: #d7dce1;
  --line-strong: #aeb6bf;
  --accent: #245c8a;
  --accent-soft: #e9f1f7;
  --warning: #8a4d16;
  --warning-bg: #fff6e9;
  --code-bg: #111820;
  --code-text: #e7edf3;
  --max: 1120px;
  --sidebar: 222px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 20px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--accent); }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
code {
  padding: .08em .28em;
  border-radius: 3px;
  background: var(--surface-subtle);
  color: #23465f;
  font-size: .9em;
}
pre code { padding: 0; color: inherit; background: none; }
.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 9px 13px;
  transform: translateY(-160%);
  background: var(--text);
  color: white;
}
.skip-link:focus { transform: none; }

.nav-toggle {
  display: none;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

.layout {
  max-width: calc(var(--max) + var(--sidebar) + 48px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, var(--max));
  gap: 48px;
  padding: 0 24px;
}
.sidebar { position: relative; }
.sidebar nav {
  position: sticky;
  top: 28px;
  padding: 14px 0;
}
.sidebar nav p {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.sidebar nav a {
  display: block;
  padding: 6px 10px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
.sidebar nav a:hover,
.sidebar nav a.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

main { min-width: 0; }
section {
  padding: 76px 0;
  border-bottom: 1px solid var(--line);
}
.intro { padding-top: 86px; }
.eyebrow {
  margin: 0 0 9px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
h1, h2, h3, h4 { line-height: 1.25; }
h1 {
  max-width: 900px;
  margin: 0 0 24px;
  font-size: clamp(36px, 5vw, 62px);
  letter-spacing: -.035em;
}
h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -.025em;
}
h3 { margin: 38px 0 14px; font-size: 20px; }
h4 { margin: 0 0 6px; font-size: 15px; }
p { margin: 0 0 14px; }
.lead {
  max-width: 900px;
  color: #35414c;
  font-size: 19px;
  line-height: 1.65;
}
.intro-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 44px 0;
  border: 1px solid var(--line);
  background: var(--line);
}
.intro-grid article { padding: 24px; background: var(--surface); }
.intro-grid h2 { margin: 0 0 9px; font-size: 16px; }
.intro-grid p { margin: 0; color: var(--muted); font-size: 13px; }
.mental-model {
  padding: 24px 26px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
}
.mental-model h2 { margin-bottom: 8px; font-size: 18px; }
.mental-model p { margin: 0; }
.facts {
  margin: 36px 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.facts div { padding: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.facts dd { margin: 3px 0 0; font-size: 13px; font-weight: 600; }

.section-heading { max-width: 860px; margin-bottom: 38px; }
.section-heading > p:last-child { max-width: 760px; margin: 13px 0 0; color: var(--muted); font-size: 16px; }
.path-list { border-top: 1px solid var(--line-strong); }
.path-list > div {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 25px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.path-list p { margin: 0; color: var(--muted); }

.diagram-shell {
  margin: 26px 0 38px;
  padding: 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
}
.diagram-shell > h3 { margin: 0 0 12px; font-size: 15px; }
.diagram-shell .mermaid {
  min-width: 660px;
  margin: 0;
  padding: 22px;
  border-radius: 3px;
  background: #f8fafb;
  color: #35414c;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.55;
}
.diagram-shell svg { display: block; max-width: 100%; height: auto; margin: auto; }
.diagram-source {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.diagram-source summary { padding-top: 10px; cursor: pointer; }
.diagram-source pre {
  padding: 14px;
  overflow: auto;
  background: var(--code-bg);
  color: var(--code-text);
  white-space: pre-wrap;
}
.diagram-note { margin-top: 10px; color: var(--warning); }
.diagram-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.diagram-grid .diagram-shell { min-width: 0; margin-top: 0; }

.table-wrap {
  width: 100%;
  margin: 26px 0 38px;
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}
caption {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}
th, td {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child > * { border-bottom: 0; }
thead th {
  background: var(--surface-subtle);
  color: #414c57;
  font-size: 11px;
  letter-spacing: .035em;
  text-transform: uppercase;
}
tbody th { min-width: 145px; }
td code, th code { overflow-wrap: anywhere; }
td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}
.fn-row[hidden] { display: none; }

.workflow-steps {
  margin: 34px 0;
  padding: 0;
  list-style: none;
  counter-reset: workflow;
}
.workflow-steps li {
  position: relative;
  padding: 20px 18px 20px 72px;
  border-top: 1px solid var(--line);
  counter-increment: workflow;
}
.workflow-steps li:last-child { border-bottom: 1px solid var(--line); }
.workflow-steps li::before {
  content: counter(workflow, decimal-leading-zero);
  position: absolute;
  left: 17px;
  top: 22px;
  color: var(--accent);
  font: 700 12px "SFMono-Regular", Consolas, monospace;
}
.workflow-steps h3 { margin: 0 0 5px; font-size: 16px; }
.workflow-steps p { margin: 0; color: var(--muted); }
.workflow-steps .source { margin-top: 6px; font-size: 12px; }

.rule-list,
.boundary-notes,
.tool-contract-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.rule-list article,
.boundary-notes article,
.tool-contract-grid article {
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.rule-list p,
.boundary-notes p,
.tool-contract-grid p { margin: 0; color: var(--muted); font-size: 13px; }
.tool-contract-grid h3 { margin-top: 0; font-size: 16px; }

.function-tools {
  position: sticky;
  z-index: 30;
  top: 0;
  padding: 13px;
  border: 1px solid var(--line);
  background: rgba(245,246,247,.96);
  backdrop-filter: blur(8px);
}
.function-tools label { display: block; margin-bottom: 5px; font-size: 11px; font-weight: 700; }
.function-tools input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface);
  color: var(--text);
}
.function-tools p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.function-group {
  margin-top: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.function-group > summary {
  padding: 16px 18px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
}
.function-group > summary span {
  margin-right: 8px;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.function-group .table-wrap { margin: 0; border-width: 1px 0 0; }
.function-group table { min-width: 880px; table-layout: fixed; }
.function-group th:nth-child(1) { width: 24%; }
.function-group th:nth-child(2) { width: 20%; }
.function-group th:nth-child(3) { width: 23%; }
.function-group th:nth-child(4) { width: 33%; }
.function-group.filtered-empty { display: none; }

.command-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.command-grid article {
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.command-grid h3 { margin: 0 0 12px; font-size: 15px; }
.command-grid p { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
pre {
  margin: 18px 0;
  padding: 18px;
  overflow: auto;
  border-radius: 3px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 12px;
  line-height: 1.6;
}
.command-grid pre { margin: 0; }
.notice {
  margin: 18px 0;
  padding: 15px 17px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-size: 13px;
}
.notice.warning { border-color: var(--warning); background: var(--warning-bg); color: #5c3c1f; }
.recovery-steps { padding-left: 22px; }
.recovery-steps li { margin: 8px 0; padding-left: 5px; }
.checklist { padding: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
.checklist li { position: relative; padding: 10px 10px 10px 32px; border-bottom: 1px solid var(--line); }
.checklist li::before { content: "□"; position: absolute; left: 7px; color: var(--accent); }

.evidence { font-size: 13px; color: var(--muted); }
.evidence h2 { color: var(--text); font-size: 28px; }
.evidence ul { padding-left: 20px; }
footer {
  padding: 34px 0 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
footer p { margin: 0; }
footer a { font-weight: 600; text-decoration: none; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .sidebar { position: sticky; z-index: 45; top: 0; padding-top: 8px; background: rgba(245,246,247,.96); }
  .sidebar nav {
    display: none;
    position: static;
    max-height: calc(100vh - 46px);
    padding: 12px;
    overflow: auto;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }
  .sidebar nav.open { display: block; }
  .nav-toggle { display: block; }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .layout { padding-right: 16px; padding-left: 16px; }
  section { padding: 58px 0; }
  .intro { padding-top: 58px; }
  h1 { font-size: 36px; }
  .lead { font-size: 17px; }
  .intro-grid, .facts, .diagram-grid, .rule-list, .boundary-notes, .tool-contract-grid, .command-grid, .checklist { grid-template-columns: 1fr; }
  .facts { border-left: 0; }
  .facts div { border-left: 1px solid var(--line); }
  .path-list > div { grid-template-columns: 1fr; gap: 5px; }
  .diagram-shell { padding: 10px; }
  .diagram-shell .mermaid { min-width: 560px; padding: 14px; }
  th, td { padding: 10px 11px; }
  footer { align-items: flex-start; gap: 18px; flex-direction: column; }
}

@media print {
  body { background: white; font-size: 10pt; }
  .sidebar, .function-tools, .skip-link { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  section { break-inside: auto; padding: 24px 0; }
  .function-group { break-inside: avoid; }
  .function-group > summary { list-style: none; }
  .diagram-shell, .table-wrap, article { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}


/* Tool mechanism chapter */
.tool-index { margin: 24px 0 32px; }
.tool-index td:first-child { white-space: nowrap; }
.tool-index a { font-weight: 700; }
.tool-detail { margin: 18px 0; padding: 24px; border: 1px solid var(--line); background: var(--surface); }
.tool-detail > h3 { margin: 0 0 8px; }
.tool-meta { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 18px; }
.tool-meta span { padding: 3px 7px; border: 1px solid var(--line); border-radius: 2px; color: var(--muted); font: 600 10px "SFMono-Regular", Consolas, monospace; text-transform: uppercase; letter-spacing: .04em; }
.tool-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 28px; }
.tool-columns h4 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tool-columns h4:first-child { margin-top: 0; }
.tool-columns p, .tool-columns li { color: var(--muted); font-size: 13px; }
.tool-columns p { margin: 0; }
.mechanism { margin: 0; padding: 0; list-style: none; counter-reset: mechanism; }
.mechanism li { position: relative; padding: 0 0 13px 34px; counter-increment: mechanism; }
.mechanism li::before { content: counter(mechanism); position: absolute; left: 0; top: 1px; width: 21px; height: 21px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--accent); font: 700 10px/19px "SFMono-Regular", Consolas, monospace; text-align: center; }
.mechanism li:last-child { padding-bottom: 0; }
.source-line { margin-top: 18px !important; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11px !important; }
@media (max-width: 720px) { .tool-columns { grid-template-columns: 1fr; } }


/* Expanded diagrams */
body { font-size: 16px; }
table { font-size: 14px; }
.diagram-shell .mermaid { font-size: 14px; line-height: 1.6; }
.diagram-stack { display: grid; grid-template-columns: 1fr; gap: 26px; }
.diagram-stack .diagram-shell { min-width: 0; margin-top: 0; }
#system-map-diagram { padding: 22px; }
#system-map-diagram .mermaid { min-width: 620px; padding: 22px 14px; }
#system-map-diagram > h3 { margin-bottom: 5px; font-size: 18px; }
.diagram-intro { max-width: 760px; margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.tool-columns p, .tool-columns li { font-size: 14px; }
@media (max-width: 720px) {
  body { font-size: 15px; }
  #system-map-diagram { padding: 12px; }
  #system-map-diagram .mermaid { min-width: 600px; padding: 18px; }
}
