/* Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0e1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.3);
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --border-color: #30363d;
  --live-red: #ef4444;
  --success-green: #22c55e;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* App Wrapper */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 20px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.back-home-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.back-home-btn:hover {
  background: var(--accent);
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-free {
  font-size: 0.65rem;
  font-weight: 800;
  background: #10b981;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.brand-text .subtext {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Mode Toggles */
.mode-toggles {
  display: flex;
  background-color: var(--bg-primary);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  gap: 4px;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.toggle-btn.active {
  background-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.toggle-btn:hover:not(.active) {
  color: var(--text-main);
  background-color: var(--bg-tertiary);
}

/* Language Selector */
.lang-selector {
  display: flex;
  background-color: var(--bg-primary);
  border-radius: 8px;
  padding: 4px;
  border: 1px solid var(--border-color);
  gap: 4px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-btn.active {
  background-color: var(--bg-tertiary);
  color: #fff;
  border: 1px solid var(--border-color);
}

.lang-btn:hover:not(.active) {
  color: var(--text-main);
}

/* IPTV Source Bar */
.source-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background-color: #111620;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  flex-wrap: wrap;
  gap: 8px;
}

.source-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.source-label {
  font-weight: 600;
  color: var(--text-main);
}

#iptv-playlist-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

.counter-badge {
  background: var(--bg-tertiary);
  color: #38bdf8;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
}

.source-action-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.proxy-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.proxy-toggle-label:hover {
  background: rgba(34, 197, 94, 0.22);
}

.proxy-toggle-label input {
  cursor: pointer;
  accent-color: #22c55e;
}

.text-green {
  color: #22c55e;
}

.source-action-btn:hover {
  background: var(--accent);
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1.8fr 1.2fr;
  gap: 16px;
  padding: 16px 20px;
  flex: 1;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}

/* Player Panel */
.player-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.media-container {
  background-color: #000;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.video-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

.video-wrapper video, .tv-iframe {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-color: #000;
  border: none;
}

/* Radio Player Interface */
.radio-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  text-align: center;
}

.radio-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.radio-disc {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: #fff;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
  transition: transform 0.3s ease;
}

.radio-disc.spinning {
  animation: disc-spin 3s linear infinite;
}

@keyframes disc-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#audio-visualizer {
  width: 260px;
  height: 50px;
  background: transparent;
}

.radio-info h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.radio-info p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.radio-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 8px;
}

.ctrl-play-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.15s ease, background 0.2s;
}

.ctrl-play-btn:hover {
  transform: scale(1.06);
  background: var(--accent-hover);
}

.volume-container {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.volume-container input[type="range"] {
  accent-color: var(--accent);
  width: 100px;
  cursor: pointer;
}

/* Stream Loader & Error states */
.stream-loader, .stream-error {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #fff;
  z-index: 10;
  padding: 20px;
  text-align: center;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.stream-error {
  color: #f87171;
}

.stream-error i {
  font-size: 32px;
}

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

.btn-retry, .btn-next {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.btn-next {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

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

/* Now Playing Card */
.now-playing-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.np-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.live-badge {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--live-red);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: var(--live-red);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

.np-details h3 {
  font-size: 1rem;
  font-weight: 600;
}

.np-details p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.np-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.action-btn.active i {
  color: #f43f5e;
  font-weight: 900;
}

/* Directory Panel */
.directory-panel {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  height: calc(100vh - 150px);
  overflow: hidden;
}

.directory-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  gap: 10px;
}

.search-box i {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.search-box input {
  background: transparent;
  border: none;
  color: var(--text-main);
  outline: none;
  font-size: 0.88rem;
  width: 100%;
}

.clear-search {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

/* Category Chips */
.category-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

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

.chip {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.chip:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

.chip.active {
  background-color: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Channel List */
.channel-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.channel-list::-webkit-scrollbar {
  width: 6px;
}

.channel-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* Channel Item Card */
.channel-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.channel-card:hover {
  background-color: var(--bg-tertiary);
  border-color: #3b82f6;
  transform: translateX(2px);
}

.channel-card.active {
  border-color: var(--accent);
  background-color: rgba(37, 99, 235, 0.15);
}

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

.card-logo {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background-color: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.card-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-meta {
  min-width: 0;
}

.card-meta h4 {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tags {
  display: flex;
  gap: 6px;
  margin-top: 3px;
}

.tag-lang, .tag-cat {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  text-transform: capitalize;
}

.tag-lang.hi {
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.tag-lang.en {
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.tag-lang.ja {
  color: #ec4899;
  border: 1px solid rgba(236, 72, 153, 0.3);
}

.card-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fav-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.9rem;
  transition: color 0.15s;
}

.fav-icon-btn.is-fav {
  color: #f43f5e;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 10px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 36px;
  margin-bottom: 10px;
  opacity: 0.6;
}

/* Modal Dialog */
.modal-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box h3 {
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.m3u-input {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.btn-cancel, .btn-confirm {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.btn-cancel {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.btn-confirm {
  background: var(--accent);
  color: #fff;
}

/* Footer */
.footer-bar {
  text-align: center;
  padding: 10px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* PWA Install Banner / Button */
.install-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
  transition: all 0.2s ease;
}

.install-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.45);
}

/* Mobile & Touch Responsive Enhancements */
@media (max-width: 768px) {
  .app-container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .navbar {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .navbar::-webkit-scrollbar {
    display: none;
  }

  .brand {
    gap: 8px;
    flex-shrink: 0;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
    font-size: 13px;
    border-radius: 6px;
  }

  .brand-text h1 {
    font-size: 0.92rem;
  }

  .badge-free {
    display: none;
  }

  .brand-text .subtext {
    display: none;
  }

  .mode-toggles {
    order: unset;
    flex-shrink: 0;
    padding: 2px;
  }

  .toggle-btn {
    padding: 5px 9px;
    font-size: 0.75rem;
  }

  .lang-selector {
    order: unset;
    flex-shrink: 0;
    padding: 2px;
  }

  .lang-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .install-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
    flex-shrink: 0;
  }

  .source-bar {
    padding: 5px 10px;
    font-size: 0.75rem;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .source-left, .source-right {
    width: auto;
    flex-shrink: 0;
  }

  #iptv-playlist-select {
    max-width: 140px;
    font-size: 0.72rem;
    padding: 3px 6px;
  }

  .counter-badge {
    display: none;
  }

  .proxy-toggle-label {
    font-size: 0.7rem;
    padding: 3px 6px;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    padding: 4px 6px 0;
    gap: 6px;
    flex: 1;
    overflow: hidden;
  }

  .player-panel {
    flex-shrink: 0;
    padding-bottom: 0;
    gap: 6px;
  }

  .media-container {
    border-radius: 8px;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 32vh;
  }

  .now-playing-card {
    padding: 6px 10px;
  }

  .np-details h3 {
    font-size: 0.82rem;
  }

  .np-details p {
    font-size: 0.68rem;
  }

  .action-btn {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .directory-panel {
    flex: 1;
    height: auto;
    max-height: none;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    padding: 8px 6px;
    margin-bottom: 0;
  }

  .directory-header {
    margin-bottom: 6px;
    gap: 6px;
  }

  .search-box {
    padding: 5px 8px;
  }

  .search-box input {
    font-size: 0.8rem;
  }

  .category-scroll {
    gap: 4px;
    padding-bottom: 2px;
  }

  .chip {
    padding: 3px 8px;
    font-size: 0.7rem;
  }

  .channel-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
  }

  .channel-card {
    padding: 8px 10px;
  }

  .card-logo {
    width: 34px;
    height: 34px;
  }

  .card-meta h4 {
    font-size: 0.82rem;
  }

  .footer-bar {
    display: none;
  }
}
