@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700;900&family=Noto+Sans+SC:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --color-bg: #FCFCF9;
  --color-bg-sidebar: #F5F4F0;
  --color-bg-card: #F8F8F5;
  --color-bg-code: #F2F1ED;
  --color-bg-highlight: #F5F8F7;
  --color-text: #1D1D1F;
  --color-text-secondary: #5E5E63;
  --color-text-muted: #8E8E8C;
  --color-accent: #2F6B6E;
  --color-accent-hover: #255558;
  --color-accent-light: rgba(47, 107, 110, 0.06);
  --color-accent-soft: rgba(47, 107, 110, 0.12);
  --color-border: #E8E8E4;
  --color-border-light: #F0EFEB;
  --color-tag: #B8935A;
  --color-shadow: rgba(29, 29, 31, 0.04);
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', Georgia, serif;
  --font-sans: 'Noto Sans SC', 'Source Han Sans SC', 'PingFang SC', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --sidebar-width: 260px;
  --content-max-width: 720px;
  --header-height: 56px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.88;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

/* ---- Progress Bar ---- */
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  width: 0%;
  height: 2px;
  background: var(--color-accent);
  z-index: 10001;
  transition: width 0.08s linear;
}

/* ---- Header ---- */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: rgba(252, 252, 249, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
  z-index: 10000;
  display: flex;
  align-items: center;
  padding: 0 24px;
}

.header-inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-right: 12px;
  color: var(--color-text);
}

.menu-toggle svg { width: 20px; height: 20px; }

.site-title {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.site-title a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.site-title a:hover { color: var(--color-accent); }

.site-title .separator {
  margin: 0 8px;
  color: var(--color-border);
}

.site-title .book-name {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-nav a {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.header-nav a:hover { color: var(--color-accent); }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 28px 0;
  z-index: 9998;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

.sidebar-section { margin-bottom: 24px; }

.sidebar-label {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  padding: 0 20px;
  margin-bottom: 8px;
}

.sidebar-nav { list-style: none; }

.sidebar-nav a {
  display: block;
  padding: 5px 20px;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
}

.sidebar-nav a:hover {
  color: var(--color-text);
  background: var(--color-accent-light);
}

.sidebar-nav a.active {
  color: var(--color-accent);
  background: var(--color-accent-light);
  border-left-color: var(--color-accent);
  font-weight: 500;
}

.sidebar-nav .chapter-num {
  display: inline-block;
  min-width: 22px;
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.75rem;
}

.sidebar-divider {
  height: 1px;
  background: var(--color-border);
  margin: 16px 20px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(29, 29, 31, 0.25);
  z-index: 9997;
}

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
  display: flex;
  justify-content: center;
  padding: 56px 48px 96px;
}

.content-wrapper {
  width: 100%;
  max-width: var(--content-max-width);
}

/* ---- Hero (Index) ---- */
.hero {
  text-align: center;
  padding: 72px 0 64px;
  margin-bottom: 56px;
  border-bottom: 1px solid var(--color-border);
}

.hero-site-name {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--color-text-muted);
  margin-bottom: 24px;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 2.625rem;
  font-weight: 900;
  line-height: 1.25;
  color: var(--color-text);
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.hero-subtitle {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--color-text-secondary);
  margin-bottom: 32px;
  font-style: italic;
}

.hero-description {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  line-height: 1.9;
  color: var(--color-text-secondary);
  max-width: 580px;
  margin: 0 auto 32px;
  text-align: left;
}

.hero-meta {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  flex-wrap: wrap;
}

.hero-meta span {
  padding: 4px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
}

/* ---- Chapter Cards ---- */
.chapter-list-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 8px;
}

.chapter-list-section-title {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-top: 40px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
}

.ch-card {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding: 20px 20px;
  margin-bottom: 6px;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  transition: all 0.2s ease;
}

.ch-card:hover {
  background: var(--color-bg-card);
  border-color: var(--color-border);
  box-shadow: 0 2px 12px var(--color-shadow);
}

.ch-card:hover .ch-card-name { color: var(--color-accent); }
.ch-card:hover .ch-card-arrow { opacity: 1; transform: translateX(0); }

.ch-card-num {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 24px;
  padding-top: 3px;
  flex-shrink: 0;
}

.ch-card-body { flex: 1; min-width: 0; }

.ch-card-name {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  margin-bottom: 4px;
  transition: color 0.2s;
}

.ch-card-desc {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.65;
  color: var(--color-text-muted);
}

.ch-card-arrow {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--color-accent);
  opacity: 0;
  transform: translateX(-6px);
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding-top: 2px;
}

/* ---- Chapter Header ---- */
.chapter-header {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--color-border);
}

.chapter-number {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--color-accent);
  margin-bottom: 12px;
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--color-text);
  margin-bottom: 12px;
}

.chapter-subtitle {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--color-text-secondary);
}

/* ---- Prose Content ---- */
.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--color-text);
  margin-top: 56px;
  margin-bottom: 20px;
  padding-top: 28px;
  border-top: 1px solid var(--color-border-light);
}

.prose h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--color-text);
  margin-top: 40px;
  margin-bottom: 14px;
}

.prose h4 {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  margin-top: 32px;
  margin-bottom: 10px;
}

.prose p { margin-bottom: 20px; }

.prose strong { font-weight: 600; color: var(--color-text); }
.prose em { font-style: italic; }

.prose ul, .prose ol {
  margin-bottom: 20px;
  padding-left: 24px;
}

.prose li { margin-bottom: 8px; }
.prose li > ul, .prose li > ol { margin-bottom: 0; margin-top: 8px; }

.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-code);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--color-accent);
}

.prose pre {
  background: var(--color-bg-code);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 20px 24px;
  margin-bottom: 24px;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.7;
}

.prose pre code { background: none; padding: 0; color: var(--color-text); font-size: inherit; }

.prose blockquote {
  border-left: 3px solid var(--color-accent);
  padding: 16px 24px;
  margin: 24px 0;
  background: var(--color-accent-light);
  font-style: italic;
  color: var(--color-text-secondary);
}

.prose blockquote p:last-child { margin-bottom: 0; }

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 24px 0;
  border: 1px solid var(--color-border-light);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.prose th, .prose td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.prose th {
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg-sidebar);
}

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

/* ---- Key Points Box ---- */
.key-points {
  background: var(--color-bg-highlight);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 28px 28px 24px;
  margin: 40px 0;
}

.key-points-title {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.key-points-title::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 2px;
  background: var(--color-accent);
}

.key-points ul { list-style: none; padding: 0; }
.key-points li {
  position: relative;
  padding-left: 16px;
  margin-bottom: 10px;
  font-size: 0.9375rem;
  line-height: 1.8;
  color: var(--color-text-secondary);
}

.key-points li::before {
  content: '';
  position: absolute;
  left: 0; top: 12px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.5;
}

.key-points li:last-child { margin-bottom: 0; }

/* ---- Chapter TOC ---- */
.chapter-toc {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 24px 28px;
  margin-bottom: 40px;
}

.chapter-toc-title {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 14px;
}

.chapter-toc ol { list-style: none; padding: 0; counter-reset: toc-counter; }

.chapter-toc li {
  counter-increment: toc-counter;
  margin-bottom: 5px;
}

.chapter-toc a {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.15s;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.chapter-toc a:hover { color: var(--color-accent); }

.chapter-toc a::before {
  content: counter(toc-counter, decimal-leading-zero);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  min-width: 20px;
}

/* ---- Chapter Navigation ---- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--color-border);
}

.chapter-nav a {
  display: block;
  text-decoration: none;
  flex: 1;
  max-width: 50%;
  padding: 20px 24px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.chapter-nav a:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.chapter-nav a:hover .nav-title { color: var(--color-accent); }

.chapter-nav .nav-next { text-align: right; margin-left: auto; }

.nav-label {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.nav-title {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  transition: color 0.2s;
}

/* ---- About Section ---- */
.about-section {
  margin-top: 56px;
  padding-top: 40px;
  border-top: 1px solid var(--color-border);
}

.about-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 20px;
}

.about-body p {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  line-height: 1.9;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

.about-body p:last-child { margin-bottom: 0; }

/* ---- Back to Top ---- */
.back-to-top {
  position: fixed;
  bottom: 32px; right: 32px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 9990;
  box-shadow: 0 2px 8px var(--color-shadow);
}

.back-to-top.visible { opacity: 1; visibility: visible; }
.back-to-top:hover { color: var(--color-accent); border-color: var(--color-accent); }
.back-to-top svg { width: 16px; height: 16px; }

/* ---- Footer ---- */
.site-footer {
  margin-left: var(--sidebar-width);
  padding: 32px 48px;
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.8;
}

.site-footer a {
  color: var(--color-text-secondary);
  text-decoration: none;
}

.site-footer a:hover { color: var(--color-accent); }

/* ---- 404 Page ---- */
.page-404 {
  text-align: center;
  padding: 120px 24px;
}

.page-404 .code {
  font-family: var(--font-serif);
  font-size: 5rem;
  font-weight: 900;
  color: var(--color-border);
  line-height: 1;
  margin-bottom: 20px;
}

.page-404 h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin-bottom: 16px;
  border: none;
  padding: 0;
}

.page-404 p {
  font-family: var(--font-sans);
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

.page-404 a {
  display: inline-block;
  padding: 10px 24px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--color-accent);
  text-decoration: none;
  transition: all 0.2s;
}

.page-404 a:hover {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .menu-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(29, 29, 31, 0.08); }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0; padding: 36px 24px 72px; }
  .site-footer { margin-left: 0; padding: 24px; }
}

@media (max-width: 640px) {
  :root { --header-height: 48px; }
  .hero { padding: 40px 0 36px; }
  .hero-title { font-size: 1.75rem; }
  .chapter-title { font-size: 1.5rem; }
  .prose h2 { font-size: 1.25rem; }
  .prose h3 { font-size: 1.0625rem; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .chapter-nav .nav-next { text-align: left; }
  .main-content { padding: 28px 16px 64px; }
  .header-nav { display: none; }
}

@media (min-width: 1200px) {
  .content-wrapper {
    position: relative;
  }
  .content-wrapper::after {
    content: '';
    position: absolute;
    top: 0; right: -24px;
    width: 1px; height: 100%;
    background: linear-gradient(180deg, transparent 0%, var(--color-border-light) 20%, var(--color-border-light) 80%, transparent 100%);
    pointer-events: none;
  }
}

@media print {
  .site-header, .sidebar, .progress-bar, .back-to-top, .chapter-nav, .chapter-toc, .sidebar-overlay { display: none !important; }
  .main-content { margin-left: 0 !important; margin-top: 0 !important; padding: 0 !important; }
  .site-footer { margin-left: 0 !important; }
}
