:root {
  color-scheme: light;
  --page: #f7f6f1;
  --paper: #fffdf8;
  --rail: #f3f1ea;
  --ink: #171d1a;
  --text: #2d342f;
  --muted: #777b75;
  --line: #dedbd2;
  --soft-line: #ebe8df;
  --teal: #17635e;
  --teal-soft: #e7f0ee;
  --red: #b43c34;
  --red-soft: #f6e7e4;
  --chip: #eeeae1;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  line-height: 1.78;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(260px, 306px) minmax(560px, 1fr);
  align-items: center;
  width: 100%;
  min-height: 58px;
  background: rgba(255, 253, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 0 26px;
  min-width: 0;
}

.brand {
  flex: 0 0 auto;
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.brand-subtitle {
  color: #9a9a92;
  font-size: 12px;
  white-space: nowrap;
}

.topnav {
  display: flex;
  justify-content: center;
  gap: 32px;
  height: 58px;
  color: #343b36;
  font-size: 14px;
}

.topnav a,
.topnav span {
  display: inline-flex;
  align-items: center;
  border-bottom: 2px solid transparent;
}

.topnav a:hover,
.topnav a.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

.topnav span {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 306px) minmax(680px, 1fr) minmax(240px, 300px);
  width: 100%;
  min-height: calc(100vh - 58px);
  background: var(--paper);
}

.left-rail {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  padding: 28px 16px 22px 26px;
  background: var(--rail);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.rail-title {
  margin-bottom: 20px;
  color: #4c554f;
  font-size: 14px;
}

.kernel-tree {
  display: grid;
  gap: 4px;
}

details {
  border-radius: 6px;
}

summary {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 42px;
  color: #242b27;
  cursor: pointer;
  font-size: 15px;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "⌄";
  margin-left: auto;
  color: #848880;
  font-size: 15px;
}

details:not([open]) summary::after {
  transform: rotate(-90deg);
}

summary span {
  width: 24px;
  color: #1e2521;
  font-weight: 700;
}

.kernel-tree a {
  display: block;
  margin-left: 36px;
  padding: 9px 12px 9px 18px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  color: #555d57;
  font-size: 14px;
}

.kernel-tree .disabled-link {
  display: block;
  margin-left: 36px;
  padding: 9px 12px 9px 18px;
  color: #a0a39c;
  font-size: 14px;
}

.kernel-tree a:hover {
  color: var(--teal);
  background: rgba(255, 253, 248, 0.68);
}

.kernel-tree a.current {
  color: var(--red);
  background: rgba(180, 60, 52, 0.07);
  border-left-color: var(--red);
  font-weight: 700;
}

.rail-divider {
  height: 1px;
  margin: 22px 0;
  background: var(--line);
}

.utility-links {
  display: grid;
  gap: 10px;
  color: #48514b;
  font-size: 14px;
}

.utility-links a {
  padding: 6px 0;
}

.utility-links a:hover,
.right-rail a:hover {
  color: var(--teal);
}

.article-shell {
  display: flex;
  justify-content: center;
  min-width: 0;
  padding: 34px 48px 88px;
  background: var(--paper);
}

.article {
  width: min(100%, 720px);
}

.breadcrumb {
  margin: 2px 0 16px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

.article-header {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  font-size: 56px;
  line-height: 1.16;
}

h2 {
  margin-top: 34px;
  font-size: 25px;
  line-height: 1.35;
}

h3 {
  margin-top: 24px;
  font-size: 20px;
  line-height: 1.4;
}

.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-width: 32px;
  height: 42px;
  margin-top: 8px;
  border: 1px solid var(--red);
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.05;
  writing-mode: vertical-rl;
}

.subtitle {
  margin: 12px 0 18px;
  color: #5b625c;
  font-size: 17px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  color: #7f837d;
  font-size: 13px;
}

.meta-line span + span::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin: 0 18px 2px 0;
  border-radius: 50%;
  background: #c4c0b6;
}

.article-body {
  padding-top: 24px;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 17px;
}

.article-body p {
  margin: 0 0 18px;
}

.article-body ul {
  margin: 0 0 20px;
  padding-left: 22px;
}

.article-body li {
  margin: 7px 0;
}

.article-body code {
  padding: 1px 5px;
  border: 1px solid var(--soft-line);
  border-radius: 4px;
  background: rgba(238, 234, 225, 0.72);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
}

blockquote {
  margin: 30px 0;
  padding: 4px 0 4px 24px;
  border-left: 3px solid var(--teal);
  color: var(--teal);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.85;
}

.kernel-visual {
  margin: 28px 0 34px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--line);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

.diagram-panel {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.8);
  overflow: hidden;
}

.diagram-panel img {
  display: block;
  width: 100%;
  height: auto;
}

.diagram-panel figcaption {
  display: grid;
  gap: 4px;
  padding: 13px 16px 15px;
  border-top: 1px solid var(--soft-line);
  color: #59615b;
  font-size: 13px;
  line-height: 1.6;
}

.diagram-panel figcaption strong {
  color: var(--teal);
  font-size: 14px;
}

.primitive-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.primitive-strip span {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1eee6;
  color: #626961;
  font-size: 12px;
}

.kernel-matrix {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 253, 248, 0.7);
}

.matrix-head,
.matrix-row {
  display: grid;
  grid-template-columns: 92px 1fr 1fr;
}

.matrix-head {
  background: #ebe8df;
  color: #59615b;
  font-size: 12px;
  font-weight: 700;
}

.matrix-head span,
.matrix-row strong,
.matrix-row span,
.matrix-row em {
  padding: 10px 12px;
  border-right: 1px solid var(--soft-line);
}

.matrix-head span:last-child,
.matrix-row em {
  border-right: 0;
}

.matrix-row + .matrix-row {
  border-top: 1px solid var(--soft-line);
}

.matrix-row strong {
  color: var(--ink);
  font-size: 13px;
  font-style: normal;
}

.matrix-row span,
.matrix-row em {
  color: #616963;
  font-size: 12px;
  line-height: 1.65;
}

.matrix-row em {
  color: #8a4b45;
  font-style: normal;
  background: rgba(246, 231, 228, 0.44);
}

.note {
  margin: 22px 0 10px;
  padding: 15px 18px;
  border: 1px solid var(--soft-line);
  border-radius: 6px;
  background: rgba(238, 234, 225, 0.72);
  color: #687069;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

.flow-figure {
  margin: 26px 0 10px;
  padding: 20px 18px 16px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.72);
}

.flow-figure figcaption {
  margin-bottom: 14px;
  color: var(--teal);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  font-weight: 700;
}

.flow-figure p {
  margin: 12px 0 0;
  color: #8a8d87;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 12px;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(108px, 1fr));
  gap: 10px;
  min-width: 660px;
}

.flow-col {
  display: grid;
  gap: 8px;
}

.flow-col strong {
  color: #414842;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 12px;
  text-align: center;
}

.flow-col span {
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid #cbc8be;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.86);
  color: #4c554f;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.flow-col:first-child span {
  background: var(--teal-soft);
  border-color: #bad2ce;
}

.flow-col.strong span {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 700;
}

.watch-list {
  margin: 0 0 16px;
  padding-left: 22px;
}

.watch-list li {
  margin: 8px 0;
}

.right-rail {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  padding: 220px 30px 40px 18px;
  background: var(--paper);
  overflow: auto;
  color: #6b706a;
  font-size: 14px;
}

.toc-block {
  margin-bottom: 38px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.toc-block p,
.citation-box p {
  margin: 0 0 14px;
  color: #535b55;
  font-weight: 700;
}

.toc-block a {
  display: block;
  padding: 5px 0;
}

.toc-block a.active {
  color: var(--red);
  font-weight: 700;
}

.term-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.term-pills span {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  color: #7a7c75;
  font-size: 12px;
}

.citation-box {
  margin-left: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.72);
}

.citation-box span {
  color: #80837d;
  font-size: 12px;
  line-height: 1.65;
}

@media (max-width: 1180px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 14px 24px 0;
  }

  .brand-block {
    padding: 0;
  }

  .topnav {
    justify-content: start;
    gap: 26px;
    height: 42px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .workspace {
    display: block;
  }

  .left-rail {
    position: static;
    height: auto;
    padding: 22px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .kernel-tree {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }

  .right-rail {
    display: none;
  }

  .article-shell {
    padding: 34px clamp(22px, 6vw, 56px) 72px;
  }
}

@media (max-width: 820px) {
  .brand-subtitle {
    display: none;
  }

  .topnav {
    gap: 22px;
  }

  .left-rail {
    padding: 18px 20px;
  }

  .kernel-tree {
    grid-template-columns: 1fr;
  }

  .article-shell {
    padding: 28px 20px 58px;
  }

  .article {
    width: 100%;
  }

  h1 {
    font-size: 40px;
  }

  h2 {
    font-size: 23px;
  }

  .article-body {
    font-size: 16px;
  }

  .flow-figure {
    overflow-x: auto;
  }

  .kernel-visual {
    margin-top: 22px;
  }

  .matrix-head {
    display: none;
  }

  .matrix-row {
    grid-template-columns: 1fr;
  }

  .matrix-row strong,
  .matrix-row span,
  .matrix-row em {
    border-right: 0;
  }

  .matrix-row span,
  .matrix-row em {
    padding-top: 0;
  }

}
