:root {
  --page: #ffe664;
  --shell: rgba(255, 252, 240, 0.98);
  --shell-strong: #fff7d6;
  --white: #ffffff;
  --ink: #24173a;
  --ink-soft: rgba(36, 23, 58, 0.78);
  --muted: rgba(160, 100, 60, 0.96);
  --pink: #ff3c78;
  --purple: #7850ff;
  --teal: #50dcb4;
  --orange: #ff9d00;
  --orange-deep: #ff7800;
  --yellow-line: rgba(255, 200, 0, 0.52);
  --shadow-shell: 0 0 60px rgba(255, 60, 120, 0.18);
  --shadow-soft: 0 4px 20px rgba(255, 60, 120, 0.12);
  --shadow-strong: 0 18px 34px rgba(255, 60, 120, 0.24);
}

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

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.38), transparent 18%),
    radial-gradient(circle at bottom right, rgba(255, 60, 120, 0.16), transparent 22%),
    linear-gradient(180deg, #fff39c 0%, var(--page) 52%, #ffd839 100%);
  color: var(--ink);
  font-family: "Avenir Next", "SF Pro Display", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

body {
  min-height: 100svh;
  overflow: hidden;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  width: min(100%, 480px);
  height: 100svh;
  min-height: 100svh;
  margin: 0 auto;
  background: var(--shell);
  box-shadow: var(--shadow-shell);
  display: grid;
  grid-template-rows: auto auto 3px minmax(0, 1fr);
  overflow: hidden;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  background:
    linear-gradient(180deg, rgba(255, 252, 240, 1) 0%, rgba(255, 248, 219, 0.98) 100%);
}

.topbar-copy {
  display: grid;
  gap: 2px;
}

.topbar-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(160, 100, 60, 0.82);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 5.2vw, 30px);
  line-height: 1.02;
  color: rgba(30, 20, 60, 1);
}

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

.topbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 8px 18px rgba(255, 60, 120, 0.24);
}

.stage {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  padding: 0 16px 14px;
}

.stage-shell {
  position: relative;
  width: min(100%, 328px);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 18%, #faf9f7 0%, #f0ece8 32%, #e4ded7 62%, #d5cec7 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 18px 32px rgba(125, 112, 101, 0.14);
}

.stage-shell.is-speaking {
  box-shadow: none;
}

.stage-meta {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 0;
}

.stage-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(196, 186, 176, 0.34);
  box-shadow: 0 8px 18px rgba(137, 122, 112, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.status-badge {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(200, 200, 200, 1);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.46);
}

.status-badge[data-state="ready"] {
  background: rgba(200, 200, 200, 1);
}

.status-badge[data-state="recording"] {
  background: rgba(255, 60, 120, 1);
  animation: blink-dot 1s step-end infinite;
}

.status-badge[data-state="busy"] {
  background: rgba(80, 220, 180, 1);
  animation: blink-dot 1s step-end infinite;
}

.status-text {
  font-size: 12px;
  font-weight: 800;
  color: rgba(255, 60, 120, 1);
  background-image: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stage-chip {
  border-radius: 999px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.44);
  border: 1px solid rgba(170, 160, 150, 0.32);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 700;
  color: rgba(92, 78, 70, 0.94);
}

#digitalHuman {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  display: block;
  background: transparent;
  z-index: 2;
  filter: drop-shadow(0 18px 22px rgba(78, 63, 56, 0.16));
}

.idle-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.34), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(170, 160, 151, 0.08) 100%);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.idle-overlay::before,
.idle-overlay::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.idle-overlay::before {
  bottom: 28px;
  width: 118px;
  height: 36px;
  border-radius: 999px;
  background: rgba(197, 189, 181, 0.2);
  filter: blur(10px);
}

.idle-overlay::after {
  bottom: 40px;
  width: 180px;
  height: 300px;
  border-radius: 100px 100px 44px 44px;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 236, 220, 0.88) 0 14%, transparent 14.5%),
    radial-gradient(circle at 50% 14%, rgba(106, 94, 85, 0.42) 0 20%, transparent 21%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 22%),
    linear-gradient(180deg, rgba(221, 214, 207, 0.26) 0%, rgba(206, 197, 188, 0.18) 62%, rgba(206, 197, 188, 0.06) 100%);
  opacity: 0.48;
}

.idle-overlay.has-image {
  background-position: center bottom;
  background-repeat: no-repeat;
  background-size: contain;
}

.idle-overlay.has-image::after {
  display: none;
}

.idle-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.stage-floor {
  position: absolute;
  left: 50%;
  bottom: 10px;
  width: 132px;
  height: 40px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(198, 191, 183, 0.18);
  filter: blur(10px);
  z-index: 1;
}

.stage-divider {
  background: linear-gradient(90deg, rgba(255, 200, 0, 1) 0%, rgba(255, 60, 120, 1) 40%, rgba(120, 80, 255, 1) 70%, rgba(80, 220, 180, 1) 100%);
}

@media (max-width: 640px) {
  .stage {
    padding: 0 12px 12px;
  }

  .stage-shell {
    width: min(100%, 300px);
    border-radius: 20px;
  }
}

.console {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: linear-gradient(180deg, rgba(255, 250, 230, 1) 0%, rgba(255, 252, 240, 1) 100%);
  overflow: hidden;
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 60, 120, 0.25) transparent;
  overscroll-behavior: contain;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 60, 120, 0.25);
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-width: 0;
  animation: bubble-in 180ms ease-out;
}

.message-row.user {
  flex-direction: row-reverse;
}

.message-row.error {
  justify-content: center;
}

.message-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--white);
}

.message-avatar.assistant {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 8px rgba(255, 60, 120, 0.35);
}

.message-avatar.user {
  background: linear-gradient(135deg, rgba(255, 200, 0, 1) 0%, rgba(255, 120, 0, 1) 100%);
  box-shadow: 0 2px 8px rgba(255, 160, 0, 0.35);
}

.message-stack {
  max-width: 75%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-row.user .message-stack {
  align-items: flex-end;
}

.message-row.assistant .message-stack {
  align-items: flex-start;
}

.message {
  max-width: 100%;
  max-height: min(32vh, 220px);
  padding: 12px 14px;
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 60, 120, 0.28) transparent;
}

.message::-webkit-scrollbar {
  width: 6px;
}

.message::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 60, 120, 0.28);
}

.message.assistant {
  background: rgba(255, 255, 255, 0.95);
  color: rgba(30, 20, 60, 1);
  border: 1.5px solid rgba(255, 200, 0, 0.4);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 12px rgba(255, 60, 120, 0.1);
}

.message.user {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  color: var(--white);
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 12px rgba(255, 60, 120, 0.35);
}

.message.error {
  max-width: 100%;
  background: rgba(255, 255, 255, 0.92);
  color: #a61d47;
  border: 1.5px solid rgba(255, 60, 120, 0.22);
  box-shadow: none;
}

.message-time {
  padding: 0 4px;
  font-size: 11px;
  color: rgba(160, 100, 60, 1);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 10px;
  flex: none;
}

.typing-indicator[hidden] {
  display: none;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid rgba(255, 200, 0, 0.4);
  box-shadow: 0 2px 8px rgba(255, 60, 120, 0.1);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  animation: typing-wave 0.8s ease-in-out infinite;
}

.dot-one {
  background: rgba(255, 60, 120, 1);
  animation-delay: 0s;
}

.dot-two {
  background: rgba(255, 200, 0, 1);
  animation-delay: 0.2s;
}

.dot-three {
  background: rgba(120, 80, 255, 1);
  animation-delay: 0.4s;
}

.composer {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: end;
  gap: 10px;
  padding: 12px 14px 6px;
  background: linear-gradient(180deg, rgba(255, 252, 240, 0) 0%, rgba(255, 245, 200, 0.95) 100%);
  flex: none;
}

.composer-main {
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(255, 200, 0, 0.5);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
}

.message-input {
  width: 100%;
  min-height: 40px;
  max-height: 100px;
  resize: none;
  border: 0;
  padding: 9px 0;
  background: transparent;
  color: rgba(30, 20, 60, 1);
  font-size: 14px;
  line-height: 1.55;
  outline: none;
}

.message-input::placeholder {
  color: rgba(160, 100, 60, 0.56);
}

.voice-panel {
  width: 100%;
  display: flex;
  align-items: center;
}

.voice-panel[hidden] {
  display: none;
}

.mode-toggle,
.send-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.mode-toggle:hover,
.send-button:hover,
.hold-button:hover {
  transform: translateY(-1px);
}

.mode-toggle {
  background: rgba(255, 245, 200, 1);
  border: 1.5px solid rgba(255, 200, 0, 0.6);
  color: rgba(255, 60, 120, 1);
}

.mode-toggle[data-mode="voice"] {
  color: var(--white);
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 10px rgba(255, 60, 120, 0.4);
  border-color: transparent;
}

.send-button {
  color: var(--white);
  background: rgba(230, 220, 240, 1);
  box-shadow: none;
}

.send-button.is-ready {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 12px rgba(255, 60, 120, 0.4);
}

.send-button.is-busy {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 12px rgba(255, 60, 120, 0.4);
}

.send-button.is-busy .control-glyph {
  animation: blink-dot 0.8s step-end infinite;
}

.hold-button {
  width: 100%;
  height: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  color: var(--white);
  background: linear-gradient(135deg, rgba(255, 200, 0, 1) 0%, rgba(255, 120, 0, 1) 100%);
  box-shadow: 0 2px 10px rgba(255, 160, 0, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.hold-button[hidden] {
  display: none;
}

.hold-ripple {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 60, 120, 0.18);
  opacity: 0;
}

.hold-button.is-recording {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 16px rgba(255, 60, 120, 0.5);
  transform: scale(0.98);
}

.hold-button.is-recording .hold-ripple {
  opacity: 1;
  animation: hold-ripple 1s ease-out infinite;
}

.hold-button.is-busy {
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 2px 16px rgba(255, 60, 120, 0.5);
}

.hold-text {
  position: relative;
  z-index: 1;
  font-size: 14px;
  font-weight: 700;
}

.control-icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.control-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.mode-icon {
  width: 18px;
  height: 18px;
}

.mode-icon .icon-text {
  display: none;
}

.mode-toggle[data-mode="voice"] .mode-icon .icon-voice {
  display: none;
}

.mode-toggle[data-mode="voice"] .mode-icon .icon-text {
  display: block;
}

.send-icon {
  width: 18px;
  height: 18px;
  color: rgba(125, 96, 167, 1);
  transition: color 120ms ease;
}

.send-button.is-ready .send-icon,
.send-button.is-busy .send-icon {
  color: var(--white);
}

.hold-icon {
  width: 18px;
  height: 18px;
  margin-right: 1px;
}

.hold-button.is-recording .hold-icon {
  display: none;
}

.composer {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.mode-toggle:disabled,
.send-button:disabled,
.hold-button:disabled,
.message-input:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

#ttsAudio {
  display: none;
}

.setup-app {
  width: min(100%, 720px);
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(255, 252, 240, 0.98);
}

.setup-shell {
  min-height: 0;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 250, 230, 1) 0%, rgba(255, 252, 240, 1) 100%);
}

.setup-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.76);
  border: 1.5px solid rgba(255, 200, 0, 0.3);
  box-shadow: var(--shadow-soft);
}

.setup-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.field-meta {
  font-size: 12px;
  color: var(--muted);
}

.text-field {
  width: 100%;
  min-height: 52px;
  border-radius: 18px;
  border: 1.5px solid rgba(255, 200, 0, 0.36);
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  outline: none;
  box-shadow: var(--shadow-soft);
}

.text-field:focus {
  border-color: rgba(255, 60, 120, 0.36);
}

.recorder-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.86);
  border: 1.5px solid rgba(255, 200, 0, 0.3);
}

.recorder-head,
.source-line,
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.recorder-state {
  font-size: 18px;
  color: rgba(255, 60, 120, 1);
}

.recorder-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.upload-button {
  min-height: 64px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  background: linear-gradient(135deg, rgba(255, 60, 120, 1) 0%, rgba(120, 80, 255, 1) 100%);
  box-shadow: 0 8px 18px rgba(255, 60, 120, 0.24);
}

.upload-input {
  display: none;
}

.preview-audio {
  width: 100%;
}

.create-button {
  width: 100%;
  min-height: 56px;
}

.inline-error {
  max-width: 100%;
  margin: 0;
}

.result-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid rgba(255, 200, 0, 0.3);
}

.result-code,
.snippet {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.result-code {
  display: inline-block;
  max-width: 68%;
  overflow: auto;
  color: rgba(255, 60, 120, 1);
}

.snippet {
  margin: 0;
  padding: 14px;
  border-radius: 18px;
  background: rgba(36, 23, 58, 0.96);
  color: #f8fafc;
  white-space: pre-wrap;
  word-break: break-all;
}

@keyframes typing-wave {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes hold-ripple {
  0% {
    transform: scale(0.94);
    opacity: 0.55;
  }
  100% {
    transform: scale(1.08);
    opacity: 0;
  }
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink-dot {
  50% {
    opacity: 0.42;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar-link {
    min-height: 34px;
    padding: 0 12px;
    font-size: 12px;
  }

  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .chat-log {
    padding-left: 12px;
    padding-right: 12px;
  }

  .typing-indicator {
    padding-left: 12px;
    padding-right: 12px;
  }

  .setup-shell {
    padding: 14px;
  }

  .setup-card {
    padding: 16px;
  }

  .recorder-actions {
    grid-template-columns: 1fr;
  }
}
