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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #1a1a2e;
  color: #fff;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-size: 2rem;
  margin-bottom: 20px;
  color: #4ecca3;
}

.room-info {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

#roomInput {
  padding: 12px 20px;
  border: 2px solid #4ecca3;
  background: #0f3460;
  color: #fff;
  border-radius: 8px;
  font-size: 1rem;
  min-width: 250px;
}

#roomInput:focus {
  outline: none;
  border-color: #5fd4a8;
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
}

#joinBtn {
  background: #4ecca3;
  color: #1a1a2e;
}

#joinBtn:hover:not(:disabled) {
  background: #5fd4a8;
  transform: translateY(-2px);
}

#leaveBtn {
  background: #e43f5a;
  color: #fff;
}

#leaveBtn:hover:not(:disabled) {
  background: #f05365;
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.controls {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
}

.control-btn {
  background: #0f3460;
  color: #fff;
  border: 2px solid #4ecca3;
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn:hover:not(:disabled) {
  background: #16213e;
  border-color: #5fd4a8;
}

.control-btn.active {
  background: #e43f5a;
  border-color: #e43f5a;
}

.status {
  text-align: center;
  padding: 10px;
  background: #0f3460;
  border-radius: 8px;
  margin-bottom: 20px;
  border: 2px solid #4ecca3;
}

#statusText {
  font-weight: 600;
  color: #4ecca3;
}

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

.video-wrapper {
  position: relative;
  background: #0f3460;
  border-radius: 12px;
  overflow: hidden;
  border: 3px solid #4ecca3;
  /* Aspect ratio for standalone mode only - will be overridden in embedded */
  aspect-ratio: 16/9;
}

.video-wrapper.local {
  border-color: #5fd4a8;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.video-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: #00000099;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.remote-videos {
  /* display: contents makes remote videos appear as direct children of videos-container */
  display: contents;
}

/* In embedded mode, ensure remote-videos container doesn't affect layout */
body.embedded .remote-videos {
  display: contents !important;
  flex: none !important;
}

/* Embedded mode - hide all UI controls */
body.embedded #header,
body.embedded #controls,
body.embedded #status,
body.embedded #embeddedControls {
  display: none !important;
}

body.embedded .container {
  padding: 0;
  max-width: 100%;
  height: 100%;
}

body.embedded .videos-container {
  height: 100%;
  margin: 0;
  /* ZOOM-STYLE LAYOUT: Remote video fullscreen, local video small thumbnail */
  position: relative !important;
  display: block !important;
  background: #000000;
}

/* Remote video (incoming user/tutor) - Fullscreen background */
body.embedded .video-wrapper:not(#localVideoWrapper) {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  border: none !important;
  aspect-ratio: unset !important;
  background: #000000;
}

/* Local video (you) - Small thumbnail in bottom-right corner */
body.embedded #localVideoWrapper {
  position: absolute !important;
  bottom: 16px !important;
  right: 16px !important;
  width: 240px !important;
  max-width: 25% !important;
  height: auto !important;
  aspect-ratio: 16/9 !important;
  z-index: 10 !important;
  border: 2px solid #4ecca3 !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px #00000066;
  overflow: hidden !important;
  background: #0f3460;
}

body.embedded video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* Remote video uses 'contain' to show full frame without cropping */
body.embedded .video-wrapper:not(#localVideoWrapper) video {
  object-fit: contain !important;
}

/* Local video thumbnail uses 'cover' for better appearance */
body.embedded #localVideoWrapper video {
  object-fit: cover !important;
}

body.embedded {
  background: transparent;
  overflow: hidden;
  height: 100vh;
}

body.embedded html {
  overflow: hidden;
  height: 100vh;
}

/* Screen Share Layout Styles - CSS-ONLY (no DOM manipulation) */
.layout-screenshare {
  display: flex !important;
  flex-direction: row;
  height: 100%;
  width: 100%;
  gap: 0;
  grid-template-columns: unset !important;
}

/* When screen sharing is active, local video becomes main display (80%) */
.layout-screenshare #localVideoWrapper.screenshare-active {
  flex: 0 0 80%;
  order: 1;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

.layout-screenshare #localVideoWrapper.screenshare-active video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Remote videos become thumbnail sidebar (20%) during screen share */
.layout-screenshare #remoteVideos.screenshare-thumbnails {
  flex: 0 0 20%;
  order: 2;
  background: #0f0f0f;
  display: flex !important;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
}

.layout-screenshare #remoteVideos.screenshare-thumbnails .video-wrapper {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #2a2a2a;
  transition: border-color 0.2s;
  background: #1a1a1a;
  min-height: 120px;
}

.layout-screenshare #remoteVideos.screenshare-thumbnails .video-wrapper:hover {
  border-color: #4ecca3;
}

.layout-screenshare #remoteVideos.screenshare-thumbnails video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layout-screenshare #remoteVideos.screenshare-thumbnails .video-label {
  font-size: 11px;
  padding: 4px 8px;
}

.screenshare-main {
  flex: 0 0 80%;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.screenshare-main video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.webcam-thumbnails {
  flex: 0 0 20%;
  background: #0f0f0f;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
}

.webcam-thumbnail {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 2px solid #2a2a2a;
  transition: border-color 0.2s;
  background: #1a1a1a;
}

.webcam-thumbnail:hover {
  border-color: #4ecca3;
}

.webcam-thumbnail video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.webcam-thumbnail .video-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: #000000b3;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: #ffffff;
  font-weight: 600;
}

/* Normal layout (no screen share) */
.layout-normal {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
}

/* Split-screen layout: webcam + screen share side by side (50/50) */
.layout-splitscreen {
  display: flex !important;
  flex-direction: row;
  height: 100%;
  width: 100%;
  gap: 4px;
}

/* In split-screen, local video (webcam) takes 50% */
.layout-splitscreen #localVideoWrapper {
  flex: 0 0 50% !important;
  position: relative !important;
  width: 50% !important;
  height: 100% !important;
  border: 2px solid #4ecca3 !important;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

/* In split-screen, screen share takes 50% */
.layout-splitscreen #screenShareWrapper {
  flex: 0 0 50% !important;
  position: relative !important;
  width: 50% !important;
  height: 100% !important;
  display: block !important;
  border: 2px solid #e43f5a !important;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.layout-splitscreen #screenShareWrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Hide remote videos in split-screen mode (they see your shared content) */
.layout-splitscreen #remoteVideos {
  display: none !important;
}

/* Embedded mode split-screen adjustments */
body.embedded .layout-splitscreen {
  height: 100%;
  margin: 0;
  background: #000;
}

body.embedded .layout-splitscreen #localVideoWrapper {
  z-index: 1 !important;
  bottom: unset !important;
  right: unset !important;
  max-width: unset !important;
  aspect-ratio: unset !important;
  box-shadow: none;
}

body.embedded .layout-splitscreen #localVideoWrapper video {
  object-fit: contain !important;
}

body.embedded .layout-splitscreen #screenShareWrapper {
  z-index: 1 !important;
}

/* Mobile split-screen: stack vertically */
@media (max-width: 768px) {
  .layout-splitscreen {
    flex-direction: column !important;
  }

  .layout-splitscreen #localVideoWrapper,
  .layout-splitscreen #screenShareWrapper {
    flex: 0 0 50% !important;
    width: 100% !important;
    height: 50% !important;
  }
}

/* Embedded mode adjustments for screen share layout */
body.embedded .layout-screenshare {
  min-height: unset;
  height: 100%;
  margin: 0;
}

body.embedded .layout-screenshare .screenshare-main {
  min-height: unset;
  height: 100%;
}

body.embedded .layout-screenshare .webcam-thumbnails {
  min-height: unset;
  height: 100%;
}

body.embedded .layout-screenshare .video-wrapper {
  border: none;
}

@media (max-width: 768px) {
  .videos-container {
    grid-template-columns: 1fr;
  }

  .room-info {
    flex-direction: column;
  }

  #roomInput {
    width: 100%;
  }

  /* Mobile: Adjust Zoom-style layout for smaller screens */
  body.embedded #localVideoWrapper {
    width: 140px !important;
    max-width: 30% !important;
    bottom: 8px !important;
    right: 8px !important;
  }

  /* Mobile screen share layout - stack vertically */
  .layout-screenshare {
    flex-direction: column;
  }

  .screenshare-main {
    flex: 0 0 70%;
    min-height: 70vh;
  }

  .webcam-thumbnails {
    flex: 0 0 30%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 30vh;
  }

  .webcam-thumbnail {
    min-width: 150px;
    aspect-ratio: 4/3;
  }
}

/* Device Settings Modal */
.device-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #00000080;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.device-modal-content {
  background: #0f3460;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 4px 20px #00000040;
}

.device-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #ffffff1a;
}

.device-modal-header h3 {
  margin: 0;
  color: #4ecca3;
  font-size: 1.25rem;
}

.close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.close-btn:hover {
  color: #4ecca3;
}

.device-modal-body {
  padding: 20px;
}

.device-group {
  margin-bottom: 20px;
}

.device-group:last-child {
  margin-bottom: 0;
}

.device-group label {
  display: block;
  margin-bottom: 8px;
  color: #4ecca3;
  font-weight: 500;
}

.device-select {
  width: 100%;
  padding: 12px;
  background: #1a1a2e;
  color: #fff;
  border: 2px solid #4ecca3;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.device-select:hover {
  border-color: #5fd4a8;
}

.device-select:focus {
  outline: none;
  border-color: #5fd4a8;
}

.device-select option {
  background: #1a1a2e;
  color: #fff;
}
