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

:root {
  --bg: #f0f4f8;
  --sidebar: #1e293b;
  --sidebar-hover: #334155;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --code-bg: #1e1e1e;
  --text: #1e293b;
  --muted: #64748b;
  --card: #ffffff;
  --border: #e2e8f0;
  --success: #22c55e;
  --error-bg: #fef2f2;
  --error-border: #ef4444;
  --quiz-bg: #f0fdf4;
  --quiz-border: #22c55e;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
}

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

.topbar {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.topbar-brand { min-width: 0; flex: 1 1 180px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }
.topbar .sub { font-size: 0.78rem; opacity: 0.9; }
.topbar a.home-link { color: white; font-size: 0.88rem; opacity: 0.95; white-space: nowrap; }

.topbar-search { margin: 0; }
.topbar-search .search-wrap { position: relative; }
.topbar-search input[type=search] {
  width: 220px; max-width: 42vw; padding: 8px 36px 8px 12px;
  border: none; border-radius: 20px; font-size: .88rem; outline: none;
}
.topbar-search button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer; font-size: 1rem; padding: 4px 8px;
}
.search-suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 280px;
  background: white; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 300; max-height: 320px; overflow-y: auto;
}
.suggest-item {
  display: block; padding: 10px 12px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid #f1f5f9;
}
.suggest-item:hover, .suggest-item.active { background: #eff6ff; text-decoration: none; }
.suggest-type {
  display: inline-block; font-size: .7rem; background: #e0e7ff; color: #3730a3;
  padding: 1px 6px; border-radius: 4px; margin-right: 6px;
}
.suggest-title { font-size: .88rem; font-weight: 600; display: block; margin-top: 2px; }
.suggest-meta { font-size: .75rem; color: var(--muted); display: block; margin-top: 2px; }

mark { background: #fef08a; padding: 0 2px; border-radius: 2px; }

.layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 270px;
  background: var(--sidebar);
  color: #cbd5e1;
  flex-shrink: 0;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar > nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav-home {
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid #334155;
  background: rgba(255, 255, 255, 0.04);
}
.nav-home:hover { background: var(--sidebar-hover); }

.sidebar-group { border-bottom: 1px solid #334155; }

.group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  background: transparent;
  color: #f1f5f9;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.group-title:hover { background: var(--sidebar-hover); color: #ffffff; }
.sidebar-group.expanded > .group-title {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.group-name {
  flex: 1;
  min-width: 0;
}

.group-chevron,
.chapter-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid #64748b;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.sidebar-group.expanded > .group-title .group-chevron,
.nav-chapter-block.expanded > .nav-chapter-row .chapter-chevron {
  transform: rotate(90deg);
}

.group-body {
  display: none;
}
.sidebar-group.expanded > .group-body {
  display: block;
}

.nav-chapter-block { border-top: 1px solid rgba(51, 65, 85, 0.5); }
.nav-chapter-block:first-child { border-top: none; }

.nav-chapter-row {
  display: flex;
  align-items: stretch;
  min-height: 0;
}

.nav-chapter-toggle {
  flex-shrink: 0;
  width: 28px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-chapter-toggle:hover { background: var(--sidebar-hover); }

.nav-chapter-row > .nav-chapter {
  flex: 1;
  min-width: 0;
  padding-left: 0 !important;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* 二级：章节图标（文档） */
.nav-level-icon {
  flex-shrink: 0;
  display: inline-block;
}
.nav-icon-l2 {
  width: 9px;
  height: 11px;
  border: 1.5px solid #94a3b8;
  border-radius: 1px;
  position: relative;
  top: -0.5px;
}
.nav-icon-l2::before {
  content: '';
  position: absolute;
  left: 1.5px;
  top: 2px;
  width: 4px;
  height: 1px;
  background: #94a3b8;
  box-shadow: 0 2.5px 0 #94a3b8, 0 5px 0 #94a3b8;
}
.nav-chapter:hover .nav-icon-l2,
.nav-chapter-block.has-active-section > .nav-chapter-row > .nav-chapter .nav-icon-l2 {
  border-color: #cbd5e1;
}
.nav-chapter:hover .nav-icon-l2::before,
.nav-chapter-block.has-active-section > .nav-chapter-row > .nav-chapter .nav-icon-l2::before {
  background: #cbd5e1;
  box-shadow: 0 2.5px 0 #cbd5e1, 0 5px 0 #cbd5e1;
}
.nav-chapter.active .nav-icon-l2 {
  border-color: #e2e8f0;
}
.nav-chapter.active .nav-icon-l2::before {
  background: #e2e8f0;
  box-shadow: 0 2.5px 0 #e2e8f0, 0 5px 0 #e2e8f0;
}
.group-body > .nav-item.nav-chapter {
  display: flex;
  align-items: center;
  gap: 7px;
}

.nav-sections {
  display: none;
  margin-left: 20px;
  padding: 2px 0 6px;
  border-left: 2px solid rgba(100, 116, 139, 0.35);
}
.nav-chapter-block.expanded > .nav-sections {
  display: block;
}

.nav-chapter-block.has-active-section > .nav-chapter-row > .nav-chapter {
  color: #c5d0df;
  font-weight: 600;
}

.nav-item {
  display: block;
  padding: 7px 14px 7px 18px;
  color: #94a3b8;
  font-size: 0.8125rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active {
  background: var(--sidebar-hover);
  color: #ffffff;
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-chapter {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #b0bdd0;
}
.nav-chapter:hover { color: #dbe4ef; }
.nav-chapter.active {
  color: #f1f5f9;
  font-weight: 600;
}
.nav-section {
  padding: 5px 12px 5px 16px !important;
  font-size: 0.75rem !important;
  font-weight: 400;
  color: #a8b8cc !important;
  line-height: 1.45;
}
.nav-section:hover { color: #dbe4ef !important; background: rgba(255, 255, 255, 0.04); }
.nav-section.active {
  color: #f1f5f9 !important;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.1);
  border-left-color: var(--accent);
}

.content {
  flex: 1;
  padding: 24px 28px 80px;
  max-width: 880px;
}

.breadcrumb {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.chapter-title {
  font-size: 1.65rem;
  margin-bottom: 8px;
}

.chapter-desc {
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 1rem;
}

.toc-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 28px;
}

.toc-box h3 { font-size: 0.95rem; margin-bottom: 10px; color: var(--muted); }
.toc-box ol { padding-left: 20px; }
.toc-box li { margin: 4px 0; font-size: 0.92rem; }
.toc-box a { color: var(--accent); }

.subsection {
  background: var(--card);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
}

.subsection h3 {
  font-size: 1.15rem;
  margin-bottom: 10px;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 2px solid #e2e8f0;
}

.subsection p, .subsection ul {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.subsection ul { padding-left: 22px; }

.example-card {
  border-radius: 10px;
  overflow: hidden;
  margin: 14px 0;
  border: 1px solid var(--border);
}

.example-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.example-header h4 { font-size: 0.9rem; font-weight: 600; }

.btn-copy {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.btn-copy:hover { background: var(--accent-dark); }
.btn-copy.copied { background: var(--success); }

pre.code-block {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  padding: 14px 16px;
  background: var(--code-bg);
  color: #d4d4d4;
  overflow-x: auto;
  white-space: pre;
}

.error-box {
  background: var(--error-bg);
  border-left: 4px solid var(--error-border);
  border-radius: 0 10px 10px 0;
  padding: 14px 16px;
  margin-top: 14px;
}

.error-box h4 {
  color: #b91c1c;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.error-box pre {
  font-family: Consolas, monospace;
  font-size: 0.82rem;
  background: #1e1e1e;
  color: #f87171;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.error-box p { font-size: 0.88rem; color: #7f1d1d; margin-top: 6px; }

.example-desc {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.6;
}

.compare-item {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #fecaca;
}
.compare-item:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

.compare-bad, .compare-good { margin-bottom: 8px; }
.compare-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.compare-bad .compare-label { color: #b91c1c; }
.compare-good .compare-label { color: #15803d; }
.compare-good pre {
  font-family: Consolas, monospace;
  font-size: 0.82rem;
  background: #14532d;
  color: #86efac;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0;
}
.compare-why {
  font-size: 0.88rem;
  color: #7f1d1d;
  margin: 6px 0 0;
  line-height: 1.55;
}

.tip-box {
  background: #eff6ff;
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  margin: 12px 0;
  font-size: 0.9rem;
  color: #1e40af;
}

.quiz-section {
  background: var(--quiz-bg);
  border: 2px solid var(--quiz-border);
  border-radius: 14px;
  padding: 24px;
  margin-top: 32px;
}

.quiz-section > h3 {
  font-size: 1.2rem;
  color: #166534;
  margin-bottom: 16px;
}

.quiz-item {
  background: white;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid #bbf7d0;
}

.quiz-item .q {
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.quiz-options label {
  display: block;
  padding: 6px 10px;
  margin: 4px 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.quiz-options label:hover { background: #f0fdf4; }

.quiz-options input { margin-right: 8px; }

.btn-check {
  font-family: inherit;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: #16a34a;
  color: white;
  cursor: pointer;
  margin-top: 8px;
  font-size: 0.9rem;
}

.btn-check:hover { background: #15803d; }

.quiz-result {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.quiz-result.show { display: block; }
.quiz-result.correct { background: #dcfce7; color: #166534; }
.quiz-result.wrong { background: #fee2e2; color: #991b1b; }

.quiz-answer {
  margin-top: 8px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 0.88rem;
  display: none;
}

.quiz-answer.show { display: block; }

.btn-show-answer {
  font-family: inherit;
  padding: 6px 14px;
  border: 1px solid #86efac;
  border-radius: 6px;
  background: white;
  color: #166534;
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 8px;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.chapter-nav a {
  padding: 10px 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.chapter-nav a:hover { background: #f8fafc; text-decoration: none; }

.welcome-hero {
  background: white;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  margin-bottom: 24px;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.chapter-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}

.chapter-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.chapter-card h3 { font-size: 1rem; margin-bottom: 6px; }
.chapter-card p { font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
.chapter-card .meta { font-size: 0.78rem; color: var(--accent); }

.menu-toggle {
  display: none;
  font-family: inherit;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
}

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 0;
    overflow: hidden;
    position: static;
    transition: max-height 0.3s;
    display: block;
  }
  .sidebar > nav { overflow: visible; }
  .sidebar.open { max-height: 70vh; overflow-y: auto; display: flex; flex-direction: column; }
  .sidebar.open > nav { flex: 1; min-height: 0; overflow-y: auto; }
  .menu-toggle { display: inline-block; }
  .content { padding: 16px; }
}

.site-footer {
  background: #1e293b;
  color: #94a3b8;
  text-align: center;
  padding: 20px 16px;
  font-size: 0.88rem;
  margin-top: 0;
}

.site-footer p { margin: 0; }

.site-footer a {
  color: #93c5fd;
  text-decoration: none;
}

.site-footer a:hover {
  color: #fff;
  text-decoration: underline;
}
