/* ============================================================
   版本 B — 暖纸质感
   风格：米白底色，暖灰边栏，Notion/Bear 阅读体验
   字体：Lora (标题) + 苹方/PingFang (正文)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --sidebar-width: 268px;
  --topbar-height: 54px;

  --bg: #faf8f5;
  --bg-secondary: #f3f0eb;
  --bg-sidebar: #f0ede8;
  --border: #e2ddd7;
  --border-strong: #c8c0b5;
  --text: #2d2926;
  --text-secondary: #6b6460;
  --text-muted: #b0a89e;
  --accent: #c0622a;
  --accent-hover: #a3521f;
  --code-bg: #ede9e3;
  --code-border: #ddd8d0;
  --inline-code-bg: #fde8d8;
  --inline-code-color: #b85c28;
  --inline-ref-bg: #ddeef8;
  --inline-ref-color: #2a6496;
  --heading-color: #1a1714;
  --link-color: #c0622a;
  --active-bg: #fde8d8;
  --active-color: #b85c28;
  --hover-bg: #e8e3dc;
  --shadow: 0 1px 4px rgba(60,40,20,0.06);
  --shadow-md: 0 6px 24px rgba(60,40,20,0.12);
}

[data-theme="dark"] {
  --bg: #1c1a17;
  --bg-secondary: #232018;
  --bg-sidebar: #201e1b;
  --border: #332e28;
  --border-strong: #5a5248;
  --text: #e8e0d5;
  --text-secondary: #9a9088;
  --text-muted: #5a5248;
  --accent: #e07840;
  --accent-hover: #f08850;
  --code-bg: #252219;
  --code-border: #332e28;
  --inline-code-bg: #3a2518;
  --inline-code-color: #e07840;
  --inline-ref-bg: #182030;
  --inline-ref-color: #6aaddd;
  --heading-color: #f0e8dc;
  --link-color: #e07840;
  --active-bg: #3a2518;
  --active-color: #e07840;
  --hover-bg: #2a2620;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* 消除 iOS Safari 默认 tap 高亮，用自定义 :active 替代 */
a, button, [role="button"], .toc-item, .welcome-ch, .welcome-card {
  -webkit-tap-highlight-color: transparent;
}

html { font-size: 16px; scroll-behavior: smooth; }

/* ===== 文字选中色 ===== */
::selection {
  background-color: rgba(192, 98, 42, 0.18);
  color: var(--heading-color);
}
[data-theme="dark"] ::selection {
  background-color: rgba(224, 120, 64, 0.25);
}

body {
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  transition: background 0.2s, color 0.2s;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* 防止代码块负边距产生页面级横向滚动条 */
}

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 1;
}

/* Brand 链接：Logo + 书名，整体可点击 */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  border-radius: 8px;
  padding: 6px 6px;
  margin: -6px -6px;
  transition: background 0.15s;
}

.sidebar-brand:hover {
  background: var(--hover-bg);
}

.brand-logo {
  flex-shrink: 0;
  line-height: 0;
}

.brand-logo svg rect {
  transition: fill 0.15s;
}

.sidebar-brand:hover .brand-logo svg rect {
  fill: var(--accent-hover);
}

.brand-text {
  min-width: 0;
}

.book-title {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.04em;
}

/* Topbar 首页按钮 */
.topbar-home {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
}

.topbar-home:hover {
  color: var(--text);
  background: var(--hover-bg);
}

/* TOC */
.toc { padding: 10px 0 28px; flex: 1; }

.toc-item {
  display: block;
  padding: 7px 22px;
  font-size: 13.5px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  border-left: 3px solid transparent;
  line-height: 1.45;
  user-select: none;
  border-radius: 0 6px 6px 0;
  margin-right: 8px;
}

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

.toc-item.active {
  background: var(--active-bg);
  color: var(--active-color);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-chapter-num {
  font-size: 10.5px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 1px;
  font-family: 'JetBrains Mono', monospace;
}

/* 通俗版 / 技术版分区标签 */
.toc-section-label {
  padding: 10px 22px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
}
.toc-section-label-tech {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* 通俗版条目：香槟金 */
.toc-item-easy.active {
  background: #f5f0e8;
  color: #5c4a28;
  border-left-color: #b49b64;
}
[data-theme="dark"] .toc-item-easy.active {
  background: #2a2318;
  color: #d4b87a;
  border-left-color: #8a7248;
}

/* 通俗版文章顶部 badge：不显示 */
.easy-mode-badge {
  display: none;
}

/* Main */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 40px;
  gap: 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
  box-shadow: var(--shadow);
}

.menu-btn {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: 0.2s;
}

.topbar-title {
  font-size: 13.5px;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* 左侧竖线分隔 */
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

.topbar-actions { display: flex; gap: 8px; }

.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}

.theme-btn:hover { background: var(--hover-bg); color: var(--text); }

/* Content */
.content { flex: 1; }

.content-inner {
  max-width: 740px;
  margin: 0 auto;
  padding: 56px 44px 96px;
}

/* Welcome */
.welcome { padding: 0; }

/* 欢迎页顶部不需要大段留白 */
#content-inner:has(.welcome) {
  padding-top: 20px;
}

.welcome h1 {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--heading-color);
  margin-bottom: 18px;
  line-height: 1.3;
}

.welcome p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* Markdown */
.md-body {
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--text);
}

.md-body h1 {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--heading-color);
  margin: 0 0 28px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
  word-break: break-word;
  overflow-wrap: break-word;
}

.md-body h2 {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 21px;
  font-weight: 500;
  color: var(--heading-color);
  margin: 48px 0 16px;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: break-word;
}

.md-body h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--heading-color);
  margin: 32px 0 12px;
}

.md-body h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 22px 0 8px;
}

.md-body p { margin: 0 0 18px; overflow-wrap: break-word; word-break: break-word; }

.md-body a {
  color: var(--link-color);
  text-decoration: none;
  border-bottom: 1px solid rgba(192, 98, 42, 0.3);
  transition: border-color 0.15s;
}

.md-body a:hover { border-bottom-color: var(--accent); }

.md-body code {
  font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  font-size: 12.5px;
  background: var(--inline-code-bg);
  color: var(--inline-code-color);
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid rgba(192, 98, 42, 0.15);
}

.md-body a code {
  background: var(--inline-ref-bg);
  color: var(--inline-ref-color);
  border-color: rgba(42, 100, 150, 0.15);
}

.md-body pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 22px;
  overflow-x: auto;
  margin: 22px 0;
  position: relative;
}

.md-body pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
  font-size: 13px;
  line-height: 1.65;
}

.code-lang-label {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* 代码块复制按钮 */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s, border-color 0.15s;
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  color: var(--text);
  background: var(--bg-secondary);
  border-color: var(--border);
}

.code-copy-btn.copied {
  color: #22863a;
  opacity: 1;
}

[data-theme="dark"] .code-copy-btn.copied {
  color: #aff5b4;
}

.md-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 24px 0;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.md-body blockquote p { margin: 0; }

.md-body ul, .md-body ol { margin: 12px 0 18px 26px; }
.md-body li { margin-bottom: 7px; }
.md-body li > ul, .md-body li > ol { margin-top: 4px; margin-bottom: 4px; }

.md-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 22px 0;
  font-size: 14px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.md-body th {
  background: var(--bg-secondary);
  font-weight: 600;
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--heading-color);
  font-size: 13px;
}

.md-body td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.md-body tr:last-child td { border-bottom: none; }

.md-body hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-strong), transparent);
  margin: 36px 0;
}

.md-body strong { font-weight: 700; color: var(--heading-color); }

.md-body .mermaid {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  margin: 22px 0;
  text-align: center;
  overflow-x: auto;
  cursor: zoom-in;
  transition: box-shadow 0.18s, border-color 0.18s;
  position: relative;
}

.md-body .mermaid:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192, 98, 42, 0.12);
}

/* 放大提示角标 */
.md-body .mermaid::after {
  content: '⤢';
  position: absolute;
  bottom: 8px;
  right: 10px;
  font-size: 14px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.md-body .mermaid:hover::after {
  opacity: 1;
}

/* ===== Mermaid Lightbox ===== */
@keyframes lb-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes lb-scale-in {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes lb-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.mermaid-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: lb-fade-in 0.2s ease both;
}

.mermaid-lightbox.lb-closing {
  animation: lb-fade-out 0.18s ease both;
}

.mermaid-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.mermaid-lightbox-content {
  position: relative;
  z-index: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(90vw, 960px);
  max-width: min(90vw, 960px);
  height: min(85vh, 800px);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4);
  animation: lb-scale-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.mermaid-lightbox-content.lb-dragging {
  cursor: grabbing;
}

.mermaid-lightbox.lb-closing .mermaid-lightbox-content {
  animation: lb-fade-out 0.18s ease both;
}

/* 缩放容器：transform 作用在这里，不影响 close 按钮 */
.mermaid-lb-zoom {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  box-sizing: border-box;
  transform-origin: center center;
  will-change: transform;
}

.mermaid-lb-zoom svg {
  max-width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
}

/* 缩放提示 */
.mermaid-lb-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  pointer-events: none;
  white-space: nowrap;
}

/* 缩放比例指示器 */
.mermaid-lb-scale {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.mermaid-lb-scale.visible {
  opacity: 0.7;
}

.mermaid-lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--hover-bg);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  z-index: 10; /* 确保在 lb-zoom 拖拽层之上 */
  -webkit-tap-highlight-color: transparent;
}

.mermaid-lightbox-close:hover {
  background: var(--border-strong);
  color: var(--text);
}

@media (max-width: 768px) {
  .mermaid-lightbox { padding: 8px; }
  .mermaid-lightbox-content { border-radius: 10px; width: 96vw; height: 80vh; }
  .mermaid-lb-zoom { padding: 16px; }
  .mermaid-lb-hint { display: none; }
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 22px 44px;
  background: var(--bg);
}

.footer-nav {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

.nav-btn:hover {
  background: var(--hover-bg);
  color: var(--text);
  border-color: var(--accent);
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-muted);
  font-size: 14px;
  gap: 10px;
}

.loading::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  padding: 20px 24px;
  background: #fef3ee;
  border: 1px solid #f5c9a8;
  border-radius: 8px;
  color: #b85c28;
  font-size: 14px;
  margin: 40px 0;
}

[data-theme="dark"] .error-msg {
  background: #2d1a0e;
  border-color: #5a3020;
  color: #e07840;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

/* ===== Content Transition ===== */
/* Fade-out: content slides up slightly and fades */
.content-leaving {
  animation: contentLeave 0.15s ease-in forwards;
  pointer-events: none;
}

/* Fade-in: content slides up from slightly below and fades in */
.content-entering {
  animation: contentEnter 0.28s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes contentLeave {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

@keyframes contentEnter {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== TOC item transitions ===== */
/* border-left indicator slides smoothly */
.toc-item {
  transition: background 0.18s ease, color 0.18s ease,
              border-left-color 0.18s ease, padding-left 0.18s ease;
}

/* Active item gets a subtle left-padding nudge */
.toc-item.active {
  padding-left: 26px;
}

/* 手机端 toc-item 点击态 */
.toc-item:active {
  background: var(--hover-bg);
  transform: scale(0.98);
  transition: background 0s, transform 0.08s ease;
}

/* ===== Topbar title fade on chapter change ===== */
#topbar-title {
  transition: opacity 0.2s ease;
}

/* ===== Theme button smooth icon swap ===== */
.theme-btn {
  transition: color 0.2s ease, border-color 0.2s ease,
              background 0.2s ease, transform 0.15s ease;
}

.theme-btn:active {
  transform: scale(0.92);
}

/* welcome-start 按钮点击态 */
.welcome-start:active {
  transform: scale(0.97);
  background: var(--accent-hover);
  transition: transform 0.08s ease, background 0s;
}

/* welcome-ch 点击态 */
.welcome-ch:active {
  background: var(--hover-bg);
  border-color: var(--border);
  transform: scale(0.98);
  transition: transform 0.08s ease, background 0s;
}

/* welcome-card 点击态 */
.welcome-card:active {
  transform: scale(0.99);
  transition: transform 0.08s ease;
}

/* ===== Nav buttons ===== */
.nav-btn {
  transition: background 0.18s ease, color 0.18s ease,
              border-color 0.18s ease, transform 0.12s ease;
}

.nav-btn:active {
  transform: scale(0.97);
}

/* ===== Sidebar header subtle separator ===== */
.sidebar-header {
  transition: box-shadow 0.2s ease;
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.hljs { background: transparent !important; padding: 0 !important; }

/* ===== 响应式：平板 ===== */
@media (max-width: 900px) {
  :root { --sidebar-width: 240px; }
  .content-inner { padding: 48px 32px 80px; }
}

/* ===== 响应式：手机 ===== */
@media (max-width: 768px) {
  /* 侧边栏：抽屉式 */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .overlay.show { display: block; }
  .main-wrapper { margin-left: 0; }
  .menu-btn { display: flex; }

  /* Topbar */
  .topbar { padding: 0 16px; gap: 8px; }
  .topbar-home { display: none; } /* 手机上隐藏首页文字按钮，节省空间 */
  .topbar-title { font-size: 12.5px; padding-left: 10px; }
  .star-btn { display: none !important; } /* 手机隐藏 Star 按钮 */

  /* 内容区 */
  .content-inner { padding: 28px 18px 72px; }
  .footer { padding: 16px 18px; }

  /* 标题缩放 */
  .md-body h1 { font-size: 22px; margin-bottom: 20px; }
  .md-body h2 { font-size: 18px; margin-top: 36px; }
  .md-body h3 { font-size: 15.5px; }
  .md-body { font-size: 15px; }

  /* 代码块：手机上去掉圆角和左右边框，内部横向滚动 */
  .md-body pre {
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 14px 0;
    margin: 16px -18px;
    max-width: 100vw;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .md-body pre code { font-size: 12px; }
  .line-num { width: 34px; padding: 0 8px 0 12px; font-size: 11px; }
  .line-content { padding-right: 14px; }
  .code-lang-label { display: none; } /* 手机上隐藏语言标签，避免被截断 */

  /* 表格：横向滚动容器 */
  .md-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }
  .md-body th, .md-body td { padding: 8px 12px; white-space: nowrap; }

  /* 欢迎页 */
  .welcome { padding: 20px 0 40px; max-width: 100%; }
  .welcome h1 { font-size: 26px; }
  .welcome-subtitle { font-size: 16px; }
  .welcome-desc { font-size: 14.5px; }
  .welcome-chapters { grid-template-columns: 1fr 1fr; gap: 4px; }
  .welcome-ch { padding: 6px 10px; }
  .welcome-ch-title { font-size: 12.5px; }
  .welcome-actions { flex-wrap: wrap; }

  /* 手机端卡片：单列，隐藏章节列表（太长） */
  .welcome-cards { grid-template-columns: 1fr; gap: 12px; }
  /* welcome-card-chapters 隐藏规则已移至定义之后的 @media 块，此处无需重复 */
  .welcome-card { padding: 16px 18px; }

  /* 手机端 toc-item active 不做 padding 位移（避免抖动） */
  .toc-item.active { padding-left: 22px; }

  /* 章节骨架 */
  .chapter-skeleton { padding: 32px 0 60px; }
  .sk-title-text { font-size: 24px; }

  /* 底部导航 */
  .footer-nav { gap: 8px; }
  .nav-btn { font-size: 12.5px; padding: 7px 12px; }

  /* 锚点面板：手机上全宽底部弹出 */
  .anchor-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-height: 55vh;
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform-origin: bottom center;
    animation: ap-slide-up 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .anchor-panel.ap-hiding {
    animation: ap-slide-down 0.18s ease both;
  }
  .ap-body { max-height: calc(55vh - 44px); }
  .ap-code { font-size: 12px; }
  .ap-lnum { width: 36px; padding: 0 8px 0 10px; font-size: 11px; }
}

/* ===== 响应式：小屏手机 ===== */
@media (max-width: 480px) {
  .content-inner { padding: 22px 14px 64px; }
  .topbar { padding: 0 12px; }
  .welcome h1 { font-size: 22px; }
  .welcome-chapters { grid-template-columns: 1fr; }
  .welcome-meta { flex-wrap: wrap; gap: 4px; }
  .md-body pre { margin: 14px -14px; }
  .md-body h1 { font-size: 20px; }
  .md-body h2 { font-size: 17px; }
}

/* ===== Chapter Loading Skeleton ===== */
@keyframes sk-shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}

@keyframes sk-cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes sk-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chapter-skeleton {
  padding: 48px 0 80px;
  max-width: 680px;
  animation: sk-fade-in 0.2s ease both;
}

/* 章节编号 */
.sk-chapter-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  opacity: 0.7;
}

/* 标题 + 光标 */
.sk-title {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-bottom: 28px;
}

.sk-title-text {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--heading-color);
  opacity: 0.18;
  letter-spacing: -0.02em;
}

.sk-cursor {
  display: inline-block;
  width: 2px;
  height: 34px;
  background: var(--accent);
  border-radius: 1px;
  animation: sk-cursor-blink 0.9s ease-in-out infinite;
  flex-shrink: 0;
  margin-bottom: -4px;
}

/* 分割线 */
.sk-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 28px;
  opacity: 0.6;
}

/* 骨架行公共 shimmer */
.sk-line,
.sk-code-line {
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 0%,
    var(--border) 40%,
    var(--bg-secondary) 80%
  );
  background-size: 600px 100%;
  animation: sk-shimmer 1.6s ease-in-out infinite;
}

/* 正文骨架行 */
.sk-lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sk-line {
  height: 14px;
}

.sk-line-gap {
  margin-bottom: 8px;
}

/* 代码块骨架 */
.sk-code-block {
  margin: 24px 0;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 8px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sk-code-line {
  height: 12px;
  border-radius: 3px;
  /* 代码块内用稍深的 shimmer */
  background: linear-gradient(
    90deg,
    var(--code-border) 0%,
    var(--border-strong) 40%,
    var(--code-border) 80%
  );
  background-size: 600px 100%;
  animation: sk-shimmer 1.6s ease-in-out infinite;
}

/* 各行错开动画相位，更自然 */
.sk-line:nth-child(1)  { animation-delay: 0s; }
.sk-line:nth-child(2)  { animation-delay: 0.08s; }
.sk-line:nth-child(3)  { animation-delay: 0.16s; }
.sk-line:nth-child(4)  { animation-delay: 0.24s; }
.sk-line:nth-child(5)  { animation-delay: 0.32s; }
.sk-line:nth-child(6)  { animation-delay: 0.40s; }
.sk-line:nth-child(7)  { animation-delay: 0.48s; }
.sk-line:nth-child(8)  { animation-delay: 0.56s; }
.sk-line:nth-child(9)  { animation-delay: 0.64s; }
.sk-line:nth-child(10) { animation-delay: 0.72s; }
.sk-line:nth-child(11) { animation-delay: 0.80s; }
.sk-line:nth-child(12) { animation-delay: 0.88s; }
.sk-line:nth-child(13) { animation-delay: 0.96s; }

.sk-code-line:nth-child(1) { animation-delay: 0.1s; }
.sk-code-line:nth-child(2) { animation-delay: 0.2s; }
.sk-code-line:nth-child(3) { animation-delay: 0.3s; }
.sk-code-line:nth-child(4) { animation-delay: 0.4s; }
.sk-code-line:nth-child(5) { animation-delay: 0.5s; }

@media print {
  .sidebar, .topbar, .footer { display: none; }
  .main-wrapper { margin-left: 0; }
  .content-inner { padding: 0; max-width: 100%; }
}

/* ===== Welcome Page ===== */
.welcome {
  padding: 0 0 60px;
  max-width: 680px;
}

.welcome-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--active-bg);
  border: 1px solid rgba(192,98,42,0.2);
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 20px;
  font-family: 'JetBrains Mono', monospace;
}

.welcome h1 {
  font-family: 'Lora', 'Noto Serif SC', serif;
  font-size: 38px;
  font-weight: 600;
  color: var(--heading-color);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.welcome-subtitle {
  font-family: 'Lora', serif;
  font-size: 20px;
  font-weight: 400;
  color: var(--text-muted);
  margin-bottom: 20px;
  font-style: italic;
}

.welcome-desc {
  font-size: 15.5px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 16px;
}

.welcome-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 36px;
  font-family: 'JetBrains Mono', monospace;
}

.welcome-chapters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
  margin-bottom: 36px;
}

.welcome-ch {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.welcome-ch:hover {
  background: var(--hover-bg);
  border-color: var(--border);
}

.welcome-ch-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.welcome-ch-title {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.welcome-ch:hover .welcome-ch-title {
  color: var(--text);
}

.welcome-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.welcome-start {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.welcome-start:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.welcome-github {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.welcome-github:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--hover-bg);
}

/* ===== Welcome Cards (入口卡片) ===== */
.welcome-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 28px;
}

.welcome-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 18px 20px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
  background: var(--bg-secondary);
}

.welcome-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.welcome-card-easy:hover {
  border-color: #b49b64;
}

.welcome-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.welcome-card-icon {
  flex-shrink: 0;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.welcome-card-easy .welcome-card-icon {
  color: #b49b64;
}

.welcome-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--heading-color);
  line-height: 1.3;
}

.welcome-card-easy .welcome-card-title {
  color: #8a7040;
}

[data-theme="dark"] .welcome-card-easy .welcome-card-title {
  color: #c4a85a;
}

.welcome-card-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

.welcome-card-chapters {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 2px;
}

/* 手机端隐藏卡片内章节列表（必须在定义之后，否则被覆盖） */
@media (max-width: 768px) {
  .welcome-card-chapters { display: none; }
}

.welcome-card-chapters .welcome-ch {
  padding: 4px 6px;
  border-radius: 4px;
}

@media (max-width: 640px) {
  .welcome-cards {
    grid-template-columns: 1fr;
  }
}

/* ===== GitHub Star Button (topbar) ===== */
/* ===== Share Button ===== */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  background: none;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

.share-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--active-bg);
}

.share-btn:active {
  transform: scale(0.95);
  transition: transform 0.08s ease;
}

/* 手机端只显示图标，不显示文字 */
@media (max-width: 768px) {
  .share-btn-label { display: none; }
  .share-btn { padding: 4px 8px; }
}

/* 复制成功 toast */
.share-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
  white-space: nowrap;
}

.share-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.star-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  transition: all 0.15s;
  font-weight: 500;
}

.star-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--active-bg);
}

/* ===== Code Block Line Numbers ===== */
.code-block {
  counter-reset: line;
  padding: 20px 0 !important;
}

.code-block .code-lang-label {
  right: 44px; /* 为复制按钮留出空间 */
  top: 10px;
}

.code-block code {
  display: block;
  padding: 0 !important;
}

.code-line {
  display: flex;
  line-height: 1.65;
  min-height: 1.65em;
}

.code-line:hover {
  background: rgba(192, 98, 42, 0.06);
}

[data-theme="dark"] .code-line:hover {
  background: rgba(224, 120, 64, 0.08);
}

.line-num {
  flex-shrink: 0;
  width: 44px;
  padding: 0 16px 0 20px;
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
  border-right: 1px solid var(--code-border);
  margin-right: 16px;
  opacity: 0.5;
}

.line-content {
  flex: 1;
  padding-right: 20px;
  white-space: pre;
}

/* ===== Source Anchor Inline Code ===== */
.md-body code.code-anchor {
  cursor: pointer;
  background: var(--inline-ref-bg);
  color: var(--inline-ref-color);
  border-color: rgba(42, 100, 150, 0.2);
  border-bottom: 1px dashed var(--inline-ref-color);
  transition: background 0.15s, box-shadow 0.15s;
}

.md-body code.code-anchor:hover {
  background: #c8e4f8;
}

.md-body code.code-anchor.active {
  background: #b8d8f0;
  box-shadow: 0 0 0 2px rgba(42, 100, 150, 0.25);
}

[data-theme="dark"] .md-body code.code-anchor:hover {
  background: #1e3a50;
}

[data-theme="dark"] .md-body code.code-anchor.active {
  background: #1a3348;
  box-shadow: 0 0 0 2px rgba(106, 173, 221, 0.3);
}

/* ===== Anchor Panel (内联代码预览) ===== */
@keyframes ap-expand {
  from { opacity: 0; transform: translateY(-4px) scaleY(0.96); }
  to   { opacity: 1; transform: translateY(0) scaleY(1); }
}

@keyframes ap-collapse {
  from { opacity: 1; transform: translateY(0) scaleY(1); }
  to   { opacity: 0; transform: translateY(-4px) scaleY(0.96); }
}

/* 手机端：底部滑入/滑出 */
@keyframes ap-slide-up {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ap-slide-down {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(100%); }
}

@keyframes ap-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

@keyframes ap-body-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.anchor-panel {
  position: fixed;
  z-index: 2000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #2e2e2e;
  background: #1c1c1c;
  color: #abb2bf; /* 面板始终深色背景，强制浅色默认文字 */
  box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  animation: ap-expand 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
  transform-origin: top left;
  /* width 由 JS positionPanel 动态设置 */
}

.anchor-panel.ap-hiding {
  animation: ap-collapse 0.16s ease both;
}

/* Header */
.ap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: #242424;
  border-bottom: 1px solid #2e2e2e;
  gap: 10px;
}

.ap-filepath {
  font-size: 12px;
  color: #7dd3fc;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.ap-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.ap-lang {
  font-size: 11px;
  color: #666;
  padding: 1px 7px;
  border: 1px solid #333;
  border-radius: 4px;
  margin-right: 4px;
  letter-spacing: 0.02em;
}

.ap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #666;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  line-height: 1;
}

.ap-btn:hover {
  background: #333;
  color: #bbb;
}

.ap-github:hover {
  background: #1a2e40;
  color: #7dd3fc;
}

/* Body */
.ap-body {
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
  background: #1c1c1c;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
  transition: opacity 0.15s;
}

.ap-body.ap-body-fade {
  animation: ap-body-fade-out 0.15s ease both;
}

.ap-body::-webkit-scrollbar { width: 5px; height: 5px; }
.ap-body::-webkit-scrollbar-track { background: transparent; }
.ap-body::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 3px; }

/* Loading shimmer skeleton */
.ap-loading {
  padding: 14px 16px 16px;
}

.ap-sk-lines {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ap-sk-line {
  height: 12px;
  border-radius: 3px;
  width: 100%;
  background: linear-gradient(90deg, #2a2a2a 0%, #383838 45%, #2a2a2a 90%);
  background-size: 400px 100%;
  animation: ap-shimmer 1.4s ease-in-out infinite;
}

.ap-sk-line:nth-child(1) { animation-delay: 0s; }
.ap-sk-line:nth-child(2) { animation-delay: 0.07s; }
.ap-sk-line:nth-child(3) { animation-delay: 0.14s; }
.ap-sk-line:nth-child(4) { animation-delay: 0.21s; }
.ap-sk-line:nth-child(5) { animation-delay: 0.28s; }
.ap-sk-line:nth-child(6) { animation-delay: 0.35s; }
.ap-sk-line:nth-child(7) { animation-delay: 0.42s; }

/* 目标行骨架高亮 */
.ap-sk-target {
  width: 100% !important;
  background: linear-gradient(90deg, #1e3040 0%, #2a4a60 45%, #1e3040 90%);
  background-size: 400px 100%;
  animation: ap-shimmer 1.4s ease-in-out infinite;
  box-shadow: inset 2px 0 0 #7dd3fc;
}

/* Error */
.ap-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  color: #f87171;
  font-size: 12px;
  padding: 0 16px;
}

/* Code */
.ap-code {
  display: block;
  padding: 10px 0;
  background: transparent !important;
  font-size: 12.5px;
  line-height: 1.65;
}

.ap-line {
  display: flex;
  align-items: stretch;
  min-height: 1.65em;
  transition: background 0.1s;
}

.ap-line:hover {
  background: rgba(255,255,255,0.035);
}

.ap-line-target {
  background: rgba(125, 211, 252, 0.09) !important;
  box-shadow: inset 2px 0 0 #7dd3fc;
}

.ap-line-target:hover {
  background: rgba(125, 211, 252, 0.13) !important;
}

.ap-lnum {
  flex-shrink: 0;
  width: 46px;
  padding: 0 12px 0 16px;
  text-align: right;
  color: #4a4a4a;
  font-size: 11.5px;
  user-select: none;
  border-right: 1px solid #2a2a2a;
  margin-right: 14px;
}

.ap-line-target .ap-lnum {
  color: #7dd3fc;
}

.ap-lcode {
  flex: 1;
  padding-right: 20px;
  white-space: pre;
  color: #abb2bf; /* 非 token 文字的默认颜色，hljs token 会覆盖 */
}

/* 面板 hljs 高亮主题由 index.html 的 #ap-hljs-theme <style> 标签统一管理 */

/* ===== 纸质噪点纹理（预渲染 PNG，无运行时滤镜开销）===== */
.texture-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background-image: url('./noise.png');
  background-repeat: repeat;
  background-size: 128px 128px;
  opacity: 0.035;
  mix-blend-mode: multiply;
  transform: translateZ(0);
}
[data-theme="dark"] .texture-overlay {
  opacity: 0.05;
  mix-blend-mode: screen;
}

/* ===== TOC 封面章节卡片图片 hover 缩放 ===== */
.welcome-ch {
  overflow: hidden;
}
.welcome-ch:hover .welcome-ch-title {
  transform: translateX(3px);
  transition: transform 0.2s ease;
}
.welcome-ch-title {
  transition: transform 0.2s ease;
}
