/* ==========================================================================
   设计令牌（浅色为默认，深色通过系统偏好或手动切换）
   ========================================================================== */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1d232b;
  --text-2: #3a434e;
  --muted: #66717d;
  --border: #e5e1d8;
  --accent: #0b7d6d;
  --accent-hover: #075f53;
  --accent-soft: rgba(11, 125, 109, 0.09);
  --shadow: 0 1px 2px rgba(20, 24, 30, 0.04), 0 4px 16px rgba(20, 24, 30, 0.05);

  /* 行内代码 */
  --inline-code-bg: #f0ebe3;
  --inline-code-text: #b4401a;

  /* 代码块：两种主题下都用深色面板，和正文形成明显对比 */
  --code-bg: #1e252e;
  --code-header-bg: #161c23;
  --code-border: #1e252e;
  --code-text: #e6edf3;
  --code-muted: #8b98a5;
  --code-shadow: 0 2px 4px rgba(20, 24, 30, 0.06), 0 8px 24px rgba(20, 24, 30, 0.10);
  --hl-comment: #8b98a5;
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-function: #d2a8ff;
  --hl-type: #ffa657;
  --hl-attr: #7ee787;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --content-width: 46rem;
  --radius: 10px;
  --header-h: 60px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111519;
    --surface: #171c21;
    --surface-2: #1d2329;
    --text: #e4e8ec;
    --text-2: #c5ccd3;
    --muted: #8f9aa5;
    --border: #2a3138;
    --accent: #4fc4ac;
    --accent-hover: #7dd8c5;
    --accent-soft: rgba(79, 196, 172, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --inline-code-bg: #252d35;
    --inline-code-text: #f2a47c;
    --code-bg: #0b0f13;
    --code-header-bg: #131920;
    --code-border: #2f3842;
    --code-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111519;
  --surface: #171c21;
  --surface-2: #1d2329;
  --text: #e4e8ec;
  --text-2: #c5ccd3;
  --muted: #8f9aa5;
  --border: #2a3138;
  --accent: #4fc4ac;
  --accent-hover: #7dd8c5;
  --accent-soft: rgba(79, 196, 172, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --inline-code-bg: #252d35;
  --inline-code-text: #f2a47c;
  --code-bg: #0b0f13;
  --code-header-bg: #131920;
  --code-border: #2f3842;
  --code-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ==========================================================================
   基础
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 16px);
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

img { max-width: 100%; height: auto; }

.icon {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: color .15s, border-color .15s, background-color .15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ==========================================================================
   页头
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 16px;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand__avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }

.site-nav { display: flex; gap: 4px; }
.site-nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 15px;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.site-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  width: 9rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

#theme-toggle .icon--moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon--sun { display: none; }
:root[data-theme="dark"] #theme-toggle .icon--moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon--sun { display: none; }
  :root:not([data-theme="light"]) #theme-toggle .icon--moon { display: block; }
}

@media (max-width: 760px) {
  .site-header__inner { flex-wrap: wrap; gap: 0 12px; padding-top: 10px; }
  .brand__name { font-size: 16px; }
  .search { display: none; }
  .site-nav {
    order: 3;
    width: 100%;
    margin: 6px -8px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .site-nav::-webkit-scrollbar { display: none; }
}

/* ==========================================================================
   主体
   ========================================================================== */
.site-main {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: 40px 16px 64px;
}

.page { max-width: var(--content-width); margin: 0 auto; }
.page-header { margin-bottom: 28px; }
.page-title { margin: 0; font-size: 2rem; line-height: 1.3; letter-spacing: -0.01em; }
.page-subtitle { margin: 8px 0 0; color: var(--muted); }

/* 首页 */
.intro { margin: 8px 0 32px; }
.intro__title { margin: 0; font-size: 2.1rem; line-height: 1.25; letter-spacing: -0.02em; }
.intro__text { margin: 8px 0 0; color: var(--muted); }

.post-list { list-style: none; margin: 0; padding: 0; }
.post-card { padding: 22px 0; border-top: 1px solid var(--border); }
.post-card:last-child { border-bottom: 1px solid var(--border); }
.post-card__title { margin: 0 0 6px; font-size: 1.3rem; line-height: 1.45; font-weight: 650; }
.post-card__title a { color: var(--text); }
.post-card__title a:hover { color: var(--accent); }
.post-card__excerpt {
  margin: 10px 0 0;
  color: var(--text-2);
  font-size: 15.5px;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  color: var(--muted);
  font-size: 14px;
}
.post-meta a:not(.chip) { color: var(--muted); }
.post-meta a:not(.chip):hover { color: var(--accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  line-height: 1.7;
}
.chip:hover { background: var(--accent); color: var(--surface); }
.chip--lg { padding: 4px 12px; font-size: 14px; }
.chip__count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip:hover .chip__count { color: inherit; opacity: .8; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 32px;
  font-size: 15px;
}
.pagination a, .pagination .is-disabled {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.pagination a:hover { border-color: var(--accent); }
.pagination .is-disabled { color: var(--muted); opacity: .5; }
.pagination__status { color: var(--muted); font-variant-numeric: tabular-nums; }

/* 分类 / 标签 / 归档 */
.chip-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 36px; }
.term { margin-bottom: 36px; }
.term__title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 1.25rem;
}
.term__count { color: var(--muted); font-size: 14px; font-weight: 400; }
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li {
  display: flex;
  gap: 16px;
  padding: 6px 0;
  line-height: 1.6;
}
.link-list time {
  flex: none;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.link-list a { color: var(--text); }
.link-list a:hover { color: var(--accent); }

.social { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; margin: 24px 0 0; padding: 0; }
.social a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-2);
}
.social a:hover { color: var(--accent); border-color: var(--accent); }

/* ==========================================================================
   文章页
   ========================================================================== */
.post-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--content-width));
  justify-content: center;
  gap: 56px;
}
@media (min-width: 1180px) {
  .post-layout:has(.toc--side:not([hidden])) {
    grid-template-columns: minmax(0, var(--content-width)) 15rem;
  }
}

.post-header { margin-bottom: 32px; }
.post-title {
  margin: 0 0 12px;
  font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.25rem);
  line-height: 1.3;
  letter-spacing: -0.015em;
}

.post-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.post-pager__item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.post-pager__item:hover { border-color: var(--accent); color: var(--text); }
.post-pager__item--next { text-align: right; grid-column: 2; }
.post-pager__label { color: var(--muted); font-size: 13px; }
.post-pager__title { font-size: 15px; line-height: 1.5; }
@media (max-width: 560px) {
  .post-pager { grid-template-columns: 1fr; }
  .post-pager__item--next { grid-column: 1; }
}

/* 目录 */
.toc__list a {
  display: block;
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.toc__list a.toc-h3 { padding-left: 24px; font-size: 13.5px; }
.toc__list a:hover { color: var(--text); }
.toc__list a.is-active { color: var(--accent); border-left-color: var(--accent); }

.toc--side {
  display: none;
  position: sticky;
  top: calc(var(--header-h) + 32px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
}
.toc__title { margin-bottom: 10px; color: var(--text); font-size: 13px; font-weight: 600; letter-spacing: .04em; }

.toc--inline {
  margin-bottom: 28px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.toc--inline summary { cursor: pointer; color: var(--text-2); font-size: 15px; font-weight: 600; }
.toc--inline[open] summary { margin-bottom: 8px; }

@media (min-width: 1180px) {
  .toc--side:not([hidden]) { display: block; }
  .toc--inline { display: none; }
}

/* ==========================================================================
   正文排版
   ========================================================================== */
.prose { color: var(--text); overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose pre, .prose div.highlighter-rouge {
  margin: 0 0 1.15em;
}
.prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 2em 0 .7em;
  line-height: 1.4;
  letter-spacing: -0.01em;
  font-weight: 650;
}
.prose h2 { font-size: 1.5rem; padding-bottom: .35em; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.25rem; }
.prose h4 { font-size: 1.08rem; }
.prose h5, .prose h6 { font-size: 1rem; color: var(--text-2); }

.prose a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: currentColor; }

.prose ul, .prose ol { padding-left: 1.5em; }
.prose li + li { margin-top: .3em; }
.prose li > ul, .prose li > ol { margin: .3em 0 0; }

.prose blockquote {
  padding: .2em 1.1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-2);
}
.prose blockquote p { margin: .6em 0; }

.prose hr { margin: 2.5em 0; border: 0; border-top: 1px solid var(--border); }

.prose img {
  display: block;
  margin: 1.5em auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff; /* 透明背景的图在深色模式下保持可读 */
}

.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.6;
}
.prose th, .prose td { padding: 8px 12px; border: 1px solid var(--border); vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; text-align: left; }
.prose tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }

/* 行内代码 */
.prose :not(pre) > code {
  padding: .12em .42em;
  border-radius: 5px;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  font-family: var(--font-mono);
  font-size: .86em;
  overflow-wrap: anywhere;
}
.prose a > code { color: inherit; }

/* 代码块：外层是深色面板，顶部有语言标签和复制按钮 */
.prose div.highlighter-rouge,
.prose figure.highlight,
.prose > pre {
  margin: 1.6em 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  box-shadow: var(--code-shadow);
  overflow: hidden;
}
.prose div.highlighter-rouge .highlight { margin: 0; background: none; }

.prose pre {
  margin: 0;
  padding: 16px 20px;
  overflow-x: auto;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.65;
  tab-size: 4;
}
.prose pre code { font: inherit; color: inherit; background: none; padding: 0; }
.prose div.highlighter-rouge pre, .prose figure.highlight pre { border: 0; border-radius: 0; }

/* 代码块滚动条也用深色 */
.prose pre::-webkit-scrollbar { height: 10px; }
.prose pre::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 10px; border: 3px solid var(--code-bg); }
.prose pre { scrollbar-color: rgba(255, 255, 255, .2) transparent; }

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 38px;
  padding: 0 8px 0 16px;
  background: var(--code-header-bg);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  color: var(--code-muted);
  font: 600 12px/1 var(--font-sans);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.code-header__lang { display: inline-flex; align-items: center; gap: 8px; }
.code-header__lang::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lang-color, var(--code-muted));
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px;
  background: transparent;
  color: var(--code-muted);
  font: 500 12px/1 var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  transition: color .15s, border-color .15s, background-color .15s;
}
.copy-btn:hover { color: #fff; border-color: rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .06); }
.copy-btn.is-copied { color: #7ee787; border-color: rgba(126, 231, 135, .4); }

/* MathJax 公式过宽时横向滚动 */
.prose mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* Rouge 语法高亮 */
.highlight .c, .highlight .ch, .highlight .cd, .highlight .cm, .highlight .cpf, .highlight .c1, .highlight .cs { color: var(--hl-comment); font-style: italic; }
.highlight .cp { color: var(--hl-keyword); }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .ow { color: var(--hl-keyword); }
.highlight .kt, .highlight .nc, .highlight .nn, .highlight .ne { color: var(--hl-type); }
.highlight .s, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .dl, .highlight .sd, .highlight .s2, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .sr, .highlight .s1, .highlight .ss { color: var(--hl-string); }
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il, .highlight .mo, .highlight .mx { color: var(--hl-number); }
.highlight .nf, .highlight .fm, .highlight .nd { color: var(--hl-function); }
.highlight .na, .highlight .nt, .highlight .nb, .highlight .bp { color: var(--hl-attr); }
.highlight .nv, .highlight .vc, .highlight .vg, .highlight .vi, .highlight .no { color: var(--hl-number); }
.highlight .gd { color: var(--hl-keyword); background: color-mix(in srgb, var(--hl-keyword) 10%, transparent); }
.highlight .gi { color: var(--hl-attr); background: color-mix(in srgb, var(--hl-attr) 10%, transparent); }
.highlight .gh, .highlight .gu { color: var(--hl-number); font-weight: 600; }
.highlight .err { color: inherit; background: none; }

/* ==========================================================================
   页脚
   ========================================================================== */
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.site-footer__inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
}
.site-footer__links { display: flex; gap: 20px; }
.site-footer a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s, color .15s, border-color .15s;
}
.to-top.is-visible { opacity: 1; pointer-events: auto; transform: none; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .site-main { padding-top: 24px; }
  .intro__title { font-size: 1.7rem; }
  .post-card__title { font-size: 1.15rem; }
  .link-list li { flex-direction: column; gap: 0; }
}

@media print {
  .site-header, .site-footer, .toc, .post-pager, .to-top, .code-header { display: none !important; }
  body { background: #fff; color: #000; }
}
