:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e8ee;
  --muted: #8b93a4;
  --accent: #4da3ff;
  --accent-rgb: 77, 163, 255;
  --warn: #ff7b72;
  --thumb: #3a4152;
  color-scheme: dark; /* barras de desplazamiento y controles nativos en oscuro */
}

* { scrollbar-width: thin; scrollbar-color: var(--thumb) transparent; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100vh;
}
.app.menu-hidden { grid-template-columns: 1fr; }
.app.menu-hidden .panel { display: none; }

/* ---------- Pantallas ---------- */
.wall {
  --cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr)); /* dos líneas (una si hay una sola pantallita) */
  gap: 6px;
  padding: 6px;
  min-height: 0;
}

.screen {
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .15s;
}
.screen[hidden] { display: none; }
.screen[draggable="true"] { cursor: grab; }
.screen.dragging { opacity: .5; }
/* Mientras se arrastra, los iframes no se tragan el "soltar" */
.app.is-dragging .media iframe { pointer-events: none; }

/* Halo suave de la pantalla con foco */
.screen.active {
  z-index: 2;
  box-shadow: 0 0 0 1px rgba(var(--accent-rgb), .4), 0 0 12px 2px rgba(var(--accent-rgb), .25);
}
.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
}
.screen.active::after {
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), .55), inset 0 0 14px rgba(var(--accent-rgb), .16);
}
.screen.dragover::after { box-shadow: inset 0 0 0 2px #7ee787; }

.media, .media video, .media iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}
.media video { object-fit: contain; }
/* El iframe de YouTube se traga los clics: solo es interactivo cuando tiene foco */
.screen:not(.active) .media iframe { pointer-events: none; }

.empty, .paused {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 12px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}
.empty small, .paused small { font-size: 12px; opacity: .8; }
.screen.is-empty .empty, .screen.is-suspended .paused { display: flex; }

/* Cadenas de solo audio: ecualizador de adorno */
.radio {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
}
.screen.is-audio .radio { display: flex; }
.radio .eq { display: flex; align-items: flex-end; gap: 6px; height: 44px; }
.radio .eq i {
  width: 8px;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transform-origin: bottom;
  animation: eq 1s ease-in-out infinite;
}
.radio .eq i:nth-child(2) { background: #7ee787; animation-delay: -.35s; }
.radio .eq i:nth-child(3) { background: #f2cc60; animation-delay: -.7s; }
.radio .eq i:nth-child(4) { background: #bc8cff; animation-delay: -.2s; }
.radio .eq i:nth-child(5) { background: #ff7b72; animation-delay: -.55s; }
.radio-name { font-size: 15px; font-weight: 600; color: var(--muted); }
@keyframes eq {
  0%, 100% { transform: scaleY(.2); }
  50% { transform: scaleY(1); }
}
@media (prefers-reduced-motion: reduce) { .radio .eq i { animation: none; transform: scaleY(.6); } }

/* Aviso de los reproductores incrustados con sonido propio (Atresplayer) */
.hint {
  position: absolute;
  z-index: 2;
  left: 0; right: 0; bottom: 0;
  display: none;
  padding: 14px 10px 6px;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.8));
  font-size: 12px;
  text-align: center;
  color: #d5d9e2;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.screen.is-atres .hint { display: block; }
.screen.is-atres:hover .hint,
.screen.is-atres.active .hint { opacity: 1; }
.screen.is-atres .hint:empty { display: none; }

/* Botón para quitar los controles de un reproductor incrustado (solo Atresplayer) */
.actions .b-touch { display: none; }
.screen.is-atres .actions .b-touch { display: inline-block; }
.actions .b-touch[aria-pressed="true"] { background: var(--accent); color: #06121f; }
.screen.no-touch .media iframe { pointer-events: none; }

.bar {
  position: absolute;
  z-index: 2; /* por encima del aviso de error, para poder quitar la cadena */
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: linear-gradient(rgba(0,0,0,.75), rgba(0,0,0,0));
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.screen:hover .bar,
.screen.active .bar,
.screen.has-error .bar { opacity: 1; }
.screen.is-empty .bar .actions { display: none; }

.num {
  pointer-events: auto; /* el número y el nombre sirven de asa para arrastrar */
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  font-size: 12px;
  font-weight: 600;
}
.name { flex: 1; font-weight: 600; text-shadow: 0 1px 2px #000; pointer-events: auto; }
.aud { font-size: 13px; text-shadow: 0 1px 2px #000; }
.actions { display: flex; gap: 4px; pointer-events: auto; }
.actions button {
  border: 0;
  border-radius: 4px;
  background: rgba(0,0,0,.55);
  color: #fff;
  padding: 2px 7px;
  font-size: 14px;
  cursor: pointer;
}
.actions button:hover { background: rgba(255,255,255,.25); }

.err {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,.8);
  color: var(--warn);
  text-align: center;
  padding: 16px;
}
.screen.has-error .err { display: flex; }
.err a { color: var(--accent); }
.err button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 4px 12px;
  cursor: pointer;
}

/* ---------- Modo foco: una grande y el resto alrededor ----------
   La geometría (columnas, filas y área de cada pantalla) la calcula app.js. */
@media (min-width: 901px) {
  .wall.focus {
    grid-template-columns: var(--f-cols);
    grid-template-rows: var(--f-rows);
  }
  .wall.focus .screen { grid-area: var(--area); }
}

/* ---------- Panel lateral ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h1 { margin: 0; font-size: 18px; }
.panel h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel h2 small { font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.panel section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.list-head h2 { margin: 0; }
.list-head select, .list-filter {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.list-head select { padding: 6px 8px; cursor: pointer; }
.list-filter { width: 100%; margin-bottom: 8px; padding: 7px 10px; }
.list-filter[hidden], .list-info[hidden] { display: none; }
.list-info { margin: 0 0 8px; font-size: 12px; color: var(--muted); }

.icon-btn {
  flex: none;
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }

.toggle {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.toggle:hover { border-color: var(--accent); }
.toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 700;
}
.panel-foot .toggle { margin-top: 0; }

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 8px 0;
  font-size: 15px;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: rgba(255,255,255,.05); }
.seg button.on { background: var(--accent); color: #06121f; font-weight: 700; }

.vol { display: flex; align-items: center; gap: 8px; }
.vol input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.vol output {
  width: 2.2em;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.channels {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding-right: 8px;        /* la barra de desplazamiento no pisa los botones */
  scrollbar-gutter: stable;
}
.channels details { display: grid; gap: 6px; }
.channels summary {
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.channels .row { display: flex; gap: 6px; }
.channels .ch {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.channels .ch:hover:not(:disabled) { border-color: var(--accent); }
.channels .ch:disabled { opacity: .45; cursor: not-allowed; }
.channels .star {
  flex: none;
  width: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.channels .star:hover { border-color: var(--accent); color: #f2cc60; }
.channels .star[aria-pressed="true"] { color: #f2cc60; }
.channels .label { flex: 1; }
.channels .tag { font-size: 11px; color: var(--muted); }
.channels .badges { display: flex; gap: 3px; }
.channels .badge {
  display: grid;
  place-items: center;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #06121f;
  font-size: 11px;
  font-weight: 700;
}

/* Pestaña para volver a mostrar el menú: a la misma altura que el botón de ocultarlo
   (16 px del borde superior, 32 px de alto) */
.menu-tab {
  position: fixed;
  right: 0;
  top: 16px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 22px;
  height: 32px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background: var(--panel);
  color: var(--text);
  opacity: .6;
  cursor: pointer;
  transition: opacity .15s;
}
.menu-tab[hidden] { display: none; }
.menu-tab:hover, .menu-tab:focus-visible { opacity: 1; }
/* Con el menú oculto se deja un hueco a la derecha para que la pestaña no tape los botones de las pantallas */
.app.menu-hidden .wall { padding-right: 28px; }
/* Pantalla completa de toda la app (rejilla + menú + pestaña + información) */
.app:fullscreen { background: var(--bg); }

/* Información */
dialog {
  width: min(520px, 92vw);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-body { padding: 20px 22px; }
.dlg-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.dlg-head .logo { flex: none; border-radius: 12px; }
.dlg-body h2 { margin: 0; font-size: 18px; }
.dlg-head .tagline { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.dlg-body ul { margin: 0; padding-left: 18px; }
.dlg-body li { margin: 7px 0; font-size: 13.5px; }
.dlg-body .keys { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.dlg-body .close { margin-top: 16px; }

/* ---------- Móvil / pantallas estrechas ---------- */
@media (max-width: 900px) {
  .app, .app.menu-hidden { grid-template-columns: 1fr; height: auto; }
  .wall {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: auto;
  }
  .wall.single { grid-template-columns: minmax(0, 1fr); }
  .screen { aspect-ratio: 16 / 9; }
  /* Modo foco en móvil: la grande arriba a todo el ancho y el resto debajo, de dos en dos */
  .wall.focus .screen { order: var(--ord); }
  .wall.focus .screen.is-big { grid-column: 1 / -1; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .channels { max-height: 60vh; }
  .bar { opacity: 1; }
}
.dlg-body a { color: var(--accent); }
.dlg-body code { padding: 0 4px; border-radius: 4px; background: var(--bg); font-size: 12.5px; }
