:root {
  --font-ui: "Futura PT", "Futura-PT", "Futura", "Avenir Next", "Segoe UI", Arial, sans-serif;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-ui);
}

body {
  position: relative;
}

.mapboxgl-ctrl,
.mapboxgl-popup-content,
.mapboxgl-ctrl button {
  font-family: var(--font-ui);
}

.mapboxgl-ctrl-bottom-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.mapboxgl-ctrl-bottom-right .mapboxgl-ctrl {
  float: none;
}

.mapboxgl-ctrl-bottom-right .mapboxgl-ctrl.mapboxgl-ctrl-attrib {
  order: 2;
  margin: 0;
}

.mapboxgl-ctrl-bottom-right .mapboxgl-ctrl:not(.mapboxgl-ctrl-attrib) {
  order: 1;
}

#map {
  width: 100%;
  height: 100%;
}

#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 248, 250, 0.9);
  backdrop-filter: blur(2px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

#loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#loading-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
  color: #111111;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(15, 23, 42, 0.2);
  border-top-color: #0f172a;
  border-radius: 50%;
  animation: loading-spin 800ms linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

#page-title {
  position: absolute;
  top: 56px;
  left: 56px;
  z-index: 2;
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  color: #111111;
  background: rgba(255, 255, 255, 0.86);
  font-family: var(--font-ui);
  font-size: clamp(22px, 2.4vw, 32px);
  font-weight: 700;
  line-height: 1.1;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  max-width: min(900px, calc(100vw - 220px));
}

#logo-link {
  position: absolute;
  top: 56px;
  right: 56px;
  z-index: 2;
  width: clamp(110px, 13vw, 140px);
  display: block;
}

#logo-overlay {
  display: block;
  width: 100%;
  height: auto;
}

#legend-box {
  position: absolute;
  left: 56px;
  bottom: 56px;
  z-index: 2;
  width: min(320px, calc(100vw - 124px));
  min-height: 126px;
  padding: 14px 16px 12px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.14);
  color: #111111;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#legend-toggle {
  display: none;
}

#legend-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#legend-box h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

#legend-items {
  flex: 1;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed rgba(15, 23, 42, 0.2);
  background: rgba(248, 250, 252, 0.8);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 1.3;
  color: #0f172a;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-swatch-point {
  background: #ef4444;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.3);
}

.legend-swatch-town {
  background: #6ca6c1;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25);
}

.legend-swatch-county-endorsement {
  width: 14px;
  height: 12px;
  background: #192857;
  border: 1px solid #0f1a3c;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(25, 40, 87, 0.15);
}

.legend-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: #475569;
}

.mapboxgl-popup-content {
  min-width: 240px;
  padding: 14px 16px 12px;
  border-radius: 12px;
  border: 1px solid rgba(25, 40, 87, 0.28);
  border-top: 4px solid #192857;
  background: #f8f9ff;
  box-shadow: 0 14px 26px rgba(25, 40, 87, 0.24);
}

.mapboxgl-popup-close-button {
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(25, 40, 87, 0.35);
  border-radius: 999px;
  background: #192857;
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.mapboxgl-popup-close-button:hover {
  background: #9e353c;
  border-color: #9e353c;
  transform: scale(1.06);
}

.mapboxgl-popup-close-button:focus-visible {
  outline: 2px solid #9e353c;
  outline-offset: 2px;
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip {
  border-top-color: #f8f9ff;
}

.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip {
  border-top-color: #f8f9ff;
}

.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
  border-top-color: #f8f9ff;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
  border-bottom-color: #f8f9ff;
}

.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip {
  border-bottom-color: #f8f9ff;
}

.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
  border-bottom-color: #f8f9ff;
}

.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
  border-left-color: #f8f9ff;
}

.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
  border-right-color: #f8f9ff;
}

.point-popup {
  font-family: var(--font-ui);
  color: #192857;
  font-size: 14px;
  line-height: 1.45;
}

.point-popup h3 {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: #192857;
  padding-right: 30px;
}

.point-popup-row {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.4;
  color: #1f2f63;
}

.point-popup-key {
  font-weight: 700;
  color: #9e353c;
}

.point-popup-empty {
  margin: 0;
  font-size: 13px;
  color: #4f5f93;
}

#legend-source {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: #334155;
}

#legend-source a {
  color: #0f172a;
  font-weight: 600;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

#legend-source a:hover {
  opacity: 0.75;
}

@media (max-width: 520px) {
  #page-title {
    display: none;
  }

  #logo-link {
    right: auto;
    left: 50%;
    top: 12px;
    transform: translateX(-50%);
  }

  #legend-box {
    left: 12px;
    right: auto;
    bottom: 12px;
    width: auto;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    gap: 0;
  }

  #legend-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 7px 12px;
    border: 1px solid rgba(25, 40, 87, 0.3);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.2);
    color: #192857;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
  }

  #legend-toggle:focus-visible {
    outline: 2px solid #192857;
    outline-offset: 2px;
  }

  #legend-content {
    margin-top: 8px;
    width: min(300px, calc(100vw - 24px));
    min-height: 96px;
    padding: 12px 14px 10px;
    border-radius: 10px;
    border: 1px solid rgba(15, 23, 42, 0.16);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.14);
  }

  #legend-box.is-collapsed #legend-content {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #loading-overlay {
    transition: none;
  }

  #loading-spinner {
    animation: none;
  }
}
