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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f1a;
  color: #fff;
}

/* ---- Lobby ---- */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

.header { text-align: center; margin-bottom: 30px; }
.header h1 { font-size: 2rem; color: #e0e0ff; }

.lobby-box {
  background: #1a1a2e;
  padding: 40px;
  border-radius: 16px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.btn {
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { background: #312e81; color: #fff; }
.btn-secondary:hover { background: #3730a3; }
.btn-danger { background: #dc2626; color: #fff; padding: 6px 12px; width: auto; height: 30px; font-size: 0.78rem; border: none; border-radius: 6px; cursor: pointer; white-space: nowrap; line-height: 1; flex: 0 0 auto; }
.btn-danger:hover { background: #b91c1c; }

.btn-small {
  background: transparent;
  color: #9ca3af;
  border: none;
  padding: 2px 6px;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  flex: 0 0 auto;
  width: auto;
  height: auto;
}
.btn-small:hover { color: #fff; }

.btn-action {
  background: #312e81;
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  line-height: 1;
  height: 30px;
  width: auto;
  flex: 0 0 auto;
}
.btn-action:hover { background: #4338ca; }

.divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: #6b7280;
  width: 100%;
  max-width: 400px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #374151;
}
.divider span { padding: 0 12px; }

.join-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 400px;
}
.join-row input {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #374151;
  background: #111827;
  color: #fff;
  font-size: 1rem;
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.join-row input:focus { outline: none; border-color: #4f46e5; }

.status { margin-top: 16px; font-size: 0.9rem; color: #9ca3af; }

/* ---- Device preview (lobby) ---- */
.device-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}
.device-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #6b7280;
  font-size: 0.9rem;
}
.preview-icon { font-size: 2rem; opacity: 0.7; }
.device-preview.camera-on .preview-placeholder { display: none; }

/* ---- Device buttons (split toggle + dropdown) ---- */
.device-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin-bottom: 18px;
}

.device-split {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.device-toggle {
  position: relative;
  background: #312e81;
  color: #fff;
  border: none;
  padding: 10px 12px;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px 0 0 8px;
  transition: background 0.2s;
}
.device-toggle:hover { background: #4338ca; }
.device-toggle.off .dev-icon { opacity: 0.55; }
.device-toggle.off::after {
  content: '';
  position: absolute;
  left: 9px;
  right: 9px;
  top: 50%;
  height: 2px;
  background: #ef4444;
  border-radius: 2px;
  transform: rotate(-35deg);
  pointer-events: none;
}

.device-arrow {
  background: #312e81;
  color: #c7d2fe;
  border: none;
  padding: 10px 8px;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 0 8px 8px 0;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  transition: background 0.2s;
}
.device-arrow:hover { background: #4338ca; }

.settings-btn {
  background: #312e81;
  color: #fff;
  border: none;
  width: 42px;
  padding: 10px 0;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}
.settings-btn:hover { background: #4338ca; }

/* Device dropdown menu */
.device-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 250px;
  max-width: 320px;
  max-height: 260px;
  overflow-y: auto;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: #e5e7eb;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
}
.device-item:hover { background: #1f2a48; }
.device-item.active { color: #a5b4fc; }
.device-item .check { color: #a5b4fc; flex: 0 0 auto; }
.device-item.empty { color: #6b7280; cursor: default; }
.device-item.empty:hover { background: transparent; }

/* Camera menus are anchored to the right so they stay on-screen */
#camMenuLobby, #camMenuRoom { left: auto; right: 0; }

/* In-room (compact) version */
.device-split.room .device-toggle {
  padding: 6px 8px;
  font-size: 0.85rem;
  height: 30px;
  border-radius: 6px 0 0 6px;
}
.device-split.room .device-arrow {
  padding: 6px 5px;
  height: 30px;
  font-size: 0.68rem;
  border-radius: 0 6px 6px 0;
}
.device-split.room .device-toggle.off::after { left: 6px; right: 6px; }

/* ---- Call Layout ---- */
.call { display: none; height: 100vh; }
.call:not(.hidden) { display: block; }

.call-layout {
  display: flex;
  height: 100%;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.videos-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}

.call-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 0.8rem;
  color: #d1d5db;
  z-index: 20;
  pointer-events: none;
  max-width: 80%;
  text-align: center;
}
.call-status:empty { display: none; }

/* Remote video - fills container */
.video-wrapper.remote {
  position: absolute;
  inset: 0;
}
.video-wrapper.remote video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Local video - bottom-right PIP (lecturer: bottom-left) */
.video-wrapper.local {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 180px;
  height: 135px;
  border-radius: 12px;
  overflow: hidden;
  background: #1a1a2e;
  border: 2px solid #4f46e5;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.lecturer-mode .video-wrapper.local {
  right: auto;
  left: 16px;
}
.video-wrapper.local.novideo { display: none; }

.video-wrapper.local video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-wrapper.local .label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
}

/* Non-lecturer mode: side by side */
.videos-container:not(.lecturer-mode) .video-wrapper.remote {
  position: relative;
  inset: auto;
  width: 100%;
  height: 100%;
}
.videos-container:not(.lecturer-mode) {
  display: flex;
}
.videos-container:not(.lecturer-mode) .video-wrapper.remote {
  flex: 1;
}
.videos-container:not(.lecturer-mode) .video-wrapper.local {
  position: relative;
  bottom: auto;
  right: auto;
  width: 50%;
  height: auto;
  min-height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  border-left: 2px solid #374151;
  flex: 1;
}
.videos-container:not(.lecturer-mode) .video-wrapper.local video {
  object-fit: cover;
}
.videos-container:not(.lecturer-mode) .video-wrapper.local .label {
  bottom: 8px;
  left: 8px;
  font-size: 0.8rem;
}
.videos-container:not(.lecturer-mode) .video-wrapper.local {
  border-right: 2px solid #374151;
  border-left: none;
}

/* Mirrored local preview */
video.mirror { transform: scaleX(-1); }

/* ---- Controls ---- */
.controls {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: #1a1a2e;
  border-top: 1px solid #374151;
}

.controls-divider {
  width: 1px;
  height: 24px;
  background: #374151;
}

/* ---- Settings modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.settings-modal {
  background: #1a1a2e;
  border: 1px solid #374151;
  border-radius: 14px;
  width: min(440px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #374151;
  font-weight: 600;
}
.settings-body { padding: 6px 18px 18px; }
.settings-section h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #818cf8;
  margin: 16px 0 4px;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(55, 65, 81, 0.4);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { color: #d1d5db; font-size: 0.9rem; }
.settings-row select {
  background: #111827;
  color: #fff;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  min-width: 150px;
  outline: none;
  cursor: pointer;
}
.settings-row select:focus { border-color: #4f46e5; }
.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #4f46e5;
  cursor: pointer;
}

/* ---- Chat ---- */
.chat-panel {
  width: 0;
  overflow: hidden;
  transition: width 0.25s ease;
  background: #1a1a2e;
  border-left: 1px solid #374151;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-panel.open {
  width: 300px;
}

.chat-header {
  padding: 12px 16px;
  font-weight: bold;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.chat-msg {
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 85%;
  word-wrap: break-word;
  font-size: 0.9rem;
  line-height: 1.4;
}
.chat-msg.you {
  align-self: flex-end;
  background: #4f46e5;
  border-bottom-right-radius: 4px;
}
.chat-msg.remote {
  align-self: flex-start;
  background: #312e81;
  border-bottom-left-radius: 4px;
}
.chat-msg .time {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #374151;
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #374151;
  background: #111827;
  color: #fff;
  font-size: 0.9rem;
  outline: none;
}
.chat-input-row input:focus { border-color: #4f46e5; }
.chat-input-row button {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: #4f46e5;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}
.chat-input-row button:hover { background: #4338ca; }

/* ---- Invite toast ---- */
.invite-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  border: 1px solid #4f46e5;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 300;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.invite-toast .link {
  display: block;
  color: #818cf8;
  font-family: monospace;
  margin-top: 4px;
  word-break: break-all;
}

/* ---- Hidden ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .chat-panel.open { width: 200px; }
  .video-wrapper.local { width: 120px; height: 90px; }
  .controls { flex-wrap: wrap; gap: 4px; }
  .btn-action { font-size: 0.7rem; padding: 4px 8px; height: 28px; }
  .btn-danger { font-size: 0.7rem; padding: 4px 10px; height: 28px; }
  .device-menu { min-width: 190px; }
  .lobby-box { padding: 24px; }
}
