:root {
  --bg: #121314;
  --fg: #ffffff;
  --fg2: rgba(255, 255, 255, 0.78);
  --fg3: rgba(255, 255, 255, 0.55);
  --line: rgba(255, 255, 255, 0.10);
  --green: #07c160;
  --green-press: #06ad56;
  --red: #fa5151;
  --red-press: #e64545;
  --grey: rgba(255, 255, 255, 0.16);
  --grey-on: #ffffff;
  --bubble-ai: rgba(255, 255, 255, 0.10);
  --bubble-me: rgba(7, 193, 96, 0.26);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + 16px) calc(var(--sab) + 18px) calc(var(--sal) + 16px);
  background: radial-gradient(130% 70% at 50% 0%, #3b4046 0%, #1d1f22 58%, #131415 100%);
  overflow: hidden;
}
@media (min-width: 520px) {
  body { background: #0c0d0e; }
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* 顶栏 */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.brand { font-size: 12px; letter-spacing: 0.24em; color: var(--fg3); font-weight: 600; }
.lang {
  min-width: 56px; height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.06);
  font-size: 14px; cursor: pointer;
}
.lang:active { background: rgba(255, 255, 255, 0.16); }

/* 头像 + 名字 + 状态 */
.who { text-align: center; padding-top: clamp(8px, 4.5vh, 44px); }
.avatar { position: relative; width: 96px; height: 96px; margin: 0 auto 14px; }
.avatar svg { position: relative; display: block; border-radius: 50%; }
.avatar .ring {
  position: absolute; inset: -8px; border-radius: 50%;
  border: 2px solid rgba(217, 242, 74, 0.55); opacity: 0; transform: scale(0.92);
}
.app[data-talk="ai"] .avatar .ring { animation: ring 1.6s ease-out infinite; }
@keyframes ring { 0% { opacity: 0.9; transform: scale(0.92); } 100% { opacity: 0; transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .app[data-talk="ai"] .avatar .ring { animation: none; opacity: 0.8; transform: none; } }

h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.sub { margin: 6px 0 0; font-size: 14px; color: var(--fg3); }
.demo {
  display: inline-block; margin: 10px auto 0; padding: 4px 10px; border-radius: 12px;
  background: rgba(255, 196, 0, 0.16); color: #ffd666; font-size: 12px; line-height: 1.5;
}
.status { margin: 14px 0 0; font-size: 16px; color: var(--fg2); min-height: 24px; }
.timer { margin: 4px 0 0; font-size: 15px; color: var(--fg3); font-variant-numeric: tabular-nums; min-height: 22px; }

/* 通话中把头部收紧一点，给字幕留空间 */
.app[data-state="incall"] .who { padding-top: clamp(4px, 1.5vh, 16px); }
.app[data-state="incall"] .avatar { width: 72px; height: 72px; margin-bottom: 10px; }
.app[data-state="incall"] .avatar svg { width: 72px; height: 72px; }
.app[data-state="incall"] h1 { font-size: 20px; }
.app[data-state="incall"] .status { margin-top: 10px; }

/* 引擎选择 */
.engines { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-checked="true"] { background: #fff; color: #1d1f22; border-color: #fff; font-weight: 600; }
.chip:disabled { opacity: 0.38; cursor: default; }
.app[data-state="incall"] .engines, .app[data-state="connecting"] .engines { display: none; }
#personas { margin-top: 12px; }
#personas + #engines { margin-top: 8px; }

/* 字幕 */
.captions {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 14px -4px 10px; padding: 18px 4px 6px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
  scrollbar-width: none;
}
.captions::-webkit-scrollbar { display: none; }
.hint { text-align: center; color: var(--fg3); font-size: 14px; margin: 18px 0 0; }
.line { display: flex; flex-direction: column; margin: 0 0 10px; }
.line .bubble {
  max-width: 86%; padding: 9px 13px; border-radius: 14px; font-size: 16px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.line.ai { align-items: flex-start; }
.line.ai .bubble { background: var(--bubble-ai); border-top-left-radius: 4px; }
.line.me { align-items: flex-end; }
.line.me .bubble { background: var(--bubble-me); border-top-right-radius: 4px; }
.line.pending .bubble { color: var(--fg3); }
.line .meta { font-size: 12px; color: var(--fg3); margin: 3px 4px 0; }
.line.sys { align-items: center; }
.line.sys .bubble {
  background: transparent; color: var(--fg3); font-size: 13px; padding: 2px 8px; text-align: center; max-width: 92%;
}

/* 按钮 */
.controls {
  display: flex; justify-content: center; align-items: flex-start; gap: 44px;
  padding-top: 6px; min-height: 112px;
}
.ctl { display: flex; flex-direction: column; align-items: center; width: 84px; }
.round {
  width: 68px; height: 68px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
  touch-action: manipulation;
}
.round.big { width: 76px; height: 76px; }
.round:not(.big) { margin: 4px 0; }
.round:active { transform: scale(0.95); }
.round.green { background: var(--green); color: #fff; }
.round.green:active { background: var(--green-press); }
.round.red { background: var(--red); color: #fff; }
.round.red:active { background: var(--red-press); }
.round.grey { background: var(--grey); color: #fff; }
.round.grey[aria-pressed="true"] { background: var(--grey-on); color: #1d1f22; }
.round .ic-mic-off { display: none; }
.round[aria-pressed="true"] .ic-mic { display: none; }
.round[aria-pressed="true"] .ic-mic-off { display: block; }
.round:disabled { opacity: 0.5; cursor: default; }
.lbl { margin-top: 10px; font-size: 13px; color: var(--fg2); white-space: nowrap; }
.app[data-state="connecting"] #callBtn { animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.6; } }

/* 出错时的底部卡片 */
.sheet {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  padding: 0 calc(var(--sar) + 12px) calc(var(--sab) + 14px) calc(var(--sal) + 12px);
  background: rgba(0, 0, 0, 0.45); z-index: 10;
}
.card {
  width: 100%; max-width: 456px; background: #2a2d31; border-radius: 18px; padding: 22px 20px 18px;
  text-align: center; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}
.err-ic {
  width: 40px; height: 40px; margin: 0 auto 10px; border-radius: 50%; background: rgba(250, 81, 81, 0.18);
  color: #ff7875; font-weight: 700; font-size: 22px; line-height: 40px;
}
.card h2 { margin: 0; font-size: 18px; font-weight: 600; }
.card p { margin: 10px 0 18px; font-size: 15px; line-height: 1.6; color: var(--fg2); text-align: left; white-space: pre-line; }
.btn {
  width: 100%; height: 50px; border: 0; border-radius: 12px; background: var(--green); color: #fff;
  font-size: 17px; font-weight: 600; cursor: pointer;
}
.btn:active { background: var(--green-press); }
.btn:focus { outline: none; }
.btn:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.7); outline-offset: 2px; }

/* 测试用：模拟刘海和底部横条（?sim_safe=1） */
.sim-notch, .sim-home { position: fixed; left: 50%; transform: translateX(-50%); z-index: 99; pointer-events: none; }
.sim-notch { top: 11px; width: 126px; height: 37px; border-radius: 20px; background: #000; outline: 1px dashed rgba(255, 0, 0, 0.7); }
.sim-home { bottom: 8px; width: 134px; height: 5px; border-radius: 3px; background: #fff; outline: 1px dashed rgba(255, 0, 0, 0.7); }
.sim-band { position: fixed; left: 0; right: 0; z-index: 98; pointer-events: none; background: rgba(255, 0, 0, 0.10); }

/* ===== 嵌入看板（?embed=board）：64 px 高的一条：左边按钮，右边两行字幕 ===== */
html.embed-board { --efg: #1d1f22; --efg2: #5c636b; --err: #d4380d; color-scheme: light dark; }
@media (prefers-color-scheme: dark) { html.embed-board { --efg: #eceef0; --efg2: #9aa1a8; --err: #ff7a45; } }
html.embed-board, html.embed-board body { background: transparent; height: 64px; overflow: hidden; color: var(--efg); }
html.embed-board .app {
  height: 64px; max-width: none; margin: 0; padding: 0 12px 0 calc(var(--sal) + 10px);
  display: flex; flex-direction: row; align-items: center; gap: 12px;
  background: transparent; border: 0;
}
html.embed-board .top, html.embed-board .who, html.embed-board .sheet, html.embed-board #hangWrap,
html.embed-board .lbl, html.embed-board .sim-band, html.embed-board .sim-notch, html.embed-board .sim-home { display: none !important; }
html.embed-board .controls { order: 0; flex: 0 0 auto; min-height: 0; padding: 0; gap: 0; }
html.embed-board .ctl { width: auto; }
html.embed-board .round, html.embed-board .round.big, html.embed-board .round:not(.big) { width: 46px; height: 46px; margin: 0; }
html.embed-board .round svg { width: 22px; height: 22px; }
html.embed-board .round.grey { background: rgba(127, 127, 127, 0.2); color: var(--efg); }
html.embed-board .round.grey[aria-pressed="true"] { background: var(--efg); color: #fff; }
html.embed-board .captions {
  order: 1; flex: 1 1 auto; min-width: 0; height: 44px; margin: 0; padding: 0; overflow: hidden;
  scroll-behavior: smooth; -webkit-mask-image: none; mask-image: none;
}
html.embed-board .hint { margin: 0; text-align: left; font-size: 14px; line-height: 22px; padding-top: 11px; color: var(--efg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.embed-board .hint.err { color: var(--err); }
html.embed-board .line { display: block; margin: 0; }
html.embed-board .line .bubble {
  display: block; max-width: 100%; padding: 0; border-radius: 0; background: none !important;
  font-size: 14px; line-height: 22px; height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--efg);
}
html.embed-board .line .bubble::before { content: attr(data-who) "："; color: var(--efg2); }
html.embed-board .line.sys .bubble { color: var(--efg2); text-align: left; font-size: 13px; }
html.embed-board .line.sys .bubble::before { content: "· "; }
html.embed-board .line.err .bubble { color: var(--err); }
html.embed-board .line.pending .bubble { color: var(--efg2); }
html.embed-board .line .meta { display: none !important; }

/* 打开就通话：浏览器要求先点一下时的全屏提示 */
.tap-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(10, 11, 12, 0.92); color: #fff; font-size: 22px; letter-spacing: 0.04em; cursor: pointer;
  padding: calc(var(--sat) + 16px) 16px calc(var(--sab) + 16px);
}
/* 身份 / 引擎选项收在 ⋯ 里 */
.app:not(.show-settings) #personas, .app:not(.show-settings) #engines { display: none !important; }
.top .more { min-width: 44px; margin-left: auto; margin-right: 8px; }
