:root {
  --bg: #0f1220;
  --panel: #1a1f33;
  --panel-2: #222845;
  --ink: #e8ecf5;
  --muted: #9aa3bd;
  --primary: #4f8cff;
  --primary-ink: #fff;
  --warn: #f0a93b;
  --danger: #ff5e6c;
  --ok: #36d399;
  --line: #2c3450;
  --radius: 12px;
  --subtitle-font-size: 56px;
  --subtitle-align: center;
  --subtitle-max-lines: 4;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar h1 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* 版本标记：确认当前拿到的是不是新版代码（解决缓存导致的“改了看不到”问题） */
.build-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: var(--muted); padding: 2px 8px;
  border: 1px solid rgba(255,255,255,.08); border-radius: 999px;
  background: var(--panel-2);
}

.status-pill { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.st-idle { background: #2c3450; color: var(--muted); }
.st-listening { background: rgba(54,211,153,.18); color: var(--ok); }
.st-processing { background: rgba(79,140,255,.18); color: var(--primary); }
.st-error { background: rgba(255,94,108,.18); color: var(--danger); }

/* ---------- 布局 ---------- */
.layout {
  flex: 1; display: grid;
  grid-template-columns: 300px 1fr 340px;
  gap: 14px; padding: 14px; min-height: 0;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; overflow: auto;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.panel h3 { margin: 14px 0 8px; font-size: 13px; color: var(--muted); }

/* ---------- 控件 ---------- */
.row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.row label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.row.check label { justify-content: flex-start; gap: 8px; align-items: center; color: var(--ink); }
select, input[type="text"], input[type="number"], textarea {
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
input[type="range"] { width: 100%; accent-color: var(--primary); }
.adv { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.adv summary { cursor: pointer; font-size: 13px; color: var(--primary); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  padding: 9px 14px; border-radius: 9px; font-size: 13px; cursor: pointer;
  transition: filter .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #1a1500; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255,94,108,.4); }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.main-actions .btn { flex: 1; }

/* ---------- 麦克风电平条（聆听时显示，用于自检“声音是否进来了”）---------- */
.mic-meter-row { align-items: center; gap: 8px; }
.mic-meter-row label { white-space: nowrap; }
.mic-meter {
  flex: 1; height: 10px; border-radius: 999px; overflow: hidden;
  background: var(--panel-2); border: 1px solid rgba(255,255,255,.08);
}
.mic-meter-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #36d399 0%, #ffd166 70%, #ff5e6c 100%);
  transition: width .06s linear;
}
.mic-hint { font-size: 11px; color: var(--warn, #ffd166); min-width: 0; }
.mic-hint.ok { color: #36d399; }

.hint { font-size: 12px; color: var(--muted); background: var(--panel-2); border-radius: 8px; padding: 8px 10px; line-height: 1.5; }
.hint b { color: var(--ink); }
.hint-inline { font-size: 11px; color: var(--muted); line-height: 1.4; margin-top: 2px; }

.error-banner {
  margin: 12px 14px 0; padding: 10px 14px; border-radius: 8px;
  background: rgba(255,94,108,.14); border: 1px solid rgba(255,94,108,.4); color: #ffd2d6; font-size: 13px;
}

/* 诊断按钮 + 详细错误面板：默认隐藏在 errorBanner 下，点了展开完整堆栈与 ASR 环境信息 */
.diag-toggle {
  display: block; margin: 6px 14px 0; padding: 4px 10px; font-size: 12px;
  background: transparent; color: var(--muted); border: 1px solid var(--muted);
  border-radius: 6px; cursor: pointer; align-self: flex-start;
}
.diag-toggle:hover { color: var(--text); border-color: var(--text); }
.diag-panel {
  margin: 6px 14px 0; padding: 12px 14px; border-radius: 8px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
  color: #d8dbe8; font-size: 12px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-all; max-height: 280px; overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.diag-panel .k { color: #8ab4ff; }
.diag-panel .v { color: #d8dbe8; }
.diag-panel .err { color: #ffb4b8; }

/* ---------- 字幕主屏 ---------- */
.stage { display: flex; background: #070912; }
.subtitle-board {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  padding: 24px; overflow: hidden; position: relative;
  font-size: var(--subtitle-font-size);
  line-height: 1.35;
}
.subtitle-history { display: flex; flex-direction: column; gap: 6px; }
.subtitle-line {
  text-align: var(--subtitle-align);
  background: rgba(255,255,255,.06); border-radius: 10px; padding: 6px 14px;
  color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6);
}
.subtitle-partial {
  text-align: var(--subtitle-align); color: #b9c2dd; opacity: .85;
  min-height: 1.2em; margin-top: 8px; display: none;
}
.subtitle-partial.visible { display: block; }
.subtitle-placeholder {
  text-align: center; color: #404a6b; font-size: .5em; align-self: center; margin: auto;
}

/* ---------- 验证区 ---------- */
.metrics-form { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; display: none; }
.metrics-form.open { display: block; }
.metrics-form h3 { margin-top: 0; }
.btn-group .btn { flex: 1 1 auto; }

.report-area { margin: 10px 0; font-size: 13px; }
.report-area.open { display: block; }
.report-block { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.report-block h4 { margin: 0 0 6px; font-size: 14px; }
.report-block ul { margin: 6px 0; padding-left: 18px; line-height: 1.7; }
.decision { font-weight: 700; font-size: 16px; padding: 6px 10px; border-radius: 8px; display: inline-block; }
.decision-Go { background: rgba(54,211,153,.18); color: var(--ok); }
.decision-No-Go { background: rgba(255,94,108,.18); color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.muted { color: var(--muted); font-size: 12px; }

.session-list { display: flex; flex-direction: column; gap: 6px; }
.sess-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--panel-2); border-radius: 8px; padding: 6px 10px; font-size: 12px;
}
.tag { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag-on { background: rgba(79,140,255,.2); color: var(--primary); }
.tag-off { background: rgba(240,169,59,.2); color: var(--warn); }

/* ---------- 日志 ---------- */
.logbar { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 14px; max-height: 140px; }
.log-head { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.log { overflow-y: auto; font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.log-line { padding: 1px 0; }

/* ---------- 投屏 / 横屏模式 ---------- */
body.cast-mode { background: #000; }
body.cast-mode .topbar,
body.cast-mode .controls,
body.cast-mode .validate,
body.cast-mode .logbar,
body.cast-mode .mobile-actions { display: none; }
body.cast-mode .layout { grid-template-columns: 1fr; padding: 0; }
body.cast-mode .stage { height: 100vh; height: 100dvh; }
body.cast-mode .subtitle-board { font-size: clamp(64px, 9vw, 140px); justify-content: center; }

/* 投屏退出入口：仅投屏模式可见，桌面/手机通用 */
.cast-exit {
  position: fixed; top: 12px; right: 12px; z-index: 100;
  display: none; padding: 8px 14px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff; border: 1px solid rgba(255,255,255,.25);
  font-size: 13px; cursor: pointer; backdrop-filter: blur(6px);
}
body.cast-mode .cast-exit { display: block; }

/* ---------- 移动端底部快捷栏（默认隐藏，窄屏显示） ---------- */
.mobile-actions { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  /* 堆叠时把字幕屏放到最上面，符合“先看到字幕”的移动场景 */
  .stage { order: -1; min-height: 42vh; }
  .controls, .validate { order: 0; }
}

@media (max-width: 720px) {
  body { min-height: 100vh; min-height: 100dvh; }

  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar h1 { font-size: 16px; }
  /* 移动端用底部快捷栏的投屏按钮，顶栏的隐藏避免重复 */
  .topbar #btnCast { display: none; }

  .layout { gap: 10px; padding: 10px; }
  .stage {
    order: -1; min-height: 38vh; border-radius: var(--radius);
    border: 1px solid var(--line);
  }
  .subtitle-board { font-size: clamp(26px, 7vw, 52px); padding: 16px; }

  /* 触摸友好：加大点按目标、消除 300ms 延迟、禁选中 */
  .btn {
    min-height: 46px; font-size: 14px;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; user-select: none;
  }
  select, input[type="text"], input[type="number"], textarea {
    font-size: 16px; /* 避免 iOS 聚焦时自动放大 */
    touch-action: manipulation;
  }
  .adv summary { padding: 6px 0; }

  /* 底部常驻快捷操作栏 */
  .mobile-actions {
    display: flex; position: sticky; bottom: 0; z-index: 50;
    gap: 8px; padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: rgba(15,18,32,.96); border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  .mobile-actions .btn { flex: 1 1 0; padding: 0 6px; font-size: 14px; }

  /* 移动端隐藏调试日志，给主内容让位（关键错误仍走顶部 errorBanner） */
  .logbar { display: none; }

  /* 投屏模式在手机上：大字幕居中，退出入口由 .cast-exit 提供 */
  body.cast-mode .stage { height: 100dvh; min-height: 0; }
  body.cast-mode .subtitle-board { font-size: clamp(40px, 11vw, 96px); }
}
