:root {
  --bg: #0b0e16;
  --panel: #121726;
  --panel-2: #1a2236;
  --line: #26304a;
  --text: #e6ebf5;
  --faint: #8b96b0;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #15203a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(18, 23, 38, 0.7); backdrop-filter: blur(6px);
}
.brand { font-weight: 700; letter-spacing: 1px; }
.modes { display: flex; gap: 8px; margin-left: 8px; }
.mode {
  background: var(--panel-2); color: var(--faint); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.mode.active { color: #04121a; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.status { margin-left: auto; font-size: 12px; color: var(--accent); }

.stage { flex: 1; display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; padding: 22px; min-height: 0; }
.avatar-pane {
  position: relative; border: 1px solid var(--line); border-radius: 18px;
  background: linear-gradient(180deg, #0f1626, #0b0e16);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.avatar { text-align: center; }
/* 照片头像：圆形渐变描边 + 说话时（光环呼吸 / 轻微缩放 / 声波柱）三件套 */
.photo-frame {
  width: 200px; height: 200px; border-radius: 50%;
  margin: 0 auto; position: relative; padding: 4px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 40px rgba(45, 212, 191, 0.15);
}
.photo-frame .photo {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; display: block;
  border: 2px solid var(--bg); background: var(--panel-2);
}
.photo-frame.talking { animation: avatar-pulse 1.2s ease-in-out infinite; }
@keyframes avatar-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 30px rgba(45, 212, 191, 0.2); }
  50% { transform: scale(1.02); box-shadow: 0 0 55px rgba(45, 212, 191, 0.45); }
}
/* 真唇形覆盖层（v9）：从原照片抠出的上下唇 PNG（lip-top/lip-bottom，裁剪版），
   按唇带 bbox 定位（extract-lips.py 实测值，换照片重跑脚本更新此处）。
   静止：两层拼合 = 原嘴唇（羽化边缘与原照片融合，无缝）。
   说话：上唇微抬 + 下唇下沉，中间露 mouth-cavity 暗色口腔。 */
.photo-frame .lip {
  position: absolute;
  pointer-events: none;
}
.photo-frame .lip-top {
  left: 31.64%; top: 48.44%;
  width: 39.26%; height: 10.35%;
}
.photo-frame .lip-bottom {
  left: 31.64%; top: 58.79%;
  width: 39.26%; height: 7.81%;
}
.photo-frame .mouth-cavity {
  position: absolute;
  left: 50%; top: 58.79%;           /* 唇缝位置（extract-lips.py v5 红度断崖实测 y=301/58.79%） */
  width: 13%; height: 0;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, #2d0f13 0%, #1f0a0d 60%, rgba(31, 10, 13, 0) 100%);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.photo-frame.talking .mouth-cavity {
  animation: cavity-talk 0.3s ease-in-out infinite;
}
.photo-frame.talking .lip-top {
  animation: lip-top-talk 0.3s ease-in-out infinite;
}
.photo-frame.talking .lip-bottom {
  animation: lip-bottom-talk 0.3s ease-in-out infinite;
}
@keyframes cavity-talk {
  0%, 100% { height: 0.5%; opacity: 0.3; }
  50%      { height: 3.5%; opacity: 0.9; }
}
@keyframes lip-top-talk {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.5px); }
}
@keyframes lip-bottom-talk {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(6px); }
}
/* 即梦真说话视频层（v11）：叠在照片框最上层（object-fit: cover 铺满圆形框）。
   静止隐藏；.video-talking 时淡入并循环播放（JS 控制 play/pause）。
   视频不可用（404/解码失败）时该类永不激活，自动回退上方唇形动画。 */
.photo-frame .talk-video {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  background: var(--panel-2);
}
.photo-frame.video-talking .talk-video {
  opacity: 1;
}
/* 视频播出时藏掉照片与唇形层，避免视频半透明边缘处穿帮 */
.photo-frame.video-talking .photo,
.photo-frame.video-talking .lip {
  opacity: 0;
  transition: opacity 0.3s ease;
}
/* 声波柱：静默时半透明矮柱，说话时逐根跳动 */
.wave {
  display: flex; gap: 5px; justify-content: center; align-items: flex-end;
  height: 26px; margin-top: 14px; opacity: 0.35; transition: opacity 0.2s ease;
}
.wave span {
  width: 4px; height: 6px; border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.wave.on { opacity: 1; }
.wave.on span { animation: wave-bounce 0.7s ease-in-out infinite; }
.wave.on span:nth-child(2) { animation-delay: 0.12s; }
.wave.on span:nth-child(3) { animation-delay: 0.24s; }
.wave.on span:nth-child(4) { animation-delay: 0.36s; }
.wave.on span:nth-child(5) { animation-delay: 0.48s; }
@keyframes wave-bounce {
  0%, 100% { height: 6px; }
  50% { height: 24px; }
}
.name { margin-top: 18px; color: var(--faint); letter-spacing: 2px; }
.vh-video { width: 100%; height: 100%; }
.vh-hint { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; color: var(--faint); font-size: 12px; }
.hidden { display: none !important; } /* !important：.composer 等后定义的同级规则不得顶掉它（曾导致兜底输入框常显） */

.chat-pane { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.6; font-size: 14px; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #04121a; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); }
.msg.sys { align-self: center; background: transparent; color: var(--faint); font-size: 12px; }
/* 主交互区：按住说话大圆钮（居中）；fallback 行覆盖为左对齐文字输入 */
.composer { display: flex; justify-content: center; padding: 18px 14px; border-top: 1px solid var(--line); }
.composer.fallback { justify-content: flex-start; gap: 10px; padding: 14px; }
.composer input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-size: 14px; outline: none;
}
.composer input:focus { border-color: var(--accent); }
.composer button {
  background: var(--accent); color: #04121a; border: none; border-radius: 10px;
  padding: 0 20px; font-weight: 600; cursor: pointer;
}
/* 按住说话（Push-to-Talk）：大圆钮，图标 + 文案；录音中变红脉冲 */
.ptt {
  width: 132px; height: 132px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--panel-2), #10161f);
  border: 1px solid var(--line); color: var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: none; /* 按住时禁止页面滚动/缩放干扰手势 */
  transition: transform 0.12s ease, border-color 0.2s ease, color 0.2s ease;
  box-shadow: 0 0 30px rgba(45, 212, 191, 0.12);
}
.ptt:hover { border-color: var(--accent); }
.ptt:active { transform: scale(0.96); }
.ptt.recording {
  transform: scale(0.96);
  border-color: #f87171; color: #f87171;
  background: radial-gradient(circle at 30% 30%, rgba(248, 113, 113, 0.18), #1a1216);
  animation: micPulse 1.2s infinite;
}
.ptt-label { font-size: 13px; letter-spacing: 2px; font-weight: 600; }
@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35); }
  70% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}
.mic-status { padding: 0 14px 10px; font-size: 12px; color: var(--faint); min-height: 16px; }

@media (max-width: 760px) {
  .stage { grid-template-columns: 1fr; }
  .ptt { width: 108px; height: 108px; }
  .photo-frame { width: 160px; height: 160px; }
}
