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

:root {
  --primary: #2E6FF2;
  --primary-dark: #1B4FBE;
  --bg: #F2F6FC;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-dim: #6B7280;
  --bot-bubble: #FFFFFF;
  --user-bubble: #2E6FF2;
  --border: #E5E7EB;
  --error: #DC2626;
  --ok: #16A34A;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
}

.view { min-height: 100dvh; display: flex; flex-direction: column; padding: 0; }
#login-view { align-items: center; justify-content: center; }
.hidden { display: none !important; }

/* ---- 登录页 ---- */
.login-card {
  background: var(--card);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(30, 60, 120, 0.12);
}
.logo { font-size: 52px; text-align: center; }
.login-card h1 { font-size: 24px; text-align: center; margin-top: 8px; }
.sub { text-align: center; color: var(--text-dim); font-size: 13px; margin: 6px 0 24px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }

.primary-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:active { background: var(--primary-dark); }
.error { color: var(--error); font-size: 13px; margin-top: 10px; text-align: center; min-height: 18px; }

/* ---- 聊天页 ---- */
#chat-view { justify-content: space-between; }

.chat-header {
  width: 100%;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-title { display: flex; flex-direction: column; }
.chat-title strong { font-size: 16px; }
.chat-title span { font-size: 12px; color: var(--text-dim); }
.chat-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ghost-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.messages {
  flex: 1;
  width: 100%;
  max-width: 760px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 auto;
}

.bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 15px;
  word-break: break-word;
}
.bubble.bot {
  background: var(--bot-bubble);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.bubble.user {
  background: var(--user-bubble);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.bubble p { margin: 4px 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; font-size: 16px; }
.bubble ol, .bubble ul { margin: 6px 0 6px 20px; }
.bubble li { margin: 3px 0; }
.bubble code { background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 5px; font-size: 13px; font-family: Consolas, monospace; }
.bubble.user code { background: rgba(255,255,255,0.22); }

.save-btn {
  display: block;
  margin-top: 8px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.15);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.input-bar {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 16px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.input-bar textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  max-height: 120px;
  background: var(--card);
}
.input-bar textarea:focus { outline: none; border-color: var(--primary); }
.send-btn {
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  height: 46px;
}
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- 错题集 ---- */
#mistake-view { justify-content: flex-start; }
.mistake-list {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mistake-card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  border: 1px solid var(--border);
}
.mistake-card.done { opacity: 0.55; }
.mistake-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.mistake-status { color: var(--error); }
.mistake-card.done .mistake-status { color: var(--ok); }
.mistake-q { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.mistake-note { margin-top: 6px; font-size: 13px; color: var(--text-dim); border-left: 3px solid var(--border); padding-left: 8px; }
.mistake-actions { margin-top: 10px; display: flex; gap: 8px; }
.mini-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.empty { text-align: center; color: var(--text-dim); padding: 30px 16px; font-size: 14px; }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(17,24,39,0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 移动端体验优化 ---- */
@media (max-width: 640px) {
  .chat-header { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
  .chat-actions { width: 100%; justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; padding-bottom: 2px; }
  .ghost-btn { flex-shrink: 0; padding: 6px 11px; font-size: 12.5px; }
  .chat-title { width: 100%; }
  .input-bar { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 94%; font-size: 14.5px; }
  .login-card { margin: 16px; }
  .mistake-actions { flex-wrap: wrap; }
  .mini-btn { flex: 1; text-align: center; min-width: 0; }
  .save-btn { flex: none; }
}

@media (min-width: 640px) {
  .messages { padding: 24px; }
  .bubble { max-width: 70%; }
}
