/* ============================================
   Design Tokens — Cinema Dark & Warm Cream Light
   ============================================ */
:root {
  --bg-page: #0d0f14;
  --bg-surface: #151922;
  --bg-card: #181d27;
  --bg-card-hover: #1e2432;
  --bg-input: #151922;
  --border-subtle: #252c3b;
  --border-hover: #3b465e;

  --text-primary: #f3f5f8;
  --text-secondary: #b9c1d0;
  --text-muted: #7f8a9e;

  --accent: #6e8f4e;
  --accent-hover: #7ea35a;
  --accent-soft: rgba(110, 143, 78, 0.16);

  --live-red: #ef4444;
  --live-red-soft: rgba(239, 68, 68, 0.16);
  --heart-red: #f43f5e;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.22);
  --shadow-card-hover: 0 12px 26px rgba(0, 0, 0, 0.35);
  --shadow-player: 0 18px 44px rgba(0, 0, 0, 0.48);
  --transition: 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);

  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg-page: #f9f7f1;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #fdfcf9;
  --bg-input: #ffffff;
  --border-subtle: #dfdbd0;
  --border-hover: #b8b2a2;

  --text-primary: #171715;
  --text-secondary: #383632;
  --text-muted: #6e6b63;

  --accent: #627448;
  --accent-hover: #52623b;
  --accent-soft: rgba(98, 116, 72, 0.12);

  --shadow-card: 0 2px 8px rgba(23, 23, 21, 0.04);
  --shadow-card-hover: 0 10px 24px rgba(23, 23, 21, 0.08);
  --shadow-player: 0 12px 32px rgba(23, 23, 21, 0.12);
}

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

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  min-height: 100dvh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
  padding-bottom: calc(40px + var(--safe-bottom));
  transition: background var(--transition), color var(--transition);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   App Shell
   ============================================ */
.app-shell {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 640px) {
  .app-shell {
    padding: 0 28px;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    padding: 0 40px;
  }
}

/* ============================================
   Header
   ============================================ */
.site-header {
  padding: 22px 0 18px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  color: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg {
  width: 100%;
  height: 100%;
}

.title-badge-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.badge-live-pill {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--live-red-soft);
  color: var(--live-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.site-subtitle {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.icon-action-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.icon-action-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ============================================
   Live TV Player Stage
   ============================================ */
.player-stage {
  margin-bottom: 24px;
  animation: fadeSlideDown 0.28s ease;
}

.player-stage[hidden] {
  display: none;
}

@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.player-stage-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-player);
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 66vh;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.video-overlay,
.video-error-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 17, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: #f3f5f8;
  z-index: 5;
}

.video-overlay[hidden],
.video-error-overlay[hidden] {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3.5px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-icon {
  font-size: 2.2rem;
}

.video-error-overlay h3 {
  font-size: 1.08rem;
  font-weight: 700;
}

.video-error-overlay p {
  font-size: 0.86rem;
  color: #b9c1d0;
  max-width: 460px;
}

.error-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

.btn-primary-sm,
.btn-secondary-sm {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary-sm {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary-sm:hover {
  background: var(--accent-hover);
}

.btn-secondary-sm {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.btn-secondary-sm:hover {
  background: rgba(255, 255, 255, 0.2);
}

.player-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  flex-wrap: wrap;
}

.player-channel-info {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}

.player-logo-wrap {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-weight: 800;
  font-size: 1rem;
  color: var(--accent);
}

.player-logo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.player-text-wrap {
  min-width: 0;
}

.player-status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.live {
  background: var(--live-red);
  box-shadow: 0 0 0 3px var(--live-red-soft);
  animation: pulseDot 1.6s infinite;
}

.status-dot.loading {
  background: #f59e0b;
}

@keyframes pulseDot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.status-text {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.quality-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.player-channel-name {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-channel-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.quality-select {
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.ctrl-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.ctrl-btn.is-fav {
  color: var(--heart-red);
  border-color: rgba(244, 63, 94, 0.4);
  background: rgba(244, 63, 94, 0.1);
}

.ctrl-btn.is-fav svg {
  fill: currentColor;
}

.ctrl-btn-danger:hover {
  color: var(--live-red);
  border-color: rgba(239, 68, 68, 0.45);
  background: var(--live-red-soft);
}

/* ============================================
   Controls Bar (Search, Tabs, Pills)
   ============================================ */
.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.search-box-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  width: 19px;
  height: 19px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 48px;
  padding: 0 46px 0 46px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.94rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-input::-webkit-search-cancel-button {
  display: none;
}

.btn-clear-search {
  position: absolute;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-clear-search.visible {
  display: inline-flex;
}

.btn-clear-search:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
}

.tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

@media (min-width: 640px) {
  .category-tabs {
    display: flex;
    width: auto;
    flex-wrap: wrap;
  }
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.fav-count {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.16);
}

[data-theme="light"] .tab-btn:not(.active) .fav-count {
  background: rgba(23, 23, 21, 0.08);
}

.results-meta {
  font-size: 0.84rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Subfilters Row */
.subfilters-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pills-scroller-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.pills-nav-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.pills-nav-btn[hidden] {
  display: none;
}

.pills-nav-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.category-pills {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
  cursor: grab;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.category-pills.is-dragging {
  cursor: grabbing;
  scroll-behavior: auto;
}

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

.pill-btn {
  flex-shrink: 0;
  padding: 6px 13px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.pill-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.pill-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.country-filter-wrap[hidden] {
  display: none;
}

.country-select {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 240px;
}

/* ============================================
   Channel Grid & Cards
   ============================================ */
.channel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  width: 100%;
}

@media (min-width: 560px) {
  .channel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 880px) {
  .channel-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1180px) {
  .channel-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.channel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  min-width: 0;
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition),
    box-shadow var(--transition), background var(--transition);
}

.channel-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-card-hover);
}

.channel-card.is-playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.card-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.channel-logo {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent);
}

.channel-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.channel-info {
  min-width: 0;
  flex: 1;
}

.channel-name {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-country {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-fav-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.card-fav-btn:hover {
  background: rgba(244, 63, 94, 0.12);
  color: var(--heart-red);
}

.card-fav-btn.active {
  color: var(--heart-red);
}

.card-fav-btn.active svg {
  fill: currentColor;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.card-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.tag-chip {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  text-transform: capitalize;
}

.tag-quality {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.tag-playing {
  background: var(--live-red-soft);
  color: var(--live-red);
  border-color: transparent;
}

.card-watch-cta {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ============================================
   Skeleton & Empty State
   ============================================ */
.skeleton-card {
  height: 122px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
}

.empty-state-icon {
  font-size: 2.4rem;
  margin-bottom: 10px;
}

.empty-state h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto;
}

/* ============================================
   Load More & Footer
   ============================================ */
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 26px;
}

.load-more-wrap[hidden] {
  display: none;
}

.btn-load-more {
  padding: 12px 26px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-load-more:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.site-footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ============================================
   Toast Notice
   ============================================ */
.toast-notice {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(90px);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-hover);
  padding: 11px 18px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-player);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-width: calc(100vw - 32px);
}

.toast-notice.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
