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

html, body {
  height: 100%;
  overflow: hidden;
  background: #05070f;
  color: #cfd6e4;
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#map.dragging { cursor: grabbing; }
#map.pointing { cursor: pointer; }

.hidden { display: none !important; }

/* ---- error banner ---- */
#banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(120, 30, 40, 0.92);
  color: #ffd9dd;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 30;
  max-width: 80%;
}

/* ---- search ---- */
#search {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 240px;
  z-index: 20;
}
#search-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(13, 18, 32, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  color: #e4e9f2;
  font-size: 13px;
  outline: none;
  backdrop-filter: blur(8px);
}
#search-input::placeholder { color: rgba(207, 214, 228, 0.38); }
#search-input:focus { border-color: rgba(120, 160, 255, 0.45); }
#search-results {
  list-style: none;
  margin-top: 6px;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  overflow: hidden;
  backdrop-filter: blur(8px);
}
#search-results li {
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
#search-results li:hover, #search-results li.active { background: rgba(120, 160, 255, 0.14); }
#search-results .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: none;
}
#search-results .cat {
  margin-left: auto;
  color: rgba(207, 214, 228, 0.45);
  font-size: 11px;
}

/* ---- tooltip ---- */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  z-index: 25;
  max-width: 240px;
  backdrop-filter: blur(8px);
}
#tooltip .tt-name { font-weight: 600; font-size: 13px; color: #eef2f8; }
#tooltip .tt-line { color: rgba(207, 214, 228, 0.72); margin-top: 2px; }
#tooltip .tt-note {
  color: rgba(207, 214, 228, 0.48);
  font-style: italic;
  font-size: 11px;
  line-height: 1.35;
  margin-top: 5px;
}

/* ---- detail card ---- */
#card {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 264px;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 14px 12px 10px;
  z-index: 25;
  backdrop-filter: blur(8px);
}
#card-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: rgba(207, 214, 228, 0.5);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
#card-close:hover { color: #fff; }
#card-name { font-size: 15px; font-weight: 600; color: #eef2f8; }
#card-meta { font-size: 12px; color: rgba(207, 214, 228, 0.65); margin: 3px 0 4px; }
#card-note {
  font-size: 11px;
  font-style: italic;
  color: rgba(207, 214, 228, 0.48);
  line-height: 1.35;
  margin: 0 0 6px;
}
#card-growth {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(207, 214, 228, 0.55);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
#card-growth .pos { color: rgba(126, 196, 152, 0.9); }
#card-growth .neg { color: rgba(214, 138, 138, 0.9); }
#spark { display: block; width: 240px; height: 64px; }
#card-range {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(207, 214, 228, 0.4);
  margin-top: 2px;
}

/* ---- year display ---- */
#year-display {
  position: absolute;
  right: 24px;
  bottom: 58px;
  font-size: 64px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(230, 238, 255, 0.16);
  z-index: 10;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* ---- time bar ---- */
#timebar {
  position: absolute;
  right: 24px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(13, 18, 32, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  padding: 5px 14px 5px 5px;
  z-index: 20;
  backdrop-filter: blur(8px);
}
#play {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(120, 160, 255, 0.16);
  color: #dce6ff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
#play:hover { background: rgba(120, 160, 255, 0.28); }
#year-slider {
  -webkit-appearance: none;
  appearance: none;
  width: min(200px, 34vw);
  height: 3px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  outline: none;
}
#year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #c9d8ff;
  cursor: pointer;
  border: none;
}
#year-slider::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #c9d8ff;
  cursor: pointer;
  border: none;
}

/* ---- control dock (bottom left: about, legend, panel) ---- */
#dock {
  position: absolute;
  left: 16px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  z-index: 22;
  max-height: calc(100vh - 36px);
}

#panel, #legend {
  width: 254px;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(8px);
}

#panel { padding: 4px 11px 9px; }
#panel .pg { padding-top: 7px; }
#panel .pg + .pg { border-top: 1px solid rgba(255, 255, 255, 0.07); margin-top: 7px; }
#panel .pg-h {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(207, 214, 228, 0.4);
  margin-bottom: 4px;
}
#panel .opt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 7px;
  padding: 2px 0;
  font-size: 12px;
  color: rgba(207, 214, 228, 0.78);
  cursor: pointer;
  line-height: 1.3;
}
#panel .opt:hover { color: #e8eef8; }
#panel .opt input {
  appearance: none;
  -webkit-appearance: none;
  width: 11px; height: 11px;
  flex: none;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  cursor: pointer;
}
#panel .opt input[type="radio"] { border-radius: 50%; }
#panel .opt input[type="checkbox"] { border-radius: 3px; }
#panel .opt input:checked {
  background: #86aaff;
  border-color: #86aaff;
  box-shadow: 0 0 7px rgba(134, 170, 255, 0.6);
}
#panel .opt .nm { flex: 1 1 auto; white-space: nowrap; }
#panel .opt i { font-style: normal; color: rgba(207, 214, 228, 0.4); }
#panel .kb {
  flex: none;
  font-size: 9px;
  font-weight: 600;
  color: rgba(207, 214, 228, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  padding: 0 4px;
  line-height: 14px;
}
#panel .opt.off { color: rgba(207, 214, 228, 0.3); cursor: default; }
#panel .opt.off input { cursor: default; opacity: 0.4; }
#panel .opt.off .kb { opacity: 0.4; }
#panel .na {
  flex-basis: 100%;
  font-style: italic;
  font-size: 10px;
  color: rgba(207, 214, 228, 0.3);
  padding-left: 18px;
  margin-top: -2px;
}
/* ---- dynamic legend ---- */
#legend { padding: 8px 11px 9px; overflow-y: auto; }
#legend .lg-b + .lg-b { margin-top: 8px; padding-top: 7px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
#legend .lg-h { display: flex; align-items: baseline; gap: 6px; margin-bottom: 3px; }
#legend .lg-t { font-size: 11px; font-weight: 600; color: rgba(232, 238, 250, 0.85); }
#legend .lg-g {
  margin-left: auto;
  flex: none;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: rgba(207, 214, 228, 0.38);
}
#legend .lg-r {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  line-height: 1.35;
  color: rgba(207, 214, 228, 0.62);
  padding: 1px 0 1px 2px;
}
#legend .lg-r .sw { width: 8px; height: 8px; border-radius: 50%; flex: none; }
#legend .lg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
#legend .lg-grid .lg-r { font-size: 10.5px; }

/* ---- layer cards ---- */
.ov-card {
  position: absolute;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  z-index: 24;
  backdrop-filter: blur(8px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 300ms ease, transform 300ms ease;
}
.ov-card.show { opacity: 1; transform: translateY(0); }

#ov-radar {
  top: 16px;
  right: 16px;
  width: 400px;
  padding: 13px 14px 11px;
}
#ov-radar .ov-title { font-size: 13px; font-weight: 600; line-height: 1.3; color: #eef2f8; }
#ov-radar .ov-legend {
  display: flex;
  gap: 16px;
  margin: 7px 0 3px;
  font-size: 11px;
  color: rgba(207, 214, 228, 0.7);
}
#ov-radar .ov-legend .sw {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
#ov-radar canvas { display: block; width: 372px; height: 186px; }
#ov-radar .ov-foot {
  font-size: 10px;
  line-height: 1.45;
  color: rgba(207, 214, 228, 0.42);
  margin-top: 8px;
}

/* the radar card owns the top-right corner while it is up; the detail card drops below it */
body.has-radar #card { top: 318px; }

/* ---- legend & methodology ---- */
#about-btn {
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 8px 13px;
  color: rgba(207, 214, 228, 0.7);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
#about-btn:hover { color: #e4e9f2; border-color: rgba(120, 160, 255, 0.35); }
#about {
  position: absolute;
  left: 16px;
  bottom: 18px;
  width: min(420px, calc(100vw - 32px));
  max-height: min(72vh, 640px);
  overflow-y: auto;
  background: rgba(13, 18, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 14px 14px 12px;
  z-index: 26;
  backdrop-filter: blur(8px);
}
#about-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: rgba(207, 214, 228, 0.5);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
#about-close:hover { color: #fff; }
#about-title { font-size: 15px; font-weight: 600; color: #eef2f8; margin-bottom: 10px; }
#about h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(207, 214, 228, 0.45);
  margin: 13px 0 6px;
}
#about p { font-size: 12px; line-height: 1.5; color: rgba(207, 214, 228, 0.68); margin-bottom: 5px; }
#about p b { color: rgba(232, 238, 250, 0.86); font-weight: 600; }
#about-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 12px;
}
#about-legend .li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(207, 214, 228, 0.75);
}
#about-legend .sw {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: none;
}
