:root {
  --bg-top: #e8f6ff;
  --bg-bottom: #fff8e8;
  --card-bg: rgba(255, 255, 255, 0.92);
  --text-main: #2f2a24;
  --text-sub: #6c655c;
  --primary: #ff8a3d;
  --primary-hover: #f37424;
  --danger: #ef5350;
  --danger-hover: #dc3c39;
  --mint: #2ec4b6;
  --sky: #4ea8de;
  --lavender: #8b7cf6;
  --sun: #ffd166;
  --border: rgba(47, 42, 36, 0.08);
  --shadow: 0 14px 36px rgba(68, 92, 128, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  background: linear-gradient(180deg, var(--bg-top) 0%, #f5fbff 48%, var(--bg-bottom) 100%);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* 柔和云朵背景 */
.sky-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  filter: blur(2px);
}

.cloud-1 {
  width: 220px;
  height: 70px;
  top: 6%;
  left: -30px;
}

.cloud-2 {
  width: 260px;
  height: 82px;
  top: 14%;
  right: -40px;
}

.cloud-3 {
  width: 180px;
  height: 60px;
  bottom: 12%;
  left: 8%;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 顶部栏 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, #ffe07d, #ffb347);
  display: grid;
  place-items: center;
  font-size: 26px;
  box-shadow: 0 6px 16px rgba(255, 179, 71, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-sub);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: blink 1.4s infinite;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* 提示横幅 */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
}

.banner.warning {
  background: #fff4d6;
  border: 1px solid #f7cf6c;
  color: #6b4e00;
}

.banner.error {
  background: #ffe8e8;
  border: 1px solid #f5a6a6;
  color: #8b1e1e;
}

.banner code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

/* 主舞台卡片 */
.stage-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 28px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* 小星星角色动画 */
.mascot-wrap {
  position: relative;
  width: 196px;
  height: 196px;
  display: grid;
  place-items: center;
}

.pulse-ring {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 3px solid transparent;
  opacity: 0;
  pointer-events: none;
}

.mascot-circle {
  position: relative;
  z-index: 2;
  width: 164px;
  height: 164px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #fff4d1 75%);
  box-shadow: 0 14px 30px rgba(255, 179, 71, 0.25), inset 0 2px 10px rgba(255, 255, 255, 0.9);
  display: grid;
  place-items: center;
  transition: transform 0.25s ease;
}

.star-svg {
  width: 138px;
  height: 138px;
  animation: floatIdle 3.2s ease-in-out infinite;
}

.star-mouth-talk {
  display: none;
  transform-origin: 90px 106px;
}

/* 不同状态的动效 */
.mascot-wrap[data-state="connecting"] .mascot-circle {
  animation: gentleSpin 2.2s linear infinite;
}

.mascot-wrap[data-state="listening"] .pulse-ring.ring-1 {
  border-color: rgba(46, 196, 182, 0.55);
  animation: ripple 1.8s ease-out infinite;
}

.mascot-wrap[data-state="listening"] .pulse-ring.ring-2 {
  border-color: rgba(46, 196, 182, 0.35);
  animation: ripple 1.8s ease-out 0.9s infinite;
}

.mascot-wrap[data-state="speaking"] .mascot-circle {
  transform: scale(1.05);
  box-shadow: 0 16px 36px rgba(255, 138, 61, 0.35);
}

.mascot-wrap[data-state="speaking"] .pulse-ring.ring-1 {
  border-color: rgba(255, 138, 61, 0.55);
  animation: ripple 1.2s ease-out infinite;
}

.mascot-wrap[data-state="speaking"] .star-mouth-idle {
  display: none;
}

.mascot-wrap[data-state="speaking"] .star-mouth-talk {
  display: block;
  animation: talkBounce 0.32s ease-in-out infinite alternate;
}

.mascot-wrap[data-state="thinking"] .star-svg {
  animation: wobble 1s ease-in-out infinite;
}

.state-chip {
  padding: 6px 16px;
  border-radius: 999px;
  background: #f4f1ea;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 700;
}

.state-chip.active {
  background: #e3f9f6;
  color: #0e7c72;
}

.state-chip.speaking {
  background: #fff0e2;
  color: #c8550d;
}

/* 控制按钮 */
.primary-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.big-call-btn {
  width: 100%;
  max-width: 320px;
  padding: 16px 24px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff9f43, #ff6b35);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(255, 107, 53, 0.34);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.big-call-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 28px rgba(255, 107, 53, 0.42);
}

.big-call-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.big-call-btn.connected {
  background: linear-gradient(135deg, #ff6b6b, #e63946);
  box-shadow: 0 12px 24px rgba(230, 57, 70, 0.3);
}

.big-call-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.secondary-row {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.kid-action-btn {
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  padding: 14px 10px;
  background: #f7f9fc;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.kid-action-btn .action-emoji {
  font-size: 26px;
  line-height: 1;
}

.kid-action-btn.camera-btn {
  background: #eaf7ff;
  border-color: #c5e7ff;
}

.kid-action-btn.album-btn {
  background: #f2eeff;
  border-color: #dcd2ff;
}

.kid-action-btn.mute-btn {
  background: #e9fbf7;
  border-color: #bdeee4;
}

.kid-action-btn.mute-btn.muted {
  background: #fff0f0;
  border-color: #ffc9c9;
  color: #b42318;
}

.kid-action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.kid-action-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

/* 照片预览卡片 */
.photo-preview-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 2px solid #ffd97d;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 15px;
}

.preview-body {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

#previewImg {
  width: 132px;
  height: 132px;
  object-fit: cover;
  border-radius: 16px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.photo-prompts {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt-pill {
  border: none;
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.prompt-pill:hover {
  transform: translateX(3px);
}

.prompt-pill.story {
  background: #fff2cc;
  color: #7c4d00;
}

.prompt-pill.ask {
  background: #dff4ff;
  color: #0b5394;
}

.prompt-pill.send-only {
  background: #ede9fe;
  color: #4c1d95;
}

.prompt-pill:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.section-mini-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-sub);
}

.voice-photo-hint {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.45;
}

/* 魔法生成进度条 */
.banner.magic-progress {
  background: linear-gradient(135deg, #f3e8ff, #e0f2fe);
  border: 1px solid #d8b4fe;
  color: #5b21b6;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.magic-spinner {
  display: inline-block;
  animation: spinSparkle 1.4s linear infinite;
}

/* 魔法变图 / GIF 工作台 */
.magic-studio {
  border-top: 1px dashed rgba(47, 42, 36, 0.14);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.magic-studio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.magic-mode-group {
  display: inline-flex;
  background: #f3f4f8;
  padding: 3px;
  border-radius: 999px;
  gap: 4px;
}

.mode-pill {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-pill.active {
  background: #fff;
  color: #6d28d9;
  box-shadow: 0 2px 8px rgba(109, 40, 217, 0.16);
}

.magic-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.preset-chip {
  border: 1px solid #e2d9ff;
  border-radius: 999px;
  padding: 6px 12px;
  background: #f8f5ff;
  color: #4c1d95;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.preset-chip:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #efe8ff;
  border-color: #c4b5fd;
}

.preset-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.magic-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#magicPromptInput {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  border-radius: 14px;
  border: 1.5px solid #e2d9ff;
  background: #fff;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-main);
}

#magicPromptInput:focus {
  outline: none;
  border-color: #8b7cf6;
  box-shadow: 0 0 0 3px rgba(139, 124, 246, 0.16);
}

.frames-select {
  padding: 0 10px;
  border-radius: 14px;
  border: 1.5px solid #e2d9ff;
  background: #faf8ff;
  color: #4c1d95;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.magic-go-btn {
  border: none;
  border-radius: 14px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.25);
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.magic-go-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.magic-go-btn:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

/* 对话气泡中的魔法成品展示与控件 */
.bubble.magic-result {
  align-self: flex-start;
  background: linear-gradient(180deg, #faf5ff, #fff9f0);
  border: 1px solid #e9d5ff;
  border-bottom-left-radius: 6px;
}

.magic-result-media {
  display: block;
  width: 100%;
  max-width: 280px;
  border-radius: 14px;
  margin: 6px 0 8px;
  border: 2px solid rgba(139, 92, 246, 0.18);
  background: #fff;
}

.magic-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mini-action-btn {
  border: 1px solid #ddd6fe;
  border-radius: 999px;
  padding: 5px 11px;
  background: #fff;
  color: #5b21b6;
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s ease, transform 0.12s ease;
}

.mini-action-btn:hover {
  background: #f5f3ff;
  transform: translateY(-1px);
}

.mini-action-btn.primary {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}

.mini-action-btn.primary:hover {
  background: #6d28d9;
}

/* 对话记录卡片 */
.transcript-card {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow);
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.transcript-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 13px;
  cursor: pointer;
}

.text-btn:hover {
  color: var(--text-main);
}

.transcript-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 4px;
}

.empty-hint {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  padding: 20px 10px;
}

.bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
}

.bubble.assistant {
  align-self: flex-start;
  background: #fff7e0;
  border: 1px solid #ffe4a3;
  border-bottom-left-radius: 6px;
}

.bubble.user {
  align-self: flex-end;
  background: #e6f5ff;
  border: 1px solid #c2e5ff;
  border-bottom-right-radius: 6px;
}

.bubble-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.bubble-photo {
  display: block;
  max-width: 180px;
  max-height: 180px;
  border-radius: 12px;
  margin-bottom: 6px;
  object-fit: cover;
}

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(25, 32, 46, 0.48);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.close-mini-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #f2f2f2;
  font-size: 16px;
  cursor: pointer;
}

.camera-stage {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111;
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 14px;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.capture-btn,
.primary-pill,
.secondary-pill {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.capture-btn,
.primary-pill {
  background: linear-gradient(135deg, #ff9f43, #ff6b35);
  color: #fff;
  flex: 1;
}

.secondary-pill {
  background: #f1f3f5;
  color: var(--text-main);
}

/* 设置表单 */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d8dce3;
  font-size: 14px;
  font-family: inherit;
  background: #fafbfc;
}

.settings-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-sub);
}

.passcode-modal-card {
  max-width: 400px;
}

.passcode-error {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #b42318;
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* 动画 */
@keyframes floatIdle {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

@keyframes ripple {
  0% { transform: scale(0.92); opacity: 0.75; }
  100% { transform: scale(1.28); opacity: 0; }
}

@keyframes talkBounce {
  0% { transform: scaleY(0.45); }
  100% { transform: scaleY(1.18); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

@keyframes gentleSpin {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.03); }
  100% { transform: scale(0.98); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes spinSparkle {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(1); }
}

@media (max-width: 520px) {
  .secondary-row {
    gap: 8px;
  }
  .kid-action-btn {
    padding: 12px 6px;
    font-size: 13px;
  }
  .preview-body {
    flex-direction: column;
    align-items: stretch;
  }
  #previewImg {
    width: 100%;
    height: 180px;
  }
  .magic-input-row {
    flex-wrap: wrap;
  }
  .magic-go-btn {
    flex: 1;
  }
}
