:root {
  /* Light mode colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --success: #34a853;
  --error: #ea4335;
  --warning: #fbbc04;
  --border: #dadce0;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.2);
}

.dark-mode {
  /* Dark mode colors */
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #3d3d3d;
  --text-primary: #ffffff;
  --text-secondary: #b3b3b3;
  --accent: #4285f4;
  --accent-hover: #5a95f5;
  --success: #34a853;
  --error: #ea4335;
  --warning: #fbbc04;
  --border: #404040;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.5);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Screen management */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Pre-join screen */
#prejoin {
  background: var(--bg-primary);
  padding: 2rem;
}

.container {
  max-width: 500px;
  width: 100%;
  text-align: center;
}

header h1 {
  font-size: 3rem;
  font-weight: 300;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 1rem;
}

.join-form {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 6px var(--shadow);
}

.form-group {
  margin-bottom: 1.5rem;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.media-preview {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 1.5rem auto;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-tertiary);
  aspect-ratio: 16/9;
}

#previewVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-controls {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn-primary,
.btn-danger,
.btn-control,
.btn-icon {
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 1rem;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-danger {
  background: var(--error);
  color: white;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.btn-danger:hover {
  background: #d33b2c;
}

.btn-control {
  background: var(--bg-secondary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem;
  min-width: 70px;
  border: 2px solid transparent;
}

.btn-control:hover {
  background: var(--bg-tertiary);
}

.btn-control.active {
  background: var(--accent);
  color: white;
}

.btn-control.active .icon {
  filter: brightness(0) invert(1);
}

.btn-icon {
  background: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.btn-icon.active {
  background: var(--error);
}

.btn-icon .icon {
  font-size: 1.2rem;
}

.btn-control .icon {
  font-size: 1.5rem;
}

.btn-control .label {
  font-size: 0.75rem;
}

/* Meeting screen */
#meeting {
  background: var(--bg-primary);
  flex-direction: column;
}

.meeting-container {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
}

.meeting-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.meeting-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.meeting-info h2 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
}

.status-indicator {
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-indicator.connecting {
  background: var(--warning);
  color: #000;
}

.status-indicator.connected {
  background: var(--success);
  color: white;
}

.status-indicator.disconnected,
.status-indicator.failed {
  background: var(--error);
  color: white;
}

/* Video container */
.video-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
  background: var(--bg-primary);
}

.video-wrapper {
  position: relative;
  background: var(--bg-tertiary);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16/9;
  min-height: 200px;
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-label {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  backdrop-filter: blur(10px);
}

/* Controls bar */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.controls-left,
.controls-right {
  display: flex;
  gap: 0.5rem;
}

.controls-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 200px;
}

.local-video-wrapper {
  position: relative;
  width: 100%;
  max-width: 150px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-tertiary);
  aspect-ratio: 16/9;
}

#localVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Chat panel */
.chat-panel {
  position: absolute;
  right: -400px;
  top: 0;
  bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  z-index: 100;
}

.chat-panel.open {
  right: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.chat-header h3 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-message {
  background: var(--bg-primary);
  padding: 0.75rem;
  border-radius: 8px;
  max-width: 80%;
}

.chat-message.own {
  align-self: flex-end;
  background: var(--accent);
  color: white;
}

.chat-sender {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  opacity: 0.8;
}

.chat-text {
  font-size: 0.9rem;
  word-wrap: break-word;
}

.chat-time {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.25rem;
}

.chat-input-container {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.chat-input-container input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.chat-input-container input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Error overlay */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.overlay.active {
  display: flex;
}

.overlay-content {
  background: var(--bg-primary);
  padding: 2rem;
  border-radius: 12px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px var(--shadow-lg);
}

.overlay-content h3 {
  margin-bottom: 1rem;
  color: var(--error);
}

.overlay-content p {
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Responsive design */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  header h1 {
    font-size: 2rem;
  }

  .join-form {
    padding: 1.5rem;
  }

  .meeting-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }

  .meeting-info h2 {
    font-size: 1rem;
  }

  .controls-bar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }

  .controls-left,
  .controls-right {
    flex: 1;
    justify-content: center;
  }

  .controls-center {
    order: -1;
    width: 100%;
    max-width: 100%;
    margin-bottom: 0.5rem;
  }

  .local-video-wrapper {
    max-width: 200px;
  }

  .btn-control {
    min-width: 60px;
    padding: 0.5rem;
  }

  .btn-control .icon {
    font-size: 1.25rem;
  }

  .btn-control .label {
    font-size: 0.7rem;
  }

  .chat-panel {
    width: 100%;
    right: -100%;
  }
}

@media (max-width: 480px) {
  .video-container {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .video-wrapper {
    min-height: 150px;
  }

  .controls-left,
  .controls-right {
    gap: 0.25rem;
  }

  .btn-control {
    min-width: 50px;
    padding: 0.4rem;
  }
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn-primary,
  .btn-control,
  .btn-icon {
    min-height: 44px;
    min-width: 44px;
  }

  .form-group input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.screen.active {
  animation: fadeIn 0.3s ease;
}

