:root {
  --paper: #f8f0e3;
  --paper-translucent: rgba(248, 240, 227, 0.86);
  --ink: #261916;
  --muted: #6f625b;
  --line: rgba(38, 25, 22, 0.18);
  --line-strong: rgba(38, 25, 22, 0.34);
  --accent: #7b1424;
  --restaurant: #b55b18;
  --mono: #6f318f;
  --shadow: 0 14px 30px rgba(38, 25, 22, 0.16);
  --r: 4px;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 12% 88%, rgba(181, 91, 24, 0.12), transparent 34rem),
    radial-gradient(circle at 82% 18%, rgba(111, 49, 143, 0.12), transparent 28rem),
    linear-gradient(180deg, #fbf4ea 0%, var(--paper) 100%);
}

#map {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: transparent;
  cursor: grab;
  touch-action: none;
}

#map:active {
  cursor: grabbing;
}

.map-bg {
  fill: transparent;
}

.county {
  stroke: rgba(255, 255, 255, 0.62);
  stroke-width: 0.28px;
  vector-effect: non-scaling-stroke;
  transition: opacity 120ms ease, stroke 120ms ease;
}

.county:hover {
  stroke: rgba(38, 25, 22, 0.9);
  stroke-width: 1.05px;
}

.county.filtered-out {
  opacity: 0.055;
  pointer-events: none;
}

.county.search-hit {
  stroke: #111;
  stroke-width: 1.4px;
  filter: drop-shadow(0 0 5px rgba(123, 20, 36, 0.42));
}

.state-outline {
  fill: none;
  stroke: rgba(38, 25, 22, 0.28);
  stroke-width: 0.7px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.graticule {
  fill: none;
  stroke: rgba(38, 25, 22, 0.08);
  stroke-width: 0.45px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.titlebar {
  position: absolute;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: start;
  min-height: 54px;
  padding: 10px max(18px, 2vw) 12px;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(248, 240, 227, 0.96) 0%,
    rgba(248, 240, 227, 0.72) 56%,
    rgba(248, 240, 227, 0) 100%
  );
}

.title-copy {
  max-width: min(980px, calc(100vw - 360px));
}

.kicker {
  margin: 0 0 2px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(0.58rem, 1.2vw, 0.72rem);
  line-height: 1.1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.6vw, 2.45rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
  font-weight: 850;
}

.subtitle {
  max-width: 84ch;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: clamp(0.72rem, 1.2vw, 0.92rem);
  line-height: 1.25;
}

.control-panel {
  position: absolute;
  z-index: 30;
  top: 64px;
  right: 12px;
  width: min(324px, calc(100vw - 58px));
  max-height: calc(100vh - 96px);
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper-translucent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: transform 180ms ease;
}

.control-inner {
  max-height: calc(100vh - 98px);
  overflow-y: auto;
  padding: 12px;
  transition: opacity 120ms ease;
}

.panel-toggle {
  position: absolute;
  z-index: 40;
  top: 8px;
  left: -34px;
  width: 34px;
  min-width: 34px;
  max-width: 34px;
  height: 96px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: var(--r) 0 0 var(--r);
  background: rgba(248, 240, 227, 0.94);
  color: var(--ink);
  padding: 8px 4px;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: -8px 8px 22px rgba(38, 25, 22, 0.11);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.control-panel.collapsed {
  transform: translateX(100%);
}

.control-panel.collapsed .control-inner {
  opacity: 0;
  pointer-events: none;
}

label,
.legend-panel summary {
  display: block;
  margin: 10px 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select,
input[type="search"],
button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(255, 251, 244, 0.88);
  color: var(--ink);
  padding: 8px 9px;
  font: inherit;
}

button {
  cursor: pointer;
  font-weight: 750;
}

.panel-toggle {
  width: 34px;
  padding: 8px 4px;
}

button:hover,
select:hover,
input[type="search"]:hover {
  border-color: var(--line-strong);
}

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

.button-grid button:first-child {
  grid-column: 1 / -1;
}

.button-grid button.active {
  background: var(--ink);
  color: var(--paper);
}

.legend-panel {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.legend-panel summary {
  cursor: pointer;
}

.bivar-legend {
  display: grid;
  grid-template-columns: 42px repeat(3, 1fr);
  grid-template-rows: repeat(3, 28px) 24px;
  gap: 2px;
  align-items: stretch;
  margin-top: 7px;
}

.bivar-cell {
  border: 1px solid rgba(38, 25, 22, 0.12);
}

.bivar-y {
  grid-row: 1 / 4;
  display: grid;
  place-items: center;
  color: var(--mono);
  font-size: 0.68rem;
  font-weight: 850;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bivar-x {
  grid-column: 2 / 5;
  display: grid;
  place-items: center;
  color: var(--restaurant);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.seq-legend {
  margin-top: 8px;
}

.seq-ramp {
  height: 16px;
  border: 1px solid rgba(38, 25, 22, 0.15);
  border-radius: var(--r);
}

.seq-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 12px;
}

.loading {
  position: absolute;
  z-index: 50;
  left: 18px;
  bottom: 18px;
  max-width: min(520px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(248, 240, 227, 0.94);
  color: var(--accent);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-weight: 750;
}

.loading.hidden {
  display: none;
}

.tooltip {
  position: fixed;
  z-index: 80;
  display: none;
  width: min(320px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(255, 250, 242, 0.97);
  box-shadow: var(--shadow);
  padding: 10px;
  pointer-events: none;
}

.tooltip.visible {
  display: block;
}

.tooltip h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.1;
}

.tooltip .lead {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 850;
}

.tooltip dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 10px;
  margin: 0;
  font-size: 0.82rem;
}

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

.tooltip dd {
  margin: 0;
  font-weight: 850;
}

.tooltip .fine {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
}

.attribution {
  position: absolute;
  z-index: 18;
  right: 12px;
  bottom: 8px;
  max-width: min(620px, calc(100vw - 24px));
  color: rgba(38, 25, 22, 0.56);
  font-size: 0.66rem;
  text-align: right;
  pointer-events: none;
}

.modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(38, 25, 22, 0.28);
}

.modal.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: min(78vh, 720px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper);
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 38px 10px 0;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.45;
}

.modal-card code {
  color: var(--accent);
  font-size: 0.9em;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

a {
  color: var(--accent);
  font-weight: 850;
}

@media (max-width: 760px) {
  .titlebar {
    min-height: 58px;
    padding-right: 54px;
  }

  .title-copy {
    max-width: calc(100vw - 64px);
  }

  .control-panel {
    top: 62px;
    right: 8px;
    width: min(308px, calc(100vw - 52px));
    max-height: calc(100vh - 82px);
  }

  .control-inner {
    max-height: calc(100vh - 84px);
  }

  .panel-toggle {
    top: 8px;
    left: -34px;
    right: auto;
  }

  .attribution {
    left: 8px;
    right: 8px;
    bottom: 6px;
    text-align: left;
  }
}
