:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #edf0eb;
  --text: #1d2526;
  --muted: #647071;
  --line: #d5dbd6;
  --line-strong: #b8c2bb;
  --accent: #d6420b;
  --accent-soft: #fff0e9;
  --blue: #17678a;
  --blue-soft: #e6f3f8;
  --green: #1f7650;
  --green-soft: #e5f3eb;
  --warn: #8f5b08;
  --warn-soft: #fff3d8;
  --code: #24272a;
  --code-text: #f4f2ec;
  --shadow: 0 12px 30px rgb(25 28 30 / 9%);
  --sidebar: 324px;
  --topbar: 58px;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="ink"] {
  color-scheme: light;
  --bg: #f2efe8;
  --surface: #fbf8f1;
  --surface-soft: #e9e5dc;
  --text: #25231f;
  --muted: #6b675e;
  --line: #d5cfc3;
  --line-strong: #bdb5a7;
  --accent: #b93609;
  --accent-soft: #f6e3d7;
  --blue: #315e7e;
  --green: #3a6c4b;
  --blue-soft: #e1ebef;
  --green-soft: #e3ece5;
  --warn: #80550b;
  --warn-soft: #f3ead5;
  --code: #2a2926;
  --code-text: #f7f2e8;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161819;
  --surface: #1d2021;
  --surface-soft: #25292a;
  --text: #e8e9e4;
  --muted: #a2a7a6;
  --line: #383d3e;
  --line-strong: #535a5b;
  --accent: #ff6530;
  --accent-soft: #3b261e;
  --blue: #78b2df;
  --green: #74c89c;
  --blue-soft: #18323d;
  --green-soft: #193329;
  --warn: #e2b766;
  --warn-soft: #362d1c;
  --code: #0d0f10;
  --code-text: #f1f2ed;
  --shadow: 0 14px 34px rgb(0 0 0 / 35%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.72;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

a {
  color: var(--blue);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 80;
  height: 3px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  display: flex;
  align-items: center;
  height: var(--topbar);
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.topbar-title span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.text-action {
  align-self: center;
  margin-right: 6px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.text-action:hover {
  color: var(--accent);
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
}

.forge-mark {
  display: grid;
  width: 18px;
  gap: 3px;
}

.forge-mark i {
  display: block;
  height: 3px;
  background: var(--text);
}

.forge-mark i:first-child {
  width: 9px;
  background: var(--accent);
}

.forge-mark i:nth-child(2) {
  width: 14px;
}

.forge-mark i:last-child {
  width: 18px;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
  padding-top: var(--topbar);
}

.sidebar {
  position: fixed;
  inset: var(--topbar) auto 0 0;
  z-index: 50;
  width: var(--sidebar);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.book-identity {
  padding: 30px 24px 22px;
  border-bottom: 1px solid var(--line);
}

.edition,
.chapter-kicker,
.source-map strong {
  color: var(--accent);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.book-identity > strong {
  display: block;
  margin-top: 10px;
  font-size: 23px;
  line-height: 1.28;
}

.book-identity p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  margin: 18px 18px 14px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.toc {
  padding: 0 12px 24px;
}

.search-result {
  margin: -5px 28px 14px;
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
}

.toc-group {
  margin: 0 0 18px;
}

.toc-part {
  margin: 0;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.toc a {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  padding: 7px 10px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-decoration: none;
}

.toc a span {
  color: var(--line-strong);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  line-height: 1.9;
}

.toc a:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.toc a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.toc a.active span {
  color: var(--accent);
}

.empty-search,
.sidebar-foot {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.sidebar-foot {
  margin: 0 18px 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.reader {
  grid-column: 2;
  width: min(100%, 1200px);
  margin: 0 auto;
  padding: 64px 42px 108px;
}

.chapter {
  width: min(100%, 780px);
  margin: 0 auto;
  outline: none;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 780px) 190px;
  justify-content: center;
  gap: 64px;
}

.reader-primary {
  min-width: 0;
}

.chapter-outline {
  position: sticky;
  top: calc(var(--topbar) + 34px);
  align-self: start;
  max-height: calc(100vh - var(--topbar) - 68px);
  overflow-y: auto;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.chapter-outline > p {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.chapter-outline nav {
  display: grid;
  gap: 2px;
}

.chapter-outline button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
}

.chapter-outline button:hover,
.chapter-outline button:focus-visible {
  color: var(--accent);
  outline: none;
}

.chapter-stat {
  display: grid;
  gap: 2px;
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.chapter-stat strong {
  color: var(--accent);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
}

.chapter-stat span {
  color: var(--muted);
  font-size: 11px;
}

.chapter-kicker {
  margin-bottom: 18px;
}

.chapter h1 {
  max-width: 19ch;
  margin: 0 0 18px;
  font-size: 46px;
  line-height: 1.14;
  letter-spacing: 0;
}

.chapter-deck {
  margin: 0 0 30px !important;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 17px !important;
  line-height: 1.65;
}

.chapter h2 {
  margin: 56px 0 18px;
  padding-top: 4px;
  font-size: 25px;
  line-height: 1.34;
  letter-spacing: 0;
}

.chapter h3 {
  margin: 34px 0 12px;
  font-size: 18px;
  line-height: 1.45;
  letter-spacing: 0;
}

.chapter p,
.chapter li {
  font-size: 16px;
}

.chapter p {
  margin: 14px 0;
}

.chapter ul,
.chapter ol {
  padding-left: 1.35em;
}

.chapter li + li {
  margin-top: 8px;
}

.chapter blockquote {
  margin: 24px 0 34px;
  padding: 16px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.chapter strong {
  font-weight: 700;
}

.chapter blockquote p {
  margin: 0;
}

.lead {
  color: var(--muted);
  font-size: 20px !important;
  line-height: 1.7;
}

.chapter code {
  padding: 0.14em 0.34em;
  border-radius: 3px;
  background: var(--surface-soft);
  color: var(--accent);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.86em;
}

.chapter pre {
  position: relative;
  margin: 24px 0;
  overflow-x: auto;
  padding: 20px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--code);
  color: var(--code-text);
  line-height: 1.65;
}

.chapter pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
}

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

.chapter th,
.chapter td {
  padding: 11px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.chapter th {
  background: var(--surface-soft);
  font-weight: 700;
}

.decision-grid,
.path-grid,
.layer-map,
.loop-map,
.boundary-scale {
  margin: 28px 0;
}

.decision-grid,
.path-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.decision,
.path {
  padding: 20px;
  background: var(--surface);
}

.decision h3,
.path h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.decision p,
.path p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.decision.gain {
  border-top: 3px solid var(--green);
}

.decision.cost {
  border-top: 3px solid var(--accent);
}

.layer-map {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}

.layer-map div {
  min-width: 0;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.layer-map div:last-child {
  border-right: 0;
}

.layer-map span {
  display: block;
  margin-bottom: 7px;
  color: var(--accent);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
}

.layer-map strong {
  display: block;
  font-size: 13px;
  line-height: 1.35;
}

.loop-map {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.loop-map div {
  position: relative;
  min-width: 0;
  flex: 1;
  padding: 18px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.loop-map div:not(:last-child)::after {
  content: "→";
  position: absolute;
  top: 50%;
  right: -16px;
  z-index: 1;
  width: 20px;
  transform: translateY(-50%);
  background: var(--bg);
  color: var(--accent);
}

.boundary-scale {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.boundary-scale div {
  padding: 18px 14px;
  border-right: 1px solid var(--line);
}

.boundary-scale div:last-child {
  border-right: 0;
}

.boundary-scale span {
  display: block;
  width: 24px;
  height: 4px;
  margin-bottom: 12px;
  background: var(--green);
}

.boundary-scale div:nth-child(2) span {
  width: 42px;
  background: var(--blue);
}

.boundary-scale div:nth-child(3) span {
  width: 60px;
  background: #b37500;
}

.boundary-scale div:nth-child(4) span {
  width: 78px;
  background: var(--accent);
}

.boundary-scale strong {
  display: block;
  font-size: 13px;
}

.boundary-scale small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
}

.source-map {
  margin-top: 52px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.source-map p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.version-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px !important;
}

.architecture-figure {
  margin: 32px 0 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 14px 34px rgb(28 39 35 / 8%);
  overflow: hidden;
}

.diagram-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
}

.diagram-scroll {
  overflow-x: auto;
  padding: 12px;
  scrollbar-width: thin;
}

.architecture-figure svg {
  display: block;
  width: 100%;
  min-width: 680px;
  height: auto;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.architecture-figure figcaption {
  display: grid;
  grid-template-columns: minmax(150px, .72fr) minmax(0, 1.28fr);
  gap: 20px;
  padding: 15px 16px 17px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.architecture-figure figcaption strong {
  color: var(--text);
  font-size: 13px;
}

.d-frame,
.d-panel,
.d-kernel,
.d-blue,
.d-green,
.d-accent,
.d-accent-soft,
.d-outline,
.d-warn,
.d-node,
.d-node-main,
.d-ring-fast,
.d-ring-mid,
.d-ring-core {
  stroke: var(--line-strong);
  stroke-width: 1.25;
}

.d-frame { fill: var(--bg); }
.d-panel { fill: var(--surface-soft); }
.d-kernel { fill: color-mix(in srgb, var(--text) 9%, var(--surface)); }
.d-blue { fill: var(--blue-soft); stroke: color-mix(in srgb, var(--blue) 55%, var(--line)); }
.d-green { fill: var(--green-soft); stroke: color-mix(in srgb, var(--green) 55%, var(--line)); }
.d-accent,
.d-accent-soft { fill: var(--accent-soft); stroke: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.d-warn { fill: var(--warn-soft); stroke: var(--warn); }
.d-outline { fill: var(--surface); }
.d-node { fill: var(--surface); stroke: var(--blue); }
.d-node-main { fill: var(--accent-soft); stroke: var(--accent); }
.d-ring-fast { fill: var(--surface-soft); stroke: var(--line-strong); }
.d-ring-mid { fill: var(--blue-soft); stroke: var(--blue); }
.d-ring-core { fill: var(--accent-soft); stroke: var(--accent); }

.d-line,
.d-dash,
.d-dash-accent,
.d-hot,
.d-axis,
.d-lifeline,
.d-blocked {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
}

.d-line,
.d-axis { marker-end: url(#arrow); }
.d-dash { stroke-dasharray: 5 5; }
.d-dash-accent { stroke: var(--accent); stroke-dasharray: 5 5; }
.d-hot { stroke: var(--accent); stroke-width: 2; marker-end: url(#arrow); }
.d-lifeline { stroke: var(--line-strong); stroke-dasharray: 3 5; }
.d-blocked { stroke: var(--accent); stroke-width: 5; stroke-dasharray: 8 5; }
.d-arrow { fill: var(--muted); }
.d-arrow-accent { fill: var(--accent); }
.d-title { fill: var(--text); font-size: 15px; font-weight: 700; }
.d-label { fill: var(--text); font-size: 13px; }
.d-small { fill: var(--muted); font-size: 11px; }
.d-mono { fill: var(--muted); font-family: "Cascadia Code", Consolas, monospace; font-size: 10px; }
.d-eyebrow { fill: var(--accent); font-family: "Cascadia Code", Consolas, monospace; font-size: 11px; font-weight: 700; letter-spacing: 1.4px; }
.d-grid { fill: none; stroke: var(--line); stroke-width: .65; }
.d-registration { fill: none; stroke: var(--muted); stroke-width: 1; opacity: .7; }

.reading-paths,
.source-routes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--line);
  gap: 1px;
  overflow: hidden;
}

.reading-paths > div,
.source-routes > section {
  min-width: 0;
  padding: 20px;
  background: var(--surface);
}

.reading-paths span,
.source-routes span,
.protocol-grid span,
.artifact-band span,
.timeline-compare span {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
}

.reading-paths strong,
.source-routes strong {
  display: block;
  font-size: 15px;
}

.reading-paths p,
.source-routes p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.decision-record {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.2fr;
  margin: 34px 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-top: 4px solid var(--accent);
  border-radius: 7px;
}

.decision-record > div {
  padding: 18px;
  border-right: 1px solid var(--line);
}

.decision-record > div:last-child {
  border-right: 0;
}

.decision-record span,
.status-split span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
}

.decision-record strong {
  display: block;
  font-size: 15px;
  line-height: 1.55;
}

.decision-record p,
.status-split p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 32px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.status-split section {
  padding: 20px;
  background: var(--green-soft);
}

.status-split section + section {
  border-left: 1px solid var(--line);
  background: var(--blue-soft);
}

.comparison-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.comparison-table > div {
  display: contents;
}

.comparison-table span {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}

.comparison-table span:nth-child(2n) {
  border-left: 1px solid var(--line);
  background: var(--blue-soft);
}

.comparison-table .comparison-head span {
  background: var(--surface-soft);
  font-weight: 700;
}

.topology-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 26px 0;
  border-top: 1px solid var(--line-strong);
}

.topology-list > div {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.topology-list > div:nth-child(odd) {
  padding-right: 22px;
}

.topology-list > div:nth-child(even) {
  padding-left: 22px;
  border-left: 1px solid var(--line);
}

.topology-list strong { font-size: 13px; }
.topology-list span { color: var(--muted); font-size: 13px; }

.protocol-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.protocol-grid > div {
  padding: 18px;
  border-right: 1px solid var(--line);
}

.protocol-grid > div:last-child { border-right: 0; }
.protocol-grid strong { display: block; margin-top: 8px; font-size: 13px; font-weight: 600; }

.artifact-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 26px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.artifact-band > div {
  min-width: 130px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.artifact-band > div:last-child { border-right: 0; }
.artifact-band strong { display: block; font-size: 12px; line-height: 1.5; }

.timeline-compare {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 28px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.timeline-compare > div {
  padding: 19px;
  border-right: 1px solid var(--line);
}

.timeline-compare > div:last-child { border-right: 0; }
.timeline-compare strong { font-size: 17px; }
.timeline-compare p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.warning-block {
  margin: 28px 0;
  padding: 20px 22px;
  border: 1px solid color-mix(in srgb, var(--warn) 55%, var(--line));
  border-left: 4px solid var(--warn);
  border-radius: 6px;
  background: var(--warn-soft);
}

.warning-block strong { color: var(--warn); }
.warning-block p { margin: 8px 0 0; font-size: 14px; }

.manifesto {
  margin: 34px 0;
  padding: 14px 28px;
  border-left: 4px solid var(--accent);
  background: var(--surface-soft);
}

.manifesto p {
  margin: 10px 0;
  font-size: 18px;
  font-weight: 700;
}

.principle-list {
  display: grid;
  gap: 0;
  margin: 26px 0;
  padding: 0 !important;
  border-top: 1px solid var(--line-strong);
  list-style: none;
  counter-reset: principle;
}

.principle-list li {
  display: grid;
  grid-template-columns: 30px 180px 1fr;
  gap: 14px;
  align-items: baseline;
  margin: 0 !important;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  counter-increment: principle;
}

.principle-list li::before {
  content: counter(principle, decimal-leading-zero);
  color: var(--accent);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
}

.principle-list strong { font-size: 14px; }
.principle-list span { color: var(--muted); font-size: 13px; }

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: min(100%, 780px);
  margin: 72px auto 0;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.chapter-link {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.chapter-link:hover {
  border-color: var(--accent);
}

.chapter-link span,
.chapter-link strong {
  display: block;
}

.chapter-link span {
  color: var(--muted);
  font-size: 11px;
}

.chapter-link strong {
  overflow: hidden;
  margin-top: 3px;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-link.next {
  grid-column: 2;
  text-align: right;
}

.sidebar-scrim,
.mobile-only {
  display: none;
}

@media (max-width: 1180px) {
  .reader-layout {
    display: block;
  }

  .chapter-outline {
    display: none;
  }
}

@media (max-width: 900px) {
  .mobile-only {
    display: grid;
  }

  .topbar {
    padding: 0 10px;
  }

  .topbar-title {
    margin-left: 6px;
  }

  .shell {
    display: block;
  }

  .sidebar {
    width: min(88vw, 330px);
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-scrim {
    position: fixed;
    inset: var(--topbar) 0 0;
    z-index: 40;
    border: 0;
    background: rgb(0 0 0 / 38%);
  }

  .sidebar-scrim.open {
    display: block;
  }

  body.menu-open {
    overflow: hidden;
  }

  .reader {
    width: 100%;
    padding: 50px 24px 76px;
  }

  .decision-record {
    grid-template-columns: 1fr;
  }

  .decision-record > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .decision-record > div:last-child {
    border-bottom: 0;
  }

  .artifact-band {
    grid-template-columns: repeat(5, 140px);
  }

  .chapter h1 {
    font-size: 34px;
  }

  .layer-map {
    grid-template-columns: 1fr;
  }

  .layer-map div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
  }

  .layer-map div:last-child {
    border-bottom: 0;
  }

  .loop-map {
    display: grid;
  }

  .loop-map div:not(:last-child)::after {
    content: "↓";
    top: auto;
    right: 50%;
    bottom: -18px;
    transform: translateX(50%);
  }

  .boundary-scale {
    grid-template-columns: 1fr 1fr;
  }

  .boundary-scale div:nth-child(2) {
    border-right: 0;
  }

  .boundary-scale div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .diagram-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
    padding: 9px 12px;
  }

  .architecture-figure figcaption {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .topbar-title .forge-mark {
    display: none;
  }

  .reader {
    padding: 42px 18px 64px;
  }

  .chapter h1 {
    font-size: 29px;
  }

  .text-action {
    display: none;
  }

  .chapter h2 {
    margin-top: 44px;
    font-size: 22px;
  }

  .chapter p,
  .chapter li {
    font-size: 15px;
  }

  .lead {
    font-size: 18px !important;
  }

  .decision-grid,
  .path-grid,
  .boundary-scale {
    grid-template-columns: 1fr;
  }

  .reading-paths,
  .source-routes,
  .status-split,
  .topology-list,
  .protocol-grid,
  .timeline-compare {
    grid-template-columns: 1fr;
  }

  .status-split section + section,
  .topology-list > div:nth-child(even),
  .protocol-grid > div,
  .timeline-compare > div {
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .status-split section:first-child,
  .protocol-grid > div:first-child,
  .timeline-compare > div:first-child {
    border-top: 0;
  }

  .topology-list > div:nth-child(odd),
  .topology-list > div:nth-child(even) {
    padding-right: 0;
    padding-left: 0;
  }

  .principle-list li {
    grid-template-columns: 28px 1fr;
  }

  .principle-list span {
    grid-column: 2;
  }

  .architecture-figure {
    margin-right: -2px;
    margin-left: -2px;
  }

  .diagram-scroll {
    padding: 8px;
  }

  .decision,
  .path,
  .boundary-scale div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .decision:last-child,
  .path:last-child,
  .boundary-scale div:last-child {
    border-bottom: 0;
  }

  .chapter table {
    display: block;
    overflow-x: auto;
  }

  .chapter-nav {
    grid-template-columns: 1fr;
  }

  .chapter-link.next {
    grid-column: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .topbar,
  .sidebar,
  .sidebar-scrim,
  .reading-progress,
  .chapter-nav {
    display: none !important;
  }

  .chapter-outline {
    display: none !important;
  }

  .shell,
  .reader {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
  }

  .chapter {
    width: auto;
  }

  .reader-layout {
    display: block;
  }

  .architecture-figure {
    break-inside: avoid;
    box-shadow: none;
  }

  .architecture-figure svg {
    min-width: 0;
  }

  body {
    background: white;
    color: black;
  }
}
