:root {
  --bg-body: #080a0f;
  --bg-surface: #10141d;
  --bg-surface-elevated: #161b26;
  --bg-surface-hover: #1e2433;
  --bg-surface-active: #252d3f;
  
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.20);
  
  --accent-cyan: #00f2fe;
  --accent-blue: #4facfe;
  --accent-gradient: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  --accent-glow: rgba(0, 242, 254, 0.22);
  --accent-bg-subtle: rgba(0, 242, 254, 0.08);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --status-live: #10b981;
  --status-error: #ef4444;
  --status-warn: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-accent: 0 0 20px var(--accent-glow);

  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(8, 10, 15, 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 24px;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-logo {
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-live);
  box-shadow: 0 0 8px var(--status-live);
}

.status-dot.buffering {
  background: var(--status-warn);
  box-shadow: 0 0 8px var(--status-warn);
}

.status-dot.error {
  background: var(--status-error);
  box-shadow: 0 0 8px var(--status-error);
}

.app-main {
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.player-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.player-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #030406;
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
}

#video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000000;
  display: block;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(3, 4, 6, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  padding: 24px;
  text-align: center;
}

.idle-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
}

.idle-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.idle-content p {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

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

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

.overlay-msg {
  margin-top: 14px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 440px;
}

.error-icon {
  color: var(--status-error);
}

.error-content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.error-content p {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.error-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  transition: transform var(--transition-fast), opacity var(--transition-fast), background var(--transition-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #040914;
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
}

.player-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 65%, transparent 100%);
  z-index: 20;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.player-wrapper:hover .player-controls,
.player-wrapper:focus-within .player-controls,
.player-controls.force-show {
  opacity: 1;
}

.controls-left, .controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.04);
}

.control-btn:active {
  transform: scale(0.96);
}

.volume-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  border: none;
}

.live-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #34d399;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
}

.channel-info-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.info-logo-wrap {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

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

.logo-fallback {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-cyan);
  user-select: none;
}

.info-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-header-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.info-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}

.badge {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-category {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  color: var(--text-secondary);
}

.badge-status {
  background: var(--accent-bg-subtle);
  border: 1px solid rgba(0, 242, 254, 0.25);
  color: var(--accent-cyan);
}

.info-sub-line {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.library-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 260px;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 42px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0 38px 0 42px;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.search-box input:focus {
  outline: none;
  background: var(--bg-surface-elevated);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.12);
}

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

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

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

.category-nav-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.category-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 4px 2px;
  scroll-behavior: smooth;
}

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

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(16, 20, 29, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.nav-arrow:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.nav-arrow-left {
  left: -12px;
}

.nav-arrow-right {
  right: -12px;
}

.cat-pill {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.cat-pill:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.cat-pill.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #050b16;
  font-weight: 700;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  min-height: 240px;
}

.channel-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

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

.channel-card:focus-visible {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.channel-card.active {
  border-color: var(--accent-cyan);
  background: var(--bg-surface-elevated);
  box-shadow: var(--shadow-accent);
}

.channel-card.active::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
}

.card-logo-box {
  width: 100%;
  height: 80px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
}

.card-logo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.card-fallback {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  user-select: none;
}

.card-info {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.card-category {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-sentinel {
  height: 40px;
}

.loading-grid {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state h3 {
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 600;
}

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

.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 20px 24px;
}

.footer-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-title {
  font-weight: 600;
  color: var(--text-primary);
}

.footer-tagline {
  color: var(--text-muted);
}

.footer-credits {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-credits a {
  color: var(--accent-cyan);
  font-weight: 500;
  transition: opacity var(--transition-fast);
}

.footer-credits a:hover {
  text-decoration: underline;
  opacity: 0.85;
}

.footer-sep {
  color: var(--text-muted);
}

.popup-wrapper {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  max-width: 380px;
  width: calc(100% - 48px);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease;
}

.popup-wrapper.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.popup-card {
  position: relative;
  background: rgba(16, 20, 29, 0.94);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55), 0 0 24px var(--accent-glow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popup-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.popup-close:hover {
  background: rgba(255, 255, 255, 0.18);
  color: var(--text-primary);
}

.popup-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.popup-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.popup-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.popup-text {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.popup-text strong {
  color: var(--text-primary);
}

.popup-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.popup-link {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  text-align: center;
}

.popup-link-primary {
  background: var(--accent-gradient);
  color: #050b16;
}

.popup-link-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.popup-link-secondary {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
}

.popup-link-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

@media (max-width: 900px) {
  .app-main {
    padding: 16px;
    gap: 20px;
  }
  
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .card-logo-box {
    height: 70px;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 10px 16px;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .status-indicator {
    padding: 4px 8px;
    font-size: 0.74rem;
  }

  .player-wrapper {
    border-radius: var(--radius-lg);
  }

  .player-controls {
    padding: 8px 12px;
  }

  .volume-container {
    display: none;
  }

  .channel-info-card {
    padding: 12px 14px;
    gap: 12px;
  }

  .info-logo-wrap {
    width: 44px;
    height: 44px;
  }

  .info-name {
    font-size: 1rem;
    max-width: 220px;
  }

  .controls-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: 100%;
  }

  .channel-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .footer-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}
