/* ============================================================================
   文章阅读页样式 + TOC + 评论
   ============================================================================ */

.article-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 24px 80px;
  display: grid;
  /* minmax(0, 1fr) 而不是 1fr：grid 默认 1fr = minmax(auto, 1fr)，
     超长内容（长链接 / 长公式 / 代码块）会把列撑到视口之外，必须用 minmax(0, ...) 兜底 */
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 48px;
}

/* TOC 隐藏时（短文章）的桌面布局：限定 760px 列居中。
   ⚠ 必须只在桌面生效，否则 :has() 的特异性会覆盖下面 @media 的单列规则，
   导致手机上主列仍是 760px，挤出视口造成"右边被截断"。 */
@media (min-width: 981px) {
  .article-layout:has(.toc-sidebar[hidden]) {
    grid-template-columns: minmax(0, 760px);
    justify-content: center;
  }
}

@media (max-width: 980px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc-sidebar { display: none; }
}

.article {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.article-header { margin-bottom: 24px; }

.article-tags-top {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.article-tags-top .tag { font-size: 12px; }

.article-title {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--text-main);
  margin-bottom: 24px;
  word-break: break-word;
  letter-spacing: -0.01em;
}

.article-author {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.article-author .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-soft);
  background-size: cover;
  flex-shrink: 0;
}

.article-author .info { flex: 1; min-width: 0; }
.article-author .name { font-size: 14px; color: var(--text-main); margin-bottom: 4px; font-weight: 500; }
.article-author .meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.article-author .meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-tertiary); }

.article-edit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary);
  padding: 4px 12px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  flex-shrink: 0;
}
.article-edit:hover { background: var(--primary); color: #fff; }

/* ---------- 正文排版 ---------- */
.article-body {
  font-size: 16px;
  line-height: 1.85;
  color: var(--text-main);
  word-break: break-word;
  /* 防止移动端 shrink-to-fit：所有内容必须收在视口内 */
  max-width: 100%;
  overflow-wrap: break-word;
}

/* 兜底：禁止任何后代元素撑出页面（公众号/老博客迁移过来的内联宽度等） */
.article-body * { max-width: 100%; }
.article-body img,
.article-body video,
.article-body iframe,
.article-body embed,
.article-body object,
.article-body svg {
  max-width: 100% !important;
  height: auto;
  display: block;
}
.article-body img { margin-left: auto; margin-right: auto; }
/* 公众号迁移内容里常见的 section 内联固定宽度 */
.article-body section,
.article-body figure,
.article-body div {
  max-width: 100% !important;
  box-sizing: border-box;
}
/* 表格用包裹层横向滚动，绝不撑爆 */
.article-body .table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 20px 0;
  -webkit-overflow-scrolling: touch;
}
.article-body .table-wrap > table { margin: 0; min-width: max-content; }

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  font-weight: 700;
  line-height: 1.4;
  margin: 30px 0 14px;
  scroll-margin-top: calc(var(--nav-height) + 20px);
}
.article-body h1 { font-size: 26px; }
.article-body h2 { font-size: 22px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.article-body h3 { font-size: 18px; }
.article-body h4 { font-size: 16px; }
.article-body p { margin: 14px 0; }
.article-body a { color: var(--primary); border-bottom: 1px solid rgba(234, 111, 90, 0.3); }
.article-body a:hover { border-bottom-color: var(--primary); }
.article-body img { margin-top: 20px; margin-bottom: 20px; border-radius: var(--radius); }

.article-body blockquote {
  margin: 20px 0;
  padding: 10px 18px;
  background: var(--bg-soft);
  border-left: 4px solid var(--primary);
  color: var(--text-secondary);
  font-size: 14.5px;
  border-radius: 0 4px 4px 0;
}
.article-body blockquote p { margin: 6px 0; }

.article-body ul, .article-body ol { padding-left: 26px; margin: 14px 0; }
.article-body li { margin: 6px 0; }
.article-body li::marker { color: var(--text-tertiary); }

.article-body code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.article-body pre {
  margin: 20px 0;
  background: var(--pre-bg);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.7;
}
.article-body pre code {
  background: transparent;
  color: var(--pre-text);
  padding: 0;
  font-size: 13px;
}

.article-body hr { margin: 32px 0; border: none; border-top: 1px solid var(--border); }

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}
.article-body th, .article-body td {
  border: 1px solid var(--border-strong);
  padding: 8px 12px;
  text-align: left;
}
.article-body th { background: var(--bg-soft); font-weight: 600; }

/* ---------- 文章底部 ---------- */
.article-footer {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.article-share {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------- TOC 侧栏 ---------- */
.toc-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 20px);
  align-self: start;
  max-height: calc(100vh - var(--nav-height) - 40px);
  overflow-y: auto;
}

.toc {
  padding: 14px 0 14px 14px;
  border-left: 2px solid var(--border);
  font-size: 13px;
}

.toc-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.toc-item {
  display: block;
  padding: 4px 8px;
  color: var(--text-secondary);
  line-height: 1.5;
  border-radius: 4px;
  transition: all 0.15s;
}
.toc-item:hover { color: var(--text-main); background: var(--bg-soft); }
.toc-item.active { color: var(--primary); font-weight: 500; }
.toc-item.level-3 { padding-left: 22px; font-size: 12px; }

/* ---------- 评论 ---------- */
.comments {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.comments-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 18px;
}
.comments-hint {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-secondary);
}
.comments-hint code {
  background: var(--bg-elev);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-main);
}
.comments-hint a { color: var(--brand); text-decoration: underline; }

@media (max-width: 720px) {
  .article-layout { padding: 18px 14px 50px; }
  .article-tags-top { gap: 5px; margin-bottom: 12px; }
  .article-title {
    font-size: 23px;
    margin-bottom: 16px;
    line-height: 1.4;
    letter-spacing: 0;
  }
  .article-author {
    flex-wrap: wrap;
    gap: 10px;
    padding: 6px 0 14px;
    margin-bottom: 22px;
  }
  .article-author .avatar { width: 38px; height: 38px; }
  .article-author .name { font-size: 13.5px; }
  .article-author .meta { font-size: 11.5px; gap: 6px; }
  .article-edit { font-size: 11px; padding: 3px 10px; }

  .article-body { font-size: 15.5px; line-height: 1.85; }
  .article-body h1 { font-size: 22px; }
  .article-body h2 { font-size: 19px; }
  .article-body h3 { font-size: 17px; }
  .article-body h4 { font-size: 15.5px; }
  .article-body pre { padding: 12px 14px; font-size: 12.5px; }
  .article-body blockquote { padding: 8px 14px; font-size: 14px; }
  .article-body table { font-size: 13px; }
  .article-body th, .article-body td { padding: 6px 8px; }

  .article-footer { margin-top: 30px; padding-top: 18px; }
  .comments { margin-top: 32px; padding-top: 22px; }
  .comments-title { font-size: 15px; margin-bottom: 14px; }
  .comments-hint { font-size: 12.5px; padding: 12px 14px; }
}

@media (max-width: 420px) {
  .article-title { font-size: 21px; }
  .article-author .meta .dot:nth-of-type(2) { display: none; }
  /* 窄屏隐藏「约 N 分钟」以省位；勿用 span:last-child，否则会误藏 Vercount 阅读量 */
  .article-author .meta .meta-read-mins { display: none; }
}

/* ---------- 阅读增强：进度条 / 回到顶部 / 代码复制 / 灯箱 ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #ffb199);
  box-shadow: 0 0 12px rgba(234, 111, 90, 0.35);
}

.back-to-top {
  position: fixed;
  right: 26px;
  bottom: 30px;
  z-index: 50;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s, color 0.18s, background 0.18s;
}
.back-to-top:hover {
  transform: translateY(-2px);
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.back-to-top svg { width: 20px; height: 20px; }

.article-body pre.has-copy {
  position: relative;
  padding-top: 42px;
}
.code-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--pre-text);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.code-copy:hover,
.code-copy.done {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.article-body h2,
.article-body h3,
.article-body h4 {
  position: relative;
}
.heading-anchor {
  margin-left: 8px;
  opacity: 0;
  font-size: 0.8em;
  border-bottom: none !important;
  color: var(--text-tertiary) !important;
  transition: opacity 0.15s, color 0.15s;
}
.article-body h2:hover .heading-anchor,
.article-body h3:hover .heading-anchor,
.article-body h4:hover .heading-anchor {
  opacity: 1;
}
.heading-anchor:hover { color: var(--primary) !important; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 42px;
  animation: overlayIn 0.18s ease-out;
}
.lightbox.is-hidden { display: none !important; }
.lightbox img {
  max-width: min(1100px, 100%);
  max-height: 88vh;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  cursor: zoom-out;
}
.lightbox-close {
  position: fixed;
  right: 24px;
  top: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- 上下篇 / 相关文章 ---------- */
.post-neighbors {
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.post-neighbor {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.post-neighbor:hover {
  border-color: rgba(234, 111, 90, 0.45);
  box-shadow: var(--shadow);
}
.post-neighbor.next { text-align: right; }
.post-neighbor .label {
  color: var(--text-tertiary);
  font-size: 12px;
}
.post-neighbor .title {
  color: var(--text-main);
  font-weight: 600;
  line-height: 1.45;
}

.post-related {
  margin-top: 28px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}
.post-related-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}
.post-related-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.post-related-list a {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.post-related-list li:last-child a { border-bottom: none; }
.post-related-list .t { color: var(--text-main); font-weight: 600; }
.post-related-list .meta { color: var(--text-tertiary); font-size: 12px; }

/* ---------- 外链图标 / 脚注 / 打印 ---------- */
.article-body a.external-link::after {
  content: "↗";
  margin-left: 3px;
  font-size: 0.78em;
  color: var(--text-tertiary);
}
.article-body .footnotes {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}
.article-body .footnotes::before {
  content: "注释";
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
  color: var(--text-main);
}

@media print {
  .nav,
  .toc-sidebar,
  .footer,
  .comments,
  .article-edit,
  .back-to-top,
  .reading-progress,
  .post-neighbors,
  .post-related,
  .code-copy {
    display: none !important;
  }
  .article-layout {
    display: block;
    max-width: none;
    padding: 0;
  }
  .article {
    max-width: none;
  }
  .article-body {
    color: #111;
    font-size: 12pt;
  }
  .article-body a {
    color: #111;
    border-bottom: none;
  }
}

@media (max-width: 720px) {
  .back-to-top {
    right: 16px;
    bottom: 20px;
    width: 38px;
    height: 38px;
  }
  .post-neighbors { grid-template-columns: 1fr; }
  .post-neighbor.next { text-align: left; }
  .post-related { padding: 16px 14px; }
  .lightbox { padding: 18px; }
  .lightbox-close { right: 14px; top: 14px; }
}

/* ============================================================
   代码块增强：语言徽标 / 行号 / 长代码折叠
   ============================================================ */

.article-body pre.has-line-numbers {
  /* 行号 gutter 占用左侧空间 */
  padding-left: 56px;
  position: relative;
}

.code-line-numbers {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 42px;
  padding: 16px 6px 16px 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.32);
  background: rgba(0, 0, 0, 0.18);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  user-select: none;
  white-space: pre;
  overflow: hidden;
  border-top-left-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
}

.article-body pre.has-line-numbers.has-copy {
  padding-top: 42px;
}
.article-body pre.has-line-numbers .code-line-numbers {
  /* 给顶部 meta 条让一点空间 */
  padding-top: 42px;
}

.code-lang {
  position: absolute;
  top: 10px;
  left: 56px;
  z-index: 2;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
}
.article-body pre:not(.has-line-numbers) .code-lang {
  left: 14px;
}

/* 长代码折叠：默认只显示前 ~22 行高度（约 22 * 1.7em） */
.article-body pre.code-foldable.code-folded {
  max-height: calc(1.7em * 22 + 56px);
  overflow: hidden;
  position: relative;
}
.article-body pre.code-foldable.code-folded::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 80px;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, var(--pre-bg) 70%);
}
.code-fold-toggle {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 3;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.code-fold-toggle:hover { filter: brightness(1.1); }
.article-body pre.code-foldable:not(.code-folded) {
  max-height: none;
}
.article-body pre.code-foldable:not(.code-folded) .code-fold-toggle {
  position: relative;
  left: auto;
  bottom: auto;
  transform: none;
  margin: 12px auto 4px;
  display: block;
}

/* ============================================================
   数学公式（KaTeX）
   ============================================================ */
.article-body .math-block {
  margin: 22px 0;
  overflow-x: auto;
  text-align: center;
}
.article-body .math-inline { display: inline-block; }
.article-body .math:empty::before {
  content: attr(data-tex);
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

/* ============================================================
   Mermaid
   ============================================================ */
.article-body .mermaid {
  margin: 22px 0;
  text-align: center;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 12px;
}
.article-body .mermaid svg { max-width: 100%; height: auto; }
.article-body .mermaid.mermaid-error pre {
  text-align: left;
  white-space: pre-wrap;
  font-size: 12.5px;
}

/* ============================================================
   分享 / 打赏 / 二维码 卡片
   ============================================================ */
.article-share {
  margin: 36px 0 12px;
  padding: 18px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.article-share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.article-share-label {
  margin-right: 6px;
  color: var(--text-secondary);
  font-size: 14px;
}
.article-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.article-share-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.article-share-btn.is-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.article-share-btn.is-primary:hover { color: #fff; filter: brightness(1.08); }
.article-share-qr {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
}
.article-share-qr canvas {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}
.article-share-qr-info {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.article-share-qr-info code {
  word-break: break-all;
  font-size: 12px;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 5px;
  border-radius: 3px;
}

/* 系列文章侧栏 */
.article-series {
  margin: 28px 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
}
.article-series-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.article-series-title {
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin-bottom: 0;
  font-weight: 600;
}
.article-series-all {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}
.article-series-all:hover { color: var(--primary); }
.article-series ol {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
}
.article-series li { margin: 4px 0; line-height: 1.6; }
.article-series li.is-current {
  color: var(--text-main);
  font-weight: 600;
  list-style-type: '▸ ';
}
.article-series li.is-current a { color: var(--text-main); border-bottom: none; }

/* PAT 即将过期 / 已失效 横幅（admin 顶部） */
.pat-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  font-size: 13px;
  background: #fff7e6;
  color: #ad6800;
  border-bottom: 1px solid #ffe7ba;
}
.pat-banner.is-error { background: #fff1f0; color: #a8071a; border-bottom-color: #ffccc7; }
.pat-banner a { color: inherit; text-decoration: underline; }

@media (max-width: 720px) {
  .article-body pre.has-line-numbers { padding-left: 44px; }
  .code-line-numbers { width: 34px; font-size: 12px; }
  .code-lang { font-size: 10.5px; padding: 1px 6px; }
  .article-share { padding: 14px 14px; }
}

