:root {
  --bg: #0b0f17;
  --bg-elevated: #121826;
  --bg-card: #1a2234;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f0f4fc;
  --text-muted: #8b95a8;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --live: #22c55e;
  --audio: #a855f7;
  --offline: #64748b;
  --tv-frame: linear-gradient(160deg, #2d3548 0%, #1a1f2e 45%, #0f1219 100%);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.15), transparent),
    var(--bg);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.filter-toggle input {
  accent-color: var(--accent);
}

.country-select-wrap select {
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 36px 10px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b95a8' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  min-width: 140px;
}

/* TV frame */
.player-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.tv-set {
  width: 100%;
  max-width: 880px;
}

.tv-bezel {
  background: var(--tv-frame);
  border-radius: 28px 28px 8px 8px;
  padding: 20px 20px 14px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.tv-screen-wrap {
  position: relative;
}

.tv-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
}

.tv-screen video,
.tv-screen audio {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.tv-screen.mode-audio audio {
  opacity: 1;
  pointer-events: auto;
  top: auto;
  bottom: 12px;
  left: 12px;
  right: 12px;
  width: calc(100% - 24px);
  height: 40px;
}

.tv-screen.mode-audio {
  background:
    radial-gradient(circle at 50% 40%, rgba(168, 85, 247, 0.2), transparent 60%),
    #0a0a12;
}

.tv-screen.mode-audio::after {
  content: "♫";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  color: rgba(168, 85, 247, 0.5);
  pointer-events: none;
}

.screen-idle,
.screen-loading,
.screen-error.is-geo-blocked p {
  max-width: 28rem;
  line-height: 1.5;
}

.geo-help-link {
  display: inline-block;
  margin: 12px 0 8px;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.45);
  color: #93c5fd;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.geo-help-link:hover {
  background: rgba(59, 130, 246, 0.3);
  color: #fff;
}

.channel-card.geo-blocked {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.screen-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.75);
  z-index: 2;
}

.hidden {
  display: none !important;
}

.idle-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-muted);
}

.screen-idle p,
.screen-loading p,
.screen-error p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.screen-idle.is-playable {
  cursor: pointer;
}

.screen-idle.is-playable .idle-icon {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 24px var(--accent-glow);
}

.screen-idle.is-playable p {
  color: var(--text);
}

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

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

#retry-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.now-playing {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 32px 16px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.2s;
}

.now-playing.visible {
  opacity: 1;
}

.now-playing #now-playing {
  pointer-events: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.share-btn:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(255, 255, 255, 0.35);
}

.share-btn.copied {
  border-color: var(--live);
  color: #bbf7d0;
}

.tv-led {
  position: absolute;
  bottom: -8px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #334155;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0);
  transition: background 0.3s, box-shadow 0.3s;
}

.tv-led.on {
  background: var(--live);
  box-shadow: 0 0 10px var(--live);
}

.tv-brand-plate {
  text-align: center;
  margin-top: 10px;
  font-size: 0.7rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
}

.tv-stand {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tv-neck {
  width: 80px;
  height: 28px;
  background: linear-gradient(180deg, #252b3a, #1a1f2e);
  clip-path: polygon(15% 0, 85% 0, 100% 100%, 0 100%);
}

.tv-base {
  width: 200px;
  height: 10px;
  background: linear-gradient(180deg, #2d3548, #1a1f2e);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.stat-pill {
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.stat-pill strong {
  color: var(--text);
}

/* Channels */
.channels-section {
  flex: 1;
}

.channels-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.channels-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

#channel-search {
  flex: 1;
  min-width: 180px;
  max-width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
}

#channel-search::placeholder {
  color: var(--text-muted);
}

.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.section-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.section-tab:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}

.section-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.section-heading {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-heading:first-child {
  margin-top: 0;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}

.channel-card {
  appearance: none;
  border: 2px solid transparent;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 10px 8px 8px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    transform 0.15s,
    box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  color: inherit;
  font: inherit;
}

.channel-card:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  border-color: var(--border);
}

.channel-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px var(--accent-glow);
}

.channel-card.offline {
  opacity: 0.45;
  cursor: not-allowed;
}

.channel-logo {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.35);
}

.channel-name {
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.channel-badge {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
}

.badge-live {
  background: rgba(34, 197, 94, 0.15);
  color: var(--live);
}

.badge-audio {
  background: rgba(168, 85, 247, 0.15);
  color: var(--audio);
}

.badge-vod {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.badge-geo {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.channel-card.geo-sensitive:not(.active) {
  border-color: rgba(245, 158, 11, 0.25);
}

.badge-off {
  background: rgba(100, 116, 139, 0.2);
  color: var(--offline);
}

.footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 8px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .app {
    padding: 12px 12px 24px;
  }

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

  .header-actions {
    justify-content: space-between;
  }

  .tv-bezel {
    padding: 14px 14px 10px;
    border-radius: 20px 20px 6px 6px;
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
  }

  .channel-logo {
    width: 48px;
    height: 48px;
  }

  #channel-search {
    max-width: none;
    width: 100%;
  }
}

@media (min-width: 900px) {
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }
}
