/* ── AI 全科小老师 样式 ──────────────────────────────── */

/* 首页入口横幅 */
.ai-tutor-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 60%, #a78bfa 100%);
  border-radius: 18px;
  padding: 20px 22px;
  margin-bottom: 16px;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 4px 18px rgba(99,102,241,.35);
  transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.ai-tutor-banner:active { transform: scale(.97); box-shadow: 0 2px 10px rgba(99,102,241,.3); }

.ai-banner-left { display: flex; align-items: center; gap: 14px; }
.ai-banner-icon { font-size: 2.4rem; line-height: 1; }
.ai-banner-title { font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; }
.ai-banner-sub   { font-size: 0.82rem; opacity: .85; margin-top: 2px; }
.ai-banner-arrow { font-size: 2rem; opacity: .7; font-weight: 300; }

/* AI 小老师主界面 */
#ai-tutor {
  display: none;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  flex-direction: column;
  background: #f5f3ff;
  z-index: 500;
  overflow: hidden;
}
#ai-tutor.active { display: flex; }

/* 打开 AI 老师时隐藏页面其余部分 */
body.ai-open > .header,
body.ai-open > .container { display: none !important; }

.ai-screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 10;
}
.ai-screen-header .back-btn {
  background: rgba(255,255,255,.22);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 44px;
  flex-shrink: 0;
}
.ai-screen-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}
.ai-gear-btn {
  background: rgba(255,255,255,.22);
  border: none;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-gear-btn:active { background: rgba(255,255,255,.35); }

/* 对话框 */
.ai-chat-box {
  flex: 1;
  min-height: 0;           /* 关键：允许 flex 子元素收缩 */
  overflow-y: auto;
  padding: 12px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f5f3ff;
  -webkit-overflow-scrolling: touch;
}

/* 气泡 */
.ai-bubble {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.ai-bubble-ai {
  align-self: flex-start;
  background: #fff;
  border-bottom-left-radius: 4px;
  color: #2d2d2d;
}
.ai-bubble-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-thinking {
  opacity: .7;
  animation: aiPulse 1.1s ease-in-out infinite;
}
@keyframes aiPulse {
  0%,100% { opacity: .5; }
  50%      { opacity: .9; }
}

/* 语音识别预览文字 */
.ai-preview {
  min-height: 18px;
  text-align: center;
  font-size: 0.82rem;
  color: #7c3aed;
  padding: 2px 12px;
  background: #f5f3ff;
  letter-spacing: .01em;
}

/* 文字输入行 */
.ai-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px 4px;
  background: #fff;
  border-top: 1px solid #e5e7f8;
}
.ai-text-inp {
  flex: 1;
  border: 2px solid #c4b5fd;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  background: #faf9ff;
  min-height: 40px;
}
.ai-text-inp:focus { border-color: #7c3aed; background: #fff; }
.ai-send-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  flex-shrink: 0;
  transition: opacity .15s;
}
.ai-send-btn:disabled { opacity: .5; }
.ai-send-btn:active   { opacity: .85; }

/* 底部按钮行 */
.ai-bottom-row {
  display: flex;
  gap: 8px;
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
  background: #fff;
  align-items: center;
}

/* 语音按钮 */
.ai-mic-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 46px;
  transition: all .15s;
  box-shadow: 0 3px 12px rgba(99,102,241,.3);
}
.ai-mic-btn:disabled { opacity: .5; }
.ai-mic-btn.listening {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  box-shadow: 0 3px 12px rgba(220,38,38,.35);
  animation: aiMicPulse .8s ease-in-out infinite;
}
@keyframes aiMicPulse {
  0%,100% { box-shadow: 0 3px 12px rgba(220,38,38,.35); }
  50%      { box-shadow: 0 3px 22px rgba(220,38,38,.65); }
}
.ai-mic-icon  { font-size: 1.3rem; }
.ai-mic-label { font-size: 1rem; }

/* 清空按钮 */
.ai-clear-btn {
  background: #f3f4f6;
  border: 1.5px solid #e5e7eb;
  color: #6b7280;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  min-height: 46px;
  flex-shrink: 0;
  white-space: nowrap;
}
.ai-clear-btn:active { background: #e5e7eb; }

/* ── 小屏手机适配（≤390px） ──────────────────────────── */
@media (max-width: 390px) {
  .ai-screen-header { padding: 8px 12px 8px; }
  .ai-screen-header .back-btn { padding: 6px 10px; font-size: 0.82rem; }
  .ai-screen-title  { font-size: 1rem; }
  .ai-bubble        { font-size: 0.88rem; padding: 8px 11px; }
  .ai-text-inp      { font-size: 0.88rem; }
  .ai-send-btn      { padding: 0 12px; font-size: 0.88rem; }
  .ai-mic-btn       { font-size: 0.88rem; min-height: 42px; }
  .ai-clear-btn     { font-size: 0.78rem; padding: 8px 10px; min-height: 42px; }
}
#ai-setup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.ai-setup-modal {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.ai-setup-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e1b4b;
  margin-bottom: 10px;
}
.ai-setup-desc {
  font-size: 0.95rem;
  color: #6b7280;
  line-height: 1.5;
  margin-bottom: 16px;
}
.ai-setup-desc small { font-size: 0.82rem; color: #9ca3af; }
#ai-key-inp {
  width: 100%;
  border: 2px solid #c4b5fd;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: monospace;
  outline: none;
  box-sizing: border-box;
  background: #faf9ff;
  min-height: 48px;
}
#ai-key-inp:focus { border-color: #7c3aed; }
.ai-setup-hint {
  font-size: 0.8rem;
  color: #9ca3af;
  margin: 10px 0 18px;
  line-height: 1.4;
}
.ai-setup-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.ai-setup-btns button {
  border: none;
  border-radius: 10px;
  padding: 10px 22px;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
}
.ai-setup-btns button:first-child {
  background: #f3f4f6;
  color: #374151;
}
.ai-setup-btns button.primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-weight: 600;
}
