:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #36c98b;
  --danger: #ff5c5c;
  --radius: 14px;
  --radius-sm: 10px;
}
* { box-sizing: border-box; }
/* 任何带 hidden 属性的元素强制不显示（移动端给 section 设 display:flex 时仍需遵守） */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #232733;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.net-stat { font-size: 12px; color: var(--muted); padding: 4px 10px; border-radius: 999px; background: var(--panel-2); }
.net-stat.ok { color: var(--accent-2); }
.net-stat.bad { color: var(--danger); }
main { padding: 16px; max-width: 920px; margin: 0 auto; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* 首页 */
h1 { font-size: 22px; margin: 8px 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; line-height: 1.6; }
.role-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 620px) { .role-cards { grid-template-columns: 1fr; } }
.role-card {
  text-align: left; background: var(--panel); border: 1px solid #262b36; border-radius: var(--radius);
  padding: 18px; cursor: pointer; color: var(--text); transition: .15s;
}
.role-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.role-ico { font-size: 30px; }
.role-title { font-weight: 700; margin: 8px 0 6px; }
.role-desc { color: var(--muted); font-size: 13px; line-height: 1.5; }
.tip { color: var(--muted); font-size: 12px; margin-top: 18px; }

/* 首页底部「中转服务器 (TURN)」设置面板 */
/* 首页底部：版本号 + 更新时间 */
.app-ver {
  margin-top: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  opacity: 0.85;
  user-select: text;
}

.turn-set { margin-top: 16px; border: 1px solid #262b36; border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.turn-set > summary {
  cursor: pointer; padding: 12px 16px; font-weight: 600; user-select: none;
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.turn-set > summary::-webkit-details-marker { display: none; }
.turn-sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.turn-body { padding: 4px 16px 16px; border-top: 1px solid #232733; }
.turn-body label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.turn-body input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid #2c3240; color: var(--text); font-size: 14px;
}
.turn-tip { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 12px 0 0; }
.turn-btns { display: flex; gap: 10px; margin-top: 14px; }
.turn-btns .btn { flex: 1; }
.turn-status { margin-top: 12px; font-size: 13px; color: var(--muted); }
.turn-status.on { color: var(--accent-2); }
.turn-status.err { color: var(--danger); }
.turn-note { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 12px 0 0; }
.turn-note code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

/* 通用控件 */
.btn {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 9px 14px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid #2c3240; font-weight: 500; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { background: var(--panel-2); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; position: relative; }
.bar-spacer { flex: 1 1 auto; }

/* 邀请框 */
.invite { background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.invite label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 8px; }
/* 折叠头：桌面端隐藏（信息常显），移动端才出现（点它展开/收起邀请信息） */
.invite-head {
  display: none; width: 100%; align-items: center; justify-content: space-between; gap: 10px;
  background: transparent; border: none; color: var(--text); padding: 2px;
  font-size: 14px; font-family: inherit; cursor: pointer; text-align: left;
}
.invite-head .invite-sum { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-head .invite-sum b { color: var(--text); }
.invite-head .invite-chev {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
  color: var(--accent); font-size: 13px; font-weight: 600;
}
.invite-head .invite-chev::after { content: '▾'; font-size: 11px; transition: transform .2s ease; }
.invite.open .invite-head .invite-chev::after { transform: rotate(180deg); }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input {
  flex: 1; background: var(--panel-2); border: 1px solid #2c3240; color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 10px; font-size: 13px; min-width: 0;
}
.pin-line { margin-top: 8px; font-size: 13px; color: var(--muted); }
.pin-line b { color: var(--text); }

/* 分享与二维码（二维码默认折叠，由「二维码」按钮开关） */
.btn.ghost.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.qr-panel { margin-top: 12px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-canvas { display: flex; align-items: center; justify-content: center; min-height: 162px; }
.qr-canvas canvas, .qr-canvas img { background: #fff; border-radius: 10px; padding: 6px; display: block; }
.qr-fallback { font-size: 12px; color: var(--muted); text-align: center; padding: 12px; line-height: 1.6; }
.qr-tip { font-size: 12px; color: var(--muted); }

/* 视频舞台 */
.stage-wrap { position: relative; width: 100%; max-width: 880px; margin: 0 auto; }
.stage-wrap:fullscreen { width: 100vw; height: 100vh; max-width: none; display: flex; flex-direction: column; background: #000; }
.stage {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  width: 100%; aspect-ratio: 16/9;
}
.stage-wrap:fullscreen .stage { aspect-ratio: auto; flex: 1; border-radius: 0; }
.main-video {
  width: 100%; height: 100%; object-fit: contain; background: #000; display: block; touch-action: none;
}
.pip-wrap { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.pip {
  position: absolute; width: 132px; height: 99px; background: #000; border-radius: 10px; overflow: hidden;
  border: 2px solid #2c3240; touch-action: none; cursor: grab; pointer-events: auto; z-index: 5;
}
.pip:active { cursor: grabbing; }
.pip video { width: 100%; height: 100%; object-fit: cover; }
.pip .pip-name { position: absolute; left: 4px; top: 4px; font-size: 11px; background: rgba(0,0,0,.5); padding: 1px 6px; border-radius: 6px; }
/* web 端 / 桌面壳共用的「占位 / 等待画面」友好浮层：对端已加入但还没出画时居中提示 */
.pip .pip-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #cdd6e4; font-size: 12px; line-height: 1.4; text-align: center; padding: 6px;
  background: rgba(0,0,0,.4); pointer-events: none; z-index: 2;
}
/* 桌面托盘壳专用：画中画状态角标（黑屏时直接写明原因，仅 CamLinkDesktop UA 下生成） */
.pip .pip-dbg {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 5px; font-size: 10px; line-height: 1.35;
  background: rgba(0,0,0,.68); color: #ffd479; text-align: center; pointer-events: none;
  white-space: normal; word-break: break-all;
}
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); color: var(--text); font-size: 14px; text-align: center; padding: 20px;
}
.overlay.hidden { display: none; }

/* 底部停靠区：控制条纵向叠放、整体居中，绝不横向溢出。
   z-index 高于聊天面板（9），这样控制条里的「音量」弹层能盖在聊天列之上；
   但低于成员 / 人数抽屉（11），抽屉展开时压住控制条。 */
.bottom-dock {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 14px; width: calc(100% - 24px); max-width: 820px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 10;
}
.bottom-dock > * { pointer-events: auto; }

/* 控制条：毛玻璃圆角面板，按功能分组、放不下自动折行（不再横向滚动 / 被裁切），无操作自动淡出 */
.ctrl-bar {
  position: static; transform: none;
  display: flex; gap: 4px 6px; flex-wrap: wrap; justify-content: center; align-items: center;
  padding: 6px; margin: 0; max-width: 100%;
  background: rgba(14,16,22,.72);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.07);
  z-index: 6; opacity: 1;
  transition: opacity .3s ease, transform .3s ease;
  overflow: visible;
}
.ctrl-bar[hidden] { display: none; }
/* 一组同类按钮：内部紧凑、折行时整组一起换行 */
.ctrl-bar .grp { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
/* 空闲淡出：整体下沉 + 透明，且不再拦截点击 */
.ctrl-bar.idle {
  opacity: 0; pointer-events: none;
  transform: translateY(16px);
}

/* ================= 汉堡折叠（控制条默认收起为一颗玻璃圆钮） =================
   收起时：控制条里只保留最前面的「菜单」按钮，其余整组按钮隐藏，
   控制条本身退化成无底无框的容器，菜单按钮单独变成一颗好看的圆形悬浮钮。 */
/* 展开态：圆形 toggle，置于最右侧（margin-left:auto 推到最右），淡雅强调色与整体协调 */
.ctrl-bar .dock-menu {
  border-radius: 999px;
  margin-left: auto;
  background: rgba(79,140,255,.14);
  border: 1px solid rgba(79,140,255,.42);
  color: #cfe0ff;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.ctrl-bar .dock-menu:hover { background: rgba(79,140,255,.24); border-color: rgba(79,140,255,.62); }
.ctrl-bar .dock-menu:active { transform: scale(.94); }
.ctrl-bar .dock-menu .lbl { display: none; }
.ctrl-bar .dock-menu .ico, .ctrl-bar .dock-menu .ico svg { width: 18px; height: 18px; }
.stage-wrap.dock-collapsed .ctrl-bar > *:not(.dock-menu) { display: none !important; }
.stage-wrap.dock-collapsed .ctrl-bar {
  width: 100%; justify-content: flex-end;
  padding: 0; gap: 0;
  background: transparent; border-color: transparent;
  box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  /* 折叠后控制条仍是「整行宽」的透明容器，且 z-index(10) 高于聊天列(9)。
     聊天列下沉贴底后会与它重叠 → 让它不拦截点击（否则聊天输入 / 发送按钮点不动），
     只保留那颗圆钮可点。 */
  pointer-events: none;
}
.stage-wrap.dock-collapsed .ctrl-bar .dock-menu { pointer-events: auto; }
.stage-wrap.dock-collapsed .dock-menu {
  width: 52px; height: 52px; padding: 0; gap: 0; justify-content: center;
  background: rgba(20,26,38,.74);
  border: 1px solid rgba(79,140,255,.45);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 10px 26px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.09);
  transition: background .18s ease, transform .12s ease, box-shadow .18s ease, border-color .18s ease;
}
.stage-wrap.dock-collapsed .dock-menu:hover { background: rgba(34,42,56,.85); border-color: rgba(79,140,255,.7); }
.stage-wrap.dock-collapsed .dock-menu:active { transform: scale(.92); }
.stage-wrap.dock-collapsed .dock-menu .ico,
.stage-wrap.dock-collapsed .dock-menu .ico svg { width: 22px; height: 22px; }
/* 展开动画：控制条自下而上滑入 */
.stage-wrap:not(.dock-collapsed) .ctrl-bar { animation: dock-in .2s ease both; }
@keyframes dock-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* 画面内音量 / 静音（右上角悬浮） */
.stage-audio {
  position: absolute; top: 10px; right: 10px; z-index: 9;
  display: flex; align-items: center; gap: 6px;
}
.sa-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; border-radius: 999px; cursor: pointer;
  background: rgba(14,16,22,.6); color: #fff;
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .15s, color .15s, border-color .15s;
}
.sa-btn:hover { background: rgba(255,255,255,.16); }
.sa-btn .ico, .sa-btn .ico svg { width: 18px; height: 18px; }
.sa-btn.off { color: #ff9b9b; background: rgba(255,92,92,.22); border-color: rgba(255,92,92,.42); }

/* 聊天输入行（悬浮聊天列内）：表情按钮 + 输入框 + 发送 */
.chat-row { display: flex; gap: 8px; width: 100%; max-width: 620px; align-items: center; }
.chat-row input {
  flex: 1 1 auto; min-width: 0; padding: 9px 14px; border-radius: 999px;
  background: rgba(14,16,22,.72); color: #fff; font-size: 14px;
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chat-row input::placeholder { color: rgba(255,255,255,.55); }
.chat-row .btn { flex: 0 0 auto; border-radius: 999px; padding: 9px 16px; }
/* 表情按钮：圆形，和输入框同高；展开时高亮 */
.emoji-btn {
  flex: 0 0 auto; width: 38px; height: 38px; padding: 0; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(14,16,22,.6); color: #fff;
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.emoji-btn:hover { background: rgba(255,255,255,.16); }
.emoji-btn:active { transform: scale(.92); }
.emoji-btn.on { background: var(--accent); border-color: var(--accent); }
.emoji-btn .ico, .emoji-btn .ico svg { width: 20px; height: 20px; }

/* 控制条内的按钮：胶囊样式，悬停微亮，按下回弹 */
.ctrl-bar .btn, .ctrl-bar select.sel {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  padding: 8px 12px; border-radius: 999px;
  background: transparent; border: 1px solid transparent; color: var(--text);
  font-size: 13.5px; font-weight: 500; line-height: 1;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.ctrl-bar .btn:hover, .ctrl-bar select.sel:hover { background: rgba(255,255,255,.10); }
.ctrl-bar .btn:active { transform: scale(.94); }
.ctrl-bar .btn.off { color: #ff9b9b; background: rgba(255,92,92,.12); }
.ctrl-bar .btn.danger { background: rgba(255,92,92,.14); border-color: rgba(255,92,92,.32); color: #ffb3b3; }
.ctrl-bar .btn.danger:hover { background: rgba(255,92,92,.26); border-color: rgba(255,92,92,.5); }
/* 分隔线 + 缩放读数 */
.ctrl-bar .sep { flex: 0 0 auto; width: 1px; height: 18px; margin: 0 4px; background: rgba(255,255,255,.12); }
.ctrl-bar .zval {
  flex: 0 0 auto; min-width: 44px; text-align: center;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
/* 线条图标（控制条 / 邀请按钮通用；注意不能只在 .ctrl-bar 下定义，
   否则邀请卡里的「二维码」按钮图标会按 SVG 默认尺寸 300x150 撑爆按钮） */
.ico { display: inline-flex; flex: 0 0 auto; width: 18px; height: 18px; }
.ico svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
/* 清晰度下拉 */
.ctrl-bar select.sel {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 13px;
}
.ctrl-bar select.sel option { background: #1f232c; color: var(--text); }

/* 窄屏：按钮只留图标，按分组自动折行 */
@media (max-width: 640px) {
  .bottom-dock { width: calc(100% - 12px); max-width: none; gap: 6px; }
  .ctrl-bar {
    gap: 2px 4px; padding: 5px; border-radius: 18px;
    max-width: 100%; flex-wrap: wrap; justify-content: center;
  }
  .ctrl-bar .lbl { display: none; }
  .ctrl-bar .sep { display: none; }
  .ctrl-bar .btn, .ctrl-bar select.sel { padding: 9px 10px; }
  .ctrl-bar select.sel { padding-right: 24px; background-size: 12px; }
  .ctrl-bar .zval { min-width: 34px; font-size: 11px; }
}
.members-line { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }

/* 抖音直播间风格：点画面空白处进入「沉浸模式」，隐藏全部 UI 仅留视频；再点恢复。
   注：控制条 / 聊天 / 成员 / 人数面板是 #stage 的兄弟节点（位于 .stage-wrap 内），
   故把 immersive 类挂在 .stage-wrap 上，用 .stage-wrap.immersive 选中它们。 */
.stage-wrap.immersive .bottom-dock,
.stage-wrap.immersive .chat-panel,
.stage-wrap.immersive .member-panel,
.stage-wrap.immersive .limit-panel,
.stage-wrap.immersive .stage-audio,
.stage-wrap.immersive .main-name,
.stage-wrap.immersive .tap-hint { display: none !important; }

/* 轻点提示：进入视频后短暂浮现，提示「点画面可隐藏界面」 */
.tap-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  z-index: 7; pointer-events: none; white-space: nowrap;
  background: rgba(0,0,0,.42); color: #fff; font-size: 12px; letter-spacing: .02em;
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .45s ease;
}
.tap-hint.show { opacity: 1; }

/* 底部面板：聊天（直播间悬浮气泡列）/ 成员（底部抽屉）/ 人数（底部抽屉），半透明毛玻璃，可滚动可隐藏 */
.chat-panel, .member-panel, .limit-panel {
  position: absolute; z-index: 9;
  display: flex; flex-direction: column;
}
/* 成员 / 人数抽屉要压住底部控制条，故层级高于 .bottom-dock(10) */
.member-panel, .limit-panel { z-index: 11; }
/* 聊天面板：抖音直播间风格 —— 悬浮在画面左下角的半透明竖向气泡列，
   透明度压到很低，让底层视频「隐约可见」；无滚动条，新消息从底部淡入 */
.chat-panel {
  left: 10px; right: auto; bottom: 76px;
  width: min(72%, 340px); max-height: 52%;
  background: linear-gradient(to top, rgba(4,6,10,.30), rgba(4,6,10,.03));
  border: 1px solid rgba(255,255,255,.05); border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,.14);
  backdrop-filter: blur(2px) saturate(118%); -webkit-backdrop-filter: blur(2px) saturate(118%);
  overflow: hidden;
  transition: max-height .18s ease, bottom .22s ease;
}
/* 控制条折叠态：聊天列下沉贴到底部（折叠后控制条只剩右侧一颗小圆钮，与左下聊天列不重叠）。
   JS 的 layoutChat 会再按底部安全区精确同步该值。 */
.stage-wrap.dock-collapsed .chat-panel { bottom: 12px; }
.member-panel {
  left: 8px; right: 8px; bottom: 0; max-height: 66%;
  background: rgba(10,14,22,.86);
  border: 1px solid rgba(255,255,255,.1); border-bottom: none;
  border-radius: 16px 16px 0 0;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
}
.limit-panel {
  left: 8px; right: 8px; bottom: 0; padding: 14px; gap: 10px;
  background: rgba(10,14,22,.9);
  border: 1px solid rgba(255,255,255,.1); border-bottom: none;
  border-radius: 16px 16px 0 0;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
}
.limit-panel label { font-size: 13px; color: var(--muted); }
.limit-panel input {
  width: 100%; padding: 9px 12px; border-radius: 10px; background: var(--bg);
  border: 1px solid #2c3240; color: var(--text); font-size: 15px;
}
.limit-panel .btn { width: 100%; }
/* 成员 / 人数面板标题（聊天面板不用标题，见下） */
.member-panel .chat-head, .limit-panel .chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--text);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
/* 聊天面板：无标题，仅右上角一个淡淡的关闭 × */
.chat-panel .chat-head {
  position: absolute; top: 2px; right: 4px; z-index: 2;
  padding: 0; border: none; background: transparent;
}
.chat-panel .chat-head span:not(.chat-close) { display: none; }
.chat-close {
  background: transparent; border: none; color: rgba(255,255,255,.62); font-size: 20px; line-height: 1;
  cursor: pointer; padding: 2px 7px; border-radius: 999px;
}
.chat-close:hover { color: #fff; background: rgba(255,255,255,.12); }
.chat-log {
  flex: 1 1 auto; overflow-y: auto; padding: 12px 10px 4px;
  display: flex; flex-direction: column; gap: 5px; min-height: 0;
  /* 顶部渐隐：越旧的消息越淡，营造直播间滚动感 */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px);
  /* 去掉丑陋的默认滚动条：无条、仍可滚动（滚轮 / 触摸 / 上下翻） */
  scrollbar-width: none; -ms-overflow-style: none;
}
.chat-log::-webkit-scrollbar { width: 0; height: 0; display: none; }
.chat-msg {
  display: flex; align-items: baseline;
  font-size: 13px; line-height: 1.5; color: #fff; word-break: break-word;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
  animation: chat-in .18s ease both;
}
.chat-msg .chat-name { color: #ffd479; font-weight: 600; margin-right: 4px; flex: 0 0 auto; }
/* 正文占满剩余空间 */
.chat-msg .chat-text { flex: 1 1 auto; min-width: 0; }
.chat-msg.mine { text-align: left; }
.chat-msg.mine .chat-name { color: #8fd0ff; }
.chat-msg.mine .chat-text { background: none; padding: 0; border-radius: 0; }
/* 发送时间（HH:MM）：固定在每条消息**最左侧**，等宽对齐成一列 */
.chat-msg .chat-time {
  color: rgba(255,255,255,.5); font-size: 11px; font-weight: 400;
  margin-right: 8px; flex: 0 0 auto; white-space: nowrap;
  min-width: 32px; font-variant-numeric: tabular-nums;
}
/* 系统提示（进入 / 离开房间）：灰色小字，整体**靠左**，时间同样在最左 */
.chat-msg.system { color: rgba(255,255,255,.62); font-size: 12px; }
.chat-msg.system .chat-text { text-align: left; color: rgba(255,255,255,.62); }
@keyframes chat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chat-panel .chat-row { padding: 6px 8px 8px; }
.chat-panel .chat-row input { background: rgba(0,0,0,.34); }
/* 表情面板：聊天输入框上方的九宫格表情，半透明、细滚动条 */
.emoji-panel {
  flex: 0 1 auto;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 6px 6px 4px; height: 118px; overflow-y: auto;
  border-top: 1px solid rgba(255,255,255,.07);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent;
}
.emoji-panel::-webkit-scrollbar { width: 5px; }
.emoji-panel::-webkit-scrollbar-track { background: transparent; }
.emoji-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 999px; }
.emoji-panel button {
  background: transparent; border: none; cursor: pointer; padding: 0;
  height: 30px; border-radius: 8px; font-size: 19px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, transform .1s;
}
.emoji-panel button:hover { background: rgba(255,255,255,.15); }
.emoji-panel button:active { transform: scale(.88); }
/* 成员列表：细滚动条（浅色半透明，不再突兀） */
.member-list { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent; }
.member-list::-webkit-scrollbar { width: 6px; }
.member-list::-webkit-scrollbar-track { background: transparent; }
.member-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 999px; }
.member-list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.34); }
.member-list { flex: 1 1 auto; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border-radius: 10px; }
.member-item .m-info { flex: 1 1 auto; min-width: 0; }
.member-item .m-name { font-size: 13px; color: var(--text); }
.member-item .m-dev { font-size: 11px; color: var(--muted); margin-top: 1px; }
.member-item .m-kick { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; }
.member-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 12px; }

/* 主画面姓名牌：左上角，标明当前是谁的画（房主 / 连线N / 监控 / 昵称 + 设备） */
.main-name {
  position: absolute; left: 10px; top: 10px; z-index: 3; pointer-events: none;
  background: rgba(0,0,0,.5); color: #fff; padding: 4px 10px; border-radius: 8px;
  font-size: 13px; line-height: 1.3; max-width: 70%;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.main-name .dev { display: block; font-size: 11px; color: rgba(255,255,255,.72); margin-top: 1px; }

/* 音量 / 背景弹层：挂在底部控制条里，点按钮后从控制条正上方弹出。
   ⚠️ .bg-panel 必须和 .vol-panel 共用这套「脱离文档流 + 绝对定位」的规则——
   否则它会作为 .grp 里的普通块级元素留在流里，把控制条撑成超宽超高的畸形布局。 */
.vol-panel, .bg-panel {
  position: absolute; left: 50%; bottom: calc(100% + 10px);
  top: auto; right: auto; transform: translateX(-50%);
  z-index: 12;
  background: rgba(16,19,26,.92);
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.07);
  backdrop-filter: blur(16px) saturate(150%); -webkit-backdrop-filter: blur(16px) saturate(150%);
  display: flex; flex-direction: column; gap: 10px; min-width: 238px; max-width: 86vw;
  animation: vol-pop .16s ease both;
}
@keyframes vol-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(.98); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.vol-row { display: flex; align-items: center; gap: 8px; }
.vol-row .ico { flex: 0 0 auto; }
.vol-row-label { font-size: 13px; color: var(--muted); flex: 0 0 auto; min-width: 44px; }
.vol-row .rng { flex: 1 1 auto; min-width: 84px; height: 4px; accent-color: var(--accent); cursor: pointer; }
.vol-row .volpct { font-size: 12px; color: var(--text); min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
#hostVolBtn .ico, #viewerVolBtn .ico { width: 17px; height: 17px; }
#hostVolBtn .ico svg, #viewerVolBtn .ico svg { width: 17px; height: 17px; }

/* 摄像头关闭时的背景设置面板（复用 .vol-panel 弹层定位，见上方共用规则） */
.bg-panel { min-width: 272px; max-width: min(86vw, 340px); gap: 8px; }
.bg-label { font-size: 12px; color: var(--muted); margin: 0 0 -2px; }
.bg-panel input[type=text] {
  width: 100%; box-sizing: border-box; padding: 7px 9px; border-radius: 8px; border: 1px solid #2c3240;
  background: var(--bg); color: var(--text); font-size: 13px;
}
.bg-img-row { display: flex; gap: 6px; align-items: center; }
.bg-img-row input[type=file] {
  flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--muted);
  padding: 6px 8px; border-radius: 8px; border: 1px dashed #2c3240; background: rgba(255,255,255,.03);
}
.bg-img-row .btn { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }
.bg-tip { font-size: 11px; color: var(--muted); line-height: 1.4; }

/* 美颜面板（复用 .vol-panel 弹层定位）：开关 + 磨皮 / 美白 / 红润 / 锐化 / 滤镜 + 恢复默认 */
.beauty-panel { min-width: 244px; max-width: min(86vw, 300px); gap: 8px; }
.beauty-row { display: flex; align-items: center; gap: 8px; }
.beauty-row label { font-size: 13px; color: var(--muted); flex: 0 0 auto; min-width: 40px; }
.beauty-row .rng { flex: 1 1 auto; min-width: 88px; height: 4px; accent-color: var(--accent); cursor: pointer; }
.beauty-sel { flex: 1 1 auto; min-width: 0; padding: 6px 8px; border-radius: 8px; border: 1px solid #2c3240; background: var(--bg); color: var(--text); font-size: 13px; }
.beauty-switch { justify-content: space-between; padding-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 2px; }
.beauty-title { font-size: 13px; font-weight: 600; color: #fff; }
/* 一键档位：自然 / 明显 / 强力 */
.beauty-presets { display: flex; gap: 6px; }
.beauty-preset { flex: 1 1 0; padding: 5px 0; font-size: 12px; text-align: center; border-radius: 8px; }
.beauty-preset.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.beauty-reset-row { justify-content: flex-end; }
.beauty-reset-row .btn { padding: 5px 12px; font-size: 12px; }
.beauty-tip { font-size: 11px; color: var(--muted); line-height: 1.4; }
/* iOS 风格滑动开关 */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw { position: absolute; inset: 0; cursor: pointer; background: #3a4150; border-radius: 999px; transition: background .18s; }
.slider-sw:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.switch input:checked + .slider-sw { background: var(--accent); }
.switch input:checked + .slider-sw:before { transform: translateX(18px); }
/* 美颜按钮图标尺寸对齐音量按钮；开启时高亮 */
#hostBeautyBtn .ico, #viewerBeautyBtn .ico { width: 17px; height: 17px; }
#hostBeautyBtn .ico svg, #viewerBeautyBtn .ico svg { width: 17px; height: 17px; }
.btn.beauty-on { color: var(--accent); }

/* 录制中指示（红点 + 计时）：浮在画面左上，仅录制时显示 */
.rec-badge {
  position: absolute; top: 14px; left: 14px; z-index: 12;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 9px; border-radius: 999px;
  background: rgba(8,10,14,.66); border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(14px) saturate(150%); -webkit-backdrop-filter: blur(14px) saturate(150%);
  color: #fff; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
}
.rec-badge .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ff4d4f; box-shadow: 0 0 8px rgba(255,77,79,.9); animation: rec-blink 1s steps(1) infinite; }
@keyframes rec-blink { 50% { opacity: .25; } }
/* 录制面板（复用弹层定位）：格式 / 质量选择 + 开始 / 停止 / 保存 */
.rec-panel { min-width: 268px; align-items: stretch; }
.rec-h { font-size: 13px; font-weight: 600; color: #fff; margin: 0 0 4px; }
.rec-row { display: flex; align-items: center; gap: 10px; }
.rec-row label { font-size: 12px; color: var(--muted); width: 32px; flex: 0 0 auto; }
.rec-sel {
  flex: 1 1 auto; min-width: 0; padding: 7px 9px; border-radius: 8px;
  border: 1px solid #2c3240; background: var(--bg); color: var(--text); font-size: 13px;
}
.rec-tip { font-size: 11px; color: var(--muted); line-height: 1.4; margin: 2px 0 4px; }
.rec-actions { display: flex; gap: 8px; margin-top: 6px; }
.rec-actions .btn { flex: 1 1 auto; justify-content: center; }
.rec-done { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.rec-preview { width: 100%; max-height: 180px; border-radius: 10px; background: #000; border: 1px solid rgba(255,255,255,.12); }
.rec-done .btn { text-align: center; justify-content: center; }
.rec-warn { font-size: 11.5px; color: #ffb4b4; line-height: 1.4; margin-top: 6px; }

/* 加入框 */
.join-box { background: var(--panel); border-radius: var(--radius); padding: 16px; max-width: 480px; margin: 10px auto; }
.join-box p { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.join-box label { font-size: 13px; color: var(--muted); display: block; margin: 0 0 5px 2px; }
.join-box input {
  width: 100%; background: var(--panel-2); border: 1px solid #2c3240; color: var(--text);
  border-radius: var(--radius-sm); padding: 10px; font-size: 14px; margin-bottom: 10px;
}
.join-box .btn { width: 100%; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2a2f3a; color: var(--text); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

/* =====================================================================
   移动端 / 横竖屏：让视频充满屏幕、控件更顺手
   思路：body 变纵向 flex，顶栏固定高度，main 占满剩余高度；
   视频视图里 stage-wrap 用 flex:1 撑满，视频 object-fit:contain 自适应，
   竖屏满宽、横屏满高，两种方向都不溢出、不裁切。
   ===================================================================== */
@media (max-width: 768px), (max-height: 480px) {
  html, body { height: 100dvh; }
  body { display: flex; flex-direction: column; overflow: hidden; }
  .topbar { flex: 0 0 auto; padding: 8px 14px; }
  .brand { font-size: 16px; }
  .net-stat { font-size: 11px; padding: 3px 9px; }
  main { flex: 1 1 auto; min-height: 0; max-width: 100%; margin: 0; padding: 0; overflow: hidden; }
  /* 顶栏与 main 同为 body 的 flex 子项，确保横向铺满（避免 margin:auto 在 flex 下收缩） */
  .topbar { width: 100%; box-sizing: border-box; }

  /* 首页 / 监控设置：在 main 内滚动，不挤压内容 */
  #home, #hostSetup { height: 100%; overflow-y: auto; padding: 18px 16px 32px; }
  h1 { font-size: 21px; }
  .sub { margin-bottom: 16px; }

  /* 监控端 / 观看端：纵向 flex，视频区 flex:1 撑满剩余高度（横竖屏通用） */
  #hostView, #viewerView {
    display: flex; flex-direction: column;
    height: 100%; padding: 0; overflow-y: auto;
  }
  #hostView .bar, #viewerView .bar {
    flex: 0 0 auto; margin: 0; padding: 8px 10px 6px;
    background: linear-gradient(to bottom, rgba(15,17,21,.96), rgba(15,17,21,0));
    position: relative; z-index: 7;
  }
  #hostView .bar .btn.ghost, #viewerView .bar .btn.ghost { padding: 6px 12px; font-size: 13px; }

  /* 监控端邀请信息：手机上默认折叠成一行（房间号+密码），点一下才展开，把高度让给视频 */
  #hostView .invite {
    flex: 0 0 auto; margin: 8px; padding: 10px 12px;
    max-height: 46vh; overflow-y: auto;
  }
  #hostView .invite-head { display: flex; }
  #hostView .invite-body { display: none; margin-top: 10px; }
  #hostView .invite.open { max-height: 60vh; }
  #hostView .invite.open .invite-body { display: block; }
  /* 邀请操作行：窄屏允许换行，输入框独占一行，两个按钮平分一行 */
  #hostView .copy-row { flex-wrap: wrap; }
  #hostView .copy-row input { flex: 1 1 100%; }
  #hostView .copy-row .btn {
    flex: 1 1 0; min-width: 0; padding: 12px 12px;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  }
  #hostView .invite label { font-size: 12px; }
  #hostView .qr-canvas { min-height: 0; }
  #hostView .qr-canvas canvas, #hostView .qr-canvas img { width: 168px; height: 168px; }

  /* 加入卡片：在可用空间内垂直居中，输入框更大更好点 */
  #viewerView #joinBox {
    flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center;
    max-width: 460px; margin: 0 auto; width: 100%; padding: 20px;
  }
  #viewerView #joinBox input { padding: 14px; font-size: 16px; margin-bottom: 14px; border-radius: 12px; }
  #viewerView #joinBox .btn { padding: 15px; font-size: 16px; border-radius: 12px; }
  #viewerView #joinBox label { font-size: 13px; }

  /* 视频舞台：撑满剩余空间；视频 contain 自适应（竖屏满宽、横屏满高） */
  .stage-wrap { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; margin: 0; }
  .stage { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 10px; }
  .main-video { object-fit: contain; }

  /* 控制条：底部停靠、图标优先、按分组自动折行（不再被裁切）；自动隐藏 */
  .bottom-dock {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: calc(100% - 12px); max-width: none; gap: 6px;
  }
  .member-panel, .limit-panel { bottom: 0; }
  .chat-panel {
    left: 8px; width: min(74%, 340px);
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    max-height: 50%;
  }
  .emoji-panel { grid-template-columns: repeat(7, 1fr); height: 128px; }
  .ctrl-bar {
    gap: 2px 4px; padding: 5px; border-radius: 18px;
    max-width: 100%; flex-wrap: wrap; justify-content: center;
  }
  .ctrl-bar .lbl { display: none; }
  .ctrl-bar .sep { display: none; }
  .ctrl-bar .btn, .ctrl-bar select.sel { padding: 9px 12px; }
  .ctrl-bar .ico { width: 20px; height: 20px; }
  .ctrl-bar .ico svg { width: 20px; height: 20px; }
  .ctrl-bar select.sel { padding-right: 26px; }

  /* 画中画缩小，避免遮挡主画面 */
  .pip { width: 104px; height: 78px; border-radius: 9px; border-width: 2px; }
  .pip .pip-name { font-size: 10px; padding: 1px 5px; }

  /* 横屏（landscape）微调：顶栏更紧凑、控制条贴底、邀请区给更多高度 */
  @media (orientation: landscape) {
    #hostView .invite { max-height: 50vh; }
    #hostView .invite.open { max-height: 70vh; }
    #hostView .bar, #viewerView .bar { padding: 6px 10px 4px; }
    .stage { border-radius: 8px; }
    .bottom-dock { bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  }
}
