:root {
  --bg: #0e0f1c;
  --bg-2: #15172a;
  --card: #1a1d33;
  --line: #2a2e4a;
  --text: #eef0ff;
  --muted: #9095b8;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
  --me: #6d4dff;
  --them: #24284a;
  --danger: #ff5d7a;
  --ok: #34d399;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(124, 92, 255, .25), transparent 60%),
    radial-gradient(800px 500px at 110% 10%, rgba(34, 211, 238, .14), transparent 60%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
a { color: var(--accent-2); }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Шапка ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  max-width: 980px; width: 100%; margin: 0 auto;
}
.logo {
  background: none; border: 0; padding: 0;
  font-size: 20px; font-weight: 800; letter-spacing: -.02em;
  display: flex; align-items: center; gap: 8px;
}
.logo-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--grad); color: #fff; font-size: 18px;
}
.online { color: var(--muted); font-size: 14px; display: flex; align-items: center; }
.online .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 8px;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); }
  70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

main { flex: 1; display: flex; width: 100%; max-width: 980px; margin: 0 auto; min-height: 0; }
.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Главная ---------- */
#home { padding: 12px 20px 40px; gap: 18px; max-width: 760px; margin: 0 auto; }
.hero { text-align: center; padding: 18px 0 4px; }
.hero h1 {
  font-size: clamp(30px, 6vw, 48px); line-height: 1.05; margin: 0 0 10px; letter-spacing: -.03em;
  background: linear-gradient(180deg, #fff, #c9cbff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sub { color: var(--muted); margin: 0; font-size: 17px; }

.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
}
.mode-switch button {
  border: 0; background: transparent; padding: 12px; border-radius: 10px; font-weight: 600; color: var(--muted);
  transition: .2s;
}
.mode-switch button.active { background: var(--card); color: var(--text); box-shadow: 0 2px 12px rgba(0, 0, 0, .3); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 18px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field label { display: block; font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.field label small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; transition: .15s;
}
.chip:hover { border-color: #444a78; }
.chip.on { background: var(--grad); border-color: transparent; color: #fff; font-weight: 600; }

.toggle { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; transition: transform .1s, opacity .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--grad); color: #fff; }
.btn-ghost { background: var(--bg-2); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn.big { padding: 18px; font-size: 18px; border-radius: 14px; box-shadow: 0 10px 30px rgba(124, 92, 255, .35); }
.btn.wide { width: 100%; }
.fineprint { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }

/* ---------- Чат ---------- */
#chat { height: calc(100dvh - 60px); padding: 0 12px 12px; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 14px;
}
.status-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.status-dot.searching { background: #fbbf24; animation: blink 1s infinite; }
.status-dot.chatting { background: var(--ok); }
.status-dot.ended { background: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }
#status { font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.head-tools { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); font-size: 18px;
}
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.danger { color: var(--danger); }

.voice-panel {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 22px 16px 16px; background: var(--bg-2); border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.voice-people { display: flex; align-items: center; justify-content: center; gap: 28px; width: 100%; }
.voice-person { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.vp-name { font-size: 13px; color: var(--muted); }
.voice-mid { text-align: center; min-width: 120px; }
.call-timer { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.voice-avatar {
  --lvl: 0;
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 36px;
  background: #2b2f52; transition: transform .08s linear, box-shadow .08s linear;
  transform: scale(calc(1 + var(--lvl) * .18));
  box-shadow: 0 0 0 calc(var(--lvl) * 16px) rgba(124, 92, 255, .28);
}
.voice-avatar.them { background: var(--grad); box-shadow: 0 0 0 calc(var(--lvl) * 16px) rgba(34, 211, 238, .28); }
.voice-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }
.volume { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.volume input { accent-color: var(--accent); width: 120px; }
#mute-btn.off { background: rgba(255, 93, 122, .15); border-color: var(--danger); color: #ffb3c1; }

.mic-row { display: flex; gap: 8px; }
.mic-row select {
  flex: 1; min-width: 0; background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font: inherit;
}
.meter { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; border: 1px solid var(--line); }
#mic-meter { height: 100%; width: 0; background: var(--grad); transition: width .06s linear; }
.mic-check > small { display: block; }
@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(124, 92, 255, .55); }
  70% { box-shadow: 0 0 0 22px rgba(124, 92, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(124, 92, 255, 0); }
}

.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-2); border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
.msg {
  max-width: 78%; padding: 10px 14px; border-radius: 18px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 6px; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 6px; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 13px; text-align: center; padding: 4px 10px; }
.msg.ice {
  align-self: center; text-align: center; max-width: 90%;
  background: rgba(124, 92, 255, .12); border: 1px dashed rgba(124, 92, 255, .5); color: #d9d2ff;
}
.msg.contact { align-self: center; background: rgba(52, 211, 153, .12); border: 1px solid rgba(52, 211, 153, .4); }
.msg time { display: block; font-size: 11px; opacity: .55; margin-top: 2px; text-align: right; }

.searching-anim { align-self: center; margin: auto; text-align: center; color: var(--muted); }
.searching-anim .radar {
  width: 80px; height: 80px; margin: 0 auto 14px; border-radius: 50%;
  border: 2px solid var(--accent); position: relative; animation: ring 1.6s infinite;
}
.searching-anim .radar::after {
  content: ''; position: absolute; inset: 22px; border-radius: 50%; background: var(--grad);
}

.typing {
  background: var(--bg-2); border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  padding: 0 16px 8px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 3px;
}
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; margin-right: 6px; }
@keyframes bounce { 50% { transform: translateY(-4px); } }

.composer {
  display: flex; gap: 8px; padding: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
.composer input {
  flex: 1; min-width: 0; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text);
  padding: 12px 14px; outline: none;
}
.composer input:focus { border-color: var(--accent); }
.composer input:disabled { opacity: .5; }
.btn-next { background: #2b2f52; color: var(--text); min-width: 96px; }
.btn-next.confirm { background: var(--danger); }
.btn-next.highlight { background: var(--grad); color: #fff; }
.send { width: 52px; padding: 0; font-size: 18px; }

/* ---------- Модалки ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 15, .8); backdrop-filter: blur(6px);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal, .dialog {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 26px; max-width: 420px; width: 100%;
  color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal { text-align: center; }
.modal-emoji { font-size: 44px; }
.modal h2 { margin: 8px 0; }
.modal p { color: var(--muted); line-height: 1.5; }
.dialog::backdrop { background: rgba(5, 6, 15, .7); backdrop-filter: blur(4px); }
.dialog h3 { margin: 0 0 6px; }
.dialog input {
  width: 100%; margin: 14px 0; padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--text); outline: none;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.report-reasons { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.report-reasons label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.report-reasons input { accent-color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2b2f52; border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: calc(100% - 32px); text-align: center;
}

@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
  #chat { padding: 0; height: calc(100dvh - 60px); }
  .chat-head { border-radius: 0; border-left: 0; border-right: 0; }
  .messages, .typing, .voice-panel { border-left: 0; border-right: 0; }
  .composer { border-radius: 0; border-left: 0; border-right: 0; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .btn-next { min-width: 76px; padding: 12px; }
  .msg { max-width: 86%; }
  .voice-people { gap: 14px; }
  .voice-avatar { width: 68px; height: 68px; font-size: 30px; }
  .voice-mid { min-width: 96px; }
  .call-timer { font-size: 22px; }
  .voice-panel { padding: 16px 12px 12px; }
}
