/* ===== 豫小光 · 光明初中数字人 —— 豫园主题样式 ===== */
:root {
  --green-tile: #2f5d50;
  --green-soft: #3b6e5e;
  --gold: #c9a227;
  --red: #b03a2e;
  --red-lantern: #c94436;
  --navy: #2b3a67;
  --ink: #2c2c30;
  --paper: #faf6ee;
  --paper-2: #f3ecdd;
  --radius: 14px;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
  height: 100vh;
  height: 100dvh; /* 移动端/缩放场景更稳的视口高度 */
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: minmax(340px, 46%) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden; /* 双保险：任何子内容溢出一律裁剪，绝不撑高页面 */
}

/* ================= 左侧舞台 ================= */
.stage-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--green-tile);
  min-height: 0;
  overflow: hidden;
}

.eaves {
  width: 100%;
  height: 72px;
  display: block;
  background: var(--paper);
}

.stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

/* 漏窗纹背景 */
.lattice-bg {
  background-color: #34584d;
  background-image:
    radial-gradient(circle at 25% 25%, rgba(201,162,39,.12) 2px, transparent 3px),
    radial-gradient(circle at 75% 75%, rgba(201,162,39,.12) 2px, transparent 3px),
    linear-gradient(45deg, rgba(0,0,0,.08) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.08) 75%),
    linear-gradient(-45deg, rgba(0,0,0,.08) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.08) 75%);
  background-size: 48px 48px, 48px 48px, 48px 48px, 48px 48px;
}

/* 悬挂灯笼 */
.lantern {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: sway 5s ease-in-out infinite alternate;
  transform-origin: top center;
}
.lantern.left  { left: 12%; }
.lantern.right { right: 12%; animation-delay: -2.5s; }
.tassel-line { width: 2px; height: 34px; background: var(--gold); }
.lantern-body {
  position: relative;
  width: 52px; height: 60px;
  background: var(--red-lantern);
  border-radius: 50% / 45%;
  border: 2px solid #8f2b22;
  box-shadow: inset -6px -8px 0 rgba(0,0,0,.12);
}
.lantern-body::before, .lantern-body::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  width: 18px; height: 6px; background: var(--gold); border-radius: 2px;
}
.lantern-body::before { top: -4px; }
.lantern-body::after  { bottom: -4px; }
.lantern-glow {
  position: absolute; inset: -18px;
  background: radial-gradient(circle, rgba(255,184,77,.55), transparent 70%);
  animation: glow 2.4s ease-in-out infinite alternate;
}
.tassel { width: 4px; height: 26px; background: var(--gold); border-radius: 2px; }
@keyframes sway   { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes glow   { from { opacity: .7; } to { opacity: 1; } }

/* 数字人（AI 形象，三帧切换） */
.character {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding-top: 12px;
  animation: bob 4.5s ease-in-out infinite alternate;
  transform-origin: bottom center;
}
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-8px); } }

.char-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}
.char-img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 92%;
  object-fit: contain;
  object-position: bottom;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 14px 22px rgba(0,0,0,.35));
}
.character.talking .char-img {
  filter: drop-shadow(0 14px 22px rgba(0,0,0,.35)) drop-shadow(0 0 20px rgba(255,184,77,.5));
}
/* 地面光影（与浮动同步） */
.char-shadow {
  position: absolute;
  left: 50%; bottom: -4px;
  width: 52%; height: 14px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(0,0,0,.38), transparent 70%);
  animation: shadowPulse 4.5s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes shadowPulse { from { transform: translateX(-50%) scale(1); opacity: 1; } to { transform: translateX(-50%) scale(.86); opacity: .65; } }

/* 名牌 */
.nameplate {
  margin: 6px auto 14px;
  flex-shrink: 0;
  width: fit-content;
  display: flex; align-items: center; gap: 8px;
  background: var(--paper);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: 6px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.np-badge {
  background: var(--red); color: #fff;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
}
.np-name { font-size: 14px; font-weight: 600; }

/* ================= 右侧对话 ================= */
.chat-wrap {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-left: 3px solid var(--gold);
  min-height: 0;   /* 关键：允许网格项收缩，消息增多时由内部滚动区消化，不撑高页面 */
  min-width: 0;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--green-tile), #275043);
  color: #fff;
}
.header-titles h1 { font-size: 20px; letter-spacing: 2px; }
.header-titles h1::before { content: "🏮 "; }
.header-titles p { font-size: 12px; opacity: .85; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 10px;
  font-size: 16px;
  width: 38px; height: 38px;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.28); }
.icon-btn.off { opacity: .45; }

.chat-messages {
  flex: 1;
  min-height: 0;   /* 消息区内部滚动，绝不把父级撑高 */
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { max-width: 82%; padding: 10px 14px; border-radius: var(--radius); line-height: 1.65; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.msg.user {
  align-self: flex-end;
  background: var(--navy); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.ai {
  align-self: flex-start;
  background: #fff;
  border: 1.5px solid #e4dcc8;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(60,50,20,.06);
}
.msg.ai::before { content: "豫小光"; display: block; font-size: 11px; color: var(--green-soft); font-weight: 700; margin-bottom: 4px; }
.msg.user::before { content: "我"; display: block; font-size: 11px; opacity: .7; margin-bottom: 4px; }
.msg .cursor { display: inline-block; width: 8px; animation: caret 1s steps(1) infinite; color: var(--green-soft); }
@keyframes caret { 50% { opacity: 0; } }

/* 快捷问题 */
.quick-questions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 20px 4px;
}
.quick-questions button {
  background: var(--paper-2);
  border: 1.5px solid var(--gold);
  color: #6b5310;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.quick-questions button:hover { background: var(--gold); color: #fff; }

/* 输入区 */
.chat-input {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 20px 16px;
}
.mic-btn {
  width: 46px; height: 46px;
  border: 1.5px solid var(--gold);
  border-radius: 12px;
  background: var(--paper-2);
  font-size: 18px;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.mic-btn:hover { background: var(--gold); }
.mic-btn.listening {
  background: var(--red);
  border-color: var(--red);
  animation: micPulse 1.2s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(176,58,46,.45); }
  50% { box-shadow: 0 0 0 10px rgba(176,58,46,0); }
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #d8cfba;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  max-height: 120px;
  outline: none;
  background: #fff;
}
.chat-input textarea:focus { border-color: var(--green-soft); }
.chat-input #sendBtn {
  width: 46px; height: 46px;
  border: none; border-radius: 12px;
  background: var(--red);
  color: #fff; font-size: 18px;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.chat-input #sendBtn:hover { background: #c94a3c; }
.chat-input #sendBtn:active { transform: scale(.92); }
.chat-input #sendBtn:disabled { background: #c9bfae; cursor: not-allowed; }

/* ============ 实时语音通话：全屏数字人 + 电影字幕 ============ */
.call-overlay {
  position: fixed; inset: 0;
  background: var(--green-tile);
  z-index: 100;
  overflow: hidden;
  animation: callFadeIn .35s ease;
}
@keyframes callFadeIn { from { opacity: 0; } to { opacity: 1; } }
.call-overlay.hidden { display: none; }

.call-scene {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* 全屏角色 */
.call-character {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
  animation: bob 4.5s ease-in-out infinite alternate;
  transform-origin: bottom center;
}
.call-char-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}
.call-char-img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 88%;
  object-fit: contain;
  object-position: bottom;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 16px 26px rgba(0,0,0,.4));
}
.call-character.talking .call-char-img {
  filter: drop-shadow(0 16px 26px rgba(0,0,0,.4)) drop-shadow(0 0 24px rgba(255,184,77,.55));
}
.call-shadow {
  position: absolute;
  left: 50%; bottom: -4px;
  width: 50%; height: 14px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(0,0,0,.4), transparent 70%);
  animation: shadowPulse 4.5s ease-in-out infinite alternate;
  pointer-events: none;
}

/* 状态徽章（右上角） */
.call-status { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; }
.call-status.connecting { background: #f7ecd4; color: #8a6d1a; }
.call-status.live { background: #e3f2e8; color: #1e7a3f; }
.call-status.live::before { content: "● "; animation: blinkDot 1.2s infinite; }
@keyframes blinkDot { 50% { opacity: .3; } }
.call-status.error { background: #fbe4e0; color: #b03a2e; }
.call-overlay > .call-status {
  position: absolute;
  top: 84px; right: 20px;
  z-index: 6;
  font-size: 13px;
  padding: 4px 12px;
}

/* ===== 电影字幕 ===== */
.call-subtitles {
  position: absolute;
  left: 50%; bottom: 74px;
  transform: translateX(-50%);
  width: min(760px, 92%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 5;
  pointer-events: none; /* 不挡住下方操作栏 */
}
.subtitle {
  max-width: 100%;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  padding: 9px 20px;
  border-radius: 10px;
  font-size: 17px;
  line-height: 1.65;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,.65);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  animation: subIn .25s ease;
}
@keyframes subIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.subtitle:empty { display: none; }
.sub-user {
  font-size: 14px;
  background: rgba(0, 0, 0, .38);
  color: #e8e2d2;
  padding: 6px 16px;
}
.sub-ai { font-size: 18px; font-weight: 500; }
.sub-ai::before {
  content: "豫小光";
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #ffd98a;
  margin-bottom: 2px;
}
@media (max-height: 560px) {
  .subtitle { font-size: 15px; padding: 7px 16px; }
  .sub-ai { font-size: 16px; }
  .call-subtitles { bottom: 62px; }
}

/* 底部操作栏 */
.call-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 18px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.5));
  z-index: 6;
}
.call-bar input {
  flex: 1;
  border: 1.5px solid rgba(255,255,255,.35);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  background: rgba(255, 255, 255, .92);
}
.call-bar input:focus { border-color: var(--gold); }
.call-bar button {
  border: none; border-radius: 10px;
  background: rgba(255,255,255,.18);
  color: #fff; font-size: 14px;
  padding: 9px 18px; cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.call-bar button:hover { background: rgba(255,255,255,.3); }
.call-bar .call-end {
  background: var(--red);
  font-weight: 600;
}
.call-bar .call-end:hover { background: #c94a3c; }

#callBtn.in-call { background: var(--red); border-color: var(--red); }
.modal {
  position: fixed; inset: 0;
  background: rgba(30,40,35,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(440px, 92vw);
  background: var(--paper);
  border-radius: 16px;
  border-top: 6px solid var(--green-tile);
  padding: 24px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-card h2 { font-size: 18px; margin-bottom: 6px; }
.modal-tip { font-size: 12.5px; color: #8a8272; margin-bottom: 16px; line-height: 1.5; }
.modal-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.modal-card input {
  width: 100%;
  margin-top: 5px;
  padding: 9px 12px;
  border: 1.5px solid #d8cfba;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.modal-card input:focus { border-color: var(--green-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions button {
  padding: 9px 20px;
  border-radius: 10px;
  border: 1.5px solid #d8cfba;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}
.modal-actions .primary { background: var(--green-tile); color: #fff; border-color: var(--green-tile); }

/* 响应式 */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 42%) minmax(0, 1fr); }
  .chat-wrap { border-left: none; border-top: 3px solid var(--gold); }
}
