/* ===== 主题变量 ===== */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --surface: #ffffff;
  --border: #e2e6ea;
  --text: #202122;
  --text-muted: #54595d;
  --link: #3366cc;
  --link-visited: #795cb2;
  --accent: #3366cc;
  --accent-soft: #eaf1fb;
  --code-bg: #f3f4f6;
  --mark-bg: #fff3a3;
  --mark-text: #202122;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .12);
  --radius: 10px;
  --topbar-h: 58px;
  --sidebar-w: 262px;
}

[data-theme="dark"] {
  --bg: #181a1b;
  --bg-soft: #212325;
  --surface: #202224;
  --border: #3a3d3f;
  --text: #e8e8e8;
  --text-muted: #a7a9ab;
  --link: #8ab4f8;
  --link-visited: #c58af9;
  --accent: #8ab4f8;
  --accent-soft: #2a3340;
  --code-bg: #2a2d2f;
  --mark-bg: #6b5b1f;
  --mark-text: #fff;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.menu-btn { display: none; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
}
.brand-text { font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.search-wrap { position: relative; flex: 1; max-width: 560px; margin-left: auto; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); }
.search-wrap input {
  width: 100%; height: 38px; padding: 0 42px 0 38px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-soft); color: var(--text); font-size: 14px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--text-muted); border: 1px solid var(--border);
  border-radius: 5px; padding: 0 6px; line-height: 20px; font-family: inherit;
}
.topbar-actions { display: flex; gap: 4px; flex: 0 0 auto; }

/* ===== 布局 ===== */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  padding: 22px 16px 30px;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 22px; }
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 7px; color: var(--text-muted);
  font-size: 14px; cursor: pointer;
}
.side-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link svg { width: 17px; height: 17px; }
.side-section { margin-bottom: 22px; }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin: 0 0 10px 12px; font-weight: 700; }
.category-list, .recent-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item, .recent-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; border-radius: 7px; font-size: 14px;
  color: var(--text-muted); cursor: pointer;
}
.cat-item:hover, .recent-item:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.cat-item.active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.cat-count { font-size: 12px; color: var(--text-muted); background: var(--surface); border-radius: 10px; padding: 0 8px; }
.side-footer { font-size: 12px; color: var(--text-muted); margin: 26px 12px 0; line-height: 1.6; }
.sidebar-overlay { display: none; }

/* ===== 主内容 ===== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#view { flex: 1; padding: 34px 48px 60px; max-width: 980px; width: 100%; margin: 0 auto; }
.footer {
  max-width: 980px; width: 100%; margin: 0 auto;
  padding: 18px 48px 28px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13px; color: var(--text-muted); flex-wrap: wrap;
}

/* 文章 */
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { margin: 0 8px; opacity: .5; }
.article-header { border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 24px; }
.article-header h1 { font-size: 34px; line-height: 1.3; margin: 0 0 12px; letter-spacing: -.5px; }
.article-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }
.badge { background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 20px; font-weight: 600; }

.toc {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 28px;
}
.toc-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.toc ol { margin: 0; padding-left: 20px; }
.toc li { margin: 2px 0; }
.toc a { font-size: 14px; color: var(--text-muted); }
.toc a:hover, .toc a.active { color: var(--accent); }

.content { font-size: 16px; }
.content h1, .content h2, .content h3, .content h4 { line-height: 1.35; margin: 1.7em 0 .6em; scroll-margin-top: 80px; }
.content h1 { font-size: 28px; }
.content h2 { font-size: 23px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.content h3 { font-size: 19px; }
.content h4 { font-size: 16px; }
.content > :first-child { margin-top: 0; }
.content p { margin: 0 0 1.1em; }
.content ul, .content ol { padding-left: 26px; margin: 0 0 1.1em; }
.content li { margin: 4px 0; }
.content blockquote {
  margin: 1.2em 0; padding: 10px 18px; border-left: 4px solid var(--accent);
  background: var(--bg-soft); color: var(--text-muted); border-radius: 0 8px 8px 0;
}
.content blockquote p { margin: 0; }
.content code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .9em;
}
.content pre {
  background: var(--code-bg); padding: 16px 18px; border-radius: 8px;
  overflow-x: auto; margin: 1.2em 0; line-height: 1.6;
}
.content pre code { background: none; padding: 0; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.content img { max-width: 100%; border-radius: 8px; }
.wiki-link { border-bottom: 1px dashed var(--link); }
.wiki-link.missing { color: var(--text-muted); border-bottom-style: dotted; opacity: .75; }
.content a:visited { color: var(--link-visited); }

.tags { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 12px; background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-muted); padding: 3px 10px; border-radius: 20px; cursor: pointer; }
.tag:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* 搜索结果 */
.search-header h1 { font-size: 28px; margin: 0 0 6px; }
.search-header p { color: var(--text-muted); margin: 0 0 24px; }
.result { padding: 16px 0; border-bottom: 1px solid var(--border); }
.result h3 { margin: 0 0 4px; font-size: 18px; }
.result .result-cat { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.result p { margin: 0; font-size: 14px; color: var(--text-muted); }
.result mark { background: var(--mark-bg); color: var(--mark-text); border-radius: 3px; padding: 0 2px; }
.empty { text-align: center; padding: 70px 20px; color: var(--text-muted); }
.empty h2 { color: var(--text); margin: 0 0 8px; }

/* 首页 hero */
.hero { background: linear-gradient(135deg, var(--accent-soft), transparent); border: 1px solid var(--border); border-radius: 16px; padding: 36px; margin-bottom: 30px; }
.hero h1 { font-size: 38px; margin: 0 0 10px; }
.hero p { font-size: 17px; color: var(--text-muted); margin: 0; max-width: 640px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 24px 0; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.feature-card h4 { margin: 0 0 6px; font-size: 16px; }
.feature-card p { margin: 0; font-size: 14px; color: var(--text-muted); }

/* 回到顶部 */
.to-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
}
.to-top.show { opacity: 1; visibility: visible; }
.to-top:hover { color: var(--accent); }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: var(--shadow-lg); height: calc(100vh - var(--topbar-h));
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 44; background: rgba(0,0,0,.4); }
  #view { padding: 24px 20px 50px; }
  .footer { padding: 18px 20px 28px; }
  .brand-text { display: none; }
  .search-kbd { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .search-wrap input { font-size: 13px; }
  .article-header h1 { font-size: 27px; }
  .content { font-size: 15px; }
  .hero { padding: 24px; }
  .hero h1 { font-size: 28px; }
}
