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

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --primary: #4f6ef7;
  --primary-light: #eef0fd;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel { width: 100%; max-width: 680px; height: 100dvh; display: flex; flex-direction: column; }

/* ── 注册面板 ── */
.setup-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  margin: auto;
  width: 100%;
  max-width: 420px;
}

.logo { font-size: 2.5rem; text-align: center; margin-bottom: 4px; }
.tagline { text-align: center; color: var(--text-muted); margin-bottom: 32px; font-size: 0.95rem; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.9rem; }

input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--primary); }

.grade-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.grade-btn {
  padding: 9px 4px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.grade-btn:hover { border-color: var(--primary); color: var(--primary); }
.grade-btn.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { opacity: 0.9; }

.btn-secondary {
  padding: 8px 16px;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  background: transparent;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
}

.tip { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-top: 16px; }
.link { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* ── 聊天面板 ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.avatar { font-size: 1.8rem; }
.header-name { font-weight: 700; font-size: 1rem; }
.header-sub { font-size: 0.78rem; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-flash { background: #e0f2fe; color: #0369a1; }
.badge-pro { background: #fef3c7; color: #92400e; }

.btn-icon {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text-muted);
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }

/* ── 消息列表 ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { display: flex; gap: 8px; max-width: 88%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.msg.assistant .msg-avatar { background: var(--primary-light); }
.msg.user .msg-avatar { background: #f3f4f6; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.93rem;
  line-height: 1.6;
}
.msg.user .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .msg-bubble { background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }

.msg-bubble p { margin: 0 0 6px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 700; }

/* 工具调用提示 */
.tool-notice {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  display: inline-block;
  margin-bottom: 6px;
}

/* 打字动画 */
.typing-dot { display: inline-block; width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; margin: 0 2px; animation: blink 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ── 输入区域 ── */
.input-area {
  padding: 12px 16px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.hint-bar {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding: 4px 0;
}

.input-row { display: flex; gap: 8px; align-items: flex-end; }

textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.93rem;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color 0.2s;
}
textarea:focus { border-color: var(--primary); }

.btn-send {
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.input-tip { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* ── 图片上传 ── */
.btn-attach {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s;
}
.btn-attach:hover { border-color: var(--primary); }
.btn-attach.has-image { border-color: var(--primary); background: var(--primary-light); }

.image-preview-area {
  position: relative;
  margin-bottom: 8px;
  display: inline-block;
}
.image-preview-area img {
  max-height: 160px;
  max-width: 100%;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  display: block;
}
.btn-remove-img {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: none;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* 消息气泡内的图片 */
.msg-bubble img.problem-img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
  margin-bottom: 6px;
  display: block;
}

/* ── 多题队列面板 ── */
.problem-queue-panel {
  background: var(--primary-light);
  border-bottom: 1px solid #c7d2fe;
  padding: 10px 16px;
  flex-shrink: 0;
}
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}
.queue-progress { font-weight: 700; color: var(--primary); }

.queue-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.queue-item {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  border: 1.5px solid #c7d2fe;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-muted);
}
.queue-item.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}
.queue-item.done {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

/* ── PDF 加载态 ── */
.pdf-loading {
  text-align: center;
  padding: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
@keyframes loadingPulse { 0%,100%{opacity:0.3} 50%{opacity:1} }
.loading-dot { display: inline-block; animation: loadingPulse 1.2s infinite; }

/* ── 下一题按钮 ── */
.btn-next {
  padding: 3px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.78rem;
  cursor: pointer;
  margin-left: 8px;
}

/* ── 响应式 ── */
@media (max-width: 480px) {
  .setup-card { padding: 28px 20px; margin: 16px; border-radius: var(--radius); }
  .grade-grid { grid-template-columns: repeat(3, 1fr); }
}
