:root {
  --bg: #ffffff;
  --panel: #f5f7fb;
  --panel-2: #eef1f7;
  --accent: #4f8cff;
  --accent-strong: #2f6fe0;
  --text: #1c2130;
  --muted: #737d92;
  --line: rgba(20, 28, 48, .10);
}

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

html, body {
  height: 100%;
  width: 100%;
  /* 与序列帧背景一致（不透明白），使帧无缝融合 */
  background: #ffffff;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}
/* 输入框允许选中/编辑 */
#text-input { -webkit-user-select: text; user-select: text; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: #ffffff;
  overflow: hidden;
}

/* 舞台（竖屏区域） */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #ffffff;
}

#avatar-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.6s cubic-bezier(.22, .61, .36, 1), opacity 0.4s ease;
  transform-origin: 50% 100%;
}
#avatar-wrap.hidden-avatar {
  transform: scale(0);
  opacity: 0;
}

/* 帧本身为不透明白底，不能加投影（否则露出矩形边框） */
#pig-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

/* 状态气泡 */
#state-bubble {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 1px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(20, 28, 48, .06);
  white-space: nowrap;
  z-index: 21;
}
.state-init   { color: var(--muted); }
.state-listen { color: #0f9d58; border-color: rgba(15, 157, 88, .35); }
.state-think  { color: #b7791f; }
.state-say    { color: var(--accent-strong); border-color: rgba(79, 140, 255, .40); }

/* 用户提问气泡 */
#question-bubble {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 14px;
  background: #eef3ff;
  color: #243b6b;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  border: 1px solid rgba(79, 140, 255, .25);
  box-shadow: 0 2px 10px rgba(20, 28, 48, .05);
  z-index: 20;
  transition: opacity .25s ease;
}
#question-bubble::before { content: "你问："; color: #7b8bb0; }

/* 底部字幕（AI 回答，打字机，完整展示 + 可滚动回看） */
#subtitle {
  flex: 0 0 auto;            /* 不被舞台压缩，保证长回复能完整显示 */
  width: 92%;
  max-height: 38vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
  line-height: 1.65;
  letter-spacing: .4px;
  color: var(--text);
  background: rgba(255, 255, 255, .85);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 8px auto 4px;
  box-shadow: 0 2px 10px rgba(20, 28, 48, .04);
}
#subtitle:empty { display: none; }

/* 麦克风音量条 */
#mic-meter {
  width: 60%;
  height: 6px;
  margin: 4px auto 10px;
  border-radius: 999px;
  background: rgba(20, 28, 48, .10);
  overflow: hidden;
}
#mic-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #34c77b, #f0b429, #f0655a);
  transition: width 0.08s linear;
}

/* 输入兜底 */
#input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#text-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(20, 28, 48, .16);
  background: #ffffff;
  color: var(--text);
  font-size: 16px; /* 16px 以上可避免 iOS 聚焦时自动放大页面 */
  outline: none;
  touch-action: manipulation;
}
#text-input:focus { border-color: var(--accent); }
#send-btn, #unlock-btn {
  padding: 12px 18px;
  min-height: 44px; /* 触摸目标最小 44px */
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
/* 打断按钮（AI 回答中出现，点击立即中止并重新聆听） */
#interrupt-btn {
  padding: 12px 16px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  background: #f0655a;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  box-shadow: 0 2px 10px rgba(240, 101, 90, .35);
}
#send-btn:disabled { background: #c7d0e0; }

/* Toast */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(28, 33, 48, .94);
  color: #fff;
  border: 1px solid rgba(0, 0, 0, .1);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 80%;
  text-align: center;
  z-index: 30;
  box-shadow: 0 6px 20px rgba(20, 28, 48, .18);
}

/* 解锁遮罩（与白底一致） */
#unlock-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  /* 避开刘海 / 底部安全区 */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.unlock-card { text-align: center; }
.unlock-title { font-size: 34px; font-weight: 800; letter-spacing: 4px; color: var(--text); }
.unlock-sub { color: var(--muted); margin: 8px 0 28px; letter-spacing: 2px; }
#unlock-btn { font-size: 17px; padding: 14px 28px; }

.hidden { display: none !important; }
