/*
 * 文章阅读页正文排版。
 *
 * 作用域：所有选择器都以 .post-content 打头。该类只出现在 Fluid 的 layout/post.ejs，
 * 因此这份样式不会波及 about / friends / guestbook 等同样使用 .markdown-body 的页面，
 * 也不会影响 /news/ 日报页。
 *
 * 配色一律取 aoiblog-home.css 里的 --aoi-* 变量，跟随亮/暗两套主题；
 * 正文中不再有内联样式（已由 tools/clean-post-inline-styles.mjs 清洗）。
 */

.post-content .markdown-body {
  width: 100%;
  max-width: 720px;
  margin-right: auto;
  margin-left: auto;
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--aoi-text);
  letter-spacing: 0.01em;
  word-break: break-word;
  text-wrap: pretty;
}

/* ---------- 段落与行内元素 ---------- */

.post-content .markdown-body p {
  margin: 0 0 1.2em;
}

.post-content .markdown-body > p:not(:has(img)) {
  text-indent: 2em;
}

.post-content .markdown-body a {
  color: var(--aoi-accent-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.2s ease;
}

.post-content .markdown-body a:hover {
  color: var(--aoi-accent);
}

.post-content .markdown-body strong {
  color: var(--aoi-heading);
  font-weight: 600;
}

/* 行内代码的胶囊样式。作用域必须排除代码块里的 <code class="hljs">：
   若写成 `.markdown-body code`，它的权重（0,2,1）会压过高亮主题的 `.hljs`（0,1,0），
   主题没单独着色的 token 就被刷成这里的强调色，而强调色不随代码块背景走，
   在暗色背景上对比度极低。
   这里用子选择器 `> code` 而不是后代 `:not(pre) code`：后者在 figure.highlight 里
   仍会命中——那儿 <code> 的祖先链上有 td/table 等非 pre 元素，等于没排除。 */
.post-content .markdown-body :not(pre) > code,
.post-content .markdown-body > code {
  background: var(--aoi-bg-soft);
  color: var(--aoi-accent-strong);
  border: 1px solid var(--aoi-line);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.92em;
}

/* ---------- 标题 ---------- */

.post-content .markdown-body h1,
.post-content .markdown-body h2,
.post-content .markdown-body h3,
.post-content .markdown-body h4,
.post-content .markdown-body h5,
.post-content .markdown-body h6 {
  color: var(--aoi-heading);
  line-height: 1.45;
  font-weight: 600;
  margin: 2.2em 0 0.9em;
}

.post-content .markdown-body > :first-child {
  margin-top: 0;
}

.post-content .markdown-body h1 { font-size: 1.7em; }
.post-content .markdown-body h2 { font-size: 1.42em; }
.post-content .markdown-body h3 { font-size: 1.2em; }
.post-content .markdown-body h4 { font-size: 1.06em; }

.post-content .markdown-body h2 {
  border-bottom: 1px solid var(--aoi-line);
  padding-bottom: 0.35em;
}

/* ---------- 列表 ---------- */

.post-content .markdown-body ul,
.post-content .markdown-body ol {
  margin: 0 0 1.15em;
  padding-left: 1.6em;
}

.post-content .markdown-body li {
  margin-bottom: 0.4em;
}

.post-content .markdown-body li > ul,
.post-content .markdown-body li > ol {
  margin: 0.4em 0 0;
}

/* ---------- 引用 ---------- */

.post-content .markdown-body blockquote {
  margin: 1.4em 0;
  padding: 0.8em 1.2em;
  color: var(--aoi-muted);
  background: var(--aoi-bg-soft);
  border-left: 3px solid var(--aoi-accent);
  border-radius: 0 6px 6px 0;
}

.post-content .markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

/* ---------- 代码块 ---------- */

.post-content .markdown-body pre,
.post-content .markdown-body figure.highlight {
  margin: 1.4em 0;
  border-radius: 8px;
  border: 1px solid var(--aoi-line);
}

.post-content .markdown-body pre {
  overflow-x: auto;
  overflow-y: hidden;
}

.post-content .markdown-body figure.highlight {
  overflow: hidden;
}

/* 代码块内的 code 不套用行内代码的胶囊样式，前景色一律交给高亮主题的 `.hljs`。
   这里刻意不声明 color：写死色值只能适配亮暗之一，而 `.hljs` 在两套主题里
   各自带了配套的前景色。
   字号写 inherit 而不是某个比例：主题的 `.markdown-body pre` 已经给了
   `font-size: 85% !important`，内层 <code> 再写相对值就会在 85% 之上再乘一次
   （见下面对齐规则里的实测数据）。inherit 让所有代码块——带行号的、不带行号的、
   缩进型的——都只吃主题那一档。 */
.post-content .markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* 行号列与代码列是 <td class="gutter"> 和 <td class="code"> 里两个各自独立的 <pre>，
   浏览器分别对它们排版，只有字号和行高都相同才不会逐行累积错位。

   两侧的字号都交给主题的 `.markdown-body pre { font-size: 85% !important }`——那条
   带 !important，任何选择器权重都压不过它，跟它抢只会让两侧各错一点。
   关键是代码侧多套了一层 <code>：一旦在它上面写相对字号，就会在 85% 之上再乘一次
   （实测 13.6px vs 12.24px，36 行累积错开近一整行），所以这里显式让内层 <code>
   跟住父级 <pre>，不再叠比例。
   行高则必须带单位：unitless 会各自乘以本侧字号，字号相同才等价，不如直接钉死。 */
.post-content .markdown-body figure.highlight td.gutter pre,
.post-content .markdown-body figure.highlight td.code pre,
.post-content .markdown-body figure.highlight td.code pre code {
  font-size: inherit;
  line-height: 1.5rem;
}

/* 主题给代码侧的 <pre> 留了 `padding: 1.45rem 1rem`，却把行号侧重置成 `padding: 0 .75rem`，
   于是行号整体比代码文字高出 1.45rem（实测 23.2px）——这是一个不随行数变化的固定错位，
   和上面那条累积错位是两回事，两者都修掉才真正对齐。
   只补垂直内边距，左右保持主题的 .75rem，以免动到行号与代码之间的分隔线间距。 */
.post-content .markdown-body figure.highlight td.gutter pre {
  padding-top: 1.45rem;
  padding-bottom: 1.45rem;
}

/* atom-one-dark 给注释的 #5c6370 在自家背景上只有 2.32:1，正文注释（中文尤其明显）
   几乎糊进背景。这里只提亮注释一档到约 4.6:1，跨过可读阈值又不让注释抢过代码本身。
   只在暗色下改：亮色主题的注释对比度本来就够。 */
[data-user-color-scheme="dark"] .post-content .markdown-body figure.highlight .hljs-comment,
[data-user-color-scheme="dark"] .post-content .markdown-body figure.highlight .hljs-quote {
  color: #8b949e;
}

.post-content .aoi-code-block {
  position: relative;
}

.post-content .aoi-code-wrap-toggle {
  position: absolute;
  top: 0.45rem;
  left: 0.55rem;
  z-index: 3;
  display: none;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0.35rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--aoi-line-strong);
  border-radius: 5px;
  background: color-mix(in srgb, var(--aoi-paper-strong) 92%, transparent);
  color: var(--aoi-muted);
  cursor: pointer;
}

.post-content .aoi-code-wrap-toggle:hover,
.post-content .aoi-code-wrap-toggle[aria-pressed="true"] {
  border-color: var(--aoi-accent);
  color: var(--aoi-accent-strong);
}

.post-content .aoi-code-wrap-toggle:focus-visible {
  outline: 2px solid var(--aoi-accent);
  outline-offset: 2px;
}

.post-content .aoi-code-wrap-toggle svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.post-content pre.aoi-code-block.is-code-wrapped,
.post-content figure.aoi-code-block.is-code-wrapped .code pre {
  white-space: pre-wrap !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.post-content figure.aoi-code-block.is-code-wrapped .code {
  vertical-align: top;
}

/* ---------- 表格 ---------- */

.post-content .aoi-table-scroll {
  position: relative;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  margin: 1.4em 0;
  border: 1px solid var(--aoi-line);
  border-radius: 8px;
  scrollbar-width: thin;
}

.post-content .aoi-table-scroll.is-scrollable:not(.is-at-end) {
  box-shadow: inset -14px 0 12px -14px var(--aoi-accent);
}

.post-content .aoi-table-scroll:focus-visible {
  outline: 2px solid var(--aoi-accent);
  outline-offset: 3px;
}

.post-content .aoi-content-table {
  width: max-content;
  min-width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.96em;
}

.post-content .aoi-content-table th,
.post-content .aoi-content-table td {
  padding: 0.6em 0.9em;
  border: 1px solid var(--aoi-line);
  text-align: left;
  vertical-align: top;
}

.post-content .aoi-content-table th {
  background: var(--aoi-bg-soft);
  color: var(--aoi-heading);
  font-weight: 600;
}

/* ---------- 图片与分隔线 ---------- */

.post-content .markdown-body img {
  display: block;
  max-width: 100%;
  margin: 1.6em auto;
  border-radius: 8px;
  box-shadow: var(--aoi-shadow);
}

.post-content .markdown-body hr {
  margin: 2.4em 0;
  border: 0;
  border-top: 1px solid var(--aoi-line);
}

/* ---------- 折叠块（写作时直接用 <details><summary>标题</summary> …</details>） ---------- */

.post-content .markdown-body details {
  margin: 1.4em 0;
  padding: 0 1.1em;
  background: var(--aoi-bg-soft);
  border: 1px solid var(--aoi-line);
  border-left: 3px solid var(--aoi-accent);
  border-radius: 0 6px 6px 0;
}

.post-content .markdown-body summary {
  margin: 0 -1.1em;
  padding: 0.75em 1.1em;
  color: var(--aoi-heading);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.post-content .markdown-body summary::-webkit-details-marker {
  display: none;
}

/* 展开标记用字符切换而非 rotate：伪元素上的 transform 过渡在部分浏览器不稳定 */
.post-content .markdown-body summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-right: 0.35em;
  color: var(--aoi-accent);
}

.post-content .markdown-body details[open] > summary::before {
  content: "▾";
}

.post-content .markdown-body details[open] > summary {
  border-bottom: 1px solid var(--aoi-line);
  margin-bottom: 0.9em;
}

.post-content .markdown-body details > :last-child {
  margin-bottom: 1.1em;
}

/* ---------- 窄屏 ---------- */

@media (max-width: 767px) {
  .post-content .markdown-body {
    font-size: 1rem;
    line-height: 1.8;
    letter-spacing: 0;
  }

  .post-content .markdown-body h1 { font-size: 1.5em; }
  .post-content .markdown-body h2 { font-size: 1.3em; }
  .post-content .markdown-body h3 { font-size: 1.14em; }

  .post-content .aoi-code-wrap-toggle {
    display: flex;
  }

  .post-content pre.aoi-code-block {
    padding-top: 2.7rem;
  }

  .post-content .aoi-content-table {
    font-size: 0.92em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .post-content .markdown-body a,
  .post-content .aoi-code-wrap-toggle {
    transition: none !important;
  }
}
