:root {
  --navy: #2b3568;        /* 暖调藏青 */
  --navy-dark: #1f2750;
  --gold: #e2b45a;        /* 仅用于点缀装饰 */
  --coral: #e8734a;       /* 主互动强调色 */
  --coral-deep: #c8532e;
  --coral-light: #fce8de;
  --lavender: #b7a4dd;
  --lavender-light: #f2eefa;
  --bg: #fdfbf8;
  --card: #ffffff;
  --text: #2c2620;
  --muted: #8f8a82;
  --border: #ece2d3;
  --user-bubble: #2b3568;
  --radius: 20px;
  font-size: 16px;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
}

.shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-width: 1320px;
  margin: 0 auto;
  box-shadow: 0 0 40px rgba(31, 42, 94, 0.08);
}

/* ---------- 右侧大形象 ---------- */
.figure-panel {
  order: 2; /* 数字人列固定在屏幕右侧 */
  width: 420px;
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px 24px;
  position: relative;
  overflow: hidden;
}
.figure-panel::before,
.figure-panel::after {
  content: "";
  position: absolute;
  border-radius: 4px;
  opacity: 0.35;
}
.figure-panel::before {
  top: 54px; left: 46px;
  width: 14px; height: 14px;
  background: var(--coral);
  border-radius: 50%;
}
.figure-panel::after {
  bottom: 90px; right: 46px;
  width: 18px; height: 18px;
  background: var(--gold);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.figure-wrap {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 4 / 5;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.3s;
  border: 4px solid rgba(255, 255, 255, 0.9);
}
.figure-wrap.speaking {
  box-shadow: 0 0 0 3px var(--coral), 0 10px 44px rgba(232, 115, 74, 0.4);
}
#bigFigure {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.figure-caption { text-align: center; color: #f5f1ea; position: relative; }
.figure-name { font-size: 1.35rem; font-weight: 700; letter-spacing: 1px; }
.figure-name span { font-size: 0.85rem; font-weight: 400; color: #f0a37e; margin-left: 6px; }
.figure-sub { font-size: 0.8rem; color: #a9a2c9; margin-top: 6px; }

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

/* ---------- 头部 ---------- */
.header {
  background: var(--bg);
  color: var(--navy);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.header::before {
  content: "";
  position: absolute;
  top: 14px;
  right: 120px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--coral);
  opacity: 0.4;
}
.header::after {
  content: "";
  position: absolute;
  top: 40px;
  right: 70px;
  width: 12px;
  height: 12px;
  background: var(--gold);
  opacity: 0.45;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.header-inner { display: flex; align-items: center; gap: 14px; }
.header-text h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.5px; color: var(--navy); }
.header-text p { font-size: 0.8rem; color: var(--muted); opacity: 1; margin-top: 5px; }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border: none;
  border-radius: 999px;
  font-size: 0.68rem;
  color: #fff;
  background: var(--coral);
  opacity: 1;
}

/* ---------- 头像 ---------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--lavender-light);
  color: var(--navy);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.05rem;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- 数字人面板 ---------- */
.human-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  margin: 0 20px 6px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 6px 18px rgba(60, 50, 30, 0.07);
  flex-shrink: 0;
}
.human-figure {
  position: relative;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
}
.human-photo {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 3px dashed var(--lavender);
  padding: 3px;
  box-sizing: border-box;
  box-shadow: 0 2px 12px rgba(43, 53, 104, 0.15);
}
.human-figure::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #c7c2b8;
  border: 3px solid #fff;
  transition: background 0.2s;
}
.human-panel:has(.human-status.active) .human-figure::after { background: #4fb37a; }
.human-info { flex: 1; min-width: 0; }
.human-name { font-weight: 700; color: var(--navy); font-size: 1.05rem; }
.human-name span { font-weight: 400; font-size: 0.78rem; color: var(--muted); margin-left: 6px; }
.human-status { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.human-status.active { color: #4fb37a; font-weight: 500; }

.human-controls { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.lang-toggle {
  display: flex;
  background: var(--lavender-light);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 15px;
  font-size: 0.82rem;
  cursor: pointer;
  border-radius: 999px;
}
.lang-toggle button.active { background: var(--navy); color: #fff; }
.voice-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  border: none;
  border-radius: 999px;
  background: var(--lavender-light);
  color: var(--muted);
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}
.voice-toggle.active { color: var(--coral-deep); background: var(--coral-light); font-weight: 500; }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; max-width: 92%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: var(--coral-light); color: var(--coral-deep); }

.bubble {
  background: var(--lavender-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  line-height: 1.75;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.msg.assistant .bubble { border-top-left-radius: 6px; }
.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 6px;
  white-space: pre-wrap;
}

.bubble-content p { margin: 0.4em 0; }
.bubble-content p:first-child { margin-top: 0; }
.bubble-content p:last-child { margin-bottom: 0; }
.bubble-content ul, .bubble-content ol { margin: 0.4em 0; padding-left: 1.4em; }
.bubble-content li { margin: 0.15em 0; }
.bubble-content h1, .bubble-content h2, .bubble-content h3 {
  font-size: 1em;
  margin: 0.7em 0 0.3em;
  color: var(--navy);
}
.bubble-content code {
  background: rgba(43, 53, 104, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.88em;
}
.bubble-content table { border-collapse: collapse; margin: 0.5em 0; font-size: 0.9em; }
.bubble-content th, .bubble-content td { border: 1px solid var(--border); padding: 4px 10px; }
.bubble-content th { background: var(--lavender-light); }

.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}
.sources .tag {
  display: inline-block;
  background: #e2dbf5;
  color: var(--navy);
  border-radius: 999px;
  padding: 1px 10px;
  margin: 2px 4px 0 0;
}

.error-text { color: #b42318; }

/* ---------- 消息工具条 ---------- */
.msg { flex-wrap: wrap; }
.msg .bubble { flex: 1; min-width: 0; }
.msg-tools {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  width: 100%;
  padding-left: 50px; /* 对齐气泡（头像 40px + 间距 10px） */
}
.msg.user .msg-tools {
  justify-content: flex-end;
  padding-left: 0;
  padding-right: 50px;
}
.msg-tools button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 2px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.msg-tools button:hover { color: var(--navy); border-color: var(--navy); }
.msg-tools button:disabled { opacity: 0.5; cursor: wait; }

.translation {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.msg.user .translation { border-top-color: rgba(255, 255, 255, 0.35); }
.translation-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg.user .translation-label { color: rgba(255, 255, 255, 0.7); }

/* 打字指示 */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--navy);
  opacity: 0.35;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- 快捷提问 ---------- */
.suggestions {
  display: flex;
  gap: 8px;
  padding: 0 20px 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.suggestions button {
  border: 1.5px solid var(--coral);
  background: transparent;
  color: var(--coral-deep);
  font-weight: 500;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.suggestions button:hover { background: var(--coral); color: #fff; }

/* ---------- 输入区 ---------- */
.composer {
  padding: 10px 20px 10px;
  flex-shrink: 0;
  background: var(--bg);
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--lavender-light);
  border-radius: 999px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 4px 14px rgba(60, 50, 30, 0.06);
  transition: border-color 0.15s;
}
.composer-inner:focus-within { border-color: var(--coral); }
#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  max-height: 140px;
  background: transparent;
}
#mic {
  border: none;
  background: var(--lavender-light);
  color: var(--navy);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
#mic:hover { background: #e2dbf5; }
#mic.recording {
  background: #b42318;
  color: #fff;
  animation: mic-blink 1s infinite;
}
@keyframes mic-blink { 0%, 100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.5); } 50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, 0); } }
#mic:disabled { background: #f0f1f5; color: #b6bccd; cursor: not-allowed; }

#send {
  border: none;
  background: var(--coral);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#send:hover { background: var(--coral-deep); }
#send:disabled { background: #b6bccd; cursor: not-allowed; }

.disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- 手机 / 窄屏：数字人变为顶部横条，聊天占满剩余空间 ---------- */
@media (max-width: 980px) {
  .shell { flex-direction: column; }
  .figure-panel {
    order: 0; /* 手机上放顶部 */
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .figure-wrap {
    width: 76px;
    max-width: 76px;
    flex-shrink: 0;
    border-radius: 16px;
    border-width: 2px;
  }
  .figure-caption { text-align: left; }
  .figure-name { font-size: 1rem; }
  .figure-sub { font-size: 0.72rem; margin-top: 2px; }
  .app { height: auto; flex: 1; min-height: 0; }
  /* 顶部标题栏与数字人横条信息重复，手机上收窄 */
  .header { padding: 10px 16px; }
}

@media (max-width: 600px) {
  .app { box-shadow: none; }
  .msg { max-width: 100%; }
  .header-text h1 { font-size: 0.92rem; }
  .header-text p { font-size: 0.72rem; }
  .badge { display: block; width: fit-content; margin: 3px 0 0; }

  /* 小头像一行 + 控件换行紧凑排布 */
  .human-panel { flex-wrap: wrap; gap: 8px; padding: 8px 12px; margin: 0 10px 6px; border-radius: 18px; }
  .human-figure { width: 52px; height: 52px; }
  .human-controls { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  .voice-toggle, .lang-toggle button { font-size: 0.78rem; padding: 4px 10px; }

  /* 快捷提问横向滑动，不挤占竖向空间 */
  .suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px 8px;
    scrollbar-width: none;
  }
  .suggestions::-webkit-scrollbar { display: none; }
  .suggestions button { flex-shrink: 0; }

  .chat { padding: 14px 12px; gap: 14px; }
  .bubble { font-size: 0.92rem; padding: 10px 13px; }
  .msg-tools { padding-left: 46px; }
  .msg.user .msg-tools { padding-right: 46px; }

  /* iOS 上输入框字号 <16px 聚焦会自动放大页面 */
  #input { font-size: 16px; }
  .composer { padding: 8px 12px calc(6px + env(safe-area-inset-bottom)); }
  .disclaimer { font-size: 0.62rem; margin-top: 5px; }

  /* 实时对话面板占屏更高些 */
  #liveFrame { height: min(46vh, 420px); }
}
