:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #111827;
  --muted: #5b6472;
  --line: #e3e7ec;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d7f0ec;
  --ok: #16a34a;
  --danger: #dc2626;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --text: #e6e9ee;
    --muted: #98a1ae;
    --line: #2a313c;
    --accent: #2dd4bf;
    --accent-text: #04201d;
    --accent-soft: #123a36;
    --ok: #22c55e;
    --danger: #f05252;
    --warn-bg: #3a2f10;
    --warn-text: #f5d98b;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { position: relative; max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.home { display: flex; flex-direction: column; min-height: 100%; flex: 1; }
body.in-call { overflow: hidden; }

/* ---------- cards ---------- */
.center { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--muted); }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; }
h1 { font-size: 1.5rem; margin: 0 0 2px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.lead { margin: 0 0 8px; color: var(--muted); }
label { font-size: 0.9rem; font-weight: 600; margin-top: 6px; }
input[type="text"] {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 1.05rem; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; }
.error { color: var(--danger); font-size: 0.92rem; margin: 0; min-height: 1.2em; }
.banner { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 0.92rem; }
.banner p { margin: 0; }
.banner.muted { background: var(--surface-2); color: var(--muted); }
.conn { background: var(--warn-bg); color: var(--warn-text); font-size: 0.88rem; padding: calc(6px + var(--safe-top)) 16px 6px; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); text-decoration: none; min-height: 44px; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); padding: 10px 8px; }
.btn.ghost.danger-text { color: var(--danger); }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

.status { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 4px 0 0; }
.status.ok { color: var(--ok); }
.status.small { font-size: 0.9rem; }
.status svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.countdown { margin: 0; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }

/* ---------- photo ---------- */

/* ---------- people ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; position: relative; flex: none; }
.avatar.photo { background: var(--surface-2); }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar .dot { z-index: 1; }
.avatar.big { width: 112px; height: 112px; font-size: 2.6rem; }
.avatar .dot { position: absolute; right: 2px; bottom: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface); }
.avatar.big .dot { width: 22px; height: 22px; right: 6px; bottom: 6px; border-width: 3px; }
.avatar .dot.off { background: var(--muted); }
.avatar.pulse { animation: wait-pulse 2s ease-out infinite; }
@keyframes wait-pulse { 0% { box-shadow: 0 0 0 0 rgb(15 118 110 / 45%); } 100% { box-shadow: 0 0 0 24px rgb(15 118 110 / 0%); } }
.waiting, .room { align-items: center; text-align: center; }
.waiting .status { justify-content: center; }
.me-photo, .person { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.person h1 { margin-top: 4px; }
.presence { margin: 0; color: var(--muted); font-size: 0.92rem; }
.presence.on { color: var(--ok); }
.review-photo { width: 100%; max-width: 320px; margin: 0 auto; aspect-ratio: 3 / 4; border-radius: 16px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.review-photo img { width: 100%; height: 100%; object-fit: cover; }
.call-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 4px; }
.confirm { width: 100%; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.confirm p { margin: 0 0 10px; }
.confirm .btn:not(.danger) { background: var(--surface); }
.approval { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.approval .btn.ghost { padding-left: 0; }
.empty { color: var(--muted); text-align: center; padding: 36px 24px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); background: #111827; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 0.92rem; z-index: 100; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgb(0 0 0 / 30%); }

body.in-call .toast { bottom: calc(190px + var(--safe-bottom)); }
.btn.ghost { white-space: normal; }

/* ---------- calls ---------- */
#overlay:empty { display: none; }
.call-screen {
  position: fixed; inset: 0; z-index: 50; background: #0b0f14; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(28px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
}
.call-screen video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0b0f14; }
@media (min-width: 700px) and (pointer: fine) {
  /* A laptop window is wider than most phone video: show it whole. */
  .call-screen video.remote { object-fit: contain; }
}
.call-screen:focus { outline: none; }
.call-screen video.local {
  position: absolute; right: 14px; top: calc(14px + var(--safe-top)); width: 28vw; max-width: 160px; aspect-ratio: 3 / 4;
  object-fit: cover; border-radius: 12px; background: #222; box-shadow: 0 4px 16px rgb(0 0 0 / 40%); z-index: 2;
}
.call-screen video.local.mirror { transform: scaleX(-1); }
.call-head { position: relative; z-index: 1; text-align: center; text-shadow: 0 1px 4px rgb(0 0 0 / 50%); }
.call-head .who { font-size: 1.6rem; font-weight: 700; }
.call-head .what { opacity: 0.85; margin-top: 4px; }
.call-mid { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.call-mid .avatar { width: 112px; height: 112px; font-size: 2.6rem; }
.call-mid .note { background: rgb(0 0 0 / 45%); padding: 6px 12px; border-radius: 999px; font-size: 0.9rem; }
.call-screen.has-video .call-mid .avatar { display: none; }
.call-mid .note button { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
.what-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 4px; }
.what-row .what { margin-top: 0; font-variant-numeric: tabular-nums; }
.signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.signal i { width: 4px; border-radius: 1px; background: rgb(255 255 255 / 30%); }
.signal i:nth-child(1) { height: 5px; }
.signal i:nth-child(2) { height: 9px; }
.signal i:nth-child(3) { height: 14px; }
.signal[data-grade="good"] i { background: #4ade80; }
.signal[data-grade="weak"] i:nth-child(-n+2) { background: #fbbf24; }
.signal[data-grade="poor"] i:nth-child(1) { background: #f87171; }
.call-foot { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }
.quality { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.q-ask, .q-choice { border: 0; border-radius: 999px; padding: 9px 16px; font-weight: 600; cursor: pointer; color: #fff; background: rgb(255 255 255 / 18%); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); min-height: 40px; }
.q-ask.yes { box-shadow: inset 0 0 0 2px #4ade80; }
.q-ask.no { box-shadow: inset 0 0 0 2px #fbbf24; }
.q-choices { display: flex; gap: 8px; }
.q-choice.yes { background: var(--ok); }
.q-choice.no { background: #b45309; }
.q-choice:disabled { opacity: 0.5; cursor: default; }
.stats { position: absolute; left: 10px; top: calc(110px + var(--safe-top)); z-index: 4; margin: 0; padding: 8px 10px; border-radius: 8px; background: rgb(0 0 0 / 60%); color: #d1fae5; font: 11px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre; pointer-events: none; }
.controls { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; }
.ctl { width: 60px; height: 60px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: rgb(255 255 255 / 18%); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.ctl svg { width: 28px; height: 28px; fill: currentColor; }
.ctl.off { background: #fff; color: #111; }
.ctl.end { background: var(--danger); }
.ctl.end svg, .rot { transform: rotate(135deg); }
.ctl.answer { background: var(--ok); width: 68px; height: 68px; }
.ctl.decline { background: var(--danger); width: 68px; height: 68px; }
.ctl-label { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 0.85rem; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(34 197 94 / 60%); } 100% { box-shadow: 0 0 0 22px rgb(34 197 94 / 0%); } }
.ctl.answer { animation: pulse 1.4s ease-out infinite; }

@media (min-width: 700px) {
  .center { padding-top: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  .ctl.answer, .spinner, .avatar.pulse { animation: none; }
}
