:root {
  --bg: #f7f8fc;
  --surface: rgba(255, 255, 255, 0.95);
  --text: #16203b;
  --muted: #5f6b85;
  --line: rgba(22, 32, 59, 0.12);
  --accent-a: #7c3aed;
  --accent-b: #0ea5e9;
  --accent-c: #f97316;
  --shadow: 0 24px 60px rgba(17, 24, 39, 0.16);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ---- top brand bar ---- */
.topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.topbar img { height: 30px; width: auto; display: block; }
.topbar .titles { display: flex; flex-direction: column; line-height: 1.1; }
.topbar .titles strong { font-size: 0.95rem; letter-spacing: -0.01em; }
.topbar .titles span { font-size: 0.72rem; color: var(--muted); }
.topbar a.home { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 12px; }

/* ---- language toggle ---- */
.lang {
  display: inline-flex;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-left: 4px;
}
.lang button {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--muted);
}
.lang button.active { background: linear-gradient(135deg, #1d4ed8, #0f766e); color: #fff; }

/* ---- side panel ---- */
.panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.panel h2 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel section { margin-bottom: 18px; }
.panel section:last-child { margin-bottom: 0; }

.dataset {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
}
.dataset label { font-weight: 700; font-size: 0.9rem; }
.dataset small { display: block; color: var(--muted); font-weight: 400; font-size: 0.78rem; }
.dataset input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent-a); }

.control-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 0.82rem; color: var(--muted); }
.control-row input[type="range"] { flex: 1; accent-color: var(--accent-b); }

/* legend */
.legend-bar {
  height: 14px;
  border-radius: 7px;
  margin-top: 8px;
  background: linear-gradient(to right,
    #67001f, #d6604d, #f4a582, #f7f7f7, #92c5de, #4393c3, #053061);
  border: 1px solid var(--line);
}
.legend-scale { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.legend-note { font-size: 0.72rem; color: var(--muted); margin-top: 6px; }

/* tools */
.tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tool-btn:hover { transform: translateY(-1px); }
.tool-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  border-color: transparent;
  box-shadow: 0 10px 20px rgba(124, 58, 237, 0.25);
}
.tool-btn.clear { grid-column: span 2; background: rgba(249, 115, 22, 0.10); border-color: rgba(249, 115, 22, 0.35); color: #b4530f; }

.hint { font-size: 0.78rem; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

/* results */
.results { }
.result-empty { font-size: 0.85rem; color: var(--muted); line-height: 1.55; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0 12px; }
.stat {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}
.stat .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat .v { font-size: 1.05rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .v small { font-size: 0.7rem; font-weight: 600; color: var(--muted); }
.chart-wrap { position: relative; height: 190px; margin-top: 6px; }
.range-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.range-row input[type="number"] { width: 68px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); font: inherit; }
.badge-model {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: #b4530f;
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.3);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}

/* loading + error overlay */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 248, 252, 0.85);
  backdrop-filter: blur(4px);
}
.overlay .box {
  padding: 22px 26px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 380px;
}
.overlay .box.err { border-color: rgba(220, 38, 38, 0.4); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid rgba(124, 58, 237, 0.2);
  border-top-color: var(--accent-a);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* mobile: panel becomes a bottom sheet */
@media (max-width: 720px) {
  .panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 52vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .topbar .titles span { display: none; }
}
