:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --panel-2: #efeae0;
  --ink: #1c2230;
  --muted: #6b7280;
  --line: #e2ddd2;
  --src: #4b5563;
  --accent: #0f5c6e;
  --accent-soft: #dcebee;
  --accent-ink: #ffffff;
  --live: #b45309;
  --live-soft: #fbeedd;
  --danger: #b91c1c;
  --interim: #9aa3b2;
  --bubble-mine: #e3eff1;
  --shadow: 0 10px 30px rgba(28, 34, 48, 0.14);
  --sub-size: 22px;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141820;
    --panel: #1d2330;
    --panel-2: #252c3b;
    --ink: #eef0f4;
    --muted: #9aa3b2;
    --line: #2c3444;
    --src: #aab2c0;
    --accent: #5fb8cc;
    --accent-soft: #1f3a42;
    --accent-ink: #0d1a1f;
    --live: #f59e0b;
    --live-soft: #3a2a12;
    --danger: #f87171;
    --interim: #6b7280;
    --bubble-mine: #213a41;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141820; --panel: #1d2330; --panel-2: #252c3b; --ink: #eef0f4; --muted: #9aa3b2; --line: #2c3444;
  --src: #aab2c0; --accent: #5fb8cc; --accent-soft: #1f3a42; --accent-ink: #0d1a1f; --live: #f59e0b;
  --live-soft: #3a2a12; --danger: #f87171; --interim: #6b7280; --bubble-mine: #213a41;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", "Noto Sans Thai", "Leelawadee UI", "Thonburi", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---------- 顶栏 ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand img { border-radius: 8px; }
.brand-text { min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.tagline { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.ui-lang {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 6px 8px; font-size: 14px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); display: inline-flex; align-items: center; justify-content: center; flex: none;
}

/* ---------- 选项卡 ---------- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  margin: 4px 16px 8px; padding: 4px; background: var(--panel-2); border-radius: 14px;
}
.tabs button {
  border: 0; background: transparent; border-radius: 10px; padding: 8px 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 15px; font-weight: 600; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs svg { width: 18px; height: 18px; }

/* ---------- 通用 ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 16px; overscroll-behavior: contain; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; padding: 0 16px 8px; }
.field.inline select { flex: 1; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
select {
  width: 100%; font-size: 15px; padding: 9px 30px 9px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.ui-lang { width: auto; padding-right: 24px; background-position: calc(100% - 12px) 52%, calc(100% - 7px) 52%; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius); padding: 11px 16px; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary.stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { flex: 1; padding: 14px 18px; font-size: 16px; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.small svg { width: 16px; height: 16px; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

.notices { padding: 0 16px; }
.notice {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--live);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.55; margin-bottom: 8px;
  display: flex; gap: 10px; align-items: flex-start;
}
.notice.info { border-left-color: var(--accent); }
.notice p { margin: 0; flex: 1; }
.notice button { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }

/* ---------- 听译 ---------- */
.langbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: center;
  padding: 0 16px 10px;
}
.langbar .field { display: contents; }
.langbar .field-label { font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 40px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); border: 1px solid transparent;
  padding: 6px 6px 6px 12px; font-size: 14px; font-weight: 600;
}
.chip button { border: 0; background: transparent; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); font-size: 16px; line-height: 1; padding: 0; }
.chip.add { background: transparent; border: 1px dashed var(--line); color: var(--muted); padding: 6px 12px; }

.banner {
  margin: 0 16px 8px; padding: 8px 10px; border-radius: 12px; display: flex; align-items: center; gap: 8px;
  background: var(--live-soft); font-size: 14px;
}
.banner-text { flex: 1; min-width: 0; }
.banner b { letter-spacing: .08em; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); flex: none; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.empty { color: var(--muted); font-size: 15px; line-height: 1.65; padding: 20px 4px; }
.transcript { display: flex; flex-direction: column; }
.seg { padding: 12px 0; border-bottom: 1px solid var(--line); }
.seg .src { color: var(--src); font-size: 15px; line-height: 1.5; margin: 0; overflow-wrap: anywhere; }
.seg .tgt { font-size: var(--sub-size); line-height: 1.45; margin: 6px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.seg .tgt .tag {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 0 5px; margin-right: 8px; vertical-align: 0.25em; line-height: 1.5;
}
.seg .tgt.pending { color: var(--interim); font-weight: 400; font-size: 15px; }
.seg .tgt.err { color: var(--danger); font-size: 14px; font-weight: 400; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.seg .tgt.err.noretry { cursor: default; text-decoration: none; }
.hide-src .seg .src { display: none; }
.hide-src .seg .tgt:first-of-type { margin-top: 0; }
.seg.src-only .src { font-size: var(--sub-size); color: var(--ink); font-weight: 500; }
.interim { color: var(--interim); font-size: 16px; line-height: 1.5; padding: 10px 0 0; min-height: 1.5em; overflow-wrap: anywhere; }

.dock {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); background: var(--bg);
}
.engine-tag { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.engine-tag.live { color: var(--live); }
.engine-tag.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.2s infinite; flex: none; }
#view-listen .dock .engine-tag { flex: 0 1 auto; }

/* ---------- 对话 ---------- */
.talk { gap: 0; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 16px; }
.pane-b { border-bottom: 0; }
.pane-head { display: flex; align-items: center; gap: 10px; }
.pane-head .who { font-size: 13px; font-weight: 700; color: var(--muted); min-width: 2.5em; }
.pane-head select { flex: 1; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.msgs .hint { color: var(--muted); font-size: 14px; text-align: center; margin: auto 0; }
.bubble { max-width: 88%; padding: 9px 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.bubble .main { font-size: calc(var(--sub-size) - 2px); line-height: 1.4; }
.bubble .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.bubble.mine { align-self: flex-end; background: var(--bubble-mine); border-color: transparent; }
.bubble.theirs { align-self: flex-start; }
.bubble .main.pending { color: var(--interim); font-size: 15px; }
.bubble .main.err { color: var(--danger); font-size: 14px; cursor: pointer; }
.pane-interim { color: var(--interim); font-size: 15px; min-height: 0; padding: 0 2px 6px; overflow-wrap: anywhere; }
.pane-interim:empty { display: none; }
.mic {
  border: 0; border-radius: 16px; padding: 12px; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 16px; font-weight: 700;
}
.mic svg { width: 22px; height: 22px; }
.mic.on { background: var(--danger); color: #fff; }
.mic.on svg { animation: pulse 1s infinite; }
.mic:disabled { opacity: .45; }
.talk-bar {
  display: flex; gap: 8px; align-items: center; justify-content: center; padding: 6px 16px;
  border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); background: var(--panel-2);
}
.toggle {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px;
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.toggle svg { width: 16px; height: 16px; }
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.talk-bar .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
.talk-bar .icon-btn svg { width: 17px; height: 17px; }
.talk.flipped .pane-b { transform: rotate(180deg); }
.pane-a { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }

/* ---------- 房间 ---------- */
.lobby { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card h2 { font-size: 17px; margin: 0 0 6px; }
.card p { margin: 0 0 12px; color: var(--src); line-height: 1.6; font-size: 14px; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; min-width: 0; font-size: 22px; letter-spacing: .25em; text-transform: uppercase; font-weight: 700;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); text-align: center;
}
.join-row input::placeholder { letter-spacing: normal; font-weight: 400; font-size: 16px; text-transform: none; }
.card .form-err { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 0 16px 8px; }
.room-id { flex: 1; min-width: 0; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.room-id b { letter-spacing: .1em; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--interim); flex: none; }
.conn-dot.ok { background: #16a34a; }
.conn-dot.warn { background: var(--live); }

/* ---------- 弹层 ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 22, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; background: var(--panel);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--shadow);
}
@media (min-width: 640px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}
.sheet.center { text-align: center; }
.sheet h3 { margin: 0 0 6px; font-size: 18px; }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet-list { display: flex; flex-direction: column; }
.sheet-list button { border: 0; background: transparent; text-align: left; padding: 14px 4px; font-size: 16px; border-bottom: 1px solid var(--line); }
.sheet-list button.danger { color: var(--danger); }
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.lang-grid button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px; text-align: left; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.lang-grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.lang-grid button[aria-pressed="true"]::after { content: "✓"; color: var(--accent); }
.lang-grid button:disabled { opacity: .4; }
.qr { display: flex; justify-content: center; margin: 12px auto 8px; }
.qr svg { width: min(68vw, 260px); height: auto; background: #fff; padding: 10px; border-radius: 12px; stroke: none; }
.qr-code { font-size: 34px; font-weight: 800; letter-spacing: .25em; margin: 4px 0; padding-left: .25em; }
.qr-link { font-size: 13px; color: var(--muted); word-break: break-all; margin: 0 0 6px; }
.row-btns { display: flex; gap: 8px; margin-top: 12px; }
.row-btns .btn { flex: 1; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.setting.col { flex-direction: column; align-items: stretch; }
.setting input[type="range"] { flex: 1; max-width: 55%; accent-color: var(--accent); }
.seg-ctl { display: inline-flex; background: var(--panel-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-ctl.wrap { flex-wrap: wrap; }
.seg-ctl button { border: 0; background: transparent; border-radius: 8px; padding: 7px 10px; font-size: 14px; color: var(--muted); flex: 1; white-space: nowrap; }
.seg-ctl button[aria-pressed="true"] { background: var(--panel); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.about { padding: 12px 0; font-size: 14px; line-height: 1.6; color: var(--src); }
.about summary { cursor: pointer; font-weight: 600; color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

@media (min-width: 900px) {
  .talk { flex-direction: row; }
  .talk .pane { padding: 8px 16px 16px; }
  .talk-bar { flex-direction: column; border: 0; border-left: 1px dashed var(--line); border-right: 1px dashed var(--line); padding: 16px 8px; }
  .talk.flipped .pane-b { transform: none; }
  #tkFlip { display: none; }
  .talk .pane-a { order: 1; }
  .talk .talk-bar { order: 2; }
  .talk .pane-b { order: 3; }
}
@media (max-width: 380px) {
  .tagline { display: none; }
  #lsShare span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot, .engine-tag.live::before, .mic.on svg { animation: none; }
}
[dir="rtl"] { unicode-bidi: plaintext; }
