:root {
  color-scheme: dark;
  --bg: #070a0f;
  --panel: #111720;
  --panel-2: #18212d;
  --text: #f4f7fb;
  --muted: #94a0af;
  --line: #283442;
  --accent: #e82127;
  --success: #38d996;
  --warning: #ffc857;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: radial-gradient(circle at 50% -20%, #1c2633 0, var(--bg) 46%); color: var(--text); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100%; display: grid; grid-template-rows: 72px 1fr; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(7,10,15,.88); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  color: white; background: var(--accent); font-weight: 900;
}
.connection-badge {
  display: inline-flex; align-items: center; gap: 9px; padding: 9px 13px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 14px;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #697586; }
.connection-badge[data-state="connecting"] .status-dot { background: var(--warning); box-shadow: 0 0 14px var(--warning); }
.connection-badge[data-state="connected"] .status-dot { background: var(--success); box-shadow: 0 0 14px var(--success); }
.connection-badge[data-state="error"] .status-dot { background: var(--accent); box-shadow: 0 0 14px var(--accent); }

.pairing-panel { display: grid; place-items: center; padding: 32px; }
.pairing-card {
  width: min(520px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: 28px;
  background: linear-gradient(145deg, rgba(24,33,45,.96), rgba(13,18,26,.96));
  box-shadow: 0 30px 90px rgba(0,0,0,.38); text-align: center;
}
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .18em; }
h1 { margin: 0; font-size: clamp(34px, 5vw, 54px); letter-spacing: -.045em; }
.description { margin: 16px 0 28px; color: var(--muted); font-size: 17px; }
.code-input {
  width: 100%; height: 76px; border: 1px solid #344253; border-radius: 16px;
  outline: none; background: #080c12; color: white; text-align: center;
  font-size: 36px; font-weight: 800; letter-spacing: .22em;
}
.code-input:focus { border-color: #66778c; box-shadow: 0 0 0 4px rgba(102,119,140,.18); }
.form-error { min-height: 22px; margin: 10px 0; color: #ff777b; font-size: 14px; }
.primary-button {
  width: 100%; height: 62px; border: 0; border-radius: 16px; background: var(--accent);
  color: white; font-weight: 800; font-size: 18px; cursor: pointer;
}
.primary-button:disabled { opacity: .45; cursor: wait; }
.capabilities { display: flex; justify-content: center; gap: 18px; margin-top: 22px; color: var(--muted); font-size: 12px; }
.capabilities .ok::before { content: "✓ "; color: var(--success); }
.capabilities .bad::before { content: "× "; color: var(--accent); }

.viewer-panel { min-height: 0; display: grid; grid-template-rows: 1fr 86px; background: #000; }
.viewer-panel[hidden] { display: none; }
.video-stage { position: relative; min-height: 0; overflow: hidden; touch-action: none; user-select: none; }
#remoteVideo { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.video-placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 9px; color: var(--muted); background: radial-gradient(circle, #161d27, #050608 64%);
}
.video-placeholder strong { color: var(--text); font-size: 19px; }
.loader {
  width: 42px; height: 42px; margin-bottom: 10px; border: 3px solid #28313d;
  border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.control-bar {
  display: flex; align-items: stretch; justify-content: center; gap: 12px; padding: 10px 18px 14px;
  border-top: 1px solid #202733; background: #0b0f15;
}
.control-button {
  min-width: 110px; border: 1px solid #2e3948; border-radius: 15px; background: #161e28;
  color: white; cursor: pointer; display: grid; place-content: center; gap: 2px;
}
.control-button span { font-size: 23px; line-height: 1; }
.control-button small { color: var(--muted); }
.control-button:disabled { opacity: .36; cursor: not-allowed; }
.control-button.danger { color: #ff777b; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-height: 600px) {
  .app-shell { grid-template-rows: 58px 1fr; }
  .topbar { padding: 0 18px; }
  .pairing-card { padding: 24px 34px; }
  .description { margin: 8px 0 16px; }
  .code-input { height: 64px; }
  .primary-button { height: 54px; }
  .capabilities { margin-top: 14px; }
  .viewer-panel { grid-template-rows: 1fr 72px; }
}
