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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
  background: #f5f5f5;
  font-size: 14px;
  line-height: 1.5;
}

.container {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 1.25rem;
  margin-right: auto;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.user-count {
  font-size: 0.875rem;
  font-weight: 600;
  color: #1f2937;
  padding: 4px 8px;
  background: #10b981;
  color: white;
  border-radius: 4px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  color: #4b5563;
  padding: 4px 8px;
  background: #f9fafb;
  border-radius: 4px;
}

.change-name-btn {
  background: none;
  border: none;
  color: #3b82f6;
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0;
  text-decoration: underline;
}

.change-name-btn:hover {
  color: #2563eb;
}

.status {
  font-size: 0.875rem;
  font-weight: 500;
}

.status.live {
  color: #22c55e;
}

.status.offline {
  color: #ef4444;
}

.rules-btn {
  padding: 6px 12px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
}

.rules-btn:hover {
  background: #e5e7eb;
}

.reconnect-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 8px 16px;
  text-align: center;
  font-size: 0.875rem;
}

.pinned-message {
  background: #f0f9ff;
  border-bottom: 1px solid #bfdbfe;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pinned-label {
  font-size: 0.875rem;
}

.message-list {
  height: 50vh;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px 16px;
}

.typing-indicator {
  padding: 8px 16px;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  font-size: 0.8rem;
  color: #6b7280;
  font-style: normal;
  min-height: 32px;
  display: flex;
  align-items: center;
  animation: fadeIn 150ms linear;
  letter-spacing: 0.02em;
  opacity: 0.8;
}

.new-messages-banner {
  position: sticky;
  bottom: 0;
  background: #2563eb;
  color: white;
  padding: 8px 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 10;
  cursor: pointer;
  animation: slideUp 200ms linear;
}

.new-messages-banner button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.new-messages-banner button:hover {
  background: rgba(255, 255, 255, 0.3);
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

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

@media (min-width: 768px) {
  .message-list {
    height: 60vh;
    max-height: 500px;
  }
}

/* Mobile-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  .message-list {
    -webkit-overflow-scrolling: touch;
  }
  
  .composer {
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 20;
  }
}

.message {
  margin-bottom: 12px;
  position: relative;
  padding: 8px;
  padding-right: 20px;
  margin-left: -8px;
  margin-right: -8px;
  border-radius: 4px;
  animation: slideIn 200ms linear;
  transform-origin: left center;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: baseline;
}

.message:hover {
  background: #f9fafb;
}

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

.message-name {
  font-weight: 600;
  color: #1f2937;
  letter-spacing: -0.01em;
}

.message-time {
  font-size: 0.75rem;
  color: #6b7280;
  letter-spacing: 0.02em;
  opacity: 0.7;
}

.reply-btn {
  font-size: 0.75rem;
  color: #6b7280;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  user-select: none;
  padding: 2px 6px;
  border-radius: 3px;
}

/* Show reply button on desktop hover */
@media (hover: hover) {
  .message:hover .reply-btn {
    opacity: 0.7;
  }
  
  .reply-btn:hover {
    opacity: 1 !important;
    background: #e5e7eb;
    color: #374151;
  }
}

/* Always visible on touch devices with different styling */
@media (hover: none) {
  .reply-btn {
    display: none;
  }
}

.message-text {
  word-wrap: break-word;
  color: #374151;
  grid-column: 1 / -1;
  letter-spacing: -0.01em;
  font-size: 0.95rem;
  margin-top: 2px;
}

.delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message:hover .delete-btn {
  opacity: 1;
}

.reply-preview {
  background: #eff6ff;
  border-left: 3px solid #3b82f6;
  padding: 8px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideIn 150ms linear;
  border-radius: 4px;
}

.reply-preview-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.reply-preview-label {
  font-size: 0.75rem;
  color: #6b7280;
}

.reply-preview-text {
  font-size: 0.875rem;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0 4px;
}

.reply-cancel:hover {
  color: #ef4444;
}

.message-reply {
  grid-column: 1 / -1;
  padding: 4px 8px;
  margin: 4px 0;
  background: #f9fafb;
  border-left: 2px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.875rem;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.reply-arrow {
  color: #9ca3af;
  flex-shrink: 0;
}

.reply-name {
  font-weight: 600;
  flex-shrink: 0;
}

.reply-text {
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer {
  border-top: 1px solid #e0e0e0;
  padding: 12px 16px;
}

.input-row {
  margin-bottom: 8px;
  position: relative;
}

.message-input {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.95rem;
  min-height: 44px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.message-input {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
  padding-right: 60px;
}

.char-count {
  position: absolute;
  right: 10px;
  bottom: 10px;
  font-size: 0.75rem;
  color: #6b7280;
}

.char-count.warning {
  color: #ef4444;
}

.send-btn {
  padding: 10px 24px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  min-height: 44px;
  width: 100%;
}

.send-btn:hover:not(:disabled) {
  background: #2563eb;
}

.send-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.host-bar {
  background: #fef3c7;
  border-top: 1px solid #fbbf24;
  padding: 12px 16px;
}

.host-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  font-size: 0.875rem;
}

.host-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.host-controls input[type="range"] {
  width: 60px;
}

.host-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid #d97706;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
}

.host-btn:hover {
  background: #fef3c7;
}

.rules-dialog {
  max-width: 400px;
  padding: 20px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.rules-dialog::backdrop {
  background: rgba(0,0,0,0.5);
}

.rules-dialog h2 {
  margin-bottom: 16px;
}

.rules-dialog ul {
  margin: 16px 0;
  padding-left: 20px;
}

.rules-dialog li {
  margin-bottom: 8px;
  color: #4b5563;
}

.rules-dialog button {
  width: 100%;
  padding: 10px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.rules-dialog button:hover {
  background: #2563eb;
}

.name-dialog {
  max-width: 350px;
  padding: 20px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.name-dialog::backdrop {
  background: rgba(0,0,0,0.5);
}

.name-dialog h2 {
  margin-bottom: 16px;
  font-size: 1.25rem;
}

.name-dialog-input {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 1rem;
  margin-bottom: 16px;
  min-height: 44px;
}

.dialog-buttons {
  display: flex;
  gap: 8px;
}

.dialog-buttons button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

#saveNameBtn {
  background: #3b82f6;
  color: white;
}

#saveNameBtn:hover {
  background: #2563eb;
}

#cancelNameBtn {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

#cancelNameBtn:hover {
  background: #e5e7eb;
}

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
}

.toast {
  background: #1f2937;
  color: white;
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 8px;
  animation: slideIn 0.3s ease-out;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.toast.fade-out {
  animation: fadeOut 0.3s ease-out;
}

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

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}