/* Global Styles */
*, *::before, *::after { 
  box-sizing: border-box; 
}

html, body { 
  margin: 0; 
  padding: 0; 
  height: 100%; 
  background: #2c2f33; 
  color: #ddd; 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; 
}

.container { 
  display: flex; 
  flex-direction: column; 
  height: 100vh; 
}

/* Login Screen */
#login {
  margin: auto;
  display: flex; 
  flex-direction: column; 
  gap: 10px; 
  align-items: center;
  width: 280px; 
  padding: 20px; 
  background: #36393f; 
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

#login h2 { 
  color: #fff; 
  margin: 0 0 10px 0; 
}

#login input[type="text"],
#login input[type="password"] {
  width: 100%; 
  padding: 12px; 
  background: #40444b; 
  color: #fff;
  border: 1px solid #555; 
  border-radius: 4px; 
  font-size: 1rem;
  transition: border-color 0.2s;
}

#login input[type="text"]:focus,
#login input[type="password"]:focus {
  outline: none; 
  border-color: #7289da;
}

#login input[type="color"] {
  -webkit-appearance: none; 
  appearance: none;
  width: 100%; 
  height: 40px; 
  background: #40444b; 
  border: 1px solid #555; 
  border-radius: 4px;
  cursor: pointer; 
  transition: border-color 0.2s;
}

#login input[type="color"]:hover { 
  border-color: #7289da; 
}

#login input[type="color"]::-webkit-color-swatch-wrapper { 
  padding: 0; 
}

#login input[type="color"]::-webkit-color-swatch { 
  border: none; 
  border-radius: 4px; 
}

#login button {
  width: 100%; 
  padding: 12px; 
  background: #7289da; 
  color: #fff;
  border: none; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 1rem;
  transition: background-color 0.2s;
  font-weight: 500;
}

#login button:hover { 
  background: #677bc4; 
}

#login button:disabled { 
  background: #4a4a4a; 
  cursor: not-allowed; 
}

/* Chat Screen */
#chat { 
  display: none; 
  flex: 1; 
  flex-direction: column; 
  padding: 16px; 
  min-height: 0; 
}

.chat-open #login { 
  display: none; 
}

.chat-open #chat { 
  display: flex; 
}

/* Admin Controls */
#adminControls {
  display: none;
  margin-bottom: 12px;
  padding: 12px;
  background: #36393f;
  border-radius: 6px;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#adminControls .admin-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#adminControls .admin-row:last-child {
  margin-bottom: 0;
}

#adminControls input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #40444b;
  color: #fff;
  transition: border-color 0.2s;
}

#adminControls input:focus {
  outline: none;
  border-color: #7289da;
}

#adminControls button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background: #7289da;
  color: #fff;
  cursor: pointer;
  transition: background-color 0.2s;
  font-weight: 500;
}

#adminControls button:hover { 
  background: #677bc4; 
}

#adminControls button.danger { 
  background: #f04747; 
}

#adminControls button.danger:hover { 
  background: #d73535; 
}

#adminControls select {
  padding: 8px 12px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #40444b;
  color: #fff;
  cursor: pointer;
}

/* Room Tabs */
#roomTabs {
  display: flex; 
  gap: 8px; 
  margin-bottom: 12px; 
  flex-wrap: wrap;
}

.room-tab {
  padding: 8px 16px; 
  background: #40444b; 
  color: #fff;
  border-radius: 4px; 
  cursor: pointer; 
  user-select: none;
  border: 1px solid transparent;
  transition: all 0.2s;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.room-tab:hover { 
  background: #50575e; 
  transform: translateY(-1px); 
}

.room-tab.active {
  background: #7289da;
  border-color: #677bc4;
  box-shadow: 0 2px 4px rgba(114, 137, 218, 0.3);
}

.room-tab.pocketanimals {
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  color: #fff;
  font-weight: bold;
}

.room-tab.pocketanimals:hover {
  background: linear-gradient(45deg, #ff5252, #26a69a);
}

.room-tab .user-count {
  font-size: 0.8em;
  opacity: 0.8;
  background: rgba(0,0,0,0.2);
  padding: 2px 6px;
  border-radius: 10px;
}

.room-tab .unread-indicator {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 8px;
  height: 8px;
  background: #f04747;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

/* Game Panel for PocketAnimals room */
#gamePanel {
  display: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  border: 2px solid #7289da;
  animation: gameGlow 3s ease-in-out infinite alternate;
}

@keyframes gameGlow {
  from { box-shadow: 0 0 10px rgba(114, 137, 218, 0.3); }
  to { box-shadow: 0 0 20px rgba(114, 137, 218, 0.6); }
}

#gamePanel.active { 
  display: block; 
}

#gamePanel h3 {
  margin: 0 0 12px 0;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  font-size: 1.4rem;
}

.game-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  background: rgba(255,255,255,0.1);
  padding: 8px;
  border-radius: 6px;
  text-align: center;
  backdrop-filter: blur(10px);
}

.stat-card .stat-icon {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-weight: bold;
  font-size: 1.1rem;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  opacity: 0.9;
}

.game-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-btn {
  padding: 8px 16px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
  font-weight: 500;
}

.game-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-2px);
}

.game-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.game-btn.primary {
  background: linear-gradient(45deg, #ff6b6b, #ee5a24);
  border-color: #ee5a24;
}

.game-btn.primary:hover {
  background: linear-gradient(45deg, #ff5252, #e74c3c);
}

/* Hunt Animation */
.hunt-animation {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: linear-gradient(45deg, #74b9ff, #0984e3);
  margin: 8px 0;
}

.hunt-progress {
  height: 4px;
  background: linear-gradient(90deg, #00b894, #00a085);
  border-radius: 2px;
  transition: width 0.1s ease-out;
}

.hunt-text {
  padding: 8px;
  text-align: center;
  color: #fff;
  font-weight: 500;
}

/* Game Quick Actions */
.game-quick-actions {
  display: none;
  padding: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 6px;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.game-quick-actions.active {
  display: flex;
}

.quick-action-btn {
  padding: 4px 8px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.quick-action-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.05);
}

/* User List Button */
#userCountBtn {
  align-self: flex-end;
  margin-bottom: 8px;
  padding: 8px 16px; 
  background: #40444b; 
  color: #fff;
  border: 1px solid #555; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 0.9rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

#userCountBtn:hover { 
  background: #50575e; 
  transform: translateY(-1px); 
}

#userCountBtn .online-indicator {
  width: 8px;
  height: 8px;
  background: #43b581;
  border-radius: 50%;
  animation: pulse 3s infinite;
}

/* Messages */
#messages {
  flex: 1; 
  min-height: 0; 
  overflow-y: auto;
  background: #23272a; 
  border-radius: 6px; 
  padding: 16px; 
  margin-bottom: 8px;
  border: 1px solid #2c2f33;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar {
  width: 8px;
}

#messages::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

#messages::-webkit-scrollbar-thumb {
  background: #40444b;
  border-radius: 4px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background: #50575e;
}

.message { 
  margin-bottom: 12px; 
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.2s;
  animation: messageSlide 0.3s ease-out;
}

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

.message:hover {
  background: rgba(255,255,255,0.02);
}

.message.highlight {
  background: rgba(114, 137, 218, 0.1);
  border-left: 3px solid #7289da;
}

.message .meta {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message .reaction-container {
  display: inline-flex;
  gap: 4px;
  margin-right: 4px;
}

.message .reaction-display {
  background: #4f545c;
  border-radius: 12px;
  padding: 0 6px;
  font-size: 0.75rem;
  cursor: default;
  color: #fff;
}

.message .reaction-display.user-reacted {
  background: #7289da;
}

.message .meta .timestamp {
  font-size: 0.75rem;
  opacity: 0.7;
}

.message .meta .admin-badge {
  background: #f04747;
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: bold;
}

.message .meta .game-badge {
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: bold;
}

.message .meta .edited {
  font-size: 0.7rem;
  opacity: 0.6;
  font-style: italic;
}

.message .text {
  color: #ddd; 
  margin: 4px 0 8px 0;
  overflow-wrap: break-word;
  line-height: 1.6;
}

/* Markdown styling */
.message .text h1, .message .text h2, .message .text h3, 
.message .text h4, .message .text h5, .message .text h6 {
  margin: 0.2em 0;
  color: #fff;
  line-height: 1.2;
}

.message .text h1 { 
  font-size: 1.3em; 
  border-bottom: 1px solid #555; 
  padding-bottom: 0.1em; 
}

.message .text h2 { font-size: 1.2em; }
.message .text h3 { font-size: 1.1em; }

.message .text p {
  margin: 0.2em 0;
}

.message .text a {
  color: #7289da;
  text-decoration: none;
}

.message .text a:hover {
  text-decoration: underline;
}

.message .text code {
  background: #2f3136;
  padding: 1px 3px;
  border-radius: 3px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85em;
  color: #e3e3e3;
}

.message .text pre {
  background: #2f3136;
  border: 1px solid #202225;
  border-radius: 4px;
  padding: 6px;
  overflow-x: auto;
  margin: 0.2em 0;
  font-size: 0.85em;
}

.message .text pre code {
  background: none;
  padding: 0;
  color: #e3e3e3;
  display: block;
}

.message .text blockquote {
  border-left: 3px solid #4f545c;
  margin: 0.2em 0;
  padding-left: 0.6em;
  color: #b9bbbe;
}

.message .text ul, .message .text ol {
  margin: 0.2em 0;
  padding-left: 1.5em;
}

.message .text li {
  margin: 0;
  line-height: 1.3;
}

/* Game Messages */
.game-message {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-left: 4px solid #7289da;
  padding: 12px;
  margin: 8px 0;
  border-radius: 6px;
  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.game-message.system {
  background: linear-gradient(135deg, #0585aa 0%, #047291 100%);
  color: #2d3436;
  font-size: 0.85rem;
  padding: 6px;
  margin: 4px 0;
  line-height: 1.2;
}

.game-message.hunt {
  background: linear-gradient(135deg, #55a3ff 0%, #003d82 100%);
}

.game-message.battle {
  background: linear-gradient(135deg, #fd79a8 0%, #e84393 100%);
}

/* System Messages */
.system-message {
  text-align: center;
  color: #aaa;
  font-style: italic;
  margin: 2px 0;
  padding: 2px;
  background: rgba(255,255,255,0.02);
  border-radius: 4px;
  font-size: 0.75rem;
}

/* Typing indicator */
#typingIndicator { 
  height: 24px; 
  margin-bottom: 8px; 
  font-style: italic; 
  color: #aaa; 
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #aaa;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input bar */
#inputBar { 
  display: flex; 
  gap: 8px; 
  align-items: flex-end;
}

#msgInput {
  flex: 1; 
  padding: 12px; 
  background: #40444b; 
  color: #fff;
  border: 1px solid #555; 
  border-radius: 4px; 
  font-size: 1rem;
  resize: none; 
  min-height: 20px; 
  max-height: 120px;
  font-family: inherit;
  transition: border-color 0.2s;
}

#msgInput:focus {
  outline: none;
  border-color: #7289da;
}

#msgInput::placeholder {
  color: #888;
}

#msgInput.game-mode {
  border-color: #4ecdc4;
  background: linear-gradient(135deg, #40444b, #36393f);
}

#msgInput.game-mode::placeholder {
  color: #4ecdc4;
}

.input-actions {
  display: flex;
  gap: 4px;
}

#fileBtn, #markdownBtn, #emojiBtn, #gameBtn {
  padding: 8px 12px; 
  background: #40444b; 
  color: #fff;
  border: 1px solid #555; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 1.2rem;
  transition: all 0.2s;
  position: relative;
}

#fileBtn:hover, #markdownBtn:hover, #emojiBtn:hover, #gameBtn:hover { 
  background: #50575e; 
  border-color: #7289da;
  transform: scale(1.1);
}

#gameBtn {
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  border-color: #4ecdc4;
  font-weight: bold;
}

#gameBtn:hover {
  background: linear-gradient(45deg, #ff5252, #26a69a);
}

#markdownBtn {
  font-size: 0.9rem;
  font-weight: bold;
}

#fileBtn {
  font-size: 1rem;
}

#fileInput {
  display: none;
}

#sendBtn {
  padding: 12px 20px; 
  background: #7289da; 
  color: #fff;
  border: none; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 1rem;
  transition: all 0.2s;
  font-weight: 500;
}

#sendBtn:hover { 
  background: #677bc4; 
  transform: translateY(-1px); 
}

#sendBtn:disabled { 
  background: #4a4a4a; 
  cursor: not-allowed; 
  transform: none; 
}

/* Context Menu */
#contextMenu {
  position: fixed;
  background: #36393f;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
}

#contextMenu .menu-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

#contextMenu .menu-item:hover {
  background: #40444b;
}

#contextMenu .menu-divider {
  height: 1px;
  background: #555;
  margin: 4px 0;
}

#contextMenu .reaction-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
}

#contextMenu .reaction-item {
  padding: 8px;
  text-align: center;
  cursor: pointer;
  border-radius: 4px;
  font-size: 1.2rem;
  transition: all 0.2s;
}

#contextMenu .reaction-item:hover {
  background: #40444b;
  transform: scale(1.2);
}

#contextMenu .reaction-item.user-reacted {
  background: #7289da;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

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

.modal-content {
  position: absolute;
  top: 50%; 
  left: 50%;
  transform: translate(-50%, -50%);
  background: #36393f;
  border-radius: 8px;
  padding: 20px;
  max-width: 400px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  animation: modalSlide 0.3s ease-out;
}

@keyframes modalSlide {
  from { transform: translate(-50%, -45%); opacity: 0; }
  to { transform: translate(-50%, -50%); opacity: 1; }
}

.modal h3 {
  margin: 0 0 16px 0;
  color: #fff;
}

.modal .close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 24px;
  cursor: pointer;
  transition: color 0.2s;
}

.modal .close-btn:hover {
  color: #fff;
}

/* Notifications */
#notifications {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notification {
  background: #36393f;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 12px 16px;
  color: #fff;
  min-width: 250px;
  max-width: 400px;
  animation: slideIn 0.3s ease-out;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
}

.notification.error {
  border-color: #f04747;
  background: #f04747;
}

.notification.success {
  border-color: #43b581;
  background: #43b581;
}

.notification.info {
  border-color: #7289da;
  background: #7289da;
}

.notification.game {
  border-color: #4ecdc4;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Scroll to bottom button */
#scrollToBottom {
  position: absolute;
  bottom: 80px;
  right: 30px;
  background: #40444b;
  border: 1px solid #555;
  color: #fff;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  display: none;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#scrollToBottom:hover {
  background: #50575e;
  transform: translateY(-2px);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .container { padding: 8px; }
  #login { width: 100%; max-width: 300px; }
  #roomTabs { flex-wrap: wrap; }
  .room-tab { padding: 6px 12px; font-size: 0.9rem; }
  #messages { padding: 8px; }
  .message { margin-bottom: 4px; padding: 4px 8px; }
  .message .text { font-size: 0.9rem; }
  #inputBar { flex-direction: column; align-items: stretch; }
  #msgInput { width: 100%; }
  .input-actions { 
    display: flex; 
    gap: 8px; 
    width: 100%; 
    margin-top: 8px;
  }
  #fileBtn, #markdownBtn, #emojiBtn, #gameBtn { flex: 0 0 auto; }
  #sendBtn { flex: 1; }
  .game-stats { grid-template-columns: repeat(2, 1fr); }
  .game-actions { justify-content: center; }
}