body {
  font-family: Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  background-color: #f0f0f0;
}

#main-stream-container {
  position: relative;
  width: min(1280px, 96vw);
  overflow: hidden;
  background: #000;
  border: 1px solid #ccc;
  margin-bottom: 20px;
}

.stream-container {
  position: relative;
}

#camera-stage { position: relative; }
.printer-status { color: #e4e4e7; background: #18181b; font-size: 13px; line-height: 1.4; text-align: left; overflow-wrap: anywhere; }
#main-printer-status { box-sizing: border-box; min-height: 36px; margin: 0; padding: 8px 10px; }
#secondary-streams .printer-status { position: absolute; bottom: 0; left: 0; right: 0; padding: 3px 5px; font-size: 12px; pointer-events: none; }

#main-stream {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
}

#main-stream img { position: absolute; inset: 0; }
#main-label { z-index: 1; }

#main-stream img, #secondary-streams img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#secondary-streams {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(200% / 3);
  height: calc(100% / 3);
  z-index: 2;
  transition: transform 180ms ease;
}

#secondary-streams.collapsed { transform: translateX(100%); }

.previews-below #secondary-streams {
  position: relative;
  width: calc(100% - 32px);
  height: auto;
  margin-left: 32px;
}

.previews-below #secondary-camera-panels { height: auto; aspect-ratio: 32 / 9; }
.previews-below #secondary-streams.collapsed { height: 0; }
.previews-below #secondary-streams.collapsed #camera-previews-toggle { top: -8px; transform: translateY(-100%); }

#secondary-camera-panels {
  display: flex;
  width: 100%;
  height: 100%;
}

#secondary-streams .stream-container {
  flex: 0 0 50%;
  min-width: 0;
  height: 100%;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 0;
  background: #000;
  cursor: pointer;
}

#camera-previews-toggle, #camera-layout-toggle {
  position: absolute;
  width: 32px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #71717a;
  background: rgba(16, 17, 19, 0.92);
  color: #fff;
  cursor: pointer;
}

#camera-previews-toggle { right: 100%; top: 50%; transform: translateY(-50%); border-right: 0; border-radius: 4px 0 0 4px; }
#camera-layout-toggle { right: 8px; bottom: 8px; height: 32px; border-radius: 4px; z-index: 3; }
#camera-layout-toggle .layout-inside-icon, .previews-below #camera-layout-toggle .layout-below-icon { display: none; }
.previews-below #camera-layout-toggle .layout-inside-icon { display: block; }
.collapsed #camera-previews-toggle { right: calc(100% + 44px); }
.collapsed #camera-previews-toggle svg { transform: rotate(180deg); }
#main-stream-container button:hover { border-color: #6ee7b7; }
#main-stream-container button:focus-visible { outline: 2px solid #6ee7b7; outline-offset: -3px; }
#secondary-streams .camera-label { top: 4px; left: 4px; right: 4px; width: fit-content; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; padding: 2px 4px; }
@media (prefers-reduced-motion: reduce) { #secondary-streams { transition: none; } }

.camera-label {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 5px;
  font-size: 14px;
}

/* The selected printer's second cam sits in the stage's top-right corner; a click swaps the two.
   The box takes the shape of the cam it shows (nozzle 4:3, front 16:9), so neither picture gets bars. */
#nozzle-inset {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 30%;
  aspect-ratio: 4 / 3;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid #ccc;
  background: #000;
  cursor: pointer;
}
#nozzle-inset.front { aspect-ratio: 16 / 9; }
#nozzle-inset[hidden] { display: none; }
/* The label wraps rather than cut "offline" off on a phone-sized inset. */
#nozzle-inset .camera-label { top: 4px; left: 4px; z-index: 1; max-width: calc(100% - 16px); font-size: 11px; line-height: 1.3; padding: 2px 4px; text-align: left; word-break: keep-all; overflow-wrap: anywhere; }
#nozzle-inset.offline img { opacity: 0.45; }
#nozzle-note { margin: 0; padding: 0 10px 8px; color: #a1a1aa; }
#nozzle-note[hidden] { display: none; }

/* Phone: the inset moves to the lower-right corner and the other printers go below the stage. */
@media (max-width: 600px) {
  #nozzle-inset { top: auto; bottom: 8px; right: 8px; width: 35%; }
  #camera-layout-toggle { display: none; }
  #secondary-streams { position: relative; width: calc(100% - 32px); height: auto; margin-left: 32px; }
  #secondary-camera-panels { height: auto; aspect-ratio: 32 / 9; }
  #secondary-streams.collapsed { transform: none; height: 0; }
  #secondary-streams.collapsed #secondary-camera-panels { visibility: hidden; }
  #secondary-streams.collapsed #camera-previews-toggle { right: 100%; top: -8px; transform: translateY(-100%); }
}

#main-stream-container { width: min(1280px, 96vw); }
