/* ============================================================
   JINER Blog — 文章阅读页
   进度条 · 目录 · 正文排版 · 上下篇 · 最近文章
   （合并原 template 内联样式与 article.css 阅读增强）
   ============================================================ */

/* ---------- 阅读进度 ---------- */
.reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--color-accent), #8b5cf6);
  z-index: 100;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
  pointer-events: none;
}

/* ---------- 版心 ---------- */
.article-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--nav-height, 60px) + 2rem) 1rem 3rem;
}

.article-header {
  text-align: center;
  margin-bottom: 3rem;
  position: relative;
  padding-bottom: 2rem;
}
.article-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 64px; height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--color-accent), #8b5cf6);
}
.article-header h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--color-primary);
  margin-bottom: 1.25rem;
}
.article-meta {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.article-meta time { font-family: var(--font-mono); }
.article-meta .dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--color-border);
}

/* ---------- 目录 ---------- */
#tocContainer {
  position: relative;
  margin-bottom: 2rem;
}
#tocContainer.is-hidden { display: none; }

.toc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin-bottom: 0;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-accent);
  background: var(--color-accent-soft);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}
.toc-toggle:hover {
  background: rgba(109, 40, 217, 0.12);
  border-color: var(--color-accent);
}
.toc-toggle svg { transition: transform 0.25s ease; }
.toc-toggle.open svg { transform: rotate(180deg); }

.toc-panel {
  position: absolute;
  z-index: 40;
  left: 0;
  top: calc(100% + 8px);
  min-width: 260px;
  max-width: 340px;
  max-height: 60vh;
  overflow: auto;
  padding: 20px 22px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .14);
  font-size: var(--text-sm);
  line-height: 1.8;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
}
.toc-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.toc-panel .toc-title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  font-weight: 600;
}
.toc-panel a {
  display: block;
  padding: 3px 0 3px 12px;
  border-left: 2px solid transparent;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color .15s ease, border-color .15s ease;
}
.toc-panel a:hover,
.toc-panel a.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
}
.toc-panel a.toc-h3 {
  padding-left: 32px;
  font-size: 0.9em;
}

/* 宽屏：固定左侧目录（菜鸟教程式） */
@media (min-width: 1200px) {
  .toc-toggle { display: none; }
  .toc-panel {
    position: fixed;
    left: max(12px, calc((100vw - 720px) / 2 - 252px));
    top: 130px;
    width: 232px;
    max-height: calc(100vh - 180px);
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    transform: none;
  }
  .toc-panel::before {
    content: "本页目录";
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    padding: 0 0 6px 12px;
  }
  .toc-panel .toc-title { display: none; }
  .toc-panel a { font-size: 13px; padding: 4px 0 4px 12px; }
}

/* ---------- 正文排版 ---------- */
.article-body {
  font-size: var(--text-lg);
  line-height: 1.85;
  color: var(--color-text);
}
.article-body p { margin-bottom: 1.5rem; }

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  margin-top: 3rem;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-primary);
  scroll-margin-top: 5rem;
}
.article-body h2 {
  font-size: 1.5rem;
  padding-left: .8rem;
  border-left: 4px solid var(--color-accent);
}
.article-body h3 {
  font-size: 1.25rem;
  padding-left: .75rem;
  border-left: 2px solid var(--color-border);
}

.article-body strong { color: var(--color-primary); font-weight: 600; }

.article-body code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--color-surface-alt);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-accent);
}

/* 代码块：跟随主题的底色 + 右上角复制按钮 */
.article-body pre {
  position: relative;
  background: #f6f8fa;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-md);
  padding: 0;
  margin: 2rem 0;
  overflow: visible;
  font-size: var(--text-sm);
  line-height: 1.7;
}
[data-theme="dark"] .article-body pre {
  background: #0d1117;
  border: none;
}
.article-body pre code {
  display: block;
  padding: 1rem 1.1rem;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
}
.article-body .highlight {
  margin: 2rem 0;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.article-body .highlight pre { margin: 0; }

.article-body .article-copy {
  position: absolute;
  top: 10px; right: 10px;
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .05);
  color: #6b7280;
  border: 1px solid rgba(0, 0, 0, .1);
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
}
[data-theme="dark"] .article-body .article-copy {
  background: rgba(255, 255, 255, .08);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, .14);
}
.article-body pre:hover .article-copy { opacity: 1; }
.article-body .article-copy:hover { background: rgba(0, 0, 0, .1); }
[data-theme="dark"] .article-body .article-copy:hover {
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

.article-body a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.article-body blockquote {
  border-left: 3px solid var(--color-accent);
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  color: var(--color-text-secondary);
  background: rgba(99, 102, 241, 0.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* 表格（依赖 python-markdown extra）：窄屏横向滚动，不压扁单元格 */
.article-body .table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
  -webkit-overflow-scrolling: touch;
}
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 14px;
  line-height: 1.6;
}
.article-body .table-wrap table { margin: 0; min-width: 520px; }
.article-body th,
.article-body td {
  border: 1px solid var(--color-border-light);
  padding: 10px 14px;
  text-align: left;
}
.article-body th {
  background: rgba(99, 102, 241, 0.06);
  font-weight: 600;
}
.article-body tbody tr:nth-child(even) { background: var(--color-surface-alt); }

.article-body img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 1.5rem 0;
}
.article-body ul,
.article-body ol {
  margin: 1rem 0 1.5rem;
  padding-left: 2rem;
}
.article-body li { margin-bottom: 0.5rem; }
.article-body hr {
  margin: 3rem 0;
  border: none;
  height: 1px;
  background: var(--color-border-light);
}
.article-body iframe {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 0;
}

/* 视频嵌入：固定 16:9，不撑破版心 */
.video-embed {
  position: relative;
  margin: 1.5rem 0;
  padding-top: 56.25%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
}
.video-embed iframe,
.video-embed video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* 脚注 */
.article-body .footnote {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- 上一篇 / 下一篇 ---------- */
.article-nav {
  max-width: 720px;
  margin: 3rem auto 0;
  padding: 2rem 1rem 0;
  border-top: 1px solid var(--color-border-light);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.article-nav a,
.article-nav .nav-empty {
  display: block;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  text-decoration: none;
  transition: all 0.2s ease;
}
.article-nav a:hover {
  border-color: var(--color-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.article-nav .nav-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}
.article-nav .nav-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  transition: color 0.15s;
}
.article-nav a:hover .nav-title { color: var(--color-accent); }
.article-nav .nav-prev { text-align: left; }
.article-nav .nav-next { text-align: right; }
.article-nav .nav-empty {
  border-style: dashed;
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- 最近文章 ---------- */
.recent-bar {
  max-width: 720px;
  margin: 4rem auto 0;
  padding: 2rem 1rem;
}
.recent-bar h4 {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
.recent-bar ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.recent-bar ul a {
  display: block;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  transition: all 0.2s ease;
  text-decoration: none;
}
.recent-bar ul a:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.recent-bar ul a .date {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 400;
  margin-top: 0.25rem;
}

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .article-wrap { padding: calc(var(--nav-height, 60px) + 1rem) 1rem 2rem; }
  .article-header { margin-bottom: 2rem; padding-bottom: 1.5rem; }
  .article-header h1 { font-size: 1.5rem; }
  .article-meta { gap: .6rem; font-size: var(--text-xs); }
  .article-body { font-size: var(--text-base); }
  .article-body h2 { font-size: 1.2rem; }
  .article-body h3 { font-size: 1.05rem; }
  .article-body p { margin-bottom: 1rem; }
  .article-body pre {
    margin-left: -1rem;
    margin-right: -1rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    font-size: var(--text-xs);
  }
  .article-body .highlight {
    margin-left: -1rem;
    margin-right: -1rem;
    border-radius: 0;
  }
  .article-body blockquote { margin-left: -1rem; margin-right: -1rem; border-radius: 0; }
  .article-nav { grid-template-columns: 1fr; }
  .recent-bar ul { grid-template-columns: 1fr; }
  .toc-panel { min-width: min(320px, calc(100vw - 2rem)); }
}
