:root {
  --bg: #f7f4ee;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #65717f;
  --line: #d9ded7;
  --green: #226b5f;
  --green-dark: #174b43;
  --amber: #c98212;
  --red: #b94b4b;
  --blue: #2e6f9e;
  --shadow: 0 18px 48px -34px rgba(23, 32, 42, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
a {
  font: inherit;
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.site-header h1 {
  margin: 0.1rem 0 0;
  max-width: 860px;
  font-size: clamp(1.35rem, 2.4vw, 2.25rem);
  line-height: 1.08;
  font-weight: 760;
}

.eyebrow {
  margin: 0;
  color: var(--green-dark);
  font-size: 0.73rem;
  font-weight: 760;
  text-transform: uppercase;
}

.source-link,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--green-dark);
  padding: 0.62rem 0.8rem;
  text-decoration: none;
  cursor: pointer;
}

.source-link:hover,
button:hover {
  border-color: var(--green);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(420px, 1fr) minmax(280px, 330px);
  height: calc(100svh - 132px);
  min-height: 620px;
}

.side-panel,
.meta-panel {
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem;
}

.meta-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.side-panel section + section,
.meta-panel section + section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0.7rem;
  font-size: 1rem;
}

h3 {
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.question-list {
  display: grid;
  gap: 0.65rem;
}

.question-card {
  width: 100%;
  display: grid;
  gap: 0.35rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  text-align: left;
}

.question-card[aria-pressed="true"] {
  border-left-color: var(--green);
  background: #eef7f4;
}

.question-card strong {
  font-size: 0.95rem;
}

.question-card span,
.meta-panel p,
.site-footer {
  color: var(--muted);
  font-size: 0.88rem;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.8rem;
}

.rank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

ol {
  margin: 0;
  padding-left: 1.15rem;
}

li {
  margin-bottom: 0.45rem;
  line-height: 1.25;
}

.rank-value {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.map-stage {
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #e8ece6;
}

.legend-card,
.detail-panel {
  position: absolute;
  z-index: 500;
  border: 1px solid rgba(23, 32, 42, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.legend-card {
  left: 1rem;
  bottom: 1rem;
  width: min(330px, calc(100% - 2rem));
  padding: 0.8rem;
}

.legend-title {
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  font-weight: 760;
}

.legend-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 0.45rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.swatch {
  width: 18px;
  height: 12px;
  border: 1px solid rgba(23, 32, 42, 0.18);
}

.detail-panel {
  top: 1rem;
  right: 1rem;
  width: min(320px, calc(100% - 2rem));
  padding: 0.9rem;
}

.detail-panel h2 {
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}

.metric-value {
  margin: 0.5rem 0;
  color: var(--green-dark);
  font-size: 1.85rem;
  font-weight: 800;
}

dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.7rem;
  margin: 0;
  font-size: 0.88rem;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
}

.unmatched-list {
  max-height: 260px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.leaflet-container {
  font: inherit;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 310px 1fr;
    grid-template-rows: minmax(540px, 1fr) auto;
    height: auto;
  }

  .map-stage {
    min-height: 620px;
  }

  .meta-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .site-header,
  .site-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    display: block;
    min-height: 0;
  }

  .side-panel,
  .meta-panel {
    border: 0;
  }

  .map-stage {
    height: 72svh;
    min-height: 520px;
  }

  .detail-panel {
    top: 0.75rem;
    right: 0.75rem;
    width: calc(100% - 1.5rem);
  }

  .legend-card {
    left: 0.75rem;
    bottom: 0.75rem;
    width: calc(100% - 1.5rem);
  }
}
