/* ======================================================================
   CVC Ancient Map — Stylesheet
   Command center aesthetic. Dark, immersive, satellite terrain focus.
   ====================================================================== */

:root {
  /* Charcoal base */
  --bg-dark:       #111113;
  --bg-panel:      #18181c;
  --bg-card:       #1f1f24;
  --bg-hover:      #28282f;
  /* Silver borders */
  --border:        #2a2a30;
  --border-bright: #3a3a42;
  /* Sand / silver text */
  --text:          #d4d0c8;
  --text-muted:    #908c82;
  --text-dim:      #5a5850;
  /* Gold accent */
  --accent:        #c9a84c;
  --accent-dim:    #8a6e2c;
  --accent-glow:   rgba(201, 168, 76, 0.10);
  /* Silver link */
  --link:          #8eaab8;
  --danger:        #b85a42;
  --success:       #5a9a6a;
  --radius:        5px;
  --radius-sm:     3px;
  --panel-width:   400px;
  --topbar-height: 44px;
  --timeline-height: 34px;
  --font:          -apple-system, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  --font-mono:     'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── TOPBAR ────────────────────────────────────────────────────────── */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: rgba(17, 17, 19, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  gap: 8px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.topbar-center { flex: 1; max-width: 400px; margin: 0 8px; }

.search-wrap { position: relative; width: 100%; }

#search-input {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 120px;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#search-input::placeholder { color: var(--text-dim); }

.search-dropdown {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 1010;
}

.search-dropdown.active { display: block; }

.search-item {
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.search-item:hover { background: var(--bg-hover); }
.search-item-name { font-size: 13px; font-weight: 500; }
.search-item-region { font-size: 11px; color: var(--text-muted); }
.search-item-type {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: auto;
  white-space: nowrap;
}

/* ── FILTER CHIPS ──────────────────────────────────────────────────── */

.filter-chips {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 3px 10px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  transition: all 0.15s;
}

.chip:hover { border-color: var(--accent-dim); color: var(--text-muted); }
.chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

/* ── BUTTONS ───────────────────────────────────────────────────────── */

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  white-space: nowrap;
}

.icon-btn:hover { background: var(--bg-hover); border-color: var(--accent-dim); color: var(--text); }
.icon-btn.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

.mini-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s;
}
.mini-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── TIMELINE BAR ──────────────────────────────────────────────────── */

#timeline-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--timeline-height);
  background: rgba(17, 17, 19, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 800;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.timeline-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.timeline-label, .timeline-value {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 60px;
}

.timeline-value { text-align: right; color: var(--accent); font-weight: 600; }

#timeline-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

#timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

#timeline-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ── PANELS ────────────────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: var(--topbar-height);
  bottom: var(--timeline-height);
  width: var(--panel-width);
  background: var(--bg-panel);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
}

.panel-left {
  left: 0;
  border-right: 1px solid var(--border);
}
.panel-left.hidden { transform: translateX(-100%); }

.panel-right {
  right: 0;
  border-left: 1px solid var(--border);
}
.panel-right.hidden { transform: translateX(100%); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.panel-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.panel-header-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
}
.panel-close:hover { color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.panel-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── LAYERS PANEL ──────────────────────────────────────────────────── */

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}
.layer-toggle:hover { opacity: 0.85; }
.layer-toggle:last-child { border-bottom: none; }

.layer-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.layer-info { flex: 1; }
.layer-name { font-size: 13px; font-weight: 500; }
.layer-desc { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.layer-switch {
  width: 36px; height: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.layer-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.2s;
}

.layer-toggle.active .layer-switch { background: var(--accent-dim); border-color: var(--accent); }
.layer-toggle.active .layer-switch::after { left: 18px; background: var(--accent); }

/* ── FEED PANEL ────────────────────────────────────────────────────── */

.feed-filters {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.feed-filter {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  transition: all 0.15s;
}
.feed-filter:hover { border-color: var(--accent-dim); }
.feed-filter.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

.feed-card {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.15s;
}
.feed-card:hover { opacity: 0.8; }

.feed-thumb {
  width: 90px; height: 50px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-card);
}

.feed-info { flex: 1; min-width: 0; }

.feed-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-meta { font-size: 10px; color: var(--text-muted); margin-top: 3px; }
.feed-channel { color: var(--link); }

.feed-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── SITE DETAIL PANEL ─────────────────────────────────────────────── */

.site-hero { position: relative; flex-shrink: 0; }

.site-hero img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
  background: var(--bg-card);
}

.site-meta {
  position: absolute;
  bottom: 8px; left: 8px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.badge {
  background: rgba(10, 10, 15, 0.85);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid rgba(212, 175, 55, 0.3);
  backdrop-filter: blur(4px);
  text-transform: capitalize;
}

.badge-type { color: var(--link); border-color: rgba(126, 184, 218, 0.3); }

.site-traditions {
  position: absolute;
  top: 8px; right: 8px;
  display: flex;
  gap: 4px;
}

.tradition-pip {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: help;
}

.site-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-tabs::-webkit-scrollbar { display: none; }

.site-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 9px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.site-tab:hover { color: var(--text-muted); }
.site-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

#tab-overview p,
#tab-alternative p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 14px;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  margin: 2px 4px 2px 0;
  font-size: 11px;
  color: var(--link);
  text-decoration: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all 0.15s;
}
.source-link:hover { background: var(--bg-hover); border-color: var(--link); }

/* Textual references */
.text-ref-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.text-ref-header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }

.text-ref-tradition {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.text-ref-source { font-size: 12px; color: var(--text-muted); font-style: italic; }

.text-ref-passage {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  padding: 8px 12px;
  border-left: 3px solid var(--accent-dim);
  background: var(--accent-glow);
  margin-bottom: 6px;
  font-style: italic;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.text-ref-interpretation { font-size: 12px; line-height: 1.5; color: var(--text-muted); }

/* Gallery */
#site-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.gallery-img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
  background: var(--bg-card);
}
.gallery-img:hover { opacity: 0.8; }

/* Site Navigation */
.site-nav {
  display: flex;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.site-nav-btn {
  flex: 1;
  background: var(--bg-card);
  border: none;
  color: var(--text-muted);
  padding: 10px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.site-nav-btn:first-child { border-right: 1px solid var(--border); }
.site-nav-btn:hover { background: var(--bg-hover); color: var(--accent); }

/* ── MAP ───────────────────────────────────────────────────────────── */

#map {
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0;
  bottom: var(--timeline-height);
}


/* MapLibre overrides */
.maplibregl-popup-content {
  background: var(--bg-panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: var(--radius) !important;
  padding: 0 !important;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6) !important;
  max-width: 300px !important;
  overflow: hidden !important;
}

.maplibregl-popup-tip { border-top-color: var(--bg-panel) !important; }
.maplibregl-popup-close-button { color: var(--text-muted) !important; font-size: 18px !important; right: 8px !important; top: 6px !important; z-index: 1 !important; }

.maplibregl-ctrl-group { background: rgba(15, 15, 24, 0.9) !important; border: 1px solid var(--border) !important; backdrop-filter: blur(8px) !important; }
.maplibregl-ctrl-group button { background-color: transparent !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.maplibregl-ctrl-group button span { filter: invert(0.75); }

/* Cluster list popup items */
.cluster-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: rgba(212, 175, 55, 0.15);
}
.cluster-item:hover { background: var(--bg-hover); }
.cluster-item:active { background: var(--bg-hover); }
.cluster-item:last-child { border-bottom: none; }

/* Popup */
.popup-site { cursor: pointer; }

.popup-thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--bg-card);
}

.popup-body { padding: 10px 14px 12px; }

.popup-site-name { font-size: 14px; font-weight: 600; color: var(--accent); margin-bottom: 3px; }
.popup-site-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }

.popup-site-desc {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.popup-cta { display: inline-block; margin-top: 6px; font-size: 11px; color: var(--link); font-weight: 500; }

/* ── LOADING OVERLAY ───────────────────────────────────────────────── */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  transition: opacity 0.5s ease;
}

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

.loading-content { text-align: center; }

.loading-glyph {
  font-size: 48px;
  color: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

.loading-text { margin-top: 16px; font-size: 13px; color: var(--text-muted); letter-spacing: 1px; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ── SITE COUNT ────────────────────────────────────────────────────── */

#site-count {
  position: fixed;
  bottom: calc(var(--timeline-height) + 8px);
  left: 10px;
  background: rgba(17, 17, 19, 0.88);
  color: var(--text-dim);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  z-index: 800;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}

/* ── MODAL ─────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  max-width: 500px;
  width: 90%;
  position: relative;
}

.modal-content h2 { color: var(--accent); margin-bottom: 14px; font-size: 20px; }
.modal-content h3 { color: var(--text-muted); margin: 16px 0 8px; font-size: 13px; font-weight: 600; }
.modal-content p { font-size: 13px; line-height: 1.7; color: var(--text); margin-bottom: 10px; }
.modal-content hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; }
.about-footer { color: var(--text-dim) !important; text-align: center; font-size: 12px !important; }

.about-shortcuts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 16px; }
.shortcut { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; padding: 3px 0; }
kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  min-width: 22px;
  text-align: center;
}

/* ── LIGHTBOX ──────────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: var(--radius); }

/* ── TOAST NOTIFICATION ────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: calc(var(--timeline-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--accent-dim);
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 12px;
  z-index: 4000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── RESPONSIVE ────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .filter-chips { display: none; }
}

@media (max-width: 768px) {
  :root { --panel-width: 100vw; }
  .topbar-center { margin: 0 4px; }
  .logo { font-size: 13px; }
  #btn-random { display: none; }
  #btn-layers span { display: none; }
}

@media (max-width: 480px) {
  .site-tabs { gap: 0; }
  .site-tab { padding: 9px 8px; font-size: 11px; }
}
