* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: #fdfdfb;
  color: #1a1a1a;
  line-height: 1.8;
  overflow-x: hidden;
  word-break: break-word;
}
body.dark { background: #0b1224; color: #e2e8f0; }
a { color: #2563eb; text-decoration: none; }
body.dark a { color: #60a5fa; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid rgba(0,0,0,.08);
  position: sticky; top: 0; background: rgba(253,253,251,.94);
  backdrop-filter: blur(8px); z-index: 50;
}
body.dark .topbar { background: rgba(11,18,36,.94); border-bottom-color: rgba(255,255,255,.08); }
.logo { font-weight: 800; font-size: 17px; white-space: nowrap; }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar nav a { margin-left: 8px; color: #475569; font-size: 14px; white-space: nowrap; }
body.dark .topbar nav a { color: #94a3b8; }
.topbar nav a:hover { color: #2563eb; }
.dark-toggle {
  border: 1px solid rgba(0,0,0,.15); background: transparent; border-radius: 8px;
  padding: 4px 10px; cursor: pointer; font-size: 14px; color: inherit; margin-left: 10px;
}
body.dark .dark-toggle { border-color: rgba(255,255,255,.2); }

.layout { display: grid; grid-template-columns: minmax(0,1fr) 240px; gap: 32px; max-width: 1160px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 1080px) { .layout { grid-template-columns: 1fr; } .toc-side { display: none !important; } }

/* —— 书籍布局：左侧全书目录 + 右侧内容 —— */
.book-layout { display: grid; grid-template-columns: 272px minmax(0,1fr); max-width: 1380px; margin: 0 auto; }
.book-side {
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
  border-right: 1px solid rgba(0,0,0,.07); padding: 20px 12px 40px; font-size: 13.5px;
  scrollbar-width: thin;
}
body.dark .book-side { border-right-color: rgba(255,255,255,.08); }
.book-side::-webkit-scrollbar { width: 6px; }
.book-side::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
.book-side .side-home { display:block; padding: 7px 12px; margin-bottom: 8px; border-radius: 8px; font-weight: 800; color: #2563eb; }
body.dark .book-side .side-home { color: #60a5fa; }
.book-side .side-home:hover { background: rgba(37,99,235,.06); text-decoration: none; }
.side-part { margin: 14px 0 4px; padding: 0 12px; font-size: 11.5px; font-weight: 800; color: #94a3b8; letter-spacing: .05em; text-transform: uppercase; }
.side-ch { display: block; padding: 5px 12px; border-radius: 7px; color: #475569; text-decoration: none; line-height: 1.45; }
body.dark .side-ch { color: #9fb0c3; }
.side-ch:hover { background: rgba(37,99,235,.06); color: inherit; text-decoration: none; }
.side-ch.cur { background: rgba(37,99,235,.1); color: #2563eb; font-weight: 700; }
body.dark .side-ch.cur { color: #60a5fa; background: rgba(96,165,250,.12); }
.side-sec { display: block; padding: 3px 12px 3px 26px; font-size: 12.5px; color: #64748b; text-decoration: none; border-left: 2px solid rgba(0,0,0,.06); margin-left: 18px; }
body.dark .side-sec { color: #7c8aa0; border-left-color: rgba(255,255,255,.08); }
.side-sec:hover { color: #2563eb; text-decoration: none; }
body.dark .side-sec:hover { color: #60a5fa; }
.side-sec.active { color: #2563eb; border-left-color: #2563eb; font-weight: 700; }
body.dark .side-sec.active { color: #60a5fa; }
.chapter-main2 { padding: 30px 44px 90px; min-width: 0; max-width: 900px; }
@media (max-width: 960px) {
  .book-layout { grid-template-columns: 1fr; }
  .book-side {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100vh; z-index: 200;
    width: min(320px, 86vw); background: #fff; transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: 8px 0 30px rgba(0,0,0,.15);
  }
  body.dark .book-side { background: #0e1730; }
  .book-side.drawer-open { transform: translateX(0); }
  .drawer-mask { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 190; }
  .drawer-mask.show { display: block; }
  .toc-fab {
    position: fixed; left: 14px; bottom: 18px; z-index: 150;
    border: none; border-radius: 999px; padding: 11px 18px; cursor: pointer;
    background: #2563eb; color: #fff; font-size: 14px; font-weight: 700;
    box-shadow: 0 8px 22px rgba(37,99,235,.4);
  }
  .chapter-main2 { padding: 24px 20px 90px; }
}
@media (min-width: 961px) { .toc-fab, .drawer-mask { display: none !important; } }

main.chapter-main { max-width: 820px; width: 100%; padding: 32px 0 80px; }

.breadcrumb { font-size: 13px; color: #64748b; margin-bottom: 14px; }
body.dark .breadcrumb { color: #94a3b8; }
.breadcrumb b { color: #2563eb; font-weight: 700; }
body.dark .breadcrumb b { color: #60a5fa; }

h1 { font-size: clamp(26px, 4.5vw, 38px); line-height: 1.2; margin: 0 0 12px; overflow-wrap: anywhere; }
h2 { font-size: clamp(20px, 3vw, 26px); margin: 40px 0 12px; color: #2563eb; border-bottom: 1px solid rgba(0,0,0,.08); padding-bottom: 6px; scroll-margin-top: 70px; }
body.dark h2 { color: #60a5fa; border-bottom-color: rgba(255,255,255,.1); }
h3 { font-size: 19px; margin: 26px 0 8px; scroll-margin-top: 70px; }
p { margin: 12px 0; }
code { background: rgba(0,0,0,.05); padding: 0.12em 0.4em; border-radius: 4px; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.9em; overflow-wrap: anywhere; }
body.dark code { background: rgba(255,255,255,.09); }
pre { background: #0f172a; color: #e2e8f0; padding: 16px 18px; overflow-x: auto; line-height: 1.55; border-radius: 8px; font-size: 13.5px; margin: 0; }
pre code { background: transparent; padding: 0; color: inherit; overflow-wrap: normal; }
.code-block { position: relative; margin: 16px 0; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #cbd5e1;
  border-radius: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.code-block:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,.18); }
blockquote { border-left: 4px solid #93c5fd; background: rgba(96,165,250,.06); padding: 10px 16px; color: #475569; margin: 16px 0; border-radius: 0 8px 8px 0; }
body.dark blockquote { border-left-color: #38537a; color: #94a3b8; background: rgba(96,165,250,.05); }
.lead-block blockquote { font-size: 15.5px; background: rgba(34,211,238,.07); border-left-color: #22d3ee; }
body.dark .lead-block blockquote { background: rgba(34,211,238,.06); }
.table-wrap { overflow-x: auto; margin: 16px 0; border-radius: 8px; border: 1px solid rgba(0,0,0,.08); }
body.dark .table-wrap { border-color: rgba(255,255,255,.1); }
table { border-collapse: collapse; width: 100%; margin: 0; font-size: 14.5px; min-width: 480px; }
th, td { border: 1px solid rgba(0,0,0,.08); padding: 8px 12px; text-align: left; vertical-align: top; }
body.dark th, body.dark td { border-color: rgba(255,255,255,.1); }
th { background: #f1f5f9; font-weight: 700; }
body.dark th { background: rgba(255,255,255,.06); }
hr { border: 0; border-top: 1px solid rgba(0,0,0,.08); margin: 32px 0; }
body.dark hr { border-top-color: rgba(255,255,255,.1); }
ul, ol { padding-left: 24px; }
li { margin: 5px 0; }
.task-list { list-style: none; padding-left: 6px; }
.task-list label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.task-list input[type="checkbox"] { margin-top: 6px; accent-color: #2563eb; }

.mermaid { background: #fff; border: 1px solid rgba(0,0,0,.08); border-radius: 8px; padding: 12px; margin: 16px 0; text-align: center; overflow-x: auto; }
body.dark .mermaid { background: #f8fafc; }

/* 自测交互卡片 */
.quiz-card {
  border: 1.5px dashed #93c5fd; border-radius: 12px; padding: 4px 20px 16px;
  margin: 24px 0; background: rgba(96,165,250,.04);
}
body.dark .quiz-card { border-color: #38537a; background: rgba(96,165,250,.05); }
.quiz-card h2 { border: none; margin-top: 16px; }
.quiz-reveal {
  display: block; margin: 10px 0 4px; padding: 8px 18px;
  border: none; border-radius: 8px; background: #2563eb; color: #fff;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.quiz-reveal:hover { background: #1d4ed8; }
.quiz-body { display: none; }
.quiz-card.open .quiz-body { display: block; }
.quiz-card.open .quiz-reveal { display: none; }

/* TOC 侧栏 */
.toc-side { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 100px); overflow-y: auto; padding: 18px 0; font-size: 13.5px; }
.toc-side .toc-title { font-weight: 800; margin-bottom: 10px; color: #64748b; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.toc-side a { display: block; padding: 3px 10px; color: #64748b; border-left: 2px solid transparent; border-radius: 0 6px 6px 0; }
body.dark .toc-side a { color: #94a3b8; }
.toc-side a.active { color: #2563eb; border-left-color: #2563eb; background: rgba(37,99,235,.06); font-weight: 700; }
body.dark .toc-side a.active { color: #60a5fa; }

/* 首页 */
.hero { background: linear-gradient(135deg, #0f172a, #1e293b); color: #f8fafc; padding: 56px 0; }
.hero-inner { max-width: 1080px; margin: 0 auto; padding: 0 24px; display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 40px; align-items: center; }
@media (max-width: 800px) { .hero-inner { grid-template-columns: 1fr; } .hero-cover { max-width: 240px; margin: 0 auto; } }
.hero h1 { font-size: clamp(34px, 6vw, 56px); background: linear-gradient(90deg, #22d3ee, #60a5fa, #a78bfa); -webkit-background-clip: text; background-clip: text; color: transparent; margin: 0; }
.hero p.lead { color: #cbd5e1; font-size: 18px; max-width: 640px; }
.eyebrow { color: #22d3ee; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; margin: 0 0 8px; }
.hero-cover { width: 100%; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.4); }
.part-group { margin: 28px 0 8px; font-size: 17px; font-weight: 800; color: #1e293b; display: flex; align-items: center; gap: 10px; }
body.dark .part-group { color: #e2e8f0; }
.part-group::after { content: ""; flex: 1; height: 1px; background: rgba(0,0,0,.08); }
body.dark .part-group::after { background: rgba(255,255,255,.1); }
.chapter-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; }
@media (max-width: 720px) { .chapter-list { grid-template-columns: 1fr; } }
.chapter-list li a {
  display: flex; gap: 10px; padding: 9px 12px; border-radius: 8px; color: inherit;
  border: 1px solid transparent;
}
.chapter-list li a:hover { background: rgba(37,99,235,.05); border-color: rgba(37,99,235,.15); text-decoration: none; }
.chapter-num { font-family: ui-monospace, monospace; font-size: 12px; font-weight: 800; color: #2563eb; min-width: 26px; padding-top: 2px; }
body.dark .chapter-num { color: #60a5fa; }

/* 搜索 */
.search-box { position: relative; max-width: 620px; margin: 26px auto 0; }
.search-box input {
  width: 100%; padding: 12px 18px; font-size: 15px; border-radius: 12px;
  border: 1.5px solid rgba(0,0,0,.12); background: rgba(255,255,255,.06); color: inherit; outline: none;
}
.search-box input:focus { border-color: #2563eb; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 120;
  background: #fff; border: 1px solid rgba(0,0,0,.1); border-radius: 12px;
  max-height: 380px; overflow-y: auto; box-shadow: 0 12px 32px rgba(0,0,0,.12); display: none;
}
.search-results[style*="block"] { pointer-events: auto; }
body.dark .search-results { background: #16213a; border-color: rgba(255,255,255,.12); }
.search-results .sr-item { padding: 10px 16px; cursor: pointer; border-bottom: 1px solid rgba(0,0,0,.05); }
.search-results .sr-item:hover { background: rgba(37,99,235,.06); }
.search-results .sr-title { font-weight: 700; font-size: 14px; }
.search-results .sr-snip { font-size: 12.5px; color: #64748b; margin-top: 2px; }
.search-results mark { background: #fde68a; color: #78350f; border-radius: 2px; padding: 0 1px; }

.prevnext { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 18px; border-top: 1px solid rgba(0,0,0,.08); font-size: 14px; }
body.dark .prevnext { border-top-color: rgba(255,255,255,.1); }
.prevnext a { display: inline-block; padding: 10px 14px; border: 1px solid rgba(0,0,0,.1); border-radius: 10px; color: inherit; }
body.dark .prevnext a { border-color: rgba(255,255,255,.12); }
.prevnext a:hover { border-color: #2563eb; text-decoration: none; }
.prevnext .pn-label { font-size: 11px; color: #94a3b8; display: block; }
footer.page-foot { text-align: center; color: #94a3b8; font-size: 13px; padding: 30px 0 40px; }
@media print {
  .topbar, .toc-side, .prevnext, .copy-btn, .search-box { display: none !important; }
  body { color: #000; }
}
