:root {
  --bg: #0f1419;
  --panel: rgba(20, 27, 34, 0.92);
  --panel-solid: #161d24;
  --ink: #e8edf2;
  --muted: #9aa7b2;
  --line: #2a343d;
  --accent: #4C9F70;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: 0.2px; }
#subtitle { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 6px; flex: 0 0 auto; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); background: rgba(76, 159, 112, 0.18); border-color: rgba(76, 159, 112, 0.5); }

/* ---------- views ---------- */
main { position: relative; flex: 1 1 auto; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }

/* ---------- map ---------- */
#map { position: absolute; inset: 0; background: #0b0f13; }

.panel {
  position: absolute;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 600;
  padding: 10px 12px;
}

/* Sized so the group chips pack into a few rows without covering the map;
   max-height keeps it clear of the timeline panel on short viewports. */
#filters {
  top: 12px; left: 12px; width: 232px;
  max-height: calc(100% - 150px);
  display: flex; flex-direction: column;
}
#filters .chips { overflow-y: auto; }
#filters.min .chips,
#filters.min #chips-all,
#filters.min #chips-none { display: none; }
#filters.min { width: auto; }
#filters.min .panel-head { margin-bottom: 0; gap: 12px; }
.min-btn { font-size: 14px; line-height: 1; width: 14px; text-align: center; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.panel-actions { display: flex; gap: 8px; }
.link { background: none; border: none; color: var(--accent); font-size: 11.5px; cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(0,0,0,0.3) inset; }
.chip em { font-style: normal; color: var(--muted); font-size: 11px; opacity: 0.8; }
.chip.active { color: var(--ink); background: color-mix(in srgb, var(--c) 22%, transparent); border-color: color-mix(in srgb, var(--c) 60%, transparent); }
.chip.active em { color: var(--ink); }
.chip:not(.active) .dot { background: #4a555f; }

/* ---------- timeline ---------- */
#timeline { left: 12px; right: 12px; bottom: 12px; max-width: 760px; margin: 0 auto; }
.timeline-row { display: flex; align-items: center; gap: 12px; }
.timeline-row + .timeline-row { margin-top: 8px; }
.play {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: rgba(76, 159, 112, 0.16);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
.play:hover { background: rgba(76, 159, 112, 0.3); }
/* Stacked year / month / day ticker. Fixed width + centered + tabular numerals
   so each field holds its position as the values change during playback. */
.datelabel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 56px;
  line-height: 1.05;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dl-year { font-size: 12.5px; font-weight: 600; letter-spacing: 0.5px; color: var(--ink); }
.dl-month { font-size: 10.5px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.dl-day { font-size: 19px; font-weight: 700; color: var(--accent); }

input[type="range"] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: var(--line); outline: none; cursor: pointer; }
#scrub { flex: 1 1 auto; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 2px solid #0f1419; }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 2px solid #0f1419; border-radius: 50%; background: var(--accent); }

.controls { flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--muted); border: none; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.seg-btn.active { background: rgba(76, 159, 112, 0.22); color: var(--ink); }
.ctl { display: inline-flex; align-items: center; gap: 7px; }
.ctl input[type="range"] { width: 96px; }
.ctl b { color: var(--ink); font-weight: 600; }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.hint {
  position: absolute; left: 12px; bottom: 108px;
  color: var(--muted); font-size: 11.5px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 4px 9px; border-radius: 8px; z-index: 590;
  pointer-events: none; opacity: 0.85;
}

/* ---------- leaflet popup ---------- */
.leaflet-popup-content-wrapper { background: var(--panel-solid); color: var(--ink); border-radius: 10px; }
.leaflet-popup-tip { background: var(--panel-solid); }
.leaflet-popup-content { margin: 0; width: 220px !important; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pop img { width: 100%; height: 130px; object-fit: cover; border-radius: 10px 10px 0 0; display: block; background: #222; }
.pop-body { padding: 8px 11px 11px; }
.pop-name { font-weight: 600; font-size: 13.5px; }
.pop-sci { color: var(--muted); font-size: 12px; font-style: italic; }
.pop-meta { color: var(--muted); font-size: 11px; margin: 5px 0 7px; }
.pop-body a { color: var(--accent); font-size: 12px; text-decoration: none; }
.pop-body a:hover { text-decoration: underline; }

/* ---------- guide / gallery ---------- */
#guide-controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel-solid);
}
#guide-search {
  flex: 1 1 240px; min-width: 180px; max-width: 360px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 7px 11px; font-size: 13px;
}
#guide-sort {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 7px 9px; font-size: 13px;
}
#guide-controls .chips { flex: 1 1 100%; }
#guide-controls .count { flex: 0 0 auto; }

#gallery {
  position: absolute; left: 0; right: 0; bottom: 0;
  top: 0; margin-top: 0;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  align-content: start;
}
/* guide view is a column: controls bar on top, scrolling gallery fills the rest.
   Keep flex-direction off the base display so `.view { display:none }` still hides
   it when the tab is inactive; only `.active` turns it into a flex column. */
#view-guide { flex-direction: column; }
#view-guide.active { display: flex; }
#view-guide #gallery { position: static; flex: 1 1 auto; }

.card {
  display: flex; flex-direction: column;
  background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; text-decoration: none; color: var(--ink);
  transition: transform 0.1s, border-color 0.1s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: #1b2229; display: block; }
.card-body { padding: 9px 11px 11px; position: relative; }
.card .badge { position: absolute; top: -7px; left: 11px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--panel-solid); }
.card .cc { font-size: 13px; font-weight: 600; line-height: 1.25; }
.card .cs { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 1px; }
.card .cn { font-size: 11px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }

.empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px; }

/* ---------- loading / error overlay ---------- */
#fatal {
  position: absolute; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--muted); text-align: center; padding: 24px;
}
#fatal code { color: var(--ink); background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 5px; }

@media (max-width: 620px) {
  #subtitle { display: none; }
  #filters { width: 184px; }
  .datelabel { width: 50px; }
  .dl-day { font-size: 17px; }
}
