@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Space+Grotesk:wght@300;500;700&display=swap');

:root {
  --bg-color: #f8f9fa;
  --card-bg: rgba(255, 255, 255, 0.7);
  --text-main: #1a1a1a;
  --text-muted: #666;
  --border-color: #e2e2e2;
  --accent-color: #007bff;
  --hover-bg: rgba(0, 123, 255, 0.15);
  --grid-color: rgba(0, 0, 0, 0.05);
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --message-bg: rgba(255, 255, 255, 0.9);
  --message-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --bg-color: #080808;
  --card-bg: rgba(18, 18, 18, 0.7);
  --text-main: #f0f0f0;
  --text-muted: #999;
  --border-color: #2a2a2a;
  --accent-color: #3dffac;
  --hover-bg: rgba(61, 255, 172, 0.12);
  --grid-color: rgba(61, 255, 172, 0.08);
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --message-bg: rgba(30, 30, 30, 0.9);
  --message-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

body {
  min-height: 100vh;
  padding: 2rem;
  overflow-x: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.grid-background {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-size: 30px 30px;
  background-image:
    linear-gradient(to right, var(--grid-color) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px);
  pointer-events: none;
  transition: background-image 0.3s ease;
}

.header {
  max-width: 900px;
  margin: 0 auto 3rem;
  padding-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.logo span {
  color: var(--accent-color);
}

.glow-dot {
  animation: pulse-glow 2s infinite linear;
}

@keyframes pulse-glow {
  0%, 100% { 
    text-shadow: 0 0 5px var(--accent-color); 
    opacity: 1; 
  }
  50% { 
    text-shadow: 0 0 12px var(--accent-color); 
    opacity: 0.7; 
  }
}

#theme-toggle {
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  transition: transform 0.2s, background 0.3s;
  backdrop-filter: blur(5px);
}

#theme-toggle:hover {
  background: var(--hover-bg);
}

#theme-toggle:active {
  transform: scale(0.95);
}

.container {
  max-width: 900px;
  margin: 0 auto;
}

.card {
  position: relative;
  padding: 0;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(
    600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    var(--hover-bg),
    transparent 40%
  );
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

.card:hover::before {
  opacity: 1;
}

.chat-card {
  height: 85vh;
  display: flex;
  flex-direction: column;
}

.card-header {
  position: relative;
  z-index: 1;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
}

.tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-color);
  letter-spacing: 1px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 20px;
  transition: all 0.3s;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.status.connected {
  background: rgba(61, 255, 172, 0.15);
  color: #3dffac;
}

.status.connected .status-dot {
  background: #3dffac;
  box-shadow: 0 0 8px #3dffac;
}

.status.disconnected {
  background: rgba(255, 61, 61, 0.15);
  color: #ff3d3d;
}

.status.disconnected .status-dot {
  background: #ff3d3d;
  box-shadow: 0 0 8px #ff3d3d;
  animation: none;
}

@keyframes pulse {
  0%, 100% { 
    opacity: 1; 
    transform: scale(1);
  }
  50% { 
    opacity: 0.7; 
    transform: scale(1.1);
  }
}

.chat-main {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  background: transparent;
}

.messages {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.messages li {
  position: relative;
  background: var(--message-bg);
  padding: 1rem 1.25rem;
  border-radius: 12px;
  box-shadow: var(--message-shadow);
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.2s, box-shadow 0.2s;
}

.messages li:hover {
  transform: translateX(4px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

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

.message-content {
  flex: 1;
  word-wrap: break-word;
  line-height: 1.6;
  color: var(--text-main);
  font-size: 0.9rem;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  align-self: flex-end;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-footer {
  position: relative;
  z-index: 1;
  padding: 1.5rem 2rem;
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
}

#chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.image-btn {
  padding: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.image-btn:hover {
  background: var(--hover-bg);
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.image-btn svg {
  display: block;
}

#message-input {
  flex: 1;
  padding: 0.9rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 0.9rem;
  font-family: 'JetBrains Mono', monospace;
  background: var(--card-bg);
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
  backdrop-filter: blur(8px);
}

#message-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--hover-bg);
}

#message-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.send-btn {
  padding: 0.9rem 1.5rem;
  background: var(--accent-color);
  color: #000;
  border: none;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(61, 255, 172, 0.3);
}

[data-theme="light"] .send-btn {
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2);
}

[data-theme="light"] .send-btn:hover {
  box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}

.send-btn:active {
  transform: translateY(0);
}

.send-btn svg {
  transition: transform 0.2s;
}

.send-btn:hover svg {
  transform: translateX(2px);
}

.image-preview {
  display: none;
  position: relative;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
}

.image-preview.active {
  display: block;
}

.image-preview img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  display: block;
}

.image-preview .remove-image {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 61, 61, 0.9);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  transition: all 0.2s;
}

.image-preview .remove-image:hover {
  background: #ff3d3d;
  transform: scale(1.1);
}

.error-message {
  display: none;
  color: #ff3d3d;
  font-size: 0.8rem;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 61, 61, 0.1);
  border-radius: 8px;
  border-left: 3px solid #ff3d3d;
  font-weight: 700;
  animation: slideIn 0.3s ease;
}

/* Custom Scrollbar */
.chat-main::-webkit-scrollbar {
  width: 8px;
}

.chat-main::-webkit-scrollbar-track {
  background: transparent;
}

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

.chat-main::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }

  .header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
  }

  .logo {
    font-size: 1.4rem;
  }

  #theme-toggle {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
  }

  .chat-card {
    height: 90vh;
  }

  .card-header,
  .chat-footer {
    padding: 1rem 1.25rem;
  }

  .chat-main {
    padding: 1.25rem;
  }

  .messages li {
    padding: 0.85rem 1rem;
    flex-direction: column;
    gap: 0.5rem;
  }

  .message-time {
    align-self: flex-start;
  }

  #chat-form {
    gap: 0.5rem;
  }
  
  .input-wrapper {
    width: 100%;
  }

  #message-input {
    flex: 1;
  }

  .send-btn {
    padding: 0.9rem 1.2rem;
  }

  .send-btn span {
    display: none;
  }
  
  .message-image img {
    max-width: 100%;
  }
  
  .lightbox {
    padding: 1rem;
  }
  
  .lightbox .close-lightbox {
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
  }
  
  .modal-content {
    width: 90%;
    padding: 1.5rem;
  }
  
  .modal-content h2 {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .logo {
    font-size: 1.2rem;
  }

  #theme-toggle span {
    display: none;
  }
}

/* ==================
   USERNAME MODAL
================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  width: 90%;
  max-width: 450px;
  padding: 2.5rem;
  animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2rem;
  margin: 1rem 0 0.5rem;
  color: var(--text-main);
}

.modal-content p {
  margin-bottom: 2rem;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#username-input {
  width: 100%;
  padding: 0.9rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  font-size: 1rem;
  font-family: 'JetBrains Mono', monospace;
  background: var(--card-bg);
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
  backdrop-filter: blur(8px);
}

#username-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--hover-bg);
}

.color-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.color-picker input[type="radio"] {
  display: none;
}

.color-picker label {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.2s;
  position: relative;
}

.color-picker label:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.color-picker input[type="radio"]:checked + label {
  border-color: var(--text-main);
  transform: scale(1.15);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.color-picker input[type="radio"]:checked + label::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.join-btn {
  width: 100%;
  padding: 1rem;
  background: var(--accent-color);
  color: #000;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 1rem;
}

.join-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(61, 255, 172, 0.3);
}

[data-theme="light"] .join-btn:hover {
  box-shadow: 0 8px 24px rgba(0, 123, 255, 0.3);
}

.join-btn:active {
  transform: translateY(0);
}

/* ==================
   USER MESSAGES
================== */
.message-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #000;
  flex-shrink: 0;
}

.user-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-main);
}

.messages li {
  display: block;
  padding: 1rem 1.25rem;
}

.message-body {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-top: 4px;
}

.message-image {
  margin-top: 0.5rem;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  max-width: 100%;
  transition: transform 0.2s;
}

.message-image img {
  max-width: 400px;
  max-height: 300px;
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

.message-image:hover {
  transform: scale(1.02);
}

/* Image Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(10px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  animation: fadeIn 0.3s ease;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.lightbox .close-lightbox {
  position: absolute;
  top: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: all 0.2s;
  font-weight: 300;
}

.lightbox .close-lightbox:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg) scale(1.1);
}

/* ==================
   ONLINE COUNT
================== */
.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.online-count {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(61, 255, 172, 0.1);
}

[data-theme="light"] .online-count {
  background: rgba(0, 123, 255, 0.1);
}

.online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3dffac;
  animation: pulse 2s infinite;
}

[data-theme="light"] .online-dot {
  background: #007bff;
}

/* ==================
   TYPING INDICATOR
================== */
.typing-indicator {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  min-height: 30px;
  display: flex;
  align-items: center;
}

.typing-indicator .typing-user {
  font-weight: 700;
  margin-right: 4px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
}

.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* ==================
   SYSTEM MESSAGES
================== */
.system-message {
  text-align: center;
  padding: 0.5rem 1rem;
  margin: 0.5rem 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  animation: fadeIn 0.3s ease;
}

.system-message:hover {
  transform: none !important;
  box-shadow: none !important;
}