:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --border: #e6e8ef;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --green: #16a34a;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.78;
  font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 20px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  color: var(--muted); padding: 6px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
}
.topnav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

/* 顶栏搜索 */
.topsearch { margin-left: auto; position: relative; }
.topsearch input {
  width: 200px; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-size: 14px; background: var(--bg);
  transition: width .2s, border-color .12s;
}
.topsearch input:focus { outline: none; border-color: var(--accent); width: 260px; }

/* 移动端顶栏：brand+搜索一行，导航横向滚动 */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .brand { order: 1; }
  .topsearch { order: 2; flex: 1; margin-left: 0; }
  .topsearch input { width: 100%; }
  .topsearch input:focus { width: 100%; }
  .topnav { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topnav a { white-space: nowrap; flex-shrink: 0; }
  .search-results { left: 0; right: auto; width: 100%; }
}
.search-results {
  position: absolute; top: 42px; right: 0; width: 320px; max-height: 420px; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(16,24,40,.18); z-index: 80; padding: 6px;
}
.search-results .sr-item {
  display: block; padding: 9px 12px; border-radius: 7px; cursor: pointer;
  color: var(--text); text-decoration: none;
}
.search-results .sr-item:hover { background: var(--accent-soft); }
.search-results .sr-item .t { font-size: 14px; font-weight: 600; }
.search-results .sr-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.search-results .sr-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

.app { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
}
.badge.adv { background: var(--amber-soft); color: var(--amber); }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--red-soft); color: var(--red); }
.badge.muted { background: #f3f4f6; color: var(--muted); }

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

.progress { background: #eef0f5; border-radius: 999px; height: 8px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- 首页 ---------- */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .home-grid { grid-template-columns: 1fr; } }
.hero { padding: 28px 24px; }
.hero h1 { margin: 0 0 6px; font-size: 24px; }
.hero .cta { margin-top: 16px; }
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 120px; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: 13px; }

.course-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; background: var(--panel);
}
.course-item:hover { border-color: var(--accent); }
.course-item .t { font-weight: 600; }

/* ---------- 课程目录 ---------- */
.toc-chapter { border-left: 3px solid var(--accent); padding-left: 12px; margin-bottom: 20px; }
.toc-chapter h3 { margin: 0 0 8px; font-size: 16px; }
.toc-section {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.toc-section:hover { background: var(--accent-soft); }
.toc-section .sid { color: var(--muted); font-size: 12px; min-width: 34px; }
.toc-section.learned .tt::after { content: " ✓"; color: var(--green); }
.toc-section.active .tt { font-weight: 700; color: var(--accent); }
.toc-chapter-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--muted); margin: 6px 0 2px; cursor: pointer;
  padding: 4px 6px; border-radius: 6px; font-weight: 600;
}
.toc-chapter-header:hover { background: var(--accent-soft); }
.toc-toggle { font-size: 10px; }

/* ---------- 学习页（三栏） ---------- */
.learn-grid {
  display: grid; grid-template-columns: 250px minmax(0,1fr) 320px;
  gap: 16px; align-items: start;
}
/* 移动端 Tab 切换栏（默认隐藏） */
.learn-tabs { display: none; }

@media (max-width: 1100px) { .learn-grid { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  .learn-tabs {
    display: flex; gap: 6px; margin-bottom: 10px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 6px;
    position: sticky; top: 56px; z-index: 40;
  }
  .learn-tabs button {
    flex: 1; border: none; background: none; padding: 8px 4px;
    border-radius: 7px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
  }
  .learn-tabs button.active { background: var(--accent-soft); color: var(--accent); }
  /* 移动端：三栏默认都隐藏，由 Tab 控制显示 */
  .learn-grid .col { display: none; max-height: none; position: static; }
  .learn-grid.show-content .col-content { display: block; }
  .learn-grid.show-toc .col-toc { display: block; }
  .learn-grid.show-agent .col-agent { display: block; }
}
.col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.col-toc { padding: 12px; max-height: calc(100vh - 90px); overflow: auto; position: sticky; top: 72px; }
.col-toc .vol-tab { font-size: 13px; font-weight: 700; margin: 8px 0 4px; color: var(--muted); }

.col-content { padding: 28px 36px; }
.col-agent { padding: 14px; max-height: calc(100vh - 90px); overflow: auto; position: sticky; top: 72px; display: flex; flex-direction: column; }

/* 教学内容排版（宽松） */
.lesson h1 { margin: 0 0 8px; font-size: 22px; line-height: 1.4; }
.lesson .sec-meta { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.lesson section { margin-bottom: 32px; }
.lesson section > h2 {
  font-size: 16px; padding-bottom: 8px; margin-bottom: 14px;
  border-bottom: 2px solid var(--accent-soft);
  display: flex; align-items: center; gap: 8px;
}
.theorem, .example, .pitfall, .pattern {
  border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin: 14px 0;
}
.theorem { border-left: 4px solid var(--accent); background: #fbfbfe; }
.theorem .th-name { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.theorem .th-part { margin-top: 10px; font-size: 14px; line-height: 1.75; }
.theorem .th-part b { color: var(--text); }
.example { border-left: 4px solid var(--green); }
.example .ex-head { font-weight: 700; color: var(--green); display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.example .th-part { line-height: 1.75; }
.pitfall { border-left: 4px solid var(--red); background: #fffbfb; }
.pitfall .pf-head { font-weight: 700; color: var(--red); margin-bottom: 4px; }
.pattern { border-left: 4px solid var(--amber); background: #fffefb; }
.pattern .pa-head { font-weight: 700; color: var(--amber); margin-bottom: 4px; }

.lesson-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.status-row { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* 公式块 */
.math-block { overflow-x: auto; padding: 10px 0; }

/* ---------- 答疑面板 ---------- */
.qa-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  background: var(--accent); color: #fff; padding: 12px 18px;
  border-radius: 999px; cursor: pointer; font-weight: 600;
  box-shadow: 0 4px 14px rgba(79,70,229,.4);
}
.qa-fab:hover { background: #4338ca; }
.qa-panel {
  position: fixed; right: 22px; bottom: 78px; z-index: 60;
  width: 380px; max-width: calc(100vw - 32px); height: 480px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 8px 30px rgba(16,24,40,.18);
  display: flex; flex-direction: column; overflow: hidden;
}
.qa-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.icon-btn { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.qa-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.qa-msg { max-width: 88%; padding: 10px 13px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.qa-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.qa-msg.ai { align-self: flex-start; background: #f1f2f6; border-bottom-left-radius: 3px; }
.qa-msg.ai.err { background: var(--red-soft); color: var(--red); }
.qa-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.qa-input-row textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font: inherit; font-size: 14px;
}
.qa-input-row textarea:focus { outline: none; border-color: var(--accent); }

/* ---------- 练习 ---------- */
.practice-config { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.practice-config label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.practice-config select, .practice-config input {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 14px; background: #fff;
}
.question-card { padding: 16px 18px; }
.question-card .q-text { font-size: 15px; margin: 12px 0; line-height: 1.8; }
.options label { display: block; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0; cursor: pointer; line-height: 1.6; }
.options label:hover { border-color: var(--accent); }
.options label.sel { border-color: var(--accent); background: var(--accent-soft); }
.options label.right { border-color: var(--green); background: var(--green-soft); }
.options label.wrong { border-color: var(--red); background: var(--red-soft); }
.reveal { margin-top: 10px; padding: 10px 12px; background: var(--accent-soft); border-radius: 8px; font-size: 14px; }

/* ---------- 设置 ---------- */
.settings-form { max-width: 560px; }
.settings-form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 14px; font-weight: 500; }
.settings-form input, .settings-form select {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font: inherit; font-size: 14px;
}
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  z-index: 100; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

/* KaTeX 溢出保护 */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; scrollbar-width: thin; }.katex { scrollbar-width: thin; }
/* 移动端公式缩放，避免长公式溢出 */
@media (max-width: 768px) {
  .katex-display { font-size: 0.85em; }
  .katex { font-size: 0.92em; }
}

/* 表格 */
table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; }
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
th { background: #f7f8fb; font-weight: 600; }
blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--accent); background: #f7f8fb; color: var(--muted); }
pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
code { background: #eef0f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
pre code { background: none; padding: 0; color: inherit; }
.md p { margin: 12px 0; line-height: 1.8; }
.md h1, .md h2, .md h3 { margin: 16px 0 10px; line-height: 1.4; }
.md ul, .md ol { margin: 10px 0; padding-left: 24px; }
.md li { margin: 5px 0; line-height: 1.75; }

/* 页脚作者标识（不起眼） */
.site-footer {
  text-align: center; padding: 18px 0 24px;
  font-size: 12px; color: #b6bac4; opacity: .8;
  letter-spacing: .5px;
}
