/* English Companion — 极简 UI
   设计目标：打开就像“来聊会儿天”，不是“上课”。 */

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

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #8a90a2;
  --accent: #5b8def;
  --accent-soft: #eaf1ff;
  --user-bubble: #5b8def;
  --ai-bubble: #f0f2f7;
  --shadow: 0 10px 40px rgba(30, 40, 80, 0.08);
  --radius: 18px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

/* 顶部 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #eef0f5;
}
.brand { font-weight: 600; font-size: 15px; letter-spacing: .3px; }
.status-dot {
  font-size: 12px;
  color: var(--muted);
  background: #f1f3f8;
  padding: 3px 9px;
  border-radius: 999px;
}

/* 中部舞台 */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 16px 8px;
  overflow-y: auto;
}

/* 头像 */
.avatar {
  position: relative;
  width: 92px; height: 92px;
  border-radius: 50%;
  background: linear-gradient(145deg, #eaf1ff, #dfe8ff);
  display: flex; align-items: center; justify-content: center;
  margin-top: 10px;
  margin-bottom: 18px;
}
.avatar .face { font-size: 44px; line-height: 1; }
.avatar .ring {
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
}
.avatar.speaking .ring {
  opacity: 1;
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(1);   opacity: .7; }
  100% { transform: scale(1.25); opacity: 0; }
}
.avatar.listening .face { animation: bob .9s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-4px)} }

/* 对话气泡 */
.transcript {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}
.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity:0; transform: translateY(6px);} to {opacity:1; transform:none;} }
.bubble.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 5px;
  color: var(--ink);
}
.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.bubble.system {
  align-self: center;
  background: #fff3f2;
  color: #c0392b;
  border: 1px solid #f3c9c5;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}

.hint {
  margin-top: auto;
  padding: 10px 0 4px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* 底部输入 */
.composer {
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid #eef0f5;
  background: var(--card);
}
.input-row {
  display: flex; gap: 8px; margin-bottom: 10px;
}
#textInput {
  flex: 1;
  border: 1px solid #e3e6ee;
  background: #f7f8fb;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 15px;
  outline: none;
}
#textInput:focus { border-color: var(--accent); background: #fff; }
.send {
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 16px; cursor: pointer;
}
.send:active { transform: scale(.94); }

.controls {
  display: flex; align-items: center; gap: 10px;
}
.lang-toggle {
  display: flex;
  background: #f1f3f8;
  border-radius: 999px;
  padding: 3px;
}
.lang-toggle button {
  border: none; background: transparent;
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.lang-toggle button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.mic {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 999px;
  background: var(--accent); color: #fff;
  padding: 13px; font-size: 15px; cursor: pointer;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.mic .mic-icon { font-size: 18px; }
.mic:active, .mic.holding { background: #3f6fd6; transform: scale(.99); }
.mic.holding .mic-label::after { content: "（松开发送）"; opacity: .8; }

.mem {
  width: 46px; height: 46px;
  border: 1px solid #e3e6ee; background: #f7f8fb;
  border-radius: 14px; font-size: 20px; cursor: pointer;
}

/* 记忆面板 */
.mem-panel {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(4px);
  padding: 20px;
  display: flex; flex-direction: column;
  z-index: 10;
}
.mem-panel.hidden { display: none; }
.mem-head {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; margin-bottom: 12px;
}
.mem-head button { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
#memText {
  flex: 1; overflow-y: auto;
  background: #f7f8fb; border-radius: 12px;
  padding: 14px; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; color: #404758;
}
.mem-reset {
  margin-top: 12px; padding: 10px;
  border: 1px solid #e3e6ee; background: #fff;
  border-radius: 10px; color: #c0504d; cursor: pointer; font-size: 13px;
}

/* 通用隐藏（Tab 切换用，覆盖聊天区与面板） */
.hidden { display: none !important; }

/* ---------- 顶部 Tab 导航 ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid #eef0f5;
  background: var(--card);
}
.tabs button {
  flex: 1;
  border: none;
  background: #f1f3f8;
  color: var(--muted);
  padding: 9px 0;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tabs button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- 面板（话题 / 记忆） ---------- */
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head > span:first-child { font-weight: 600; font-size: 15px; }
.panel-sub { font-size: 12px; color: var(--muted); }
.panel-body { flex: 1; }
.topic-loading { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 10px; line-height: 1.7; }

.mini-btn {
  border: 1px solid #e3e6ee;
  background: #fff;
  color: var(--accent);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.mini-btn:disabled { opacity: .5; cursor: default; }

/* ---------- 每日话题卡 ---------- */
.topic-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.tc-title { font-size: 18px; font-weight: 700; line-height: 1.35; }
.tc-zh { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tc-read { margin: 12px 0 4px; }
.tc-reading {
  font-size: 15px; line-height: 1.7; color: var(--ink);
  margin-top: 8px; white-space: pre-wrap;
}
.tc-h { font-size: 13px; font-weight: 600; color: var(--accent); margin: 16px 0 6px; }
.tc-expr { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.tc-expr li { font-size: 14px; line-height: 1.5; background: var(--accent-soft); padding: 8px 12px; border-radius: 10px; }
.tc-expr b { color: #2d5bbf; }
.tc-discuss {
  margin-top: 16px; font-size: 14px; line-height: 1.6;
  background: #fff7ec; border-left: 3px solid #f0b46a; padding: 10px 12px; border-radius: 8px;
}
.tc-answer {
  margin-top: 14px; width: 100%;
  border: none; border-radius: 12px;
  background: var(--accent); color: #fff;
  padding: 12px; font-size: 15px; cursor: pointer;
}
.tc-answer:active { transform: scale(.99); }

/* ---------- 学习记忆卡 ---------- */
.mem-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.mc-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.mc-label {
  flex: 0 0 64px;
  font-size: 12px; color: var(--muted);
  padding-top: 2px;
}
.mc-val { flex: 1; font-size: 15px; line-height: 1.5; }
.mc-val.en { font-weight: 600; color: #2d5bbf; }
.mc-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.mc-actions { display: flex; gap: 8px; margin-top: 10px; }

/* 回忆框 */
.mc-recall-box {
  margin-top: 12px; padding: 12px;
  background: #f7f8fb; border-radius: 12px;
}
.rc-q { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.rc-input {
  width: 100%; border: 1px solid #e3e6ee; background: #fff;
  border-radius: 10px; padding: 10px 12px; font-size: 15px; outline: none;
  margin-bottom: 8px;
}
.rc-input:focus { border-color: var(--accent); }
.rc-result { font-size: 14px; line-height: 1.5; margin-top: 8px; color: var(--ink); }
.mc-del-btn { color: #c0504d; border-color: #f0d4d2; }

/* ---------- 阅读：可点击单词 ---------- */
.tc-reading .tc-sentence { display: inline; }
.tap-word {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 1px;
  transition: background .12s;
}
.tap-word:hover { background: var(--accent-soft); }
.tap-word:active { background: #d6e3ff; }

/* ---------- 沉浸式查词浮层 ---------- */
.word-pop {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: transparent;   /* 不再压暗文章：浮层开着时文章仍可读、可点 */
  display: flex;
  pointer-events: none;      /* 关键：容器不劫持点击，点词直接命中文章里的单词 */
}
.word-pop.hidden { display: none !important; }
.wp-card {
  position: absolute;
  pointer-events: auto;      /* 容器放行，卡片自己照常可点/可滚 */
  width: min(88%, 340px);
  max-height: 84%;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 16px 48px rgba(20, 30, 60, 0.22);
  animation: pop .16s ease;
}
.wp-word { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wp-word-text { font-size: 20px; font-weight: 700; color: #1f2430; }
.wp-word-phonetic { font-size: 14px; font-weight: 400; color: var(--muted); }
.wp-word-phonetic:empty { display: none; }
.wp-speak {
  flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 999px;
  border: none; background: var(--accent-soft); color: var(--accent);
  font-size: 15px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .1s ease;
}
.wp-speak:active { transform: scale(.92); }

/* 四层区块通用 */
.wp-section { margin-top: 14px; }
.wp-sec-title { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 6px; letter-spacing: .3px; }

/* ① 当前语境 */
.wp-cur-body { font-size: 15px; line-height: 1.5; color: var(--ink); }
.wp-cur-meaning { font-size: 16px; font-weight: 600; color: var(--ink); line-height: 1.45; }
.wp-cur-sentence { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.55; font-style: italic; }
.wp-cur-note { font-size: 13px; color: #404758; margin-top: 6px; line-height: 1.55; background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; }

/* ② 核心感觉 */
.wp-core .wp-sec-body { font-size: 14px; color: var(--ink); line-height: 1.6; }

/* ③ 不同场景 */
.wp-scene { margin-top: 10px; padding-left: 10px; border-left: 2px solid #eef0f5; }
.wp-scene + .wp-scene { margin-top: 12px; }
.wp-scene-title { font-size: 13px; font-weight: 600; color: #2d5bbf; margin-bottom: 3px; }
.wp-scene-en { font-size: 14px; color: var(--ink); line-height: 1.5; }
.wp-scene-zh { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: 2px; }
.wp-scene-note { font-size: 12px; color: #8a5a00; margin-top: 4px; line-height: 1.45; }

/* ④ 常见搭配 */
.wp-coll-list { display: flex; flex-direction: column; gap: 5px; }
.wp-coll-item { font-size: 13px; line-height: 1.5; }
.wp-coll-en { font-weight: 600; color: #2d5bbf; }
.wp-coll-zh { color: var(--muted); }

.wp-actions { display: flex; gap: 8px; margin-top: 14px; }
.wp-actions .mini-btn { flex: 1; }

/* ---------- 语境记忆卡（区别于表达记忆） ---------- */
.mc-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.tag-expr { background: #eef3ff; color: #3f6fd6; }
.tag-context { background: #fff3e8; color: #d98028; }
.mc-word { font-size: 18px; font-weight: 700; color: #1f2430; }
.mc-meaning { font-size: 14px; color: #2d5bbf; margin: 4px 0 8px; line-height: 1.4; }
.mc-sentence {
  font-size: 14px; line-height: 1.6; color: var(--ink);
  background: var(--bg); border-radius: 10px; padding: 10px 12px;
}
.mc-sentence mark {
  background: #fff0c2; color: #8a5a00;
  border-radius: 4px; padding: 0 3px; font-weight: 600;
}
.mc-context { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* 回忆：原句挖空展示 */
.rc-sentence {
  display: block; margin-top: 6px;
  font-size: 14px; line-height: 1.6; color: var(--ink);
  background: var(--bg); border-radius: 10px; padding: 8px 10px;
}
.rc-sentence mark { background: #fff0c2; color: #8a5a00; border-radius: 4px; padding: 0 6px; font-weight: 600; }
