:root {
  --bg: #0f1720;
  --bg2: #16202c;
  --card: #1b2735;
  --card2: #223041;
  --line: #2c3d52;
  --fg: #e8eef6;
  --fg2: #9db0c6;
  --fg3: #6b7f96;
  --accent: #3b82f6;
  --accent2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body.host { overflow-y: auto; }

/* ---------------- 通用 ---------------- */
.wrap { max-width: 880px; margin: 0 auto; padding: 20px 22px 40px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg2);
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.hint { color: var(--fg3); font-size: 12.5px; line-height: 1.7; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; }

button, select, input[type="text"], input[type="password"] {
  font: inherit;
  color: var(--fg);
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  outline: none;
  transition: .15s;
}
button { cursor: pointer; }
button:hover:not(:disabled) { background: #2a3b50; border-color: #3d5470; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent2); border-color: var(--accent2); }
button.danger { background: #7f1d1d; border-color: #991b1b; color: #fee2e2; }
button.danger:hover:not(:disabled) { background: #991b1b; }
button.ghost { background: transparent; }
button.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
select { padding-right: 30px; }

label.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
label.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--fg3); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.18); }
.dot.err { background: var(--err); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
.dot.live { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--card2); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--fg2);
}

.linkbox {
  display: flex; align-items: center; gap: 10px;
  background: #0b1219; border: 1px dashed var(--line);
  border-radius: 10px; padding: 12px 14px; margin-top: 4px;
}
.linkbox .url {
  flex: 1; font-size: 16px; color: #7dd3fc; word-break: break-all;
  font-family: Consolas, monospace; user-select: all;
}
.linkbox .url.empty { color: var(--fg3); font-size: 13px; }

/* ---------------- 画面源选择 ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(4,9,15,.82);
  display: none; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; }
.modal .panel {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  width: min(920px, 94vw); max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal .head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .head h3 { margin: 0; font-size: 15px; }
.modal .body { padding: 16px 20px; overflow-y: auto; }
.modal .foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.source {
  border: 2px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--card); cursor: pointer; transition: .15s; text-align: left; padding: 0;
}
.source:hover { border-color: var(--accent); transform: translateY(-1px); }
.source.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.22); }
.source img { width: 100%; height: 118px; object-fit: contain; background: #0a0f15; display: block; }
.source .name {
  padding: 8px 10px; font-size: 12.5px; color: var(--fg2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.source .name img { width: 16px; height: 16px; height: auto; object-fit: contain; }
.source .kind { font-size: 11px; color: var(--fg3); padding: 0 10px 8px; }

/* ---------------- 观众列表 ---------------- */
.viewers { display: flex; flex-direction: column; gap: 8px; }
.viewer {
  display: flex; align-items: center; gap: 12px;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px;
}
.viewer .id { font-family: Consolas, monospace; color: var(--fg2); min-width: 76px; }
.viewer .stats { color: var(--fg3); font-size: 12.5px; font-family: Consolas, monospace; }
.empty { color: var(--fg3); text-align: center; padding: 18px 0; font-size: 13px; }

/* ---------------- 日志 ---------------- */
details summary { cursor: pointer; color: var(--fg2); font-size: 13px; padding: 4px 0; }
#log {
  margin-top: 10px; max-height: 180px; overflow-y: auto;
  background: #0a0f15; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-family: Consolas, monospace; font-size: 12px;
  color: var(--fg2); white-space: pre-wrap; line-height: 1.6;
}

/* ---------------- 提示条 ---------------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: #24344a; border: 1px solid var(--line); color: var(--fg);
  padding: 10px 20px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 99;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- 观众页 ---------------- */
body.viewer { background: #05080c; overflow: hidden; }

#stage {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #05080c;
}
body.fit-contain #stage { padding: 0; }
#screen {
  max-width: 100%; max-height: 100%; width: 100%; height: 100%;
  object-fit: contain; background: #000; outline: none; cursor: pointer;
}
body.fit-cover #screen { object-fit: cover; }

#overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: #05080c; text-align: center; padding: 24px; z-index: 10;
  transition: opacity .3s;
}
#overlay.hide { opacity: 0; pointer-events: none; }
#overlay .logo { font-size: 34px; }
#overlay h1 { margin: 0; font-size: 19px; font-weight: 600; }
#overlay p { margin: 0; color: var(--fg2); font-size: 13.5px; max-width: 420px; line-height: 1.8; }
.spinner {
  width: 30px; height: 30px; border: 3px solid #1e2a38; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#bar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(80px);
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: rgba(18,26,36,.92); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); transition: .22s; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); max-width: 96vw; flex-wrap: wrap; justify-content: center;
}
#bar.show { transform: translateX(-50%) translateY(0); }
#bar button { padding: 7px 14px; border-radius: 999px; font-size: 13px; }
#stats {
  position: fixed; top: 14px; right: 14px; z-index: 20;
  background: rgba(18,26,36,.9); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-family: Consolas, monospace; font-size: 12.5px;
  color: var(--fg2); line-height: 1.8; display: none; backdrop-filter: blur(8px);
}
#stats.show { display: block; }
#stats b { color: var(--fg); font-weight: 600; }
.badge-live {
  position: fixed; top: 14px; left: 14px; z-index: 20;
  display: none; align-items: center; gap: 7px;
  background: rgba(220,38,38,.92); color: #fff; font-size: 12.5px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
}
.badge-live.show { display: inline-flex; }
