/* CSS Variables for theming */
:root {
  /* Light theme colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #e2e8f0;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border-color: #e2e8f0;
  --accent-primary: #3182ce;
  --accent-secondary: #63b3ed;
  --accent-hover: #2c5aa0;
  --success: #38a169;
  --warning: #d69e2e;
  --error: #e53e3e;
  --shadow: rgba(0, 0, 0, 0.1);
  
  /* Layout */
  --header-height: 70px;
  --chat-width: 320px;
  --border-radius: 8px;
  --transition: all 0.2s ease;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

[data-theme="dark"] {
  --bg-primary: #1a202c;
  --bg-secondary: #2d3748;
  --bg-tertiary: #4a5568;
  --text-primary: #f7fafc;
  --text-secondary: #e2e8f0;
  --text-muted: #a0aec0;
  --border-color: #4a5568;
  --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #e2e8f0;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border-color: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.1);
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: var(--transition);
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

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

.btn-primary {
  background: var(--accent-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-secondary);
}

/* Input fields */
input, textarea {
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

/* Landing page styles */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.landing-header {
  text-align: center;
  margin-bottom: 60px;
  position: relative;
}

.logo-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.logo {
  width: 48px;
  height: 48px;
}

.landing-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.tagline {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: var(--transition);
}

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

.action-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 32px;
  width: 100%;
  max-width: 700px;
  margin-bottom: 60px;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 4px 6px var(--shadow);
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--shadow);
}

.card h2 {
  font-size: 1.5rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.join-form {
  display: flex;
  gap: 12px;
  flex-direction: column;
}

.join-form input {
  flex: 1;
  text-transform: uppercase;
  text-align: center;
  font-weight: 600;
  letter-spacing: 2px;
}

.features {
  text-align: center;
  width: 100%;
  max-width: 600px;
}

.features h3 {
  font-size: 1.3rem;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
}

.feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-radius: var(--border-radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

.feature-icon {
  font-size: 2rem;
}

/* Room page styles */
.room-body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

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

.room-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.room-title {
  font-size: 1.2rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.viewers-count {
  color: var(--text-secondary);
  font-size: 14px;
}

.user-avatars {
  display: flex;
  gap: -8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid var(--bg-primary);
  margin-left: -8px;
  position: relative;
}

.user-avatar:first-child {
  margin-left: 0;
}

.user-avatar.host::after {
  content: "👑";
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 12px;
}

.room-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.video-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  min-width: 0;
}

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16/9;
  max-height: calc(100vh - var(--header-height) - 200px);
}

.video-player {
  width: 100%;
  height: 100%;
  position: relative;
}

.no-video-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.video-controls {
  margin-top: 24px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 16px;
  border: 1px solid var(--border-color);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.control-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 16px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}

.control-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.control-icon {
  font-size: 18px;
}

.seek-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.seek-slider, .volume-slider {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  border: none;
  cursor: pointer;
}

.seek-slider::-webkit-slider-thumb,
.volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
}

.volume-slider {
  max-width: 100px;
}

.time-display {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.host-controls {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.url-input-container {
  display: flex;
  gap: 12px;
}

.video-url-input {
  flex: 1;
  min-width: 0;
}

/* Chat styles */
.chat-section {
  width: var(--chat-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

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

.chat-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--border-radius);
  font-size: 16px;
  transition: var(--transition);
}

.chat-action-btn:hover {
  background: var(--bg-tertiary);
}

.chat-messages {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: slideIn 0.2s ease;
}

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

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.message-author {
  font-weight: 600;
  color: var(--accent-primary);
}

.message-time {
  color: var(--text-muted);
}

.host-badge {
  background: var(--warning);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.message-text {
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-text a {
  color: var(--accent-primary);
  text-decoration: none;
}

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

.typing-indicator {
  padding: 12px 20px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 14px;
  border-top: 1px solid var(--border-color);
}

.chat-input-container {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
}

.chat-input-container textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  font-family: inherit;
}

/* Emoji picker */
.emoji-picker {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  padding: 0;
  max-width: 300px;
}

.emoji-picker::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.emoji-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.emoji-header h4 {
  margin: 0;
  font-size: 1rem;
}

.emoji-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 24px;
  padding: 8px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
}

.emoji-btn:hover {
  background: var(--bg-secondary);
}

/* Debug panel */
.debug-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 16px;
  font-size: 12px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 1000;
}

.debug-panel h4 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

.debug-info > div {
  margin-bottom: 4px;
  color: var(--text-secondary);
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 25px var(--shadow);
}

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

.modal-content input {
  width: 100%;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: center;
}

/* Toast styles */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  box-shadow: 0 4px 12px var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  animation: toastSlideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--error);
}

.toast.warning {
  border-left: 4px solid var(--warning);
}

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

/* Setup screen */
.setup-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.setup-screen.hidden {
  display: none;
}

.setup-content {
  text-align: center;
  max-width: 500px;
  padding: 40px;
}

.setup-content h2 {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.setup-content p {
  margin-bottom: 24px;
  color: var(--text-secondary);
}

/* Utility classes */
.hidden {
  display: none !important;
}

.host-only {
  display: none;
}

.mobile-only {
  display: none;
}

/* Mobile styles */
@media (max-width: 768px) {
  .room-main {
    flex-direction: column;
  }
  
  .chat-section {
    width: 100%;
    height: 300px;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
  
  .mobile-only {
    display: block;
  }
  
  .mobile-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
  }
  
  .mobile-chat-content {
    background: var(--bg-primary);
    width: 100%;
    height: 70%;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
  }
  
  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }
  
  .mobile-chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .video-section {
    padding: 16px;
  }
  
  .control-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .seek-container {
    order: 1;
    width: 100%;
    margin-top: 8px;
  }
  
  .join-form {
    flex-direction: row;
    gap: 8px;
  }
  
  .action-cards {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .card {
    padding: 24px;
  }
  
  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .room-header {
    padding: 0 16px;
  }
  
  .room-title {
    font-size: 1rem;
  }
  
  .toast {
    min-width: auto;
    margin: 0 16px;
  }
  
  .toast-container {
    right: 0;
    left: 0;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 20px 16px;
  }
  
  .landing-header h1 {
    font-size: 2rem;
  }
  
  .tagline {
    font-size: 1rem;
  }
  
  .card {
    padding: 20px;
  }
  
  .feature-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .url-input-container {
    flex-direction: column;
  }
  
  .control-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .seek-container {
    order: 0;
    margin-top: 0;
  }
}

/* Host-specific styles */
.is-host .host-only {
  display: block;
}

.is-host .host-controls {
  display: block !important;
}

/* Focus styles for accessibility */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

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

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

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

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

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