/* ========================================
   AI Agent Guide - Book Style Framework
   设计理念：干净、统一、实用，不要"AI味"
   ======================================== */

/* ===== CSS Variables - Design Tokens ===== */
:root {
  /* 主色调 - 现代科技蓝 + 靛蓝点缀 */
  --color-primary: #0f172a;
  --color-primary-light: #334155;
  --color-primary-dark: #020617;
  --color-accent: #4f46e5;
  --color-accent-light: #6366f1;
  --color-accent-dark: #3730a3;

  /* 背景色 - 干净现代 */
  --color-bg: #f8fafc;
  --color-bg-alt: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-hover: #f8fafc;

  /* 文字色 */
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-tertiary: #94a3b8;
  --color-text-inverse: #ffffff;

  /* 功能色 */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-info: #3b82f6;

  /* 边框 */
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-border-dark: #cbd5e1;

  /* 阴影 */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* 圆角 */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --space-2xl: 64px;

  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Georgia", "Noto Serif SC", "Source Han Serif SC", serif;
  --font-mono: "SF Mono", "Fira Code", "Source Code Pro", "Consolas", monospace;

  /* 字号 */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;
  --text-3xl: 36px;

  /* 布局 */
  --sidebar-width: 260px;
  --toc-width: 200px;
  --chat-width: 340px;
  --chat-width-min: 260px;
  --chat-width-max: 600px;
  --content-max: 780px;

  /* 动画 */
  --transition: 0.25s ease;
  --transition-slow: 0.4s ease;

  /* 渐变 */
  --gradient-accent: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
  --gradient-primary: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  --gradient-hero: linear-gradient(135deg, #1d3557 0%, #457b9d 50%, #2a9d8f 100%);
}

/* 深色主题 - GitHub Dark 风格 */
[data-theme="dark"] {
  --color-primary: #f8fafc;
  --color-primary-light: #e2e8f0;
  --color-primary-dark: #cbd5e1;
  --color-accent: #6366f1;
  --color-accent-light: #818cf8;
  --color-accent-dark: #4f46e5;

  --color-bg: #0f172a;
  --color-bg-alt: #1e293b;
  --color-surface: #1e293b;
  --color-surface-hover: #334155;

  --color-text: #f8fafc;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-text-inverse: #0f172a;

  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-info: #3b82f6;

  --color-border: #334155;
  --color-border-light: #1e293b;
  --color-border-dark: #475569;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.7);
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-tertiary);
}
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--text-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ===== 主布局 ===== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width) var(--chat-width) 48px;
  grid-template-rows: 100vh;
  height: 100vh;
  transition: grid-template-columns var(--transition);
}

.app-layout.sidebar-collapsed {
  grid-template-columns: 0 1fr var(--toc-width) var(--chat-width) 48px;
}

.app-layout.chat-collapsed {
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width) 0 48px;
}

.app-layout.sidebar-collapsed.chat-collapsed {
  grid-template-columns: 0 1fr var(--toc-width) 0 48px;
}

.app-layout.toc-collapsed {
  grid-template-columns: var(--sidebar-width) 1fr 0 var(--chat-width) 48px;
}

.app-layout.toc-collapsed.chat-collapsed {
  grid-template-columns: var(--sidebar-width) 1fr 0 0 48px;
}

.app-layout.sidebar-collapsed.toc-collapsed {
  grid-template-columns: 0 1fr 0 var(--chat-width) 48px;
}

.app-layout.sidebar-collapsed.toc-collapsed.chat-collapsed {
  grid-template-columns: 0 1fr 0 0 48px;
}

/* ===== 左侧目录栏 ===== */
.sidebar {
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: color 0.2s ease;
  user-select: none;
}

.sidebar-header h1:hover {
  color: var(--color-accent);
}

.sidebar-header h1:active {
  transform: scale(0.98);
  transition: transform 0.1s;
}

/* 让 h1 变成可点击的样式 */
.sidebar-logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: var(--radius-sm);
}

.sidebar-logo:hover {
  background: var(--color-surface-hover);
}

.sidebar-header .theme-toggle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-md);
  transition: var(--transition);
}

.sidebar-header .theme-toggle:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border-dark);
}

.sidebar-progress {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar-progress .progress-bar {
  height: 3px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.sidebar-progress .progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.sidebar-progress .progress-text {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-top: var(--space-xs);
  display: flex;
  justify-content: space-between;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 2px;
}

.sidebar:hover .sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
}

.nav-section {
  margin-bottom: var(--space-md);
}

.nav-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-tertiary);
  padding: var(--space-sm) var(--space-lg);
}

.nav-item {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  position: relative;
  border-radius: 0 20px 20px 0;
  margin-right: var(--space-md);
}

.nav-item:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.nav-item.active {
  background: rgba(79, 70, 229, 0.08); /* 极淡的靛蓝背景 */
  color: var(--color-accent);
  font-weight: 600;
  position: relative;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--color-accent);
  border-radius: 0 4px 4px 0;
}

.nav-item.completed::after {
  content: '✓';
  position: absolute;
  right: var(--space-lg);
  color: var(--color-success);
  font-size: var(--text-xs);
}

.nav-item .nav-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  margin-right: var(--space-sm);
  flex-shrink: 0;
  color: var(--color-text-tertiary);
}

.nav-item.active .nav-number {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.nav-item.completed .nav-number {
  background: var(--color-success);
  border-color: var(--color-success);
  color: white;
}

/* ===== 中间内容区 ===== */
.content-area {
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-surface);
  position: relative;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  box-shadow: -4px 0 24px rgba(0,0,0,0.02);
  margin: var(--space-xs) 0;
}

.content-area::-webkit-scrollbar {
  width: 6px;
}

.content-area::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
}

.content-area:hover::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
}

.content-header {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.85);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg) 0 0 0;
}

[data-theme="dark"] .content-header {
  background: rgba(30, 41, 59, 0.85);
}

.content-header .breadcrumb {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.content-header .breadcrumb span {
  color: var(--color-text-secondary);
}

.content-header .nav-buttons {
  display: flex;
  gap: var(--space-sm);
}

.content-header .nav-btn {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 500;
}

.content-header .nav-btn:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
  color: var(--color-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.content-header .nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.content-body {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-xl) var(--space-2xl);
}

/* 宽内容容器：限宽100%并允许内部横向滚动 */
.content-body .flowchart-container,
.content-body .comparison-table,
.content-body .wide-svg-container {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* flowchart SVG 优先自适应容器宽度，内容超宽时可横向滚动 */
.content-body .flowchart-svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 手写的宽 SVG（带 width 属性的）也允许在容器内滚动 */

/* ===== 书籍封面 ===== */
.book-cover {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-xl);
  text-align: center;
}

.book-cover .cover-badge {
  display: inline-block;
  padding: 4px 12px;
  border: 1px solid var(--color-border-dark);
  border-radius: 100px;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.06em;
  margin-bottom: var(--space-lg);
}

.book-cover h1 {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
  margin-bottom: var(--space-md);
  letter-spacing: -0.02em;
}

.book-cover .subtitle {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
  line-height: 1.6;
}

.book-cover .cover-meta {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.book-cover .cover-meta-item {
  text-align: center;
}

.book-cover .cover-meta-item .num {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-accent);
  display: block;
}

.book-cover .cover-meta-item .label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.book-cover .start-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px 32px;
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: 30px;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
}

.book-cover .start-btn:hover {
  background: var(--color-accent-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

/* ===== 章节内容样式 ===== */
.chapter-title {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
  letter-spacing: -0.02em;
}

.chapter-subtitle {
  font-size: var(--text-md);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-xl);
}

.section-heading {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--color-border);
  position: relative;
}
.section-heading::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--gradient-accent);
}

.sub-heading {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-primary-light);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-md);
}

p {
  margin-bottom: var(--space-md);
  color: var(--color-text);
  line-height: 1.8;
}

.quote {
  border-left: 3px solid var(--color-accent);
  padding: var(--space-md) var(--space-lg) var(--space-md) var(--space-xl);
  background: var(--color-surface);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: var(--space-lg) 0;
  font-style: italic;
  color: var(--color-text-secondary);
  position: relative;
}
.quote::before {
  content: '"';
  position: absolute;
  top: 6px;
  left: 16px;
  font-size: 28px;
  font-weight: 700;
  color: var(--color-accent);
  font-family: var(--font-serif);
  line-height: 1;
}

/* ===== 表格样式 ===== */
.comparison-table {
  margin: var(--space-lg) 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.comparison-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--color-surface);
}

.comparison-table th,
.comparison-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.comparison-table th {
  background: var(--color-bg-alt);
  font-weight: 600;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-border);
}

.comparison-table tr:last-child td {
  border-bottom: none;
}

.comparison-table tr:hover td {
  background: var(--color-surface-hover);
}

/* 普通表格（无 comparison-table 包装） */
.content-body .table-wrapper {
  margin: var(--space-lg) 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.content-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--color-surface);
}

.content-body th,
.content-body td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.content-body th {
  background: var(--color-bg-alt);
  font-weight: 600;
  color: var(--color-primary);
}

.content-body tr:hover td {
  background: var(--color-surface-hover);
}

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

/* 代码块 */
.code-block {
  background: var(--color-primary-dark) !important;
  color: #f8fafc !important;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  overflow-x: auto;
  position: relative;
}
/* 当 .code-block 内有 wrapper 时，去掉外层 padding（wrapper 内部已有自己的间距） */
.code-block:has(.code-block-wrapper) {
  padding: 0;
  background: transparent !important;
}

.code-block .code-label {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-md);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.code-block pre {
  margin: 0;
  white-space: pre-wrap;
  color: inherit !important;
  background: transparent !important;
}

/* 卡片 */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-title .icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 对比布局 */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.compare-grid .card {
  margin: 0;
}

.compare-grid .card:first-child {
  border-left: 3px solid var(--color-info);
}

.compare-grid .card:last-child {
  border-left: 3px solid var(--color-success);
}

/* 标签 */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
}

.tag-blue { background: rgba(92, 138, 181, 0.12); color: var(--color-info); }
.tag-green { background: rgba(91, 140, 90, 0.12); color: var(--color-success); }
.tag-orange { background: rgba(196, 148, 92, 0.12); color: var(--color-warning); }
.tag-red { background: rgba(184, 84, 80, 0.12); color: var(--color-error); }

/* 八股总结 */
.summary-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  margin: var(--space-xl) 0;
}

.summary-box .summary-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.summary-box .qa-item {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.summary-box .qa-item:last-child {
  border-bottom: none;
}

.summary-box .qa-question {
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
  font-size: var(--text-sm);
}

.summary-box .qa-question::before {
  content: 'Q';
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background: var(--color-accent);
  color: white;
  border-radius: 50%;
  font-size: var(--text-xs);
  margin-right: var(--space-sm);
  font-weight: 700;
}

.summary-box .qa-answer {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.7;
  padding-left: 28px;
}

/* 考试区域 */
.quiz-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin: var(--space-xl) 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--color-border);
}

.quiz-header h3 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-header .quiz-score {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  background: var(--color-bg-alt);
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: 500;
}

.quiz-question {
  margin-bottom: var(--space-lg);
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-alt);
  border-left: 4px solid var(--color-accent);
  transition: var(--transition);
}

.quiz-question:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 12px rgba(212, 165, 116, 0.1);
}

.quiz-question:last-child {
  margin-bottom: 0;
  border-bottom: 1px solid var(--color-border-light);
}

.quiz-question .q-type {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent);
  background: rgba(212, 165, 116, 0.1);
  padding: 2px 10px;
  border-radius: 10px;
  display: inline-block;
  margin-bottom: var(--space-sm);
}

.quiz-question .q-text {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-md);
  line-height: 1.8;
}

.quiz-option {
  display: flex;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  position: relative;
}

.quiz-option:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
  transform: translateX(4px);
}

.quiz-option.selected {
  border-color: var(--color-accent) !important;
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.12) 0%, rgba(212, 165, 116, 0.06) 100%) !important;
  color: var(--color-text) !important;
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.15), 0 2px 8px rgba(212, 165, 116, 0.1);
  transform: translateX(4px);
}

.quiz-option.selected::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}

.quiz-option.correct {
  border-color: var(--color-success) !important;
  background: linear-gradient(135deg, rgba(91, 140, 90, 0.15) 0%, rgba(91, 140, 90, 0.08) 100%) !important;
  color: var(--color-success) !important;
  box-shadow: 0 0 0 3px rgba(91, 140, 90, 0.15);
}

.quiz-option.correct::before {
  content: '✓';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-success);
  font-weight: 700;
  font-size: 18px;
}

.quiz-option.wrong {
  border-color: var(--color-error) !important;
  background: linear-gradient(135deg, rgba(184, 84, 80, 0.15) 0%, rgba(184, 84, 80, 0.08) 100%) !important;
  color: var(--color-error) !important;
  box-shadow: 0 0 0 3px rgba(184, 84, 80, 0.15);
}

.quiz-option.wrong::before {
  content: '✗';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-error);
  font-weight: 700;
  font-size: 18px;
}

.quiz-option .option-letter {
  width: 28px;
  height: 28px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-right: var(--space-md);
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.quiz-option.selected .option-letter {
  border-color: var(--color-accent) !important;
  background: var(--color-accent) !important;
  color: white !important;
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.2);
  transform: scale(1.1);
}

.quiz-option.correct .option-letter {
  border-color: var(--color-success) !important;
  background: var(--color-success) !important;
  color: white !important;
  box-shadow: 0 0 0 3px rgba(91, 140, 90, 0.2);
}

.quiz-option.wrong .option-letter {
  border-color: var(--color-error) !important;
  background: var(--color-error) !important;
  color: white !important;
  box-shadow: 0 0 0 3px rgba(184, 84, 80, 0.2);
}

.quiz-explanation {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.08) 0%, rgba(212, 165, 116, 0.03) 100%);
  border: 1px solid rgba(212, 165, 116, 0.2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.8;
  display: none;
}

.quiz-explanation strong {
  color: var(--color-accent);
  font-weight: 600;
}

.quiz-explanation.show {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* 选项容器 */
.quiz-options {
  margin-top: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.quiz-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border-light);
}

.quiz-btn {
  padding: var(--space-sm) var(--space-xl);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.quiz-btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.quiz-btn.primary {
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-light) 100%);
  color: var(--color-text-inverse);
  border-color: var(--color-accent);
}

.quiz-btn.primary:hover {
  box-shadow: 0 4px 16px rgba(212, 165, 116, 0.3);
  transform: translateY(-2px);
}

.quiz-result {
  text-align: center;
  padding: var(--space-xl);
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.05) 0%, rgba(212, 165, 116, 0.02) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(212, 165, 116, 0.15);
  animation: fadeIn 0.5s ease;
}

.quiz-result .score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 4px solid var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-md);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-accent);
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.1) 0%, rgba(212, 165, 116, 0.05) 100%);
  box-shadow: 0 4px 16px rgba(212, 165, 116, 0.2);
  position: relative;
}

.quiz-result .score-circle::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px dashed rgba(212, 165, 116, 0.3);
  animation: spin 20s linear infinite;
}

.quiz-result .score-label {
  font-size: var(--text-md);
  color: var(--color-text);
  margin-bottom: var(--space-lg);
  font-weight: 600;
}

/* ===== 章节目录栏 (TOC) — 配色与章节内容一致 ===== */
/* TOC 作为独立面板，但使用章节内容配色（--color-primary / --color-primary-light），*/
/* 使目录视觉上属于章节而非独立的工具面板。仅在有标题时展示。*/

.toc-panel {
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
  width: 100%;
}

.app-layout.toc-collapsed .toc-panel {
  background: transparent;
  border-left: none;
}

.app-layout.toc-collapsed .toc-header h3 {
  display: none;
}

.app-layout.toc-collapsed .toc-nav {
  display: none;
}

.app-layout.toc-collapsed .toc-header {
  justify-content: center;
  padding: var(--space-md) 0;
  border-bottom: none;
}

.toc-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.toc-header h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  margin: 0;
}

.toc-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
  /* 目录字体与配色与章节内容一致 */
  font-size: var(--text-sm);
  color: var(--color-primary);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-dark) transparent;
}

.toc-nav::-webkit-scrollbar {
  width: 4px;
}

.toc-nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 2px;
}

.toc-panel:hover .toc-nav::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
}

/* TOC 分组结构 — 与章节内容配色保持一致 */
.toc-section {
  margin-bottom: var(--space-sm);
}

.toc-section-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary); /* 与 section-heading 一致 */
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  line-height: 1.5;
}

.toc-section-header:hover {
  background: var(--color-surface-hover);
  color: var(--color-accent);
}

.toc-section-header.active {
  background: var(--color-bg-alt);
  color: var(--color-accent);
}

.toc-section-header .toc-num {
  flex-shrink: 0;
  color: var(--color-accent);
  font-weight: 700;
  min-width: 26px;
}

.toc-section-header .toc-title {
  flex: 1;
}

/* 子项容器 */
.toc-sub-items {
  padding-left: var(--space-lg);
  margin-top: 2px;
  border-left: 1px solid var(--color-border);
  margin-left: 12px;
}

.toc-sub-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-xs);
  padding: 3px var(--space-md) 3px var(--space-sm);
  font-size: var(--text-xs);
  color: var(--color-primary-light); /* 与 sub-heading 配色一致 */
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  line-height: 1.5;
  font-weight: 400;
}

.toc-sub-item:hover {
  background: var(--color-surface-hover);
  color: var(--color-accent);
}

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

.toc-sub-item .toc-num {
  flex-shrink: 0;
  color: var(--color-text-tertiary);
  font-size: 10px;
  min-width: 28px;
  font-weight: 500;
}

.toc-sub-item .toc-title {
  flex: 1;
}

/* ===== 右侧 AI 对话栏 ===== */
.chat-panel {
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  width: var(--chat-width);
  min-width: var(--chat-width-min);
  max-width: var(--chat-width-max);
  flex-shrink: 0;
  position: relative;
}

/* 拖拽手柄 */
.chat-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  z-index: 10;
  transition: background 0.2s;
}

.chat-resize-handle:hover,
.chat-resize-handle.active {
  background: var(--color-accent);
  opacity: 0.3;
}

.chat-panel:hover {
  box-shadow: var(--shadow-md);
}

.app-layout.chat-collapsed .chat-panel {
  background: transparent;
  border-left: none;
  box-shadow: none;
}

.app-layout.chat-collapsed .chat-header .title-text {
  display: none;
}

.app-layout.chat-collapsed .chat-model-selector,
.app-layout.chat-collapsed .chat-context-badge,
.app-layout.chat-collapsed .chat-messages,
.app-layout.chat-collapsed .chat-input-area,
.app-layout.chat-collapsed #chatClearBtn {
  display: none;
}

.app-layout.chat-collapsed .chat-header {
  justify-content: center;
  padding: var(--space-md) 0;
  border-bottom: none;
}

/* ===== 右侧工具栏 ===== */
.right-toolbar {
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-md) 0;
  gap: var(--space-md);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.toolbar-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  transition: var(--transition);
  opacity: 0.7;
  border-left: 3px solid transparent;
  position: relative;
}

.toolbar-btn:hover {
  background: var(--color-surface-hover);
  opacity: 1;
  transform: scale(1.05);
}

.toolbar-btn.active {
  background: var(--color-surface);
  color: var(--color-accent);
  opacity: 1;
  border-left-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* 项目按钮 - 绿色主题 */
.toolbar-btn-project {
  color: #2ecc71;
}
.toolbar-btn-project:hover {
  background: rgba(46, 204, 113, 0.12);
  border-left-color: #2ecc71;
  color: #27ae60;
}

/* GitHub 按钮 - 黑色主题 */
.toolbar-btn-github {
  color: #24292e;
}
.toolbar-btn-github:hover {
  background: rgba(36, 41, 46, 0.1);
  border-left-color: #24292e;
  color: #000000;
}

.chat-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 100%);
}

.chat-header .chat-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.chat-header .chat-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25), 0 0 8px rgba(16, 185, 129, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25), 0 0 8px rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.15), 0 0 12px rgba(16, 185, 129, 0.6); }
}

.chat-header .chat-actions {
  display: flex;
  gap: var(--space-xs);
}

.chat-context-badge {
  background: rgba(79, 70, 229, 0.06);
  color: var(--color-accent);
  font-size: 12px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  font-weight: 500;
}

.chat-context-badge .context-icon {
  font-size: 13px;
}

.app-layout.chat-collapsed .chat-context-badge {
  display: none !important;
}

.chat-header .chat-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  transition: var(--transition);
}

.chat-header .chat-action-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

/* 模型选择器 */
.chat-model-selector {
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.chat-model-selector select {
  flex: 1;
  padding: 6px var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  cursor: pointer;
  font-family: var(--font-sans);
  outline: none;
}

.chat-model-selector select:focus {
  border-color: var(--color-accent);
}

.chat-model-selector .settings-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  transition: var(--transition);
}

.chat-model-selector .settings-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

/* 快捷提示词（位于输入框上方，融合为一体） */
.chat-quick-prompts {
  padding: 8px 12px 4px 12px;
  flex-shrink: 0;
}

.quick-prompts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
}

.quick-prompts-row.visible {
  max-height: 34px; /* 1行 */
  opacity: 1;
}

.quick-prompts-row.expanded {
  max-height: 120px; /* 2-3行 */
}

.quick-prompt {
  background: var(--color-bg-alt);
  border: 1px solid transparent;
  color: var(--color-text-secondary);
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
  line-height: 1.5;
  user-select: none;
}

.quick-prompt:hover {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.2);
  transform: translateY(-1px);
}

.quick-prompt:active {
  transform: scale(0.96);
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.15);
}

.quick-prompts-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 20px;
  margin: 3px auto 0;
  border: none;
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: 10px;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.quick-prompts-toggle:hover {
  color: var(--color-accent);
  background: rgba(79, 70, 229, 0.06);
}

.quick-prompts-toggle .toggle-icon {
  display: inline-block;
  transition: transform 0.3s ease;
}

.quick-prompts-toggle.expanded .toggle-icon {
  transform: rotate(180deg);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* 回到最新消息按钮 - 居中优雅设计 */
.chat-scroll-bottom-btn {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  min-width: 100px;
  padding: 8px 20px;
  border-radius: 24px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
  letter-spacing: 0.3px;
}

/* 按钮图标 */
.chat-scroll-bottom-btn::before {
  content: '↓';
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.chat-scroll-bottom-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.chat-scroll-bottom-btn:hover {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  transform: translateX(-50%) translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
}

.chat-scroll-bottom-btn:active {
  transform: translateX(-50%) translateY(0) scale(0.98);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 2px;
  transition: background 0.3s;
}

.chat-panel:hover .chat-messages::-webkit-scrollbar-thumb,
.chat-messages:hover::-webkit-scrollbar-thumb {
  background: var(--color-border-dark);
}

.chat-msg {
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
}

.chat-msg.user {
  align-items: flex-end;
}

.chat-msg.assistant {
  align-items: flex-start;
}

.chat-msg .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: var(--space-xs);
  flex-shrink: 0;
}

.chat-msg.user .msg-avatar {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.chat-msg.assistant .msg-avatar {
  background: var(--color-accent);
  color: white;
}

.chat-msg .msg-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px 16px 16px 4px;
  font-size: var(--text-sm);
  line-height: 1.6;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.chat-msg.user .msg-bubble {
  background: var(--gradient-accent);
  color: var(--color-text-inverse);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

/* 用户消息气泡内的所有子元素强制白色文字 */
.chat-msg.user .msg-bubble,
.chat-msg.user .msg-bubble *,
.chat-msg.user .msg-bubble strong,
.chat-msg.user .msg-bubble code,
.chat-msg.user .msg-bubble a,
.chat-msg.user .msg-bubble h1,
.chat-msg.user .msg-bubble h2,
.chat-msg.user .msg-bubble h3,
.chat-msg.user .msg-bubble h4,
.chat-msg.user .msg-bubble h5,
.chat-msg.user .msg-bubble h6,
.chat-msg.user .msg-bubble p,
.chat-msg.user .msg-bubble span,
.chat-msg.user .msg-bubble div {
  color: var(--color-text-inverse) !important;
}

/* 用户消息中的链接保持可点击颜色 */
.chat-msg.user .msg-bubble a {
  color: rgba(255, 255, 255, 0.9) !important;
  text-decoration: underline;
}

.chat-msg.assistant .msg-bubble {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 16px 16px 16px 4px;
  box-shadow: var(--shadow-sm);
}

.chat-msg .msg-bubble pre {
  background: var(--color-primary-dark);
  color: #d8d4ce;
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  margin: var(--space-sm) 0;
  font-size: var(--text-xs);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* ========== Markdown 渲染样式 ========== */

/* 标题 */
.chat-msg .msg-bubble h1,
.chat-msg .msg-bubble h2,
.chat-msg .msg-bubble h3,
.chat-msg .msg-bubble h4,
.chat-msg .msg-bubble h5,
.chat-msg .msg-bubble h6 {
  margin: 16px 0 8px;
  line-height: 1.4;
  font-weight: 700;
}

.chat-msg .msg-bubble h1 { font-size: 1.3em; }
.chat-msg .msg-bubble h2 { font-size: 1.2em; border-bottom: 1px solid var(--color-border); padding-bottom: 4px; }
.chat-msg .msg-bubble h3 { font-size: 1.1em; color: var(--color-accent); }
.chat-msg .msg-bubble h4 { font-size: 1em; }
.chat-msg .msg-bubble h1:first-child,
.chat-msg .msg-bubble h2:first-child,
.chat-msg .msg-bubble h3:first-child { margin-top: 0; }

/* 段落 */
.chat-msg .msg-bubble p {
  margin: 8px 0;
  line-height: 1.7;
}
.chat-msg .msg-bubble p:first-child { margin-top: 0; }
.chat-msg .msg-bubble p:last-child { margin-bottom: 0; }

/* 列表 */
.chat-msg .msg-bubble ul,
.chat-msg .msg-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}
.chat-msg .msg-bubble li {
  margin: 4px 0;
  line-height: 1.6;
}
.chat-msg .msg-bubble li > ul,
.chat-msg .msg-bubble li > ol {
  margin: 4px 0;
}

/* 引用块 */
.chat-msg .msg-bubble blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--color-accent);
  background: rgba(79, 70, 229, 0.05);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-secondary);
}
.chat-msg .msg-bubble blockquote p {
  margin: 4px 0;
}
.chat-msg .msg-bubble blockquote blockquote {
  margin-top: 6px;
  border-left-color: var(--color-text-tertiary);
}

/* 表格 */
.chat-msg .msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.9em;
  overflow-x: auto;
  display: block;
}
.chat-msg .msg-bubble thead {
  background: var(--color-primary-dark);
  color: #d8d4ce;
}
.chat-msg .msg-bubble th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.9em;
  white-space: nowrap;
}
.chat-msg .msg-bubble td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
}
.chat-msg .msg-bubble tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}
.chat-msg .msg-bubble tbody tr:hover {
  background: rgba(79, 70, 229, 0.04);
}

/* 水平线 */
.chat-msg .msg-bubble hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 14px 0;
}

/* 行内代码 */
.chat-msg .msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-accent-dark);
}

/* 代码块 */
.chat-msg .msg-bubble pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 14px 16px;
  border-radius: 8px;
  margin: 10px 0;
  font-size: 0.85em;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
}
.chat-msg .msg-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

/* 链接 */
.chat-msg .msg-bubble a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.chat-msg .msg-bubble a:hover {
  border-bottom-color: var(--color-accent);
}

/* 粗体/斜体 */
.chat-msg .msg-bubble strong {
  font-weight: 700;
  color: var(--color-primary);
}
.chat-msg .msg-bubble em {
  font-style: italic;
}

/* 图片 */
.chat-msg .msg-bubble img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

/* 深色主题下的 Markdown 样式 */
[data-theme="dark"] .chat-msg .msg-bubble h3 {
  color: var(--color-accent-light);
}
[data-theme="dark"] .chat-msg .msg-bubble blockquote {
  background: rgba(99, 102, 241, 0.08);
}
[data-theme="dark"] .chat-msg .msg-bubble strong {
  color: var(--color-primary-light);
}
[data-theme="dark"] .chat-msg .msg-bubble thead {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
}
[data-theme="dark"] .chat-msg .msg-bubble td {
  border-bottom-color: var(--color-border);
}
[data-theme="dark"] .chat-msg .msg-bubble tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}
[data-theme="dark"] .chat-msg .msg-bubble tbody tr:hover {
  background: rgba(99, 102, 241, 0.08);
}
[data-theme="dark"] .chat-msg .msg-bubble code {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-accent-light);
}
[data-theme="dark"] .chat-msg .msg-bubble h2 {
  border-bottom-color: var(--color-border);
}

/* 用户消息中的 Markdown 样式覆盖 */
.chat-msg.user .msg-bubble code {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.95) !important;
}

.chat-msg.user .msg-bubble pre {
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-msg.user .msg-bubble pre code {
  color: rgba(255, 255, 255, 0.95) !important;
}

.chat-msg.user .msg-bubble strong {
  color: #ffffff !important;
  font-weight: 700;
}

.chat-msg.user .msg-bubble blockquote {
  background: rgba(255, 255, 255, 0.1);
  border-left-color: rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.9) !important;
}

.chat-msg.user .msg-bubble table thead {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff !important;
}

.chat-msg.user .msg-bubble td {
  border-bottom-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9) !important;
}

.chat-msg.user .msg-bubble ul li,
.chat-msg.user .msg-bubble ol li {
  color: rgba(255, 255, 255, 0.95) !important;
}

.chat-msg.user .msg-bubble hr {
  border-top-color: rgba(255, 255, 255, 0.2);
}

.chat-msg .msg-meta {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-top: var(--space-xs);
}

.chat-msg.loading .msg-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
}

.chat-msg.loading .msg-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: bounce 1.2s infinite;
}

.chat-msg.loading .msg-bubble span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.loading .msg-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* 对话输入区 */
.chat-input-area {
  padding: 0;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

.chat-input-area .chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 0 10px 10px 10px;
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  padding: 8px 12px 8px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-area .chat-input-wrapper:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}

.chat-input-area textarea {
  flex: 1;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-sans);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
  line-height: 1.6;
}

.chat-input-area textarea:focus {
  outline: none;
}

.chat-input-area textarea::placeholder {
  color: var(--color-text-tertiary);
  font-size: 13px;
}

.chat-input-area .send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  position: relative;
  overflow: hidden;
}

/* 按钮光晕效果 */
.chat-input-area .send-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.chat-input-area .send-btn:hover:not(:disabled)::before {
  opacity: 1;
}

.chat-input-area .send-btn:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
}

.chat-input-area .send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.chat-input-area .send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

/* API Key 设置弹窗 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 540px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-primary);
}

.modal-header .close-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: var(--text-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-header .close-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
}

/* API配置列表 */
.api-config-item {
  padding: var(--space-md);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  position: relative;
  background: var(--color-bg);
  transition: var(--transition);
}

.api-config-item:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

.api-config-item .form-row {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.api-config-item .form-group {
  flex: 1;
}

.api-config-item label {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-xs);
  font-weight: 500;
}

.api-config-item input,
.api-config-item select {
  width: 100%;
  padding: 6px var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  outline: none;
}

.api-config-item input:focus,
.api-config-item select:focus {
  border-color: var(--color-accent);
}

.api-config-item .remove-btn {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: var(--text-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.api-config-item .remove-btn:hover {
  color: var(--color-error);
}

.modal-footer .btn {
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: var(--transition);
}

.modal-footer .btn:hover {
  background: var(--color-surface-hover);
}

.modal-footer .btn.primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.modal-footer .btn.primary:hover {
  background: var(--color-primary-light);
}

/* 代码块包装器 */
.code-block-wrapper {
  position: relative;
  margin: var(--space-lg) 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--color-primary-dark);
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.code-lang-label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-sans);
}
.copy-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(4px);
}
.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}
.copy-code-btn.copied {
  background: rgba(46, 160, 67, 0.2);
  color: #2ea043;
  border-color: rgba(46, 160, 67, 0.3);
}
/* 代码块在 wrapper 中去掉顶部圆角（和 header 衔接） */
.code-block-wrapper .code-block,
.code-block-wrapper pre {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin: 0;
  background: var(--color-primary-dark) !important;
  color: #f8fafc !important;
}

.code-block-wrapper code {
  color: inherit !important;
}

/* ===== Hero 首页样式 ===== */
.hero-section {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.hero-bg {
  position: absolute;
  inset: 0;
  background: var(--gradient-hero);
  opacity: 0.04;
  animation: heroGradientShift 8s ease infinite;
}
[data-theme="dark"] .hero-bg {
  opacity: 0.15;
}
@keyframes heroGradientShift {
  0%, 100% { opacity: 0.06; transform: scale(1); }
  50% { opacity: 0.1; transform: scale(1.05); }
}
.hero-content {
  text-align: center;
  position: relative;
  z-index: 2;
  max-width: 720px;
}
.hero-content .cover-badge {
  display: inline-block;
  padding: 6px 20px;
  border: 1px solid var(--color-primary);
  border-radius: 100px;
  font-size: var(--text-xs);
  color: var(--color-primary);
  letter-spacing: 0.08em;
  margin-bottom: var(--space-lg);
  background: rgba(79, 70, 229, 0.08);
}
.hero-title {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: var(--space-md);
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-info) 60%, var(--color-success) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
[data-theme="dark"] .hero-title {
  background: linear-gradient(135deg, #f8fafc 0%, #818cf8 60%, #10b981 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
  line-height: 1.6;
}
.hero-btn-group {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}
.hero-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px 28px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-sans);
}
.hero-btn.primary {
  background: var(--gradient-accent);
  color: white;
  border: none;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
}
.hero-btn.primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.4);
}
.hero-btn.secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.hero-btn.secondary:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.hero-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
  margin: var(--space-xl) 0;
  padding: var(--space-lg) var(--space-md);
  background: var(--color-surface);
  border-radius: 12px;
  border: 1px solid var(--color-border);
}
.hero-stat-item {
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  position: relative;
  flex: 1;
  min-width: 80px;
}
.hero-stat-item:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 20%;
  height: 60%;
  width: 1px;
  background: var(--color-border);
}
.hero-stat-item .stat-num {
  font-size: 32px;
  font-weight: 800;
  color: var(--color-primary);
  display: block;
  line-height: 1.2;
}
.hero-stat-item .stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* Agent 循环动画 */
.hero-agent-loop {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: var(--space-xl);
  opacity: 0.7;
}
[data-theme="dark"] .hero-agent-loop {
  opacity: 0.9;
}
.hero-loop-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: var(--transition);
}
.hero-loop-step .loop-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.hero-loop-step .loop-arrow {
  color: var(--color-accent);
  font-size: 16px;
}
.hero-loop-step:nth-child(1) .loop-icon { animation: loopPulse 3s ease infinite 0s; }
.hero-loop-step:nth-child(2) .loop-icon { animation: loopPulse 3s ease infinite 0.6s; }
.hero-loop-step:nth-child(3) .loop-icon { animation: loopPulse 3s ease infinite 1.2s; }
.hero-loop-step:nth-child(4) .loop-icon { animation: loopPulse 3s ease infinite 1.8s; }
.hero-loop-step:nth-child(5) .loop-icon { animation: loopPulse 3s ease infinite 2.4s; }
@keyframes loopPulse {
  0%, 70%, 100% { border-color: var(--color-border); background: var(--color-surface); transform: scale(1); }
  35% { border-color: var(--color-accent); background: rgba(79, 70, 229, 0.1); transform: scale(1.1); }
}

/* 章节地图横向滚动 */
.hero-chapter-map {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}
.hero-map-title {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-md);
  text-align: center;
}
.hero-map-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: var(--space-sm);
  scrollbar-width: thin;
}
.hero-map-scroll::-webkit-scrollbar { height: 3px; }
.hero-map-scroll::-webkit-scrollbar-thumb { background: var(--color-border-dark); border-radius: 2px; }
.hero-map-card {
  flex: 0 0 auto;
  min-width: 100px;
  padding: 8px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: var(--text-xs);
  text-align: center;
}
.hero-map-card:hover {
  border-color: var(--color-accent);
  background: rgba(79, 70, 229, 0.06);
  transform: translateY(-2px);
}
.hero-map-card .map-num {
  font-weight: 700;
  color: var(--color-accent);
  font-size: 15px;
  display: block;
}
.hero-map-card .map-title {
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* 骨架屏 */
.skeleton-loader {
  padding: var(--space-xl);
}
.skeleton-line {
  height: 16px;
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-border-light) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  border-radius: 8px;
  margin-bottom: var(--space-md);
  animation: skeletonShimmer 1.5s ease-in-out infinite;
}
.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 70%; }
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 章节底部导航 */
.chapter-nav-bottom {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-sans);
  box-shadow: var(--shadow-sm);
}

.chapter-nav-btn:hover {
  border-color: var(--color-accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.chapter-nav-btn .nav-label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}
.chapter-nav-btn .nav-title {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
}
.chapter-nav-btn .nav-arrow {
  font-size: var(--text-lg);
  color: var(--color-accent);
}

/* 考试全屏遮罩 */
.exam-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 200;
  display: flex;
  overflow-y: auto;
}
.exam-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-xl);
}
.exam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-lg);
}
.exam-header h2 {
  font-size: var(--text-xl);
  color: var(--color-primary);
}
.exam-info {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.exam-close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: var(--text-lg);
  transition: var(--transition);
}
.exam-close-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-error);
}
.exam-progress-bar {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin-bottom: var(--space-lg);
}
.exam-progress-fill {
  height: 100%;
  background: var(--gradient-accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}
.exam-question {
  margin-bottom: var(--space-xl);
}
.exam-q-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
.exam-q-num {
  font-weight: 700;
  color: var(--color-accent);
}
.exam-q-type {
  padding: 2px 8px;
  border-radius: 100px;
  font-size: var(--text-xs);
  background: rgba(231, 111, 81, 0.06);
  color: var(--color-accent);
}
.exam-q-type.multi {
  background: rgba(69, 123, 157, 0.06);
  color: var(--color-info);
}
.exam-q-chapter {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}
.exam-q-text {
  font-size: var(--text-md);
  color: var(--color-text);
  margin-bottom: var(--space-md);
  line-height: 1.8;
}
.exam-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.exam-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: var(--text-sm);
  position: relative;
  user-select: none;
}
/* 隐藏原生 input，用自定义样式 */
.exam-option input[type="radio"],
.exam-option input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}
.exam-option input[type="radio"] {
  border-radius: 50%;
}
.exam-option input[type="radio"]:checked {
  border-color: var(--color-accent);
  background: var(--color-accent);
  box-shadow: inset 0 0 0 3px white;
}
.exam-option input[type="checkbox"]:checked {
  border-color: var(--color-accent);
  background: var(--color-accent);
}
.exam-option input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.exam-option:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
  transform: translateX(3px);
}
.exam-option.selected {
  border-color: var(--color-accent) !important;
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.12) 0%, rgba(212, 165, 116, 0.06) 100%) !important;
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.12);
  transform: translateX(3px);
}
.exam-option.selected::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}
.exam-option-text {
  color: var(--color-text-secondary);
}
.exam-option.selected .exam-option-text {
  color: var(--color-text);
  font-weight: 500;
}
.exam-footer {
  display: flex;
  justify-content: center;
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}
.exam-submit-btn {
  padding: 12px 32px;
  background: var(--gradient-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
  font-family: var(--font-sans);
}
.exam-submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.4);
}

/* 考试结果 */
.exam-result-header h2 {
  text-align: center;
  font-size: var(--text-xl);
}
.exam-score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  margin: var(--space-xl) auto var(--space-md);
  font-weight: 700;
}
.exam-score-circle.excellent {
  background: rgba(42, 157, 143, 0.1);
  border: 3px solid var(--color-success);
  color: var(--color-success);
}
.exam-score-circle.good {
  background: rgba(69, 123, 157, 0.1);
  border: 3px solid var(--color-info);
  color: var(--color-info);
}
.exam-score-circle.pass {
  background: rgba(233, 196, 106, 0.1);
  border: 3px solid var(--color-warning);
  color: var(--color-warning);
}
.exam-score-circle.fail {
  background: rgba(231, 111, 81, 0.1);
  border: 3px solid var(--color-error);
  color: var(--color-error);
}
.exam-score-circle .score-num { font-size: 36px; }
.exam-score-circle .score-unit { font-size: var(--text-sm); }
.exam-grade {
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-md);
}
.exam-advice {
  text-align: center;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}
.exam-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
}
.exam-stat {
  text-align: center;
}
.exam-stat .stat-val {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-primary);
  display: block;
}
.exam-stat .stat-key {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}
.exam-weak-chapters {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.exam-weak-chapters h3 {
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
}
.exam-wrong-list h3 {
  color: var(--color-primary);
  margin-bottom: var(--space-md);
}
.exam-wrong-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}
.wrong-q-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}
.wrong-q-num { font-weight: 700; color: var(--color-error); }
.wrong-q-chapter { font-size: var(--text-xs); color: var(--color-text-tertiary); }
.wrong-q-text { font-size: var(--text-sm); margin-bottom: var(--space-sm); }
.wrong-q-answer { display: flex; gap: var(--space-md); font-size: var(--text-xs); margin-bottom: var(--space-xs); }
.wrong-user { color: var(--color-error); }
.wrong-correct { color: var(--color-success); }
.wrong-explanation { font-size: var(--text-xs); color: var(--color-text-secondary); padding-left: 8px; border-left: 2px solid var(--color-border); }
.exam-result-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  margin-top: var(--space-xl);
}

/* 信息/提示 banner */
.info-banner, .tip-banner {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-sm);
}
.info-banner { border-left: 4px solid var(--color-info); }
.tip-banner { border-left: 4px solid var(--color-success); }
.banner-title {
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* ===== Prism.js 主题覆盖 ===== */
pre[class*="language-"],
code[class*="language-"] {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  background: var(--color-primary-dark);
  color: #c9d1d9;
}
[data-theme="dark"] pre[class*="language-"],
[data-theme="dark"] code[class*="language-"] {
  background: #161b22;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #6e7681; }
.token.punctuation { color: #c9d1d9; }
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol { color: #79c0ff; }
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin { color: #a5d6ff; }
.token.operator,
.token.entity,
.token.url { color: #d2a8ff; }
.token.atrule,
.token.attr-value,
.token.keyword { color: #ff7b72; }
.token.function,
.token.class-name { color: #d2a8ff; }
.token.regex,
.token.important,
.token.variable { color: #ffa657; }


/* ===== 响应式 ===== */
@media (max-width: 1200px) {
  :root {
    --chat-width: 320px;
    --sidebar-width: 240px;
  }
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar, .chat-panel {
    display: none;
  }
  .sidebar.mobile-show, .chat-panel.mobile-show {
    display: flex;
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: 100%;
  }
  .sidebar.mobile-show { left: 0; }
  .chat-panel.mobile-show { right: 0; }
  .hero-title { font-size: 28px; }
  .hero-stats { gap: var(--space-md); }
  .hero-stat-item .stat-num { font-size: 22px; }
  .hero-agent-loop { gap: 12px; }
}

/* ========================================
   Chapter Tabs - 精致小标签：文章/八股/面试
   ======================================== */

/* ===== 章节书签 Tab 导航 ===== */

/* 导航栏容器 */
.chapter-tabs-nav {
  display: flex;
  gap: 2px;
  padding: 10px 0 0;
  margin-bottom: 24px;
  margin-left: auto;
  margin-right: auto;
  border-bottom: 2px solid var(--color-border);
  position: sticky;
  top: 57px;
  z-index: 9;
  background: var(--color-surface);
  transition: box-shadow 0.2s ease;
  max-width: var(--content-max);
}

/* 吸顶时增加阴影和背景毛玻璃效果，视觉分隔更清晰 */
.chapter-tabs-nav.is-stuck {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .chapter-tabs-nav.is-stuck {
  background: rgba(30, 41, 59, 0.92);
}

/* 单个 Tab 按钮 */
.chapter-tab-btn {
  position: relative;
  padding: 10px 22px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 0;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}

/* Tab 图标 */
.chapter-tab-btn .tab-icon {
  font-size: 15px;
  line-height: 1;
}

/* Tab 计数徽章 */
.chapter-tab-btn .tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-border);
  color: var(--color-text-secondary);
  transition: background 0.2s ease, color 0.2s ease;
}

/* hover 态 */
.chapter-tab-btn:hover {
  color: var(--color-text);
}

.chapter-tab-btn:hover .tab-badge {
  background: var(--color-border-dark);
  color: var(--color-text);
}

/* 激活态 — 底部指示线 + 强调色 */
.chapter-tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
  font-weight: 600;
}

.chapter-tab-btn.active .tab-badge {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

/* ===== 深色主题适配 ===== */
[data-theme="dark"] .chapter-tabs-nav {
  background: var(--color-surface);
  border-bottom-color: var(--color-border);
}

[data-theme="dark"] .chapter-tab-btn {
  color: var(--color-text-secondary);
}

[data-theme="dark"] .chapter-tab-btn:hover {
  color: var(--color-text);
}

[data-theme="dark"] .chapter-tab-btn.active {
  color: var(--color-accent-light);
  border-bottom-color: var(--color-accent-light);
}

[data-theme="dark"] .chapter-tab-btn .tab-badge {
  background: var(--color-border-dark);
  color: var(--color-text-secondary);
}

[data-theme="dark"] .chapter-tab-btn.active .tab-badge {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

/* ===== 面板容器 ===== */
.chapter-panels-container {
  position: relative;
}

/* 内容面板 */
.chapter-tab-panel {
  display: none;
  padding: 8px 0;
  min-height: 200px;
}

.chapter-tab-panel.active {
  display: block;
}

/* 标签页内的 qa-item 微调 */
.chapter-tab-panel .qa-item,
[data-tab-section="bagu"] .qa-item {
  margin-bottom: var(--space-md);
}

/* 标签页内的 quiz 微调 */
.chapter-tab-panel #quizArea,
[data-tab-section="quiz"] #quizArea {
  padding: 0;
}

/* 标签页隐藏类 */
.tab-hidden {
  display: none !important;
}

/* ===== 移动端响应式适配 ===== */
@media (max-width: 1024px) {
  /* 中等屏幕：隐藏 TOC 面板，保留侧边栏和内容区 */
  .app-layout {
    grid-template-columns: var(--sidebar-width) 1fr !important;
  }
  .toc-panel {
    display: none !important;
  }
}

@media (max-width: 768px) {
  /* 平板/手机：隐藏侧边栏和聊天栏，改为抽屉式 */
  .app-layout {
    grid-template-columns: 1fr !important;
    grid-template-areas: "content" !important;
  }

  /* 侧边栏改为抽屉 */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* 聊天面板改为底部抽屉 */
  .chat-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    top: auto;
    height: 60vh;
    width: 100% !important;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .chat-panel.mobile-open {
    transform: translateY(0);
  }

  /* 右侧工具栏改为底部固定 */
  .right-toolbar {
    position: fixed;
    bottom: 16px;
    right: 16px;
    flex-direction: row !important;
    z-index: 999;
  }

  /* 内容区占满宽度 */
  .content-area {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Tab 书签在小屏幕上紧凑显示 */
  .chapter-tab-btn {
    padding: 8px 14px;
    font-size: var(--text-xs);
  }
  .chapter-tab-btn .tab-icon {
    font-size: 13px;
  }

  /* 代码块横向滚动 */
  .code-block-wrapper pre {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  /* 手机端进一步缩小 */
  .chapter-tab-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
  .chapter-tab-btn .tab-badge {
    min-width: 16px;
    height: 16px;
    font-size: 10px;
  }
  .content-header {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* ===== 回到顶部按钮 ===== */
.back-to-top {
  position: fixed;
  bottom: 40px;
  right: 420px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
  z-index: 100;
  font-size: 20px;
}

.back-to-top:hover {
  background: var(--color-accent-dark);
  box-shadow: var(--shadow-lg);
  transform: translateY(0) scale(1.08);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

[data-theme="dark"] .back-to-top {
  background: var(--color-accent-light);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .back-to-top:hover {
  background: var(--color-accent);
}

/* 响应式：小屏调整位置 */
@media (max-width: 1200px) {
  .back-to-top {
    right: 30px;
    bottom: 30px;
  }
}
