:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --text: #e8edf6;
  --muted: #8a96ad;
  --accent: #22c55e;
  --accent-text: #052e14;
  --danger: #ef4444;
  --line: #24304a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { height: 100%; }
body { min-height: 100%; margin: 0; }

body {
  background: radial-gradient(120% 80% at 50% 0%, #17233d 0%, var(--bg) 60%);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.phone { width: 100%; max-width: 380px; }

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 32px 0;
}
.screen[hidden] { display: none; }

h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
h2 { margin: 0; }
.sub { margin: 0; color: var(--muted); }
.fine { margin: 0; color: var(--muted); font-size: 0.8rem; }

.avatar {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  position: relative;
}
.avatar svg { width: 56px; height: 56px; fill: var(--muted); }
.avatar.ringing::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 1.6s ease-out infinite;
}
.avatar.live { border-color: var(--accent); }
.avatar.live svg { fill: var(--accent); }

@keyframes pulse {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.35); opacity: 0; }
}

.status { font-size: 1.15rem; font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); min-height: 1.5em; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; border-radius: 16px; }
.btn[hidden] { display: none; }
.btn:focus-visible, .round:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.share { display: flex; gap: 8px; width: 100%; }
.share input {
  flex: 1; min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.85rem;
}

.controls { display: flex; gap: 40px; justify-content: center; margin-top: 8px; }
.controls[hidden] { display: none; }

.round {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer;
}
.round svg {
  width: 64px; height: 64px;
  padding: 18px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  fill: var(--text);
}
.round[aria-pressed="true"] svg { background: var(--text); fill: var(--bg); }
.round.danger svg { background: var(--danger); border-color: var(--danger); fill: #fff; }

.speaker { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.85rem; }
.speaker[hidden] { display: none; }
.speaker select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font: inherit; max-width: 200px;
}

.row { display: flex; gap: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- home ---------- */
.top { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; border-radius: 10px; }
.small { font-size: 0.85rem; }

.card {
  width: 100%;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  text-align: left;
}
.card[hidden] { display: none; }
.card-title { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card label { font-weight: 600; }

.field-row { display: flex; gap: 8px; }
.field-row input, .pin-details input {
  flex: 1; min-width: 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font: inherit;
}
.field-row input:focus, .pin-details input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { margin: 0; color: #fca5a5; font-size: 0.85rem; }
.error[hidden] { display: none; }

.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.me[hidden] { display: none; }
.me strong { color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.link-btn { appearance: none; background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.people li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.people li:first-child { border-top: 0; }
.people .initial {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: var(--line); font-weight: 700;
}
.people .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.people .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .who small { color: var(--muted); }
.people .who small.busy { color: #fbbf24; }
.people .btn { padding: 8px 14px; }
.people .btn:disabled { opacity: 0.4; cursor: not-allowed; }
#people-empty[hidden] { display: none; }

.pin-details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.pin-details input { width: 100%; margin-top: 8px; }

/* ---------- call ---------- */
.avatar span { font-size: 2.6rem; font-weight: 700; color: var(--text); }
.avatar span:empty { display: none; }
.avatar span:not(:empty) + svg { display: none; }
.peer-name { font-size: 1.5rem; font-weight: 700; min-height: 0; }
.peer-name:empty { display: none; }
.meta-row { display: flex; gap: 12px; align-items: center; min-height: 1.5em; }

.quality { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.quality[hidden] { display: none; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars i { width: 3px; background: var(--line); border-radius: 1px; }
.bars i:nth-child(1) { height: 4px; }
.bars i:nth-child(2) { height: 8px; }
.bars i:nth-child(3) { height: 12px; }
.quality.good .bars i { background: var(--accent); }
.quality.fair .bars i:nth-child(-n+2) { background: #fbbf24; }
.quality.poor .bars i:nth-child(1) { background: var(--danger); }

.share[hidden], #pin-note[hidden] { display: none; }
.round.accept svg { background: var(--accent); border-color: var(--accent); fill: var(--accent-text); }

/* ---------- incoming overlay & banner ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  padding: 16px;
}
.overlay[hidden] { display: none; }

.banner {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 20; display: flex; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 8px 8px 14px; font-size: 0.9rem; width: max-content; max-width: calc(100% - 32px);
}
.banner[hidden] { display: none; }

/* ---------- video ---------- */
.controls { gap: 20px; }
.round[hidden] { display: none; }
.alerts .btn { align-self: flex-start; }
.btn[disabled] { opacity: 0.6; cursor: progress; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 58vh;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.stage[hidden] { display: none; }
.stage video { display: block; background: #000; }
.stage video[hidden] { display: none; }
#remote-video { width: 100%; height: 100%; object-fit: cover; }
#remote-video.contain { object-fit: contain; }
#local-video {
  position: absolute; right: 10px; bottom: 10px;
  width: 30%; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 12px; border: 2px solid rgb(255 255 255 / 0.35);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}
.stage.solo #local-video { inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; }
.mirror { transform: scaleX(-1); }
.has-video .avatar { display: none; }
.has-video .peer-name { font-size: 1.15rem; }
