/*
 * NoteDocs —— 知识库/Docs 风格 Typecho 主题
 * 三栏布局:左侧导航树 + 中间内容 + 右侧 TOC
 */

:root {
  --nd-bg: #ffffff;
  --nd-sidebar-bg: #f7f8fa;
  --nd-main-bg: #ffffff;
  --nd-border: #e5e7eb;
  --nd-text: #1f2937;
  --nd-text-muted: #6b7280;
  --nd-text-light: #9ca3af;
  --nd-primary: #2563eb;
  --nd-primary-soft: #eff6ff;
  --nd-accent: #7c3aed;
  --nd-code-bg: #f6f8fa;
  --nd-code-text: #24292f;
  --nd-inline-code-bg: #f0f2f5;
  --nd-card-bg: #ffffff;
  --nd-shadow: 0 1px 3px rgba(0,0,0,.06);
  --nd-sidebar-w: 280px;
  --nd-toc-w: 250px;
  --nd-content-max: min(88vw, 1480px);
  --nd-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
             "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --nd-mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --nd-radius: 8px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--nd-font);
  color: var(--nd-text);
  background: var(--nd-bg);
  line-height: 1.7;
  font-size: 16px;
}

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

/* ===== 布局骨架 ===== */
.nd-layout { display: flex; min-height: 100vh; }

/* ===== 左侧导航栏 ===== */
.nd-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--nd-sidebar-w);
  background: var(--nd-sidebar-bg);
  border-right: 1px solid var(--nd-border);
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.nd-sidebar-inner {
  padding: 20px 0 24px;
  overflow-y: auto;
  height: 100%;
}
.nd-sidebar-inner::-webkit-scrollbar { width: 6px; }
.nd-sidebar-inner::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.nd-brand { padding: 0 20px 16px; }
.nd-logo {
  display: flex; align-items: center; gap: 9px;
  font-size: 19px; font-weight: 700; color: var(--nd-text);
}
.nd-logo:hover { text-decoration: none; }
.nd-logo-icon { font-size: 22px; }
.nd-subtitle { margin: 6px 0 0 31px; font-size: 12.5px; color: var(--nd-text-muted); }

/* 搜索框 */
.nd-search {
  display: flex; align-items: center; gap: 8px;
  margin: 0 16px 14px;
  padding: 8px 12px;
  background: #fff; border: 1px solid var(--nd-border); border-radius: var(--nd-radius);
  color: var(--nd-text-light);
}
.nd-search input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--nd-text); font-family: inherit;
}
.nd-search input::placeholder { color: var(--nd-text-light); }

/* ===== 导航树 ===== */
.nd-nav { flex: 1; padding: 0 10px; }
.nd-tree { list-style: none; margin: 0; padding: 0; }
.nd-tree ul { list-style: none; margin: 0; padding: 0; }
.nd-tree li { font-size: 14px; }

.nd-cat { margin-bottom: 2px; }
.nd-cat-head {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: default;
}
.nd-cat-head:hover { background: #eef0f3; }

.nd-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; flex: none;
  border: none; background: transparent; cursor: pointer; padding: 0;
  color: var(--nd-text-muted);
  transition: transform .18s ease;
}
.nd-toggle svg { display: block; }
.nd-cat.is-open > .nd-cat-head .nd-toggle { transform: rotate(90deg); }

.nd-cat-link {
  flex: 1; font-weight: 600; color: var(--nd-text);
  padding: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px;
}
.nd-cat-link:hover { text-decoration: none; color: var(--nd-primary); }

.nd-items { margin: 2px 0 6px; }
.nd-items > li > a {
  display: block; padding: 5px 8px 5px 30px;
  color: var(--nd-text-muted); font-size: 13.5px;
  border-radius: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  position: relative;
}
.nd-items > li > a:hover { color: var(--nd-primary); background: #eef0f3; text-decoration: none; }
.nd-items > li.active > a {
  color: var(--nd-primary); background: #dbeafe; font-weight: 600;
}
.nd-items > li.active > a::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 16px; border-radius: 2px; background: var(--nd-primary);
}
.nd-cat.active > .nd-cat-head { background: var(--nd-primary-soft); }
.nd-cat.active > .nd-cat-head .nd-cat-link { color: var(--nd-primary); font-weight: 700; }
.nd-cat.active > .nd-cat-head .nd-toggle { color: var(--nd-primary); }

/* 子分类缩进 */
.nd-subcats .nd-cat-head { padding-left: 20px; }

/* ===== 主内容区 ===== */
.nd-main {
  flex: 1; margin-left: var(--nd-sidebar-w);
  min-width: 0;
  display: flex; flex-direction: column;
}
.nd-layout.flat .nd-main { margin-left: 0; }

.nd-topbar {
  position: sticky; top: 0; z-index: 40;
  display: none; align-items: center;
  padding: 10px 16px;
  background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--nd-border);
}
.nd-menu-btn {
  border: 1px solid var(--nd-border); background: #fff;
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--nd-text);
}

.nd-content {
  width: 100%; max-width: var(--nd-content-max);
  margin: 0 auto; padding: 40px 56px 80px;
}

/* 文章/独立页:正文占主区 70%(自适应),右侧 TOC 并排 */
.nd-content.nd-post,
.nd-content.nd-page {
  max-width: none;
  margin-left: 0; margin-right: 0;
}

/* ===== 文章页正文 + TOC 并排(sticky 跟随) ===== */
.nd-post-body {
  display: flex; align-items: flex-start; gap: 48px;
}
/* 正文严格占主区(去掉侧栏)的 60%,TOC 固定 250px 在右侧 */
.nd-content.nd-post .nd-article,
.nd-content.nd-page .nd-article {
  flex: 0 0 auto;
  width: calc((100vw - var(--nd-sidebar-w)) * 0.6);
  min-width: 0;
}

/* ===== 面包屑 ===== */
.nd-crumbs {
  font-size: 13px; color: var(--nd-text-muted);
  margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.nd-crumb-sep { color: var(--nd-text-light); }
.nd-crumb-now { color: var(--nd-text); }

/* ===== 文章 ===== */
.nd-article-head { margin-bottom: 28px; }
.nd-article-title {
  font-size: 30px; line-height: 1.3; margin: 0 0 12px; font-weight: 800;
  letter-spacing: -.02em;
}
.nd-article-meta {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 13px; color: var(--nd-text-muted);
}
.nd-meta-item { display: inline-flex; align-items: center; gap: 4px; }

.nd-article-body {
  font-size: 16px; line-height: 1.85; color: var(--nd-text);
  word-wrap: break-word;
}
.nd-article-body h1, .nd-article-body h2, .nd-article-body h3,
.nd-article-body h4, .nd-article-body h5, .nd-article-body h6 {
  margin: 1.8em 0 .8em; line-height: 1.4; font-weight: 700; color: #111827;
  scroll-margin-top: 24px;
}
.nd-article-body h1 { font-size: 26px; }
.nd-article-body h2 { font-size: 22px; padding-bottom: 8px; border-bottom: 1px solid var(--nd-border); }
.nd-article-body h3 { font-size: 19px; }
.nd-article-body h4 { font-size: 16.5px; }
.nd-article-body p { margin: 0 0 1em; }
.nd-article-body img { max-width: 100%; height: auto; border-radius: var(--nd-radius); }
.nd-article-body a { border-bottom: 1px solid transparent; }
.nd-article-body a:hover { border-bottom-color: currentColor; }

/* 引用 */
.nd-article-body blockquote {
  margin: 1.2em 0; padding: 10px 18px;
  border-left: 4px solid var(--nd-primary);
  background: var(--nd-primary-soft);
  color: #374151; border-radius: 0 6px 6px 0;
}
.nd-article-body blockquote p:last-child { margin: 0; }

/* 代码块 */
.nd-article-body pre {
  background: var(--nd-code-bg); color: var(--nd-code-text);
  border: 1px solid var(--nd-border); border-radius: var(--nd-radius);
  padding: 16px; overflow-x: auto; line-height: 1.6;
  font-size: 14px;
}
.nd-article-body code {
  font-family: var(--nd-mono); font-size: .9em;
}
.nd-article-body :not(pre) > code {
  background: var(--nd-inline-code-bg);
  color: #d6336c; padding: 2px 6px; border-radius: 4px;
  font-size: .88em;
}
.nd-article-body pre { border-radius: 0; overflow-x: auto; }
.nd-article-body pre code {
  background: none; padding: 0;
  color: inherit;
}

/* 表格 */
.nd-article-body table {
  border-collapse: collapse; width: 100%; margin: 1.2em 0;
  font-size: 14.5px;
}
.nd-article-body th, .nd-article-body td {
  border: 1px solid var(--nd-border); padding: 9px 12px; text-align: left;
}
.nd-article-body th { background: #f9fafb; font-weight: 600; }

/* 列表 */
.nd-article-body ul, .nd-article-body ol { margin: 0 0 1em; padding-left: 1.6em; }
.nd-article-body li { margin-bottom: 4px; }
.nd-article-body hr { border: none; border-top: 1px solid var(--nd-border); margin: 2em 0; }

/* 标签 */
.nd-article-tags { margin-top: 32px; display: flex; flex-wrap: wrap; gap: 8px; }
.nd-article-tags a {
  display: inline-block; font-size: 13px;
  padding: 3px 11px; border-radius: 999px;
  background: #f3f4f6; color: var(--nd-text-muted);
}
.nd-article-tags a:hover { background: var(--nd-primary-soft); color: var(--nd-primary); text-decoration: none; }
.nd-tag-none { font-size: 13px; color: var(--nd-text-light); }

/* 上一篇/下一篇 */
.nd-pager {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--nd-border);
  font-size: 14px;
}
.nd-pager a { color: var(--nd-text-muted); }
.nd-pager a:hover { color: var(--nd-primary); text-decoration: none; }
.nd-pager-prev, .nd-pager-next { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== 右侧 TOC(sticky 并排,滚动跟随) ===== */
.nd-toc {
  flex: 0 0 var(--nd-toc-w);
  position: sticky; top: 88px;
  max-height: calc(100vh - 120px);
  overflow-y: auto; padding: 4px 0;
  font-size: 13px;
  scrollbar-width: thin;
}
.nd-toc::-webkit-scrollbar { width: 4px; }
.nd-toc::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }
.nd-toc-inner { border-left: 2px solid var(--nd-border); padding-left: 16px; }
.nd-toc-title {
  display: block; font-weight: 700; color: var(--nd-text-muted);
  margin-bottom: 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.nd-toc-inner ul { list-style: none; margin: 0; padding: 0; }
.nd-toc-inner li { margin: 4px 0; line-height: 1.5; }
.nd-toc-inner a {
  color: var(--nd-text-muted); display: block;
  transition: color .15s;
}
.nd-toc-inner a:hover { color: var(--nd-primary); text-decoration: none; }
.nd-toc-inner a.on { color: var(--nd-primary); font-weight: 600; }
.nd-toc-l3 { padding-left: 14px; }
.nd-toc-l3 a { font-size: 12.5px; }

/* ===== 首页 ===== */
.nd-hero {
  padding: 24px 0 8px; margin-bottom: 32px;
}
.nd-hero-title { font-size: 34px; font-weight: 800; margin: 0 0 10px; letter-spacing: -.02em; }
.nd-hero-desc { color: var(--nd-text-muted); font-size: 16px; margin: 0; }

.nd-sec-title { font-size: 16px; font-weight: 700; margin: 0 0 16px; color: #111827; }

.nd-catgrid { margin-bottom: 40px; }
.nd-catgrid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.nd-catcard {
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px 22px; background: var(--nd-card-bg);
  border: 1px solid var(--nd-border); border-radius: 12px;
  transition: border-color .18s, box-shadow .18s, transform .18s;
}
.nd-catcard:hover {
  text-decoration: none; border-color: var(--nd-primary);
  box-shadow: 0 6px 20px rgba(37,99,235,.08); transform: translateY(-2px);
}
.nd-catcard-top { display: flex; align-items: center; gap: 8px; }
.nd-catcard-icon { font-size: 18px; }
.nd-catcard-name { font-weight: 650; color: var(--nd-text); font-size: 15.5px; }
.nd-catcard-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.nd-catcard-count {
  font-size: 12px; color: var(--nd-primary);
  background: var(--nd-primary-soft);
  padding: 2px 9px; border-radius: 999px; font-weight: 600;
}
.nd-catcard-sub {
  font-size: 12px; color: var(--nd-text-muted);
  background: #f3f4f6; padding: 2px 9px; border-radius: 999px;
}
.nd-catcard-latest {
  font-size: 12.5px; color: var(--nd-text-light);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 文章列表(首页/归档) */
.nd-postlist { display: flex; flex-direction: column; gap: 8px; }
.nd-postitem {
  padding: 16px 20px; border: 1px solid var(--nd-border); border-radius: 12px;
  background: var(--nd-card-bg); transition: border-color .15s;
}
.nd-postitem:hover { border-color: var(--nd-primary); }
.nd-postitem-title { margin: 0 0 6px; font-size: 16.5px; }
.nd-postitem-title a { color: var(--nd-text); }
.nd-postitem-title a:hover { color: var(--nd-primary); }
.nd-postitem-meta { font-size: 12.5px; color: var(--nd-text-light); margin-bottom: 6px; }
.nd-postitem-excerpt { margin: 0; font-size: 14px; color: var(--nd-text-muted); }

/* 分页 */
.nd-pagenav { display: flex; gap: 6px; margin-top: 24px; }
.nd-pagenav a, .nd-pagenav .current {
  padding: 6px 12px; border: 1px solid var(--nd-border); border-radius: 6px;
  font-size: 14px; color: var(--nd-text-muted);
}
.nd-pagenav .current { background: var(--nd-primary); color: #fff; border-color: var(--nd-primary); }
.nd-pagenav a:hover { text-decoration: none; border-color: var(--nd-primary); color: var(--nd-primary); }

/* 归档标题 */
.nd-archive-title { font-size: 26px; margin: 0 0 24px; }

/* 空状态 */
.nd-empty { padding: 60px 20px; text-align: center; color: var(--nd-text-light); }

/* 404 */
.nd-404-inner { text-align: center; padding: 80px 20px; }
.nd-404-code { font-size: 88px; font-weight: 800; color: var(--nd-primary-soft); line-height: 1; }
.nd-404-msg { color: var(--nd-text-muted); margin: 16px 0 24px; }
.nd-404-back { font-size: 15px; }

/* ===== 返回顶部按钮(玻璃拟态) ===== */
.nd-backtop {
  position: fixed; right: 32px; bottom: 36px; z-index: 200;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.55); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--nd-primary);
  background: rgba(255,255,255,.68);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  box-shadow: 0 6px 22px rgba(31,41,55,.14), inset 0 1px 0 rgba(255,255,255,.7);
  opacity: 0; visibility: hidden; transform: translateY(14px) scale(.92);
  transition: opacity .3s ease, transform .3s cubic-bezier(.2,.8,.3,1), visibility .3s,
              box-shadow .25s, border-color .25s, color .25s;
}
.nd-backtop.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.nd-backtop:hover {
  border-color: var(--nd-primary);
  color: #fff;
  background: var(--nd-primary);
  box-shadow: 0 10px 26px rgba(37,99,235,.35);
  transform: translateY(-3px) scale(1.03);
}
.nd-backtop:active { transform: translateY(-1px) scale(.97); }
.nd-backtop svg { display: block; }

/* ===== 响应式 ===== */
@media (max-width: 1280px) {
  .nd-toc { display: none !important; }
  .nd-backtop { right: 32px; }
}
@media (max-width: 1100px) {
  .nd-content { padding-left: 32px; padding-right: 32px; }
}
@media (max-width: 900px) {
  .nd-sidebar {
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: none;
  }
  .nd-sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .nd-main { margin-left: 0; }
  .nd-topbar { display: flex; }
  .nd-content { padding: 24px 20px 64px; max-width: 100%; }
  .nd-article-title { font-size: 24px; }
  .nd-mask.active { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 90; }
  .nd-post-body { display: block; }
  .nd-backtop { right: 18px; bottom: 22px; width: 44px; height: 44px; }
}

/* 打印 */
@media print {
  .nd-sidebar, .nd-toc, .nd-topbar, .nd-mask, .nd-backtop { display: none !important; }
  .nd-main { margin-left: 0; }
}
/* ===== highlight.js GitHub 配色(本地化,不依赖CDN) ===== */
.hljs{color:#24292e;background:#fff}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#d73a49}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#6f42c1}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#005cc5}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#032f62}.hljs-built_in,.hljs-symbol{color:#e36209}.hljs-code,.hljs-comment,.hljs-formula{color:#6a737d}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#22863a}.hljs-subst{color:#24292e}.hljs-section{color:#005cc5;font-weight:700}.hljs-bullet{color:#735c0f}.hljs-emphasis{color:#24292e;font-style:italic}.hljs-strong{color:#24292e;font-weight:700}.hljs-addition{color:#22863a;background-color:#f0fff4}.hljs-deletion{color:#b31d28;background-color:#ffeef0}