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

:root {
  --primary-color: #6366f1;
  --secondary-color: #4f46e5;
  --accent-color: #ec4899;
  --background: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --border-color: #475569;
  --success-color: #10b981;
  --error-color: #ef4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ================= SCREEN TRANSITIONS ================= */
.screen {
  display: none;
  width: 100%;
  max-width: 900px;
  height: 100vh;
  max-height: 90vh;
  animation: slideIn 0.3s ease-out;
}

.screen.active {
  display: flex;
}

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

/* ================= LOGIN SCREEN ================= */
#loginScreen {
  align-items: center;
  justify-content: center;
}

.login-container {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-container > p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

#loginForm {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#loginForm input {
  background: var(--surface-light);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
}

#loginForm input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#loginForm input::placeholder {
  color: var(--text-secondary);
}

#loginForm button {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

#loginForm button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.4);
}

.error-message {
  color: var(--error-color);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

/* ================= CHAT SCREEN ================= */
#chatScreen {
  flex-direction: column;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.chat-header h2 {
  font-size: 1.5rem;
  margin: 0;
}

.header-info {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.875rem;
}

.username-badge,
.user-count {
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  backdrop-filter: blur(10px);
}

/* Chat Body */
.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.messages-container::-webkit-scrollbar {
  width: 8px;
}

.messages-container::-webkit-scrollbar-track {
  background: var(--surface-light);
  border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  animation: messageSlide 0.3s ease-out;
}

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

.message.self {
  align-self: flex-end;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.message.self .message-header {
  flex-direction: row-reverse;
}

.username {
  font-weight: 600;
}

.timestamp {
  opacity: 0.7;
}

.message-text {
  background: var(--surface-light);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  word-wrap: break-word;
  line-height: 1.4;
}

.message.self .message-text {
  background: var(--primary-color);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.other .message-text {
  border-bottom-left-radius: 4px;
}

/* System Messages */
.system-message {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem;
  margin: 0.5rem 0;
  font-style: italic;
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
}

.room-id-display {
  background: var(--surface-light);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: 8px;
  margin-top: 1rem;
  width: 100%;
}

.room-id-display p {
  margin: 0 0 0.75rem 0;
  color: var(--text-primary);
}

.room-id-display code {
  background: var(--background);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  color: var(--primary-color);
  font-weight: bold;
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  padding: 0.5rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  background: var(--surface-light);
}

.typing-users {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-users::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Chat Footer */
.chat-footer {
  background: var(--surface-light);
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message-input-group {
  display: flex;
  gap: 0.75rem;
}

.message-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.message-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.message-input::placeholder {
  color: var(--text-secondary);
}

.send-btn,
.copy-btn,
.leave-btn {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.95rem;
}

.send-btn:hover,
.copy-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.4);
}

.leave-btn {
  background: var(--error-color);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  align-self: flex-end;
}

.leave-btn:hover {
  background: #d32f2f;
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.4);
}

/* ================= RESPONSIVE DESIGN ================= */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }

  .screen {
    max-height: 100vh;
  }

  .login-container {
    padding: 1.5rem;
  }

  .chat-container {
    border-radius: 8px;
  }

  .message {
    max-width: 85%;
  }

  .chat-header {
    padding: 1rem;
    flex-wrap: wrap;
  }

  .header-info {
    gap: 0.5rem;
    font-size: 0.75rem;
  }

  .messages-container {
    padding: 1rem;
  }

  .chat-footer {
    padding: 0.75rem 1rem;
  }

  .message-input-group {
    gap: 0.5rem;
  }

  .send-btn,
  .copy-btn,
  .leave-btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .login-container {
    max-width: 100%;
  }

  .message {
    max-width: 95%;
  }

  .chat-header h2 {
    font-size: 1.2rem;
  }

  .header-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .room-id-display {
    padding: 0.75rem;
  }

  .room-id-display code {
    font-size: 1rem;
  }
}
