:root {
  --primary-bg: #1a1a1a;
  --secondary-bg: #333333;
  --container-bg: rgba(40, 40, 40, 0.95);
  --message-sent-bg: linear-gradient(135deg, #ffffff, #e0e0e0);
  --message-received-bg: linear-gradient(135deg, #4a4a4a, #2a2a2a);
  --text-color: #ffffff;
  --input-bg: rgba(255, 255, 255, 0.1);
  --button-bg: linear-gradient(135deg, #ffffff, #e0e0e0);
  --button-text: #000000;
  --button-hover: linear-gradient(135deg, #f5f5f5, #d4d4d4);
  --shadow-color: rgba(0, 0, 0, 0.3);
  --border-color: rgba(255, 255, 255, 0.1);
}

/* Light Theme */
.theme-light {
  --primary-bg: #f5f5f5;
  --secondary-bg: #e0e0e0;
  --container-bg: rgba(255, 255, 255, 0.95);
  --message-sent-bg: linear-gradient(135deg, #4a4a4a, #2a2a2a);
  --message-received-bg: linear-gradient(135deg, #e0e0e0, #f5f5f5);
  --text-color: #000000;
  --input-bg: rgba(0, 0, 0, 0.1);
  --button-bg: linear-gradient(135deg, #4a4a4a, #2a2a2a);
  --button-text: #ffffff;
  --button-hover: linear-gradient(135deg, #333333, #1a1a1a);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --border-color: rgba(0, 0, 0, 0.1);
}

/* Gray Theme */
.theme-gray {
  --primary-bg: #696969;
  --secondary-bg: #808080;
  --container-bg: rgba(105, 105, 105, 0.95);
  --message-sent-bg: linear-gradient(135deg, #a9a9a9, #c0c0c0);
  --message-received-bg: linear-gradient(135deg, #2f4f4f, #363636);
  --text-color: #ffffff;
  --input-bg: rgba(255, 255, 255, 0.2);
  --button-bg: linear-gradient(135deg, #a9a9a9, #c0c0c0);
  --button-text: #000000;
  --button-hover: linear-gradient(135deg, #989898, #b0b0b0);
  --shadow-color: rgba(0, 0, 0, 0.2);
  --border-color: rgba(255, 255, 255, 0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Arial', sans-serif;
  transition: background-color 0.3s, color 0.3s;
}

body {
  background: linear-gradient(135deg, var(--primary-bg), var(--secondary-bg));
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.chat-container {
  background: var(--container-bg);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 700px;
  box-shadow: 0 8px 32px var(--shadow-color);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.theme-selector {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}

.theme-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.theme-btn:hover {
  transform: scale(1.1);
}

.theme-btn.dark { background: #1a1a1a; }
.theme-btn.light { background: #f5f5f5; }
.theme-btn.gray { background: #696969; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.username-display {
  font-size: 1.2rem;
  font-weight: bold;
}

.chat-messages {
  height: 400px;
  overflow-y: auto;
  margin-bottom: 20px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

.message {
  margin: 15px 0;
  padding: 12px 18px;
  border-radius: 15px;
  max-width: 80%;
  word-wrap: break-word;
  backdrop-filter: blur(5px);
}

.message.sent {
  background: var(--message-sent-bg);
  color: var(--button-text);
  margin-left: auto;
}

.message.received {
  background: var(--message-received-bg);
  margin-right: auto;
}

.message.announcement {
  text-align: center;
  margin: 15px auto;
  padding: 10px;
  background: transparent;
  font-style: italic;
}

.message span {
  font-size: 0.85em;
  opacity: 0.8;
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.input-container {
  display: flex;
  gap: 12px;
}

.input-container input {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 16px;
  transition: all 0.3s ease;
}

.input-container input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.input-container button {
  padding: 16px 24px;
  border: none;
  border-radius: 12px;
  background: var(--button-bg);
  color: var(--button-text);
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 100px;
}

.input-container button:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.3);
}

.input-container button:active {
  transform: translateY(0);
}

.error-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.error-modal.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--container-bg);
  padding: 30px;
  border-radius: 15px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-bottom: 15px;
  color: #ff4d4d;
}

.modal-content p {
  margin-bottom: 25px;
  line-height: 1.5;
}

.modal-close {
  padding: 12px 24px;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-close:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

.typing-indicator {
  font-size: 0.9em;
  font-style: italic;
  color: var(--text-color);
  opacity: 0.7;
  margin: -10px 0 10px 5px;
  height: 18px; /* reserve space so layout doesn't jump */
}






/* Loading screen overlay */
#loadingScreen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: none; /* hidden by default */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 1.2em;
  z-index: 2000;
}

#loadingScreen .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #fff;
  border-top: 4px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}
