:root {
  --water: #dff0ff;
  --land: #f4c3bc;
  --coverage-country: #d7ebcf;
  --coverage-detail: #cae8bf;
  --coverage-fallback: #f0d5a1;
  --coverage-override: #9cd58f;
  --ink: #1f2933;
  --ink-soft: #56616d;
  --panel: rgba(255, 249, 245, 0.9);
  --line: rgba(135, 86, 80, 0.14);
  --shadow: 0 18px 48px rgba(78, 37, 30, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  overflow: hidden;
  background: var(--water);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
}

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

.maplibregl-map {
  background: var(--water);
}

.panel {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 2;
  width: min(360px, calc(100vw - 36px));
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-header-copy {
  min-width: 0;
}

.panel-home {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.68rem;
  border: 1px solid rgba(135, 86, 80, 0.18);
  border-radius: 999px;
  color: #614842;
  text-decoration: none;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.panel-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 68px;
  padding: 0.36rem 0.74rem;
  border: 1px solid rgba(135, 86, 80, 0.18);
  border-radius: 999px;
  background: rgba(255, 249, 245, 0.94);
  color: #614842;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.panel-body {
  margin-top: 0.85rem;
}

.panel.is-collapsed .panel-body {
  display: none;
}

.panel h1 {
  margin: 0.9rem 0 0;
  font-size: clamp(1.8rem, 2.5vw, 2.35rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.panel-copy,
.panel-note,
.panel-attribution {
  margin: 0.85rem 0 0;
  color: var(--ink-soft);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.94rem;
  line-height: 1.45;
}

.legend {
  display: grid;
  gap: 0.7rem;
  margin-top: 1.05rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(135, 86, 80, 0.12);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.92rem;
}

.legend-swatch {
  display: inline-block;
  width: 22px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(109, 66, 61, 0.16);
}

.legend-swatch.land {
  background: var(--land);
}

.legend-swatch.coverage-country {
  background: var(--coverage-country);
}

.legend-swatch.coverage-detail {
  background: var(--coverage-detail);
}

.legend-swatch.coverage-fallback {
  background: var(--coverage-fallback);
}

.legend-swatch.coverage-override {
  background: var(--coverage-override);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(223, 240, 255, 0.88);
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

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

.loading-card {
  display: grid;
  justify-items: center;
  gap: 0.9rem;
  padding: 1.2rem 1.4rem;
  border: 1px solid rgba(135, 86, 80, 0.12);
  border-radius: 20px;
  background: rgba(255, 249, 245, 0.94);
  box-shadow: 0 20px 42px rgba(54, 45, 44, 0.12);
}

.loading-card p {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.95rem;
  color: #4b5b68;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(103, 152, 201, 0.2);
  border-top-color: rgba(103, 152, 201, 0.86);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.error-banner {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  max-width: min(420px, calc(100vw - 36px));
  padding: 0.85rem 1rem;
  border: 1px solid rgba(163, 61, 61, 0.12);
  border-radius: 16px;
  background: rgba(255, 245, 245, 0.94);
  box-shadow: 0 16px 38px rgba(99, 52, 52, 0.14);
  color: #883535;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.92rem;
}

.maplibregl-ctrl-top-right {
  top: 18px;
  right: 18px;
}

.maplibregl-ctrl-group {
  background: rgba(255, 249, 245, 0.92);
  border: 1px solid rgba(135, 86, 80, 0.12);
  box-shadow: var(--shadow);
}

.maplibregl-popup-content {
  background: rgba(255, 249, 245, 0.96);
  color: #433331;
  border: 1px solid rgba(135, 86, 80, 0.12);
  box-shadow: 0 18px 40px rgba(54, 45, 44, 0.16);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: rgba(255, 249, 245, 0.96);
}

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

@media (max-width: 720px) {
  .panel {
    top: 14px;
    left: 14px;
    right: 14px;
    width: auto;
    padding: 15px 15px 14px;
  }

  .panel h1 {
    font-size: 1.8rem;
  }

  .panel-toggle {
    display: inline-flex;
  }

  .panel.is-collapsed {
    right: auto;
    width: min(280px, calc(100vw - 28px));
  }

  .panel.is-collapsed .panel-header {
    align-items: center;
  }

  .panel.is-collapsed h1 {
    margin-top: 0.55rem;
    font-size: 1.32rem;
  }

  .maplibregl-ctrl-top-right {
    top: auto;
    right: 14px;
    bottom: 14px;
  }
}
