/* ============================================================
   灵犀的第二套记忆 — 设计系统
   方向：档案纸 + 编辑式排版；暖红=工具记忆，深青=会话记忆
   ============================================================ */

:root {
  --paper: #f5f2ea;
  --paper-2: #fbf9f3;
  --surface: #fffdf8;
  --ink: #17191a;
  --ink-2: #3d4245;
  --ink-3: #6b7073;
  --line: #ddd6c8;
  --line-strong: #c6bda9;

  --tool: #b8402a;
  --tool-soft: #f3e2dc;
  --memory: #0e6a61;
  --memory-soft: #dcece8;
  --cloud: #2e4a78;
  --cloud-soft: #e0e6f0;
  --warn: #9a6a12;

  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "IBM Plex Mono", Menlo, Consolas, monospace;

  --measure: 41rem;
  --gutter: clamp(1.25rem, 4vw, 3.5rem);
  --radius: 3px;
  --shadow: 0 1px 0 rgba(23, 25, 26, 0.04), 0 12px 32px -24px rgba(23, 25, 26, 0.45);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5.5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: 0.006em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 12% 8%, rgba(184, 64, 42, 0.05), transparent 42%),
    radial-gradient(circle at 88% 24%, rgba(14, 106, 97, 0.055), transparent 46%);
}

::selection { background: var(--memory-soft); color: var(--ink); }

a {
  color: var(--memory);
  text-decoration: none;
  border-bottom: 1px solid rgba(14, 106, 97, 0.28);
  transition: border-color 0.2s ease, color 0.2s ease;
}
a:hover { border-bottom-color: var(--memory); }

/* ---------- 顶部进度 ---------- */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--tool), var(--memory));
  z-index: 60;
}

/* ---------- 页头 ---------- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem var(--gutter);
  background: rgba(245, 242, 234, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.mark {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.mark b {
  font-family: var(--sans);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
}
.mark span { color: var(--ink-3); }

.masthead nav {
  display: flex;
  gap: 1.1rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.masthead nav a { border: 0; color: inherit; }
.masthead nav a:hover { color: var(--memory); }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  z-index: 1;
  padding: clamp(3.5rem, 9vw, 7rem) var(--gutter) clamp(2.5rem, 5vw, 4rem);
  border-bottom: 1px solid var(--line);
}
.hero-inner {
  max-width: 76rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 0.85fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: end;
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--tool);
}
.kicker::before {
  content: "";
  width: 1.9rem;
  height: 1px;
  background: var(--tool);
}

h1 {
  margin: 1.1rem 0 1.2rem;
  font-family: var(--serif);
  font-size: clamp(2.7rem, 6.4vw, 5.1rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
}
h1 em {
  font-style: normal;
  color: var(--memory);
  position: relative;
  white-space: nowrap;
}
h1 em::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.04em;
  height: 0.3em;
  background: var(--memory-soft);
  z-index: -1;
}

.deck {
  max-width: 40rem;
  font-size: clamp(1.02rem, 1.5vw, 1.18rem);
  line-height: 1.85;
  color: var(--ink-2);
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.hero-meta b { color: var(--ink); font-weight: 600; }

.hero-card {
  position: relative;
  padding: 1.5rem 1.5rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}
.hero-card::before {
  content: "TL;DR";
  position: absolute;
  top: -0.62rem;
  left: 1.2rem;
  padding: 0 0.45rem;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  color: var(--tool);
}
.hero-card ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: tldr;
}
.hero-card li {
  counter-increment: tldr;
  position: relative;
  padding: 0.5rem 0 0.5rem 2rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink-2);
  border-bottom: 1px dashed var(--line);
}
.hero-card li:last-child { border-bottom: 0; }
.hero-card li::before {
  content: counter(tldr, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.62rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--memory);
}

/* ---------- 布局 ---------- */
.layout {
  position: relative;
  z-index: 1;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 var(--gutter) 6rem;
  display: grid;
  grid-template-columns: 15.5rem minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: start;
}

.toc {
  position: sticky;
  top: 5.2rem;
  padding: 2.6rem 0 1rem;
  font-size: 0.755rem;
}
.toc-title {
  margin-bottom: 0.9rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.toc ol { margin: 0; padding: 0; list-style: none; }
.toc li { margin: 0; }
.toc a {
  display: flex;
  gap: 0.6rem;
  padding: 0.34rem 0;
  border: 0;
  color: var(--ink-3);
  line-height: 1.45;
  transition: color 0.2s ease;
}
.toc a .n {
  flex: 0 0 1.5rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--line-strong);
}
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--memory); }
.toc a.active .n { color: var(--memory); }

.article { min-width: 0; padding-top: 2.6rem; }

/* ---------- 章节 ---------- */
.chapter {
  padding: 2.2rem 0 3.4rem;
  border-top: 1px solid var(--line);
  animation: rise 0.6s ease both;
}
.chapter:first-child { border-top: 0; padding-top: 0; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .chapter { animation: none; }
}

.chapter-head { display: flex; gap: 1rem; align-items: baseline; }
.chapter-num {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--tool);
  padding-top: 0.35rem;
}
h2 {
  margin: 0 0 0.4rem;
  font-family: var(--serif);
  font-size: clamp(1.65rem, 3.1vw, 2.35rem);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
h3 {
  margin: 2.6rem 0 0.7rem;
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
h3::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.55rem;
  border: 1px solid var(--ink);
  transform: translateY(-0.08rem);
}
.lede {
  max-width: var(--measure);
  margin: 0.5rem 0 1.6rem;
  font-size: 1.03rem;
  color: var(--ink-2);
}

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1.15rem; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { font-weight: 600; }
.prose code,
.lede code,
li code,
td code {
  padding: 0.1em 0.35em;
  background: rgba(23, 25, 26, 0.055);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 0.85em;
  white-space: normal;
  overflow-wrap: anywhere;
}
.prose ul, .prose ol { margin: 0 0 1.2rem; padding-left: 1.15rem; }
.prose li { margin-bottom: 0.45rem; }
.prose li::marker { color: var(--tool); font-family: var(--mono); font-size: 0.85em; }

.quote {
  margin: 2rem 0;
  padding: 0.2rem 0 0.2rem 1.4rem;
  border-left: 2px solid var(--memory);
  font-family: var(--serif);
  font-size: 1.16rem;
  line-height: 1.75;
  color: var(--ink-2);
}
.quote span { display: block; margin-top: 0.5rem; font-family: var(--sans); font-size: 0.8rem; color: var(--ink-3); }

.note {
  margin: 1.8rem 0;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 2px solid var(--tool);
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--ink-2);
}
.note b { color: var(--tool); }

/* ---------- 双栏对比 ---------- */
.duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 2.2rem 0;
  border: 1px solid var(--line-strong);
  background: var(--surface);
}
.duo-col { padding: 1.5rem 1.5rem 1.4rem; }
.duo-col + .duo-col { border-left: 1px solid var(--line); }
.duo-tag {
  display: inline-block;
  margin-bottom: 0.7rem;
  padding: 0.12rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.duo-col.tool .duo-tag { background: var(--tool-soft); color: var(--tool); }
.duo-col.mem .duo-tag { background: var(--memory-soft); color: var(--memory); }
.duo h4 {
  margin: 0 0 0.3rem;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
}
.duo .sub { margin: 0 0 1rem; font-size: 0.82rem; color: var(--ink-3); }
.duo dl { margin: 0; display: grid; grid-template-columns: 3.7rem 1fr; gap: 0.35rem 0.55rem; }
.duo dt { font-family: var(--mono); font-size: 0.68rem; color: var(--ink-3); padding-top: 0.2rem; }
.duo dd { margin: 0; font-size: 0.86rem; line-height: 1.65; color: var(--ink-2); }

/* ---------- 图 ---------- */
figure {
  margin: 2.4rem 0;
  padding: 0;
}
.figframe {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: clamp(0.8rem, 2vw, 1.3rem);
  overflow-x: auto;
  overflow-y: hidden;
}

/* 宽屏时图表向目录一侧出血，保证架构图可读 */
@media (min-width: 1081px) {
  .chapter .figframe {
    margin-left: calc(-15.5rem - clamp(2rem, 5vw, 5rem));
  }
}
.figframe svg { display: block; width: 100%; height: auto; min-width: 700px; }
@media (max-width: 1180px) { .figframe svg { min-width: 760px; } }
figcaption {
  display: flex;
  gap: 0.7rem;
  margin-top: 0.7rem;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-3);
}
figcaption b { flex: 0 0 auto; font-family: var(--mono); font-weight: 500; color: var(--tool); }

.swipe-hint {
  display: none;
  margin-top: 0.45rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--ink-3);
}
@media (max-width: 1180px) {
  .swipe-hint { display: block; }
}

/* SVG 通用文字 */
.svg-label { font-family: var(--sans); }
.svg-mono { font-family: var(--mono); letter-spacing: 0.02em; }

/* ---------- 表格 ---------- */
.table-wrap {
  margin: 1.8rem 0;
  overflow-x: auto;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.84rem;
  line-height: 1.6;
  background: transparent;
}
thead th {
  padding: 0.65rem 0.8rem;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
tbody td { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(14, 106, 97, 0.035); }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- 数字墙 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 2rem 0;
  background: var(--line);
  border: 1px solid var(--line);
}
.stat { background: var(--surface); padding: 1.1rem 1rem 1rem; }
.stat .v {
  display: block;
  font-family: var(--mono);
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.stat .k { display: block; margin-top: 0.4rem; font-size: 0.72rem; line-height: 1.5; color: var(--ink-3); }
.stat:nth-child(1) .v { color: var(--tool); }
.stat:nth-child(2) .v { color: var(--ink); }
.stat:nth-child(3) .v { color: var(--memory); }
.stat:nth-child(4) .v { color: var(--cloud); }
.stat:nth-child(5) .v { color: var(--ink); }
.stat:nth-child(6) .v { color: var(--memory); }
.stat:nth-child(7) .v { color: var(--tool); }
.stat:nth-child(8) .v { color: var(--cloud); }

/* ---------- 时间线 ---------- */
.timeline {
  margin: 2.2rem 0;
  border-left: 1px solid var(--line-strong);
  padding-left: 1.6rem;
}
.tl-item { position: relative; padding: 0 0 1.4rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: "";
  position: absolute;
  left: -1.92rem;
  top: 0.55rem;
  width: 7px;
  height: 7px;
  background: var(--paper);
  border: 1px solid var(--memory);
  border-radius: 50%;
}
.tl-item.tool::before { border-color: var(--tool); }
.tl-t {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.tl-h { display: block; margin: 0.15rem 0 0.25rem; font-size: 0.95rem; font-weight: 600; }
.tl-d { display: block; font-size: 0.84rem; line-height: 1.65; color: var(--ink-2); }

/* ---------- 入口卡 ---------- */
.entries {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 2rem 0;
  background: var(--line);
  border: 1px solid var(--line);
}
.entry { background: var(--surface); padding: 1.15rem 1.1rem; }
.entry .idx { font-family: var(--mono); font-size: 0.66rem; color: var(--tool); letter-spacing: 0.1em; }
.entry h4 { margin: 0.45rem 0 0.4rem; font-size: 0.98rem; font-weight: 600; }
.entry p { margin: 0 0 0.6rem; font-size: 0.82rem; line-height: 1.65; color: var(--ink-2); }
.entry .path { font-family: var(--mono); font-size: 0.68rem; color: var(--ink-3); word-break: break-all; line-height: 1.5; }

/* ---------- 坑 ---------- */
.pits { margin: 2rem 0; border-top: 1px solid var(--ink); }
.pit { border-bottom: 1px solid var(--line); }
.pit summary {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.85rem 0;
  cursor: pointer;
  list-style: none;
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.5;
}
.pit summary::-webkit-details-marker { display: none; }
.pit summary::after {
  content: "+";
  margin-left: auto;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 400;
  color: var(--ink-3);
}
.pit[open] summary::after { content: "−"; }
.pit .no { flex: 0 0 1.6rem; font-family: var(--mono); font-size: 0.7rem; font-weight: 400; color: var(--tool); }
.pit .body { padding: 0 0 1.1rem 2.4rem; font-size: 0.86rem; line-height: 1.7; color: var(--ink-2); }
.pit .body p { margin: 0 0 0.5rem; }
.pit .body p:last-child { margin: 0; }
.pit .body b { color: var(--ink); }

/* ---------- 代码 ---------- */
.code {
  position: relative;
  margin: 1.6rem 0;
  background: #1b1f20;
  border-radius: var(--radius);
  overflow: hidden;
}
.code header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.45);
}
.code button {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  padding: 0.15rem 0.2rem;
}
.code button:hover { color: #fff; }
.code pre,
.code pre code {
  white-space: pre;
}
.code pre {
  margin: 0;
  padding: 0.95rem 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.75;
  color: #e6e3da;
  tab-size: 2;
}
.code .c { color: #7e8b8a; }
.code .k { color: #e0a06a; }
.code .s { color: #9dc7a8; }

/* ---------- 步骤 ---------- */
.steps { margin: 2rem 0; counter-reset: step; }
.step {
  position: relative;
  padding: 0 0 1.5rem 3.1rem;
  counter-increment: step;
}
.step::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.15rem;
  width: 2rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--tool);
}
.step::after {
  content: "";
  position: absolute;
  left: 2.9rem;
  top: 0.55rem;
  bottom: 0.15rem;
  width: 1px;
  background: var(--line);
}
.step:last-child { padding-bottom: 0; }
.step:last-child::after { display: none; }
.step h4 { margin: 0 0 0.3rem; font-size: 0.95rem; font-weight: 600; }
.step p { margin: 0; font-size: 0.86rem; line-height: 1.7; color: var(--ink-2); }

/* ---------- 开源边界 ---------- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4rem;
  margin: 2rem 0;
}
.panel {
  padding: 1.2rem 1.2rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
}
.panel h4 {
  margin: 0 0 0.7rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.panel ul { margin: 0; padding-left: 1rem; font-size: 0.85rem; line-height: 1.7; color: var(--ink-2); }
.panel li { margin-bottom: 0.35rem; }
.panel li::marker { color: var(--memory); }
.panel.keep { border-top: 2px solid var(--memory); }
.panel.drop { border-top: 2px solid var(--tool); }
.panel.drop li::marker { color: var(--tool); }

/* ---------- 结尾 ---------- */
.endnote {
  margin-top: 2rem;
  padding: 2rem 0 0;
  border-top: 1px solid var(--ink);
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--ink-3);
}
.endnote p { margin: 0 0 0.6rem; }

/* ---------- 页脚 ---------- */
footer {
  position: relative;
  z-index: 1;
  padding: 2rem var(--gutter) 3rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.footer-inner {
  max-width: 76rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 2rem;
  justify-content: space-between;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .hero-inner { grid-template-columns: 1fr; align-items: start; }
  .hero-card { max-width: 34rem; }
  .layout { grid-template-columns: 1fr; }
  .toc { display: none; }
  .article { padding-top: 1.4rem; }
}

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .entries { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  body { font-size: 16px; line-height: 1.8; }
  .masthead nav { display: none; }
  .hero { padding-top: 3rem; }
  .duo { grid-template-columns: 1fr; }
  .duo-col + .duo-col { border-left: 0; border-top: 1px solid var(--line); }
  .chapter-head { gap: 0.7rem; }
  h2 { font-size: 1.6rem; }
  .figframe svg { min-width: 640px; }
  .pit .body { padding-left: 0; }
  .code pre { font-size: 0.72rem; }
}

@media print {
  .masthead, .toc, .progress, .swipe-hint { display: none; }
  body { background: #fff; }
  .chapter { break-inside: avoid; }
}
