/* ============================================
   Cinema Premium — webOS TV app
   Target: 1920x1080 — auto-scale al viewport real via #tv-root
   Compatible Chromium 38+ (webOS 3.0+):
     - SIN inset (usar top/right/bottom/left)
     - SIN gap en flexbox (usar margin entre hijos)
     - SIN aspect-ratio (usar width/height explícitos)
     - SIN :focus-visible (usar :focus normal)
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #0a0a0f;
  color: #fff;
  font-family: 'LG Smart UI', 'Segoe UI', 'Helvetica', sans-serif;
  font-size: 18px;
}

/* Contenedor que siempre mide 1920x1080. JS lo escala con transform:scale()
   para que entre en el viewport real de la TV (cualquier resolución). */
#tv-root {
  position: absolute;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: top left;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ============================================
   Screens
   ============================================ */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 1920px;
  height: 1080px;
  display: none;
  overflow: hidden;
}
.screen.active { display: block; }

/* ============================================
   Splash
   ============================================ */
#splash {
  background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a0f 100%);
}
.splash-content {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.logo, .brand {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 8px;
  color: #fff;
}
.logo span, .brand span {
  color: #e50914;
}
.loader {
  width: 60px; height: 60px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: #e50914;
  border-radius: 50%;
  margin: 40px auto 20px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#splash-status {
  color: #999;
  font-size: 20px;
}

/* ============================================
   Top bar
   ============================================ */
.top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 40px 80px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  pointer-events: none;
}
.top-bar .brand {
  font-size: 32px;
  letter-spacing: 4px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}
.top-actions {
  display: flex;
  align-items: center;
  pointer-events: auto;
}
/* Reemplazo de "gap: 20px" — flexbox gap NO existe en Chromium 53/68 */
.top-actions > * + * { margin-left: 20px; }

.top-btn {
  padding: 10px 20px;
  font-size: 18px;
  color: #fff;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  transition: background 0.2s, transform 0.2s;
}
.top-btn.focused {
  background: #e50914;
  transform: scale(1.08);
}
.updated {
  color: #888;
  font-size: 14px;
}

/* ============================================
   Hero
   ============================================ */
.hero {
  position: relative;
  width: 100%;
  height: 720px;
  overflow: hidden;
}
.hero-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-size: cover;
  background-position: center;
  transition: background-image 0.5s;
}
.hero-gradient {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    linear-gradient(to right, rgba(10,10,15,0.95) 0%, rgba(10,10,15,0.4) 50%, transparent 100%),
    linear-gradient(to top, #0a0a0f 0%, transparent 40%);
}
.hero-content {
  position: absolute;
  bottom: 80px;
  left: 80px;
  max-width: 900px;
  z-index: 10;
}

/* Cuando el foco baja a las filas de categorías, ocultamos el hero
   para que no quede detrás de los títulos de fila ("Familia", "Acción"). */
.hero.hero-hidden {
  visibility: hidden;
  pointer-events: none;
}
.hero-tagline {
  color: #e50914;
  font-weight: 700;
  letter-spacing: 3px;
  margin-bottom: 10px;
  font-size: 20px;
  text-transform: uppercase;
}
.hero-title {
  font-size: 72px;
  font-weight: 900;
  margin-bottom: 15px;
  line-height: 1.1;
  text-shadow: 0 2px 20px rgba(0,0,0,0.8);
}
.hero-meta {
  display: flex;
  margin-bottom: 20px;
  color: #ccc;
  font-size: 20px;
}
.hero-meta > * + * { margin-left: 20px; }
.hero-meta .badge {
  padding: 2px 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  font-size: 16px;
}
.hero-synopsis {
  font-size: 22px;
  line-height: 1.5;
  color: #eee;
  margin-bottom: 30px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 5px rgba(0,0,0,0.8);
}
.hero-actions {
  display: flex;
}
.hero-actions > * + * { margin-left: 15px; }

.btn-primary, .btn-secondary {
  padding: 14px 32px;
  font-size: 20px;
  font-weight: 700;
  border-radius: 4px;
  /* sin transition: en TVs Chromium 53/68 las animaciones encadenadas laguean */
}
.btn-primary {
  background: #fff;
  color: #000;
}
.btn-primary.focused {
  background: #e50914;
  color: #fff;
  transform: scale(1.08);
}
.btn-secondary {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.btn-secondary.focused {
  background: rgba(255,255,255,0.4);
  transform: scale(1.08);
}

/* ============================================
   Categorías / Grilla
   ============================================ */
.categories {
  position: relative;
  margin-top: 0;
  padding: 20px 0 60px;
  z-index: 1;
  /* sin transition: el scroll vertical es instantáneo (mucho más fluido en TV) */
  will-change: transform;
}
.row {
  margin-bottom: 40px;
  padding: 0 80px;
}
.row-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 15px;
  color: #fff;
}
.row-items {
  display: flex;
  /* sin transition: scroll horizontal instantáneo */
  will-change: transform;
}
.row-items > * + * { margin-left: 15px; }

.card {
  flex: 0 0 260px;
  width: 260px;
  height: 380px;
  border-radius: 6px;
  background: #1a1a2e;
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  /* sin transitions: feedback inmediato al cambiar foco */
  border: 4px solid transparent;
  box-sizing: border-box;
}
.card.focused {
  /* Sin scale (era expensive). Borde sólido del mismo tamaño que el placeholder. */
  border-color: #e50914;
  z-index: 10;
}
.card-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 15px;
  background: linear-gradient(to top, rgba(0,0,0,0.95), transparent);
  opacity: 0;
}
.card.focused .card-overlay { opacity: 1; }
.card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.card-info {
  font-size: 14px;
  color: #bbb;
}
.card-placeholder {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
  color: rgba(255,255,255,0.1);
}

/* ============================================
   Detalle
   ============================================ */
.detail-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-size: cover;
  background-position: center;
  filter: blur(2px);
  opacity: 0.5;
}
.detail-gradient {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    linear-gradient(to right, rgba(10,10,15,0.98) 0%, rgba(10,10,15,0.85) 100%);
}
.detail-content {
  position: absolute;
  top: 120px;
  left: 80px;
  max-width: 1100px;
  z-index: 2;
}
.back-btn {
  position: absolute;
  top: 40px; left: 80px;
  padding: 12px 24px;
  font-size: 20px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 4px;
  z-index: 100;
  transition: background 0.2s, transform 0.2s;
}
.back-btn.focused {
  background: #e50914;
  transform: scale(1.05);
}
.detail-title {
  font-size: 64px;
  font-weight: 900;
  margin-bottom: 15px;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  color: #ccc;
  margin-bottom: 25px;
  font-size: 18px;
}
.detail-meta > * { margin-right: 15px; margin-bottom: 5px; }
.detail-meta .badge {
  padding: 4px 12px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  font-size: 16px;
}
.detail-tagline {
  color: #e50914;
  font-style: italic;
  margin-bottom: 20px;
  font-size: 22px;
}
.detail-synopsis {
  font-size: 22px;
  line-height: 1.6;
  margin-bottom: 30px;
  color: #eee;
}
/* detail-info usa GRID — gap en grid SÍ funciona en Chromium 57+ */
.detail-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-row-gap: 12px;
  grid-column-gap: 40px;
  margin-bottom: 40px;
  font-size: 18px;
  color: #bbb;
  max-width: 800px;
}
.detail-info strong { color: #fff; margin-right: 8px; }
.detail-actions { display: flex; }
.detail-actions > * + * { margin-left: 15px; }

/* ============================================
   Player
   ============================================ */
#player { background: #000; }
#video, #video-iframe {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: 0;
  background: #000;
  display: block;
}
#video.hidden, #video-iframe.hidden { display: none; }
.player-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent 30%, transparent 70%, rgba(0,0,0,0.7));
  opacity: 0;
  pointer-events: none;
}
.player-overlay.visible { opacity: 1; }

/* Back button del player: SIEMPRE visible y clickeable, fuera del overlay
   que se auto-oculta. Z-index alto para estar sobre el iframe. */
.back-btn.player-back-fixed {
  position: absolute;
  top: 30px;
  left: 30px;
  z-index: 200;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 14px 28px;
  font-size: 22px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
}
.back-btn.player-back-fixed.focused,
.back-btn.player-back-fixed:hover {
  background: #e50914;
  border-color: #fff;
}
.back-btn.player-back-fixed.back-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.player-info {
  position: absolute;
  top: 40px; left: 50%;
  transform: translateX(-50%);
}
.player-info h3 {
  font-size: 28px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

/* ============================================
   Error toast
   ============================================ */
.toast {
  position: fixed;
  bottom: 40px; left: 50%;
  transform: translateX(-50%) translateY(150%);
  background: #e50914;
  color: #fff;
  padding: 20px 40px;
  border-radius: 8px;
  font-size: 20px;
  visibility: hidden;
  font-weight: 600;
  transition: transform 0.3s;
  z-index: 1000;
  max-width: 800px;
  text-align: center;
}
.toast.visible {
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
