:root {
  --bg: #f4f5f7; --surface: #fff; --text: #14161a; --muted: #6b7280; --line: #e3e5e8;
  --accent: #2563eb; --green: #16a34a; --red: #dc2626; --tile: #1c1f26; --ctl: #2a2e37;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --surface: #181b21; --text: #e8eaed; --muted: #9aa0a6; --line: #2a2e37; --accent: #4f8cff; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 24px; height: 24px; fill: currentColor; }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; font-size: 16px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.screen { height: 100dvh; display: flex; flex-direction: column; }
.card { background: var(--surface); border-radius: 18px; padding: 24px; box-shadow: 0 8px 30px rgb(0 0 0 / .12); }
.narrow { width: min(380px, calc(100% - 32px)); margin: auto; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.brand h1 { margin: 0; font-size: 24px; }
.logo { width: 36px; height: 36px; color: var(--accent); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.btn { padding: 12px; border-radius: 10px; font-weight: 600; }
.primary { background: var(--accent); color: #fff; }
.err { color: var(--red); min-height: 1em; margin: 0; text-align: center; font-size: 13px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.link { color: var(--accent); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--surface); }
.me { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.content { flex: 1; overflow: auto; padding: 12px 16px; width: 100%; max-width: 640px; margin: 0 auto; }
.search { margin-bottom: 8px; }

.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.who { flex: 1; min-width: 0; display: grid; }
.who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small.free { color: var(--green); }
.who small.busy { color: #d97706; }
.who small.away { color: var(--muted); }
.icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.call-btn { color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.call-btn:hover { background: color-mix(in srgb, var(--green) 22%, transparent); }

.avatar { --h: 210; width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: hsl(var(--h) 55% 45%); }
.avatar.big { width: 96px; height: 96px; font-size: 40px; }

/* ---- Call ---- */
#call { background: #0b0d10; color: #e8eaed; position: relative; overflow: hidden; }
.call-bar { background: transparent; border: 0; justify-content: center; flex-direction: column; gap: 0; color: #fff; }
.call-bar #callTitle { font-weight: 600; }
.call-bar .muted { color: #9aa0a6; font-size: 13px; font-variant-numeric: tabular-nums; }
.tiles { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px; position: relative;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); grid-auto-rows: 1fr; }
.tiles[data-n="0"], .tiles[data-n="1"] { grid-template-columns: 1fr; }
.tile { position: relative; background: var(--tile); border-radius: 14px; overflow: hidden; display: grid; place-items: center; min-height: 0;
  outline: 3px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--green); }
.tile.weak::after { content: "Reconnecting…"; position: absolute; top: 8px; left: 8px; font-size: 12px; background: rgb(0 0 0 / .6); padding: 2px 8px; border-radius: 6px; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.tile.screen video { object-fit: contain; background: #000; }
.tile.video-on video { opacity: 1; }
.tile.video-on .avatar { visibility: hidden; }
.tile.mirror video { transform: scaleX(-1); }
.tile .label { position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 4px; font-size: 13px;
  background: rgb(0 0 0 / .55); padding: 3px 8px; border-radius: 6px; max-width: calc(100% - 16px); }
.tile .label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mute-ico { width: 16px; height: 16px; color: #f87171; display: none; }
.tile.muted .mute-ico { display: block; }
.tile.pip { position: absolute; right: 16px; bottom: 16px; width: clamp(96px, 26vw, 220px); aspect-ratio: 3/4; z-index: 2;
  box-shadow: 0 6px 20px rgb(0 0 0 / .5); }
@media (min-aspect-ratio: 1/1) { .tile.pip { aspect-ratio: 16/9; } }
.tile.pip .avatar.big { width: 48px; height: 48px; font-size: 20px; }
.tile.pip .label { display: none; }

.controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 12px 12px max(14px, env(safe-area-inset-bottom)); }
.ctl { width: 52px; height: 52px; border-radius: 50%; background: var(--ctl); color: #fff; display: grid; place-items: center; position: relative; transition: background .15s; }
.ctl:hover { background: #3a3f4b; }
.ctl.off { background: #e8eaed; color: #111; }
.ctl.on { background: var(--accent); }
.ctl.hang, .round.hang { background: var(--red); color: #fff; }
.ctl.hang { width: 64px; border-radius: 26px; }
.badge { position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); font-size: 11px; display: grid; place-items: center; padding: 0 4px; }

.panel { position: absolute; z-index: 5; right: 0; top: 0; bottom: 0; width: min(360px, 100%); background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; box-shadow: -8px 0 30px rgb(0 0 0 / .35); }
.panel .people { overflow: auto; padding: 0 12px; }
.chat-log { flex: 1; overflow: auto; list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-log li { background: var(--bg); padding: 8px 10px; border-radius: 12px; max-width: 85%; align-self: flex-start; overflow-wrap: anywhere; }
.chat-log li.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
.chat-log b { display: block; font-size: 12px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat-form .icon { color: var(--accent); }

/* ---- Incoming ---- */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .6); display: grid; place-items: center; backdrop-filter: blur(6px); }
.ringing { text-align: center; display: grid; justify-items: center; gap: 4px; width: min(340px, calc(100% - 32px)); }
.ringing h2 { margin: 12px 0 0; }
.row { display: flex; gap: 22px; margin-top: 18px; }
.round { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.round svg { width: 28px; height: 28px; }
.accept { background: var(--green); }
.pulse { animation: pulse 1.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 hsl(var(--h) 55% 45% / .6); } 100% { box-shadow: 0 0 0 26px hsl(var(--h) 55% 45% / 0); } }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #202329; color: #fff; padding: 10px 16px; border-radius: 10px; transition: .2s; z-index: 20; max-width: calc(100% - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  .ctl { width: 46px; height: 46px; } .ctl.hang { width: 58px; }
  .controls { gap: 8px; }
}

.banner { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 10px 12px; margin-bottom: 10px;
  border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-size: 14px; }
.btn.small { padding: 7px 14px; flex: none; }
