:root {
  --blue: #1da1f2; --blue2: #1a91da; --ink: #14171a; --muted: #657786; --dim: #aab8c2;
  --line: #e1e8ed; --bg: #ffffff; --bg2: #f5f8fa;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(.2, .7, .1, 1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--sans); font-weight: 400; font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); letter-spacing: .02em; }
.kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; }
.mark { width: 34px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 22px; border: 1px solid currentColor; font-family: var(--mono); font-size: 13px; transition: background .25s, color .25s, border-color .25s, transform .2s var(--ease); }
.btn:active { transform: scale(.97); }
.btn.small { height: 36px; padding: 0 14px; font-size: 12px; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.blue:hover { background: var(--ink); border-color: var(--ink); }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink); }

/* ---------- gate ---------- */
.gate { position: fixed; inset: 0; background: var(--blue); color: #fff; display: flex; align-items: center; padding: 0 clamp(20px, 6vw, 90px); transition: opacity .6s var(--ease), transform .8s var(--ease); z-index: 30; }
.gate.leave { opacity: 0; transform: translateY(-4%); pointer-events: none; }
#gateFx { position: absolute; inset: 0; width: 100%; height: 100%; }
.gate .brand { position: absolute; top: 22px; left: clamp(20px, 6vw, 90px); display: flex; align-items: center; gap: 10px; font-size: 18px; letter-spacing: -.02em; }
.gate .brand em { font-style: normal; opacity: .65; }
.gate-box { position: relative; max-width: 560px; }
.gate h1 { font-weight: 300; font-size: clamp(46px, 7.4vw, 104px); line-height: .98; letter-spacing: -.035em; margin: 20px 0 22px; }
.gate .lead { font-size: clamp(15px, 1.3vw, 18px); max-width: 28em; opacity: .92; font-weight: 300; }
.gate-cta { display: flex; gap: 12px; flex-wrap: wrap; margin: 32px 0 26px; }
.gate .btn.solid { background: #fff; color: var(--blue); border-color: #fff; }
.gate .btn.solid:hover { background: var(--ink); border-color: var(--ink); color: #fff; }
.gate .btn:not(.solid):hover { background: rgba(255, 255, 255, .16); }
.gate .note { font-size: 11px; opacity: .78; text-transform: uppercase; letter-spacing: .1em; }
.gate-box > * { opacity: 0; transform: translateY(18px); animation: rise .9s var(--ease) forwards; }
.gate-box > :nth-child(2) { animation-delay: .08s; } .gate-box > :nth-child(3) { animation-delay: .16s; }
.gate-box > :nth-child(4) { animation-delay: .24s; } .gate-box > :nth-child(5) { animation-delay: .32s; }
@keyframes rise { to { opacity: 1; transform: none; } }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 78px 340px 1fr; height: 100vh; height: 100dvh; animation: fade .6s var(--ease); }
@keyframes fade { from { opacity: 0; } }
.app.wide { grid-template-columns: 78px 1fr; }
.app.wide .list { display: none; }
.rail { background: var(--blue); color: #fff; display: flex; flex-direction: column; align-items: center; padding: 18px 0; gap: 6px; }
.rail-brand { margin-bottom: 22px; }
.tab { width: 62px; padding: 10px 0 8px; display: grid; justify-items: center; gap: 5px; font-size: 10.5px; font-family: var(--mono); opacity: .72; transition: opacity .2s, background .2s; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.tab:hover { opacity: 1; }
.tab.on { opacity: 1; background: rgba(255, 255, 255, .2); }
.tab.out { margin-top: auto; }

.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.list-head { padding: 20px 20px 14px; border-bottom: 1px solid var(--line); }
.list-head h2 { font-weight: 400; font-size: 22px; letter-spacing: -.02em; display: flex; justify-content: space-between; align-items: center; }
.field { display: flex; margin-top: 14px; border: 1px solid var(--line); transition: border-color .2s; }
.field:focus-within { border-color: var(--blue); }
.field input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 0; outline: 0; background: none; font-family: var(--mono); font-size: 12.5px; }
.field button { padding: 0 14px; font-family: var(--mono); font-size: 12px; color: var(--blue); }
.items { overflow-y: auto; flex: 1; }
.item { width: 100%; display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 14px 20px; text-align: left; border-bottom: 1px solid var(--line); position: relative; transition: background .2s; animation: itemIn .5s var(--ease) backwards; }
@keyframes itemIn { from { opacity: 0; transform: translateX(-10px); } }
.item:hover { background: var(--bg2); }
.item.on { background: #e8f5fe; }
.item.on::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue); }
.item b { font-weight: 500; display: block; }
.item small { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.item .meta { font-family: var(--mono); font-size: 10.5px; color: var(--dim); text-align: right; display: grid; gap: 6px; justify-items: end; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; background: var(--blue); color: #fff; font-size: 10.5px; display: grid; place-items: center; border-radius: 9px; }
.item > div { min-width: 0; }

.avatar { width: 44px; height: 44px; background: var(--bg2); border: 1px solid var(--line); flex: none; display: grid; }
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.sm { width: 34px; height: 34px; }
.avatar.xl { width: 112px; height: 112px; border-color: rgba(255, 255, 255, .6); background: #fff; }

/* ---------- conversation ---------- */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg2); position: relative; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.empty h3 { font-weight: 300; font-size: 34px; letter-spacing: -.03em; color: var(--ink); margin-bottom: 8px; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 14px 22px; background: var(--bg); border-bottom: 1px solid var(--line); }
.conv-head .who { flex: 1; min-width: 0; }
.conv-head .who b { font-weight: 500; display: block; }
.conv-head .who small { font-family: var(--mono); font-size: 11.5px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; font-size: 20px; padding: 4px 8px 4px 0; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); transition: border-color .2s, background .2s, color .2s; }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.icon-btn:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
.thread { flex: 1; overflow-y: auto; padding: 24px 22px; display: flex; flex-direction: column; gap: 10px; }
.sys { align-self: center; font-family: var(--mono); font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; padding: 6px 0; }
.msg { max-width: min(74%, 560px); padding: 11px 15px; background: var(--bg); border: 1px solid var(--line); word-break: break-word; animation: msgIn .45s var(--ease) backwards; }
@keyframes msgIn { from { opacity: 0; transform: translateY(12px); } }
.msg.me { align-self: flex-end; background: var(--blue); border-color: var(--blue); color: #fff; }
.msg.them { align-self: flex-start; }
.msg .from { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--blue); margin-bottom: 3px; }
.msg time { display: block; font-family: var(--mono); font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }
.msg.cipher span.t { font-family: var(--mono); font-size: 12.5px; opacity: .8; }
.typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 14px 15px; background: var(--bg); border: 1px solid var(--line); }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: typing 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }
.composer { display: flex; gap: 10px; padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; height: 46px; padding: 0 14px; border: 1px solid var(--line); outline: 0; background: var(--bg2); transition: border-color .2s, background .2s; }
.composer input:focus { border-color: var(--blue); background: var(--bg); }

/* ---------- rooms / profile panels ---------- */
.panel { padding: clamp(22px, 4vw, 54px); overflow-y: auto; flex: 1; }
.panel h3 { font-weight: 300; font-size: clamp(30px, 3.4vw, 46px); letter-spacing: -.03em; line-height: 1.05; margin: 12px 0 10px; }
.panel p.sub { color: var(--muted); max-width: 34em; margin-bottom: 26px; }
.stagebox { background: var(--blue); color: #fff; padding: 26px; position: relative; overflow: hidden; }
.stagebox canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; }
.stagebox > * { position: relative; }
.speakers { display: flex; flex-wrap: wrap; gap: 18px; margin: 22px 0; }
.spk { display: grid; justify-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; }
.spk .avatar { width: 64px; height: 64px; background: #fff; border: 2px solid transparent; transition: border-color .2s, transform .2s; }
.spk.talk .avatar { border-color: #fff; transform: scale(1.07); box-shadow: 0 0 0 5px rgba(255, 255, 255, .28); }
.rowlist { border-top: 1px solid var(--line); background: var(--bg); }
.rowlist li { list-style: none; display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.rowlist small { color: var(--muted); display: block; }
.kv { background: var(--bg); border: 1px solid var(--line); margin-bottom: 18px; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid var(--line); align-items: center; }
.kv > div:last-child { border-bottom: 0; }
.kv span { color: var(--muted); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.kv code { font-family: var(--mono); font-size: 13px; word-break: break-all; text-align: right; }
.claim { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.claim .field { margin: 0; flex: 1; min-width: 220px; background: var(--bg); }
.claim .field em { align-self: center; padding-right: 12px; font-style: normal; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.lock { color: var(--muted); font-family: var(--mono); font-size: 11px; }

/* ---------- call overlay ---------- */
.callx { position: fixed; inset: 0; z-index: 40; background: var(--blue); color: #fff; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 26px 20px calc(34px + env(safe-area-inset-bottom)); animation: callIn .5s var(--ease); }
@keyframes callIn { from { opacity: 0; transform: scale(1.04); } }
#callFx { position: absolute; inset: 0; width: 100%; height: 100%; }
.callx > * { position: relative; }
.callx-top { width: 100%; display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; }
.callx-mid { text-align: center; display: grid; justify-items: center; gap: 14px; }
.callx-mid h2 { font-weight: 300; font-size: clamp(34px, 5vw, 60px); letter-spacing: -.03em; }
.callx-mid p { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; }
.callx-ctl { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ctl { height: 46px; padding: 0 22px; border: 1px solid rgba(255, 255, 255, .7); font-family: var(--mono); font-size: 13px; transition: background .2s, color .2s, border-color .2s; }
.ctl:hover { background: rgba(255, 255, 255, .18); }
.ctl.on { background: #fff; color: var(--blue); border-color: #fff; }
.ctl.end { background: #e0245e; border-color: #e0245e; }
.ctl.end:hover { background: #c81e52; }

.toast { position: fixed; left: 50%; bottom: 26px; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 12px 18px; transition: opacity .3s, transform .4s var(--ease); white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phone ---------- */
@media (max-width: 860px) {
  .app, .app.wide { grid-template-columns: 1fr; grid-template-rows: 1fr 62px; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 0 6px calc(env(safe-area-inset-bottom)); }
  .rail-brand { display: none; }
  .tab { width: auto; flex: 1; padding: 8px 0 6px; }
  .tab.out { margin: 0; }
  .list { grid-row: 1; border-right: 0; }
  .main { position: fixed; inset: 0 0 62px 0; z-index: 10; transform: translateX(100%); transition: transform .45s var(--ease); }
  .app.open .main { transform: none; }
  .app.wide .list { display: none; }
  .app.wide .main { transform: none; position: static; grid-row: 1; }
  .back { display: block; }
  .conv-head { padding: 12px 14px; gap: 8px; }
  .conv-head .btn.small { padding: 0 10px; }
  .msg { max-width: 86%; }
  .toast { white-space: normal; width: max-content; max-width: 88vw; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; transition-duration: .01s !important; }
}

/* ---------- real calls + relay state ---------- */
#rv { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; background: #0b6fb0; }
.callx.video #rv { opacity: 1; }
.callx.video #callFx, .callx.video .avatar.xl { display: none; }
#lv { position: absolute; right: 18px; top: 58px; width: min(26vw, 190px); aspect-ratio: 4 / 3; object-fit: cover; border: 2px solid #fff; display: none; transform: scaleX(-1); }
.callx.video #lv { display: block; }
.callx.video .callx-mid h2, .callx.video .callx-mid p, .callx.video .callx-top { text-shadow: 0 1px 12px rgba(0, 0, 0, .45); }
.state { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); margin-right: 7px; vertical-align: middle; }
.state.on { background: #17bf63; }
.msg.failed { opacity: .55; }
.gate .btn:disabled { opacity: .6; cursor: wait; }

.mark .far { opacity: .55; }
