/* Earth — full-bleed map with a floating layer panel. */

:root {
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-fg: #2a2a2a;
  --panel-muted: #666;
  --panel-border: rgba(0, 0, 0, 0.08);
  --panel-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
  --accent: #2f6fdb;
  --track: rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --panel-bg: rgba(24, 24, 26, 0.92);
    --panel-fg: #e8e8e8;
    --panel-muted: #9a9a9a;
    --panel-border: rgba(255, 255, 255, 0.1);
    --panel-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --accent: #6ea4f2;
    --track: rgba(255, 255, 255, 0.12);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0b0f14;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--panel-fg);
}

#map {
  position: fixed;
  inset: 0;
}

/* MapLibre's own zoom control, kept clear of the panel */
.maplibregl-ctrl-bottom-right { margin: 0 0.6rem 0.6rem 0; }

.panel {
  position: fixed;
  top: 3.1rem;
  right: 0.6rem;
  width: 280px;
  max-width: calc(100vw - 1.2rem);
  max-height: calc(100vh - 3.8rem);
  overflow-y: auto;
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: saturate(1.3) blur(10px);
  -webkit-backdrop-filter: saturate(1.3) blur(10px);
  z-index: 500;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem 0.3rem;
}
.panel-head h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
.panel-collapse {
  border: none;
  background: transparent;
  color: var(--panel-muted);
  font-size: 1rem;
  line-height: 1;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  cursor: pointer;
}
.panel-collapse:hover { background: var(--track); color: var(--panel-fg); }

.panel-body { padding: 0 0.9rem 0.9rem; }
.panel.is-collapsed .panel-body { display: none; }

.sub { color: var(--panel-muted); margin: 0.1rem 0 0.8rem; font-size: 0.82rem; }

.block { margin-bottom: 0.9rem; }
.row-head h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--panel-muted);
  margin: 0 0 0.4rem;
  font-weight: 600;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--panel-fg);
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--panel-border); }
.seg-btn.is-active { background: var(--accent); color: #fff; }

.seg-small { margin-top: 0.4rem; }
.seg-small .seg-btn { padding: 0.2rem 0.5rem; font-size: 0.72rem; }

.hover-toggle-row { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.82rem; cursor: pointer; }
.hover-toggle-row input { margin-top: 0.15rem; accent-color: var(--accent); flex: none; }

.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.layer-row { display: flex; align-items: flex-start; gap: 0.5rem; }
.layer-row input[type="checkbox"] { margin-top: 0.2rem; accent-color: var(--accent); }
.layer-row.is-planned { opacity: 0.6; }
.layer-row:has(input:disabled:not(:checked)) { opacity: 0.45; }
.layer-main { display: flex; flex-direction: column; }
.layer-label-row { display: flex; align-items: center; gap: 0.4rem; }
.layer-label { font-size: 0.86rem; }
.layer-note { font-size: 0.74rem; color: var(--panel-muted); margin-top: 0.1rem; }
.layer-badge {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--panel-muted);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
}

.coord .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.86rem; margin: 0; }

.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; }
.legend-list li { display: flex; align-items: center; }
.legend-count { margin-left: auto; color: var(--panel-muted); font-variant-numeric: tabular-nums; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.5rem; flex: none; }
.swatch-member { background: #2f6fdb; }
.swatch-observer { background: #caa23c; }
.swatch-other { background: #8a8a8a; }

/* Legend block — one compact row per active data layer, stacked tightly
   ("one over the other") rather than scattered as separate panel blocks. */
.legend-row { padding: 0.45rem 0; }
.legend-row + .legend-row { border-top: 1px solid var(--panel-border); }
.legend-row-head { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--panel-muted); margin-bottom: 0.35rem; }

.area-gradient, .pop-gradient, .density-gradient {
  height: 10px;
  border-radius: 5px;
  margin-bottom: 0.3rem;
}
.area-gradient { background: linear-gradient(to right, #f7fcf5, #c7e9c0, #74c476, #238b45, #00441b); }
.pop-gradient { background: linear-gradient(to right, #f2f0f7, #cbc9e2, #9e9ac8, #6a51a3, #3f007d); }
.density-gradient { background: linear-gradient(to right, #ffffe5, #fed98e, #fe9929, #d95f0e, #993404); }

.legend-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--panel-muted);
  margin-bottom: 0.4rem;
}
.legend-stat { font-size: 0.8rem; margin: 0.15rem 0; }
.legend-stat span { color: var(--panel-muted); }

.country-detail {
  margin-top: 0.3rem;
}
.country-name { font-size: 0.98rem; font-weight: 600; margin: 0; }
.country-sub { font-size: 0.78rem; color: var(--panel-muted); margin: 0.1rem 0 0.5rem; }
.country-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.6rem; font-size: 0.8rem; margin: 0.28rem 0; }
.country-row .k { color: var(--panel-muted); flex: none; }
.country-row .swatch { margin-right: 0.4rem; }
/* Some fields (Neighbors, Languages) run long — e.g. Russia borders 14
   countries — so the value needs to wrap instead of overflowing the
   panel. min-width: 0 is required for a flex item to actually shrink/wrap
   rather than hold its unwrapped content width. */
.country-row > span:last-child { text-align: right; overflow-wrap: break-word; min-width: 0; }

/* Detail card — one row-group per active layer, stacked directly below
   each other under the same country name, with a thin divider between
   groups (but not above the first one). */
.detail-group + .detail-group { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px solid var(--panel-border); }

.credit {
  font-size: 0.68rem;
  color: var(--panel-muted);
  border-top: 1px solid var(--panel-border);
  padding-top: 0.6rem;
  margin: 0.4rem 0 0;
}
.credit a { color: inherit; }

.layer-table-btn {
  align-self: flex-start;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--panel-fg);
  border-radius: 6px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
}
.layer-table-btn:hover { background: var(--track); }

.table-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}
.table-overlay[hidden] { display: none; }
.table-card {
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: saturate(1.3) blur(10px);
  -webkit-backdrop-filter: saturate(1.3) blur(10px);
  width: min(880px, 100%);
  max-height: min(78vh, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.table-card-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--panel-border);
  flex: none;
}
.table-card-head h2 { font-size: 1rem; margin: 0; font-weight: 600; flex: none; }
.table-filter {
  flex: 1;
  min-width: 0;
  background: var(--track);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--panel-fg);
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}
.table-close {
  border: none;
  background: transparent;
  color: var(--panel-muted);
  font-size: 1.3rem;
  line-height: 1;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 6px;
  cursor: pointer;
  flex: none;
}
.table-close:hover { background: var(--track); color: var(--panel-fg); }

.table-scroll { overflow: auto; }
#dataTable { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
#dataTable th, #dataTable td { padding: 0.4rem 0.7rem; text-align: left; white-space: nowrap; }
#dataTable th {
  position: sticky;
  top: 0;
  background: var(--panel-bg);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--panel-muted);
}
#dataTable th:hover { color: var(--panel-fg); }
#dataTable th.is-sorted { color: var(--accent); }
#dataTable td.num, #dataTable th.num { text-align: right; font-variant-numeric: tabular-nums; }
#dataTable tbody tr:hover { background: var(--track); cursor: pointer; }
#dataTable tbody tr:nth-child(even) { background: rgba(127, 127, 127, 0.06); }

.table-foot {
  font-size: 0.72rem;
  color: var(--panel-muted);
  padding: 0.5rem 1rem;
  margin: 0;
  border-top: 1px solid var(--panel-border);
  flex: none;
}

.hover-tooltip {
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: saturate(1.3) blur(10px);
  -webkit-backdrop-filter: saturate(1.3) blur(10px);
  padding: 0.6rem 0.8rem;
  width: 240px;
  font-size: 0.8rem;
}
.hover-tooltip .country-name { font-size: 0.9rem; }
.hover-tooltip .country-row { font-size: 0.76rem; margin: 0.22rem 0; }

@media (max-width: 600px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 48vh;
    border-radius: 12px 12px 0 0;
  }

  .table-overlay { padding: 0; }
  .table-card { width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
  .table-card-head { padding-top: 2.6rem; flex-wrap: wrap; }
}
