/* ============================================
   教材辅导 - 教材阅读器样式
   与学习能量站配色保持一致性
   暖橙 #FF6B35 / 草绿 #67C23A / 米白 #FFF8E7
   ============================================ */

/* ---- 教材视图容器 ---- */
.textbook-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: calc(100vh - 140px);
  position: relative;
}

/* ---- 教材列表页 ---- */
.textbook-list-page {
  flex: 1;
  padding: 28px 32px;
}

.textbook-list-page h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.textbook-list-page .subtitle {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 24px;
}

/* 学段分组标题（小学 / 初中 / 高中） */
.textbook-stage + .textbook-stage {
  margin-top: 28px;
}

.textbook-stage-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.textbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.textbook-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 2px solid transparent;
}

.textbook-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.textbook-card .book-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.textbook-card .book-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.textbook-card .book-subject {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 12px;
}

.textbook-card .book-info {
  font-size: 13px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 12px;
}

.textbook-card .book-info span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- 分屏阅读布局 ---- */
.textbook-reader {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  gap: 0;
}

.textbook-panel {
  flex: 2;
  min-width: 200px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.textbook-panel .reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #FFF8E7, #FFFBF0);
  flex-shrink: 0;
}

.textbook-panel .reader-header .back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  background: transparent;
  font-family: inherit;
}

.textbook-panel .reader-header .back-btn:hover {
  background: rgba(255, 107, 53, 0.08);
}

.textbook-panel .reader-header .book-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.textbook-panel .reader-header .page-info {
  font-size: 13px;
  color: var(--text-light);
  font-weight: 600;
}

/* 页码输入框（点击页码后可输入数字跳转） */
.page-jump-input {
  width: 68px;
  padding: 2px 8px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  background: #fff;
  outline: none;
}

.textbook-panel .reader-footer .page-indicator .page-jump-input {
  font-size: 14px;
  width: 76px;
}

.textbook-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  line-height: 1.9;
  font-size: 16px;
  color: var(--text);
}

.textbook-content p {
  margin-bottom: 12px;
  text-indent: 2em;
  line-height: 1.9;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  transition: background 0.2s ease;
  position: relative;
}

.textbook-content p:hover {
  background: rgba(255, 215, 0, 0.15);
}

.textbook-content p .highlight {
  background: #FFD700;
  transition: background 0.3s ease;
  border-radius: 2px;
  padding: 0 2px;
}

.textbook-content p .highlight.fade-out {
  background: transparent;
  transition: background 0.6s ease;
}

.textbook-content .page-placeholder {
  color: var(--text-light);
  text-align: center;
  padding: 60px 20px;
  font-size: 15px;
}

/* ---- OCR 区域 ---- */
.ocr-section {
  margin-top: 16px;
  border-top: 2px dashed var(--border);
  padding-top: 16px;
}

.ocr-section .page-placeholder {
  padding: 20px;
  font-size: 14px;
}

.ocr-btn {
  display: block;
  margin: 0 auto 16px;
  padding: 12px 28px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.ocr-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.ocr-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.ocr-text-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: 12px 0 8px;
  text-align: center;
}

.ocr-result .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: tbSpin 0.8s linear infinite;
  margin: 0 auto 8px;
}

.ocr-save-btn {
  display: block;
  margin: 12px auto 0;
  padding: 10px 22px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.ocr-save-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.ocr-save-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

/* ---- PDF 页面图片渲染 ---- */
.page-image-container {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 20px;
  text-align: center;
  position: relative;
  display: inline-block;
}

.page-image-container img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: block;
}

/* ---- 文字覆盖层（图片上直接点读） ---- */
.text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 5;
  pointer-events: none;
}

.ov-line {
  position: absolute;
  display: block;
  color: transparent;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
  user-select: text;
  -webkit-user-select: text;
  overflow: hidden;
  white-space: nowrap;
  font-size: 0;
  pointer-events: auto;
  transition: background 0.15s ease;
}

.ov-line:hover {
  background: rgba(255, 215, 0, 0.4);
}

.ov-line.highlight {
  background: rgba(255, 215, 0, 0.6);
}

/* 框选选中行高亮 */
.ov-line.selected {
  background: rgba(74, 144, 217, 0.25);
}

/* 纯框选模式（数学教材）：隐藏热区 hover/单击高亮，避免与框选冲突 */
.selection-only .ov-line {
  cursor: default;
}

.selection-only .ov-line:hover,
.selection-only .ov-line.highlight {
  background: transparent;
}

/* ---- 选取式点读：选区矩形 + 操作工具条 ---- */
.selection-rect {
  position: absolute;
  border: 2px solid var(--primary);
  background: rgba(74, 144, 217, 0.12);
  pointer-events: none;
  z-index: 5;
  border-radius: 3px;
}

.selection-bar {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 6px 8px;
  z-index: 6;
}

.selection-bar button {
  border: none;
  background: var(--bg);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}

.selection-bar button:hover {
  background: var(--border);
}

.selection-bar button.sel-cancel {
  padding: 6px 9px;
  color: var(--text-light);
}

/* ---- 语音设置面板 ---- */
.reader-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

.voice-wrap {
  position: relative;
}

.voice-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 107, 53, 0.1);
  border: 1px solid rgba(255, 107, 53, 0.2);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  font-family: inherit;
}

.voice-btn:hover {
  background: rgba(255, 107, 53, 0.2);
  transform: scale(1.05);
}

.voice-panel {
  position: absolute;
  top: 42px;
  right: 0;
  width: 260px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
  padding: 14px 16px;
  z-index: 100;
}

.voice-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text);
}

.voice-row label {
  width: 34px;
  flex-shrink: 0;
  font-weight: 600;
}

.voice-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.voice-row span {
  width: 34px;
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.voice-row select {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  max-width: 160px;
}

.page-text-content {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 8px;
}

/* 空内容时隐藏：无识别提示/兜底文字时不显示横线和空白区域 */
.page-text-content:empty {
  display: none;
}

.page-text-content p {
  margin-bottom: 12px;
  text-indent: 2em;
  line-height: 1.9;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  transition: background 0.2s ease;
  position: relative;
}

.page-text-content p:hover {
  background: rgba(255, 215, 0, 0.15);
}

.textbook-panel .reader-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #FFFBF0;
  flex-shrink: 0;
}

.textbook-panel .reader-footer .page-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
  background: var(--card);
  font-family: inherit;
}

.textbook-panel .reader-footer .page-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.textbook-panel .reader-footer .page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.textbook-panel .reader-footer .page-indicator {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  min-width: 80px;
  text-align: center;
}

/* ---- 可拖动分割线 ---- */
.textbook-divider {
  width: 8px;
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  margin: 0 -2px;
}

.textbook-divider::before {
  content: '';
  width: 3px;
  height: 40px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.2s ease, height 0.2s ease;
}

.textbook-divider:hover::before,
.textbook-divider.active::before {
  background: var(--primary);
  height: 60px;
}

.textbook-divider.active::before {
  background: var(--primary);
  box-shadow: 0 0 8px rgba(255, 107, 53, 0.4);
}

/* ---- 选中文字浮标 ---- */
.textbook-selection-tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--primary);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.35);
  pointer-events: none;
  animation: tooltipFadeIn 0.2s ease;
  transform: translateX(-50%);
}

@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- AI 聊天区 ---- */
.ai-chat-panel {
  flex: 1;
  min-width: 240px;
  max-width: 480px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.ai-chat-panel .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  flex-shrink: 0;
}

.ai-chat-panel .chat-header h3 {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chat-panel .chat-header .chat-actions {
  display: flex;
  gap: 6px;
}

.ai-chat-panel .chat-header .chat-actions button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: none;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  font-family: inherit;
}

.ai-chat-panel .chat-header .chat-actions button:hover {
  background: rgba(255, 255, 255, 0.35);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages .chat-welcome {
  text-align: center;
  color: var(--text-light);
  font-size: 14px;
  padding: 20px 20px 40px;
  line-height: 1.6;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgFadeIn 0.3s ease;
}

/* ---- 答题表单（出题后作答 → 提交批改） ---- */
.exercise-answer-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin: 10px 0 6px;
  max-width: 85%;
}

.exercise-answer-box .ea-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ea-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.ea-row .ea-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  flex-shrink: 0;
  width: 16px;
  text-align: right;
}

.ea-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.ea-row input:focus {
  border-color: var(--primary);
}

.ea-submit {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s, transform 0.2s;
}

.ea-submit:hover:not(:disabled) {
  transform: translateY(-1px);
}

.ea-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.chat-message.ai {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-message .bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message.ai .bubble {
  background: #F0F0F0;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-message .bubble strong {
  font-weight: 700;
}

.chat-message .bubble ul,
.chat-message .bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chat-message .bubble li {
  margin-bottom: 4px;
}

.chat-message .bubble p {
  margin-bottom: 6px;
}

.chat-message .bubble p:last-child {
  margin-bottom: 0;
}

/* ---- AI 内容渲染：标题/分隔线/引用/代码等（面向学生，简洁清晰） ---- */
.chat-message .bubble h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin: 10px 0 6px;
}

.chat-message .bubble h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 8px 0 4px;
}

.chat-message .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.chat-message .bubble blockquote {
  border-left: 3px solid var(--primary);
  background: rgba(255, 107, 53, 0.06);
  margin: 8px 0;
  padding: 6px 10px;
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

.chat-message .bubble code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 13px;
}

.chat-message .bubble .md-code {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.chat-message .bubble .md-math {
  font-weight: 700;
  color: var(--primary);
}

.chat-message .bubble .exercise-block {
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.2);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  font-weight: 600;
  color: var(--text);
}

.chat-message .bubble .grade-result {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  margin: 4px 0;
}

.chat-message .bubble .grade-result.correct {
  background: rgba(103, 194, 58, 0.15);
  color: var(--accent);
}

.chat-message .bubble .grade-result.wrong {
  background: rgba(231, 76, 60, 0.12);
  color: var(--coral);
}

.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #FFFBF0;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

.chat-input-area input:focus {
  border-color: var(--primary);
}

.chat-input-area .send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.chat-input-area .send-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-lg);
}

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

.chat-input-area .exercise-btn {
  padding: 8px 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  font-family: inherit;
}

.chat-input-area .exercise-btn.page-solve-btn {
  background: linear-gradient(135deg, var(--blue), #6BB5E8);
}

.chat-input-area .exercise-btn:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow);
}

/* ---- 加载状态 ---- */
.textbook-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-light);
  gap: 16px;
}

.textbook-loading .spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: tbSpin 0.8s linear infinite;
}

@keyframes tbSpin {
  to { transform: rotate(360deg); }
}

.textbook-loading .loading-text {
  font-size: 14px;
  font-weight: 500;
}

/* 骨架屏 */
.skeleton-pulse {
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

@keyframes skeletonPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: var(--border);
  margin-bottom: 10px;
}

.skeleton-line:nth-child(1) { width: 85%; }
.skeleton-line:nth-child(2) { width: 70%; }
.skeleton-line:nth-child(3) { width: 90%; }
.skeleton-line:nth-child(4) { width: 60%; }
.skeleton-line:nth-child(5) { width: 80%; }
.skeleton-line:nth-child(6) { width: 75%; }
.skeleton-line:nth-child(7) { width: 65%; }
.skeleton-line:nth-child(8) { width: 88%; }

.chat-typing .bubble {
  background: #F0F0F0;
  color: var(--text-light);
  font-style: italic;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-typing .typing-dots::after {
  content: '...';
  animation: typingDot 1.2s infinite;
}

@keyframes typingDot {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

/* ---- 聊天区折叠按钮（移动端） ---- */
.chat-toggle-btn {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 80px;
  z-index: 50;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  font-family: inherit;
}

.chat-toggle-btn:hover {
  transform: scale(1.08);
}

/* ---- 移动端适配 ---- */
@media (max-width: 900px) {
  .textbook-reader {
    flex-direction: column;
  }

  .textbook-panel {
    flex: 1;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .textbook-content {
    padding: 20px;
  }

  .textbook-divider {
    display: none;
  }

  .ai-chat-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: auto;
    max-width: 100%;
    max-height: 50vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: 60;
    transform: translateY(calc(100% - 52px));
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .ai-chat-panel.expanded {
    transform: translateY(0);
  }

  .ai-chat-panel .chat-header {
    cursor: pointer;
    user-select: none;
  }

  .ai-chat-panel .chat-header::after {
    content: '▲';
    font-size: 12px;
    transition: transform 0.3s;
  }

  .ai-chat-panel.expanded .chat-header::after {
    transform: rotate(180deg);
  }

  .chat-toggle-btn {
    display: flex;
  }
}

@media (max-width: 480px) {
  .textbook-list-page {
    padding: 20px 16px;
  }

  .textbook-content {
    padding: 16px;
    font-size: 15px;
  }

  .textbook-grid {
    grid-template-columns: 1fr;
  }

  .textbook-card {
    padding: 20px 16px;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-input-area {
    padding: 10px 12px;
  }
}

/* ---- 知识点卡片 ---- */
.knowledge-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin: 0 0 8px;
}

.knowledge-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.knowledge-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.knowledge-card:last-child {
  margin-bottom: 0;
}

.knowledge-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.12);
  transform: translateX(2px);
}

.knowledge-card .kp-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}

.knowledge-card .kp-desc {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.5;
}

.knowledge-card .kp-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.knowledge-card .kp-btn {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.knowledge-card .kp-explain {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
}

.knowledge-card .kp-practice {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
}

.knowledge-card .kp-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ---- 错题本面板 ---- */
.wrong-answer-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin: 0 0 8px;
  max-height: 320px;
  overflow-y: auto;
}

.wrong-answer-panel .wa-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wrong-answer-panel .wa-count {
  font-size: 11px;
  color: var(--text-light);
  font-weight: 500;
}

.wrong-answer-panel .wa-loading {
  font-size: 11px;
  color: var(--text-light);
  font-weight: 400;
}

.wrong-answer-panel .wa-empty {
  text-align: center;
  color: var(--text-light);
  padding: 16px;
  font-size: 13px;
}

.wrong-answer-panel .wa-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  position: relative;
}

.wrong-answer-panel .wa-item:last-child {
  margin-bottom: 0;
}

.wrong-answer-panel .wa-q {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.5;
}

.wrong-answer-panel .wa-answer {
  font-size: 12px;
  margin-bottom: 3px;
  line-height: 1.5;
}

.wrong-answer-panel .wa-label {
  color: var(--text-light);
  font-weight: 500;
}

.wrong-answer-panel .wa-wrong {
  color: var(--coral);
  font-weight: 600;
}

.wrong-answer-panel .wa-right {
  color: var(--accent);
  font-weight: 600;
}

.wrong-answer-panel .wa-kp {
  font-size: 11px;
  color: var(--primary);
  margin-top: 4px;
  font-weight: 500;
}

.wrong-answer-panel .wa-exp {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  line-height: 1.5;
  padding: 6px 8px;
  background: var(--bg);
  border-radius: 6px;
}

.wrong-answer-panel .wa-del {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
  transition: color 0.2s;
}

.wrong-answer-panel .wa-del:hover {
  color: var(--coral);
  background: rgba(231, 76, 60, 0.08);
}

.wrong-answer-panel .wa-actions {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.wrong-answer-panel .wa-review-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}

.wrong-answer-panel .wa-review-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.25);
}