
:root {
  --paper: #f7f5ef;
  --paper-shadow: rgba(38, 34, 30, 0.12);
  --ink: #44403a;
  --muted-ink: #6f6a63;
  --line-blue: rgba(100, 145, 200, 0.12);
  --panel-bg: rgba(249, 246, 239, 0.93);
  --panel-border: rgba(74, 69, 61, 0.22);
  --accent-purple: #5c4867;
  --accent-green: #617a5b;
  --light-gray: #d9d6cf;
  --missing-gray: #e4e2de;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(0,0,0,0.03), transparent 25%),
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.75) 0px,
      rgba(255,255,255,0.75) 25px,
      var(--line-blue) 26px,
      rgba(255,255,255,0.65) 27px
    ),
    var(--paper);
  color: var(--ink);
}

body {
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.35rem 0.75rem 1.35rem;
  border-bottom: 1px solid rgba(60, 55, 48, 0.12);
  background: linear-gradient(to bottom, rgba(250,248,243,0.96), rgba(247,245,239,0.88));
  backdrop-filter: blur(4px);
}

.app-header h1 {
  margin: 0;
  font-family: "Caveat", cursive;
  font-size: clamp(1.65rem, 2.8vw, 2.55rem);
  font-weight: 700;
  color: #4a4346;
  letter-spacing: 0.01em;
}

.icon-button {
  border: 1px solid rgba(73, 67, 61, 0.22);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.78);
  color: #534b47;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

.map-wrap, #map {
  width: 100%;
  height: 100%;
  display: block;
}

.loading-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 12;
  background: rgba(247, 245, 239, 0.9);
  color: #5d5550;
  letter-spacing: 0.01em;
}

.loading-state.hidden {
  display: none;
}

.control-panel {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  width: min(26rem, calc(100vw - 2rem));
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 12px 28px var(--paper-shadow);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.panel-toggle {
  width: 100%;
  border: 0;
  background: rgba(83, 76, 72, 0.08);
  color: #47413c;
  padding: 0.8rem 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  cursor: pointer;
  text-align: left;
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600;
}

.panel-toggle-hint {
  font-size: 0.77rem;
  color: var(--muted-ink);
  font-weight: 400;
}

.panel-body {
  padding: 0.95rem;
  display: grid;
  gap: 0.9rem;
}

.control-panel:not(.open) .panel-body {
  display: none;
}

.control-group {
  display: grid;
  gap: 0.35rem;
}

.control-group label,
.legend-title {
  font-family: "Special Elite", "Courier New", monospace;
  font-size: 0.9rem;
  color: #524a46;
}

select, input[type="range"] {
  width: 100%;
}

select {
  appearance: none;
  padding: 0.62rem 0.72rem;
  border-radius: 8px;
  border: 1px solid rgba(74,69,61,0.18);
  background: rgba(255,255,255,0.82);
  color: #3f3935;
  font-size: 0.96rem;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

output {
  font-family: "Special Elite", "Courier New", monospace;
  color: #5b544d;
}

input[type="range"] {
  accent-color: var(--accent-purple);
}

.legend-block {
  display: grid;
  gap: 0.45rem;
  padding-top: 0.15rem;
}

#legend {
  display: grid;
  gap: 0.35rem;
}

.legend-row {
  display: grid;
  grid-template-columns: 1.4rem 1fr;
  gap: 0.5rem;
  align-items: center;
  font-family: "Special Elite", "Courier New", monospace;
  font-size: 0.82rem;
  color: #4d4741;
}

.legend-swatch {
  width: 1.25rem;
  height: 0.95rem;
  border-radius: 3px;
  border: 1px solid rgba(50,50,50,0.08);
}

.panel-footnote {
  color: #6a635d;
  font-size: 0.8rem;
  line-height: 1.3;
}

.popup {
  position: absolute;
  z-index: 40;
  min-width: 17rem;
  max-width: 22rem;
  padding: 0.7rem 0.8rem;
  background: rgba(255,255,255,0.96);
  border-radius: 8px;
  border: 1px solid rgba(72,65,58,0.14);
  box-shadow: 0 14px 28px rgba(0,0,0,0.14);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  font-family: "Special Elite", "Courier New", monospace;
  color: #403a36;
}

.popup.hidden {
  display: none;
}

.popup::after {
  content: "";
  position: absolute;
  left: calc(50% - 8px);
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: rgba(255,255,255,0.96);
  border-right: 1px solid rgba(72,65,58,0.12);
  border-bottom: 1px solid rgba(72,65,58,0.12);
  transform: rotate(45deg);
}

.popup h3 {
  margin: 0 0 0.45rem 0;
  font-size: 0.95rem;
  color: #4e4743;
}

.popup dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.5rem;
  font-size: 0.78rem;
}

.popup dt {
  color: #706862;
}

.popup dd {
  margin: 0;
  text-align: right;
}

.county {
  transition: fill 180ms ease-out, opacity 180ms ease-out, stroke-width 180ms ease-out;
  cursor: pointer;
}

.county:hover {
  stroke: #3e3935 !important;
  stroke-width: 0.8px !important;
}

.state-borders {
  fill: none;
  stroke: rgba(79,74,69,0.52);
  stroke-width: 0.7px;
  pointer-events: none;
  stroke-linejoin: round;
}

.nation-outline {
  fill: none;
  stroke: rgba(54,50,47,0.42);
  stroke-width: 1px;
  pointer-events: none;
}

.county.no-data-both {
  fill: var(--missing-gray);
  stroke: none;
  cursor: default;
}

.county.no-data-layer {
  fill: #ece9e3;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(30, 28, 26, 0.38);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(42rem, 100%);
  max-height: min(80vh, 46rem);
  overflow: auto;
  border-radius: 10px;
  background: rgba(251,249,245,0.98);
  border: 1px solid rgba(77,71,66,0.15);
  box-shadow: 0 18px 42px rgba(0,0,0,0.18);
  padding: 1rem 1.1rem 1.1rem 1.1rem;
}

.modal h2 {
  margin: 0 0 0.7rem 0;
  font-size: 1.05rem;
}

.modal p {
  margin: 0 0 0.75rem 0;
  line-height: 1.45;
  color: #4e4943;
}

.modal a {
  color: #4d5e8f;
}

@media (max-width: 720px) {
  .app-header {
    padding-inline: 1rem;
  }

  .control-panel {
    right: 0.75rem;
    bottom: 0.75rem;
    width: min(24rem, calc(100vw - 1.5rem));
  }

  .popup {
    min-width: 14rem;
    max-width: min(18rem, calc(100vw - 1rem));
  }
}
