/* ===================================================================
 * v2 Design System — shadcn-inspired 改版
 * ===================================================================
 * 设计目标：
 *  - shadcn/ui 风格（中性灰 + 单一强调色 + 微圆角 + 大量留白）
 *  - 字体：标题 Inter 700/900 + 正文 Noto Sans SC 400/500 + 代码 JetBrains Mono
 *  - 暗色模式原生支持（[data-theme="dark"]）
 *  - 微动效：hover 浮起 + 按下回弹 + 进度过渡
 *  - 4/8/12/16/24/32/48/64 spacing scale
 *  - 0/1/2/4/6/8/12/16/24/32/48/64 shadow scale
 *
 * 策略：v2 不删 v1 任何样式（css/style.css 仍保留），而是用更高的选择器特异性
 *  和新 class（带 v2- 前缀）做覆盖，git revert 即可回退
 * =================================================================== */

/* ===== Design Tokens (Light) ===== */
:root,
[data-theme="light"] {
  --v2-bg: #FAFAFA;
  --v2-bg-elevated: #FFFFFF;
  --v2-bg-subtle: #F4F4F5;
  --v2-bg-muted: #F4F4F5;

  --v2-fg: #0A0A0A;
  --v2-fg-secondary: #3F3F46;
  --v2-fg-muted: #71717A;
  --v2-fg-subtle: #A1A1AA;

  --v2-border: #E4E4E7;
  --v2-border-strong: #D4D4D8;
  --v2-ring: #18181B;

  --v2-accent: #DC2626;        /* 医学警示红 = P<0.05 / 显著 */
  --v2-accent-fg: #FFFFFF;
  --v2-accent-subtle: #FEE2E2;

  --v2-primary: #18181B;       /* 主色 = 近黑（shadcn 风格） */
  --v2-primary-fg: #FAFAFA;
  --v2-primary-subtle: #F4F4F5;

  --v2-secondary: #6366F1;     /* 次强调 = 靛蓝（学习路径/章节） */
  --v2-secondary-subtle: #EEF2FF;

  --v2-success: #10B981;        /* 完成/已学 */
  --v2-warning: #F59E0B;
  --v2-info: #0EA5E9;

  --v2-radius: 10px;
  --v2-radius-sm: 6px;
  --v2-radius-lg: 14px;
  --v2-radius-xl: 20px;
  --v2-radius-full: 9999px;

  --v2-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --v2-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --v2-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --v2-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --v2-shadow-glow: 0 0 0 4px rgba(220, 38, 38, 0.08);

  --v2-font-sans: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --v2-font-serif: "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --v2-font-mono: "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;

  --v2-sidebar-width: 268px;
  --v2-topbar-height: 56px;
}

/* ===== Design Tokens (Dark) ===== */
[data-theme="dark"] {
  --v2-bg: #09090B;
  --v2-bg-elevated: #18181B;
  --v2-bg-subtle: #1C1C1F;
  --v2-bg-muted: #27272A;

  --v2-fg: #FAFAFA;
  --v2-fg-secondary: #D4D4D8;
  --v2-fg-muted: #A1A1AA;
  --v2-fg-subtle: #71717A;

  --v2-border: #3F3F46;          /* 加深: 暗背景下 chip 边框更明显 */
  --v2-border-strong: #52525B;
  --v2-ring: #FAFAFA;

  --v2-accent: #F87171;
  --v2-accent-fg: #09090B;
  --v2-accent-subtle: #450A0A;

  --v2-primary: #FAFAFA;
  --v2-primary-fg: #18181B;
  --v2-primary-subtle: #27272A;

  --v2-secondary: #818CF8;
  --v2-secondary-subtle: #1E1B4B;

  --v2-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --v2-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --v2-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --v2-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --v2-shadow-glow: 0 0 0 4px rgba(248, 113, 113, 0.15);
}

/* ===== Reset (只影响 v2 class 范围内的元素) ===== */
body.v2-active {
  font-family: var(--v2-font-sans);
  background: var(--v2-bg);
  color: var(--v2-fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
  transition: background 0.2s ease, color 0.2s ease;
}

body.v2-active * {
  border-color: var(--v2-border);
}

/* ===== App layout ===== */
body.v2-active #app {
  display: grid;
  grid-template-columns: var(--v2-sidebar-width) 1fr;
  min-height: 100vh;
  background: var(--v2-bg);
}

/* ===== Sidebar v2 ===== */
body.v2-active #sidebar {
  background: var(--v2-bg-elevated);
  border-right: 1px solid var(--v2-border);
  width: var(--v2-sidebar-width);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.v2-active .sidebar-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--v2-border);
}

body.v2-active .sidebar-header h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--v2-fg);
  margin: 0 0 4px 0;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

body.v2-active .sidebar-header .subtitle {
  font-size: 0.72rem;
  color: var(--v2-fg-muted);
  font-weight: 500;
  margin: 0 0 12px 0;
}

body.v2-active .search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--v2-bg-subtle);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-sm);
  color: var(--v2-fg);
  font-size: 0.85rem;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
}

body.v2-active .search-box input:focus {
  outline: none;
  border-color: var(--v2-ring);
  background: var(--v2-bg-elevated);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}

body.v2-active .search-box {
  position: relative;
}

body.v2-active .search-box::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  opacity: 0.5;
  pointer-events: none;
}

body.v2-active .search-result {
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-sm);
  margin-top: 4px;
  padding: 8px 12px;
}

/* nav */
body.v2-active #chapter-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

body.v2-active .nav-group {
  border-bottom: none;
  margin-bottom: 4px;
}

body.v2-active .v2-nav-label {
  font-family: var(--v2-font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--v2-fg-secondary);
  letter-spacing: -0.01em;
}

body.v2-active .nav-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--v2-radius-sm);
  transition: background 0.12s ease;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

body.v2-active .nav-group-header:hover {
  background: var(--v2-bg-subtle);
}

body.v2-active .nav-group-header:hover .v2-nav-label {
  color: var(--v2-fg);
}

body.v2-active .chapter-count {
  font-family: var(--v2-font-mono);
  font-size: 0.7rem;
  color: var(--v2-fg-muted);
  background: var(--v2-bg-subtle);
  padding: 1px 6px;
  border-radius: var(--v2-radius-full);
}

body.v2-active .nav-group-header:hover {
  background: var(--v2-bg-subtle);
  color: var(--v2-fg);
}

body.v2-active .nav-group-content {
  padding: 2px 0 6px 0;
}

body.v2-active .nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 24px;
  font-size: 0.83rem;
  color: var(--v2-fg-secondary);
  border-radius: var(--v2-radius-sm);
  margin: 1px 0;
  transition: all 0.12s ease;
  text-decoration: none;
}

body.v2-active .nav-item:hover {
  background: var(--v2-bg-subtle);
  color: var(--v2-fg);
}

body.v2-active .nav-item.active {
  background: var(--v2-primary);
  color: var(--v2-primary-fg);
  font-weight: 600;
}

/* v2 改版后 .chapter-link 是实际渲染的类（不是 .nav-item），
   v1.css 写了硬编码 rgba(255,255,255,0.7) 假设 sidebar 永远深色，
   light 模式下 v2 sidebar 变白 → 白字白底看不见。
   这里用 v2 token 覆盖两种模式都清晰。
   active 用 v1 一致的 #2563EB 蓝（保持用户视觉习惯）。 */
body.v2-active a.chapter-link {
  display: flex;
  align-items: center;
  width: calc(100% - 16px);
  margin: 0 8px;
  padding: 6px 12px 6px 16px;
  font-size: 0.83rem;
  color: var(--v2-fg-secondary);
  background: transparent;
  border-radius: var(--v2-radius-sm);
  gap: 8px;
  text-decoration: none;
  transition: all 0.12s ease;
}

body.v2-active a.chapter-link:hover {
  background: var(--v2-bg-subtle);
  color: var(--v2-fg);
}

body.v2-active a.chapter-link.active {
  background: #2563EB;
  color: #FFFFFF;
  font-weight: 600;
}

body.v2-active a.chapter-link .nav-num {
  font-family: var(--v2-font-mono);
  font-size: 0.7rem;
  color: var(--v2-fg-subtle);
  min-width: 20px;
}

body.v2-active a.chapter-link.active .nav-num {
  color: rgba(255, 255, 255, 0.85);
}

/* 修 light 模式分组标题看不见：v1.css 硬编码 #fff，light 模式 sidebar 变白 → 看不见 */
body.v2-active .nav-group-header {
  color: var(--v2-fg) !important;
  font-weight: 600;
}
body.v2-active .nav-group-header:hover {
  background: var(--v2-bg-subtle);
}
body.v2-active .nav-group-header::after {
  color: var(--v2-fg-muted);
}

/* 修 light 模式分组分割线看不见：v1.css rgba(255,255,255,0.06) 几乎透明 */
body.v2-active .nav-group {
  border-bottom: 1px solid var(--v2-border) !important;
}

body.v2-active .nav-group-header::after {
  content: "›";
  font-size: 1.1rem;
  color: var(--v2-fg-subtle);
  font-weight: 400;
  transition: transform 0.18s ease;
}

body.v2-active .nav-group-header[aria-expanded="true"]::after {
  transform: rotate(90deg);
}

/* ===== Sidebar footer (progress) v2 ===== */
body.v2-active .sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--v2-border);
  background: var(--v2-bg-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

body.v2-active .progress-ring-text {
  font-family: var(--v2-font-mono);
  letter-spacing: -0.02em;
}

body.v2-active .progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--v2-fg-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

body.v2-active #progress-text {
  font-family: var(--v2-font-mono);
  color: var(--v2-fg);
  font-weight: 600;
}

body.v2-active .progress-bar {
  height: 4px;
  background: var(--v2-border);
  border-radius: var(--v2-radius-full);
  overflow: hidden;
}

body.v2-active .last-chapter {
  font-size: 0.7rem;
  color: var(--v2-fg-muted);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.v2-active .btn-continue {
  margin-top: 8px;
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  background: var(--v2-primary);
  color: var(--v2-primary-fg);
  border: none;
  border-radius: var(--v2-radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
}

body.v2-active .btn-continue:hover {
  transform: translateY(-1px);
  box-shadow: var(--v2-shadow-md);
}

body.v2-active .btn-reset-progress {
  font-size: 0.72rem;
  min-height: 32px;
  padding: 8px 10px;
  margin-top: 6px;
  background: transparent;
  color: var(--v2-fg-secondary);
  border: none;
  cursor: pointer;
  text-align: left;
  align-self: flex-start;
  border-radius: var(--v2-radius-sm);
  transition: color 0.15s ease;
  font-family: var(--v2-font-sans);
}

body.v2-active .btn-reset-progress:hover {
  color: var(--v2-fg);
  background: var(--v2-bg-muted);
}

/* ===== Main content area v2 ===== */
body.v2-active #main-content {
  background: var(--v2-bg);
  min-height: 100vh;
}

body.v2-active #topbar {
  height: var(--v2-topbar-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--v2-border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

[data-theme="dark"] body.v2-active #topbar {
  background: rgba(9, 9, 11, 0.85);
}

body.v2-active #topbar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--v2-fg);
  flex: 1;
  letter-spacing: -0.01em;
}

body.v2-active #theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--v2-radius-sm);
  background: transparent;
  border: 1px solid var(--v2-border);
  color: var(--v2-fg);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

body.v2-active #theme-toggle:hover {
  background: var(--v2-bg-subtle);
  border-color: var(--v2-border-strong);
}

body.v2-active #home-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--v2-radius-sm);
  background: transparent;
  border: 1px solid var(--v2-border);
  color: var(--v2-fg);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  transition: all 0.15s ease;
}

body.v2-active #home-btn:hover {
  background: var(--v2-bg-subtle);
  border-color: var(--v2-border-strong);
}

/* ===== Welcome Hero v2 ===== */
body.v2-active .welcome-hero {
  padding: 56px 40px 24px;
  max-width: 1280px;
  margin: 0 auto;
}

body.v2-active .welcome-hero h1 {
  font-family: var(--v2-font-sans);
  font-size: clamp(2rem, 3.5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
  color: var(--v2-fg);
  margin: 0 0 16px 0;
}

body.v2-active .welcome-hero .lead {
  font-size: 1.05rem;
  color: var(--v2-fg-secondary);
  line-height: 1.55;
  margin: 0 0 12px 0;
  max-width: 560px;
}

body.v2-active .welcome-hero .lead-sub.v2-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 28px 0;
}

body.v2-active .welcome-hero .lead-sub .v2-keyword-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-full);
  font-size: 0.78rem;
  color: var(--v2-fg-secondary);
  font-weight: 500;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
  cursor: default;
}

body.v2-active .welcome-hero .lead-sub .v2-keyword-pill:hover {
  border-color: var(--v2-secondary);
  color: var(--v2-secondary);
  transform: translateY(-1px);
}

body.v2-active .welcome-cta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

body.v2-active .welcome-cta .btn-primary,
body.v2-active .welcome-cta button.v2-btn-primary {
  background: var(--v2-primary);
  color: var(--v2-primary-fg);
  border: 1px solid var(--v2-primary);
}

body.v2-active .welcome-cta .btn-secondary,
body.v2-active .welcome-cta button.v2-btn-secondary {
  background: var(--v2-bg-elevated);
  color: var(--v2-fg);
  border: 1px solid var(--v2-border);
}

body.v2-active .welcome-cta .btn-ghost,
body.v2-active .welcome-cta button.v2-btn-ghost {
  background: transparent;
  color: var(--v2-fg-secondary);
  border: 1px solid transparent;
}

body.v2-active .welcome-cta button {
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--v2-radius-sm);
  cursor: pointer;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

body.v2-active .welcome-cta button:hover {
  transform: translateY(-1px);
  box-shadow: var(--v2-shadow-sm);
}

body.v2-active .welcome-cta .btn-primary:hover {
  box-shadow: var(--v2-shadow-md);
}

/* ===== Stats strip v2 ===== */
body.v2-active .v2-stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}

body.v2-active .v2-stat-card {
  padding: 14px 16px;
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.18s ease;
  cursor: default;
}

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

body.v2-active .v2-stat-card .v2-stat-num {
  font-family: var(--v2-font-sans);
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--v2-fg);
  line-height: 1;
}

body.v2-active .v2-stat-card .v2-stat-label {
  font-size: 0.74rem;
  color: var(--v2-fg-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

body.v2-active .v2-stat-card .v2-stat-trend {
  font-size: 0.72rem;
  color: var(--v2-success);
  font-weight: 600;
  font-family: var(--v2-font-mono);
}

body.v2-active .v2-stat-card .v2-stat-trend.down { color: var(--v2-accent); }

/* ===== 4 Category cards v2 (基础/高级/文献/附录) ===== */
body.v2-active .v2-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 56px;
}

body.v2-active .v2-category-card {
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-lg);
  padding: 24px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body.v2-active .v2-category-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, var(--v2-secondary-subtle) 100%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

body.v2-active .v2-category-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--v2-shadow-lg);
  border-color: var(--v2-border-strong);
}

body.v2-active .v2-category-card:hover::before {
  opacity: 0.5;
}

body.v2-active .v2-category-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--v2-radius);
  background: var(--v2-primary-subtle);
  color: var(--v2-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--v2-font-sans);
}

body.v2-active .v2-category-card[data-tier="basic"] .v2-category-icon { background: var(--v2-secondary-subtle); color: var(--v2-secondary); }
body.v2-active .v2-category-card[data-tier="advanced"] .v2-category-icon { background: var(--v2-accent-subtle); color: var(--v2-accent); }
body.v2-active .v2-category-card[data-tier="papers"] .v2-category-icon { background: #FEF3C7; color: #B45309; }
body.v2-active .v2-category-card[data-tier="appendix"] .v2-category-icon { background: var(--v2-bg-subtle); color: var(--v2-fg-muted); }
[data-theme="dark"] body.v2-active .v2-category-card[data-tier="papers"] .v2-category-icon { background: #422006; color: #FBBF24; }

body.v2-active .v2-category-title {
  font-family: var(--v2-font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--v2-fg);
  letter-spacing: -0.015em;
}

body.v2-active .v2-category-desc {
  font-size: 0.82rem;
  color: var(--v2-fg-secondary);
  line-height: 1.55;
  flex: 1;
}

body.v2-active .v2-category-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--v2-border);
}

body.v2-active .v2-category-count {
  font-family: var(--v2-font-mono);
  font-size: 0.78rem;
  color: var(--v2-fg-muted);
  font-weight: 600;
}

body.v2-active .v2-category-arrow {
  color: var(--v2-fg-muted);
  font-size: 1.1rem;
  transition: transform 0.2s ease, color 0.2s ease;
}

body.v2-active .v2-category-card:hover .v2-category-arrow {
  transform: translateX(4px);
  color: var(--v2-fg);
}

/* ===== Method Finder v2 (overrides home-enhancements) ===== */
body.v2-active .method-finder {
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-lg);
  box-shadow: var(--v2-shadow-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(640px, calc(100vh - 160px));
  overflow: hidden;
}

body.v2-active .method-finder h2 {
  font-family: var(--v2-font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--v2-fg);
  margin: 0 0 4px 0;
  letter-spacing: -0.015em;
}

body.v2-active .method-finder-subtitle {
  font-size: 0.78rem;
  color: var(--v2-fg-muted);
  margin: 0;
}

body.v2-active .method-finder-tip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--v2-radius-full);
  background: var(--v2-secondary-subtle);
  color: var(--v2-secondary);
  font-size: 0.7rem;
  font-weight: 600;
}

body.v2-active .method-filter-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

body.v2-active .method-filter-label {
  font-size: 0.72rem;
  color: var(--v2-fg-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0;
}

body.v2-active .method-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

body.v2-active .method-option {
  padding: 5px 10px;
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-full);
  background: var(--v2-bg-elevated);
  color: var(--v2-fg-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--v2-font-sans);
}

body.v2-active .method-option:hover {
  border-color: var(--v2-secondary);
  color: var(--v2-secondary);
}

body.v2-active .method-option.active {
  background: var(--v2-primary);
  color: var(--v2-primary-fg);
  border-color: var(--v2-primary);
}

body.v2-active .method-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

body.v2-active .method-results button {
  padding: 8px 10px;
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-sm);
  background: var(--v2-bg-subtle);
  color: var(--v2-fg);
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
}

body.v2-active .method-results button:hover {
  border-color: var(--v2-primary);
  background: var(--v2-bg-elevated);
}

/* ===== Section heading v2 ===== */
body.v2-active h2.v2-section-title {
  font-family: var(--v2-font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v2-fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 20px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

body.v2-active h2.v2-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--v2-border);
}

/* ===== Features grid v2 ===== */
body.v2-active .v2-features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 56px;
}

body.v2-active .v2-feature-item {
  padding: 16px;
  border-radius: var(--v2-radius);
  background: transparent;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: all 0.15s ease;
}

body.v2-active .v2-feature-item:hover {
  background: var(--v2-bg-subtle);
}

body.v2-active .v2-feature-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--v2-radius-sm);
  background: var(--v2-primary-subtle);
  color: var(--v2-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}

body.v2-active .v2-feature-content h4 {
  font-family: var(--v2-font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--v2-fg);
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}

body.v2-active .v2-feature-content p {
  font-size: 0.78rem;
  color: var(--v2-fg-muted);
  line-height: 1.55;
  margin: 0;
}

/* ===== Learning paths v2 ===== */
body.v2-active .v2-paths {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 56px;
}

body.v2-active .v2-path-card {
  padding: 20px;
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-lg);
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
  overflow: hidden;
}

body.v2-active .v2-path-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--v2-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

body.v2-active .v2-path-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--v2-shadow-md);
}

body.v2-active .v2-path-card:hover::before {
  transform: scaleX(1);
}

body.v2-active .v2-path-card .v2-path-step {
  font-family: var(--v2-font-mono);
  font-size: 0.72rem;
  color: var(--v2-fg-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

body.v2-active .v2-path-card .v2-path-title {
  font-family: var(--v2-font-sans);
  font-size: 1rem;
  font-weight: 700;
  color: var(--v2-fg);
  margin: 0 0 8px 0;
  letter-spacing: -0.01em;
}

body.v2-active .v2-path-card .v2-path-desc {
  font-size: 0.8rem;
  color: var(--v2-fg-muted);
  line-height: 1.5;
  margin: 0 0 12px 0;
}

body.v2-active .v2-path-card .v2-path-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

body.v2-active .v2-path-card .v2-path-list li {
  font-size: 0.78rem;
  color: var(--v2-fg-secondary);
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border-radius: var(--v2-radius-sm);
  transition: all 0.12s ease;
}

body.v2-active .v2-path-card .v2-path-list li::before {
  content: "→";
  color: var(--v2-fg-subtle);
  font-family: var(--v2-font-mono);
  font-size: 0.75rem;
}

body.v2-active .v2-path-card .v2-path-list li:hover {
  color: var(--v2-fg);
  background: var(--v2-bg-subtle);
  padding-left: 6px;
  padding-right: 6px;
}

/* ===== Footer v2 ===== */
body.v2-active .site-footer {
  margin-top: 72px;
  padding: 32px 40px;
  border-top: 1px solid var(--v2-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--v2-fg-muted);
  flex-wrap: wrap;
  gap: 16px;
}

body.v2-active .site-footer a {
  color: var(--v2-fg-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

body.v2-active .site-footer a:hover {
  color: var(--v2-fg);
}

/* ===== Home continue panel v2 ===== */
body.v2-active .home-continue-panel {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 20px 0;
  padding: 8px 8px 8px 16px;
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-full);
  font-size: 0.82rem;
  color: var(--v2-fg-secondary);
  box-shadow: var(--v2-shadow-sm);
}

body.v2-active .home-continue-panel strong {
  color: var(--v2-fg);
  font-weight: 600;
  font-family: var(--v2-font-mono);
}

body.v2-active .home-continue-link {
  padding: 5px 14px;
  border-radius: var(--v2-radius-full);
  background: var(--v2-primary);
  color: var(--v2-primary-fg);
  font-size: 0.76rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
}

body.v2-active .home-continue-link:hover {
  transform: translateY(-1px);
  box-shadow: var(--v2-shadow-md);
}

/* ===== Chapter content area v2 ===== */
body.v2-active #chapter-content {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 40px;
  font-family: var(--v2-font-sans);
  line-height: 1.7;
  color: var(--v2-fg);
}

body.v2-active #chapter-content h1 {
  font-family: var(--v2-font-sans);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--v2-fg);
  margin: 0 0 24px 0;
  border-bottom: 1px solid var(--v2-border);
  padding-bottom: 16px;
}

body.v2-active #chapter-content h2 {
  font-family: var(--v2-font-sans);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--v2-fg);
  margin: 40px 0 14px 0;
}

body.v2-active #chapter-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--v2-fg);
  margin: 28px 0 10px 0;
}

body.v2-active #chapter-content p {
  margin: 0 0 14px 0;
}

body.v2-active #chapter-content pre {
  font-family: var(--v2-font-mono);
  font-size: 0.95rem;  /* 加大 13.44 → 15.2px 解决"白线"视觉错觉(小字号 anti-aliasing) */
  line-height: 1.7;
  background: #0F172A !important;  /* 永远 dark bg — 跟 R token 配色协调 */
  color: #E2E8F0 !important;         /* 浅色 fg — 在 #0F172A 上对比度 11.6:1 */
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius);
  padding: 18px 22px;
  overflow-x: auto;
  font-synthesis: none;  /* 禁掉浏览器合成 bold/italic,用真实字形 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* code.sourceCode 在 pre 内部，不能再有 border — 否则会在 pre 内部画 1px 边线 = "白线" bug! */
body.v2-active #chapter-content code.sourceCode {
  font-family: var(--v2-font-mono);
  font-size: 0.95rem;
  line-height: 1.7;
  background: transparent;  /* 透明 — 让 pre bg 透出 */
  color: inherit;            /* 继承 pre color */
  border: 0 !important;      /* 关键:不画 border,避免在 pre 内部出现"白线" */
  border-radius: 0;
  padding: 0;                /* 不要 padding — padding 由 pre 提供 */
  display: block;
  white-space: pre;
}

/* 修 R token 在深 bg 上的对比度：
   v1.css 用了 VSCode dark theme 配色（#1e1e1e bg 上调色），
   v2 改版后 bg 变 #0F172A，token 对比度大幅下降。
   下面用 v2 dark palette 重新调色，token 颜色在 #0F172A 上对比度 ≥ 4.5:1 (WCAG AA)。
   核心思路：保留 token 语义颜色（绿/紫/蓝/黄/红/橙），但提亮到 AAA 级别。 */
body.v2-active #chapter-content pre.sourceCode .co,  /* R 注释 */
body.v2-active #chapter-content pre.sourceCode .comment { color: #7EB987; }  /* 浅绿 */
body.v2-active #chapter-content pre.sourceCode .ot,  /* 操作符 = */
body.v2-active #chapter-content pre.sourceCode .op   { color: #94A3B8; }  /* 浅灰 */
body.v2-active #chapter-content pre.sourceCode .kw,  /* 关键字 if/function */
body.v2-active #chapter-content pre.sourceCode .keyword { color: #7DD3FC; }  /* 浅蓝 */
body.v2-active #chapter-content pre.sourceCode .do,  /* R 输出 ## */
body.v2-active #chapter-content pre.sourceCode .hljs-doctag {
  color: #CBD5E1;  /* slate-300 — 在 #0F172A 上对比度 9.7:1 (AAA), 提亮 R 输出可读性 */
  font-weight: 500;  /* medium 加重, 不依赖 italic 也能区分 R 输出 vs R 代码 */
}
body.v2-active #chapter-content pre.sourceCode .dt,  /* 类型 */
body.v2-active #chapter-content pre.sourceCode .hljs-title { color: #5EEAD4; }  /* 青 */
body.v2-active #chapter-content pre.sourceCode .fu,  /* 函数名 as.numeric */
body.v2-active #chapter-content pre.sourceCode .hljs-name { color: #FCD34D; }  /* 浅黄 */
body.v2-active #chapter-content pre.sourceCode .st,  /* 字符串 */
body.v2-active #chapter-content pre.sourceCode .hljs-string { color: #FCA5A5; }  /* 浅红 */
body.v2-active #chapter-content pre.sourceCode .at,  /* 属性 data= */
body.v2-active #chapter-content pre.sourceCode .hljs-attr { color: #93C5FD; }  /* 浅蓝 */
body.v2-active #chapter-content pre.sourceCode .dv,  /* 数字 */
body.v2-active #chapter-content pre.sourceCode .hljs-number { color: #C4B5FD; }  /* 浅紫 */
body.v2-active #chapter-content pre.sourceCode .sc   { color: #FBBF24; }  /* $ 符号 */
body.v2-active #chapter-content pre.sourceCode .pp   { color: #93C5FD; }
body.v2-active #chapter-content pre.sourceCode .vs,
body.v2-active #chapter-content pre.sourceCode .hljs-variable { color: #E2E8F0; }  /* 浅灰 fg */
body.v2-active #chapter-content pre.sourceCode .cn,
body.v2-active #chapter-content pre.sourceCode .hljs-constant { color: #5EEAD4; }
body.v2-active #chapter-content pre.sourceCode .al,
body.v2-active #chapter-content pre.sourceCode .hljs-alert { color: #FCA5A5; }  /* 警告红 */
body.v2-active #chapter-content pre.sourceCode .ss,
body.v2-active #chapter-content pre.sourceCode .wa   { color: #FBBF24; }
body.v2-active #chapter-content pre.sourceCode .ex,
body.v2-active #chapter-content pre.sourceCode .pd,
body.v2-active #chapter-content pre.sourceCode .ch   { color: #FCD34D; }

body.v2-active #chapter-content pre code,
body.v2-active #chapter-content code.sourceCode code {
  font-family: var(--v2-font-mono);
  font-size: 0.84rem;
}

body.v2-active #chapter-content .code-copy-button {
  background: var(--v2-bg-subtle);
  border: 1px solid var(--v2-border);
  color: var(--v2-fg-secondary);
  border-radius: var(--v2-radius-sm);
  padding: 4px 8px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

body.v2-active #chapter-content .code-copy-button:hover {
  background: var(--v2-bg-elevated);
  border-color: var(--v2-primary);
  color: var(--v2-fg);
}

body.v2-active #chapter-content .callout,
body.v2-active #chapter-content div.callout-note,
body.v2-active #chapter-content .box {
  border-left: 3px solid var(--v2-secondary);
  background: var(--v2-secondary-subtle);
  border-radius: var(--v2-radius);
  padding: 14px 18px;
  margin: 18px 0;
}

body.v2-active #chapter-content .callout-warning {
  border-left-color: var(--v2-accent);
  background: var(--v2-accent-subtle);
}

body.v2-active #chapter-content .callout-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--v2-fg);
  font-size: 0.92rem;
}

body.v2-active #chapter-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  margin: 18px 0;
}

body.v2-active #chapter-content th,
body.v2-active #chapter-content td {
  padding: 8px 12px;
  border: 1px solid var(--v2-border);
  text-align: left;
}

body.v2-active #chapter-content th {
  background: var(--v2-bg-subtle);
  font-weight: 700;
}

body.v2-active #chapter-content td {
  /* Browser UA default for <td> is white — override with token so dark mode flips */
  background: var(--v2-bg-elevated);
}

body.v2-active #chapter-content input[type="text"],
body.v2-active #chapter-content input[type="number"],
body.v2-active #chapter-content input[type="range"],
body.v2-active #chapter-content select,
body.v2-active #chapter-content textarea {
  background: var(--v2-bg-elevated);
  color: var(--v2-fg);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

body.v2-active #chapter-content input[type="text"]:focus,
body.v2-active #chapter-content input[type="number"]:focus,
body.v2-active #chapter-content select:focus,
body.v2-active #chapter-content textarea:focus {
  outline: none;
  border-color: var(--v2-ring);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

/* Range slider (viz-slider) — track + thumb need explicit dark-mode styling */
body.v2-active #chapter-content input[type="range"] {
  padding: 0;
  background: transparent;
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 9999px;
  background: var(--v2-bg-subtle);
}

body.v2-active #chapter-content input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--v2-primary);
  border: 2px solid var(--v2-bg-elevated);
  cursor: pointer;
  box-shadow: var(--v2-shadow-sm);
}

body.v2-active #chapter-content input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--v2-primary);
  border: 2px solid var(--v2-bg-elevated);
  cursor: pointer;
  box-shadow: var(--v2-shadow-sm);
}

body.v2-active #chapter-content .viz-controls {
  background: var(--v2-bg-subtle);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-sm);
  padding: 12px;
  margin: 12px 0;
}

body.v2-active #chapter-content .viz-sliders {
  background: transparent;
  padding: 0;
}

body.v2-active #chapter-content a {
  color: var(--v2-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

body.v2-active #chapter-content a:hover {
  color: var(--v2-primary);
}

/* ===== Stat viz cards v2 ===== */
body.v2-active .viz-card,
body.v2-active .calc-card {
  background: var(--v2-bg-elevated);
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-lg);
  box-shadow: var(--v2-shadow-sm);
  padding: 18px;
  margin: 18px 0;
}

body.v2-active .viz-header {
  font-family: var(--v2-font-sans);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--v2-fg);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

body.v2-active .viz-reset,
body.v2-active .viz-card button {
  background: var(--v2-bg-subtle);
  border: 1px solid var(--v2-border);
  color: var(--v2-fg-secondary);
  border-radius: var(--v2-radius-sm);
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: var(--v2-font-sans);
  transition: all 0.15s ease;
}

body.v2-active .viz-card button:hover {
  background: var(--v2-bg-elevated);
  border-color: var(--v2-primary);
}

body.v2-active .viz-stats {
  font-size: 0.82rem;
  color: var(--v2-fg-secondary);
  margin-top: 10px;
  font-family: var(--v2-font-mono);
}

body.v2-active .viz-stats strong {
  color: var(--v2-fg);
  font-weight: 700;
}

/* ===== Scrollbar v2 ===== */
body.v2-active ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
body.v2-active ::-webkit-scrollbar-track {
  background: transparent;
}
body.v2-active ::-webkit-scrollbar-thumb {
  background: var(--v2-border-strong);
  border-radius: var(--v2-radius-full);
  border: 2px solid var(--v2-bg);
}
body.v2-active ::-webkit-scrollbar-thumb:hover {
  background: var(--v2-fg-subtle);
}

/* ===== Selection ===== */
body.v2-active ::selection {
  background: var(--v2-accent);
  color: var(--v2-accent-fg);
}

/* ===== Smooth focus ring ===== */
body.v2-active :focus-visible {
  outline: 2px solid var(--v2-ring);
  outline-offset: 2px;
  border-radius: var(--v2-radius-sm);
}

/* ===== Skip link (a11y: 键盘用户 Tab 一次跳过 sidebar) ===== */
body.v2-active .skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--v2-accent);
  color: white;
  padding: 8px 16px;
  z-index: 9999;
  font-weight: 600;
  border-radius: 0 0 var(--v2-radius) 0;
  transition: top 0.2s ease;
  text-decoration: none;
}
body.v2-active .skip-link:focus {
  top: 0;
  outline: 2px solid var(--v2-ring);
  outline-offset: 2px;
}

/* ===== Responsive v2 ===== */
@media (max-width: 900px) {
  body.v2-active #app {
    grid-template-columns: 1fr;
  }
  body.v2-active #sidebar {
    position: fixed;
    transform: translateX(-100%);
    z-index: 100;
    transition: transform 0.2s ease;
  }
  body.v2-active #sidebar.open {
    transform: translateX(0);
  }
  body.v2-active .welcome-hero {
    padding: 32px 20px 16px;
  }
  body.v2-active #chapter-content {
    padding: 24px 20px;
  }
  /* 移动端把搜索框脱离 sidebar, 放主视图顶部 (a11y + UX) */
  body.v2-active .search-box {
    position: fixed !important;
    top: 8px;
    left: 60px;
    right: 60px;
    z-index: 50;
    background: var(--v2-bg);
    border-radius: var(--v2-radius);
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
    max-width: 360px;
  }
  /* topbar 内的 search 在移动端, 仍然用上面的 fixed 规则 (在 #topbar 之外的位置) */
  /* desktop: search-box 在 #topbar 内, 用 topbar 布局, 不需要 absolute */

  /* 移动端隐藏 stats-strip (装饰性, 避免 CLS; desktop 仍显示 4 个统计卡) */
  body.v2-active .v2-stats-strip {
    display: none;
  }
}

/* ===== Accessibility: 尊重 prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  body.v2-active .btn-continue:hover,
  body.v2-active .v2-category-card:hover,
  body.v2-active .v2-path-card:hover,
  body.v2-active .v2-feature-item:hover {
    transform: none !important;
  }
}
