/* ==================== 变量 ==================== */
:root {
  --sidebar-w: 280px;
  --content-max: 820px;
  --bg: #ffffff;
  --text: #111827;
  --text-light: #6b7280;
  --border: #f2f2f2;
  --sidebar-bg: #f9f9f9;
  --accent: #0a45ce;
  --accent-bg: #ebebeb;
  --accent-hover: #1d4ed8;
  --accent-underline: rgba(37, 99, 235, .35);
  --code-bg: #f4f5f6;
  --code-border: #e5e7eb;
  --bq-bg: #f9fafb;
  --bq-border: #d1d5db;
  --table-stripe: #fcfcfd;
  --panel-bg: #f9f9f9;
  --hover-bg: rgb(240, 240, 240);
  --float-bg: rgba(255, 255, 255, .92);
  --btn-bg: #ffffff;
  --btn-primary-bg: #111827;
  --btn-primary-fg: #ffffff;
  --btn-primary-bg-hover: #000000;
  --radius: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --trans: 0.18s ease;
}

/* ==================== 暗色模式 ==================== */
[data-theme="dark"] {
  --bg: #0d0e11;
  --text: #e6e8eb;
  --text-light: #9aa0a6;
  --border: #26282e;
  --sidebar-bg: #14161a;
  --accent: #7aa7ff;
  --accent-bg: rgba(122, 167, 255, .12);
  --accent-hover: #a8c5ff;
  --accent-underline: rgba(122, 167, 255, .4);
  --code-bg: #181a1f;
  --code-border: #26282e;
  --bq-bg: #14161a;
  --bq-border: #3a3d44;
  --table-stripe: rgba(255, 255, 255, .02);
  --panel-bg: #181a1f;
  --hover-bg: rgba(255, 255, 255, .045);
  --float-bg: rgba(20, 22, 26, .85);
  --btn-bg: transparent;
  --btn-primary-bg: #ffffff;
  --btn-primary-fg: #0d0e11;
  --btn-primary-bg-hover: #f5f5f5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 8px 24px rgba(0,0,0,.55);
  color-scheme: dark;
}

[data-theme="dark"] body { background: var(--bg); }

/* ==================== 重置 ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 15px; }
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans SC", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "WenQuanYi Micro Hei",
    sans-serif;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background-color: #0a45ce;
  color: #fff;
}

::-moz-selection {
  background-color: #0a45ce;
  color: #fff;
}

/* ==================== 布局 ==================== */
#layout {
  display: flex;
  min-height: 100vh;
}

/* ==================== 侧边栏 ==================== */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  z-index: 100;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
  padding: 14px 16px;
}

/* ==================== 目录 ==================== */
#toc {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 48px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#toc::-webkit-scrollbar { width: 4px; }
#toc::-webkit-scrollbar-track { background: transparent; }
#toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#toc ul { list-style: none; }

#toc a {
  display: block;
  padding: 8px 14px 8px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color var(--trans), background var(--trans), border-color var(--trans);
  word-break: break-all;
}

#toc a:hover {
  color: var(--accent);
  background: var(--hover-bg);
}

#toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-bg);
  font-weight: 500;
}

/* TOC 层级缩进：data-level 取自标题 HTML 标签数字（h2/h3/h4 → 2/3/4） */
#toc li[data-level="2"] > a {
  font-size: 15px;
  padding-left: 16px;
  font-weight: 600;
}
#toc li[data-level="3"] > a {
  font-size: 15px;
  padding-left: 28px;
}
#toc li[data-level="4"] > a {
  padding-left: 40px;
  font-size: 14px;
  color: var(--text-light);
}

/* ==================== 主内容区 ==================== */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

#article {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 8px 52px 80px;
}

/* ==================== Hero ==================== */
.hero {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 56px 52px 44px;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: clamp(48px, 8vw, 88px);
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, Monaco, monospace;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-light);
}
.hero-top-date {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hero-title {
  margin: 0 0 32px;
  font-size: clamp(4em, 7vw + .5em, 6em);
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text);
}

.hero-subtitle {
  max-width: 56ch;
  margin: 0 0 clamp(48px, 7vw, 48px);
  font-size: clamp(1em, .25vw + .95em, 1.15em);
  line-height: 1.7;
  font-weight: 400;
  color: var(--text-light);
}

.hero-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
  padding: 24px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  margin-bottom: clamp(48px, 8vw, 88px);
}

.hero-author {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  transition: opacity var(--trans);
}
.hero-author:hover { opacity: .6; }

.hero-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.hero-author-handle {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .005em;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  transition: border-color var(--trans), background var(--trans), color var(--trans);
}
.hero-btn:hover {
  border-color: var(--text);
}

.hero-btn-primary {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
}
.hero-btn-primary:hover {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg-hover);
  border-color: var(--btn-primary-bg-hover);
}

.hero-btn-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ==================== 文章排版 ==================== */
#article h2 {
  font-size: 2.25em;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 2.6em 0 .7em;
  scroll-margin-top: 28px;
}
#article h2:first-child { margin-top: 0; }

#article h3 {
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.01em;
  margin: 2.4em 0 .8em;
  scroll-margin-top: 28px;
}

#article h4 {
  font-size: 1.15em;
  font-weight: 600;
  line-height: 1.5;
  margin: 2em 0 .6em;
  scroll-margin-top: 28px;
}

#article h5 {
  font-size: 1em;
  font-weight: 600;
  margin: 1.4em 0 .5em;
  scroll-margin-top: 28px;
}

#article p { margin: 0 0 1em; }
#article p:last-child { margin-bottom: 0; }

#article ul, #article ol { margin: .5em 0 1em 1.5em; }
#article li { margin: .25em 0; }
#article li > p { margin-bottom: .25em; }

#article a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--accent-underline);
  text-underline-offset: 3px;
  transition: color var(--trans), text-decoration-color var(--trans);
}
#article a:hover {
  color: var(--accent-hover);
  text-decoration-color: currentColor;
}
#article a > code { text-decoration: inherit; }
#article a:has(> img) { text-decoration: none; }

#article strong { font-weight: 700; }
#article em { font-style: italic; }

#article :not(pre) > code {
  font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, Monaco, monospace;
  font-size: .875em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: .1em .38em;
  border-radius: 4px;
}

#article pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  overflow-x: auto;
  margin: .65em 0 1.1em;
  -webkit-overflow-scrolling: touch;
}
#article pre code {
  font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, Monaco, monospace;
  font-size: .875em;
  line-height: 1.65;
  background: none;
  border: none;
  padding: 0;
  unicode-bidi: plaintext;
}

.hljs { background: transparent !important; padding: 0 !important; }

#article blockquote {
  border-left: 3px solid var(--bq-border);
  margin: 1em 0;
  padding: .65em 1em;
  background: var(--bq-bg);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-light);
}
#article blockquote p { margin-bottom: .4em; }
#article blockquote p:last-child { margin-bottom: 0; }
#article blockquote strong { color: var(--text); }

/* 「参考来源 / 相关新闻 / 拓展阅读 / 常见字库官网」类的辅助说明：弱化处理，与正文分层 */
#article p.ref-line {
  font-size: .82em;
  color: var(--text-light);
  margin-top: -.4em;
}
#article p.ref-line a {
  color: var(--text-light);
  text-decoration-color: var(--border);
}
#article p.ref-line a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: .8em 0 1.2em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
#article table { width: 100%; border-collapse: collapse; font-size: .9em; }
#article th, #article td {
  padding: 8px 14px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}
#article th {
  background: var(--sidebar-bg);
  font-weight: 600;
  white-space: nowrap;
}
#article tr:nth-child(even) > td { background: var(--table-stripe); }

#article img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}
.doc-figure { margin: 1em 0; }

#article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

#article p > a > img {
  display: inline;
  border: none;
  border-radius: 3px;
  vertical-align: middle;
}

/* ==================== 站点页脚 ==================== */
#site-footer {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 52px 56px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-light);
  text-align: center;
}

#site-footer .footer-line {
  line-height: 1.6;
}
#site-footer .footer-line + .footer-line {
  margin-top: 14px;
}

#site-footer a {
  color: var(--text-light);
  text-decoration: none;
  transition: color var(--trans);
}
#site-footer a:hover {
  color: var(--accent);
}

#site-footer .footer-icons {
  display: flex;
  justify-content: center;
  gap: 8px;
}

#site-footer .footer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-light);
  transition: color var(--trans), background var(--trans);
}
#site-footer .footer-icon:hover {
  color: var(--text);
  background: var(--hover-bg);
}
#site-footer .footer-icon svg {
  width: 16px;
  height: 16px;
}

/* ==================== 移动端导航按钮 ==================== */
#nav-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--float-bg);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px;
}

/* ==================== 主题切换按钮 ==================== */
#theme-toggle {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--trans), background var(--trans), color var(--trans);
}
#theme-toggle:hover {
  border-color: var(--text-light);
  background: var(--hover-bg);
}
#theme-toggle .theme-icon { width: 14px; height: 14px; }
#theme-toggle .theme-icon-sun { display: none; }
#theme-toggle .theme-icon-moon { display: block; }
[data-theme="dark"] #theme-toggle .theme-icon-sun { display: block; }
[data-theme="dark"] #theme-toggle .theme-icon-moon { display: none; }
#nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all var(--trans);
}
#nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
#nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
#nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  z-index: 90;
}
#overlay.visible { display: block; }

/* ==================== 响应式 ==================== */
@media (max-width: 800px) {
  #nav-toggle { display: flex; }
  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
    transition: transform .22s ease, box-shadow .22s ease;
    box-shadow: none;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  #main { margin-left: 0; }
  .hero { padding: 70px 22px 32px; }
  .hero-top { margin-bottom: 56px; padding-left: 50px; padding-right: 50px; }
  .hero-bottom { margin-bottom: 56px; }
  #article { padding: 8px 22px 64px; }
  #site-footer { padding: 28px 22px 48px; }
}

@media (max-width: 600px) {
  .hero-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 18px;
  }
}

@media (max-width: 480px) {
  .hero { padding: 64px 16px 28px; }
  .hero-top {
    font-size: 10px;
    letter-spacing: .1em;
    margin-bottom: 40px;
  }
  .hero-subtitle { margin-bottom: 40px; }
  #article { padding: 4px 16px 64px; }
  #article h2 { font-size: 1.5em; }
  #article h3 { font-size: 1.2em; }
  #site-footer { padding: 24px 16px 40px; }
}

/* ==================== 打印 ==================== */
@media print {
  #sidebar, #nav-toggle, #theme-toggle, #overlay { display: none !important; }
  #main { margin-left: 0 !important; }
  #article { max-width: 100% !important; padding: 0 !important; }
  #article pre { white-space: pre-wrap; overflow-wrap: break-word; }
}
