/* =====================
   BASE & FONTS
   ===================== */
* { box-sizing: border-box; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: #0a0a0f;
  -webkit-font-smoothing: antialiased;
}

/* =====================
   JOIN SCREEN
   ===================== */
.join-card {
  animation: fadeUp 0.5s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  box-shadow: 0 0 40px rgba(167,139,250,0.35);
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 40px rgba(167,139,250,0.35); }
  50%       { box-shadow: 0 0 60px rgba(167,139,250,0.6); }
}

.join-input {
  background: #111118;
  border: 1.5px solid #1f2937;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.join-input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,0.18);
}

.join-btn {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  font-family: 'Plus Jakarta Sans', sans-serif;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(124,58,237,0.4);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.join-btn:hover  { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(124,58,237,0.55); }
.join-btn:active { transform: translateY(0); }
.join-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* =====================
   CHAT SCREEN
   ===================== */
#chat-screen {
  background: #0a0a0f;
  position: relative;
}

/* Subtle noise texture overlay */
#chat-screen::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0; opacity: 0.4;
}

.chat-header {
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid #1a1a2e;
  position: relative; z-index: 10;
}

.logo-sm {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

.online-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.name-badge {
  background: rgba(124,58,237,0.2);
  color: #a78bfa;
  border: 1px solid rgba(124,58,237,0.3);
  font-family: 'Space Grotesk', sans-serif;
}

.leave-btn {
  background: rgba(239,68,68,0.1);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.2);
  cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: background 0.2s;
}
.leave-btn:hover { background: rgba(239,68,68,0.2); }

/* Users Bar */
.users-bar {
  background: transparent;
  border-bottom: 1px solid #0f0f1a;
  min-height: 44px;
  position: relative; z-index: 5;
  scrollbar-width: none;
}
.users-bar::-webkit-scrollbar { display: none; }

.user-pill {
  display: inline-flex; align-items: center; gap-1.5;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  transition: transform 0.15s;
  animation: popIn 0.3s ease both;
}
@keyframes popIn {
  from { opacity:0; transform: scale(0.7); }
  to   { opacity:1; transform: scale(1); }
}
.user-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #34d399;
}

/* Messages Area */
.messages-area {
  scrollbar-width: thin;
  scrollbar-color: #1f2937 transparent;
  position: relative; z-index: 1;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: #1f2937; border-radius: 4px; }

/* Message Wrapper */
.msg-wrapper {
  display: flex;
  flex-direction: column;
  animation: msgAppear 0.25s ease both;
  margin-bottom: 2px;
}
@keyframes msgAppear {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-wrapper.mine  { align-items: flex-end; }
.msg-wrapper.other { align-items: flex-start; }
.msg-wrapper.system { align-items: center; }

/* Group spacing */
.msg-wrapper.mine  + .msg-wrapper.other,
.msg-wrapper.other + .msg-wrapper.mine {
  margin-top: 8px;
}

/* Name label above bubble */
.msg-name {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 3px;
  padding: 0 4px;
  letter-spacing: 0.02em;
}

/* Bubble */
.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  transition: transform 0.1s;
}
.msg-bubble:active { transform: scale(0.98); }

.mine .msg-bubble {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 12px rgba(124,58,237,0.35);
}

.other .msg-bubble {
  background: #161622;
  color: #e5e7eb;
  border-bottom-left-radius: 5px;
  border: 1px solid #1f2937;
}

/* System message */
.system-msg {
  font-size: 0.72rem;
  color: #4b5563;
  background: rgba(255,255,255,0.03);
  border: 1px solid #1a1a2e;
  padding: 4px 14px;
  border-radius: 999px;
  margin: 6px 0;
}

/* Timestamp */
.msg-time {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.35);
  margin-top: 3px;
  padding: 0 4px;
}
.mine  .msg-time { text-align: right; }
.other .msg-time { text-align: left; }

/* Typing Indicator */
.typing-bubble {
  display: flex; align-items: center; gap-6px;
  padding: 6px 0;
}
.typing-dots {
  display: inline-flex; gap: 3px; align-items: center; margin-left: 6px;
}
.typing-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #a78bfa;
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity:0.4; }
  30%            { transform: translateY(-5px); opacity:1; }
}

/* Input Area */
.input-area {
  background: rgba(10,10,15,0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid #1a1a2e;
  position: relative; z-index: 10;
}

.emoji-toggle-btn {
  background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: 12px;
  transition: background 0.15s, transform 0.15s;
  filter: grayscale(20%);
}
.emoji-toggle-btn:hover { background: rgba(255,255,255,0.06); transform: scale(1.15); }

.msg-textarea {
  background: #111118;
  border: 1.5px solid #1f2937;
  color: #e5e7eb;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.875rem;
  max-height: 120px;
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.5;
}
.msg-textarea:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}
.msg-textarea::placeholder { color: #374151; }

.send-btn {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  border: none; cursor: pointer;
  box-shadow: 0 2px 12px rgba(124,58,237,0.4);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.send-btn:hover  { transform: scale(1.07); box-shadow: 0 4px 20px rgba(124,58,237,0.55); }
.send-btn:active { transform: scale(0.96); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Emoji Picker */
.emoji-picker {
  background: #111118;
  border: 1px solid #1f2937;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  width: 272px;
  animation: fadeDown 0.18s ease both;
}
@keyframes fadeDown {
  from { opacity:0; transform: translateY(8px) scale(0.97); }
  to   { opacity:1; transform: translateY(0) scale(1); }
}
.emoji-item {
  font-size: 1.3rem;
  cursor: pointer; padding: 4px;
  border-radius: 8px;
  text-align: center;
  transition: background 0.1s, transform 0.1s;
  border: none; background: none;
}
.emoji-item:hover { background: rgba(124,58,237,0.2); transform: scale(1.25); }

/* =====================
   RESPONSIVE
   ===================== */
@media (min-width: 640px) {
  #chat-screen {
    border-left: 1px solid #1a1a2e;
    border-right: 1px solid #1a1a2e;
  }
}

/* Date divider */
.date-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 0;
}
.date-divider span {
  font-size: 0.68rem; color: #374151;
  white-space: nowrap;
}
.date-divider::before, .date-divider::after {
  content: ''; flex: 1;
  height: 1px; background: #1a1a2e;
}
