/* -------------------- RESET BÁSICO -------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root {
  --topbar-h: 56px;
}

html,
body {
  min-height: 100%;
}

body {
  background: #0b0c10;
  color: #f9fafb;
}

/* -------------------- LAYOUT GENERAL -------------------- */
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 8px 16px;
  background: #111827;
  border-bottom: 1px solid #1f2933;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 600;
  font-size: 18px;
}

/* zona de videos */
.stage {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 10px;
  align-items: stretch;
}

.video-box {
  position: relative;
  flex: 1 1 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover; /* rellenar 16:9 sin deformar */
  object-position: center;
}

/* loading del remoto */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #3b82f6;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -------------------- SELECTORES BAJO LA CÁMARA LOCAL -------------------- */
#local-container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* contenedor general, oculto por defecto */
#deviceSelectors {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 80%;
  user-select: none;
}

#local-container:hover #deviceSelectors {
  display: flex;
}

.selector-row {
  display: flex;
  flex-direction: column;
}

.selector-main {
  display: flex;
  align-items: center;
  background: #b1b1b1;
  color: #111827;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
}

.selector-main:hover {
  filter: brightness(0.95);
}

.selector-icon {
  width: 16px;
  height: 16px;
  margin-right: 6px;
}

.selector-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selector-arrow {
  margin-left: 6px;
}

.selector-options {
  background: #d0d0d0;
  color: #111827;
  border-radius: 4px;
  margin-top: 2px;
  padding: 4px;
  display: none;
  max-height: 130px;
  overflow-y: auto;
}

.selector-option {
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}

.selector-option:hover {
  background: #b8b8b8;
}

/* -------------------- BOTONES -------------------- */
.controls {
  padding: 10px;
  display: flex;
  justify-content: center;
  gap: 10px;
  border-top: 1px solid #1f2933;
  background: #111827;
}

.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  cursor: pointer;
  transition: 0.15s;
}

.start {
  background: #2563eb;
  color: #fff;
}

.start:hover {
  filter: brightness(1.05);
}

.stop {
  background: #dc2626;
  color: #fff;
}

.stop:hover {
  filter: brightness(1.05);
}

.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* -------------------- RESPONSIVE -------------------- */
@media (max-width: 900px) {
  .topbar {
    min-height: var(--topbar-h);
    padding: 10px 14px;
  }

  #app {
    min-height: 100vh;
  }

  .stage {
    padding: 0;
    gap: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - var(--topbar-h));
    overflow: hidden;
  }

  .video-box {
    border-radius: 0;
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
    width: 100vw;
    max-width: 100vw;
    max-height: calc(100vh - var(--topbar-h));
  }

  .video-box video {
    object-fit: cover;
  }

  .controls {
    display: none;
  }

  /* Desactivar animaciones previas para un layout que llena pantalla */
  .stage,
  .video-box,
  .controls,
  .btn.start {
    animation: none !important;
    transition: none !important;
  }
}

/* Apilar en vertical (retrato): dos cuadrados exactos */
@media (max-width: 900px) and (orientation: portrait) {
  .stage {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
  }

  .video-box {
    width: min(100vw, calc((100vh - var(--topbar-h)) / 2));
    height: auto;
  }
}

/* Colocar lado a lado en horizontal (apaisado): dos cuadrados iguales */
@media (max-width: 900px) and (orientation: landscape) {
  .stage {
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }

  .video-box {
    width: min(50vw, calc(100vh - var(--topbar-h)));
    height: auto;
  }
}

/* -------------------- ANIMACIONES SOLO MÓVIL -------------------- */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes gentleFloat {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes pulseRing {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45);
  }
  70% {
    box-shadow: 0 0 0 18px rgba(37, 99, 235, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
  }
}

@media (max-width: 900px) and (prefers-reduced-motion: no-preference) {
  .stage {
    animation: fadeUp 0.65s ease-out both;
  }

  .video-box {
    animation: gentleFloat 10s ease-in-out infinite;
    will-change: transform;
  }

  .controls {
    animation: fadeUp 0.65s ease-out 0.08s both;
  }

  .btn.start:not(.disabled) {
    animation: pulseRing 3.4s ease-out infinite;
  }
}

@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .stage,
  .video-box,
  .controls,
  .btn.start {
    animation: none !important;
    transition: none !important;
  }
}
