:root {
  --bg: #ffffff;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --panel-border: rgba(12, 18, 28, 0.08);
  --panel-shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
  --soft-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);

  --text: #12202f;
  --text-soft: #4a596b;
  --text-faint: #7d8895;

  --green-strong: #1b9e77;
  --green-mid: #7bc8ac;
  --white-mid: #ffffff;
  --purple-mid: #c2a5cf;
  --purple-strong: #7b3294;

  --stroke-light: #d8dee5;
  --stroke-mid: #b9c4cf;
  --stroke-dark: #7f8a96;

  --overlay: rgba(255, 255, 255, 0.82);
  --modal-overlay: rgba(18, 32, 47, 0.24);

  --radius-sm: 4px;
  --radius-md: 4px;
  --radius-lg: 4px;

  --title-height: 72px;
  --panel-width: 360px;
  --panel-gap: 16px;

  --transition-fast: 160ms ease;
  --transition-med: 260ms ease;
  --transition-slow: 380ms ease;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  overflow: hidden;
}

body {
  font-family: "IBM Plex Sans", "Inter", Arial, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

a {
  color: var(--purple-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
}

/* MOBILE PORTRAIT GATE */

#mobilePortraitGate {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.96)),
    radial-gradient(circle at 50% 20%, rgba(123, 50, 148, 0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(27, 158, 119, 0.08), transparent 40%);
}

.mobile-gate-card {
  max-width: 560px;
  padding: 28px 28px 24px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--panel-shadow);
  text-align: center;
}

.mobile-gate-title {
  margin: 0 0 14px;
  font-family: "Inter", Arial, sans-serif;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.mobile-gate-text {
  margin: 0 0 12px;
  color: var(--text-soft);
  line-height: 1.45;
}

/* MAIN APP */

#mapApp {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
}

/* TOP BAR */

#topBar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--title-height);
  z-index: 30;
  pointer-events: none;
}

#titleWrap {
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 10px;
  padding: 16px 18px 0;
  pointer-events: none;
}

#mapTitle {
  margin: 0;
  max-width: min(72vw, 1080px);
  font-family: "Inter", Arial, sans-serif;
  font-size: clamp(1.1rem, 1.6vw, 1.8rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: #1a2430;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  user-select: none;
  pointer-events: auto;
}

#layout {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

#mapStage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
}

#mapSurface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(123, 50, 148, 0.02), transparent 25%),
    radial-gradient(circle at 80% 80%, rgba(27, 158, 119, 0.025), transparent 30%),
    #ffffff;
}

#mapSvgWrap {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#mapSvgWrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* BUTTONS */

.icon-button,
.subtle-button,
.map-control,
#panelOpenHandle,
#mobileSourcesFab {
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast),
    opacity var(--transition-fast);
}

.icon-button:hover,
.subtle-button:hover,
.map-control:hover,
#panelOpenHandle:hover,
#mobileSourcesFab:hover {
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.subtle-button:focus-visible,
.map-control:focus-visible,
#panelOpenHandle:focus-visible,
#mobileSourcesFab:focus-visible,
#mapSelector:focus-visible,
.modal-close:focus-visible {
  outline: 2px solid rgba(123, 50, 148, 0.45);
  outline-offset: 2px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  pointer-events: auto;
}

.info-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-family: "Inter", Arial, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  color: var(--purple-strong);
}

.subtle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(18, 32, 47, 0.1);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.05);
}

.subtle-button:hover {
  background: #fafbfc;
}

.map-control {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 12;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(18, 32, 47, 0.12);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: var(--soft-shadow);
}

.home-icon {
  font-size: 1.05rem;
  line-height: 1;
}

/* PANEL */

#panelOpenHandle {
  position: absolute;
  top: 50%;
  right: 0;
  z-index: 26;
  transform: translateY(-50%);
  width: 36px;
  height: 86px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-right: 0;
  border-radius: 4px 0 0 4px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: -8px 8px 18px rgba(15, 23, 42, 0.08);
  display: none;
  align-items: center;
  justify-content: center;
}

.panel-arrow {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text);
}

#explorerPanel {
  position: absolute;
  top: 5vh;
  right: 0;
  width: var(--panel-width);
  height: 90vh;
  z-index: 25;
  border-left: 1px solid var(--panel-border);
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
  overflow: hidden;
  transform: translateX(0);
  transition: transform var(--transition-slow);
}

#explorerPanel.panel-closed {
  transform: translateX(calc(100% - 1px));
}

#panelInner {
  position: absolute;
  inset: 0;
  padding: 14px 14px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

#panelHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#panelTitle {
  margin: 0;
  font-family: "Inter", Arial, sans-serif;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.panel-section {
  border: 1px solid rgba(18, 32, 47, 0.06);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.86);
  padding: 10px;
}

.panel-title-wrap {
  min-width: 0;
}

#panelSubtitle {
  margin: 6px 0 0;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.35;
}

.control-label {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}

#mapSelector {
  width: 100%;
  min-height: 38px;
  padding: 0 38px 0 10px;
  border: 1px solid rgba(18, 32, 47, 0.12);
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(246,248,250,0.98));
  color: var(--text);
  font-size: 0.93rem;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "▾";
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-soft);
  font-size: 0.95rem;
}

.histogram-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.histogram-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.mini-heading {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
}

.mini-description {
  margin: 2px 0 0;
  color: var(--text-soft);
  font-size: 0.8rem;
  line-height: 1.2;
}

#histogramWrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 520px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(250,252,253,0.96));
  overflow: hidden;
}

.histogram-header-copy {
  min-width: 0;
}

#histogramSvg {
  display: block;
  width: 100%;
  height: 100%;
}

.panel-help {
  margin-top: 10px;
  color: var(--text-faint);
  font-size: 0.82rem;
  line-height: 1.4;
}

.panel-footnote-section {
  flex: 0 0 auto;
}

.selection-summary {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}

.panel-footnote {
  color: var(--text-faint);
  font-size: 0.82rem;
  line-height: 1.45;
}

.subtle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(18, 32, 47, 0.1);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.05);
}

/* LOADING */

#loadingOverlay {
  position: absolute;
  inset: 0;
  z-index: 16;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(1.5px);
}

#loadingOverlay.is-visible {
  display: flex;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 320px;
  padding: 18px 20px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--panel-shadow);
  text-align: center;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(123, 50, 148, 0.14);
  border-top-color: var(--purple-strong);
  border-radius: 999px;
  animation: spin 0.85s linear infinite;
}

.loading-text {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.4;
}

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

/* TOOLTIP / INFO WINDOW */

.feature-tooltip {
  position: absolute;
  z-index: 18;
  min-width: 260px;
  max-width: 320px;
  padding: 0;
  pointer-events: none;
  transform: translate(14px, 14px);
}

.tooltip-inner {
  padding: 12px 14px 11px;
  border: 1.5px solid var(--stroke-mid);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.14);
}

.tooltip-title-row {
  margin-bottom: 8px;
}

.tooltip-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.tooltip-metric-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
}

.tooltip-label {
  color: var(--text-soft);
  font-size: 0.9rem;
}

.tooltip-value {
  color: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
}

.tooltip-subtle {
  margin-top: 8px;
  color: #9aa3ad;
  font-size: 0.78rem;
  line-height: 1.35;
}

/* HISTOGRAM HOVER LABEL */

.histogram-hover-label {
  position: absolute;
  z-index: 19;
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
  pointer-events: none;
}

/* MODAL */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-overlay);
}

.modal-window {
  position: relative;
  width: min(760px, calc(100vw - 40px));
  max-height: min(82vh, 900px);
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.18);
  overflow: auto;
  z-index: 1;
}

.modal-content {
  padding: 24px 24px 20px;
}

.modal-close {
  position: sticky;
  top: 8px;
  float: right;
  margin: 10px 10px 0 0;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  z-index: 2;
}

.modal-content h2 {
  margin: 0 0 16px;
  font-family: "Inter", Arial, sans-serif;
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.modal-section + .modal-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(18, 32, 47, 0.08);
}

.modal-section h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
  font-weight: 700;
}

.modal-section p {
  margin: 0 0 10px;
  color: var(--text-soft);
  line-height: 1.5;
}

.modal-list {
  margin: 8px 0 0 18px;
  padding: 0;
  color: var(--text-soft);
}

.modal-list li + li {
  margin-top: 6px;
}

.link-line {
  word-break: break-word;
}

/* MOBILE SOURCES FAB */

#mobileSourcesFab {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 35;
  display: none;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(18, 32, 47, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--purple-strong);
  font-family: "Inter", Arial, sans-serif;
  font-weight: 700;
  box-shadow: var(--soft-shadow);
}

/* SVG / D3 DEFAULT CLASS STYLES */

.map-root {
  width: 100%;
  height: 100%;
}

.map-background-rect {
  fill: #ffffff;
}

.state-boundary {
  fill: none;
  stroke: #e2e7ec;
  stroke-width: 0.65px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.county-boundary {
  fill: none;
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 0.24px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.map-feature {
  stroke: #e6eaee;
  stroke-width: 0.4px;
  vector-effect: non-scaling-stroke;
  transition:
    opacity var(--transition-fast),
    stroke-width var(--transition-fast),
    filter var(--transition-fast);
}

.map-feature.is-hovered {
  stroke-width: 1.2px;
  filter: brightness(1.02);
}

.map-feature.is-dimmed {
  opacity: 0.5;
}

.map-feature.is-suppressed {
  fill: #f4f6f8;
  stroke: #dde3e8;
  stroke-dasharray: 2 2;
}

.map-feature.is-selected {
  opacity: 1;
  stroke-width: 1.05px;
}

.hist-range-band {
  cursor: pointer;
}

.hist-range-band:focus {
  outline: none;
}

.hist-range-band-rect {
  fill: transparent;
}

.hist-range-band.is-active .hist-range-band-rect {
  fill: rgba(18, 32, 47, 0.045);
}

.histogram-tick-text {
  fill: #556374;
  font-size: 12.5px;
  font-weight: 600;
  font-family: "IBM Plex Sans", Arial, sans-serif;
}

.histogram-axis-line,
.histogram-tick-line {
  stroke: #b4bec8;
  stroke-width: 1.1px;
  shape-rendering: crispEdges;
}

.histogram-class-segment {
  stroke-linecap: round;
}

.hist-dot {
  stroke: none;
}

.hist-dot.is-white-class {
  stroke: #cfd6dd;
  stroke-width: 1px;
}

/* RESPONSIVE */

@media (max-width: 1100px) {
  :root {
    --panel-width: 332px;
  }

  #mapTitle {
    max-width: min(64vw, 760px);
    font-size: clamp(1rem, 1.7vw, 1.45rem);
  }
}

@media (max-width: 820px) {
  #topBar {
    display: none;
  }

  #explorerPanel,
  #panelOpenHandle {
    display: none !important;
  }

  #mobileSourcesFab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .modal {
    padding: 16px;
  }

  .modal-window {
    width: min(92vw, 720px);
    max-height: 78vh;
  }
}

/* Portrait phone gate */
@media (max-width: 820px) and (orientation: portrait) {
  #mobilePortraitGate {
    display: flex;
  }

  #mapApp {
    display: none;
  }
}

/* Landscape mobile limited app */
@media (max-width: 820px) and (orientation: landscape) {
  #mapApp {
    display: block;
  }

  #mobilePortraitGate {
    display: none;
  }

  #layout {
    inset: 0;
  }

  #homeButton {
    left: 12px;
    bottom: 12px;
  }

  #loadingOverlay {
    z-index: 20;
  }

  .feature-tooltip {
    min-width: 220px;
    max-width: 260px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

.panel-footnote-section,
.panel-help {
  display: none !important;
}

.legend-status-pill {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  padding: 8px 10px;
  border: 1px solid rgba(18, 32, 47, 0.08);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  font-size: 0.78rem;
  line-height: 1.25;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.legend-status-prefix {
  color: var(--text-soft);
  font-weight: 700;
  margin-right: 4px;
}

.legend-word {
  font-weight: 800;
}

.legend-word-low {
  color: var(--green-strong);
}

.legend-word-mid {
  color: #7a8794;
}

.legend-word-high {
  color: var(--purple-strong);
}

.legend-sep {
  color: #b0bac4;
}

