/* ---------- 布局 ---------- */

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 60;
  height: 2px;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.note-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px;
  align-items: start;
  gap: 72px;
  padding-top: 44px;
}

.note {
  min-width: 0;
  max-width: 780px;
}

.note-header {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
  color: var(--text-faint);
  font-size: 13px;
}

.breadcrumb a {
  transition: color 0.15s;
}

.breadcrumb a:hover {
  color: var(--text);
}

.note-title {
  font-size: clamp(28px, 4.4vw, 42px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.note-lead {
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.75;
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  margin-top: 22px;
  color: var(--text-faint);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.note-meta > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.note-tags .tag-chip {
  height: 28px;
  font-size: 12.5px;
}

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

.note-aside {
  position: sticky;
  top: calc(var(--header-h) + 36px);
  max-height: calc(100vh - var(--header-h) - 72px);
  overflow-y: auto;
  padding-bottom: 12px;
}

.toc-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

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

.toc-item a {
  display: block;
  margin-left: -1px;
  padding: 5px 0 5px 14px;
  border-left: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.5;
  transition: color 0.15s, border-color 0.15s;
}

.toc-level-3 a {
  padding-left: 28px;
  font-size: 13px;
}

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

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

.toc-top {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
  color: var(--text-faint);
  font-size: 13px;
  transition: color 0.15s;
}

.toc-top:hover {
  color: var(--text);
}

.toc-mobile {
  display: none;
  margin-bottom: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.toc-mobile summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 550;
  list-style: none;
  cursor: pointer;
}

.toc-mobile summary::-webkit-details-marker {
  display: none;
}

.toc-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.toc-mobile[open] .toc-chevron {
  transform: rotate(180deg);
}

.toc-mobile .toc-list {
  margin: 0 16px 14px;
}

/* ---------- 正文 ---------- */

.prose {
  color: var(--text);
  font-size: 16px;
  line-height: 1.85;
  overflow-wrap: break-word;
}

.prose > :first-child {
  margin-top: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose dl,
.prose blockquote,
.prose table,
.prose details,
.prose .math.block,
.prose .markdown-alert,
.prose pre.mermaid {
  margin: 0 0 1.15em;
}

.prose h2 {
  margin: 2.2em 0 0.8em;
  padding-bottom: 0.45em;
  border-bottom: 1px solid var(--border);
  font-size: 1.55em;
  letter-spacing: -0.025em;
}

.prose h3 {
  margin: 1.8em 0 0.6em;
  font-size: 1.25em;
}

.prose h4 {
  margin: 1.6em 0 0.5em;
  font-size: 1.06em;
}

.prose .header-anchor {
  margin-left: 0.3em;
  color: var(--text-faint);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.prose h2:hover .header-anchor,
.prose h3:hover .header-anchor,
.prose h4:hover .header-anchor,
.prose .header-anchor:focus-visible {
  opacity: 1;
}

.prose .header-anchor:hover {
  color: var(--accent-text);
}

.prose a:not(.header-anchor):not(.footnote-backref):not([href^="#fn"]) {
  color: var(--accent-text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}

.prose a:not(.header-anchor):hover {
  text-decoration-color: currentColor;
}

.prose strong {
  font-weight: 650;
}

.prose ul,
.prose ol {
  padding-left: 1.6em;
}

.prose li + li {
  margin-top: 0.35em;
}

.prose li > ul,
.prose li > ol {
  margin: 0.35em 0 0;
}

.prose li > p {
  margin-bottom: 0.5em;
}

.prose li::marker {
  color: var(--text-faint);
}

.prose .contains-task-list {
  padding-left: 0.2em;
  list-style: none;
}

.prose .task-list-item input {
  width: 15px;
  height: 15px;
  margin: 0 0.6em 0 0;
  vertical-align: -0.15em;
  accent-color: var(--accent);
}

.prose blockquote {
  margin-inline: 0;
  padding: 0.15em 1.2em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.prose blockquote > :last-child,
.prose .markdown-alert > :last-child,
.prose details > :last-child,
.prose li > :last-child {
  margin-bottom: 0;
}

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

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.prose :not(pre) > code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font: 0.86em/1.5 var(--font-mono);
  font-variant-ligatures: none;
  white-space: break-spaces;
}

.prose kbd {
  font-size: 0.78em;
}

.prose mark {
  padding: 0.05em 0.2em;
  border-radius: 3px;
  background: var(--mark-bg);
  color: inherit;
}

.prose sub,
.prose sup {
  font-size: 0.75em;
  line-height: 0;
}

.prose abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* 表格 */

.prose table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92em;
  line-height: 1.6;
}

.prose th,
.prose td {
  padding: 0.6em 1em;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.prose th:last-child,
.prose td:last-child {
  border-right: 0;
}

.prose tbody tr:last-child td {
  border-bottom: 0;
}

.prose th {
  background: var(--bg-subtle);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.prose tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg-subtle) 70%, transparent);
}

/* 定义列表、折叠块 */

.prose dt {
  font-weight: 620;
}

.prose dd {
  margin: 0.2em 0 0.8em 1.6em;
  color: var(--text-muted);
}

.prose details {
  padding: 0.7em 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.prose summary {
  font-weight: 560;
  cursor: pointer;
}

.prose details[open] > summary {
  margin-bottom: 0.6em;
}

/* 代码块 */

.prose .code-block {
  margin: 0 0 1.3em;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 6px 0 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font: 500 12px var(--font-mono);
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font: 500 12px var(--font-sans);
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.code-copy:hover {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.code-copy.is-copied {
  color: var(--tint-terminal);
}

.prose .code-block pre {
  margin: 0;
  padding: 14px 16px 16px;
  overflow-x: auto;
  font: 13.5px/1.7 var(--font-mono);
  font-variant-ligatures: none;
  tab-size: 4;
}

.prose .code-block code {
  font: inherit;
}

/* 提示块 */

.prose .markdown-alert {
  --alert: #3b82f6;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
  padding: 0.85em 1.1em;
  border: 1px solid color-mix(in srgb, var(--alert) 26%, var(--border));
  border-left: 3px solid var(--alert);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--alert) 7%, var(--bg));
}

.prose .markdown-alert-tip {
  --alert: #16a34a;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5M9 18h6M10 22h4'/%3E%3C/svg%3E");
}

.prose .markdown-alert-important {
  --alert: #8b5cf6;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM12 7v2M12 13h.01'/%3E%3C/svg%3E");
}

.prose .markdown-alert-warning {
  --alert: #d97706;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}

.prose .markdown-alert-caution {
  --alert: #dc2626;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 16h.01M12 8v4M15.31 2a2 2 0 0 1 1.42.59l4.68 4.68A2 2 0 0 1 22 8.69v6.62a2 2 0 0 1-.59 1.42l-4.68 4.68a2 2 0 0 1-1.42.59H8.69a2 2 0 0 1-1.42-.59l-4.68-4.68A2 2 0 0 1 2 15.31V8.69a2 2 0 0 1 .59-1.42l4.68-4.68A2 2 0 0 1 8.69 2z'/%3E%3C/svg%3E");
}

[data-theme="dark"] .prose .markdown-alert { --alert: #60a5fa; }
[data-theme="dark"] .prose .markdown-alert-tip { --alert: #4ade80; }
[data-theme="dark"] .prose .markdown-alert-important { --alert: #a78bfa; }
[data-theme="dark"] .prose .markdown-alert-warning { --alert: #fbbf24; }
[data-theme="dark"] .prose .markdown-alert-caution { --alert: #f87171; }

.prose .markdown-alert-title {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 0.3em;
  color: var(--alert);
  font-weight: 650;
}

.prose .markdown-alert-title::before {
  content: "";
  flex: none;
  width: 1.05em;
  height: 1.05em;
  background: currentColor;
  -webkit-mask: var(--alert-icon) center / contain no-repeat;
  mask: var(--alert-icon) center / contain no-repeat;
}

/* 脚注 */

.prose .footnote-ref a {
  padding: 0 0.1em;
  color: var(--accent-text);
  font-size: 0.85em;
}

.prose .footnotes-sep {
  margin: 3em 0 1.4em;
}

.prose .footnotes {
  color: var(--text-muted);
  font-size: 0.9em;
}

.prose .footnotes-list {
  padding-left: 1.4em;
}

.prose .footnote-item p {
  margin-bottom: 0.4em;
}

.prose .footnote-item:target {
  border-radius: 6px;
  background: var(--accent-soft);
}

.prose .footnote-backref {
  margin-left: 0.2em;
  color: var(--accent-text);
}

/* 公式与图表 */

.prose .math.block {
  padding: 0.4em 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

.prose .katex {
  font-size: 1.08em;
}

.prose pre.mermaid {
  display: flex;
  justify-content: center;
  padding: 20px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-faint);
  font: 13px/1.6 var(--font-mono);
}

.prose pre.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ---------- 上一篇 / 下一篇 ---------- */

.note-pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.pager-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.pager-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.pager-next {
  grid-column: 2;
  align-items: flex-end;
  text-align: right;
}

.pager-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font-size: 12.5px;
}

.pager-title {
  font-weight: 600;
  line-height: 1.5;
  transition: color 0.15s;
}

.pager-card:hover .pager-title {
  color: var(--accent-text);
}

.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, color 0.15s;
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.back-to-top:hover {
  color: var(--text);
}

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) {
  .note-layout {
    grid-template-columns: minmax(0, 780px);
    justify-content: center;
  }

  .note-aside {
    display: none;
  }

  .toc-mobile {
    display: block;
  }
}

@media (max-width: 640px) {
  .note-layout {
    padding-top: 28px;
  }

  .prose {
    font-size: 15.5px;
  }

  .prose .code-block pre {
    font-size: 12.5px;
  }

  .note-pager {
    grid-template-columns: minmax(0, 1fr);
  }

  .pager-next {
    grid-column: auto;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
  }
}
