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

@supports (padding-top: env(safe-area-inset-top)) {
  .header {
    padding-top: env(safe-area-inset-top);
  }
}

:root {
  --bg:          #0a0a0f;
  --bg2:         #111118;
  --bg3:         #1a1a26;
  --bg4:         #22222e;
  --border:      rgba(255,255,255,0.07);
  --border2:     rgba(255,255,255,0.12);
  --text:        #e8e8f0;
  --text2:       #9090a8;
  --text3:       #5a5a72;
  --accent:      #a78bfa;
  --accent2:     #f472b6;
  --accent3:     #fb923c;
  --grad:        linear-gradient(135deg, #a78bfa, #f472b6);
  --grad2:       linear-gradient(135deg, #f472b6, #fb923c);
  --shadow:      0 8px 32px rgba(0,0,0,0.5);
  --shadow2:     0 2px 12px rgba(0,0,0,0.4);
  --radius:      14px;
  --radius-sm:   8px;
  --sidebar-w:   290px;
  --header-h:    62px;
  --transition:  0.22s cubic-bezier(.4,0,.2,1);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Header ───────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 100%;
  padding: 0 20px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.logo-text {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}
.logo-accent {
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Search */
.header-center { flex: 1; max-width: 520px; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0 16px;
  height: 40px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.15);
}
.search-icon { color: var(--text3); flex-shrink: 0; }
#searchInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}
#searchInput::placeholder { color: var(--text3); }
.search-clear {
  background: none; 
  border: none;
  color: var(--text3); 
  cursor: pointer;
  font-size: 0.75rem; 
  padding: 2px 4px;
  border-radius: 4px;
  display: none;
  transition: color var(--transition);
}
.search-clear:hover { color: var(--text); }
.search-clear.visible { display: block; }

/* Header right */
.header-right {
  display: flex; align-items: center; gap: 14px;
  flex-shrink: 0; margin-left: auto;
}
.live-badge {
  display: flex; align-items: center; gap: 6px;
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 50px;
}
.live-dot {
  width: 7px; height: 7px;
  background: #ef4444;
  border-radius: 50%;
  animation: pulse-red 1.4s infinite;
  flex-shrink: 0;
}
.live-dot.small { width: 6px; height: 6px; }
@keyframes pulse-red {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}
.channel-count {
  font-size: 0.8rem;
  color: var(--text2);
  font-weight: 500;
}

.download-button {
  display: none;
}

.download-button a {
  color: var(--text);
  text-decoration: none;
  font-size: .8rem;
  background: var(--grad);
  padding: 6px 12px;
  border-radius: 50px;
}

/* ── Layout ───────────────────────────────────── */
.app-layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  height: 100%;
  overflow: hidden;
  transition: transform var(--transition);
}

.sidebar-inner {
  height: 100%;
  overflow: hidden;
  padding: 16px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 0 4px;
  margin-bottom: 10px;
}

/* Category pills */
.category-pills {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cat-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  transition: background var(--transition), color var(--transition);
  width: 100%;
}
.cat-pill:hover { background: var(--bg3); color: var(--text); }
.cat-pill.active {
  background: rgba(167,139,250,0.12);
  color: var(--accent);
  font-weight: 600;
}
.cat-pill-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.cat-pill-count {
  margin-left: auto;
  font-size: 0.72rem;
  background: var(--bg4);
  color: var(--text3);
  padding: 2px 7px;
  border-radius: 50px;
}
.cat-pill.active .cat-pill-count {
  background: rgba(167,139,250,0.2);
  color: var(--accent);
}

/* Channel list */
.channel-list-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.channels-title { display: flex; align-items: center; gap: 8px; }
.count-badge {
  background: var(--bg4);
  color: var(--text3);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 50px;
  letter-spacing: 0;
  text-transform: none;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 4px;
}
.channel-list::-webkit-scrollbar {
  width: 6px;
}
.channel-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 99px;
}
.channel-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}
.channel-list::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
.ch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition);
  width: 100%;
}
.ch-item:hover { background: var(--bg3); }
.ch-item.active {
  background: rgba(167,139,250,0.12);
  border: 1px solid rgba(167,139,250,0.2);
}
.ch-thumb {
  width: 38px; height: 28px;
  border-radius: 5px;
  object-fit: contain;
  background: var(--bg4);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.ch-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.ch-item.active .ch-name { color: var(--accent); }
.ch-play-icon {
  width: 18px; height: 18px;
  opacity: 0;
  color: var(--accent);
  flex-shrink: 0;
  transition: opacity var(--transition);
}
.ch-item:hover .ch-play-icon,
.ch-item.active .ch-play-icon { opacity: 1; }

.sidebar-search-section {
  display: none;
}

/* ── Main Content ─────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  height: 100%;
}

/* ── Player ───────────────────────────────────── */
.player-section {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}
.player-wrap {
  position: relative;
  width: 100%;
  max-width: min(960px, calc((100vh - var(--header-h) - 80px) * 16 / 9));
  aspect-ratio: 16/9;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* Placeholder */
.player-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 50%, rgba(167,139,250,0.05) 0%, transparent 70%);
}
.placeholder-inner { text-align: center; }
.placeholder-icon { margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.placeholder-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.placeholder-subtitle { font-size: 0.875rem; color: var(--text3); }

/* Video */
#videoPlayer {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}

/* Overlay (channel name on screen) */
.player-overlay {
  position: absolute;
  top: 14px; left: 14px;
  pointer-events: none;
  animation: fadeSlide .35s ease;
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.channel-on-screen {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 8px 14px 8px 10px;
  border-radius: 10px;
}
#overlayLogo { width: 36px; height: 28px; object-fit: contain; border-radius: 4px; background: rgba(255,255,255,0.05); }
.overlay-name { font-size: 0.85rem; font-weight: 700; color: #fff; }
.overlay-group { font-size: 0.72rem; color: rgba(255,255,255,0.55); margin-top: 2px; }

/* Loading ring */
.loading-ring {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.ring {
  width: 52px; height: 52px;
  border: 3px solid rgba(167,139,250,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error overlay */
.error-overlay {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
}
.error-inner { text-align: center; }
.error-icon { font-size: 2.5rem; margin-bottom: 10px; }
.error-title { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.error-subtitle { font-size: 0.82rem; color: var(--text2); margin-bottom: 18px; max-width: 280px; }
.retry-btn {
  background: var(--grad);
  border: none;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 24px;
  border-radius: 50px;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.retry-btn:hover { opacity: 0.9; transform: scale(1.03); }

.now-playing-bar {
  display: none !important;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.npb-left { display: flex; align-items: center; gap: 12px; }
.npb-logo {
  width: 44px; height: 32px;
  object-fit: contain;
  background: var(--bg4);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.npb-name { font-size: 0.9rem; font-weight: 700; color: #fff; white-space: nowrap; }
.npb-group {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}
.npb-live {
  display: flex; align-items: center; gap: 6px;
  background: rgba(239,68,68,0.18);
  border: 1px solid rgba(239,68,68,0.35);
  color: #f87171;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 50px;
  flex-shrink: 0;
}

/* ── Sidebar Empty State ──────────────────────── */
.sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  text-align: center;
  color: var(--text3);
  gap: 8px;
  flex: 1;
}
.sidebar-empty-icon { font-size: 2rem; opacity: 0.5; }
.sidebar-empty p { font-size: 0.82rem; font-weight: 600; color: var(--text2); }
.sidebar-empty span { font-size: 0.75rem; }

/* ── Mobile sidebar toggle ───────────────────── */
.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 200;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--grad);
  border: none;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(167,139,250,0.4);
  align-items: center; justify-content: center;
  transition: transform var(--transition);
}
.mobile-sidebar-toggle:hover { transform: scale(1.08); }

@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }
  .live-badge {
    display: none;
  }
  .channel-count { 
    display: none; 
  }

  /* Download Button */
  .download-button {
    display: block;
  }

  /* Hide header search bar and use sidebar search on mobile */
  .header-center {
    display: none;
  }

  body {
    height: auto;
    overflow-y: auto;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* Fixed video player at the top of the mobile screen */
  .main-content {
    order: -1;
    position: sticky;
    top: var(--header-h);
    z-index: 100;
    background: var(--bg);
    width: 100%;
    padding: 0;
    overflow: visible;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  }

  .player-section {
    width: 100%;
    flex: none;
  }

  .player-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  /* Inline sidebar beneath player */
  .sidebar {
    position: static;
    transform: none;
    width: 100%;
    height: auto;
    background: transparent;
    border: none;
    display: block;
  }

  .sidebar-inner {
    height: auto;
    overflow: visible;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* Sidebar Search (Visible on Mobile) */
  .sidebar-search-section {
    display: block;
    width: 100%;
  }
  .sidebar-search-section .search-bar {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    height: 44px;
  }
  
  .sidebar-search-section input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    width: 100%;
  }

  /* Horizontal Scrolling Category Pills */
  .category-pills {
    flex-direction: row;
    overflow-x: auto;
    white-space: nowrap;
    padding: 4px 0;
    gap: 8px;
    scrollbar-width: none;
  }
  .category-pills::-webkit-scrollbar {
    display: none;
  }
  .cat-pill {
    width: auto;
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 50px;
    background: var(--bg3);
  }

  /* Grid of Channel Cards */
  .channel-list-section {
    flex: none;
    height: auto;
    overflow: visible;
  }

  .channel-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    padding: 8px 0;
    height: auto;
    overflow: visible;
  }

  .ch-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    padding: 16px 8px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    aspect-ratio: 1 / 1;
    position: relative;
    width: 100%;
    box-sizing: border-box;
  }

  .ch-item:hover {
    background: var(--bg3);
    border-color: var(--accent);
  }

  .ch-item.active {
    background: rgba(167,139,250,0.12);
    border-color: var(--accent);
  }

  .ch-thumb {
    width: 46px;
    height: 34px;
    object-fit: contain;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
  }

  .ch-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ch-fav-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 1;
    margin: 0;
    padding: 2px;
  }

  .ch-play-icon {
    display: none;
  }

  .mobile-sidebar-toggle {
    display: none !important;
  }
}

@media (max-width: 560px) {
  .header-inner { gap: 10px; padding: 0 14px; }
  .logo-text { font-size: 1rem; }
  .logo-icon { width: 30px; height: 30px; }
  .player-wrap { border-radius: var(--radius-sm); }
}



/* ── Category color dots ──────────────────────── */
.cat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

/* ── Load Error ──────────────────────── */
.load-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  color: var(--text3);
  gap: 6px;
}
.load-error p {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  margin: 0;
}
.load-error span {
  font-size: 0.82rem;
}

/* ── Favorites Styling ────────────────── */
.ch-fav-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  opacity: 0.25;
  transition: opacity var(--transition), color var(--transition), transform var(--transition);
  flex-shrink: 0;
  margin-left: 6px;
}
.ch-item:hover .ch-fav-btn,
.ch-fav-btn.active {
  opacity: 1;
}
.ch-fav-btn:hover {
  color: #fbbf24;
  transform: scale(1.15);
}
.ch-fav-btn.active {
  color: #fbbf24;
}
.ch-fav-btn .star-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.copyright {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text);
  font-size: .9rem;
  border: solid 1px var(--accent);   
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg3);
  box-shadow: 0 0 5px var(--accent);  
  z-index: 100;
}

