/* ============================================================
   内容增强层 —— 阅读进度条 / 代码高亮 / 文章目录 / 架构图 / 归档页
   设计语言沿用 style.css 的纸感配色与青蓝强调色
   ============================================================ */

/* ------------------------------------------------------------
   1. 顶部阅读进度条
   只有文章页（body.has-article）才显示，避免首页出现无意义进度
   ------------------------------------------------------------ */
.read-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  z-index: 1001;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-dark) 100%);
  transform: scaleX(0);
  transform-origin: 0 50%;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.1s linear, opacity 0.3s ease;
  will-change: transform;
}
body.has-article .read-progress { opacity: 1; }
.reduced-motion .read-progress { transition: none; }

/* ------------------------------------------------------------
   2. 代码块容器 + 语言标签 + 复制按钮
   pre 外包一层 .code-wrap，工具栏绝对定位在右上角，不干扰选中复制
   ------------------------------------------------------------ */
.code-wrap {
  position: relative;
  margin: 1.5rem 0;
  border-radius: var(--radius-sm);
  background: var(--ink);
  overflow: hidden;
}
.code-wrap > pre {
  margin: 0 !important;
  border-radius: var(--radius-sm);
  background: transparent !important;
  padding: 1.5rem !important;
}
.code-wrap > pre > code {
  display: block;
  /* 正文栏只有 720px，长代码行如果横向滚动，读者很容易漏看右半部分。
     这里改为软换行：内容全部可见，需要原始文本时用右上角「复制」按钮。 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  tab-size: 4;
  -moz-tab-size: 4;
}
/* 滚动条也做成深色，避免突兀的白色轨道 */
.code-wrap > pre::-webkit-scrollbar { height: 8px; }
.code-wrap > pre::-webkit-scrollbar-track { background: transparent; }
.code-wrap > pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
}
.code-wrap > pre::-webkit-scrollbar-thumb:hover { background: rgba(99, 212, 240, 0.45); }

.code-bar {
  position: absolute;
  top: 0.6rem;
  right: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.code-wrap:hover .code-bar,
.code-wrap:focus-within .code-bar {
  opacity: 1;
  pointer-events: auto;
}
.code-lang {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9aa4ad;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.09);
  padding: 0.3rem 0.5rem;
  border-radius: 5px;
  user-select: none;
}
.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-family: var(--font);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #c6ced6;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.3rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.code-copy:hover {
  background: rgba(99, 212, 240, 0.18);
  border-color: rgba(99, 212, 240, 0.42);
  color: #a8ecfb;
}
.code-copy:active { transform: translateY(1px); }
.code-copy.copied {
  color: #a7f3d0;
  border-color: rgba(167, 243, 208, 0.45);
  background: rgba(167, 243, 208, 0.1);
}
/* 触屏设备没有 hover，工具栏常显 */
@media (hover: none) {
  .code-bar { opacity: 1; pointer-events: auto; }
}

/* ------------------------------------------------------------
   3. 代码高亮配色
   底色即 pre 的 --ink (#262626)，不另换色块以保持版面统一
   ------------------------------------------------------------ */
.article-body .hljs {
  color: #e4e4e7;
  background: transparent;
  padding: 0;
}
.article-body .hljs-comment,
.article-body .hljs-quote {
  color: #6f7b85;
  font-style: italic;
}
.article-body .hljs-keyword,
.article-body .hljs-selector-tag,
.article-body .hljs-literal,
.article-body .hljs-type,
.article-body .hljs-doctag {
  color: #8be5fb;
}
.article-body .hljs-string,
.article-body .hljs-regexp,
.article-body .hljs-addition {
  color: #a7f3d0;
}
.article-body .hljs-number,
.article-body .hljs-symbol,
.article-body .hljs-bullet,
.article-body .hljs-variable.constant_ {
  color: #fcd34d;
}
.article-body .hljs-title,
.article-body .hljs-title.function_,
.article-body .hljs-section,
.article-body .hljs-selector-id {
  color: #93c5fd;
}
.article-body .hljs-title.class_,
.article-body .hljs-built_in {
  color: #f0abfc;
}
.article-body .hljs-attr,
.article-body .hljs-attribute,
.article-body .hljs-property,
.article-body .hljs-params {
  color: #e4e4e7;
}
.article-body .hljs-meta,
.article-body .hljs-meta .hljs-keyword {
  color: #94a3b8;
}
.article-body .hljs-tag,
.article-body .hljs-name {
  color: #8be5fb;
}
.article-body .hljs-deletion {
  color: #fca5a5;
  background: rgba(127, 29, 29, 0.35);
}
.article-body .hljs-addition {
  background: rgba(20, 83, 45, 0.35);
}
.article-body .hljs-emphasis { font-style: italic; }
.article-body .hljs-strong { font-weight: 600; }

/* ------------------------------------------------------------
   4. 文章目录 TOC
   文章栏固定 720px 居中，TOC 落其右侧；窄屏直接隐藏
   ------------------------------------------------------------ */
.toc {
  position: fixed;
  top: calc(var(--nav-height) + 64px);
  left: calc(50% + 380px);
  width: 244px;
  max-height: calc(100vh - var(--nav-height) - 140px);
  overflow-y: auto;
  display: none;
  font-size: 0.82rem;
  line-height: 1.45;
  padding-left: 1rem;
  border-left: 1px solid var(--line-soft);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 40;
  scrollbar-width: thin;
}
/* 注意：is-visible 只负责淡入，不负责 display。
   display 只在宽屏媒体查询里打开，否则窄屏会浮出来压住正文。 */
.toc.is-visible {
  opacity: 1;
  transform: none;
}
@media (min-width: 1300px) {
  .toc { display: block; }
}
.toc-title {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.8rem;
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a {
  position: relative;
  display: block;
  padding: 0.32rem 0 0.32rem 0.9rem;
  margin-left: -1rem;
  color: var(--ink-faint);
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.18s ease, border-color 0.18s ease;
}
.toc-list a::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: transparent;
  transition: background 0.18s ease;
}
.toc-list a:hover { color: var(--ink); }
.toc-list a.lv3 {
  padding-left: 1.7rem;
  font-size: 0.78rem;
}
.toc-list a.active {
  color: var(--accent-dark);
  font-weight: 600;
}
.toc-list a.active::before { background: var(--accent); }

/* ------------------------------------------------------------
   5. mermaid 架构图
   ------------------------------------------------------------ */
.mermaid-figure {
  margin: 1.75rem 0;
  padding: 1.5rem 1rem;
  background: var(--bone);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  text-align: center;
}
.mermaid-figure .mermaid { display: flex; justify-content: center; }
.mermaid-figure svg { max-width: 100%; height: auto; }
.mermaid-figure.is-error {
  background: #fff7ed;
  border-color: #fed7aa;
  text-align: left;
}
.mermaid-figure.is-error pre {
  background: var(--ink) !important;
  margin-top: 0.75rem !important;
}
.mermaid-err-note {
  font-size: 0.78rem;
  color: #c2410c;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* ------------------------------------------------------------
   6. 归档页 /archive
   ------------------------------------------------------------ */
.archive-hero {
  padding-top: 160px;
  max-width: 860px;
  margin: 0 auto;
  padding-left: 2rem;
  padding-right: 2rem;
}
.archive-hero .stat {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line-soft);
}
/* 数字组与右侧链接分开，数字之间底部对齐，避免日期那列标签错位 */
.archive-hero .stat-group {
  display: flex;
  align-items: flex-end;
  gap: 2.5rem;
}
.archive-hero .stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.archive-hero .stat-item .n {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.archive-hero .stat-item .n.is-date {
  font-size: 1.05rem;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.archive-hero .stat-item .l {
  display: block;
  font-size: 0.76rem;
  line-height: 1.2;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
.archive-hero .stat-link {
  color: var(--accent-dark);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.2;
  padding-bottom: 0.1rem;
  white-space: nowrap;
  transition: color 0.18s ease;
}
.archive-hero .stat-link:hover { color: var(--ink); }

.archive-body {
  max-width: 860px;
  margin: 3.5rem auto 5rem;
  padding: 0 2rem;
}
.archive-year { margin-bottom: 3.25rem; }
.archive-year:last-child { margin-bottom: 0; }
.archive-year-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.archive-year-head .num {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.archive-year-head .cnt {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  padding: 0.15rem 0.45rem;
  background: var(--paper-warm);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}
.archive-list {
  list-style: none;
  margin: 0 0 0 0.35rem;
  padding: 0 0 0 1.4rem;
  border-left: 1px solid var(--line);
}
.archive-item {
  position: relative;
  display: grid;
  grid-template-columns: 62px 1fr auto;
  align-items: baseline;
  gap: 1rem;
  padding: 0.72rem 0;
  border-bottom: 1px dashed var(--line-soft);
}
.archive-item:last-child { border-bottom: none; }
.archive-item::before {
  content: '';
  position: absolute;
  left: calc(-1.4rem - 4px);
  top: 1.18rem;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line-hover);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.archive-item:hover::before {
  background: var(--accent);
  border-color: var(--accent-dark);
  transform: scale(1.25);
}
.archive-item .when {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.archive-item .what {
  color: var(--ink);
  font-size: 0.97rem;
  font-weight: 500;
  transition: color 0.18s ease;
}
.archive-item:hover .what { color: var(--accent-dark); }
.archive-item .what .tagline {
  display: inline-block;
  margin-left: 0.6rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-faint);
  vertical-align: 1px;
}
.archive-item .rt {
  font-size: 0.72rem;
  color: var(--ink-faint);
  white-space: nowrap;
}
.archive-empty {
  color: var(--ink-faint);
  font-style: italic;
  padding: 2rem 0;
}

@media (max-width: 640px) {
  .archive-hero { padding-top: 130px; }
  .archive-hero .stat {
    flex-direction: column;
    align-items: flex-start;
    gap: 1.25rem;
  }
  .archive-hero .stat-group { gap: 1.75rem; }
  .archive-item {
    grid-template-columns: 52px 1fr;
    row-gap: 0.15rem;
  }
  .archive-item .rt { grid-column: 2; }
  .archive-item .what { font-size: 0.92rem; }
}
