/* ============================================
   Bongo TV — Netflix-Style Design System
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- CSS Variables --- */
:root {
  --bg-primary: #141414;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #222;
  --bg-elevated: #2a2a2a;
  --surface: rgba(30, 30, 30, 0.9);
  --surface-hover: rgba(50, 50, 50, 0.9);
  --accent: #e50914;
  --accent-hover: #f40612;
  --accent-dark: #b20710;
  --white: #ffffff;
  --text-primary: #e5e5e5;
  --text-secondary: #999;
  --text-muted: #666;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(255, 255, 255, 0.5);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.6);
  --shadow-card-hover: 0 8px 40px rgba(0, 0, 0, 0.8);
  --shadow-glow: 0 0 20px rgba(229, 9, 20, 0.3);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 68px;
  --category-bar-height: 50px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.4;
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 0px;
  height: 0px;
}

/* ============================================
   HEADER — Netflix-style gradient header
   ============================================ */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.6) 60%, transparent 100%);
  display: flex;
  align-items: center;
  padding: 0 4%;
  z-index: 100;
  transition: background var(--transition-normal);
  gap: 20px;
}

.header.scrolled {
  background: rgba(20, 20, 20, 0.98);
}

.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-banner-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
  transition: all var(--transition-fast);
}

.header-banner-logo:hover {
  filter: drop-shadow(0 2px 6px rgba(229, 9, 20, 0.3)) brightness(1.05);
}

/* Search */
.search-container {
  margin-left: auto;
  position: relative;
  width: 0;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-container.expanded {
  width: 260px;
}

.search-input {
  width: 100%;
  padding: 8px 14px 8px 38px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  color: var(--white);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition-normal);
  opacity: 0;
}

.search-container.expanded .search-input {
  opacity: 1;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--white);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--white);
  width: 18px;
  height: 18px;
  cursor: pointer;
  z-index: 2;
}

.search-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--white);
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
}

.search-toggle-btn svg {
  width: 22px;
  height: 22px;
}

/* ============================================
   CATEGORY BAR — Netflix row selector
   ============================================ */
.category-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: var(--category-bar-height);
  background: linear-gradient(to bottom, rgba(20, 20, 20, 0.95) 0%, rgba(20, 20, 20, 0.8) 80%, transparent 100%);
  display: flex;
  align-items: center;
  padding: 0 4%;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  z-index: 99;
  scrollbar-width: none;
}

.category-bar::-webkit-scrollbar {
  display: none;
}

.category-pill {
  padding: 6px 16px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 100px;
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-normal);
  user-select: none;
  flex-shrink: 0;
  outline: none;
  letter-spacing: 0.3px;
}

.category-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.4);
  color: var(--white);
}

.category-pill.active {
  background: var(--white);
  color: #000;
  border-color: var(--white);
  font-weight: 600;
}

.category-pill:focus-visible,
.category-pill.tv-focus {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

/* ============================================
   CHANNEL GRID — Netflix card layout
   ============================================ */
.main-content {
  padding-top: calc(var(--header-height) + var(--category-bar-height) + 12px);
  padding-bottom: 60px;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  padding: 0 4%;
  max-width: 1920px;
  margin: 0 auto;
}

.channel-card {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  transition: all var(--transition-normal), transform 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  border: none;
  transform-origin: center;
}

.channel-card:hover {
  transform: scale(1.15);
  z-index: 10;
  box-shadow: var(--shadow-card-hover);
  border-radius: var(--radius-md);
}

/* Subtle white border on hover */
.channel-card:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  pointer-events: none;
  z-index: 3;
}

/* TV Focus state */
.channel-card:focus-visible,
.channel-card.tv-focus {
  outline: none;
  transform: scale(1.18);
  z-index: 10;
  box-shadow: 0 0 0 3px var(--white), var(--shadow-card-hover);
  border-radius: var(--radius-md);
}

.channel-logo {
  width: 55%;
  height: 55%;
  object-fit: contain;
  position: relative;
  z-index: 1;
  filter: brightness(0.95);
  transition: all var(--transition-normal);
}

.channel-card:hover .channel-logo,
.channel-card.tv-focus .channel-logo {
  filter: brightness(1.1);
  transform: scale(1.05);
}

/* Fallback — styled letter */
.channel-logo-fallback {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #333 0%, #555 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--white);
  position: relative;
  z-index: 1;
  letter-spacing: -1px;
}

/* Empty state */
.grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 100px 20px;
  color: var(--text-muted);
}

.grid-empty svg {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.grid-empty p {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Skeleton loading */
.channel-skeleton {
  aspect-ratio: 16 / 9;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.channel-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,0.02) 50%, transparent 75%);
  animation: shimmer 1.8s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ============================================
   VIDEO PLAYER OVERLAY — Cinematic
   ============================================ */
.player-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: none;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.player-overlay.active {
  display: flex;
  opacity: 1;
}

.player-video-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

.player-video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* Player Info — top gradient */
.player-info {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 20px 4%;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 14px;
  opacity: 0;
  transform: translateY(-8px);
  transition: all var(--transition-slow);
  z-index: 5;
}

.player-overlay.show-controls .player-info {
  opacity: 1;
  transform: translateY(0);
}

.player-info-text h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 1px;
}

.player-info-text span {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 400;
}

.player-back-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  outline: none;
}

.player-back-btn:hover,
.player-back-btn:focus-visible {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.1);
}

/* Player Controls — bottom */
.player-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 4%;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: all var(--transition-slow);
  z-index: 5;
}

.player-overlay.show-controls .player-controls {
  opacity: 1;
  transform: translateY(0);
}

.ctrl-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  flex-shrink: 0;
}

.ctrl-btn:hover,
.ctrl-btn:focus-visible {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.15);
}

.ctrl-btn svg {
  width: 22px;
  height: 22px;
}

.ctrl-spacer {
  flex: 1;
}

/* Volume */
.volume-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 70px;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  opacity: 0;
  width: 0;
  transition: all 0.3s ease;
}

.volume-group:hover .volume-slider {
  opacity: 1;
  width: 70px;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

/* Channel switch toast */
.channel-switch-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 28px 48px;
  text-align: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.channel-switch-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.channel-switch-toast h3 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--white);
  margin-bottom: 4px;
}

.channel-switch-toast p {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 400;
}

/* Loading spinner */
.player-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
}

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

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

/* ============================================
   PWA INSTALL POPUP — Netflix-style bottom bar
   ============================================ */
.install-popup {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.85) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 16px 4%;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 500;
  transform: translateY(100%);
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.install-popup.visible {
  transform: translateY(0);
  opacity: 1;
}

.install-popup-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.install-popup-content {
  flex: 1;
  min-width: 0;
}

.install-popup-content h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 1px;
}

.install-popup-content p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.install-popup-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  padding: 8px 20px;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.install-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.dismiss-btn {
  padding: 8px 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.dismiss-btn:hover {
  color: var(--white);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ============================================
   LOADING SCREEN
   ============================================ */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  animation: loading-pulse 1.4s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.6; }
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ============================================
   ERROR SCREEN
   ============================================ */
.error-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  min-height: 300px;
}

.error-screen.active {
  display: flex;
}

.error-screen svg {
  width: 48px;
  height: 48px;
  color: var(--accent);
  margin-bottom: 16px;
  opacity: 0.6;
}

.error-screen h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.error-screen p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.retry-btn {
  padding: 10px 32px;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.retry-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Large TV */
@media (min-width: 1800px) {
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
  }

  .channel-card.tv-focus {
    transform: scale(1.2);
  }
}

/* Desktop */
@media (min-width: 1200px) and (max-width: 1799px) {
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
  }
}

/* Tablet */
@media (max-width: 768px) {
  .header {
    padding: 0 3%;
    height: 56px;
  }

  .header-banner-logo {
    height: 30px;
  }

  .category-bar {
    top: 56px;
    padding: 0 3%;
    height: 44px;
  }

  .main-content {
    padding-top: calc(56px + 44px + 8px);
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 4px;
    padding: 0 3%;
  }

  .channel-card:hover {
    transform: scale(1.05);
  }

  .player-info {
    padding: 16px 3%;
  }

  .player-controls {
    padding: 14px 3%;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .header {
    padding: 0 12px;
    height: 50px;
    gap: 8px;
  }

  .header-banner-logo {
    height: 26px;
  }

  .search-container.expanded {
    width: 180px;
  }

  .category-bar {
    top: 50px;
    padding: 0 12px;
    height: 40px;
    gap: 5px;
  }

  .category-pill {
    padding: 5px 12px;
    font-size: 0.72rem;
  }

  .main-content {
    padding-top: calc(50px + 40px + 6px);
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 3px;
    padding: 0 8px;
  }

  .channel-card:hover {
    transform: scale(1.03);
  }

  .channel-logo-fallback {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .player-info-text h2 {
    font-size: 0.95rem;
  }

  .install-popup {
    padding: 14px 12px;
    gap: 10px;
  }

  .install-popup-icon {
    width: 36px;
    height: 36px;
  }
}

/* Focus for mouse users — hide ring */
.channel-card:focus:not(:focus-visible):not(.tv-focus) {
  outline: none;
  box-shadow: none;
  transform: none;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.channel-card {
  animation: fadeIn 0.35s ease forwards;
  opacity: 0;
}

.channel-card:nth-child(1) { animation-delay: 0.02s; }
.channel-card:nth-child(2) { animation-delay: 0.04s; }
.channel-card:nth-child(3) { animation-delay: 0.06s; }
.channel-card:nth-child(4) { animation-delay: 0.08s; }
.channel-card:nth-child(5) { animation-delay: 0.10s; }
.channel-card:nth-child(6) { animation-delay: 0.12s; }
.channel-card:nth-child(7) { animation-delay: 0.14s; }
.channel-card:nth-child(8) { animation-delay: 0.16s; }
.channel-card:nth-child(9) { animation-delay: 0.18s; }
.channel-card:nth-child(10) { animation-delay: 0.20s; }
.channel-card:nth-child(n+11) { animation-delay: 0.22s; }

/* Hide server status element */
.server-status {
  display: none !important;
}
