/* ============================================================
   Hermes Agent — Book Style (Light, Editorial)
   纸质感浅色主题。端正、正式、长时间阅读友好。
   ============================================================ */

:root {
  /* — 纸质米白背景（书籍质感）— */
  --bg: #fbfaf6;
  --bg-elev: #f3f1e8;
  --bg-elev-2: #e9e6d9;
  --bg-code: #f6f4eb;
  --bg-hover: #efece1;

  /* — 暖深棕黑前景 — */
  --fg: #2a2723;
  --fg-soft: #4d4a44;
  --fg-dim: #807c75;
  --fg-bright: #1a1814;

  /* — 主强调色：深酒红（书脊/标题色）— */
  --accent: #8b1538;
  --accent-dim: #6b1028;
  --accent-soft: #b04658;

  /* — 链接：深靛蓝 — */
  --link: #1a4d80;
  --link-hover: #0d3a66;

  /* — 边框 — */
  --border: #d6d3c4;
  --border-soft: #e6e3d4;
  --border-strong: #c2bea9;
  --kbd-bg: #ebe8da;

  /* — 语义色（callout） — */
  --warn: #b85c00;
  --warn-bg: #faf0e3;
  --info: #2c5282;
  --info-bg: #e8eff5;
  --good: #2f5d3a;
  --good-bg: #ecf3eb;
  --research: #6b4488;
  --research-bg: #f0eaf1;
  --tip-bg: #f5ede0;

  /* — 代码语法高亮（浅色背景） — */
  --code-keyword: #8b1538;     /* 深红 */
  --code-string: #2e6a3e;      /* 深绿 */
  --code-comment: #807c70;     /* 灰 */
  --code-fn: #1e5a99;          /* 深蓝 */
  --code-name: #a82c30;        /* 深红 2 */
  --code-num: #a86420;         /* 深棕橙 */
  --code-default: #2a2723;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 1.5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Source Sans 3", "Source Sans Pro", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.layout { display: flex; min-height: 100vh; }

nav.sidebar {
  width: 296px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 28px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-size: 13.5px;
}
nav.sidebar::-webkit-scrollbar { width: 8px; }
nav.sidebar::-webkit-scrollbar-track { background: transparent; }
nav.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

nav.sidebar .book-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 4px 0;
  letter-spacing: 0.2px;
}
nav.sidebar .book-sub {
  color: var(--fg-dim);
  font-size: 11px;
  margin-bottom: 24px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
nav.sidebar a {
  color: var(--fg);
  text-decoration: none;
}
nav.sidebar a:hover { color: var(--accent); }

nav.sidebar .part {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}
nav.sidebar .part:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
nav.sidebar .part-label {
  font-size: 10.5px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 8px;
  font-weight: 700;
}
nav.sidebar .part-title {
  font-size: 13px;
  color: var(--fg-soft);
  margin-bottom: 6px;
  font-weight: 600;
}
nav.sidebar ol.chapters {
  list-style: none;
  padding: 0;
  margin: 0;
}
nav.sidebar ol.chapters li {
  margin: 2px 0;
  padding: 4px 0 4px 10px;
  border-left: 2px solid transparent;
  transition: border-color 0.12s, background 0.12s;
}
nav.sidebar ol.chapters li:hover {
  background: var(--bg-hover);
}
nav.sidebar ol.chapters li a {
  display: block;
  font-size: 13.5px;
  color: var(--fg);
  line-height: 1.45;
}
nav.sidebar ol.chapters li.current {
  border-left-color: var(--accent);
  background: rgba(139, 21, 56, 0.06);
}
nav.sidebar ol.chapters li.current a {
  color: var(--accent);
  font-weight: 600;
}
nav.sidebar ol.chapters li a::before {
  content: attr(data-num);
  display: inline-block;
  width: 32px;
  color: var(--fg-dim);
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11.5px;
}

nav.sidebar .home-link {
  display: block;
  font-size: 12.5px;
  color: var(--fg-soft);
  margin-bottom: 20px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  background: var(--bg);
  transition: border-color 0.12s, color 0.12s;
}
nav.sidebar .home-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   MAIN CONTENT COLUMN
   ============================================================ */

main {
  flex: 1;
  max-width: 880px;
  padding: 48px 72px 100px 72px;
  min-width: 0;
}

.breadcrumb {
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--fg-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.breadcrumb .sep { margin: 0 8px; opacity: 0.5; }

/* ============================================================
   CHAPTER HEADING
   ============================================================ */

.chapter-head {
  margin-bottom: 56px;
  padding-bottom: 28px;
  border-bottom: 2px solid var(--accent);
  position: relative;
}
.chapter-head .chapter-num {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin-bottom: 12px;
  font-weight: 600;
}
.chapter-head h1 {
  font-size: 40px;
  line-height: 1.18;
  margin: 0 0 18px 0;
  color: var(--fg-bright);
  font-weight: 700;
  letter-spacing: -0.4px;
}
.chapter-head .chapter-subtitle {
  font-size: 17px;
  color: var(--fg-soft);
  font-style: italic;
  line-height: 1.55;
  margin: 0;
}
.chapter-head .meta {
  margin-top: 24px;
  display: flex;
  gap: 22px;
  font-size: 12.5px;
  color: var(--fg-dim);
  letter-spacing: 0.3px;
}
.chapter-head .meta span::before { content: "·"; margin-right: 8px; color: var(--border-strong); }
.chapter-head .meta span:first-child::before { content: ""; margin: 0; }

/* ============================================================
   HEADINGS (within chapter)
   ============================================================ */

h2.section {
  font-size: 26px;
  color: var(--fg-bright);
  margin-top: 72px;
  margin-bottom: 10px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  letter-spacing: -0.2px;
}
h2.section .secnum {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  font-size: 18px;
  margin-right: 14px;
  font-weight: 500;
}

h3 {
  font-size: 20px;
  color: var(--fg-bright);
  margin-top: 44px;
  margin-bottom: 14px;
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  font-weight: 600;
}

h4 {
  font-size: 17px;
  color: var(--fg-bright);
  margin-top: 30px;
  margin-bottom: 10px;
  font-weight: 600;
}

h5 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--fg-dim);
  margin-top: 24px;
  margin-bottom: 8px;
  font-weight: 700;
}

/* ============================================================
   PROSE
   ============================================================ */

p {
  margin: 14px 0;
}

p.lead {
  font-size: 17.5px;
  line-height: 1.7;
  color: var(--fg);
  margin: 0 0 28px 0;
}

p.lead::first-letter,
.drop-cap::first-letter {
  font-size: 3.6em;
  float: left;
  line-height: 0.9;
  font-weight: 700;
  margin-right: 10px;
  margin-top: 8px;
  color: var(--accent);
  font-family: "Georgia", "Iowan Old Style", "Source Serif Pro", serif;
}

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.12s, color 0.12s;
}
a:hover {
  color: var(--link-hover);
  border-bottom-color: var(--link-hover);
}
strong { color: var(--fg-bright); font-weight: 600; }
em { color: var(--accent); font-style: normal; font-weight: 500; }
em.italic { font-style: italic; color: inherit; font-weight: inherit; }

ul, ol { padding-left: 26px; }
ul li, ol li { margin: 6px 0; }
ol ol, ul ul, ol ul, ul ol { margin-top: 4px; margin-bottom: 4px; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

/* ============================================================
   CODE
   ============================================================ */

code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", monospace;
  background: rgba(139, 21, 56, 0.06);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.86em;
  border: 1px solid rgba(139, 21, 56, 0.08);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 18px 22px;
  overflow-x: auto;
  margin: 20px 0;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
pre code {
  background: none;
  padding: 0;
  color: var(--code-default);
  font-size: inherit;
  border: none;
}
pre .filename {
  color: var(--fg-dim);
  font-size: 11.5px;
  display: block;
  margin: -4px 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  font-family: ui-monospace, monospace;
}
pre .filename .lines { color: var(--accent); }

/* token coloring (浅色背景版) */
.k { color: var(--code-keyword); font-weight: 500; }
.s { color: var(--code-string); }
.c { color: var(--code-comment); font-style: italic; }
.f { color: var(--code-fn); }
.n { color: var(--code-name); }
.num { color: var(--code-num); }
.deco { color: var(--code-num); }
.builtin { color: var(--code-num); }

.code-caption {
  font-size: 12.5px;
  color: var(--fg-dim);
  margin-top: -12px;
  margin-bottom: 26px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  font-style: italic;
}
.code-caption .listing {
  color: var(--accent);
  font-weight: 600;
  font-style: normal;
  margin-right: 6px;
}

/* ============================================================
   CALLOUTS
   ============================================================ */

.callout {
  border-left: 4px solid var(--info);
  background: var(--info-bg);
  padding: 16px 20px;
  margin: 24px 0;
  border-radius: 0 5px 5px 0;
  font-size: 15px;
  color: var(--fg);
}
.callout.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.callout.good { border-left-color: var(--good); background: var(--good-bg); }
.callout.tip  { border-left-color: var(--accent); background: var(--tip-bg); }
.callout.research { border-left-color: var(--research); background: var(--research-bg); }
.callout .label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 1.4px;
  color: var(--info);
  display: block;
  margin-bottom: 6px;
}
.callout.warn .label { color: var(--warn); }
.callout.good .label { color: var(--good); }
.callout.tip  .label { color: var(--accent); }
.callout.research .label { color: var(--research); }
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }

.research-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--research);
  background: var(--bg-elev);
  padding: 18px 22px;
  margin: 28px 0;
  border-radius: 0 5px 5px 0;
}
.research-card .ref-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--research);
  font-weight: 700;
  margin-bottom: 6px;
}
.research-card .ref-title {
  font-size: 15px;
  color: var(--fg-bright);
  font-weight: 600;
  margin-bottom: 4px;
}
.research-card .ref-meta {
  font-size: 12.5px;
  color: var(--fg-dim);
  margin-bottom: 10px;
  font-family: ui-monospace, monospace;
}
.research-card p:last-child { margin-bottom: 0; }

blockquote {
  margin: 28px 0;
  padding: 8px 0 8px 24px;
  border-left: 3px solid var(--accent);
  color: var(--fg-soft);
  font-style: italic;
  font-size: 16.5px;
  line-height: 1.6;
}
blockquote footer {
  font-style: normal;
  font-size: 13px;
  color: var(--fg-dim);
  margin-top: 10px;
}
blockquote footer::before { content: "— "; }

/* ============================================================
   TABLES
   ============================================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 22px 0;
  font-size: 14px;
  border-top: 2px solid var(--fg-bright);
  border-bottom: 2px solid var(--fg-bright);
}
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--fg-bright);
  font-weight: 600;
  border-bottom: 1px solid var(--fg-bright);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--bg-elev);
}
tr:hover td { background: var(--bg-hover); }

/* ============================================================
   DIAGRAM (ASCII, legacy)
   ============================================================ */

.diagram {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  padding: 22px;
  border-radius: 5px;
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  overflow-x: auto;
  color: var(--fg);
  margin: 24px 0;
  white-space: pre;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
.diagram .accent { color: var(--accent); }
.diagram .dim { color: var(--fg-dim); }
.diagram .good { color: var(--good); }
.diagram .warn { color: var(--warn); }

/* ============================================================
   MERMAID
   ============================================================ */

pre.mermaid {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 28px 20px;
  margin: 28px 0;
  text-align: center;
  overflow-x: auto;
  font-size: 0;
  line-height: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
pre.mermaid svg {
  max-width: 100%;
  height: auto;
  font-size: 14px;
  line-height: 1.4;
}

/* ============================================================
   KBD
   ============================================================ */

kbd {
  background: var(--kbd-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 7px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--fg-bright);
  box-shadow: 0 1px 0 var(--border-strong);
}

/* ============================================================
   STEP LIST
   ============================================================ */

.step-list {
  counter-reset: step;
  padding-left: 0;
  list-style: none;
}
.step-list > li {
  counter-increment: step;
  position: relative;
  padding: 4px 0 16px 50px;
  margin-bottom: 8px;
}
.step-list > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 4px;
  width: 32px;
  height: 32px;
  line-height: 30px;
  text-align: center;
  background: var(--bg);
  color: var(--accent);
  border: 2px solid var(--accent);
  font-weight: 700;
  border-radius: 50%;
  font-size: 13px;
  font-family: ui-monospace, monospace;
}

/* ============================================================
   GRID CARDS
   ============================================================ */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 22px 0; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; margin: 22px 0; }
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
.card h4 { margin-top: 0; color: var(--accent); }
.card p:last-child { margin-bottom: 0; }

/* ============================================================
   EXERCISES
   ============================================================ */

.exercises {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 26px 30px;
  margin-top: 56px;
}
.exercises h3 {
  border-left: none;
  padding-left: 0;
  margin-top: 0;
  font-size: 17px;
  color: var(--accent);
  letter-spacing: 0.3px;
}
.exercises ol {
  margin: 0;
  padding-left: 24px;
}
.exercises ol li {
  margin: 14px 0;
  padding-left: 6px;
}
.exercises .difficulty {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 9px;
  border-radius: 10px;
  margin-right: 10px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  border: 1px solid currentColor;
}
.exercises .d-easy { color: var(--good); background: rgba(47, 93, 58, 0.07); }
.exercises .d-medium { color: var(--warn); background: rgba(184, 92, 0, 0.07); }
.exercises .d-hard { color: var(--research); background: rgba(107, 68, 136, 0.07); }

/* ============================================================
   FOOTER NAV (next / prev chapter)
   ============================================================ */

.chapter-foot {
  margin-top: 96px;
  padding-top: 32px;
  border-top: 2px solid var(--accent);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.chapter-foot a {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 18px 22px;
  text-decoration: none;
  color: var(--fg);
  transition: border-color 0.15s, background 0.15s;
}
.chapter-foot a:hover {
  border-color: var(--accent);
  background: var(--bg-elev);
}
.chapter-foot a .direction {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--fg-dim);
  margin-bottom: 6px;
}
.chapter-foot a .title {
  font-size: 14.5px;
  color: var(--fg-bright);
  font-weight: 600;
}
.chapter-foot a.next { text-align: right; }
.chapter-foot a.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ============================================================
   INDEX (HOME) STYLES
   ============================================================ */

.hero {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 52px 60px 44px 60px;
  margin-bottom: 56px;
  position: relative;
}
.hero::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 8px 8px 0 0;
}
.hero h1 {
  font-size: 46px;
  margin: 8px 0 14px 0;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.1;
}
.hero .tagline {
  font-size: 18px;
  color: var(--fg-soft);
  margin: 0;
  font-style: italic;
}
.hero .author {
  color: var(--fg-dim);
  font-size: 12.5px;
  margin-top: 28px;
  letter-spacing: 0.5px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}

.toc-part {
  margin-bottom: 40px;
}
.toc-part .part-banner {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--fg-bright);
  margin-bottom: 18px;
}
.toc-part .part-num {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 2px;
  font-weight: 700;
}
.toc-part .part-name {
  font-size: 22px;
  color: var(--fg-bright);
  font-weight: 700;
}
.toc-part .part-desc {
  font-size: 14px;
  color: var(--fg-dim);
  font-style: italic;
  margin-left: auto;
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-list li {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 18px;
  padding: 12px 14px;
  border-radius: 4px;
  align-items: baseline;
  border-bottom: 1px dashed var(--border-soft);
}
.toc-list li:last-child { border-bottom: none; }
.toc-list li:hover { background: var(--bg-elev); }
.toc-list .num {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}
.toc-list .title a {
  color: var(--fg-bright);
  font-weight: 600;
  font-size: 15.5px;
  text-decoration: none;
  border-bottom: none;
}
.toc-list .title a:hover { color: var(--accent); }
.toc-list .desc {
  display: block;
  font-size: 13px;
  color: var(--fg-dim);
  margin-top: 4px;
  font-weight: 400;
}
.toc-list .pages {
  color: var(--fg-dim);
  font-size: 12px;
  font-family: ui-monospace, monospace;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1100px) {
  main { padding: 36px 48px 88px 48px; }
}
@media (max-width: 980px) {
  nav.sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .layout { flex-direction: column; }
  main { padding: 28px 20px 80px 20px; max-width: 100%; }
  .chapter-head h1 { font-size: 30px; }
  h2.section { font-size: 22px; }
  h3 { font-size: 18px; }
  .hero { padding: 32px 26px 28px 26px; }
  .hero h1 { font-size: 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .chapter-foot { grid-template-columns: 1fr; }
}

/* ============================================================
   PRINT
   ============================================================ */

@media print {
  nav.sidebar, .chapter-foot, .breadcrumb { display: none; }
  body { background: white; color: black; }
  main { max-width: 100%; padding: 0; }
  pre { border: 1px solid #ccc; background: #f8f8f8; color: #222; }
  pre code { color: #222; }
  .callout { background: #f8f8f8; border-left-color: #888; color: #222; }
  a { color: #1a4d80; }
}
