/* ===== 配色：和首页海报同一套绿 ===== */
:root {
  --content-max-width: 820px;
  --sidebar-target-width: 320px;
  --menu-bar-height: 56px;
  /* 黑体一律用读者设备自带的：Mac/iPhone 是苹方，Windows 是微软雅黑，安卓是思源黑体；不从网上加载字体 */
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  --heading: var(--sans);
  --brand-ink: #1f4a3b;
  --brand-deep: #245c48;
  --brand-mid: #3e8a6c;
  --brand-mint: #9fd8bf;
  --brand-mint-light: #e3f2ea;
}
html.light, html.rust {
  --bg: #fbfcfb;
  --fg: #27332d;
  --sidebar-bg: #f2f6f3;
  --sidebar-fg: #3d4b45;
  --sidebar-non-existant: #a4b0aa;
  --sidebar-active: #245c48;
  --sidebar-spacer: #dbe7df;
  --scrollbar: #c9d8cf;
  --icons: #7c8c84;
  --icons-hover: #245c48;
  --links: #2f7a5f;
  --inline-code-color: #245c48;
  --theme-popup-bg: #ffffff;
  --theme-popup-border: #dbe7df;
  --theme-hover: #e3f2ea;
  --quote-bg: #eef6f1;
  --quote-border: #9fd8bf;
  --table-border-color: #dbe7df;
  --table-header-bg: #e3f2ea;
  --table-alternate-bg: #f5faf7;
  --searchbar-border-color: #c9d8cf;
  --searchbar-bg: #ffffff;
  --searchbar-fg: #27332d;
  --searchbar-shadow-color: #dbe7df;
  --searchresults-header-fg: #7c8c84;
  --searchresults-border-color: #dbe7df;
  --searchresults-li-bg: #f5faf7;
  --search-mark-bg: #cdebdc;
  --copy-button-filter: invert(55%) sepia(8%) saturate(400%) hue-rotate(100deg) brightness(90%) contrast(85%);
  --copy-button-filter-hover: invert(28%) sepia(30%) saturate(600%) hue-rotate(110deg) brightness(90%) contrast(90%);
  --footnote-highlight: #cdebdc;
  --sidebar-header-border-color: #9fd8bf;
  --color-scheme: light;
}

/* ===== 正文排版 ===== */
body {
  font-family: var(--sans);
  font-size: 1.7rem;
  line-height: 1.8;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}
.content { padding: 0 24px 60px; }
.content main { margin-top: 36px; }
/* 每行约 48 个字，行高 1.9，段间距一行的七成 */
.content p, .content ol, .content ul, .content li { line-height: 1.9; }
.content p { margin: 1.25em 0; text-align: justify; }
.content li { text-align: justify; }
.content h1, .content h2, .content h3, .content h4 {
  font-family: var(--heading);
  color: var(--brand-ink);
  font-weight: 600;
  letter-spacing: 0;
}
html.navy .content h1, html.coal .content h1, html.ayu .content h1,
html.navy .content h2, html.coal .content h2, html.ayu .content h2,
html.navy .content h3, html.coal .content h3, html.ayu .content h3 { color: var(--fg); }
.content h1 {
  font-size: 2.6rem;
  line-height: 1.35;
  margin: 0 0 1.3em;
  padding-bottom: 0.55em;
  border-bottom: 1px solid var(--sidebar-spacer);
}
.content h2 {
  font-size: 2rem;
  line-height: 1.4;
  margin: 2.4em 0 0.8em;
  padding-left: 14px;
  border-left: 4px solid var(--brand-mint);
}
.content h3 { font-size: 1.75rem; margin: 2em 0 0.6em; }
.content h4 { font-size: 1.7rem; margin: 1.6em 0 0.5em; }
.content a.header:hover::after { color: var(--brand-mint); }
.content a { text-decoration: none; border-bottom: 1px solid rgba(47, 122, 95, 0.35); }
.content a:hover { border-bottom-color: var(--links); }
.content a.header { border-bottom: 0; }
.content strong { color: var(--brand-ink); font-weight: 600; }
html.navy .content strong, html.coal .content strong, html.ayu .content strong { color: var(--fg); }
.content ul, .content ol { padding-left: 1.6em; margin: 1.1em 0; }
.content li { margin: 0.5em 0; }
.content li::marker { color: var(--brand-mid); }
.content hr { border: 0; border-top: 1px solid var(--sidebar-spacer); margin: 3em auto; width: 60%; }

/* 每章开头那条方法论：标题后面的第一个引用块 */
.content h1 + blockquote {
  position: relative;
  margin: 0 0 2.4em;
  padding: 22px 26px 20px 28px;
  border: 0;
  border-left: 4px solid var(--brand-mid);
  border-radius: 0 14px 14px 0;
  background: var(--quote-bg);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.75;
  color: var(--brand-deep);
}
html.navy .content h1 + blockquote, html.coal .content h1 + blockquote, html.ayu .content h1 + blockquote { color: var(--fg); }
.content h1 + blockquote::before {
  content: "方法论";
  display: block;
  font-family: var(--sans);
  font-size: 1.25rem;
  letter-spacing: 0.18em;
  color: var(--brand-mid);
  margin-bottom: 8px;
}
.content h1 + blockquote p { margin: 0; }
.content blockquote {
  margin: 1.6em 0;
  padding: 14px 22px;
  border: 0;
  border-left: 3px solid var(--quote-border);
  border-radius: 0 10px 10px 0;
  background: var(--quote-bg);
  color: var(--fg);
}
.content blockquote p { margin: 0.4em 0; }

/* 代码 */
.content code {
  font-family: var(--mono-font);
  font-size: 0.88em;
  padding: 0.1em 0.4em;
  border-radius: 5px;
  background: var(--brand-mint-light);
}
html.navy .content code, html.coal .content code, html.ayu .content code { background: rgba(255,255,255,0.08); }
.content pre {
  margin: 1.4em 0;
  border-radius: 12px;
  border: 1px solid var(--sidebar-spacer);
}
.content pre > code {
  padding: 18px 20px;
  font-size: 0.86em;
  line-height: 1.7;
  background: #f4f8f5;
  border-radius: 12px;
  /* 代码块里多是给 AI 的模板和命令，长行折行显示，不用横向滚动 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
html.navy .content pre > code, html.coal .content pre > code, html.ayu .content pre > code { background: var(--quote-bg); }

/* 表格 */
.content table {
  margin: 1.6em 0;
  width: 100%;
  border-collapse: collapse;
  border: 0;
  font-size: 0.94em;
  line-height: 1.65;
}
.content table th, .content table td {
  border: 0;
  border-bottom: 1px solid var(--table-border-color);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}
.content table th {
  background: var(--table-header-bg);
  color: var(--brand-ink);
  font-weight: 600;
}
html.navy .content table th, html.coal .content table th, html.ayu .content table th { color: var(--fg); }
.content table tbody tr:nth-child(2n) { background: transparent; }
.content table td:first-child, .content table th:first-child { min-width: 7em; }
.content table code { white-space: normal; overflow-wrap: anywhere; }

/* 图片：同一行的几张图并排放，高度统一限制 */
.book-figures { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 16px; margin: 1.6em 0; }
.book-figures .book-figure {
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  max-width: calc(50% - 8px);
  max-height: 440px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--sidebar-spacer);
  box-shadow: 0 8px 24px rgba(31, 74, 59, 0.08);
}
.book-figures .book-figure:only-child { max-width: 100%; max-height: 520px; }
.content pre.mermaid { border: 0; background: transparent; text-align: center; }

/* ===== 顶栏：按钮和书名都搬进了侧栏，顶栏不再显示 ===== */
#mdbook-menu-bar, #mdbook-menu-bar-hover-placeholder { display: none; }
.page { margin-block-start: 0; padding-top: 28px; }

/* 侧栏顶部的书名和按钮 */
.sidebar-brand { padding: 4px 10px 18px; margin-bottom: 10px; border-bottom: 1px solid var(--sidebar-spacer); }
.sidebar-brand-title { display: block; text-decoration: none; color: var(--brand-ink); }
.sidebar-brand-title:hover { text-decoration: none; }
.sidebar-brand-main { display: block; font-size: 1.9rem; font-weight: 600; line-height: 1.3; letter-spacing: 0.02em; }
.sidebar-brand-sub { display: block; margin-top: 4px; font-size: 1.3rem; color: var(--icons); letter-spacing: 0.04em; }
html.navy .sidebar-brand-title, html.coal .sidebar-brand-title, html.ayu .sidebar-brand-title { color: var(--fg); }
.sidebar-tools { position: relative; display: flex; align-items: center; gap: 2px; margin-top: 14px; }
.sidebar-tools .icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; margin: 0; border-radius: 8px;
  color: var(--icons); font-size: 1.6rem; line-height: 1;
}
.sidebar-tools .icon-button:hover { background: var(--brand-mint-light); color: var(--brand-deep); }
.sidebar-tools .theme-popup { top: calc(100% + 6px); left: 0; border-radius: 10px; font-size: 1.3rem; box-shadow: 0 8px 24px rgba(31, 74, 59, 0.12); }
.sidebar-tools .theme-popup .theme { padding: 6px 14px; }
.sidebar-tools .icon-button svg { display: block; }

/* 目录收起时左上角的打开按钮 */
.sidebar-float-toggle {
  position: fixed; top: 14px; left: 14px; z-index: 120;
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--sidebar-spacer); color: var(--brand-deep);
  cursor: pointer; box-shadow: 0 4px 12px rgba(31, 74, 59, 0.08);
}
html.sidebar-visible .sidebar-float-toggle { display: none; }
.sidebar-float-toggle:hover { background: var(--brand-mint-light); }

/* 正文两侧的翻页箭头不显示；手机底部的翻页按钮保留，做成细线圆形按钮 */
.nav-wide-wrapper { display: none !important; }
.nav-chapters { color: var(--icons); background: transparent !important; }
.nav-chapters i, .mobile-nav-chapters i, .nav-chapters .fa-svg, .mobile-nav-chapters .fa-svg { display: none; }
.nav-chapters::before, .mobile-nav-chapters::before {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid var(--sidebar-spacer);
  background-color: var(--bg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M10 3.5 5.5 8 10 12.5' fill='none' stroke='%23245c48' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.nav-chapters.next::before, .mobile-nav-chapters.next::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6 3.5 10.5 8 6 12.5' fill='none' stroke='%23245c48' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.nav-chapters:hover::before, .mobile-nav-chapters:hover::before { background-color: var(--brand-mint-light); border-color: var(--brand-mint); }
.mobile-nav-chapters { background: transparent; }

/* ===== 左侧目录 ===== */
.sidebar {
  font-family: var(--sans);
  font-size: 1.45rem;
  border-right: 1px solid var(--sidebar-spacer);
}
.sidebar .sidebar-scrollbox { padding: 18px 16px 40px; }
.chapter li { line-height: 1.6; }
.chapter li.chapter-item { margin-block-start: 0.35em; }
.chapter li a {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 8px;
  color: var(--sidebar-fg);
}
.chapter li a .chapter-title { flex: 1; min-width: 0; }
.chapter li a .chapter-no { display: block; font-size: 0.86em; letter-spacing: 0.04em; color: var(--icons); line-height: 1.5; }
.chapter li a .chapter-name { display: block; margin-top: 1px; }
.chapter li a.active .chapter-no { color: var(--brand-mid); }
.chapter li a.is-locked .chapter-no { color: var(--sidebar-non-existant); }
.chapter li a .trial-badge { flex: none; margin-left: 0; margin-top: 2px; }
.chapter li.chapter-item { margin-block-start: 0.5em; }
/* mdbook 给带小节的章加的折叠箭头不要，只保留按篇折叠的 */
.chapter .chapter-fold-toggle:not(.book-part-toggle) { display: none; }
.chapter li a:hover { background: var(--brand-mint-light); color: var(--brand-deep); text-decoration: none; }
html.navy .chapter li a:hover, html.coal .chapter li a:hover, html.ayu .chapter li a:hover { background: var(--theme-hover); color: var(--fg); }
.chapter li a.active {
  background: var(--brand-mint-light);
  color: var(--brand-deep);
  font-weight: 500;
}
html.navy .chapter li a.active, html.coal .chapter li a.active, html.ayu .chapter li a.active { background: var(--theme-hover); color: var(--fg); }
.chapter li a.active .trial-badge { background: var(--bg); color: var(--brand-deep); }
.chapter li a.is-locked { color: var(--sidebar-non-existant); }
.chapter li a.is-locked.active { color: var(--brand-deep); }
.trial-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 0.78em;
  line-height: 1.7;
  letter-spacing: 0.08em;
  vertical-align: 1px;
  background: var(--brand-mint-light);
  color: var(--brand-deep);
}
.chapter .chapter-link-wrapper { display: flex; align-items: center; }
.chapter .chapter-link-wrapper > a:not(.chapter-fold-toggle) { flex: 1; }

/* 按篇折叠，见 part-fold.js */
.chapter li.book-part { margin-block-start: 1.3em; }
.book-part-head {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  padding: 4px 10px;
  color: var(--brand-ink);
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.05em;
  letter-spacing: 0.06em;
}
html.navy .book-part-head, html.coal .book-part-head, html.ayu .book-part-head { color: var(--fg); }
.book-part-head .book-part-name { flex: 1; white-space: nowrap; }
.book-part-head:hover .book-part-name { color: var(--brand-mid); }
.chapter li a.book-part-toggle { flex: 0 0 auto; display: flex; align-items: center; color: var(--icons); text-decoration: none; padding: 0 2px 0 8px; margin-inline-start: auto; opacity: 1; }
.book-part-toggle div { display: flex; transition: transform 150ms ease-out; }
.book-part-head:hover .book-part-toggle { color: var(--brand-deep); }
.chapter li.book-part.expanded > .book-part-head .book-part-toggle div { transform: rotate(90deg); }
.chapter li.book-part:not(.expanded) > .book-part-head { margin-bottom: 0; }
.chapter ol.book-part-body { padding-inline-start: 0; margin-top: 4px; }
.chapter .part-title { display: none; }

/* 左侧目录只列章，章内各节由右侧导航条负责 */
#mdbook-sidebar .on-this-page { display: none; }

/* 侧栏拖动条：平时不显示，鼠标放到边界上或正在拖动时才出现 */
.sidebar-resize-handle { background: transparent; }
.sidebar-resize-indicator { background: var(--sidebar-spacer); opacity: 0; transition: opacity 150ms ease-out; }
.sidebar-resize-handle:hover .sidebar-resize-indicator,
html.sidebar-resizing .sidebar-resize-indicator { opacity: 1; }

/* ===== 目录页 ===== */
.toc-intro { color: var(--icons); margin-top: -1em; }
.toc .toc-part {
  margin: 2.2em 0 0.6em;
  padding-left: 0;
  border-left: 0;
  font-size: 1.9rem;
}
.toc .toc-list { list-style: none; padding: 0; margin: 0; }
.toc .toc-item {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 9px 12px;
  border-bottom: 1px solid var(--sidebar-spacer);
}
.toc .toc-item a { flex: 1; border-bottom: 0; color: var(--sidebar-non-existant); }
.toc .toc-item.is-trial a { color: var(--fg); }
.toc .toc-item.is-trial a:hover { color: var(--links); }
.toc .toc-item .trial-badge { margin-left: 12px; }

/* ===== 非试读章节的替代页 ===== */
.trial-stub { max-width: 620px; margin: 0.5em 0 0; }
.trial-stub-quote blockquote {
  position: relative;
  margin: 0 0 2em;
  padding: 22px 26px 20px 28px;
  border: 0;
  border-left: 4px solid var(--brand-mid);
  border-radius: 0 14px 14px 0;
  background: var(--quote-bg);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.75;
  color: var(--brand-deep);
}
html.navy .trial-stub-quote blockquote, html.coal .trial-stub-quote blockquote, html.ayu .trial-stub-quote blockquote { color: var(--fg); }
.trial-stub-quote blockquote::before {
  content: "本章方法论";
  display: block;
  font-family: var(--sans);
  font-size: 1.25rem;
  letter-spacing: 0.18em;
  color: var(--brand-mid);
  margin-bottom: 8px;
}
.trial-stub-quote blockquote p { margin: 0; }
.trial-stub-note { color: var(--icons); margin-bottom: 0.8em; }
/* 试读章节：等宽的一列，一行一章，行高压紧 */
.trial-stub-links { list-style: none; padding: 0; margin: 0; max-width: 520px; border: 1px solid var(--sidebar-spacer); border-radius: 12px; overflow: hidden; }
.trial-stub-links li { margin: 0; }
.trial-stub-links li + li a { border-top: 1px solid var(--sidebar-spacer); }
.trial-stub-links a {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 7px 14px;
  border-bottom: 0;
  color: var(--fg);
  font-size: 0.94em;
  line-height: 1.6;
  transition: background-color 120ms ease-out;
}
.trial-stub-links a .no { flex: none; width: 4.6em; font-size: 0.86em; color: var(--brand-mid); letter-spacing: 0.04em; }
.trial-stub-links a .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trial-stub-links a .go { flex: none; color: var(--brand-mid); opacity: 0; transition: opacity 120ms ease-out; }
.trial-stub-links a:hover { background: var(--brand-mint-light); color: var(--brand-deep); }
.trial-stub-links a:hover .go { opacity: 1; }
.trial-contact {
  display: flex; align-items: center; gap: 22px;
  margin-top: 2.4em; padding: 20px 24px;
  border-radius: 14px; border: 1px solid var(--sidebar-spacer); background: rgba(255,255,255,0.6);
}
html.navy .trial-contact, html.coal .trial-contact, html.ayu .trial-contact { background: var(--quote-bg); }
.trial-contact img { width: 128px; height: 128px; border-radius: 8px; flex: none; }
.trial-contact-title { margin: 0; font-size: 1.75rem; font-weight: 500; color: var(--brand-ink); }
html.navy .trial-contact-title, html.coal .trial-contact-title, html.ayu .trial-contact-title { color: var(--fg); }
.trial-contact-sub { margin: 6px 0 0; color: var(--icons); font-size: 1.45rem; }

/* ===== 章内导航条：正文右侧的一列短线，见 chapter-rail.js ===== */
.book-rail { position: fixed; top: 50%; transform: translateY(-50%); z-index: 50; padding: 6px 4px; }
.book-rail.is-hidden { display: none; }
.book-rail-ticks { display: flex; flex-direction: column; align-items: flex-end; max-height: 60vh; overflow-y: auto; scrollbar-width: none; }
.book-rail-ticks::-webkit-scrollbar { display: none; }
.book-rail-tick { position: relative; display: block; width: 28px; height: 10px; border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer; }
.book-rail-tick::before {
  content: ''; position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: var(--tick-w, 5px); height: 2px; border-radius: 1px; background: var(--icons); opacity: 0.75;
  transition: width 150ms ease-out, height 150ms ease-out, background-color 150ms ease-out;
}
.book-rail-tick.is-hover::before { height: 3px; }
.book-rail-tick.is-current::before, .book-rail-tick.is-hover::before { background: var(--sidebar-active); opacity: 1; }
.book-rail-tick:focus-visible { outline: 2px solid var(--sidebar-active); outline-offset: 2px; }
.book-rail-card[hidden] { display: none; }
.book-rail-card {
  position: absolute; left: calc(100% + 10px); width: 300px; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--sidebar-spacer);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); pointer-events: none;
}
.book-rail-card-title { font-size: 0.95em; font-weight: 600; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-rail-card-summary { font-size: 0.85em; line-height: 1.45; color: var(--icons); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ===== 搜索框 ===== */
#mdbook-searchbar { border-radius: 10px; font-family: var(--sans); }
#mdbook-searchbar:focus { box-shadow: 0 0 0 3px var(--brand-mint-light); }

/* ===== 手机 ===== */
@media (max-width: 640px) {
  body { font-size: 1.6rem; line-height: 1.85; }
  .content { padding: 0 18px 50px; }
  .content h1 { font-size: 2.4rem; }
  .content h2 { font-size: 1.95rem; }
  .content h1 + blockquote, .trial-stub-quote blockquote { font-size: 1.65rem; padding: 18px 20px 16px 22px; }
  .page { padding-top: 60px; }
  .trial-contact { flex-direction: column; align-items: flex-start; }
  .trial-stub-links a { align-items: flex-start; }
  .trial-stub-links a .name { white-space: normal; overflow: visible; text-overflow: clip; }
  .trial-stub-links a .go { display: none; }
}
