:root {
  --bg-1: #0a0a2a;
  --bg-2: #1a0a3a;
  --cyan: #00ffff;
  --pink: #ff77ff;
  --text: #f4f4ff;
  --muted: rgba(244,244,255,0.55);
  --line: rgba(255,119,255,0.22);
  --panel: rgba(0,0,40,0.78);
  --orange: #f60;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%) fixed;
  overflow: hidden;
}

/* Perspective grid backdrop */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,119,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,119,255,0.06) 1px, transparent 1px);
  background-size: 40px 40px;
  transform: perspective(800px) rotateX(60deg) translateY(80px);
  transform-origin: center bottom;
  pointer-events: none;
  z-index: -1;
}

/* TOP BAR */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--pink);
  background: rgba(0,0,40,0.6); backdrop-filter: blur(6px);
}
.brand {
  font-family: 'Orbitron', sans-serif; font-weight: 700;
  letter-spacing: 0.18em; color: var(--cyan);
  text-shadow: 0 0 10px rgba(0,255,255,0.45);
}
.brand-meta { color: var(--pink); text-shadow: 0 0 8px rgba(255,119,255,0.4); }
.stat { font-family: 'Orbitron', sans-serif; font-size: 11px; letter-spacing: 0.15em; color: var(--muted); }
.stat span { color: var(--cyan); font-weight: 700; }

/* SEARCH + FACETS */
.searchbar {
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: rgba(0,0,40,0.45); display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
}
#q {
  flex: 1; min-width: 280px;
  background: rgba(0,0,40,0.85); color: var(--cyan); font-size: 16px;
  border: 1px solid var(--cyan); padding: 10px 14px; outline: none;
  font-family: 'Orbitron', sans-serif; letter-spacing: 0.05em;
  box-shadow: 0 0 10px rgba(0,255,255,0.25) inset, 0 0 16px rgba(0,255,255,0.18);
}
#q::placeholder { color: rgba(0,255,255,0.45); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips-divider { width: 1px; background: var(--line); margin: 0 6px; }
.chips button {
  border: 1px solid var(--pink); color: var(--pink); background: transparent;
  padding: 4px 10px; font: 600 10px/1 'Orbitron', sans-serif; letter-spacing: 0.12em;
  cursor: pointer; transition: all 0.18s;
}
.chips button:hover { background: rgba(255,119,255,0.12); }
.chips button.is-active { background: var(--pink); color: var(--bg-1); box-shadow: 0 0 10px rgba(255,119,255,0.55); }

/* ATLAS LAYOUT */
.atlas {
  display: grid;
  grid-template-columns: 1fr 480px;
  height: calc(100vh - 56px - 60px);
}
@media (max-width: 900px) {
  .atlas { grid-template-columns: 1fr; grid-template-rows: 50% 50%; }
}

#map { background: #050518; border-right: 1px solid var(--pink); }
.mapboxgl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--pink); font-family: inherit; }
.mapboxgl-popup-tip { border-top-color: var(--pink) !important; }

/* RESULT LIST */
#results { display: flex; flex-direction: column; overflow: hidden; }
#results-header {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 14px;
  border-bottom: 1px solid var(--line); font-family: 'Orbitron', sans-serif; font-size: 11px;
  letter-spacing: 0.1em; color: var(--muted);
}
#results-count { color: var(--cyan); }
.pill {
  background: transparent; color: var(--pink); border: 1px solid var(--pink);
  padding: 3px 8px; margin-left: 6px; font: 600 10px/1 'Orbitron', sans-serif;
  letter-spacing: 0.1em; cursor: pointer;
}
.pill.is-active { background: var(--pink); color: var(--bg-1); }

/* Gallery/Videos grid view — shown when #results-grid is non-empty */
#results-grid {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
}
#results-grid.is-active { display: grid; }
#results-grid .tile {
  position: relative; aspect-ratio: 1;
  background: #050518; border: 1px solid var(--line);
  cursor: pointer; overflow: hidden;
  transition: border-color 0.18s, transform 0.18s, box-shadow 0.18s;
}
#results-grid .tile:hover {
  border-color: var(--cyan); transform: scale(1.03); z-index: 2;
  box-shadow: 0 0 14px rgba(0,255,255,0.45);
}
#results-grid .tile img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
#results-grid .tile .meta {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, transparent, rgba(10,10,42,0.92) 60%);
  color: var(--text); padding: 18px 8px 6px;
  font-size: 10px; line-height: 1.3; pointer-events: none;
}
#results-grid .tile .meta strong {
  display: block; font-family: 'Orbitron', sans-serif;
  color: var(--cyan); font-size: 9px; letter-spacing: 0.1em; margin-bottom: 2px;
}
#results-grid .tile .meta .loc {
  color: var(--pink); font-size: 9px; letter-spacing: 0.05em; margin-top: 2px;
}
#results-grid .tile .play-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--cyan); text-shadow: 0 0 10px rgba(0,0,0,0.85);
  pointer-events: none; background: rgba(0,0,0,0.22);
  font-family: 'Orbitron', sans-serif;
}
@media (max-width: 600px) {
  #results-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

#realm-banner {
  padding: 10px 14px;
  background: rgba(255,119,255,0.10);
  border-bottom: 1px solid var(--pink);
  color: var(--text); font-size: 12px; line-height: 1.45;
}
#realm-banner strong {
  color: var(--pink); font-family: 'Orbitron',sans-serif; letter-spacing: 0.1em; font-size: 11px;
  display: inline-block; margin-bottom: 2px;
}

#results-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#results-list li {
  padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; flex-direction: row; gap: 12px; align-items: flex-start;
}
#results-list li:hover, #results-list li.is-active { background: rgba(255,119,255,0.08); }
.r-thumb {
  flex: 0 0 80px;
  width: 80px; height: 80px;
  background: #050518;
  border: 1px solid var(--line);
  object-fit: cover;
  display: block;
}
.r-thumb-wrap {
  flex: 0 0 80px; width: 80px; height: 80px;
  position: relative;
}
.r-thumb-wrap .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--cyan); text-shadow: 0 0 8px rgba(0,0,0,0.85);
  background: rgba(0,0,0,0.22); pointer-events: none;
}
.r-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.r-title {
  color: var(--text); font-weight: 500; font-size: 13px;
  line-height: 1.35; word-break: break-word; overflow-wrap: break-word;
}
.r-snippet { color: var(--muted); font-size: 12px; line-height: 1.45; }
.r-snippet mark { background: rgba(255,119,255,0.35); color: var(--text); padding: 0 2px; }
.r-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.r-pill {
  display: inline-block;
  padding: 2px 8px;
  font: 600 9px/1.4 'Orbitron', sans-serif;
  letter-spacing: 0.1em;
  border-radius: 2px;
  white-space: nowrap;
}
.r-pill.agency  { background: rgba(0,255,255,0.15);   color: var(--cyan); border: 1px solid rgba(0,255,255,0.4); }
.r-pill.type    { background: rgba(255,119,255,0.15); color: var(--pink); border: 1px solid rgba(255,119,255,0.4); }
.r-pill.loc     { background: rgba(244,244,255,0.06); color: var(--muted); border: 1px solid var(--line); }
.r-pill.date    { background: rgba(244,244,255,0.06); color: var(--muted); border: 1px solid var(--line); }

#results-pager {
  padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: center;
}
#results-pager button {
  background: transparent; color: var(--cyan); border: 1px solid var(--cyan);
  padding: 4px 10px; font: 600 11px/1 'Orbitron', sans-serif; cursor: pointer; letter-spacing: 0.1em;
}
#results-pager button:disabled { opacity: 0.3; cursor: not-allowed; }
#results-pager button.is-current { background: var(--cyan); color: var(--bg-1); }

/* MODAL */
#modal { position: fixed; inset: 0; background: rgba(0,0,20,0.85); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 100; }
#modal[hidden] { display: none; }
.modal-shell { width: min(900px, 92vw); max-height: 88vh; background: var(--panel); border: 1px solid var(--pink); padding: 24px; overflow-y: auto; position: relative; box-shadow: 0 0 40px rgba(255,119,255,0.4); }
#modal-close { position: absolute; top: 8px; right: 12px; background: transparent; color: var(--cyan); border: none; font-size: 28px; cursor: pointer; line-height: 1; }
.modal-title { font-family: 'Orbitron', sans-serif; color: var(--cyan); font-size: 22px; letter-spacing: 0.1em; text-shadow: 0 0 10px rgba(0,255,255,0.4); margin: 0 0 6px; }
.modal-meta { display: flex; gap: 14px; flex-wrap: wrap; font: 600 11px/1 'Orbitron', sans-serif; color: var(--pink); letter-spacing: 0.1em; margin-bottom: 16px; }
.modal-redacted { color: #ff5050; font-style: italic; font-size: 13px; margin: 8px 0; }
.modal-desc { line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions a, .modal-actions button {
  background: transparent; color: var(--cyan); border: 1px solid var(--cyan);
  padding: 8px 14px; font: 600 11px/1 'Orbitron', sans-serif; letter-spacing: 0.1em;
  text-decoration: none; cursor: pointer;
}
.modal-actions a:hover { background: var(--cyan); color: var(--bg-1); }
.modal-media { margin: 16px 0; }
.modal-media img, .modal-media video { width: 100%; max-height: 60vh; object-fit: contain; background: #050518; }
.modal-media iframe { width: 100%; height: 60vh; border: 1px solid var(--cyan); background: #050518; }
