/* ===== Theme: light, flat, minimal (inspired by thetruesize.com) ===== */
:root {
  --ocean: #dbe3e7; /* map background */
  --panel: #ffffff;
  --panel-2: #f6f7f7;
  --line: #e3e5e4;
  --line-soft: #eef0ef;

  --text: #20262e;
  --muted: #6b7480;
  --muted-2: #9aa2ad;

  --picked: #c8473f; /* red — selected countries */
  --picked-bg: #f7ebe9;
  --poor: #3f6db0; /* blue/navy — poorest countries */
  --poor-bg: #eaeff6;

  --country: #fbfbf9; /* land — near white */
  --country-hover: #eef2f3;
  --country-border: #b9c3c9;
  --nodata: #c9d0d4; /* land without data */

  --radius: 10px;
  --shadow: 0 10px 30px -12px rgba(20, 30, 45, 0.28);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--ocean);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  overflow: hidden;
}

/* ===== Full-screen map (Leaflet) ===== */
#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  background: var(--ocean);
}
.leaflet-container {
  background: var(--ocean);
  font-family: var(--font);
  cursor: grab;
}
.leaflet-container:active {
  cursor: grabbing;
}
.leaflet-interactive {
  cursor: pointer;
  transition: fill-opacity 0.15s ease;
}
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.7) !important;
  font-size: 10px;
  color: var(--muted-2);
}
.leaflet-control-attribution a {
  color: var(--muted);
}

/* ===== Brand + hint ===== */
.brandbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.01em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  padding: 7px 15px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.stage__hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 6px 13px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
#excludeHint.hint-clear {
  color: var(--picked);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
#excludeHint.hint-clear:hover {
  opacity: 0.8;
}

/* ===== Zoom ===== */
.zoom {
  position: fixed;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  gap: 5px;
}
.zoom button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s;
}
.zoom button:hover {
  background: var(--panel-2);
}
.zoom button.active {
  background: var(--poor);
  border-color: var(--poor);
  color: #fff;
}

/* ===== Floating widgets ===== */
.widget {
  position: fixed;
  z-index: 10;
  width: 330px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#w-select {
  top: 16px;
  left: 16px;
}
#w-total {
  top: 16px;
  right: 16px;
  width: 300px;
}
#w-poor {
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  max-height: 56vh;
}
.widget__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.widget.collapsed .widget__head {
  border-bottom: none;
}
.widget__title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.widget__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.widget__toggle {
  border: none;
  background: none;
  color: var(--muted-2);
  cursor: pointer;
  font-size: 13px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  transition: transform 0.2s, background 0.15s;
}
.widget__toggle:hover {
  background: var(--panel-2);
  color: var(--text);
}
.widget.collapsed .widget__toggle {
  transform: rotate(-90deg);
}
.widget__body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: visible;
}
.widget.collapsed .widget__body {
  display: none;
}
#w-poor .widget__body {
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

/* ===== Segmented control (measure: GDP / PPP) ===== */
.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.seg button {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 7px 3px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover {
  color: var(--text);
}
.seg button.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 30, 45, 0.12);
}
.seg--mode {
  background: #eef1f4;
}
.seg--mode button.active {
  background: var(--poor);
  color: #fff;
}

/* ===== Search ===== */
.search {
  position: relative;
}
#search {
  width: 100%;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.15s;
}
#search::placeholder {
  color: var(--muted-2);
}
#search:focus {
  outline: none;
  border-color: var(--muted);
}
.search__results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 5px;
}
.opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}
.opt:hover {
  background: var(--panel-2);
}
.opt__gdp {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.opt.picked {
  color: var(--picked);
  opacity: 0.7;
}

/* ===== Presets ===== */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s;
}
.preset:hover {
  background: var(--panel-2);
  border-color: var(--muted-2);
}

/* ===== Chips ===== */
.ghost {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  padding: 2px 4px;
}
.ghost:hover {
  color: var(--picked);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 132px;
  overflow-y: auto;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 11px;
  border-radius: 999px;
  background: var(--picked-bg);
  border: 1px solid var(--picked);
  color: var(--picked);
  font-size: 13px;
  font-weight: 500;
}
.chip__gdp {
  opacity: 0.75;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.chip__x {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(200, 71, 63, 0.15);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.chip__x:hover {
  background: var(--picked);
  color: #fff;
}

/* ===== Total / result ===== */
.total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.total strong {
  font-size: 17px;
  font-weight: 700;
  color: var(--picked);
  font-variant-numeric: tabular-nums;
}
.result__headline {
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  color: var(--text);
}
.result__big {
  font-size: 38px;
  font-weight: 700;
  color: var(--poor);
  display: block;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 2px 0;
}
.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--poor-bg);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  background: var(--poor);
  width: 0;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.result__meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.result__meta strong {
  color: var(--poor);
  font-weight: 600;
}
.result__warn {
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
  background: var(--picked-bg);
  border-left: 3px solid var(--picked);
  padding: 9px 11px;
  border-radius: 4px;
  margin: 0;
}

/* ===== Continent filter ===== */
.continents {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.continent {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}
.continent:hover {
  border-color: var(--poor);
}
.continent.active {
  background: var(--poor);
  border-color: var(--poor);
  color: #fff;
}

/* ===== Toggle switch (tiny countries) ===== */
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.switch input {
  appearance: none;
  -webkit-appearance: none;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex: none;
  margin: 0;
}
.switch input:checked {
  background: var(--poor);
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(20, 30, 45, 0.25);
}
.switch input:checked::after {
  transform: translateX(16px);
}
.switch em {
  color: var(--muted-2);
  font-style: normal;
}

/* ===== Poorest list ===== */
.poorlist {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.poorlist li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 13px;
}
.poorlist li:nth-child(odd) {
  background: var(--poor-bg);
}
.poorlist .rank {
  color: var(--muted-2);
  width: 24px;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.poorlist .nm {
  flex: 1;
}
.poorlist .gd {
  color: var(--poor);
  font-variant-numeric: tabular-nums;
}

/* ===== Legend (Google-Maps style: transparent, horizontal) ===== */
.legend {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 7px 13px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
}
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex: none;
}
.swatch--picked {
  background: var(--picked);
}
.swatch--poor {
  background: var(--poor);
}
.swatch--nodata {
  background: var(--nodata);
}

/* ===== Scrollbars ===== */
.chips::-webkit-scrollbar,
.search__results::-webkit-scrollbar,
.poorlist::-webkit-scrollbar {
  width: 8px;
}
.chips::-webkit-scrollbar-thumb,
.search__results::-webkit-scrollbar-thumb,
.poorlist::-webkit-scrollbar-thumb {
  background: #d7dadc;
  border-radius: 8px;
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - 13px));
  white-space: nowrap;
}
.tooltip__name {
  font-weight: 600;
  margin-bottom: 2px;
}
.tooltip__gdp {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tooltip__tag {
  display: inline-block;
  margin-top: 5px;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 500;
}
.tooltip__tag.picked {
  background: var(--picked-bg);
  color: var(--picked);
}
.tooltip__tag.poor {
  background: var(--poor-bg);
  color: var(--poor);
}
.tooltip__tag.excluded {
  background: var(--picked-bg);
  color: var(--picked);
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
  body {
    overflow: auto;
  }
  #map {
    position: relative;
    height: 56vh;
  }
  .brandbar {
    position: absolute;
  }
  .zoom,
  .stage__hint {
    position: absolute;
  }
  .widget {
    position: static !important;
    width: auto;
    max-width: none;
    max-height: none !important;
    margin: 10px;
  }
  #w-poor {
    max-height: none;
  }
  #w-poor .widget__body {
    overflow: visible;
  }
  .poorlist {
    max-height: 50vh;
  }
}
