:root {
  --bg: #0f1115;
  --card: rgba(255, 255, 255, 0.96);
  --ink: #1a1d24;
  --muted: #5b6472;
  --line: rgba(20, 25, 35, 0.10);
  --shadow: 0 6px 28px rgba(8, 12, 20, 0.22);
  --radius: 14px;
  --green: #3fb24f;
  --yellow: #ffd21e;
  --amber: #ff8c1a;
  --red: #e3382b;
  --black: #15181d;
  --nodata: #d7dbe0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
#map { position: absolute; inset: 0; background: #eef1f4; }

.card {
  background: var(--card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

/* ---- Title bar ---- */
#topbar {
  position: absolute; z-index: 3; top: 14px; left: 14px;
  padding: 13px 16px; max-width: 340px;
}
#topbar .brand { display: flex; align-items: center; gap: 11px; }
#topbar .brand .logo { display: block; flex: none; filter: drop-shadow(0 1px 2px rgba(227,56,43,.25)); }
#topbar .brand-txt { display: flex; flex-direction: column; line-height: 1; }
#topbar h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; font-weight: 800; color: var(--ink); }
#topbar .tag { margin-top: 3px; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: var(--red); }
#topbar p { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
#topbar p.sub { margin-top: 8px; font-size: 12.5px; color: var(--ink); font-weight: 600; }
#topbar .info {
  margin-top: 9px; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: #2563eb; cursor: pointer;
  background: none; border: 0; padding: 0;
}
#topbar .info:hover { text-decoration: underline; }

/* ---- Trip search ---- */
#tripForm { display: flex; gap: 6px; margin-top: 10px; }
#tripForm input {
  flex: 1; min-width: 0; font: inherit; font-size: 12.5px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 9px; outline: none; background: #fff; color: var(--ink);
}
#tripForm input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
#tripForm button {
  font: inherit; font-size: 12.5px; font-weight: 700; white-space: nowrap; cursor: pointer;
  border: 0; border-radius: 9px; padding: 7px 12px; background: var(--red); color: #fff;
}
#tripForm button:hover { background: #c72d22; }

/* ---- Trip report panel ---- */
#report { position: absolute; inset: 0; z-index: 9; display: none; align-items: center; justify-content: center;
  background: rgba(10,14,20,.5); }
#report.open { display: flex; }
#report .box { position: relative; max-width: 560px; width: calc(100% - 40px); max-height: 86%;
  overflow: auto; padding: 22px 24px; }
#report .closeR { position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
#report h2 { margin: 0 0 4px; font-size: 20px; }
#report h4 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#report p { font-size: 13.5px; line-height: 1.55; color: #2b313b; margin: 6px 0; }
#report a { color: #2563eb; font-weight: 600; }
#report .rp-place { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
#report .rp-place span { color: var(--ink); font-weight: 600; }
#report .rp-tiles { display: flex; gap: 10px; }
#report .rp-tile { flex: 1; display: flex; align-items: center; gap: 9px; padding: 10px 12px;
  background: #f5f7f9; border-radius: 10px; }
#report .rp-tile .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
#report .rp-tile b { font-size: 13px; display: block; }
#report .rp-tile small { color: var(--muted); font-size: 11.5px; }
#report ul { margin: 6px 0; padding-left: 4px; list-style: none; }
#report .rp-bullets li, #report .sp-list li { position: relative; padding: 4px 0 4px 18px; font-size: 13px; line-height: 1.5; }
#report .rp-bullets li::before { content: "•"; position: absolute; left: 4px; color: var(--red); }
#report .sp-list li { padding-left: 22px; }
#report .sp-list .sd { position: absolute; left: 2px; top: 8px; width: 11px; height: 11px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
#report .kit-list { padding-left: 4px; }
#report .kit-list li { padding: 4px 0 4px 20px; position: relative; font-size: 13px; }
#report .kit-list li::before { content: "🛒"; position: absolute; left: 0; font-size: 11px; }
#report .rep-quotes li { font-size: 12.5px; font-style: italic; color: #444; padding: 5px 0; line-height: 1.45; }
#report .rp-meta { color: var(--muted); font-size: 11.5px; font-style: normal; font-weight: 500; }
#report .rp-foot { margin-top: 16px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
#report .rp-loading { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); padding: 20px 4px; }

/* ---- Metric switcher ---- */
#controls {
  position: absolute; z-index: 3; top: 14px; left: 50%; transform: translateX(-50%);
  padding: 8px 11px; display: flex; align-items: center; gap: 9px;
  flex-wrap: wrap; justify-content: center; max-width: min(94vw, 660px);
}
#controls label { font-size: 12px; font-weight: 600; color: var(--muted); }
#controls select {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px;
  background: #fff; cursor: pointer; outline: none;
}
#controls .chk { display: flex; align-items: center; gap: 5px; font-size: 12.5px;
  font-weight: 600; color: var(--ink); cursor: pointer; }
#controls .jump { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
#controls .jump button { font: inherit; font-size: 11.5px; border: 1px solid var(--line);
  background: #fff; border-radius: 7px; padding: 3px 8px; cursor: pointer; }
#controls .jump button:hover { background: #f2f4f7; }
#controls .seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
#controls .seg button { font: inherit; font-size: 12.5px; font-weight: 600; border: 0;
  background: #fff; color: var(--muted); padding: 6px 11px; cursor: pointer; }
#controls .seg button.on { background: var(--ink); color: #fff; }
#controls .seg button + button { border-left: 1px solid var(--line); }

/* ---- social report popup ---- */
.maplibregl-popup-content { border-radius: 10px; box-shadow: var(--shadow); padding: 11px 13px; }
.pop { font-size: 12.5px; max-width: 260px; }
.pop b { font-size: 13px; }
.pop .sev { font-size: 11px; }
.pop .q { margin: 5px 0; font-style: italic; color: #333; line-height: 1.4; }
.pop .q-local { color: #6b7280; font-size: 11.5px; padding-top: 4px; border-top: 1px dashed var(--line); }
.pop .q-local .lang { font-style: normal; font-weight: 600; font-size: 10px; text-transform: uppercase;
  letter-spacing: .04em; color: #9aa2ad; margin-left: 4px; }
.pop a { color: #2563eb; font-weight: 600; }

/* ---- Legend ---- */
#legend { position: absolute; z-index: 3; left: 14px; bottom: 14px; padding: 12px 14px; }
#legend h2 {
  margin: 0 0 9px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
#legend .row { display: flex; align-items: center; gap: 9px; margin: 5px 0; font-size: 12.5px; }
#legend .sw { width: 15px; height: 15px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
#legend .row small { color: var(--muted); margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
#legend .divider { height: 1px; background: var(--line); margin: 8px 0; }
#legend .social-head { font-weight: 600; }
#legend .social-key { display: flex; align-items: center; gap: 5px; margin-top: 6px; }
#legend .social-key .sdot { width: 13px; height: 13px; border-radius: 50%;
  box-shadow: 0 0 0 1.3px #fff, inset 0 0 0 1px rgba(0,0,0,.12); }
#legend .social-key .social-cap { margin-left: 7px; font-size: 10.5px; color: var(--muted); }

/* ---- Detail panel ---- */
#detail {
  position: absolute; z-index: 4; top: 14px; right: 14px; width: 290px;
  padding: 16px 18px; transform: translateX(calc(100% + 24px));
  transition: transform .26s cubic-bezier(.2,.7,.2,1); max-height: calc(100% - 28px); overflow:auto;
}
#detail.open { transform: translateX(0); }
#detail .close {
  position: absolute; top: 10px; right: 12px; border: 0; background: none;
  font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer;
}
#detail h3 { margin: 0 6px 2px 0; font-size: 17px; }
#detail .country { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
#detail .tierbig {
  display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 14px;
  padding: 9px 11px; border-radius: 10px; background: #f5f7f9; margin-bottom: 12px;
}
#detail .tierbig .dot { width: 14px; height: 14px; border-radius: 50%; }
#detail table { width: 100%; border-collapse: collapse; font-size: 13px; }
#detail td { padding: 5px 0; border-bottom: 1px solid var(--line); }
#detail td.n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
#detail td .sd { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
#detail td .d-adjust { padding: 9px 11px; margin: 2px 0 4px; font-size: 11.5px; line-height: 1.5;
  color: var(--ink); background: rgba(60,178,79,0.12); border: 1px solid rgba(60,178,79,0.35);
  border-radius: 8px; font-weight: 500; }
#detail td:has(.d-adjust) { border-bottom: none; }
#detail .caveat { margin-top: 12px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* ---- Tooltip ---- */
#tooltip {
  position: absolute; z-index: 5; pointer-events: none; display: none;
  background: rgba(20,24,30,0.94); color: #fff; padding: 7px 10px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.35; box-shadow: var(--shadow); max-width: 220px;
}
#tooltip .t-name { font-weight: 700; }
#tooltip .t-tier { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: #d7dde6; }
#tooltip .t-tier .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---- Stats footer ---- */
#stats {
  position: absolute; z-index: 3; right: 14px; bottom: 14px; padding: 7px 11px;
  font-size: 11.5px; color: var(--muted);
}
#stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---- Loading / error ---- */
#loading {
  position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center;
  background: rgba(238,241,244,0.85); font-size: 14px; color: var(--muted); gap: 10px;
}
#loading.hide { display: none; }
.spinner {
  width: 18px; height: 18px; border: 3px solid rgba(0,0,0,.15); border-top-color: var(--red);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Methodology modal ---- */
#modal { position: absolute; inset: 0; z-index: 8; display: none; align-items: center; justify-content: center; background: rgba(10,14,20,.5); }
#modal.open { display: flex; }
#modal .box { max-width: 540px; width: calc(100% - 40px); max-height: 80%; overflow: auto; padding: 24px 26px; }
#modal h2 { margin: 0 0 12px; font-size: 19px; }
#modal h4 { margin: 16px 0 5px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#modal p, #modal li { font-size: 13.5px; line-height: 1.55; color: #2b313b; }
#modal ul { margin: 4px 0; padding-left: 20px; }
#modal .close2 { float: right; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
#modal a { color: #2563eb; }

@media (max-width: 720px) {
  #topbar { max-width: calc(100% - 28px); }
  #controls { top: auto; bottom: 150px; }
  #detail { width: calc(100% - 28px); }
  #stats { display: none; }
}
