/* 小书童 · 儿童友好聊天页样式（移动端优先） */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --blue: #4a9eff;
  --green: #3ecf8e;
  --orange: #ffb84d;
  --ink: #3a3f4b;
  --paper: #ffffff;
}

html, body {
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: linear-gradient(160deg, #dff0ff 0%, #e8fbe8 100%);
  color: var(--ink);
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 640px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.55);
}

/* ---- 顶部 ---- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  color: #2f6fd6;
  letter-spacing: 1px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #6b7280;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 5px 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9ca3af;
}
.dot.ok    { background: var(--green); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.25); }
.dot.warn  { background: var(--orange); box-shadow: 0 0 0 3px rgba(255, 184, 77, 0.25); }
.dot.bad   { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

/* ---- 学习监督入口 ---- */
.study-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 16px 10px;
  padding: 13px 16px;
  background: linear-gradient(135deg, #3ecf8e, #2f6fd6);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(47, 111, 214, 0.25);
}
.study-entry-sub {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
}
.study-entry.homework {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}
.study-entry.room {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.25);
}
.study-entry.game {
  background: linear-gradient(135deg, #ec4899, #be185d);
  box-shadow: 0 4px 12px rgba(190, 24, 93, 0.25);
}

/* ---- 快捷问句 ---- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  border: none;
  background: #fff;
  color: #2f6fd6;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(47, 111, 214, 0.15);
  cursor: pointer;
  transition: transform 0.1s;
}
.chip:active { transform: scale(0.95); }

/* ---- 聊天区 ---- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.msg.error { justify-content: flex-start; }

.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.msg.user .bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg.assistant .bubble {
  background: var(--paper);
  border-bottom-left-radius: 6px;
}
.msg.error .bubble {
  background: #fee2e2;
  color: #b91c1c;
  border-bottom-left-radius: 6px;
  font-size: 14px;
}

/* 打字动画 */
.typing .bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}
.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b6c2d6;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- 输入栏 ---- */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

#chat-input {
  flex: 1;
  border: 2px solid #dbe7f5;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 16px;
  outline: none;
  background: #fff;
}
#chat-input:focus { border-color: var(--blue); }

#send-btn {
  border: none;
  background: linear-gradient(135deg, #4a9eff, #2f6fd6);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 0 22px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(47, 111, 214, 0.35);
  transition: transform 0.1s;
}
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled { opacity: 0.6; }

/* ---- 底部隐私说明 ---- */
.foot {
  text-align: center;
  font-size: 12px;
  color: #8a94a6;
  padding: 8px 12px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.9);
}

/* ---- 隐私横幅（醒目） ---- */
.privacy-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #e7f9ee;
  border-bottom: 2px solid #3ecf8e;
  color: #166534;
  font-size: 13px;
  line-height: 1.7;
  padding: 8px 42px 8px 14px;
  position: relative;
}
.privacy-banner .pb-inner { flex: 1; }
.privacy-banner .pb-close {
  position: absolute;
  right: 8px;
  top: 6px;
  border: none;
  background: none;
  color: #166534;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

/* ---- 管理端入口 ---- */
.admin-link {
  position: fixed;
  right: 12px;
  bottom: 46px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 18px;
  z-index: 20;
}

/* ---- 邀请码锁屏 ---- */
.access-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, #dff0ff 0%, #e8fbe8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.access-overlay.hidden { display: none; }
.access-card {
  width: 100%;
  max-width: 340px;
  background: #fff;
  border-radius: 22px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(47, 111, 214, 0.25);
}
.access-icon { font-size: 44px; margin-bottom: 10px; }
.access-card h2 { font-size: 20px; color: #2f6fd6; margin-bottom: 6px; }
.access-card p { font-size: 14px; color: #6b7280; margin-bottom: 18px; }
.access-card input {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid #dbe7f5;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  margin-bottom: 14px;
}
.access-card input:focus { border-color: #4a9eff; }
.access-card button {
  width: 100%;
  border: none;
  background: linear-gradient(135deg, #4a9eff, #2f6fd6);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 12px 0;
  border-radius: 999px;
  cursor: pointer;
}
.access-card button:disabled { opacity: 0.6; }
.access-error {
  margin-top: 12px;
  color: #b91c1c;
  font-size: 13px;
  background: #fee2e2;
  border-radius: 10px;
  padding: 8px 10px;
}
.access-error.hidden { display: none; }

/* ---- 首访隐私声明（全屏） ---- */
.privacy-notice {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(30, 41, 59, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.privacy-notice .pn-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 14px 46px rgba(0, 0, 0, 0.3);
  max-height: 92vh;
  overflow-y: auto;
}
.pn-icon { font-size: 38px; text-align: center; }
.pn-card h2 { text-align: center; color: #2f6fd6; margin: 6px 0 10px; font-size: 20px; }
.pn-body { font-size: 14px; color: #374151; line-height: 1.8; }
.pn-body ul { padding-left: 4px; list-style: none; }
.pn-body li { margin: 6px 0; }
.pn-report-hint { margin-top: 10px; font-weight: 600; }
.pn-report { margin-top: 10px; }
.pn-report textarea,
.pn-report input {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid #dbe7f5;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  margin-bottom: 8px;
  font-family: inherit;
  resize: vertical;
}
.pn-report textarea:focus,
.pn-report input:focus { border-color: #4a9eff; }
.pn-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 6px;
}
.pn-btn.ok { background: linear-gradient(135deg, #3ecf8e, #1fa866); color: #fff; }
.pn-btn.warn { background: linear-gradient(135deg, #f87171, #dc2626); color: #fff; }
.pn-btn:disabled { opacity: 0.6; }
.pn-report-msg { font-size: 13px; margin-top: 6px; }
.pn-report-msg.ok { color: #15803d; }
.pn-report-msg.err { color: #b91c1c; }
.pn-contact-line { font-size: 13px; color: #6b7280; margin-top: 8px; text-align: center; }

/* ---- 语音提问（聊天输入栏） ---- */
.icon-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  font-size: 19px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
}
.icon-btn:active { transform: scale(0.92); }
#mic-btn.live {
  background: #ef4444;
  color: #fff;
  animation: micPulse 1.3s infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(239, 68, 68, 0); }
}
#speak-toggle.off { background: #e5e7eb; opacity: 0.55; }
#speak-toggle.on { background: #d3e8ff; }

/* 语音状态提示条（悬浮在输入栏上方） */
.voice-hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  text-align: center;
  color: #334155;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
  z-index: 60;
}
.voice-hint.err { background: #fef2f2; color: #b91c1c; }

/* 页面底部版本号 */
.foot .ver {
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(47, 111, 214, 0.08);
  color: #2f6fd6;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* 主设备：设备管理入口 */
.study-entry[hidden] { display: none !important; }
.study-entry.device { background: linear-gradient(135deg, #f0f7ff, #e6f0fb); border-color: #bcd9f5; }

/* 锁屏：绑定主设备步骤 */
.bind-step { text-align: center; }
.bind-step .bind-tip { color: #334155; font-size: 15px; line-height: 1.8; margin-bottom: 10px; }
.bind-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: #eef2f7;
  color: #334155;
  margin-top: 8px;
}
.bind-btn.main { background: linear-gradient(135deg, #3ecf8e, #1fa866); color: #fff; }

/* PWA：新版本提示 + 页脚刷新按钮 */
.sw-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(120px + env(safe-area-inset-bottom));
  background: #1f2937;
  color: #fff;
  font-size: 14px;
  border-radius: 999px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.4);
  z-index: 200;
}
.sw-toast button {
  border: none;
  background: linear-gradient(135deg, #3ecf8e, #1fa866);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.ref-btn {
  border: none;
  background: transparent;
  color: #8a94a6;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 8px;
}

/* ===== 大屏自适应 / Wide-screen layout（管理端·教学游戏 body.wide） ===== */
body.wide .app { max-width: 1280px; }
@media (min-width: 1500px) { body.wide .app { max-width: 1600px; } }
@media (min-width: 2000px) { body.wide .app { max-width: 1840px; } }
body.wide .top { padding: 8px 18px; }
body.wide .foot { font-size: 12px; }
