:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #8b93a3;
  --accent: #7c6cff;
  --accent-2: #9a8dff;
  --green: #2ecc71;
  --red: #ff4d5e;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 22px; margin: 22px 0 6px; text-align: center; }
h2 { font-size: 22px; margin: 4px 0 4px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--red); text-align: center; margin-top: 16px; }
.ok { color: var(--green); text-align: center; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 520px; margin: 0 auto; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 16px; font-size: 13px; color: var(--muted); }
.topbar b { color: var(--text); }
.stat { display: flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); margin-right: 2px; }
.chip { margin-left: auto; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 11px; font-weight: 700; letter-spacing: .05em; }

main { flex: 1; overflow-y: auto; padding: 0 16px 24px; }
.tab { display: none; }
.tab.active { display: block; }
.view { display: none; flex-direction: column; align-items: center; padding-top: 6vh; text-align: center; }
.view.active { display: flex; }

/* ---------- idle ---------- */
.mic-btn {
  width: 128px; height: 128px; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 0 #5848d6, 0 20px 40px rgba(124, 108, 255, .35);
  display: grid; place-items: center; transition: transform .12s, box-shadow .12s;
}
.mic-btn:active { transform: translateY(6px); box-shadow: 0 4px 0 #5848d6, 0 10px 20px rgba(124, 108, 255, .3); }
.mic-btn svg { width: 54px; height: 54px; color: #fff; }

.segmented { display: inline-flex; margin-top: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.segmented button { padding: 8px 16px; border-radius: 999px; color: var(--muted); font-size: 14px; }
.segmented button.on { background: var(--surface-2); color: var(--text); }

/* ---------- searching ---------- */
.radar { position: relative; width: 160px; height: 160px; display: grid; place-items: center; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: pulse 2.4s infinite; }
.radar span:nth-child(2) { animation-delay: .8s; }
.radar span:nth-child(3) { animation-delay: 1.6s; }
.radar-core { width: 84px; height: 84px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; color: #fff; }
.radar-core svg { width: 36px; height: 36px; }
@keyframes pulse { from { transform: scale(.5); opacity: .9; } to { transform: scale(1.25); opacity: 0; } }

/* ---------- buttons ---------- */
.btn { width: 100%; max-width: 360px; padding: 14px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; margin-top: 18px; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); margin-top: 10px; }
.link { color: var(--accent-2); font-weight: 600; padding: 6px 0; }
.link.danger { color: var(--red); font-weight: 500; font-size: 14px; }
.round { width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 26px; }
.round.red { background: var(--red); border-color: var(--red); color: #fff; }
.round.off { background: #fff; border-color: #fff; color: var(--red); }
.round.picked { border-color: var(--accent); background: rgba(124, 108, 255, .2); }

/* ---------- call ---------- */
.partner { display: flex; flex-direction: column; align-items: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; position: relative; }
.avatar.big { width: 96px; height: 96px; font-size: 36px; background: linear-gradient(145deg, #3a3f4d, #262a34); }
.ring { position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--green); opacity: 0; transition: opacity .1s, transform .1s; }
.p-name { font-size: 20px; font-weight: 700; margin-top: 12px; }
.p-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tag { background: var(--surface-2); border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text); }
.conn { font-size: 13px; color: var(--muted); margin-top: 8px; }
.conn.good { color: var(--green); }
.conn.bad { color: var(--red); }
.timer { font-size: 40px; font-weight: 300; font-variant-numeric: tabular-nums; margin: 18px 0 10px; }
.timer.low { color: var(--red); }
.topic-card { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: left; }
.topic-title { font-weight: 700; margin-bottom: 8px; }
.topic-q { color: var(--muted); min-height: 44px; }
.call-actions { display: flex; gap: 40px; margin-top: 22px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.action-label { font-size: 12px; color: var(--muted); }
.round .ic-off { display: none; }
.round.off .ic-on { display: none; }
.round.off .ic-off { display: block; }
.muted-banner { margin: 16px 0 0; padding: 8px 14px; border-radius: 999px; background: rgba(255, 77, 94, .15); color: var(--red); font-size: 13px; }
.muted-banner[hidden] { display: none; }

/* ---------- ended ---------- */
.card { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 16px; }
.card p { margin: 0 0 12px; }
.rate-btns { display: flex; justify-content: center; gap: 24px; margin-bottom: 8px; }
.reasons { display: grid; gap: 8px; }
.reasons button { text-align: left; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }

/* ---------- topics / lists ---------- */
.list { display: grid; gap: 8px; margin-top: 14px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.item-head { display: flex; align-items: center; gap: 10px; font-weight: 600; width: 100%; text-align: left; }
.item-head small { margin-left: auto; color: var(--muted); font-weight: 400; }
.item ul { margin: 10px 0 2px; padding-left: 20px; color: var(--muted); }
.item.flash { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 108, 255, .25); }
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.row .grow div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row small { color: var(--muted); }

/* ---------- profile ---------- */
.profile-head { display: flex; flex-direction: column; align-items: center; padding-top: 8px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 20px; }
.stats-grid div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 4px; text-align: center; }
.stats-grid b { display: block; font-size: 20px; }
.stats-grid span { font-size: 11px; color: var(--muted); }
.levels { display: flex; flex-wrap: wrap; gap: 8px; }
.levels button { padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; text-transform: capitalize; }
.levels button.on { border-color: var(--accent); background: rgba(124, 108, 255, .18); }
.invite-row { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.invite-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }

/* ---------- tab bar ---------- */
.tabbar { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: var(--surface); padding-bottom: var(--safe-bottom); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0 8px; font-size: 11px; color: var(--muted); }
.tabbar button.on { color: var(--accent-2); }
.tabbar.locked { pointer-events: none; opacity: .4; }

/* ---------- level sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px 20px 0 0; padding: 18px 16px calc(24px + var(--safe-bottom)); }
.sheet h3 { margin-top: 0; }
