/* 智学宝样式 */
:root {
  --primary: #4A90D9;
  --primary-dark: #3578C1;
  --accent: #F5A623;
  --success: #52C41A;
  --bg: #F0F4FA;
  --bg-white: #FFFFFF;
  --text: #333;
  --text-light: #888;
  --border: #E4E9F0;
  --shadow: 0 2px 8px rgba(74,144,217,0.15);
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 顶部栏 ===== */
.top-bar {
  background: var(--primary);
  color: white;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(74,144,217,0.3);
  flex-shrink: 0;
  z-index: 10;
}

.logo-area { display: flex; align-items: center; gap: 6px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: 1px; }

.grade-badge {
  flex: 1;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.2s;
}
.grade-badge:hover { background: rgba(255,255,255,0.3); }

.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.35); }

/* ===== 主聊天区 ===== */
.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  scroll-behavior: smooth;
}
.chat-main::-webkit-scrollbar { width: 4px; }
.chat-main::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }

/* 欢迎页 */
.welcome {
  text-align: center;
  padding: 30px 16px;
}
.welcome-avatar {
  font-size: 56px;
  margin-bottom: 12px;
  animation: bounce 2s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.welcome h2 { font-size: 20px; color: var(--primary); margin-bottom: 8px; }

/* 全科快捷区 */
.pop-subjects { margin: 0 0 18px; }
.pop-label { font-size: 13px; color: var(--text-light); margin-bottom: 10px; text-align: center; }
.pop-subj-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pop-subj-item {
  display: flex; align-items: center; gap: 5px;
  background: white;
  border: 2px solid var(--border);
  border-radius: 22px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.pop-subj-item:hover, .pop-subj-item:active {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(74,144,217,0.2);
}
.pop-subj-item .icon { font-size: 16px; }
.pop-subj-item.active-subj {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.welcome p { font-size: 14px; color: var(--text-light); margin-bottom: 20px; }

.quick-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}
.subj-btn {
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.subj-btn:hover, .subj-btn:active {
  background: var(--primary);
  color: white;
}

.welcome-tips { text-align: left; max-width: 300px; margin: 0 auto; }
.tip-item {
  background: white;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.tip-item span { color: var(--text-light); }

/* 消息 */
.messages { display: flex; flex-direction: column; gap: 12px; }

.msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.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%;
  background: var(--primary);
  color: white;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--accent); }
.msg.user .msg-avatar::after { content: '😊'; }

.msg-bubble {
  background: white;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: var(--shadow);
  word-break: break-all;
}
.msg.user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  border-bottom-left-radius: 4px;
}
.msg-bubble .thinking-label {
  font-size: 11px;
  color: var(--primary);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-bubble .thinking-label::before { content: '🧠'; font-size: 13px; }
.msg-bubble .thinking-label::after {
  content: '';
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--primary);
  animation: blink 0.8s infinite;
}
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

.msg-time { font-size: 10px; color: var(--text-light); margin-top: 4px; text-align: right; }
.msg.assistant .msg-time { text-align: left; }

/* ===== 科目选择栏 ===== */
.subject-bar {
  background: white;
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  flex-shrink: 0;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.05);
}
.subject-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.subject-scroll::-webkit-scrollbar { display: none; }
.subj-tag {
  white-space: nowrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
}
.subj-tag.active, .subj-tag:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== 底部输入区 ===== */
.input-area {
  background: white;
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}

.input-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.tool-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.tool-btn:hover, .tool-btn:active {
  border-color: var(--primary);
  background: #EBF5FF;
}
.tool-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#inputText {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}
#inputText:focus { border-color: var(--primary); }

.send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }

.recording-indicator {
  text-align: center;
  font-size: 12px;
  color: #e74c3c;
  padding: 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #e74c3c;
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity:1; transform:scale(1); } 50% { opacity:0.5; transform:scale(0.8); } }

/* ===== 弹窗 ===== */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-bg[hidden] { display: none; }

.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { max-width: 500px; }

.modal-header {
  padding: 16px 18px;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 18px;
  cursor: pointer;
  color: var(--text-light);
  display: flex; align-items: center; justify-content: center;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* 年级选择 */
.grade-section { margin-bottom: 14px; }
.grade-group-label { font-size: 12px; color: var(--text-light); margin-bottom: 8px; font-weight: 600; }
.grade-list { display: flex; flex-wrap: wrap; gap: 6px; }
.grade-item {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.grade-item:hover { border-color: var(--primary); color: var(--primary); }
.grade-item.active { background: var(--primary); color: white; border-color: var(--primary); }
.name-input-row { margin-top: 12px; }
.name-input-row input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
.name-input-row input:focus { border-color: var(--primary); }
.confirm-btn {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 14px;
  transition: background 0.2s;
}
.confirm-btn:hover { background: var(--primary-dark); }

/* 拍照解题 */
.vision-upload { text-align: center; margin-bottom: 12px; }
.vision-preview {
  min-height: 180px;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
  overflow: hidden;
}
.vision-preview img { max-width: 100%; max-height: 250px; }
.vision-preview .placeholder { font-size: 40px; margin-bottom: 6px; }
.vision-preview .placeholder-text { font-size: 12px; color: var(--text-light); }
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 14px;
  cursor: pointer;
}
.vision-question { margin-bottom: 12px; }
.vision-question textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
}
.vision-question textarea:focus { border-color: var(--primary); }
.vision-result { margin-top: 14px; }
.vision-answer {
  background: #F0F7FF;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  line-height: 1.7;
  max-height: 300px;
  overflow-y: auto;
}
.speak-btn {
  margin-top: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
}

/* 帮助 */
.help-body { display: flex; flex-direction: column; gap: 12px; }
.help-item {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  gap: 8px;
}
.help-item strong { color: var(--primary); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.75);
  color: white;
  padding: 10px 20px;
  border-radius: 22px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 打字光标 ===== */
.msg-bubble .cursor {
  display: inline-block;
  width: 2px; height: 14px;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 0.8s infinite;
}
.msg.user .msg-bubble .cursor { background: white; }


/* 科目弹层 */
.subject-picker{position:fixed;bottom:80px;left:50%;transform:translateX(-50%) scale(0.9);opacity:0;pointer-events:none;transition:all .2s;z-index:100;width:340px;max-width:90vw;background:#fff;border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,.15);overflow:hidden}
.subject-picker.open{transform:translateX(-50%) scale(1);opacity:1;pointer-events:all}
.sp-header{display:flex;justify-content:space-between;align-items:center;padding:14px 16px 10px;font-size:15px;font-weight:600;color:#333;border-bottom:1px solid #eee}
.sp-close{width:28px;height:28px;border-radius:50%;background:#f0f0f0;border:none;font-size:18px;cursor:pointer;color:#666;text-align:center;line-height:28px}
.sp-list{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;padding:12px}
.sp-item{display:flex;flex-direction:column;align-items:center;gap:4px;padding:10px 4px;border-radius:10px;border:1.5px solid #e8e8e8;background:#fafafa;cursor:pointer;font-size:13px;color:#444;transition:all .15s}
.sp-item .icon{font-size:20px}
.sp-item:hover{border-color:var(--primary);background:#eef5ff}
.sp-item.active{border-color:var(--primary);background:#dbeeff;color:var(--primary);font-weight:600}
.quick-subjects{cursor:pointer}
.quick-subjects:hover{opacity:.85}
.quick-subjects .subj-btn.active{background:var(--primary);color:#fff}
