/* ============================================================
   ANCIENT TRADE ROUTES — Dark antiquity theme
   Gold lines on void. Parchment text. Animated caravans.
   ============================================================ */

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

:root {
  --void: #0a0c12;
  --panel: rgba(14, 17, 26, 0.92);
  --panel-solid: #0e111a;
  --panel-hover: #161a28;

  --gold: #d4a843;
  --gold-bright: #e8c45a;
  --gold-dim: #9a7828;
  --gold-glow: rgba(212, 168, 67, 0.12);

  --text: #d4cbba;
  --text-dim: #8a8070;
  --text-faint: #5a5248;

  --border: rgba(212, 168, 67, 0.15);
  --border-strong: rgba(212, 168, 67, 0.30);

  --sea: #5c9ece;
  --land-tag: #c08040;

  --f-display: 'Playfair Display', serif;
  --f-body: 'Cormorant Garamond', serif;
}

body {
  background: var(--void);
  overflow: hidden;
  font-family: var(--f-body);
  color: var(--text);
}

#map {
  width: 100vw;
  height: 100vh;
}

/* === TITLE OVERLAY === */

#title-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  pointer-events: none;
}

#title-overlay h1 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--gold);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

#title-overlay .subtitle {
  font-family: var(--f-body);
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-top: 2px;
  font-style: italic;
}

/* === TYPE FILTER === */

#type-filter {
  position: absolute;
  top: 16px;
  right: 56px;
  z-index: 10;
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.type-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 7px 14px;
  font-family: var(--f-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  border-right: 1px solid var(--border);
}

.type-btn:last-child { border-right: none; }

.type-btn:hover {
  background: var(--gold-glow);
  color: var(--text);
}

.type-btn.active {
  background: rgba(212, 168, 67, 0.18);
  color: var(--gold);
}

/* === LEGEND === */

#legend {
  position: absolute;
  bottom: 32px;
  left: 16px;
  z-index: 10;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 260px;
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

#legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#legend-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px 4px;
  transition: transform 0.25s;
}

#legend.collapsed #legend-toggle {
  transform: rotate(-90deg);
}

#legend-body {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

#legend.collapsed #legend-body,
#legend.collapsed #legend-footer {
  display: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.legend-item:hover {
  background: var(--gold-glow);
}

.legend-item.active {
  background: rgba(212, 168, 67, 0.18);
}

.legend-swatch {
  width: 22px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-name {
  font-family: var(--f-body);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  line-height: 1.2;
}

.legend-item:hover .legend-name,
.legend-item.active .legend-name {
  color: var(--gold);
}

.legend-era {
  font-size: 0.72rem;
  color: var(--text-faint);
  white-space: nowrap;
}

#legend-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-faint);
  text-align: center;
}

/* === LOADING BAR === */

#loading-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 100;
  background: rgba(0,0,0,0.3);
  transition: opacity 0.4s;
}

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

#loading-fill {
  height: 100%;
  width: 40%;
  border-radius: 0 2px 2px 0;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright), var(--gold-dim));
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s ease-in-out infinite;
}

#loading-text {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--f-body);
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
}

#loading-bar.hidden #loading-text { display: none; }

@keyframes loading-shimmer {
  0% { background-position: 200% 0; transform: translateX(-60%); }
  100% { background-position: -200% 0; transform: translateX(160%); }
}

/* === MAPLIBRE POPUP OVERRIDES === */

.maplibregl-popup-content {
  background: var(--panel-solid) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 8px !important;
  padding: 0 !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
  min-width: 260px;
  max-width: 320px;
  color: var(--text);
}

.maplibregl-popup-tip {
  border-top-color: var(--panel-solid) !important;
}

.maplibregl-popup-close-button {
  color: rgba(255,255,255,0.5) !important;
  font-size: 18px !important;
  right: 6px !important;
  top: 6px !important;
  z-index: 2;
}

.maplibregl-popup-close-button:hover {
  color: #fff !important;
  background: transparent !important;
}

.route-popup-header {
  padding: 12px 14px;
  border-radius: 7px 7px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.route-popup-header h3 {
  font-family: var(--f-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.route-type-badge {
  font-family: var(--f-body);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-size: 0.88rem;
}

.popup-label {
  color: var(--text-dim);
  font-weight: 500;
}

.popup-value {
  color: var(--text);
  text-align: right;
}

.popup-goods {
  margin-top: 8px;
}

.popup-goods .popup-label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.82rem;
}

.goods-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pill {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--gold-glow);
  color: var(--gold);
  border: 1px solid var(--border);
}

.popup-cities {
  margin-top: 8px;
  font-size: 0.82rem;
}

.popup-cities .popup-label {
  display: block;
  margin-bottom: 2px;
}

.cities-list {
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  display: block;
}

.popup-desc {
  margin-top: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

/* === ATTRIBUTION === */

.maplibregl-ctrl-attrib {
  background: rgba(10, 12, 18, 0.7) !important;
  font-size: 0.65rem !important;
}

.maplibregl-ctrl-attrib a {
  color: var(--text-faint) !important;
}

/* === RESPONSIVE === */

@media (max-width: 640px) {
  #title-overlay {
    top: 10px;
    left: 10px;
    padding: 10px 14px;
  }

  #title-overlay h1 { font-size: 1.1rem; }
  #title-overlay .subtitle { font-size: 0.82rem; }

  #type-filter {
    top: 10px;
    right: 50px;
  }

  .type-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  #legend {
    bottom: 20px;
    left: 10px;
    width: 220px;
  }

  .legend-era { display: none; }
}

@media (max-width: 420px) {
  #title-overlay .subtitle { display: none; }

  #legend { width: 180px; }

  .maplibregl-popup-content {
    min-width: 220px !important;
    max-width: 280px !important;
  }
}
