/* ============================================================
   小星 · 可交互数字人  — 样式表
   ============================================================ */

:root {
  --ink: #2f2b57;
  --ink-soft: #5b5480;
  --accent: #7c6ff0;
  --accent-2: #a18cff;
  --line: #e6e2f8;
  --radius: 26px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #e9f0ff 0%, #ffeef5 46%, #f1ecff 100%);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage {
  display: flex;
  gap: 18px;
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------------- 左侧：角色面板 ---------------- */

#avatarPanel {
  position: relative;
  flex: 1.02;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 18px 50px rgba(110, 96, 210, 0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.18));
}

#avatarPanel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 85% at 50% 8%, var(--tint, #dbe7ff) 0%, rgba(255, 255, 255, 0) 72%);
  opacity: 0.55;
  pointer-events: none;
}

#avatarPanel .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  pointer-events: none;
}
#avatarPanel .orb.o1 {
  width: 150px; height: 150px; left: -40px; bottom: 6%;
  background: rgba(255, 255, 255, 0.5);
  animation: floaty 7s ease-in-out infinite;
}
#avatarPanel .orb.o2 {
  width: 90px; height: 90px; right: -18px; top: 20%;
  background: rgba(255, 255, 255, 0.45);
  animation: floaty 9s ease-in-out infinite reverse;
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-16px); }
}

/* 心情配色 */
#avatarPanel[data-mood="happy"]     { --tint: #ffe1ee; }
#avatarPanel[data-mood="sad"]       { --tint: #d9e4f5; }
#avatarPanel[data-mood="angry"]     { --tint: #ffdcdc; }
#avatarPanel[data-mood="surprised"] { --tint: #fff0d2; }
#avatarPanel[data-mood="thinking"]  { --tint: #e4e0ff; }
#avatarPanel[data-mood="normal"]    { --tint: #dbe7ff; }

#avatarWrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px 6px 0;
}

#avatarSvg {
  width: min(78%, 430px);
  height: auto;
  max-height: 100%;
  display: block;
  z-index: 1;
}

#nameTag {
  position: absolute;
  top: 14px;
  left: 18px;
  z-index: 2;
  font-size: 15px;
  font-weight: 700;
  color: #6a63a8;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.9);
  padding: 6px 14px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* 特效层 */
#fxLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.fx {
  position: absolute;
  transform: translate(-50%, -50%);
  animation: fxUp var(--dur, 1.8s) cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
  will-change: transform, opacity;
}

@keyframes fxUp {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% - 140px)) scale(1.2); }
}

.thinkBubble {
  position: absolute;
  left: 46%;
  top: 24%;
  background: #fff;
  border-radius: 14px;
  padding: 9px 13px;
  box-shadow: 0 6px 18px rgba(90, 70, 180, 0.2);
  display: flex;
  gap: 5px;
  animation: popIn 0.25s ease-out, popOut 0.25s ease-in 2s forwards;
}
.thinkBubble::after {
  content: "";
  position: absolute;
  left: 20px;
  bottom: -8px;
  width: 12px; height: 12px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px;
}
.thinkBubble i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #a694ff;
  animation: dottle 1s ease-in-out infinite;
}
.thinkBubble i:nth-child(2) { animation-delay: 0.15s; }
.thinkBubble i:nth-child(3) { animation-delay: 0.3s; }

@keyframes dottle {
  0%, 100% { transform: translateY(0); opacity: 0.45; }
  50% { transform: translateY(-5px); opacity: 1; }
}
@keyframes popIn  { from { opacity: 0; transform: scale(0.7) translateY(8px); } }
@keyframes popOut { to   { opacity: 0; transform: scale(0.9) translateY(6px); } }

/* ---------------- 角色动作按钮 ---------------- */

#avatarActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 10px 14px 16px;
  position: relative;
  z-index: 2;
}

.actBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.78);
  color: #575079;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.actBtn:hover {
  transform: translateY(-2px);
  background: #fff;
  box-shadow: 0 8px 18px rgba(110, 96, 210, 0.18);
}
.actBtn:active { transform: translateY(0) scale(0.96); }
.actBtn span { font-size: 16px; }

/* ---------------- 右侧：聊天面板 ---------------- */

#chatPanel {
  flex: 1.18;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 18px 50px rgba(110, 96, 210, 0.14);
  overflow: hidden;
}

.hd {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  background: rgba(255, 255, 255, 0.5);
}

.logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffa7cf, #a18cff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  box-shadow: 0 4px 12px rgba(180, 130, 220, 0.35);
  animation: bob 3.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.titles { flex: 1; min-width: 0; }
.titles h1 { margin: 0; font-size: 16.5px; }
.titles small { color: var(--ink-soft); font-size: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  background: rgba(18, 183, 106, 0.12);
  color: #109c5b;
  transition: background 0.25s, color 0.25s;
}
.pill .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: currentColor;
  animation: dotPulse 2s ease-out infinite;
}
.pill.think  { background: rgba(247, 144, 9, 0.14);  color: #d97f06; }
.pill.speak  { background: rgba(46, 124, 246, 0.12); color: #2e7cf6; }
.pill.listen { background: rgba(194, 65, 176, 0.12); color: #c241b0; }
.pill.speak .dot { animation-duration: 0.9s; }
.pill.listen .dot { animation-duration: 0.8s; }

@keyframes dotPulse {
  0%    { box-shadow: 0 0 0 0 rgba(127, 127, 127, 0.35); }
  80%,100% { box-shadow: 0 0 0 7px rgba(127, 127, 127, 0); }
}

.hdbtns { display: flex; gap: 8px; }
.iconBtn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.iconBtn:hover { transform: translateY(-1px); box-shadow: 0 5px 12px rgba(110, 96, 210, 0.18); }

/* 消息区 */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 6px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: #dcd6f5; border-radius: 8px; }
#messages::-webkit-scrollbar-track { background: transparent; }

.msg {
  display: flex;
  gap: 8px;
  margin: 10px 0;
  opacity: 0;
  animation: msgIn 0.28s ease forwards;
  align-items: flex-end;
}
.msg.user { justify-content: flex-end; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatarIcon {
  width: 30px; height: 30px;
  flex: none;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-bottom: 2px;
}

.bubble {
  max-width: 76%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 6px 16px rgba(124, 111, 240, 0.3);
}

.msg.bot .bubble {
  background: #fff;
  border: 1px solid #efeafa;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 4px 14px rgba(80, 70, 160, 0.08);
}

.bubble.typing { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.bubble.typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #b6adf0;
  animation: dottle 1s ease-in-out infinite;
}
.bubble.typing i:nth-child(2) { animation-delay: 0.15s; }
.bubble.typing i:nth-child(3) { animation-delay: 0.3s; }

/* 快捷语 */
#chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 10px;
}
.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.16s;
  font-family: inherit;
}
.chip:hover {
  border-color: var(--accent-2);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(124, 111, 240, 0.16);
}

/* 输入区 */
#inputRow {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  background: rgba(255, 255, 255, 0.5);
}
#inputWrap { flex: 1; position: relative; }
#txt {
  width: 100%;
  padding: 11px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#txt:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(161, 140, 255, 0.16);
}
#inputHint {
  font-size: 11px;
  color: #a5a0c8;
  text-align: right;
  margin-top: 4px;
}

.roundBtn {
  width: 46px; height: 46px;
  flex: none;
  border-radius: 50%;
  border: none;
  font-size: 19px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
}
.roundBtn:hover { transform: translateY(-2px); }
.roundBtn:active { transform: scale(0.94); }

#micBtn {
  background: #fff;
  border: 1.5px solid var(--line);
}
#micBtn.rec {
  background: #ff4d6d;
  border-color: transparent;
  animation: micPulse 1.1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(255, 77, 109, 0); }
}

#sendBtn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 16px rgba(124, 111, 240, 0.35);
}
#sendBtn:disabled { opacity: 0.45; cursor: default; transform: none; }

#stopBtn {
  display: none;
  background: #fff;
  border: 1.5px solid #ffc9c9;
  color: #f05252;
  font-size: 17px;
}
#stopBtn.show { display: flex; }

/* ---------------- 开始遮罩 ---------------- */

#startOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(165deg, #eaf0ff 0%, #ffeef6 55%, #f3edff 100%);
  transition: opacity 0.5s ease;
}
#startOverlay.hidden { opacity: 0; pointer-events: none; }

.bigAvatar {
  width: 148px; height: 148px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 108px;
  line-height: 1;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(150, 110, 210, 0.25);
  animation: bob 3.2s ease-in-out infinite;
  padding-top: 8px;
}
.bigAvatar span { transform: translateY(6px); }

#startOverlay h1 {
  margin: 6px 0 0;
  font-size: 26px;
  background: linear-gradient(90deg, #7c6ff0, #e86fa8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#startOverlay .sub {
  color: #6d6894;
  font-size: 14.5px;
  max-width: 460px;
  text-align: center;
  line-height: 1.7;
  padding: 0 20px;
}

#startBtn {
  margin-top: 10px;
  padding: 14px 44px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, #7c6ff0, #e86fa8);
  box-shadow: 0 10px 26px rgba(150, 100, 220, 0.4);
  animation: startPulse 2s ease-in-out infinite;
  transition: transform 0.18s;
}
#startBtn:hover { transform: translateY(-2px) scale(1.02); }

@keyframes startPulse {
  0%, 100% { box-shadow: 0 10px 26px rgba(150, 100, 220, 0.4); }
  50% { box-shadow: 0 10px 40px rgba(230, 100, 170, 0.55); }
}

.featureRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 0 20px;
}
.fp {
  font-size: 12.5px;
  color: #6d6894;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.95);
  padding: 6px 13px;
  border-radius: 999px;
}

/* ---------------- 设置弹窗 ---------------- */

.mask {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(35, 32, 77, 0.4);
  backdrop-filter: blur(6px);
}
.mask.open { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } }

.card {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 22px;
  padding: 22px 24px;
  box-shadow: 0 24px 70px rgba(40, 30, 90, 0.3);
  animation: cardIn 0.25s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.card h2 { margin: 0 0 4px; font-size: 19px; }
.card p.sub { margin: 0 0 12px; color: #8a85b5; font-size: 13px; }

.srow { margin: 13px 0; }
.srow label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: #6d6894;
  margin-bottom: 5px;
}
.srow input[type="text"],
.srow input[type="password"],
.srow input[type="number"],
.srow select {
  width: 100%;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  background: #fbfaff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.srow input:focus, .srow select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(161, 140, 255, 0.15);
  background: #fff;
}

.krow { display: flex; gap: 8px; align-items: center; }
.krow input { flex: 1; }
.krow .iconBtn { flex: none; width: 40px; height: 40px; }

.rangeRow { display: flex; align-items: center; gap: 12px; }
.rangeRow input[type="range"] { flex: 1; accent-color: var(--accent); }
.rangeRow output {
  min-width: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: #f2eefe;
  border-radius: 8px;
  padding: 3px 6px;
}

.checkRow { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.checkRow input { width: 17px; height: 17px; accent-color: var(--accent); }

.khint {
  background: #fff7e8;
  border: 1px solid #ffe3ad;
  color: #8a6a1d;
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.6;
  margin: 12px 0;
}
.khint b { display: block; margin-bottom: 2px; }

.foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}
.btn {
  padding: 10px 20px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.16s;
}
.btn:hover { border-color: var(--accent-2); color: var(--accent); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  box-shadow: 0 6px 16px rgba(124, 111, 240, 0.35);
}
.btn.primary:hover { color: #fff; transform: translateY(-1px); }

/* ---------------- 响应式 ---------------- */

@media (max-width: 940px) {
  body { overflow: auto; height: auto; }
  #stage { flex-direction: column; height: auto; padding: 10px; }
  #avatarPanel { min-height: 420px; flex: none; }
  #avatarImg { width: min(66%, 320px); }
  #chatPanel { height: 62vh; flex: none; }
}

@media (max-width: 520px) {
  #avatarPanel { min-height: 380px; }
  .bubble { max-width: 84%; font-size: 14.5px; }
  #startOverlay h1 { font-size: 22px; }
  .bigAvatar { width: 122px; height: 122px; font-size: 88px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   弦仔立绘动画：呼吸 / 说话 / 动作 / 视图切换
   ============================================================ */

#avatarStage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

#avatarImg {
  max-width: min(74%, 400px);
  max-height: 82%;
  object-fit: contain;
  transform-origin: 50% 94%;
  transition: transform 0.3s ease;
}

@keyframes imgBob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.01); }
}

/* 说话：轻快起伏（静态立绘无法改口型，用整体律动表达） */
#avatarImg.talking { animation: talkPulse 0.42s ease-in-out infinite; }
@keyframes talkPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.03); }
}

/* 动作 */
#avatarImg.action-wave { animation: imgWave 0.8s ease-in-out 2; }
@keyframes imgWave {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: rotate(-6deg) translateX(-6px); }
  50% { transform: rotate(5deg) translateX(6px); }
  75% { transform: rotate(-4deg) translateX(-4px); }
}
#avatarImg.action-heart { animation: imgBounce 0.6s ease 2; }
@keyframes imgBounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.06); }
}
#avatarImg.action-happy { animation: imgJump 0.5s ease-in-out 2; }
@keyframes imgJump {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-20px) scale(1.03); }
  60% { transform: translateY(0) scale(0.98); }
  80% { transform: translateY(-8px) scale(1.01); }
}
#avatarImg.action-cheer { animation: imgBounce 0.6s ease 2; }
#avatarImg.action-think {
  animation: none;
  transform: scale(0.97) rotate(1.5deg);
  filter: brightness(0.97) saturate(0.92) drop-shadow(0 16px 28px rgba(120, 90, 200, 0.30));
}