/* Gracs v2 — 影院式深色主题 + 响应式（桌面 / 平板 / 手机观看优化） */
:root {
  --bg: #0a0c13;
  --bg-2: #10131d;
  --bg-3: #161a27;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f8;
  --dim: #97a0b8;
  --accent: #4dd4c8;
  --accent-2: #8b7cf6;
  --ok: #38d39f;
  --warn: #f0b429;
  --bad: #f4645f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 80% -10%, #1a1f36 0%, transparent 55%),
              radial-gradient(900px 600px at -10% 110%, #16243a 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#app { height: 100%; }
.screen { height: 100%; display: flex; flex-direction: column; }
/* 移动端浏览器地址栏伸缩：用 dvh 动态视口高度，避免底部被裁掉 */
@supports (height: 100dvh) {
  html, body, #app { height: 100dvh; }
}
.dim { color: var(--dim); }
.spacer { flex: 1; }
.hint { color: var(--dim); font-size: 12px; margin: 6px 0 0; }
.error { color: var(--bad); font-size: 13px; margin: 8px 0 0; }
.banner { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.banner.warn { background: rgba(240, 180, 41, 0.12); border: 1px solid rgba(240, 180, 41, 0.35); color: #ffd884; }
.hidden, [hidden] { display: none !important; }

/* ── 按钮 / 表单 ── */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-strong); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #35c9bd, #6f7bf7);
  border: none;
  color: #05121a;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 12px 20px; font-size: 15px; border-radius: 12px; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.danger { color: #ffb4b1; }
.btn.sharing { background: linear-gradient(135deg, #f4645f, #e0526f); color: #fff; }

.field { margin: 12px 0; }
.field > label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(9, 11, 18, 0.75);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77, 212, 200, 0.13); }
select { cursor: pointer; }
.check { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; white-space: nowrap; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
input[type="range"] { accent-color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--panel-strong);
  color: var(--dim); font-size: 11px;
}

/* ── 进入页 ── */
.lobby { align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.lobby-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.lobby-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.logo-mark {
  width: 52px; height: 52px; border-radius: 15px;
  display: grid; place-items: center; font-size: 26px;
  background: linear-gradient(135deg, rgba(77, 212, 200, 0.18), rgba(139, 124, 246, 0.22));
  border: 1px solid var(--border);
}
.lobby-brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.tagline { margin: 2px 0 0; color: var(--dim); font-size: 12px; }
.lobby-server {
  font-size: 12px; color: var(--dim);
  background: rgba(9, 11, 18, 0.55); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; margin-bottom: 10px;
  word-break: break-all;
}
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
/* 云房间卡片占满一行（三卡布局；不支持 :has 的旧浏览器自动回落为普通卡片） */
.mode-cards .mode-card:has(#mode-cloud) { grid-column: 1 / -1; }
.mode-card {
  position: relative; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 12px 12px 40px;
  background: var(--panel);
  display: flex; flex-direction: column; gap: 2px;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card input { position: absolute; left: 12px; top: 14px; accent-color: var(--accent); }
.mode-card:has(input:checked) { border-color: var(--accent); background: rgba(77, 212, 200, 0.08); }
.mode-icon { font-size: 18px; }
.mode-title { font-weight: 600; }
.mode-desc { font-size: 11px; color: var(--dim); }
.lobby-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: center; flex-wrap: wrap; }

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 19, 0.72);
  backdrop-filter: blur(10px);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.logo-dot {
  width: 10px; height: 10px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.conn-status { font-size: 12px; color: var(--ok); }
.conn-status.bad { color: var(--bad); }
.room-info { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 下拉菜单 */
.dropdown-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 190px; padding: 6px;
  background: #171b29; border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 50;
}
.dropdown button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 9px 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.dropdown button:hover { background: var(--panel-strong); }

/* ── 房间布局 ── */
.room-main { flex: 1; display: grid; grid-template-columns: 250px minmax(0, 1fr) auto; min-height: 0; }
.sidebar {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(10, 12, 19, 0.4);
}
.sidebar-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-size: 13px; color: var(--dim); }
.member-list { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; }
.member-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 10px; margin-bottom: 4px;
  cursor: pointer; transition: background 0.15s;
}
.member-item:hover { background: var(--panel); }
.member-item.me { background: rgba(77, 212, 200, 0.07); }
.member-avatar {
  width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  background: linear-gradient(135deg, rgba(77, 212, 200, 0.25), rgba(139, 124, 246, 0.3));
  flex: none;
}
.member-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 6px;
  background: var(--panel-strong); color: var(--dim); white-space: nowrap;
}
.badge.live { background: rgba(56, 211, 159, 0.16); color: var(--ok); }
.badge.cinema { background: rgba(139, 124, 246, 0.2); color: #c3b8ff; }
.sidebar-foot { padding: 10px; display: grid; gap: 8px; border-top: 1px solid var(--border); }

/* ── 舞台 ── */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; gap: 10px; }
.stage-main { flex: 1; min-height: 0; position: relative; }
.stage-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 2px; min-height: 0; }
.stage-strip:empty { display: none; }

.tile {
  position: relative; overflow: hidden;
  background: #05070c; border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.tile.main { width: 100%; height: 100%; }
.stage-strip .tile { flex: none; width: 190px; height: 107px; cursor: pointer; }
.tile video, .tile canvas { width: 100%; height: 100%; object-fit: contain; display: block; background: #05070c; }
.tile.audio-only { background: linear-gradient(135deg, #101425, #0b0e18); }

.tile-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.62), transparent);
  font-size: 12px; pointer-events: none;
}
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-badge {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  background: rgba(0, 0, 0, 0.55); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; font-size: 11px; color: var(--dim);
  white-space: nowrap;
}
.tile-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.tile-badge.good .dot { background: var(--ok); }
.tile-badge.fair .dot { background: var(--warn); }
.tile-badge.poor .dot { background: var(--bad); }

.tile-tools {
  position: absolute; bottom: 8px; left: 8px; right: 8px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  opacity: 0; transition: opacity 0.18s;
}
.tile:hover .tile-tools, .tile.pinned .tile-tools { opacity: 1; }
.tile-tools .icon-btn, .tile-tools select {
  background: rgba(8, 10, 16, 0.78); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; padding: 5px 8px; border-radius: 8px; cursor: pointer;
  backdrop-filter: blur(6px);
}
.icon-btn { background: rgba(8, 10, 16, 0.78); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 5px 9px; cursor: pointer; font-size: 12px; }
.tile-volume { display: flex; align-items: center; gap: 6px; background: rgba(8, 10, 16, 0.78); border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; }
.tile-volume input { width: 74px; }
.tile-empty {
  display: grid; place-items: center; text-align: center; gap: 6px;
  width: 100%; height: 100%; color: var(--dim);
}
.tile-empty .big-icon { font-size: 44px; opacity: 0.8; }
.tile-empty .title { font-size: 16px; color: var(--text); }

/* ── 统计面板 ── */
.stats-panel {
  width: 330px; border-left: 1px solid var(--border);
  background: rgba(10, 12, 19, 0.55); display: flex; flex-direction: column; min-height: 0;
}
.stats-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.stats-body { overflow: auto; padding: 10px 12px; display: grid; gap: 10px; }
.stat-card { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--panel); }
.stat-card h4 { margin: 0 0 6px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat-rows { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12px; color: var(--dim); }
.stat-rows b { color: var(--text); font-weight: 600; }
.spark { width: 100%; height: 34px; margin-top: 8px; }

/* ── 底栏 ── */
.bottombar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: rgba(10, 12, 19, 0.8);
  backdrop-filter: blur(10px);
}
.share-btn { min-width: 150px; }
.ctl-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctl { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; white-space: nowrap; }
.ctl select { width: auto; padding: 6px 8px; font-size: 12px; }
.share-status { font-size: 12px; color: var(--accent); }
.uplink-info { font-size: 12px; }

/* ── 弹窗 ── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 10, 0.66);
  opacity: 0; transition: opacity 0.16s;
  padding: 16px;
}
.modal.open { opacity: 1; }
.modal-card {
  width: min(520px, 100%); max-height: 86vh; overflow: auto;
  background: linear-gradient(180deg, #171b29, #12151f);
  border: 1px solid var(--border-strong); border-radius: 18px;
  padding: 20px; box-shadow: var(--shadow);
}
.modal-card.wide { width: min(760px, 100%); }
.modal-card.narrow { width: min(360px, 100%); }
.modal-card h3 { margin: 0 0 10px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* 链接列表 / 二维码 */
.link-list { display: grid; gap: 8px; }
.link-row {
  display: flex; align-items: center; gap: 8px;
  background: rgba(9, 11, 18, 0.6); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
}
.link-kind { font-size: 11px; color: var(--dim); flex: none; }
.link-url { flex: 1; font-size: 12px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; }
.qr-wrap { display: grid; place-items: center; gap: 6px; margin: 14px 0 4px; }
.qr-wrap img { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; }
.url-text { font-size: 12px; word-break: break-all; text-align: center; }

/* 诊断 */
.verdict-list { display: grid; gap: 8px; margin-bottom: 12px; }
.verdict {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: var(--panel);
}
.verdict .icon { font-size: 16px; flex: none; margin-top: 1px; }
.verdict .title { font-weight: 600; font-size: 13px; }
.verdict .detail { font-size: 12px; color: var(--dim); margin-top: 2px; word-break: break-word; }
.verdict.ok { border-color: rgba(56, 211, 159, 0.35); }
.verdict.warn { border-color: rgba(240, 180, 41, 0.35); }
.verdict.bad { border-color: rgba(244, 100, 95, 0.4); }
.network-detail { font-size: 12px; color: var(--dim); display: grid; gap: 4px; }
.advanced-box { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ── Toast ── */
.toast-box {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom)); z-index: 500;
  display: grid; gap: 8px; justify-items: center; pointer-events: none;
  width: min(560px, calc(100vw - 32px));
}
.toast {
  background: rgba(20, 24, 36, 0.95); border: 1px solid var(--border-strong);
  color: var(--text); padding: 10px 16px; border-radius: 12px;
  font-size: 13px; box-shadow: var(--shadow); text-align: center;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s;
  max-width: 100%;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: rgba(244, 100, 95, 0.5); }
.toast-ok { border-color: rgba(56, 211, 159, 0.5); }

/* ── 共享源选择 ── */
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.source-card {
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--panel); cursor: pointer; padding: 0; color: var(--text);
  text-align: left; transition: border-color 0.15s, transform 0.12s;
}
.source-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.source-thumb { height: 96px; display: grid; place-items: center; background: #05070c; font-size: 30px; overflow: hidden; }
.source-thumb img { width: 100%; height: 100%; object-fit: cover; }
.source-name { display: block; padding: 8px 10px 2px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-type { display: block; padding: 0 10px 8px; font-size: 11px; color: var(--dim); }

/* ── 伪全屏（CSS 覆盖视口；iOS 等不支持 Fullscreen API 的设备兜底）── */
.tile.pseudo-fullscreen {
  position: fixed; inset: 0; z-index: 400;
  width: 100vw; height: 100vh; height: 100dvh;
  border: none; border-radius: 0;
  background: #000;
}
body.pseudo-fullscreen-active { overflow: hidden; }
.tile.pseudo-fullscreen .tile-media, .tile.pseudo-fullscreen video, .tile.pseudo-fullscreen canvas {
  width: 100%; height: 100%; object-fit: contain;
}
.pseudo-exit {
  position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px; z-index: 410;
  background: rgba(8, 10, 16, 0.82); border: 1px solid var(--border-strong); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  backdrop-filter: blur(8px);
}

/* ── 触摸设备：工具栏常显（没有 hover），点击区域更大 ── */
@media (hover: none) {
  .tile.main .tile-tools { opacity: 1; }
  .tile-tools .icon-btn, .tile-tools select { padding: 7px 10px; font-size: 13px; }
  .tile-volume input { width: 88px; }
}
button, select, input, .tile { touch-action: manipulation; }

.mobile-only { display: none; }
@media (max-width: 900px) {
  .mobile-only { display: initial; }
  .room-main { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(78vw, 300px);
    z-index: 90; transform: translateX(-105%); transition: transform 0.22s ease;
    background: #10131d; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .stats-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(88vw, 340px); z-index: 95; background: #10131d; }
  .stage { padding: 8px; gap: 8px; }
  .stage-strip { flex-direction: row; }
  .stage-strip .tile { width: 148px; height: 83px; }
  .room-info { display: none; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .bottombar { padding: 8px 10px calc(8px + var(--safe-bottom)); gap: 8px; }
  .share-btn { flex: 1; min-width: 0; }
  .ctl-group { order: 3; width: 100%; justify-content: space-between; }
  .uplink-info { display: none; }
  .mode-cards { grid-template-columns: 1fr; }
  .lobby-card { padding: 20px 16px; }
  .toast-box { bottom: calc(88px + var(--safe-bottom)); }
}
@media (max-width: 560px) {
  .stage-strip .tile { width: 128px; height: 72px; }
  .tile-volume input { width: 56px; }
}
