html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #222;
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Écran principal toujours en 16/9 */
.screen {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));

  aspect-ratio: 16 / 9;

  display: flex;
  flex-direction: column;

  overflow: hidden;
  background: black;
}

/* ========================================
   PARTIE HAUTE : PREVIEW ET PROGRAM
   ======================================== */

.top-row {
  width: 100%;
  height: 50%;

  display: flex;

  min-width: 0;
  min-height: 0;

  overflow: hidden;
}

.tv-box {
  flex: 1 1 0;

  width: auto;
  height: 100%;

  min-width: 0;
  min-height: 0;

  position: relative;
  overflow: hidden;

  border: 4px solid white;
}

#preview {
  position: relative;
  background: black;
  overflow: hidden;
}

/* Le bloc Program possède déjà la classe tv-box */
.live-wrapper {
  flex: 1 1 0;

  width: auto;
  height: 100%;

  min-width: 0;
  min-height: 0;

  position: relative;
  overflow: hidden;
}

#live {
  position: relative;

  width: 100%;
  height: 100%;

  min-width: 0;
  min-height: 0;

  overflow: hidden;
  background: black;
}

/* Contenu affiché dans Preview et Program */
#preview video,
#live video,
#preview canvas,
#live canvas {
  display: block;

  width: 100%;
  height: 100%;

  max-width: 100%;
  max-height: 100%;

  object-fit: contain;
}

/* Guide superposé sur Preview */
.preview-overlay {
  position: absolute;
  inset: 0;

  width: 100%;
  height: 100%;

  object-fit: fill;

  pointer-events: none;
  z-index: 20;
}

/* Fond noir pour le Fade To Black */
#black {
  position: absolute;
  inset: 0;

  background: black;
  opacity: 0;

  transition: opacity 1s;

  pointer-events: none;
  z-index: 50;
}

/* Transition entre les sources */
.fade-video {
  position: absolute;
  inset: 0;

  width: 100%;
  height: 100%;

  object-fit: contain;

  opacity: 1;
  transition: opacity 500ms ease;

  z-index: 5;
}

/* ========================================
   PARTIE BASSE : SOURCES
   ======================================== */

.bottom-row {
  width: 100%;
  height: 50%;

  display: grid;

  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));

  min-width: 0;
  min-height: 0;

  overflow: hidden;
}

.small-box {
  position: relative;

  min-width: 0;
  min-height: 0;

  overflow: hidden;

  border: 4px solid white;
  background: black;
}

.small-box video,
.small-box canvas {
  display: block;

  width: 100%;
  height: 100%;

  min-width: 0;
  min-height: 0;

  max-width: 100%;
  max-height: 100%;

  object-fit: contain;
}

/* Sources vides */
#pc-x,
#pc-local {
  background: black;
}

/* ========================================
   ÉTIQUETTES
   ======================================== */

.label-box {
  position: absolute;

  bottom: 15px;
  left: 50%;

  transform: translateX(-50%);

  max-width: calc(100% - 20px);
  padding: 3px 10px;

  color: white;
  background: #555;

  border: 4px solid white;
  border-radius: 3px;

  font-family: Arial, sans-serif;
  font-size: 16px;
  white-space: nowrap;

  overflow: hidden;
  text-overflow: ellipsis;

  z-index: 30;
}

/* ========================================
   SÉLECTION DE LA VIDÉO PC1
   ======================================== */

#pc1 {
  position: relative;
}

#pc1-video-select {
  position: absolute;

  top: 8px;
  left: 8px;

  width: 150px;
  max-width: calc(100% - 16px);

  padding: 4px;

  background: rgba(0, 0, 0, 0.7);
  color: white;

  border: 1px solid white;
  border-radius: 4px;

  z-index: 40;
}

/* ========================================
   BOUTON D'INFORMATION DU DÉLAI
   ======================================== */

.delay-button {
  position: absolute;

  top: 12px;
  left: 50%;

  transform: translateX(-50%);

  max-width: calc(100% - 24px);
  padding: 8px 14px;

  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;

  background: rgba(0, 0, 0, 0.65);
  color: white;

  font-size: 13px;
  font-weight: 600;
  text-align: center;

  cursor: pointer;
  backdrop-filter: blur(4px);

  z-index: 40;
}

.delay-button:hover {
  background: rgba(30, 30, 30, 0.85);
}

/* ========================================
   ANCIENS BOUTONS DE TEST
   ======================================== */

.bottom-buttons {
  height: 100px;
}