:root {
  --bg-dark: #060a12;
  --bg-card: rgba(14, 20, 36, 0.72);
  --border-color: rgba(255, 255, 255, 0.07);
  --accent: #ff3d5a;
  --accent-glow: rgba(255, 61, 90, 0.35);
  --accent-2: #00d4aa;
  --accent-2-glow: rgba(0, 212, 170, 0.3);
  --text-white: #f0f4ff;
  --text-gray: #8b95a8;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-white);
  font-family: 'Outfit', sans-serif;
  overflow-x: hidden;
  min-height: 100vh;
}

.background-effects {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(ellipse at 20% 0%, rgba(255, 61, 90, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 100%, rgba(0, 212, 170, 0.06) 0%, transparent 50%);
}

.circle {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  animation: float 12s ease-in-out infinite;
}

.c1 {
  width: 420px;
  height: 420px;
  background: rgba(255, 61, 90, 0.12);
  top: -120px;
  right: -80px;
}

.c2 {
  width: 500px;
  height: 500px;
  background: rgba(0, 212, 170, 0.08);
  bottom: -180px;
  left: -120px;
  animation-delay: -4s;
}

.c3 {
  width: 300px;
  height: 300px;
  background: rgba(100, 120, 255, 0.06);
  top: 40%;
  left: 50%;
  animation-delay: -8s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(20px, -15px); }
}

header {
  background: rgba(6, 10, 18, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.logo {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 3px;
  background: linear-gradient(135deg, #fff 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-2);
  background: rgba(0, 212, 170, 0.1);
  border: 1px solid rgba(0, 212, 170, 0.25);
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 7px;
  height: 7px;
  background: var(--accent-2);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-2-glow); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px transparent; }
}

.search-box {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 40px;
  padding: 0 18px;
  flex: 1;
  max-width: 480px;
  transition: all 0.25s ease;
}

.search-box:focus-within {
  border-color: rgba(255, 61, 90, 0.5);
  box-shadow: 0 0 20px var(--accent-glow);
  background: rgba(255, 255, 255, 0.06);
}

.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-gray);
  flex-shrink: 0;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-white);
  padding: 12px 12px;
  width: 100%;
  font-size: 0.95rem;
  font-family: inherit;
}

.admin-link {
  color: var(--text-gray);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  transition: all 0.25s;
  flex-shrink: 0;
}

.admin-link:hover {
  color: var(--text-white);
  border-color: rgba(255, 61, 90, 0.4);
  background: rgba(255, 61, 90, 0.08);
}

.container {
  max-width: 1400px;
  margin: 24px auto 60px;
  padding: 0 24px;
}

.main-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Sections rail ── */
.categories-section {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  backdrop-filter: none;
}

.categories-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.sections-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-gray);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.remote-hint {
  font-size: 0.68rem;
  color: var(--text-gray);
  opacity: 0.75;
  white-space: nowrap;
  display: none;
}

body.tv-mode .remote-hint,
body.mobile-mode .remote-hint {
  display: inline;
}

.categories-rail-wrap {
  position: relative;
  min-height: 0;
}

.categories-rail-wrap::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 8px;
  width: 48px;
  background: linear-gradient(90deg, transparent, var(--bg-dark));
  pointer-events: none;
}

.categories-rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  padding: 4px 4px 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
  touch-action: pan-x pan-y;
}

.categories-rail::-webkit-scrollbar { height: 4px; }
.categories-rail::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* PC + menu lateral con scroll vertical */
@media (min-width: 900px) {
  .main-layout {
    display: grid;
    grid-template-columns: minmax(220px, 280px) 1fr;
    gap: 24px;
    align-items: start;
  }

  .categories-section {
    position: sticky;
    top: 88px;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 14px;
    backdrop-filter: blur(12px);
    overflow: hidden;
  }

  .categories-top {
    flex-shrink: 0;
  }

  .categories-rail-wrap {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) rgba(255, 255, 255, 0.05);
    outline: none;
    direction: rtl; /* scrollbar a la izquierda del panel */
  }

  .categories-rail-wrap .categories-rail,
  .categories-rail-wrap .category-item {
    direction: ltr;
  }

  .categories-rail-wrap::-webkit-scrollbar { width: 10px; }
  .categories-rail-wrap::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 5px;
  }
  .categories-rail-wrap::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
  }

  .categories-rail-wrap::after {
    display: none;
  }

  .categories-rail {
    display: flex;
    flex-direction: column;
    overflow: visible;
    height: auto;
    max-height: none;
    flex: none;
    min-height: 0;
    gap: 6px;
    padding: 2px 4px 8px 2px;
    scroll-snap-type: none;
    touch-action: auto;
  }

  .category-item {
    min-width: 0;
    max-width: none;
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    flex-shrink: 0;
  }

  .category-item::after {
    left: 0;
    top: 10px;
    bottom: 10px;
    right: auto;
    width: 3px;
    height: auto;
    border-radius: 0 3px 3px 0;
  }

  .remote-hint {
    display: inline;
    font-size: 0.62rem;
  }
}

.category-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  min-width: 148px;
  max-width: 220px;
  padding: 14px 20px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.category-item::after {
  content: '';
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}

.category-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.category-item:focus {
  outline: none;
}

.category-item:focus-visible {
  border-color: rgba(255, 61, 90, 0.45);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.category-item.active {
  background: rgba(255, 61, 90, 0.1);
  border-color: rgba(255, 61, 90, 0.4);
}

.category-item.active::after {
  opacity: 1;
}

.category-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
}

.category-item.active .category-name {
  color: var(--text-white);
}

.category-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-gray);
  opacity: 0.85;
}

.category-item.active .category-count {
  color: var(--accent);
}

.channels-section {
  min-width: 0;
}

.channels-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  gap: 16px;
}

.channels-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
}

.channels-subtitle {
  font-size: 0.85rem;
  color: var(--text-gray);
  margin-top: 4px;
}

.channel-count-badge {
  color: var(--text-gray);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 8px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,61,90,0.04), transparent);
  opacity: 0;
  transition: opacity 0.25s;
}

.card:hover::before, .card:focus::before {
  opacity: 1;
}

.card:hover, .card:focus {
  transform: translateY(-3px);
  border-color: rgba(255, 61, 90, 0.4);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), 0 0 20px var(--accent-glow);
  outline: none;
}

.card-logo-wrap {
  position: relative;
  flex-shrink: 0;
}

.card-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 5px;
  display: block;
}

.card-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex-grow: 1;
}

.card-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.card-group {
  font-size: 0.72rem;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

.loading-grid {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 0;
  color: var(--text-gray);
}

.loader {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.no-results, .error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-gray);
  padding: 40px;
}

/* Modal — compacto, botones siempre visibles */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-content {
  background: rgba(14, 20, 36, 0.98);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.close-modal {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-gray);
  transition: color 0.2s;
  line-height: 1;
  z-index: 2;
}

.close-modal:hover, .close-modal:focus {
  color: var(--accent);
  outline: none;
}

#modal-channel-name {
  font-size: 1.05rem;
  font-weight: 700;
  padding-right: 36px;
  margin: 0;
  flex-shrink: 0;
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(42vh, 380px);
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

#video-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding-top: 4px;
}

.zapping-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-zapping {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 10px 18px;
  border-radius: 30px;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.close-modal:hover, .close-modal:focus {
  color: var(--accent);
  outline: none;
}

.btn-zapping:hover, .btn-zapping:focus {
  background: rgba(255, 61, 90, 0.15);
  border-color: rgba(255, 61, 90, 0.4);
  outline: none;
}

.audio-select-container {
  display: none;
  align-items: center;
  gap: 8px;
}

.audio-select-label {
  font-size: 0.85rem;
  color: var(--text-gray);
}

.audio-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 8px 14px;
  border-radius: 20px;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.error-overlay {
  position: absolute;
  inset: 0;
  background: url('no_signal.jpg') no-repeat center center / cover;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  padding: 20px;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}

.error-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 18, 0.45);
  backdrop-filter: blur(1px);
  z-index: 1;
}

.error-overlay-message {
  position: relative;
  z-index: 2;
  color: #ff4d4d;
  font-size: 1.15rem;
  font-weight: 600;
  text-shadow: 0 0 12px rgba(255, 77, 77, 0.5), 0 2px 4px rgba(0, 0, 0, 0.8);
  max-width: 85%;
  line-height: 1.5;
  background: rgba(10, 14, 23, 0.88);
  padding: 16px 28px;
  border-radius: 35px;
  border: 1px solid rgba(255, 77, 77, 0.35);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

button:focus, select:focus, input:focus {
  outline: none;
}

/* ── Android TV / TV Box ── */
body.tv-mode header {
  padding: 20px 0;
}

body.tv-mode .logo {
  font-size: 2rem;
}

body.tv-mode .search-box input {
  padding: 14px 12px;
  font-size: 1rem;
}

body.tv-mode .category-item {
  min-height: 50px;
  min-width: 0;
  max-width: none;
  width: 100%;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: 10px;
}

body.tv-mode .category-item::after {
  left: 0;
  top: 8px;
  bottom: 8px;
  right: auto;
  width: 4px;
  height: auto;
  border-radius: 0 4px 4px 0;
}

body.tv-mode .category-item.active::after {
  opacity: 1;
}

body.tv-mode .category-item:focus-visible,
body.tv-mode .card:focus-visible,
body.tv-mode .btn-zapping:focus-visible,
body.tv-mode .close-modal:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  box-shadow: 0 0 0 8px var(--accent-glow), 0 10px 28px rgba(0, 0, 0, 0.45);
  transform: scale(1.03);
  z-index: 2;
}

body.tv-mode .card {
  min-height: 76px;
  padding: 16px 18px;
}

body.tv-mode .card-logo {
  width: 58px;
  height: 58px;
}

body.tv-mode .card-name {
  font-size: 1.05rem;
}

body.tv-mode .btn-zapping {
  padding: 14px 28px;
  font-size: 1rem;
  min-height: 48px;
}

body.tv-mode .modal-content {
  max-width: 96vw;
}

@media (min-width: 900px) {
  body.tv-mode .main-layout {
    display: grid;
    grid-template-columns: minmax(240px, 300px) 1fr;
    gap: 28px;
    align-items: start;
  }

  body.tv-mode .categories-section {
    position: sticky;
    top: 92px;
    height: calc(100vh - 110px);
    max-height: calc(100vh - 110px);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    backdrop-filter: blur(12px);
    overflow: hidden;
  }

  body.tv-mode .categories-rail-wrap::after {
    display: none;
  }

  body.tv-mode .categories-rail-wrap {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    direction: rtl;
  }

  body.tv-mode .categories-rail-wrap .categories-rail,
  body.tv-mode .categories-rail-wrap .category-item {
    direction: ltr;
  }

  body.tv-mode .categories-rail {
    flex-direction: column;
    overflow: visible;
    height: auto;
    max-height: none;
    flex: none;
    gap: 6px;
    padding: 2px 4px 8px 2px;
  }

  body.tv-mode .grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
  }
}

/* ── Mobile / touch ── */
body.mobile-mode .header-container {
  flex-wrap: wrap;
  gap: 12px;
}

body.mobile-mode .search-box {
  order: 3;
  max-width: 100%;
  flex: 1 1 100%;
}

body.mobile-mode .search-box input {
  padding: 14px 12px;
  font-size: 16px;
}

body.mobile-mode .live-badge {
  display: none;
}

body.mobile-mode .categories-rail {
  gap: 8px;
  padding-bottom: 10px;
}

body.mobile-mode .category-item {
  min-width: 130px;
  padding: 16px 18px;
  min-height: 56px;
}

body.mobile-mode .category-name {
  font-size: 0.82rem;
}

body.mobile-mode .grid {
  grid-template-columns: 1fr;
  gap: 12px;
}

body.mobile-mode .card {
  min-height: 72px;
  padding: 16px;
}

body.mobile-mode .card-logo {
  width: 56px;
  height: 56px;
}

body.mobile-mode .card-name {
  font-size: 1rem;
}

body.mobile-mode .channels-header {
  flex-direction: column;
  align-items: flex-start;
}

body.tv-mode .modal-content {
  max-width: 720px;
}

body.mobile-mode .modal {
  padding: 10px;
  align-items: center;
}

body.mobile-mode .modal-content {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 16px;
  padding: 16px;
  min-height: unset;
}

body.mobile-mode .video-container {
  max-height: min(38vh, 320px);
}

body.mobile-mode .btn-zapping {
  padding: 12px 16px;
  font-size: 0.85rem;
  min-height: 44px;
}

body.mobile-mode .player-controls {
  flex-direction: column;
  align-items: stretch;
}

body.mobile-mode .zapping-buttons {
  justify-content: center;
  width: 100%;
}

body.mobile-mode .zapping-buttons .btn-zapping {
  flex: 1;
  text-align: center;
}

@media (hover: none) {
  .category-item:active,
  .card:active,
  .btn-zapping:active {
    transform: scale(0.97);
    opacity: 0.92;
  }
}

@media (max-width: 768px) {
  .header-container {
    flex-wrap: wrap;
  }
  .search-box {
    order: 3;
    max-width: 100%;
    flex: 1 1 100%;
  }
  .categories-rail {
    gap: 8px;
  }
  .category-item {
    min-width: 120px;
    padding: 14px 16px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .channels-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .live-badge {
    display: none;
  }
  .container {
    padding: 0 16px;
    margin-top: 16px;
  }
}
