/* ============ EchoMirror 样式（含数字人舞台动画） ============ */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e6eaf3;
  --text: #1b2334;
  --text-2: #5a6478;
  --text-3: #8b94a9;
  --accent: #4f6ef7;
  --accent-2: #7c5cfc;
  --accent-soft: #eef1fe;
  --ai-bubble: #ffffff;
  --danger: #d64550;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .07);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---------- 左侧资料卡 ----------
   桌面端：固定不动。整个面板跟随视口高度，内容超出时面板内部滚动，
   页面本身不滚动 —— 这样右侧聊天记录滚动时左侧资料栏纹丝不动 */
#profile-panel {
  padding: 20px 0 20px 20px;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 手机端资料卡抽屉的遮罩层：
   必须 position:fixed（脱离网格流），否则它会成为 #app 网格的子元素，
   占据第一行第二列，把聊天面板挤到第二行的窄列里（页面"只有一半"的元凶） */
#backdrop {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(20, 26, 43, .45);
  display: none;
}
body.profile-open #backdrop { display: block; }

.profile-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.profile-banner {
  height: 84px;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 60%, #9d7cfc 100%);
  position: relative;
}
.profile-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 20%, rgba(255, 255, 255, .35), transparent 55%);
}

.avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  margin: -36px auto 0;
  position: relative; z-index: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(79, 110, 247, .35);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 28px; font-weight: 700;
}

.p-name { text-align: center; font-size: 20px; margin-top: 10px; letter-spacing: .5px; }
.p-school { text-align: center; color: var(--text-2); font-size: 12.5px; margin: 4px 16px 0; }

.intention {
  margin: 14px 16px 0;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: 10px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.intention-label {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px;
}
.intention-value { color: var(--text); font-weight: 500; }

.section { margin: 16px 16px 0; }
.section:last-child { margin-bottom: 18px; }
.section h3 {
  font-size: 12.5px; color: var(--text-3); font-weight: 600;
  letter-spacing: 1px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.section h3::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  background: #f3f5fa; border: 1px solid var(--border);
  color: var(--text-2); font-size: 12px;
  padding: 3px 10px; border-radius: 999px; transition: all .15s;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag.empty { color: var(--text-3); border-style: dashed; }

.contact { list-style: none; }
.contact li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 5px 0; font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.contact li:last-child { border-bottom: none; }
.c-label { flex-shrink: 0; width: 50px; color: var(--text-3); font-size: 12px; }
.c-val { color: var(--text); word-break: break-all; }
.c-val a { color: var(--accent); text-decoration: none; }
.c-val a:hover { text-decoration: underline; }

/* ---------- 右侧聊天区 ----------
   竖向 flex：头部（含数字人舞台）固定，只有 #messages 滚动。
   min-height:0 是关键 —— 否则 flex 子项不会收缩，内部滚动条失效。 */
#chat-panel {
  display: flex; flex-direction: column;
  padding: 20px 20px 0 0; min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#chat-header {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 11px 16px;
  margin-bottom: 12px;
  flex-shrink: 0;   /* 固定不滚动、不被压缩 */
}
.chat-title { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.logo {
  font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle { font-size: 12px; color: var(--text-3); }
.chat-actions { display: flex; gap: 8px; }

#clear-btn, #voice-btn, #mobile-profile-btn {
  border: 1px solid var(--border);
  background: #fff; color: var(--text-2);
  font-size: 12.5px; padding: 5px 12px;
  border-radius: 8px; cursor: pointer; transition: all .15s;
}
#clear-btn:hover, #voice-btn:hover, #mobile-profile-btn:hover { border-color: var(--accent); color: var(--accent); }
#voice-btn.off { color: var(--text-3); border-style: dashed; }
#mobile-profile-btn { display: none; }

/* ---------- 数字人舞台 ----------
   flex-shrink:0：聊天记录滚动时，数字人（含头像）保持固定不动 */
#avatar-stage {
  display: flex; gap: 18px; align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

#avatar-frame {
  position: relative;
  width: 132px; flex-shrink: 0;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(160deg, #e8edfa, #f2ecfd);
  border: 1px solid var(--border);
}

/* 面部图层：承载呼吸/低头/点头动画，让五官覆盖层跟着脸一起动 */
.avatar-face {
  position: absolute; inset: 0;
  animation: breath 4.2s ease-in-out infinite alternate;
  transform-origin: 50% 90%;
}

#avatar-img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: top center;
  display: block;
}

/* 呼吸起伏 */
@keyframes breath {
  from { transform: scale(1) translateY(0); }
  to   { transform: scale(1.016) translateY(-1.2%); }
}

#avatar-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

/* 眨眼：肤色眼睑 + 睫毛线（位置由 JS 按照片标定）
   用肤色而不是深色块，既真实又不会在脸上留下黑点 */
.lid {
  position: absolute;
  width: 13%; height: 4.4%;
  border-radius: 50%;
  background: #f1cab3;
  box-shadow: inset 0 -2px 0 rgba(92, 62, 50, .8);
  opacity: 0;
  transform: translate(-50%, -50%) scaleY(.12);
  pointer-events: none;
}
#avatar-frame.blink .lid {
  animation: lidclose .16s ease-in-out;
}
@keyframes lidclose {
  0% { opacity: 0; transform: translate(-50%, -50%) scaleY(.12); }
  45% { opacity: 1; transform: translate(-50%, -50%) scaleY(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scaleY(.12); }
}

/* 口型（位置由 JS 标定，张合幅度由 JS 按音量/语流驱动）
   尺寸按 avatar.png 实测唇形标定：唇宽约占图宽 16%，静止时有自然唇线。
   用 SVG 路径绘制真实唇形（上唇唇峰 + 下唇饱满 + 张开露出暗色口腔），
   避免小椭圆缩放后只剩"一条黑线/黑点"的观感问题。
   静止时不可见（照片本身有唇形），只在说话时叠加动态口型 */
#mouth {
  position: absolute;
  width: 16%; height: 9%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
}
#avatar-frame.speaking #mouth { opacity: 1; }

/* 思考：轻微低头 + 缓慢摆动 */
#avatar-frame.thinking .avatar-face {
  animation: thinkSway 3.2s ease-in-out infinite alternate;
}
@keyframes thinkSway {
  from { transform: scale(1.01) translateY(.6%) rotate(.9deg); }
  to   { transform: scale(1.018) translateY(1.4%) rotate(-.6deg); }
}

/* 点头 */
#avatar-frame.nod .avatar-face { animation: nod .7s ease-in-out; }
@keyframes nod {
  0% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(2.4%) rotate(.6deg); }
  60% { transform: translateY(.4%) rotate(-.2deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* 说话时的声波条 */
#avatar-meta { flex: 1; min-width: 0; }
.a-name { font-size: 16px; font-weight: 700; margin-bottom: 6px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: #f3f5fa; border: 1px solid var(--border);
  padding: 3px 12px; border-radius: 999px;
  font-size: 12.5px; color: var(--text-2); margin-bottom: 10px;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .45);
  animation: pulse 2s infinite;
}
#avatar-frame.thinking ~ #avatar-meta .dot { background: var(--warn); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .45); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.wave { display: flex; gap: 4px; align-items: flex-end; height: 22px; margin-bottom: 10px; }
.wave i {
  width: 4px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  height: 5px; opacity: .35;
  transition: height .1s;
}
.wave.active i { animation: wobble 0.9s ease-in-out infinite; }
.wave.active i:nth-child(2) { animation-delay: .12s; }
.wave.active i:nth-child(3) { animation-delay: .24s; }
.wave.active i:nth-child(4) { animation-delay: .36s; }
.wave.active i:nth-child(5) { animation-delay: .48s; }
@keyframes wobble {
  0%, 100% { height: 5px; opacity: .4; }
  50% { height: 20px; opacity: 1; }
}

.a-tip { font-size: 12px; color: var(--text-3); line-height: 1.7; }

/* ---------- 消息区 ----------
   唯一滚动容器：min-height:0 + flex:1 让它在固定头尾之间占据剩余空间，
   聊天记录在其中滚动，头部与数字人舞台保持不动 */
#messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 4px 4px 10px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: #d4dae8; border-radius: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }

.msg {
  display: flex; gap: 10px;
  max-width: 780px;
  margin: 0 auto 14px;
  animation: rise .25s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar-sm {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  margin-top: 2px;
  overflow: hidden;
}
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.msg.ai .avatar-sm { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar-sm { background: linear-gradient(135deg, #94a3b8, #64748b); }

.bubble {
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 14.5px;
  word-break: break-word;
  min-width: 40px;
}
.msg.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .05);
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-top-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.ai .bubble.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

/* Markdown 排版（AI 气泡内） */
.bubble p { margin: 0 0 .55em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.4em; }
.bubble li { margin: .18em 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: .6em 0 .35em; line-height: 1.4; }
.bubble h1 { font-size: 1.18em; } .bubble h2 { font-size: 1.12em; } .bubble h3 { font-size: 1.05em; }
.bubble strong { color: var(--accent); font-weight: 600; }
.bubble a { color: var(--accent); }
.bubble code {
  background: #f1f3f9; border: 1px solid var(--border);
  border-radius: 5px; padding: .1em .38em; font-size: .88em;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}
.bubble pre {
  background: #f7f8fc; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  overflow-x: auto; margin: .5em 0;
}
.bubble pre code { background: none; border: none; padding: 0; font-size: .86em; line-height: 1.55; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: .5em 0; padding: .4em .9em;
  border-radius: 0 8px 8px 0;
  color: var(--text-2);
}
.bubble table { border-collapse: collapse; margin: .5em 0; font-size: .92em; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: .35em .7em; }
.bubble th { background: #f6f8fc; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: .7em 0; }

/* 流式光标 */
.cursor {
  display: inline-block;
  width: 8px; height: 1em; margin-left: 2px;
  vertical-align: -2px; border-radius: 2px;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* 思考动画 */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b6c0d4;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}
/* 等待计时提示：让等待可感知，也便于定位卡在哪一步 */
.wait-note {
  display: block; margin-top: 6px;
  font-size: 12px; color: var(--text-3); letter-spacing: .02em;
}

/* ---------- 快捷提问 ---------- */
#quick-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  max-width: 780px; margin: 0 auto 10px; width: 100%;
  flex-shrink: 0;
}
.quick-btn {
  border: 1px solid var(--border);
  background: #fff; color: var(--text-2);
  font-size: 12.5px; padding: 5px 12px;
  border-radius: 999px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.quick-btn:hover {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-soft); transform: translateY(-1px);
}

/* ---------- 输入区 ---------- */
#composer {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 10px 10px 16px;
  max-width: 780px; margin: 0 auto; width: 100%;
  flex-shrink: 0;
}
#composer:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: none; outline: none; resize: none;
  font: inherit; font-size: 14.5px; line-height: 1.55;
  max-height: 140px; padding: 6px 0;
  background: transparent; color: var(--text);
}
#input::placeholder { color: var(--text-3); }
#send-btn {
  flex-shrink: 0; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; padding: 8px 20px;
  border-radius: 10px; cursor: pointer;
  transition: opacity .15s, transform .15s;
}
#send-btn:hover { opacity: .92; transform: translateY(-1px); }
#send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

#disclaimer {
  text-align: center; font-size: 11px; color: var(--text-3);
  padding: 9px 0 11px;
  flex-shrink: 0;
}

/* 桌面端整体不滚动：仅左侧面板内部与 #messages 各自滚动 */
@media (min-width: 901px) {
  html, body { overflow: hidden; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #chat-panel { padding: 12px 12px 0; }
  #mobile-profile-btn { display: block; }
  #profile-panel {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(340px, 88vw); padding: 12px; z-index: 40;
    background: rgba(20, 26, 43, .45);
    transform: translateX(-105%);
    transition: transform .25s ease;
  }
  body.profile-open #profile-panel { transform: translateX(0); }
  #avatar-stage { padding: 10px 14px; gap: 12px; }
  #avatar-frame { width: 76px; }
  .a-tip { display: none; }
  .msg { margin-bottom: 12px; }
  .bubble { font-size: 14px; }
  #disclaimer { padding: 7px 0 9px; }
}

@media (prefers-reduced-motion: reduce) {
  #avatar-img, .wave.active i, .status-pill .dot { animation: none !important; }
}
