:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --panel-2: #1e2430;
  --line: #2a3140;
  --text: #eef1f6;
  --muted: #8b95a7;
  --accent: #ff4d6d;
  --accent-2: #ffb347;
  --ok: #2ecc71;
  --warn: #f5a623;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand::before { content: "●"; color: var(--accent); margin-right: 6px; }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill-live { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; animation: pulse 2s infinite; }
.pill-on { background: rgba(46,204,113,.15); border-color: var(--ok); color: var(--ok); }
.pill-wait { background: rgba(245,166,35,.15); border-color: var(--warn); color: var(--warn); }
.pill-off, .pill-ghost { color: var(--muted); }
@keyframes pulse { 50% { opacity: .75; } }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px;
  padding: 16px; height: calc(100% - 52px);
}
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; overflow: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.video-wrap {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; width: 100%; flex-shrink: 0;
}
.video-wrap video, .video-wrap canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.mirror canvas { transform: scaleX(-1); }
.preview { width: 100%; height: 100%; }
.cam-hint {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--muted); padding: 20px;
}
.rec-badge {
  position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,.6); color: #ff5252;
  font-weight: 700; padding: 4px 10px; border-radius: 8px; font-size: 13px;
}
.captions {
  position: absolute; left: 0; right: 0; bottom: 4%; display: flex; flex-direction: column;
  align-items: center; gap: 6px; padding: 0 6%; pointer-events: none;
}
.cap-line:empty { display: none; }
.cap-line {
  background: rgba(0,0,0,.68); padding: 4px 12px; border-radius: 8px; text-align: center;
  max-width: 100%; text-shadow: 0 1px 2px #000;
}
.cap-zh { font-size: 14px; color: #cfd6e4; }
.cap-en { font-size: 18px; font-weight: 600; }
.cap-en.big { font-size: clamp(16px, 2.6vw, 26px); }

/* ---------- controls ---------- */
.controls { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1 1 160px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: inherit; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled { opacity: .6; }
.slider { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.slider input { flex: 1; padding: 0; accent-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }
details.sub { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
details.sub > summary { cursor: pointer; font-weight: 600; margin-bottom: 6px; }
details.sub[open] > *:not(summary) { margin-top: 8px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3d4659; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #ff7a59); border: none; color: #fff; }
.btn-danger { background: #c0392b; border-color: #c0392b; color: #fff; }
.btn-warn { border-color: var(--warn); color: var(--warn); }
.btn-block { width: 100%; padding: 12px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.chat h2 { font-size: 15px; margin: 0; }
.messages { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 160px; }
.msg { background: var(--panel-2); border-radius: 10px; padding: 7px 10px; word-break: break-word; }
.msg-host { border-left: 3px solid var(--accent-2); }
.msg-name { color: var(--accent-2); font-weight: 600; margin-right: 6px; }
.msg-orig { margin-left: 6px; background: none; border: none; color: var(--muted); font-size: 11px; cursor: pointer; text-decoration: underline; padding: 0; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }
.transcript-title { font-size: 13px; margin: 6px 0 0; color: var(--muted); }
.transcript { margin: 0; padding: 0 0 0 18px; max-height: 26%; overflow-y: auto; font-size: 13px; }
.transcript li { margin-bottom: 6px; }
.t-zh { color: var(--muted); }

/* ---------- overlay / toasts ---------- */
/* 弹窗比屏幕高时可以滚动；margin: auto 让它在空间足够时仍然居中 */
.overlay { position: fixed; inset: 0; background: rgba(5,6,10,.85); display: flex; padding: 16px; z-index: 10; overflow-y: auto; }
.join-card { width: min(420px, 100%); margin: auto; display: flex; flex-direction: column; gap: 12px; }
.join-card h1 { margin: 0; font-size: 22px; }
.join-card p { margin: 0; }
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; width: min(92vw, 480px); }
.toast { background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: opacity .4s; }
.toast-error { border-color: #c0392b; }
.toast.out { opacity: 0; }

/* ---------- home ---------- */
.home-wrap { max-width: 880px; margin: 0 auto; padding: 12vh 16px 40px; text-align: center; }
.hero { font-size: clamp(30px, 6vw, 52px); margin: 0 0 10px; line-height: 1.15; }
.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { margin: 0 0 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; text-align: left; }
.card { padding: 24px; display: flex; flex-direction: column; gap: 6px; transition: border-color .2s, transform .2s; }
a.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h2 { margin: 4px 0 0; }
.card p { margin: 0 0 8px; }
.card-icon { font-size: 30px; }
.card .row input { flex: 1; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; padding: 10px; }
  .chat { height: 70vh; }
  .stage { overflow: visible; }
}

/* ---------- setup ---------- */
.setup-wrap { max-width: 720px; margin: 0 auto; padding: 32px 16px 60px; display: flex; flex-direction: column; gap: 16px; }
.setup-wrap h1 { margin: 0; }
.setup-wrap > p { margin: 0; }
.setup-wrap form { display: flex; flex-direction: column; gap: 16px; }
.setup-card { display: flex; flex-direction: column; gap: 12px; }
.setup-card h2 { margin: 0; font-size: 16px; }
.setup-card p { margin: 0; }
.setup-card [data-group] { display: flex; flex-direction: column; gap: 12px; }
.setup-field input[type="text"], .setup-field input[type="password"] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.setup-field .switch { color: var(--muted); }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.test-result { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; word-break: break-word; }
.field-error:empty { display: none; }
.field-error, .err-text { color: #ff6b6b; }
.ok-text { color: var(--ok); }
.link { color: var(--accent-2); text-decoration: underline; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; font-size: 0.92em; }
.home-foot { margin-top: 32px; }
