/* voice-realtime 网页客户端 —— 零构建纯静态,深色简洁风 */
:root {
  --bg: #101418;
  --panel: #171d24;
  --panel-2: #1d2530;
  --text: #dce3ea;
  --muted: #7d8a97;
  --accent: #4da3ff;
  --ok: #3ecf8e;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --played: #eaf2ff;
  --pending: #5a6673;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- 头部 ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid #232c37;
}
.brand { font-weight: 700; letter-spacing: 0.5px; }
.app-header nav { display: flex; gap: 6px; flex: 1; }
.app-header nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 12px;
  border-radius: 6px;
}
.app-header nav a.active { color: var(--text); background: var(--panel-2); }
.app-header nav a.stub { opacity: 0.45; }
.badge {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.on { background: rgba(62, 207, 142, 0.15); color: var(--ok); }
.badge.off { background: rgba(255, 107, 107, 0.12); color: var(--danger); }

/* ---------- 布局 ---------- */
.page { flex: 1; display: flex; gap: 16px; padding: 16px 18px; overflow: hidden; }
.page.hidden { display: none; }
/* 手机抽屉的包装层在桌面不参与布局,角色/历史仍是 #page-session 的直接 flex 项。 */
.session-people-panel { display: contents; }
.session-mobile-bar,
.mobile-panel-header,
.session-mobile-backdrop,
.session-mobile-dock { display: none; }
#page-settings, #page-characters {
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  overflow-y: auto;
}
.card {
  width: min(720px, 100%);
  background: var(--panel);
  border: 1px solid #232c37;
  border-radius: 10px;
  padding: 14px 18px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; }

.session-left {
  width: 316px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.session-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* ---------- 舞台占位 ---------- */
.avatar-stage {
  position: relative;
  height: 220px;
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 120%, #1b2836 0%, var(--panel) 70%);
  border: 1px solid #232c37;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.stage-bars {
  display: flex;
  gap: 7px;
  align-items: flex-end;
  height: 90px;
}
.stage-bars span {
  width: 9px;
  height: 12%;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), #2c6db5);
  transition: height 80ms linear;
}
.stage-hint {
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 电平表 ---------- */
.meters { display: flex; flex-direction: column; gap: 6px; }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row label { width: 44px; color: var(--muted); font-size: 12px; }
.meter {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--panel-2);
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--ok), var(--warn) 80%, var(--danger));
  transition: width 60ms linear;
}
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #39434e;
  flex-shrink: 0;
}
.dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(62, 207, 142, 0.7); }

/* VAD 概率条:门槛竖线 + 超线变红 */
.meter#vad-meter { position: relative; }
.meter#vad-meter em {
  position: absolute;
  top: -2px; bottom: -2px;
  left: 50%;
  width: 2px;
  background: var(--warn);
  border-radius: 1px;
}
.meter#vad-meter i { background: linear-gradient(90deg, #3a8f6d, var(--ok)); transition: width 40ms linear; }
.meter#vad-meter i.over { background: var(--danger); }

/* ---------- 控件 ---------- */
button {
  font: inherit;
  padding: 7px 16px;
  border-radius: 7px;
  border: 1px solid #2b3644;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #2c6db5; border-color: #3579c4; }
button.primary:hover:not(:disabled) { background: #3579c4; }
button.danger { background: #7a2f2f; border-color: #944; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.statusline { color: var(--muted); font-size: 13px; }
.statusline b { color: var(--text); }
.muted { color: var(--muted); }

.notes {
  flex: 1;
  min-height: 90px;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: 8px 10px;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid #232c37;
  border-radius: 8px;
  white-space: pre-wrap;
}

/* ---------- 字幕/转写(微信聊天样式) ---------- */
.transcript {
  flex: 1;
  overflow-y: auto;
  background: #141a22;
  border: 1px solid #232c37;
  border-radius: 10px;
  padding: 14px 16px;
}
.turn { display: flex; gap: 8px; margin: 7px 0; align-items: flex-start; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}
.turn.assistant .avatar, .subtitle-current .avatar { background: #3b5166; color: #cfe3ff; }
.turn.user { flex-direction: row-reverse; }
.turn.user .avatar { background: #57855a; color: #eaffea; }
.turn .bubble {
  max-width: 72%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.turn.assistant .bubble {
  background: #232b34;
  color: var(--text);
  border-top-left-radius: 2px;
}
.turn.user .bubble {
  background: #95ec69; /* 微信绿 */
  color: #10230d;
  border-top-right-radius: 2px;
}
/* 气泡小尾巴 */
.turn.assistant .bubble::before {
  content: '';
  position: absolute;
  top: 12px;
  left: -5px;
  border: 5px solid transparent;
  border-right-color: #232b34;
  border-left: 0;
}
.turn.user .bubble::before {
  content: '';
  position: absolute;
  top: 12px;
  right: -5px;
  border: 5px solid transparent;
  border-left-color: #95ec69;
  border-right: 0;
}
/* 已播/未播语义保留在 AI 气泡内 */
.turn .bubble .played { color: inherit; }
.turn .bubble .pending { color: #6b7683; }
/* 台词外内容(thought/action/address 等):剧本注解样式,不参与播放 */
.turn .bubble .aside {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: #8a93a0;
  font-style: italic;
  margin: 3px 0;
}
.turn .bubble .cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.time-divider {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 12px 0 4px;
  user-select: none;
}
.chat-divider {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0 6px;
  width: 100%;
  user-select: none;
}
.chat-divider::before, .chat-divider::after {
  content: '';
  display: inline-block;
  width: 28%;
  border-top: 1px dashed #2b3644;
  vertical-align: middle;
  margin: 0 8px;
}

/* 底部:正在识别的用户语音(微信输入条位置,右侧半透明绿气泡) */
.subtitle-current {
  background: var(--panel);
  border: 1px solid #232c37;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 60px;
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
  align-items: flex-start;
}
.subtitle-current .bubble.live-input {
  background: rgba(149, 236, 105, 0.75);
  color: #10230d;
  border-radius: 10px;
  border-top-right-radius: 2px;
  max-width: 72%;
  padding: 8px 12px;
  white-space: pre-wrap;
}
.subtitle-current .bubble.live-input:empty { display: none; }

/* ---------- 表单 ---------- */
.form-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.form-row label { width: 88px; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.form-row input[type="text"], .form-row select {
  flex: 1;
  min-width: 200px;
  font: inherit;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid #2b3644;
  background: #121820;
  color: var(--text);
}
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0 98px; width: 100%; }
.adv-group {
  margin: 16px 0 4px;
  font-size: 13px;
  color: var(--accent);
  border-bottom: 1px dashed #2b3644;
  padding-bottom: 4px;
}
.adv-group:first-child { margin-top: 4px; }
.adv-item input[type="number"] { width: 110px; min-width: 110px; flex: 0; }
.adv-item input[type="checkbox"] { width: 18px; height: 18px; }
.adv-item select { flex: 0; min-width: 240px; }
.ok { color: var(--ok); font-size: 13px; }
.hidden { display: none !important; }

/* 自动保存全局提示(固定右下角,任何滚动位置可见) */
.save-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: rgba(62, 207, 142, 0.15);
  color: var(--ok);
  border: 1px solid rgba(62, 207, 142, 0.4);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
  z-index: 99;
}
.save-toast.show { opacity: 1; transform: translateY(0); }

/* 全局 note 浮动提示(2026-11-05):右上角堆叠,body 级,跨页可见
   ——local:note 此前唯一渲染点是会话页 #notes,其它页(音频库录音的
   修复/降噪/建议提示)全写进隐藏抽屉=用户零感知。toast=即时反馈,
   会话页 notes 日志=事后可查,两通道并存。
   位置选右上:右下被设置页 .save-toast 常驻占用,避免叠罗汉。 */
.global-toasts {
  position: fixed;
  right: 18px;
  top: 56px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1200;
  pointer-events: none;
  max-width: min(420px, 60vw);
}
.global-toast {
  background: rgba(38, 42, 50, 0.97);
  color: #e6e6e6;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-left: 3px solid #3ecf8e;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 200ms ease, transform 200ms ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
.global-toast.show { opacity: 1; transform: translateY(0); }

/* 电平表刻度 */
.meter-col { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.meter-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
  user-select: none;
}

/* 三条轴右端对齐:统一宽度的右侧槽位 */
.meter-side {
  width: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.meter-side #vad-text { font-size: 12px; }

/* ---------- 角色卡片 ---------- */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 8px 0;
}
.character-card {
  background: var(--panel-2);
  border: 2px solid #232c37;
  border-radius: 12px;
  padding: 16px 14px;
  cursor: pointer;
  transition: border-color 150ms, transform 100ms;
  text-align: center;
  position: relative;
}
.character-card:hover {
  border-color: var(--accent, #4da3ff);
  transform: translateY(-2px);
}
.character-card.active {
  border-color: var(--accent, #4da3ff);
  background: color-mix(in srgb, var(--accent, #4da3ff) 10%, var(--panel-2));
}
.character-card.add-card {
  border-style: dashed;
  opacity: 0.6;
}
.character-card.add-card:hover { opacity: 1; }
.char-emoji { font-size: 36px; margin-bottom: 6px; }
.char-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.char-desc { font-size: 12px; color: var(--muted); margin-bottom: 6px; min-height: 18px; }
.char-voice { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.char-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.char-btn {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 5px;
  border: 1px solid #2b3644;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.char-btn.select { background: var(--accent, #4da3ff); border-color: var(--accent); color: #fff; }
.character-card.active .char-btn.select { opacity: 0.7; }

/* ---------- 会话页角色横幅 ---------- */
.char-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid #232c37;
  border-radius: 8px;
}
.char-banner-emoji { font-size: 22px; }
.char-banner-name { font-weight: 600; flex: 1; }
.char-banner-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.char-banner-link:hover { text-decoration: underline; }

/* ---------- 音频库 ---------- */
.voice-list { display: flex; flex-direction: column; gap: 8px; }
.voice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid #232c37;
  border-radius: 8px;
}
.voice-info { flex: 1; min-width: 0; }
.voice-name { font-weight: 600; font-size: 14px; }
.voice-id { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.voice-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 12px; }

/* ---------- 内联编辑/行内提示(替代 prompt/alert) ---------- */
.inline-input {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--accent, #4da3ff);
  background: #121820;
  color: var(--text);
}
.inline-input.inline-num { width: 110px; }
.inline-note { font-size: 12px; margin-left: 6px; }
.inline-note.ok { color: var(--ok); }
.inline-note.err { color: var(--danger); }
.mini-btn {
  font-size: 11px;
  padding: 2px 8px;
  margin-left: 4px;
  border-radius: 5px;
  border: 1px solid #2b3644;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

/* ============================================================
 * 角色扮演完整人设面板(折叠区块 + 多条字段)
 * ============================================================ */
.rp-panel {
  border: 1px solid #2b3644;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 6px 0 10px;
  background: #0e141b;
}
.rp-panel > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
  user-select: none;
}
.rp-panel[open] > summary { color: var(--text); margin-bottom: 6px; }

.rp-section {
  border: 1px solid #22303f;
  border-radius: 7px;
  margin-bottom: 6px;
  background: #121820;
}
.rp-section > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  user-select: none;
  list-style: none;
}
.rp-section > summary::before { content: '▸ '; color: var(--muted); }
.rp-section[open] > summary::before { content: '▾ '; }
.rp-section-body { padding: 2px 10px 8px; }

.rp-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.rp-field > label {
  width: 150px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}
.rp-field-inputs { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.rp-field-inputs > input, .rp-field-inputs > select, .rp-field-inputs > textarea {
  width: 100%;
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #2b3644;
  background: #0e141b;
  color: var(--text);
}

.rp-multi { display: flex; flex-direction: column; gap: 3px; }
.rp-multi-row { display: flex; gap: 4px; align-items: center; }
.rp-multi-row > input {
  flex: 1;
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #2b3644;
  background: #0e141b;
  color: var(--text);
}
.rp-pairs-row > .rp-pairs-name { flex: 0 0 30%; }
.rp-mini-btn {
  border: none;
  background: #1b2735;
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 7px;
  cursor: pointer;
  font-size: 11px;
  flex-shrink: 0;
}
.rp-mini-btn:hover { color: var(--text); background: #243244; }
.rp-add-btn { align-self: flex-start; margin-top: 1px; }

.rp-field-inputs > textarea { resize: vertical; min-height: 44px; }

/* ============================================================
 * 历史页:对话气泡
 * ============================================================ */
.history-transcript { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; max-height: 60vh; overflow-y: auto; }
.hist-bubble { padding: 8px 12px; border-radius: 10px; max-width: 78%; white-space: pre-wrap; font-size: 14px; line-height: 1.5; }
.hist-user { align-self: flex-end; background: #95ec69; color: #10390b; }
.hist-assistant { align-self: flex-start; background: #1b2735; color: var(--text); }

/* ============================================================
 * 会话页五列:通讯录 | 历史 | 对话(中) | 场景 | 舞台/控制
 * ============================================================ */
/* 五列宽度预算(2026-10-12 二轮,用户实测 1460-1720 屏没见到通讯录):
 * 通讯录 84 + 记录 186 + 场景 300 + 舞台 316 + 4×12 间距 ≈ 934px 固定,
 * 对话列弹性——1366px 屏起五列全可见(对话约 430px) */
.session-scene { margin-left: auto; }

/* 第一列:角色通讯录(头像+名字) */
.session-roster {
  width: 84px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.session-roster-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  max-height: calc(100vh - 120px);
  padding: 0 6px 6px;
}
.roster-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
  border-radius: 8px;
  border: 1px solid #232c37;
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s;
}
.roster-item:hover { border-color: #3a4a5c; }
.roster-item.active { border-color: var(--accent); background: #16222e; }
.roster-item .r-emoji { font-size: 22px; line-height: 1.1; }
/* 角色头像图(卡 avatarUrl;加载失败 JS 落回 emoji) */
.char-avatar { display: block; border-radius: 50%; object-fit: cover; background: #232c37; }
.char-emoji .char-avatar { width: 48px; height: 48px; margin: 0 auto; }
.char-banner-emoji .char-avatar { width: 26px; height: 26px; }
.roster-item .r-emoji .char-avatar { width: 40px; height: 40px; margin: 0 auto; }
.roster-item .r-name {
  font-size: 11px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* 第四列:场景面板 */
.session-scene {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.session-scene-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  max-height: calc(100vh - 120px);
  padding: 0 10px 10px;
}
.scene-card {
  padding: 8px 10px;
  border: 1px solid #232c37;
  border-radius: 8px;
  background: var(--panel);
  font-size: 12px;
}
.scene-card.active { border-color: var(--accent); }
.scene-title { font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.scene-title .tag {
  font-weight: 400;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid #2b3644;
  border-radius: 999px;
  padding: 0 6px;
}
.scene-meta { color: var(--muted); font-size: 11px; line-height: 1.7; margin-top: 2px; word-break: break-all; }
.scene-field { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.scene-field label { font-size: 11px; color: var(--muted); }
.scene-field input,
.scene-field select {
  padding: 4px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  width: 100%;
  box-sizing: border-box;
}
.scene-btns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.scene-btns button {
  padding: 3px 12px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.scene-btns button:hover { border-color: var(--accent); }
.scene-btns button.primary {
  background: linear-gradient(135deg, #2c7ad5, #429bf0);
  border: none;
  color: #fff;
}
.scene-gen textarea,
.scene-field textarea {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid #2b3644;
  background: #121820;
  color: var(--text);
  resize: vertical;
}
.scene-status { font-size: 11px; margin-top: 4px; word-break: break-all; }
.scene-hint { font-size: 11px; color: var(--muted); line-height: 1.6; }
.scene-actions { display: flex; gap: 6px; margin-top: 4px; }
.scene-actions button {
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.scene-actions button:hover { color: var(--text); border-color: var(--accent); }
/* 当前场景卡底部:另存为新场景(输入名 + 按钮一行) */
.scene-save-row { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.scene-save-row input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  box-sizing: border-box;
}
.scene-save-row button {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.scene-save-row button:hover { border-color: var(--accent); }
/* 管理区紧凑行(替代原卡片列表):名字截断 + 删除 */
.scene-manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid #232c37;
  border-radius: 8px;
  background: var(--panel);
  font-size: 12px;
}
.scene-manage-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.scene-manage-row button {
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.scene-manage-row button:hover { color: #e57373; border-color: #e57373; }

/* 五列的窄屏退化:按"最不关键先藏"逐级收列(通讯录→历史→场景) */
@media (max-width: 1360px) { .session-roster { display: none; } }
@media (max-width: 1150px) { .session-history { display: none; } }
@media (max-width: 940px) { .session-scene { display: none; } }

.session-history {
  width: 186px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.session-history-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 4px;
}
.session-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  max-height: calc(100vh - 120px);
}
.hist-item {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #232c37;
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s;
}
.hist-item:hover { border-color: #3a4a5c; }
.hist-item.active { border-color: #4da3ff; }
.hist-item .h-title { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .h-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.hist-item .h-row { display: flex; align-items: center; gap: 4px; }
.hist-item .h-title { flex: 1; }
.hist-item .h-rename {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 11px; padding: 2px 4px; border-radius: 4px; opacity: 0;
  transition: opacity .15s;
}
.hist-item:hover .h-rename { opacity: 1; }
.hist-item .h-rename:hover { color: var(--text); background: #243244; }

/* ============================================================
 * 设置页:左类别导航 + 内容列
 * ============================================================ */
#page-settings { flex-direction: row; align-items: flex-start; }
.settings-nav {
  width: 150px;
  flex-shrink: 0;
  position: sticky;
  top: 70px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.settings-nav a {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
}
.settings-nav a:hover { color: var(--text); background: #16202b; }
.settings-nav a.active { color: var(--text); background: #1b2735; border-color: #2b3644; }
.settings-content { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (max-width: 900px) { .settings-nav { display: none; } }

/* ===== 数字人状态徽标(avatar-state 驱动器;未接 avatar 后端时完全不出现)===== */
.avatar-pill {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 2;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
  background: rgba(15, 22, 31, 0.82);
  border: 1px solid #2b3644;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.avatar-pill::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.avatar-live .avatar-pill::before { background: var(--accent); }
/* 状态氛围:说话中给舞台一圈缓慢呼吸的描边,打断给一拍红,其余静态 */
.avatar-stage.avatar-st--speaking { border-color: #2c6db5; box-shadow: 0 0 0 1px rgba(44, 109, 181, 0.35); }
.avatar-stage.avatar-st--interrupted { border-color: #a3413c; }
.avatar-stage.avatar-st--interrupted .avatar-pill::before { background: #d06862; }
.avatar-stage.avatar-st--degraded { border-color: #8a6d2f; }
.avatar-stage.avatar-st--degraded .avatar-pill::before { background: #c9a34e; }
.avatar-stage.avatar-st--closed { opacity: 0.55; }

/* 说话中的呼吸描边(替代瞬时跳变;尊重减少动效偏好) */
@keyframes avatar-breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(44, 109, 181, 0.20); }
  50% { box-shadow: 0 0 0 3px rgba(44, 109, 181, 0.45); }
}
.avatar-stage.avatar-st--speaking { animation: avatar-breathe 2.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .avatar-stage.avatar-st--speaking { animation: none; }
}
/* closed 只弱化徽标自身,不压暗仍在随播放能量起伏的声柱 */
.avatar-stage.avatar-st--closed { opacity: 1; }
.avatar-stage.avatar-st--closed .avatar-pill { opacity: 0.55; }

/* ============================================================
   前端美化(2026-09-30)——在原有深色基础上精修,不推翻
   ============================================================ */

/* ---------- 全局质感 ---------- */
:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #1a2330;
  --panel-3: #212d3d;
  --border: #243040;
  --text: #e4ecf4;
  --muted: #8296a8;
  --accent: #5db0ff;
  --accent-glow: rgba(93,176,255,0.12);
  --ok: #42d392;
  --danger: #ff6b6b;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}
body {
  background: linear-gradient(180deg, var(--bg) 0%, #0e141b 100%);
  font-family: -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.app-header {
  background: rgba(19,26,34,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand::before {
  content: "🎙";
  font-size: 16px;
  filter: saturate(1.2);
}
.app-header nav a {
  color: var(--muted);
  padding: 5px 14px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: var(--transition);
}
.app-header nav a:hover { color: var(--text); background: var(--panel-2); }
.app-header nav a.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* ---------- 用户徽章 & 退出 ---------- */
#user-badge {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--ok);
  font-weight: 500;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  transition: var(--transition);
}
#user-badge:hover { border-color: var(--ok); }
#btn-logout {
  border: 1px solid var(--border) !important;
  background: none !important;
  color: var(--muted) !important;
  font-size: 12px !important;
  padding: 3px 12px !important;
  border-radius: 6px !important;
  transition: var(--transition);
}
#btn-logout:hover { color: var(--danger) !important; border-color: var(--danger) !important; }

/* ---------- 登录页 ---------- */
#page-login:not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 46px);
  background: radial-gradient(ellipse at 50% 40%, rgba(93,176,255,0.04) 0%, transparent 60%);
}
#page-login .card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  max-width: 380px;
  width: 90vw;
}
#page-login h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--text) 40%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#page-login .form-row input {
  background: var(--panel-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  padding: 10px 14px !important;
  font-size: 14px !important;
  color: var(--text) !important;
  transition: var(--transition);
}
#page-login .form-row input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}
#page-login details summary { user-select: none; }
#page-login details input {
  background: var(--panel-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  padding: 6px 10px !important;
  font-size: 12px !important;
  color: var(--muted) !important;
}
#btn-login-submit {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #2c7ad5, #429bf0);
  border: none;
  box-shadow: 0 4px 16px rgba(66,155,240,0.25);
  transition: var(--transition);
  letter-spacing: 0.5px;
}
#btn-login-submit:hover:not(:disabled) {
  background: linear-gradient(135deg, #3685de, #4fa8f5);
  box-shadow: 0 6px 20px rgba(66,155,240,0.35);
  transform: translateY(-1px);
}
#btn-login-submit:active:not(:disabled) { transform: translateY(0); }
#login-msg { min-height: 20px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* ---------- 按钮 ---------- */
button {
  border-radius: var(--radius);
  transition: var(--transition);
  font-weight: 500;
}
button.primary {
  background: linear-gradient(135deg, #2c7ad5, #429bf0);
  border: none;
  box-shadow: 0 2px 8px rgba(66,155,240,0.2);
}
button.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #3685de, #4fa8f5);
  box-shadow: 0 4px 12px rgba(66,155,240,0.3);
}
button.danger {
  background: linear-gradient(135deg, #8b3030, #a53838);
  border: none;
}

/* ---------- 表单 ---------- */
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  transition: var(--transition);
}
.form-row input:focus,
.form-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}
.form-row input[type="checkbox"] { accent-color: var(--accent); }

/* ---------- 会话页 ---------- */
#page-session { gap: 12px; padding: 14px 18px; }
#transcript {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--panel);
}
.session-history {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.session-left { border-radius: var(--radius-lg); }

/* ---------- 控制区 ---------- */
.controls button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 16px;
}
.controls button:hover:not(:disabled) { border-color: var(--accent); }
.controls button.primary {
  background: linear-gradient(135deg, #2c7ad5, #429bf0);
  border: none;
}
.controls button.danger {
  background: linear-gradient(135deg, #8b3030, #a53838);
  border: none;
}

/* ---------- 状态行 ---------- */
.statusline {
  border-radius: 6px;
  padding: 4px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
.statusline b { color: var(--accent); }

/* ---------- 头像舞台 ---------- */
.avatar-stage {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: radial-gradient(ellipse at center, var(--panel-2) 0%, var(--panel) 100%);
}
.stage-hint { color: var(--muted); font-size: 11px; }

/* ---------- 仪表条 ---------- */
.meter { border-radius: 4px; overflow: hidden; background: var(--panel-3); }
.meter i { border-radius: 4px; }
.meter-row label { font-weight: 500; font-size: 12px; color: var(--muted); }
.meter-scale span { font-size: 10px; color: var(--muted); opacity: 0.6; }
.dot { border-radius: 50%; transition: var(--transition); }

/* ---------- 音量滑条 ---------- */
input[type="range"] {
  accent-color: var(--accent);
  border-radius: 4px;
}

/* ---------- 提示/说明 ---------- */
.hint { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }

/* ---------- 保存提示 ---------- */
.save-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--panel-3);
  border: 1px solid var(--ok);
  color: var(--ok);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
}

/* ---------- 设置页导航 ---------- */
.settings-nav {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px;
}
.settings-nav a {
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 13px;
  transition: var(--transition);
}
.settings-nav a:hover { background: var(--panel-2); }
.settings-nav a.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* ---------- 高级参数 ---------- */
.adv-group {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.3px;
  margin-top: 16px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.adv-item { padding: 4px 0; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- 选中态 ---------- */
::selection { background: var(--accent-glow); color: var(--accent); }

/* ---------- 响应式微调 ---------- */
@media (max-width: 900px) {
  .page { flex-direction: column; overflow-y: auto; }
  .app-header { flex-wrap: wrap; gap: 8px; }
}

/* ---------- 列表三态(ui-state.js:加载中/空/错误) ---------- */
.ui-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 26px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.ui-state .ui-state-text { margin: 0; }
.ui-state-hint { margin: 0; font-size: 12px; opacity: 0.85; }
.ui-state-icon { font-size: 20px; line-height: 1; opacity: 0.75; }
.ui-state-error .ui-state-text { color: var(--danger); }

/* CSS 旋转圈:底环用 --border、高亮弧用 --accent,两套主题变量下都成立 */
.ui-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border, #2b3644);
  border-top-color: var(--accent);
  animation: ui-spin 0.8s linear infinite;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* 重试按钮:沿用全局 button 的面板底色,hover 呼应 accent */
.ui-retry {
  margin-top: 4px;
  padding: 4px 16px;
  font-size: 12px;
  border: 1px solid var(--border, #2b3644);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition, 0.18s);
}
.ui-retry:hover { border-color: var(--accent); color: var(--accent); }

/* 会话 ID 条(排障):右侧顶部常显,点击复制;对应 data/logs/{id}.log */
.conv-id-bar {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted, #8a97a8);
  padding: 2px 10px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px dashed rgba(138, 151, 168, 0.25);
}
.conv-id-bar:hover { color: var(--accent, #4da3ff); }

/* LLM 视图(调试):切换字幕区为实际发给模型的 user/assistant 原始消息 */
.llm-view-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 10px 4px;
}
.llm-view-bar button {
  padding: 2px 10px;
  font-size: 11px;
  border: 1px solid var(--border, #2b3644);
  border-radius: 6px;
  background: none;
  color: var(--muted, #8a97a8);
  cursor: pointer;
}
.llm-view-bar button.on {
  color: var(--accent, #4da3ff);
  border-color: var(--accent, #4da3ff);
}
.llm-view {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
}
.llm-view .lmsg { margin: 0 0 10px; padding: 6px 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.llm-view .lmsg .lrole { font-weight: 600; margin-right: 6px; }
.llm-view .lmsg.user { background: rgba(77, 163, 255, 0.08); }
.llm-view .lmsg.output { background: rgba(120, 200, 120, 0.10); border-top: 2px solid rgba(120, 200, 120, 0.35); margin-top: 10px; }
.llm-view .lmsg.outmeta { color: #888; font-size: 12px; padding: 2px 10px 6px; }
.llm-view .lmsg.cutline { color: #e0a458; font-size: 12px; padding: 4px 10px; border-top: 1px dashed #e0a458; margin-top: 4px; }
.llm-view .lmsg.user .lrole { color: #4da3ff; }
.llm-view .lmsg.assistant { background: rgba(138, 151, 168, 0.07); }
.llm-view .lmsg.assistant .lrole { color: #81c784; }
.llm-view .lmsg.trimmed { opacity: 0.45; }
.llm-view .lmsg.trimmed .lrole::after { content: " · 已裁出上下文"; font-weight: 400; font-size: 10px; }
/* 调用卡片(2026-10-03 结构化):每次 LLM 调用一块,summary=序号+输入摘要 */
.llm-view details.lcall { margin: 0 0 10px; border: 1px solid rgba(128, 145, 165, 0.25); border-radius: 10px; overflow: hidden; }
.llm-view details.lcall > summary { cursor: pointer; padding: 7px 10px; background: rgba(128, 145, 165, 0.1); font-size: 12px; color: #9fb3c8; user-select: none; list-style: none; }
.llm-view details.lcall > summary::before { content: "▸ "; }
.llm-view details.lcall[open] > summary::before { content: "▾ "; }
.llm-view details.lcall[open] > summary { border-bottom: 1px solid rgba(128, 145, 165, 0.2); }
.llm-view details.lcall > summary:hover { background: rgba(128, 145, 165, 0.18); }
.llm-view details.lcall .lmsg { margin: 0; border-radius: 0; border-bottom: 1px dashed rgba(128, 145, 165, 0.12); }
.llm-view details.lcall .lmsg:last-child { border-bottom: none; }
.llm-view details.lmsg.fixed { padding: 0; }
.llm-view details.lmsg.fixed > summary { cursor: pointer; padding: 6px 10px; font-size: 11px; opacity: 0.75; list-style: none; }
.llm-view details.lmsg.fixed > summary::before { content: "▸ "; }
.llm-view details.lmsg.fixed[open] > summary::before { content: "▾ "; }
.llm-view details.lmsg.fixed > *:not(summary) { display: block; padding: 4px 10px; }
.llm-view .lmsg.system { background: rgba(190, 140, 255, 0.06); }
.llm-view .lmsg.system .lrole, .llm-view details.lmsg.system > summary { color: #b98aff; }

/* 服务健康圆点(头部):绿=正常 红=不可达 灰=未配置;悬停看延迟 */
.svc-dots { display: inline-flex; gap: 6px; align-items: center; font-size: 11px; }
.svc-dots .svc { display: inline-flex; align-items: center; gap: 3px; color: var(--muted, #8a97a8); cursor: default; }
.svc-dots .svc i { width: 8px; height: 8px; border-radius: 50%; background: #8a97a8; display: inline-block; }
.svc-dots .svc.ok i { background: #81c784; }
.svc-dots .svc.down i { background: #e57373; }
.svc-dots .svc.down { color: #e57373; }

/* 说话人徽章(声纹多用户,P0.5):用户气泡内的剧本身份小签 */
.bubble .spk {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  color: #ffe9b0;
  font-size: 11px;
  line-height: 18px;
  vertical-align: 1px;
}

/* 声纹门控拦截轮:灰显+划线,明确"这句没进对话"(7468fd40 反馈) */
.turn.user.turn-blocked { opacity: 0.45; }
.turn.user.turn-blocked .bubble { text-decoration: line-through; text-decoration-color: rgba(255, 107, 107, 0.55); }

/* ============================================================
 * 手机底座 + 会话页(2026-11-06)
 * 桌面继续五列;手机复用同一 DOM:对话主视图 + 三个抽屉 + 底部原控制节点。
 * 第二个条件覆盖宽度超过 900px 的手机横屏,不把触控增强和布局断点绑死。
 * ============================================================ */
@media (max-width: 900px), (max-width: 1000px) and (pointer: coarse) {
  html, body { height: 100%; height: 100dvh; }
  body { overflow: hidden; }

  /* 顶栏只保留可横向滚动的页面导航、连接态和退出,不再把导航挤成多行。 */
  .app-header {
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: 6px;
    padding: calc(5px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 5px max(8px, env(safe-area-inset-left));
  }
  .app-header .brand,
  #user-badge,
  #build-badge,
  #svc-dots { display: none; }
  .app-header nav {
    flex: 1;
    min-width: 0;
    gap: 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .app-header nav::-webkit-scrollbar { display: none; }
  .app-header nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-height: 38px;
    padding: 4px 11px;
    white-space: nowrap;
  }
  #conn-badge { flex-shrink: 0; padding: 2px 7px; white-space: nowrap; }
  #btn-logout { flex-shrink: 0; min-width: 46px; padding: 5px 8px !important; }

  .page { min-height: 0; }
  .page:not(#page-session) { overflow-y: auto; overscroll-behavior-y: contain; }
  #page-login { min-height: 0 !important; overflow-y: auto; }

  #page-session {
    position: relative;
    flex-direction: column;
    gap: 0;
    min-height: 0;
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    overflow: hidden;
  }
  .session-mobile-bar {
    order: 0;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 6px;
    min-height: 52px;
    padding: 4px 0;
  }
  .mobile-session-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    min-height: 44px;
    padding: 7px 10px;
    border-color: var(--border);
    background: var(--panel);
    white-space: nowrap;
  }
  .mobile-session-trigger[aria-expanded="true"] {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-glow);
  }
  .mobile-more-trigger { min-width: 44px; padding: 7px 12px; font-size: 22px; line-height: 1; }
  .mobile-session-character {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.25;
  }
  .mobile-session-character > span { color: var(--muted); font-size: 10px; }
  #mobile-char-name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  #page-session .session-right {
    order: 1;
    flex: 1;
    min-height: 0;
    gap: 6px;
    padding: 4px 0 8px;
  }
  #transcript { min-height: 0; padding: 10px; overscroll-behavior-y: contain; }
  .turn .bubble { max-width: 82%; font-size: 15px; }
  .turn .avatar { width: 32px; height: 32px; }
  .subtitle-current {
    flex-shrink: 0;
    min-height: 48px;
    padding: 6px 8px;
  }
  .subtitle-current .avatar { width: 32px; height: 32px; }
  .subtitle-current .bubble.live-input { max-width: 82%; }
  .llm-view-bar { min-height: 0; padding: 0 4px; }
  .llm-view { min-height: 0; padding: 8px 10px; overscroll-behavior-y: contain; }
  .conv-id-bar { flex-shrink: 0; }

  /* 底部 dock 是 flex 的固定槽位,字幕自身滚动,连接/打断/结束始终可达。 */
  .session-mobile-dock {
    order: 2;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 5px;
    margin: 0 calc(-1 * max(8px, env(safe-area-inset-right))) 0 calc(-1 * max(8px, env(safe-area-inset-left)));
    padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: rgba(19, 26, 34, 0.98);
    border-top: 1px solid var(--border);
    box-shadow: 0 -5px 18px rgba(0, 0, 0, 0.24);
    z-index: 110;
  }
  #session-mobile-dock #session-primary-controls {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
    width: 100%;
    padding: 0;
  }
  #session-mobile-dock .controls button {
    min-width: 0;
    min-height: 44px;
    padding: 7px 5px;
    font-size: 13px;
    white-space: nowrap;
  }
  #session-mobile-dock #btn-interrupt { grid-column: 1 / 3; }
  #session-mobile-dock .check {
    min-height: 40px;
    justify-content: center;
    padding: 0 5px;
    color: var(--text);
    white-space: nowrap;
  }
  #session-mobile-dock #session-statusline {
    min-height: 23px;
    padding: 1px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    line-height: 19px;
  }

  /* 遮罩与抽屉高于顶栏/dock;关闭时 visibility+inert 双重隔离焦点。 */
  .session-mobile-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgba(2, 6, 10, 0.66);
    z-index: 480;
    transition: opacity var(--transition);
  }
  .session-mobile-backdrop.mobile-open { visibility: visible; opacity: 1; }
  #page-session .session-people-panel,
  #page-session .session-scene,
  #page-session .session-left {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 500;
    visibility: hidden;
    pointer-events: none;
    margin: 0;
    border-radius: 0;
    background: var(--panel);
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition);
  }
  #page-session .session-people-panel {
    left: 0;
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    width: min(94vw, 390px);
    transform: translateX(-102%);
  }
  #page-session .session-scene,
  #page-session .session-left {
    right: 0;
    width: min(92vw, 400px);
    transform: translateX(102%);
  }
  #page-session .session-people-panel.mobile-open,
  #page-session .session-scene.mobile-open,
  #page-session .session-left.mobile-open {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
  }
  .mobile-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 12px;
    min-height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border);
    background: var(--panel);
  }
  #session-people-panel > .mobile-panel-header { grid-column: 1 / -1; }
  .mobile-panel-header strong { font-size: 15px; }
  .mobile-panel-close {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
  }

  /* 覆盖旧断点的 display:none:手机上三列全部可经入口恢复。 */
  #page-session .session-people-panel .session-roster,
  #page-session .session-people-panel .session-history {
    display: flex;
    width: auto;
    min-height: 0;
    max-height: none;
    border: 0;
    border-radius: 0;
    overflow: hidden;
  }
  #page-session .session-people-panel .session-roster { border-right: 1px solid var(--border); }
  #page-session .session-roster-list,
  #page-session .session-history-list {
    max-height: none;
    padding: 0 6px calc(10px + env(safe-area-inset-bottom));
    overscroll-behavior-y: contain;
  }
  #page-session .session-history-list { padding-right: 10px; padding-left: 10px; }
  .roster-item { min-height: 66px; }
  .hist-item { padding: 10px 8px; }
  .hist-item .h-rename { opacity: 1; min-width: 30px; min-height: 32px; }

  #page-session .session-scene { display: flex; gap: 0; overflow: hidden; }
  #page-session .session-scene > .session-history-header { display: none; }
  #page-session .session-scene-body {
    max-height: none;
    padding: 10px max(14px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) 14px;
    overscroll-behavior-y: contain;
  }
  .scene-field input, .scene-field select, .scene-save-row input { min-height: 44px; }
  .scene-btns button, .scene-save-row button, .scene-manage-row button { min-height: 40px; }

  #page-session .session-left {
    display: flex;
    gap: 12px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
  #page-session .session-left > :not(.mobile-panel-header) {
    flex-shrink: 0;
    margin-left: 14px;
    margin-right: max(14px, env(safe-area-inset-right));
  }
  #page-session .session-left .avatar-stage { height: 170px; }
  /* meter 的通用 flex:1 在竖向 meter-col 里会变成 0 高度;抽屉里给三条表固定槽高。 */
  #page-session .session-left .meter-col .meter { flex: 0 0 10px; width: 100%; height: 10px; }
  #page-session .session-left .notes { flex: none; min-height: 120px; max-height: 32dvh; }
  #page-session .session-left .controls { width: auto; }
  .char-banner-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }

  /* iOS 输入框小于 16px 会在聚焦时自动放大;只改字号,不禁用页面缩放。 */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select, textarea { font-size: 16px !important; }
  .form-row input[type="text"], .form-row input[type="number"],
  .form-row input[type="password"], .form-row select { min-width: 0; max-width: 100%; }
  .global-toasts {
    top: calc(58px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    max-width: none;
  }
  .global-toast {
    font-size: 12px;
    line-height: 1.45;
  }
  /* 桌面最多叠 4 条;手机只留最新一条,完整历史仍可在“更多→日志”查看。 */
  .global-toasts .global-toast:not(:last-child) { display: none; }
  .save-toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 360px) {
  #conn-badge { display: none; }
}

/* 矮横屏:五个原控制项排成一行,把有限高度还给字幕。 */
@media (max-width: 900px) and (max-height: 500px),
       (max-width: 1000px) and (max-height: 500px) and (pointer: coarse) {
  #session-mobile-dock #session-primary-controls {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1fr);
  }
  #session-mobile-dock #btn-interrupt { grid-column: auto; }
  #session-mobile-dock .check { min-height: 44px; font-size: 12px; }
}

/* 触控目标独立于宽度断点:触屏笔记本同样放大,不禁用双指缩放。 */
@media (pointer: coarse) {
  button { min-height: 44px; }
  .app-header nav a { min-height: 44px; }
  input[type="checkbox"] { width: 20px; height: 20px; }
  .hist-item .h-rename { opacity: 1; min-width: 36px; min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .session-mobile-backdrop,
  #page-session .session-people-panel,
  #page-session .session-scene,
  #page-session .session-left { transition: none; }
}
