/* Palette aligned to map.thetaxdeedcollective.com (interactive 50-state map):
   --tax-deed #0B2E59, --redeemable #22C7FF, --tax-lien #FFE600, --hybrid #FF8A00,
   --navy #052A66 / --navy2 #031B43, --bg #f4f7fb, --ink #12233a, --muted #607089,
   --line #dbe4ef. Sale-type fills live in data/state-data.js TYPE_COLORS. */
:root {
  --ink: #12233a;          /* map --ink */
  --ink-soft: #607089;     /* map --muted */
  --paper: #f4f7fb;        /* map --bg */
  --paper-raised: #ffffff; /* map --card */
  --line: #dbe4ef;         /* map --line */
  --accent: #052a66;       /* map --navy */
  --accent-soft: #22c7ff;  /* map --redeemable */
  --highlight: #ff8a00;    /* map --hybrid */
  --tax-deed: #0b2e59;
  --redeemable: #22c7ff;
  --tax-lien: #ffe600;
  --hybrid: #ff8a00;
  --navy: #052a66;
  --navy2: #031b43;
  --focus: #052a66;
  --shadow: 0 18px 45px rgba(6, 29, 56, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
}

body {
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
}

/* Document flow (not a fixed viewport shell) so the course-note footer
   always sits below the map/detail cards instead of overlapping them. */
.page {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* Hero — exact structure/colors from map.thetaxdeedcollective.com */
.hero {
  background: linear-gradient(135deg, var(--navy), var(--navy2));
  color: #fff;
  border-radius: 24px;
  padding: 1.75rem;
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 1.5rem;
  box-shadow: var(--shadow);
  align-items: center;
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: #b7d9ff;
}

.hero h1 {
  margin: 0 0 0.65rem;
  font-size: clamp(1.85rem, 3.6vw, 3.1rem);
  line-height: 1.05;
  font-weight: 800;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
}

.hero-lead {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  max-width: 48rem;
  color: rgba(255, 255, 255, 0.92);
}

/* Glass legend panel on the right of the hero */
.hero-legend {
  align-self: center;
  justify-self: stretch;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  padding: 1.15rem 1.25rem;
  display: grid;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.hero-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.hero-legend .legend-swatch {
  width: 1.5rem;
  height: 1.15rem;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  display: inline-block;
  flex-shrink: 0;
}

/* Map card + detail panel row — height from content, not viewport flex. */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 1.5rem;
  margin-top: 1.5rem;
  margin-bottom: 0;
  align-items: start;
}

.card,
.panel {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.map-pane {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.map-toolbar {
  margin-bottom: 0.85rem;
  font-family: Arial, Helvetica, sans-serif;
}

.map-heading {
  margin: 0 0 0.35rem;
  color: var(--navy);
  font-size: 1.35rem;
  font-weight: 800;
}

.sub {
  margin: 0 0 0.35rem;
  color: var(--ink-soft);
  line-height: 1.45;
  font-size: 0.9rem;
}

.hint-inline { margin-bottom: 0.75rem; }

.breadcrumb { font-size: 0.9rem; color: var(--ink-soft); }
.breadcrumb strong { color: var(--ink); }
.breadcrumb .crumb-link {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  color: var(--navy);
}
.breadcrumb .crumb-link:hover { color: var(--hybrid); }

.controls.picker {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.picker label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-family: Arial, Helvetica, sans-serif;
}

select {
  font: inherit;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-width: 160px;
}

select:focus, .reset-btn:focus, #population-filter:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.pop-label { min-width: 190px; }

.pop-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

#population-readout {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy);
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

#population-filter {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.6rem;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

#population-filter::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
#population-filter::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

#population-filter::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1rem;
  height: 1rem;
  margin-top: -0.375rem;
  border-radius: 50%;
  background: var(--navy);
  border: 2px solid #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
#population-filter::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--navy);
  border: 2px solid #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.reset-btn {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--navy);
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.reset-btn:disabled { opacity: 0.4; cursor: default; }
.reset-btn:not(:disabled):hover {
  background: var(--navy2);
  border-color: var(--navy2);
}

.map-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.5rem;
}

#map {
  width: 100%;
  max-width: 100%;
  display: block;
  height: auto;
  min-height: 0;
  background: #fff;
  border: none;
  border-radius: 0;
  /* Prefer viewBox aspect; height comes from width × ratio. */
  aspect-ratio: 960 / 600;
}

/* Map shapes. These are SVG paths, so they take SVG defaults when unstyled —
   notably fill:black and pointer-events:visiblePainted. Both matter below. */
.state-shape, .county-shape, .state-outline { vector-effect: non-scaling-stroke; }

.state-shape { stroke: var(--paper-raised); stroke-width: 0.6; cursor: pointer; transition: filter 0.15s ease; }
.state-shape:hover { filter: brightness(1.12); }
.state-shape.selected { stroke: var(--ink); stroke-width: 1.6; }
.state-shape.dimmed { opacity: 0.35; }

/* Two-letter USPS codes — match map.thetaxdeedcollective.com .inside-label
   (white fill + dark halo) so codes read on navy tax-deed fills and lighter
   cyan/yellow/orange fills. No opaque background rect. */
.state-label {
  fill: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;
  pointer-events: none;
  user-select: none;
  paint-order: stroke fill;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 2.5px;
  stroke-linejoin: round;
}

/* The stroke is what makes individual counties legible — without it the
   whole state renders as one undifferentiated block of the type color. */
.county-shape { stroke: var(--paper-raised); stroke-width: 0.4; cursor: pointer; transition: filter 0.15s ease; }
.county-shape:hover { filter: brightness(1.15); }
.county-shape.selected { stroke: var(--ink); stroke-width: 1.4; }
/* Counties below the population filter get their fill attribute removed in
   app.js, so this rule is their only fill — without it they default to black. */
.county-shape.county-excluded { fill: var(--line); cursor: default; opacity: 0.55; }
.county-shape.county-excluded:hover { filter: none; }

/* fill:none and pointer-events:none are both load-bearing: the outline layer
   is drawn on top of the counties, so a filled outline would hide every
   county underneath it and swallow their clicks. */
.state-outline { fill: none; stroke: var(--ink); stroke-width: 1.4; pointer-events: none; }

/* Detail panel — white card like TDC .panel */
.detail-pane {
  min-width: 0;
  max-height: min(70vh, 52rem);
  overflow-y: auto;
  padding: 0;
  background: var(--paper-raised);
  position: sticky;
  top: 1rem;
  z-index: 1;
}

.detail-empty,
.detail-content {
  padding: 1.25rem;
}

/* Course footnote — always below map/detail, never under them. */
.footnote {
  flex: 0 0 auto;
  position: relative;
  z-index: 3;
  clear: both;
  margin: 1.5rem 0 0;
  padding: 1rem 0.25rem 1.5rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-soft);
  font-family: Arial, Helvetica, sans-serif;
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.footnote strong { color: var(--ink); }

/* State/county panel header — match map.thetaxdeedcollective.com .panel-head */
.detail-head {
  background: var(--navy);
  color: #fff;
  padding: 1.35rem 1.35rem 1.25rem;
  border-radius: 24px 24px 0 0;
  margin: 0;
  box-shadow: none;
}

.detail-empty .detail-head {
  margin-bottom: 0;
  border-radius: 24px;
}

.detail-content .detail-head {
  margin: -1.25rem -1.25rem 1.15rem;
  border-radius: 24px 24px 0 0;
}

.detail-kicker {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: #b7d9ff;
  margin: 0 0 0.35rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.detail-title {
  font-size: 1.55rem;
  margin: 0 0 0.35rem;
  font-family: "Iowan Old Style", Georgia, serif;
  color: #fff;
  line-height: 1.15;
}
.detail-sub {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.82);
  margin: 0 0 0.85rem;
  line-height: 1.45;
}
.detail-head .detail-sub:last-child { margin-bottom: 0; }

.type-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  /* Text colour is set inline per type so yellow/cyan pills stay readable. */
  margin: 0.15rem 0 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.type-pill-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; opacity: 0.85; }

/* Body content below the navy header */
.detail-body { padding: 0 0.1rem; }

.field-grid { display: grid; grid-template-columns: 1fr; gap: 0.9rem; margin-bottom: 1.1rem; }
.field label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin-bottom: 0.2rem; }
.field p { margin: 0; font-size: 0.92rem; line-height: 1.45; }

.type-desc { font-size: 0.85rem; line-height: 1.5; color: var(--ink-soft); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 0.9rem; margin-bottom: 1.1rem; }

/* Gold is the brand's attention colour, so the "inherited data" caveat uses a
   tinted gold surface with navy text rather than the gold itself as ink. */
.county-flag {
  font-size: 0.78rem;
  line-height: 1.45;
  background: #fff6e8;
  border: 1px solid #ffd9a0;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 1.1rem;
}

.detail-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border-top: 1px solid var(--line);
  margin: 1.2rem 0 0.7rem;
  padding-top: 0.9rem;
}
.detail-section-title:first-of-type { border-top: none; margin-top: 0.2rem; padding-top: 0; }

.neighborhood-list { margin: 0 0 1.1rem; padding-left: 1.1rem; font-size: 0.88rem; line-height: 1.5; }
.neighborhood-list li { margin-bottom: 0.4rem; }

.source-note {
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--ink-soft);
  border-top: 1px dashed var(--line);
  padding-top: 0.7rem;
  margin-top: 0.4rem;
}
.source-note a { color: var(--ink-soft); }

/* Transcribed source-report block. Deliberately set apart from the atlas's
   own fields above it so the weaker provenance stays visible. */
.detail-subsection-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 1rem 0 0.5rem;
}

.doc-attrib {
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 1rem;
}

.doc-flag { background: var(--paper); border-color: var(--line); color: var(--ink-soft); }

.doc-prose { margin-bottom: 1.1rem; }
.doc-prose p { margin: 0 0 0.7rem; font-size: 0.88rem; line-height: 1.55; }
.doc-prose p:last-child { margin-bottom: 0; }

.doc-links { margin: 0 0 1.1rem; padding-left: 1.1rem; font-size: 0.85rem; line-height: 1.5; }
.doc-links li { margin-bottom: 0.35rem; }
.doc-links a { color: var(--accent); }

/* Tablet + mobile: single column, map always visible above detail. */
@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .map-pane {
    order: 1;
    width: 100%;
  }

  .detail-pane {
    order: 2;
    position: static;
    max-height: none;
    width: 100%;
  }

  .controls.picker {
    flex-direction: column;
    align-items: stretch;
  }

  .picker label,
  .pop-label,
  select,
  .reset-btn {
    width: 100%;
    min-width: 0;
  }

  /* Give the map a reliable height on narrow screens. */
  .map-wrap {
    min-height: 220px;
  }

  #map {
    width: 100%;
    min-width: 0;
    min-height: 220px;
    aspect-ratio: 960 / 600;
  }
}

@media (max-width: 600px) {
  .page {
    padding: 0.85rem 0.75rem 0;
  }

  .hero {
    border-radius: 16px;
    padding: 1.1rem 1rem;
    gap: 1rem;
  }

  .hero h1 {
    font-size: 1.55rem;
  }

  .hero-lead {
    font-size: 0.95rem;
  }

  .hero-legend {
    padding: 0.9rem 1rem;
    font-size: 0.88rem;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem 0.75rem;
  }

  .map-pane,
  .panel {
    border-radius: 16px;
  }

  .map-pane {
    padding: 0.85rem;
  }

  .map-heading {
    font-size: 1.15rem;
  }

  .map-wrap {
    min-height: 200px;
    border-radius: 14px;
    /* Horizontal pan when SVG needs more width than the phone. */
    overflow-x: auto;
  }

  #map {
    /* Keep map readable on phones; allow side-scroll if needed. */
    min-width: min(100%, 520px);
    width: 100%;
    min-height: 200px;
    height: auto;
    aspect-ratio: 960 / 600;
  }

  .state-label {
    font-size: 13px;
    stroke-width: 2px;
  }

  .detail-empty,
  .detail-content {
    padding: 0.9rem;
  }

  .detail-content .detail-head {
    margin: -0.9rem -0.9rem 1rem;
  }

  .detail-title {
    font-size: 1.3rem;
  }

  .footnote {
    margin-top: 1rem;
    padding: 0.85rem 0.15rem 1.25rem;
    font-size: 0.78rem;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .hero-legend {
    grid-template-columns: 1fr;
  }

  #map {
    min-height: 180px;
  }
}
