:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #13201b;
  --muted: #5f6e68;
  --line: #dde4e0;
  --accent: #128c5e;
  --accent-ink: #ffffff;
  --red: #d93a3a;
  --green: #1aa36a;
  --dim: rgba(255, 255, 255, 0.16);
  --overlay: #0f1714;
  --overlay-text: #eef4f1;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #17221e;
    --text: #e8efeb;
    --muted: #93a39c;
    --line: #26332e;
    --accent: #22b07a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.4em; margin: 4px 0 0; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

/* login */
#login { display: flex; flex-direction: column; justify-content: center; gap: 32px; }
.brand { text-align: center; }
.brand img { border-radius: 16px; }
.brand h1 { font-size: 30px; margin-top: 12px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px;
  padding: 13px 16px; cursor: pointer; background: var(--line); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; padding: 8px; cursor: pointer; }

/* home */
.topbar { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.topbar h2 { font-size: 24px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: #c9a227; }
.conn.ok i { background: var(--green); }
.conn.bad i { background: var(--red); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.hint p { margin: 0 0 10px; }
.hint p:last-child { margin-bottom: 0; }

.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.contacts, .history { list-style: none; margin: 0; padding: 0; }
.contact {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.contact .meta { flex: 1; min-width: 0; }
.contact .meta strong { display: block; font-size: 17px; }
.contact .status { font-size: 13px; color: var(--muted); }
.contact .status.on { color: var(--green); }
.contact button {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--line); color: var(--text);
}
.contact button.voice { background: var(--accent); color: var(--accent-ink); }
.contact button svg { width: 22px; height: 22px; fill: currentColor; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
}
.avatar.big { width: 104px; height: 104px; font-size: 40px; background: rgba(255,255,255,.1); color: var(--overlay-text); }

.history li {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 2px;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.history .missed { color: var(--red); }
.history time { color: var(--muted); white-space: nowrap; }
.foot { display: flex; justify-content: space-between; margin-top: 28px; }

/* overlays */
.overlay {
  position: fixed; inset: 0; z-index: 10; background: var(--overlay); color: var(--overlay-text);
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 64px) 16px calc(env(safe-area-inset-bottom) + 48px);
}
.overlay .muted { color: rgba(238,244,241,.7); }
.who { text-align: center; display: grid; justify-items: center; gap: 14px; position: relative; z-index: 2; }
.who h2 { font-size: 28px; }
.actions { display: flex; gap: 28px; position: relative; z-index: 2; }
.round {
  width: 68px; height: 68px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; color: #fff;
}
.round svg { width: 30px; height: 30px; fill: currentColor; }
.round.red { background: var(--red); }
.round.green { background: var(--green); }
.round.dim { background: var(--dim); }
.round.dim[aria-pressed="true"] { background: #fff; color: #111; }
#hangupBtn svg, #decline svg { transform: rotate(0deg); }

.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(26,163,106,.45); }
  50% { box-shadow: 0 0 0 22px rgba(26,163,106,0); }
}
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; z-index: 1; }
#remoteVideo:not(.has-video) { opacity: 0; }
#localVideo {
  position: absolute; z-index: 3; right: 16px; top: calc(env(safe-area-inset-top) + 16px);
  width: 28vw; max-width: 150px; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px;
  transform: scaleX(-1); background: #000;
}
#call.video-on .who { opacity: 0; pointer-events: none; }
#call.video-on.show-who .who { opacity: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center;
}
