:root {
  --bg: #07111f;
  --panel: rgba(10, 21, 38, 0.72);
  --text: #f5f7fb;
  --muted: rgba(233, 240, 255, 0.72);
  --line: rgba(255, 255, 255, 0.08);
  --accent: #5ff2c3;
  --danger: #ff6d74;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius-xl: 28px;
  --radius-md: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(35, 195, 154, 0.24), transparent 32%),
    radial-gradient(circle at 85% 15%, rgba(255, 184, 106, 0.25), transparent 25%),
    linear-gradient(140deg, #050b14 0%, #08162a 54%, #03060e 100%);
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 28px);
  overflow: hidden; /* screens are sized to fit; only the chat log scrolls */
}

/* decorative blobs — fixed so they never affect layout */
.ambient { position: fixed; border-radius: 999px; filter: blur(20px); opacity: 0.3; pointer-events: none; z-index: 0; }
.ambient-one { top: 8%; left: -40px; width: 180px; height: 180px; background: #29e5b0; }
.ambient-two { bottom: 6%; right: 4%; width: 220px; height: 220px; background: #e3a35f; }

.app { position: relative; z-index: 1; width: min(1080px, 100%); }

.hidden { display: none !important; }

/* ───────── shared card / controls ───────── */
.card {
  position: relative;
  padding: clamp(18px, 2.4vw, 26px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent), var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.card-label {
  margin: 0 0 12px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.82rem;
  color: var(--accent);
}

h1, h2, h3, p { margin: 0; }

.card-note { color: var(--muted); line-height: 1.55; font-size: 0.92rem; }

.id-line strong { font-size: clamp(1.4rem, 3.5vw, 2.1rem); letter-spacing: -0.04em; word-break: break-all; }

.field { display: grid; gap: 8px; }
.field span { font-size: 0.9rem; color: var(--muted); }

input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 14px 16px;
  font: inherit;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
input:focus { border-color: rgba(95, 242, 195, 0.7); background: rgba(255, 255, 255, 0.07); }
input:disabled { opacity: 0.5; cursor: not-allowed; }

button {
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
}
button:hover:not(:disabled) { transform: translateY(-2px); }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.primary-button { background: linear-gradient(135deg, var(--accent), #aefbe4); color: #06231a; box-shadow: 0 14px 30px rgba(95, 242, 195, 0.22); }
.secondary-button, .ghost-button { background: rgba(255, 255, 255, 0.06); color: var(--text); border: 1px solid rgba(255, 255, 255, 0.08); }
.danger-button { background: linear-gradient(135deg, #ff8b90, var(--danger)); color: #2f070a; }

.action-row { display: flex; gap: 10px; }
.action-row .primary-button { flex: 1; }

/* ───────── MAIN SCREEN ───────── */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: clamp(16px, 3vh, 28px); }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: "Space Grotesk", sans-serif; font-weight: 700; letter-spacing: 0.18em; font-size: 1.05rem;
}
.brand-dot, .pulse-live {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 rgba(95, 242, 195, 0.5); animation: glow 1.8s infinite;
}

/* Join screen: one cohesive card (name → room → enter), centred and readable. */
.join-card { display: flex; flex-direction: column; gap: 16px; max-width: 460px; margin: 0 auto; width: 100%; }
.join-card .room-row { display: flex; gap: 10px; }
.join-card .room-row input { flex: 1; min-width: 0; }
.join-card .join-submit { width: 100%; margin-top: 2px; }

.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; }
.mini-stats div { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.04); }
.mini-stats span { display: block; margin-bottom: 4px; font-size: 0.78rem; color: var(--muted); }

/* ───────── CALL SCREEN ───────── */
.call-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  height: min(84dvh, 700px);
}
.call-stage { display: flex; flex-direction: column; gap: 14px; overflow: hidden; }
.stage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stage-head h2 { margin-top: 4px; font-size: clamp(1.4rem, 2.6vw, 2.1rem); letter-spacing: -0.04em; }
.pulse-wrap { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.04); color: var(--muted); font-size: 0.85rem; white-space: nowrap; }

.sound-orbit { display: grid; place-items: center; flex: 1; min-height: 0; }
.sound-core {
  position: relative; display: grid; place-items: center;
  width: min(100%, 220px); aspect-ratio: 1; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.24), transparent 34%),
    radial-gradient(circle at center, rgba(95, 242, 195, 0.28), rgba(6, 17, 31, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 30px 60px rgba(4, 10, 20, 0.42);
}
.sound-core strong { position: relative; z-index: 2; width: 74%; text-align: center; font-size: clamp(1.05rem, 1.8vw, 1.5rem); letter-spacing: -0.03em; word-break: break-all; }
.core-ring { position: absolute; inset: -14px; border: 1px solid rgba(95, 242, 195, 0.3); border-radius: 50%; animation: ripple 3s linear infinite; }
.core-ring-delayed { inset: -30px; animation-delay: 1.4s; }

.call-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.call-metrics div { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.04); min-width: 0; }
.call-metrics span { display: block; margin-bottom: 4px; font-size: 0.72rem; color: var(--muted); }
.call-metrics strong { font-size: 0.92rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.call-controls { display: flex; gap: 10px; }
.call-controls button { flex: 1; }

/* chat */
.chat-card { display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.chat-log {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding-right: 4px;
}
.chat-empty { color: var(--muted); font-size: 0.9rem; margin: auto 0; text-align: center; }
.chat-msg {
  max-width: 82%; padding: 9px 13px; border-radius: 16px; font-size: 0.93rem; line-height: 1.4; word-break: break-word;
}
.chat-msg.out { align-self: flex-end; background: linear-gradient(135deg, var(--accent), #aefbe4); color: #06231a; border-bottom-right-radius: 5px; }
.chat-msg.in { align-self: flex-start; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; }
.chat-send { padding-inline: 16px; }

/* ───────── incoming / toast ───────── */
.incoming-sheet { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(3, 8, 18, 0.66); backdrop-filter: blur(12px); z-index: 20; }
.incoming-card { width: min(100%, 420px); padding: 26px; border-radius: 26px; background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(6, 16, 28, 0.96)); border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: var(--shadow); display: grid; gap: 12px; }
.incoming-card h3 { font-size: 1.6rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 24px); padding: 13px 18px; border-radius: 999px; background: rgba(8, 18, 33, 0.92); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--text); opacity: 0; pointer-events: none; transition: transform 0.25s ease, opacity 0.25s ease; z-index: 30; max-width: calc(100% - 32px); text-align: center; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(95, 242, 195, 0.55); } 70% { box-shadow: 0 0 0 14px rgba(95, 242, 195, 0); } 100% { box-shadow: 0 0 0 0 rgba(95, 242, 195, 0); } }
@keyframes ripple { 0% { transform: scale(0.92); opacity: 0.95; } 100% { transform: scale(1.12); opacity: 0; } }

/* ───────── responsive ───────── */
@media (max-width: 820px) {
  body { overflow-y: auto; } /* allow scroll on small screens as a safety net */
  .call-grid { grid-template-columns: 1fr; height: auto; }
  .chat-card { height: 60dvh; }
  .sound-core { width: min(100%, 180px); }
}

/* ── group mesh: participants, room code, chat system line ─────────────────── */
.room-code { font-size: 1.5rem; letter-spacing: 0.04em; word-break: break-all; }
.room-actions { align-items: center; gap: 12px; margin-bottom: 6px; }
.self-tag { font-size: 0.85rem; color: var(--muted, rgba(255,255,255,0.6)); }
.participant-list { list-style: none; margin: 8px 0 4px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.participant { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line, rgba(255,255,255,0.08)); font-size: 0.95rem; }
.participant-self { background: rgba(174, 251, 228, 0.08); border-color: rgba(174, 251, 228, 0.25); }
.participant .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--accent, #46e6b0); }
.participant .dot-off { background: rgba(255, 255, 255, 0.25); }
.participant .dot-on { background: #46e6b0; box-shadow: 0 0 8px rgba(70, 230, 176, 0.6); }
/* Active speaker ("кто говорит"): a soft green ring + a brighter dot. Driven by the
   per-stream WebAudio meter in call-app.mjs (logic in speaking-detect.mjs). The
   transitions are debounced (attack/release) so this doesn't strobe between syllables. */
.participant.speaking { border-color: rgba(70, 230, 176, 0.65); box-shadow: 0 0 0 1px rgba(70, 230, 176, 0.35), 0 0 14px rgba(70, 230, 176, 0.25); transition: box-shadow 0.12s ease, border-color 0.12s ease; }
.participant.speaking .dot { background: #5ff2c3; box-shadow: 0 0 10px rgba(95, 242, 195, 0.85); }
/* Per-peer playback volume: name takes the slack, slider sits compact on the right. */
.participant .participant-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Connection-quality signal bars (driven by quality.mjs via class swap in call-app.mjs).
   3 bars; fill count + colour reflect the level. Greyed bars = the unreached levels. */
/* "Talking while muted" nudge — shown only while you speak into a muted mic. */
.muted-hint { margin: 8px 0 2px; padding: 8px 12px; border-radius: 12px; font-size: 0.88rem;
  color: #fca5a5; background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.35);
  animation: mutepulse 1.4s ease-in-out infinite; }
.muted-hint[hidden] { display: none; }
@keyframes mutepulse { 0%,100% { opacity: 0.75; } 50% { opacity: 1; } }

/* Mic picker (call screen): same visual language as the join-screen fields. */
.mic-field { display: grid; gap: 6px; margin: 10px 0 4px; }
.mic-field[hidden] { display: none; }
.mic-field span { font-size: 0.85rem; color: var(--muted); }
.mic-field select {
  width: 100%; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 12px;
  background: rgba(255, 255, 255, 0.05); color: var(--text); padding: 10px 12px;
  font: inherit; outline: none; cursor: pointer;
}
.mic-field select:focus { border-color: rgba(95, 242, 195, 0.7); }

/* Muted-mic badge — shown when a peer has muted themselves (peer_mute broadcast). */
.participant .muted-badge { flex-shrink: 0; font-size: 0.95rem; line-height: 1; opacity: 0.85; filter: grayscale(0.2); }
.participant .sig { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; flex-shrink: 0; }
.participant .sig i { width: 3px; border-radius: 1px; background: rgba(255, 255, 255, 0.18); }
.participant .sig i:nth-child(1) { height: 5px; }
.participant .sig i:nth-child(2) { height: 8px; }
.participant .sig i:nth-child(3) { height: 11px; }
.participant .sig.sig-good i { background: #46e6b0; }
.participant .sig.sig-fair i:nth-child(1), .participant .sig.sig-fair i:nth-child(2) { background: #f5d76e; }
.participant .sig.sig-poor i:nth-child(1) { background: #f0a868; }
.participant .sig.sig-bad i:nth-child(1) { background: #f87171; }
/* Custom range so the FILL is accurate: native ranges inset the thumb at each end, so
   the accent fill shows a sliver at 0 and grey at 100 ("doesn't go all the way"). Here
   the track is a gradient driven by --pct (set via CSSOM in call-app.mjs — CSP-safe,
   no inline style attribute): empty grey at 0, fully mint at 100. */
.participant .vol {
  -webkit-appearance: none; appearance: none;
  flex-shrink: 0; width: 96px; height: 6px; border-radius: 999px; cursor: pointer;
  --pct: 100;
  background: linear-gradient(to right, #46e6b0 calc(var(--pct) * 1%), rgba(255, 255, 255, 0.16) calc(var(--pct) * 1%));
}
.participant .vol::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%; background: #5ff2c3;
  border: 2px solid #07111f; box-shadow: 0 0 6px rgba(95, 242, 195, 0.55); cursor: pointer;
}
.participant .vol::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: #5ff2c3;
  border: 2px solid #07111f; box-shadow: 0 0 6px rgba(95, 242, 195, 0.55); cursor: pointer;
}
.participant .vol::-moz-range-track { background: transparent; }
.chat-msg.chat-system { align-self: stretch; background: transparent; border: none; color: var(--muted, rgba(255,255,255,0.5)); font-size: 0.82rem; text-align: center; padding: 4px 0; }
.secondary-button.muted { background: rgba(248, 113, 113, 0.18); border-color: rgba(248, 113, 113, 0.4); color: #fca5a5; }
