/* Define la interfaz visual ligera y navegable con control remoto. */
:root {
  color-scheme: dark;
  --bg: #09080f;
  --surface: #17151f;
  --surface-strong: #211e2d;
  --text: #f8f7fb;
  --muted: #aaa6b5;
  --primary: #7657ff;
  --primary-strong: #987fff;
  --focus: #ffffff;
  --danger: #ff647c;
  --radius: 18px;
  --page-x: clamp(24px, 4vw, 72px);
  /* Reserva espacio para la barra superpuesta de los navegadores Smart TV. */
  --tv-browser-top-inset: clamp(48px, 6vh, 72px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  min-width: 320px;
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button { color: inherit; }

.hidden { display: none !important; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(280px, 640px) auto;
  align-items: center;
  gap: clamp(18px, 3vw, 48px);
  min-height: calc(88px + var(--tv-browser-top-inset));
  padding: calc(16px + var(--tv-browser-top-inset)) var(--page-x) 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 8, 15, 0.95);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
  border: 0;
  background: transparent;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.brand-mark {
  position: relative;
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #a489ff, #4f36df);
  transform: rotate(45deg);
  box-shadow: 0 10px 28px rgba(87, 59, 224, 0.42);
}

.brand-mark span {
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 14px solid white;
  transform: rotate(-45deg) translate(1px, -1px);
}

.search {
  display: grid;
  grid-template-columns: 1fr 58px;
  min-height: 54px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 18px;
  background: #25232c;
}

.search:focus-within { border-color: var(--primary-strong); }

.search input {
  min-width: 0;
  padding: 0 20px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 18px;
}

.search input::placeholder { color: #918d9c; }

.search-button {
  border: 0;
  background: transparent;
  font-size: 32px;
  cursor: pointer;
}

.nav { display: flex; gap: 8px; }

.nav-button, .filter-button {
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.nav-button.active, .filter-button.active {
  color: white;
  background: rgba(118, 87, 255, 0.22);
}

.main {
  min-height: calc(100vh - 88px);
  padding: 34px var(--page-x) 72px;
  outline: 0;
}

.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(34px, 4vw, 58px); }
h2 { margin-bottom: 0; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.media-section { margin-bottom: 48px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-heading h2 { font-size: clamp(24px, 2vw, 34px); }

.media-row {
  display: grid;
  grid-auto-columns: clamp(150px, 12vw, 220px);
  grid-auto-flow: column;
  gap: 18px;
  padding: 5px 5px 18px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #4c465a transparent;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 28px 20px;
}

.media-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  padding: 0;
  border: 3px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transform: translateZ(0);
  transition: transform 130ms ease, border-color 130ms ease;
}

.media-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: linear-gradient(135deg, #292533, #15131c);
}

.media-card::after {
  content: "";
  position: absolute;
  inset: 42% 0 0;
  background: linear-gradient(transparent, rgba(5, 4, 9, 0.94));
  pointer-events: none;
}

.card-copy {
  position: absolute;
  z-index: 1;
  right: 12px;
  bottom: 13px;
  left: 12px;
  text-align: left;
}

.card-title {
  display: block;
  overflow: hidden;
  color: white;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  display: block;
  margin-top: 5px;
  color: #c5c1cc;
  font-size: 12px;
}

.episode-badge {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(9, 8, 15, 0.88);
  font-size: 12px;
  font-weight: 800;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.filter-group { display: flex; gap: 10px; }

.secondary-button, .primary-button, .server-button {
  min-height: 48px;
  padding: 0 20px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: var(--surface-strong);
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  border-color: transparent;
  background: var(--primary);
}

.status-view {
  display: grid;
  min-height: 45vh;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: var(--muted);
}

.loader {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--primary-strong);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.details-layer, .player-layer {
  position: fixed;
  z-index: 50;
  inset: 0;
  overflow: auto;
  background: var(--bg);
}

.details-backdrop {
  position: fixed;
  inset: 0;
  background-position: center top;
  background-size: cover;
  opacity: 0.42;
}

.details-shade {
  position: fixed;
  inset: 0;
  background: linear-gradient(90deg, #09080f 14%, rgba(9, 8, 15, 0.78) 58%, rgba(9, 8, 15, 0.48)),
    linear-gradient(0deg, #09080f 4%, transparent 72%);
}

.details-content {
  position: relative;
  z-index: 1;
  min-height: 100%;
  padding: 30px var(--page-x) 64px;
}

.round-button {
  display: grid;
  width: 50px;
  height: 50px;
  padding: 0;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(20, 18, 27, 0.9);
  font-size: 26px;
  cursor: pointer;
}

.details-layout {
  display: grid;
  grid-template-columns: minmax(190px, 280px) minmax(0, 780px);
  gap: clamp(32px, 5vw, 80px);
  align-items: start;
  margin-top: clamp(32px, 7vh, 88px);
}

.details-poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.details-copy h1 { max-width: 850px; }

.details-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  color: #d8d4df;
}

.meta-pill {
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
}

.details-description {
  max-width: 760px;
  color: #d2cfda;
  font-size: clamp(16px, 1.35vw, 21px);
  line-height: 1.55;
}

.details-actions { display: flex; gap: 14px; margin: 26px 0; }

.episode-picker, .server-list {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.picker-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.picker-row label { color: var(--muted); font-weight: 700; }

.select {
  min-height: 46px;
  padding: 0 14px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  color: white;
  background: var(--surface-strong);
}

.episode-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: 270px;
  padding: 4px;
  overflow-y: auto;
}

.episode-button {
  min-height: 58px;
  padding: 9px 12px;
  border: 2px solid transparent;
  border-radius: 11px;
  background: var(--surface);
  color: #dedbe5;
  text-align: left;
  cursor: pointer;
}

.episode-button.active { border-color: var(--primary); color: white; }

.server-list h3 { margin: 0 0 14px; }

.server-buttons { display: flex; flex-wrap: wrap; gap: 12px; }
.server-button { min-width: 170px; text-align: left; }
.server-button small { display: block; margin-top: 3px; color: var(--muted); }

.player-layer { z-index: 80; overflow: hidden; }

.player-header {
  position: absolute;
  z-index: 3;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 36px);
  padding: 10px 18px 10px 10px;
  border-radius: 17px;
  background: rgba(9, 8, 15, 0.9);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.player-header .eyebrow { margin-bottom: 3px; font-size: 10px; }
.player-header h2 { overflow: hidden; max-width: 68vw; font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }

#playerFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: black;
}

.player-loading {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: black;
  color: var(--muted);
}

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  max-width: min(460px, calc(100vw - 48px));
  padding: 16px 20px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: #292531;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.48);
}

.focusable:focus, [data-focusable]:focus {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.media-card:focus { border-color: white; transform: scale(1.055); }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: auto 1fr; }
  .nav { grid-column: 1 / -1; justify-content: center; }
}

@media (max-width: 720px) {
  :root { --tv-browser-top-inset: 0px; }
  .topbar { position: static; grid-template-columns: 1fr; min-height: 0; }
  .brand { justify-content: center; }
  .nav { grid-column: auto; overflow-x: auto; justify-content: flex-start; }
  .main { padding-top: 24px; }
  .media-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
  .media-row { grid-auto-columns: 31vw; gap: 12px; }
  .card-title { font-size: 13px; }
  .details-layout { grid-template-columns: 1fr; margin-top: 24px; }
  .details-poster { width: min(42vw, 220px); }
  .details-shade { background: rgba(9, 8, 15, 0.82); }
  .view-heading { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
