:root {
  --bg-space: #040711;
  --bg-panel: rgba(10, 17, 34, 0.88);
  --bg-card: rgba(14, 24, 46, 0.82);
  --bg-card-hover: rgba(20, 35, 66, 0.96);
  --border-hud: rgba(56, 189, 248, 0.24);
  --border-strong: rgba(56, 189, 248, 0.65);
  --cyan: #38bdf8;
  --cyan-glow: rgba(56, 189, 248, 0.28);
  --emerald: #10b981;
  --emerald-bright: #34d399;
  --emerald-glow: rgba(16, 185, 129, 0.28);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg-space);
  background-image:
    radial-gradient(circle at 18% 15%, rgba(16, 185, 129, 0.14), transparent 36%),
    radial-gradient(circle at 82% 20%, rgba(56, 189, 248, 0.16), transparent 40%),
    linear-gradient(rgba(56, 189, 248, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 48px 48px, 48px 48px;
  color: var(--text-main);
  font-family: 'Segoe UI', Roboto, Ubuntu, Cantarell, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.dp-nav {
  outline: none;
  touch-action: manipulation;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.dp-nav:hover,
.dp-nav.dp-focus,
.dp-nav:focus-visible {
  transform: translateY(-2px) scale(1.015);
  border-color: var(--emerald-bright) !important;
  box-shadow: 0 0 0 2px var(--emerald-bright), 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 22px var(--emerald-glow);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(8, 14, 28, 0.95), rgba(8, 14, 28, 0.72));
  border-bottom: 1px solid var(--border-hud);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.45);
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  color: var(--emerald-bright);
  text-transform: uppercase;
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--emerald-bright);
  box-shadow: 0 0 10px var(--emerald-bright);
}

.sync-dot.local {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.nav-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.nav-btn, .btn, .btn-secondary, .btn-fav {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  min-height: 40px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.nav-btn.active {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.28), rgba(56, 189, 248, 0.16));
  border-color: var(--emerald-bright);
  color: #ecfdf5;
  box-shadow: 0 0 16px var(--emerald-glow);
}

.btn {
  background: linear-gradient(135deg, #0284c7, #0d9488);
  border-color: rgba(56, 189, 248, 0.55);
  color: #ffffff;
}

.btn-secondary {
  background: rgba(15, 23, 42, 0.9);
  border-color: var(--border-hud);
  color: var(--text-main);
}

.btn-fav.active {
  border-color: #f43f5e;
  background: rgba(244, 63, 94, 0.18);
  color: #fda4af;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box input,
.modal-card input,
.modal-card select,
.settings-card input,
.settings-card select {
  background: rgba(5, 10, 22, 0.9);
  color: var(--text-main);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-height: 40px;
  font-size: 0.92rem;
}

.main-wrap {
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px 22px 78px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.page-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-shadow: 0 0 18px rgba(56, 189, 248, 0.22);
}

.space-home {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
  margin-bottom: 24px;
}

.space-home.hidden {
  display: none;
}

.hub-tile {
  position: relative;
  min-height: 150px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(13, 24, 48, 0.92), rgba(7, 13, 28, 0.95));
  border: 1px solid var(--border-hud);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  overflow: hidden;
}

.hub-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.14), transparent 65%);
  pointer-events: none;
}

.hub-tile.hero-live {
  grid-row: span 2;
  min-height: 316px;
  background: linear-gradient(155deg, rgba(16, 185, 129, 0.26), rgba(6, 78, 59, 0.22) 55%, rgba(8, 15, 30, 0.96));
  border-color: rgba(52, 211, 153, 0.55);
}

.hub-tile-tag {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cyan);
  font-weight: 700;
}

.hub-tile.hero-live .hub-tile-tag {
  color: var(--emerald-bright);
}

.hub-tile-title {
  font-size: 1.45rem;
  font-weight: 800;
  margin-top: 6px;
}

.hub-tile.hero-live .hub-tile-title {
  font-size: 2rem;
}

.hub-tile-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

.vod-explorer {
  display: none;
  grid-template-columns: 270px 1fr;
  gap: 18px;
  min-height: 560px;
  margin-bottom: 20px;
}

.vod-explorer.active {
  display: grid;
}

.vod-sidebar {
  background: var(--bg-panel);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  padding: 12px;
  max-height: 74vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vod-side-btn {
  width: 100%;
  padding: 11px 14px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  background: rgba(12, 22, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.22);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.vod-side-btn.selected {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.34), rgba(6, 95, 70, 0.28));
  border-color: var(--emerald-bright);
  color: #ecfdf5;
}

.vod-divider {
  height: 1px;
  background: var(--border-hud);
  margin: 4px 0;
}

.vod-content-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.vod-category-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-left: 3px solid var(--emerald-bright);
  padding: 6px 4px 6px 12px;
}

.vod-category-heading {
  font-size: 1.25rem;
  font-weight: 800;
  color: #f8fafc;
}

.vod-poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px;
}

.poster-card {
  background: var(--bg-card);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.poster-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: #070d1c;
}

.poster-card-title {
  padding: 9px 10px;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-explorer {
  display: none;
  grid-template-columns: 280px 1fr 290px;
  gap: 16px;
  min-height: 540px;
  margin-bottom: 20px;
}

.live-explorer.active {
  display: grid;
}

.live-col {
  background: var(--bg-panel);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.live-col-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cyan);
  font-weight: 800;
  padding: 4px 6px 8px;
  border-bottom: 1px solid var(--border-hud);
}

.cat-pill {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 12px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-hud);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.cat-pill.selected {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.28), rgba(56, 189, 248, 0.16));
  border-color: var(--emerald-bright);
  color: #ecfdf5;
}

.channel-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  min-height: 56px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-hud);
  cursor: pointer;
}

.channel-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.channel-row-logo {
  width: 48px;
  height: 36px;
  object-fit: contain;
  background: rgba(5, 10, 22, 0.85);
  border-radius: 6px;
  padding: 3px;
  flex-shrink: 0;
}

.channel-row-title {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.epg-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
}

.epg-now {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.45);
}

.epg-slot {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(10, 18, 36, 0.8);
  border: 1px solid var(--border-hud);
  font-size: 0.85rem;
}

.cw-section {
  display: none;
  margin-bottom: 24px;
}

.cw-section.visible {
  display: block;
}

.section-heading {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--cyan);
}

.cw-carousel {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.cw-card {
  flex: 0 0 240px;
  background: var(--bg-card);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
}

.cw-thumb-wrap {
  position: relative;
  width: 100%;
  height: 132px;
  background: #060b16;
}

.cw-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(148, 163, 184, 0.25);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald-bright), var(--cyan));
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 16px;
}

.grid.channels {
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

.poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: #070d1c;
}

.channel-logo {
  width: 100%;
  height: 120px;
  object-fit: contain;
  padding: 12px;
  background: rgba(5, 10, 22, 0.85);
}

.card-body {
  padding: 12px;
}

.card-title {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.3;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-foot {
  padding: 0 12px 12px;
  display: flex;
  justify-content: flex-end;
}

.pager-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 22px;
}

.pager-bar.visible {
  display: flex;
}

.settings-wrap {
  display: none;
}

.settings-wrap.visible {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.settings-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-hud);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overlay-screen,
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.88);
  backdrop-filter: blur(8px);
  z-index: 60;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay-screen.open,
.overlay-screen.active,
.modal-backdrop.open,
.modal-backdrop.active {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 540px;
  background: linear-gradient(160deg, rgba(13, 23, 45, 0.98), rgba(6, 11, 23, 0.98));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75), 0 0 32px var(--cyan-glow);
}

.login-error {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fecaca;
  font-size: 0.88rem;
}

.login-error.show {
  display: block;
}

.player-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #02040a;
  z-index: 90;
  flex-direction: column;
}

.player-overlay.open,
.player-overlay.active {
  display: flex;
}

.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(7, 13, 28, 0.96), rgba(7, 13, 28, 0.72));
  border-bottom: 1px solid var(--border-hud);
  z-index: 2;
}

.player-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.player-stage {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(14, 26, 52, 0.45), #02040a 75%);
  overflow: hidden;
}

#videoEl {
  width: 100%;
  height: 100%;
  max-height: 100%;
  background: #000000;
  object-fit: contain;
}

.player-error-box {
  display: none;
  position: absolute;
  max-width: 460px;
  width: calc(100% - 32px);
  padding: 22px;
  border-radius: var(--radius-lg);
  background: rgba(11, 18, 35, 0.96);
  border: 1px solid rgba(239, 68, 68, 0.65);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  text-align: center;
  z-index: 5;
}

.player-error-box.show {
  display: block;
}

.tv-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 22px;
  background: rgba(5, 9, 20, 0.94);
  border-top: 1px solid var(--border-hud);
  font-size: 0.8rem;
  color: var(--text-muted);
  z-index: 25;
}

.tv-footer strong {
  color: var(--cyan);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 48px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: rgba(10, 20, 42, 0.96);
  border: 1px solid var(--emerald-bright);
  color: #ecfdf5;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 120;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1050px) {
  .vod-explorer.active,
  .live-explorer.active {
    grid-template-columns: 1fr;
    max-height: none;
  }
  .vod-sidebar,
  .live-col {
    max-height: 300px;
  }
}

@media (max-width: 900px) {
  .space-home {
    grid-template-columns: 1fr;
  }
  .hub-tile.hero-live {
    grid-row: auto;
    min-height: 190px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 14px;
    gap: 10px;
  }
  .main-wrap {
    padding: 14px 14px 86px;
  }
  .search-box {
    width: 100%;
  }
  .search-box input {
    flex: 1;
    min-width: 0;
  }
  .vod-poster-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 12px;
  }
  .tv-footer {
    font-size: 0.72rem;
    padding: 8px 14px;
  }
}