/* ==============================
   越南语学越南 - 口语练习页
   亮色风格（与其他3页一致：白底黑字）
   ============================== */
/* 全局兜底：任何 CSS class 设了 display:grid/flex 的元素，只要加了 HTML hidden 属性就必须隐藏 */
[hidden] { display: none !important; }
:root {
  --bg: #f5f7fb;
  --fg: #1f2430;
  --muted: #6b7588;
  --line: #e8ebf2;
  --card: #ffffff;
  --brand: #ff5a76;
  --brand-soft: #ffe1e7;
  --shadow-card: 0 1px 2px rgba(20,30,50,0.04);
  --radius-card: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 520px) {
  html, body { background: linear-gradient(135deg, #eef2f9 0%, #e6ecf7 100%); min-height: 100vh; }
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;             /* 锁死视口高度，不让 body 出现整页滚动条 */
  overflow: hidden;           /* 把滚动范围限制在内部容器 */
  padding: 12px 12px 100px;  /* 底部留出 composer（约 84px）空间，避免历史框被输入栏遮挡 */
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  background: transparent;
}

/* ===== 顶部状态栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 10px 16px;
  background: #ffffff;
  border-bottom: 1px solid #eef0f4;
  border-radius: 20px 20px 0 0;
  position: sticky;
  top: 0;
  z-index: 20;
}
.settings-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #fff;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  color: #6b7588;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
/* 强制让 HTML hidden 属性生效（display: grid 会覆盖默认 display: none） */
.settings-btn[hidden] { display: none; }
.brand {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--fg);
}
.usage-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff5e6;
  border: 1px solid #ffe0a8;
  color: #b97400;
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 10px;
}
.usage-pill::before {
  content: "";
  width: 6px; height: 6px;
  background: #ff5a76; border-radius: 50%;
}
.online-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #19c79b;
}
.online-dot::before {
  content: "";
  width: 6px; height: 6px;
  background: #19c79b; border-radius: 50%;
}
.user-pill {
  margin-left: 8px; padding: 4px 10px; border-radius: 999px;
  background: #e8f0ff; color: #2f6bff; font-size: 12.5px; font-weight: 600;
  text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
}
.user-pill.logged { background: #e6fbf0; color: #1a9d57; }

/* ===== 主圆卡（语音/主题模式） ===== */
.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px 16px 14px;
  position: relative;
  overflow: hidden;
}
.stage-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.zh-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto;
  font-size: 12.5px; color: var(--muted, #6b7280);
  cursor: pointer; user-select: none;
}
.zh-toggle input { width: 15px; height: 15px; accent-color: var(--brand, #2f6bff); cursor: pointer; }
.mode-pill {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff7e6;
  color: #b97400;
  border: 1px solid #ffe0a8;
  border-radius: 999px;
  font-size: 12.5px;
  padding: 5px 14px;
  font-weight: 600;
}
.mode-pill::before {
  content: "";
  width: 6px; height: 6px;
  background: #f59e0b; border-radius: 50%;
}
.mode-pill.dialog {
  background: #e8f1ff;
  color: #2f6bff;
  border-color: #bcd3ff;
}
.mode-pill.dialog::before {
  background: #2f6bff;
}

/* 圆球对话态：提示可点击录音 */
.orb.dialog { cursor: pointer; }
.orb.dialog.idle::before { opacity: 1; animation: pulse 2.4s ease-in-out infinite; }
.orb.active { box-shadow: 0 0 0 6px rgba(47,107,255,.12); }

.deco-dots {
  position: absolute;
  width: 70px; height: 70px;
  opacity: 0.7;
  background-image: radial-gradient(circle, #c9cfdb 1.4px, transparent 1.6px);
  background-size: 9px 9px;
  pointer-events: none;
}
.deco-dots.tl { top: 8px;   left: 12px; }
.deco-dots.tr { top: 8px;   right: 12px; }
.deco-dots.bl { bottom: 8px; left: 12px; }
.deco-dots.br { bottom: 8px; right: 12px; }

/* 圆球 */
.orb {
  width: 147px;   /* 原 220px 的 2/3：缩小 1/3，给下方对话框让出空间 */
  height: 147px;
  margin: 14px auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #ffffff 0%, #e8efff 50%, #cfd9ff 100%);
  border: 2px solid #b8c7ff;
  display: grid;
  place-items: center;
  position: relative;
  box-shadow:
    inset 0 0 30px rgba(124,144,255,0.18),
    0 8px 30px rgba(80,110,255,0.18);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
/* 呼吸式波纹：两层环，像活人"呼气(向外扩散)/吸气(向内收束)"交替。
   与球体 breathe 缩放同周期(4s)，整体呈呼吸起伏。 */
.orb::before,
.orb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(150,175,255,0.55);
  opacity: 0;
  pointer-events: none;
}
/* 呼气：环向外扩散、变淡；吸气：环向内收束回球体、变浓 */
.orb.idle::before,
.orb.idle::after { opacity: 1; }
.orb.idle::before { animation: breatheWave 4s ease-in-out infinite; }
.orb.idle::after  { animation: breatheWave 4s ease-in-out infinite; animation-delay: -2s; }

.orb.listening::before,
.orb.listening::after,
.orb.thinking::before,
.orb.thinking::after,
.orb.speaking::before,
.orb.speaking::after {
  opacity: 1;
  border-color: #ffb1c2;
}
.orb.listening::before { animation: breatheWave 4s ease-in-out infinite; }
.orb.listening::after  { animation: breatheWave 4s ease-in-out infinite; animation-delay: -2s; }
.orb.thinking::before  { animation: breatheWave 2.6s ease-in-out infinite; }
.orb.thinking::after   { animation: breatheWave 2.6s ease-in-out infinite; animation-delay: -1.3s; }
.orb.speaking::before  { animation: breatheWave 2.2s ease-in-out infinite; }
.orb.speaking::after   { animation: breatheWave 2.2s ease-in-out infinite; animation-delay: -1.1s; }

@keyframes breatheWave {
  /* 吸气末：贴着球体(满) → 呼气：向外大幅扩散变淡消失
     → 吸气：从更深处明显向内收束回球体(可见的"回吸"动作) */
  0%   { transform: scale(1);    opacity: 0.6;  }   /* 吸气末，贴球 */
  45%  { transform: scale(1.5);  opacity: 0;    }   /* 呼气：扩散到最外、淡出 */
  45.01% { transform: scale(0.62); opacity: 0; }    /* 瞬移回球内深处 */
  50%  { transform: scale(0.62); opacity: 0.75; }   /* 吸气开始：深处、清晰 */
  100% { transform: scale(1);    opacity: 0.6;  }   /* 向内收束回球体(明显回吸) */
}
/* ===== 拟人头像 SVG ===== */
.orb .face {
  width: 84%;
  height: 84%;
  display: block;
}
.orb .skin   { fill: #fff4ec; }
.orb .ear    { fill: #ffd9c2; }
.orb .eye    { fill: #3a3a4a; }
.orb .blush  { fill: #ffb3a7; opacity: .7; }
.orb .mouth  { fill: none; stroke: #c2607a; stroke-width: 4; stroke-linecap: round; }

/* 思考：整张脸缓慢转圈 */
.orb.thinking .face {
  transform-box: fill-box;
  transform-origin: center;
  animation: spin 2.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 听：耳朵轻轻扇动 */
.orb.listening .ear-l { transform-box: fill-box; transform-origin: center; animation: earL 0.5s ease-in-out infinite; }
.orb.listening .ear-r { transform-box: fill-box; transform-origin: center; animation: earR 0.5s ease-in-out infinite; }
@keyframes earL { 0%,100% { transform: translateX(0); } 50% { transform: translateX(-3px); } }
@keyframes earR { 0%,100% { transform: translateX(0); } 50% { transform: translateX(3px); } }

/* 说：嘴巴开合（用 scaleY 模拟张嘴）。
   关键：transform-box: fill-box 让 transform-origin 相对嘴自身包围盒，
   否则 SVG 的 transform-origin 单位混乱导致缩放跑偏、看起来不动。 */
.orb.speaking .mouth {
  transform-box: fill-box;
  transform-origin: center;
  animation: talk 0.32s ease-in-out infinite;
}
@keyframes talk {
  0%,100% { transform: scaleY(0.35); }
  50%     { transform: scaleY(1.4); }
}

/* 待机：轻微呼吸（脸随胸腔微微胀缩），与波纹同周期(4s)，眼睛偶尔眨 */
.orb.idle .face { transform-box: fill-box; transform-origin: center; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.orb.idle .eye { transform-box: fill-box; transform-origin: center; animation: blink 4s ease-in-out infinite; }
@keyframes blink { 0%,92%,100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }


.prompt {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  margin: 4px 0 14px;
}

/* ===== 话题快捷键 ===== */
.quick {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.quick button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  color: #1f2430;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.quick button:hover { border-color: #c4cce0; }
.quick button:active { transform: scale(0.97); }

/* ===== 历史对话（豆包式可滚动对话流，紧跟 stage 卡片下方，宽度与上下框体一致） ===== */
.history[hidden] { display: none; }
.history {
  /* 固定高度 245px：不随球体文案忽高忽低 */
  height: 245px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;    /* 裁切内部溢出，框体高度固定、不撑高 .app，球体不被推走 */
}
.history-inner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;                     /* 恢复 history 内的竖向滚动（外层 touch-action:none） */
  overscroll-behavior: contain;            /* 滚动不外溢到 body */
  /* 自定义滚动条：只针对对话历史框 */
  scrollbar-width: thin;                                  /* Firefox */
  scrollbar-color: rgba(0,0,0,.18) transparent;            /* Firefox：短且半透明 */
}
/* WebKit / Blink：窄且半透明的滚动条 */
.history-inner::-webkit-scrollbar { width: 4px; height: 4px; }
.history-inner::-webkit-scrollbar-track { background: transparent; }
.history-inner::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.18);                  /* 半透明、低调 */
  border-radius: 999px;
  border: none;
}
.history-inner::-webkit-scrollbar-thumb:hover { background-color: rgba(0, 0, 0, 0.32); }
.history-inner::-webkit-scrollbar-button { display: none; height: 0; width: 0; } /* 去掉上下箭头 */
/* 空态提示 */
.history-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 20px;
}
/* 单条消息分组：同一角色连续多条靠同一侧 */
.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 86%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot  { align-self: flex-start; align-items: flex-start; }
.bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot .bubble {
  background: #f0f3f9;
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.bubble.bot-zh {
  background: #eef7ee;
  color: #3a7d44;
  border-bottom-left-radius: 4px;
  font-size: 12.5px;
  border-left: 3px solid #7bc47f;
}
/* 中文翻译：默认隐藏，勾选"显示中文"时展开 */
.history.hide-zh .bubble.bot-zh { display: none; }
/* 流式中的"正在输入" */
.typing {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  padding: 4px 2px;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9aa2b1;
  animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
  0%,60%,100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== 文字输入栏（固定在 TabBar 上方，外框内） ===== */
.composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 64px; /* 紧贴 TabBar 上沿 */
  width: 100%;
  padding: 16px 16px;   /* 加大上下内边距，拉长整条输入栏 */
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 49;
}
@media (min-width: 520px) {
  .composer {
    bottom: 64px;
  }
}
.composer .mic-btn {
  width: 52px; height: 52px;   /* 拉长：按钮放大 */
  border-radius: 50%;
  background: #eef2f9;
  color: #6b7588;
  border: none;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.composer .mic-btn:hover { background: #e2e8f3; }
.composer .mic-btn.active {
  background: #ff5a76;
  color: #fff;
  animation: micPulse 1.4s ease-in-out infinite;
}
@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,90,118,0.5); }
  50%     { box-shadow: 0 0 0 8px rgba(255,90,118,0); }
}
.composer .field {
  flex: 1;
  background: #eef2f9;
  border-radius: 999px;
  padding: 13px 16px;   /* 加大输入框内边距，拉长对话框 */
  display: flex; align-items: center;
  cursor: text;
}
.composer input {
  flex: 1;
  border: none; outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--fg);
  font-family: inherit;
  min-width: 0;
}
.composer input::placeholder { color: #a0a7b4; }
.composer .count {
  flex-shrink: 0;
  font-size: 11px;
  color: #a0a7b4;
  margin-left: 6px;
}
.composer .send-btn {
  width: 52px; height: 52px;   /* 拉长：按钮放大 */
  border-radius: 50%;
  background: #c2cad8;
  color: #fff;
  border: none;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .12s;
  flex-shrink: 0;
}
.composer .send-btn:hover { background: #aab3c4; }
.composer .send-btn.active {
  background: #6e90ff;
}
.composer .send-btn.active:hover { background: #5a7be8; }

/* ---------- 大模型设置弹层（齿轮） ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(20,24,33,0.42);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
  animation: fadeIn .18s ease;
}
.modal-mask[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  animation: slideUp .22s ease;
  overscroll-behavior: contain;
  box-sizing: border-box;
}
/* 底部安全区（iPhone 等带 home 指示条） */
.modal .modal-body:last-child { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }
@media (min-width: 520px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  font-size: 16px; font-weight: 600;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,.05);
}
.modal-close {
  border: none; background: none; font-size: 24px; line-height: 1;
  color: #9aa2b1; cursor: pointer; padding: 0 4px;
}
.modal-body { padding: 16px 18px 20px; }
.modal-tip { font-size: 12.5px; color: #8a93a3; margin: 0 0 14px; line-height: 1.5; word-break: break-word; }
.modal-tip code { word-break: break-all; overflow-wrap: anywhere; }

.field-row {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px;
}
.field-label { font-size: 13px; color: #5b6472; font-weight: 500; }
.field-row input, .field-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e1e6ef;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fafbfd;
  color: var(--fg);
  box-sizing: border-box;
  outline: none;
  transition: border-color .12s, background .12s;
}
.field-row input:focus, .field-row select:focus {
  border-color: #2f6bff;
  background: #fff;
}
.field-row input::placeholder { color: #b3bac6; }

.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 4px;
}
.btn-ghost, .btn-primary {
  border-radius: 10px; padding: 9px 16px; font-size: 14px;
  cursor: pointer; border: 1px solid transparent; font-family: inherit;
}
.btn-ghost { background: #f1f3f8; color: #5b6472; border-color: #e1e6ef; }
.btn-ghost:hover { background: #e8ecf4; }
.btn-primary { background: #2f6bff; color: #fff; }
.btn-primary:hover { background: #245be0; }

.modal-status {
  margin-top: 12px; font-size: 12.5px; color: #2f9e5e; min-height: 16px;
}
.modal-status.err { color: #e5484d; }
