/* =========================================================
   科普站样式  ——  改颜色只改 :root 里的变量即可
   深色模式三态：跟随系统 / 强制浅色 / 强制深色
   ========================================================= */

:root {
  --bg: #fcfbf8;
  --bg-soft: #f4f2ec;
  --fg: #201e1a;
  --fg-soft: #57524a;
  --fg-mute: #8b8478;
  --line: #e7e2d7;
  --accent: #1f6f63;
  --accent-hover: #17574e;
  --accent-soft: #e7f1ee;
  --mark: #d9ece6;

  --measure: 45rem;
  --radius: 12px;

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

  --shadow: 0 1px 2px rgba(32, 30, 26, 0.04), 0 8px 24px rgba(32, 30, 26, 0.05);
}

/* 系统偏好深色，且用户没有手动选浅色 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a;
    --bg-soft: #1f1f25;
    --fg: #e9e6df;
    --fg-soft: #b3ada3;
    --fg-mute: #837d74;
    --line: #2b2b33;
    --accent: #5fb8a7;
    --accent-hover: #7fcbba;
    --accent-soft: #1e2f2b;
    --mark: #27453e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  }
}

/* 用户手动选了深色，无视系统 */
:root[data-theme="dark"] {
  --bg: #16161a;
  --bg-soft: #1f1f25;
  --fg: #e9e6df;
  --fg-soft: #b3ada3;
  --fg-mute: #837d74;
  --line: #2b2b33;
  --accent: #5fb8a7;
  --accent-hover: #7fcbba;
  --accent-soft: #1e2f2b;
  --mark: #27453e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent-soft);
  color: var(--fg);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.wrap {
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 20px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  z-index: 30;
}

.skip-link:focus {
  left: 0;
}

/* ---------------- 阅读进度条 ---------------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 20;
  pointer-events: none;
}

.progress.is-visible {
  opacity: 1;
}

/* ---------------- 页头 ---------------- */

.site-header {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-name {
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--fg);
}

.brand-tagline {
  font-size: 12.5px;
  color: var(--fg-mute);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.site-nav {
  display: flex;
  gap: 2px;
}

.site-nav a {
  font-size: 14px;
  color: var(--fg-soft);
  text-decoration: none;
  padding: 7px 11px;
  border-radius: 999px;
  transition: background-color 0.18s, color 0.18s;
}

.site-nav a:hover {
  background: var(--bg-soft);
  color: var(--fg);
}

.site-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 550;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--fg-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s, background-color 0.18s;
}

.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--fg-mute);
  background: var(--bg-soft);
}

.theme-toggle svg {
  display: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html:not([data-theme-pref]) .theme-toggle .i-auto,
html[data-theme-pref="auto"] .theme-toggle .i-auto,
html[data-theme-pref="light"] .theme-toggle .i-light,
html[data-theme-pref="dark"] .theme-toggle .i-dark {
  display: block;
}

/* ---------------- 首页 ---------------- */

.intro {
  padding: 56px 0 8px;
}

.intro-compact {
  padding-bottom: 0;
}

.intro-title {
  margin: 0 0 18px;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  line-height: 1.3;
  letter-spacing: -0.015em;
  font-weight: 700;
}

.intro-text {
  margin: 0;
  max-width: 32em;
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--fg-soft);
  text-wrap: pretty;
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 52px 0 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.list-heading {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--fg-mute);
}

.list-count {
  font-size: 12.5px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item + .post-item {
  border-top: 1px solid var(--line);
}

.post-link {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 20px;
  align-items: start;
  padding: 22px 12px;
  margin: 0 -12px;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
  transition: background-color 0.18s;
}

.post-link:hover {
  background: var(--bg-soft);
}

.post-date {
  font-size: 13px;
  line-height: 2.1;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.post-main {
  display: block;
  min-width: 0;
}

.post-title {
  display: block;
  font-size: 17.5px;
  font-weight: 620;
  line-height: 1.55;
  letter-spacing: -0.008em;
  color: var(--fg);
  transition: color 0.18s;
}

.post-link:hover .post-title {
  color: var(--accent);
}

.post-summary {
  display: block;
  margin-top: 7px;
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--fg-soft);
}

.post-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 11px;
  flex-wrap: wrap;
}

.post-tag {
  display: inline-block;
  font-size: 12px;
  line-height: 1.6;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: 0.02em;
  text-decoration: none;
}

a.post-tag:hover {
  background: var(--accent);
  color: var(--bg);
}

.post-read {
  font-size: 12.5px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 32px 0;
  color: var(--fg-mute);
  font-size: 14px;
}

/* 分页 */

.page-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.page-link {
  color: var(--accent);
  text-decoration: none;
}

.page-link:hover {
  color: var(--accent-hover);
}

.page-nav .page-link:last-child {
  text-align: right;
}

.page-info {
  color: var(--fg-mute);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.page-link.page-empty {
  pointer-events: none;
}

/* ---------------- 文章页 ---------------- */

/* 文章页需要放右侧目录，主栏放宽 */
.is-article main.wrap {
  max-width: 70rem;
}

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 45rem) 15rem;
  gap: 3.5rem;
  justify-content: center;
  align-items: start;
}

.article {
  padding: 36px 0 0;
  min-width: 0;
}

.back-link {
  display: inline-block;
  font-size: 13.5px;
  color: var(--fg-mute);
  text-decoration: none;
  margin-bottom: 34px;
  transition: color 0.18s;
}

.back-link:hover {
  color: var(--accent);
}

.article-head {
  padding-bottom: 30px;
  border-bottom: 1px solid var(--line);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

.article-meta .post-tag {
  margin-top: 0;
}

.read-time::before,
.views::before {
  content: "·";
  margin-right: 10px;
  color: var(--line);
}

.views {
  font-variant-numeric: tabular-nums;
}

.article-title {
  margin: 16px 0 0;
  font-size: clamp(1.55rem, 5.2vw, 2rem);
  line-height: 1.4;
  letter-spacing: -0.015em;
  font-weight: 700;
  text-wrap: balance;
}

.article-summary {
  margin: 20px 0 0;
  padding-left: 14px;
  border-left: 2px solid var(--accent);
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--fg-soft);
  text-wrap: pretty;
}

.article-author {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--fg-mute);
}

.article-body {
  padding: 34px 0 0;
  font-size: 17px;
  line-height: 1.9;
  color: var(--fg);
  overflow-wrap: break-word;
}

.article-body > p {
  margin: 0 0 1.45em;
}

.article-body > p:first-child {
  font-size: 17.5px;
  color: var(--fg);
}

.article-body h2,
.article-body h3 {
  /* 锚点跳转时给吸顶页头留出空间 */
  scroll-margin-top: 90px;
}

.article-body h2 {
  position: relative;
  margin: 2.6em 0 0.9em;
  padding-left: 0.82em;
  font-size: 1.28rem;
  line-height: 1.5;
  letter-spacing: -0.01em;
  font-weight: 680;
}

.article-body h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.42em;
  width: 3px;
  height: 0.92em;
  border-radius: 2px;
  background: var(--accent);
}

.article-body h3 {
  margin: 2em 0 0.6em;
  font-size: 1.08rem;
  font-weight: 640;
  line-height: 1.6;
}

.article-body h4 {
  margin: 1.8em 0 0.5em;
  font-size: 1rem;
  font-weight: 640;
}

.article-body ul,
.article-body ol {
  margin: 0 0 1.45em;
  padding-left: 1.35em;
}

.article-body li {
  margin: 0.45em 0;
}

.article-body li > ul,
.article-body li > ol {
  margin: 0.45em 0 0.2em;
}

.article-body blockquote {
  margin: 1.8em 0;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--bg-soft);
  color: var(--fg-soft);
  font-size: 15.5px;
  line-height: 1.85;
}

.article-body blockquote > p:last-child {
  margin-bottom: 0;
}

.article-body hr {
  height: 1px;
  border: 0;
  margin: 2.6em 0;
  background: var(--line);
}

.article-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.8em auto;
  border-radius: 10px;
}

.article-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-soft);
  padding: 0.15em 0.42em;
  border-radius: 5px;
}

.article-body pre {
  margin: 1.8em 0;
  padding: 16px 18px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.7;
}

.article-body pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.article-body a {
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.article-body a:hover {
  text-decoration-color: currentColor;
}

.table-wrap {
  margin: 1.8em 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.7;
}

.article-body th,
.article-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  /* 防止长文本列把相邻短列挤成一条竖线 */
  min-width: 4.5em;
}

.article-body th {
  background: var(--bg-soft);
  font-weight: 620;
  font-size: 14px;
  white-space: nowrap;
}

.article-body strong {
  font-weight: 650;
}

/* 文末导航 */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 3.2em;
  padding-top: 1.6em;
  border-top: 1px solid var(--line);
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.18s, background-color 0.18s;
}

.pager-link:hover {
  border-color: var(--accent);
  background: var(--bg-soft);
}

.pager-link:last-child {
  text-align: right;
  align-items: flex-end;
}

.pager-link.pager-empty {
  border-color: transparent;
  pointer-events: none;
}

.pager-dir {
  font-size: 12px;
  color: var(--fg-mute);
  letter-spacing: 0.02em;
}

.pager-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--fg);
}

.article-disclaimer {
  margin: 2.4em 0 0;
  padding-top: 1.4em;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--fg-mute);
}

/* ---------------- 目录 ---------------- */

.toc-side {
  position: sticky;
  top: 96px;
  padding-top: 64px;
  font-size: 13.5px;
  line-height: 1.7;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.toc-title {
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--fg-mute);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--line);
}

.toc-item {
  margin: 0;
}

.toc-item a {
  display: block;
  padding: 5px 0 5px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--fg-mute);
  text-decoration: none;
  transition: color 0.18s, border-color 0.18s;
}

.toc-item a:hover {
  color: var(--fg);
}

.toc-item a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 550;
}

.toc-l3 a {
  padding-left: 26px;
  font-size: 12.8px;
}

/* 手机 / 中屏：侧栏换成正文顶部的折叠块 */
.toc-inline {
  display: none;
  margin: 22px 0 0;
  padding: 12px 16px;
  background: var(--bg-soft);
  border-radius: 10px;
  font-size: 14px;
}

.toc-inline summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-soft);
  letter-spacing: 0.04em;
}

.toc-inline .toc-list {
  margin-top: 10px;
  border-left: 0;
}

.toc-inline .toc-item a {
  padding: 4px 0;
  border-left: 0;
}

/* ---------------- 标签页 ---------------- */

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 34px;
  padding-bottom: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  color: var(--fg-soft);
  text-decoration: none;
  transition: border-color 0.18s, color 0.18s, background-color 0.18s;
}

.tag-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tag-count {
  font-size: 11.5px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

.tag-section {
  scroll-margin-top: 88px;
}

.tag-section + .tag-section .list-head {
  margin-top: 44px;
}

/* ---------------- 搜索页 ---------------- */

.search-box {
  margin-top: 34px;
}

.search-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background-color 0.18s;
}

.search-input::placeholder {
  color: var(--fg-mute);
}

.search-input:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.search-hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

.search-results {
  margin-top: 24px;
}

.search-results:not(:empty) {
  border-top: 1px solid var(--line);
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

/* ---------------- 页脚 ---------------- */

.site-footer {
  margin-top: 72px;
  padding: 26px 0 44px;
  border-top: 1px solid var(--line);
}

.footer-note {
  margin: 0 0 8px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--fg-mute);
  max-width: 36em;
  /* 让两行长度接近，避免末行只剩一两个字 */
  text-wrap: balance;
}

.footer-copy {
  margin: 0;
  font-size: 12.5px;
  color: var(--fg-mute);
}

.footer-copy a {
  color: var(--fg-mute);
  text-decoration-color: var(--line);
}

.footer-copy a:hover {
  color: var(--accent);
}

/* ---------------- 中屏：收起右侧目录 ---------------- */

@media (max-width: 1080px) {
  .is-article main.wrap {
    max-width: var(--measure);
  }

  .article-layout {
    display: block;
  }

  .toc-side {
    display: none;
  }

  .toc-inline {
    display: block;
  }
}

/* ---------------- 手机适配 ---------------- */

@media (max-width: 640px) {
  body {
    font-size: 15.5px;
  }

  .header-inner {
    min-height: 58px;
    gap: 8px;
  }

  .brand-tagline {
    display: none;
  }

  .site-nav {
    gap: 0;
  }

  .site-nav a {
    font-size: 13px;
    padding: 6px 8px;
  }

  .header-tools {
    gap: 4px;
  }

  .theme-toggle {
    width: 30px;
    height: 30px;
  }

  .intro {
    padding: 36px 0 4px;
  }

  .list-head {
    margin-top: 36px;
  }

  .post-link {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 18px 12px;
  }

  .post-date {
    line-height: 1.6;
    font-size: 12.5px;
  }

  .post-title {
    font-size: 16.5px;
  }

  .post-summary {
    font-size: 14px;
  }

  .article {
    padding-top: 24px;
  }

  .back-link {
    margin-bottom: 24px;
  }

  .article-body {
    font-size: 16.5px;
    padding-top: 26px;
  }

  .article-body > p:first-child {
    font-size: 17px;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager-link:last-child {
    text-align: left;
    align-items: flex-start;
  }

  .pager-link.pager-empty {
    display: none;
  }

  .site-footer {
    margin-top: 52px;
  }

  .page-nav {
    grid-template-columns: 1fr 1fr;
    row-gap: 8px;
  }

  .page-info {
    grid-column: 1 / -1;
    order: -1;
  }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
  }
}

/* 打印时输出干净的正文 */
@media print {
  .site-header,
  .site-footer,
  .pager,
  .back-link,
  .skip-link,
  .progress,
  .toc-side,
  .toc-inline {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  .article-body {
    font-size: 12pt;
  }
}
