:root {
  --bg: #fafaf7;
  --bg-side: #f0ede5;
  --text: #1a1a1a;
  --text-soft: #555;
  --text-mute: #888;
  --accent: #c2410c;
  --accent-soft: #fef3c7;
  --link: #1d4ed8;
  --border: #d6d3c4;
  --code-bg: #f5f5f0;
  --quote-bar: #c2410c;
  --table-header: #ede9d8;
  --star: #d97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Serif TC", "Songti TC", "PingFang TC", Georgia, serif;
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: 280px 1fr;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Sidebar ─────────────────────────────────── */
nav.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem 1.5rem 1.5rem;
  font-family: "PingFang TC", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  font-size: 14px;
}

nav.sidebar .brand {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--accent);
  letter-spacing: 0.5px;
}
nav.sidebar .brand-sub {
  font-size: 12px;
  color: var(--text-mute);
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

nav.sidebar ol {
  list-style: none;
  padding-left: 0;
}
nav.sidebar > ol > li {
  margin: 0.7rem 0 0.4rem 0;
}
nav.sidebar > ol > li > a.part {
  font-weight: 700;
  color: var(--text);
  display: block;
  padding: 0.2rem 0;
  border-bottom: 1px solid transparent;
}
nav.sidebar > ol > li > a.part:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }

nav.sidebar ol ol {
  padding-left: 0.8rem;
  margin-top: 0.2rem;
}
nav.sidebar ol ol li {
  margin: 0.15rem 0;
}
nav.sidebar ol ol li a {
  color: var(--text-soft);
  font-size: 13px;
  display: block;
  padding: 1px 0;
}
nav.sidebar ol ol li a:hover { color: var(--accent); text-decoration: none; }
nav.sidebar ol ol li a.active { color: var(--accent); font-weight: 600; }

/* ─── Main content ───────────────────────────── */
main {
  max-width: 800px;
  padding: 3rem 3.5rem 6rem 3.5rem;
}

main header.doc-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--border);
}
main header.doc-header h1 {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--accent);
  margin-bottom: 0.8rem;
}
main header.doc-header p.subtitle {
  font-size: 16px;
  color: var(--text-soft);
  line-height: 1.6;
}
main header.doc-header .meta {
  margin-top: 1.5rem;
  font-size: 13px;
  color: var(--text-mute);
  font-family: "PingFang TC", -apple-system, sans-serif;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
}
main header.doc-header .meta b { color: var(--text-soft); font-weight: 600; }

main section.part {
  margin: 3rem 0 2rem 0;
  padding-top: 2rem;
  border-top: 4px double var(--accent);
}
main section.part > h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
  letter-spacing: 0.5px;
}
main section.part > .part-intro {
  font-size: 15px;
  color: var(--text-soft);
  font-style: italic;
  margin-bottom: 1.5rem;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
}

main section.subsection {
  margin: 2rem 0;
  padding-top: 1rem;
}
main section.subsection > h3 {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
main section.subsection > h3 .star {
  color: var(--star);
  margin-right: 0.3rem;
  font-size: 16px;
}
main section.subsection > h4 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin: 1.5rem 0 0.5rem 0;
}
main section.subsection p {
  margin: 0.7rem 0;
}
main section.subsection ul, main section.subsection ol {
  margin: 0.7rem 0 0.7rem 1.5rem;
}
main section.subsection ul li, main section.subsection ol li {
  margin: 0.3rem 0;
}

main section.subsection strong { color: var(--text); font-weight: 700; }
main section.subsection em { font-style: italic; }

main section.subsection blockquote {
  margin: 1rem 0;
  padding: 0.8rem 1.2rem;
  background: var(--accent-soft);
  border-left: 4px solid var(--quote-bar);
  color: var(--text);
  font-style: normal;
}
main section.subsection blockquote p { margin: 0.3rem 0; }
main section.subsection blockquote.citation {
  background: #f5f5f0;
  border-left-color: var(--border);
  color: var(--text-soft);
  font-size: 14px;
}

main section.subsection .callout {
  margin: 1rem 0;
  padding: 1rem 1.2rem;
  border-radius: 4px;
  font-size: 15px;
}
.callout.warn { background: #fef2f2; border-left: 4px solid #dc2626; }
.callout.tip  { background: #ecfdf5; border-left: 4px solid #059669; }
.callout.info { background: #eff6ff; border-left: 4px solid #2563eb; }
.callout.key  { background: #fef3c7; border-left: 4px solid #d97706; }
.callout > .callout-label {
  font-weight: 700;
  font-family: "PingFang TC", sans-serif;
  font-size: 13px;
  display: block;
  margin-bottom: 0.3rem;
  letter-spacing: 0.5px;
}
.callout.warn .callout-label { color: #dc2626; }
.callout.tip  .callout-label { color: #059669; }
.callout.info .callout-label { color: #2563eb; }
.callout.key  .callout-label { color: #b45309; }

main section.subsection table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 14.5px;
  font-family: "PingFang TC", -apple-system, sans-serif;
}
main section.subsection th, main section.subsection td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  text-align: left;
  vertical-align: top;
}
main section.subsection th {
  background: var(--table-header);
  font-weight: 700;
}

main section.subsection figure {
  margin: 1.5rem 0;
  text-align: center;
}
main section.subsection figure img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
}
main section.subsection figure figcaption {
  font-size: 13px;
  color: var(--text-mute);
  margin-top: 0.5rem;
  font-family: "PingFang TC", -apple-system, sans-serif;
  font-style: italic;
}

main section.subsection code {
  background: var(--code-bg);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-family: "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 0.92em;
  color: var(--accent);
}
main section.subsection pre {
  background: var(--code-bg);
  padding: 1rem 1.2rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1rem 0;
  font-size: 14px;
  border: 1px solid var(--border);
}
main section.subsection pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

main section.subsection .source-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--text-mute);
  font-family: "PingFang TC", sans-serif;
  background: #f5f5f0;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* Footer */
footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-mute);
  font-family: "PingFang TC", sans-serif;
}

/* Responsive */
@media (max-width: 1024px) {
  body { grid-template-columns: 1fr; }
  nav.sidebar { position: relative; height: auto; max-height: 50vh; }
  main { padding: 2rem 1.5rem 4rem 1.5rem; }
}

/* Print */
@media print {
  nav.sidebar { display: none; }
  body { grid-template-columns: 1fr; }
  main { max-width: 100%; padding: 1cm; }
  section.part { break-before: page; }
}
