:root {
  --bg: #f5f4ee;
  --card: rgba(255, 255, 255, 0.94);
  --ink: #13231c;
  --muted: #4b5f54;
  --line: rgba(19, 35, 28, 0.17);
  --brand: #0d8f6f;
  --brand-2: #f16f3d;
  --brand-3: #f0c45d;
  --ok: #1f8f4b;
  --warn: #b55f16;
  --bad: #8f1f1f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(circle at 0% 0%, #fff9ee 0%, rgba(255, 244, 221, 0.55) 34%, transparent 70%),
    radial-gradient(circle at 95% 0%, rgba(199, 245, 229, 0.7) 0%, transparent 45%),
    var(--bg);
  color: var(--ink);
  font-family: 'Source Sans 3', sans-serif;
}

body {
  min-height: 100vh;
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 700;
}

h1,
h2,
h3,
h4,
summary {
  font-family: 'Space Grotesk', sans-serif;
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 1.8vw, 2rem);
}

.subhead {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.load-chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.86rem;
  color: var(--muted);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 0.75rem;
  align-items: start;
}

.left-stack {
  display: grid;
  gap: 0.7rem;
  align-content: start;
}

.map-card,
.panel-card,
.guide-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(19, 35, 28, 0.09);
}

.map-card {
  position: relative;
  overflow: hidden;
}

.map-head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.map-head h2 {
  font-size: 1rem;
}

.map-head p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-shell {
  width: 170px;
  height: 8px;
  border-radius: 999px;
  background: #dfe7e2;
  overflow: hidden;
  flex-shrink: 0;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width 300ms ease;
}

#map {
  height: min(62vh, 640px);
  filter: saturate(1.08) contrast(1.02);
}

.panel-card {
  padding: 0.78rem;
  display: grid;
  gap: 0.72rem;
  max-height: calc(100vh - 7rem);
  overflow: auto;
}

.panel-card section {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: linear-gradient(160deg, #ffffff, #f8fbf9);
}

.panel-card section h3 {
  font-size: 0.95rem;
  margin-bottom: 0.45rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.grid-2 label {
  display: grid;
  gap: 0.28rem;
  font-size: 0.83rem;
  color: var(--muted);
}

.grid-2 .span-2 {
  grid-column: 1 / -1;
}

select,
input,
button {
  font: inherit;
}

select,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 0.45rem 0.5rem;
}

.toggle-row {
  margin-top: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

button {
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #fcfffc, #f2f7f3);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
}

button:hover {
  border-color: #8ea198;
}

#selectedTitle {
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

#selectedMeta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.metric-grid {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem;
  background: #f5faf7;
}

.metric .label {
  font-size: 0.72rem;
  color: var(--muted);
}

.metric .value {
  font-size: 0.96rem;
  font-weight: 700;
  margin-top: 0.12rem;
}

.chart {
  width: 100%;
  height: 205px;
}

.snapshot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: stretch;
}

.snapshot-card {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.45rem;
  background: linear-gradient(150deg, #ffffff, #f4f9f6);
  min-height: 74px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.snapshot-card .label {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
}

.snapshot-card .value {
  margin-top: 0.18rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
}

.map-legend {
  position: absolute;
  left: 0.85rem;
  bottom: 0.9rem;
  width: min(360px, calc(100% - 1.7rem));
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(17, 33, 27, 0.16);
  padding: 0.62rem 0.72rem;
  z-index: 3;
}

.map-legend h3 {
  margin: 0;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #2f4a3f;
}

.map-legend p {
  margin: 0.28rem 0 0;
  color: var(--muted);
  font-size: 0.81rem;
  line-height: 1.35;
}

.legend-ramp {
  margin-top: 0.48rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.52rem;
  align-items: center;
}

.legend-ramp span {
  font-size: 0.74rem;
  color: #335244;
  font-weight: 600;
}

.legend-gradient {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e25f35, #f0c45d, #0a9170);
  border: 1px solid rgba(9, 43, 34, 0.22);
}

.legend-notes {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.24rem;
}

.legend-notes span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #395a4b;
  font-size: 0.75rem;
}

.dot-symbol,
.poly-symbol,
.selected-symbol {
  display: inline-block;
  width: 0.82rem;
  height: 0.82rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.dot-symbol {
  background: #0a9170;
  border: 1px solid #0d271e;
}

.poly-symbol {
  border-radius: 3px;
  background: rgba(10, 145, 112, 0.42);
  border: 1px solid #34584a;
}

.selected-symbol {
  background: #ffffff;
  border: 2px solid #0d271e;
}

.guide-card {
  margin-top: 0;
  padding: 0.3rem 0.72rem;
}

.guide-card details {
  border-bottom: 1px solid var(--line);
  padding: 0.36rem 0;
}

.guide-card details:last-child {
  border-bottom: none;
}

.guide-card summary {
  cursor: pointer;
  font-size: 0.95rem;
}

.guide-card ul {
  margin: 0.45rem 0 0;
  padding-left: 1.15rem;
  color: var(--muted);
}

.guide-card li {
  margin-bottom: 0.3rem;
}

.maplibregl-popup-content {
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}

.map-pop {
  font-size: 0.83rem;
}

.map-pop strong {
  display: block;
  margin-bottom: 0.2rem;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel-card {
    max-height: none;
  }

  #map {
    height: 58vh;
  }

  .map-legend {
    width: min(430px, calc(100% - 1.7rem));
  }
}

@media (max-width: 640px) {
  body {
    padding: 0.65rem;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .load-chip {
    width: 100%;
    text-align: center;
  }

  .map-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .progress-shell {
    width: 100%;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-2 .span-2 {
    grid-column: auto;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .toggle-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .snapshot-grid {
    grid-template-columns: 1fr;
  }

  .map-legend {
    position: static;
    width: auto;
    margin: 0.65rem;
  }
}
