:root {
  --navy: #1f2a5e;        /* 西浦深蓝 */
  --navy-dark: #17204a;
  --gold: #c9a227;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #24292f;
  --muted: #6b7280;
  --border: #e3e7ef;
  --user-bubble: #1f2a5e;
  --radius: 14px;
  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: linear-gradient(165deg, #1b2450, #10162e 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px 24px;
  border-left: 3px solid var(--gold);
}
.figure-wrap {
  position: relative;
  width: 100%;
  max-width: 380px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.3s;
}
.figure-wrap.speaking {
  box-shadow: 0 0 0 3px var(--gold), 0 10px 44px rgba(201, 162, 39, 0.4);
}
#bigFigure {
  display: block;
  width: 100%;
  height: auto;
}
.figure-caption { text-align: center; color: #e8ebf5; }
.figure-name { font-size: 1.35rem; font-weight: 700; letter-spacing: 1px; }
.figure-name span { font-size: 0.85rem; font-weight: 400; color: var(--gold); margin-left: 6px; }
.figure-sub { font-size: 0.8rem; color: #9aa3c4; margin-top: 6px; }

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

/* ---------- 头部 ---------- */
.header {
  background: linear-gradient(135deg, var(--navy-dark), var(--navy));
  color: #fff;
  padding: 14px 20px;
  border-bottom: 3px solid var(--gold);
  flex-shrink: 0;
}
.header-inner { display: flex; align-items: center; gap: 14px; }
.header-text h1 { font-size: 1.05rem; font-weight: 600; letter-spacing: 0.5px; }
.header-text p { font-size: 0.8rem; opacity: 0.85; margin-top: 3px; }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  font-size: 0.68rem;
  opacity: 0.9;
}

/* ---------- 头像 ---------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy-dark);
  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;
  background: linear-gradient(180deg, #f7f8fc, #fff);
  border-bottom: 1px solid var(--border);
  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 solid #fff;
  box-shadow: 0 2px 12px rgba(31, 42, 94, 0.25);
}
.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: #1a7f37; }

.human-controls { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  border: none;
  background: #fff;
  color: var(--muted);
  padding: 5px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}
.lang-toggle button.active { background: var(--navy); color: #fff; }
.voice-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}
.voice-toggle.active { border-color: var(--gold); color: var(--navy); background: #fdf8ea; }

/* ---------- 聊天区 ---------- */
.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: #d8ddeb; color: var(--navy); }

.bubble {
  background: #f1f3f9;
  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: 4px; }
.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 4px;
  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(31, 42, 94, 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: #eaedf5; }

.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: #eaedf5;
  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: 1px solid var(--border);
  background: #fff;
  color: var(--navy);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.suggestions button:hover { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid var(--border);
  padding: 12px 20px 10px;
  flex-shrink: 0;
  background: var(--card);
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.composer-inner:focus-within { border-color: var(--navy); }
#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: #eef0f7;
  color: var(--navy);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
#mic:hover { background: #dde2f0; }
#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(--navy);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#send:hover { background: var(--navy-dark); }
#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));
    border-left: none;
    border-bottom: 3px solid var(--gold);
  }
  .figure-wrap {
    width: 76px;
    max-width: 76px;
    flex-shrink: 0;
    border-radius: 10px;
  }
  .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; }
  .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); }
}
