:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #232733;
  --border: #2d3240;
  --text: #eef0f4;
  --muted: #9aa2b2;
  --accent: #4f7cff;
  --accent-hover: #6a90ff;
  --danger: #e5484d;
  --danger-hover: #f05a5f;
  --ok: #3ecf8e;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.round.danger svg { fill: currentColor; width: 28px; height: 28px; }

h1 { font-size: 1.6rem; margin: 0 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.3rem; margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: #ff8a8d; min-height: 1.2em; margin: .6rem 0 0; font-size: .9rem; }

/* ---------- Layout ---------- */
#app, .screen { height: 100%; }
.card-screen { display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
}
.card .muted { margin: 0 0 1.4rem; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 22px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Controls ---------- */
input[type=text] {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; width: 100%;
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }

.btn {
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 18px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #2b3040; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.wide { width: 100%; }
.btn:focus-visible, .round:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.round {
  width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.round:hover { background: #2f3445; }
.round[aria-pressed="false"] { background: #fff; color: #111; border-color: #fff; }
.round.danger { background: var(--danger); border-color: var(--danger); color: #fff; width: 64px; }
.round.danger:hover { background: var(--danger-hover); }
.round:disabled { opacity: .4; cursor: default; }

/* ---------- Lobby ---------- */
.card.lobby { max-width: 900px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; align-items: center; }
.preview { position: relative; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-controls { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 12px; }
.lobby-form .btn { margin-top: 16px; }
@media (max-width: 720px) {
  .card.lobby { grid-template-columns: 1fr; padding: 16px; gap: 18px; }
}

.video-off { position: absolute; inset: 0; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.video-off.big { background: var(--surface); }
.avatar {
  width: 120px; height: 120px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; font-size: 3rem; font-weight: 700; color: #fff;
}

/* ---------- Call ---------- */
#screen-call { display: flex; flex-direction: column; background: #000; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#remote-video { width: 100%; height: 100%; object-fit: contain; background: #000; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0; padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
}
.peer-name { font-weight: 600; }
.badge { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,.5); }
.badge svg { width: 16px; height: 16px; }
.status { color: var(--muted); font-size: .9rem; }
.timer {
  margin-left: auto; padding: 3px 10px; border-radius: 999px;
  background: rgba(0,0,0,.5); font-size: .9rem; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
}

.local {
  position: absolute; right: 16px; bottom: 16px;
  width: min(26vw, 220px); aspect-ratio: 4 / 3;
  border-radius: 12px; overflow: hidden; background: #111;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.12);
}
.local video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

.waiting {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  padding: 16px; background: var(--bg);
}
.waiting #waiting-text { font-size: 1.3rem; font-weight: 600; margin: 0 0 .4rem; }
.waiting .row { width: min(520px, calc(100vw - 32px)); margin-top: 10px; }

.security {
  position: absolute; left: 16px; bottom: 16px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); color: var(--ok); border: 1px solid rgba(62,207,142,.4);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer;
}
.security svg { width: 16px; height: 16px; }
.security-panel {
  position: absolute; left: 16px; bottom: 60px; max-width: 320px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.security-panel p { margin: 0 0 .5rem; }
.code { font: 600 1.5rem/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; color: var(--text); margin: 0 !important; }

.banner {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,36,.92); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; font-size: .9rem; max-width: calc(100% - 32px);
}

.controls {
  display: flex; justify-content: center; gap: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: #fff; color: #111; padding: 8px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
}

@media (max-width: 600px) {
  .local { width: 34vw; right: 10px; bottom: 10px; }
  .security { left: 10px; bottom: 10px; }
  .round { width: 50px; height: 50px; }
}
