:root {
  --void: #060914;
  --space: #080d1c;
  --orbit: #0d1325;
  --raised: #11182b;
  --signal: #8b3dff;
  --bright: #a55cff;
  --moon: #f5f4fa;
  --text: #c6cad8;
  --muted: #8991a7;
  --line: rgba(166, 177, 214, 0.14);
  --soft: rgba(166, 177, 214, 0.08);
  --online: #67d643;
  --warn: #ff9f2f;
  --sidebar: 260px;
  --player-h: clamp(180px, 28dvh, 240px);
  --nav-h: 64px;
  --top-h: 72px;
}
*, ::before, ::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; color-scheme: dark; }
body {
  min-height: 100dvh; overflow: hidden;
  background: var(--space); color: var(--moon);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #343b52; border-radius: 9px; }

/* === MOBILE FIRST (default) === */
.app-shell { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px; flex: none; position: relative; z-index: 40;
  min-height: var(--top-h); padding: 10px 14px; border-bottom: 1px solid var(--soft);
  background: var(--space);
}
.brand {
  display: flex; align-items: center; gap: 8px; flex: none; color: var(--moon); text-decoration: none;
}
.brand-mark { position: relative; width: 22px; height: 28px; flex: none; }
.brand-mark i { position: absolute; left: 3px; width: 8px; height: 24px; border-radius: 3px 7px 7px 3px; }
.brand-mark i:nth-child(1) { background: #7047ff; transform: skewY(-30deg); }
.brand-mark i:nth-child(2) { background: #a340ed; transform: translateX(6px) skewY(30deg); }
.brand-mark i:nth-child(3) { top: 9px; height: 14px; background: #e13bc8; transform: translateX(11px) skewY(-30deg); }
.brand strong { font-size: 15px; letter-spacing: -0.5px; display: none; }
.search-box {
  display: flex; align-items: center; gap: 8px; flex: 1; max-width: 420px; height: 38px;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 20px; background: #070b17;
}
.search-box:focus-within { border-color: var(--bright); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: white; font-size: 13px; }
.search-box input::placeholder { color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.top-actions button { display: flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text); font-size: 12px; position: relative; padding: 6px; }
.fav-count {
  position: absolute; top: -2px; right: -2px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--signal); color: white; font-size: 9px; font-weight: 700; line-height: 17px; text-align: center;
}
.profile { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--signal); font-weight: 700; font-size: 13px; flex: none; }

.main { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* Content */
.content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; padding: 0 14px 24px; }

/* Hero */
.hero {
  max-width: 1000px; margin: 0 auto 20px; position: relative; min-height: 280px; overflow: hidden;
  border: 1px solid var(--soft); border-radius: 0 0 16px 16px; isolation: isolate;
}
.hero.hidden { display: none; }
.night-sky {
  position: absolute; inset: 0; z-index: -2;
  background-color: #061126;
  background-image: radial-gradient(circle at 71% 32%, #fff 0 1px, transparent 2px), radial-gradient(circle at 58% 22%, #fff 0 1px, transparent 1.5px), radial-gradient(circle at 88% 14%, #70c5ff 0 1px, transparent 2px), radial-gradient(circle at 76% 48%, #bd87ff 0 1px, transparent 2px), radial-gradient(ellipse at 78% 45%, #815bbc55, transparent 28%), linear-gradient(180deg, #071126, #0a1834 55%, #2f2447 78%, #08101f);
  background-size: 84px 91px, 121px 113px, 157px 149px, 211px 193px, 100% 100%, 100% 100%;
}
.hero::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, #040812f5, #040812c7 28%, #04081220 65%); }
.hero-copy { padding: 32px 28px 50px; }
.hero .eyebrow { margin-bottom: 6px; color: var(--bright); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; }
.hero h1 { font-size: clamp(36px, 6vw, 60px); line-height: 1.02; letter-spacing: -2px; }
.hero h1 span { color: #e5e1ff; }
.hero-description { margin-top: 14px; color: var(--text); font-size: 14px; line-height: 1.5; }
.hero-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border-radius: 8px; font-size: 13px; padding: 0 18px; }
.primary-button { border: 1px solid #a35cff; background: var(--signal); font-weight: 650; }
.secondary-button { border: 1px solid var(--line); background: #090e1dd9; }
.signal-card { display: none; }

/* Catalogue */
.catalogue { max-width: 1200px; margin: 0 auto; padding: 20px 0; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.section-heading p { color: var(--bright); font-size: 9px; font-weight: 700; letter-spacing: 0.1em; }
.section-heading h2 { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.section-heading h2 svg { color: var(--bright); }
.channel-count { color: var(--muted); font-size: 11px; white-space: nowrap; }
.filter-row {
  display: flex; align-items: center; gap: 8px; margin-top: 14px;
  overflow-x: auto; flex-wrap: nowrap; -ms-overflow-style: none; scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #090e1d; color: var(--text); font-size: 11px;
}
.filter-chip svg { width: 16px; }
.welcome-note {
  display: flex; align-items: center; gap: 16px; min-height: 100px; margin-top: 14px;
  padding: 18px 22px; border: 1px solid var(--soft); border-radius: 12px; background: var(--orbit);
}
.welcome-note > div { display: grid; place-items: center; flex: 0 0 46px; height: 46px; border: 1px solid #a55cff59; border-radius: 50%; color: var(--bright); background: #8b3dff14; }
.welcome-note strong { font-size: 14px; }
.welcome-note p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }

/* Channel grid */
.channels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 14px; }
.channel-card {
  position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: 10px; background: var(--orbit); transition: 0.18s;
}
.channel-card:hover { border-color: #a55cff80; background: var(--raised); }
.card-visual {
  position: relative; display: grid; place-items: center; min-height: 100px; padding: 16px;
  background: radial-gradient(circle at 70% 20%, #8b3dff38, transparent 42%), linear-gradient(135deg, #121432, #07172a);
}
.card-visual::after { content: ""; position: absolute; inset: 0; opacity: 0.14; background-image: radial-gradient(circle, #fff 0 1px, transparent 1px); background-size: 24px 24px; }
.card-logo { z-index: 1; display: grid; place-items: center; width: 64px; height: 48px; }
.card-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card-placeholder { display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid #ffffffcc; border-radius: 50%; font-size: 18px; font-weight: 800; }
.card-placeholder.s { width: 28px; height: 28px; font-size: 11px; }
.live-badge { position: absolute; top: 8px; left: 8px; z-index: 2; padding: 3px 7px; border-radius: 4px; background: var(--signal); font-size: 8px; font-weight: 800; }
.fav-star {
  position: absolute; top: 8px; right: 8px; z-index: 2; display: grid; place-items: center;
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 50%; background: rgba(0, 0, 0, 0.5); color: var(--muted);
}
.fav-star.on { color: #ff4d6d; border-color: #ff4d6d66; }
.fav-star.on svg { fill: #ff4d6d; stroke: #ff4d6d; }
.card-body { display: grid; gap: 6px; padding: 10px 12px; }
.card-name { overflow: hidden; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 10px; }
.card-meta svg { width: 12px; color: #74b7ff; }
/* Categories */
.categories-view { margin-top: 14px; }
.category-section { margin-bottom: 24px; }
.category-header { display: flex; justify-content: space-between; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--soft); }
.category-name { font-size: 14px; font-weight: 600; }
.category-count { color: var(--muted); font-size: 10px; }
.category-channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.cat-channel {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 10px;
  border: 1px solid var(--soft); border-radius: 8px; background: var(--orbit); transition: 0.18s;
}
.cat-channel:hover { border-color: #a55cff66; background: var(--raised); }
.cat-logo { display: grid; place-items: center; flex: 0 0 32px; height: 32px; }
.cat-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cat-name { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.show-more, .empty, .loading-cat { grid-column: 1/-1; padding: 24px; color: var(--muted); text-align: center; font-size: 11px; }
.show-more { color: var(--bright); }

/* Player */
.player-panel {
  flex: none; display: flex; flex-direction: column; overflow: hidden;
  background: #03050b; border-top: 1px solid #a55cff66;
  transition: height 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.player-panel.hidden { display: none; }
.player-bar {
  display: flex; align-items: center; justify-content: space-between; flex: none;
  min-height: 40px; padding: 4px 12px; background: var(--orbit); gap: 8px;
}
.player-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); box-shadow: 0 0 5px var(--online); flex: none; }
.player-info small { color: var(--bright); font-size: 8px; flex: none; display: none; }
.player-info strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-nav { display: flex; align-items: center; gap: 4px; flex: none; }
.p-nav {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 1px solid var(--line); border-radius: 5px; background: transparent; color: var(--text);
}
.p-nav:hover { color: white; border-color: var(--bright); background: var(--raised); }
.p-nav svg { width: 16px; height: 16px; }
.p-counter { color: var(--muted); font-size: 10px; min-width: 30px; text-align: center; }
.player-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.p-btn {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted);
}
.p-btn:hover { color: white; border-color: var(--line); }
.p-btn svg { width: 16px; height: 16px; }
.player-wrap {
  position: relative; display: grid; place-items: center; flex: 1; min-height: 0;
  background: #000; overflow: hidden;
}
#videoPlayer { display: block; width: 100%; height: 100%; object-fit: contain; }
.player-overlay { position: absolute; inset: 0; display: grid; place-content: center; place-items: center; gap: 10px; background: #010308c7; z-index: 5; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--bright); border-radius: 50%; animation: spin 0.8s linear infinite; }
#overlayText { color: var(--muted); font-size: 11px; }

/* Bottom nav (mobile) */
.bottom-nav {
  display: flex; align-items: center; justify-content: space-around; flex: none; position: relative; z-index: 60;
  height: var(--nav-h); padding: 0 4px env(safe-area-inset-bottom);
  border-top: 1px solid var(--line); background: #0a0f1ff0; backdrop-filter: blur(16px);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  flex: 1; height: 100%; border: 0; background: transparent; color: var(--muted); font-size: 9px; padding: 2px;
  position: relative;
}
.nav-btn svg { width: 18px; height: 18px; }
.nav-btn.active { color: var(--bright); }
.nav-btn.active::before { content: ""; position: absolute; top: 0; left: 50%; width: 20px; height: 2px; background: var(--bright); border-radius: 0 0 2px 2px; transform: translateX(-50%); }

/* Modal (mobile country picker) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  background: #080d1cf5; backdrop-filter: blur(14px);
}
.modal-overlay.hidden { display: none; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; flex: none;
  padding: 16px 18px; border-bottom: 1px solid var(--soft);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--text);
}
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 18px; }
.country-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 14px;
  border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text); font-size: 14px; margin-bottom: 4px;
}
.country-btn:hover, .country-btn.active { color: white; background: var(--raised); border-color: var(--soft); }
.country-btn .flag { font-size: 20px; }

/* Desktop sidebar */
.sidebar {
  display: none; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--soft); background: var(--space);
}
.sidebar .brand { padding: 20px 20px 0; }
.sidebar .brand strong { display: block; font-size: 19px; }
.sidebar .brand small { margin-top: 5px; color: var(--text); font-size: 9px; letter-spacing: 3px; }
.sidebar .primary-nav { display: grid; gap: 4px; padding: 28px 12px 0; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text); font-size: 13px;
}
.sidebar .nav-item:hover { color: white; background: #ffffff09; }
.sidebar .nav-item.active { color: white; border-color: #a55cff38; background: #8b3dff29; }
.sidebar .nav-item.active::before { content: ""; position: absolute; left: -1px; width: 2px; height: 24px; background: var(--bright); }
.sidebar .country-panel { display: flex; flex: 1; min-height: 0; flex-direction: column; padding: 16px 12px 20px; }
.sidebar .side-heading { display: flex; align-items: center; gap: 10px; padding: 8px 16px 6px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar .countries { overflow-y: auto; flex: 1; min-height: 0; }
.sidebar .country-btn { min-height: 36px; font-size: 12px; padding: 5px 14px; margin-bottom: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; z-index: 200;
  padding: 10px 20px; border-radius: 8px; background: var(--raised);
  border: 1px solid var(--line); color: var(--moon); font-size: 12px;
  transform: translateX(-50%); transition: opacity 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.hidden { opacity: 0; }

/* === TABLET / DESKTOP === */
@media (min-width: 800px) {
  .bottom-nav { display: none; }
  .sidebar { display: flex; }
  .app-shell { flex-direction: row; }
  .topbar { min-height: 80px; padding: 12px 28px 12px 36px; }
  .content { padding: 0 28px 32px 36px; }
  .hero { min-height: 340px; }
  .hero-copy { padding: 44px 40px 60px; }
  .hero h1 { font-size: clamp(42px, 4.5vw, 64px); }
  .hero-description { font-size: 15px; }
  .signal-card {
    display: grid; position: absolute; right: 5%; bottom: 32px; gap: 6px;
    min-width: 220px; padding: 16px 18px; border: 1px solid #a55cff88; border-radius: 10px;
    background: #060811dc; backdrop-filter: blur(12px);
  }
  .signal-card span { display: flex; align-items: center; gap: 6px; color: var(--bright); font-size: 9px; }
  .signal-card strong { font-size: 15px; }
  .signal-card small { color: var(--muted); font-size: 11px; }
  .channels-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
  .category-channels { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
  .player-panel { height: var(--player-h); }
  .toast { bottom: 24px; }
}

@media (min-width: 1200px) {
  .channels-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .category-channels { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* === SMALL MOBILE === */
@media (max-width: 430px) {
  .channels-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .category-channels { grid-template-columns: 1fr; }
  .card-visual { min-height: 86px; }
}

@keyframes spin { to { transform: rotate(360deg); } }
:focus-visible { outline: 3px solid var(--bright); outline-offset: 3px; }

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