@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;600;700&family=ZCOOL+KuaiLe&display=swap');

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #0f1923;
  color: #333;
  height: 100vh;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ── 顶部 ──────────────────────────────────── */
#header {
  background: linear-gradient(135deg, #1a2a3a 0%, #0d1f30 100%);
  color: white;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

#header h1 { font-size: 18px; font-weight: 700; white-space: nowrap; letter-spacing: 0.5px; }

#set-title {
  font-size: 13px;
  color: rgba(255,255,255,0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

#header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 进度胶囊 */
#progress-pill {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}

#model-select {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
#model-select option { background: #1a2a3a; color: white; }

#mute-btn {
  background: rgba(255,255,255,0.1);
  border: none; border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 15px; cursor: pointer; color: white;
}

/* ── 主体 ──────────────────────────────────── */
#main { display: flex; flex: 1; overflow: hidden; }

/* ── 左侧黑板 ─────────────────────────────── */
#whiteboard {
  width: 62%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #1e3a28;
  background-image:
    radial-gradient(ellipse at 25% 15%, rgba(255,255,255,0.025) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 85%, rgba(0,0,0,0.12) 0%, transparent 55%);
  box-shadow: inset 0 0 80px rgba(0,0,0,0.3);
}

/* 木框上边 */
#whiteboard::before {
  content: "";
  display: block; flex-shrink: 0;
  height: 7px;
  background: linear-gradient(180deg, #5a3a08 0%, #9a6420 30%, #7a5018 60%, #5a3a08 100%);
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}

/* 粉笔槽下边 */
#whiteboard::after {
  content: "";
  display: block; flex-shrink: 0;
  height: 10px;
  background: linear-gradient(0deg, #5a3a08 0%, #9a6420 40%, #7a5018 70%, #5a3a08 100%);
  box-shadow: 0 -3px 8px rgba(0,0,0,0.4);
}

#board-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* 顶部题目行：题目卡（左）+ 老师头像（右，等高） */
#question-row {
  display: flex;
  align-items: stretch;      /* 头像高度拉伸到与题目卡一致 */
  gap: 16px;
  padding: 18px 24px 6px;
  flex-shrink: 0;
}
#question-holder { flex: 1 1 auto; min-width: 0; }
#question-holder #question-card { margin-bottom: 0; }

/* 数字人老师：题目右侧圆形头像，高度=题目区高度 */
#avatar-box {
  flex: 0 0 auto;
  align-self: stretch;
  position: relative;
  aspect-ratio: 1 / 1;       /* 正方形 → 宽度跟随高度 */
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(160deg, #eaf2ff 0%, #cfe0f7 55%, #b8d0ee 100%);
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 2px #48bb78, 0 6px 16px rgba(0,0,0,0.25);
  pointer-events: none;
}
#avatar-box canvas { display: block; }
#avatar-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(60,80,110,0.5); font-size: 22px;
}

/* 题目卡片 + 答案行放在这里（不再撑满，草稿区紧随其下） */
#board-main {
  padding: 20px 28px 4px;
  font-family: "Georgia", "PingFang SC", "Hiragino Sans GB", serif;
  color: rgba(255,255,255,0.92);
  flex-shrink: 0;
}

/* 手写草稿区：紧贴题目下方，是讲解的主要板书区 */
#board-draft {
  margin: 4px 28px 20px;
  padding: 10px 14px 14px;
  font-family: "Caveat", "ZCOOL KuaiLe", cursive, sans-serif;
  border-left: 3px solid rgba(252,229,136,0.25);
  background: rgba(255,255,255,0.02);
  border-radius: 0 8px 8px 0;
}

#board-draft:empty { display: none; }

/* 板书空状态 */
.board-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh;
  color: rgba(255,255,255,0.25);
  font-size: 18px; gap: 12px;
}
.board-empty-icon { font-size: 52px; opacity: 0.4; }
.board-empty-sub { font-size: 14px; color: rgba(255,255,255,0.18); margin-top: 4px; }

/* ── 黑板 Markdown 排版 ─────────────────── */
.board-md h1 { font-size: 22px; color: #fce588; margin: 0 0 12px; font-weight: 700; }
.board-md h2 { font-size: 19px; color: #fce588; margin: 18px 0 10px; padding-bottom: 6px; border-bottom: 2px dashed rgba(255,255,255,0.18); font-weight: 600; }
.board-md h3 { font-size: 16px; color: #90e0b0; margin: 14px 0 8px; font-weight: 600; }
.board-md p  { font-size: 17px; line-height: 1.9; color: rgba(255,255,255,0.9); margin-bottom: 8px; }
.board-md ul, .board-md ol { padding-left: 20px; margin-bottom: 8px; }
.board-md li { font-size: 16px; line-height: 1.9; margin-bottom: 3px; color: rgba(255,255,255,0.87); }
.board-md strong { color: #fce588; font-weight: 700; }
.board-md em    { color: #90e0b0; font-style: italic; }
.board-md hr    { border: none; border-top: 1px dashed rgba(255,255,255,0.15); margin: 12px 0; }
.board-md code  { background: rgba(255,255,255,0.1); padding: 1px 6px; border-radius: 3px; font-size: 15px; color: #ff9e9e; font-family: monospace; }
.board-md blockquote {
  border-left: 4px solid #fce588;
  padding: 8px 14px; margin: 10px 0;
  background: rgba(252,229,136,0.08);
  color: rgba(255,255,255,0.85);
  border-radius: 0 6px 6px 0;
  font-size: 15px;
}
.board-md table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 15px; }
.board-md th { background: rgba(252,229,136,0.18); color: #fce588; padding: 7px 12px; text-align: left; border: 1px solid rgba(255,255,255,0.12); font-weight: 600; }
.board-md td { padding: 7px 12px; border: 1px solid rgba(255,255,255,0.08); color: rgba(255,255,255,0.86); }
.board-md tr:nth-child(even) td { background: rgba(255,255,255,0.03); }

/* 题目卡（出题时黑板上方常驻） */
#question-card {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 16px;
}

.qcard-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}

.qcard-num {
  font-size: 22px; font-weight: 700; color: #fce588;
  font-family: "Caveat", cursive;
}

.qcard-type {
  font-size: 12px; color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.08);
  padding: 2px 10px; border-radius: 10px;
}

.qcard-progress {
  margin-left: auto; font-size: 12px; color: rgba(255,255,255,0.4);
}

/* 进度条 */
.progress-bar-wrap {
  height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px;
  margin-bottom: 14px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #48bb78, #68d391);
  transition: width 0.4s ease;
}

.qcard-context {
  font-size: 18px; line-height: 1.9;
  color: rgba(255,255,255,0.92);
  font-family: "Georgia", serif;
  letter-spacing: 0.2px;
}

.qcard-blank {
  display: inline-block;
  min-width: 80px;
  border-bottom: 2.5px solid #fce588;
  color: #fce588;
  font-weight: 700;
  text-align: center;
  padding: 0 6px;
  margin: 0 4px;
  vertical-align: bottom;
}

/* 分析区渐入 */
#analysis-area {
  animation: fadeIn 0.4s ease;
}

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

/* ── 手写草稿区 ─────────────────────────────── */
.draft-item {
  font-size: 26px;
  font-family: "Caveat", "ZCOOL KuaiLe", cursive, sans-serif;
  color: rgba(235,235,230,0.92);
  line-height: 2;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 0 1px rgba(255,255,255,0.3), 1px 0 1px rgba(200,200,195,0.2);
  -webkit-text-stroke: 0.4px rgba(255,255,255,0.1);
  letter-spacing: 0.5px;
  filter: url(#chalk-texture);
}
.draft-item:nth-child(odd)  { transform: rotate(-0.3deg); }
.draft-item:nth-child(even) { transform: rotate(0.4deg);  }
.draft-item:nth-child(3n)   { letter-spacing: 0.7px; }

/* 粉笔：行内元素，始终跟在最后一个字后面；抖动由 JS 驱动 */
#chalk-cursor {
  display: inline-block;
  width: 7px; height: 24px;
  margin-left: -2px;
  vertical-align: 9px;   /* 抬高笔杆，让笔尖落在字的中部 */
  background: linear-gradient(to top,
    #fffdf5 0%, #fff3c4 12%,      /* 笔尖：磨白的接触端 */
    #ffe082 35%, #ffd54f 70%, #f0c040 100%);
  border-radius: 1px 1px 3px 3px;
  transform-origin: 50% 92%;       /* 以笔尖为支点抖动 */
  transform: rotate(18deg);
  pointer-events: none;
  box-shadow: 0 0 6px rgba(255,220,80,0.45), inset -1px 0 1px rgba(0,0,0,0.15);
  transition: opacity 0.4s;
}

/* 逐字落笔的浮现效果 */
.chalk-char {
  display: inline-block;
  animation: chalkCharIn 0.14s ease-out;
}

@keyframes chalkCharIn {
  from { opacity: 0; filter: blur(2px); transform: scale(0.85) rotate(-3deg); }
  to   { opacity: 1; filter: none;     transform: scale(1)    rotate(0); }
}

/* 手写旁注装饰（圈、下划线） */
.draft-decorated {
  position: relative;
  display: inline;
}
.draft-deco-circle    { color: rgba(255,160,120,0.95); }
.draft-deco-underline { color: rgba(255,160,120,0.95); }

/* SVG 绘图旁注条 */
.draft-svg-item {
  display: flex; align-items: center; gap: 6px;
  line-height: 2; font-size: 24px;
}
.draft-arrow-label {
  font-family: "Caveat", cursive;
  font-size: 24px;
  color: rgba(235,235,230,0.9);
  filter: url(#chalk-texture);
}

/* 白板分段分隔线 */
.board-segment + .board-segment {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255,255,255,0.1);
}

/* ── SVG 动画 ─────────────────────────────── */
@keyframes svgLineDraw {
  to { stroke-dashoffset: 0; }
}
@keyframes svgCircleDraw {
  to { stroke-dashoffset: 0; }
}
@keyframes svgFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── 右侧对话区 ─────────────────────────────── */
#chat-panel {
  flex: 1; display: flex; flex-direction: column;
  background: #f8fafc; min-width: 0;
  border-left: 1px solid rgba(0,0,0,0.1);
  position: relative;
}

#chat-messages { flex: 1; overflow-y: auto; padding: 16px; }

.chat-msg { margin-bottom: 14px; display: flex; gap: 8px; animation: fadeIn 0.25s ease; }
.chat-msg.teacher { flex-direction: row; }
.chat-msg.student  { flex-direction: row-reverse; }

.chat-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.chat-msg.teacher .chat-avatar { background: #1a365d; color: white; }
.chat-msg.student  .chat-avatar { background: #276749; color: white; }

.chat-bubble {
  max-width: 82%; padding: 10px 14px;
  border-radius: 14px; font-size: 14px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.teacher .chat-bubble {
  background: white; color: #2d3748;
  border-top-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.chat-msg.student .chat-bubble {
  background: #1a365d; color: white;
  border-top-right-radius: 4px;
}

/* 学生答题气泡特殊样式 */
.student-answer-bubble {
  display: flex; flex-direction: column; gap: 4px;
}
.student-answer-bubble .ans-option {
  font-size: 18px; font-weight: 700; color: white;
}
.student-answer-bubble .ans-word {
  font-size: 13px; opacity: 0.8;
}
.student-answer-bubble .ans-result {
  font-size: 13px; margin-top: 2px;
}
.student-answer-bubble .ans-result.right { color: #68d391; }
.student-answer-bubble .ans-result.wrong { color: #fc8181; }

/* ── 学生提问栏 ──────────────────────────── */
#ask-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: white;
  border-top: 1px solid #e8ecf0;
  flex-shrink: 0;
}

#mic-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 17px;
  background: #f1f5f9; flex-shrink: 0;
  transition: all 0.2s;
}
#mic-btn:hover { background: #e8f0fe; }
#mic-btn.recording {
  background: #e53e3e;
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,62,62,0.45); }
  50%      { box-shadow: 0 0 0 10px rgba(229,62,62,0); }
}

#ask-input {
  flex: 1; padding: 9px 14px;
  border: 1.5px solid #e2e8f0; border-radius: 20px;
  font-size: 14px; outline: none; font-family: inherit;
  color: #2d3748; background: #f8fafc;
  transition: border-color 0.15s;
}
#ask-input:focus { border-color: #2c5282; background: white; }

#ask-send {
  padding: 9px 18px; border: none; border-radius: 20px;
  background: #1a365d; color: white;
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit; flex-shrink: 0;
}
#ask-send:hover { filter: brightness(1.2); }

/* ── 选项按钮区 ──────────────────────────── */
#options-area {
  padding: 12px 16px 8px;
  background: white;
  border-top: 1px solid #e8ecf0;
  flex-shrink: 0;
}

.options-label {
  font-size: 12px; color: #94a3b8; margin-bottom: 8px; font-weight: 500;
}

.options-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.option-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: #f1f5f9;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: all 0.15s;
  color: #2d3748;
  font-family: inherit;
}

.option-btn:hover:not(:disabled) {
  background: #e8f0fe;
  border-color: #2c5282;
  color: #1a365d;
}

.option-btn:disabled { cursor: not-allowed; opacity: 0.5; }

.option-letter {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
  background: #1a365d; color: white;
}

.option-text { flex: 1; line-height: 1.4; }

/* 答对/答错高亮 */
.option-btn.correct {
  background: #f0fff4; border-color: #38a169; color: #276749;
}
.option-btn.correct .option-letter { background: #38a169; }

.option-btn.wrong {
  background: #fff5f5; border-color: #e53e3e; color: #742a2a;
}
.option-btn.wrong .option-letter { background: #e53e3e; }

/* ── 导航按钮区 ──────────────────────────── */
#nav-area {
  padding: 8px 16px 12px;
  background: white;
  border-top: 1px solid #e8ecf0;
  display: flex; gap: 8px; flex-shrink: 0;
}

#nav-area:empty { display: none; }

.nav-btn {
  flex: 1; padding: 10px 16px;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}

.nav-btn-next {
  background: linear-gradient(135deg, #2c5282, #1a365d);
  color: white;
}
.nav-btn-next:hover { filter: brightness(1.15); }

.nav-btn-finish {
  background: linear-gradient(135deg, #276749, #1c4532);
  color: white;
}
.nav-btn-finish:hover { filter: brightness(1.15); }

.nav-btn-skip {
  background: #f1f5f9;
  color: #4a5568;
  border: 1px solid #e2e8f0;
}
.nav-btn-skip:hover { background: #e8ecf2; }

/* 打字动画 */
.typing-indicator { display: flex; gap: 4px; padding: 10px 14px; }
.typing-indicator span { width: 7px; height: 7px; background: #94a3b8; border-radius: 50%; animation: typing 1.2s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* ── 弹窗 ──────────────────────────────────── */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-content {
  background: white; border-radius: 20px; padding: 28px;
  max-width: 560px; width: 92%; max-height: 82vh; overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}
.modal-content h2 { font-size: 20px; color: #1a2d3d; margin-bottom: 18px; font-weight: 700; }

.set-option {
  padding: 16px; border: 2px solid #e2e8f0; border-radius: 12px;
  margin-bottom: 10px; cursor: pointer; transition: all 0.18s;
}
.set-option:hover { border-color: #2c5282; background: #f7fafc; }
.set-option .set-title { font-size: 17px; font-weight: 600; color: #1a2d3d; }
.set-option .set-meta  { font-size: 13px; color: #718096; margin-top: 5px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 8px; font-size: 12px; }
.tag-blue { background: #ebf4ff; color: #2c5282; }
.tag-green { background: #f0fff4; color: #276749; }

/* ── 成绩弹窗 ──────────────────────────────── */
#score-modal .modal-content { max-width: 480px; }

.score-big {
  text-align: center; padding: 20px 0 16px;
}
.score-number {
  font-size: 72px; font-weight: 800; line-height: 1;
  background: linear-gradient(135deg, #48bb78, #2c5282);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.score-sub { font-size: 16px; color: #718096; margin-top: 6px; }

.score-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.score-table th { background: #f7fafc; color: #4a5568; padding: 8px 12px; text-align: left; border-bottom: 2px solid #e2e8f0; font-weight: 600; }
.score-table td { padding: 8px 12px; border-bottom: 1px solid #f0f4f8; color: #2d3748; }
.score-table tr:last-child td { border-bottom: none; }
.res-right { color: #38a169; font-weight: 700; }
.res-wrong { color: #e53e3e; font-weight: 700; }

.score-actions { display: flex; gap: 10px; margin-top: 20px; }
.score-actions button {
  flex: 1; padding: 12px; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-restart { background: #1a365d; color: white; }
.btn-review  { background: #f1f5f9; color: #2d3748; }

/* ── 调试面板（占据布局底部，不遮挡内容） ──── */
#debug-panel {
  flex-shrink: 0;
  background: #1e1e1e; color: #d4d4d4;
  font-family: "SF Mono", monospace; font-size: 11px;
  max-height: 40vh; display: flex; flex-direction: column;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
  transition: max-height 0.3s ease;
}
#debug-panel.collapsed { max-height: 28px; }
#debug-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 14px; background: #2d2d2d; cursor: pointer;
  user-select: none; border-top: 1px solid #444;
}
#debug-toggle .title { font-weight: 600; color: #e0e0e0; font-size: 11px; }
#debug-toggle .arrow { color: #888; transition: transform 0.3s; }
#debug-panel.collapsed #debug-toggle .arrow { transform: rotate(180deg); }
#debug-log { flex: 1; overflow-y: auto; padding: 6px 14px; }
.debug-entry { margin-bottom: 10px; border-bottom: 1px solid #333; padding-bottom: 6px; }
.debug-label { font-weight: 600; font-size: 10px; margin-bottom: 3px; }
.debug-label.prompt { color: #569cd6; }
.debug-label.response { color: #6a9955; }
.debug-entry pre { white-space: pre-wrap; word-break: break-word; margin: 0; padding: 4px 8px; background: rgba(255,255,255,0.04); border-radius: 3px; max-height: 150px; overflow-y: auto; color: #ccc; line-height: 1.5; }

/* ── 响应式 ──────────────────────────────────── */
@media (max-width: 768px) {
  #main { flex-direction: column; }
  #whiteboard { width: 100%; height: 45vh; }
  #whiteboard::before, #whiteboard::after { display: none; }
  .options-grid { grid-template-columns: 1fr; }
  .chat-bubble { max-width: 88%; }
}
