/* 对坐分屏：上半屏整体旋转 180° 朝向对方；每半屏＝标题栏 / 字幕流 / 按住说话按钮 */
:root {
  --bg: #eef1f4;
  --half-me: #ffffff;
  --half-them: #f6f8fa;
  --ink: #15202b;
  --muted: #5b6774;
  --line: #d6dce3;
  --bubble: #eef1f5;
  --bubble-own: #dfe9ff;
  --accent: #1f5fd6;
  --accent-ink: #ffffff;
  --rec: #d22c3c;
  --warn-bg: #fff1dc;
  --warn-ink: #8a4b00;
  --scale: 1;
  --font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1015;
    --half-me: #121a22;
    --half-them: #0f161d;
    --ink: #e7ecf1;
    --muted: #9aa6b2;
    --line: #26313c;
    --bubble: #1b2530;
    --bubble-own: #1d3156;
    --accent: #5b8ff0;
    --accent-ink: #0b1015;
    --rec: #f2566c;
    --warn-bg: #3a2a0f;
    --warn-ink: #f4bb62;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* 组件规则（如 .overlay 的 display:grid）会覆盖浏览器对 hidden 的默认隐藏，这里强制生效 */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.stage {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
.half {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.half.me { background: var(--half-me); border-top: 2px solid var(--line); }
.half.them { background: var(--half-them); transform: rotate(180deg); }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding-block: 8px;
  border-bottom: 1px solid var(--line);
}
.who { font-weight: 700; letter-spacing: 0.02em; }
.hint { color: var(--muted); font-size: 0.85rem; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tools button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 12px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty-hint { color: var(--muted); text-align: center; margin: auto 0; font-size: 0.95rem; padding-inline: 12px; }

.item {
  max-width: 88%;
  align-self: flex-start;
  background: var(--bubble);
  border-radius: 14px;
  padding: 10px 14px;
  display: grid;
  gap: 4px;
  min-width: 0;
}
.item.own { align-self: flex-end; background: var(--bubble-own); }
.item .main {
  margin: 0;
  font-size: calc(1.3rem * var(--scale));
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.item .sub {
  margin: 0;
  font-size: calc(0.9rem * var(--scale));
  color: var(--muted);
  overflow-wrap: anywhere;
}
.item.pending .main { color: var(--muted); font-style: italic; }
.item.failed { background: var(--warn-bg); }
.item.failed .main { color: var(--warn-ink); font-size: calc(1rem * var(--scale)); }
.meta { display: flex; align-items: center; gap: 10px; font-size: 0.78rem; color: var(--muted); }
.meta button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 2px 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.dock { padding-top: 8px; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
.half.them .dock { padding-bottom: max(12px, env(safe-area-inset-top, 0px)); }
.talk {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 64px;
  border-radius: 32px;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.talk .meter {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--level, 0) * 100%);
  background: color-mix(in srgb, var(--rec) 28%, transparent);
  transition: width 80ms linear;
}
.talk .talk-label { position: relative; }
.talk.active { background: var(--rec); border-color: var(--rec); color: #fff; }
.talk.active .meter { background: rgba(255, 255, 255, 0.28); }
.talk:disabled { opacity: 0.4; cursor: not-allowed; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 440px);
  justify-content: center;
  align-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(4px);
}
.card {
  width: 100%;
  min-width: 0;
  background: var(--half-me);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  display: grid;
  gap: 12px;
}
.card h1 { margin: 0; font-size: 1.4rem; }
.card label { font-weight: 600; }
.card input, .card textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  font-size: 1.05rem;
}
.card textarea { resize: vertical; }
.card .row { display: flex; gap: 10px; justify-content: flex-end; }
.card button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.card button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card button:disabled { opacity: 0.6; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.82rem; }
.msg { margin: 0; color: var(--rec); min-height: 1.2em; font-size: 0.9rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: calc(100% - 32px);
}

@media (prefers-reduced-motion: reduce) {
  .talk .meter { transition: none; }
}
