:root {
  --bg: #0A2540;
  --surface: #0f3050;
  --primary: #0B5FFF;
  --danger: #E5484D;
  --ok: #30A46C;
  --warn: #F5A623;
  --text: #F2F6FA;
  --muted: #9BB0C4;
  --radius: 12px;
}

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

body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 420px; }
.card.center { text-align: center; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand img { height: 32px; }
.brand h1 { font-size: 20px; font-weight: 600; }

video { width: 100%; border-radius: var(--radius); background: #000; display: block; }
#previewVideo { aspect-ratio: 4/3; object-fit: cover; transform: scaleX(-1); }

.meter { height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; margin: 12px 0 4px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width .1s linear; }
.hint, .fineprint { font-size: 13px; color: var(--muted); }

.checks { list-style: none; margin: 16px 0; display: flex; gap: 16px; font-size: 14px; }
.checks .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.checks .ok .dot { background: var(--ok); }
.checks .fail .dot { background: var(--danger); }

.field { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
.field select {
  width: 100%; margin-top: 4px; padding: 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.15); background: var(--bg); color: var(--text);
}

.btn {
  width: 100%; padding: 14px; border: 0; border-radius: 10px; font-size: 16px;
  font-weight: 600; cursor: pointer; margin-top: 12px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:disabled { background: #2a4a70; color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,.25); }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; margin: 0; background: var(--primary); color: #fff; }

.error { color: var(--danger); font-size: 14px; margin-top: 12px; }
.muted { color: var(--muted); }

.spinner {
  width: 36px; height: 36px; margin: 0 auto 16px;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- in call ---------- */
#incall { display: block; padding: 0; position: relative; }
#stage { position: relative; width: 100%; height: 100dvh; background: #000; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; border-radius: 0; }

.placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: var(--bg);
}
.placeholder span {
  width: 84px; height: 84px; border-radius: 50%; background: var(--primary);
  display: grid; place-items: center; font-size: 32px; font-weight: 600; margin-bottom: 12px;
}

#localVideo {
  position: absolute; right: 12px; top: 12px; width: 108px; aspect-ratio: 3/4;
  object-fit: cover; border-radius: 10px; border: 2px solid rgba(255,255,255,.2);
  transform: scaleX(-1);
}

.banner {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  background: var(--warn); color: #1a1a1a; padding: 8px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 500; max-width: 90%; text-align: center;
}

.quality { position: absolute; left: 12px; top: 16px; display: flex; align-items: flex-end; gap: 2px; }
.quality .bar { width: 4px; background: rgba(255,255,255,.3); border-radius: 1px; }
.quality .bar:nth-child(1) { height: 7px; }
.quality .bar:nth-child(2) { height: 11px; }
.quality .bar:nth-child(3) { height: 15px; }
.quality.good .bar { background: var(--ok); }
.quality.fair .bar:nth-child(-n+2) { background: var(--warn); }
.quality.poor .bar:nth-child(1) { background: var(--danger); }
.quality em { font-style: normal; font-size: 12px; color: var(--muted); margin-left: 6px; }

.rec {
  position: absolute; right: 12px; bottom: 100px; display: flex; align-items: center;
  gap: 6px; font-size: 12px; font-weight: 600; letter-spacing: .05em;
  background: rgba(0,0,0,.6); padding: 5px 10px; border-radius: 14px;
}
.rec span { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

#controls {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center; gap: 12px;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.75) 40%);
}
.ctrl {
  width: 52px; height: 52px; border-radius: 50%; border: 0; font-size: 20px;
  background: rgba(255,255,255,.16); color: #fff; cursor: pointer;
}
.ctrl.off { background: rgba(255,255,255,.35); }
.ctrl.danger { background: var(--danger); }
.ctrl.active { background: var(--primary); }
.ctrl[hidden] { display: none; }

#sidepanel {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100%);
  background: var(--surface); display: flex; flex-direction: column; z-index: 5;
}
#sidepanel header { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid rgba(255,255,255,.1); }
.tab { background: none; border: 0; color: var(--muted); font-size: 15px; cursor: pointer; padding: 6px 10px; border-radius: 6px; }
.tab.active { color: var(--text); background: rgba(255,255,255,.1); }
.icon-btn { margin-left: auto; background: none; border: 0; color: var(--text); font-size: 24px; cursor: pointer; }
.pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#chatLog { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.1); font-size: 14px; }
.msg.mine { align-self: flex-end; background: var(--primary); }
#chatForm { display: flex; gap: 8px; padding: 12px; border-top: 1px solid rgba(255,255,255,.1); }
#chatInput { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: var(--bg); color: var(--text); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 420px; }
.modal-card h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 12px; margin-top: 8px; }

/* Desktop: side-by-side rather than the mobile overlay. */
@media (min-width: 900px) {
  #localVideo { width: 200px; }
  #incall:has(#sidepanel:not([hidden])) #stage { width: calc(100% - 360px); }
}
