:root {
  --bg: #0b0d14;
  --bg-glow: #181c30;
  --surface: #141826;
  --surface-elevated: #1c2235;
  --surface-bright: #252c44;
  --border: rgba(255, 255, 255, 0.11);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #a78bfa;
  --primary-strong: #7c3aed;
  --secondary: #f472b6;
  --emerald: #34d399;
  --danger: #fb7185;
  --amber: #fbbf24;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: radial-gradient(circle at top right, var(--bg-glow) 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-strong), #9333ea);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: rgba(251, 113, 133, 0.18);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fecdd3;
}

.btn-emerald {
  background: rgba(52, 211, 153, 0.18);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: #a7f3d0;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.icon-btn:hover,
.btn:hover {
  opacity: 0.94;
}

.input,
.textarea,
.select {
  width: 100%;
  background: rgba(11, 13, 20, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  color: var(--text);
  outline: none;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary);
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

/* Auth & Onboarding */
.center-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: rgba(20, 24, 38, 0.94);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid rgba(167, 139, 250, 0.45);
}

.brand-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(167, 139, 250, 0.16);
  border: 1px solid rgba(167, 139, 250, 0.35);
  color: #ddd6fe;
}

.pill-emerald {
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.4);
  color: #6ee7b7;
}

.pill-muted {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.28);
  color: #cbd5e1;
}

.error-box {
  background: rgba(251, 113, 133, 0.14);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fecdd3;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
}

/* App Shell */
.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1360px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(16, 20, 32, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--primary-strong), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #ffffff;
  flex-shrink: 0;
  position: relative;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  position: absolute;
  bottom: 0;
  right: 0;
}

.status-online {
  background: var(--emerald);
}

.status-private {
  background: var(--amber);
}

.status-offline {
  background: #64748b;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(15, 19, 30, 0.8);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  min-height: 40px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: transparent;
}

.tab-btn.active {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid rgba(167, 139, 250, 0.4);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Crisp High-Contrast Friend & Room Cards (zero text shadow) */
.card {
  background: var(--surface-elevated);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card.selected {
  border-color: var(--primary);
  background: #232942;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.friend-name {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-sub {
  font-size: 0.8rem;
  color: #cbd5e1;
}

.main-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(11, 13, 20, 0.6);
  position: relative;
}

.pane-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 24, 38, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.family-member-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 18px;
  background: rgba(28, 34, 53, 0.72);
  border-bottom: 1px solid var(--border);
}

.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  color: #f8fafc;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.msg-row.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sender {
  font-size: 0.75rem;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 3px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: #f8fafc;
  word-break: break-word;
}

.msg-row.mine .msg-bubble {
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  border-color: rgba(196, 181, 253, 0.35);
}

.msg-img {
  max-width: 260px;
  border-radius: 12px;
  margin-top: 6px;
  display: block;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(20, 24, 38, 0.94);
}

/* Sub-tabs inside Family & Private rooms */
.room-subtabs {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 21, 34, 0.9);
  overflow-x: auto;
}

.room-subtab {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
}

.room-subtab.active {
  background: rgba(167, 139, 250, 0.22);
  color: #ffffff;
  border: 1px solid rgba(167, 139, 250, 0.4);
}

/* Inline Call Banner & Full-Screen Video Call Overlay */
.incoming-call-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  width: min(94vw, 460px);
  background: #1e1b4b;
  border: 1px solid rgba(167, 139, 250, 0.55);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.call-stage-inline {
  margin: 10px 16px 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: #171c2e;
  border: 1px solid rgba(167, 139, 250, 0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.call-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: #05070d;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.call-top-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent);
}

.call-bottom-area {
  position: relative;
  z-index: 2;
  padding: 16px 20px 26px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.call-controls-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(12px);
}

/* Small corner self-preview + tiny camera flip button */
.local-pip-box {
  position: fixed;
  right: 16px;
  bottom: 92px;
  width: 84px;
  height: 118px;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.42);
  background: #0f172a;
  z-index: 125;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65);
}

.local-pip-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.flip-btn-mini {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 6, 12, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(96vw, 540px);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: #1e293b;
  color: #ffffff;
  border: 1px solid rgba(167, 139, 250, 0.5);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Music & Games panels */
.panel-pad {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.track-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

/* Responsive Mobile Layout */
.mobile-back-btn {
  display: none;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .workspace.chat-open .sidebar {
    display: none;
  }
  .workspace:not(.chat-open) .main-pane {
    display: none;
  }
  .mobile-back-btn {
    display: inline-flex;
  }
}
