:root {
  --sky-top: #38bdf8;
  --sky-bottom: #e0f2fe;
  --card-bg: rgba(255, 255, 255, 0.94);
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent: #ef4444;
  --radius-lg: 24px;
  --radius-md: 16px;
  --shadow: 0 12px 32px rgba(14, 116, 144, 0.16);
}

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

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

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

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  filter: blur(1px);
  animation: drift 36s linear infinite;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  width: 140px;
  height: 48px;
  top: 8%;
  left: -160px;
}
.cloud-1::before { width: 64px; height: 64px; top: -28px; left: 22px; }
.cloud-1::after { width: 48px; height: 48px; top: -18px; left: 72px; }

.cloud-2 {
  width: 180px;
  height: 56px;
  top: 24%;
  left: -220px;
  animation-duration: 48s;
  animation-delay: -14s;
  opacity: 0.7;
}
.cloud-2::before { width: 76px; height: 76px; top: -34px; left: 30px; }
.cloud-2::after { width: 58px; height: 58px; top: -24px; left: 96px; }

.cloud-3 {
  width: 120px;
  height: 40px;
  top: 62%;
  left: -140px;
  animation-duration: 42s;
  animation-delay: -26s;
  opacity: 0.6;
}
.cloud-3::before { width: 52px; height: 52px; top: -22px; left: 20px; }
.cloud-3::after { width: 40px; height: 40px; top: -16px; left: 60px; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 300px)); }
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 14px 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 顶部栏 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

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

.brand-icon {
  font-size: 30px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #0c4a6e;
}

.engine-badge {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
}

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

.badge-counter {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fef3c7;
  color: #b45309;
  font-weight: 800;
  font-size: 15px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #fde68a;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  font-size: 19px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:hover { background: #e2e8f0; transform: scale(1.06); }
.icon-btn:active { transform: scale(0.95); }

/* 模式切换 */
.mode-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-pill {
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.72);
  color: #0f172a;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-pill.active {
  background: #facc15;
  border-color: #eab308;
  color: #713f12;
  box-shadow: 0 4px 12px rgba(234, 179, 8, 0.35);
  transform: translateY(-1px);
}

/* 角色选择栏 */
.character-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.char-card {
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.char-card:hover {
  transform: translateY(-2px);
  background: #ffffff;
}

.char-card.active {
  background: #ffffff;
  border-color: var(--char-color, #ef4444);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
  transform: translateY(-3px);
}

.char-card-svg {
  width: 48px;
  height: 48px;
}

.char-card-name {
  font-size: 13px;
  font-weight: 800;
  color: #1e293b;
}

/* 主舞台 */
.stage-card {
  flex: 1;
  min-height: 320px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 3D 动态舞台 */
.stage3d-wrap {
  position: relative;
  height: 235px;
  background: linear-gradient(180deg, #0ea5e9 0%, #7dd3fc 65%, #e0f2fe 100%);
  overflow: hidden;
  transition: background 0.35s ease;
}

.stage3d-canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}

.stage3d-canvas:active {
  cursor: grabbing;
}

.stage3d-hud {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.hero-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 999px;
}

.hero-pill h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
}

.hero-role {
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 10px;
  border-radius: 999px;
}

.stage3d-tip {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: #0369a1;
  background: rgba(255, 255, 255, 0.72);
  padding: 3px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.speaking-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.2s;
}

.speaking-wave.active {
  opacity: 1;
}

.speaking-wave span {
  width: 4px;
  height: 8px;
  background: #ffffff;
  border-radius: 4px;
  animation: waveBar 0.6s ease-in-out infinite alternate;
}
.speaking-wave span:nth-child(2) { animation-delay: 0.15s; }
.speaking-wave span:nth-child(3) { animation-delay: 0.3s; }
.speaking-wave span:nth-child(4) { animation-delay: 0.45s; }

@keyframes waveBar {
  from { height: 6px; }
  to { height: 22px; }
}

/* 聊天区 */
.chat-log {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 44dvh;
}

.msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: fadeUp 0.22s ease;
}

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

.msg-row.user {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.ai .msg-bubble {
  background: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 6px;
}

.msg-row.user .msg-bubble {
  background: #0284c7;
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.replay-btn {
  border: none;
  background: #e2e8f0;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* 快捷提示 */
.quick-prompts {
  padding: 8px 16px 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid #f1f5f9;
}

.quick-chip {
  border: 1.5px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-chip:hover {
  background: #e0f2fe;
  border-color: #38bdf8;
  color: #0369a1;
}

/* 底部输入区 */
.input-dock {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--card-bg);
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.mic-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
  transition: transform 0.15s ease;
}

.mic-btn:active { transform: scale(0.95); }

.mic-btn.listening {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.25);
  animation: pulseMic 1s infinite;
}

@keyframes pulseMic {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.text-form {
  flex: 1;
  display: flex;
  gap: 8px;
}

.text-form input {
  flex: 1;
  min-width: 0;
  border: 2px solid #e2e8f0;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  outline: none;
}

.text-form input:focus {
  border-color: #38bdf8;
}

.send-btn {
  border: none;
  background: #0284c7;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

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

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

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

.gate-desc {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.gate-question {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gate-question span {
  font-size: 18px;
  font-weight: 800;
}

.gate-question input {
  width: 100px;
  padding: 8px 12px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  font-size: 16px;
}

.error-text {
  color: #dc2626;
  font-size: 13px;
  margin-top: 8px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
}

.settings-form select,
.settings-form input {
  padding: 10px 12px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
}

.api-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.primary-btn {
  border: none;
  background: #0284c7;
  color: #ffffff;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
}

.secondary-btn {
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.badge-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #facc15, #f59e0b);
  color: #713f12;
  font-weight: 900;
  font-size: 16px;
  padding: 12px 24px;
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(245, 158, 11, 0.45);
  z-index: 100;
  animation: fadeUp 0.25s ease;
}

@media (max-width: 640px) {
  .character-bar {
    gap: 6px;
  }
  .char-card-svg {
    width: 38px;
    height: 38px;
  }
  .char-card-name {
    font-size: 12px;
  }
  .input-dock {
    flex-direction: column;
    align-items: stretch;
  }
  .mic-btn {
    justify-content: center;
  }
}
