:root {
  --fondo: #0b0b0d;
  --superficie: #1a1a1f;
  --superficie-2: #26262c;
  --texto: #f5f5f7;
  --suave: rgba(245, 245, 247, 0.62);
  --acento: #ffffff;
  --verde: #32d74b;
  --naranja: #ff9f0a;
  --rojo: #ff453a;
  --radio: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100dvh;
}
h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 17px; font-weight: 700; margin: 22px 0 10px; }
.suave { color: var(--suave); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- Pantallas de entrar y vincular --- */
.pantalla { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.centrada { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 28px; padding-bottom: 16px; }
.marca { text-align: center; display: grid; justify-items: center; gap: 8px; }
.marca p { max-width: 340px; margin: 0; }
.icono-tv {
  width: 64px; height: 44px; border-radius: 10px; border: 4px solid var(--texto); position: relative; margin-bottom: 8px;
}
.icono-tv::after { content: ""; position: absolute; left: 50%; bottom: -12px; width: 24px; height: 4px; margin-left: -12px; border-radius: 2px; background: var(--texto); }
.tarjeta-form { display: grid; gap: 10px; width: 100%; max-width: 360px; margin: 0 auto; }
.tarjeta-form.ancho { max-width: none; }
input {
  font: inherit; color: var(--texto); background: var(--superficie); border: 1px solid transparent;
  border-radius: 12px; padding: 14px 16px; width: 100%; outline: none;
}
input:focus { border-color: rgba(255, 255, 255, 0.35); }
#codigo { text-align: center; font-size: 26px; letter-spacing: 0.3em; font-weight: 700; }
.error { color: var(--rojo); margin: 0; text-align: center; }

.boton {
  border: 0; border-radius: 12px; padding: 13px 18px; background: var(--superficie-2); font-weight: 600;
}
.boton.primario { background: var(--acento); color: #111; }
.boton.grande { width: 100%; padding: 16px; font-size: 17px; margin-top: 14px; }
.boton:active { transform: scale(0.98); }
.fila-botones { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

/* --- Cabecera y estado --- */
.cabecera { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 12px; }
.cabecera h1 { margin-bottom: 4px; }
.pildora-estado { font-size: 13px; font-weight: 600; color: var(--suave); }
.pildora-estado::before { content: "●"; margin-right: 6px; }
.pildora-estado.conectada { color: var(--verde); }
.pildora-estado.desconectada { color: var(--naranja); }
.boton-icono { background: var(--superficie); border: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 20px; }

.ahora { display: flex; gap: 12px; align-items: center; background: var(--superficie); border-radius: var(--radio); padding: 10px; margin-bottom: 14px; }
.ahora-imagen { width: 96px; aspect-ratio: 16/9; border-radius: 9px; background: var(--superficie-2) center/cover; flex: none; }
.ahora-texto { display: grid; min-width: 0; }
.ahora-texto b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etiqueta { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rojo); }

/* --- Pestañas --- */
.pestanas {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--superficie); padding: 4px; border-radius: 999px;
  position: sticky; top: 8px; z-index: 5;
}
.pestanas button { border: 0; background: none; padding: 9px 4px; border-radius: 999px; font-weight: 600; color: var(--suave); }
.pestanas button.activa { background: var(--texto); color: #111; }
.campo { margin: 14px 0 4px; }

/* --- Filas y tarjetas --- */
.fila { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.fila::-webkit-scrollbar { display: none; }
.cuadricula { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 12px; margin-top: 14px; }
.tarjeta { flex: 0 0 62%; max-width: 260px; scroll-snap-align: start; border: 0; background: none; padding: 0; text-align: left; }
.cuadricula .tarjeta { max-width: none; }
.tarjeta-imagen {
  aspect-ratio: 16/9; border-radius: 12px; background: var(--superficie-2) center/cover; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.tarjeta-imagen img.logo { max-width: 72%; max-height: 58%; object-fit: contain; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.6)); }
.tarjeta-imagen .progreso { position: absolute; left: 8px; right: 8px; bottom: 7px; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); }
.tarjeta-imagen .progreso i { display: block; height: 100%; border-radius: 2px; background: #fff; }
.tarjeta b { display: block; margin-top: 7px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tarjeta span { display: block; font-size: 13px; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cuadricula-canales { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; margin-top: 14px; }
.canal { border: 0; background: var(--superficie); border-radius: 12px; padding: 12px 8px 10px; display: grid; gap: 8px; justify-items: center; }
.canal img { width: 72px; height: 44px; object-fit: contain; }
.canal .sin-logo { height: 44px; display: grid; place-items: center; font-weight: 800; }
.canal b { font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.25; }
.vivo { font-size: 9px; font-weight: 800; color: #fff; background: #e5262b; border-radius: 4px; padding: 1px 5px; letter-spacing: 0.05em; }

.lista { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--superficie); border-radius: 12px; padding: 10px 12px; border: 0; text-align: left; width: 100%; }
.item .miniatura { width: 92px; aspect-ratio: 16/9; border-radius: 8px; background: var(--superficie-2) center/cover; flex: none; }
.item .texto { flex: 1; min-width: 0; }
.item .texto b, .item .texto span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .texto span { font-size: 13px; color: var(--suave); }
.item .accion { background: var(--texto); color: #111; border: 0; border-radius: 999px; padding: 7px 13px; font-weight: 700; font-size: 13px; flex: none; }
.item .borrar { background: none; border: 0; color: var(--suave); font-size: 18px; padding: 4px 6px; }
.vacio { color: var(--suave); text-align: center; padding: 26px 0; }

/* --- Ficha (hoja que sube desde abajo) --- */
.velo { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 20; }
.ficha {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto; z-index: 21;
  background: #141418; border-radius: 20px 20px 0 0; max-width: 760px; margin: 0 auto;
  animation: subir 0.25s ease-out;
}
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
.ficha-imagen { aspect-ratio: 16/9; background: var(--superficie-2) center/cover; display: flex; align-items: center; justify-content: center; }
.ficha-imagen img { max-width: 70%; max-height: 50%; object-fit: contain; filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.7)); }
.ficha-cuerpo { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.ficha-cuerpo h2 { margin: 0 0 4px; font-size: 22px; }
.ficha-cuerpo p { margin: 0; }
.resumen { margin-top: 10px !important; color: rgba(245, 245, 247, 0.85); }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 18px 0 12px; scrollbar-width: none; }
.chips button { border: 0; background: var(--superficie-2); border-radius: 999px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.chips button.activa { background: var(--texto); color: #111; }

/* --- Control remoto --- */
.control {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-width: 760px; margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(20, 20, 24, 0.92); backdrop-filter: blur(16px); border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.control button { border: 0; background: var(--superficie-2); border-radius: 14px; height: 48px; font-size: 22px; }
.control button:active { background: var(--texto); color: #111; }

.aviso {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--texto); color: #111; font-weight: 600; padding: 11px 18px; border-radius: 999px; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.aviso.error-aviso { background: var(--rojo); color: #fff; }

/* --- Vincular con un toque --- */
.tv-esperando { display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--superficie); border-radius: 12px; padding: 16px; }
.punto-vivo { width: 10px; height: 10px; border-radius: 50%; background: var(--verde); box-shadow: 0 0 0 0 rgba(50, 215, 75, 0.6); animation: latir 1.6s infinite; }
@keyframes latir { 70% { box-shadow: 0 0 0 10px rgba(50, 215, 75, 0); } 100% { box-shadow: 0 0 0 0 rgba(50, 215, 75, 0); } }
.otra-forma { max-width: 360px; width: 100%; margin: 0 auto; text-align: center; }
.otra-forma summary { color: var(--suave); cursor: pointer; padding: 8px; }
.otra-forma p { margin: 4px 0 12px; }
