:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent2: #22d3ee;
  --user: #2563eb;
  --coach: #334155;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --border: #334155;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}
body {
  display: flex; flex-direction: column;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.brand b { font-size: 12px; color: var(--accent); font-weight: 600; margin-left: 4px; }
.status { font-size: 12px; color: var(--muted); max-width: 55%; text-align: right; }

.card {
  background: var(--card);
  margin: 10px;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--border);
}

.controls .row {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px;
}
.controls .row:last-child { margin-bottom: 0; }
.controls label {
  display: flex; flex-direction: column; font-size: 12px; color: var(--muted);
  flex: 1; min-width: 90px; gap: 4px;
}
.controls select, .controls input[type=range] {
  width: 100%; padding: 8px; border-radius: 8px;
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  font-size: 14px;
}
#rateVal { color: var(--accent); font-size: 12px; }

.btn {
  border: none; border-radius: 10px; padding: 10px 14px;
  background: var(--accent); color: #03263a; font-weight: 700; font-size: 14px;
  cursor: pointer;
}
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--border); font-weight: 600; }

.chat {
  flex: 1; overflow-y: auto; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 82%; padding: 10px 13px; border-radius: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; font-size: 15px;
  border: 2px solid transparent;
}
.bubble.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.bubble.coach { align-self: flex-start; background: var(--coach); border-bottom-left-radius: 4px; }
.bubble.review { align-self: flex-start; background: var(--card2); font-size: 14px; border-bottom-left-radius: 4px; }
.bubble.target {
  align-self: flex-start; background: #14324a; border: 1px dashed var(--accent);
  font-size: 16px; font-style: italic;
}
.bubble .who { font-size: 11px; color: var(--muted); display: block; margin-bottom: 4px; }

/* 朗读时边框闪烁（内容不闪） */
@keyframes speakFlash {
  0%, 100% { border-color: var(--accent); box-shadow: 0 0 0 0 rgba(56,189,248,0.0); }
  50% { border-color: var(--accent2); box-shadow: 0 0 10px 2px rgba(34,211,238,0.35); }
}
.bubble.speaking { animation: speakFlash 1s ease-in-out infinite; }

.inputbar { display: flex; gap: 8px; align-items: center; }
.inputbar input {
  flex: 1; padding: 11px; border-radius: 10px; background: var(--card2);
  border: 1px solid var(--border); color: var(--text); font-size: 15px;
}

.actionbar { display: flex; gap: 10px; padding: 0 10px 10px; }
.record {
  flex: 1; padding: 16px; border-radius: 14px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #03263a; font-weight: 800; font-size: 17px; cursor: pointer;
}
.record.listening {
  background: linear-gradient(135deg, var(--err), #fb7185); color: #fff;
  animation: speakFlash 1.2s ease-in-out infinite;
}
.actionbar .btn.ghost { flex: 0 0 auto; }

.apikey-card { border-color: var(--accent); }
.apikey-head { font-size: 13px; color: var(--text); margin-bottom: 8px; font-weight: 600; }
.apikey-row { display: flex; gap: 8px; align-items: center; }
.apikey-row input {
  flex: 1; padding: 11px; border-radius: 10px; background: var(--card2);
  border: 1px solid var(--border); color: var(--text); font-size: 14px;
  min-width: 0;
}
.apikey-status { font-size: 12px; color: var(--muted); margin-top: 8px; }
.apikey-status.ok { color: var(--ok); }
.apikey-status.warn { color: var(--warn); }
.apikey-status.err { color: var(--err); }
.apikey-status.loading { color: var(--accent); }

/* —— 多服务商 key 卡片 —— */
.ak-label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.ak-label.grow { flex: 1; min-width: 150px; }
.apikey-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.apikey-row:first-of-type { margin-top: 0; }
.apikey-row.ak-actions { align-items: center; }
.input-wrap { position: relative; display: flex; align-items: center; flex: 1; min-width: 0; }
.input-wrap input {
  width: 100%; padding: 11px 72px 11px 11px; border-radius: 10px;
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; min-width: 0;
}
.input-wrap .icn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border: none; border-radius: 7px;
  background: var(--card); color: var(--muted); font-size: 13px; cursor: pointer;
}
.input-wrap .icn + .icn { right: 40px; }
.apikey-note { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* —— 语速档 + 微调 —— */
.grow { flex: 1; min-width: 120px; }
.rate-block { align-items: flex-end; flex-wrap: wrap; }
.rate-block label { flex: 0 0 auto; }
.rate-block .grow { flex: 1; min-width: 120px; }
.rate-val { font-size: 12px; color: var(--accent); white-space: nowrap; align-self: center; margin-left: 4px; }

.footer {
  text-align: center; font-size: 11px; color: var(--muted);
  padding: 8px 16px 14px;
}

/* 状态颜色 */
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }
.status.loading { color: var(--accent); }
