/* Can You Afford — monochrome system (black, white, one grey ramp). Color is for map data only. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f5f5f7;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --border: #e5e5ea;
  --border-strong: #d2d2d7;
  --focus: #0071e3;
  --ink: #1d1d1f;
  --on-ink: #ffffff;
  --tip-bg: #1d1d1f;
  --tip-text: #f5f5f7;
  --tip-text-2: #a1a1a6;

  /* Diverging map scale: orange = out of reach, gray = right at the edge, blue = room to spare.
     Validated (dataviz validator): each arm monotone, adjacent ΔE >= 15 normal / >= 13 CVD. */
  --c0: #7a3c14;
  --c1: #cb6800;
  --c2: #f0a276;
  --c3: #e7e6e3;
  --c4: #86b6ef;
  --c5: #3987e5;
  --c6: #184f95;
  --nd: #f5f5f7;
  --county-edge: #ffffff;
  --state-edge: rgba(29, 29, 31, 0.42);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --hero: clamp(2.6rem, 6vw + 1rem, 5.5rem);
  --display: clamp(2.2rem, 4vw + 1rem, 4rem);
  --title: clamp(1.6rem, 1.6vw + 1rem, 2.25rem);
  --body: 1.0625rem;
  --caption: 0.8125rem;
  --max: 1200px;
  --prose: 760px;
  --gutter: max(1rem, 4vw);
  --radius: 18px;
  --radius-sm: 12px;
  --pill: 999px;
  --touch: 44px;
  --ease: cubic-bezier(0.28, 0.11, 0.32, 1);
  --dur: 240ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-soft: #1d1d1f;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #86868b;
    --border: #2c2c2e;
    --border-strong: #3a3a3c;
    --focus: #2997ff;
    --ink: #f5f5f7;
    --on-ink: #000000;
    --tip-bg: #f5f5f7;
    --tip-text: #1d1d1f;
    --tip-text-2: #6e6e73;
    --c0: #f8b793;
    --c1: #cf630d;
    --c2: #8a4517;
    --c3: #2e2e2c;
    --c4: #215aa2;
    --c5: #3c86e4;
    --c6: #a1caff;
    --nd: #141415;
    --county-edge: #000000;
    --state-edge: rgba(245, 245, 247, 0.38);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000; --bg-soft: #1d1d1f; --text: #f5f5f7; --text-2: #a1a1a6; --text-3: #86868b;
  --border: #2c2c2e; --border-strong: #3a3a3c; --focus: #2997ff; --ink: #f5f5f7; --on-ink: #000000;
  --tip-bg: #f5f5f7; --tip-text: #1d1d1f; --tip-text-2: #6e6e73;
  --c0: #f8b793; --c1: #cf630d; --c2: #8a4517; --c3: #2e2e2c; --c4: #215aa2; --c5: #3c86e4; --c6: #a1caff;
  --nd: #141415; --county-edge: #000000; --state-edge: rgba(245, 245, 247, 0.38);
}
@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--body)/1.47 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }
.prose { max-width: var(--prose); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Nav */
.nav { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border); }
.nav .wrap { display: flex; align-items: center; justify-content: space-between; height: 52px; gap: 1rem; }
.brand { font: 700 1.0625rem/1 var(--font-display); letter-spacing: -0.02em; text-decoration: none; white-space: nowrap; }
.nav-links { display: flex; gap: 1.25rem; font-size: 0.875rem; }
.nav-links a { text-decoration: none; color: var(--text-2); }
.nav-links a:hover, .nav-links a[aria-current] { color: var(--text); }

/* Type */
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.03em; margin: 0; }
.hero { padding-block: clamp(2.5rem, 7vw, 6rem) clamp(1.5rem, 3vw, 2.5rem); }
.hero h1 { font-size: var(--hero); line-height: 1.02; font-weight: 700; max-width: 12ch; }
.lede { font-size: clamp(1.1875rem, 0.6vw + 1rem, 1.5rem); color: var(--text-2); margin: 1rem 0 0; max-width: 36ch; line-height: 1.35; }
.kicker { font-size: var(--caption); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); margin: 0 0 0.5rem; }

/* Controls */
.controls { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.25rem 2rem; align-items: start; background: var(--bg-soft); border-radius: var(--radius); padding: 1.5rem; }
.field { display: grid; gap: 0.45rem; min-width: 0; }
.field > label, .field > .label { font-size: var(--caption); font-weight: 600; color: var(--text-2); }
.hint { font-size: var(--caption); color: var(--text-3); }
.money { display: flex; align-items: baseline; gap: 0.15rem; border-bottom: 2px solid var(--border-strong); transition: border-color var(--dur) var(--ease); }
.money:focus-within { border-color: var(--text); }
.money span { font: 600 1.5rem/1 var(--font-display); color: var(--text-2); }
.money input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--text); font: 700 2rem/1.2 var(--font-display); letter-spacing: -0.03em; padding: 0.15rem 0; outline: none; font-variant-numeric: tabular-nums; }
.money.sm span { font-size: 1.125rem; }
.money.sm input { font-size: 1.375rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 0.375rem; }
.seg button, .toggle button {
  min-height: 40px; padding: 0 1rem; border-radius: var(--pill); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: 600 0.9375rem/1 var(--font); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.seg button[aria-checked="true"], .toggle button[aria-selected="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.more { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 1rem; }
.more summary { cursor: pointer; font-size: 0.9375rem; font-weight: 600; list-style: none; display: inline-flex; gap: 0.4rem; align-items: center; min-height: var(--touch); }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "+"; font-weight: 400; color: var(--text-2); }
.more[open] summary::after { content: "–"; }
.more-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem 2rem; padding-top: 0.5rem; }

/* Result */
.result { padding-block: clamp(2rem, 4vw, 3rem) 1rem; }
.result-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem 2rem; margin-bottom: 1.25rem; }
.headline { margin: 0; font: 700 var(--display)/1.05 var(--font-display); letter-spacing: -0.035em; max-width: 20ch; }
.headline .of { color: var(--text-2); }
.subhead { margin: 0.5rem 0 0; color: var(--text-2); font-size: 1.0625rem; max-width: 46ch; }
.toggle { display: inline-flex; gap: 0.25rem; padding: 0.25rem; border-radius: var(--pill); background: var(--bg-soft); }
.toggle button { border: 0; background: transparent; min-height: 36px; }

.map-wrap { position: relative; margin: 0; }
#map { display: block; width: 100%; height: auto; touch-action: manipulation; }
#map .counties path { stroke: var(--county-edge); stroke-width: 0.3; fill-rule: evenodd; cursor: pointer; }
#map .borders { fill: none; stroke: var(--state-edge); stroke-width: 0.6; pointer-events: none; }
#map .hl { fill: none; stroke: var(--text); stroke-width: 1.6; pointer-events: none; vector-effect: non-scaling-stroke; }
.c0 { fill: var(--c0); } .c1 { fill: var(--c1); } .c2 { fill: var(--c2); } .c3 { fill: var(--c3); }
.c4 { fill: var(--c4); } .c5 { fill: var(--c5); } .c6 { fill: var(--c6); } .nd { fill: url(#nd); }
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); font-size: var(--caption); }

.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 220px; max-width: 280px;
  background: var(--tip-bg); color: var(--tip-text); border-radius: var(--radius-sm); padding: 0.75rem 0.9rem;
  font-size: 0.875rem; line-height: 1.4; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.tip strong { display: block; font-size: 0.9375rem; }
.tip .row { display: flex; justify-content: space-between; gap: 1rem; color: var(--tip-text-2); }
.tip .row b { color: var(--tip-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .verdict { margin-top: 0.35rem; font-weight: 600; display: flex; align-items: center; gap: 0.45rem; }
.chip { width: 12px; height: 12px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.25); }
.chip.c0 { background: var(--c0); } .chip.c1 { background: var(--c1); } .chip.c2 { background: var(--c2); } .chip.c3 { background: var(--c3); }
.chip.c4 { background: var(--c4); } .chip.c5 { background: var(--c5); } .chip.c6 { background: var(--c6); }

.legend { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.35rem; }
.legend li { display: grid; gap: 0.35rem; font-size: 0.75rem; color: var(--text-2); line-height: 1.25; }
.legend .bar { height: 10px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.18); }
.legend b { color: var(--text); font-weight: 600; font-size: 0.8125rem; }
.legend-note { font-size: var(--caption); color: var(--text-3); margin: 0.5rem 0 0; }

.actions { display: flex; flex-wrap: wrap; gap: 0.625rem; margin-top: 1.5rem; }
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: var(--touch);
  padding: 0 1.4rem; border-radius: var(--pill); border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--text); font: 600 1rem/1 var(--font); text-decoration: none; cursor: pointer;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.pill:active { transform: scale(0.98); }
.pill.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* Share preview */
.share-preview { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 1.5rem; margin-top: 1.5rem; align-items: start; }
.pv { margin: 0; background: var(--bg-soft); border-radius: var(--radius); padding: 1rem; display: grid; gap: 0.75rem; }
.pv-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 36px; }
.pv-title { font-size: var(--caption); font-weight: 600; color: var(--text-2); }
.pv-frame { position: relative; background: #ffffff; border-radius: var(--radius-sm); overflow: hidden; box-shadow: 0 0 0 1px var(--border); }
.pv-frame.square { aspect-ratio: 1 / 1; }
.pv-frame.wide { aspect-ratio: 1200 / 630; border-radius: var(--radius-sm) var(--radius-sm) 0 0; box-shadow: none; }
.pv-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.pv-status { position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--caption); color: #86868b; text-align: center; padding: 1rem; }
.pv-opts .seg button { min-height: 36px; font-size: 0.875rem; }
.toggle.sm button { min-height: 30px; padding: 0 0.85rem; font-size: 0.8125rem; }
.link-card { border-radius: var(--radius-sm); overflow: hidden; box-shadow: 0 0 0 1px var(--border); background: var(--bg); }
.link-meta { display: grid; gap: 0.15rem; padding: 0.7rem 0.9rem 0.8rem; }
.link-domain { font-size: 0.75rem; color: var(--text-3); }
.link-title { font-size: 0.9375rem; font-weight: 600; line-height: 1.3; }

/* Ads: collapsed (width kept for sizing) until AdSense marks the unit filled */
.ad { margin-top: clamp(2rem, 4vw, 3rem); text-align: center; }
.ad-label { margin: 0 0 0.4rem; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.ad-unit { width: 100%; }
.ad:not(:has(ins[data-ad-status="filled"])) { height: 0; margin-top: 0; overflow: hidden; }

/* County card and finder */
.find { padding-block: clamp(2rem, 4vw, 3rem) 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 2rem; align-items: start; }
.find h2, .list h2, .section-title { font-size: var(--title); font-weight: 700; }
.find input, .list select {
  width: 100%; min-height: 48px; margin-top: 1rem; padding: 0 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: 400 1.0625rem/1 var(--font);
}
.card { background: var(--bg-soft); border-radius: var(--radius); padding: 1.5rem; }
.card h3 { font-size: 1.5rem; font-weight: 700; }
.card .big { font: 700 2.5rem/1.05 var(--font-display); letter-spacing: -0.035em; margin: 0.75rem 0 0.15rem; }
.card .verdict { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; margin: 0.25rem 0 1rem; }
.card-empty { color: var(--text-2); margin: 0; }
.lines { display: grid; gap: 0.35rem; margin: 0 0 1rem; }
.lines div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--border); padding: 0.35rem 0; font-size: 0.9375rem; }
.lines div span:first-child { color: var(--text-2); }
.lines div span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }

/* List view */
.list { padding-block: clamp(2.5rem, 5vw, 4rem) 0; }
.list-head { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: end; justify-content: space-between; }
.list select { width: auto; min-width: 240px; margin: 0; }
.table-scroll { overflow-x: auto; margin-top: 1rem; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: right; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th { font-size: var(--caption); font-weight: 600; color: var(--text-2); }
td a { text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }
td .tag { display: inline-flex; align-items: center; gap: 0.4rem; justify-content: flex-end; }

/* Explainer + footer */
.explain { padding-block: clamp(3rem, 6vw, 5rem); }
.explain-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2rem; margin-top: 1.5rem; }
.explain-grid h3 { font-size: 1.1875rem; font-weight: 700; margin-bottom: 0.4rem; }
.explain-grid p { color: var(--text-2); margin: 0; }
.footer { border-top: 1px solid var(--border); padding-block: 2rem calc(2rem + env(safe-area-inset-bottom, 0px)); font-size: var(--caption); color: var(--text-2); }
.footer .wrap { display: grid; gap: 0.5rem; }
.footer nav { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.footer a { text-decoration: none; }
.footer a:hover { color: var(--text); }

/* County and state pages */
.page { padding-block: clamp(2.5rem, 6vw, 5rem) clamp(2rem, 4vw, 3rem); }
.page h1 { font-size: var(--display); line-height: 1.05; font-weight: 700; max-width: 18ch; }
.stat { font: 700 var(--hero)/1 var(--font-display); letter-spacing: -0.04em; margin: 1.5rem 0 0.4rem; }
.stat-label { color: var(--text-2); font-size: 1.1875rem; margin: 0; max-width: 34ch; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; margin-top: 2.5rem; }
.note { color: var(--text-2); font-size: 0.9375rem; }
.crumbs { font-size: var(--caption); color: var(--text-2); margin-bottom: 1.25rem; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.states-grid { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.25rem 1.5rem; }
.states-grid a { display: block; padding: 0.5rem 0; border-bottom: 1px solid var(--border); text-decoration: none; }
.prose-block h2 { font-size: var(--title); margin: 2.5rem 0 0.75rem; }
.prose-block p, .prose-block li { color: var(--text-2); }
.prose-block strong { color: var(--text); }

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .field.income { grid-column: 1 / -1; }
  .more-grid { grid-template-columns: 1fr 1fr; }
  .find, .split, .share-preview { grid-template-columns: 1fr; }
  .explain-grid { grid-template-columns: 1fr; gap: 1.5rem; }
}
@media (max-width: 600px) {
  .nav-links { gap: 1rem; }
  .nav-links .wide { display: none; }
  .controls { grid-template-columns: 1fr; padding: 1.25rem; border-radius: var(--radius-sm); }
  .more-grid { grid-template-columns: 1fr; }
  .map-wrap { margin: 0 calc(var(--gutter) * -1); }
  .legend { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.2rem; }
  /* Seven labels don't fit a phone: label the two ends and the middle only. */
  .legend li span.range { display: none; }
  .legend li { position: relative; min-height: 34px; }
  .legend li b { position: absolute; top: 16px; white-space: nowrap; font-size: 0.75rem; }
  .legend li:nth-child(2) b, .legend li:nth-child(3) b, .legend li:nth-child(5) b, .legend li:nth-child(6) b { display: none; }
  .legend li:nth-child(1) b { left: 0; }
  .legend li:nth-child(4) b { left: 50%; transform: translateX(-50%); }
  .legend li:nth-child(7) b { right: 0; }
  .actions .pill { flex: 1 1 auto; }
  .list select { width: 100%; }
}
