:root {
  --bg-page: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-input: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #4f8cff;
  --primary-hover: #3b76ea;
  --accent: #7c3aed;
  --danger: #ef4444;
  --success: #10b981;
  --live: #e11d48;
  --live-hover: #be123c;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --glow: 0 10px 40px rgba(79, 140, 255, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 58, 237, 0.06), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(79, 140, 255, 0.06), transparent 60%),
    linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.controls-panel {
  width: 380px;
  min-width: 380px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px;
  gap: 16px;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.06);
}

.controls-panel::-webkit-scrollbar { width: 6px; }
.controls-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}
.panel-header h1 {
  font-size: 1.1rem; font-weight: 700;
  background: linear-gradient(90deg, #1e293b, #4f8cff 60%, #7c3aed);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: 0.5px;
}

.badge {
  background: #eff6ff;
  color: #2563eb;
  font-size: 0.72rem;
  padding: 5px 10px;
  border-radius: 9999px;
  font-weight: 600;
  border: 1px solid #bfdbfe;
}
.badge.is-live {
  background: var(--live);
  color: #fff;
  border-color: var(--live);
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(225,29,72,0.5); } 50% { box-shadow: 0 0 0 10px rgba(225,29,72,0); } 100% { box-shadow: 0 0 0 0 rgba(225,29,72,0); } }

.control-group {
  display: flex; flex-direction: column; gap: 8px;
  background: #f8fafc;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.control-group:hover { border-color: var(--border-strong); box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
.control-group h3 {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: all .2s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%2364748b' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
input[type="text"], input[type="number"] { background-image: none; padding-right: 12px; }
select:focus, input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.12);
}
select:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; background: #f1f5f9; }

.row { display: flex; gap: 10px; }
.col { flex: 1; display: flex; flex-direction: column; gap: 6px; }

.btn {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: 0 4px 14px rgba(79, 140, 255, 0.3);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.4);
}
.btn-primary:disabled {
  background: #e2e8f0;
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}
.btn-toggle { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.btn-toggle:hover:not(:disabled) { background: #d1fae5; }
.btn-toggle.is-off { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.btn-toggle.is-off:hover:not(:disabled) { background: #fee2e2; }

.btn-live {
  background: linear-gradient(135deg, #ff3a5e, #b91c1c);
  color: white;
  font-size: 1rem;
  padding: 14px;
  margin-top: 8px;
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.35);
}
.btn-live:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 26px rgba(225, 29, 72, 0.45);
}
.btn-live:disabled { background: #e2e8f0; color: var(--text-muted); cursor: not-allowed; box-shadow: none; }

.btn-stop {
  background: linear-gradient(135deg, #6b7280, #374151);
  color: white;
  font-size: 1rem;
  padding: 14px;
  margin-top: 8px;
  box-shadow: 0 6px 20px rgba(55, 65, 81, 0.3);
}
.btn-stop:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 26px rgba(55, 65, 81, 0.4);
}
.btn-stop:disabled { background: #e2e8f0; color: var(--text-muted); cursor: not-allowed; box-shadow: none; }

.share-box { margin-top: 6px; }

.panel-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.status-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.preview-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 30px;
  background:
    radial-gradient(circle at 50% 50%, rgba(79, 140, 255, 0.04), transparent 60%),
    #0f172a;
}

.video-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.3),
    0 0 0 1px rgba(255,255,255,0.06);
  transition: width .4s ease, height .4s ease;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain !important;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  transition: all .3s ease;
}

.empty-state {
  position: absolute;
  display: flex; flex-direction: column;
  align-items: center; gap: 14px;
  color: #64748b;
  pointer-events: none;
  text-align: center;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.is-hidden { display: none !important; }

/* ==========================================
   纯观众端：网站搭建成功页面
   ========================================== */
.site-ready {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.site-ready-content {
  text-align: center;
  color: #1e293b;
}
.site-ready-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  border-radius: 50%;
  background: #10b981;
  color: #fff;
  font-size: 36px;
  line-height: 72px;
  font-weight: 700;
}
.site-ready-content h1 {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.site-ready-content p {
  font-size: 0.9rem;
  color: #64748b;
}

/* ==========================================
   观众端特化样式：纯净黑屏
   ========================================== */
body.viewer-mode { background: #000; }
body.viewer-mode .app-container { display: block; height: 100vh; }
body.viewer-mode .controls-panel { display: none !important; }
body.viewer-mode .preview-panel { padding: 0 !important; background: #000; }
body.viewer-mode .video-wrapper {
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #000;
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: auto !important;
  position: absolute !important;
  top: 0; left: 0; right: 0; bottom: 0;
}
body.viewer-mode video {
  border-radius: 0 !important;
  box-shadow: none !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  display: block;
}
body.viewer-mode .empty-state { display: none !important; }

/* OBS 浏览器源兜底：直接让 video 撑满 viewport */
body.viewer-mode #previewVideo {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999;
}

@media (max-width: 900px) {
  .app-container { flex-direction: column-reverse; }
  .controls-panel { width: 100%; min-width: 100%; height: 50vh; }
  .preview-panel { height: 50vh; padding: 12px; }
  .video-wrapper { border-radius: 12px; }
}
