/* Font display optimization */
/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1a1a1a;
  background: #f9fafb;
  line-height: 1.75;
  font-size: 16px;
}
a { color: #4c6ef5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100vh;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
  overflow-y: auto;
  z-index: 100;
  padding: 24px 0;
  transition: transform 0.3s;
}
.sidebar-header {
  padding: 0 20px 16px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 8px;
}
.sidebar-header a {
  font-size: 18px;
  font-weight: 700;
  color: #1a1a1a;
}
.sidebar-header a:hover { text-decoration: none; color: #4c6ef5; }
.nav-list { list-style: none; }
.nav-item {}
.nav-link {
  display: flex;
  align-items: center;
  padding: 8px 20px;
  font-size: 14px;
  color: #4b5563;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  line-height: 1.5;
}
.nav-link:hover { background: #f3f4f6; color: #1a1a1a; text-decoration: none; }
.nav-link.active { background: #eef2ff; color: #4c6ef5; font-weight: 600; border-right: 3px solid #4c6ef5; }
.nav-link .arrow {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s;
  color: #9ca3af;
}
.nav-item.expanded .arrow { transform: rotate(90deg); }
.sub-nav { list-style: none; display: none; }
.nav-item.expanded .sub-nav { display: block; }
.sub-nav li a {
  display: block;
  padding: 5px 20px 5px 36px;
  font-size: 13px;
  color: #6b7280;
  transition: color 0.15s;
  line-height: 1.5;
}
.sub-nav li a:hover { color: #4c6ef5; text-decoration: none; }
.sub-nav li a.active { color: #4c6ef5; font-weight: 600; }

/* ===== Main content area ===== */
.main {
  margin-left: 280px;
  padding: 40px 48px 80px;
}
.content {
  max-width: 860px;
  margin: 0 auto;
}

/* ===== Markdown rendered styles ===== */
.content h1 { font-size: 2em; font-weight: 700; margin: 0.6em 0 0.4em; color: #111; border-bottom: 2px solid #e5e7eb; padding-bottom: 0.3em; }
.content h2 { font-size: 1.5em; font-weight: 700; margin: 1.6em 0 0.6em; color: #1a1a1a; border-bottom: 1px solid #f0f0f0; padding-bottom: 0.25em; }
.content h3 { font-size: 1.25em; font-weight: 600; margin: 1.4em 0 0.5em; color: #333; }
.content h4 { font-size: 1.1em; font-weight: 600; margin: 1.2em 0 0.4em; color: #444; }
.content p { margin: 0.8em 0; }
.content ul, .content ol { margin: 0.8em 0; padding-left: 2em; }
.content li { margin: 0.3em 0; }
.content blockquote {
  margin: 1em 0;
  padding: 12px 20px;
  border-left: 4px solid #4c6ef5;
  background: #f5f7ff;
  color: #374151;
  border-radius: 0 4px 4px 0;
}
.content blockquote p { margin: 0.4em 0; }
.content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}
.content pre {
  margin: 1em 0;
  padding: 16px 20px;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.6;
}
.content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.875em;
}
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.95em;
}
.content table th,
.content table td {
  border: 1px solid #e5e7eb;
  padding: 10px 14px;
  text-align: left;
}
.content table th {
  background: #f9fafb;
  font-weight: 600;
}
.content table tr:nth-child(even) { background: #fafbfc; }
.content img { max-width: 100%; height: auto; border-radius: 6px; margin: 1em 0; }
.content hr { border: none; border-top: 1px solid #e5e7eb; margin: 2em 0; }
.content strong { font-weight: 600; }

/* ===== Page navigation (prev/next) ===== */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}
.page-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  color: #4b5563;
  transition: border-color 0.2s, color 0.2s;
}
.page-nav a:hover { border-color: #4c6ef5; color: #4c6ef5; text-decoration: none; }
.page-nav .spacer { flex: 1; }

/* ===== Hamburger for mobile ===== */
.hamburger {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #374151;
}
.overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 90;
}

/* ===== Index page ===== */
.index-hero {
  text-align: center;
  padding: 80px 20px 40px;
}
.index-hero h1 {
  font-size: 2.8em;
  font-weight: 800;
  color: #1a1a1a;
  margin-bottom: 16px;
}
.index-hero p {
  font-size: 1.15em;
  color: #6b7280;
  max-width: 640px;
  margin: 0 auto;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  max-width: 960px;
  margin: 40px auto;
  padding: 0 20px;
}
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 24px;
  transition: box-shadow 0.2s, transform 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-2px);
  text-decoration: none;
}
.card .ch-num {
  display: inline-block;
  background: #eef2ff;
  color: #4c6ef5;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.card h3 {
  font-size: 1.1em;
  font-weight: 600;
  margin-bottom: 8px;
  color: #1a1a1a;
}
.card p {
  font-size: 0.9em;
  color: #6b7280;
  line-height: 1.6;
}

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; }
  .overlay.open { display: block; }
  .main { margin-left: 0; padding: 60px 20px 80px; }
  .index-hero { padding-top: 60px; }
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
/* ===== Illustration Component ===== */
.illustration {
  text-align: center;
  margin: 2rem auto;
  max-width: 680px;
}
.illustration img {
  width: 100%;
  border-radius: 12px;
  border: 2px solid #e8eaed;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.illustration .caption {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #666;
  font-style: italic;
}


/* Chapter Social QR Code Section */
.chapter-social {
  margin: 3rem 0;
  padding: 2rem;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-radius: 16px;
  text-align: center;
}

.chapter-social h3 {
  font-size: 1.25rem;
  color: #0c4a6e;
  margin-bottom: 0.5rem;
}

.chapter-social > p {
  color: #475569;
  margin-bottom: 1.5rem;
}

.chapter-qr-grid {
  display: flex;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.chapter-qr-item {
  text-align: center;
}

.chapter-qr-item img,
.chapter-qr-item .qr-fallback {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: #4f46e5;
  margin-bottom: 0.5rem;
}

.chapter-qr-item span {
  font-size: 0.9rem;
  color: #334155;
  font-weight: 500;
}

@media (max-width: 640px) {
  .chapter-social {
    padding: 1.5rem;
  }
  
  .chapter-qr-item img,
  .chapter-qr-item .qr-fallback {
    width: 100px;
    height: 100px;
  }
}
