@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Anybody:wght@400;700;900&display=swap');

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #050508;
  font-family: 'Space Mono', monospace;
  color: #d0d0d0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── CRT Effects ── */
body.crt-enabled::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  mix-blend-mode: multiply;
}

body.crt-enabled::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.45) 100%),
    linear-gradient(
      0deg,
      transparent 0%,
      transparent var(--crt-band-pos, 0%),
      rgba(255,255,255,0.015) calc(var(--crt-band-pos, 0%) + 4%),
      transparent calc(var(--crt-band-pos, 0%) + 8%),
      transparent 100%
    );
  animation: crtRoll 8s linear infinite;
}

body.crt-enabled {
  text-shadow: 0.4px 0 0 rgba(255,0,0,0.04), -0.4px 0 0 rgba(0,255,255,0.04);
}

@keyframes crtRoll {
  0%   { --crt-band-pos: -8%; }
  100% { --crt-band-pos: 108%; }
}

@property --crt-band-pos {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInOpacity {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) translateY(8px); }
  to   { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Globe Container ── */
#globe-container {
  position: absolute;
  inset: 0;
  z-index: 10;
}
#globe-container canvas { outline: none !important; }

/* ── Dim Overlay ── */
#dim-overlay {
  position: absolute;
  inset: 0;
  background: black;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 50;
}
#dim-overlay.active { opacity: 0.85; }

/* ── Header ── */
#header {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(5,5,8,0.92) 0%, transparent 100%);
  pointer-events: none;
  z-index: 100;
}

#header h1 {
  font-family: 'Anybody', sans-serif;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ff4444, #ff8800, #ffdd00, #44ff66, #44aaff, #8855ff, #ff44aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  white-space: nowrap;
}

#header .subtitle {
  font-size: 11px;
  opacity: 0.5;
  margin-top: 2px;
  letter-spacing: 0.04em;
}

#header .title-area,
#header .actions {
  pointer-events: auto;
}

#header .actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Icon Button ── */
.icon-btn {
  background: #000;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 6px;
  padding: 8px 12px;
  color: #ccc;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  font-family: 'Space Mono', monospace;
  transition: background 0.15s;
}
.icon-btn:hover { background: #111; }

.channels-btn {
  padding: 8px 14px;
  font-size: 12px;
  gap: 6px;
}

/* ── Filter Legend ── */
#filter-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(17,17,17,0.67);
  border: 1px solid #333;
  border-radius: 5px;
  cursor: pointer;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #555;
  transition: all 0.2s;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.filter-btn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  transition: all 0.2s;
}

.filter-btn.active { color: var(--filter-color); background: var(--filter-bg); border-color: var(--filter-border); }
.filter-btn.active .dot { background: var(--filter-color); box-shadow: 0 0 6px var(--filter-color); }

/* ── Mobile Filters ── */
#mobile-filters {
  display: none;
  position: absolute;
  bottom: 16px;
  left: 8px;
  right: 8px;
  z-index: 100;
  flex-direction: column;
  gap: 6px;
}

#mobile-filter-toggle {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(0,0,0,0.67);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #aaa;
  backdrop-filter: blur(8px);
}

#mobile-filter-row {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  animation: fadeIn 0.2s ease;
}

#mobile-filter-row .filter-btn {
  padding: 8px 12px;
  font-size: 10px;
  flex-shrink: 0;
  min-height: 36px;
}

#mobile-filter-close {
  padding: 8px 10px;
  background: rgba(17,17,17,0.67);
  border: 1px solid #333;
  border-radius: 5px;
  cursor: pointer;
  color: #666;
  font-size: 12px;
  flex-shrink: 0;
  min-height: 36px;
}

/* ── Sidebar ── */
#sidebar-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 190;
}

#sidebar {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  background: rgba(8, 8, 14, 0.97);
  border-left: 1px solid rgba(255,255,255,0.05);
  backdrop-filter: blur(20px);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
#sidebar.open { transform: translateX(0); }

#sidebar .header-bar {
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

#sidebar .header-bar .top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

#sidebar .header-bar .title {
  font-weight: 700;
  font-size: 14px;
  font-family: 'Anybody', sans-serif;
}

#sidebar .mobile-settings { display: none; }

#sidebar .close-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px;
  color: #ccc;
  font-size: 12px;
  font-family: 'Space Mono', monospace;
  outline: none;
}

#channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.channel-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.024);
  cursor: pointer;
  color: #ccc;
  font-family: 'Space Mono', monospace;
  transition: background 0.15s;
}
.channel-item:hover { background: rgba(255,255,255,0.03); }
.channel-item.selected { background: rgba(255,255,255,0.04); }

.channel-item .name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.channel-item .ch-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.channel-item .ch-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.channel-item .ch-location {
  font-size: 10px;
  opacity: 0.5;
  margin-left: 14px;
}

/* ── Modals ── */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 490;
  display: none;
}

.modal-content {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 15, 0.95);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 12px;
  padding: 24px;
  width: 400px;
  max-width: 90vw;
  z-index: 500;
  box-shadow: 0 20px 40px rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
  animation: modalFadeIn 0.2s ease;
  color: #eee;
  font-family: 'Space Mono', monospace;
  display: none;
}

.modal-content .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-content h2 {
  font-size: 18px;
  font-weight: 700;
  font-family: 'Anybody', sans-serif;
  margin: 0;
}

.modal-content .modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-content .body {
  font-size: 13px;
  line-height: 1.6;
  color: #ccc;
}

.modal-content .body p { margin-bottom: 12px; }
.modal-content .body p:last-child { margin-bottom: 0; }

/* ── Location Selector ── */
#location-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 390;
  display: none;
}

#location-selector {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 15, 0.95);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  z-index: 400;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  animation: modalFadeIn 0.2s ease;
  display: none;
}

#location-selector .loc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

#location-selector .loc-title {
  font-size: 14px;
  font-weight: 700;
  font-family: 'Anybody', sans-serif;
}

#location-selector .loc-subtitle {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}

#location-selector .loc-close {
  background: none;
  border: none;
  color: #888;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

#location-channels {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.loc-channel-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 6px;
  cursor: pointer;
  color: #eee;
  font-family: 'Space Mono', monospace;
  text-align: left;
  transition: all 0.2s;
  min-height: 48px;
}

.loc-channel-btn:hover {
  background: rgba(255,255,255,0.08);
}

.loc-channel-btn .loc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.loc-channel-btn .loc-ch-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loc-channel-btn .loc-ch-type {
  font-size: 10px;
  margin-top: 2px;
}

/* ── Type Badge ── */
.type-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 3px;
}

/* ── Video Player (Desktop) ── */
#player-desktop {
  position: absolute;
  z-index: 300;
  animation: fadeInOpacity 0.3s ease;
  display: none;
}

#player-desktop .player-shell {
  width: 100%;
  height: 100%;
  background: #0a0a0f;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 20px 80px rgba(0,0,0,0.8), 0 0 1px rgba(255,255,255,0.13);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #0f0f16;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.player-titlebar .left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.player-titlebar .ch-label {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-titlebar .right {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.player-link {
  font-size: 10px;
  color: #888;
  text-decoration: none;
  padding: 2px 6px;
  border: 1px solid #333;
  border-radius: 3px;
}

.player-close-btn {
  background: rgba(255,68,85,0.13);
  border: 1px solid rgba(255,68,85,0.27);
  color: #ff6666;
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 10px;
  cursor: pointer;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
}

.player-video-area {
  flex: 1;
  position: relative;
  background: #000;
}

.player-video-area iframe {
  width: 100%;
  height: 100%;
  border: none;
  transition: opacity 0.5s;
}

.player-info-bar {
  padding: 8px 12px;
  background: #0f0f16;
  border-top: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
  font-size: 10px;
  opacity: 0.5;
  line-height: 1.5;
}

/* ── Static Noise ── */
.static-noise-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.static-noise-overlay canvas {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  opacity: 0.6;
}

.tuning-label {
  position: relative;
  z-index: 2;
  font-size: 13px;
  font-weight: 700;
  color: #555;
  animation: pulse 1.5s infinite;
}

/* ── Video Player (Mobile) ── */
#player-mobile {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 55vh;
  z-index: 300;
  animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: none;
  flex-direction: column;
}

#player-mobile .player-shell {
  width: 100%;
  height: 100%;
  background: #0a0a0f;
  border-radius: 16px 16px 0 0;
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom: none;
  box-shadow: 0 -10px 60px rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#player-mobile .drag-hint {
  display: flex;
  justify-content: center;
  padding: 8px 0 0;
}

#player-mobile .drag-hint span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.13);
}

#player-mobile .player-titlebar {
  cursor: default;
  padding: 8px 14px 10px;
}

#player-mobile .player-link,
#player-mobile .player-close-btn {
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Resize Handle (Desktop) ── */
.resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 10;
}

.resize-handle::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(255,255,255,0.2);
  border-bottom: 2px solid rgba(255,255,255,0.2);
}

/* ── Empty State ── */
#empty-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 90;
  animation: fadeIn 1s ease 0.5s both;
}

#empty-hint .hint-pill {
  font-size: 12px;
  color: rgba(255,255,255,0.27);
  background: rgba(0,0,0,0.4);
  padding: 8px 20px;
  border-radius: 20px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.05);
}

/* ── Mobile drag handle in sidebar ── */
#sidebar .drag-hint {
  display: none;
  justify-content: center;
  padding: 10px 0 4px;
}
#sidebar .drag-hint span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.13);
}

/* ═══════════════════ MOBILE ═══════════════════ */
@media (max-width: 767px) {
  #header { padding: 12px 14px; }
  #header h1 { font-size: 18px; }
  #header .subtitle { display: none; }
  #header .actions { gap: 6px; }
  .icon-btn { padding: 10px 12px; }
  #btn-lights, #btn-crt { display: none !important; }

  #filter-legend { display: none !important; }
  #mobile-filters { display: flex; }

  #sidebar {
    top: 10%;
    left: 0;
    right: 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #sidebar.open { transform: translateY(0); }

  #sidebar .drag-hint { display: flex; }
  #sidebar .mobile-settings { display: flex; gap: 8px; }
  #sidebar .mobile-settings .icon-btn { padding: 6px 8px; font-size: 14px; min-width: 32px; min-height: 32px; }

  #search-input { padding: 10px 14px; font-size: 14px; }
  .channel-item { padding: 14px 16px; }

  #empty-hint { bottom: 70px; left: 0; transform: none; width: calc(100% - 32px); margin-left: 16px; }
  #empty-hint .hint-pill { font-size: 11px; padding: 10px 16px; }

  #location-selector {
    top: auto; left: 0; right: 0; bottom: 0;
    transform: none;
    border-radius: 16px 16px 0 0;
    width: 100%;
    animation: slideUp 0.3s ease;
  }
}
