:root {
  --bg: #dfe7f0;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --line: #dfe3ea;
  --line-strong: #c6ccd7;
  --text: #16181d;
  --text-dim: #6c7280;
  --text-faint: #9aa0ac;
  --blue: #2f76d2;
  --blue-dark: #245fac;
  --blue-tint: #e9f1fb;
  --green: #45b34a;
  --danger: #e2504d;
  --stop: #dd9296;
  --danger-tint: #fdeceb;
  --stage: #1b1c1e;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { overflow: hidden; }

.sprite { display: none; }
.hidden { display: none !important; }
.muted { color: var(--text-dim); font-size: 13.5px; margin: 0; }

.ic {
  width: 24px; height: 24px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-14 { width: 14px; height: 14px; stroke-width: 2.2; }
.ic-16 { width: 16px; height: 16px; stroke-width: 1.9; }
.ic-18 { width: 18px; height: 18px; }
.ic-20 { width: 20px; height: 20px; }
.ic-32 { width: 44px; height: 44px; stroke-width: 1.3; }

/* ══ main screen: stage / middle / dock ══ */
.screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── stage ── */
.stage {
  position: relative;
  flex: 0 0 auto;
  height: 46vh;
  min-height: 230px;
  background: var(--stage);
  overflow: hidden;
}
.remote-video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: var(--stage);
  display: none;
}
.state-live .remote-video { display: block; }

.stage-gear {
  position: absolute; top: 10px; left: 10px;
  z-index: 4;
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,0.14);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}
.state-live .stage-gear { display: none; }

.stage-idle, .stage-search {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  color: #fff;
  padding: 14px;
}
.state-idle .stage-search,
.state-search .stage-idle,
.state-live .stage-idle,
.state-live .stage-search { display: none; }

.stage-logo { color: #fff; opacity: 0.95; }
.stage-idle h1 { margin: 2px 0 0; font-size: 27px; font-weight: 700; letter-spacing: -0.3px; }
.online-line { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 13.5px; color: #cfd3da; }
.online-line b { color: #fff; font-weight: 600; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

.stage-filters { display: flex; gap: 10px; margin-top: 14px; }
.filter-btn {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 1px;
  min-width: 118px;
  padding: 8px 14px;
  border: none;
  border-radius: 999px;
  background: #e9ebef;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.filter-btn:active { background: #dcdfe4; }
.filter-label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }
.filter-value { font-size: 14px; font-weight: 600; }

.search-rings { position: relative; width: 84px; height: 84px; margin-bottom: 6px; }
.search-rings span {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.45);
  animation: radar 2.4s ease-out infinite;
}
.search-rings span:nth-child(2) { animation-delay: 0.8s; }
.search-rings span:nth-child(3) { animation-delay: 1.6s; }
@keyframes radar { 0% { transform: scale(0.35); opacity: 0.9; } 100% { transform: scale(1); opacity: 0; } }
.stage-search p { margin: 0; font-size: 14.5px; }
.search-timer { font-size: 13px; color: #b9bec7; font-variant-numeric: tabular-nums; }

.stage-live-top {
  position: absolute; top: 0; left: 0; right: 0;
  z-index: 2;
  display: none;
  align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 10px;
}
.state-live .stage-live-top { display: flex; }

/* NOTE: nothing layered over live video uses backdrop-filter — compositing a
   blur pass over decoding video frames collapses framerate on mid-range
   Android. Solid fills only, here. */
.peer-chip {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
  background: rgba(255,255,255,0.94);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
}
.peer-chip-body { min-width: 0; display: flex; flex-direction: column; }
.peer-chip-body strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-chip-body span { font-size: 11px; color: var(--text-dim); }

.conn-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.94);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.conn-badge i { font-style: normal; font-size: 10.5px; color: var(--text-faint); }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: #e0a83c; }
.conn-dot.live { background: var(--green); }
.conn-dot.dead { background: var(--danger); }

.video-controls {
  position: absolute; right: 10px; bottom: 10px;
  z-index: 3;
  display: none;
  flex-direction: column; gap: 8px;
}
.state-live .video-controls { display: flex; }
.mini-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.94);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
}
.mini-btn.mini-btn-off { background: var(--danger); color: #fff; }

.stage-status {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  background: rgba(255,255,255,0.95);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 12.5px;
}
.unmute-cta {
  position: absolute; left: 50%; bottom: 12px;
  transform: translateX(-50%);
  z-index: 4;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: none; border-radius: 999px;
  background: var(--blue); color: #fff;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}

/* ── middle ── */
.middle {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 0;
  overflow: hidden;
}
.info-card {
  display: flex; gap: 11px;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 13px 14px;
}
.info-ic { color: var(--blue); flex: 0 0 auto; }
.info-card p { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--text); }
.info-card b { color: var(--blue); font-weight: 600; }
.state-live .info-card { display: none; }

.chat-messages {
  display: none;
  flex: 1; min-height: 0;
  overflow-y: auto;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 4px;
}
.state-live .chat-messages { display: flex; }
.chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.38;
  word-wrap: break-word;
}
.chat-bubble time { display: block; font-size: 10px; opacity: 0.6; margin-top: 2px; text-align: right; }
.chat-bubble.mine { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.theirs { align-self: flex-start; background: var(--surface); color: var(--text); border-bottom-left-radius: 4px; }
.chat-bubble.system { align-self: center; background: transparent; color: var(--text-dim); font-size: 11.5px; padding: 2px 8px; }
.chat-bubble.system time { display: none; }

.typing { display: flex; align-items: center; gap: 7px; padding: 2px 4px 4px; font-size: 11.5px; color: var(--text-dim); }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint); animation: typeBounce 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typeBounce { 0%,60%,100% { opacity: 0.35; } 30% { opacity: 1; } }

/* ── dock: self view + input + actions ── */
.dock {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-b));
}
.self-wrap {
  position: relative;
  width: 104px;
  flex: 0 0 auto;
  aspect-ratio: 3 / 4;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #22242a;
}
.self-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.self-off {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: #22242a;
  color: #8b909c;
}
.self-flip {
  position: absolute; top: 5px; left: 5px;
  width: 26px; height: 26px;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,0.42);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}
.self-level {
  position: absolute; left: 6px; right: 6px; bottom: 6px;
  height: 4px; border-radius: 999px;
  background: rgba(255,255,255,0.28);
  overflow: hidden;
}
.self-level span { display: block; height: 100%; width: 0%; background: var(--green); transition: width 0.08s linear; }
.self-wrap.mic-off .self-level span { background: var(--danger); }

.dock-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }

.chat-input-row { display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 999px; padding: 4px 6px 4px 14px; }
.chat-input-row input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: none;
  font-family: inherit; font-size: 15px; color: var(--text);
  padding: 8px 0;
}
.chat-input-row input::placeholder { color: var(--text-faint); }
.chat-send-btn {
  width: 36px; height: 36px;
  flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: none;
  color: var(--blue);
  display: grid; place-items: center;
  cursor: pointer;
}
.chat-send-btn:disabled { color: var(--text-faint); }

.action-row { display: flex; gap: 10px; flex: 1; }
.action-btn {
  flex: 1;
  border: none;
  border-radius: var(--r-md);
  padding: 13px 8px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
.action-btn:active { opacity: 0.9; }
.action-stop { background: var(--stop); }
.action-start { background: var(--blue); }
.action-btn:disabled { opacity: 0.5; }

/* ══ settings page ══ */
.settings-page {
  position: fixed; inset: 0;
  z-index: 25;
  background: var(--bg);
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px 9px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 16px; font-weight: 650; margin: 0; }
.topbar-spacer { width: 36px; }
.icon-btn {
  width: 36px; height: 36px;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer;
}
.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 14px;
}

.avatar {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--blue-tint);
  display: grid; place-items: center;
  font-weight: 650; font-size: 17px;
  color: var(--blue);
  overflow: hidden;
  background-size: cover; background-position: center;
}
.avatar.has-photo span { display: none; }
.avatar-sm { width: 30px; height: 30px; font-size: 13px; }
.avatar-lg { width: 66px; height: 66px; font-size: 24px; }
.avatar-block { display: flex; align-items: center; gap: 14px; }
.avatar-meta strong { display: block; font-size: 16px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-row { display: flex; align-items: center; justify-content: space-between; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.label-with-ic { display: inline-flex; align-items: center; gap: 6px; }
.field-hint { font-size: 12px; color: var(--text-faint); }
.range-value { font-size: 13px; font-weight: 650; }

input[type="number"] {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit; font-size: 16px; font-weight: 500;
}
input[type="number"]:focus { outline: none; border-color: var(--blue); }

.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice-grid-3 { grid-template-columns: repeat(3, 1fr); }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 13px 8px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-family: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer;
}
.choice.active { color: var(--blue-dark); background: var(--blue-tint); border-color: var(--blue); }

.range-stack { position: relative; height: 32px; }
.range-track { position: absolute; top: 14px; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--line-strong); }
.range-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--blue); }
.range-stack input[type="range"] {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 32px; margin: 0;
  background: none; -webkit-appearance: none; appearance: none;
  pointer-events: none;
}
.range-stack input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2px solid var(--blue);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  cursor: pointer;
}
.range-stack input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2px solid var(--blue);
}

.consent {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 13px;
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
}
.consent input { position: absolute; opacity: 0; pointer-events: none; }
.consent-box {
  width: 21px; height: 21px; flex: 0 0 auto;
  border-radius: 6px;
  border: 1.5px solid var(--line-strong);
  display: grid; place-items: center;
  color: transparent; background: var(--surface);
}
.consent input:checked + .consent-box { background: var(--blue); border-color: var(--blue); color: #fff; }
.consent-text { font-size: 13px; color: var(--text-dim); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

.btn {
  border: none; border-radius: var(--r-md);
  padding: 12px 18px;
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--text);
}
.btn-block { width: 100%; }
.btn-lg { padding: 14px 20px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.45; }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); color: var(--text-dim); }
.btn-danger { background: var(--danger); color: #fff; }

/* ══ sheets ══ */
.sheet-overlay { position: fixed; inset: 0; z-index: 30; background: rgba(20,22,28,0.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 10px 16px calc(18px + var(--safe-b));
  display: flex; flex-direction: column; gap: 9px;
}
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0 auto 4px; }
.sheet h3 { margin: 0 0 2px; font-size: 16px; font-weight: 650; }
.sheet-item {
  display: flex; align-items: center; gap: 12px;
  text-align: left; width: 100%;
  padding: 12px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
.sheet-item strong { display: block; font-size: 14.5px; font-weight: 600; }
.sheet-item em { display: block; font-style: normal; font-size: 12px; color: var(--text-dim); }
.sheet-item-danger { color: var(--danger); }
.sheet-item-danger em { color: #b07472; }
.sheet-actions { display: flex; gap: 9px; }
.sheet-actions .btn { flex: 1; }

.radio-list { display: flex; flex-direction: column; gap: 7px; }
.radio-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 12px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer;
}
.radio-dot { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.radio-item.active { color: var(--blue-dark); border-color: var(--blue); background: var(--blue-tint); }
.radio-item.active .radio-dot { border-color: var(--blue); border-width: 5px; }

.toast {
  position: fixed;
  bottom: calc(96px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  max-width: 88%;
  background: #23262e;
  color: #fff;
  padding: 10px 17px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}

@media (prefers-reduced-motion: reduce) {
  .search-rings span, .typing-dots i { animation: none !important; }
}

@media (max-height: 640px) {
  .stage { height: 40vh; min-height: 190px; }
  .self-wrap { width: 92px; }
  .stage-idle h1 { font-size: 23px; }
  .ic-32 { width: 36px; height: 36px; }
}
