:root {
  --bg: #ffffff;
  --panel: #f7f9fc;
  --line: #d7e0ee;
  --text: #1c2a3d;
  --muted: #5b6b82;
  --primary: #1d4ed8;
  --primary-soft: #e8f0ff;
  --warn: #9a3412;
  --warn-bg: #fff4e8;
  --ok: #166534;
  --ok-bg: #ecfdf3;
  --note: #1e3a5f;
  --note-bg: #eef5ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

.app { display: flex; height: 100%; min-height: 0; }
.nav {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}
.nav-head { padding: 18px 16px 10px; border-bottom: 1px solid var(--line); }
.nav-head strong { display: block; font-size: 18px; }
.nav-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.tree { padding: 10px 8px 24px; }
.tree details { margin: 0; }
.tree summary,
.tree a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  list-style: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before {
  content: "▸";
  width: 12px;
  color: var(--muted);
  font-size: 12px;
}
.tree details[open] > summary::before { content: "▾"; }
.tree a { padding-left: 22px; color: #334155; font-size: 14px; }
.tree .group > summary { font-weight: 700; }
.tree .child { margin-left: 10px; border-left: 1px solid var(--line); padding-left: 4px; }
.tree a:hover, .tree summary:hover { background: #fff; }
.tree a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }

.main { min-width: 0; flex: 1; overflow: auto; background: #fff; }
.article { max-width: 1080px; padding: 28px 36px 80px; }
.article h1 { margin: 0 0 10px; font-size: 28px; line-height: 1.3; }
.article h2 { margin: 26px 0 8px; font-size: 20px; }
.article p { margin: 0 0 14px; }
.article .lead { font-size: 17px; color: var(--muted); }
.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; }
.article li { margin: 0 0 6px; }
.article code, .article kbd {
  padding: 1px 6px;
  border-radius: 4px;
  background: #eef2f7;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}

.note, .warn, .ok {
  padding: 14px 16px;
  margin: 0 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.note { background: var(--note-bg); color: var(--note); }
.warn { background: var(--warn-bg); color: var(--warn); }
.ok { background: var(--ok-bg); color: var(--ok); }

.flow, .cards, .pair, .legend {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
}
.flow { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.step, .card, .legend-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}
.step b, .card b, .legend-item b { display: block; margin-bottom: 6px; color: var(--primary); }
.step p, .card p, .legend-item p { margin: 0; color: var(--muted); font-size: 14px; }

.figure, .figure-full, .figure-narrow, .figure-aside img, .pair img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f3f6fb;
  cursor: zoom-in;
}
.figure-full { margin: 8px 0 18px; }
.figure-narrow { max-width: 640px; margin: 8px 0 18px; }
.pair { grid-template-columns: 1fr 1fr; align-items: start; }
.pair figcaption, .figure-full + p.cap, figcaption {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.figure-aside {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
  align-items: start;
  margin: 0 0 18px;
}
.figure-aside .text p:last-child { margin-bottom: 0; }

table { width: 100%; border-collapse: collapse; margin: 0 0 18px; }
th, td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f3f6fb; }

pre {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9fc;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.65 ui-monospace, Consolas, monospace;
}

.downloads { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.downloads a {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
}
.downloads a:hover { background: var(--primary-soft); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.82);
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: min(96vw, 1600px);
  max-height: 88vh;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}
.lightbox p { position: absolute; bottom: 12px; color: #dbe7ff; font-size: 13px; }
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .app { display: block; }
  .nav { width: 100%; height: auto; max-height: 42vh; }
  .article { padding: 18px 16px 60px; }
  .pair, .figure-aside, .flow { grid-template-columns: 1fr; }
}
