:root {
  --bg: #0b0f14;
  --bg-elev: #111823;
  --panel: #151e2b;
  --panel-2: #1b2637;
  --text: #e8eef7;
  --muted: #8fa1b8;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1100px 700px at 15% -10%, rgba(59, 130, 246, 0.18), transparent 60%),
    radial-gradient(900px 700px at 105% 0%, rgba(139, 92, 246, 0.14), transparent 55%);
}

.screen {
  position: relative;
  z-index: 1;
}

.muted {
  color: var(--muted);
}

.error {
  color: #fca5a5;
  font-size: 13px;
  margin: 10px 0 0;
  line-height: 1.35;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin: 16px 0 0;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 26px 24px;
  border-radius: 30px;
  border: 1px solid var(--border);
  background: rgba(21, 30, 43, 0.78);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
}

.logo {
  display: block;
  margin: 0 auto 14px;
  border-radius: 20px;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.35);
}

h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: -0.02em;
  text-align: center;
}

.login-sub {
  margin: 0 0 24px;
  text-align: center;
  font-size: 14px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(11, 15, 20, 0.75);
  color: var(--text);
  padding: 13px 14px;
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: rgba(143, 161, 184, 0.65);
}

input:focus,
textarea:focus {
  border-color: rgba(59, 130, 246, 0.7);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  padding: 13px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  margin-top: 6px;
  border-color: transparent;
  background: linear-gradient(180deg, #4f8ef7, #2563eb);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.35);
}

.btn.primary:active {
  transform: translateY(1px);
}

.btn.ghost {
  width: auto;
  padding: 10px 16px;
  background: transparent;
}

/* ---------- Chat ---------- */

.chat-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 12px 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.peer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.peer-text {
  min-width: 0;
}

.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.avatar.xl {
  width: 92px;
  height: 92px;
  font-size: 36px;
}

.peer-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.status.online {
  color: #86efac;
}

.status.online::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--ok);
  vertical-align: 1px;
}

.topbar-actions {
  display: flex;
  gap: 2px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.07);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu {
  position: absolute;
  top: calc(58px + var(--safe-top));
  right: 12px;
  z-index: 10;
  min-width: 216px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.menu button {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.danger-text {
  color: #fca5a5 !important;
}

/* ---------- Messages ---------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 14px 8px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
}

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  animation: pop 0.16s ease-out;
}

.msg.own {
  align-items: flex-end;
}

.msg .sender {
  margin: 2px 9px 3px;
  font-size: 12px;
  color: var(--muted);
}

.bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 6px;
  background: var(--panel);
  word-break: break-word;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.msg.own .bubble {
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(180deg, #2f6fe0, #2459b8);
}

.bubble .text {
  font-size: 15.5px;
  line-height: 1.36;
  white-space: pre-wrap;
}

.bubble .meta {
  margin-top: 4px;
  font-size: 10.5px;
  color: rgba(232, 238, 247, 0.55);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.msg.own .bubble .meta {
  color: rgba(255, 255, 255, 0.72);
}

.msg.pending .bubble {
  opacity: 0.62;
}

.msg.failed .bubble {
  outline: 1px solid rgba(239, 68, 68, 0.6);
}

.bubble .media {
  margin: -3px -6px 7px;
  overflow: hidden;
  border-radius: 14px;
  background: #000;
}

.bubble .media img,
.bubble .media video {
  display: block;
  width: 100%;
  max-height: 420px;
  background: #000;
}

.bubble .media img {
  object-fit: cover;
  cursor: zoom-in;
}

.bubble .media video {
  object-fit: contain;
}

.bubble .file-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 2px 2px;
  color: inherit;
  text-decoration: none;
}

.bubble .file-row svg {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}

.bubble .file-name {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bubble .file-size {
  font-size: 11px;
  color: rgba(232, 238, 247, 0.55);
}

.msg.own .bubble .file-size {
  color: rgba(255, 255, 255, 0.65);
}

.progress {
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.progress > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: #fff;
  transition: width 0.12s linear;
}

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.composer .attach {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

#input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 15px;
  border-radius: 22px;
  background: var(--panel);
  line-height: 1.35;
  resize: none;
}

.send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.3);
}

.send-btn:active {
  transform: scale(0.96);
}

.send-btn:disabled {
  opacity: 0.4;
  box-shadow: none;
}

.typing {
  min-height: 18px;
  padding: 0 18px 5px;
  font-size: 12.5px;
  color: var(--muted);
}

.conn-banner {
  position: absolute;
  top: calc(64px + var(--safe-top));
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: #7c2d12;
  color: #fed7aa;
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- Call ---------- */

.call {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: #05070a;
}

.call #remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.call #local-video {
  position: absolute;
  right: 14px;
  bottom: calc(118px + var(--safe-bottom));
  z-index: 2;
  width: 104px;
  height: 148px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: #000;
  box-shadow: var(--shadow);
}

.call-top {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 0;
  right: 0;
  z-index: 3;
  text-align: center;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85);
}

#call-peer-name {
  font-size: 20px;
  font-weight: 650;
}

#call-timer {
  margin-top: 2px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  font-variant-numeric: tabular-nums;
}

.call-status {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  z-index: 3;
  transform: translateY(-50%);
  text-align: center;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.82);
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: 18px;
}

.call-btn {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.call-btn svg {
  width: 26px;
  height: 26px;
}

.call-btn.danger {
  border-color: transparent;
  background: var(--danger);
}

.call-btn.accept {
  border-color: transparent;
  background: var(--ok);
}

.call-btn .off {
  display: none;
}

.call-btn.muted .on {
  display: none;
}

.call-btn.muted .off {
  display: block;
}

/* ---------- Incoming ---------- */

.incoming {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 7, 10, 0.78);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.incoming-card {
  width: 100%;
  max-width: 340px;
  padding: 30px 24px 26px;
  border: 1px solid var(--border);
  border-radius: 30px;
  background: var(--panel);
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease-out;
}

.incoming-name {
  margin: 12px 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.incoming-actions {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 28px;
}

/* ---------- Lightbox / modal / toasts ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.93);
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.modal-card {
  width: 100%;
  max-width: 400px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.modal-card p {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.invite-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.invite-row input {
  flex: 1;
  font-size: 14px;
  padding: 10px 12px;
}

.invite-row button {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.invite-code {
  margin-top: 14px;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.participant {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.participant:hover {
  background: rgba(255, 255, 255, 0.06);
}

.participant .avatar {
  width: 36px;
  height: 36px;
  font-size: 14px;
}

.participant .who {
  flex: 1;
  min-width: 0;
}

.participant .who b {
  display: block;
  font-weight: 600;
  font-size: 15px;
}

.participant .who small {
  color: var(--muted);
  font-size: 12px;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.96);
  color: var(--text);
  font-size: 13.5px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 900px) {
  .chat-screen {
    max-width: 820px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
