:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0e1014;
  color: #f2f4f7;
  --bg: #0e1014;
  --panel: #171a20;
  --panel-2: #1e222a;
  --border: #303641;
  --muted: #939baa;
  --soft: #c8ced8;
  --accent: #7e9bff;
  --ok: #4ade80;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { min-height: 100dvh; overflow-x: hidden; }
button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app {
  width: min(1480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.topbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.top-actions, .control-group { display: flex; align-items: center; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #15181e;
  font-size: 13px;
}
.badge.live { color: #dffbea; border-color: #29583a; background: #13271a; }

.player-shell {
  position: relative;
  width: 100%;
  border: 1px solid #282d36;
  border-radius: 18px;
  overflow: hidden;
  background: #050607;
  box-shadow: 0 28px 90px #0008;
}
.stage {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 260px;
  max-height: calc(100dvh - 170px);
  display: grid;
  place-items: center;
  background: #000;
  position: relative;
  outline: none;
}
.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.stage.fill video { object-fit: cover; }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  color: var(--muted);
  padding: 28px;
}
.empty-state strong { color: var(--soft); font-size: clamp(20px, 3vw, 30px); }
.empty-state span { max-width: 520px; line-height: 1.5; }
.pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(126,155,255,.45);
  animation: pulse 1.8s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 13px rgba(126,155,255,0); } }
.tap-hint {
  display: none;
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #11151dcc;
  border: 1px solid #343b47;
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--soft);
  font-size: 12px;
}
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 64px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.player-shell:hover .controls,
.player-shell.controls-visible .controls,
.player-shell:focus-within .controls {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.icon-button {
  min-width: 42px;
  min-height: 42px;
  border: 1px solid #3a414d;
  border-radius: 11px;
  background: #171b22dd;
  color: #f3f5f7;
  cursor: pointer;
}
.icon-button:hover { background: #242a34; border-color: #505968; }
.text-button { min-width: auto; padding: 0 13px; font-weight: 650; }
.stream-label { color: #d8dde5; font-size: 13px; white-space: nowrap; }
.stats-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  padding: 16px;
}
.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.stats-head > div { display: flex; flex-direction: column; gap: 4px; }
.stats-head span { color: var(--muted); font-size: 12px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.stat {
  min-width: 0;
  border: 1px solid #2a3039;
  border-radius: 12px;
  background: #11141a;
  padding: 11px;
}
.stat b { display: block; margin-bottom: 5px; color: #7f8897; font-size: 10px; letter-spacing: .06em; }
.stat span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
.viewer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.link-button { border: 0; background: transparent; color: var(--soft); cursor: pointer; padding: 8px; }
.dev-panel {
  border: 1px dashed #3b424e;
  border-radius: 12px;
  padding: 12px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
}
.dev-panel label { display: flex; align-items: center; gap: 8px; }
.dev-panel select, .dev-panel button {
  min-height: 38px;
  border: 1px solid #3a414d;
  border-radius: 9px;
  background: #1b1f26;
  color: #f2f4f7;
  padding: 0 11px;
}

body.theater .app { width: 100%; max-width: none; padding-left: 0; padding-right: 0; }
body.theater .topbar,
body.theater .stats-panel,
body.theater .viewer-footer { margin-left: 18px; margin-right: 18px; }
body.theater .player-shell { border-left: 0; border-right: 0; border-radius: 0; }
body.theater .stage { max-height: calc(100dvh - 88px); }

.player-shell:fullscreen { border: 0; border-radius: 0; }
.player-shell:fullscreen .stage { width: 100vw; height: 100vh; max-height: none; aspect-ratio: auto; }
.player-shell:fullscreen .controls { padding-bottom: max(16px, env(safe-area-inset-bottom)); }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage { max-height: none; }
}
@media (max-width: 620px) {
  .app { padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); gap: 10px; }
  .brand { font-size: 20px; }
  .topbar { min-height: 42px; }
  .badge { min-height: 30px; font-size: 11px; padding: 0 9px; }
  .top-actions { gap: 5px; }
  .top-actions .icon-button { min-height: 34px; }
  .player-shell { border-radius: 13px; }
  .stage { aspect-ratio: 16 / 10; min-height: 220px; }
  .controls { opacity: 1; transform: none; pointer-events: auto; min-height: 58px; padding: 10px; }
  .icon-button { min-width: 40px; min-height: 40px; }
  .stream-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .tap-hint { display: none !important; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .stat { padding: 9px; }
  .viewer-footer { align-items: flex-start; line-height: 1.4; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .topbar, .viewer-footer { display: none; }
  .app { padding: 0; gap: 0; }
  .player-shell { border: 0; border-radius: 0; min-height: 100dvh; }
  .stage { width: 100vw; height: 100dvh; max-height: none; aspect-ratio: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (max-width: 620px) {
  .topbar { min-width: 0; gap: 8px; }
  .top-actions { min-width: 0; margin-left: auto; gap: 4px; }
  .badge { max-width: 105px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions .text-button { padding: 0 9px; }
  .controls { gap: 6px; }
  .control-group { gap: 4px; }
  .stream-label { display: none; }
  .right-controls .icon-button { min-width: 38px; padding-left: 9px; padding-right: 9px; }
  .empty-state { min-width: 0; width: 100%; padding: 20px 16px 76px; }
  .empty-state span { width: 100%; max-width: 300px; overflow-wrap: anywhere; }
  .dev-panel { display: none !important; }
}
@media (max-width: 620px) {
  .topbar { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; }
  .top-actions { display: contents; }
  .badge { justify-self: end; max-width: 92px; }
  #statsButton { width: 40px; min-width: 40px; padding: 0; font-size: 0; }
  #statsButton::before { content: "⋯"; font-size: 19px; line-height: 1; }
  .controls { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; }
  .left-controls { grid-column: 1; }
  .right-controls { grid-column: 3; justify-self: end; }
  #theaterButton { display: none; }
}
/* Readability baseline */
html { font-size: 16px; }
body, button, select { font-size: 16px; }
.badge { font-size: 14px; }
.stream-label { font-size: 16px; }
.empty-state span { font-size: 16px; }
.viewer-footer { font-size: 14px; }
.stats-head span { font-size: 14px; }
.stat b { font-size: 12px; }
.stat span { font-size: 14px; }

@media (max-width: 620px) {
  body, button, select { font-size: 16px; }
  .brand { font-size: 22px; }
  .badge { font-size: 13px; }
  .viewer-footer { font-size: 14px; }
  .empty-state span { font-size: 16px; line-height: 1.5; }
  .stat span { font-size: 13px; }
}

/* Browser sender */
.start-panel,.sender-bar{
  border:1px solid var(--border);
  border-radius:18px;
  background:var(--panel);
  padding:clamp(20px,4vw,38px);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:28px;
}
.start-panel[hidden],.sender-bar[hidden]{display:none!important}
.start-panel>div:first-child{max-width:720px}
.eyebrow{display:block;color:var(--accent);font-size:13px;font-weight:750;letter-spacing:.09em;margin-bottom:9px}
.start-panel h1{font-size:clamp(28px,4vw,46px);line-height:1.08;margin:0 0 12px;letter-spacing:-.035em}
.start-panel p{font-size:17px;line-height:1.55;color:var(--muted);margin:0;max-width:650px}
.start-actions,.sender-actions{display:flex;gap:10px;flex-wrap:wrap}
.primary-button,.secondary-button,.danger-button{
  min-height:48px;
  border-radius:12px;
  padding:0 18px;
  font-size:16px;
  font-weight:700;
  cursor:pointer;
}
.primary-button{border:1px solid #f2f4f7;background:#f2f4f7;color:#11141a}
.secondary-button{border:1px solid #3b424e;background:#20252d;color:#f2f4f7}
.danger-button{border:1px solid #63343b;background:#3a2025;color:#ffd9de}
.primary-button:disabled{opacity:.55;cursor:wait}
.sender-bar{padding:16px 18px}
.sender-bar>div:first-child{display:flex;flex-direction:column;gap:4px}
.sender-bar strong{font-size:17px}
.sender-bar span{font-size:14px;color:var(--muted)}

@media(max-width:700px){
  .start-panel,.sender-bar{align-items:stretch;flex-direction:column;gap:18px;padding:20px 16px}
  .start-actions,.sender-actions{width:100%}
  .start-actions button,.sender-actions button{flex:1 1 160px}
  .start-panel h1{font-size:30px}
}

.dev-panel[hidden]{display:none!important}
@media(max-width:620px){
  .start-actions,.sender-actions{display:grid;grid-template-columns:1fr;width:100%}
  .start-actions button,.sender-actions button{width:100%;min-width:0}
  .start-panel{padding:20px 16px}
  .start-panel h1{font-size:29px}
  .top-actions #statsButton{display:none}
  .badge{max-width:110px}
}

.device-panel{padding:28px;border:1px solid #2a2f38;border-radius:18px;background:#11151b;margin-bottom:18px}
.device-panel-head h1{margin:8px 0 8px;font-size:28px}.device-panel-head p{margin:0 0 20px;color:#9ba3af}
.device-list{display:grid;gap:10px}.device-row{width:100%;display:flex;align-items:center;justify-content:space-between;gap:18px;padding:16px 18px;border:1px solid #303640;border-radius:13px;background:#181d24;color:#f5f5f5;text-align:left;cursor:pointer}
.device-row:hover{border-color:#5d6878;background:#1c222b}.device-row:disabled{opacity:.55;cursor:wait}.device-row strong{font-size:16px}.device-row span{color:#9ba3af;font-size:13px}
.device-empty{padding:18px 0;color:#7f8997}.device-panel .secondary-button{margin-top:14px}
