/* ============================================================
 * AI 导论课程 · 样式
 * 浅色主题，简洁学术风
 * ============================================================ */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #1a1d24;
  --ink-2: #4a5160;
  --ink-3: #8a919e;
  --line: #e6e9ee;
  --accent: #2f6bff;
  --accent-soft: #eaf0ff;
  --accent-ink: #1d4ed8;
  --good: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 8px 24px rgba(20, 30, 60, 0.06);
  --shadow-lg: 0 12px 40px rgba(20, 30, 60, 0.16);
  --sidebar-w: 288px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  z-index: 60;
}
.topbar-inner {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-weight: 700; font-size: 13px;
  border-radius: 9px;
}
.brand-text { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.site-return { font-size: 13px; text-decoration: none; white-space: nowrap; }
.site-return:hover { text-decoration: underline; }

.lang-toggle {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.lang-toggle:hover { border-color: var(--accent); color: var(--accent-ink); }
.lang-toggle .lang-sep { margin: 0 3px; color: var(--ink-3); }
.lang-toggle[data-active="zh"] .lang-zh { color: var(--accent-ink); font-weight: 700; }
.lang-toggle[data-active="en"] .lang-en { color: var(--accent-ink); font-weight: 700; }

.menu-toggle {
  display: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 9px;
  width: 38px; height: 38px;
  font-size: 18px; cursor: pointer;
}

/* ---------- 布局 ---------- */
.layout {
  display: flex;
  padding-top: var(--topbar-h);
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  width: var(--sidebar-w);
  padding: 24px 16px 40px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.sidebar-head { padding: 0 8px 16px; }
.sidebar-title { font-weight: 700; font-size: 15px; }
.progress-wrap { margin-top: 14px; }
.progress-bar {
  height: 6px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), #7c3aed);
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-text { margin-top: 6px; font-size: 12px; color: var(--ink-3); }

.toc { display: flex; flex-direction: column; gap: 2px; }
.toc-chapter { margin-top: 10px; }
.toc-chapter > .toc-chapter-btn {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border: none; background: none;
  text-align: left; cursor: pointer;
  border-radius: 9px;
  font-family: var(--font);
}
.toc-chapter > .toc-chapter-btn:hover { background: var(--surface-2); }
.toc-num {
  font-family: var(--mono);
  font-size: 12px; color: var(--ink-3);
  min-width: 22px;
}
.toc-chapter-title { font-size: 14px; font-weight: 600; color: var(--ink); flex: 1; }
.toc-chapter.active > .toc-chapter-btn { background: var(--accent-soft); }
.toc-chapter.active .toc-chapter-title { color: var(--accent-ink); }
.toc-chapter.active .toc-num { color: var(--accent-ink); }

.toc-sections { margin: 2px 0 4px 32px; display: flex; flex-direction: column; gap: 1px; border-left: 2px solid var(--line); padding-left: 8px; }
.toc-section-btn {
  width: 100%;
  padding: 6px 8px;
  border: none; background: none;
  text-align: left; cursor: pointer;
  border-radius: 7px;
  font-family: var(--font);
  font-size: 13px; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.toc-section-btn:hover { background: var(--surface-2); color: var(--ink); }
.toc-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--line); flex: none;
}
.toc-section-btn.visited .toc-dot { background: var(--good); }
.toc-section-btn.active { color: var(--accent-ink); font-weight: 600; }
.toc-section-btn.active .toc-dot { background: var(--accent); }

/* ---------- 主内容 ---------- */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 40px 48px 80px;
  max-width: calc(100% - var(--sidebar-w));
}

.hero { margin-bottom: 40px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.hero-eyebrow { font-size: 14px; color: var(--accent-ink); margin: 0 0 10px; }
.hero-title { font-size: 40px; font-weight: 800; letter-spacing: -0.5px; margin: 0 0 10px; }
.hero-instructor { font-size: 14px; color: var(--ink-2); margin: 0 0 12px; }
.hero-note { font-size: 13px; color: var(--ink-3); font-style: italic; margin: 0; }

/* 章节块 */
.chapter {
  margin: 56px 0;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.chapter-head {
  display: flex; align-items: baseline; gap: 14px;
  padding-bottom: 14px; margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.chapter-num {
  font-family: var(--mono);
  font-size: 15px; color: var(--accent-ink);
  font-weight: 700;
}
.chapter-title { font-size: 24px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }

/* 小节 */
.section {
  margin: 28px 0;
  padding: 24px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.section-title { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.section-intro { font-size: 15px; color: var(--ink-2); margin: 0 0 16px; }
.section-body p { margin: 0 0 12px; font-size: 15px; }
.section-body p:last-child { margin-bottom: 0; }

.keypoints {
  margin: 18px 0 0;
  padding: 14px 18px;
  background: var(--accent-soft);
  border-radius: 10px;
}
.keypoints-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--accent-ink);
  margin: 0 0 8px;
}
.keypoints ul { margin: 0; padding-left: 18px; }
.keypoints li { margin: 4px 0; font-size: 14px; }

/* 交互演示 */
.demo {
  margin-top: 22px;
  border-top: 1px dashed var(--line);
  padding-top: 20px;
}
.demo-title { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.demo-hint { font-size: 13px; color: var(--ink-3); margin: 0 0 14px; }
.demo-stage {
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
}
.demo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.demo-controls label { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.demo-controls input[type="range"] { width: 130px; accent-color: var(--accent); }
.demo-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.demo-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.demo-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.demo-btn.primary:hover { background: var(--accent-ink); }
.demo-stat { font-size: 13px; color: var(--ink-2); font-family: var(--mono); margin-left: auto; }
.demo-readout { font-size: 13px; color: var(--ink-3); margin-top: 10px; line-height: 1.6; }

/* SVG 可视化 */
.viz-svg { display: block; width: 100%; height: auto; }
.viz text { font-family: var(--font); }

/* 页脚 */
.foot { margin-top: 60px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-3); }

/* ---------- AI 问答助手 ---------- */
.qa-fab {
  position: fixed;
  right: 26px; bottom: 26px;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  transition: transform .15s;
}
.qa-fab:hover { transform: translateY(-2px); }
.qa-fab-icon { font-size: 16px; }

.qa-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 24, 34, 0.28);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 90;
}
.qa-backdrop.open { opacity: 1; pointer-events: auto; }

.qa-panel {
  position: fixed;
  right: 26px; bottom: 88px;
  width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 140px));
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; transform: translateY(12px) scale(.98);
  pointer-events: none;
  transition: all .2s ease;
  z-index: 95;
}
.qa-panel.open { opacity: 1; transform: none; pointer-events: auto; }

.qa-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, var(--accent-soft), #f3ecff);
}
.qa-title { font-weight: 700; font-size: 15px; }
.qa-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.qa-close {
  border: none; background: none; color: var(--ink-3);
  font-size: 18px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px;
}
.qa-close:hover { background: rgba(0,0,0,.06); color: var(--ink); }

.qa-messages {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.qa-msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.qa-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.qa-msg.assistant { align-self: flex-start; background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 4px; }
.qa-msg.error { align-self: flex-start; background: #fdecec; color: #b3261e; }
.qa-msg .cursor { display: inline-block; width: 7px; height: 15px; background: var(--ink-3); margin-left: 2px; vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.qa-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 16px; background: var(--surface-2); border-radius: 14px; border-bottom-left-radius: 4px; }
.qa-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: bounce 1.2s infinite; }
.qa-typing span:nth-child(2) { animation-delay: .15s; }
.qa-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

.qa-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.qa-input textarea {
  flex: 1; resize: none;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-family: var(--font); font-size: 14px;
  max-height: 120px; line-height: 1.5;
}
.qa-input textarea:focus { outline: none; border-color: var(--accent); }
.qa-send {
  border: none; background: var(--accent); color: #fff;
  width: 40px; height: 40px; border-radius: 10px;
  font-size: 18px; cursor: pointer; flex: none;
}
.qa-send:disabled { background: var(--ink-3); cursor: not-allowed; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar {
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
    z-index: 70;
  }
  .sidebar.open { visibility: visible; transform: translateX(0); }
  .menu-toggle { display: block; }
  .content { margin-left: 0; max-width: 100%; padding: 28px 20px 60px; }
  .hero-title { font-size: 32px; }
}

@media (max-width: 480px) {
  .topbar-inner { padding: 0 12px; }
  .topbar-actions { gap: 8px; }
  .brand-text { display: none; }
  .lang-toggle { padding: 6px 10px; }
  .qa-panel { right: 16px; }
}
