/* ====== Design tokens ====== */
:root {
  --c-bg:        #0a0d18;
  --c-surface:   #131829;
  --c-surface-2: #1a2038;
  --c-border:    rgba(255,255,255,0.06);
  --c-border-strong: rgba(255,255,255,0.12);
  --c-text:      #e7eaf3;
  --c-text-dim:  #8a92b2;
  --c-accent:    #7c6cff;
  --c-accent-2:  #5ac8fa;
  --c-success:   #3ddc97;
  --c-warning:   #ffb547;
  --c-danger:    #ff5570;
  --c-grad:      linear-gradient(135deg, #7c6cff 0%, #5ac8fa 100%);
  --shadow-md:   0 8px 24px rgba(0,0,0,0.3);
  --shadow-lg:   0 20px 60px rgba(0,0,0,0.5);
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --topbar-h:    62px;
  --sidebar-w:   260px;
}

[data-theme="light"] {
  --c-bg: #f7f8fc;
  --c-surface: #ffffff;
  --c-surface-2: #f0f3fa;
  --c-border: rgba(0,0,0,0.06);
  --c-border-strong: rgba(0,0,0,0.12);
  --c-text: #14182a;
  --c-text-dim: #5a6080;
}

/* ====== Reset ====== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin:0; padding:0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
button { font-family: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--c-accent); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

/* ====== Loading skeleton ====== */
.loading-skeleton {
  background: linear-gradient(90deg, var(--c-surface) 0%, var(--c-surface-2) 50%, var(--c-surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* ====== Topbar ====== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: rgba(10,13,24,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
}
.topbar-left { display: flex; align-items: center; gap: 18px; }
.brand {
  font-size: 19px; font-weight: 800; letter-spacing: -0.02em;
  background: var(--c-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar-nav { display: flex; gap: 4px; }
.nav-tab {
  background: transparent; border: none; color: var(--c-text-dim);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all 0.15s;
}
.nav-tab:hover { color: var(--c-text); background: rgba(255,255,255,0.04); }
.nav-tab.active { color: var(--c-text); background: rgba(124,108,255,0.15); }
.nav-toggle { display: none; }
.icon-btn, .icon-btn-small {
  background: rgba(255,255,255,0.04); border: 1px solid var(--c-border);
  color: var(--c-text); width: 38px; height: 38px;
  border-radius: 10px; display: grid; place-items: center; cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--c-border-strong); }
.icon-btn-small { width: 28px; height: 28px; border-radius: 6px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.search-wrap {
  position: relative; width: 320px; max-width: 32vw;
}
.search-wrap input {
  width: 100%; background: rgba(255,255,255,0.04);
  border: 1px solid var(--c-border); color: var(--c-text);
  padding: 9px 14px 9px 36px; border-radius: 10px; font-size: 14px;
  font-family: inherit; transition: all 0.15s;
}
.search-wrap input:focus { outline: none; border-color: var(--c-accent); background: rgba(124,108,255,0.06); }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--c-text-dim); pointer-events: none; }
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--c-border);
  border-radius: 999px; cursor: pointer; color: var(--c-text);
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--c-grad); display: grid; place-items: center;
  font-weight: 700; font-size: 12px; color: white;
}
.user-info { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; }
.user-expiry { font-size: 11px; color: var(--c-text-dim); }
.user-expiry.warn { color: var(--c-warning); }
.user-expiry.danger { color: var(--c-danger); }
.user-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 12px; padding: 6px; min-width: 200px;
  box-shadow: var(--shadow-lg);
}
.user-dropdown.open { display: block; }
.user-dropdown a {
  display: block; padding: 10px 12px; color: var(--c-text);
  border-radius: 8px; font-size: 13px;
}
.user-dropdown a:hover { background: rgba(255,255,255,0.04); }
.user-dropdown hr { border: none; border-top: 1px solid var(--c-border); margin: 6px 0; }

/* ====== Main wrap ====== */
.main-wrap {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 16px 12px; overflow-y: auto;
  height: calc(100vh - var(--topbar-h));
  position: sticky; top: var(--topbar-h);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 14px; }
.sidebar-title { font-size: 11px; font-weight: 700; color: var(--c-text-dim); letter-spacing: 0.08em; text-transform: uppercase; }
#sidebar-close { display: none; }
.cat-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; color: var(--c-text-dim); margin: 2px 0;
  transition: all 0.12s; user-select: none;
}
.cat-item:hover { background: rgba(255,255,255,0.04); color: var(--c-text); }
.cat-item.active { background: rgba(124,108,255,0.15); color: var(--c-text); }
.cat-count { font-size: 11px; color: var(--c-text-dim); background: rgba(255,255,255,0.06); padding: 2px 8px; border-radius: 999px; }

/* ====== Content ====== */
.content {
  padding: 18px;
  display: grid; grid-template-rows: auto 1fr; gap: 18px;
  min-width: 0;
}

/* Player */
.player-section { display: grid; grid-template-rows: auto auto; gap: 12px; }
.player-frame {
  position: relative; aspect-ratio: 16/9; background: #000;
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--c-border);
}
.player-frame video { width: 100%; height: 100%; }
.player-overlay {
  position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0.2), rgba(0,0,0,0.6));
  display: grid; place-items: center; pointer-events: none; transition: opacity 0.2s;
}
.player-frame.playing .player-overlay { opacity: 0; }
.player-empty { text-align: center; color: var(--c-text-dim); }
.player-empty p { margin-top: 12px; font-size: 14px; }
.player-error {
  position: absolute; inset: 0; background: rgba(10,13,24,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--c-text); padding: 20px;
}
.player-error strong { font-size: 16px; color: var(--c-danger); }

.now-playing {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-md); padding: 12px;
}
.np-thumb { width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--c-surface-2); }
.np-thumb img { width: 100%; height: 100%; object-fit: contain; }
.np-title { font-weight: 600; font-size: 15px; }
.np-epg { font-size: 12px; color: var(--c-text-dim); margin-top: 2px; }
.np-actions { display: flex; gap: 8px; }

/* Streams grid */
.streams-section {}
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.view-toggle { display: flex; gap: 4px; background: var(--c-surface); border-radius: 10px; padding: 4px; border: 1px solid var(--c-border); }
.view-btn {
  background: transparent; border: none; color: var(--c-text-dim);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer;
  display: grid; place-items: center;
}
.view-btn.active { background: rgba(124,108,255,0.18); color: var(--c-text); }

.streams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.streams-grid.list { grid-template-columns: 1fr; }
.streams-grid.list .stream-card {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  aspect-ratio: auto; padding: 10px 14px;
}
.streams-grid.list .stream-thumb { aspect-ratio: 1; height: 64px; }
.streams-grid.list .stream-name { text-align: left; padding: 0; font-size: 14px; }

.stream-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-md); overflow: hidden; cursor: pointer;
  transition: all 0.15s; position: relative;
  display: flex; flex-direction: column;
}
.stream-card:hover { transform: translateY(-2px); border-color: var(--c-border-strong); box-shadow: var(--shadow-md); }
.stream-card.playing { border-color: var(--c-accent); box-shadow: 0 0 0 2px rgba(124,108,255,0.3); }
.stream-thumb {
  aspect-ratio: 16/10; background: var(--c-surface-2);
  display: grid; place-items: center; padding: 14px;
}
.stream-thumb img { max-height: 100%; max-width: 100%; object-fit: contain; }
.stream-thumb .placeholder {
  font-weight: 800; font-size: 22px; color: var(--c-text-dim);
}
.stream-name {
  padding: 8px 10px 10px; font-size: 12px; font-weight: 500;
  text-align: center; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.stream-num {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.6); color: white;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
}
.stream-fav {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); border: none; color: white;
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; opacity: 0; transition: opacity 0.15s;
}
.stream-card:hover .stream-fav, .stream-fav.active { opacity: 1; }
.stream-fav.active { color: var(--c-warning); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--c-text-dim); }

/* ====== Search overlay ====== */
.search-overlay {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0;
  background: rgba(10,13,24,0.96); backdrop-filter: blur(8px);
  z-index: 40; overflow-y: auto; display: none;
}
.search-overlay.open { display: block; }
.search-results-inner { max-width: 980px; margin: 0 auto; padding: 30px 20px; }
.search-group h3 { font-size: 13px; color: var(--c-text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin: 24px 0 12px; }

/* ====== Modal ====== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,7,15,0.85); backdrop-filter: blur(6px);
  z-index: 100; display: grid; place-items: center; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); padding: 24px;
  max-width: 700px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-card.small { max-width: 420px; }
.modal-card h3 { margin: 0 0 12px; font-size: 18px; }
.modal-card p { color: var(--c-text-dim); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-primary, .btn-secondary {
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
}
.btn-primary { background: var(--c-grad); color: white; border: none; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(124,108,255,0.4); }
.btn-secondary { background: rgba(255,255,255,0.04); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: rgba(255,255,255,0.08); }

/* ====== Series episode list ====== */
.series-info { display: grid; grid-template-columns: 200px 1fr; gap: 20px; margin-bottom: 20px; }
.series-cover { width: 100%; border-radius: 12px; aspect-ratio: 2/3; object-fit: cover; background: var(--c-surface-2); }
.series-meta h2 { margin: 0 0 8px; }
.series-meta .plot { color: var(--c-text-dim); font-size: 13px; line-height: 1.5; }
.season-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 12px; }
.season-tab { padding: 6px 14px; background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--c-text-dim); }
.season-tab.active { background: rgba(124,108,255,0.15); color: var(--c-text); border-color: var(--c-accent); }
.episode-list { display: flex; flex-direction: column; gap: 6px; }
.episode-row {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; background: var(--c-surface-2); border-radius: 8px;
  cursor: pointer; transition: all 0.12s;
}
.episode-row:hover { background: rgba(124,108,255,0.1); }
.episode-num { color: var(--c-text-dim); font-weight: 600; font-size: 13px; }
.episode-title { font-size: 14px; }
.episode-play { color: var(--c-accent); }

/* ====== Plyr customization ====== */
.plyr--video { --plyr-color-main: #7c6cff; }
.plyr--full-ui input[type=range] { color: var(--c-accent); }

/* ====== Responsive ====== */
@media (max-width: 980px) {
  .topbar-nav { display: none; }
  .nav-toggle { display: grid; place-items: center; }
  .search-wrap { width: 200px; }
  .user-info { display: none; }
  .main-wrap { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: min(280px, 86vw);
    z-index: 60; transform: translateX(-100%); transition: transform 0.25s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  #sidebar-close { display: grid; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 12px; }
  .brand { font-size: 16px; }
  .search-wrap { width: 140px; max-width: 40vw; }
  .search-wrap input { padding-left: 32px; padding-right: 8px; }
  .user-chip { padding: 4px; }
  .content { padding: 12px; gap: 12px; }
  .streams-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
  .now-playing { grid-template-columns: 48px 1fr; }
  .now-playing .np-actions { grid-column: span 2; justify-content: flex-end; }
  .np-thumb { width: 48px; height: 48px; }
}
