:root {
  --radius: 4px;
  --paper: #efe2cc;
  --paper-2: #f7eddc;
  --ink: #2b1a12;
  --muted: #7f6d5d;
  --hairline: rgba(74, 47, 31, 0.18);
  --county-stroke: rgba(255, 250, 240, 0.42);
  --state-stroke: rgba(49, 30, 20, 0.58);
  --accent: #a64b31;
  --accent-dark: #65291f;
  --panel: rgba(255, 248, 236, 0.92);
  --panel-solid: #fff5e5;
  --shadow: 0 24px 60px rgba(61, 36, 22, 0.20);
  --shadow-soft: 0 12px 30px rgba(61, 36, 22, 0.15);
  --z-map: 1;
  --z-panel: 30;
  --z-tooltip: 80;
  --z-header: 100;
  --z-backdrop: 190;
  --z-drawer: 200;
  --z-modal: 240;
}

* { box-sizing: border-box; }

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

body {
  height: 100dvh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 243, 216, .9), rgba(239, 226, 204, .1) 34rem),
    linear-gradient(135deg, #e7d4b7, #f1e1c8 45%, #dfc4a2);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .72rem clamp(1rem, 2vw, 1.8rem);
  background: rgba(45, 26, 16, .92);
  color: #fff4e4;
  border-bottom: 1px solid rgba(255, 236, 202, .18);
  backdrop-filter: blur(14px);
}

.brand-kicker {
  display: block;
  font-size: .7rem;
  line-height: 1;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #e4bd84;
  margin-bottom: .2rem;
}

.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.05rem, 1.55vw, 1.62rem);
  font-weight: 650;
  letter-spacing: .015em;
}

.menu-toggle {
  min-inline-size: 104px;
  block-size: 42px;
  display: inline-grid;
  place-content: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 236, 202, .38);
  background: rgba(255, 246, 229, .12);
  color: #fff4e4;
  cursor: pointer;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}

.menu-toggle span {
  display: none;
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 246, 229, .18);
  border-color: rgba(255, 236, 202, .72);
  outline: none;
}

.map-stage {
  position: relative;
  z-index: 0;
  width: 100vw;
  height: calc(100dvh - 70px);
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.map-svg {
  position: relative;
  z-index: var(--z-map);
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  filter: saturate(.98);
}

.map-paper {
  fill: transparent;
}

.inner-paper {
  fill: transparent;
  stroke: none;
  stroke-width: 0;
}

.map-frame {
  filter: none;
}

.county {
  fill-rule: evenodd;
  stroke: var(--county-stroke);
  stroke-width: .36;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill .24s ease, opacity .2s ease, stroke .14s ease, stroke-width .14s ease;
}

.county.no-data {
  cursor: default;
  fill: url(#noDataPattern);
  stroke: rgba(255, 255, 255, .45);
}

.county:hover,
.county:focus-visible,
.county.is-active {
  stroke: #1f120c;
  stroke-width: 1.45;
  outline: none;
}

.county.is-active {
  filter: drop-shadow(0 0 4px rgba(33, 18, 11, .28));
}

.state-outline {
  fill: none;
  stroke: var(--state-stroke);
  stroke-width: .88;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.inset-hairline {
  fill: none;
  stroke: rgba(76, 50, 31, .25);
  stroke-width: 1;
  stroke-dasharray: 3 5;
  vector-effect: non-scaling-stroke;
}

.inset-label,
.svg-caption {
  fill: rgba(67, 42, 28, .72);
  font-size: 13px;
  letter-spacing: .04em;
}

.svg-caption {
  font-size: 14px;
  font-weight: 650;
}

.desktop-panel {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: var(--z-panel);
  width: min(350px, 31vw);
  border: 1px solid rgba(83, 52, 33, .18);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.desktop-panel-toggle,
.detail-panel-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .8rem;
  border: 0;
  background: rgba(255, 251, 242, .44);
  color: var(--ink);
  cursor: pointer;
  padding: .86rem .95rem .72rem;
  text-align: left;
}

.desktop-panel-toggle:hover,
.desktop-panel-toggle:focus-visible,
.detail-panel-header:hover,
.detail-panel-header:focus-visible {
  background: rgba(255, 251, 242, .72);
  outline: none;
}

.panel-title {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.08;
  font-weight: 650;
}

.panel-toggle-mark {
  font-size: 1.35rem;
  line-height: 1;
  color: rgba(43, 26, 18, .72);
}

.desktop-panel-body {
  padding: 0 .95rem .95rem;
}

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

.panel-eyebrow {
  margin: 0 0 .35rem;
  color: var(--accent);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.drawer h2,
.modal-card h2 {
  margin: 0 0 .45rem;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 650;
  line-height: 1.08;
}

.desktop-panel p,
.drawer p,
.modal-card p,
.modal-card li {
  color: #594739;
  line-height: 1.42;
}

.desktop-panel p {
  margin: .45rem 0 .8rem;
  font-size: .92rem;
}

.mode-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin: .85rem 0 .85rem;
}

.drawer-pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.drawer-pills .mode-button {
  width: 100%;
  text-align: center;
}

.mode-button,
.text-action {
  border: 1px solid rgba(96, 58, 38, .22);
  background: rgba(255, 251, 242, .72);
  color: var(--ink);
  border-radius: 999px;
  padding: .45rem .68rem;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255,255,255,.65) inset;
}

.mode-button:hover,
.mode-button:focus-visible,
.text-action:hover,
.text-action:focus-visible {
  border-color: rgba(112, 50, 31, .5);
  outline: none;
}

.mode-button.is-selected {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff4e4;
}

.legend-box {
  margin-top: .65rem;
  padding-top: .75rem;
  border-top: 1px solid rgba(86, 53, 34, .14);
}

.drawer-legend-section .legend-box {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.legend-title {
  margin: 0 0 .45rem;
  font-weight: 800;
  color: #3a2317;
}

.legend-note {
  margin: .32rem 0 .65rem;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.32;
}

.bivar-grid {
  width: 144px;
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(3, 32px);
  gap: 4px;
  margin: .25rem 0;
}

.bivar-cell,
.swatch {
  border: 1px solid rgba(45, 27, 18, .2);
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset;
}

.bivar-cell {
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  transition: transform .14s ease, opacity .14s ease, outline-color .14s ease, box-shadow .14s ease;
}

.bivar-cell:hover,
.bivar-cell:focus-visible {
  transform: translateY(-1px);
  outline: 2px solid rgba(43, 26, 18, .55);
  outline-offset: 1px;
}

.bivar-cell.is-active {
  outline: 2px solid #27150d;
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(255,246,229,.72);
}

.bivar-clear {
  display: inline-block;
  margin-top: .45rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: #7a3525;
  font-size: .82rem;
  font-weight: 800;
  cursor: pointer;
}

.bivar-axis {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}

.bivar-axis.x {
  margin-left: 2px;
}

.bivar-row {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.bivar-y-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 108px;
  text-align: center;
}

.swatch-list {
  display: grid;
  gap: .38rem;
}

.swatch-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #4e3d31;
  font-size: .86rem;
}

.swatch {
  inline-size: 22px;
  block-size: 16px;
  border-radius: var(--radius);
  flex: 0 0 auto;
}
.swatch.hatched {
  background:
    repeating-linear-gradient(35deg, #d9d0c2 0 5px, #b8a996 5px 7px, #d9d0c2 7px 12px);
}


.loading-state {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 40;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  border: 1px solid rgba(99, 60, 38, .16);
  border-radius: 999px;
  background: rgba(255, 247, 233, .94);
  box-shadow: var(--shadow-soft);
  color: #513623;
}

.loader-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(166, 75, 49, .18);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

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

.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 280px;
  pointer-events: none;
  padding: .72rem .8rem;
  border: 1px solid rgba(69, 40, 24, .18);
  border-radius: var(--radius);
  background: rgba(43, 26, 18, .94);
  color: #fff4e4;
  box-shadow: var(--shadow-soft);
  transform: translate(14px, 14px);
}

.tooltip strong {
  display: block;
  margin-bottom: .25rem;
}

.tooltip span {
  display: block;
  color: #f0c997;
  font-size: .83rem;
  line-height: 1.32;
}

.detail-panel {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: var(--z-panel);
  width: min(380px, 34vw);
  border: 1px solid rgba(83, 52, 33, .18);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-panel-body {
  padding: .85rem .95rem .95rem;
}

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

.detail-panel.is-collapsed {
  width: min(330px, 30vw);
}

.panel-close,
.drawer-close,
.modal-close {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.75rem;
  line-height: 1;
}

.panel-close {
  position: absolute;
  top: .72rem;
  right: .74rem;
  z-index: 2;
}

.county-title {
  margin: 0 1.7rem .25rem 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.28rem;
  line-height: 1.1;
}

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

.metric-card {
  padding: .65rem;
  border-radius: var(--radius);
  background: rgba(255,255,255,.42);
  border: 1px solid rgba(87, 53, 33, .12);
}

.metric-card b {
  display: block;
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.metric-card span {
  display: block;
  margin-top: .2rem;
  font-size: 1.05rem;
  font-weight: 800;
  color: #3b2317;
}

.detail-footnote {
  margin: .55rem 0 0;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.35;
}

.attribution {
  position: absolute;
  right: 1rem;
  bottom: .35rem;
  z-index: 5;
  color: rgba(61, 39, 27, .72);
  font-size: .74rem;
  text-align: right;
}

.attribution a {
  color: rgba(61, 39, 27, .78);
  text-decoration: none;
  font-weight: 700;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-backdrop);
  background: rgba(35, 20, 13, .35);
  backdrop-filter: blur(3px);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: var(--z-drawer);
  width: min(430px, calc(100vw - 2rem));
  height: 100dvh;
  overflow-y: auto;
  padding: 1.1rem;
  background: #fff3df;
  box-shadow: -22px 0 60px rgba(35, 20, 13, .28);
  transform: translateX(105%);
  transition: transform .22s ease;
  border-left: 1px solid rgba(74, 45, 28, .14);
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding-bottom: .9rem;
  border-bottom: 1px solid rgba(74, 45, 28, .13);
}

.drawer-section {
  padding: 1rem 0;
  border-bottom: 1px solid rgba(74, 45, 28, .11);
}

.drawer-section h3 {
  margin: 0 0 .55rem;
  font-size: .95rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.drawer code,
.modal-card code {
  border-radius: var(--radius);
  padding: .08rem .25rem;
  background: rgba(104, 62, 38, .1);
  color: #5b2f21;
}

.search-label {
  display: block;
  margin-bottom: .4rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
}

.county-search {
  width: 100%;
  border: 1px solid rgba(82, 50, 31, .24);
  border-radius: var(--radius);
  padding: .68rem .8rem;
  background: rgba(255,255,255,.66);
  color: var(--ink);
}

.county-search:focus {
  outline: 2px solid rgba(166, 75, 49, .35);
  border-color: rgba(166, 75, 49, .55);
}

.search-results {
  display: grid;
  gap: .4rem;
  margin-top: .6rem;
}

.search-results button {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(82, 50, 31, .12);
  border-radius: var(--radius);
  padding: .55rem .65rem;
  background: rgba(255,255,255,.5);
  color: var(--ink);
  cursor: pointer;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
}

.modal-backdrop {
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-card {
  position: relative;
  width: min(620px, calc(100vw - 2rem));
  max-height: min(84dvh, 760px);
  overflow-y: auto;
  padding: 1.35rem;
  border: 1px solid rgba(91, 55, 33, .18);
  border-radius: var(--radius);
  background: #fff6e8;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: .85rem;
  right: .95rem;
}

.modal-card ul {
  padding-left: 1.2rem;
}

.modal-card a {
  color: #8c3f2b;
  font-weight: 800;
}

.made-with {
  padding-top: .7rem;
  border-top: 1px solid rgba(91, 55, 33, .14);
}

.portrait-lock {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  place-items: center;
  padding: 1.25rem;
  background: rgba(45, 26, 16, .92);
  color: #fff4e4;
  text-align: center;
}

.portrait-lock-card {
  max-width: 330px;
  padding: 1.15rem 1.25rem;
  border: 1px solid rgba(255, 236, 202, .2);
  border-radius: var(--radius);
  background: rgba(255, 246, 229, .08);
  box-shadow: var(--shadow);
}

.portrait-lock-card h2 {
  margin: 0 0 .45rem;
  font-family: Georgia, "Times New Roman", serif;
}

.portrait-lock-card p {
  margin: 0;
  line-height: 1.35;
}

[hidden] {
  display: none !important;
}

@media (max-width: 920px) {
  .desktop-panel {
    display: none;
  }

  .map-stage {
    padding: 0;
    height: calc(100dvh - 70px);
  }

  .map-svg {
    height: 100%;
    min-height: 0;
  }

  .detail-panel {
    position: fixed;
    left: .65rem;
    right: .65rem;
    bottom: .75rem;
    width: auto;
    max-height: 46dvh;
    overflow-y: auto;
    z-index: 130;
  }

  .detail-panel.is-collapsed {
    width: auto;
  }

  .attribution {
    left: .9rem;
    right: .9rem;
    bottom: .05rem;
    text-align: center;
    font-size: .68rem;
  }
}

@media (max-width: 640px) {
  .app-header {
    min-height: 62px;
    padding: .58rem .78rem;
  }

  .brand-kicker {
    font-size: .58rem;
  }

  .brand h1 {
    font-size: 1.14rem;
  }

  .menu-toggle {
    min-inline-size: 96px;
    block-size: 40px;
    font-size: .72rem;
  }

  .map-stage {
    height: calc(100dvh - 62px);
    min-height: 0;
    padding: 0;
  }

  .map-svg {
    height: 100%;
    min-height: 0;
  }

  .drawer {
    width: 100vw;
    padding: .95rem;
  }

  .drawer-pills {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-button {
    padding: .55rem .55rem;
  }

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

  .tooltip {
    display: none;
  }
}

@media (max-width: 920px) and (orientation: portrait) {
  .portrait-lock {
    display: grid;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
