:root {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #22c55e;
  --border: #1f2937;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #0f172a 0%, #0b1220 100%);
}
header h1 { margin: 0; font-size: 20px; }
header p { margin: 4px 0 0; color: var(--muted); }
.header-left { display: flex; flex-direction: column; }
.site-title { color: inherit; text-decoration: none; }
.site-title:hover { color: var(--accent); }

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 5px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--border); }
.nav-link.nav-active { color: var(--accent); font-weight: 600; }

.year-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.year-control input[type="range"] { width: 200px; }
#year-value { min-width: 48px; text-align: center; font-weight: 600; }

main { display: flex; flex: 1; overflow: hidden; position: relative; }
.page { display: flex; flex: 1; min-width: 0; width: 100%; height: 100%; }
.page[hidden] { display: none; }
#page-map { position: relative; }
#map { flex: 1; min-width: 0; width: 100%; height: 100%; }

/* Info pages (About / Terms / Privacy) */
.info-page {
  overflow-y: auto;
  background: var(--bg);
  justify-content: center;
}
.info-content {
  max-width: 720px;
  width: 100%;
  padding: 48px 24px 80px;
}
.info-content h2 { font-size: 28px; margin: 0 0 8px; }
.info-content h3 { font-size: 17px; margin: 32px 0 8px; color: var(--text); }
.info-content p, .info-content li { color: var(--muted); line-height: 1.7; font-size: 15px; }
.info-content ul { padding-left: 20px; margin: 8px 0; }
.info-content a { color: var(--accent); text-decoration: none; }
.info-content a:hover { text-decoration: underline; }
.info-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--panel);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
}
.source-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 12px 0;
}
.source-title { font-weight: 600; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.source-body { color: var(--muted); font-size: 14px; line-height: 1.6; }
.source-body a { color: var(--accent); }
.info-date { font-size: 13px; color: var(--muted); margin: 0 0 24px; }
.info-footer { margin-top: 48px; font-size: 13px; border-top: 1px solid var(--border); padding-top: 16px; }

#legend-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 320px;
  max-width: calc(100% - 32px);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  padding: 12px 14px;
  z-index: 2;
}
#legend { display: flex; flex-direction: column; gap: 8px; max-height: 400px; overflow-y: auto; padding-right: 4px; }
#legend-title { cursor: pointer; margin: 0 0 8px; font-size: 16px; }
.legend-item { display: flex; flex-direction: column; gap: 4px; }
.legend-bar { flex: 1; height: 12px; background: #1f2937; border: 1px solid #0b0f19; border-radius: 6px; overflow: visible; min-width: 120px; position: relative; }
.legend-bar-fill { height: 100%; position: relative; display: flex; align-items: center; overflow: visible; }
.legend-bar-label { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; color: #fff; white-space: nowrap; pointer-events: none; }
.legend-bar-label.tiny { left: auto; color: var(--text); }
.legend-row { display: flex; align-items: center; gap: 10px; }
.legend-area-text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.legend-row.legend-selected .legend-bar { outline: 1px solid var(--accent); box-shadow: 0 0 0 2px rgba(34,197,94,0.15); }

#field-details p { margin: 0; color: var(--muted); }
#history-chart { display: flex; flex-direction: column; gap: 6px; }
.history-row { display: flex; align-items: center; gap: 8px; }
.history-year { width: 46px; color: var(--muted); font-size: 12px; }
.history-bar { flex: 1; display: flex; height: 14px; border-radius: 6px; overflow: hidden; background: #111827; border: 1px solid #0b0f19; }
.history-segment { height: 100%; }

.maplibregl-popup-content {
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  min-width: 384px;
  max-width: 432px;
}
.maplibregl-popup-close-button {
  font-size: 20px;
  color: var(--text);
}
.popup-header { display: flex; align-items: center; gap: 6px; }
.popup-dominant { font-size: 14px; color: var(--muted); margin-top: 4px; }
.popup-history { margin-top: 8px; }
.popup-history-title { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.popup-empty { font-size: 11px; color: var(--muted); }
.popup-history-row { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); line-height: 1.3; }
.popup-history-year { font-weight: 600; color: var(--text); font-size: 13px; }
.popup-history-bar { height: 12px; flex: 1; }
.segment-label { font-size: 11px; color: #fff; margin-left: 4px; white-space: nowrap; display: flex; align-items: center; height: 100%; }
.loading-bar { width: 100%; height: 8px; background: #1f2937; border-radius: 6px; overflow: hidden; border: 1px solid #0b0f19; }
.loading-fill { width: 100%; height: 100%; background: linear-gradient(90deg, #22c55e 0%, #10b981 50%, #22c55e 100%); animation: loading 1s linear infinite; }

@keyframes loading {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@media (max-width: 768px) {
  header { flex-direction: column; align-items: flex-start; gap: 8px; }
  header p { display: none; }
  .main-nav { gap: 0; }
  .nav-link { font-size: 13px; padding: 4px 8px; }
  main { flex-direction: column; }
  #map { height: 55vh; flex: none; }
  #legend-panel {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: 220px;
  }
  #legend { max-height: 220px; overflow-y: auto; }
  #legend.legend-expanded { max-height: 50vh; }
  .maplibregl-popup-content { min-width: 312px; max-width: 360px; }
}
