/* ───────────────────────── a11y / SEO utilities ───────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0,0,0,0) !important;
  white-space: nowrap !important; border: 0 !important;
}

/* ───────────────────────── reset & base ───────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  background: #0a0a0a;
  color: #e6e6dc;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

:root {
  --bg: #0a0a0a;
  --bg-2: #131313;
  --bg-3: #1a1a1a;
  --fg: #e6e6dc;
  --fg-dim: #8a8a82;
  --line: #2a2a26;
  --green: #5cf28d;
  --amber: #ffb340;
  --red: #ff4d4d;
  --pdf: #a8b8ff;
  --vid: #5cf28d;
  --img: #ffb340;
}

/* ─────────────────────── topbar ─────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-brand { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.brand-mark { font-size: 14px; font-weight: 700; letter-spacing: 0.06em; color: var(--green); }
.brand-sub { font-size: 10px; letter-spacing: 0.16em; color: var(--fg-dim); }
.topbar-nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 8px 14px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.1em;
  color: var(--fg-dim);
  border: 1px solid transparent;
  border-radius: 2px;
  transition: all .15s;
}
.nav-btn:hover { color: var(--fg); border-color: var(--line); }
.nav-btn.is-active { color: var(--bg); background: var(--green); border-color: var(--green); }

/* ─────────────────────── views ─────────────────────── */
.view { position: fixed; inset: 0; padding-top: 58px; display: none; }
.view.is-active { display: block; }

/* ─────────────────────── MAP VIEW ─────────────────────── */
#map {
  width: 100%; height: 100%;
  background: #050505;
}
.leaflet-container {
  background: #050505 !important;
  font-family: inherit;
}
.leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(1.1) saturate(0.6); }
.leaflet-control-attribution { background: rgba(0,0,0,0.6) !important; color: var(--fg-dim) !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: var(--fg) !important; }
.leaflet-control-zoom a {
  background: rgba(20,20,20,0.92) !important; color: var(--fg) !important;
  border: 1px solid var(--line) !important;
}

.uap-pin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #0a0a0a;
  box-shadow: 0 0 0 1px currentColor, 0 0 12px currentColor;
}
.uap-pin.pdf { background: var(--pdf); color: var(--pdf); }
.uap-pin.vid { background: var(--vid); color: var(--vid); }
.uap-pin.img { background: var(--img); color: var(--img); }
.uap-pin.is-closest { width: 22px; height: 22px; animation: pulse 1.6s infinite ease-out; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 currentColor, 0 0 18px currentColor; }
  100% { box-shadow: 0 0 0 14px transparent, 0 0 18px currentColor; }
}

.leaflet-popup-content-wrapper {
  background: #131313 !important;
  color: var(--fg) !important;
  border: 1px solid var(--line);
  border-radius: 2px !important;
  font-family: inherit;
}
.leaflet-popup-tip { background: #131313 !important; }
.leaflet-popup-content { margin: 12px 14px !important; font-size: 12px; line-height: 1.4; }
.leaflet-popup-content strong { color: var(--green); display: block; margin-bottom: 4px; }
.leaflet-popup-content em { font-style: normal; color: var(--fg-dim); font-size: 10px; }

.map-overlay {
  position: absolute; bottom: 24px; left: 24px;
  width: min(420px, calc(100vw - 48px));
  background: rgba(10, 10, 10, 0.94);
  border: 1px solid var(--green);
  border-radius: 2px;
  padding: 18px 20px;
  z-index: 600;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 1px var(--green) inset;
}
.overlay-stamp {
  font-size: 10px; letter-spacing: 0.18em; color: var(--green);
  margin-bottom: 8px;
}
#closest-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 22px; font-weight: 600; line-height: 1.2;
  margin-bottom: 8px; color: var(--fg);
}
.overlay-meta {
  font-size: 11px; color: var(--fg-dim); letter-spacing: 0.06em;
  margin-bottom: 10px; text-transform: uppercase;
}
.overlay-meta .dot { margin: 0 6px; }
#closest-description {
  font-size: 12px; color: var(--fg-dim); line-height: 1.5;
  margin-bottom: 14px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.overlay-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 14px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.12em;
  border: 1px solid var(--line);
  border-radius: 2px;
  transition: all .15s;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: var(--bg); border-color: var(--green); }
.btn-primary:hover { background: #7ff5a3; }
.btn-ghost { color: var(--fg); }
.btn-ghost:hover { background: var(--bg-3); border-color: var(--fg-dim); }

.map-legend {
  position: absolute; top: 70px; right: 16px; z-index: 600;
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(10,10,10,0.85);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 10px; letter-spacing: 0.1em; color: var(--fg-dim);
}
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-item .dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-item .dot.pdf { background: var(--pdf); }
.legend-item .dot.vid { background: var(--vid); }
.legend-item .dot.img { background: var(--img); }

/* ─────────────────────── FEED VIEW ─────────────────────── */
.view-feed { background: #050505; overflow: hidden; }
.feed-stack {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.feed-stack::-webkit-scrollbar { display: none; }
.feed-card {
  scroll-snap-align: start;
  height: calc(100vh - 58px);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #050505;
  overflow: hidden;
}
.feed-media {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.feed-media video, .feed-media img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.feed-media iframe {
  width: 100%; height: 100%;
  border: 0;
  background: #000;
}
.feed-meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 60px 24px 24px;
  background: linear-gradient(to top, rgba(0,0,0,0.95) 30%, transparent);
  color: #fff;
  z-index: 5;
}
.feed-tag {
  display: inline-block;
  font-size: 10px; letter-spacing: 0.16em; color: var(--green);
  margin-bottom: 8px; padding: 3px 8px;
  border: 1px solid var(--green);
}
.feed-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 26px; font-weight: 600; line-height: 1.2;
  margin-bottom: 10px;
}
.feed-info { font-size: 11px; color: var(--fg-dim); letter-spacing: 0.08em; margin-bottom: 14px; text-transform: uppercase; }
.feed-info span + span::before { content: " · "; opacity: 0.5; margin: 0 6px; }
.feed-desc {
  font-size: 13px; line-height: 1.55; color: #cdcdc4;
  max-width: 640px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.feed-actions { margin-top: 14px; display: flex; gap: 8px; }
.feed-progress {
  position: absolute; top: 12px; left: 24px; right: 24px;
  display: flex; gap: 4px; z-index: 6;
}
.feed-progress span { flex: 1; height: 2px; background: rgba(255,255,255,0.15); }
.feed-progress span.is-active { background: var(--green); }

/* ─────────────────────── BROWSE VIEW ─────────────────────── */
.view-browse { background: var(--bg); overflow: hidden; }
.browse-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
#search {
  flex: 1; min-width: 220px;
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 2px;
  font-size: 12px; letter-spacing: 0.1em;
}
#search:focus { outline: none; border-color: var(--green); }
.filter-group { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 6px 10px;
  font-size: 10px; letter-spacing: 0.1em;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--fg-dim);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { color: var(--fg); }
.chip.is-active { color: var(--bg); background: var(--fg); border-color: var(--fg); }
.result-count {
  margin-left: auto;
  font-size: 11px; color: var(--fg-dim); letter-spacing: 0.1em;
}
.browse-list {
  height: calc(100% - 78px); overflow-y: auto;
  padding: 0;
}
.row {
  display: grid;
  grid-template-columns: 64px 90px 1fr 220px 120px 80px;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}
.row:hover { background: var(--bg-2); }
.row-thumb {
  width: 64px; height: 48px;
  background: #1a1a1a center/cover no-repeat;
  border: 1px solid var(--line);
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.row-thumb.no-thumb.vid::after {
  content: '▶';
  color: var(--vid);
  font-size: 16px;
  text-shadow: 0 0 8px var(--vid);
}
.row-thumb.no-thumb.pdf::after { content: 'PDF'; color: var(--pdf); font-size: 9px; letter-spacing: 0.1em; }
.row-thumb.no-thumb.img::after { content: 'IMG'; color: var(--img); font-size: 9px; letter-spacing: 0.1em; }
.row-type {
  font-size: 10px; letter-spacing: 0.16em;
  padding: 3px 7px;
  border: 1px solid currentColor;
  display: inline-block;
  width: max-content;
}
.row-type.pdf { color: var(--pdf); }
.row-type.vid { color: var(--vid); }
.row-type.img { color: var(--img); }
.row-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 15px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-loc { font-size: 11px; color: var(--fg-dim); letter-spacing: 0.06em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-date { font-size: 11px; color: var(--fg-dim); letter-spacing: 0.06em; }
.row-agency { font-size: 10px; color: var(--fg-dim); letter-spacing: 0.1em; text-align: right; }

/* ─────────────────────── DRAWER ─────────────────────── */
.drawer {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; justify-content: flex-end;
}
.drawer[hidden] { display: none; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-panel {
  position: relative;
  width: min(560px, 100vw);
  height: 100%;
  background: var(--bg-2);
  border-left: 1px solid var(--green);
  padding: 20px 24px;
  overflow-y: auto;
  animation: slide .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.drawer-agency { font-size: 11px; letter-spacing: 0.18em; color: var(--green); }
.drawer-close { font-size: 18px; color: var(--fg-dim); padding: 4px 8px; }
.drawer-close:hover { color: var(--fg); }
#drawer-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 24px; font-weight: 600; line-height: 1.25;
  margin-bottom: 12px;
}
.drawer-meta {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 11px; letter-spacing: 0.08em; color: var(--fg-dim);
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
}
.drawer-meta dt { color: var(--fg-dim); font-size: 9px; }
.drawer-meta dd { color: var(--fg); margin-bottom: 6px; }
.drawer-media {
  margin-bottom: 18px;
  background: #050505;
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}
.drawer-media video, .drawer-media img {
  width: 100%; height: auto; max-height: 60vh; object-fit: contain; border: 0;
  display: block;
}
/* Constrain the DVIDS iframe to its native 16:9 player ratio so the embed's
   "View on dvidshub.net" footer link gets clipped. */
.drawer-media iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
  background: #000;
}
.drawer-desc { font-size: 13px; line-height: 1.6; color: #d0d0c8; margin-bottom: 20px; }
.drawer-actions { display: flex; gap: 8px; }

/* ─────────────────────── toast ─────────────────────── */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: var(--bg);
  padding: 10px 16px;
  font-size: 11px; letter-spacing: 0.1em; font-weight: 600;
  z-index: 3000;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.is-visible { opacity: 1; }

/* ─────────────────────── per-file detail pages (SEO landing) ─────────────────────── */
.record-page-body {
  overflow: auto;
  background: var(--bg);
}
.record-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 96px 24px 72px;
  color: var(--fg);
}
.record-page-back {
  display: inline-block;
  font-size: 11px; letter-spacing: 0.14em;
  color: var(--fg-dim);
  margin-bottom: 28px;
  text-transform: uppercase;
}
.record-page-back:hover { color: var(--green); }
.record-page-agency {
  display: inline-block;
  font-size: 12px; letter-spacing: 0.18em;
  color: var(--green);
  margin-bottom: 12px;
}
.record-page-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 36px; font-weight: 600; line-height: 1.18;
  letter-spacing: -0.005em;
  margin-bottom: 24px;
  color: var(--fg);
}
.record-page-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.record-page-meta dt {
  font-size: 9px; letter-spacing: 0.18em;
  color: var(--fg-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.record-page-meta dd {
  font-size: 12px; letter-spacing: 0.06em;
  color: var(--fg);
  text-transform: uppercase;
}
.record-page-media {
  margin-bottom: 28px;
  background: #050505;
  border: 1px solid var(--line);
  overflow: hidden;
}
.record-page-media img {
  display: block;
  width: 100%; height: auto; max-height: 70vh;
  object-fit: contain;
}
.record-page-iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #000;
}
.record-page-desc {
  font-size: 14px; line-height: 1.7; color: #d0d0c8;
  margin-bottom: 32px;
  white-space: pre-line;
}
.record-page-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 36px;
}
.record-page-source {
  font-size: 11px; line-height: 1.6;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.record-page-source a { color: var(--green); }
.record-page-source a:hover { text-decoration: underline; }

/* ─────────────────────── responsive ─────────────────────── */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .brand-mark { font-size: 12px; }
  .brand-sub { display: none; }
  .nav-btn { padding: 6px 10px; font-size: 11px; }
  .map-overlay { left: 12px; right: 12px; bottom: 12px; width: auto; padding: 14px 16px; }
  #closest-title { font-size: 18px; }
  .row {
    grid-template-columns: 56px 1fr 70px;
    gap: 10px;
  }
  .row-type, .row-loc, .row-date, .row-agency { display: none; }
  .row-thumb { width: 56px; height: 42px; }
  .row-title { font-size: 13px; }
  .row::after {
    content: attr(data-mobile-meta);
    grid-column: 2;
    font-size: 10px; color: var(--fg-dim); letter-spacing: 0.1em;
    margin-top: 2px;
  }
  .browse-toolbar { padding: 12px; gap: 8px; }
  .feed-title { font-size: 22px; }
  .map-legend { top: 64px; right: 8px; }
  .record-page { padding: 84px 16px 56px; }
  .record-page-title { font-size: 26px; }
  .record-page-meta { grid-template-columns: 1fr 1fr; gap: 10px 16px; }

  /* Mobile feed: stack media on top, metadata below — no absolute overlays.
     Fixes the DVIDS embed showing its "View on dvidshub.net" footer link
     and the dead space between video and meta on portrait viewports. */
  .feed-card {
    flex-direction: column;
    justify-content: flex-start;
  }
  .feed-progress { top: 8px; left: 16px; right: 16px; }
  .feed-media {
    position: static;
    width: 100%;
    aspect-ratio: 16 / 9;
    flex: none;
    background: #000;
  }
  .feed-media iframe { aspect-ratio: 16 / 9; height: auto; }
  .feed-meta {
    position: static;
    flex: 1;
    padding: 18px 18px 24px;
    background: transparent;
    overflow: hidden;
  }
  .feed-tag { margin-top: 4px; }
  .feed-desc { -webkit-line-clamp: 6; }
}
