/* ========== 基础变量与重置 ========== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --text: #1f2937;
  --text-sub: #6b7280;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(30, 41, 59, 0.08);
}

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

/* hidden 属性必须生效（内联 display 会覆盖 UA 默认样式，需强制） */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}

button { font-family: inherit; cursor: pointer; }
select, textarea, input { font-family: inherit; font-size: 14px; }

/* ========== 顶部栏 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  box-shadow: 0 2px 10px rgba(30, 58, 138, 0.35);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px; height: 44px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
}
.brand-logo svg { width: 28px; height: 28px; }
.brand-text h1 { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 12px; opacity: 0.85; letter-spacing: 2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; position: relative; }

/* 移动端菜单按钮（桌面端隐藏） */
.mobile-menu-btn { display: none; }
.mobile-menu-dropdown { display: none; }

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
}
.badge-on { background: var(--success-light); color: #14532d; }
.badge-off { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* ========== 按钮 ========== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.18s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; transform: translateY(-1px); }
.btn-ghost { background: rgba(255, 255, 255, 0.12); color: #fff; border: 1px solid rgba(255, 255, 255, 0.3); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.25); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ========== 布局 ========== */
.main { display: flex; min-height: calc(100vh - 68px); }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 14px;
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
}
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-sub);
  text-align: left;
  transition: all 0.15s ease;
  position: relative;
}
.nav-item:hover { background: #f0f4ff; color: var(--primary); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }
.nav-icon {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}
.nav-item:not(.active) .nav-icon { background: var(--text-sub); opacity: 0.5; }
.nav-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}
.nav-count[hidden] { display: none !important; }

.sidebar-foot { padding: 10px 6px; }
.book-info { font-size: 12px; color: var(--text-sub); line-height: 1.6; }
.book-info strong { color: var(--primary); }

.content {
  flex: 1;
  padding: 26px 30px 60px;
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

/* ========== 通用卡片与区块 ========== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
  border: 1px solid rgba(229, 231, 235, 0.6);
}
.page-head { margin-bottom: 20px; }
.page-head h2 { font-size: 22px; font-weight: 800; }
.page-head p { color: var(--text-sub); font-size: 13.5px; margin-top: 4px; }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ''; width: 4px; height: 18px; background: var(--primary); border-radius: 2px; }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.chip-blue { background: var(--primary-light); color: var(--primary-dark); }
.chip-green { background: var(--success-light); color: #14532d; }
.chip-red { background: var(--danger-light); color: var(--danger); }
.chip-orange { background: var(--warning-light); color: var(--warning); }
.chip-gray { background: #f3f4f6; color: var(--text-sub); }

/* ========== 知识讲解 ========== */
.knowledge-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.tree-panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; position: sticky; top: 92px; max-height: calc(100vh - 120px); overflow-y: auto; }
.tree-chapter { margin-bottom: 6px; }
.tree-chapter-btn {
  width: 100%; text-align: left;
  padding: 10px 12px;
  border: none; border-radius: 10px;
  background: #f0f4ff; color: var(--primary-dark);
  font-weight: 700; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.tree-chapter-btn .arrow { transition: transform 0.2s; font-size: 12px; }
.tree-chapter.open .tree-chapter-btn .arrow { transform: rotate(90deg); }
.tree-chapter-body { display: none; padding: 8px 4px 8px 10px; }
.tree-chapter.open .tree-chapter-body { display: block; }
.tree-section { margin-bottom: 8px; }
.tree-section-title { font-size: 13px; font-weight: 700; color: var(--text-sub); margin: 6px 0 4px; }
.tree-kp {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: none; border-radius: 8px;
  background: transparent; font-size: 13.5px; color: var(--text);
  transition: all 0.12s;
}
.tree-kp:hover { background: #f0f4ff; color: var(--primary); }
.tree-kp.active { background: var(--primary); color: #fff; }

.kp-card .kp-title { font-size: 19px; font-weight: 800; margin-bottom: 14px; }
.kp-block { margin-bottom: 16px; }
.kp-block h4 {
  font-size: 14px; font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  display: inline-block;
}
.kp-concept h4 { background: var(--primary-light); color: var(--primary-dark); }
.kp-points h4 { background: #f0f4ff; color: #3730a3; }
.kp-example h4 { background: var(--success-light); color: #14532d; }
.kp-pitfall h4 { background: var(--danger-light); color: var(--danger); }
.kp-memory h4 { background: var(--warning-light); color: var(--warning); }
.kp-block p { font-size: 14.5px; }
.kp-block ul { padding-left: 20px; }
.kp-block li { margin-bottom: 4px; font-size: 14.5px; }
.example-box {
  background: #f8fafc;
  border-left: 3px solid var(--success);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
}
.example-box .q { font-weight: 700; margin-bottom: 6px; }
.memory-box {
  background: var(--warning-light);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
  color: #78350f;
}
.kp-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.ai-answer { margin-top: 14px; background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 10px; padding: 14px 16px; font-size: 14px; }
.ai-answer h5 { color: #0369a1; margin-bottom: 6px; }

/* ========== 表单 ========== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.form-field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.form-field select, .form-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
.form-field select:focus, .form-field input:focus { border-color: var(--primary); }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.form-row select, .form-row textarea, .form-row input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-row select:focus, .form-row textarea:focus, .form-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ========== 题目 ========== */
.question-card { border: 1.5px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; background: #fff; }
.question-card.wrong { border-color: var(--danger); background: #fffbfb; }
.question-card.right { border-color: var(--success); background: #fafffa; }
.q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.q-no {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.q-stem { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.q-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.q-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.12s;
  font-size: 14.5px;
}
.q-option:hover { border-color: var(--primary); background: #f5f8ff; }
.q-option.selected { border-color: var(--primary); background: var(--primary-light); font-weight: 600; }
.q-option input { display: none; }
.q-option .opt-key {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.q-option.selected .opt-key { background: var(--primary); color: #fff; border-color: var(--primary); }
.q-answer-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14.5px;
  outline: none;
}
.q-answer-input:focus { border-color: var(--primary); }
.q-feedback { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.q-feedback .fb-title { font-weight: 800; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.q-feedback .my-answer { margin-bottom: 6px; }
.q-feedback .analysis { margin-top: 6px; }

/* ========== 成绩单 ========== */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.score-item {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}
.score-item .num { font-size: 26px; font-weight: 800; color: var(--primary); }
.score-item .num.green { color: var(--success); }
.score-item .num.red { color: var(--danger); }
.score-item .label { font-size: 12.5px; color: var(--text-sub); margin-top: 2px; }

/* ========== 培优 ========== */
.star { color: var(--warning); letter-spacing: 2px; }
.difficulty-tag { display: inline-flex; align-items: center; gap: 4px; }
.deep-block { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.deep-hint { background: #fefce8; border-left: 3px solid var(--warning); }
.deep-solution { background: #f0fdf4; border-left: 3px solid var(--success); }
.deep-method { background: #eff6ff; border-left: 3px solid var(--primary); }
.deep-extension { background: #faf5ff; border-left: 3px solid #9333ea; }
.deep-block h5 { margin-bottom: 5px; font-size: 13.5px; }

/* ========== 错题本 ========== */
.wrong-item { border-left: 4px solid var(--danger); }
.wrong-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.wrong-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.wrong-answers .box { border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.wrong-answers .mine { background: var(--danger-light); }
.wrong-answers .correct { background: var(--success-light); }
.wrong-answers .box b { display: block; font-size: 12px; margin-bottom: 3px; }

/* ========== 统计 ========== */
.stat-bars { display: flex; flex-direction: column; gap: 12px; }
.stat-bar-row { display: grid; grid-template-columns: 120px 1fr 70px; align-items: center; gap: 12px; font-size: 13.5px; }
.stat-bar-track { height: 14px; background: #eef1f6; border-radius: 999px; overflow: hidden; }
.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa, #2563eb);
  transition: width 0.8s ease;
  min-width: 2px;
}
.stat-bar-row .pct { text-align: right; font-weight: 700; color: var(--primary); }
.empty-tip { text-align: center; color: var(--text-sub); padding: 40px 0; font-size: 14px; }
.empty-tip .big { font-size: 40px; margin-bottom: 8px; }

/* ========== 答疑浮层 ========== */
.qa-mask[hidden], .qa-drawer[hidden] { display: none !important; }
.qa-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 90;
}
.qa-drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 400px;
  max-width: 92vw;
  background: #fff;
  z-index: 100;
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.qa-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
}
.qa-head h3 { font-size: 16px; }
.qa-body { padding: 18px; overflow-y: auto; flex: 1; }
.qa-answer { margin-top: 14px; }
.qa-answer .answer-box {
  background: #f8fafc;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.qa-answer .answer-src { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.qa-loading { color: var(--text-sub); font-size: 13px; margin-top: 10px; }

/* ========== 答疑对话线程 ========== */
.qa-thread {
  max-height: 300px;
  overflow-y: auto;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qa-empty { text-align: center; color: var(--text-sub); font-size: 13px; padding: 18px 0; }
.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }
.msg-tag { font-size: 11px; color: var(--text-sub); margin-bottom: 3px; padding: 0 4px; }
.msg-bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.7;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.ai .msg-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ========== 提示条 ========== */
.notice {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.notice-info { background: var(--primary-light); color: var(--primary-dark); }
.notice-warn { background: var(--warning-light); color: #78350f; }

/* ========== 学生信息引导 ========== */
.profile-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.92), rgba(37, 99, 235, 0.92));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.profile-modal[hidden] { display: none !important; }
.editinfo-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.editinfo-modal[hidden] { display: none !important; }
.lg-error {
  margin: 4px 0 10px;
  padding: 8px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: 10px;
  font-size: 13px;
}
.profile-card {
  width: 420px;
  max-width: 100%;
  background: #fff;
  border-radius: 20px;
  padding: 36px 34px 30px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  animation: popIn 0.3s ease;
}
@keyframes popIn { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.profile-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  border-radius: 16px;
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-card h2 { text-align: center; font-size: 20px; font-weight: 800; }
.profile-sub { text-align: center; color: var(--text-sub); font-size: 13px; margin: 6px 0 22px; }
.req { color: var(--danger); }
.form-hint { font-size: 12px; color: var(--text-sub); margin-top: 4px; }
.btn-lg { padding: 13px 20px; font-size: 16px; }

/* 登录弹窗输入框美化 */
.profile-card .form-row input {
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.profile-card .form-row input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
  outline: none;
}
.profile-card .form-row input::placeholder {
  color: #94a3b8;
  font-weight: 400;
}
.profile-card .form-row label {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 7px;
}
#lg-submit {
  margin-top: 6px;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
#lg-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}
#lg-submit:active { transform: translateY(0); }

/* ========== 顶部学生信息 ========== */
.student-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 4px 6px 4px 14px;
  color: #fff;
  font-size: 13.5px;
}
.student-chip[hidden] { display: none; }
.student-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
  flex-shrink: 0;
}

/* ========== 实时讲解播放器 ========== */
.lecture-player {
  border: 1.5px solid var(--primary);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 18px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15);
  animation: slideDown 0.25s ease;
}
.lecture-player[hidden] { display: none; }
@keyframes slideDown { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.lecture-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
}
.lecture-title-line { display: flex; align-items: center; gap: 8px; }
.lecture-title { font-weight: 800; font-size: 15px; }
.lecture-live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f87171;
  animation: blink 1.2s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.lecture-progress { font-size: 13px; font-weight: 600; opacity: 0.95; }
.lecture-screen {
  min-height: 110px;
  padding: 20px 22px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.lecture-screen.loading { opacity: 0.6; }
.lecture-text {
  font-size: 17px;
  line-height: 1.9;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}
.lecture-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  flex-wrap: wrap;
  background: #fff;
}
.lecture-controls .btn { margin: 0; }
.speed-select {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  outline: none;
}
.speed-select:focus { border-color: var(--primary); }
.lp-close-btn { margin-left: auto; }

@media (max-width: 560px) {
  .lecture-controls { justify-content: center; }
  .lp-close-btn { margin-left: 0; }
}

/* ========== 添加教材弹窗 ========== */
.addtb-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.addtb-modal[hidden] { display: none !important; }
.addtb-card {
  width: 460px;
  max-width: 100%;
  max-height: 90vh;
  background: #fff;
  border-radius: 18px;
  padding: 28px 30px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  animation: popIn 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
#addtb-modal .addtb-card {
  padding: 22px 30px;
  max-height: 80vh;
}
.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--text-sub);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.15s;
}
.modal-close-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}
.addtb-card h3 { font-size: 18px; font-weight: 800; text-align: center; margin: 0 0 2px; flex-shrink: 0; }
.addtb-card .profile-sub { flex-shrink: 0; margin: 4px 0 10px; }
.addtb-card > *:not(.addtb-scroll):not(h3):not(.profile-sub):not(.preview-head):not([style*="display:flex"]) {
  flex-shrink: 0;
}
/* 预览区整体：内容决定高度，可收缩；内部树形区滚动，按钮栏固定底部 */
#addtb-preview {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
#addtb-preview .addtb-scroll {
  flex: 0 1 auto;
  overflow-y: auto;
  max-height: calc(80vh - 220px);
  min-height: 120px;
  margin: 4px -30px;
  padding: 4px 30px;
}
#addtb-preview > div:last-child {
  flex-shrink: 0;
  margin-top: 8px;
}
.addtb-scroll::-webkit-scrollbar { width: 6px; }
.addtb-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3.5px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== 实时讲解画中画 ========== */
.pip-window {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 336px;
  max-width: calc(100vw - 32px);
  z-index: 150;
  background: #fff;
  border: 1.5px solid var(--primary);
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.28);
  overflow: hidden;
  animation: pipIn 0.25s ease;
}
.pip-window[hidden] { display: none !important; }
@keyframes pipIn {
  from { transform: translateY(18px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.pip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 8px 14px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  cursor: move;
  user-select: none;
}
.pip-title { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; }
.pip-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f87171;
  animation: blink 1.2s infinite;
}
.pip-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.pip-close:hover { color: #fff; }
.pip-body {
  padding: 12px 14px;
  min-height: 56px;
  background: #f8fafc;
}
.pip-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  margin: 0;
}
.pip-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
}
.pip-btn {
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.pip-btn:hover { border-color: var(--primary); color: var(--primary); }
.pip-play { background: var(--primary); border-color: var(--primary); color: #fff; font-size: 12px; }
.pip-play:hover { background: var(--primary-dark); color: #fff; }
.pip-progress { margin-left: auto; font-size: 12px; color: var(--text-sub); font-weight: 600; }

/* ========== 教材目录预览确认 ========== */
.preview-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.pv-tree { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.pv-chapter { margin-bottom: 10px; }
.pv-chapter:last-child { margin-bottom: 0; }
.pv-ch-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.pv-no { font-size: 12.5px; font-weight: 800; color: var(--primary-dark); background: var(--primary-light); padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.pv-input { flex: 1; padding: 5px 9px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 13.5px; outline: none; min-width: 0; }
.pv-input:focus { border-color: var(--primary); }
.pv-del { border: 1px solid var(--danger); color: var(--danger); background: #fff; border-radius: 7px; font-size: 12px; padding: 3px 10px; cursor: pointer; white-space: nowrap; }
.pv-del:hover { background: var(--danger-light); }
.pv-sec { margin: 4px 0 4px 12px; padding: 5px 8px; background: #f8fafc; border-radius: 8px; }
.pv-sec-head { display: flex; align-items: center; gap: 7px; }
.pv-sec-no { font-size: 12px; font-weight: 700; color: var(--text-sub); white-space: nowrap; }
.pv-del-sm { border: none; background: none; color: var(--text-sub); font-size: 15px; cursor: pointer; padding: 0 2px; }
.pv-del-sm:hover { color: var(--danger); }
.pv-kps { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; padding-left: 4px; }
.pv-kp { font-size: 11.5px; background: #fff; border: 1px solid var(--border); color: var(--text-sub); padding: 1px 7px; border-radius: 999px; }

/* ========== 响应式（移动端） ========== */
@media (max-width: 820px) {
  /* 顶部栏精简 */
  .topbar { padding: 10px 12px; }
  .brand-logo { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
  .brand-text h1 { font-size: 15px; letter-spacing: 0.5px; }
  .brand-sub { display: none; }
  .topbar-right { gap: 8px; }
  .student-chip { font-size: 12px; padding: 4px 5px 4px 10px; gap: 6px; max-width: 132px; }
  .student-chip b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #ai-badge { display: none; }  /* 手机端隐藏长徽标，避免顶部换行拥挤 */
  #btn-qa { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }
  .btn-sm { padding: 5px 9px; }
  /* 移动端个人信息菜单 */
  .mobile-menu-btn { display: inline-flex !important; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; font-size: 16px; border-radius: 8px; }
  .mobile-menu-dropdown {
    position: absolute; top: calc(100% + 6px); right: 12px; z-index: 250;
    background: #fff; border-radius: 12px; box-shadow: 0 8px 28px rgba(15,23,42,0.18);
    min-width: 130px; overflow: hidden; animation: popIn 0.15s ease;
    display: none;
  }
  .mobile-menu-dropdown.show { display: block; }
  .mobile-menu-item {
    display: block; width: 100%; padding: 12px 16px; border: none; background: #fff;
    font-size: 14px; text-align: left; cursor: pointer; color: var(--text);
  }
  .mobile-menu-item:hover { background: var(--bg); }
  .mobile-menu-item:last-child { color: var(--danger); }

  /* 主布局：底部留出 Tab 导航空间 */
  .main { flex-direction: column; }
  .content { padding: 14px 12px calc(76px + env(safe-area-inset-bottom)); }

  /* 侧边导航 -> 底部 Tab（移动端最佳实践） */
  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    height: auto;
    z-index: 120;
    flex-direction: row;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.08);
  }
  .nav { flex-direction: row; width: 100%; gap: 2px; }
  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 7px 2px;
    font-size: 10.5px;
    justify-content: center;
    text-align: center;
    border-radius: 10px;
    white-space: normal;
    min-height: 48px;
    position: relative;
  }
  .nav-icon { width: 7px; height: 7px; }
  .nav-count { position: absolute; top: 3px; right: calc(50% - 26px); min-width: 16px; height: 16px; font-size: 9px; padding: 0 4px; }
  .sidebar-foot { display: none; }

  /* 知识讲解 */
  .knowledge-layout { grid-template-columns: 1fr; }
  .tree-panel { position: static; max-height: 300px; }
  .kp-title { font-size: 17px; }

  /* 实时讲解播放器：触控目标加大 */
  .lecture-screen { min-height: 96px; padding: 16px; }
  .lecture-text { font-size: 15.5px; }
  .lecture-controls { gap: 6px; padding: 10px; }
  .lecture-controls .btn { min-height: 42px; padding: 8px 14px; font-size: 13px; }
  .speed-select { min-height: 42px; }

  /* 画中画：避让底部导航 */
  .pip-window { right: 10px; bottom: calc(80px + env(safe-area-inset-bottom)); width: min(280px, 84vw); }

  /* 答疑浮层全屏 */
  .qa-drawer { width: 100vw; max-width: 100vw; }

  /* 表单与弹窗 */
  .profile-card { padding: 26px 20px 24px; }
  .addtb-card { padding: 22px 18px; }
  .form-grid { grid-template-columns: 1fr; }

  /* 测评：触控目标加大 */
  .q-option { padding: 12px; min-height: 46px; }
  .q-answer-input { min-height: 46px; padding: 11px 12px; font-size: 15px; }
  .q-stem { font-size: 15px; }

  /* 统计 */
  .stat-bar-row { grid-template-columns: 84px 1fr 54px; font-size: 12.5px; }

  /* 成绩单两列 */
  .scoreboard { grid-template-columns: repeat(2, 1fr); }

  /* 其他 */
  .wrong-answers { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .page-head h2 { font-size: 19px; }
  .notice { font-size: 13px; }
}

/* ========== 推荐教材库 ========== */
.cs-library {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}
.cs-lib-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.cs-lib-item:hover { border-color: var(--primary); background: #f8faff; }
.cs-lib-item.imported { opacity: 0.55; cursor: default; background: #f9fafb; }
.cs-lib-item.imported:hover { border-color: var(--border); }
.cs-lib-name { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.4; }
.cs-lib-meta { font-size: 11.5px; color: var(--text-sub); }
.cs-lib-tag {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}
.cs-lib-item.imported .cs-lib-tag { background: #f3f4f6; color: var(--text-sub); }

/* ========== 拍照识别与网络资源 ========== */
.photo-divider {
  text-align: center;
  color: var(--text-sub);
  font-size: 12.5px;
  margin: 10px 0 8px;
  position: relative;
}
.photo-divider::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--border);
}
.photo-divider span { background: #fff; padding: 0 10px; position: relative; }
.kp-resources h4 { background: #f0f9ff; color: #0369a1; }
.resource-list { list-style: none; padding: 0; }
.resource-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.resource-list li:last-child { border-bottom: none; }
.resource-list a { color: var(--primary); font-weight: 600; text-decoration: none; }
.resource-list a:hover { text-decoration: underline; }
.resource-snip { display: block; font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* ========== OCR 识别原文对照 ========== */
.ocr-original {
  margin: 4px 0 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-sub);
}
.ocr-original summary { cursor: pointer; font-weight: 600; color: var(--text-sub); }
.ocr-text {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow-y: auto;
}

/* ========== 学习进度 ========== */
.resume-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 13.5px;
  flex-wrap: wrap;
}
.resume-bar .resume-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.25);
  flex-shrink: 0;
}
.resume-bar em { font-style: normal; opacity: 0.8; }
.resume-bar .btn { margin-left: auto; }
.progress-overview { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.progress-ring {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) var(--p, 0%), #eef1f6 0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--primary);
  position: relative;
  flex-shrink: 0;
}
.progress-ring::before {
  content: '';
  position: absolute;
  inset: 6px;
  background: #fff;
  border-radius: 50%;
}
.progress-ring span { position: relative; }
.progress-text p { margin: 2px 0; font-size: 14px; }
.progress-text b { color: var(--primary); font-size: 16px; }
.student-hint { font-size: 12px; color: var(--text-sub); text-align: center; margin-top: 10px; }

/* ========== 语音朗读 ========== */
.voice-btn.voice-on {
  background: var(--success-light);
  color: #14532d;
  border-color: var(--success);
  font-weight: 700;
}
.voice-btn.voice-on::after {
  content: '●';
  font-size: 8px;
  margin-left: 4px;
  vertical-align: middle;
}
.pip-voice-btn.voice-on {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.pip-voice-btn.voice-on::after {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  right: 3px;
}
.pip-voice-btn { position: relative; }
