:root {
  --bg: #ffffff;
  --bg-soft: #f6f5ff;
  --bg-talk: #f3f2ff;
  --primary: #5b5cff;
  --primary-soft: #ecebff;
  --primary-deep: #4546e0;
  --text: #1a1a22;
  --muted: #8b8b9a;
  --line: #ebeaf2;
  --danger: #e84b6a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans SC", "DM Sans", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 50% -8%, #ebe9ff 0%, transparent 60%),
    linear-gradient(180deg, #fafaff 0%, var(--bg) 42%, #f7f6ff 100%);
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: calc(20px + var(--safe-top)) 24px calc(48px + var(--safe-bottom));
}
.screen.active {
  display: flex;
}

#home.screen.active {
  justify-content: space-between;
}

button {
  font-family: inherit;
}

/* ---------- 首页 ---------- */
.gear-btn {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 18px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(91, 92, 255, 0.08);
  color: var(--primary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  z-index: 2;
}
.gear-btn:active {
  transform: scale(0.94);
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  padding-top: 56px;
  padding-bottom: 12px;
  gap: 18px;
  min-height: 0;
}

.avatar-stage {
  position: relative;
  width: 210px;
  height: 210px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}

.avatar-dot-ring {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 1px dotted rgba(160, 165, 195, 0.3);
  animation: spin-slow 36s linear infinite;
  pointer-events: none;
}

.wave-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.pulse-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1.6px solid rgba(170, 175, 210, 0.35);
  box-shadow: 0 0 0 0 rgba(124, 133, 255, 0.08);
  opacity: 0.4;
  transform: scale(1);
  animation: ring-breathe 3s ease-in-out infinite;
}
.pulse-ring.p2 {
  inset: 8px;
  border-color: rgba(185, 189, 220, 0.26);
  opacity: 0.26;
  animation-delay: 1.2s;
}

.avatar-stage-inner {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
}

.avatar,
.orb-avatar.coach-3d {
  width: 172px;
  height: 172px;
  border-radius: 50%;
  overflow: hidden;
  background: #ecf2fa;
  position: relative;
  z-index: 1;
  box-shadow: 0 16px 40px rgba(91, 92, 255, 0.22);
  transform-style: preserve-3d;
  will-change: transform, box-shadow, filter;
  transition: box-shadow 0.45s ease, filter 0.45s ease;
}

.coach-photo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center center;
  border-radius: 50%;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: 50% 55%;
  animation: coach-breathe 4.8s ease-in-out infinite;
}

.coach-shine {
  position: absolute;
  inset: -20%;
  background: linear-gradient(
    125deg,
    transparent 35%,
    rgba(255, 255, 255, 0.22) 48%,
    transparent 62%
  );
  transform: translateX(-40%) rotate(8deg);
  animation: coach-shine 6.5s ease-in-out infinite;
  pointer-events: none;
  mix-blend-mode: soft-light;
}

.coach-lid {
  display: none;
}

/* idle / listening：轻柔呼吸 + 偶尔眨眼 */
.coach-3d.is-idle .coach-photo,
.coach-3d.is-listening .coach-photo,
.coach-3d.is-connecting .coach-photo,
.coach-3d.is-thinking .coach-photo {
  animation: coach-breathe 4.8s ease-in-out infinite;
}

.coach-3d.is-listening {
  box-shadow: 0 18px 44px rgba(91, 92, 255, 0.3);
}

.coach-3d.is-thinking .coach-photo {
  animation: coach-think 2.4s ease-in-out infinite;
  filter: saturate(0.96) brightness(0.98);
}

/* speaking：连贯的说话微动，不要切图 */
.coach-3d.is-speaking {
  box-shadow: 0 20px 52px rgba(91, 92, 255, 0.38);
  filter: saturate(1.05);
}
.coach-3d.is-speaking .coach-photo {
  animation: coach-talk 0.9s ease-in-out infinite;
}
.coach-3d.is-speaking .coach-shine {
  animation-duration: 2.8s;
  opacity: 1;
}

.avatar-stage.alive .pulse-ring {
  border-color: rgba(118, 125, 255, 0.45);
  box-shadow: 0 0 0 10px rgba(118, 125, 255, 0.08);
  animation-duration: 1.6s;
}
.avatar-stage.alive .pulse-ring.p2 {
  animation-delay: 0.55s;
}
.avatar-stage.alive .avatar {
  box-shadow: 0 18px 48px rgba(91, 92, 255, 0.35);
}


.headline {
  margin: 0;
  font-size: clamp(18px, 4.8vw, 24px);
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  max-width: 100%;
}
.headline .accent {
  color: var(--primary);
}

.desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  max-width: 34em;
}

.cta-btn {
  width: min(100%, 360px);
  height: 56px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(91, 92, 255, 0.32);
  transition: transform 0.12s ease, background 0.15s ease;
  flex-shrink: 0;
  margin-top: 12px;
  margin-bottom: 36px;
}
.cta-btn:active {
  transform: scale(0.98);
  background: var(--primary-deep);
}
.cta-btn.compact {
  margin: 0;
  width: 100%;
  height: 50px;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(91, 92, 255, 0.28);
}
.cta-icon {
  flex-shrink: 0;
}

@keyframes coach-breathe {
  0%,
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
  50% {
    transform: translateY(-3px) scale(1.018) rotate(0.4deg);
  }
}
@keyframes coach-talk {
  0%,
  100% {
    transform: translateY(0) scale(1) rotate(-0.4deg);
  }
  35% {
    transform: translateY(-2px) scale(1.03) rotate(0.5deg);
  }
  70% {
    transform: translateY(1px) scale(1.012) rotate(-0.2deg);
  }
}
@keyframes coach-think {
  0%,
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  50% {
    transform: translateY(-2px) scale(0.985);
    opacity: 0.94;
  }
}
@keyframes coach-shine {
  0%,
  100% {
    transform: translateX(-55%) rotate(8deg);
    opacity: 0.35;
  }
  45% {
    transform: translateX(55%) rotate(8deg);
    opacity: 0.7;
  }
}
@keyframes ring-breathe {
  0%,
  100% {
    opacity: 0.22;
    transform: scale(0.985);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.03);
  }
}
@keyframes spin-slow {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 设置页 ---------- */
.settings-screen {
  align-items: stretch;
  background: #fff;
  padding-left: 18px;
  padding-right: 18px;
  padding-bottom: 0;
}
.settings-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.settings-header h2 {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.soft {
  color: var(--muted);
  font-size: 16px;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}
.settings-block {
  margin-bottom: 22px;
}
.settings-block h3 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
}
.block-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mode-card {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 14px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.mode-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px rgba(91, 92, 255, 0.08);
}
.mode-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #f3f3f7;
}
.mode-card.selected .mode-icon {
  color: var(--primary);
  background: #fff;
}
.mode-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mode-copy strong {
  font-size: 15px;
  color: var(--text);
}
.mode-copy span {
  font-size: 12px;
  color: var(--muted);
}
.mode-card.selected .mode-copy strong {
  color: var(--primary);
}

.field-label {
  display: block;
  margin: 16px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: #3d3d4a;
}

.voice-card {
  width: 100%;
  display: grid;
  grid-template-columns: 52px 1fr 28px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.voice-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  background: #efeaff;
  position: relative;
}
.voice-avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5.5v13l11-6.5L8 5.5z'/%3E%3C/svg%3E")
    center / 18px 18px no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5.5v13l11-6.5L8 5.5z'/%3E%3C/svg%3E")
    center / 18px 18px no-repeat;
}
.voice-avatar img,
.voice-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.voice-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.voice-meta strong {
  font-size: 15px;
}
.voice-meta span {
  font-size: 12px;
  color: var(--muted);
}
.swap-icon {
  color: var(--muted);
  display: grid;
  place-items: center;
}

.voice-options {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-option {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.voice-option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.textarea-wrap {
  position: relative;
}
.textarea-wrap textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 28px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: #fff;
  resize: vertical;
  outline: none;
  user-select: text;
  min-height: 64px;
}
.textarea-wrap textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 92, 255, 0.12);
}
.textarea-wrap textarea::placeholder {
  color: #b0b0bd;
}
.char-count {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.settings-footer {
  padding: 12px 0 calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
}

/* ---------- 对话页 ---------- */
.talk-screen {
  background: var(--bg-talk);
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 0;
  align-items: stretch;
}
.talk-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 0 4px;
}
.caption-btn {
  font-size: 18px;
}
.caption-btn.off {
  opacity: 0.4;
}
.talk-title {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.talk-title #modeLabel {
  font-weight: 700;
  font-size: 16px;
}
.state-text {
  font-size: 13px;
  color: var(--primary);
}

.talk-stage {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
}
.orb {
  position: relative;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.orb.compact {
  width: 132px;
  height: 132px;
}
.orb-avatar.coach-3d {
  width: 152px;
  height: 152px;
}
.orb.compact .orb-avatar.coach-3d {
  width: 104px;
  height: 104px;
}
.orb.speaking .orb-avatar.coach-3d {
  /* motion handled by coach-talk */
}
.orb.thinking .orb-avatar.coach-3d {
  /* motion handled by coach-think */
}
.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(91, 92, 255, 0.28);
  opacity: 0;
}
.orb.listening .orb-ring {
  animation: pulse 1.8s ease-out infinite;
  opacity: 1;
}
.orb.listening .ring2 {
  animation-delay: 0.9s;
}
@keyframes pulse {
  0% {
    transform: scale(0.62);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.12);
    opacity: 0;
  }
}
@keyframes talk {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}
@keyframes think {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.88;
  }
  50% {
    transform: scale(0.94);
    opacity: 1;
  }
}
.orb-hint {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin: 0;
  min-height: 18px;
}

/* 微信式聊天区 */
.chat-panel {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 18px 18px 0 0;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(235, 234, 242, 0.9);
  border-bottom: none;
  overflow: hidden;
}
.chat-panel.hidden {
  display: none;
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-row {
  display: flex;
  width: 100%;
}
.chat-row.ai {
  justify-content: flex-start;
}
.chat-row.user {
  justify-content: flex-end;
}
.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  user-select: text;
  box-shadow: 0 1px 2px rgba(30, 30, 50, 0.04);
}
.chat-bubble.ai {
  background: var(--primary-soft);
  color: var(--text);
  border-top-left-radius: 6px;
}
.chat-bubble.user {
  background: #fff;
  color: var(--text);
  border-top-right-radius: 6px;
  border: 1px solid var(--line);
}
.chat-bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 0.35em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.1em;
  background: currentColor;
  opacity: 0.45;
  animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.talk-footer {
  width: 100%;
  padding: 10px 0 calc(14px + var(--safe-bottom));
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(243, 242, 255, 0), var(--bg-talk) 30%);
}
.end-btn {
  width: 100%;
  height: 52px;
  border-radius: 14px;
  border: none;
  background: rgba(232, 75, 106, 0.1);
  color: var(--danger);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 12px;
}
.end-btn:active {
  transform: scale(0.98);
}

/* ---------- Sheet / Toast ---------- */
.sheet[hidden] {
  display: none;
}
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 30, 0.35);
}
.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 480px);
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 24px 22px calc(22px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.12);
}
.sheet-panel h3 {
  margin: 0 0 10px;
  font-size: 18px;
}
.sheet-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(28, 28, 40, 0.94);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 84%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
