* {
  box-sizing: border-box;
}

:root {
  --ad-h: 90px;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

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

/* ---- compass rose ---- */
#compass {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 74px;
  height: 74px;
  z-index: 1300;
  pointer-events: none;
  filter: drop-shadow(0 2px 7px rgba(0, 0, 0, 0.3));
}

#compass svg {
  width: 100%;
  height: 100%;
}

.cmp-ring-outer {
  fill: rgba(255, 255, 255, 0.93);
  stroke: #9fb0bf;
  stroke-width: 1.5;
}

.cmp-ring-inner {
  fill: none;
  stroke: #d2dbe3;
  stroke-width: 1;
}

.cmp-tick line {
  stroke: #7d8d9c;
  stroke-width: 1.4;
}

.cmp-tick line.major {
  stroke: #4a5a6a;
  stroke-width: 2.2;
}

.cmp-light {
  fill: #eef3f8;
  stroke: #9fb0bf;
  stroke-width: 0.4;
}

.cmp-dark {
  fill: #b9c6d2;
  stroke: #9fb0bf;
  stroke-width: 0.4;
}

.cmp-n-light {
  fill: #ef4d6b;
}

.cmp-n-dark {
  fill: #c01038;
}

.cmp-hub {
  fill: #2b3a4a;
  stroke: #fff;
  stroke-width: 1;
}

.cmp-label {
  font-size: 11px;
  font-weight: 800;
  fill: #2b3a4a;
  text-anchor: middle;
  dominant-baseline: middle;
}

.cmp-label.cmp-north {
  fill: #e6194b;
}

body.dark .cmp-ring-outer {
  fill: rgba(24, 34, 45, 0.94);
  stroke: #3c5168;
}

body.dark .cmp-ring-inner {
  stroke: #2c3a48;
}

body.dark .cmp-light {
  fill: #3a4d60;
  stroke: #2c3a48;
}

body.dark .cmp-dark {
  fill: #243443;
  stroke: #2c3a48;
}

body.dark .cmp-tick line {
  stroke: #6b7d8e;
}

body.dark .cmp-tick line.major {
  stroke: #aebccb;
}

body.dark .cmp-label {
  fill: #d7e1ea;
}

body.dark .cmp-hub {
  fill: #d7e1ea;
  stroke: #11191f;
}

/* ---- AdSense banner slots ---- */
.ad-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 728px;
  max-width: 100%;
  height: 90px;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(241, 243, 245, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border: 1px dashed rgba(120, 135, 150, 0.5);
  overflow: hidden;
}

#ad-top {
  top: 0;
  border-width: 0 0 1px;
}

#ad-bottom {
  bottom: 0;
  border-width: 1px 0 0;
}

/* Pin Leaflet attribution to the far bottom-right corner of the screen. */
.leaflet-bottom.leaflet-right {
  bottom: 0;
  right: 0;
  z-index: 1300;
}

.leaflet-bottom.leaflet-right .leaflet-control-attribution {
  margin: 0;
}

/* Keep the zoom control clear of the bottom ad overlay. */
.leaflet-bottom.leaflet-left {
  bottom: var(--ad-h);
}

.ad-bar .adsbygoogle {
  position: relative;
  z-index: 2;
}

/* Subtle placeholder so the slot is visible before/without a fill. */
.ad-tag {
  position: absolute;
  z-index: 1;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #aab4be;
  pointer-events: none;
}

body.dark .ad-bar {
  background: rgba(17, 25, 31, 0.78);
  border-color: rgba(60, 81, 104, 0.6);
}

body.dark .ad-tag {
  color: #4a5a6a;
}

#panel {
  position: absolute;
  top: calc(var(--ad-h) + 16px);
  left: 16px;
  z-index: 1000;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 18px 18px 16px;
  backdrop-filter: blur(4px);
}

#panel header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #1c2b3a;
}

.tagline {
  margin: 4px 0 14px;
  font-size: 13px;
  color: #5a6b7b;
  line-height: 1.4;
}

.search-wrap {
  position: relative;
}

#search {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1.5px solid #d3dce4;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}

#search:focus {
  border-color: #2f80ed;
}

#suggestions {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  position: absolute;
  width: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1100;
  display: none;
}

#suggestions.open {
  display: block;
}

#suggestions li {
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
  color: #2b3a4a;
}

#suggestions li:hover,
#suggestions li.active {
  background: #eef4fb;
}

#chips {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#chips li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: default;
}

#chips li button {
  border: none;
  background: rgba(255, 255, 255, 0.35);
  color: #fff;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

#chips li button:hover {
  background: rgba(255, 255, 255, 0.6);
}

#areas {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#areas:empty {
  margin: 0;
}

#areas li {
  display: grid;
  grid-template-columns: 1fr;
  align-items: baseline;
  gap: 3px 8px;
  font-size: 13px;
}

.area-head {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.area-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.area-flag {
  font-size: 15px;
  line-height: 1;
  flex: 0 0 auto;
}

.area-flag:empty {
  display: none;
}

.area-pop {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: #7a8b9b;
  font-variant-numeric: tabular-nums;
}

.area-pop:not(:empty)::before {
  content: "👤 ";
  font-size: 9px;
}

body.dark .area-pop {
  color: #8295a7;
}

.area-name {
  font-weight: 600;
  color: #2b3a4a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.area-meta {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  justify-self: start;
  white-space: nowrap;
}

.area-km2 {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #1c2b3a;
}

.area-ratio {
  font-size: 11px;
  color: #7a8b9b;
  font-variant-numeric: tabular-nums;
}

.area-bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 3px;
  opacity: 0.75;
  min-width: 2px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.actions button {
  flex: 1;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid #d3dce4;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: #2b3a4a;
  transition: background 0.15s, border-color 0.15s;
}

.actions button:hover {
  background: #f3f7fb;
  border-color: #b9c6d2;
}

.toggles {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.toggle {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid #d3dce4;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: #2b3a4a;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.toggle:hover {
  background: #f3f7fb;
  border-color: #b9c6d2;
}

.toggle.on {
  background: #2f80ed;
  border-color: #2f80ed;
  color: #fff;
}

.hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: #7a8b9b;
  line-height: 1.45;
}

/* ---- graticule labels ---- */
.grid-label {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  font-size: 10px;
  font-weight: 600;
  color: #5a6b7b;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.85),
    0 0 3px rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  pointer-events: none;
}

.grid-label::before {
  display: none;
}

.grid-label.gmt {
  color: #888888;
  font-weight: 800;
  font-size: 11px;
}

/* ---- country (place) labels ---- */
.place-label {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  color: #4a5a6a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9),
    0 0 4px rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.place-label::before {
  display: none;
}

/* ---- dark theme ---- */
body.dark #map {
  background: #14202b;
}

body.dark #panel {
  background: rgba(24, 34, 45, 0.95);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

body.dark #panel header h1 {
  color: #eef3f8;
}

body.dark .tagline,
body.dark .hint {
  color: #93a4b5;
}

body.dark #search {
  background: #0f1923;
  border-color: #34465a;
  color: #eef3f8;
}

body.dark #suggestions {
  background: #1b2733;
  border-color: #34465a;
}

body.dark #suggestions li {
  color: #d7e1ea;
}

body.dark #suggestions li:hover,
body.dark #suggestions li.active {
  background: #243443;
}

body.dark .actions button,
body.dark .toggle {
  background: #1b2733;
  border-color: #34465a;
  color: #d7e1ea;
}

body.dark .actions button:hover,
body.dark .toggle:hover {
  background: #243443;
  border-color: #46586c;
}

body.dark .toggle.on {
  background: #2f80ed;
  border-color: #2f80ed;
  color: #fff;
}

body.dark .area-name {
  color: #d7e1ea;
}

body.dark .area-km2 {
  color: #eef3f8;
}

body.dark .area-ratio {
  color: #8295a7;
}

body.dark .country-label {
  color: #f3f7fb;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 5px rgba(0, 0, 0, 0.9);
}

body.dark #loading {
  background: rgba(20, 32, 43, 0.9);
  color: #eef3f8;
}

body.dark .grid-label {
  color: #aebccb;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.9);
}

body.dark .grid-label.gmt {
  color: #aaaaaa;
}

body.dark .place-label {
  color: #c2cdd8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 4px rgba(0, 0, 0, 0.9);
}

#loading {
  position: absolute;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(170, 211, 223, 0.85);
  font-size: 18px;
  font-weight: 600;
  color: #1c2b3a;
}

#loading.hidden {
  display: none;
}

/* Country label tooltips floating on the dragged shapes */
.country-label {
  background: transparent;
  border: none;
  box-shadow: none;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9),
    0 0 4px rgba(255, 255, 255, 0.9);
  color: #1c2b3a;
  padding: 0;
}

.country-label::before {
  display: none;
}

.draggable-shape {
  cursor: grab;
}

.draggable-shape.dragging {
  cursor: grabbing;
}

@media (max-width: 520px) {
  :root {
    --ad-h: 90px;
  }
  #panel {
    width: calc(100vw - 24px);
    left: 12px;
    top: calc(var(--ad-h) + 12px);
    padding: 14px;
  }
  #panel header h1 {
    font-size: 19px;
  }
}
