/* Root Variables & Reset */
:root {
  --primary: #4fc3f7;
  --primary-dark: #0288d1;
  --primary-light: #81d4fa;
  --secondary: #ff5722;
  --secondary-dark: #e64a19;
  --background: rgba(0, 0, 0, 0.92);
  --surface: rgba(40, 40, 40, 0.95);
  --surface-light: rgba(60, 60, 60, 0.8);
  --text: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --error: #ff5252;
  --success: #4caf50;
  --warning: #ffc107;
  --border-radius: 12px;
  --box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", Arial, sans-serif;
}

body {
  overflow: hidden;
  background-color: var(--background);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout Containers */
#app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#three-d-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#chat-container {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 350px;
  background-color: var(--surface);
  border-radius: var(--border-radius);
  padding: 20px;
  z-index: 9999;
  box-shadow: var(--box-shadow);
  transition: var(--transition);
  overflow: hidden;
}

/* Minimized chat state */
#chat-container.minimized {
  height: 40px;
  padding: 0;
}

#chat-container.minimized h2 {
  margin: 10px 0;
  font-size: 1rem;
}

#chat-container.minimized .messages-container,
#chat-container.minimized .input-container {
  display: none;
}

.minimize-button {
  position: absolute;
  top: 0;
  right: 15px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--surface-light);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  z-index: 10;
}

.minimize-button:hover {
  background-color: var(--primary);
  transform: scale(1.1);
}

/* Typography */
h2 {
  text-align: center;
  margin-bottom: 15px;
  color: var(--primary);
  font-size: 1.5rem;
  font-weight: 600;
}

/* Messages Container */
.messages-container {
  height: 300px;
  overflow-y: auto;
  margin-bottom: 15px;
  padding: 15px;
  border-radius: var(--border-radius);
  background-color: rgba(30, 30, 30, 0.8);
  scroll-behavior: smooth;
}

.message {
  margin-bottom: 10px;
  padding: 12px;
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  transition: transform 0.2s ease;
  animation: fadeIn 0.3s ease-out;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  word-break: break-word;
}

.message:hover {
  transform: translateX(5px);
}

.message.ai-typing {
  opacity: 0.7;
  background-color: rgba(79, 195, 247, 0.2);
  border-left: 3px solid var(--primary);
}

.username {
  font-weight: 600;
  color: var(--primary);
  margin-right: 8px;
}

.no-messages {
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
  padding: 20px 0;
}

/* Input Elements */
.input-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.textarea-container {
  position: relative;
  width: 100%;
}

textarea#message-input {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  color: var(--text);
  resize: none;
  min-height: 80px;
  line-height: 1.5;
  transition: var(--transition);
}

textarea#message-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.2);
}

.char-counter {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background-color: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 10px;
}

/* Username and Send Button Row */
.username-send-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

input#username-input {
  flex: 1;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  color: var(--text);
  transition: var(--transition);
}

input#username-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.2);
}

/* Buttons */
button {
  padding: 12px 20px;
  border: none;
  border-radius: var(--border-radius);
  background-color: var(--primary);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

button:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

button:active {
  transform: translateY(0);
}

#send-button {
  background-color: var(--secondary);
}

#send-button:hover {
  background-color: var(--secondary-dark);
}

.action-button {
  background-color: var(--surface-light);
  padding: 8px 12px;
  font-size: 0.8rem;
}

.action-button:hover {
  background-color: var(--primary);
}

#reset-pattern-button {
  position: absolute;
  bottom: 10px;
  right: 380px;
  z-index: 9999;
  padding: 8px 12px;
  font-size: 0.8rem;
  background-color: var(--surface-light);
}

/* Rooms Section */
#rooms-section {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 300px;
  background-color: var(--surface);
  border-radius: var(--border-radius);
  padding: 20px;
  z-index: 9999;
  box-shadow: var(--box-shadow);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

.rooms-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}

#room-name-input,
#room-type-select,
#room-filter {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  color: var(--text);
  transition: var(--transition);
}

#room-name-input:focus,
#room-type-select:focus,
#room-filter:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.2);
}

#room-name-input {
  flex: 1;
  min-width: 120px;
}

#room-filter {
  width: 100%;
  margin: 10px 0;
}

#rooms-list {
  display: grid;
  gap: 10px;
  margin-top: 15px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  padding-right: 5px;
}

.room-item {
  background-color: var(--surface-light);
  border-radius: var(--border-radius);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition);
  animation: slideIn 0.3s ease-out;
}

.room-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.room-item.active {
  background-color: var(--primary);
}

.room-item.active .join-button {
  background-color: var(--surface);
}

.room-item .join-button {
  padding: 8px 12px;
  font-size: 0.8rem;
}

/* Private Room Dialog */
#private-room-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

#create-private-room-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.dialog-content {
  background-color: var(--surface);
  border-radius: var(--border-radius);
  padding: 30px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--box-shadow);
  animation: fadeIn 0.3s ease-out;
}

.dialog-content h3 {
  margin-bottom: 20px;
  color: var(--primary);
  text-align: center;
}

#room-password-input {
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  color: var(--text);
}

#create-room-password-input {
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background-color: var(--surface-light);
  color: var(--text);
}

.dialog-buttons {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.dialog-buttons button {
  flex: 1;
}

#cancel-join-button {
  background-color: var(--surface-light);
}

/* Social Bubbles */
#social-bubbles-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.social-bubble {
  position: absolute;
  cursor: pointer;
  user-select: none;
  will-change: transform;
  pointer-events: auto;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
  transition: filter 0.3s ease;
}

.social-bubble:hover {
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}

.bubble-content {
  padding: 15px;
  border-radius: var(--border-radius);
  background-color: var(--surface);
  color: var(--text);
  box-shadow: var(--box-shadow);
  transition: var(--transition);
  max-width: 250px;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.bubble-icon {
  font-size: 1.2rem;
  margin-right: 8px;
}

.bubble-count {
  font-size: 0.9rem;
  word-break: break-word;
}

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

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

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Loading States */
.loading {
  position: relative;
  opacity: 0.7;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive Design */
@media screen and (max-width: 1200px) {
  #rooms-section {
    width: 280px;
  }

  #reset-pattern-button {
    right: 380px;
  }
}

@media screen and (max-width: 992px) {
  #chat-container {
    width: 320px;
  }

  #reset-pattern-button {
    right: 350px;
  }
}

@media screen and (max-width: 768px) {
  #rooms-section {
    width: calc(100% - 40px);
    left: 20px;
    top: 20px;
    max-height: 50vh;
  }

  #chat-container {
    width: calc(100% - 40px);
    left: 20px;
    right: 20px;
    bottom: 20px;
  }

  .rooms-header {
    flex-direction: column;
  }

  #create-room-button,
  #refresh-rooms-button {
    width: 100%;
  }

  #reset-pattern-button {
    bottom: auto;
    top: 50vh;
    right: 20px;
  }
}

@media screen and (max-width: 480px) {
  #rooms-section,
  #chat-container {
    width: calc(100% - 20px);
    left: 10px;
    right: 10px;
    padding: 15px;
  }

  #rooms-section {
    top: 10px;
    max-height: 90vh;
  }

  #chat-container {
    bottom: 10px;
  }

  .message {
    padding: 10px;
  }

  .username-send-row {
    flex-direction: column;
  }

  input#username-input,
  #send-button {
    width: 100%;
  }

  .bubble-content {
    max-width: 200px;
    padding: 10px;
  }

  h2 {
    font-size: 1.2rem;
  }

  .minimize-button {
    top: 0;
    right: 10px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

::-webkit-scrollbar-track {
  background: rgba(30, 30, 30, 0.5);
  border-radius: 8px;
}

::-webkit-scrollbar-thumb {
  background: rgba(100, 100, 100, 0.5);
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 120, 120, 0.7);
}

/* Touch Device Optimizations */
@media (hover: none) {
  button,
  .room-item,
  .social-bubble {
    transition: none;
  }

  button:active {
    background-color: var(--primary-dark);
  }

  #send-button:active {
    background-color: var(--secondary-dark);
  }

  .room-item:active {
    background-color: var(--primary-light);
  }

  .social-bubble .bubble-content {
    padding: 15px;
  }
}

.dialog-error {
  color: var(--error);
  margin-bottom: 15px;
  font-size: 0.9rem;
  text-align: center;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--border-radius);
  background-color: var(--surface);
  color: var(--text);
  box-shadow: var(--box-shadow);
  animation: fadeInUp 0.3s ease-out, fadeOut 0.3s ease-out 2.7s forwards;
  pointer-events: auto;
  max-width: 300px;
  text-align: center;
}

.toast.error {
  background-color: var(--error);
}

.toast.success {
  background-color: var(--success);
}

.toast.warning {
  background-color: var(--warning);
  color: #333;
}

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

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