*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #eef2f8;
  --app: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #eef1f6;
  --blue: #2563eb;
  --blue-2: #3b82f6;
  --red: #ef4444;
  --green: #10b981;
  --bubble: #f4f6fa;
}
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 10% -10%, #dce8ff 0%, transparent 58%),
    radial-gradient(720px 420px at 100% 112%, #e4f7f0 0%, transparent 55%),
    var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  -webkit-font-smoothing: antialiased;
}
button, select { font-family: inherit; }
button { border: 0; background: none; cursor: pointer; color: inherit; }

/* ── 外壳 ─────────────────────────────── */
.app {
  position: relative;
  width: min(560px, 100%);
  height: min(900px, calc(100dvh - 56px));
  min-height: 520px;
  background: var(--app);
  border-radius: 30px;
  box-shadow:
    0 34px 90px -24px rgba(15, 23, 42, .30),
    0 0 0 1px rgba(15, 23, 42, .04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 顶栏 ─────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 22px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 13px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  box-shadow: 0 10px 22px -8px rgba(37, 99, 235, .65);
}
.mark svg { width: 21px; height: 21px; }
.brand h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .2px;
  line-height: 1.2;
}
.brand p {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
}
.conn-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  color: #64748b;
  background: #f4f6fa;
  border: 1px solid #e9edf4;
  white-space: nowrap;
  transition: color .18s, background .18s, border-color .18s;
}
.conn-badge i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #cbd5e1;
}
.conn-badge.connecting { color: #a16207; background: #fef8e8; border-color: #f7e7bd; }
.conn-badge.connecting i { background: #f59e0b; animation: pulse 1.3s infinite; }
.conn-badge.connected { color: #047857; background: #ecfdf5; border-color: #c7f0df; }
.conn-badge.connected i { background: #10b981; }
.conn-badge.error { color: #b91c1c; background: #fef2f2; border-color: #fbdada; }
.conn-badge.error i { background: #ef4444; }

/* ── 页签 ─────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin: 2px 20px 0;
  padding: 4px;
  background: #f2f5fa;
  border-radius: 14px;
  flex: none;
}
.tab {
  flex: 1;
  height: 38px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: #64748b;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tab.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 2px 9px rgba(15, 23, 42, .09);
}

/* ── 状态条 ───────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 14px 24px 2px;
  font-size: 12px;
  color: var(--ink-3);
  flex: none;
  transition: color .18s;
}
.status-dot {
  flex: none;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: background .18s;
}
.status.listening { color: #dc2626; }
.status.listening .status-dot { background: var(--red); animation: pulse 1.3s infinite; }
.status.thinking { color: #b45309; }
.status.thinking .status-dot { background: #f59e0b; animation: pulse 1.3s infinite; }
.status.playing { color: #059669; }
.status.playing .status-dot { background: var(--green); }
.status.error { color: #dc2626; }
.status.error .status-dot { background: var(--red); }

/* ── 消息区 ───────────────────────────── */
.pane {
  flex: 1;
  display: none;
  flex-direction: column;
  gap: 16px;
  padding: 14px 22px 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #dbe2ee transparent;
}
.pane.active { display: flex; }
.pane::-webkit-scrollbar { width: 5px; }
.pane::-webkit-scrollbar-thumb { background: #dbe2ee; border-radius: 99px; }

.empty {
  margin: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  color: var(--ink-3);
}
.empty .orb {
  width: 64px; height: 64px;
  margin-bottom: 4px;
  border-radius: 22px;
  display: grid; place-items: center;
  color: #93b4f5;
  background: linear-gradient(160deg, #f1f6ff, #e4edff);
  border: 1px solid #e2ebfc;
}
.empty .orb svg { width: 27px; height: 27px; }
.empty b { font-size: 14px; font-weight: 600; color: #64748b; }
.empty span { font-size: 12px; line-height: 1.7; max-width: 250px; }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: rise .28s cubic-bezier(.2, .7, .3, 1);
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.ai { align-self: flex-start; }

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px 5px;
  font-size: 11px;
  color: #94a3b8;
}
.meta .dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #c7d2e3;
}

.bubble {
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble {
  color: #fff;
  background: linear-gradient(150deg, #3b82f6, #2563eb);
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 10px 20px -12px rgba(37, 99, 235, .85);
}
.msg.user .bubble.pending { color: rgba(255, 255, 255, .55); letter-spacing: 3px; }
.msg.ai .bubble {
  min-width: 58px;
  min-height: 40px;
  color: #1e293b;
  background: var(--bubble);
  border: 1px solid #edf1f7;
  border-radius: 18px 18px 18px 6px;
}
.bubble.typing::after {
  content: "";
  display: inline-block;
  width: 2px; height: 14px;
  margin-left: 3px;
  vertical-align: -2px;
  background: #94a3b8;
  animation: blink 1s steps(1) infinite;
}

/* 中文对照卡：跟在原文气泡下方 */
.ref-card {
  margin-top: 7px;
  max-width: 100%;
  padding: 8px 11px;
  border-radius: 12px;
  background: #f7f9fc;
  border: 1px solid #edf1f7;
  color: #64748b;
  text-align: left;
  animation: rise .2s ease;
}
.ref-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 3px;
}
.ref-tag {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  line-height: 16px;
  color: #64748b;
  background: #e8edf6;
  white-space: nowrap;
}
.ref-state { font-size: 10.5px; color: #a3adbd; }
.ref-body {
  font-size: 12.5px;
  line-height: 1.6;
  color: #64748b;
  white-space: pre-wrap;
  word-break: break-word;
}
.ref-card.failed { border-color: #f6dada; background: #fffafa; }

.playing {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 7px 4px 0;
  font-size: 11px;
  color: #059669;
}
.eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}
.eq i {
  width: 2.5px;
  height: 4px;
  border-radius: 2px;
  background: currentColor;
  animation: eq 1s ease-in-out infinite;
}
.eq i:nth-child(2) { animation-delay: .14s; }
.eq i:nth-child(3) { animation-delay: .28s; }
.eq i:nth-child(4) { animation-delay: .42s; }
.status .eq { color: inherit; }

/* ── 底部控制 ─────────────────────────── */
.composer {
  flex: none;
  padding: 12px 20px 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid #f0f3f8;
  background: #fff;
}
.lang-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 11px;
  font-size: 11.5px;
  color: var(--ink-3);
}
.lang-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 10px;
  background: #f6f8fc;
  border: 1px solid #eef1f7;
}
.lang-pill b { color: var(--ink-2); font-weight: 600; }
.lang-pill em {
  font-style: normal;
  font-size: 10px;
  color: #aeb7c6;
}
.lang-pill select {
  appearance: none;
  border: 0;
  outline: none;
  padding: 0 15px 0 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  background: transparent
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>")
    no-repeat right center;
  cursor: pointer;
}
.lang-pill select:disabled { color: var(--ink-3); cursor: default; }
.arrow { color: #c2cad8; }

.sound-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border-radius: 9px;
  border: 1px solid #eef1f7;
  background: #f6f8fc;
  font-size: 11.5px;
  color: #64748b;
  transition: color .18s, background .18s;
}
.sound-btn svg { width: 14px; height: 14px; }
.sound-btn.off { color: #b4bdcb; background: #fafbfd; }

.action-btn {
  width: 100%;
  height: 54px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 15.5px;
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  box-shadow: 0 12px 26px -12px rgba(37, 99, 235, .8);
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background .18s, transform .1s, box-shadow .18s;
}
.action-btn:hover { background: #1d4ed8; }
.action-btn:active { transform: scale(.986); }
.action-btn.busy {
  background: #cbd5e1;
  box-shadow: none;
  cursor: default;
}
.action-btn.busy:hover { background: #cbd5e1; }
.action-btn.recording,
.action-btn.running {
  background: var(--red);
  box-shadow: 0 12px 26px -12px rgba(239, 68, 68, .75);
}
.action-btn.running:hover { background: #dc2626; }
.action-btn.recording { animation: breathe 1.8s ease-in-out infinite; }
.action-btn svg { width: 18px; height: 18px; flex: none; }
.action-btn .stop-square {
  width: 11px; height: 11px;
  border-radius: 3px;
  background: currentColor;
}

.tip {
  margin-top: 9px;
  text-align: center;
  font-size: 11px;
  color: #a3adbd;
}

/* ── 顶栏右侧 ─────────────────────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  max-width: 120px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid #e9edf4;
  background: #f7f9fc;
  font-size: 11px;
  color: #64748b;
  transition: background .18s, color .18s;
}
.voice-chip:hover { background: #eef3fa; color: #334155; }
.voice-chip svg { width: 13px; height: 13px; flex: none; }
.voice-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 音色设置弹层 ─────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .38);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(480px, 100%);
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 30px 80px -20px rgba(15, 23, 42, .45);
  animation: rise .22s ease;
}
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 12px;
  border-bottom: 1px solid #f1f4f9;
}
.sheet-head h2 { font-size: 16px; font-weight: 650; }
.sheet-head p { margin-top: 3px; font-size: 11.5px; color: var(--ink-3); }
.sheet-close {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 9px;
  font-size: 20px;
  line-height: 1;
  color: #94a3b8;
  background: #f6f8fc;
}
.sheet-close:hover { background: #eef3fa; color: #475569; }
.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 22px 24px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #dbe2ee transparent;
}
.sheet-body::-webkit-scrollbar { width: 5px; }
.sheet-body::-webkit-scrollbar-thumb { background: #dbe2ee; border-radius: 99px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field + .field {
  padding-top: 18px;
  border-top: 1px solid #f1f4f9;
}
.field h3, .field-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field-hint { font-size: 11.5px; line-height: 1.65; color: var(--ink-3); }

.voice-select,
.text-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid #e6ebf3;
  background: #f8fafd;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.voice-select {
  appearance: none;
  padding-right: 32px;
  background: #f8fafd
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>")
    no-repeat right 12px center;
  cursor: pointer;
}
.voice-select:focus,
.text-input:focus {
  border-color: #93b4f5;
  box-shadow: 0 0 0 3px #e6efff;
}
.voice-select:disabled { color: var(--ink-3); cursor: default; }

.script-box {
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px dashed #dfe6f0;
  background: #f7f9fc;
  font-size: 12px;
  line-height: 1.7;
  color: #64748b;
}

.enroll-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-secondary,
.btn-primary {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 600;
  transition: background .18s;
}
.btn-secondary {
  background: #f6f8fc;
  border: 1px solid #e9edf4;
  color: #475569;
}
.btn-secondary:hover { background: #eef3fa; }
.btn-secondary.recording {
  background: #fef2f2;
  border-color: #fbdada;
  color: #dc2626;
}
.file-btn { cursor: pointer; }
.file-btn input { display: none; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.record-state { font-size: 11.5px; line-height: 1.5; color: #059669; }
.record-state.recording { color: #dc2626; }
.record-state.error { color: #dc2626; }

.voice-list { display: flex; flex-direction: column; gap: 8px; }
.voice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid #edf1f7;
  background: #f8fafd;
}
.voice-item .vi-main { min-width: 0; }
.voice-item .vi-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-item .vi-meta { margin-top: 2px; font-size: 10.5px; color: #a3adbd; }
.voice-item .vi-del {
  flex: none;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #f7d9d9;
  background: #fff1f1;
  font-size: 11px;
  color: #b91c1c;
}
.voice-item .vi-del:hover { background: #ffe8e8; }
.voice-empty { font-size: 11.5px; color: #a3adbd; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50%      { box-shadow: 0 0 0 4px transparent; opacity: .55; }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes eq {
  0%, 100% { height: 4px; }
  50%      { height: 11px; }
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 12px 26px -12px rgba(239, 68, 68, .75), 0 0 0 0 rgba(239, 68, 68, .18); }
  50%      { box-shadow: 0 12px 26px -12px rgba(239, 68, 68, .75), 0 0 0 9px rgba(239, 68, 68, 0); }
}

@media (max-width: 640px) {
  body { padding: 0; align-items: stretch; }
  .app {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .modal { align-items: flex-end; padding: 0; }
  .sheet {
    width: 100%;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
  }
}
@media (max-width: 430px) {
  .voice-chip span { display: none; }
  .voice-chip { padding: 0 7px; }
  .brand p { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-height: 620px) {
  .app-header { padding-top: 16px; }
  .empty .orb { display: none; }
}