/* ============================================================
   CUDA × LLM 推理 — Book Style (Light, Editorial)
   纸质感浅色主题。端正、正式、长时间阅读友好。
   参考 Hermes Agent Tutorial 的设计语言。
   ============================================================ */

: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;
  --code-num:     #a86420;
  --code-default: #2a2723;

  --sidebar-w: 296px;
}

* { 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;
}

/* ============================================================
   顶部进度条
   ============================================================ */
#progress {
  position: fixed;
  top: 0; left: 0;
  width: 0%;
  height: 3px;
  background: var(--accent);
  z-index: 1000;
  transition: width 80ms linear;
}

/* ============================================================
   LAYOUT — sidebar + main
   ============================================================ */
#layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
#sidebar {
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 28px 22px;
  font-size: 13.5px;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

#sidebar h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: 0.2px;
  line-height: 1.3;
}
#sidebar h1 a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: none;
}
#sidebar h1::after {
  content: "A Code-Level Book";
  display: block;
  color: var(--fg-dim);
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

#sidebar nav { margin-top: 18px; }
#sidebar nav .stage {
  font-size: 10.5px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: 20px 0 8px;
  font-weight: 700;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}
#sidebar nav .stage:first-child { padding-top: 0; border-top: none; margin-top: 0; }

#sidebar nav ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: ch;
}
#sidebar nav li {
  counter-increment: ch;
  margin: 2px 0;
  padding: 4px 0 4px 10px;
  border-left: 2px solid transparent;
  transition: border-color 0.12s, background 0.12s;
}
#sidebar nav li:hover { background: var(--bg-hover); }
#sidebar nav li::before { content: ""; }
#sidebar nav a {
  display: block;
  color: var(--fg);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.45;
  border-bottom: none;
}
#sidebar nav a::before {
  content: counter(ch, decimal-leading-zero);
  display: inline-block;
  width: 28px;
  color: var(--fg-dim);
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11.5px;
}
#sidebar nav a:hover { color: var(--accent); }
#sidebar nav a.current {
  color: var(--accent);
  font-weight: 600;
}
#sidebar nav li:has(a.current) {
  border-left-color: var(--accent);
  background: rgba(139, 21, 56, 0.06);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
main {
  max-width: 880px;
  padding: 48px 72px 100px;
  margin: 0 auto;
  min-width: 0;
}

main h1 {
  font-size: 40px;
  line-height: 1.18;
  margin: 0 0 18px;
  color: var(--fg-bright);
  font-weight: 700;
  letter-spacing: -0.4px;
  padding-bottom: 28px;
  border-bottom: 2px solid var(--accent);
}

main h2 {
  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;
}

main 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;
}

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

main p { margin: 14px 0; }

/* 章首第一段（紧跟 chapter-meta 之后的）自动放大 */
main .chapter-meta + p {
  font-size: 17.5px;
  line-height: 1.7;
  color: var(--fg);
  margin: 0 0 28px;
}

main a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.12s, color 0.12s;
}
main a:hover {
  color: var(--link-hover);
  border-bottom-color: var(--link-hover);
}

main strong { color: var(--fg-bright); font-weight: 600; }
main em { color: var(--accent); font-style: normal; font-weight: 500; }

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

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

/* ============================================================
   章节 meta 信息条
   ============================================================ */
.chapter-meta {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  margin: -6px 0 36px;
  font-size: 12.5px;
  color: var(--fg-dim);
  letter-spacing: 0.3px;
  padding: 0;
  background: none;
  border-left: none;
  border-radius: 0;
}
.chapter-meta span { display: inline-flex; align-items: center; gap: 4px; }
.chapter-meta span + span::before {
  content: "·";
  margin-right: 14px;
  color: var(--border-strong);
}

/* ============================================================
   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, pre[class*="language-"] {
  background: var(--bg-code) !important;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 18px 22px !important;
  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);
  color: var(--code-default);
}
pre code {
  background: none;
  padding: 0;
  color: var(--code-default);
  font-size: inherit;
  border: none;
}

.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--bg);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms, color 120ms, border-color 120ms;
  font-family: ui-monospace, monospace;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.ok { color: var(--good); border-color: var(--good); }

/* ============================================================
   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.danger  { border-left-color: var(--accent); background: var(--tip-bg); }
.callout.ok      { 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 strong  { color: var(--accent-dim); }
.callout.warn strong { color: #8a4500; }
.callout.ok strong   { color: var(--good); }
.callout p:first-child { margin-top: 0; }
.callout p:last-child  { margin-bottom: 0; }

/* ============================================================
   BLOCKQUOTE
   ============================================================ */
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;
}

/* ============================================================
   TABLES — editorial
   ============================================================ */
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);
  background: transparent;
  border-radius: 0;
}
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:nth-child(even) td { background: transparent; }
tr:hover td { background: var(--bg-hover); }
tr:last-child td { border-bottom: none; }

/* ============================================================
   DETAILS / 自检
   ============================================================ */
details {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 16px;
  margin: 10px 0;
  transition: border-color 120ms;
}
details:hover { border-color: var(--border-strong); }
details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  position: relative;
  padding-left: 22px;
  font-size: 14.5px;
}
details > summary::before {
  content: "▶";
  position: absolute;
  left: 0;
  font-size: 10px;
  color: var(--fg-dim);
  transition: transform 120ms;
  top: 6px;
}
details[open] > summary::before { transform: rotate(90deg); }
details[open] { padding-bottom: 14px; }
details > summary::-webkit-details-marker { display: none; }
details p:last-child { margin-bottom: 0; }

/* ============================================================
   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;
}

/* ============================================================
   章末导航 prev / next
   ============================================================ */
.chapter-nav {
  margin-top: 96px;
  padding-top: 32px;
  border-top: 2px solid var(--accent);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.chapter-nav 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-nav a:hover {
  border-color: var(--accent);
  background: var(--bg-elev);
}
.chapter-nav a.next { text-align: right; }
.chapter-nav .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--fg-dim);
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

/* ============================================================
   术语 tooltip
   ============================================================ */
.term {
  border-bottom: 1px dashed var(--accent);
  cursor: help;
  position: relative;
}
.term:hover::after {
  content: attr(data-en);
  position: absolute;
  bottom: 130%; left: 50%; transform: translateX(-50%);
  background: var(--fg-bright);
  color: var(--bg);
  padding: 5px 10px;
  border-radius: 3px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
}

/* ============================================================
   首页 hero + 路线图卡片
   ============================================================ */
.hero {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 52px 60px 44px;
  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;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.1;
  padding: 0;
  border-bottom: none;
}
.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);
}

.roadmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin: 28px 0;
}
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 20px;
  text-decoration: none;
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s, transform 0.12s;
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.card .num {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  font-size: 11.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 700;
}
.card .title {
  font-size: 16px;
  color: var(--fg-bright);
  font-weight: 600;
  margin: 6px 0 4px;
}
.card .desc {
  color: var(--fg-soft);
  font-size: 13px;
  line-height: 1.55;
}

.stage-banner {
  margin: 44px 0 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--fg-bright);
  color: var(--fg-bright);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.4px;
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.stage-banner::before {
  content: attr(data-part);
  font-family: ui-monospace, monospace;
  color: var(--accent);
  font-size: 14px;
  letter-spacing: 2px;
  font-weight: 700;
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 1100px) {
  main { padding: 36px 48px 88px; }
}
@media (max-width: 980px) {
  #layout { grid-template-columns: 1fr; }
  #sidebar {
    position: static;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  main { padding: 28px 20px 80px; max-width: 100%; }
  main h1 { font-size: 30px; }
  main h2 { font-size: 22px; }
  main h3 { font-size: 18px; }
  .hero { padding: 32px 26px 28px; }
  .hero h1 { font-size: 32px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .roadmap { grid-template-columns: 1fr; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  #sidebar, #progress, .copy-btn, .chapter-nav { 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; }
}
