/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  --bg: #020205;
  --panel: rgba(12, 12, 28, 0.95); /* Slightly more opaque for better perf */
  --accent-cyan: #00f0ff;
  --accent-magenta: #ff006e;
  --text: #e8eaf6;
  --text-dim: #8a9bb8;
  --border: rgba(0, 240, 255, 0.12);
  --glow-cyan: 0 0 20px rgba(0, 240, 255, 0.25);
  --radius: 14px;
  --transition: all 0.2s ease-out; /* Faster transitions */
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  /* Hardware acceleration for body */
  transform: translateZ(0);
}

/* ============================================
   LOADING OVERLAY (Lightweight)
   ============================================ */
#loading-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem;
  transition: opacity 0.3s ease;
}

#loading-overlay.hidden { opacity: 0; pointer-events: none; }

#loading-text {
  font-size: 1.2rem; font-weight: 600;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

#loading-sub { color: var(--text-dim); font-size: 0.8rem; }

.loader-ring {
  display: inline-block; position: relative;  width: 50px; height: 50px;
}
.loader-ring div {
  box-sizing: border-box; display: block; position: absolute;
  width: 40px; height: 40px; margin: 5px;
  border: 3px solid var(--accent-cyan);
  border-radius: 50%;
  animation: loader-ring 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  border-color: var(--accent-cyan) transparent transparent transparent;
}
.loader-ring div:nth-child(1) { animation-delay: -0.3s; }
.loader-ring div:nth-child(2) { animation-delay: -0.2s; }
.loader-ring div:nth-child(3) { animation-delay: -0.1s; }

@keyframes loader-ring {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================
   HEADER
   ============================================ */
header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 50;
  padding: 0.8rem 1.5rem;
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, rgba(2,2,5,0.95) 0%, rgba(2,2,5,0) 100%);
  pointer-events: none;
}
header > * { pointer-events: auto; }

.brand {
  display: flex; align-items: center; gap: 0.8rem;
  background: rgba(12, 12, 28, 0.6);
  backdrop-filter: blur(5px); /* Reduced blur for perf */
  padding: 0.4rem 0.8rem 0.4rem 0.4rem;
  border-radius: 50px;
  border: 1px solid rgba(0, 240, 255, 0.1);
}

.logo-icon {
  font-size: 1.4rem;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(0, 240, 255, 0.3);
  background: radial-gradient(circle, rgba(0,240,255,0.1) 0%, transparent 70%);
}

.brand h1 {  font-size: 1.3rem; font-weight: 800;
  background: linear-gradient(135deg, #fff 0%, #00f0ff 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.byline {
  font-size: 0.6rem; color: var(--accent-cyan);
  text-transform: uppercase; letter-spacing: 1px;
  display: block; margin-top: 2px;
}

/* ============================================
   SEARCH
   ============================================ */
.search-box { position: relative; width: 300px; }

.search-box input {
  width: 100%; padding: 0.6rem 1rem 0.6rem 2.2rem;
  border-radius: 100px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text); font-size: 0.9rem; outline: none;
}
.search-box input:focus { border-color: var(--accent-cyan); }

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

.dropdown {
  position: absolute; top: 110%; left: 0; right: 0;
  max-height: 400px; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 60; padding: 0.5rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.dropdown.hidden { display: none; }

.search-section {
  padding: 0.4rem 0.6rem; font-size: 0.7rem;
  text-transform: uppercase; color: var(--accent-cyan);
  border-bottom: 1px solid var(--border); margin-bottom: 0.2rem;
}

.search-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.6rem; border-radius: 8px;
  cursor: pointer; transition: background 0.2s;}
.search-item:hover { background: rgba(0, 240, 255, 0.08); }

.search-logo {
  width: 28px; height: 28px; border-radius: 4px;
  background: rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; overflow: hidden; flex-shrink: 0;
}
.search-logo img { width: 100%; height: 100%; object-fit: cover; }

.search-name { font-weight: 600; font-size: 0.85rem; }
.search-meta { font-size: 0.7rem; color: var(--text-dim); }
.search-empty { padding: 1rem; text-align: center; color: var(--text-dim); }

/* ============================================
   GLOBE
   ============================================ */
#globe-container { width: 100vw; height: 100vh; cursor: grab; }
#globe-container:active { cursor: grabbing; }

.scene-tooltip {
  background: rgba(12, 12, 28, 0.95) !important;
  border: 1px solid var(--accent-cyan) !important;
  border-radius: 8px !important; padding: 8px 12px !important;
  color: #fff !important; font-size: 12px !important;
}

/* ============================================
   LEGEND & CONTROLS
   ============================================ */
#legend {
  position: absolute; bottom: 2rem; left: 1.5rem; z-index: 40;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.8rem;
  pointer-events: none;
}
.legend-title { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 0.4rem; text-transform: uppercase; }
.legend-gradient { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #141e32, var(--accent-cyan), var(--accent-magenta)); margin-bottom: 0.3rem; }
.legend-labels { display: flex; justify-content: space-between; font-size: 0.65rem; color: var(--text-dim); }

#reset-view {
  position: absolute; bottom: 2rem; right: 1.5rem; z-index: 40;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#reset-view:hover { border-color: var(--accent-cyan); }
/* ============================================
   SIDEBAR
   ============================================ */
#sidebar {
  position: absolute; top: 70px; right: 15px;
  width: 340px; max-height: calc(100vh - 90px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 45; display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
#sidebar.hidden { display: none; }

.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1rem; font-weight: 700; }
.meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; }

#close-sidebar {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  background: rgba(255,255,255,0.05); color: var(--text-dim);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#close-sidebar:hover { background: rgba(255,0,110,0.2); color: var(--accent-magenta); }

.sidebar-filters { padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); }
.sidebar-filters input {
  width: 100%; padding: 0.4rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--border); background: rgba(255,255,255,0.03);
  color: var(--text); font-size: 0.8rem; outline: none;
}

#channels { list-style: none; overflow-y: auto; flex: 1; padding: 0.4rem; }

.channel-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem; border-radius: 8px; cursor: pointer;
  transition: background 0.2s; border: 1px solid transparent;
}
.channel-item:hover { background: rgba(0, 240, 255, 0.05); border-color: rgba(0, 240, 255, 0.1); }

.channel-logo {
  width: 36px; height: 36px; border-radius: 6px;
  background: rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden; font-weight: 700; color: var(--accent-cyan);}
.channel-logo img { width: 100%; height: 100%; object-fit: cover; }
.logo-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: rgba(0,240,255,0.1); }

.channel-info { flex: 1; min-width: 0; }
.channel-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-meta { font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; }

.play-btn {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: var(--accent-cyan); color: #000;
  cursor: pointer; opacity: 0; transition: opacity 0.2s;
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem;
}
.channel-item:hover .play-btn { opacity: 1; }

.empty { padding: 1.5rem; text-align: center; color: var(--text-dim); font-size: 0.85rem; }

/* ============================================
   PLAYER
   ============================================ */
#player-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
#player-overlay.hidden { display: none; }

.player-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.9); backdrop-filter: blur(5px); }

.player-card {
  position: relative; width: 100%; max-width: 850px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

.player-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border);
}
.player-header .channel-info { display: flex; align-items: center; gap: 0.6rem; }
#player-logo { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: rgba(255,255,255,0.05); }
#player-logo.hidden { display: none; }
#current-channel-name { font-size: 0.95rem; font-weight: 700; }
#close-player {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: rgba(255,255,255,0.05); color: var(--text-dim);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}#close-player:hover { background: rgba(255,0,110,0.2); color: var(--accent-magenta); }

.player-body { position: relative; background: #000; }

#video-player {
  width: 100%; height: auto; max-height: 60vh;
  display: block; aspect-ratio: 16/9;
  transform: translateZ(0); /* GPU Force */
}

.player-loader, .stream-fallback, .player-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.8rem; background: rgba(0,0,0,0.8); z-index: 5;
}
.player-loader p, .stream-fallback p, .player-error p { color: var(--text-dim); font-size: 0.85rem; }

.player-error button {
  padding: 0.4rem 1rem; border-radius: 6px;
  border: 1px solid var(--accent-cyan); background: transparent;
  color: var(--accent-cyan); cursor: pointer; font-size: 0.8rem;
}
.player-error button:hover { background: rgba(0, 240, 255, 0.1); }

.hidden { display: none !important; }

.stream-controls {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 1rem; background: rgba(255,255,255,0.02);
  border-top: 1px solid var(--border);
}
#stream-indicator { font-size: 0.75rem; color: var(--text-dim); }
#next-stream {
  padding: 0.3rem 0.8rem; border-radius: 4px;
  border: 1px solid var(--border); background: rgba(0, 240, 255, 0.05);
  color: var(--accent-cyan); cursor: pointer; font-size: 0.75rem;
}

/* ============================================
   FOOTER
   ============================================ */
footer {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 40;
  padding: 0.5rem 1.5rem;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.7rem; color: var(--text-dim);
  background: linear-gradient(0deg, rgba(2,2,5,0.95) 0%, transparent 100%);
  pointer-events: none;
}
#stats { font-weight: 500; color: var(--text); }
@media (max-width: 768px) {
  header { padding: 0.6rem 1rem; flex-direction: column; gap: 0.6rem; }
  .search-box { width: 100%; }
  #sidebar { width: calc(100% - 2rem); right: 1rem; left: 1rem; top: 130px; }
  footer { flex-direction: column; gap: 0.2rem; text-align: center; }
}
