:root {
  color-scheme: dark;
  --bg: #070914;
  --panel: rgba(16, 20, 38, 0.78);
  --panel-strong: rgba(20, 25, 48, 0.94);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f6ff;
  --muted: #9ba6c8;
  --accent: #795cff;
  --accent-2: #26d6d1;
  --green: #43e59a;
  --red: #ff647c;
  --warning: #ffc857;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.44);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(121, 92, 255, 0.23), transparent 42%),
    linear-gradient(145deg, #070914 0%, #090d1c 58%, #060810 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  z-index: 0;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.18;
  pointer-events: none;
}
.ambient-one { top: 15%; left: -220px; background: var(--accent); }
.ambient-two { right: -220px; bottom: 0; background: var(--accent-2); }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(26px, env(safe-area-inset-top)) 0 max(34px, env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 34px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(121, 92, 255, 0.95), rgba(54, 44, 127, 0.85));
  box-shadow: 0 11px 34px rgba(121, 92, 255, 0.3);
  font-size: 24px;
  font-weight: 900;
}
.brand-name { font-size: 18px; font-weight: 850; letter-spacing: 0.08em; }
.brand-name span { color: #9d8aff; }
.brand-subtitle { margin-top: 4px; color: var(--muted); font-size: 12px; }

.panel {
  border: 1px solid var(--border);
  border-radius: 25px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.lobby-panel {
  width: min(590px, 100%);
  margin: 7vh auto 0;
  padding: clamp(25px, 5vw, 48px);
}

.invite-badge {
  display: inline-flex;
  margin-bottom: 17px;
  padding: 7px 11px;
  border: 1px solid rgba(38, 214, 209, 0.25);
  border-radius: 999px;
  background: rgba(38, 214, 209, 0.09);
  color: #8af2ed;
  font-size: 12px;
  font-weight: 750;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 13px; font-size: clamp(30px, 6vw, 48px); line-height: 1.05; letter-spacing: -0.045em; }
h2 { margin-bottom: 8px; font-size: 30px; letter-spacing: -0.03em; }
h3 { margin-bottom: 8px; }
.lead { max-width: 470px; margin-bottom: 30px; color: var(--muted); font-size: 16px; line-height: 1.6; }

label {
  display: block;
  margin-bottom: 8px;
  color: #cdd4ed;
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 14px;
  outline: none;
  background: rgba(4, 7, 17, 0.58);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
input::placeholder { color: #697492; }
input:focus {
  border-color: rgba(121, 92, 255, 0.75);
  background: rgba(8, 10, 25, 0.84);
  box-shadow: 0 0 0 4px rgba(121, 92, 255, 0.12);
}

.primary-button, .secondary-button, .control-button {
  border: 0;
  cursor: pointer;
  color: white;
  font-weight: 760;
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease, border-color 140ms ease;
}
.primary-button:hover, .secondary-button:hover, .control-button:hover { filter: brightness(1.08); }
.primary-button:active, .secondary-button:active, .control-button:active { transform: translateY(1px) scale(0.993); }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 55px;
  margin-top: 15px;
  border-radius: 15px;
  background: linear-gradient(135deg, #7358ff, #9276ff);
  box-shadow: 0 13px 34px rgba(115, 88, 255, 0.26);
}
.button-icon { font-size: 19px; }

.secondary-button {
  min-width: 105px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.075);
}
.code-row { display: flex; gap: 10px; }
.divider {
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 25px 0 15px;
  color: #697492;
  font-size: 12px;
}
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: rgba(255, 255, 255, 0.08); }

.room-preview {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 13px;
}
.room-preview strong { color: #b8aaff; letter-spacing: 0.06em; }

.privacy-note { margin: 24px 0 0; color: #77819d; font-size: 12px; line-height: 1.55; }

.message {
  margin-top: 16px;
  padding: 13px 15px;
  border-radius: 13px;
  font-size: 13px;
  line-height: 1.5;
}
.error-message { border: 1px solid rgba(255, 100, 124, 0.25); background: rgba(255, 100, 124, 0.1); color: #ffb1bd; }
.warning-message { border: 1px solid rgba(255, 200, 87, 0.23); background: rgba(255, 200, 87, 0.09); color: #ffe0a0; }
.warning-message button { margin-left: 8px; border: 0; background: transparent; color: white; text-decoration: underline; cursor: pointer; }

.connecting-panel {
  width: min(520px, 100%);
  margin: 13vh auto 0;
  padding: 48px;
  text-align: center;
}
.connecting-panel p { color: var(--muted); }
.pulse-loader { display: flex; justify-content: center; gap: 8px; margin-bottom: 24px; }
.pulse-loader span { width: 10px; height: 10px; border-radius: 50%; background: #8e75ff; animation: pulse 1s infinite ease-in-out; }
.pulse-loader span:nth-child(2) { animation-delay: 0.13s; }
.pulse-loader span:nth-child(3) { animation-delay: 0.26s; }
@keyframes pulse { 0%, 100% { transform: translateY(0); opacity: 0.35; } 50% { transform: translateY(-8px); opacity: 1; } }

.voice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 315px;
  gap: 18px;
}
.room-main { min-height: 660px; padding: clamp(20px, 4vw, 34px); }
.room-sidebar { align-self: start; padding: 25px; }
.room-topbar, .participants-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.eyebrow { margin-bottom: 8px; color: #8674dc; font-size: 10px; font-weight: 850; letter-spacing: 0.16em; }
.connection-pill { padding: 7px 11px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.connection-pill.connecting { background: rgba(255, 200, 87, 0.1); color: #ffd77b; }
.connection-pill.connected { background: rgba(67, 229, 154, 0.1); color: #75f1b7; }
.connection-pill.reconnecting { background: rgba(255, 200, 87, 0.1); color: #ffd77b; }
.connection-pill.disconnected { background: rgba(255, 100, 124, 0.1); color: #ff9aaa; }

.participants-heading { margin: 38px 0 14px; }
.participants-heading h3 { margin: 0; font-size: 14px; }
.participants-heading span { display: grid; place-items: center; min-width: 25px; height: 25px; padding: 0 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); color: #aeb7d2; font-size: 12px; }
.participants-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
.participant-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 162px;
  padding: 20px 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 18px;
  background: rgba(4, 7, 17, 0.4);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.participant-card.speaking { border-color: rgba(67, 229, 154, 0.58); box-shadow: 0 0 0 3px rgba(67, 229, 154, 0.08), inset 0 0 35px rgba(67, 229, 154, 0.045); transform: translateY(-2px); }
.avatar {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(121, 92, 255, 0.6), rgba(38, 214, 209, 0.22));
  font-size: 23px;
  font-weight: 900;
  text-transform: uppercase;
}
.participant-name { max-width: 100%; overflow: hidden; color: #edf0ff; font-size: 14px; font-weight: 760; text-overflow: ellipsis; white-space: nowrap; }
.participant-state { margin-top: 6px; color: #7e89a8; font-size: 11px; }
.participant-card.speaking .participant-state { color: #6ce8ad; }
.mic-state { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 27px; height: 27px; border-radius: 9px; background: rgba(255, 255, 255, 0.06); font-size: 12px; }

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.control-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 50px;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 12px;
}
.control-icon { font-size: 17px; }
.mic-control.muted { border-color: rgba(255, 100, 124, 0.2); background: rgba(255, 100, 124, 0.1); color: #ffabb8; }
.danger-control { background: rgba(255, 100, 124, 0.1); color: #ff9ead; }

.sidebar-block + .sidebar-block { margin-top: 31px; padding-top: 25px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.sidebar-block p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.invite-link-box { display: flex; align-items: center; gap: 8px; padding: 9px 9px 9px 12px; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 12px; background: rgba(4, 7, 17, 0.42); }
.invite-link-box span { flex: 1; min-width: 0; overflow: hidden; color: #aeb7d2; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.invite-link-box button { width: 34px; height: 34px; border: 0; border-radius: 9px; background: rgba(121, 92, 255, 0.16); color: white; cursor: pointer; }
.tips-block ul { margin: 0; padding-left: 18px; color: #8994b3; font-size: 12px; line-height: 1.8; }


.chat-panel {
  grid-column: 1 / -1;
  padding: clamp(20px, 4vw, 30px);
}
.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.chat-header h3 { margin: 0; font-size: 18px; }
.chat-note {
  flex: 0 0 auto;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: #8994b3;
  font-size: 10px;
}
.chat-messages {
  min-height: 260px;
  max-height: 390px;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 17px;
  background: rgba(4, 7, 17, 0.42);
  scrollbar-color: rgba(142, 117, 255, 0.45) transparent;
}
.chat-empty {
  display: grid;
  place-items: center;
  min-height: 230px;
  color: #6f7a99;
  font-size: 13px;
  text-align: center;
}
.chat-message {
  width: min(78%, 620px);
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px 14px 14px 4px;
  background: rgba(255, 255, 255, 0.055);
}
.chat-message.own {
  margin-left: auto;
  border-color: rgba(121, 92, 255, 0.24);
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, rgba(115, 88, 255, 0.22), rgba(146, 118, 255, 0.12));
}
.chat-message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}
.chat-message-meta strong {
  min-width: 0;
  overflow: hidden;
  color: #cfc7ff;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-message-meta time { color: #697492; font-size: 9px; }
.chat-message p {
  margin: 0;
  overflow-wrap: anywhere;
  color: #edf0ff;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
}
.chat-form input { min-height: 50px; }
.chat-send-button {
  min-width: 120px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #7358ff, #9276ff);
  color: white;
  cursor: pointer;
  font-weight: 780;
}
.chat-send-button:disabled { cursor: not-allowed; opacity: 0.55; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 11px 17px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(16, 20, 38, 0.94);
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.4);
  color: white;
  font-size: 12px;
  white-space: nowrap;
  backdrop-filter: blur(15px);
}

.hidden { display: none !important; }
#audio-root { position: fixed; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }

@media (max-width: 820px) {
  .voice-layout { grid-template-columns: 1fr; }
  .room-sidebar { order: 2; }
  .room-main { min-height: auto; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 1120px); padding-top: max(17px, env(safe-area-inset-top)); }
  .brand { margin-bottom: 19px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 13px; }
  .brand-subtitle { display: none; }
  .lobby-panel { margin-top: 3vh; border-radius: 21px; }
  .connecting-panel { margin-top: 8vh; padding: 38px 20px; }
  .participants-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .participant-card { min-height: 145px; }
  .controls { grid-template-columns: 1fr; }
  .control-button { justify-content: flex-start; padding-left: 20px; }
  .code-row { flex-direction: column; }
  .chat-header { flex-direction: column; gap: 8px; }
  .chat-messages { min-height: 230px; max-height: 330px; padding: 10px; }
  .chat-empty { min-height: 205px; }
  .chat-message { width: 90%; }
  .chat-form { grid-template-columns: 1fr; }
  .chat-send-button { min-height: 49px; }
  .secondary-button { min-height: 49px; }
  .room-topbar { align-items: flex-start; }
}
