/* live-translate / live.html — 大厂简约风，无外部依赖
   布局（自上而下）：顶栏 / 中央画面区 / 历史区 / 底部字幕带 / 操作栏
   字幕只出现在底部专用字幕带，绝不遮挡中央画面区。 */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-muted: #fafafa;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-pressed: #0077ed;
  --danger: #d70015;
  --warn-bg: #fff8e1;
  --warn-text: #7a5c00;
  --ok: #1d7a3d;
  --caption-size: 22px;
  --radius: 14px;
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-muted: #2c2c2e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --border: #38383a;
    --accent: #0a84ff;
    --accent-pressed: #409cff;
    --danger: #ff453a;
    --warn-bg: #3a2f00;
    --warn-text: #ffd60a;
    --ok: #30d158;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
}

/* ---- 顶栏 ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
}
.topbar h1 { font-size: 19px; font-weight: 700; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a.back { color: var(--accent); text-decoration: none; font-size: 15px; white-space: nowrap; }
.lang-toggle {
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; cursor: pointer;
}
.wakelock {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.wakelock .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.wakelock.on { color: var(--ok); }
.wakelock.on .dot { background: var(--ok); }
.wakelock.unsupported { color: var(--warn-text); }
.wakelock.unsupported .dot { background: var(--warn-text); }

/* ---- 提示横幅 ---- */
.banner {
  display: none;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 12px;
}
.banner.show { display: block; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.error { background: #fdecea; color: #8f1d1d; }
@media (prefers-color-scheme: dark) { .banner.error { background: #3a1518; color: #ff9a94; } }
.banner .steps { margin: 8px 0 0; padding-left: 20px; }
.banner .steps li { margin: 4px 0; }

/* ---- 中央画面区（永不被字幕遮挡） ---- */
.stage {
  flex: 1 1 auto;
  min-height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  text-align: center;
}
.stage .state-pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}
.stage .state-pill[data-state="listening"],
.stage .state-pill[data-state="recognizing"],
.stage .state-pill[data-state="translating"] { background: #e8f1fd; color: #0057b8; border-color: #bcd8f7; }
.stage .state-pill[data-state="reconnecting"] { background: var(--warn-bg); color: var(--warn-text); border-color: #e8d48a; }
.stage .state-pill[data-state="disconnected"] { background: #fdecea; color: #8f1d1d; border-color: #f5c6c2; }
.stage .state-pill[data-state="ended"] { background: var(--surface-muted); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .stage .state-pill[data-state="listening"],
  .stage .state-pill[data-state="recognizing"],
  .stage .state-pill[data-state="translating"] { background: #0a2a4a; color: #6db3ff; border-color: #1d4e79; }
}
.stage .stage-hint { color: var(--muted); font-size: 15px; line-height: 1.6; max-width: 420px; }
.stage .mic-level { width: min(320px, 80%); height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.stage .mic-level > i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 120ms linear; }
.stage .reconnect-note { font-size: 14px; color: var(--warn-text); }

/* ---- 历史区 ---- */
.history {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 32vh;
  overflow-y: auto;
  padding: 6px 0;
}
.history:empty { display: none; }
.history-item { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 15px; line-height: 1.55; }
.history-item:last-child { border-bottom: 0; }
.history-item .src { color: var(--text); }
.history-item .dst { color: var(--accent); }
.history-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.history-empty { padding: 12px 16px; color: var(--muted); font-size: 14px; text-align: center; }

/* ---- 底部专用字幕带：最多 2 行，超出滚动进历史区 ---- */
.caption-band {
  margin-top: 12px;
  background: #000;
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: calc(var(--caption-size) * 2 * 1.5 + 24px);
}
.caption-band .cap-src,
.caption-band .cap-dst {
  font-size: var(--caption-size);
  line-height: 1.5;
  overflow-wrap: anywhere;
  /* 视觉兜底：最多两行（原文一行 + 译文一行） */
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.caption-band .cap-dst { color: #7dc4ff; }
.caption-band .cap-src:empty,
.caption-band .cap-dst:empty { display: none; }
.caption-band .cap-empty { color: #a1a1a6; font-size: 15px; line-height: 1.5; }
.caption-band .cap-source {
  margin-top: 4px;
  font-size: 12px;
  color: #a1a1a6;
}
.caption-band .cap-source:empty { display: none; }

/* ---- 操作栏：单手可达的大按钮 ---- */
.controls {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lang-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.lang-row label { font-size: 14px; color: var(--muted); }
.lang-row select {
  flex: 1;
  min-width: 120px;
  min-height: var(--tap);
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}
.lang-row .swap { min-width: var(--tap); min-height: var(--tap); border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 18px; cursor: pointer; }
.font-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.font-row button {
  min-width: var(--tap); min-height: 40px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 15px; cursor: pointer;
}
.font-row button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.action-row { display: flex; gap: 10px; }
.btn {
  flex: 1;
  min-height: 56px;
  border: 0;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.btn-start { background: var(--accent); color: #fff; }
.btn-start:active { background: var(--accent-pressed); }
.btn-end { background: var(--danger); color: #fff; }
.btn-retry { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.session-line { font-size: 13px; color: var(--muted); text-align: center; }

/* ---- 平板 / PC ---- */
@media (min-width: 700px) {
  .page { padding-left: 24px; padding-right: 24px; }
  .topbar h1 { font-size: 22px; }
  .stage { min-height: 300px; }
  .controls { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .lang-row { flex: 1 1 420px; }
  .font-row { flex: 0 0 auto; }
  .action-row { flex: 1 1 100%; }
}
