/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --topbar-h: 52px;
  --accent:   #4f46e5;
  --accent-bg:#eef2ff;
  --text:     #1e293b;
  --muted:    #64748b;
  --border:   #e2e8f0;
  --bg:       #f8fafc;
  --white:    #ffffff;
  --code-bg:  #f1f5f9;
  --radius:   6px;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
}

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.25rem;
  gap: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.logo { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.menu-toggle {
  display: none; margin-left: auto;
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: var(--text);
}

/* ── Layout ── */
.layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
}

.article-list { list-style: none; }
.article-list li a {
  display: block;
  padding: .45rem 1.1rem .45rem 1.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: .82rem;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.article-list li a:hover { background: var(--accent-bg); color: var(--accent); }
.article-list li.active a {
  background: var(--accent-bg);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* ── In-page TOC ── */
.toc-section { margin-top: 1.5rem; padding: 0 1.25rem; }
.toc-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: .5rem;
}
.toc-list { list-style: none; }
.toc-list li a {
  display: block; padding: .25rem 0;
  font-size: .82rem; color: var(--muted);
  text-decoration: none; transition: color .15s;
}
.toc-list li a:hover { color: var(--accent); }
.toc-level-1 { padding-left: 0; }
.toc-level-2 { padding-left: .75rem; }
.toc-level-3 { padding-left: 1.5rem; }
.toc-level-4 { padding-left: 2.25rem; }

/* ── Main Content ── */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2.5rem 3rem;
  max-width: 860px;
}

/* ── Article Typography ── */
.article-body h1 { font-size: 2rem; margin-bottom: 1rem; color: var(--text); }
.article-body h2 {
  font-size: 1.4rem; margin: 2rem 0 .75rem;
  padding-bottom: .4rem; border-bottom: 1px solid var(--border);
}
.article-body h3 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.article-body h4 { font-size: 1rem; margin: 1.25rem 0 .4rem; color: var(--muted); }

.article-body p { margin-bottom: 1rem; }

.article-body a { color: var(--accent); text-decoration: underline; }
.article-body a:hover { opacity: .8; }

.article-body ul, .article-body ol {
  margin: .75rem 0 1rem 1.5rem;
}
.article-body li { margin-bottom: .3rem; }

.article-body code {
  background: #f0f0f0;
  padding: .15em .4em;
  border-radius: 4px;
  font-size: .88em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: #c7254e;
}

/* ── 实例代码块 ── */
.code-block {
  border: 1px solid #d0d7de;
  border-radius: var(--radius);
  margin: 1.25rem 0 1.75rem;
  overflow: hidden;
}

.code-header {
  background: #f0f6ff;
  border-bottom: 1px solid #d0d7de;
  padding: .45rem 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.code-label {
  font-size: .78rem;
  font-weight: 700;
  color: #0969da;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.code-block pre {
  margin: 0;
  padding: 1.1rem 1.25rem;
  background: #f6f8fa;
  overflow-x: auto;
  border-radius: 0;
  border: none;
}

.code-block pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: .875rem;
  line-height: 1.65;
}

.article-body table {
  width: 100%; border-collapse: collapse;
  margin: 1rem 0 1.5rem; font-size: .9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border-radius: var(--radius);
  overflow: hidden;
}
.article-body th, .article-body td {
  border: 1px solid var(--border);
  padding: .6rem 1rem; text-align: left;
}
.article-body th {
  background: #f0f6ff;
  font-weight: 600;
  color: #0969da;
  border-bottom: 2px solid #d0d7de;
}
.article-body tr:nth-child(even) td { background: #fafbfc; }
.article-body tr:hover td { background: #f0f6ff; transition: background .1s; }

.article-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.article-body img { max-width: 100%; border-radius: var(--radius); }

.article-body blockquote {
  border-left: 4px solid var(--accent);
  background: var(--accent-bg);
  padding: .75rem 1rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
}

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 4rem 2rem; color: var(--muted);
}
.empty-state p { margin-bottom: .75rem; font-size: 1.05rem; }
.empty-state code { background: var(--code-bg); padding: .2em .5em; border-radius: 4px; }

.error { color: #dc2626; }

/* ── Scrollbar ── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .menu-toggle { display: block; }

  /* 侧边栏抽屉 */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 90;
    width: 80vw;
    max-width: 300px;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* 遮罩层 */
  body.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 80;
  }

  /* 内容区 */
  .content {
    margin-left: 0;
    padding: 1.25rem 1rem;
    max-width: 100%;
  }

  /* 文章标题 */
  .article-body h1 { font-size: 1.5rem; }
  .article-body h2 { font-size: 1.2rem; }
  .article-body h3 { font-size: 1.05rem; }

  /* 代码块横向滚动 */
  .code-block { margin: 1rem 0; }
  .code-block pre { padding: .85rem 1rem; font-size: .8rem; }

  /* 表格横向滚动 */
  .article-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: .8rem;
  }
  .article-body th,
  .article-body td { padding: .45rem .65rem; white-space: nowrap; }

  /* 上下篇导航 */
  .article-nav {
    flex-direction: column !important;
    gap: .6rem;
    margin-top: 2rem;
  }
  .article-nav-prev,
  .article-nav-next {
    flex: none !important;
    width: 100% !important;
    text-align: left !important;
  }
  .article-nav a {
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding: .65rem .9rem;
  }
  .nav-title {
    font-size: .85rem;
    white-space: normal;
    word-break: break-all;
  }

  /* 底部 */
  .footer {
    margin-left: 0 !important;
    padding: .85rem 4rem .85rem 1rem !important;
  }
  .footer-inner {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: .3rem;
    font-size: .78rem;
  }
  .footer-sep { display: none; }

  /* 回到顶部按钮位置 */
  .back-top { right: 1rem; bottom: 1.25rem; width: 36px; height: 36px; font-size: 1rem; }
}

/* ── 上一篇 / 下一篇 ── */
.article-nav {
  display: flex;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.article-nav-prev,
.article-nav-next { flex: 1; }
.article-nav-next { text-align: right; }

.article-nav a {
  display: inline-flex;
  flex-direction: column;
  gap: .2rem;
  padding: .75rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
  max-width: 100%;
}
.article-nav a:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.nav-label {
  font-size: .75rem;
  color: var(--muted);
}
.nav-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── 底部版权 ── */
.footer {
  margin-left: var(--sidebar-w);
  border-top: 1px solid var(--border);
  background: var(--white);
  padding: 1rem 3rem;
}
.footer-inner {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .82rem;
  color: var(--muted);
}
.footer-inner a { color: var(--muted); text-decoration: none; }
.footer-inner a:hover { color: var(--accent); }
.footer-sep { color: var(--border); }

/* footer 和 article-nav 的移动端样式已合并到上方 Mobile 块 */

/* ── 回到顶部 ── */
.back-top {
  position: fixed;
  right: 1.5rem;
  bottom: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(79,70,229,.35);
}
.back-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-top:hover { background: #4338ca; }

/* ── 侧边栏分类标题 ── */
.sidebar-category { margin-top: .5rem; }

.category-label {
  font-size: .8rem;
  font-weight: 700;
  color: #334155;
  padding: .7rem 1.1rem .3rem;
  margin: 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .35rem;
  letter-spacing: .01em;
}

.sidebar-category:first-of-type .category-label {
  border-top: none;
  padding-top: .4rem;
}

/* ══ 首页 Hero ══ */
.home-hero {
  text-align: center;
  padding: 3rem 1rem 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.home-hero-badge {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: .75rem;
  font-weight: 700;
  padding: .25rem .75rem;
  border-radius: 99px;
  margin-bottom: 1rem;
  letter-spacing: .04em;
}
.home-hero-title {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: .75rem;
  line-height: 1.2;
}
.home-hero-desc {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto 1.75rem;
  line-height: 1.7;
}
.home-hero-actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: .65rem 1.5rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); }
.btn-secondary {
  background: var(--white);
  color: var(--text);
  padding: .65rem 1.5rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
  border: 1px solid var(--border);
  transition: border-color .15s, transform .1s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.home-stats {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.stat strong { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.stat span   { font-size: .78rem; color: var(--muted); }

/* ══ 分类卡片 ══ */
.home-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
}
.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.1rem;
  padding-bottom: 2rem;
}
.home-card {
  background: var(--card-bg, #f8fafc);
  border: 1px solid var(--card-border, #e2e8f0);
  border-radius: 10px;
  padding: 1.25rem;
  transition: transform .15s, box-shadow .15s;
}
.home-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
}
.home-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.home-card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--card-color, var(--text));
}
.home-card-count {
  font-size: .72rem;
  background: var(--white);
  border: 1px solid var(--card-border, #e2e8f0);
  color: var(--card-color, var(--muted));
  padding: .1rem .5rem;
  border-radius: 99px;
  font-weight: 600;
}
.home-card-desc {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: .85rem;
  line-height: 1.5;
}
.home-card-list {
  list-style: none;
  margin: 0; padding: 0;
}
.home-card-list li { border-top: 1px solid var(--card-border, #e2e8f0); }
.home-card-list li:first-child { border-top: none; }
.home-card-list li a {
  display: block;
  padding: .35rem 0;
  font-size: .82rem;
  color: var(--text);
  text-decoration: none;
  transition: color .15s;
}
.home-card-list li a:hover { color: var(--card-color, var(--accent)); }
.home-card-list li.more a {
  color: var(--card-color, var(--accent));
  font-weight: 600;
  font-size: .8rem;
}

@media (max-width: 768px) {
  .home-hero-title { font-size: 1.8rem; }
  .home-stats { gap: 1.5rem; }
  .home-cards { grid-template-columns: 1fr; }
}
