← Demos
Web Pages · Demos

CountyWise

Shows what a paycheck is really worth in each of Kentucky's 120 counties, with real rent, child care and every county, city and school district wage tax, then builds a dated plan. Try: click See an example in the header (a Pikeville single mom earning $28,000 with a $4,200 hospital bill), then open Your plan. Notice the best counties for her pay, the benefits she likely qualifies for, the hospital bill check, and how her tax refund pays off debt each February.

by Kai Sanfilippo Nov 20, 2026 25 views 285.8 KB
Sandbox · countywise · no access to your account
View source — the whole page is this one file
<!-- Copyright (c) 2026 Kai Sanfilippo and Grant Sumner. Released under the MIT License. -->
<!-- CountyWise: for Kentucky households, especially lower income families, deciding where to live and how to budget. For educational use only, not financial, tax or legal advice. -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CountyWise</title>
<link rel="icon" id="favicon" href="data:,">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Serif:wght@500;600&display=swap" rel="stylesheet">
<style>
:root{
  color-scheme:light;
  --bg:#f3f5f9; --surface:#ffffff; --surface2:#f7f9fc; --ink:#0b1424; --ink2:#475467; --ink3:#667085; --line:#dfe4ee;
  --uk:#0033a0; --uk2:#001f63; --accent:#0033a0; --accent-soft:#e6ecf8; --on-accent:#ffffff;
  --green:#047857; --green-soft:#e2f3eb; --yellow:#a16207; --yellow-soft:#fef6d8; --red:#b42318; --red-soft:#fdecea;
  --shadow:0 1px 2px rgba(11,20,36,.06),0 8px 24px rgba(11,20,36,.06);
  --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --s5:#e87ba4; --s6:#008300; --s7:#6250d6; --s8:#e34948; --s9:#98a2b3; --s10:#a0785a;
  --t1:#0033a0; --t2:#3b5ba9; --t3:#6b85c4; --t4:#a3b4dd;
  --map-mid:#eceff4; --map-pos:#0f7a3d; --map-neg:#c0352b; --map-seq:#0033a0;
  --serif:"IBM Plex Serif",Georgia,"Times New Roman",serif; --sans:"IBM Plex Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; --mono:"IBM Plex Mono",ui-monospace,Menlo,monospace;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
  color-scheme:dark;
  --bg:#000000; --surface:#121214; --surface2:#0b0b0d; --ink:#f3f4f6; --ink2:#cbd5e1; --ink3:#9ca3af; --line:#2a2b30;
  --uk:#0033a0; --uk2:#001640; --accent:#7ea6f5; --accent-soft:#16244a; --on-accent:#0a0f1a;
  --green:#34d399; --green-soft:#0f2a20; --yellow:#facc15; --yellow-soft:#332a0c; --red:#f08178; --red-soft:#3a1d1a;
  --shadow:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.3);
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500; --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767; --s9:#667085; --s10:#b08968;
  --t1:#7ea6f5; --t2:#5f87d6; --t3:#4a6cb3; --t4:#34528a;
  --map-mid:#243044; --map-pos:#34c27a; --map-neg:#e8675c; --map-seq:#7ea6f5;
}}
:root[data-theme="dark"]{
  color-scheme:dark;
  --bg:#000000; --surface:#121214; --surface2:#0b0b0d; --ink:#f3f4f6; --ink2:#cbd5e1; --ink3:#9ca3af; --line:#2a2b30;
  --uk:#0033a0; --uk2:#001640; --accent:#7ea6f5; --accent-soft:#16244a; --on-accent:#0a0f1a;
  --green:#34d399; --green-soft:#0f2a20; --yellow:#facc15; --yellow-soft:#332a0c; --red:#f08178; --red-soft:#3a1d1a;
  --shadow:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.3);
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500; --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767; --s9:#667085; --s10:#b08968;
  --t1:#7ea6f5; --t2:#5f87d6; --t3:#4a6cb3; --t4:#34528a;
  --map-mid:#243044; --map-pos:#34c27a; --map-neg:#e8675c; --map-seq:#7ea6f5;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.55 var(--sans);font-variant-numeric:tabular-nums;-webkit-font-smoothing:antialiased}
a{color:var(--accent)}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;touch-action:manipulation}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:6px}
.skiplink{position:absolute;left:-999px}.skiplink:focus{left:16px;top:8px;z-index:100;background:var(--surface);padding:8px 12px}
.pos{color:var(--green)!important}.neg{color:var(--red)!important}.mid{color:var(--yellow)!important}

.forwho{font-size:13px;opacity:.85;margin-top:6px!important}
.hero{background:radial-gradient(1100px 380px at 90% -30%,rgba(255,255,255,.16),transparent 60%),radial-gradient(800px 460px at -10% 130%,rgba(126,166,245,.35),transparent 60%),linear-gradient(135deg,var(--uk),var(--uk2));color:#fff}
.hero-in{max-width:1240px;margin:0 auto;padding:26px 16px 20px;display:flex;flex-wrap:wrap;gap:16px;align-items:center;justify-content:space-between}
.brand{display:flex;gap:14px;align-items:center}
.mark{height:56px;width:127px;flex:none}.mark path{fill:#fff;stroke:#0033a0;stroke-width:5;stroke-linejoin:round}.mark path.here{fill:#ffd166}.mark.cty{width:96px;height:96px}
@media (max-width:640px){.mark.cty{width:72px;height:72px}}
.mark path.one{fill:#fff;stroke:none}.markwrap{display:flex;flex-direction:column-reverse;align-items:center;gap:4px;flex:none}
.markname{color:#fff;font-weight:700;line-height:1.1;text-align:center;white-space:nowrap}.markname:empty{display:none}
@media (max-width:640px){.mark{height:38px;width:86px}.brand h1{font-size:26px}}
.brand h1{font-family:var(--serif);font-weight:600;font-size:30px;letter-spacing:-.01em;margin:0;line-height:1.1}
.brand h1 em{font-style:normal;font-weight:500;opacity:.85}
.brand p{margin:4px 0 0;color:#d6e0f5;font-size:14px;max-width:520px}
.actions{display:flex;gap:8px;flex-wrap:wrap}
.ghost{background:rgba(255,255,255,.1);border:1px solid rgba(255,255,255,.28);color:#fff;border-radius:10px;padding:10px 16px;min-height:44px;transition:background .2s}
.ghost:hover{background:rgba(255,255,255,.2)}
.menubtn{display:none}
@media (max-width:640px){
  .hero-in{padding:14px 16px 12px;gap:10px}.brand p{font-size:13px}
  .actions>button:not(.menubtn){display:none}.actions.open>button{display:inline-flex}.menubtn{display:inline-flex}
}
.ghost.solid{background:#fff;border-color:#fff;color:var(--uk);font-weight:600}
.sample{max-width:1240px;margin:12px auto 0;padding:0 16px}
.sample div{display:flex;flex-wrap:wrap;gap:8px 14px;align-items:center;justify-content:space-between;border:1px solid var(--line);background:var(--accent-soft);border-radius:12px;padding:10px 14px;font-size:14px}

.tabs{position:sticky;top:0;z-index:20;background:color-mix(in srgb,var(--surface) 90%,transparent);backdrop-filter:saturate(1.4) blur(10px);-webkit-backdrop-filter:saturate(1.4) blur(10px);border-bottom:1px solid var(--line)}
.tabs-in{max-width:1240px;margin:0 auto;padding:0 8px;display:flex;gap:2px;overflow-x:auto;scrollbar-width:none}
.tabs-in::-webkit-scrollbar{display:none}
.tab{flex:none;display:flex;align-items:center;gap:8px;background:none;border:0;border-bottom:3px solid transparent;padding:14px 11px 11px;color:var(--ink3);font-weight:500;font-size:15px;white-space:nowrap;min-height:48px;transition:color .2s,border-color .2s}
.tab:hover{color:var(--ink)}
.tab .n{display:inline-grid;place-items:center;width:24px;height:24px;border-radius:50%;border:1.5px solid currentColor;font-size:12px;font-family:var(--mono)}
.tab.done .n{background:var(--green-soft);border-color:var(--green);color:var(--green)}
.tab.skipped .n{border-style:dashed;color:var(--ink3)}
.tab[aria-selected=true]{color:var(--ink);border-bottom-color:var(--accent)}
.tab[aria-selected=true] .n{background:var(--accent);border-color:var(--accent);color:var(--on-accent);border-style:solid}

.layout{max-width:1240px;margin:0 auto;padding:24px 16px 40px;display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:24px;align-items:start}
@media (max-width:1000px){.layout{grid-template-columns:minmax(0,1fr);padding-bottom:120px}}
.panel{animation:enter .28s ease-out}
@keyframes enter{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
.eyebrow{font-family:var(--mono);font-size:12px;letter-spacing:.12em;text-transform:uppercase;color:var(--accent)}
.panel h2{font-family:var(--serif);font-weight:600;font-size:32px;line-height:1.15;letter-spacing:-.01em;margin:6px 0 6px}
.lede{color:var(--ink2);margin:0 0 20px;max-width:660px}
.card{background:var(--surface);border:1px solid var(--line);border-radius:18px;padding:22px;box-shadow:var(--shadow);margin-bottom:16px}
.card h3{font-family:var(--serif);font-weight:600;font-size:20px;margin:0 0 4px}
.card .sub{color:var(--ink3);font-size:14px;margin:0 0 14px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.grid3{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
@media (max-width:640px){.grid2,.grid3{grid-template-columns:1fr}}
label,.lbl{display:block;font-size:14px;font-weight:500;color:var(--ink2);margin:14px 0 6px}
.field{position:relative}
.field .pre{position:absolute;left:14px;top:50%;transform:translateY(-50%);color:var(--ink3);pointer-events:none}
.field .post{position:absolute;right:14px;top:50%;transform:translateY(-50%);color:var(--ink3);pointer-events:none}
select,input[type=number],input[type=text],input[type=password],input[type=date],textarea{width:100%;background:var(--surface2);border:1px solid var(--line);border-radius:12px;padding:12px 14px;min-height:48px;font-size:16px;transition:border-color .2s,box-shadow .2s}
select:focus,input:focus,textarea:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 4px var(--accent-soft)}
.field input.money{padding-left:30px;font-size:22px;font-weight:600}
.field input.cash{padding-left:30px}
.field input.pct{padding-right:34px}
.hint{font-size:13px;color:var(--ink3);margin:6px 0 0}
.field.amt{margin-top:8px;max-width:300px}.field.amt input{padding-left:28px}
@keyframes grow{from{transform:scaleX(0)}}
@keyframes draw{from{stroke-dashoffset:1}}
.panel>.card,.rec{animation:enter .35s ease-out backwards}
.panel>.card:nth-child(n+5),.rec:nth-child(2){animation-delay:.06s}.panel>.card:nth-child(n+6),.rec:nth-child(3){animation-delay:.12s}.panel>.card:nth-child(n+7),.rec:nth-child(n+4){animation-delay:.18s}
.part .track i{transform-origin:left;animation:grow .7s ease-out backwards}
.gArc{stroke-dasharray:1;animation:draw .9s ease-out}
.rec{transition:transform .15s,box-shadow .2s}.rec:hover{transform:translateY(-2px);box-shadow:var(--shadow)}
.btn{transition:border-color .2s,transform .15s}.btn:hover{border-color:var(--accent)}.btn:active{transform:scale(.97)}
.seg{display:inline-flex;background:var(--surface2);border:1px solid var(--line);border-radius:12px;padding:4px;gap:4px;flex-wrap:wrap}
.seg button{border:0;background:none;border-radius:9px;padding:10px 16px;min-height:44px;color:var(--ink2);font-weight:500;transition:background .2s,color .2s}
.seg button[aria-pressed=true]{background:var(--accent);color:var(--on-accent);box-shadow:var(--shadow)}
.seg button[disabled]{opacity:.45;cursor:not-allowed}
.stepper{display:flex;align-items:center;gap:12px;background:var(--surface2);border:1px solid var(--line);border-radius:14px;padding:12px 14px}
.stepper .t{flex:1}.stepper .t b{display:block}.stepper .t span{font-size:13px;color:var(--ink3)}
.stepper button{width:44px;height:44px;border-radius:50%;border:1px solid var(--line);background:var(--surface);font-size:22px;line-height:1;display:grid;place-items:center}
.stepper button:hover{border-color:var(--accent)}
.stepper output{min-width:28px;text-align:center;font-size:22px;font-weight:600}
.slider{margin:18px 0}
.slider .top{display:flex;justify-content:space-between;align-items:baseline;gap:8px}
.slider .top span{font-weight:500}.slider .top b{font-weight:600}.slider .top small{font-weight:500}
.slider .ends{display:flex;justify-content:space-between;font-size:12px;color:var(--ink3)}
input[type=range]{width:100%;accent-color:var(--accent);height:28px;margin:4px 0 0;cursor:pointer}
.presets{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}
.preset{border:1px solid var(--line);background:var(--surface2);border-radius:14px;padding:14px;text-align:left;min-height:44px;transition:border-color .2s,transform .15s}
.preset:hover{border-color:var(--accent)}.preset:active{transform:scale(.98)}
.preset b{display:block;font-size:15px}.preset span{display:block;font-size:13px;color:var(--ink3)}
.preset .big{font-family:var(--serif);font-size:24px;font-weight:600;color:var(--ink);margin-top:6px}
.preset[aria-pressed=true]{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 2px var(--accent)}
.preset[aria-pressed=true] span{color:var(--ink2)}
.mixbar{display:flex;height:8px;border-radius:4px;overflow:hidden;margin:8px 0 6px}
@media (max-width:640px){.presets{grid-template-columns:1fr}}
.bar{display:flex;height:26px;gap:2px;margin:14px 0 6px}
.bar div{min-width:3px;height:100%}
.bar div:first-child{border-radius:7px 0 0 7px}.bar div:last-child{border-radius:0 7px 7px 0}.bar div:only-child{border-radius:7px}
table{width:100%;border-collapse:collapse;font-size:15px}
td,th{padding:10px 6px;border-bottom:1px solid var(--line);text-align:right}
td:first-child,th:first-child{text-align:left}
th{font-size:12px;color:var(--ink3);font-weight:500;font-family:var(--mono);text-transform:uppercase;letter-spacing:.06em}
tr.total td{font-weight:600;border-bottom:0}
.sw{display:inline-block;width:11px;height:11px;border-radius:3px;margin-right:10px;vertical-align:-1px}
.chartwrap{position:relative}
svg{display:block;max-width:100%}
svg text{fill:var(--ink3);font-size:12px;font-family:var(--sans)}
.tip{position:absolute;pointer-events:none;background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:10px 12px;font-size:14px;box-shadow:var(--shadow);display:none;min-width:190px;z-index:3}
.legend{display:flex;gap:18px;flex-wrap:wrap;font-size:14px;color:var(--ink2);margin:8px 0}
.legend i{display:inline-block;width:16px;height:3px;border-radius:2px;margin-right:8px;vertical-align:middle}
.tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:14px}
@media (max-width:640px){.tiles{grid-template-columns:1fr}}
.tile{border:1px solid var(--line);background:var(--surface2);border-radius:14px;padding:14px}
.tile .l{font-size:13px;color:var(--ink3)}.tile .v{font-size:22px;font-weight:600;margin-top:2px}
.rowlist{display:grid;grid-template-columns:1.4fr 1fr .8fr 1fr 44px;gap:8px;align-items:center;margin-bottom:8px}
.rowlist.g3{grid-template-columns:1.6fr 1fr 1fr 44px}
.rowlist.head{font-size:12px;color:var(--ink3);font-family:var(--mono);text-transform:uppercase;letter-spacing:.06em;margin:16px 0 6px}
.rowlist input{min-height:44px;padding:9px 10px}
.icon{width:44px;height:44px;border-radius:12px;border:1px solid var(--line);background:var(--surface2);display:grid;place-items:center;color:var(--ink3)}
.icon:hover{color:var(--red);border-color:var(--red)}
@media (max-width:640px){.rowlist,.rowlist.g3{grid-template-columns:1fr 1fr 44px}.rowlist .nm{grid-column:1/-1}.rowlist.head{display:none}}
.btn{border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:10px 16px;min-height:44px;font-weight:500}
.btn:hover{border-color:var(--accent)}
.btn.primary{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}
.btn[disabled]{opacity:.45;cursor:not-allowed}
.callout{border-radius:14px;padding:14px 16px;background:var(--accent-soft);color:var(--ink);margin-top:14px}
.callout.warn{background:var(--red-soft);color:var(--red)}
.badge{display:inline-flex;align-items:center;gap:6px;font-size:12px;font-weight:500;padding:3px 10px;border-radius:99px;background:var(--green-soft);color:var(--green)}
.badge.mid{background:var(--yellow-soft);color:var(--yellow)}
.badge.low{background:var(--red-soft);color:var(--red)}
.bigrate{font-family:var(--serif);font-size:44px;font-weight:600;line-height:1;margin:8px 0}
.nav{display:flex;justify-content:space-between;align-items:flex-end;gap:12px;margin-top:8px}
.navr{display:flex;flex-direction:column;align-items:flex-end;gap:6px}
.skipbtn{background:var(--surface);border:1.5px solid var(--line);color:var(--ink2);font-size:16px;font-weight:600;border-radius:12px;padding:10px 18px;min-height:44px}
.skipbtn:hover{color:var(--ink);border-color:var(--ink3)}
.futbit[hidden],.nowrow[hidden]{display:none!important}
.nowrow{animation:enter .35s ease-out backwards}
.nowrow .zero{margin-top:8px;font-size:14px}
.cinfo{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:10px;margin-top:10px}
.cinfo div{border:1px solid var(--line);border-radius:10px;padding:10px 12px;background:var(--surface2)}
.cinfo span{display:block;font-size:12px;color:var(--ink3)}.cinfo b{font-size:17px}
.rec ul{margin:8px 0 0;padding-left:20px;color:var(--ink2);font-size:15px}.rec li{margin:3px 0}
.plan td.why{color:var(--ink3);font-size:13px}
.billcta{border:2px solid var(--accent);background:color-mix(in srgb,var(--accent-soft) 60%,var(--surface))}
.billcta>div{flex:1;min-width:220px}.bigbtn{font-size:17px;padding:14px 22px;min-height:52px;font-weight:600}
.billres .big{font-family:var(--serif);font-size:24px;font-weight:600;line-height:1.3;margin:4px 0 8px}
.billres.ok{border:2px solid var(--green);background:color-mix(in srgb,var(--green-soft) 50%,var(--surface))}
.billres.no{border:2px solid var(--yellow);background:color-mix(in srgb,var(--yellow-soft) 45%,var(--surface))}
.billres .when{font-size:13px;font-weight:600;color:var(--accent);text-transform:uppercase;letter-spacing:.04em}
#billKit,.billres{overflow-wrap:anywhere}
#billLetter{width:100%;border:1px solid var(--line);border-radius:12px;padding:12px;background:var(--surface2);color:var(--ink);resize:vertical}
#countyCard .when,#benCard .when{font-size:13px;font-weight:600;color:var(--accent);text-transform:uppercase;letter-spacing:.04em}
#countyCard h3{font-family:var(--serif);font-size:24px;margin:4px 0 12px}
.bestlist{list-style:none;padding:0;margin:8px 0 0;display:grid;gap:6px}
.bestlist li{display:flex;justify-content:space-between;gap:8px;padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:var(--surface2)}
.bestlist li.me{border-color:var(--accent);background:var(--accent-soft)}
.linkbtn{border:0;background:none;color:var(--accent);font-weight:600;padding:0;text-align:left}
.benlist{list-style:none;padding:0;margin:10px 0 0;display:grid;gap:10px}
.benlist li{border:1px solid var(--line);border-left:5px solid var(--green);border-radius:12px;padding:12px 14px;background:color-mix(in srgb,var(--green-soft) 35%,var(--surface))}
.benlist p{margin:4px 0 0;color:var(--ink2);font-size:15px}.benlist .how{color:var(--ink);font-weight:500}
.more{margin-top:16px}.more>summary{font-size:16px;font-weight:600;padding:14px 16px;border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--accent)}
.more[open]>summary{margin-bottom:6px}
.goalcard{border:2px solid var(--accent);background:color-mix(in srgb,var(--accent-soft) 55%,var(--surface))}
.goalcard h3{font-family:var(--serif);font-size:26px;line-height:1.25;margin:4px 0 12px}
@media (max-width:640px){.goalcard h3{font-size:21px}}
.miles{list-style:none;padding:0;margin:0;display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:10px}
.miles li{background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:12px 14px}
.miles span{display:block;font-size:13px;color:var(--ink3)}.miles b{font-family:var(--serif);font-size:20px}
.road{list-style:none;padding:0;margin:12px 0 0;position:relative}
.road li{position:relative;padding:0 0 18px 30px;border-left:2px solid var(--line);margin-left:9px}
.road li:last-child{border-left-color:transparent;padding-bottom:0}
.road li::before{content:"";position:absolute;left:-9px;top:2px;width:16px;height:16px;border-radius:50%;background:var(--surface);border:3px solid var(--accent)}
.road .when{font-size:13px;font-weight:600;color:var(--accent);text-transform:uppercase;letter-spacing:.04em}
.road h4{margin:2px 0 4px;font-size:17px}.road ul{margin:4px 0 0;padding-left:18px;color:var(--ink2);font-size:15px}.road li li{border:0;padding:0;margin:3px 0}.road li li::before{display:none}
@media (max-width:640px){.plan td:nth-child(5),.plan th:nth-child(5){display:none}.plan td,.plan th{padding-left:6px;padding-right:6px}}
.plan th:nth-child(2),.plan th:nth-child(3){white-space:nowrap}
.next{background:var(--accent);color:var(--on-accent);border:0;border-radius:12px;padding:12px 20px;min-height:48px;font-weight:600;display:inline-flex;gap:8px;align-items:center;transition:transform .15s,filter .2s}
.next:hover{filter:brightness(1.15)}.next:active{transform:scale(.98)}
details summary{cursor:pointer;color:var(--accent);font-size:14px;font-weight:500;margin-top:14px;min-height:32px}

/* Charts */
.sankey .link{transition:opacity .2s}
.sankey:hover .link{opacity:.25}.sankey .link:hover{opacity:.7!important}
.sankey .nl{fill:var(--ink);font-size:13px;font-weight:500}.sankey .nv{fill:var(--ink3);font-size:12px}
@media (max-width:640px){.sankey .nl{font-size:12px}.sankey .nv{font-size:11px}}
.donutwrap{display:grid;grid-template-columns:240px 1fr;gap:20px;align-items:center}
@media (max-width:640px){.donutwrap{grid-template-columns:1fr}.donutwrap svg{margin:0 auto}}
.donut path{transition:opacity .2s}.donut:hover path{opacity:.55}.donut path:hover{opacity:1}
.mapbox{max-width:640px;margin:0 auto;position:relative}
.map path{stroke:var(--surface);stroke-width:1;cursor:pointer;transition:opacity .15s}
.map path:hover{opacity:.75}
.map path.here{stroke:var(--ink);stroke-width:2.5}
.map.pan{cursor:grab;touch-action:none}.map.pan path{cursor:grab}.map.dragging,.map.dragging path{cursor:grabbing}
.zoom{position:absolute;right:6px;top:6px;display:grid;gap:6px;z-index:2}
.zoom button{width:40px;height:40px;border-radius:10px;border:1px solid var(--line);background:var(--surface);box-shadow:var(--shadow);font-size:20px;font-weight:600;display:grid;place-items:center}
.zoom button:hover{border-color:var(--accent)}
.ramp{height:10px;border-radius:5px;margin:8px 0 4px}
.ramp-l{display:flex;justify-content:space-between;font-size:12px;color:var(--ink3)}
.toplist{list-style:none;padding:0;margin:8px 0 0;display:grid;gap:6px}
.toplist li{display:flex;justify-content:space-between;gap:8px;padding:8px 12px;border:1px solid var(--line);border-radius:10px;background:var(--surface2)}
.toplist button{border:0;background:none;color:var(--accent);font-weight:500;padding:0}
.score{display:grid;grid-template-columns:220px 1fr;gap:20px;align-items:center}
@media (max-width:640px){.score{grid-template-columns:1fr}.score svg{margin:0 auto}}
.part{display:grid;grid-template-columns:1fr auto;gap:4px 12px;margin-bottom:10px}
.part .track{grid-column:1/-1;height:8px;border-radius:4px;background:var(--surface2);border:1px solid var(--line);overflow:hidden}
.part .track i{display:block;height:100%;border-radius:4px}
.part small{grid-column:1/-1;color:var(--ink3);font-size:13px}
.goal{display:grid;grid-template-columns:72px 1fr;gap:14px;align-items:center;padding:12px;border:1px solid var(--line);border-radius:14px;background:var(--surface2);margin-bottom:10px}
.goal b{display:block}.goal span{font-size:13px;color:var(--ink3)}
.drop{border:2px dashed var(--line);border-radius:14px;padding:22px;text-align:center;background:var(--surface2);transition:border-color .2s,background .2s}
.drop.over{border-color:var(--accent);background:var(--accent-soft)}
.drop img{max-height:160px;max-width:100%;border-radius:8px;margin-top:10px}
.progress{height:6px;border-radius:3px;background:var(--line);overflow:hidden;margin-top:10px}.progress i{display:block;height:100%;width:100%;background:var(--accent);transform-origin:left;transform:scaleX(0);transition:transform .2s}
.recs{display:grid;gap:12px}
.rec{display:grid;grid-template-columns:auto 1fr auto;gap:14px;align-items:start;border:1px solid var(--line);border-radius:14px;padding:16px;background:var(--surface)}
.rec.r{background:color-mix(in srgb,var(--red-soft) 45%,var(--surface))}.rec.y{background:color-mix(in srgb,var(--yellow-soft) 45%,var(--surface))}.rec.g{background:color-mix(in srgb,var(--green-soft) 45%,var(--surface))}
.rec .ic{width:34px;height:34px;border-radius:50%;display:grid;place-items:center;font-weight:700}
.rec.r .ic{background:var(--red-soft);color:var(--red)}.rec.y .ic{background:var(--yellow-soft);color:var(--yellow)}.rec.g .ic{background:var(--green-soft);color:var(--green)}
.rec h4{margin:0 0 4px;font-size:17px}.rec p{margin:0;color:var(--ink2);font-size:15px}
.rec .impact{font-family:var(--serif);font-weight:600;font-size:20px;text-align:right;white-space:nowrap}
.rec .impact small{display:block;font-family:var(--sans);font-size:12px;font-weight:500;color:var(--ink3)}
.rec .go{margin-top:10px}
@media (max-width:640px){.rec{grid-template-columns:auto 1fr}.rec .impact{grid-column:2;text-align:left}}

/* Summary dock */
.dock{position:sticky;top:76px}
.dock .card{padding:0;overflow:hidden}
.dock .head{background:linear-gradient(135deg,var(--uk),var(--uk2));color:#fff;padding:18px 20px}
.dock .head .l{font-family:var(--mono);font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:#d6e0f5}
.dock .head .v{font-family:var(--serif);font-size:40px;font-weight:600;line-height:1.1;margin-top:4px}
.dock .head .v.neg{color:#ffb4ab!important}.dock .head .v.pos{color:#8ff0bf!important}
.dock .head .s{font-size:13px;color:#d6e0f5}
.dock .rows{padding:6px 20px}
.dock .row{display:flex;justify-content:space-between;padding:9px 0;border-bottom:1px solid var(--line);font-size:15px}
.dock .row:last-child{border-bottom:0}.dock .row span{color:var(--ink2)}
.dock .future{margin:0 20px 20px;border-radius:14px;padding:14px;background:var(--accent-soft)}
.dock .future .l{font-size:13px;color:var(--ink2)}
.dock .future .v{font-family:var(--serif);font-size:28px;font-weight:600;color:var(--accent)}
.dock .bar{margin:4px 20px 0;height:10px}
.dock .where{font-size:13px;color:var(--ink3);padding:0 20px 14px}
.bump{animation:bump .35s ease-out}
@keyframes bump{0%{opacity:.4;transform:translateY(3px)}100%{opacity:1;transform:none}}
@media (max-width:1000px){
  .dock{position:fixed;left:0;right:0;bottom:0;top:auto;z-index:30}
  .dock .card{margin:0;border-radius:18px 18px 0 0;border-bottom:0}
  .dock .rows,.dock .future,.dock .bar,.dock .where{display:none}
  .dock .head{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:12px 16px calc(12px + env(safe-area-inset-bottom))}
  .dock .head .v{font-size:26px}
  .dock .mini{display:flex!important}
}
.dock .mini{display:none;gap:16px;text-align:right}
.dock .mini div{font-size:12px;color:#d6e0f5}.dock .mini b{display:block;font-size:16px;color:#fff}

.toasts{position:fixed;left:16px;bottom:16px;z-index:40;display:grid;gap:8px;max-width:360px;pointer-events:none}
@media (max-width:1000px){.toasts{left:12px;right:12px;bottom:88px;max-width:none}}
.toast{background:var(--uk2);color:#fff;border-radius:14px;padding:12px 14px;box-shadow:0 10px 30px rgba(0,0,0,.25);font-size:14px;display:flex;gap:10px;align-items:flex-start;animation:tin .25s ease-out}
.toast.out{animation:tout .18s ease-in forwards}
.toast .dot{width:8px;height:8px;border-radius:50%;margin-top:6px;flex:none;background:#9fb9f0}
.toast .dot.up{background:#5ee0a8}.toast .dot.down{background:#ffb4ab}
.toast.err{background:var(--red)}
@keyframes tin{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
@keyframes tout{to{opacity:0;transform:translateY(6px)}}

.scrim{position:fixed;inset:0;background:rgba(6,11,20,.5);z-index:50;opacity:0;pointer-events:none;transition:opacity .2s}
.scrim.on{opacity:1;pointer-events:auto}
.drawer{position:fixed;top:0;right:0;bottom:0;width:min(440px,100%);background:var(--surface);z-index:51;transform:translateX(100%);transition:transform .25s ease-out;display:flex;flex-direction:column;box-shadow:-10px 0 40px rgba(0,0,0,.2)}
.drawer.on{transform:none}
.drawer header{display:flex;justify-content:space-between;align-items:center;padding:18px 20px;border-bottom:1px solid var(--line)}
.drawer header h2{font-family:var(--serif);font-size:22px;margin:0}
.drawer .body{overflow:auto;padding:16px 20px 28px;flex:1}
.faq details{border-bottom:1px solid var(--line);padding:4px 0 10px}
.faq summary{color:var(--ink);font-size:15px;font-weight:600;margin-top:8px}
.faq p{margin:8px 0 0;color:var(--ink2);font-size:15px}
.chat{margin-top:20px;border:1px solid var(--line);border-radius:14px;padding:14px;background:var(--surface2)}
.chat .ans{white-space:pre-wrap;font-size:15px;margin-top:12px;padding:12px;border-radius:12px;background:var(--surface);border:1px solid var(--line)}
.consent{display:flex;gap:10px;align-items:flex-start;font-size:13px;color:var(--ink2);margin:10px 0}
.consent input{width:20px;height:20px;margin-top:2px;flex:none}

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

footer{max-width:1240px;margin:0 auto;padding:0 16px 48px;color:var(--ink3);font-size:13px;display:grid;gap:12px}
.sources{font-size:11px;line-height:1.5}.sources summary{font-size:12px;color:var(--ink3);margin-top:0;min-height:0}
.fine{font-size:12px;color:var(--ink3)}

#welcome{border:0;border-radius:20px;padding:26px;max-width:540px;width:calc(100% - 32px);background:var(--surface);color:var(--ink);box-shadow:0 20px 60px rgba(0,0,0,.35)}
#welcome::backdrop{background:rgba(0,20,60,.55)}
#welcome .when{font-size:13px;font-weight:600;color:var(--accent);text-transform:uppercase;letter-spacing:.04em}
#welcome h2{font-family:var(--serif);font-size:26px;line-height:1.2;margin:6px 0 10px}#welcome p{color:var(--ink2);margin:0 0 10px}
.welsteps{padding-left:22px;margin:10px 0 14px;display:grid;gap:8px}.welsteps li{color:var(--ink2)}.welsteps b{color:var(--ink)}
.exbar{position:sticky;top:0;z-index:40;display:flex;gap:12px;align-items:center;justify-content:space-between;flex-wrap:wrap;background:#ffd166;color:#0b1424;padding:10px 16px;font-size:15px}
.exbar[hidden]{display:none}
.exitbtn{background:#0033a0;color:#fff;border:0;border-radius:12px;padding:12px 18px;min-height:48px;font-size:16px;font-weight:700;box-shadow:0 2px 8px rgba(0,0,0,.25);cursor:pointer}
.exitbtn:hover{filter:brightness(1.2)}
.exbar>div{flex:1;min-width:220px;max-width:1000px}
@media (min-width:1100px){.exbar{flex-wrap:nowrap;justify-content:center;font-size:14px;padding:8px 16px}.exbar>div{flex:0 1 auto;min-width:0;max-width:none;white-space:nowrap}.exbar .exitbtn{min-height:40px;padding:8px 16px;white-space:nowrap}}
#report{display:none}
@media print{
  body{background:#fff;color:#000}
  body>*:not(#report){display:none!important}
  #report{display:block}.rep{padding:0}.rep .card{box-shadow:none}
  .rep,.rep *{-webkit-print-color-adjust:exact;print-color-adjust:exact}
  @page{margin:14mm}
}
</style>
</head>
<body>
<a class="skiplink" href="#panels">Skip to content</a>
<header class="hero">
  <div class="hero-in">
    <div class="brand">
      <div class="markwrap"><div class="markname" id="markName"></div><svg class="mark" id="mark" aria-hidden="true"></svg></div>
      <div><h1>CountyWise</h1><p>What your paycheck is really worth in every Kentucky county. Real local taxes, real county costs, and a clear plan for what to do next.</p><p class="forwho">For Kentucky households, especially families making every dollar count. For learning only, not financial advice.</p></div>
    </div>
    <div class="actions" id="actions">
      <button class="ghost menubtn" id="menuBtn" aria-expanded="false" aria-controls="actions">Menu</button>
      <button class="ghost solid" id="saveBtn">Save plan</button>
      <button class="ghost" id="openBtn" title="Opens a plan file you saved earlier">Open saved plan</button>
      <input id="openFile" type="file" accept=".html,.htm,.json,text/html,application/json" hidden>
      <button class="ghost" id="printBtn">Print report</button>
      <button class="ghost" id="exBtn">See an example</button>
      <button class="ghost" id="resetBtn">Start over</button>
      <button class="ghost" id="helpBtn" aria-controls="drawer" aria-expanded="false">Help</button>
    </div>
  </div>
</header>

<div class="exbar" id="exBar" hidden><div><b>You're viewing an example.</b> A single mom in Pikeville with two kids, earning $28,000, with a $4,200 hospital bill. Your own plan stays untouched.</div><button class="exitbtn" id="exExit">Exit Example</button></div>
<nav class="tabs" aria-label="Plan steps"><div class="tabs-in" role="tablist" id="tablist"></div></nav>

<div class="layout">
<main id="panels">

<section class="panel" id="p-location" role="tabpanel" aria-labelledby="t-location">
  <div class="eyebrow">Step 1 of 7</div><h2>Where in Kentucky do you live?</h2>
  <div class="card">
    <div class="mapbox chartwrap">
      <div class="zoom"><button id="zoomIn" aria-label="Zoom in on your county">+</button><button id="zoomOut" aria-label="Zoom out">−</button></div>
      <svg id="map" class="map" width="100%" role="img"></svg><div class="tip" id="mapTip"></div>
    </div>
    <p class="hint" id="panHint" style="text-align:center" hidden>Click and drag the map to move around.</p>
    <label for="cpCounty">Not sure where to tap? Pick your county</label><select id="cpCounty" data-k="liveCounty"></select>
    <p class="hint">Check your property tax bill, voter registration card or driver's license if you're not sure. Living in a city doesn't change your county.</p>
    <p class="sub" style="margin-top:14px">Where you <b>live</b> sets your rent, groceries, car and child care costs. Where you <b>work</b> sets most of your local wage tax.</p>
    <div class="lbl">Map color: typical monthly housing cost for your household</div>
    <div style="min-width:200px;max-width:300px"><div class="ramp" id="ramp"></div><div class="ramp-l"><span id="rampLo"></span><span id="rampHi"></span></div></div>
    <div class="lbl" id="hereLbl" style="margin-top:14px"></div><div class="cinfo" id="mapHere"></div>
    <p class="hint">Typical costs for your household size. Median income is for all households in the county.</p>
  </div>
  <div class="grid2">
    <div class="card"><h3>Home</h3>
      <label for="liveCounty">County</label><select id="liveCounty" data-k="liveCounty"></select>
      <label for="liveCity">City or town</label><select id="liveCity" data-k="liveCity"></select>
      <p class="hint" id="liveNote"></p></div>
    <div class="card"><h3>Work</h3>
      <label for="workCounty">County</label><select id="workCounty" data-k="workCounty"></select>
      <label for="workCity">City or town</label><select id="workCity" data-k="workCity"></select>
      <button class="btn" id="sameBtn" style="margin-top:12px">Same as home</button></div>
  </div>
  <div class="card">
    <div style="display:flex;justify-content:space-between;gap:12px;flex-wrap:wrap;align-items:flex-start">
      <div><h3>Your local wage tax</h3><div class="bigrate" id="lrBig"></div><div id="lrBadge"></div></div>
      <div style="text-align:right"><div class="sub" style="margin:0">Per month</div><div class="bigrate" id="lrMonth" style="font-size:30px"></div></div>
    </div>
    <p class="sub" id="lrWhy" style="margin-top:12px"></p>
    <details><summary>Know your exact rate? Enter it here</summary>
      <label for="localOverride">Your local rate (%)</label><input id="localOverride" data-k="localOverride" type="text" inputmode="decimal" placeholder="Leave blank to use our estimate">
      <p class="hint">Look for "OL tax" or "local" on your pay stub, or ask your city's finance office.</p></details>
  </div>
  <div class="nav"><span></span><div class="navr"><button class="skipbtn" data-skip="location">Skip this step</button><button class="next" data-go="income">Next: Income <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-income" role="tabpanel" aria-labelledby="t-income" hidden>
  <div class="eyebrow">Step 2 of 7</div><h2>Your income and household</h2>
  <p class="lede">Tell us who lives with you and what you make. We work out every tax and follow every dollar to where it goes.</p>
  <div class="card">
    <h3>Who lives with you?</h3>
    <div class="lbl" id="earnLbl">Who earns money?</div>
    <div class="seg" role="group" aria-labelledby="earnLbl"><button data-adults="1">Just me</button><button data-adults="2">Me and a partner</button></div>
    <div class="grid2" style="margin-top:14px">
      <div class="stepper"><div class="t"><b>Kids under 5</b><span>Need full day child care</span></div><button data-step="under5" data-d="-1" aria-label="One fewer young child">−</button><output id="o-under5" data-o="under5"></output><button data-step="under5" data-d="1" aria-label="One more young child">+</button></div>
      <div class="stepper"><div class="t"><b>Kids 5 to 17</b><span>Need care before and after school</span></div><button data-step="schoolAge" data-d="-1" aria-label="One fewer school age child">−</button><output id="o-schoolAge" data-o="schoolAge"></output><button data-step="schoolAge" data-d="1" aria-label="One more school age child">+</button></div>
    </div>
    <p class="hint" id="houseNote"></p>
  </div>
  <div class="card">
    <h3>What you earn</h3>
    <div class="grid2">
      <div><label for="income1">Your yearly pay, before taxes</label><div class="field"><span class="pre">$</span><input class="money" id="income1" data-k="income1" data-money type="text" inputmode="numeric" placeholder="Enter your yearly pay" autocomplete="off"></div></div>
      <div id="inc2wrap" class="inc2"><label for="income2">Partner's yearly pay, before taxes</label><div class="field"><span class="pre">$</span><input class="money" id="income2" data-k="income2" data-money type="text" inputmode="numeric" placeholder="0" autocomplete="off"></div></div>
    </div>
    <div class="grid2">
      <div><label for="k401">You put into your 401k</label><div class="field"><input class="pct" id="k401" data-k="k401" data-num type="number" min="0" max="50" step="1"><span class="post">%</span></div><p class="hint">Your work retirement account. It comes out before income tax.</p></div>
      <div><label for="match">Your employer adds</label><div class="field"><input class="pct" id="match" data-k="match" data-num type="number" min="0" max="25" step="0.5"><span class="post">%</span></div><p class="hint">The "match." Free money when you put in at least this much.</p></div>
    </div>
  </div>
  <div class="card">
    <h3>Where every dollar goes</h3>
    <p class="sub" id="payTitle"></p>
    <div class="chartwrap"><svg id="sankey" class="sankey" width="100%" height="420" role="img"></svg><div class="tip" id="sankeyTip"></div></div>
    <details><summary>See the tax breakdown</summary><table id="payTable"><tbody></tbody></table></details>
  </div>
  <div class="nav"><button class="btn" data-go="location">← Back</button><div class="navr"><button class="skipbtn" data-skip="income">Skip this step</button><button class="next" data-go="budget">Next: Budget <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-budget" role="tabpanel" aria-labelledby="t-budget" hidden>
  <div class="eyebrow">Step 3 of 7</div><h2>Your budget</h2>
  <p class="lede">Tell us what you spend in a normal month, one item at a time. We use it to build your recommended plan in the last step.</p>
  <div class="callout warn negwarn" hidden></div>
  <div class="card">
    <h3>How do you live now?</h3>
    <p class="sub">Slide to the range closest to what you spend, or type the exact amount. The next item opens when you finish one. Debt payments go in the Debt step.</p>
    <div id="nowRows"></div>
    <p class="hint" id="nowSum"></p>
  </div>
  <div class="card">
    <h3>Where your take home pay goes</h3>
    <p class="sub" id="budgetSub"></p>
    <div class="donutwrap">
      <div class="chartwrap"><svg id="donut" class="donut" width="240" height="240" viewBox="0 0 240 240" role="img"></svg><div class="tip" id="donutTip"></div></div>
      <table id="budgetTable"><thead><tr><th>Category</th><th>Month</th><th>Share</th></tr></thead><tbody></tbody></table>
    </div>
  </div>
  <div class="card">
    <h3>Upload a statement <span class="badge mid" style="vertical-align:middle;margin-left:6px">Optional</span></h3>
    <p class="sub">Upload a photo or screenshot of a bank or card statement. We read the purchases, sort them into categories, and compare them with your plan.</p>
    <div class="drop" id="drop">
      <b>Drop an image here</b> or <button class="btn" id="pickImg" style="margin-left:6px">Choose an image</button>
      <input type="file" id="imgFile" accept="image/*" hidden>
      <p class="hint">PNG or JPG. Screenshots from your banking app work best.</p>
      <div id="imgPrev"></div>
    </div>
    <div id="readBtns" style="display:none;margin-top:12px;gap:8px;flex-wrap:wrap">
      <button class="btn primary" id="readLocal">Read it on this device</button>
      <button class="btn" id="readAI">Read it with Claude AI (needs your key)</button>
    </div>
    <p class="hint">On this device: free text reading software (Tesseract.js) downloads from jsDelivr once, then runs inside your browser. Your image never leaves your device.</p>
    <div class="progress" id="ocrProg" hidden><i></i></div>
    <div id="importOut"></div>
  </div>
  <div class="nav"><button class="btn" data-go="income">← Back</button><div class="navr"><button class="skipbtn" data-skip="budget">Skip this step</button><button class="next" data-go="debt">Next: Debt <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-debt" role="tabpanel" aria-labelledby="t-debt" hidden>
  <div class="eyebrow">Step 4 of 7</div><h2>Get out of debt faster</h2>
  <p class="lede">List what you owe: student loans, car loans, credit cards. Minimum payments come out of your budget. Anything extra comes out of what you have left. Have a hospital or medical bill? There's a separate check for it below your debts.</p>
  <div class="callout warn negwarn" hidden></div>
  <div class="card">
    <h3>Your debts</h3>
    <p class="sub">Add each loan or card you're paying off. If you have none, skip to the next step.</p>
    <div class="lbl" id="stratLbl">Which debt should extra money go to first?</div>
    <div class="seg" id="strategy" role="group" aria-labelledby="stratLbl"><button data-s="avalanche">Highest interest first</button><button data-s="snowball">Smallest balance first</button></div>
    <div class="rowlist head"><span>Debt</span><span>Balance</span><span>Interest %</span><span>Min / month</span><span></span></div>
    <div id="debts"></div>
    <select id="addDebt" aria-label="Add a debt" style="max-width:260px"><option value="">+ Add a debt</option><option>Credit card</option><option>Student loan</option><option>Car loan</option><option>Personal loan</option><option>Medical bill</option><option>Buy now, pay later</option><option>Payday loan</option><option value=" ">Something else</option></select>
    <div class="slider"><div class="top"><span>Extra toward debt each month</span><b id="extraTxt"></b></div><input type="range" id="extra" data-k="extra" data-num min="0" max="2000" step="25" aria-label="Extra debt payment per month"></div>
    <div class="legend" id="debtLegend"></div>
    <div class="chartwrap"><svg id="debtChart" width="100%" height="260" role="img"></svg><div class="tip" id="debtTip"></div></div>
    <div class="tiles" id="debtTiles"></div>
    <div class="callout" id="debtDelta"></div>
  </div>
  <div class="card billcta" id="billCta"><h3>Have a hospital or medical bill?</h3><p class="sub">Most big Kentucky hospitals forgive part or all of a bill based on your income, but only if you ask. Check what you may really owe and get a letter to send.</p><button class="btn primary bigbtn" id="billOpen" aria-expanded="false" aria-controls="billBox">Check my hospital bill</button></div>
  <div id="billBox" hidden>
  <div class="card">
    <h3>Your bill</h3>
    <div class="grid2">
      <div><label for="billAmt">How much the bill says you owe</label><div class="field"><span class="pre">$</span><input class="money" id="billAmt" data-b="amt" type="text" inputmode="numeric" placeholder="Enter the amount" autocomplete="off"></div></div>
      <div><label for="billHosp">Which hospital sent it</label><select id="billHosp" data-b="hosp"></select></div>
    </div>
    <div class="grid2">
      <div><label for="billDate">Date on your first bill</label><input id="billDate" data-b="date" type="date"><p class="hint">It sets your deadlines. Leave it blank if you don't know.</p></div>
      <div><div class="lbl" id="insLbl">Your insurance</div><div class="seg" role="group" aria-labelledby="insLbl"><button data-ins="none">No insurance</button><button data-ins="ins">Insured, but I still owe</button><button data-ins="medicaid">Medicaid</button></div></div>
    </div>
    <p class="hint" id="billHH" style="margin-top:14px"></p>
  </div>
  <div class="card billres" id="billRes" aria-live="polite"></div>
  <div class="card" id="billKit" hidden>
    <h3>Your action kit</h3><p class="sub">Do these in order. Each step protects your chance at help.</p>
    <ol class="road" id="billSteps"></ol>
    <h3 style="margin-top:22px">Your letter to the hospital</h3>
    <p class="sub">Fill in the parts in [brackets], send it to the billing office, and keep a copy. Nothing you type here leaves your device.</p>
    <textarea id="billLetter" rows="18" readonly style="font-family:var(--mono);font-size:13px"></textarea>
    <div style="display:flex;gap:8px;flex-wrap:wrap;margin-top:10px"><button class="btn primary" id="copyLetter">Copy the letter</button><button class="btn" id="billToDebt">Add what's left to my plan</button></div>
  </div>
  </div>
  <div class="nav"><button class="btn" data-go="budget">← Back</button><div class="navr"><button class="skipbtn" data-skip="debt">Skip this step</button><button class="next" data-go="goals">Next: Goals <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-goals" role="tabpanel" aria-labelledby="t-goals" hidden>
  <div class="eyebrow">Step 5 of 7</div><h2>Your savings goals</h2>
  <p class="lede">Tell us what you have saved today and what you're saving for. We'll show when you'll get there.</p>
  <div class="card">
    <h3>What you have today</h3>
    <div class="grid2">
      <div><label for="startCash">Cash in savings and checking</label><div class="field"><span class="pre">$</span><input class="cash" id="startCash" data-k="startCash" data-money type="text" inputmode="numeric" placeholder="0"></div></div>
      <div><label for="startInvest">Retirement accounts and investments</label><div class="field"><span class="pre">$</span><input class="cash" id="startInvest" data-k="startInvest" data-money type="text" inputmode="numeric" placeholder="0"></div></div>
    </div>
    <p class="hint" id="netWorth"></p>
  </div>
  <div class="card">
    <h3>Goals</h3>
    <p class="sub" id="goalSub"></p>
    <div class="slider" style="margin-top:0"><div class="top"><span>Emergency fund: months of bills to keep</span><b id="efTxt"></b></div><input type="range" id="efMonths" data-k="efMonths" data-num min="1" max="12" step="1" aria-label="Emergency fund months"><div class="ends"><span>1 month</span><span>12 months</span></div></div>
    <div id="goalRings"></div>
    <div class="rowlist g3 head"><span>Goal</span><span>Cost</span><span>Saved so far</span><span></span></div>
    <div id="goals"></div>
    <select id="addGoal" aria-label="Add a goal" style="max-width:260px"><option value="">+ Add a goal</option><option>House down payment</option><option>Car</option><option>College</option><option>Wedding</option><option>Vacation</option><option>Moving costs</option><option>New baby</option><option value=" ">Something else</option></select>
  </div>
  <div class="nav"><button class="btn" data-go="debt">← Back</button><div class="navr"><button class="skipbtn" data-skip="goals">Skip this step</button><button class="next" data-go="invest">Next: Invest <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-invest" role="tabpanel" aria-labelledby="t-invest" hidden>
  <div class="eyebrow">Step 6 of 7</div><h2>Watch your money grow</h2>
  <p class="lede">Pick how you'd invest. Each choice uses real historical average returns, shown after inflation so the numbers are in today's dollars.</p>
  <div class="card">
    <div class="presets" id="portfolios"></div>
    <p class="callout" id="sameNote" hidden>All three mixes show the same total because nothing is being invested yet, so there's nothing for the mix to grow. Raise the <b>invest</b> slider below, or add a 401k in the Income step, to see how they differ.</p>
    <div class="grid2" style="margin-top:6px">
      <div class="slider"><div class="top"><span>Years ahead</span><b id="yearsTxt"></b></div><input type="range" id="years" data-k="years" data-num min="5" max="65" step="1" aria-label="Years ahead"></div>
      <div class="slider"><div class="top"><span id="investLbl">Of what you have left, invest</span><b id="investTxt"></b></div><input type="range" id="investShare" data-k="investShare" data-num min="0" max="100" step="5" aria-label="Share of savings invested"><div class="ends"><span>Keep as cash</span><span>Invest it all</span></div></div>
    </div>
    <div class="slider"><div class="top"><span>Raise what you invest each year by</span><b id="growthTxt"></b></div><input type="range" id="growth" data-k="growth" data-num min="0" max="10" step="0.5" aria-label="Yearly increase in what you invest"><div class="ends"><span>Same every year</span><span>10% more each year</span></div></div>
    <p class="hint" style="margin-bottom:12px">We assume your pay and spending stay the same every year, which is cautious. Expect raises? This grows what you put in each year, on top of inflation.</p>
    <div class="legend" id="projLegend"></div>
    <div class="chartwrap"><svg id="proj" width="100%" height="340" role="img"></svg><div class="tip" id="projTip"></div></div>
    <div class="tiles" id="projTiles"></div>
    <details><summary>Where these numbers come from</summary>
      <p class="hint">Average yearly returns from 1926 to 2022 using the total U.S. stock market and intermediate U.S. bonds: 30% stocks earned 7.0%, 60% stocks earned 8.6%, and 100% stocks earned 10.2% (source: Boldin, formerly NewRetirement). We subtract about 2.9% average inflation to show today's dollars. "Bad markets" and "good markets" are our own range around that average. Past returns don't promise future returns, and none of this recommends a specific investment.</p>
      <div class="grid3">
        <div><label for="rLow">Bad markets (%/yr)</label><input id="rLow" data-k="rLow" data-num type="number" step="0.1"></div>
        <div><label for="rExp">Average (%/yr)</label><input id="rExp" data-k="rExp" data-num type="number" step="0.1"></div>
        <div><label for="rHigh">Good markets (%/yr)</label><input id="rHigh" data-k="rHigh" data-num type="number" step="0.1"></div>
      </div>
    </details>
  </div>
  <div class="nav"><button class="btn" data-go="goals">← Back</button><div class="navr"><button class="skipbtn" data-skip="invest">Skip this step</button><button class="next" data-go="recommend">See my plan <span aria-hidden="true">→</span></button></div></div>
</section>

<section class="panel" id="p-recommend" role="tabpanel" aria-labelledby="t-recommend" hidden>
  <div class="eyebrow">Step 7 of 7</div><h2>Your plan: what to do next</h2>
  <p class="lede" id="recLede"></p>
  <div class="card goalcard" id="goalCard" hidden><div class="eyebrow">Your goal</div><h3 id="goalHead"></h3><ul class="miles" id="goalMiles"></ul></div>
  <div class="card">
    <div class="score"><svg id="gauge" width="220" height="150" viewBox="0 0 220 150" role="img"></svg><div id="scoreParts"></div></div>
  </div>
  <div class="card" id="countyCard" hidden><div class="when">Where you live</div><h3 id="countyHead"></h3><ul class="miles" id="countyFacts"></ul>
    <h3 style="margin-top:18px">Best counties for your pay</h3><ol class="bestlist" id="countyBest"></ol><p class="hint" id="countyNote"></p></div>
  <div class="card" id="benCard" hidden><div class="when">Help you may qualify for</div><p class="sub" id="benSub"></p><ul class="benlist" id="benList"></ul>
    <p class="hint">These are estimates from income limits only. Each program checks other rules too and makes the final decision. Sources: Kentucky Health Benefit Exchange (April 2026), USDA, the Federal Register and Kentucky's 2026 energy assistance plan.</p></div>
  <div class="card" id="roadCard" hidden><h3>Your next 12 months and beyond</h3><p class="sub">Do these in order. Each step builds on the one before it.</p><ol class="road" id="road"></ol></div>
  <details class="more" id="planMore"><summary id="moreSum">See every recommendation and your full budget comparison</summary>
  <div class="card" id="nowCmp" hidden><h3>What you do now vs. what we recommend</h3><p class="sub" id="nowCmpSub"></p><div style="overflow-x:auto"><table id="nowTable" class="plan"></table></div></div>
  <div class="recs" id="recs"></div>
  </details>
  <div class="callout" style="margin-top:16px">These suggestions are general education based on the numbers you entered, not professional financial advice. Talk with a qualified professional before big decisions.</div>
  <div class="nav" style="margin-top:16px"><button class="btn" data-go="invest">← Back</button><div class="navr" style="flex-direction:row"><button class="btn" id="printEnd">Print report</button><button class="next" id="saveEnd">Save my plan</button></div></div>
</section>
</main>

<aside class="dock" aria-label="Your live summary">
  <div class="card">
    <div class="head">
      <div><div class="l" id="dLeftL">Left each month</div><div class="v" id="dLeft" aria-live="polite"></div><div class="s" id="dLeftS"></div></div>
      <div class="mini"><div>Score<b id="mScore"></b></div><div class="futbit">In <span class="yrs"></span> yrs<b id="mFut"></b></div></div>
    </div>
    <div class="bar" id="dBar"></div>
    <div class="rows">
      <div class="row"><span>Pay before taxes</span><b id="dGross"></b></div>
      <div class="row"><span>Taxes</span><b id="dTax"></b></div>
      <div class="row"><span>401k (you + employer)</span><b id="d401"></b></div>
      <div class="row"><span>Take home pay</span><b id="dNet"></b></div>
      <div class="row"><span>Bills and spending</span><b id="dSpend"></b></div>
      <div class="row"><span>Investing</span><b id="dInv"></b></div>
      <div class="row"><span>Debt free in</span><b id="dDebt"></b></div>
      <div class="row"><span>Money health score</span><b id="dScore"></b></div>
    </div>
    <div class="future futbit"><div class="l">Could grow to in <span class="yrs"></span> years</div><div class="v" id="dFut"></div><div class="l" id="dFutS"></div></div>
    <div class="where" id="dWhere"></div>
  </div>
</aside>
</div>

<div class="toasts" id="toasts" aria-live="polite" role="status"></div>

<div class="scrim" id="scrim"></div>
<aside class="drawer" id="drawer" role="dialog" aria-modal="true" aria-labelledby="drawerTitle" hidden>
  <header><h2 id="drawerTitle">Questions and answers</h2><button class="icon" id="closeHelp" aria-label="Close help"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button></header>
  <div class="body">
    <div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:12px"><button class="btn" id="showWelcome">What does this site do?</button><button class="btn" id="helpEx">See an example</button></div>
    <label for="faqSearch" style="margin-top:0">Search</label><input id="faqSearch" type="text" placeholder="Try: local tax, emergency fund, 401k">
    <div class="faq" id="faq"></div>
    <div class="chat">
      <h3 style="font-family:var(--serif);margin:0 0 4px;font-size:18px">Ask Claude about your plan</h3>
      <p class="hint" style="margin:0">Optional. Uses your own Anthropic API key, kept only in this browser tab and never saved in your plan file. Educational answers only, never specific investment picks.</p>
      <label for="apiKey">Your Anthropic API key</label><input id="apiKey" type="password" autocomplete="off" spellcheck="false" placeholder="sk-ant-...">
      <label for="question">Your question</label><textarea id="question" rows="3" placeholder="Why is my local tax higher in Covington than Florence?"></textarea>
      <label class="consent"><input type="checkbox" id="consent"><span>I agree that pressing Ask sends my question and a summary of my plan numbers (income, household size, county, budget totals, debts and goals, no names) to <b>Anthropic</b>, the company that makes Claude.</span></label>
      <button class="btn primary" id="askBtn">Ask</button>
      <div id="answer"></div>
    </div>
  </div>
</aside>

<dialog id="welcome" aria-labelledby="welTitle">
  <div class="when">Welcome</div>
  <h2 id="welTitle">Your county changes what your paycheck is worth</h2>
  <p>CountyWise shows you how, county by county, and builds a money plan that fits where you live.</p>
  <ol class="welsteps">
    <li><b>Pick your county.</b> Real rent, groceries, child care and local wage taxes for your county.</li>
    <li><b>Add your pay, spending and debts.</b> See every tax, the credits you get back, and where every dollar goes.</li>
    <li><b>Get your plan.</b> Dated next steps, the best counties for your pay, help you may qualify for, and a check on any hospital bill.</li>
  </ol>
  <p class="hint">About 5 minutes. Everything stays on your device. For learning, not financial advice.</p>
  <div style="display:flex;gap:10px;flex-wrap:wrap"><button class="next" id="welGo">Start my plan <span aria-hidden="true">→</span></button><button class="btn" id="welEx" style="min-height:48px">See an example first</button></div>
</dialog>
<div id="report"></div>

<footer>
  <div class="fine">For learning only, not financial advice. Numbers are estimates.</div>
  <details class="sources"><summary>Outside services and code</summary>This page loads its fonts (IBM Plex) from Google Fonts. Only if you choose to, it downloads Tesseract.js (Apache License 2.0) from jsDelivr to read a statement image on your own device, and Anthropic's TypeScript SDK (MIT License) from jsDelivr to ask Anthropic's Claude a question with your own API key after you agree. Your plan never leaves your device otherwise, and everything else works without a key or a connection. No code from other projects was copied into this page.</details>
  <details class="sources"><summary>Sources</summary>County rent, utilities, food, car, child care, health and phone costs: Federal Reserve Bank of Atlanta, <a href="https://github.com/Research-Division/policy-rules-database">Policy Rules Database</a> (HUD Fair Market Rents, USDA food plans, ALICE cost data); rent updated to HUD's FY2026 Fair Market Rents, other costs 2024. 2026 federal brackets, standard deductions, child tax credit, Social Security wage base, and Kentucky's 3.5% rate and $3,360 standard deduction: IRS Rev. Proc. 2025 32 and Kentucky Department of Revenue, as compiled in <a href="https://github.com/PolicyEngine/policyengine-us">PolicyEngine US</a>. County median household income, 2024: U.S. Census Bureau, <a href="https://www.census.gov/programs-surveys/saipe.html">Small Area Income and Poverty Estimates</a>. Hospital financial assistance: each hospital system's own published policy or summary (UK HealthCare, Norton, Baptist Health, UofL Health, Owensboro Health, CHI Saint Joseph, Mercy Health, St. Elizabeth, Med Center Health, UK St. Claire, Pikeville Medical Center, UK King's Daughters, Ephraim McDowell, ARH, T.J. Regional Health), IRS rules for nonprofit hospitals (section 501(r)), Kentucky's hospital program (KRS 205.640) and the Kentucky Health Benefit Exchange's 2026 Medicaid limits. County wage tax rates for all 120 counties: <a href="https://kaco.org/media/7051/2026-databrief-occupationaltaxes.pdf">Kentucky Association of Counties, 2026 data brief</a>. City wage tax rates: each city's own website, ordinance or tax form, or its county's 2026 rate table (marked "Official rate"); the Kentucky Secretary of State's occupational tax database (marked "From state filings"); the Kentucky League of Cities' table of all 410 cities, FY2023 (marked "From the Kentucky League of Cities list"); otherwise 2026 payroll tax guides, news reports and older local documents (marked "From a tax guide"). School district wage taxes: Kentucky Department of Education, Tax Rates Levied 2025 to 2026. County populations for the 30,000 rule: U.S. Census Bureau 2024 estimates. Portfolio returns 1926 to 2022: <a href="https://help.boldin.com/en/articles/8430287-historical-rate-of-return-for-equity-and-bond-portfolios">Boldin (formerly NewRetirement)</a>. County map: U.S. Census Bureau boundaries via <a href="https://github.com/topojson/us-atlas">us-atlas</a>. City list: Wikipedia, List of cities in Kentucky. Only numbers and shapes were used from these sources; no code was copied. Fonts: IBM Plex.</details>
  <div>© 2026 Kai Sanfilippo and Grant Sumner. Built with help from Claude, an AI assistant, for the Kentucky PFM Challenge.</div>
</footer>

<script id="data">const DATA={"util":[2175,3395,3830,4119,3395,3830,4119,4660],"counties":{"Adair":{"rent":[6057,5545,7618,7329,5545,7618,7329,11372],"food":[[6237,5539],[5718,5078],[5458,4847],[5198,4616],[4938,4385],[4938,4385]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Allen":{"rent":[7593,6529,9238,8949,6529,9238,8949,11048],"food":[[7186,6382],[6587,5850],[6288,5584],[5989,5318],[5689,5052],[5689,5052]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Anderson":{"rent":[7305,8497,9346,9057,8497,9346,9057,13448],"food":[[6599,5860],[6049,5372],[5774,5128],[5499,4883],[5224,4639],[5224,4639]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Ballard":{"rent":[6669,5977,8458,8169,5977,8458,8169,10148],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Barren":{"rent":[6117,5389,7690,7401,5389,7690,7401,10220],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Bath":{"rent":[6057,5821,7618,7329,5821,7618,7329,10700],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Bell":{"rent":[6237,6937,7618,7329,6937,7618,7329,11036],"food":[[6418,5700],[5883,5225],[5616,4987],[5349,4750],[5081,4512],[5081,4512]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Boone":{"rent":[11421,11917,16042,15753,11917,16042,15753,21740],"food":[[7005,6221],[6422,5703],[6130,5444],[5838,5184],[5546,4925],[5546,4925]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Bourbon":{"rent":[8373,9565,11554,11265,9565,11554,11265,16232],"food":[[6779,6021],[6215,5519],[5932,5268],[5650,5017],[5368,4766],[5368,4766]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Boyd":{"rent":[8961,7825,8986,8697,7825,8986,8697,11972],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Boyle":{"rent":[6537,5389,7678,7389,5389,7678,7389,10676],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Bracken":{"rent":[9477,9709,13162,12873,9709,13162,12873,17876],"food":[[6915,6141],[6339,5629],[6051,5374],[5763,5117],[5475,4862],[5475,4862]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Breathitt":{"rent":[6057,6229,7618,7329,6229,7618,7329,11228],"food":[[6644,5900],[6090,5409],[5814,5163],[5537,4917],[5260,4671],[5260,4671]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Breckinridge":{"rent":[7077,5929,7618,7329,5929,7618,7329,10460],"food":[[6915,6141],[6339,5629],[6051,5374],[5763,5117],[5475,4862],[5475,4862]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Bullitt":{"rent":[11061,11041,13726,13437,11041,13726,13437,17960],"food":[[6870,6101],[6297,5592],[6011,5338],[5725,5084],[5439,4830],[5439,4830]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Butler":{"rent":[7725,6901,9370,9081,6901,9370,9081,13424],"food":[[6057,5379],[5552,4931],[5300,4707],[5048,4482],[4795,4258],[4795,4258]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Caldwell":{"rent":[6057,6505,7618,7329,6505,7618,7329,9152],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Calloway":{"rent":[7929,7381,10294,10005,7381,10294,10005,12356],"food":[[6824,6061],[6256,5556],[5972,5303],[5688,5050],[5403,4798],[5403,4798]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Campbell":{"rent":[9477,9709,13162,12873,9709,13162,12873,17876],"food":[[7412,6582],[6794,6034],[6486,5760],[6177,5485],[5868,5211],[5868,5211]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Carlisle":{"rent":[6153,5425,7750,7461,5425,7750,7461,9296],"food":[[5966,5299],[5469,4857],[5221,4637],[4972,4415],[4724,4195],[4724,4195]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Carroll":{"rent":[6441,6649,8158,7869,6649,8158,7869,10376],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Carter":{"rent":[6729,5653,7786,7497,5653,7786,7497,11372],"food":[[7321,6502],[6711,5960],[6406,5689],[6102,5418],[5797,5147],[5797,5147]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Casey":{"rent":[6057,6937,7618,7329,6937,7618,7329,9644],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Christian":{"rent":[9921,9493,12394,12105,9493,12394,12105,18068],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Clark":{"rent":[8373,9565,11554,11265,9565,11554,11265,16232],"food":[[6779,6021],[6215,5519],[5932,5268],[5650,5017],[5368,4766],[5368,4766]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Clay":{"rent":[7533,6373,7618,7329,6373,7618,7329,11372],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Clinton":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Crittenden":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Cumberland":{"rent":[6057,5497,7618,7329,5497,7618,7329,11060],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Daviess":{"rent":[9093,7957,11062,10773,7957,11062,10773,15056],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Edmonson":{"rent":[9465,9709,11650,11361,9709,11650,11361,13988],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Elliott":{"rent":[6057,5545,7618,7329,5545,7618,7329,9668],"food":[[7321,6502],[6711,5960],[6406,5689],[6102,5418],[5797,5147],[5797,5147]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Estill":{"rent":[6057,5497,7618,7329,5497,7618,7329,9728],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Fayette":{"rent":[9177,10597,12730,12441,10597,12730,12441,17852],"food":[[7141,6342],[6546,5813],[6248,5549],[5951,5284],[5654,5020],[5654,5020]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Fleming":{"rent":[6057,6361,7618,7329,6361,7618,7329,10472],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Floyd":{"rent":[6405,5689,8086,7797,5689,8086,7797,9704],"food":[[6779,6021],[6215,5519],[5932,5268],[5650,5017],[5368,4766],[5368,4766]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Franklin":{"rent":[7605,7681,10210,9921,7681,10210,9921,13784],"food":[[6734,5981],[6173,5482],[5893,5233],[5612,4984],[5332,4735],[5332,4735]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Fulton":{"rent":[6057,5329,7618,7329,5329,7618,7329,11372],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Gallatin":{"rent":[9477,9709,13162,12873,9709,13162,12873,17876],"food":[[5741,5098],[5262,4673],[5023,4461],[4784,4248],[4545,4036],[4545,4036]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Garrard":{"rent":[6369,7321,8038,7749,7321,8038,7749,9872],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Grant":{"rent":[7857,8089,10690,10401,8089,10690,10401,14216],"food":[[5741,5098],[5262,4673],[5023,4461],[4784,4248],[4545,4036],[4545,4036]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Graves":{"rent":[6057,5329,7618,7329,5329,7618,7329,11372],"food":[[5966,5299],[5469,4857],[5221,4637],[4972,4415],[4724,4195],[4724,4195]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Grayson":{"rent":[6921,5749,7618,7329,5749,7618,7329,10796],"food":[[5921,5259],[5428,4820],[5181,4601],[4935,4382],[4688,4163],[4688,4163]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Green":{"rent":[6057,6937,7618,7329,6937,7618,7329,10460],"food":[[6237,5539],[5718,5078],[5458,4847],[5198,4616],[4938,4385],[4938,4385]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Greenup":{"rent":[8961,7825,8986,8697,7825,8986,8697,11960],"food":[[7050,6261],[6463,5739],[6169,5479],[5876,5217],[5582,4957],[5582,4957]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Hancock":{"rent":[9093,7957,11062,10773,7957,11062,10773,15056],"food":[[6915,6141],[6339,5629],[6051,5374],[5763,5117],[5475,4862],[5475,4862]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Hardin":{"rent":[9141,7981,10354,10065,7981,10354,10065,15224],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Harlan":{"rent":[6057,5653,7618,7329,5653,7618,7329,10244],"food":[[6599,5860],[6049,5372],[5774,5128],[5499,4883],[5224,4639],[5224,4639]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Harrison":{"rent":[6057,6937,7618,7329,6937,7618,7329,10460],"food":[[7141,6342],[6546,5813],[6248,5549],[5951,5284],[5654,5020],[5654,5020]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Hart":{"rent":[6057,5461,7618,7329,5461,7618,7329,9524],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Henderson":{"rent":[8121,7441,10078,9789,7441,10078,9789,12500],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Henry":{"rent":[11061,11041,13726,13437,11041,13726,13437,17960],"food":[[6734,5981],[6173,5482],[5893,5233],[5612,4984],[5332,4735],[5332,4735]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Hickman":{"rent":[6057,5329,7618,7329,5329,7618,7329,11048],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Hopkins":{"rent":[6501,5845,8302,8013,5845,8302,8013,10808],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Jackson":{"rent":[6057,5329,7618,7329,5329,7618,7329,11048],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Jefferson":{"rent":[12081,12181,15046,14757,12181,15046,14757,19628],"food":[[6960,6181],[6380,5666],[6090,5409],[5800,5151],[5511,4893],[5511,4893]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Jessamine":{"rent":[8373,9565,11554,11265,9565,11554,11265,16232],"food":[[6734,5981],[6173,5482],[5893,5233],[5612,4984],[5332,4735],[5332,4735]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Johnson":{"rent":[6057,5329,7618,7329,5329,7618,7329,10196],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Kenton":{"rent":[9477,9709,13162,12873,9709,13162,12873,17876],"food":[[7141,6342],[6546,5813],[6248,5549],[5951,5284],[5654,5020],[5654,5020]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Knott":{"rent":[6705,5545,7618,7329,5545,7618,7329,9140],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Knox":{"rent":[6057,5629,7618,7329,5629,7618,7329,9140],"food":[[6373,5660],[5842,5188],[5577,4952],[5311,4716],[5046,4481],[5046,4481]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Larue":{"rent":[9141,7981,10354,10065,7981,10354,10065,15224],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Laurel":{"rent":[5877,5557,7906,7617,5557,7906,7617,10100],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Lawrence":{"rent":[6189,5473,7798,7509,5473,7798,7509,9512],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Lee":{"rent":[6057,5329,7618,7329,5329,7618,7329,10628],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Leslie":{"rent":[6057,6937,7618,7329,6937,7618,7329,11048],"food":[[6644,5900],[6090,5409],[5814,5163],[5537,4917],[5260,4671],[5260,4671]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Letcher":{"rent":[6057,6577,7618,7329,6577,7618,7329,11372],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Lewis":{"rent":[6057,6097,7618,7329,6097,7618,7329,11048],"food":[[6102,5419],[5594,4967],[5339,4742],[5085,4516],[4831,4290],[4831,4290]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Lincoln":{"rent":[6057,6769,7618,7329,6769,7618,7329,9140],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Livingston":{"rent":[6201,5701,7810,7521,5701,7810,7521,9368],"food":[[6599,5860],[6049,5372],[5774,5128],[5499,4883],[5224,4639],[5224,4639]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Logan":{"rent":[6177,5461,7618,7329,5461,7618,7329,11372],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Lyon":{"rent":[6057,5329,7618,7329,5329,7618,7329,9716],"food":[[6599,5860],[6049,5372],[5774,5128],[5499,4883],[5224,4639],[5224,4639]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Madison":{"rent":[7593,7501,8626,8337,7501,8626,8337,12800],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Magoffin":{"rent":[6057,6937,7618,7329,6937,7618,7329,9824],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Marion":{"rent":[6057,5329,7618,7329,5329,7618,7329,9548],"food":[[6237,5539],[5718,5078],[5458,4847],[5198,4616],[4938,4385],[4938,4385]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Marshall":{"rent":[6297,6625,7942,7653,6625,7942,7653,10628],"food":[[6599,5860],[6049,5372],[5774,5128],[5499,4883],[5224,4639],[5224,4639]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Martin":{"rent":[6057,5545,7618,7329,5545,7618,7329,9668],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Mason":{"rent":[5961,6445,8038,7749,6445,8038,7749,9992],"food":[[6102,5419],[5594,4967],[5339,4742],[5085,4516],[4831,4290],[4831,4290]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"McCracken":{"rent":[6969,6913,9514,9225,6913,9514,9225,11420],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"McCreary":{"rent":[6057,6937,7618,7329,6937,7618,7329,9644],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"McLean":{"rent":[9093,7957,11062,10773,7957,11062,10773,15056],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Meade":{"rent":[8985,7825,10834,10545,7825,10834,10545,15236],"food":[[6915,6141],[6339,5629],[6051,5374],[5763,5117],[5475,4862],[5475,4862]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Menifee":{"rent":[6057,5545,7618,7329,5545,7618,7329,10016],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Mercer":{"rent":[6057,5329,7618,7329,5329,7618,7329,11372],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Metcalfe":{"rent":[6057,5677,7618,7329,5677,7618,7329,9668],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Monroe":{"rent":[6057,5329,7618,7329,5329,7618,7329,10928],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Montgomery":{"rent":[6057,5329,7618,7329,5329,7618,7329,10460],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Morgan":{"rent":[6057,5329,7618,7329,5329,7618,7329,11216],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Muhlenberg":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Nelson":{"rent":[6513,5809,8230,7941,5809,8230,7941,12044],"food":[[6824,6061],[6256,5556],[5972,5303],[5688,5050],[5403,4798],[5403,4798]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Nicholas":{"rent":[6057,5329,7618,7329,5329,7618,7329,10844],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Ohio":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6057,5379],[5552,4931],[5300,4707],[5048,4482],[4795,4258],[4795,4258]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Oldham":{"rent":[13005,13237,16366,16077,13237,16366,16077,21344],"food":[[6734,5981],[6173,5482],[5893,5233],[5612,4984],[5332,4735],[5332,4735]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Owen":{"rent":[6837,6145,8698,8409,6145,8698,8409,11480],"food":[[5741,5098],[5262,4673],[5023,4461],[4784,4248],[4545,4036],[4545,4036]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Owsley":{"rent":[6057,5545,7618,7329,5545,7618,7329,10568],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Pendleton":{"rent":[9477,9709,13162,12873,9709,13162,12873,17876],"food":[[5741,5098],[5262,4673],[5023,4461],[4784,4248],[4545,4036],[4545,4036]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Perry":{"rent":[6777,6085,8602,8313,6085,8602,8313,10316],"food":[[6644,5900],[6090,5409],[5814,5163],[5537,4917],[5260,4671],[5260,4671]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Pike":{"rent":[7149,6781,9118,8829,6781,9118,8829,10940],"food":[[6644,5900],[6090,5409],[5814,5163],[5537,4917],[5260,4671],[5260,4671]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Powell":{"rent":[6057,5329,7618,7329,5329,7618,7329,11372],"food":[[6508,5780],[5966,5298],[5695,5058],[5424,4816],[5153,4576],[5153,4576]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Pulaski":{"rent":[6753,6061,8566,8277,6061,8566,8277,10268],"food":[[6373,5660],[5842,5188],[5577,4952],[5311,4716],[5046,4481],[5046,4481]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Robertson":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6915,6141],[6339,5629],[6051,5374],[5763,5117],[5475,4862],[5475,4862]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Rockcastle":{"rent":[6057,5545,7618,7329,5545,7618,7329,10496],"food":[[6192,5499],[5676,5041],[5418,4812],[5161,4582],[4903,4354],[4903,4354]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Rowan":{"rent":[5757,5893,7738,7449,5893,7738,7449,9896],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Russell":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Scott":{"rent":[8373,9565,11554,11265,9565,11554,11265,16232],"food":[[7141,6342],[6546,5813],[6248,5549],[5951,5284],[5654,5020],[5654,5020]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Shelby":{"rent":[10233,10333,11746,11457,10333,11746,11457,15668],"food":[[6870,6101],[6297,5592],[6011,5338],[5725,5084],[5439,4830],[5439,4830]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Simpson":{"rent":[7533,7045,9658,9369,7045,9658,9369,13412],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Spencer":{"rent":[11061,11041,13726,13437,11041,13726,13437,17960],"food":[[6870,6101],[6297,5592],[6011,5338],[5725,5084],[5439,4830],[5439,4830]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Taylor":{"rent":[6057,6937,7618,7329,6937,7618,7329,10736],"food":[[6237,5539],[5718,5078],[5458,4847],[5198,4616],[4938,4385],[4938,4385]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Todd":{"rent":[6057,5329,7618,7329,5329,7618,7329,10364],"food":[[6147,5459],[5635,5004],[5379,4777],[5123,4549],[4867,4322],[4867,4322]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Trigg":{"rent":[9921,9493,12394,12105,9493,12394,12105,18068],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Trimble":{"rent":[6369,6349,8038,7749,6349,8038,7749,11012],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Union":{"rent":[6225,5497,7834,7545,5497,7834,7545,9404],"food":[[6328,5620],[5801,5151],[5537,4917],[5274,4683],[5010,4449],[5010,4449]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Warren":{"rent":[9465,9709,11650,11361,9709,11650,11361,13988],"food":[[6554,5820],[6008,5335],[5735,5093],[5462,4850],[5189,4608],[5189,4608]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Washington":{"rent":[6621,5917,8386,8097,5917,8386,8097,10040],"food":[[6824,6061],[6256,5556],[5972,5303],[5688,5050],[5403,4798],[5403,4798]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Wayne":{"rent":[6057,5701,7618,7329,5701,7618,7329,11372],"food":[[6283,5580],[5759,5114],[5498,4882],[5236,4649],[4974,4417],[4974,4417]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]},"Webster":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[36.0,34.0,12.75],"health":[1686,4553,6389,707]},"Whitley":{"rent":[6057,5329,7618,7329,5329,7618,7329,9140],"food":[[6418,5700],[5883,5225],[5616,4987],[5349,4750],[5081,4512],[5081,4512]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Wolfe":{"rent":[6057,5605,7618,7329,5605,7618,7329,9140],"food":[[6463,5740],[5925,5261],[5656,5023],[5386,4783],[5117,4544],[5117,4544]],"car":[8308,8308,8526,8526,8526,8526],"care":[30.0,28.0,10.5],"health":[1686,4553,6389,707]},"Woodford":{"rent":[8373,9565,11554,11265,9565,11554,11265,16232],"food":[[7366,6542],[6753,5997],[6446,5724],[6139,5451],[5832,5179],[5832,5179]],"car":[8308,8308,8526,8526,8526,8526],"care":[54.0,46.0,17.25],"health":[1686,4553,6389,707]}},"years":{"rent":2025,"food":2024,"car":2024,"care":2024,"health":2024},"phone":[528,936],"broadband":920,"cities":{"Adair":["Columbia"],"Allen":["Scottsville"],"Anderson":["Lawrenceburg"],"Ballard":["LaCenter","Wickliffe","Barlow","Kevil"],"Barren":["Glasgow","Cave City","Park City"],"Bath":["Owingsville","Sharpsburg","Salt Lick"],"Bell":["Middlesboro","Pineville"],"Boone":["Florence","Union","Walton"],"Bourbon":["Paris","Millersburg","North Middletown"],"Boyd":["Ashland","Catlettsburg"],"Boyle":["Danville","Junction City","Perryville"],"Bracken":["Augusta","Brooksville","Germantown"],"Breathitt":["Jackson"],"Breckinridge":["Hardinsburg","Irvington","Cloverport"],"Bullitt":["Mount Washington","Shepherdsville","Hillview","Pioneer Village","Lebanon Junction","Hebron Estates","Fox Chase","Hunters Hollow"],"Butler":["Morgantown","Rochester","Woodbury"],"Caldwell":["Princeton","Fredonia"],"Calloway":["Murray","Hazel"],"Campbell":["Fort Thomas","Newport","Alexandria","Highland Heights","Cold Spring","Dayton","Bellevue","Southgate","Wilder","Silver Grove","Melbourne","Crestview","Mentor","Woodlawn","California"],"Carlisle":["Bardwell","Arlington"],"Carroll":["Carrollton","Ghent","Sanders","Worthville","Prestonville"],"Carter":["Grayson","Olive Hill"],"Casey":["Liberty"],"Christian":["Hopkinsville","Oak Grove","Pembroke","Crofton","LaFayette"],"Clark":["Winchester"],"Clay":["Manchester"],"Clinton":["Albany"],"Crittenden":["Marion"],"Cumberland":["Burkesville"],"Daviess":["Owensboro","Whitesville"],"Edmonson":["Brownsville"],"Elliott":["Sandy Hook"],"Estill":["Irvine","Ravenna"],"Fayette":["Lexington"],"Fleming":["Flemingsburg","Ewing"],"Floyd":["Prestonsburg","Martin","Wheelwright","Wayland","Allen"],"Franklin":["Frankfort"],"Fulton":["Hickman","Fulton"],"Gallatin":["Warsaw","Glencoe","Sparta"],"Garrard":["Lancaster"],"Grant":["Crittenden","Williamstown","Dry Ridge","Corinth"],"Graves":["Mayfield","Wingo"],"Grayson":["Leitchfield","Clarkson","Caneyville"],"Green":["Greensburg"],"Greenup":["Flatwoods","Russell","Raceland","Worthington","Greenup","South Shore","Wurtland","Bellefonte"],"Hancock":["Lewisport","Hawesville"],"Hardin":["Elizabethtown","Radcliff","Vine Grove","West Point","Upton","Sonora"],"Harlan":["Cumberland","Harlan","Evarts","Lynch","Loyall","Benham"],"Harrison":["Cynthiana","Berry"],"Hart":["Horse Cave","Munfordville"],"Henderson":["Henderson","Corydon","Robards"],"Henry":["Eminence","New Castle","Campbellsburg","Pleasureville","Smithfield"],"Hickman":["Clinton","Columbus"],"Hopkins":["Madisonville","Dawson Springs","Earlington","Nortonville","White Plains","Hanson","Mortons Gap","St. Charles","Nebo"],"Jackson":["McKee"],"Jefferson":["Louisville","Jeffersontown","St. Matthews","Shively","Lyndon","Middletown","Douglass Hills","Hurstbourne","Prospect","Indian Hills","Graymoor-Devondale","Anchorage","Windy Hills","Hurstbourne Acres","Worthington Hills","St. Regis Park","Audubon Park","West Buechel","Coldstream","Beechwood","Barbourmeade","Heritage Creek","Watterson Park","Northfield","Woodlawn Park","Lynnview","Rolling Hills","Bellemeade","Langdon Place","Fincastle","Plantation","Hollow Creek","Blue Ridge Manor","Woodland Hills","Meadow Vale","Rolling Fields","Green Spring","Strathmoor Village","Spring Valley","Seneca Gardens","Brownsboro Farm","Parkway Village","Glenview","Westwood","Murray Hill","Wellington","Hollyvilla","Bancroft","Houston Acres","Riverwood","Briarwood","Forest Hills","Norbourne Estates","Moorland","Richlawn","Kingsley","Norwood","Glenview Hills","Old Brownsboro Place","Strathmoor Manor","Bellewood","Brownsboro Village","Creekside","Goose Creek","Druid Hills","Spring Mill","Wildwood","Broeck Pointe","Manor Creek","Crossgate","Glenview Manor","Maryhill Estates","Thornhill","Meadowview Estates","Mockingbird Valley","Sycamore","Cambridge","Hills and Dales","Lincolnshire","Hickory Hill","Meadowbrook Farm","Ten Broeck"],"Jessamine":["Nicholasville","Wilmore"],"Johnson":["Paintsville"],"Kenton":["Covington","Independence","Erlanger","Elsmere","Fort Mitchell","Edgewood","Villa Hills","Taylor Mill","Fort Wright","Ludlow","Crescent Springs","Crestview Hills","Park Hills","Lakeside Park","Ryland Heights","Bromley","Fairview","Kenton Vale"],"Knott":["Hindman","Pippa Passes"],"Knox":["Barbourville"],"Larue":["Hodgenville"],"Laurel":["London"],"Lawrence":["Louisa"],"Lee":["Beattyville"],"Leslie":["Hyden"],"Letcher":["Jenkins","Whitesburg","Fleming-Neon"],"Lewis":["Vanceburg","Concord"],"Lincoln":["Stanford","Crab Orchard","Hustonville"],"Livingston":["Salem","Grand Rivers","Smithland","Carrsville"],"Logan":["Russellville","Auburn","Adairville","Lewisburg"],"Lyon":["Eddyville","Kuttawa"],"Madison":["Richmond","Berea"],"Magoffin":["Salyersville"],"Marion":["Lebanon","Loretto","Bradfordsville"],"Marshall":["Benton","Calvert City","Hardin"],"Martin":["Inez","Warfield"],"Mason":["Maysville","Dover","Sardis"],"McCracken":["Paducah"],"McCreary":[],"McLean":["Livermore","Calhoun","Island","Sacramento"],"Meade":["Brandenburg","Muldraugh","Ekron"],"Menifee":["Frenchburg"],"Mercer":["Harrodsburg","Burgin"],"Metcalfe":["Edmonton"],"Monroe":["Tompkinsville","Gamaliel","Fountain Run"],"Montgomery":["Mount Sterling","Jeffersonville","Camargo"],"Morgan":["West Liberty"],"Muhlenberg":["Central City","Greenville","Powderly","Drakesboro","Bremen","South Carrollton"],"Nelson":["Bardstown","Bloomfield","New Haven","Fairfield"],"Nicholas":["Carlisle"],"Ohio":["Beaver Dam","Hartford","Fordsville","Centertown","McHenry","Rockport"],"Oldham":["La Grange","Crestwood","Pewee Valley","Orchard Grass Hills","Goshen","River Bluff"],"Owen":["Owenton","Gratz"],"Owsley":["Booneville"],"Pendleton":["Falmouth","Butler"],"Perry":["Hazard","Buckhorn"],"Pike":["Pikeville","Coal Run Village","Elkhorn City"],"Powell":["Stanton","Clay City"],"Pulaski":["Somerset","Ferguson","Burnside","Science Hill","Eubank"],"Robertson":["Mount Olivet"],"Rockcastle":["Mount Vernon","Brodhead","Livingston"],"Rowan":["Morehead","Lakeview Heights"],"Russell":["Russell Springs","Jamestown"],"Scott":["Georgetown","Stamping Ground","Sadieville"],"Shelby":["Shelbyville","Simpsonville"],"Simpson":["Franklin"],"Spencer":["Taylorsville"],"Taylor":["Campbellsville"],"Todd":["Elkton","Guthrie","Trenton"],"Trigg":["Cadiz"],"Trimble":["Milton","Bedford"],"Union":["Morganfield","Sturgis","Uniontown","Waverly"],"Warren":["Bowling Green","Smiths Grove","Plum Springs","Woodburn","Oakland"],"Washington":["Springfield","Willisburg","Mackville"],"Wayne":["Monticello"],"Webster":["Providence","Sebree","Clay","Dixon","Slaughters","Wheatcroft"],"Whitley":["Corbin","Williamsburg"],"Wolfe":["Campton"],"Woodford":["Versailles","Midway"]},"countyTax":{"Adair":0.5,"Allen":1.0,"Anderson":0,"Ballard":1.5,"Barren":0,"Bath":2.0,"Bell":0,"Boone":0.8,"Bourbon":1.25,"Boyd":1.0,"Boyle":1.25,"Bracken":0,"Breathitt":2.0,"Breckinridge":0,"Bullitt":0,"Butler":1.0,"Caldwell":1.5,"Calloway":0,"Campbell":0.9,"Carlisle":0,"Carroll":1.5,"Carter":1.0,"Casey":0,"Christian":0,"Clark":1.5,"Clay":1.0,"Clinton":1.25,"Crittenden":1.5,"Cumberland":1.25,"Daviess":1.0,"Edmonson":0,"Elliott":1.0,"Estill":2.0,"Fayette":2.25,"Fleming":0,"Floyd":0,"Franklin":1.0,"Fulton":0,"Gallatin":1.0,"Garrard":2.0,"Grant":2.5,"Graves":1.0,"Grayson":0.5,"Green":0,"Greenup":0,"Hancock":1.6,"Hardin":1.0,"Harlan":0,"Harrison":1.5,"Hart":0.8,"Henderson":1.0,"Henry":0,"Hickman":1.0,"Hopkins":0.5,"Jackson":1.85,"Jefferson":1.25,"Jessamine":1.0,"Johnson":0.5,"Kenton":0.7,"Knott":0,"Knox":1.0,"Larue":0,"Laurel":1.0,"Lawrence":0,"Lee":0,"Leslie":1.0,"Letcher":0,"Lewis":0,"Lincoln":1.0,"Livingston":1.0,"Logan":0.75,"Lyon":0,"Madison":1.0,"Magoffin":1.0,"Marion":1.0,"Marshall":1.0,"Martin":2.0,"Mason":1.0,"McCracken":1.0,"McCreary":1.5,"McLean":1.0,"Meade":0,"Menifee":1.25,"Mercer":1.0,"Metcalfe":1.0,"Monroe":1.0,"Montgomery":2.0,"Morgan":1.5,"Muhlenberg":0,"Nelson":0.5,"Nicholas":1.0,"Ohio":1.25,"Oldham":0,"Owen":0,"Owsley":0,"Pendleton":1.0,"Perry":1.0,"Pike":1.0,"Powell":1.75,"Pulaski":1.0,"Robertson":1.5,"Rockcastle":1.5,"Rowan":1.5,"Russell":1.0,"Scott":1.0,"Shelby":1.0,"Simpson":1.25,"Spencer":0.8,"Taylor":1.0,"Todd":1.0,"Trigg":0,"Trimble":0,"Union":0.5,"Warren":1.0,"Washington":0.75,"Wayne":0.9,"Webster":0,"Whitley":1.0,"Wolfe":1.25,"Woodford":1.5},"map":{"w":1000,"h":440,"paths":{"Todd":"M294,415.8L304.4,344.2L305.3,349.5L322.8,348.8L331.3,346.2L330.3,415.5L323.3,415.6L294,415.8Z","Scott":"M635.2,131.8L650.8,118.8L656.4,111.8L659.3,108.5L663.5,118.3L672.5,128.3L675.8,140.6L674.4,143.3L680,155.8L651.3,168.8L650.3,171L647,166.3L647.5,161L639.9,161.6L637.6,157.8L635.2,131.8Z","Lee":"M745.2,266.2L754.6,250.7L756,245.8L765.9,237.6L769.2,237.4L771.1,237.4L782.9,245.5L795.7,250.2L788.1,272.2L782.4,271.5L780.6,266.6L774.9,271.3L767.8,269.8L766.4,274.2L755.1,275.5L748,270.3L745.2,266.2Z","McLean":"M273.2,248.8L284.6,242.8L303.9,253.1L325.6,262.2L333.2,263.2L324.7,276.5L325.2,287.2L315.7,287.6L310.5,293L299.2,291.2L292.1,285.7L290.7,275.2L292.1,270.2L288.8,261.7L286,258.5L274.7,256.5L273.2,248.8Z","Franklin":"M601.7,134.6L613.5,128L618.2,131L628.6,134L635.2,131.8L637.6,157.8L619.2,166.8L619.2,170.8L614,174.8L597.9,168.8L600.8,163.5L601.2,144.6L606.9,135.2L601.7,134.6Z","Edmonson":"M408.2,303L449.3,300.6L463.4,320.5L462.5,328.5L460.1,347.5L454.9,346.1L444.5,343.5L441.2,338.9L432.8,342.9L417.2,328.1L408.2,303Z","Carroll":"M574.8,75.6L578.6,76.1L597.9,63.7L605.9,77.4L609.7,80.4L604.5,84.6L591.3,91.3L579,93.1L573.4,94L571,86.3L557.3,68.2L567.2,67.9L574.8,75.6Z","Graves":"M100,394L100,365L114.7,365.7L143,365.9L143,397.7L142.5,439L138.7,439L99.6,438.7L100,394Z","Monroe":"M472.9,402.2L495,385.8L504,382.6L520.5,384L522.9,386.4L523.8,393.3L530,393.7L533.3,400.8L539.4,400.5L536.1,407.7L543.7,419.6L537,420.2L497.4,419.1L472.9,417.9L476.6,412.4L472.9,402.2Z","Owsley":"M748,270.3L755.1,275.5L766.4,274.2L767.8,269.8L774.9,271.3L780.6,266.6L782.4,271.5L788.1,272.2L793.8,287L791.9,290.9L792.4,300.7L791.9,308.6L794.7,313.4L785.7,307.7L778.2,296.9L774.9,300.3L761.2,298.4L756.5,292.9L752.2,281.9L748,277.1L748,270.3Z","Jackson":"M706.5,269.5L710.2,263.8L720.6,262.2L726.8,262.8L737.1,259.8L745.2,266.2L748,270.3L748,277.1L752.2,281.9L756.5,292.9L761.2,298.4L748.9,307.4L745.6,314.1L740,314.7L726.3,311.8L714.5,303.1L715.9,296.9L710.2,292.3L711.7,286.9L706,275.6L706.5,269.5Z","Whitley":"M693.7,365.3L698,362.5L701.7,366L703.6,362.9L708.8,366.3L716.4,361.2L720.6,363.6L723.9,380.4L729.1,386.4L734.8,389.3L734.3,396.3L738.1,401.5L748.9,408.2L738.6,415.1L741.9,424.8L734.3,424.3L702.7,423.9L692.3,409.9L690.4,396.3L686.6,392.7L687.6,383.3L691.4,379.6L690.4,374.4L693.7,365.3Z","Hardin":"M433.7,257.8L449.7,223.7L468.6,220.4L472.9,210.9L470,190.4L477.1,188.9L478.1,190.5L481.8,191.6L482.3,199.8L488.9,199.3L494.1,208.6L493.6,213.7L504,221.6L505.4,227.7L511.6,234.7L504.5,247.7L496,252.8L493.2,260.9L486.1,265.9L483.7,283.2L463.4,281.6L462.5,273.9L454.9,262.1L446.4,264.2L439.4,260.8L437.5,256.4L433.7,257.8Z","Breckinridge":"M383.7,216.5L391.2,212.3L392.2,203.3L403,202L400.7,196.6L400.7,185.7L405.4,182.7L413.4,190.2L437.9,210.7L449.7,223.7L433.7,257.8L423.3,258.8L424.3,262.9L415.8,262.2L402.5,252.8L399.2,258.4L394.1,256.8L391.7,262.6L385.6,253.5L385.6,246.4L387.9,247.5L380.8,224.7L383.7,216.5Z","Union":"M202.9,223.6L213.8,228.1L219.4,221.4L214.7,211.7L216.6,206.6L231.2,229.7L238.8,235.3L239.3,245.1L241.6,250.2L232.7,260.1L215.7,276.6L207.2,272.2L204.8,265.5L198.7,272.3L197.3,268.5L189.2,260.9L185.9,246L191.1,238L199.2,233L202.9,223.6Z","Wayne":"M592.7,379.7L606.4,370.2L608.3,362.9L613.5,365.3L622.9,356.6L631.4,363.3L639.9,359.5L644.2,360.5L651.3,373.4L656.9,378.3L656.4,388.8L650.8,390.4L649.4,394.5L644.2,395.8L644.2,399.5L630.5,422.1L604.5,420.1L601.2,418.6L601.2,409.9L598.4,403.1L600.8,396.7L597.9,388.3L592.7,379.7Z","Shelby":"M563.9,130.9L601.7,134.6L606.9,135.2L601.2,144.6L600.8,163.5L597.9,168.8L595.1,178.2L588,184.1L570.6,175.4L545.5,165.8L547.9,146.4L539.9,142.9L550.3,139.2L558.8,138.9L563.9,130.9Z","Warren":"M417.2,328.1L432.8,342.9L441.2,338.9L444.5,343.5L454.9,346.1L447.9,367.2L442.7,371.6L434.6,374.2L435.1,377.3L416.2,393.4L417.2,388.3L393.1,384.4L389.3,375.7L381.3,356.3L388.9,331.9L387.9,326.2L404.4,324.7L408.2,330.9L417.2,328.1Z","Rockcastle":"M673.9,275.6L683.3,277.8L687.1,266.8L692.8,267.1L697.5,270.8L706.5,269.5L706,275.6L711.7,286.9L710.2,292.3L715.9,296.9L714.5,303.1L713.1,306L704.1,309.7L704.1,316L699.4,316.5L693.3,328.1L694.7,331.1L666.8,301.7L673.9,275.6Z","Hancock":"M341.2,201.9L350.6,199.8L357.2,192.4L362.4,190.5L365.3,192.1L370.9,204.8L375.6,207.9L380.4,204.3L385.1,205.8L383.7,216.5L380.8,224.7L387.9,247.5L385.6,246.4L361.5,233.8L362.4,224.9L357.2,216.7L349.7,217.3L352.1,209.9L347.3,205.3L339.8,207.3L341.2,201.9Z","Casey":"M591.3,287.6L595.6,287.9L596,265.8L600.8,267.6L614.4,267.9L621.5,265.2L619.6,278.8L621,285.3L628.1,291.5L637.6,296.4L639.9,306.6L637.6,308.7L638,316.7L614.4,336.9L607.4,339.4L595.6,325.4L593.7,313.6L579.5,304.7L584.2,292.4L591.3,287.6Z","Jessamine":"M639.5,213.2L646.1,189.6L655,192.5L669.7,200.2L673.4,205.3L675.3,215.6L668.7,216.7L672,222.9L663.5,228.6L657.9,235.3L647.9,225.4L651.7,222.9L643.7,219.2L638.5,220.9L639.5,213.2Z","Henry":"M560.2,108.5L564.4,107.9L579,93.1L591.3,91.3L600.8,98.7L597.5,105.5L604.1,105.1L602.6,109.4L606.9,111.6L605.9,117.6L616.8,121.2L614.9,128L618.2,131L613.5,128L601.7,134.6L563.9,130.9L558.3,123.2L555.9,114.1L560.2,108.5Z","Cumberland":"M541.8,366.6L570.6,368.7L564.9,373.2L570.1,380.6L572.9,380.4L568.7,398.7L562.5,418.4L543.7,419.6L536.1,407.7L539.4,400.5L533.3,400.8L530,393.7L523.8,393.3L522.9,386.4L525.7,383.1L521.9,377.4L527.6,381L534.7,378.3L538.9,373.9L541.8,366.6Z","Hopkins":"M231.2,298L260,279.6L272.8,275.3L288.8,261.7L292.1,270.2L290.7,275.2L292.1,285.7L299.2,291.2L292.6,304.9L288.3,304.4L287.4,312.8L297.8,324.4L294.5,330.2L289.3,334.4L274.2,335.4L269.9,338.8L248.7,331.5L239.7,321.5L232.7,316.3L232.2,307.6L226.5,302.9L231.2,298Z","Johnson":"M865.5,196.2L870.7,190.2L886.3,195.6L906.6,208.2L915.1,210.3L907.5,214.9L910.8,219.7L907,225.6L909.9,227.1L911.3,236.7L895.2,230.7L881.1,235.3L877.3,239.5L872.1,237.4L870.7,224.3L865.5,220.4L863.6,213.6L869.3,204.8L865.5,196.2Z","Knott":"M871.2,272.8L874,275.5L886.3,278.8L885.8,287.5L892.9,285L896.2,287.6L895.2,297.7L896.6,305.1L902.3,308.8L899.5,311.3L888.2,311.7L880.6,316.1L878.2,320.3L866.9,327.7L864.1,323.8L857,320.4L855.6,315.7L849,316.3L847.6,311.7L849.5,301.1L848,289L846.6,280.3L856.1,268.9L860.3,272.2L871.2,272.8Z","Knox":"M720.6,363.6L728.6,358.2L738.1,360L741.9,356.9L742.8,350.2L749.9,347.2L757,351.8L762.2,350.1L767.3,355.2L780.1,363L786.7,363.6L790,367.6L787.6,372.2L774.4,380.4L766.9,389.3L760.7,389.4L757.9,398.1L748.9,408.2L738.1,401.5L734.3,396.3L734.8,389.3L729.1,386.4L723.9,380.4L720.6,363.6Z","Lawrence":"M861.3,189.1L866.4,181.9L878.7,171.5L874,161.3L879.7,157.7L883.4,158.7L891.5,149.9L899,150.9L903.7,146.9L915.1,146.2L916,149.3L915.5,161.8L911.8,161.8L911.8,167.3L918.8,172.5L923.5,178.9L927.8,190.4L934.9,193.5L930.2,199.3L925.4,196.5L919.3,197.9L915.1,210.3L906.6,208.2L886.3,195.6L870.7,190.2L865.5,196.2L861.3,189.1Z","Madison":"M663.5,228.6L672,222.9L668.7,216.7L675.3,215.6L678.6,211.6L681.9,215.9L684.8,213.7L682.9,206.6L688.5,208.2L697,204L698,210.7L708.4,210.3L722,214.7L716.8,221.3L723,223.3L720.2,234.3L721.1,245.4L715.9,249.7L720.6,262.2L710.2,263.8L706.5,269.5L697.5,270.8L692.8,267.1L687.1,266.8L683.8,257.9L676.3,249.5L663.5,228.6Z","Lewis":"M829.2,87.7L846.2,86L848.5,79.7L858.4,73.1L861.3,76.9L854.6,85.3L854.6,91.5L848,101.4L842.4,106.7L832.9,119.5L833.9,134L819.3,137.3L809.8,124.5L804.6,126.9L802.7,124.1L787.6,118.6L785.3,106.9L779.6,103.1L782,88.8L779.1,84.6L783.4,76.7L795.7,73.6L802.7,78.1L816,81L821.1,84.4L823.5,90.5L829.2,87.7Z","Livingston":"M132.6,343.2L142.5,345.1L146.3,344.1L151,331.4L147.7,322L139.7,312.7L138.7,309.1L143,299.9L143.9,292L152.4,285.9L159.5,289L165.2,290.2L168,300.6L177.9,311L180.7,319.8L177.9,326L181.2,331.8L176.5,342.8L177,351.6L179.3,356.3L175.1,359.3L166.1,348.2L158.6,345.6L150.5,347.9L143.5,352.5L137.3,350.5L132.6,343.2Z","McCracken":"M84,318.4L84.9,318.7L101,325L107.6,330.5L124.1,336.2L132.6,343.2L137.3,350.5L143.5,352.5L143,365.9L114.7,365.7L100,365L99.6,363.9L84,318.4Z","Harlan":"M799.9,373.6L810.3,374.4L811.7,369.4L821.6,366.2L830.1,361.5L833.9,355.8L840.5,352.8L848,356L844.3,363.5L859.4,358.9L872.1,353.6L881.5,360.6L883,368.3L880.1,374L868.3,379.9L854.6,380.4L847.1,391.8L846.2,399L838.6,399.5L823,404.5L807.5,411.7L803.7,411.9L803.7,406.5L798.5,400.5L800.4,392.3L797.1,388.3L800.8,381.3L799.9,373.6Z","Magoffin":"M863.6,213.6L865.5,220.4L870.7,224.3L872.1,237.4L871.2,243.7L876.8,250L878.7,262.5L877.8,271.8L874,275.5L871.2,272.8L861.7,265.1L862.7,259.4L858.9,259.2L852.3,251.4L846.6,255.5L841.4,249.7L831.5,245.1L829.6,238L832.5,232.7L828.7,228.6L834.4,225.1L836.7,220.3L849.5,212.9L847.1,207.8L856.5,211.9L859.8,209.2L863.6,213.6Z","Martin":"M915.1,210.3L919.3,197.9L925.4,196.5L930.2,199.3L933.5,206.9L940.5,209.6L940.1,214.5L946.2,223.2L950.9,225.9L951.9,233.3L946.2,233.6L941.5,238L944.8,240.5L942.4,244.8L935.8,245.3L927.3,241L921.7,242.5L911.3,236.7L909.9,227.1L907,225.6L910.8,219.7L907.5,214.9L915.1,210.3Z","Metcalfe":"M503.5,328.1L511.1,326L518.2,335.5L531.9,338.1L535.2,355L543.2,363.9L541.8,366.6L538.9,373.9L534.7,378.3L527.6,381L521.9,377.4L525.7,383.1L522.9,386.4L520.5,384L504,382.6L501.7,338.1L499.3,333.4L503.5,328.1Z","Nicholas":"M707.4,128.6L719.2,114.1L731.5,118.5L735.3,117.4L739.5,120.1L743.7,130.5L749.4,130.2L754.6,138L752.7,141L735.7,158.4L734.3,154L729.1,154.7L724.4,151.3L725.3,147.7L720.2,147.3L710.7,131.3L707.4,128.6Z","Perry":"M792.4,300.7L805.1,293.4L811.2,300.1L814.1,300.1L820.7,293.3L828.7,290L835.8,282.6L838.1,287.5L848,289L849.5,301.1L847.6,311.7L849,316.3L855.6,315.7L857,320.4L864.1,323.8L856.5,335.7L858.4,345.9L854.6,349.2L857,353.3L848,356L840.5,352.8L842.4,339.2L834.4,333.5L837.7,327.2L830.6,322.4L821.6,318.8L817.8,307.1L811.7,303L803.7,307.6L797.5,317.1L794.7,313.4L791.9,308.6L792.4,300.7Z","Larue":"M511.6,234.7L517.2,240.7L523.4,241.1L522.4,250.1L525.7,250.2L519.1,264.6L527.1,269.5L528.6,264.4L532.8,264.2L535.2,265.1L539.9,279L535.6,276.1L531.9,280.9L524.3,278.3L517.7,277.9L514.9,286.2L483.7,283.2L486.1,265.9L493.2,260.9L496,252.8L504.5,247.7L511.6,234.7Z","Pike":"M902.3,308.8L907.5,305.3L909.9,297.9L908,294.9L914.1,292L918.4,282.2L916.9,272.8L913.6,272.6L916.9,249.7L915.1,245L921.7,242.5L927.3,241L935.8,245.3L942.4,244.8L944.8,240.5L941.5,238L946.2,233.6L951.9,233.3L957.1,245L964.1,246.5L967.4,252.5L971.7,252.2L975,257.9L978.8,258.1L980.2,263.4L993.4,267.6L1000,267.1L954.2,307.1L949,312.3L931.6,317.8L923.1,322.5L921.2,323.7L913.2,315.1L907.5,318.5L899.5,311.3L902.3,308.8Z","Powell":"M737.1,201.8L748.5,206L757,206.9L763.1,203.9L765.5,207.6L781,219.3L771.1,237.4L769.2,237.4L762.2,230.7L756.5,232.6L755.1,229.3L745.2,230.3L737.6,223.4L737.6,216L732.4,217.3L733.8,203.9L737.1,201.8Z","Trigg":"M185.9,378.3L206.2,371.2L222.7,362.9L225.6,364.5L237.8,360.5L242.1,355.9L251.5,361.9L250.1,376.4L249.6,396.8L246.8,416.5L226.1,417.1L226.5,412.1L197.7,409.7L192.1,398.3L185.9,378.3Z","Fleming":"M741.9,108.5L751.3,114.5L779.6,103.1L785.3,106.9L787.6,118.6L802.7,124.1L804.6,126.9L798.5,132.2L799.9,136.5L797.5,145.6L780.6,159.1L773,155.6L773.5,151.4L766.4,143L758.8,143.9L752.7,141L754.6,138L749.4,130.2L743.7,130.5L739.5,120.1L735.3,117.4L741.9,108.5Z","Bath":"M735.7,158.4L752.7,141L758.8,143.9L766.4,143L773.5,151.4L773,155.6L780.6,159.1L786.2,162.3L782.4,165.5L795.2,170.5L793.8,174.5L803.2,177.1L798.5,181.9L788.6,180.5L789.1,186.4L783.9,189.1L777.7,185.7L764.5,190.5L758.8,183.4L756.5,176.8L748.5,167.7L736.2,164L735.7,158.4Z","Clay":"M740,314.7L745.6,314.1L748.9,307.4L761.2,298.4L774.9,300.3L778.2,296.9L785.7,307.7L794.7,313.4L797.5,317.1L798,322.4L791.9,328.5L791.4,343.1L797.1,355.6L797.1,366.5L786.7,363.6L780.1,363L767.3,355.2L762.2,350.1L757,351.8L749.9,347.2L750.8,341.1L748,336.5L742.3,337.5L736.7,328.2L740.4,322L740,314.7Z","Crittenden":"M159.5,289L167.5,282L173.2,280.5L195.8,277.8L198.7,272.3L204.8,265.5L207.2,272.2L215.7,276.6L214.7,285.6L219.4,290.2L227,286.5L227.5,294L233.1,293.3L200.1,316.8L194.9,319.4L194.4,326.4L191.1,330.5L182.6,335.4L181.2,331.8L177.9,326L180.7,319.8L177.9,311L168,300.6L165.2,290.2L159.5,289Z","Fulton":"M32.1,417.4L41.1,428.5L47.2,425.9L52.4,414.2L56.2,414.5L71.7,423.9L83.1,424.1L87.8,426.5L97.2,438.7L75.5,438.9L35.9,438L29.7,438.7L20.3,439.5L26.4,419.2L32.1,417.4ZM11.3,439.7L4.2,439.6L0,431.3L1.9,427.1L11.8,427.3L14.2,434.3L11.3,439.7Z","Boyd":"M908,106.4L914.6,111.1L917.4,120.2L916.9,133L920.7,138.2L920.2,146.4L916,149.3L915.1,146.2L903.7,146.9L899,150.9L891.5,149.9L892.9,132.9L894.3,130L888.2,128.2L894.8,118.3L908,106.4Z","Carlisle":"M62.3,365.6L64.7,370.3L73.6,367.9L76.9,369.6L86.4,365.9L99.6,363.9L100,365L100,394L66.5,394L61.8,390L59,392L51.9,388.3L52.4,382.9L57.1,381.6L62.3,365.6Z","Henderson":"M246.3,207.3L251.1,207.9L249.6,218.6L254.8,219L261,213.3L255.8,204.2L259.1,194.8L262.9,195.6L265.7,202.6L272.3,205.3L278.9,200.1L288.3,200.9L298.7,207.2L295.9,220.3L302.5,226.4L295.9,233.1L286.5,236L284.6,242.8L273.2,248.8L241.6,250.2L239.3,245.1L238.8,235.3L231.2,229.7L216.6,206.6L223.7,203.3L228.9,210.7L246.3,207.3Z","Laurel":"M685.7,363L686.6,358L690.9,356.3L689.9,345.9L696.1,339.4L694.7,331.1L693.3,328.1L699.4,316.5L704.1,316L704.1,309.7L713.1,306L714.5,303.1L726.3,311.8L740,314.7L740.4,322L736.7,328.2L742.3,337.5L748,336.5L750.8,341.1L749.9,347.2L742.8,350.2L741.9,356.9L738.1,360L728.6,358.2L720.6,363.6L716.4,361.2L708.8,366.3L703.6,362.9L701.7,366L698,362.5L693.7,365.3L687.1,366.3L685.7,363Z","Wolfe":"M781,219.3L786.7,220.4L795.2,218.3L799,213.2L807.5,220.3L813.6,221.2L820.2,227L821.1,231.3L829.6,238L831.5,245.1L820.7,244.3L812.6,240.1L809.3,241.7L803.7,251.7L799,253.4L795.7,250.2L782.9,245.5L771.1,237.4L781,219.3Z","Caldwell":"M233.1,293.3L231.2,298L226.5,302.9L232.2,307.6L232.7,316.3L239.7,321.5L248.7,331.5L244.9,352.6L242.1,355.9L237.8,360.5L225.6,364.5L222.7,362.9L210,345.1L201,327.2L194.4,326.4L194.9,319.4L200.1,316.8L233.1,293.3Z","Boyle":"M597.5,251.5L597.9,243.5L634.7,237.8L639.9,240.4L640.9,245.3L646.1,251L646.1,253.7L634.3,258.9L621.5,265.2L614.4,267.9L600.8,267.6L596,265.8L597.5,251.5Z","Pulaski":"M614.4,336.9L638,316.7L659.7,297.2L666.8,301.7L694.7,331.1L696.1,339.4L689.9,345.9L690.9,356.3L686.6,358L685.7,363L678.2,365L656.9,378.3L651.3,373.4L644.2,360.5L639.9,359.5L631.4,363.3L622.9,356.6L613.5,348.5L614.4,336.9Z","Hart":"M463.4,281.6L483.7,283.2L514.9,286.2L515.8,290.5L511.1,296.3L509.7,306.1L513,311.8L511.1,326L503.5,328.1L482.3,331.7L462.5,328.5L463.4,320.5L449.3,300.6L459.2,297.9L460.1,293L467.2,290.7L463.4,281.6Z","Ohio":"M325.2,287.2L324.7,276.5L333.2,263.2L345,251.7L347.8,252.8L362.4,244.4L355.8,238.6L361.5,233.8L385.6,246.4L385.6,253.5L391.7,262.6L382.3,265.6L389.3,290.7L370,305.9L367.6,302.1L362.4,301.7L363.4,307.8L353.5,317.3L351.6,321L340.7,311.6L340.3,303.7L331.3,294.9L326.6,296.6L324.7,301.9L320.4,300.6L325.6,293.9L325.2,287.2Z","Harrison":"M659.3,108.5L668.7,105.9L670.1,100.2L673.9,102.4L680,97.2L705.5,93.7L704.6,98.1L711.7,98.2L708.4,107.7L715.4,110.1L719.2,114.1L707.4,128.6L696.1,138L682.9,144.2L674.4,143.3L675.8,140.6L672.5,128.3L663.5,118.3L659.3,108.5Z","Taylor":"M524.3,278.3L531.9,280.9L535.6,276.1L539.9,279L548.4,277.3L556.4,278.3L564.4,284L565.4,287L578.6,279L584.2,281L591.3,287.6L584.2,292.4L579.5,304.7L575.7,311.1L560.2,315.4L560.6,318.5L555,324.4L549.8,316.8L544.6,305.6L538.5,295.9L524.3,284.6L524.3,278.3Z","Barren":"M447.9,367.2L454.9,346.1L460.1,347.5L462.5,328.5L482.3,331.7L503.5,328.1L499.3,333.4L501.7,338.1L504,382.6L495,385.8L472.9,402.2L469.6,396.3L460.6,388.6L462.5,384.7L459.7,380.4L459.7,374L446.4,370.4L447.9,367.2Z","Menifee":"M764.5,190.5L777.7,185.7L783.9,189.1L789.1,186.4L788.6,180.5L798.5,181.9L807,184.7L805.6,199.8L799,208.5L799,213.2L795.2,218.3L786.7,220.4L781,219.3L765.5,207.6L763.1,203.9L762.2,192.2L764.5,190.5Z","Butler":"M351.6,321L353.5,317.3L363.4,307.8L362.4,301.7L367.6,302.1L370,305.9L389.3,290.7L405.9,296.2L408.2,303L417.2,328.1L408.2,330.9L404.4,324.7L387.9,326.2L388.9,331.9L381.3,356.3L358.7,346.9L345.9,344.8L352.1,341.6L348.3,332.5L348.7,326.4L352.1,326.8L351.6,321Z","Meade":"M409.2,170.1L416.7,172.7L420.5,168.5L426.6,168.3L427.1,164.7L421,163L420.5,158.1L426.1,160.3L434.2,167.4L434.6,180.8L446.9,188.6L457.3,188.8L463.4,197.1L465.3,191.9L470,190.4L472.9,210.9L468.6,220.4L449.7,223.7L437.9,210.7L413.4,190.2L405.4,182.7L410.1,181.9L412.9,176L409.2,170.1Z","Lincoln":"M621.5,265.2L634.3,258.9L646.1,253.7L646.1,251L651.3,257.8L670.6,274.2L673.9,275.6L666.8,301.7L659.7,297.2L638,316.7L637.6,308.7L639.9,306.6L637.6,296.4L628.1,291.5L621,285.3L619.6,278.8L621.5,265.2Z","Bell":"M748.9,408.2L757.9,398.1L760.7,389.4L766.9,389.3L774.4,380.4L787.6,372.2L790,367.6L786.7,363.6L797.1,366.5L799.9,373.6L800.8,381.3L797.1,388.3L800.4,392.3L798.5,400.5L803.7,406.5L803.7,411.9L794.7,411.7L779.1,418.6L775.4,422.5L773.5,425.5L741.9,424.8L738.6,415.1L748.9,408.2Z","Owen":"M591.3,91.3L604.5,84.6L609.7,80.4L618.2,74.4L629.5,70.7L631,87.5L643.2,97.4L650.3,109.8L656.4,111.8L650.8,118.8L635.2,131.8L628.6,134L618.2,131L614.9,128L616.8,121.2L605.9,117.6L606.9,111.6L602.6,109.4L604.1,105.1L597.5,105.5L600.8,98.7L591.3,91.3Z","Gallatin":"M628.1,48.1L646.1,61.3L630,63.3L629.5,70.7L618.2,74.4L609.7,80.4L605.9,77.4L597.9,63.7L615.9,58.3L626.2,58.7L623.4,52.5L628.1,48.1Z","Bourbon":"M674.4,143.3L682.9,144.2L696.1,138L707.4,128.6L710.7,131.3L720.2,147.3L725.3,147.7L724.4,151.3L729.1,154.7L734.3,154L735.7,158.4L722,171.1L695.1,179.1L682.9,171.4L686.2,160.7L683.8,155.7L680,155.8L674.4,143.3Z","Bracken":"M702.2,52.9L704.6,56.6L725.8,62.3L735.7,59.6L745.2,62.7L733.8,91.7L728.2,93.5L721.6,91.1L716.8,96.7L711.7,98.2L704.6,98.1L705.5,93.7L701.7,53.8L702.2,52.9Z","Russell":"M570.6,368.7L574.3,356.8L579.5,350.8L595.6,325.4L607.4,339.4L614.4,336.9L613.5,348.5L622.9,356.6L613.5,365.3L608.3,362.9L606.4,370.2L592.7,379.7L585.7,385L570.6,375.3L572.9,380.4L570.1,380.6L564.9,373.2L570.6,368.7Z","Lyon":"M181.2,331.8L182.6,335.4L191.1,330.5L194.4,326.4L201,327.2L210,345.1L222.7,362.9L206.2,371.2L185.9,378.3L181.7,367L175.1,359.3L179.3,356.3L177,351.6L176.5,342.8L181.2,331.8Z","Grayson":"M391.7,262.6L394.1,256.8L399.2,258.4L402.5,252.8L415.8,262.2L424.3,262.9L423.3,258.8L433.7,257.8L437.5,256.4L439.4,260.8L446.4,264.2L454.9,262.1L462.5,273.9L463.4,281.6L467.2,290.7L460.1,293L459.2,297.9L449.3,300.6L408.2,303L405.9,296.2L389.3,290.7L382.3,265.6L391.7,262.6Z","Daviess":"M298.7,207.2L303,210.5L309.1,215.3L317.6,217.2L321.4,226L326.6,225.6L329.9,221.7L332.2,207.9L341.2,201.9L339.8,207.3L347.3,205.3L352.1,209.9L349.7,217.3L357.2,216.7L362.4,224.9L361.5,233.8L355.8,238.6L362.4,244.4L347.8,252.8L345,251.7L333.2,263.2L325.6,262.2L303.9,253.1L284.6,242.8L286.5,236L295.9,233.1L302.5,226.4L295.9,220.3L298.7,207.2Z","Campbell":"M690.9,20.7L694.7,31.7L701.3,40.8L702.2,45.1L681.9,55.5L677.7,56.5L671.5,49.1L674.8,39.6L672,33.4L673.4,25.4L668.2,20.8L666.4,8.6L670.6,4.1L674.4,5.3L676.3,15.1L690.9,20.7Z","Rowan":"M780.6,159.1L797.5,145.6L799.9,136.5L798.5,132.2L804.6,126.9L809.8,124.5L819.3,137.3L823.5,148.4L824.4,155.4L832,158.4L837.2,161.1L834.8,168.4L829.6,171.1L820.2,176.2L814.1,181.7L807,184.7L798.5,181.9L803.2,177.1L793.8,174.5L795.2,170.5L782.4,165.5L786.2,162.3L780.6,159.1Z","Green":"M514.9,286.2L517.7,277.9L524.3,278.3L524.3,284.6L538.5,295.9L544.6,305.6L549.8,316.8L555,324.4L551.2,328.4L531.9,338.1L518.2,335.5L511.1,326L513,311.8L509.7,306.1L511.1,296.3L515.8,290.5L514.9,286.2Z","McCreary":"M656.9,378.3L678.2,365L685.7,363L687.1,366.3L693.7,365.3L690.4,374.4L691.4,379.6L687.6,383.3L686.6,392.7L690.4,396.3L692.3,409.9L702.7,423.9L698.4,424.1L661.2,423.3L630.5,422.1L644.2,399.5L644.2,395.8L649.4,394.5L650.8,390.4L656.4,388.8L656.9,378.3Z","Allen":"M416.2,393.4L435.1,377.3L434.6,374.2L442.7,371.6L447.9,367.2L446.4,370.4L459.7,374L459.7,380.4L462.5,384.7L460.6,388.6L469.6,396.3L472.9,402.2L476.6,412.4L472.9,417.9L442.7,416.1L415.8,414.2L416.2,393.4Z","Clinton":"M562.5,418.4L568.7,398.7L572.9,380.4L570.6,375.3L585.7,385L592.7,379.7L597.9,388.3L600.8,396.7L598.4,403.1L601.2,409.9L601.2,418.6L604.5,420.1L564.9,418.2L562.5,418.4Z","Jefferson":"M482.8,160.4L489.4,153.3L492.2,144.3L497.4,142.4L503.5,145.9L512.5,140.3L517.2,127.2L539.9,142.9L547.9,146.4L545.5,165.8L545.1,170.7L526.7,177.8L507.8,175.8L485.1,183.5L478.1,190.5L477.1,188.9L479.9,185.9L482.3,176L482.8,160.4Z","Floyd":"M872.1,237.4L877.3,239.5L881.1,235.3L895.2,230.7L911.3,236.7L921.7,242.5L915.1,245L916.9,249.7L913.6,272.6L916.9,272.8L918.4,282.2L914.1,292L908,294.9L909.9,297.9L907.5,305.3L902.3,308.8L896.6,305.1L895.2,297.7L896.2,287.6L892.9,285L885.8,287.5L886.3,278.8L874,275.5L877.8,271.8L878.7,262.5L876.8,250L871.2,243.7L872.1,237.4Z","Marion":"M532.8,264.2L542.2,242.4L548.4,235L552.1,239.7L552.1,244.5L556.4,248.1L567.2,251.5L597.5,251.5L596,265.8L595.6,287.9L591.3,287.6L584.2,281L578.6,279L565.4,287L564.4,284L556.4,278.3L548.4,277.3L539.9,279L535.2,265.1L532.8,264.2Z","Pendleton":"M662.6,58.9L677.7,56.5L681.9,55.5L702.2,45.1L702.2,52.9L701.7,53.8L705.5,93.7L680,97.2L673.9,102.4L670.1,100.2L662.6,58.9Z","Boone":"M624.8,6.8L633.3,0L636.6,0.3L643.7,8L650.8,12L654.1,44.3L651.7,57.2L646.1,61.3L628.1,48.1L627.7,42.3L618.2,40.8L618.2,36.1L623.4,30.7L617.3,19.2L615.9,13.3L624.8,6.8Z","Logan":"M331.3,346.2L345.9,344.8L358.7,346.9L381.3,356.3L389.3,375.7L383.7,376.9L379,382.1L370.9,401.5L369.5,414.5L330.3,415.5L331.3,346.2Z","Spencer":"M545.1,170.7L545.5,165.8L570.6,175.4L588,184.1L584.2,190.9L579,190.6L579,194.9L548.8,200.2L537,191.8L533.3,188.4L539.4,174.2L545.1,170.7Z","Robertson":"M711.7,98.2L716.8,96.7L721.6,91.1L728.2,93.5L733.8,91.7L736.7,92.8L738.1,101.8L741.9,108.5L735.3,117.4L731.5,118.5L719.2,114.1L715.4,110.1L708.4,107.7L711.7,98.2Z","Marshall":"M143,365.9L143.5,352.5L150.5,347.9L158.6,345.6L166.1,348.2L175.1,359.3L181.7,367L185.9,378.3L192.1,398.3L143,397.7L143,365.9Z","Morgan":"M807,184.7L814.1,181.7L820.2,176.2L829.6,171.1L828.7,178.8L834.8,182.9L838.6,188.5L846.2,189.6L861.3,189.1L865.5,196.2L869.3,204.8L863.6,213.6L859.8,209.2L856.5,211.9L847.1,207.8L849.5,212.9L836.7,220.3L834.4,225.1L828.7,228.6L832.5,232.7L829.6,238L821.1,231.3L820.2,227L813.6,221.2L807.5,220.3L799,213.2L799,208.5L805.6,199.8L807,184.7Z","Muhlenberg":"M299.2,291.2L310.5,293L315.7,287.6L325.2,287.2L325.6,293.9L320.4,300.6L324.7,301.9L326.6,296.6L331.3,294.9L340.3,303.7L340.7,311.6L351.6,321L352.1,326.8L348.7,326.4L348.3,332.5L352.1,341.6L345.9,344.8L331.3,346.2L322.8,348.8L305.3,349.5L304.4,344.2L301.1,338.4L294.5,334.4L294.5,330.2L297.8,324.4L287.4,312.8L288.3,304.4L292.6,304.9L299.2,291.2Z","Simpson":"M369.5,414.5L370.9,401.5L379,382.1L383.7,376.9L389.3,375.7L393.1,384.4L417.2,388.3L416.2,393.4L415.8,414.2L403,413.9L395.5,417.1L392.2,413.9L369.5,414.5Z","Ballard":"M52.9,344.9L60.9,336.5L65.1,327.2L71.3,321.3L77.4,318.3L84,318.4L99.6,363.9L86.4,365.9L76.9,369.6L73.6,367.9L64.7,370.3L62.3,365.6L58,359.2L51.4,351.8L52.9,344.9Z","Adair":"M531.9,338.1L551.2,328.4L555,324.4L560.6,318.5L560.2,315.4L575.7,311.1L579.5,304.7L593.7,313.6L595.6,325.4L579.5,350.8L574.3,356.8L570.6,368.7L541.8,366.6L543.2,363.9L535.2,355L531.9,338.1Z","Greenup":"M858.4,73.1L861.3,69.3L868.3,69.3L878.2,64.7L881.5,69.4L880.1,75.7L884.4,91.5L888.6,95.5L900.4,97.7L908,106.4L894.8,118.3L888.2,128.2L875.9,124.1L867.9,124.9L857.5,113.1L842.4,106.7L848,101.4L854.6,91.5L854.6,85.3L861.3,76.9L858.4,73.1Z","Leslie":"M797.5,317.1L803.7,307.6L811.7,303L817.8,307.1L821.6,318.8L830.6,322.4L837.7,327.2L834.4,333.5L842.4,339.2L840.5,352.8L833.9,355.8L830.1,361.5L821.6,366.2L811.7,369.4L810.3,374.4L799.9,373.6L797.1,366.5L797.1,355.6L791.4,343.1L791.9,328.5L798,322.4L797.5,317.1Z","Carter":"M819.3,137.3L833.9,134L832.9,119.5L842.4,106.7L857.5,113.1L867.9,124.9L875.9,124.1L888.2,128.2L894.3,130L892.9,132.9L891.5,149.9L883.4,158.7L879.7,157.7L874,161.3L867.4,161.7L862.7,156.1L857.5,160.6L853.2,153.4L843.3,146.4L835.3,151L832,158.4L824.4,155.4L823.5,148.4L819.3,137.3Z","Kenton":"M650.8,12L660.2,7.8L666.4,8.6L668.2,20.8L673.4,25.4L672,33.4L674.8,39.6L671.5,49.1L677.7,56.5L662.6,58.9L651.7,57.2L654.1,44.3L650.8,12Z","Clark":"M695.1,179.1L722,171.1L737.1,201.8L733.8,203.9L732.4,217.3L725.3,217.6L722,214.7L708.4,210.3L698,210.7L697,204L688.5,208.2L686.6,207.2L690.4,196.1L690.4,190.1L695.6,187.1L695.1,179.1Z","Calloway":"M143,397.7L192.1,398.3L197.7,409.7L202.5,430.6L199.6,439.7L142.5,439L143,397.7Z","Mason":"M733.8,91.7L745.2,62.7L752.7,66.3L754.1,71.2L761.2,74.9L763.6,82L771.6,84.1L779.1,84.6L782,88.8L779.6,103.1L751.3,114.5L741.9,108.5L738.1,101.8L736.7,92.8L733.8,91.7Z","Elliott":"M829.6,171.1L834.8,168.4L837.2,161.1L832,158.4L835.3,151L843.3,146.4L853.2,153.4L857.5,160.6L862.7,156.1L867.4,161.7L874,161.3L878.7,171.5L866.4,181.9L861.3,189.1L846.2,189.6L838.6,188.5L834.8,182.9L828.7,178.8L829.6,171.1Z","Garrard":"M638.5,220.9L643.7,219.2L651.7,222.9L647.9,225.4L657.9,235.3L663.5,228.6L676.3,249.5L683.8,257.9L687.1,266.8L683.3,277.8L673.9,275.6L670.6,274.2L651.3,257.8L646.1,251L640.9,245.3L639.9,240.4L634.7,237.8L639.9,234.8L641.3,229.6L638.5,220.9Z","Letcher":"M848,356L857,353.3L854.6,349.2L858.4,345.9L856.5,335.7L864.1,323.8L866.9,327.7L878.2,320.3L880.6,316.1L888.2,311.7L899.5,311.3L907.5,318.5L913.2,315.1L921.2,323.7L912.2,330.7L900.4,337.1L900.4,349.3L892.9,354.9L887.2,355.2L881.5,360.6L872.1,353.6L859.4,358.9L844.3,363.5L848,356Z","Trimble":"M557.3,68.2L571,86.3L573.4,94L579,93.1L564.4,107.9L560.2,108.5L551.7,104.2L544.1,103.2L546.5,100.5L545.1,93L541.8,72.6L547.4,67.9L557.3,68.2Z","Hickman":"M59,392L61.8,390L66.5,394L100,394L99.6,438.7L98.2,438.7L87.8,426.5L83.1,424.1L71.7,423.9L56.2,414.5L52.4,414.2L53.3,408.5L49.1,403.4L51,397.1L58.5,397.5L59,392Z","Fayette":"M650.3,171L651.3,168.8L680,155.8L683.8,155.7L686.2,160.7L682.9,171.4L695.1,179.1L695.6,187.1L690.4,190.1L690.4,196.1L686.6,207.2L688.5,208.2L682.9,206.6L684.8,213.7L681.9,215.9L678.6,211.6L675.3,215.6L673.4,205.3L669.7,200.2L655,192.5L646.1,189.6L650.3,171Z","Washington":"M548.4,235L555,230.6L554.5,226.1L560.6,224.6L562.1,218.3L574.3,215.9L574.8,207.2L580.9,207.3L584.7,204L587.1,207.9L597.5,208.3L601.2,214.5L597.9,243.5L597.5,251.5L567.2,251.5L556.4,248.1L552.1,244.5L552.1,239.7L548.4,235Z","Woodford":"M637.6,157.8L639.9,161.6L647.5,161L647,166.3L650.3,171L646.1,189.6L639.5,213.2L631.9,215.6L630,205.6L623.9,204.2L628.1,200.8L628.1,195.2L621,182.4L623.9,176.4L619.2,170.8L619.2,166.8L637.6,157.8Z","Christian":"M248.7,331.5L269.9,338.8L274.2,335.4L289.3,334.4L294.5,330.2L294.5,334.4L301.1,338.4L304.4,344.2L294,415.8L253.9,416.4L246.8,416.5L249.6,396.8L250.1,376.4L251.5,361.9L242.1,355.9L244.9,352.6L248.7,331.5Z","Estill":"M722,214.7L725.3,217.6L732.4,217.3L737.6,216L737.6,223.4L745.2,230.3L755.1,229.3L756.5,232.6L762.2,230.7L769.2,237.4L765.9,237.6L756,245.8L754.6,250.7L745.2,266.2L737.1,259.8L726.8,262.8L720.6,262.2L715.9,249.7L721.1,245.4L720.2,234.3L723,223.3L716.8,221.3L722,214.7Z","Grant":"M646.1,61.3L651.7,57.2L662.6,58.9L670.1,100.2L668.7,105.9L659.3,108.5L656.4,111.8L650.3,109.8L643.2,97.4L631,87.5L629.5,70.7L630,63.3L646.1,61.3Z","Mercer":"M597.5,208.3L603.1,205.9L604.5,201.1L609.2,198.1L616.3,200.2L628.1,195.2L628.1,200.8L623.9,204.2L630,205.6L631.9,215.6L639.5,213.2L638.5,220.9L641.3,229.6L639.9,234.8L634.7,237.8L597.9,243.5L601.2,214.5L597.5,208.3Z","Montgomery":"M735.7,158.4L736.2,164L748.5,167.7L756.5,176.8L758.8,183.4L764.5,190.5L762.2,192.2L763.1,203.9L757,206.9L748.5,206L737.1,201.8L722,171.1L735.7,158.4Z","Webster":"M215.7,276.6L232.7,260.1L241.6,250.2L273.2,248.8L274.7,256.5L286,258.5L288.8,261.7L272.8,275.3L260,279.6L231.2,298L233.1,293.3L227.5,294L227,286.5L219.4,290.2L214.7,285.6L215.7,276.6Z","Bullitt":"M478.1,190.5L485.1,183.5L507.8,175.8L526.7,177.8L545.1,170.7L539.4,174.2L533.3,188.4L537,191.8L530.9,196.1L529,202.2L524.3,205L525.2,209.3L511.6,221L504,221.6L493.6,213.7L494.1,208.6L488.9,199.3L482.3,199.8L481.8,191.6L478.1,190.5Z","Anderson":"M588,184.1L595.1,178.2L597.9,168.8L614,174.8L619.2,170.8L623.9,176.4L621,182.4L628.1,195.2L616.3,200.2L609.2,198.1L604.5,201.1L603.1,205.9L597.5,208.3L587.1,207.9L584.7,204L580.9,207.3L579,194.9L579,190.6L584.2,190.9L588,184.1Z","Nelson":"M504,221.6L511.6,221L525.2,209.3L524.3,205L529,202.2L530.9,196.1L537,191.8L548.8,200.2L579,194.9L580.9,207.3L574.8,207.2L574.3,215.9L562.1,218.3L560.6,224.6L554.5,226.1L555,230.6L548.4,235L542.2,242.4L532.8,264.2L528.6,264.4L527.1,269.5L519.1,264.6L525.7,250.2L522.4,250.1L523.4,241.1L517.2,240.7L511.6,234.7L505.4,227.7L504,221.6Z","Breathitt":"M788.1,272.2L795.7,250.2L799,253.4L803.7,251.7L809.3,241.7L812.6,240.1L820.7,244.3L831.5,245.1L841.4,249.7L846.6,255.5L852.3,251.4L858.9,259.2L862.7,259.4L861.7,265.1L871.2,272.8L860.3,272.2L856.1,268.9L846.6,280.3L848,289L838.1,287.5L835.8,282.6L828.7,290L820.7,293.3L814.1,300.1L811.2,300.1L805.1,293.4L792.4,300.7L791.9,290.9L793.8,287L788.1,272.2Z","Oldham":"M517.2,127.2L521.5,117.4L535.6,112.5L538.9,106.2L544.1,103.2L551.7,104.2L560.2,108.5L555.9,114.1L558.3,123.2L563.9,130.9L558.8,138.9L550.3,139.2L539.9,142.9L517.2,127.2Z"}}};
// Rent updated to HUD's FY2026 Fair Market Rents: each county's figure scaled by its own FY2025 to FY2026 change for the matching home size
for(const [c,r] of Object.entries({"Adair":[6111,5539,7609,7263,5539,7609,7263,11269],"Allen":[7664,6595,9332,9220,6595,9332,9220,11383],"Anderson":[7710,8872,9758,8734,8872,9758,8734,12968],"Ballard":[7674,6882,9739,9356,6882,9739,9356,11622],"Barren":[6089,5358,7646,7237,5358,7646,7237,9993],"Bath":[5797,5814,7609,7077,5814,7609,7077,10332],"Bell":[6293,6929,7609,6984,6929,7609,6984,10516],"Boone":[12088,12528,16865,16473,12528,16865,16473,22733],"Bourbon":[9200,10444,12615,12404,10444,12615,12404,17873],"Boyd":[8993,7841,9005,8628,7841,9005,8628,11877],"Boyle":[6861,5642,8039,7631,5642,8039,7631,11025],"Bracken":[10031,10207,13837,13461,10207,13837,13461,18693],"Breathitt":[5932,6222,7609,7329,6222,7609,7329,11228],"Breckinridge":[6917,5922,7609,7707,5922,7609,7707,10999],"Bullitt":[10586,10560,13127,12739,10560,13127,12739,17027],"Butler":[7713,6893,9359,8999,6893,9359,8999,13302],"Caldwell":[5766,6497,7609,7273,6497,7609,7273,9082],"Calloway":[8133,7574,10563,10222,7574,10563,10222,12624],"Campbell":[10031,10207,13837,13461,10207,13837,13461,18693],"Carlisle":[6604,5660,8086,8280,5660,8086,8280,10316],"Carroll":[6314,7132,8751,8069,7132,8751,8069,10640],"Carter":[7157,5646,7777,7429,5646,7777,7429,11269],"Casey":[6111,6929,7609,7018,6929,7609,7018,9235],"Christian":[11120,10397,13574,13152,10397,13574,13152,19631],"Clark":[9200,10444,12615,12404,10444,12615,12404,17873],"Clay":[7726,6366,7609,7094,6366,7609,7094,11007],"Clinton":[6048,5323,7609,7301,5323,7609,7301,9105],"Crittenden":[6048,5323,7609,7280,5323,7609,7280,9079],"Cumberland":[6300,5491,7609,7409,5491,7609,7409,11181],"Daviess":[8945,7830,10885,10571,7830,10885,10571,14774],"Edmonson":[9389,9543,11451,11128,9543,11451,11128,13701],"Elliott":[6111,5539,7609,7302,5539,7609,7302,9632],"Estill":[7099,5491,7609,7531,5491,7609,7531,9996],"Fayette":[10083,11570,13899,13698,11570,13899,13698,19656],"Fleming":[5762,6354,7609,7303,6354,7609,7303,10435],"Floyd":[6414,5695,8095,7947,5695,8095,7947,9891],"Franklin":[7786,7818,10392,10013,7818,10392,10013,13912],"Fulton":[6048,5323,7609,7263,5323,7609,7263,11269],"Gallatin":[10031,10207,13837,13461,10207,13837,13461,18693],"Garrard":[6440,7329,8047,8136,7329,8047,8136,10365],"Grant":[8330,8509,11245,10888,8509,11245,10888,14882],"Graves":[6048,5323,7609,7263,5323,7609,7263,11269],"Grayson":[7111,5742,7609,7511,5742,7609,7511,11063],"Green":[6111,6929,7609,7310,6929,7609,7310,10433],"Greenup":[8993,7841,9005,8628,7841,9005,8628,11865],"Hancock":[8184,7167,9964,9699,7167,9964,9699,13554],"Hardin":[8971,7840,10171,9818,7840,10171,9818,14850],"Harlan":[6181,5646,7609,7413,5646,7609,7413,10362],"Harrison":[6111,6929,7609,7707,6929,7609,7707,10999],"Hart":[6743,5455,7609,7343,5455,7609,7343,9542],"Henderson":[7557,6700,9074,9187,6700,9074,9187,11731],"Henry":[10586,10560,13127,12739,10560,13127,12739,17027],"Hickman":[6048,5323,7609,7033,5323,7609,7033,10602],"Hopkins":[6371,5724,8130,7951,5724,8130,7951,10725],"Jackson":[6048,5323,7609,7415,5323,7609,7415,11178],"Jefferson":[11562,11650,14390,13991,11650,14390,13991,18609],"Jessamine":[9200,10444,12615,12404,10444,12615,12404,17873],"Johnson":[6378,5323,7609,7518,5323,7609,7518,10459],"Kenton":[10031,10207,13837,13461,10207,13837,13461,18693],"Knott":[6764,5539,7609,7280,5539,7609,7280,9079],"Knox":[6597,5623,7609,7280,5623,7609,7280,9079],"Larue":[8971,7840,10171,9818,7840,10171,9818,14850],"Laurel":[5860,5507,7835,7276,5507,7835,7276,9648],"Lawrence":[6631,5753,8196,7761,5753,8196,7761,9831],"Lee":[6781,5772,8251,7126,5772,8251,7126,10334],"Leslie":[6111,6929,7609,7415,6929,7609,7415,11178],"Letcher":[6089,6569,7609,7033,6569,7609,7033,10913],"Lewis":[5560,6090,7609,6996,6090,7609,6996,10547],"Lincoln":[5923,6761,7609,7280,6761,7609,7280,9079],"Livingston":[8640,7485,10254,9820,7485,10254,9820,12232],"Logan":[6076,5455,7609,7106,5455,7609,7106,11026],"Lyon":[6048,5323,7609,8103,5323,7609,8103,10742],"Madison":[7225,7183,8260,7921,7183,8260,7921,12161],"Magoffin":[6111,6929,7609,6935,6929,7609,6935,9296],"Marion":[6048,5323,7609,7445,5323,7609,7445,9699],"Marshall":[6405,6566,7871,7871,6566,7871,7871,10931],"Martin":[6111,5539,7609,7302,5539,7609,7302,9632],"Mason":[6113,6545,8163,7756,6545,8163,7756,10001],"McCracken":[7594,7234,9956,9611,7234,9956,9611,11898],"McCreary":[6111,6929,7609,7228,6929,7609,7228,9511],"McLean":[8945,7830,10885,10571,7830,10885,10571,14774],"Meade":[8688,7571,10483,10237,7571,10483,10237,14791],"Menifee":[6111,5539,7609,7316,5539,7609,7316,9998],"Mercer":[6048,5323,7609,7263,5323,7609,7263,11269],"Metcalfe":[6657,5670,7609,7302,5670,7609,7302,9632],"Monroe":[6048,5323,7609,7472,5323,7609,7472,11141],"Montgomery":[6323,5563,7952,7643,5563,7952,7643,10908],"Morgan":[6048,5323,7609,7335,5323,7609,7335,11225],"Muhlenberg":[6048,5323,7609,7280,5323,7609,7280,9079],"Nelson":[7298,6457,9148,8537,6457,9148,8537,12948],"Nicholas":[6378,5323,7609,7510,5323,7609,7510,11112],"Ohio":[6048,5323,7609,7315,5323,7609,7315,9123],"Oldham":[12446,12660,15652,15242,12660,15652,15242,20236],"Owen":[7168,6443,9120,9138,6443,9120,9138,12475],"Owsley":[6111,5539,7609,7081,5539,7609,7081,10211],"Pendleton":[10031,10207,13837,13461,10207,13837,13461,18693],"Perry":[6900,6195,8757,8423,6195,8757,8423,10452],"Pike":[6908,6753,9081,8747,6753,9081,8747,10838],"Powell":[6048,5323,7609,7263,5323,7609,7263,11269],"Pulaski":[6659,5977,8447,8123,5977,8447,8123,10077],"Robertson":[6048,5323,7609,7581,5323,7609,7581,9455],"Rockcastle":[6630,5539,7609,7189,5539,7609,7189,10295],"Rowan":[6011,6128,8047,7807,6128,8047,7807,10372],"Russell":[6048,5323,7609,7280,5323,7609,7280,9079],"Scott":[9200,10444,12615,12404,10444,12615,12404,17873],"Shelby":[10183,10279,11685,11212,10279,11685,11212,15333],"Simpson":[8304,7272,9970,9615,7272,9970,9615,13765],"Spencer":[10586,10560,13127,12739,10560,13127,12739,17027],"Taylor":[6111,6929,7609,7568,6929,7609,7568,11086],"Todd":[6414,5642,8066,7413,5642,8066,7413,10482],"Trigg":[11120,10397,13574,13152,10397,13574,13152,19631],"Trimble":[6731,7069,8950,8617,7069,8950,8617,12246],"Union":[6410,5665,8073,7736,5665,8073,7736,9642],"Warren":[9389,9543,11451,11128,9543,11451,11128,13701],"Washington":[6649,5943,8422,8911,5943,8422,8911,11049],"Wayne":[5952,5694,7609,7263,5694,7609,7263,11269],"Webster":[6048,5323,7609,7820,5323,7609,7820,9752],"Whitley":[6048,5323,7609,7280,5323,7609,7280,9079],"Wolfe":[6066,5599,7609,7581,5599,7609,7581,9455],"Woodford":[9200,10444,12615,12404,10444,12615,12404,17873]})) DATA.counties[c].rent=r;
// Campbell County's form adds 0.10% mental health and 0.05% senior services to its 0.90% general fee
DATA.countyTax.Campbell=1.05;
// Median household income by county, 2024: U.S. Census Bureau SAIPE
DATA.income={"Adair":50581,"Allen":64655,"Anderson":76395,"Ballard":61431,"Barren":58256,"Bath":53078,"Bell":39209,"Boone":103122,"Bourbon":66264,"Boyd":61094,"Boyle":63052,"Bracken":66635,"Breathitt":41866,"Breckinridge":58822,"Bullitt":85779,"Butler":60561,"Caldwell":51984,"Calloway":56410,"Campbell":76744,"Carlisle":61317,"Carroll":65791,"Carter":53796,"Casey":48938,"Christian":56457,"Clark":63815,"Clay":39016,"Clinton":42798,"Crittenden":57359,"Cumberland":47274,"Daviess":68015,"Edmonson":57647,"Elliott":46905,"Estill":48992,"Fayette":71046,"Fleming":56093,"Floyd":44735,"Franklin":63103,"Fulton":44503,"Gallatin":67617,"Garrard":64539,"Grant":67881,"Graves":56968,"Grayson":53988,"Green":52542,"Greenup":61352,"Hancock":76970,"Hardin":70505,"Harlan":41808,"Harrison":67409,"Hart":55611,"Henderson":62182,"Henry":67994,"Hickman":57997,"Hopkins":57348,"Jackson":49388,"Jefferson":70659,"Jessamine":71861,"Johnson":49122,"Kenton":82787,"Knott":44407,"Knox":40065,"Larue":63320,"Laurel":54404,"Lawrence":41782,"Lee":41150,"Leslie":40363,"Letcher":44339,"Lewis":47414,"Lincoln":54345,"Livingston":61242,"Logan":60406,"Lyon":67019,"Madison":64536,"Magoffin":43039,"Marion":62645,"Marshall":70547,"Martin":38950,"Mason":59252,"McCracken":64076,"McCreary":40509,"McLean":60175,"Meade":76163,"Menifee":47808,"Mercer":67889,"Metcalfe":51715,"Monroe":48686,"Montgomery":61732,"Morgan":46382,"Muhlenberg":53408,"Nelson":75726,"Nicholas":56479,"Ohio":59028,"Oldham":123360,"Owen":64666,"Owsley":34802,"Pendleton":68030,"Perry":44945,"Pike":46499,"Powell":50993,"Pulaski":56318,"Robertson":58457,"Rockcastle":48953,"Rowan":55174,"Russell":51235,"Scott":93893,"Shelby":93720,"Simpson":67496,"Spencer":96943,"Taylor":56626,"Todd":58651,"Trigg":64717,"Trimble":72488,"Union":61745,"Warren":67824,"Washington":66540,"Wayne":41853,"Webster":60750,"Whitley":48936,"Wolfe":44554,"Woodford":89773};
</script>
<script id="calc">
// ---- Tax rules, tax year 2026 ----
const FED={
  std:{single:16100,hoh:24150,mfj:32200},
  brackets:{ // upper bounds for 10,12,22,24,32,35 (37% above)
    single:[12400,50400,105700,201775,256225,640600],
    hoh:[17700,67450,105700,201750,256200,640600],
    mfj:[24800,100800,211400,403550,512450,768700]},
  rates:[.10,.12,.22,.24,.32,.35,.37],
  // Earned income credit, Rev. Proc. 2025-32 §4.06, by kids 0/1/2/3+
  eitc:{max:[664,4427,7316,8231],phaseIn:[.0765,.34,.40,.45],phaseOut:[.0765,.1598,.2106,.2106],start:{single:[10860,23890,23890,23890],mfj:[18140,31160,31160,31160]}},
  ctc:2200, ctcRefund:1700, ctcPhase:{single:200000,hoh:200000,mfj:400000},
  ssRate:.062, ssCap:184500, medRate:.0145, addMed:.009, addMedThr:{single:200000,hoh:200000,mfj:250000}
};
// Family size credit (KRS 141.066, Schedule ITC): thresholds are the 2026 HHS poverty guidelines for 1 to 4+ people;
// the credit is a share of Kentucky tax that steps down from 100% at the threshold to 0% above 133% of it.
const KY={rate:.035, std:3360, fsc:[15960,21640,27320,33000], fscBands:[[1,1],[1.04,.9],[1.08,.8],[1.12,.7],[1.16,.6],[1.2,.5],[1.24,.4],[1.27,.3],[1.3,.2],[1.33,.1]]};
const ELSE="Outside city limits";
// Portfolio mixes: average yearly returns 1926 to 2022 (Boldin), minus ~2.9% average inflation. Bad/good markets are a range around the average.
const INFL=2.9;
const PORTFOLIOS={
  conservative:{name:"Conservative",mix:[30,70],nominal:7.0,spread:1.5,blurb:"30% stocks, 70% bonds. Steadier, slower growth."},
  balanced:{name:"Balanced",mix:[60,40],nominal:8.6,spread:2.0,blurb:"60% stocks, 40% bonds. A middle path."},
  aggressive:{name:"Aggressive",mix:[100,0],nominal:10.2,spread:3.0,blurb:"100% stocks. Most growth, biggest swings."}};
function portfolioRates(key){const p=PORTFOLIOS[key], r=+((1+p.nominal/100)/(1+INFL/100)*100-100).toFixed(1);return {rExp:r,rLow:+(r-p.spread).toFixed(1),rHigh:+(r+p.spread).toFixed(1)};}
// Local occupational license taxes (%), owed where you work. County rates come from DATA.countyTax (KACo 2026).
// The city fee counts toward the county fee (pay the higher) only in counties of 30,000+ people (KRS 68.197, 2024 Census estimates),
// and not in the STACK counties, whose fees are added on top. In smaller counties both fees apply.
const STACK=new Set(["Kenton","Boone","Campbell","Scott","Jessamine","Boyle"]);
const BIG=new Set(["Barren","Boone","Boyd","Boyle","Bullitt","Calloway","Campbell","Christian","Clark","Daviess","Fayette","Floyd","Franklin","Graves","Greenup","Hardin","Henderson","Hopkins","Jefferson","Jessamine","Kenton","Knox","Laurel","Madison","Marshall","McCracken","Meade","Muhlenberg","Nelson","Oldham","Pike","Pulaski","Scott","Shelby","Warren","Whitley"]);
// City rates: [rate, source].
const CITY_RATE={
  // official: the city's own site, ordinance, form, or its county's 2026 rate table
  Alexandria:[1.5,"official"],Bardstown:[1,"official"],Bellevue:[2.5,"official"],Benton:[0.6,"official"],Berea:[2,"official"],Bromley:[1,"official"],
  Cadiz:[1.9,"official"],Campbellsville:[1.5,"official"],"Cold Spring":[1,"official"],Covington:[2.45,"official"],"Crescent Springs":[1,"official"],
  "Crestview Hills":[1.15,"official"],Dayton:[2.5,"official"],Edgewood:[1,"official"],Elizabethtown:[1.95,"official"],Elkton:[2,"official"],
  Elsmere:[1.75,"official"],Erlanger:[1.5,"official"],Fairview:[0,"official"],"Fort Mitchell":[1.25,"official"],"Fort Thomas":[1.25,"official"],
  "Fort Wright":[0.99,"official"],Frankfort:[1.95,"official"],Glasgow:[1.75,"official"],Harrodsburg:[1.5,"official"],Hillview:[1.8,"official"],
  Independence:[1.25,"official"],Jeffersontown:[1,"official"],"Kenton Vale":[0,"official"],"La Grange":[1,"official"],"Lakeside Park":[1,"official"],
  Lebanon:[1,"official"],London:[1,"official"],Ludlow:[2,"official"],Lyndon:[0.75,"official"],Maysville:[1.99,"official"],Melbourne:[0,"official"],
  Middletown:[1,"official"],"Mount Washington":[1,"official"],Newport:[2.5,"official"],"Oak Grove":[1.5,"official"],Paris:[1.5,"official"],
  "Park Hills":[1.5,"official"],"Ryland Heights":[1,"official"],Shelbyville:[1.5,"official"],Shepherdsville:[2,"official"],Shively:[2,"official"],
  Southgate:[2.5,"official"],"St. Matthews":[0.75,"official"],"Taylor Mill":[2,"official"],Union:[2,"official"],Versailles:[1.5,"official"],
  "Villa Hills":[1.5,"official"],Walton:[2,"official"],Wilder:[2.25,"official"],Woodlawn:[0,"official"],
  // registry: the rate the city filed with the Kentucky Secretary of State's occupational tax database
  Adairville:[1.5,"registry"],Augusta:[1.25,"registry"],Brownsville:[1,"registry"],"Calvert City":[0.5,"registry"],Camargo:[2,"registry"],
  Catlettsburg:[1.5,"registry"],"Cave City":[2,"klc"],"Coal Run Village":[1,"registry"],Corbin:[1,"registry"],Cynthiana:[1.5,"registry"],
  Eminence:[0.75,"registry"],Falmouth:[1.5,"registry"],Gamaliel:[1,"registry"],Greensburg:[1.5,"registry"],Hartford:[1,"registry"],
  Hickman:[1.75,"klc"],Hodgenville:[0.75,"klc"],Leitchfield:[1.2,"registry"],Marion:[0.75,"klc"],Mayfield:[1.9,"registry"],
  McKee:[1,"registry"],Middlesboro:[2,"registry"],Midway:[2,"registry"],Millersburg:[1,"registry"],Morehead:[1.5,"registry"],Morgantown:[2,"registry"],
  "Mount Vernon":[1,"registry"],Nortonville:[1.5,"klc"],"Park City":[1,"registry"],Perryville:[1.5,"klc"],Pineville:[1.5,"registry"],
  Princeton:[1.5,"registry"],Raceland:[1,"klc"],Russell:[1.5,"registry"],Scottsville:[1.5,"registry"],Simpsonville:[0.5,"registry"],
  Springfield:[1,"klc"],Stanford:[1.15,"klc"],Vanceburg:[1,"registry"],"Vine Grove":[2,"registry"],"West Liberty":[1,"registry"],
  // guide: 2026 payroll guides, news reports or older local documents
  Ashland:[2.375,"guide"],"Bowling Green":[2,"guide"],Columbia:[1,"guide"],Crestwood:[0,"guide"],Danville:[1.9,"guide"],Florence:[2,"guide"],
  Franklin:[1,"registry"],Georgetown:[1,"guide"],Hazard:[1.25,"registry"],Henderson:[1.65,"guide"],"Highland Heights":[1,"registry"],Hindman:[0,"guide"],
  Hopkinsville:[1.95,"guide"],Inez:[0,"guide"],Jenkins:[1.5,"guide"],Lawrenceburg:[0,"guide"],Louisa:[0,"guide"],Madisonville:[2.5,"guide"],
  "Mount Sterling":[2,"guide"],Murray:[1,"guide"],Nicholasville:[1.5,"guide"],Owensboro:[1.78,"guide"],Paducah:[2,"guide"],Paintsville:[1.5,"klc"],
  Pikeville:[2,"guide"],Prestonsburg:[1.5,"guide"],Radcliff:[2.25,"klc"],Richmond:[2,"guide"],Russellville:[2,"registry"],Salyersville:[1,"klc"],
  Somerset:[1.2,"guide"],Wilmore:[2,"guide"],Winchester:[2.15,"guide"],
  // klc: Kentucky League of Cities city occupational tax table (FY2023), 410 cities; 0 = no city wage tax
  Auburn:[1.5,"klc"],Barbourville:[1.0,"klc"],Bardwell:[1,"guide"],Beattyville:[1.0,"klc"],Brandenburg:[0.33,"registry"],Brodhead:[1.0,"klc"],Brooksville:[1.75,"klc"],Burkesville:[2.0,"klc"],
  Carlisle:[1.0,"klc"],Clarkson:[1.2,"klc"],"Clay City":[1.0,"klc"],Clinton:[0.5,"klc"],"Crab Orchard":[1.0,"klc"],"Dawson Springs":[1.5,"klc"],"Dry Ridge":[1.25,"klc"],Earlington:[1.5,"klc"],
  Eddyville:[1.5,"klc"],Edmonton:[1.5,"klc"],"Elkhorn City":[1.0,"klc"],Flemingsburg:[1.0,"klc"],Fordsville:[1.25,"klc"],"Fountain Run":[1.0,"klc"],Fulton:[2.0,"klc"],Grayson:[1.0,"klc"],
  Greenup:[1.0,"klc"],Guthrie:[1.0,"klc"],"Hebron Estates":[1.0,"klc"],"Horse Cave":[1.0,"klc"],Irvington:[0.25,"registry"],Jackson:[2.0,"klc"],Jamestown:[1.0,"klc"],Jeffersonville:[1.0,"klc"],
  "Junction City":[1.0,"klc"],Lancaster:[0.5,"klc"],"Lebanon Junction":[1.5,"klc"],Lewisburg:[1.5,"klc"],"Mount Olivet":[2.0,"klc"],Muldraugh:[1.75,"klc"],Munfordville:[0.75,"klc"],Owenton:[1.0,"klc"],
  "Pioneer Village":[1.5,"klc"],Prestonville:[1.6,"klc"],"Russell Springs":[1.0,"klc"],Salem:[1,"registry"],"Silver Grove":[1.5,"klc"],"Smiths Grove":[1.0,"klc"],Stanton:[1.0,"klc"],Taylorsville:[0.75,"klc"],
  Tompkinsville:[1.75,"klc"],Warsaw:[1.0,"klc"],"West Buechel":[1.5,"klc"],"West Point":[1.0,"klc"],Whitesville:[1.15,"registry"],Williamsburg:[1.0,"klc"],Wurtland:[1.0,"klc"],
  Albany:[0,"klc"],Allen:[0,"klc"],Anchorage:[0,"klc"],Arlington:[0,"klc"],"Audubon Park":[0,"klc"],Bancroft:[0,"klc"],Barbourmeade:[0,"klc"],Barlow:[0,"klc"],
  "Beaver Dam":[0,"klc"],Bedford:[0,"klc"],Beechwood:[0,"klc"],Bellefonte:[0,"klc"],Bellemeade:[0,"klc"],Bellewood:[0,"klc"],Benham:[0,"klc"],Berry:[0,"klc"],
  Bloomfield:[0,"klc"],"Blue Ridge Manor":[0,"klc"],Booneville:[0,"klc"],Bradfordsville:[0,"klc"],Bremen:[0,"klc"],Briarwood:[0,"klc"],"Broeck Pointe":[0,"klc"],"Brownsboro Farm":[0,"klc"],
  "Brownsboro Village":[0,"klc"],Buckhorn:[0,"klc"],Burgin:[0,"klc"],Burnside:[0,"klc"],Butler:[0,"klc"],Calhoun:[0,"klc"],California:[0,"klc"],Cambridge:[0,"klc"],
  Campbellsburg:[0,"klc"],Campton:[0,"klc"],Caneyville:[0,"klc"],Carrollton:[0,"klc"],Carrsville:[0,"klc"],Centertown:[0,"klc"],"Central City":[0,"klc"],Clay:[0,"klc"],
  Cloverport:[0,"klc"],Coldstream:[0,"klc"],Columbus:[0,"klc"],Concord:[0,"klc"],Corinth:[0,"klc"],Corydon:[0,"klc"],Creekside:[0,"klc"],Crestview:[0,"klc"],
  Crittenden:[0,"klc"],Crofton:[0,"klc"],Crossgate:[0,"klc"],Cumberland:[0,"klc"],Dixon:[0,"klc"],"Douglass Hills":[0,"klc"],Dover:[0,"klc"],Drakesboro:[0,"klc"],
  "Druid Hills":[0,"klc"],Ekron:[0,"klc"],Eubank:[0,"klc"],Evarts:[0,"klc"],Ewing:[0,"klc"],Fairfield:[0,"klc"],Ferguson:[0,"klc"],Fincastle:[0,"klc"],
  Flatwoods:[0,"klc"],"Fleming-Neon":[0,"klc"],"Forest Hills":[0,"klc"],"Fox Chase":[0,"klc"],Fredonia:[0,"klc"],Frenchburg:[0,"klc"],Germantown:[0,"klc"],Ghent:[0,"klc"],
  Glencoe:[0,"klc"],Glenview:[0,"klc"],"Glenview Hills":[0,"klc"],"Glenview Manor":[0,"klc"],"Goose Creek":[0,"klc"],Goshen:[0,"klc"],"Grand Rivers":[0,"klc"],Gratz:[0,"klc"],
  "Graymoor-Devondale":[0,"klc"],"Green Spring":[0,"klc"],Greenville:[0,"klc"],Hanson:[0,"klc"],Hardin:[0,"klc"],Hardinsburg:[0,"klc"],Harlan:[0,"klc"],Hawesville:[0,"klc"],
  Hazel:[0,"klc"],"Heritage Creek":[0,"klc"],"Hickory Hill":[0,"klc"],"Hills and Dales":[0,"klc"],"Hollow Creek":[0,"klc"],Hollyvilla:[0,"klc"],"Houston Acres":[0,"klc"],"Hunters Hollow":[0,"klc"],
  Hurstbourne:[0,"klc"],"Hurstbourne Acres":[0,"klc"],Hustonville:[0,"klc"],Hyden:[0,"klc"],"Indian Hills":[0,"klc"],Irvine:[0,"klc"],Island:[0,"klc"],Kevil:[0,"klc"],
  Kingsley:[0,"klc"],Kuttawa:[0,"klc"],LaCenter:[0,"klc"],LaFayette:[0,"klc"],"Lakeview Heights":[0,"klc"],"Langdon Place":[0,"klc"],Lewisport:[0,"klc"],Liberty:[0,"klc"],
  Lincolnshire:[0,"klc"],Livermore:[0,"klc"],Livingston:[0,"klc"],Loretto:[0,"klc"],Loyall:[0,"klc"],Lynch:[0,"klc"],Lynnview:[0,"klc"],Mackville:[0,"klc"],
  Manchester:[0,"klc"],"Manor Creek":[0,"klc"],Martin:[0,"klc"],"Maryhill Estates":[0,"klc"],McHenry:[0,"klc"],"Meadow Vale":[0,"klc"],"Meadowbrook Farm":[0,"klc"],"Meadowview Estates":[0,"klc"],
  Mentor:[0,"klc"],Milton:[0,"klc"],"Mockingbird Valley":[0,"klc"],Monticello:[0,"klc"],Moorland:[0,"klc"],Morganfield:[0,"klc"],"Mortons Gap":[0,"klc"],"Murray Hill":[0,"klc"],
  Nebo:[0,"klc"],"New Castle":[0,"klc"],"New Haven":[0,"klc"],"Norbourne Estates":[0,"klc"],"North Middletown":[0,"klc"],Northfield:[0,"klc"],Norwood:[0,"klc"],Oakland:[0,"klc"],
  "Old Brownsboro Place":[0,"klc"],"Olive Hill":[0,"klc"],"Orchard Grass Hills":[0,"klc"],Owingsville:[0,"klc"],"Parkway Village":[0,"klc"],Pembroke:[0,"klc"],"Pewee Valley":[0,"klc"],"Pippa Passes":[0,"klc"],
  Plantation:[0,"klc"],Pleasureville:[0,"klc"],"Plum Springs":[0,"klc"],Powderly:[0,"klc"],Prospect:[0,"klc"],Providence:[0,"klc"],Ravenna:[0,"klc"],Richlawn:[0,"klc"],
  "River Bluff":[0,"klc"],Riverwood:[0,"klc"],Robards:[0,"klc"],Rochester:[0,"klc"],Rockport:[0,"klc"],"Rolling Fields":[0,"klc"],"Rolling Hills":[0,"klc"],Sacramento:[0,"klc"],
  Sadieville:[0,"klc"],"Salt Lick":[0,"klc"],Sanders:[0,"klc"],"Sandy Hook":[0,"klc"],Sardis:[0,"klc"],"Science Hill":[0,"klc"],Sebree:[0,"klc"],"Seneca Gardens":[0,"klc"],
  Sharpsburg:[0,"klc"],Slaughters:[0,"klc"],Smithfield:[0,"klc"],Smithland:[0,"klc"],Sonora:[0,"klc"],"South Carrollton":[0,"klc"],"South Shore":[0,"klc"],Sparta:[0,"klc"],
  "Spring Mill":[0,"klc"],"Spring Valley":[0,"klc"],"St. Charles":[0,"klc"],"St. Regis Park":[0,"klc"],"Stamping Ground":[0,"klc"],"Strathmoor Manor":[0,"klc"],"Strathmoor Village":[0,"klc"],Sturgis:[0,"klc"],
  Sycamore:[0,"klc"],"Ten Broeck":[0,"klc"],Thornhill:[0,"klc"],Trenton:[0,"klc"],Uniontown:[0,"klc"],Upton:[0,"klc"],Warfield:[0,"klc"],"Watterson Park":[0,"klc"],
  Waverly:[0,"klc"],Wayland:[0,"klc"],Wellington:[0,"klc"],Westwood:[0,"klc"],Wheatcroft:[0,"klc"],Wheelwright:[0,"klc"],"White Plains":[0,"klc"],Whitesburg:[0,"klc"],
  Wickliffe:[0,"klc"],Wildwood:[0,"klc"],Williamstown:[0,"klc"],Willisburg:[0,"klc"],"Windy Hills":[0,"klc"],Wingo:[0,"klc"],Woodburn:[0,"klc"],Woodbury:[0,"klc"],
  "Woodland Hills":[0,"klc"],"Woodlawn Park":[0,"klc"],Worthington:[0,"klc"],"Worthington Hills":[0,"klc"],Worthville:[0,"klc"]};

// School district wage taxes, KDE "Tax Rates Levied" 2025-26 (KRS 160.605/160.611): only residents of the district, only on pay for work inside it.
// Jefferson's 0.75% (JCPS and Anchorage Independent) is handled in localRate0. The cities listed run their own independent district with no wage tax.
// ponytail: district = county minus the listed independent-district city; boundaries don't follow city limits exactly.
const SCHOOL_TAX={Boone:[0.5,["Walton"]],Cumberland:[0.5,[]],Fayette:[0.5,[]],Marshall:[0.5,[]],Scott:[0.5,[]],Warren:[0.5,["Bowling Green"]]};
function localRate(workCounty,workCity,liveCounty,liveCity){
  const L=localRate0(workCounty,workCity,liveCounty), sc=SCHOOL_TAX[liveCounty];
  if(!sc||workCounty!==liveCounty||sc[1].includes(liveCity)) return L;
  return {...L,rate:L.rate+sc[0],school:sc[0],why:`${L.why} Because you live and work in the ${liveCounty} County school district, its ${sc[0]}% school wage tax is added on top.`};
}
// Returns {rate (%), src: official | guide | county | cityUnknown, why}
function localRate0(workCounty,workCity,liveCounty){
  if(workCounty==="Jefferson"){
    const res=liveCounty==="Jefferson", metro=1.45+(res?.75:0), city=CITY_RATE[workCity];
    const why=`Louisville Metro charges 1.25% plus 0.20% for TARC buses${res?", plus 0.75% for JCPS schools because you live in Jefferson County":". Because you live outside Jefferson County, you skip the 0.75% school fee"}.`;
    if(workCity==="Louisville"||workCity===ELSE) return {rate:metro,src:"official",why};
    if(city) return {rate:metro+city[0],src:city[1],why:`${why} ${workCity} ${city[0]?`adds its own ${city[0]}% on top`:"has no city wage tax of its own"}.`};
    return {rate:metro,src:"cityUnknown",why:`${why} ${workCity} may add its own fee on top; we couldn't confirm it, so check your pay stub.`};
  }
  if(workCounty==="Fayette") return {rate:2.25,src:"official",why:"Lexington charges one 2.25% fee on pay earned anywhere in Fayette County."};
  const county=DATA.countyTax[workCounty]||0, city=CITY_RATE[workCity];
  const cTxt=county?`${workCounty} County charges ${county}%`:`${workCounty} County has no county wage tax`;
  if(workCity===ELSE) return {rate:county,src:"county",why:cTxt+" outside city limits."};
  if(!city) return {rate:county,src:"cityUnknown",why:`${cTxt}. We couldn't confirm a rate for ${workCity}; many Kentucky cities add their own fee, so check your pay stub.`};
  const stack=STACK.has(workCounty)||!BIG.has(workCounty);
  return {rate:stack?city[0]+county:Math.max(city[0],county),src:city[1],
    why:`${workCity} ${city[0]?`charges ${city[0]}%`:"has no city wage tax"}. ${cTxt}${county&&city[0]?stack?(STACK.has(workCounty)?", added on top of the city fee.":". In counties under 30,000 people Kentucky doesn't credit one fee against the other, so you pay both."):", but the city fee counts toward it, so you pay whichever is higher.":"."}`};
}

function bracketTax(income,status){
  const b=FED.brackets[status]; let tax=0,lo=0;
  for(let i=0;i<FED.rates.length;i++){
    const hi=i<b.length?b[i]:Infinity;
    if(income>lo) tax+=(Math.min(income,hi)-lo)*FED.rates[i];
    lo=hi;
  }
  return tax;
}

function healthTier(people){return people<=1?0:people===2?1:2}

// Core annual math for one place. Pure: (state, data, place) -> numbers.
function compute(s,D,place){
  const kids=s.under5+s.schoolAge, people=s.adults+kids;
  const status=s.adults===2?"mfj":kids>0?"hoh":"single";
  const C=D.counties[place.liveCounty];
  const inc=[s.income1,s.adults===2?s.income2:0];
  const gross=inc[0]+inc[1];
  const k401=inc.map(x=>x*s.k401/100), k401Sum=k401[0]+k401[1];
  const matchSum=gross*s.match/100;
  const A=s.actual; // optional {category: monthly dollars} the user entered; otherwise county typical costs
  const prem=A?Math.min(C.health[healthTier(people)],A.health*12):C.health[healthTier(people)];
  // Payroll taxes per earner; health premium is pre tax for FICA (assigned to the higher earner)
  const premOn=inc[0]>=inc[1]?0:1;
  let fica=0;
  inc.forEach((w,i)=>{const fw=Math.max(0,w-(i===premOn?prem:0)); fica+=Math.min(fw,FED.ssCap)*FED.ssRate+fw*FED.medRate;});
  fica+=Math.max(0,gross-prem-FED.addMedThr[status])*FED.addMed;
  const agi=Math.max(0,gross-k401Sum-prem);
  const fedTaxable=Math.max(0,agi-FED.std[status]);
  const fedBefore=bracketTax(fedTaxable,status);
  const under17=kids, over=Math.max(0,agi-FED.ctcPhase[status]);
  const ctc=Math.max(0,FED.ctc*under17-50*Math.ceil(over/1000));
  const nonref=Math.min(ctc,fedBefore);
  const refund=Math.min(ctc-nonref,FED.ctcRefund*under17,.15*Math.max(0,gross-2500));
  // ponytail: AGI stands in for earned income; skips the 25 to 64 age rule (no kids) and the investment income limit
  const ek=Math.min(kids,3), E=FED.eitc, eStart=E.start[status==="mfj"?"mfj":"single"][ek];
  const eitc=gross?Math.max(0,Math.min(E.max[ek],agi*E.phaseIn[ek])-Math.max(0,agi-eStart)*E.phaseOut[ek]):0;
  const fed=fedBefore-nonref-refund-eitc;
  const kyBefore=Math.max(0,agi-KY.std*s.adults)*KY.rate, band=KY.fscBands.find(([r])=>agi<=KY.fsc[Math.min(people,4)-1]*r);
  const kyFsc=kyBefore*(band?band[1]:0), ky=kyBefore-kyFsc;
  const custom=s.localOverride!==""&&isFinite(parseFloat(s.localOverride));
  const lr=custom?{rate:parseFloat(s.localOverride),src:"custom",why:"Using the rate you entered."}:localRate(place.workCounty,place.workCity,place.liveCounty,place.liveCity);
  const local=gross*lr.rate/100;
  const taxes=fica+fed+ky+local;
  const refundAmt=Math.max(0,-fed); // credits beyond federal tax come back once a year at filing, not in paychecks
  const net=gross-taxes-refundAmt-k401Sum; // paycheck take home; health premium shown as a budget line
  // Living costs from county data
  const idx=(s.adults-1)*4+Math.min(kids,3), fs=Math.min(people,6)-1;
  const rent=C.rent[idx]*s.housing/100;
  const util=D.util[idx];
  const food=(s.adults*C.food[fs][0]+kids*C.food[fs][1])*s.food/100;
  const car=C.car[fs]*s.car/100;
  const care=(s.under5*(C.care[0]+C.care[1])/2+s.schoolAge*C.care[2])*260;
  const health=prem+C.health[3]*people;
  const phone=D.phone[s.adults-1]+D.broadband;
  const fun=Math.max(0,net)*s.fun/100, other=Math.max(0,net)*(s.other||0)/100;
  const debtMin=s.debts.reduce((a,d)=>a+(d.bal>0?d.min:0),0)*12;
  const extra=s.debts.some(d=>d.bal>0)?s.extra*12:0;
  const spend=A?{housing:A.housing*12,food:A.food*12,car:A.car*12,care:A.care*12,health:A.health*12,phone:A.phone*12,fun:A.fun*12,other:A.other*12,debt:debtMin+extra}
    :{housing:rent+util,food,car,care,health,phone,fun,other,debt:debtMin+extra};
  const spent=Object.values(spend).reduce((a,b)=>a+b,0);
  const left=net-spent;
  const essentials=(spend.housing+spend.food+spend.car+spend.care+spend.health+spend.phone+debtMin)/12;
  return {status,gross,fica,fed,ky,local,localRate:lr,taxes,k401Sum,matchSum,net,spend,spent,left,debtMin,essentials,ctc:nonref+refund,eitc,kyFsc,refund:refundAmt};
}

// Month by month debt payoff. Fixed budget = minimums + extra; freed minimums roll to the target debt.
function payoff(debts,strategy,extra,lump=0){
  let ds=debts.filter(d=>d.bal>0).map(d=>({...d}));
  const budget=ds.reduce((a,d)=>a+d.min,0)+extra;
  const paid=[], lumps=[], bal=[ds.reduce((a,d)=>a+d.bal,0)]; let interest=0,m=0;
  while(ds.some(d=>d.bal>0.005)&&m<600){
    ds.forEach(d=>{if(d.bal>0){const i=d.bal*d.rate/1200; d.bal+=i; interest+=i;}});
    const L=lump&&(m+1)%12===3&&ds.some(d=>d.bal>0&&d.rate>=8)?lump:0; // yearly tax refund, February
    let pool=budget+L, spent=0;
    ds.forEach(d=>{if(d.bal>0){const p=Math.min(d.min,d.bal); d.bal-=p; pool-=p; spent+=p;}});
    const order=ds.filter(d=>d.bal>0).sort(strategy==="avalanche"?(a,b)=>b.rate-a.rate:(a,b)=>a.bal-b.bal);
    for(const d of order){if(pool<=0)break; const p=Math.min(pool,d.bal); d.bal-=p; pool-=p; spent+=p;}
    const used=L-Math.min(L,Math.max(0,pool)); lumps.push(used); paid.push(spent-used); bal.push(Math.max(0,ds.reduce((a,d)=>a+d.bal,0))); m++;
  }
  return {months:m,interest,paid,lumps,bal,budget,stuck:m>=600};
}

// Monthly projection of 401k + investing + cash at a real return r (%/yr), starting from today's balances.
function project(s,res,debt,r,years){
  const mr=Math.pow(1+r/100,1/12)-1;
  const share=s.investShare/100;
  const k=(res.k401Sum+res.matchSum)/12, gr=1+(s.growth||0)/100; // growth: yearly raise in what goes in, after inflation
  let a=s.startInvest,b=0,c=s.startCash; const pts=[a+c];
  for(let m=1;m<=years*12;m++){
    const freed=debt.budget>0?debt.budget-(debt.paid[m-1]||0):0;
    const up=Math.pow(gr,Math.floor((m-1)/12));
    const save=Math.max(0,res.left/12+freed)+(m%12===3?Math.max(0,(res.refund||0)-((debt.lumps||[])[m-1]||0))/up:0); // paid off debt frees its payment for saving; the tax refund arrives once a year
    a=a*(1+mr)+k*up; b=b*(1+mr)+save*up*share; c=c+save*up*(1-share);
    if(m%12===0) pts.push(a+b+c);
  }
  return {pts,k401:a,invest:b,cash:c};
}

// Money health score, 0 to 100: five parts worth 20 points each.
function healthScore(s,R){
  const lerp=(v,good,bad)=>Math.max(0,Math.min(1,(v-bad)/(good-bad)));
  const g=R.gross||1;
  const parts=[
    ["Saving",lerp((Math.max(0,R.left)+R.k401Sum+R.matchSum)/g,.20,0),`You save ${Math.round((Math.max(0,R.left)+R.k401Sum+R.matchSum)/g*100)}% of your gross pay. Benchmark: 20% or more.`],
    ["Emergency cushion",lerp(s.startCash/Math.max(1,R.essentials),6,0),`Your cash would cover ${(s.startCash/Math.max(1,R.essentials)).toFixed(1)} months of essential bills. Benchmark: 6 months.`],
    ["Debt payments",lerp(R.debtMin/g,.10,.36),`Minimum debt payments take ${Math.round(R.debtMin/g*100)}% of your gross pay. Benchmark: 10% or less.`],
    ["Housing cost",lerp(R.spend.housing/g,.28,.50),`Housing takes ${Math.round(R.spend.housing/g*100)}% of your gross pay. Benchmark: 28% or less.`],
    ["Retirement saving",lerp((R.k401Sum+R.matchSum)/g,.15,0),`You and your employer put ${Math.round((R.k401Sum+R.matchSum)/g*100)}% of your pay into your 401k. Benchmark: 15% or more.`]];
  return {score:Math.round(parts.reduce((a,p)=>a+p[1]*20,0)),parts};
}

// Recommended monthly plan. R = what you do now, T = typical costs for your county and household.
// Needs stay near county typical, wants stay within 30% of take home and give way to a 20% savings goal,
// and the plan never spends more than take home pay. Leftover is split by the usual order:
// starter emergency fund and high interest debt first, then a full emergency fund, then investing.
function recommendPlan(s,R,T){
  const net=Math.max(0,R.net/12), gm=R.gross/12, a=k=>R.spend[k]/12, t=k=>T.spend[k]/12;
  const p={housing:Math.min(a("housing"),Math.max(.30*gm,t("housing"))),food:Math.min(a("food"),t("food")*1.1),car:Math.min(a("car"),t("car")),
    care:a("care"),health:a("health"),phone:Math.min(a("phone"),t("phone")),debtMin:R.debtMin/12};
  const needs=()=>p.housing+p.food+p.car+p.care+p.health+p.phone+p.debtMin;
  const wantsNow=a("fun")+a("other");
  let wants=Math.min(wantsNow,.30*net,Math.max(Math.min(wantsNow,.10*net),net-needs()-.20*net));
  // Still over? Trim wants, then housing (roommate or cheaper place), car, groceries
  let gap=needs()+wants-net;
  if(gap>0){const c=Math.min(wants,gap); wants-=c; gap-=c;}
  for(const [k,floor] of [["housing",.6],["car",.6],["food",.85]]) if(gap>0){const c=Math.min(gap,p[k]*(1-floor)); p[k]-=c; gap-=c;}
  p.fun=wantsNow?wants*a("fun")/wantsNow:0; p.other=wantsNow?wants*a("other")/wantsNow:0;
  const L=Math.max(0,net-needs()-wants);
  const efm=s.startCash/Math.max(1,R.essentials), hot=s.debts.some(d=>d.bal>0&&d.rate>=8);
  const [dx,cs]=hot?(efm<1?[.5,.5]:[.7,.15]):efm<(s.efMonths||3)?[0,.6]:[0,.2];
  p.debtExtra=L*dx; p.cash=L*cs; p.invest=L-p.debtExtra-p.cash;
  return {p,short:Math.max(0,gap),efm,hot};
}

// Follow the recommended plan month by month: debt extra goes highest rate first, cash fills the emergency fund then goals,
// and money freed by paid off debt or a full emergency fund rolls into investing. 401k rises to the full match.
// Returns the month (1 = next month, 0 = already) each milestone is reached, or null if not within `years`.
function followPlan(s,R,p,years,r){
  const mr=Math.pow(1+r/100,1/12)-1, target=s.efMonths*R.essentials, starter=R.essentials;
  const ds=s.debts.filter(d=>d.bal>0).map(d=>({...d})), budget=R.debtMin/12+p.debtExtra;
  const goals=s.goals.map(g=>({name:g.name,need:Math.max(0,g.target-g.saved)}));
  const k=(R.gross*Math.max(s.k401,s.match)/100+R.matchSum)/12;
  let cash=s.startCash, inv=0, ret=s.startInvest, cash12=s.startCash;
  const ms={starter:cash>=starter?0:null,efFull:cash>=target?0:null,debtFree:ds.length?null:0,goals:goals.map(g=>g.need?null:0)};
  for(let m=1;m<=years*12;m++){
    let spare=0; const lump=m%12===3?R.refund||0:0, hot=lump&&ms.debtFree===null&&ds.some(d=>d.bal>0&&d.rate>=8); // yearly tax refund
    if(ms.debtFree===null){
      ds.forEach(d=>{if(d.bal>0) d.bal+=d.bal*d.rate/1200;});
      let pool=budget+(hot?lump:0);
      ds.forEach(d=>{if(d.bal>0){const x=Math.min(d.min,d.bal);d.bal-=x;pool-=x;}});
      for(const d of ds.filter(d=>d.bal>0).sort((a,b)=>b.rate-a.rate)){if(pool<=0)break;const x=Math.min(pool,d.bal);d.bal-=x;pool-=x;}
      if(ds.every(d=>d.bal<0.005)){ms.debtFree=m;spare=Math.max(0,pool);}
    } else spare=budget;
    let save=p.cash+spare+(hot?0:lump);
    if(cash<target){const x=Math.min(save,target-cash);cash+=x;save-=x;}
    if(cash>=target) goals.forEach((g,i)=>{if(g.need>0&&save>0){const x=Math.min(save,g.need);g.need-=x;save-=x;if(g.need<=0)ms.goals[i]=m;}});
    inv=inv*(1+mr)+p.invest+save; ret=ret*(1+mr)+k;
    if(ms.starter===null&&cash>=starter) ms.starter=m;
    if(ms.efFull===null&&cash>=target-0.5) ms.efFull=m;
    if(m===12) cash12=cash;
  }
  return {ms,goals,cash12,total:cash+inv+ret,target,starter};
}

// ---- Hospital bills: nonprofit hospital financial assistance policies (see hospital-research.md) ----
// 2026 HHS poverty guidelines: $15,960 for 1 person plus $5,680 for each extra person.
const FPL=n=>15960+5680*(Math.max(1,n)-1);
// tiers: [up to % of poverty line, what you get]. A number = percent off; "agb" = pay no more than insured patients;
// "halfagb" = half of what insured patients pay; "slide" = a sliding scale discount the hospital sets.
const HOSPITALS=[
  {id:"uk",name:"UK HealthCare",counties:["Fayette"],tiers:[[300,100]],date:"August 2026",unins:"60% off charges for uninsured patients",
    url:"https://ukhealthcare.uky.edu/patients-visitors/patients/payment-insurance/financial-assistance",note:"Apply before the bill goes to a collection agency; UK can't forgive balances that are already there."},
  {id:"norton",name:"Norton Healthcare",counties:["Jefferson"],tiers:[[350,100]],date:"September 2025",phone:"502-479-6300",
    url:"https://nortonhealthcare.com/patient-resources/billing-information/financial-assistance/",note:"Norton also checks savings and other assets and asks for three months of bank statements."},
  {id:"baptist",name:"Baptist Health",counties:["Jefferson","Fayette","Whitley","Hardin","Oldham","Hopkins","McCracken","Madison"],tiers:[[300,100],[400,50]],date:"June 2026",
    url:"https://www.baptisthealth.com/patients-visitors/planning/financial-assistance",note:"Doctors who bill separately from the hospital aren't covered; ask them about their own policy."},
  {id:"uofl",name:"UofL Health",counties:["Jefferson","Shelby","Bullitt"],tiers:[[300,100]],date:"2022",older:true,
    url:"https://uoflhealth.org/wp-content/uploads/2022/10/2022-Financial-Assistance-Policy-Updated-1.pdf"},
  {id:"owensboro",name:"Owensboro Health",counties:["Daviess","Muhlenberg","Grayson"],tiers:[[400,100],[450,"slide"]],date:"January 2026",unins:"10% off for paying promptly",
    url:"https://www.owensborohealth.org/patient-visitor/billing/financial-assistance",note:"Owensboro Health counts savings and checking balances as part of income."},
  {id:"chisj",name:"CHI Saint Joseph Health",counties:["Fayette","Laurel","Montgomery","Madison","Nelson"],tiers:[[200,100],[400,"agb"]],date:"current summary",
    url:"https://www.commonspirit.org/patient-resources/saint-joseph-health-financial-assistance"},
  {id:"mercy",name:"Mercy Health (Lourdes, Marcum and Wallace)",counties:["McCracken","Estill"],tiers:[[200,100],[400,"slide"]],date:"September 2026",phone:"1-855-732-0138",unins:"an automatic self pay discount",
    url:"https://www.mercy.com/financial-assistance"},
  {id:"stelizabeth",name:"St. Elizabeth Healthcare",counties:["Kenton","Boone","Campbell","Grant"],tiers:[[200,100],[300,50],[400,25]],date:"2023",older:true,phone:"877-424-5750",
    url:"https://www.stelizabeth.com/docs/default-source/pay-my-bill/documents/2023/2023-fap-plain-language-summary-pls---20230517.pdf"},
  {id:"medcenter",name:"Med Center Health",counties:["Warren","Logan","Simpson","Ohio","Allen","Clinton"],tiers:[[200,100],[300,50],[400,25]],date:"current web page",phone:"270-745-1100",unins:"20% off for self pay patients, plus 10% for paying quickly",
    url:"https://medcenterhealth.org/cfr/billing-policies/financial-assistance/"},
  {id:"stclaire",name:"UK St. Claire",counties:["Rowan"],tiers:[[200,100]],date:"June 2026",unins:"25% off for uninsured patients",
    url:"https://www.st-claire.org/sites/uksc/files/2026-06/Healthcare-Financial-Assistance-Program-A10-0605-02.pdf"},
  {id:"pmc",name:"Pikeville Medical Center",counties:["Pike"],tiers:[[150,100],[268,"halfagb"],[400,"agb"]],date:"May 2025",
    url:"https://www.pmcky.org/financial-assistance-policy/"},
  {id:"kdmc",name:"UK King's Daughters",counties:["Boyd","Greenup"],tiers:[[150,100],[200,90],[250,80]],date:"July 2025",phone:"606-408-4118",unins:"70% off hospital charges for uninsured patients",
    url:"https://www.kdmc.org/documents/Financial%20Assistance%20Policy/Updated-FAP-07.31.25.pdf"},
  {id:"emh",name:"Ephraim McDowell Health",counties:["Boyle","Lincoln","Casey","Mercer"],tiers:[[125,100],[300,"slide"]],date:"2020",older:true,
    url:"https://www.emhealth.org/wp-content/uploads/dlm_uploads/2018/09/Financial-Assistance-Program-Policy-Approved-05-26-20.pdf"},
  {id:"arh",name:"ARH (Appalachian Regional Healthcare)",counties:["Perry","Harlan","Floyd","Letcher","Leslie","Morgan","Knox","Pike"],tiers:null,phone:"859-226-2440",unins:"up to 40% off for uninsured patients",
    url:"https://arh.org/financial-assistance"},
  {id:"tj",name:"T.J. Regional Health",counties:["Barren","Adair"],tiers:null,
    url:"https://res.cloudinary.com/dpmykpsih/image/upload/tj-samson-site-251/media/c727577d19194604a530602b5e7069ec/financial-assistance-plain-language-summary.pdf"}];
// What a household can expect on a bill: share of the poverty line, the hospital's tier, an estimate when the tier is a fixed percent,
// and the Kentucky programs that may apply (Medicaid for adults to 138%, the state's DSH hospital program to 100%, KRS 205.640).
function billCheck(size,income,amount,hospId,ins){
  const pct=Math.round(income/FPL(size)*100), h=HOSPITALS.find(x=>x.id===hospId);
  let tier=null; if(h&&h.tiers) tier=h.tiers.find(([max])=>pct<=max)||null;
  const off=tier&&typeof tier[1]==="number"?tier[1]:null;
  return {pct,h,tier,off,owe:off!=null?Math.round(amount*(1-off/100)):null,limit:h&&h.tiers?h.tiers[h.tiers.length-1][0]:null,
    medicaid:pct<=138&&ins!=="medicaid",dsh:pct<=100&&ins==="none"};
}

// ---- Help you may qualify for: 2026 limits as a percent of the 2026 poverty line (see benefits-research.md) ----
// s = household (adults, under5, schoolAge, income1, income2); R = compute() result for the credits it already works out.
function benefitsFor(s,R){
  const kids=s.under5+s.schoolAge, size=s.adults+kids, income=s.income1+(s.adults===2?s.income2:0), pct=Math.round(income/FPL(size)*100), out=[];
  const add=(id,name,limit,why,how)=>out.push({id,name,limit,why,how});
  if(!income) return {pct,list:out};
  if(pct<=138) add("medicaid","Kentucky Medicaid for adults",138,"Free or low cost health coverage for adults.","Apply at kynect.ky.gov or call 855-459-6328.");
  if(kids&&pct<=218) add("kchip","Medicaid or KCHIP for your kids",218,`Free or low cost health coverage for children under 19 up to 200% of the poverty line, and up to 218% if they're uninsured.`,"Apply at kynect.ky.gov or call 855-459-6328.");
  if(pct<=200) add("snap","SNAP food benefits",200,"Money each month on an EBT card for groceries. Kentucky's gross income limit is 200% of the poverty line; your income after certain costs must also be at or below the poverty line. Federal rules may change.","Apply at kynect.ky.gov or call 855-459-6328.");
  if(s.under5&&pct<=185) add("wic","WIC",185,"Healthy food, formula and nutrition help for pregnant women, babies and children under 5.","Contact your local health department.");
  if(s.schoolAge&&pct<=185) add("meals",pct<=130?"Free school meals":"Reduced price school meals",pct<=130?130:185,`School breakfast and lunch are free up to 130% of the poverty line and reduced price up to 185% for the 2026 to 2027 school year.`,"Fill out the meal application from your child's school.");
  if(pct<=150) add("liheap","Help with heating and cooling bills (LIHEAP)",150,"Kentucky's energy assistance pays part of heating bills in winter and cooling bills in summer.","Apply at your local Community Action agency (find it at capky.org) during the sign up windows.");
  if(pct<=200) add("wx","Free home weatherization",200,"Insulation, sealing and repairs that lower your energy bills for good.","Ask your local Community Action agency.");
  if(pct<=135) add("lifeline","Lifeline phone or internet discount",135,"A monthly discount on one phone or internet plan.","Apply at lifelinesupport.org or through your phone company.");
  // CCAP: 85% of Kentucky's state median income, monthly, by family size 2 to 8 (CHFS fact sheet, 2025 SMI)
  const ccap=[0,0,4639,5731,6822,7914,9005,9210,9414][Math.min(size,8)];
  if(kids&&ccap&&income<=ccap*12) add("ccap","Help paying for child care (CCAP)",null,`Kentucky's Child Care Assistance Program helps pay for child care for kids under 13 while you work or go to school. The limit for your family is about ${"$"+(ccap*12).toLocaleString("en-US")} a year (85% of Kentucky's state median income).`,"Apply at kynect.ky.gov.");
  if(R&&R.eitc>0) add("eitc",`Earned income credit, about ${Math.round(R.eitc).toLocaleString("en-US")} dollars`,null,"A federal tax credit you only get by filing a tax return, even if you owe no tax.","Free tax filing at an IRS VITA site; call 211 to find one.");
  if(R&&R.kyFsc>0) add("kyfsc",`Kentucky family size credit, about ${Math.round(R.kyFsc).toLocaleString("en-US")} dollars`,null,"Lowers or erases your Kentucky income tax. It's already counted in your take home pay here.","Claimed on your Kentucky tax return.");
  return {pct,list:out};
}

// Sort a statement line into a budget category by keywords.
const KEYWORDS={housing:["rent","mortgage","apartment","property mgmt","lg&e","kentucky utilities","duke energy","water","sewer","columbia gas","atmos","electric","utility","hoa"],
  food:["kroger","meijer","aldi","save a lot","whole foods","grocery","food lion","trader joe","piggly","foods","market","costco","sam's club","walmart"],
  car:["shell","bp ","speedway","marathon","circle k","thorntons","exxon","chevron","fuel","gas station","auto","car payment","geico","progressive","state farm","parking","valvoline","jiffy","toyota","honda","ford credit"],
  care:["daycare","day care","child care","childcare","kindercare","preschool","learning center"],
  health:["pharmacy","cvs","walgreens","doctor","hospital","dental","dentist","clinic","baptist health","uk healthcare","norton","medical","optometr","humana","anthem"],
  phone:["verizon","at&t","t-mobile","spectrum","comcast","xfinity","internet","cricket","boost mobile","windstream"],
  fun:["netflix","spotify","hulu","disney","prime video","restaurant","bar ","grill","pizza","mcdonald","starbucks","chick-fil-a","doordash","uber eats","grubhub","movie","cinema","ticket","steam","xbox","playstation","hbo","youtube","taco","wendy","burger","cafe","coffee","brewing","bourbon","amazon"],
  debt:["loan","navient","nelnet","mohela","sallie mae","aidvantage","card payment","capital one","discover","synchrony"]};
function categorize(text){
  const t=" "+text.toLowerCase()+" ";
  for(const [k,words] of Object.entries(KEYWORDS)) if(words.some(w=>t.includes(w))) return k;
  return "other";
}
// Pull "description ... amount" lines out of recognized statement text. Skips deposits and balances.
function parseStatement(text){
  const out=[];
  for(const raw of text.split(/\n/)){
    const line=raw.trim(), m=line.match(/-?\(?\$?\s?\d{1,3}(?:,\d{3})*\.\d{2}\)?/);
    if(!m) continue;
    const desc=line.slice(0,m.index).replace(/^\d{1,2}[\/-]\d{1,2}(?:[\/-]\d{2,4})?\s*/,"").replace(/[^\w&'.\- ]/g," ").replace(/\s+/g," ").trim();
    if(desc.length<3||/balance|deposit|payroll|direct dep|transfer from|interest paid|total|beginning|ending/i.test(desc)) continue;
    const amt=Math.abs(parseFloat(m[0].replace(/[^\d.]/g,"")));
    if(amt>0&&amt<50000) out.push({desc,amount:amt,cat:categorize(desc)});
  }
  return out;
}
</script>
<script>
const $=id=>document.getElementById(id);
const fmt=n=>(n<0?"−":"")+"$"+Math.round(Math.abs(n)).toLocaleString("en-US");
const fmtK=n=>{const a=Math.abs(n);return (n<0?"−":"")+(a>=1e6?"$"+(a/1e6).toFixed(a>=1e7?0:1)+"M":a>=1e3?"$"+Math.round(a/1e3)+"K":"$"+Math.round(a))};
const esc=s=>String(s).replace(/[&"<>]/g,c=>({"&":"&amp;",'"':"&quot;","<":"&lt;",">":"&gt;"})[c]);
// A blank plan: what "Start over" gives you.
const BLANK={adults:1,under5:0,schoolAge:0,liveCounty:"Jefferson",liveCity:"Louisville",workCounty:"Jefferson",workCity:"Louisville",workSet:false,
  localOverride:"",income1:0,income2:0,k401:0,match:0,housing:100,food:100,car:100,fun:8,other:5,growth:0,investShare:0,
  debts:[],strategy:"avalanche",extra:0,years:30,portfolio:"balanced",...portfolioRates("balanced"),
  startCash:0,startInvest:0,efMonths:3,goals:[],now:{},skip:{},countySet:false,bill:{amt:0,hosp:"",date:"",ins:"none"}};
// How you live now: monthly [about, up to]. A range uses the middle.
// [key, label, top of slider as a share of monthly take home pay]
const NOWCATS=[["housing","Rent or mortgage, plus utilities",.6],["food","Groceries",.25],["car","Car payment, insurance and gas",.3],["care","Child care",.4],["health","Health insurance and doctor visits",.2],["phone","Phone and internet",.08],["fun","Eating out, fun and shopping",.3],["other","Other: clothes, haircuts, gifts, pets",.2]];
const nowVal=k=>{const [lo,hi]=S.now[k]||[0,0];return hi?(lo+hi)/2:lo;}; // [lo,hi] from the slider, [exact,0] from the box
const nowTxt=k=>{const [lo,hi]=S.now[k]||[0,0];return hi?(lo?`${fmt(lo)} to ${fmt(hi)}`:`Under ${fmt(hi)}`):fmt(lo);};
// Slider steps: 10 steps up to a share of take home pay, rounded to friendly amounts
function nowStep(k,R){const net=R.gross?R.net/12:3400, raw=NOWCATS.find(c=>c[0]===k)[2]*net/10, u=raw<100?25:raw<250?50:raw<600?100:250;return Math.max(u,Math.round(raw/u)*u);}
// Rows asked in order; child care only with kids. A row counts as answered once it's in S.now (even $0).
const nowAsk=()=>NOWCATS.filter(([k])=>k!=="care"||S.under5+S.schoolAge>0);
const TYPICAL={housing:100,food:100,car:100,fun:8,other:5};
const placeOf=E=>({liveCounty:E.liveCounty,liveCity:E.liveCity,workCounty:E.workCounty,workCity:E.workCity});
// County typical costs for this household, ignoring what the user entered
const typical=(E,pl)=>compute({...E,...TYPICAL,actual:null},DATA,pl||placeOf(E));
const CATS=[["housing","Housing and utilities","--s1"],["food","Groceries","--s2"],["car","Car and gas","--s3"],["care","Child care","--s4"],["health","Health care","--s5"],["save","Left over","--s6"],["fun","Entertainment","--s7"],["debt","Debt payments","--s8"],["phone","Phone and internet","--s9"],["other","Other spending","--s10"]];
const CATNAME=Object.fromEntries(CATS.map(c=>[c[0],c[1]]));
const TABS=[["location","Your county"],["income","Income"],["budget","Budget"],["debt","Debt"],["goals","Goals"],["invest","Invest"],["recommend","Your plan"]];
const SRC={official:["Official rate",""],registry:["From state filings, double check","mid"],klc:["From the Kentucky League of Cities list, double check","mid"],guide:["From a tax guide, double check","mid"],county:["Official county rate",""],cityUnknown:["City rate not confirmed","low"],custom:["Your number",""]};
let S=structuredClone(BLANK), dirty=false, tab="location", visited=new Set(["location"]), mapZoom=1, APIKEY="", lastImport=null;
const counties=Object.keys(DATA.counties);

function cityList(county){return [...DATA.cities[county]||[],ELSE]}
function fillSelect(el,opts,val){el.innerHTML=opts.map(o=>`<option>${esc(o)}</option>`).join(""); el.value=opts.includes(val)?val:opts[0];}
const PAIRS=[["liveCounty","liveCity"],["workCounty","workCity"]];
function syncCities(){PAIRS.forEach(([c,ci])=>{fillSelect($(ci),cityList(S[c]),S[ci]); S[ci]=$(ci).value;});}
const money=v=>v?Math.round(v).toLocaleString("en-US"):"";
function writeInputs(){
  document.querySelectorAll("[data-k]").forEach(el=>{
    const k=el.dataset.k;
    if(PAIRS.some(p=>p[0]===k)) fillSelect(el,counties,S[k]);
    else if(el.hasAttribute("data-money")) el.value=money(S[k]);
    else if(!PAIRS.some(p=>p[1]===k)) el.value=S[k];
  });
  if(!S.countySet){const c=$("cpCounty");c.insertAdjacentHTML("afterbegin",`<option value="">Choose your county</option>`);c.value="";}
  syncCities(); renderLists();
}
const xBtn=(i,list,name)=>`<button class="icon" aria-label="Remove ${esc(name)}" data-del="${i}" data-list="${list}"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>`;
function renderLists(){
  const nv=v=>v?v:""; // new rows start blank
  $("debts").innerHTML=S.debts.map((d,i)=>`<div class="rowlist" data-list="debts" data-i="${i}">
    <input class="nm" type="text" aria-label="Debt name" data-f="name" value="${esc(d.name)}" placeholder="Name">
    <input type="number" aria-label="${esc(d.name)} balance in dollars" data-f="bal" min="0" step="100" value="${nv(d.bal)}" placeholder="$ owed">
    <input type="number" aria-label="${esc(d.name)} interest rate percent" data-f="rate" min="0" step="0.1" value="${nv(d.rate)}" placeholder="%">
    <input type="number" aria-label="${esc(d.name)} minimum payment per month" data-f="min" min="0" step="5" value="${nv(d.min)}" placeholder="$ a month">${xBtn(i,"debts",d.name)}</div>`).join("")||`<p class="hint">No debts yet. Add one, or skip this step if you don't have any.</p>`;
  $("nowRows").innerHTML=NOWCATS.map(([k,l])=>`<div class="slider nowrow" data-row="${k}"><div class="top"><span>${l}</span><b class="nowv"></b></div>
    <input type="range" min="0" max="10" step="1" data-nowr="${k}" aria-label="${l}, about how much a month">
    <div class="ends"><span>$0</span><span class="nowmax"></span></div>
    <div class="field amt"><span class="pre">$</span><input type="text" inputmode="numeric" data-nowx="${k}" aria-label="${l}, exact amount a month" placeholder="Exact amount (optional)" autocomplete="off"></div>
    <button class="btn zero" data-zero="${k}">I don't pay this</button></div>`).join("");
  $("goals").innerHTML=S.goals.map((g,i)=>`<div class="rowlist g3" data-list="goals" data-i="${i}">
    <input class="nm" type="text" aria-label="Goal name" data-f="name" value="${esc(g.name)}" placeholder="Name">
    <input type="number" aria-label="${esc(g.name)} cost in dollars" data-f="target" min="0" step="500" value="${nv(g.target)}" placeholder="$ cost">
    <input type="number" aria-label="${esc(g.name)} saved so far" data-f="saved" min="0" step="100" value="${nv(g.saved)}" placeholder="$ saved">${xBtn(i,"goals",g.name)}</div>`).join("");
}

// ---- Tabs ----
function renderTabs(){
  $("tablist").innerHTML=TABS.map(([id,l],i)=>{const sk=S.skip[id]&&id!==tab, dn=!sk&&visited.has(id)&&id!==tab;
    return `<button class="tab${dn?" done":""}${sk?" skipped":""}" role="tab" id="t-${id}" aria-controls="p-${id}" aria-selected="${id===tab}" tabindex="${id===tab?0:-1}" data-tab="${id}"${sk?' title="Skipped"':""}><span class="n">${dn?"✓":i+1}</span>${l}</button>`;}).join("");
}
function go(id,focus){
  if(!TABS.some(t=>t[0]===id)) return;
  tab=id; visited.add(id);
  TABS.forEach(([t])=>$("p-"+t).hidden=t!==id);
  renderTabs(); render();
  if(history.replaceState) history.replaceState(null,"","#"+id);
  const tb=$("t-"+id), tl=$("tablist"); tl.scrollLeft=tb.offsetLeft-tl.clientWidth/2+tb.offsetWidth/2; // scrolls the tab strip only, never the page
  if(focus) tb.focus();
  window.scrollTo({top:0,behavior:"smooth"}); // every step starts at its top
}
$("tablist").addEventListener("keydown",e=>{
  const i=TABS.findIndex(t=>t[0]===tab);
  if(e.key==="ArrowRight") go(TABS[(i+1)%TABS.length][0],true);
  else if(e.key==="ArrowLeft") go(TABS[(i+TABS.length-1)%TABS.length][0],true);
});

// ---- Model: skipped steps fall back to typical values ----
function eff(){
  const k=S.skip, e={...S};
  // Budget uses what you entered (blank = $0); skipping it uses typical costs for your county
  if(k.budget) Object.assign(e,TYPICAL,{actual:null});
  else e.actual=Object.fromEntries(NOWCATS.map(([c])=>[c,nowVal(c)]));
  if(k.debt){e.debts=[];e.extra=0;}
  if(k.goals){e.goals=[];e.startCash=0;e.startInvest=0;}
  if(k.invest) Object.assign(e,{investShare:0,growth:0},portfolioRates("balanced"));
  return e;
}
function model(){
  const E=eff(), here=placeOf(E);
  const R=compute(E,DATA,here), debt=payoff(E.debts,E.strategy,E.extra,R.refund), T=typical(E,here);
  const P=[["Average",E.rExp,"--s1"],["Bad markets",E.rLow,"--s2"],["Good markets",E.rHigh,"--s3"]].map(([l,r,c])=>({l,r,c,...project(E,R,debt,r,E.years)}));
  return {E,R,T,debt,P,H:healthScore(E,R),inv:Math.max(0,R.left/12)*E.investShare/100};
}
function render(){
  const M=model();
  document.querySelectorAll("[data-adults]").forEach(b=>b.setAttribute("aria-pressed",+b.dataset.adults===S.adults));
  document.querySelectorAll(".inc2").forEach(el=>el.style.visibility=S.adults===2?"visible":"hidden");
  ["under5","schoolAge"].forEach(k=>document.querySelectorAll(`[data-o="${k}"]`).forEach(o=>o.textContent=S[k]));
  document.querySelectorAll("[data-ins]").forEach(b=>b.setAttribute("aria-pressed",b.dataset.ins===S.bill.ins));
  document.querySelectorAll("#strategy button").forEach(b=>b.setAttribute("aria-pressed",b.dataset.s===S.strategy));
  renderDock(M); const mk=(S.countySet?"c:":"ky:")+S.liveCounty; if($("mark").dataset.c!==mk){drawMark();$("mark").dataset.c=mk;}
  const neg=M.R.gross>0&&M.R.left<0;
  document.querySelectorAll(".negwarn").forEach(el=>{el.hidden=!neg; if(neg) el.innerHTML=`<b>You're in the negative.</b> You spend ${fmt(-M.R.left/12)} a month more than you take home. Your plan in the last step shows where to cut.`;});
  ({location:renderLocation,income:renderIncome,budget:renderBudget,debt:renderDebt,goals:renderGoals,invest:renderInvest,recommend:renderRecommend})[tab](M);
  maybeToast(M);
}

function place(c,ci){return ci===ELSE?c+" County":ci}
function setV(id,txt){const el=$(id); if(el.textContent!==txt){el.textContent=txt; el.classList.remove("bump"); void el.offsetWidth; el.classList.add("bump");}}
const yrs=m=>m<12?m+" mo":Math.floor(m/12)+" yr"+(m%12?" "+(m%12)+" mo":"");
const scoreWord=s=>s>=80?"Strong":s>=60?"On track":s>=40?"Getting there":"Needs work";
const scoreColor=s=>s>=70?"--green":s>=45?"--yellow":"--red";
// Logo: Kentucky drawn from its 120 county shapes, with your home county in gold
// Kentucky until you choose a county, then your county's outline, scaled to fill the same space
function drawMark(){const M=DATA.map,m=$("mark");
  m.classList.toggle("cty",!!(S.countySet&&M.paths[S.liveCounty])); // county outlines are about square, so give them a square box
  if(S.countySet&&M.paths[S.liveCounty]){m.innerHTML=`<path class="one" d="${M.paths[S.liveCounty]}"/>`;
    const b=m.querySelector("path").getBBox(), p=Math.max(b.width,b.height)*.04; m.setAttribute("viewBox",`${b.x-p} ${b.y-p} ${b.width+2*p} ${b.height+2*p}`);
    // County name in white just above the outline; longer names get a smaller font so they fit the logo width
    const nm=S.liveCounty+" County", w=m.getBoundingClientRect().width||96;
    $("markName").textContent=nm; $("markName").style.fontSize=Math.max(9,Math.min(15,w*1.75/nm.length))+"px";
    m.setAttribute("aria-label",S.liveCounty+" County");}
  else{$("markName").textContent=""; m.setAttribute("viewBox",`-4 -4 ${M.w+8} ${M.h+8}`); m.removeAttribute("aria-label");
  m.innerHTML=Object.entries(M.paths).map(([c,d])=>`<path d="${d}"${c===S.liveCounty?' class="here"':""}/>`).join("");}
  // Browser tab icon: white Kentucky on a blue square
  if(!$("favicon").dataset.done){const all=Object.values(M.paths).join("");
    $("favicon").href="data:image/svg+xml,"+encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="-40 ${M.h/2-540} 1080 1080"><rect x="-40" y="${M.h/2-540}" width="1080" height="1080" rx="200" fill="#0033a0"/><path d="${all}" fill="#fff" stroke="#fff" stroke-width="6"/></svg>`);
    $("favicon").dataset.done=1;}}
function renderDock({E,R,debt,P,H,inv}){
  const noInc=!R.gross, left=R.left/12-inv; // left after what you choose to invest
  // Until spending is entered (or the step skipped), "left" would just be take home pay, so say so instead of showing it
  const noSpend=!noInc&&!S.skip.budget&&!Object.keys(S.now).length;
  $("dLeftL").textContent=inv>0?"Left after investing":"Left each month"; setV("dLeft",noInc||noSpend?"—":fmt(left)); $("dLeft").className="v"+(noInc||noSpend?"":left<0?" neg":left>0?" pos":"");
  $("dLeftS").textContent=noInc?"Add your pay in the Income step.":noSpend?"Add your spending in the Budget step.":left<0?"You're spending more than you make.":`${fmt(left*12)} a year`;
  setV("dGross",fmt(R.gross/12)); setV("dTax",fmt(R.taxes/12)); setV("d401",fmt((R.k401Sum+R.matchSum)/12));
  setV("dNet",fmt(R.net/12)); setV("dSpend",fmt(R.spent/12)); setV("dInv",fmt(inv));
  document.querySelectorAll(".futbit").forEach(el=>el.hidden=!visited.has("invest"));
  setV("dDebt",!E.debts.some(d=>d.bal>0)?"No debt":debt.stuck?"Never at this pace":yrs(debt.months));
  $("dDebt").className=!E.debts.some(d=>d.bal>0)?"pos":debt.stuck?"neg":debt.months>120?"mid":"pos";
  setV("dScore",noInc?"—":`${H.score} / 100 · ${scoreWord(H.score)}`); $("dScore").className=noInc?"":H.score>=70?"pos":H.score>=45?"mid":"neg";
  setV("mScore",noInc?"—":H.score+"/100");
  setV("dFut",R.gross?fmt(P[0].pts[E.years]):"—"); $("dFutS").textContent=`${PORTFOLIOS[E.portfolio]?PORTFOLIOS[E.portfolio].name+" mix · ":""}range ${fmtK(P[1].pts[E.years])} to ${fmtK(P[2].pts[E.years])}`;
  document.querySelectorAll(".yrs").forEach(e=>e.textContent=E.years);
  setV("mFut",fmtK(P[0].pts[E.years]));
  $("dWhere").textContent=`Living in ${place(S.liveCounty,S.liveCity)}, working in ${place(S.workCounty,S.workCity)}`;
  $("dBar").innerHTML=budgetRows(R).filter(r=>r.v>0).map(r=>`<div style="flex:${r.v};background:var(${r.c})" title="${r.l}"></div>`).join("");
}

// ---- Charts ----
function attachTip(el,tip,html,wrap){
  const show=e=>{tip.innerHTML=html;tip.style.display="block";const b=wrap.getBoundingClientRect(),r=el.getBoundingClientRect();
    const x=e&&e.clientX?e.clientX-b.left:r.left-b.left+r.width/2, y=e&&e.clientY?e.clientY-b.top:r.top-b.top;
    tip.style.left=Math.max(0,Math.min(x+12,b.width-210))+"px"; tip.style.top=Math.max(0,y+12)+"px";};
  el.addEventListener("mousemove",show); el.addEventListener("focus",()=>show()); el.addEventListener("mouseleave",()=>tip.style.display="none"); el.addEventListener("blur",()=>tip.style.display="none");
}
// Money flow: gross pay -> taxes, 401k, take home -> spending categories and savings.
function drawSankey(svg,R,tip){
  if(!R.gross){svg.setAttribute("viewBox","0 0 600 120");svg.setAttribute("height",120);svg.innerHTML=`<text x="300" y="64" text-anchor="middle" style="font-size:15px">Enter your pay above to see where every dollar goes.</text>`;return;}
  const W=Math.max(320,svg.clientWidth||760), H=420, T=10, nw=12, pad=8, small=W<560;
  // Phones get short names so three columns fit side by side
  const SHORT={"Social Security and Medicare":"Payroll tax","Kentucky tax":"KY tax","Local wage tax":"Local tax","Housing and utilities":"Housing","Car and gas":"Car","Health care":"Health","Entertainment":"Fun","Debt payments":"Debt","Phone and internet":"Phone","Other spending":"Other"};
  const nm=l=>W<760&&SHORT[l]||l; // short names below 760px so labels never reach the next column
  const taxes=[["Federal tax",Math.max(0,R.fed),"--t1"],["Social Security and Medicare",R.fica,"--t2"],["Kentucky tax",R.ky,"--t3"],["Local wage tax",R.local,"--t4"]].filter(t=>t[1]>0);
  const mid=[...taxes,["401k",R.k401Sum,"--s7"],["Take home",Math.max(0,R.net),"--green"]].filter(t=>t[1]>0);
  const outs=budgetRows(R).filter(r=>r.v>0).map(r=>[r.l,r.v,r.c]);
  const total=Math.max(R.gross,1), colH=(arr,k)=>arr.reduce((s,o)=>s+Math.max(2,o[1]*k)+pad,-pad);
  let k=(H-pad*(Math.max(mid.length,outs.length)-1))/Math.max(total,outs.reduce((a,o)=>a+o[1],0)+0.01);
  while(colH(mid,k)>H||colH(outs,k)>H) k*=.97; // tiny slices get a 2px minimum, so shrink until every column fits
  const x0=small?4:150, x1=small?W*.36:W*.42, x2=W-(small?104:200);
  const col=(arr,x)=>{let y=0;return arr.map(([l,v,c])=>{const h=Math.max(2,v*k),n={l,v,c,x,y,h};y+=h+pad;return n;});};
  const N0={l:"Pay before taxes",v:R.gross,c:"--uk",x:x0,y:0,h:R.gross*k}, N1=col(mid,x1);
  const th=N1.find(n=>n.l==="Take home"), N2=col(outs,x2), h2=colH(outs,k), off2=th?Math.max(0,Math.min(H-h2,th.y+th.h/2-h2/2)):0;
  N2.forEach(n=>n.y+=off2);
  const band=(ax,ay,ah,bx,by,bh,c)=>{const m=(ax+bx)/2;return `<path class="link" d="M${ax},${ay}C${m},${ay} ${m},${by} ${bx},${by}L${bx},${by+bh}C${m},${by+bh} ${m},${ay+ah} ${ax},${ay+ah}Z" fill="var(${c})" fill-opacity=".38"`;};
  let g="", y0=N0.y, links=[];
  N1.forEach(n=>{links.push([band(N0.x+nw,y0,n.h,n.x,n.y,n.h,n.c),`<b>${n.l}</b><br>${fmt(n.v/12)} a month · ${Math.round(n.v/total*100)}% of your pay`]);y0+=n.h;});
  if(th){let yy=th.y;const tk=th.h/Math.max(1,N2.reduce((a,n)=>a+n.v,0));N2.forEach(n=>{const hh=n.v*tk;links.push([band(th.x+nw,yy,hh,n.x,n.y,n.h,n.c),`<b>${n.l}</b><br>${fmt(n.v/12)} a month · ${R.net>0?Math.round(n.v/R.net*100):0}% of take home pay`]);yy+=hh;});}
  g+=links.map(([p],i)=>p+` data-i="${i}"/>`).join("");
  // Labels: name plus amount, pushed apart when slices are thin; amounts drop if a column is too crowded
  const labels=(ns,anchor,lx)=>{
    for(const lineH of [small?30:34,small?16:18]){
      const L=ns.map(n=>({n,h:lineH,top:n.y+n.h/2-lineH/2}));
      let prev=-T; L.forEach(o=>{o.top=Math.max(o.top,prev);prev=o.top+o.h;});
      let next=H+T; for(let i=L.length-1;i>=0;i--){L[i].top=Math.min(L[i].top,next-L[i].h);next=L[i].top;}
      if(L[0].top>=-T||lineH<20) return L.map(({n,h,top})=>`<text class="nl" x="${lx}" y="${top+13}" text-anchor="${anchor}">${esc(nm(n.l))}</text>`+(h>20?`<text class="nv" x="${lx}" y="${top+(small?27:30)}" text-anchor="${anchor}">${fmt(n.v/12)}/mo</text>`:"")).join("");
    }};
  const rect=n=>`<rect x="${n.x}" y="${n.y}" width="${nw}" height="${n.h}" rx="3" fill="var(${n.c})"/>`;
  g+=rect(N0)+N1.map(rect).join("")+N2.map(rect).join("");
  if(!small) g+=labels([N0],"end",x0-8);
  g+=small?labels(N1,"end",x1-6):labels(N1,"start",x1+nw+6);
  g+=labels(N2,"start",x2+nw+6);
  svg.setAttribute("viewBox",`0 ${-T} ${W} ${H+2*T}`); svg.setAttribute("height",H+2*T); svg.innerHTML=g;
  svg.setAttribute("aria-label",`Money flow: ${fmt(R.gross/12)} pay a month, ${fmt((R.taxes+R.refund)/12)} to taxes, ${fmt(R.k401Sum/12)} to your 401k, ${fmt(R.net/12)} take home.`);
  if(tip) svg.querySelectorAll(".link").forEach(p=>attachTip(p,tip,links[+p.dataset.i][1],svg.parentNode));
}
function drawDonut(svg,rows,total,center,tip){
  const cx=120,cy=120,r=104,ri=70; let a=-Math.PI/2, g="";
  const live=rows.filter(r=>r.v>0), sum=live.reduce((s,r)=>s+r.v,0)||1;
  live.forEach((row,i)=>{
    const da=row.v/sum*Math.PI*2, a2=a+da-(live.length>1?.012:0), lg=da>Math.PI?1:0;
    const p=(rr,t)=>`${(cx+rr*Math.cos(t)).toFixed(2)},${(cy+rr*Math.sin(t)).toFixed(2)}`;
    g+=`<path tabindex="0" data-i="${i}" d="M${p(r,a)}A${r},${r} 0 ${lg} 1 ${p(r,a2)}L${p(ri,a2)}A${ri},${ri} 0 ${lg} 0 ${p(ri,a)}Z" fill="var(${row.c})" aria-label="${esc(row.l)} ${fmt(row.v/12)} a month"/>`;
    a+=da;
  });
  g+=`<text x="120" y="112" text-anchor="middle" style="fill:var(--ink3);font-size:12px">${center[0]}</text><text x="120" y="138" text-anchor="middle" style="fill:var(${center[2]});font-size:24px;font-weight:600;font-family:var(--serif)">${center[1]}</text>`;
  svg.innerHTML=g;
  if(tip) svg.querySelectorAll("path").forEach(p=>{const row=live[+p.dataset.i];attachTip(p,tip,`<b>${esc(row.l)}</b><br>${fmt(row.v/12)} a month · ${total>0?Math.round(row.v/total*100):0}%`,svg.parentNode);});
}
// Line chart with crosshair tooltip and end labels. series: [{l,c,pts,thick}]
function drawLines(svg,tip,series,o){
  const W=Math.max(320,svg.clientWidth||700), H=o.H, m={l:58,r:92,t:14,b:30}, n=Math.max(...series.map(s=>s.pts.length))-1||1;
  const max=Math.max(1,...series.flatMap(s=>s.pts));
  const nice=(()=>{const raw=max/4,p=Math.pow(10,Math.floor(Math.log10(raw))),f=raw/p;return (f<=1?1:f<=2?2:f<=2.5?2.5:f<=5?5:10)*p})();
  const top=Math.ceil(max/nice)*nice;
  const x=i=>m.l+i/n*(W-m.l-m.r), y=v=>H-m.b-v/top*(H-m.t-m.b);
  let g=`<defs><linearGradient id="${svg.id}fill" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="var(${series[0].c})" stop-opacity=".18"/><stop offset="1" stop-color="var(${series[0].c})" stop-opacity="0"/></linearGradient></defs>`;
  for(let v=0;v<=top+1e-6;v+=nice) g+=`<line x1="${m.l}" x2="${W-m.r}" y1="${y(v)}" y2="${y(v)}" stroke="var(--line)"/><text x="${m.l-10}" y="${y(v)+4}" text-anchor="end">${fmtK(v)}</text>`;
  for(let i=0;i<=n;i++){const t=o.xTick(i,n);if(t!=null) g+=`<text x="${x(i)}" y="${H-8}" text-anchor="middle">${t}</text>`;}
  const path=s=>s.pts.map((v,i)=>(i?"L":"M")+x(i).toFixed(1)+","+y(v).toFixed(1)).join("");
  if(o.fill) g+=`<path d="${path(series[0])}L${x(series[0].pts.length-1)},${y(0)}L${x(0)},${y(0)}Z" fill="url(#${svg.id}fill)"/>`;
  series.slice().reverse().forEach(s=>{g+=`<path d="${path(s)}" fill="none" stroke="var(${s.c})" stroke-width="${s.thick?2.5:2}" stroke-linejoin="round" stroke-linecap="round"${s.dash?' stroke-dasharray="5 4"':""}/>`});
  const ends=series.map(s=>({s,i:s.pts.length-1,yy:y(s.pts[s.pts.length-1])})).sort((a,b)=>a.yy-b.yy);
  for(let i=1;i<ends.length;i++) if(ends[i].yy-ends[i-1].yy<18) ends[i].yy=ends[i-1].yy+18;
  ends.forEach(e=>{g+=`<circle cx="${x(e.i)}" cy="${y(e.s.pts[e.i])}" r="4.5" fill="var(${e.s.c})" stroke="var(--surface)" stroke-width="2"/><text x="${x(e.i)+10}" y="${e.yy+4}" style="fill:var(--ink);font-weight:600">${o.endLabel?o.endLabel(e.s,e.i):fmtK(e.s.pts[e.i])}</text>`});
  g+=`<line class="xh" y1="${m.t}" y2="${H-m.b}" stroke="var(--ink3)" stroke-dasharray="3 3" visibility="hidden"/><rect class="hit" x="${m.l}" y="0" width="${W-m.l-m.r}" height="${H}" fill="transparent"/>`;
  svg.setAttribute("viewBox",`0 0 ${W} ${H}`); svg.setAttribute("height",H); svg.innerHTML=g;
  if(!tip) return;
  const xh=svg.querySelector(".xh"), hit=svg.querySelector(".hit");
  const move=cx=>{
    const bx=svg.getBoundingClientRect(), sc=W/bx.width, i=Math.max(0,Math.min(n,Math.round(((cx-bx.left)*sc-m.l)/(W-m.l-m.r)*n)));
    xh.setAttribute("x1",x(i));xh.setAttribute("x2",x(i));xh.setAttribute("visibility","visible");
    tip.innerHTML=`<b>${o.xTip(i)}</b>`+series.map(s=>`<div style="display:flex;justify-content:space-between;gap:14px"><span><span class="sw" style="background:var(${s.c})"></span>${s.l}</span><b>${s.pts[i]!=null?fmt(s.pts[i]):"Paid off"}</b></div>`).join("");
    tip.style.display="block"; tip.style.left=Math.min(x(i)/sc+14,bx.width-210)+"px"; tip.style.top="18px";
  };
  hit.onmousemove=e=>move(e.clientX); hit.ontouchmove=e=>move(e.touches[0].clientX);
  hit.onmouseleave=hit.ontouchend=()=>{tip.style.display="none";xh.setAttribute("visibility","hidden")};
}
function drawGauge(svg,score){
  const cx=110,cy=120,r=90,p=t=>`${(cx+r*Math.cos(Math.PI*(1-t))).toFixed(2)},${(cy-r*Math.sin(Math.PI*(1-t))).toFixed(2)}`;
  svg.innerHTML=`<path d="M${p(0)}A${r},${r} 0 0 1 ${p(1)}" fill="none" stroke="var(--line)" stroke-width="16" stroke-linecap="round"/>`+
    (score>0?`<path class="gArc" pathLength="1" d="M${p(0)}A${r},${r} 0 0 1 ${p(score/100)}" fill="none" stroke="var(${scoreColor(score)})" stroke-width="16" stroke-linecap="round"/>`:"")+
    `<text x="110" y="108" text-anchor="middle" style="fill:var(--ink);font-family:var(--serif);font-size:44px;font-weight:600">${score}</text><text x="110" y="134" text-anchor="middle" style="fill:var(${scoreColor(score)});font-size:14px;font-weight:600">${scoreWord(score)}</text>`;
  svg.setAttribute("aria-label",`Money health score ${score} out of 100, ${scoreWord(score)}`);
}
const ring=(pct,c)=>{const r=28,C=2*Math.PI*r,v=Math.max(0,Math.min(1,pct));return `<svg width="72" height="72" viewBox="0 0 72 72" aria-hidden="true"><circle cx="36" cy="36" r="${r}" fill="none" stroke="var(--line)" stroke-width="8"/><circle cx="36" cy="36" r="${r}" fill="none" stroke="var(${c})" stroke-width="8" stroke-linecap="round" stroke-dasharray="${(C*v).toFixed(1)} ${C.toFixed(1)}" transform="rotate(-90 36 36)"/><text x="36" y="40" text-anchor="middle" style="fill:var(--ink);font-size:13px;font-weight:600">${Math.round(v*100)}%</text></svg>`;};

// ---- Location: map first ----
function countyValues(){
  const E=eff();
  return counties.map(c=>({c,housing:typical(E,{liveCounty:c,liveCity:ELSE,workCounty:c,workCity:ELSE}).spend.housing/12,income:DATA.income[c]}));
}
function pickCounty(c){
  S.countySet=true;
  S.liveCounty=c; S.liveCity=cityList(c)[0];
  if(!S.workSet){S.workCounty=c; S.workCity=S.liveCity;}
  delete S.skip.location; dirty=true; writeInputs(); render();
  toast(`Home set to <b>${esc(place(c,S.liveCity))}</b>.`);
}
// Map view: zoom level plus a center point you can drag around
let mapCenter=null, mapDrag=null, mapDragged=false;
function setMapView(){
  const M=DATA.map, svg=$("map");
  if(mapZoom<=1){svg.setAttribute("viewBox",`0 0 ${M.w} ${M.h}`);return;}
  const w=M.w/mapZoom,h=M.h/mapZoom, c=mapCenter||[M.w/2,M.h/2];
  const x=Math.max(0,Math.min(M.w-w,c[0]-w/2)), y=Math.max(0,Math.min(M.h-h,c[1]-h/2));
  mapCenter=[x+w/2,y+h/2]; svg.setAttribute("viewBox",`${x} ${y} ${w} ${h}`);
}
(()=>{const svg=$("map");
  svg.addEventListener("pointerdown",e=>{if(mapZoom<=1||e.button!==0) return; mapDrag={x:e.clientX,y:e.clientY,c:mapCenter.slice()}; mapDragged=false;});
  svg.addEventListener("pointermove",e=>{if(!mapDrag) return; const dx=e.clientX-mapDrag.x, dy=e.clientY-mapDrag.y;
    if(!mapDragged&&Math.hypot(dx,dy)<4) return; // a small wiggle still counts as a click
    if(!mapDragged){mapDragged=true; svg.setPointerCapture(e.pointerId); svg.classList.add("dragging"); $("mapTip").style.display="none";}
    const s=svg.viewBox.baseVal.width/svg.getBoundingClientRect().width;
    mapCenter=[mapDrag.c[0]-dx*s,mapDrag.c[1]-dy*s]; setMapView();});
  const end=()=>{if(!mapDrag) return; mapDrag=null; svg.classList.remove("dragging"); setTimeout(()=>{mapDragged=false;},0);};
  svg.addEventListener("pointerup",end); svg.addEventListener("pointercancel",end);})();
function drawMap(svg,tip,vals){
  const M=DATA.map, byC=Object.fromEntries(vals.map(v=>[v.c,v]));
  const arr=vals.map(v=>v.housing), lo=Math.min(...arr), hi=Math.max(...arr);
  const fill=v=>`color-mix(in oklab, var(--map-seq) ${Math.round((v-lo)/Math.max(1,hi-lo)*100)}%, var(--map-mid))`;
  $("ramp").style.background="linear-gradient(90deg,var(--map-mid),var(--map-seq))"; $("rampLo").textContent=fmt(lo)+"/mo, cheaper"; $("rampHi").textContent=fmt(hi)+"/mo";
  svg.innerHTML=Object.entries(M.paths).map(([c,d])=>`<path d="${d}" data-c="${esc(c)}" tabindex="0" role="button" aria-label="${esc(c)} County: housing ${fmt(byC[c].housing)} a month, median income ${fmt(byC[c].income)} a year. Press Enter to choose." class="${c===S.liveCounty?"here":""}" fill="${fill(byC[c].housing)}"/>`).join("");
  const here=svg.querySelector(".here"); if(here) svg.appendChild(here);
  // Zoom starts on your county; after a drag it stays where you moved it
  if(mapZoom>1&&!mapCenter&&here){const b=here.getBBox();mapCenter=[b.x+b.width/2,b.y+b.height/2];}
  setMapView();
  svg.classList.toggle("pan",mapZoom>1); $("panHint").hidden=mapZoom<=1;
  svg.querySelectorAll("path").forEach(p=>{const v=byC[p.dataset.c];
    attachTip(p,tip,`<b>${esc(v.c)} County</b><br>Median household income: ${fmt(v.income)}/yr<br>Housing: ${fmt(v.housing)}/mo<br><small>Click to choose</small>`,svg.parentNode);
    p.onclick=()=>{if(!mapDragged) pickCounty(v.c);}; p.onkeydown=e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();pickCounty(v.c);}};});
}
// ---- Hospital bill: what you may owe, your deadlines, steps and a letter ----
const dayFmt=d=>d.toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"});
const addDays=(iso,n)=>{const d=new Date(iso+"T12:00:00");d.setDate(d.getDate()+n);return d;};
// Everything the bill step, Your plan and the report say about the bill. has=false until there's an amount.
function billOutlook(){
  const B=S.bill, size=S.adults+S.under5+S.schoolAge, income=S.income1+(S.adults===2?S.income2:0), amt=B.amt||0;
  const c=billCheck(size,income,amt,B.hosp,B.ins), h=c.h, other=B.hosp==="other", hn=h?h.name:"the hospital";
  const freeAt=HOSPITALS.filter(x=>x.tiers&&x.tiers[0][1]===100&&c.pct<=x.tiers[0][0]);
  const o={has:amt>0&&!!income,amt,size,income,c,h,hn,freeAt};
  if(B.date){o.applyBy=addDays(B.date,240);o.ecaFrom=addDays(B.date,120);o.late=new Date()>o.applyBy;}
  // One plain sentence for the result, with the dollar estimate when the policy gives a fixed percent
  if(B.ins==="medicaid") o.result="Medicaid usually covers hospital care in full, so you may not owe this at all.";
  else if(!h&&!other) o.result="Pick the hospital to see what its policy means for you.";
  else if(other) o.result=freeAt.length?`At your income, ${freeAt.length} of Kentucky's ${HOSPITALS.length} largest hospital systems would forgive the whole bill. Ask this hospital for its financial assistance policy.`:"Ask this hospital for its financial assistance policy. Nonprofit hospitals are required to have one.";
  else if(!h.tiers) o.result=`${hn} doesn't publish its income limits, but it does offer free and discounted care on a sliding scale. Ask for its financial assistance application.`;
  else if(!c.tier) o.result=`Your income is above ${hn}'s limit of ${c.limit}% of the poverty line (about ${fmt(FPL(size)*c.limit/100)} a year for your household). You can still ask for a payment plan, a discount for paying at once, or help because of hardship.`;
  else if(c.off===100) o.result=`You likely qualify for free care. Estimated bill: $0 instead of ${fmt(amt)}.`;
  else if(c.off!=null) o.result=`You likely qualify for ${c.off}% off: about ${fmt(c.owe)} instead of ${fmt(amt)}.`;
  else o.result={agb:"You likely qualify to pay no more than what insured patients pay, which is usually far less than the full bill.",halfagb:"You likely qualify to pay half of what insured patients pay, which is usually far less than the full bill.",slide:"You likely qualify for a discount on a sliding scale. The hospital sets the exact amount when you apply."}[c.tier[1]];
  o.good=B.ins==="medicaid"||(c.tier&&c.off!==0)||(other&&freeAt.length);
  o.owe=B.ins==="medicaid"?0:c.owe!=null?c.owe:c.tier?null:amt; // null: discounted, amount set by the hospital
  // Steps
  const contact=h?(h.phone?`Call ${h.phone} or visit ${h.url}`:`Visit ${h.url}`):"Call the billing office number on your bill";
  o.steps=[{w:"Today",t:"Protect your chance at help",i:["Don't put the bill on a credit card or a medical credit card. You'd pay interest, and getting money back later is much harder than not paying it in the first place","Ask the billing office for an itemized bill and check it for mistakes, like charges for things you didn't get"]},
    {w:o.applyBy?(o.late?"As soon as you can":`By ${dayFmt(o.applyBy)}`):"This week",t:`Apply for financial assistance at ${hn}`,
      i:[contact,"Have ready: pay stubs or last year's tax return, a photo ID, the bill, and recent bank statements",
        ...(o.late?["Your first bill is more than 240 days old. Many hospitals still accept applications, so apply anyway and ask"]:[]),
        ...(h&&h.note?[h.note]:[])]}];
  if(c.medicaid) o.steps.splice(1,0,{w:"This week",t:"Apply for Medicaid at kynect.ky.gov",i:[`Your household is at ${c.pct}% of the poverty line. Kentucky Medicaid covers adults up to 138%`,"Ask whether Medicaid can cover bills from the months before you applied"]});
  if(c.dsh) o.steps.push({w:"When you apply",t:"Ask for a Kentucky DSH application",i:["Kentucky's hospital program pays for care for uninsured patients at or below the poverty line, and the hospital then can't bill you for it (KRS 205.640)"]});
  o.steps.push({w:"While you wait",t:"Ask them to hold the account",i:[...(o.ecaFrom?[`No serious collection steps are allowed before ${dayFmt(o.ecaFrom)}`]:[]),"Nonprofit hospitals can't report you to credit bureaus, sell the debt or sue for at least 120 days after the first bill, and must warn you in writing 30 days first","Ask the billing office to put the account on hold while your application is reviewed"]});
  o.steps.push({w:"If you still owe something",t:"Pay it without new debt",i:["Ask for an interest free payment plan you can afford",...(h&&h.unins&&B.ins==="none"?[`Ask for ${h.unins}`]:[]),"Use Add what's left to my plan below, and CountyWise will fit it into your budget"]});
  // Letter
  const tierTxt=c.off===100?"free care":c.off!=null?`a ${c.off}% discount`:c.tier?"a discount":"";
  o.letter=`[Your name]
[Your address]
${dayFmt(new Date())}

${h?h.name:"[Hospital name]"} Billing Office

Re: Request for financial assistance, account [account number]

To whom it may concern,

I am writing about my bill of ${fmt(amt)}${B.date?`, first billed on ${dayFmt(new Date(B.date+"T12:00:00"))}`:""}. I would like to be screened for financial assistance under your hospital's financial assistance policy.

My household has ${size} ${size===1?"person":"people"} and a total yearly income of about ${fmt(income)} before taxes. That is about ${c.pct}% of the federal poverty guidelines.${tierTxt?` Based on your published policy, I believe I qualify for ${tierTxt}.`:""}

Please:
1. Send me your financial assistance application and a list of the documents you need.
2. Send me an itemized bill.
3. Hold my account, with no collection activity, while my application is reviewed.${c.medicaid?`
4. Let me know whether I should also apply for Medicaid${c.dsh?" and for Kentucky's Disproportionate Share Hospital (DSH) program":""}.`:""}

Thank you. You can reach me at [phone or email].

Sincerely,
[Your name]`;
  return o;
}
function renderBill(){
  const B=S.bill, sel=$("billHosp");
  // Hospitals near your home county first
  if(sel.dataset.c!==S.liveCounty){const near=HOSPITALS.filter(x=>x.counties.includes(S.liveCounty)), rest=HOSPITALS.filter(x=>!near.includes(x)), opt=x=>`<option value="${x.id}">${esc(x.name)}</option>`;
    sel.innerHTML=`<option value="">Choose a hospital</option>`+(near.length?`<optgroup label="Near ${esc(S.liveCounty)} County">${near.map(opt).join("")}</optgroup>`:"")+`<optgroup label="Other Kentucky hospital systems">${rest.map(opt).join("")}</optgroup><option value="other">Another hospital (not listed)</option>`;
    sel.dataset.c=S.liveCounty;}
  sel.value=B.hosp; if($("billAmt")!==document.activeElement) $("billAmt").value=money(B.amt); $("billDate").value=B.date;
  const O=billOutlook(), c=O.c, res=$("billRes");
  $("billHH").innerHTML=O.income?`Using your household from the Income step: ${O.size} ${O.size===1?"person":"people"}, ${fmt(O.income)} a year before taxes, living in ${esc(S.liveCounty)} County. <button class="linkbtn" data-go="income">Change it</button>`:"";
  if(!S.income1&&!S.income2){res.innerHTML=`<h3>What you may owe</h3><p class="sub">Add who lives with you and your yearly pay in the Income step, and this will show where you stand. <button class="linkbtn" data-go="income">Go to Income</button></p>`;$("billKit").hidden=true;return;}
  const line=`Your household of ${O.size} earning ${fmt(O.income)} a year is at <b>${c.pct}%</b> of the federal poverty line.`;
  if(!O.amt){res.innerHTML=`<h3>What you may owe</h3><p class="sub">${line} At that income, <b>${O.freeAt.length} of Kentucky's ${HOSPITALS.length} largest hospital systems</b> would forgive a bill completely. Enter your bill above to see yours.</p>`;$("billKit").hidden=true;return;}
  const badges=[c.medicaid?`<span class="badge">You may qualify for Medicaid</span>`:"",c.dsh?`<span class="badge">You may qualify for Kentucky's hospital program (DSH)</span>`:""].join(" ");
  res.className="card billres "+(O.good?"ok":"no");
  res.innerHTML=`<div class="when">What you may owe</div><p class="big">${esc(O.result)}</p><p class="sub">${line}</p>${badges?`<p>${badges}</p>`:""}`+
    (O.h?`<p class="hint">From ${esc(O.h.name)}'s financial assistance policy${O.h.date?`, ${esc(O.h.date)}`:""}. <a href="${O.h.url}" target="_blank" rel="noopener">Read the policy</a>.${O.h.older?" This is the newest version we could find online, so confirm with the hospital.":""} This is an estimate; the hospital decides when you apply.</p>`:"")+
    (O.applyBy?`<div class="callout${O.late?" warn":""}"><b>${O.late?"Your 240 day window may have passed.":`Apply by ${dayFmt(O.applyBy)}.`}</b> ${O.late?"Apply anyway; many hospitals still accept late applications.":`The hospital can't take serious collection steps before ${dayFmt(O.ecaFrom)}.`}</div>`:"");
  $("billKit").hidden=false;
  $("billSteps").innerHTML=O.steps.map(s=>`<li><div class="when">${esc(s.w)}</div><h4>${esc(s.t)}</h4><ul>${s.i.map(x=>`<li>${esc(x)}</li>`).join("")}</ul></li>`).join("");
  $("billLetter").value=O.letter;
  $("billToDebt").hidden=O.owe===0;
}

function renderLocation({R,T}){
  const vals=countyValues();
  drawMap($("map"),$("mapTip"),vals);
  const rank=vals.slice().sort((a,b)=>a.housing-b.housing).findIndex(v=>v.c===S.liveCounty)+1, ct=DATA.countyTax[S.liveCounty]||0, m=k=>fmt(T.spend[k]/12)+"/mo";
  $("hereLbl").textContent=S.countySet?`${S.liveCounty} County at a glance`:`Showing ${S.liveCounty} County until you choose yours`;
  $("mapHere").innerHTML=[["Median household income",fmt(DATA.income[S.liveCounty])+"/yr"],["Housing and utilities",m("housing")],["Housing cost rank",`#${rank} cheapest of 120`],["Groceries",m("food")],["Car and gas",m("car")]]
    .concat(T.spend.care?[["Child care",m("care")]]:[]).concat([["Health care",m("health")],["County wage tax",ct?ct+"%":"None"]])
    .map(([l,v])=>`<div><span>${l}</span><b>${v}</b></div>`).join("");
  const lr=R.localRate, b=SRC[lr.src];
  $("lrBig").textContent=(+lr.rate.toFixed(4))+"%";
  $("lrMonth").textContent=fmt(R.local/12);
  $("lrBadge").innerHTML=`<span class="badge ${b[1]}">${b[0]}</span>`;
  $("lrWhy").textContent=lr.why;
  $("liveNote").textContent=`Typical costs come from ${S.liveCounty} County data. Housing runs about ${fmt(T.spend.housing/12)} a month for your household.`;
}

// ---- Income and household ----
function renderIncome({R,T}){
  const kids=S.under5+S.schoolAge, ppl=S.adults+kids;
  $("houseNote").textContent=`${ppl} ${ppl===1?"person":"people"} in your home. In ${S.liveCounty} County that typically means about ${fmt(T.spend.housing/12)} for housing (HUD fair market rent) and ${fmt(T.spend.food/12)} for groceries (USDA food plan, cooking every meal at home) a month`+(T.spend.care?`, plus ${fmt(T.spend.care/12)} for child care`:"")+"."+(kids?` You'd get up to ${fmt(2200*kids)} a year in child tax credits.`:"");
  const lbl=R.localRate.src==="custom"?"your rate":place(S.workCounty,S.workCity);
  const rows=[["Federal income tax"+(R.ctc||R.eitc?` (after ${[R.ctc&&fmt(R.ctc)+" child tax credit",R.eitc&&fmt(R.eitc)+" earned income credit"].filter(Boolean).join(" and ")})`:""),Math.max(0,R.fed),"--t1"],["Social Security and Medicare",R.fica,"--t2"],
    ["Kentucky income tax (3.5%)"+(R.kyFsc?` (after ${fmt(R.kyFsc)} family size credit)`:""),R.ky,"--t3"],[`Local wage tax, ${lbl} (${+R.localRate.rate.toFixed(4)}%)`,R.local,"--t4"],["Your 401k",R.k401Sum,"--s7"],["Take home pay",R.net,"--green"]];
  $("payTitle").textContent=!R.gross?"":R.refund?`${fmt(R.gross/12)} a month before taxes. Your paychecks bring home ${fmt(R.net/12)} a month. Your tax credits are bigger than your taxes, so you also get about ${fmt(R.refund)} back once a year when you file. Your budget leaves that refund out, and your plan puts it to work each spring. Point at any stream to see it.`:`${fmt(R.gross/12)} a month before taxes. Taxes take ${Math.round(R.taxes/R.gross*100)}%, and you keep ${fmt(R.net/12)}. Point at any stream to see it.`;
  drawSankey($("sankey"),R,$("sankeyTip"));
  $("payTable").tBodies[0].innerHTML=rows.map(([l,v,c])=>`<tr${l==="Take home pay"?' class="total"':""}><td><span class="sw" style="background:var(${c})"></span>${esc(l)}</td><td>${fmt(v/12)}</td></tr>`).join("")
    +(R.fed<0?`<tr><td colspan="2" class="hint">Your tax credits are bigger than your federal tax, so ${fmt(-R.fed)} a year comes back as a refund.</td></tr>`:"");
}
function budgetRows(R){return CATS.map(([k,l,c])=>({k,l,c,v:k==="save"?Math.max(0,R.left):R.spend[k]})).filter(r=>r.v>0||r.k==="save")}
function renderBudget({E,R}){
  const rows=budgetRows(R);
  $("budgetSub").innerHTML=S.skip.budget?`Typical costs for a household of ${S.adults+S.under5+S.schoolAge} in ${S.liveCounty} County, because you skipped this step.`:"Based on what you entered above."+(R.fed<0?` This uses paycheck money only. Your ${fmt(R.refund)} yearly tax refund is left out, so your budget works every month, not just in refund season.`:"");
  drawDonut($("donut"),rows,R.net,R.left<0?["Short each month",fmt(R.left/12),"--red"]:["Left over",fmt(R.left/12),R.left>0?"--green":"--ink"],$("donutTip"));
  $("budgetTable").tBodies[0].innerHTML=[...rows.filter(r=>r.k!=="save"),{k:"save",l:R.left<0?"Short each month":"Left over",c:R.left<0?"--red":"--s6",v:R.left}].map(r=>`<tr><td><span class="sw" style="background:var(${r.c})"></span>${r.l}</td><td${r.k==="save"?` class="${R.left>0?"pos":R.left<0?"neg":""}"`:""}>${fmt(r.v/12)}</td><td>${R.net>0?(r.v<0?"−":"")+Math.abs(Math.round(r.v/R.net*100)):0}%</td></tr>`).join("")
    +`<tr class="total"><td>Take home pay</td><td>${fmt(R.net/12)}</td><td>100%</td></tr>`;
  // One row at a time: a row shows once every row before it is answered
  const ask=nowAsk().map(c=>c[0]); let open=true;
  NOWCATS.forEach(([k])=>{const row=document.querySelector(`[data-row="${k}"]`), w=nowStep(k,R), v=nowVal(k), [lo,hi]=S.now[k]||[0,0], x=row.querySelector("[data-nowx]");
    row.hidden=!ask.includes(k)||!open; if(ask.includes(k)&&!(k in S.now)) open=false;
    row.querySelector("[data-nowr]").value=v?Math.min(10,Math.max(1,Math.ceil(v/w))):0;
    row.querySelector(".nowv").textContent=k in S.now?(v?nowTxt(k)+" a month":"$0, I don't pay this"):"Not entered";
    row.querySelector(".nowmax").textContent="Up to "+fmt(10*w);
    if(x!==document.activeElement) x.value=hi?"":money(lo);});
  const nowTot=NOWCATS.reduce((a,[k])=>a+nowVal(k),0);
  $("nowSum").innerHTML=open?(nowTot?`All done. You spend about <b>${fmt(nowTot)}</b> a month on everyday costs.`:""):nowTot?`So far: about <b>${fmt(nowTot)}</b> a month.`:"";
  if(lastImport) renderImport(R);
}
// Opens the hospital bill checker in the Debt step and scrolls to it
function showBill(open){$("billBox").hidden=!open;$("billOpen").setAttribute("aria-expanded",String(open));$("billOpen").textContent=open?"Hide the hospital bill check":"Check my hospital bill";if(open)renderBill();}
function openBill(){go("debt");showBill(true);setTimeout(()=>$("billCta").scrollIntoView({behavior:"smooth",block:"start"}),60);}
function renderDebt({E,R,debt}){
  if(S.bill.amt>0&&$("billBox").hidden&&!$("billOpen").dataset.closed) showBill(true);
  if(!$("billBox").hidden) renderBill();
  $("extraTxt").textContent=fmt(S.extra)+"/mo";
  const has=E.debts.some(d=>d.bal>0);
  $("debtChart").style.display=has?"":"none"; $("debtLegend").innerHTML="";
  if(!has){$("debtTiles").innerHTML="";$("debtDelta").className="callout";$("debtDelta").textContent="No debt entered. Everything left over goes to savings.";return;}
  const other=payoff(E.debts,E.strategy==="avalanche"?"snowball":"avalanche",E.extra,R.refund), noExtra=payoff(E.debts,E.strategy,0,R.refund);
  const when=m=>m>=600?"Never at this pace":yrs(m);
  if(!debt.stuck){
    const series=[{l:"Your plan",c:"--s1",pts:debt.bal,thick:true}];
    if(E.extra>0&&!noExtra.stuck) series.push({l:"Minimums only",c:"--s2",pts:noExtra.bal,dash:true});
    const n=Math.max(...series.map(s=>s.pts.length))-1, step=n<=24?6:n<=72?12:24;
    drawLines($("debtChart"),$("debtTip"),series,{H:260,xTick:i=>i===0?"Now":i%step===0?(i%12===0?"Yr "+i/12:i+" mo"):null,xTip:i=>i===0?"Now":"Month "+i,endLabel:(s,i)=>i===0?"":"Paid off"});
    $("debtLegend").innerHTML=series.map(s=>`<span><i style="background:var(${s.c})"></i>${s.l} · debt free in ${yrs(s.pts.length-1)}</span>`).join("");
  } else $("debtChart").style.display="none";
  $("debtTiles").innerHTML=[["Debt free in",when(debt.months),debt.stuck?"neg":debt.months>120?"mid":"pos"],["Interest you'll pay",fmt(debt.interest),""],["Paying each month",fmt(debt.budget),""]].map(([l,v,c])=>`<div class="tile"><div class="l">${l}</div><div class="v ${c}">${v}</div></div>`).join("");
  const parts=[];
  if(debt.stuck) parts.push("Your payments don't cover the interest, so the balance never goes down. Raise a minimum payment or add extra.");
  else{
    if(E.extra>0&&!noExtra.stuck) parts.push(`Your extra ${fmt(E.extra)} a month saves ${fmt(noExtra.interest-debt.interest)} in interest and makes you debt free ${yrs(noExtra.months-debt.months)} sooner.`);
    else if(!noExtra.stuck) parts.push("Try the slider: even $50 extra a month cuts your interest.");
    if(R.refund&&(debt.lumps||[]).some(x=>x>0)) parts.push(`This counts your ${fmt(R.refund)} tax refund going on your highest rate debt each February.`);
    const diff=other.interest-debt.interest;
    if(E.debts.filter(d=>d.bal>0).length>1) parts.push(Math.abs(diff)<1?"Both orders cost about the same here.":diff>0?`This order saves ${fmt(diff)} compared with the other.`:`The other order would save ${fmt(-diff)} in interest, but paying off the smallest balance first gives quicker wins.`);
    parts.push("Once a debt is gone, its payment goes into your savings.");
  }
  $("debtDelta").className="callout"+(debt.stuck?" warn":"");
  $("debtDelta").textContent=parts.join(" ");
}
// Goals are funded in order (emergency fund first) from the cash share of what's left each month.
function goalPlan(E,R){
  const keep=1-E.investShare/100, monthly=Math.max(0,R.left/12)*keep, lump=(R.refund||0)*keep; // lump: cash share of the February tax refund
  const ef={name:"Emergency fund",target:Math.round(E.efMonths*R.essentials),saved:E.startCash,auto:true};
  let need=0;
  return {monthly,lump,list:[ef,...E.goals].map(g=>{const n=Math.max(0,g.target-g.saved);
    if(n===0) return {...g,months:0}; need+=n;
    let pot=0,m=0; while(pot<need&&m<=600){m++; pot+=monthly+(m%12===3?lump:0);} // goals fill in order
    return {...g,months:pot>=need?m:Infinity};})};
}
const when=m=>{if(!isFinite(m)) return "not funded yet"; if(m===0) return "reached"; if(m>360) return "30+ years at this pace"; const d=new Date(); d.setMonth(d.getMonth()+m); return d.toLocaleString("en-US",{month:"short",year:"numeric"});};
function renderGoals({E,R}){
  const debts=E.debts.reduce((a,d)=>a+d.bal,0), nw=E.startCash+E.startInvest-debts;
  $("netWorth").innerHTML=`What you own minus what you owe (net worth): <b class="${nw<0?"neg":"pos"}">${fmt(nw)}</b>.`;
  const G=goalPlan(E,R);
  $("efTxt").textContent=`${E.efMonths} month${E.efMonths>1?"s":""} · ${fmt(E.efMonths*R.essentials)}`;
  $("goalSub").textContent=G.monthly>0||G.lump>0?`${G.monthly>0?`${fmt(G.monthly)} a month from your paychecks`:"Your paychecks leave nothing extra yet, but"}${G.lump>0?`${G.monthly>0?" plus":""} ${fmt(G.lump)} of your tax refund each February`:""} goes to goals: the part of your leftover money you keep as cash (${100-E.investShare}%). Goals fill in order, emergency fund first.`:"Nothing is going to goals yet. Free up money in Budget, or keep more as cash in the Invest step.";
  $("goalRings").innerHTML=G.list.map(g=>{const pct=g.target?g.saved/g.target:1, c=pct>=1?"--green":isFinite(g.months)&&g.months<=60?"--yellow":"--red";
    if(g.auto&&!g.target) return `<div class="goal">${ring(0,"--ink3")}<div><b>${esc(g.name)}</b><span>Add your pay and spending first to size this fund</span></div></div>`;
    return `<div class="goal">${ring(pct,c)}<div><b>${esc(g.name)}</b><span>${fmt(g.saved)} of ${fmt(g.target)}${g.auto?" (your cash savings)":""} · ${g.months===0?"Done":isFinite(g.months)?"Reached by "+when(g.months):"Not funded yet"}</span></div></div>`;}).join("");
}
function renderInvest({E,R,debt,P}){
  const fut=Object.keys(PORTFOLIOS).map(k=>project(E,R,debt,portfolioRates(k).rExp,E.years).pts[E.years]);
  $("sameNote").hidden=Math.max(...fut)-Math.min(...fut)>=1;
  $("portfolios").innerHTML=Object.entries(PORTFOLIOS).map(([k,p])=>{const r=portfolioRates(k), f=project(E,R,debt,r.rExp,E.years).pts[E.years];
    return `<button class="preset" data-port="${k}" aria-pressed="${E.portfolio===k}"><b>${p.name}</b><div class="mixbar"><i style="flex:${p.mix[0]};background:var(--s1)"></i><i style="flex:${p.mix[1]};background:var(--s9)"></i></div><span>${p.blurb}</span><span>About ${r.rExp}% a year after inflation</span><div class="big">${fmtK(f)}</div><span>in ${E.years} years</span></button>`;}).join("");
  $("yearsTxt").textContent=E.years+" years"; $("investTxt").innerHTML=`${E.investShare}% <small style="color:var(--ink3)">${fmt(Math.max(0,R.left/12)*E.investShare/100)}/mo</small>`;
  $("investLbl").textContent=`Of ${fmt(Math.max(0,R.left/12))} left, invest`;
  $("growthTxt").textContent=E.growth?E.growth+"% a year":"No increase";
  const n=E.years, step=n<=10?1:n<=20?5:10;
  drawLines($("proj"),$("projTip"),P.map((p,i)=>({l:p.l,c:p.c,pts:p.pts,thick:i===0})),{H:340,fill:true,xTick:i=>i===0?"Now":i%step===0?"Year "+i:null,xTip:i=>i===0?"Now":"Year "+i});
  $("proj").setAttribute("aria-label",`In ${n} years: average ${fmt(P[0].pts[n])}, bad markets ${fmt(P[1].pts[n])}, good markets ${fmt(P[2].pts[n])}.`);
  $("projLegend").innerHTML=`<span><b>${PORTFOLIOS[E.portfolio]?PORTFOLIOS[E.portfolio].name:"Your"} mix:</b></span>`+P.map(p=>`<span><i style="background:var(${p.c})"></i>${p.l} (${p.r}% a year)</span>`).join("")+`<span style="color:var(--ink3)">Stocks <i style="background:var(--s1);width:10px;height:10px"></i> Bonds <i style="background:var(--s9);width:10px;height:10px"></i></span>`;
  const e=P[0];
  $("projTiles").innerHTML=[["401k and investments you have now",e.k401],["New investing account",e.invest],["Cash savings",e.cash]].map(([l,v])=>`<div class="tile"><div class="l">${l}</div><div class="v">${fmt(v)}</div><div class="l">in ${n} years, average markets</div></div>`).join("");
}

// ---- Recommendations: action steps from all the numbers, in the usual personal finance order ----
const PLANROWS=[["housing","Housing and utilities"],["food","Groceries"],["car","Car and gas"],["care","Child care"],["health","Health care"],["phone","Phone and internet"],["fun","Eating out and fun"],["other","Other spending"],["debtMin","Debt minimum payments"],["debtExtra","Extra toward debt"],["cash","Cash savings and goals"],["invest","Investing"]];
const tabName=id=>id==="billcheck"?"the hospital bill check":(TABS.find(t=>t[0]===id)||[0,""])[1];
// What you do now, in the same rows as the recommended plan (monthly)
function nowPlan(M){
  const {E,R,inv}=M, n=Object.fromEntries(NOWCATS.map(([k])=>[k,R.spend[k]/12]));
  n.debtMin=R.debtMin/12; n.debtExtra=(R.spend.debt-R.debtMin)/12; n.invest=inv; n.cash=R.left/12-inv;
  return n;
}
function cutList(n,p){
  return PLANROWS.filter(([k])=>!["debtExtra","cash","invest"].includes(k)&&n[k]-p[k]>=5).sort((x,y)=>(n[y[0]]-p[y[0]])-(n[x[0]]-p[x[0]])).map(([k,l])=>`${l}: from ${fmt(n[k])} to ${fmt(p[k])}, saving ${fmt(n[k]-p[k])} a month`);
}
function recommendations(M){
  const {E,R,T,debt}=M, out=[];
  if(!R.gross) return [{lvl:"r",t:"Add your pay",d:"We need your yearly pay to build your plan.",go:"income"}];
  const RP=recommendPlan(E,R,T), p=RP.p, n=nowPlan(M), gm=R.gross/12, net=R.net/12, t=k=>T.spend[k]/12;
  const efm=RP.efm, need1=R.essentials, cty=E.liveCounty+" County";
  const mon=(goal,per)=>per>0?Math.ceil(goal/per):Infinity, inMo=m=>isFinite(m)?(m<=1?"about a month":m<12?m+" months":yrs(m)):"not at this pace";

  const BO=billOutlook();
  if(BO.has&&S.bill.ins!=="medicaid") out.push({lvl:"r",t:"Apply for help with your hospital bill",d:`${BO.result} Your household is at ${BO.c.pct}% of the federal poverty line, and nonprofit hospitals must have a financial assistance policy.`,
    steps:BO.steps.slice(0,2).flatMap(s=>s.i.slice(0,1)).concat(BO.applyBy&&!BO.late?[`Apply by ${dayFmt(BO.applyBy)}`]:[]),imp:BO.owe!=null&&BO.amt-BO.owe>=5?fmt(BO.amt-BO.owe):"",sm:"could be forgiven",go:"billcheck"});
  if(R.left<0) out.push({lvl:"r",t:`Close your ${fmt(-R.left/12)} monthly shortfall`,
    d:"You spend more than you take home. That gap usually ends up on a credit card at high interest, so closing it comes before anything else. The recommended plan closes the gap with these changes. Anything past the gap goes to savings and debt, so you stop falling behind and start getting ahead:",
    steps:cutList(n,p).slice(0,5),imp:fmt(-R.left/12),sm:"a month to close",go:"budget"});
  if(RP.short>0) out.push({lvl:"r",t:"Your must pay bills are more than your take home pay",
    d:`Even after trimming wants, housing, car and groceries, you'd still be ${fmt(RP.short)} a month short. Cutting further isn't realistic, so the next steps are on the income side and in benefits you may qualify for.`,
    steps:["Ask about a raise, more hours or overtime, and look at what similar jobs pay in your area","Consider side income or a second earner in the household","A roommate or a cheaper place at your next lease renewal is the biggest single saving",
      "Check kynect.ky.gov for health coverage, SNAP food benefits and other help","With kids, Kentucky's Child Care Assistance Program can lower child care costs"],go:"income"});

  // Starter emergency fund
  if(efm<1) out.push({lvl:"r",t:"Build a starter emergency fund first",
    d:`Your cash covers ${efm.toFixed(1)} months of must pay bills. Without a cushion, a car repair or a missed paycheck goes on a credit card. One month of bills (${fmt(need1)}) is the first target, then 3 to 6 months.`,
    steps:[p.cash>0?`Set up an automatic transfer of ${fmt(p.cash)} a month to a separate savings account on payday. At that pace you reach one month in ${inMo(mon(need1-E.startCash,p.cash))}.`:"Free up money in your budget first, even $25 a week adds up",
      "Keep it in a high yield savings account, which pays more interest than a regular one and keeps the money apart from spending","Put tax refunds, bonuses and gifts here until you reach the target"],
    imp:fmt(Math.max(0,need1-E.startCash)),sm:"still needed for 1 month",go:"goals"});

  // 401k match
  if(E.match>E.k401){const R2=compute({...E,k401:E.match},DATA,placeOf(E)), free=(E.match-E.k401)/100*R.gross, cost=(R.net-R2.net)/12;
    out.push({lvl:"r",t:"Collect your full 401k match",
      d:`Your employer adds up to ${E.match}% of your pay when you put in the same. At ${E.k401}% you're passing up ${fmt(free)} a year. That's an instant 100% return, better than almost any other use of the money.`,
      steps:[`Raise your contribution from ${E.k401}% to ${E.match}% on your employer's benefits site or through HR`,`It lowers your take home pay by only about ${fmt(cost)} a month, because 401k money comes out before income tax`,"Check how long until the match is yours to keep (the vesting schedule)"],
      imp:fmt(free),sm:"a year from your employer",go:"income"});}

  // High interest debt
  const hot=E.debts.filter(d=>d.bal>0&&d.rate>=8).sort((a,b)=>b.rate-a.rate);
  if(debt.stuck) out.push({lvl:"r",t:"Your debt is growing, not shrinking",d:"Your payments don't cover the interest, so the balance goes up every month.",
    steps:["Raise the payment on the debt with the highest rate until the balance starts falling","Call the lender and ask about a lower rate or a hardship plan","A nonprofit credit counselor (look for NFCC members) can set up a debt management plan"],go:"debt"});
  else if(hot.length){const ex=Math.max(E.extra,Math.round(p.debtExtra)), plan=payoff(E.debts,"avalanche",ex,R.refund), minOnly=payoff(E.debts,"avalanche",0);
    out.push({lvl:"r",t:`Pay off high interest debt, starting with ${hot[0].name||"your highest rate debt"}`,
      d:`At ${hot[0].rate}% interest, this debt costs more than savings or investments are likely to earn, so extra money goes here after your starter emergency fund. Paying the highest rate first costs the least.`,
      steps:[(ex<5&&R.refund?`Pay the minimum on every debt, and use your tax refund each February to pay down ${hot[0].name||"the highest rate debt"}`:`Pay the minimum on every debt, then send ${fmt(ex)} extra a month to ${hot[0].name||"the highest rate debt"}${R.refund?", plus your tax refund each February":""}`)+(plan.stuck?"":`. You'd be debt free in ${yrs(plan.months)} and save ${fmt(Math.max(0,minOnly.interest-plan.interest))} in interest compared with minimums only.`),
        "Call your card company and ask for a lower rate; people who ask often get one","A 0% balance transfer card or a credit union loan can cut the rate if your credit allows. Watch for transfer fees.","Pay with debit or cash while you pay it down so the balance doesn't grow"],
      imp:plan.stuck?"":fmt(Math.max(0,minOnly.interest-plan.interest)),sm:"interest saved",go:"debt"});}

  // Housing
  const hs=R.spend.housing/R.gross, cap=.30*gm;
  if(hs>.30) out.push({lvl:hs>.40?"r":"y",t:`Bring housing closer to 30% of your pay`,
    d:`Housing takes ${pctOf(R.spend.housing,R.gross)}% of your pay before taxes. The common benchmark is 30% or less (${fmt(cap)} a month for you). Typical housing for your household in ${cty} is ${fmt(t("housing"))}.`,
    steps:["A roommate can cut your rent and utilities close to in half","At lease renewal, ask to keep the same rent or trade a longer lease for a lower rate","Compare nearby counties on the map in the Location step; check the commute cost too","If you own, ask your lender about refinancing, and check your property assessment with your county PVA",
      "Cut utility bills: LED bulbs, a smart thermostat, and your utility's free home energy check"],
    imp:n.housing-p.housing>=5?fmt(n.housing-p.housing):"",sm:"a month freed up",go:"location"});
  else out.push({lvl:"g",t:"Your housing is affordable",d:`Housing takes ${pctOf(R.spend.housing,R.gross)}% of your pay, within the 30% benchmark. That leaves room for saving.`,go:"budget"});

  // Car
  if(n.car>t("car")*1.1) out.push({lvl:"y",t:"Lower your car costs",
    d:`You spend ${fmt(n.car)} a month on your car, above the typical ${fmt(t("car"))} for your household in ${cty}.`,
    steps:["Shop your car insurance every year; quotes for the same coverage can vary by hundreds of dollars","With an emergency fund in place, a higher deductible lowers your premium","Refinance your car loan at a credit union if rates dropped or your credit improved",`For your next car, keep payment, insurance and gas under about 15% of take home pay (${fmt(.15*net)})`],
    imp:fmt(n.car-p.car),sm:"a month freed up",go:"budget"});
  // Groceries
  if(n.food>t("food")*1.1) out.push({lvl:"y",t:"Trim your grocery bill",
    d:`You spend ${fmt(n.food)} a month on groceries. Typical for your household in ${cty} is ${fmt(t("food"))}, based on USDA food plans.`,
    steps:["Plan the week's meals and shop with a list","Store brands usually cost much less than name brands","Use your store's app for digital coupons and fuel points","Buy staples like rice, beans and frozen vegetables in bulk"],
    imp:fmt(n.food-p.food),sm:"a month freed up",go:"budget"});
  // Wants
  const wants=n.fun+n.other;
  if(wants>.30*net||n.fun+n.other-p.fun-p.other>=5) out.push({lvl:"y",t:"Set a limit for eating out, fun and extras",
    d:`Wants take ${fmt(wants)} a month, ${pctOf(wants,net)}% of take home pay.${R.left<0?" Your paychecks don't cover your bills yet, so your plan pauses these until the gap closes.":wants<=.30*net?" That's within the usual limit, but trimming here is how your plan reaches its savings goal.":""} A common guide is the 50/30/20 rule: about 50% for needs, up to 30% for wants, and at least 20% for saving and debt.`,
    steps:["Cancel subscriptions you haven't used in the last month","Set a weekly cash or card limit for eating out","Wait 48 hours before any purchase over $50 that isn't a need",`Your plan allows ${fmt(p.fun+p.other)} a month for wants`],
    imp:fmt(wants-p.fun-p.other),sm:"a month freed up",go:"budget"});
  // Phone
  if(n.phone>t("phone")*1.2) out.push({lvl:"y",t:"Cut your phone and internet bill",d:`You pay ${fmt(n.phone)} a month; typical is about ${fmt(t("phone"))}.`,
    steps:["Prepaid plans and family plans often cost much less on the same network","Call your internet provider and ask for a current promotion or a slower, cheaper speed","Lifeline lowers phone or internet bills for households that qualify"],imp:fmt(n.phone-p.phone),sm:"a month freed up",go:"budget"});

  // Debt load
  const dti=(R.debtMin+R.spend.housing)/R.gross;
  if(dti>.36) out.push({lvl:"y",t:"Your debt load is high for lenders",
    d:`Housing and debt payments take ${pctOf(R.debtMin+R.spend.housing,R.gross)}% of your pay. Lenders usually want this under 36% before approving a mortgage or car loan. It only matters when you apply for a new loan.`,
    steps:["This number drops on its own as you follow the plan and balances fall","Planning to buy a home or car soon? Fully paying off one small debt first removes its whole payment and helps your approval"].concat(E.debts.some(d=>/student/i.test(d.name))?["For federal student loans, an income driven repayment plan at studentaid.gov can lower your payment"]:[]),go:"debt"});

  // Emergency fund, full
  const target=E.efMonths*need1;
  if(efm>=1&&efm<E.efMonths) out.push({lvl:"y",t:`Grow your emergency fund to ${E.efMonths} months`,
    d:`You have ${efm.toFixed(1)} months of bills saved. ${E.efMonths} months (${fmt(target)}) protects you from a job loss or big repair without new debt.`,
    steps:[p.cash>0?`Saving ${fmt(p.cash)} a month, you reach it in ${inMo(mon(target-E.startCash,p.cash))}`:"Free up money in your budget to start saving","Once you reach it, the money you were saving can go to investing or your goals"],go:"goals"});
  else if(efm>=E.efMonths) out.push({lvl:"g",t:"Your emergency fund is solid",d:`Your cash covers ${efm.toFixed(1)} months of bills, at or above your ${E.efMonths} month target.`,go:"goals"});

  // Retirement
  const ret=(R.k401Sum+R.matchSum)/R.gross;
  if(ret<.15&&!hot.length&&efm>=1) out.push({lvl:"y",t:"Work toward saving 15% for retirement",
    d:`You and your employer put ${Math.round(ret*100)}% of your pay into your 401k. A common benchmark is 15%, counting the match. Starting early matters most because growth compounds.`,
    steps:["Raise your 401k by 1% each year, or each time you get a raise, so you barely notice it","An IRA lets you save for retirement on top of a 401k, with tax benefits",p.invest>0?`Your plan also sends ${fmt(p.invest)} a month to investing`:"Once debts and the emergency fund are handled, send leftover money to investing"],go:"income"});
  else if(ret>=.15) out.push({lvl:"g",t:"Your retirement saving is on track",d:`You and your employer put ${Math.round(ret*100)}% of your pay toward retirement, at or above the 15% benchmark.`,go:"invest"});

  // Overall saving rate
  const srNow=(Math.max(0,R.left)+R.k401Sum+R.matchSum)/R.gross, srPlan=((p.cash+p.invest+p.debtExtra)*12+(R.refund||0)+R.k401Sum+R.matchSum)/R.gross;
  out.push({lvl:srNow>=.2?"g":srNow>=.1?"y":"r",t:srNow>=.2?"You're saving at a strong rate":"Raise your saving rate",
    d:`Your saving rate is the share of your pay that goes to savings, investing and extra debt payments, counting your 401k. Today yours is ${Math.round(srNow*100)}%. The recommended plan gets you to ${Math.round(srPlan*100)}%${R.refund?", counting your tax refund going to debt and savings":""}. The usual benchmark is 20% for saving and paying down debt.`,
    steps:srNow>=.2?undefined:["Pay yourself first: move savings out automatically on payday, before you can spend it","Save at least half of every raise"],go:srNow>=.2?"invest":"budget"});

  if(E.debts.some(d=>d.bal>0)&&!debt.stuck&&debt.months<=60) out.push({lvl:"g",t:`Debt free in ${yrs(debt.months)}`,d:"You're on pace to be done with debt in five years or less. Then those payments can go straight to saving.",go:"debt"});
  if(R.localRate.src==="cityUnknown") out.push({lvl:"y",t:"Confirm your local wage tax",d:`We couldn't confirm ${E.workCity}'s rate, so we used the county's.`,steps:["Find the local or OL tax line on your pay stub and type the exact rate in Location"],go:"location"});
  const skipped=TABS.filter(([id])=>S.skip[id]).map(([,l])=>l);
  if(skipped.length) out.push({lvl:"y",t:"Fill in the steps you skipped",d:`You skipped ${skipped.join(", ")}. We used typical values there, so your plan is less exact.`,go:TABS.find(([id])=>S.skip[id])[0]});
  const order={r:0,y:1,g:2}; return out.sort((a,b)=>order[a.lvl]-order[b.lvl]);
}
const pctOf=(a,b)=>b>0?Math.round(a/b*100):0;
const WHY={housing:"Up to 30% of pay or your county's typical cost",food:"Within 10% of typical for your county",car:"Typical for your county",phone:"Typical for your county",fun:"Wants kept within 30% of take home",other:"Wants kept within 30% of take home",
  debtExtra:"High interest debt costs more than savings earn",cash:"Emergency fund first, then goals",invest:"Long term growth after the basics are covered"};
// The goal headline, milestones and roadmap from following the recommended plan
function planOutlook(M){
  const {E,R,T,H}=M, RP=recommendPlan(E,R,T), p=RP.p, n=nowPlan(M), F=followPlan(E,R,p,E.years,E.rExp);
  const sav=x=>x.debtExtra+Math.max(0,x.cash)+x.invest, more=sav(p)-sav(n), Y=E.years;
  const by=m=>m===0?"Already there":m==null?`Not within ${Y} years`:when(m), hasDebt=E.debts.some(d=>d.bal>0);
  const head=(RP.short>0?`Your first goal: close a ${fmt(RP.short)} monthly gap so your bills fit your pay.`
    :R.left<0?`Your plan closes a ${fmt(-R.left/12)} monthly gap${sav(p)>=5?` and puts ${fmt(sav(p))} a month toward your future`:""}.`
    :more>=5?`Your plan frees up ${fmt(more)} a month for your future, ${fmt(more*12)} a year.`:"Your spending already fits your pay. Keep it going.")
    +(R.refund?` Each spring your ${fmt(R.refund)} tax refund goes to ${E.debts.some(d=>d.bal>0&&d.rate>=8)?"your high interest debt first, then savings":"your emergency fund, then your goals"}.`:"");
  const BO=billOutlook(), bill=BO.has&&(BO.h||S.bill.hosp==="other");
  const miles=[...(bill?[[`Hospital bill (${BO.hn})`,BO.owe===0?"Likely $0":BO.owe!=null?"About "+fmt(BO.owe):"Discount likely"]]:[]),[`Emergency fund (${E.efMonths} months, ${fmt(F.target)})`,by(F.ms.efFull)]];
  if(hasDebt) miles.push(["Debt free",by(F.ms.debtFree)]);
  E.goals.forEach((g,i)=>miles.push([g.name||"Your goal",by(F.ms.goals[i])]));
  miles.push([`Saved and invested in ${Y} years on this plan`,fmtK(F.total)]);
  const auto=[[p.cash,"to savings"],[p.invest,"to investing"],[p.debtExtra,"extra to your highest rate debt"]].filter(([v])=>v>=5).map(([v,l])=>`${fmt(v)} ${l}`);
  const first=[];
  if(E.match>E.k401) first.push(`Raise your 401k from ${E.k401}% to ${E.match}% to get your full employer match`);
  first.push(...cutList(n,p).slice(0,3).map(s=>"Lower "+s[0].toLowerCase()+s.slice(1).replace(": from"," from")));
  if(n.car>T.spend.car/12*1.1) first.push("Get three car insurance quotes and switch if one is cheaper");
  if(auto.length) first.push(`Set up automatic transfers on payday: ${auto.join(", ")}`);
  if(RP.short>0) first.push("Look for more income: a raise, more hours or side work","Check kynect.ky.gov for health coverage, SNAP and child care help");
  const BEN=benefitsFor(E,R).list, apply=BEN.filter(b=>!["eitc","kyfsc"].includes(b.id)), credits=BEN.filter(b=>b.id==="eitc");
  const road=[...(apply.length?[{w:"This month",t:"Apply for help you likely qualify for",i:[...apply.slice(0,5).map(b=>b.name),"Medicaid, KCHIP, SNAP and child care help all use one application at kynect.ky.gov"]}]:[]),...(bill?[{w:"This month",t:`Apply for help with your ${fmt(BO.amt)} hospital bill`,i:[BO.result,...(BO.applyBy&&!BO.late?[`Apply by ${dayFmt(BO.applyBy)}`]:[]),"Use the action kit and letter in the hospital bill check (Debt step)"]}]:[]),{w:"This month",t:"Set up your plan",i:first}];
  const top=E.debts.filter(d=>d.bal>0).sort((a,b)=>b.rate-a.rate)[0];
  const dated=[]; // timed steps, sorted by finish date below
  if(F.ms.starter>0) dated.push({m:F.ms.starter,w:`Now to ${when(F.ms.starter)}`,t:`Build a starter emergency fund of ${fmt(F.starter)}`,i:["Keep it in a separate savings account so it isn't spent by accident","Covers one month of bills if a car repair or missed paycheck hits"]});
  if(hasDebt) dated.push({m:F.ms.debtFree??1e9,w:F.ms.debtFree==null?"Ongoing":`Now to ${when(F.ms.debtFree)}`,t:"Become debt free",i:[`Pay minimums on everything and send extra to ${top.name||"the highest rate debt"} (${top.rate}%) first`,"When a debt is paid off, move its payment to the next one, then to savings"]});
  if(F.ms.efFull>0) dated.push({m:F.ms.efFull,w:`By ${when(F.ms.efFull)}`,t:`Finish your ${E.efMonths} month emergency fund (${fmt(F.target)})`,i:["This protects you from a job loss without new debt"]});
  E.goals.forEach((g,i)=>{const m=F.ms.goals[i]; if(m) dated.push({m,w:`By ${when(m)}`,t:`Reach your ${g.name||"goal"} goal (${fmt(g.target)})`,i:["Goals fill from cash savings after your emergency fund"]});});
  road.push(...dated.sort((a,b)=>a.m-b.m));
  road.push({w:"Every month",t:"Invest for the long run",i:[p.invest>=5?`${fmt(p.invest)} a month now, more once debt and the emergency fund are done`:"Start once debt and the emergency fund are handled","Raise your 401k by 1% each year until you and your employer reach 15%",`About ${fmtK(F.total)} saved and invested in ${Y} years in average markets, in today's dollars`]});
  if(credits.length) road.push({w:"At tax time",t:"File a tax return to collect your earned income credit",i:[`About ${fmt(R.eitc)} that you only get by filing`,...(R.refund?[`Your plan puts the ${fmt(R.refund)} refund toward ${E.debts.some(d=>d.bal>0&&d.rate>=8)?"your high interest debt":"your emergency fund, then your goals"}`]:[]),"Free filing at an IRS VITA site; call 211 to find one near you"]});
  road.push({w:"Every year",t:"Check in on your plan",i:["Update your numbers here when your pay, rent or household changes","Shop your insurance and phone plans again","Check the local wage tax on your pay stub"]});
  const k401=Math.max(E.k401,E.match), R2={...R,left:(p.cash+p.invest)*12,k401Sum:R.gross*k401/100,spend:{...R.spend,housing:p.housing*12},debtMin:F.ms.debtFree!=null&&F.ms.debtFree<=12?0:R.debtMin};
  return {head:bill?`First, apply for help with your ${fmt(BO.amt)} hospital bill. ${head}`:head,miles,road,H2:healthScore({...E,startCash:F.cash12},R2)};
}
// ---- Your county: facts about where you live, and every county ranked for your pay ----
// Same job (where you work stays put), same household, each county's typical costs and local tax.
function bestCounties(E){
  return counties.map(c=>{const pl={liveCounty:c,liveCity:ELSE,workCounty:S.workSet?E.workCounty:c,workCity:S.workSet?E.workCity:ELSE}, X=typical(E,pl);
    return {c,left:X.left/12,housing:X.spend.housing/12};}).sort((a,b)=>b.left-a.left);
}
const leftTxt=(v,C,c)=>c===C.here.c?"your county":(v>=C.here.left?"+":"−")+fmt(Math.abs(v-C.here.left))+"/mo"; // vs your county, since your own budget may differ from typical costs
function countyOutlook(M){
  const {E,R,T}=M, rank=bestCounties(E), me=rank.findIndex(v=>v.c===E.liveCounty), here=rank[me], top=rank.slice(0,5);
  const med=DATA.income[E.liveCounty], inc=E.income1+(E.adults===2?E.income2:0), near=HOSPITALS.filter(h=>h.counties.includes(E.liveCounty)).map(h=>h.name);
  const facts=[["Typical housing for your household",fmt(T.spend.housing/12)+"/mo"],["Median household income here",fmt(med)+"/yr"],
    ["Your household's income",inc?`${Math.round(inc/med*100)}% of the county median`:"Not entered"],
    ["Local wage tax where you work",`${+R.localRate.rate.toFixed(3)}%, about ${fmt(R.local/12)}/mo`],["Hospitals near you",near.length?near.join(", "):"None of the 15 systems we track"],
    ["Rank for your pay",`#${me+1} of 120 counties`]];
  return {rank,me,here,top,facts,gap:rank[0].left-here.left};
}
function renderCounty(M,B){
  const {E}=M, C=countyOutlook(M);
  $("countyHead").textContent=`You live in ${E.liveCounty} County`;
  $("countyFacts").innerHTML=C.facts.map(([l,v])=>`<li><span>${l}</span><b>${esc(v)}</b></li>`).join("");
  $("countyBest").innerHTML=C.top.map((v,i)=>`<li${v.c===E.liveCounty?' class="me"':""}><span>${i+1}. ${esc(v.c)} County${v.c===E.liveCounty?" (yours)":""}</span><b class="${v.c===E.liveCounty?"":v.left>=C.here.left?"pos":"neg"}">${leftTxt(v.left,C,v.c)}</b></li>`).join("")+
    (C.me>=5?`<li class="me"><span>${C.me+1}. ${esc(E.liveCounty)} County (yours)</span><b>your county</b></li>`:"");
  $("countyNote").textContent=(C.me===0?`${E.liveCounty} County already leaves you the most of all 120 counties for your pay.`:`Living in ${C.rank[0].c} County would leave about ${fmt(C.gap)} more a month than ${E.liveCounty} County.`)+
    ` This compares typical rent, groceries, car, child care, health care and local taxes for your household in every county, ${S.workSet?`keeping your job in ${place(E.workCounty,E.workCity)}`:"assuming you'd also work in that county"}. It doesn't count commute time or gas, so a county far from your job may not be realistic.`+(C.rank[0].left<0?" These use full price costs; help like Medicaid, SNAP and child care assistance below can cover much of the gap.":"");
  const ben=B.list;
  $("benSub").innerHTML=ben.length?`Your household of ${E.adults+E.under5+E.schoolAge} is at <b>${B.pct}%</b> of the 2026 federal poverty line. Based on Kentucky's 2026 limits, you may qualify for:`:"At your income you're above the 2026 limits for most Kentucky assistance programs. If your income drops, check again.";
  $("benList").innerHTML=ben.map(b=>`<li><b>${esc(b.name.replace(/about (\d[\d,]*) dollars/,(m,n)=>"about $"+n))}</b>${b.limit?` <span class="badge">up to ${b.limit}% of poverty line</span>`:""}<p>${esc(b.why)}</p><p class="how">${esc(b.how)}</p></li>`).join("");
}
function renderRecommend(M){
  const {E,R,T,H}=M, O=R.gross?planOutlook(M):null;
  $("goalCard").hidden=$("roadCard").hidden=$("countyCard").hidden=$("benCard").hidden=!O;
  if(O) renderCounty(M,benefitsFor(E,R));
  if(O){$("goalHead").textContent=O.head;
    $("goalMiles").innerHTML=O.miles.map(([l,v])=>`<li><span>${esc(l)}</span><b>${esc(v)}</b></li>`).join("");
    $("road").innerHTML=O.road.map(s=>`<li><div class="when">${esc(s.w)}</div><h4>${esc(s.t)}</h4><ul>${s.i.map(x=>`<li>${esc(x)}</li>`).join("")}</ul></li>`).join("");}
  $("nowCmp").hidden=!R.gross;
  if(R.gross){const RP=recommendPlan(E,R,T), p=RP.p, n=nowPlan(M), net=R.net/12, sav=x=>x.debtExtra+Math.max(0,x.cash)+x.invest, more=sav(p)-sav(n);
    const rows=PLANROWS.filter(([k])=>n[k]>=1||p[k]>=1);
    $("nowCmpSub").innerHTML=(RP.short>0?`Your take home pay is <b>${fmt(net)}</b> a month.`:`Both columns add up to your take home pay of <b>${fmt(net)}</b> a month, so the plan never spends more than you make. In the Change column, <span class="pos">green</span> means more money freed up or saved, <span class="neg">red</span> means less.`)+
      (more>=5?` Following it puts <b class="pos">${fmt(more)} more a month</b> toward saving and debt, ${fmt(more*12)} a year.`:"")+(RP.short>0?` <span class="neg">Even this plan runs ${fmt(RP.short)} a month short; see the first step below.</span>`:"");
    const SAVE=["debtExtra","cash","invest"]; // for these rows, more is better
    const ch=k=>{const d=p[k]-n[k];return Math.abs(d)<5?`<td>same</td>`:`<td class="${(d>0)===SAVE.includes(k)?"pos":"neg"}">${d>0?"+":"−"}${fmt(Math.abs(d))}</td>`;};
    $("nowTable").innerHTML=`<thead><tr><th>Category</th><th>You now</th><th>Recommended</th><th>Change</th><th>Why</th></tr></thead><tbody>`+
      rows.map(([k,l])=>`<tr><td>${l}</td><td class="${n[k]<0?"neg":""}">${fmt(n[k])}</td><td><b>${fmt(p[k])}</b></td>${ch(k)}<td class="why">${Math.abs(p[k]-n[k])>=5||SAVE.includes(k)?WHY[k]||"":""}</td></tr>`).join("")+
      (RP.short>0?`<tr><td>Still short after cuts</td><td></td><td class="neg">−${fmt(RP.short)}</td><td></td><td class="why">Needs more income or benefits</td></tr>`:"")+
      `<tr class="total"><td>Take home pay</td><td>${fmt(net)}</td><td>${fmt(net)}</td><td></td><td></td></tr></tbody>`;}
  const recs=recommendations(M), c={r:0,y:0,g:0}; recs.forEach(r=>c[r.lvl]++);
  $("moreSum").textContent=!R.gross?"See what to do first":`See ${recs.length===1?"your recommendation":`all ${recs.length} recommendations`} and your full budget comparison`;
  $("recLede").innerHTML=R.gross?`Based on everything you entered: <b class="neg">${c.r} priority action${c.r===1?"":"s"}</b>, <b class="mid">${c.y} way${c.y===1?"":"s"} to improve</b>, and <b class="pos">${c.g} strength${c.g===1?"":"s"}</b>. Work from the top down.<br><small style="color:var(--ink3)">Red: do these first. Yellow: worth doing next. Green: already going well, keep it up.</small>`:"Add your pay to get your plan.";
  $("gauge").style.display=R.gross?"":"none"; if(R.gross) drawGauge($("gauge"),H.score);
  $("scoreParts").innerHTML=!R.gross?`<h3 style="font-family:var(--serif);margin:0 0 4px">Money health score</h3><p class="sub" style="margin:0">Add your pay in the Income step to see your score.</p>`:`<h3 style="font-family:var(--serif);margin:0 0 4px">Money health score</h3>`+
    (O?`<p class="sub" style="margin:0 0 12px">Today <b>${H.score}</b>. ${O.H2.score>H.score?`Follow your plan and it rises to about <b class="pos">${O.H2.score}</b> in 12 months.`:"Follow your plan to keep it there."}</p>`:"")+H.parts.map(([l,v,tipTxt])=>`<div class="part"><b>${l}</b><span class="${v>=.75?"pos":v>=.4?"mid":"neg"}">${Math.round(v*20)} / 20</span><div class="track"><i style="width:${v*100}%;background:var(${v>=.75?"--green":v>=.4?"--yellow":"--red"})"></i></div><small>${tipTxt}</small></div>`).join("");
  const icon={r:"!",y:"•",g:"✓"};
  $("recs").innerHTML=recs.map(r=>`<div class="rec ${r.lvl}"><div class="ic" aria-hidden="true">${icon[r.lvl]}</div><div><h4>${esc(r.t)}</h4><p>${esc(r.d)}</p>${r.steps&&r.steps.length?`<ul>${r.steps.map(s=>`<li>${esc(s)}</li>`).join("")}</ul>`:""}<button class="btn go" data-go="${r.go}">Go to ${tabName(r.go)} →</button></div>${r.imp?`<div class="impact ${r.lvl==="r"?"neg":r.lvl==="y"?"mid":"pos"}">${r.imp}<small>${esc(r.sm)}</small></div>`:"<div></div>"}</div>`).join("");
}

// ---- Statement import ----
function renderImport(R){
  const tx=lastImport.tx, tot={};
  tx.forEach(t=>tot[t.cat]=(tot[t.cat]||0)+t.amount);
  const cats=[...CATS.filter(c=>c[0]!=="save").map(c=>c[0])].filter(c=>tot[c]);
  if(!lastImport.read){$("importOut").innerHTML="";return;}
  if(!tx.length){$("importOut").innerHTML=`<div class="callout warn">We couldn't find any purchases in that image. Try a clearer screenshot, or the Claude AI option.</div>`;return;}
  $("importOut").innerHTML=`<div class="callout">Found <b>${tx.length} purchases</b> adding up to <b>${fmt(tx.reduce((a,t)=>a+t.amount,0))}</b> (read by ${lastImport.via}). We assume this covers about one month. Check the categories below.</div>
    <table style="margin-top:12px"><thead><tr><th>Category</th><th>This statement</th><th>Your plan</th></tr></thead><tbody>${cats.map(c=>`<tr><td><span class="sw" style="background:var(${(CATS.find(x=>x[0]===c)||[0,0,"--s9"])[2]})"></span>${CATNAME[c]}</td><td>${fmt(tot[c])}</td><td>${R.spend[c]!=null?fmt(R.spend[c]/12):"n/a"}</td></tr>`).join("")}</tbody></table>
    <details><summary>See and fix each purchase (${tx.length})</summary><table>${tx.map((t,i)=>`<tr><td>${esc(t.desc)}</td><td>${fmt(t.amount)}</td><td><select data-tx="${i}" aria-label="Category for ${esc(t.desc)}">${[...CATS.filter(c=>c[0]!=="save").map(c=>c[0])].map(c=>`<option value="${c}"${c===t.cat?" selected":""}>${CATNAME[c]}</option>`).join("")}</select></td></tr>`).join("")}</table></details>
    <button class="btn primary" id="applyImport" style="margin-top:12px">Use these numbers in my budget</button>`;
}
function applyImport(){
  const tot={}; lastImport.tx.forEach(t=>tot[t.cat]=(tot[t.cat]||0)+t.amount);
  NOWCATS.forEach(([k])=>{if(tot[k]) S.now[k]=[Math.round(tot[k]),0];});
  delete S.skip.budget; writeInputs(); dirty=true; render(); toast("Your spending now matches your statement.");
}
async function loadImage(file){
  if(!file||!file.type.startsWith("image/")){toast("Please choose an image file (PNG or JPG).","err");return;}
  if(file.size>15e6){toast("That image is over 15 MB. Try a smaller screenshot.","err");return;}
  const url=URL.createObjectURL(file);
  lastImport={file,url,tx:[],read:false};
  $("imgPrev").innerHTML=`<img src="${url}" alt="Statement you chose">`;
  $("readBtns").style.display="flex"; $("importOut").innerHTML="";
}
function loadScript(src){return new Promise((ok,bad)=>{const s=document.createElement("script");s.src=src;s.onload=ok;s.onerror=()=>bad(new Error("load"));document.head.appendChild(s);});}
async function readLocal(){
  const prog=$("ocrProg"), bar=prog.querySelector("i"); prog.hidden=false; bar.style.transform="scaleX(.05)";
  try{
    if(!window.Tesseract) await loadScript("https://cdn.jsdelivr.net/npm/tesseract.js@5.1.1/dist/tesseract.min.js");
    const res=await Tesseract.recognize(lastImport.file,"eng",{logger:m=>{if(m.progress!=null) bar.style.transform=`scaleX(${m.progress})`;}});
    lastImport.tx=parseStatement(res.data.text); lastImport.via="text reading on this device"; lastImport.read=true;
    renderImport(model().R);
  }catch(e){toast("Couldn't load the text reader. Check your internet connection; everything else still works.","err");}
  finally{prog.hidden=true;}
}
async function claudeClient(){
  if(!APIKEY){toast("Add your Anthropic API key in Help first.","err");openHelp();$("apiKey").focus();return null;}
  try{const {default:Anthropic}=await import("https://cdn.jsdelivr.net/npm/@anthropic-ai/sdk@0.135.0/+esm");
    return {Anthropic,client:new Anthropic({apiKey:APIKEY,dangerouslyAllowBrowser:true})};}
  catch(e){toast("Couldn't reach Anthropic's library. Check your connection; everything else still works.","err");return null;}
}
function claudeError(e,Anthropic){
  if(e instanceof Anthropic.AuthenticationError) return "That API key didn't work. Check it and try again.";
  if(e instanceof Anthropic.RateLimitError) return "Claude is busy or your key hit its limit. Wait a minute and try again.";
  if(e instanceof Anthropic.APIConnectionError) return "Couldn't reach Anthropic. Check your connection; everything else still works.";
  if(e instanceof Anthropic.APIError) return `Claude returned an error (${e.status}). Everything else still works.`;
  return "Something went wrong talking to Claude. Everything else still works.";
}
async function ask(system,content,effort){
  const C=await claudeClient(); if(!C) return null;
  try{
    const msg=await C.client.beta.messages.create({model:"claude-opus-5-5",max_tokens:16000,betas:["server-side-fallback-2026-07-01"],fallbacks:"default",
      output_config:{effort},system,messages:[{role:"user",content}]});
    if(msg.stop_reason==="refusal") return {error:"Claude declined to answer that. Try rewording your question."};
    return {text:msg.content.filter(b=>b.type==="text").map(b=>b.text).join("")};
  }catch(e){return {error:claudeError(e,C.Anthropic)};}
}
async function readAI(){
  const f=lastImport.file;
  if(!confirm(`This sends the image "${f.name}" to Anthropic (the company that makes Claude) so Claude can read the purchases. Nothing else is sent. Continue?`)) return;
  const data=await new Promise(ok=>{const r=new FileReader();r.onload=()=>ok(String(r.result).split(",")[1]);r.readAsDataURL(f);});
  const prog=$("ocrProg"), bar=prog.querySelector("i"); prog.hidden=false; bar.style.transform="scaleX(.5)";
  const res=await ask("You read bank and card statements for a budgeting app. Reply with JSON only.",
    [{type:"image",source:{type:"base64",media_type:f.type,data}},{type:"text",text:`List every purchase or bill payment (money going out) on this statement. Skip deposits, transfers in, balances and totals. Reply with only this JSON: {"transactions":[{"desc":"merchant","amount":12.34,"cat":"housing|food|car|care|health|phone|fun|debt|other"}]}. Categories: housing = rent, mortgage, utilities; food = groceries; car = gas, car payment, car insurance; care = child care; health = medical, pharmacy, health insurance; phone = phone, internet; fun = restaurants, entertainment, subscriptions, shopping; debt = loan or credit card payments.`}],"medium");
  prog.hidden=true;
  if(!res) return; if(res.error){toast(res.error,"err");return;}
  try{
    const j=JSON.parse(res.text.slice(res.text.indexOf("{"),res.text.lastIndexOf("}")+1));
    const ok=new Set([...Object.keys(KEYWORDS),"other"]);
    lastImport.tx=(j.transactions||[]).filter(t=>t&&typeof t.desc==="string"&&isFinite(+t.amount)&&+t.amount>0).map(t=>({desc:t.desc.slice(0,80),amount:Math.abs(+t.amount),cat:ok.has(t.cat)?t.cat:"other"}));
    lastImport.via="Claude AI"; lastImport.read=true; renderImport(model().R);
  }catch{toast("Claude's answer couldn't be read. Try again or use the on device option.","err");}
}

// ---- Help: FAQ and optional Claude chat ----
const FAQ=[
  ["Can a hospital really forgive my bill?","Yes. Nonprofit hospitals, which include most big Kentucky hospitals, must have a financial assistance policy, accept applications for at least 240 days after your first bill, and wait at least 120 days before serious collection steps. Many forgive the whole bill below a set income, often 200% to 400% of the federal poverty line. You have to apply. The hospital bill check (top of the page, or in the Debt step) shows what each hospital's own policy says and writes the letter for you."],
  ["Where do the cost numbers come from?","Rent and utilities come from HUD Fair Market Rents for 2025. Groceries, car, child care, health care and phone costs come from USDA food plans and ALICE cost data for 2024. The Federal Reserve Bank of Atlanta's Policy Rules Database puts them together for every Kentucky county."],
  ["Why does where I work change my taxes?","Kentucky cities and counties charge a small tax on your pay, often called an occupational or payroll tax. It's owed where you do the work, not where you live. That's why the Location step asks for both."],
  ["Why does Louisville charge less if I live outside Jefferson County?","Louisville's rate has three parts: 1.25% for city government, 0.20% for TARC buses, and 0.75% for JCPS schools. People who live outside Jefferson County don't pay the school part, so they pay 1.45% instead of 2.2%."],
  ["What does \"City rate not confirmed\" mean?","Kentucky has 408 cities, and many small ones don't post their wage tax rate online. When we couldn't find a city's rate, we use the county rate and flag it. You can type your exact rate from your pay stub in the Location step."],
  ["What is a 401k match?","Many employers add money to your 401k retirement account when you put money in. A 4% match means if you put in at least 4% of your pay, they add 4% too. It's like a raise you only get if you save."],
  ["Highest interest first or smallest balance first?","Highest interest first (sometimes called the avalanche method) usually costs the least. Smallest balance first (the snowball method) wipes out whole debts sooner, which some people find motivating. The Debt step shows the dollar difference for you."],
  ["What's the difference between conservative, balanced and aggressive?","It's how much is in stocks versus bonds. Conservative is 30% stocks, balanced is 60%, and aggressive is 100%. Stocks have grown more over long periods but go up and down a lot more. Bonds are steadier. This tool doesn't recommend any specific investment."],
  ["Where do the investment returns come from?","Average yearly returns from 1926 to 2022 for the total U.S. stock market and intermediate U.S. bonds, published by Boldin. We subtract about 2.9% average inflation so results are in today's dollars. The past doesn't promise the future."],
  ["How big should my emergency fund be?","A common guideline is 3 to 6 months of your must pay bills: housing, food, car, health care, child care and minimum debt payments. Set your target in the Goals step."],
  ["What is the money health score?","Five checks worth 20 points each: how much you save, how many months your cash covers, how much of your pay goes to debt, how much goes to housing, and how much you put toward retirement. It's a quick gauge, not a credit score."],
  ["What does Skip do?","Skip moves you to the next step and uses typical values for that part of your plan. You can come back anytime; changing anything there turns it back on."],
  ["Is my information sent anywhere?","No. Your plan stays on your device. The only exceptions are things you turn on yourself: if you add your own Anthropic API key and agree each time, your question or chosen statement image goes to Anthropic so Claude can answer."],
  ["How does statement upload work?","Upload a screenshot of a statement. \"Read it on this device\" uses free text reading software that runs in your browser, so the image never leaves your computer. \"Read it with Claude AI\" is more accurate but sends the image to Anthropic, only after you agree. Either way you can fix categories before using the numbers."],
  ["How do I save and reopen my plan?","Press Save plan to download countywise-plan.html, a page you can open in any browser to read your plan. To keep editing later, press Open saved plan and choose that file. Your API key is never saved in it."],
  ["How exact are the numbers?","They're careful estimates. Taxes include federal brackets, the child tax credit, the earned income credit, Social Security and Medicare, Kentucky's 3.5% tax with its family size credit, and your local wage tax. Living costs are typical for your county. Your own pay stub and bills are always the final word."]];
function renderFAQ(q){
  const words=(q||"").toLowerCase().split(/\s+/).filter(Boolean);
  const hits=FAQ.filter(([a,b])=>words.every(w=>(a+" "+b).toLowerCase().includes(w)));
  $("faq").innerHTML=hits.length?hits.map(([a,b])=>`<details><summary>${esc(a)}</summary><p>${esc(b)}</p></details>`).join(""):`<p class="hint">No matching questions. Try other words, or ask Claude below.</p>`;
}
let lastFocus=null;
function openHelp(){lastFocus=document.activeElement;$("drawer").hidden=false;requestAnimationFrame(()=>{$("drawer").classList.add("on");$("scrim").classList.add("on");});$("helpBtn").setAttribute("aria-expanded","true");setTimeout(()=>$("faqSearch").focus(),50);}
function closeHelp(){$("drawer").classList.remove("on");$("scrim").classList.remove("on");$("helpBtn").setAttribute("aria-expanded","false");setTimeout(()=>{$("drawer").hidden=true;},250);if(lastFocus)lastFocus.focus();}
function planSummary(){
  const {E,R,debt,H}=model();
  return `Plan (monthly unless noted): household ${E.adults} adult(s), ${E.under5} kid(s) under 5, ${E.schoolAge} age 5 to 17. Lives in ${place(E.liveCounty,E.liveCity)}, works in ${place(E.workCounty,E.workCity)}, Kentucky. Pay before taxes ${fmt(R.gross/12)}; federal tax ${fmt(R.fed/12)}; Social Security and Medicare ${fmt(R.fica/12)}; Kentucky tax ${fmt(R.ky/12)}; local wage tax ${fmt(R.local/12)} at ${R.localRate.rate}% (${R.localRate.src}); 401k ${E.k401}% with ${E.match}% match; take home ${fmt(R.net/12)}. Spending: `+
    CATS.filter(c=>c[0]!=="save").map(c=>`${c[1]} ${fmt(R.spend[c[0]]/12)}`).join(", ")+`. Left over ${fmt(R.left/12)}. Debts: ${E.debts.map(d=>`${d.name} ${fmt(d.bal)} at ${d.rate}%`).join("; ")||"none"}; debt free in ${debt.stuck?"never at this pace":yrs(debt.months)}. Cash savings ${fmt(E.startCash)}, investments ${fmt(E.startInvest)}. Investment mix ${E.portfolio}. Money health score ${H.score}/100.`;
}
async function askClaude(){
  const q=$("question").value.trim();
  if(!q){toast("Type a question first.","err");return;}
  if(!$("consent").checked){toast("Check the box to agree before anything is sent.","err");return;}
  $("askBtn").disabled=true; $("answer").innerHTML=`<div class="ans">Thinking…</div>`;
  const res=await ask("You are the help assistant inside CountyWise, an educational budgeting web page for Kentucky residents. Answer in plain, everyday language in under 180 words. Use the plan numbers given when relevant. Explain concepts and trade offs; never recommend specific securities, funds or products, and never give personalized investment, tax or legal advice. Suggest a qualified professional for big decisions.",
    [{type:"text",text:planSummary()+"\n\nQuestion: "+q}],"low");
  $("askBtn").disabled=false;
  if(!res){$("answer").innerHTML="";return;}
  $("answer").innerHTML=`<div class="ans">${esc(res.error||res.text)}</div>`;
}

// ---- Printable report ----
// Report styles, shared by Print report and the saved plan file. Light colors always, so it prints and opens the same anywhere.
const RCSS=`.rep{${(document.querySelector("style").textContent.match(/:root\{([\s\S]*?)\n\}/)||["",""])[1]}
  font-family:var(--sans);color:var(--ink);background:var(--bg);max-width:900px;margin:0 auto;padding:24px 16px 40px;line-height:1.45}
.rep .rh{background:linear-gradient(135deg,#0033a0,#001f63);color:#fff;border-radius:18px;padding:22px;display:flex;gap:18px;align-items:center;flex-wrap:wrap}
.rep .rh svg{width:120px;height:auto;flex:none}.rep .rh h1{font-family:var(--serif);font-size:28px;margin:0}.rep .rh p{margin:4px 0 0;color:#d6e0f5;font-size:14px}
.rep .card{background:var(--surface);border:1px solid var(--line);border-radius:16px;padding:18px 20px;margin-top:16px;box-shadow:var(--shadow);break-inside:avoid}
.rep h2{font-family:var(--serif);font-size:21px;margin:0 0 10px}.rep .sub{color:var(--ink2);font-size:14px;margin:0 0 10px}
.rep .goal{border:2px solid #0033a0;background:#f2f5fc}.rep .big{font-family:var(--serif);font-size:23px;font-weight:600;margin:0 0 12px}
.rep .miles{list-style:none;padding:0;margin:0;display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px}
.rep .miles li{background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px 12px}.rep .miles span{display:block;font-size:12px;color:var(--ink3)}.rep .miles b{font-family:var(--serif);font-size:19px}
.rep table{width:100%;border-collapse:collapse;font-size:14px}.rep td,.rep th{padding:7px 8px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
.rep th{font-size:12px;color:var(--ink3);text-transform:uppercase;letter-spacing:.03em}.rep tr.total td{font-weight:700;border-bottom:0}.rep td.why{color:var(--ink3);font-size:13px}
.rep .pos{color:var(--green)}.rep .neg{color:var(--red)}.rep .mid{color:var(--yellow)}
.rep .road{list-style:none;padding:0;margin:8px 0 0}.rep .road>li{position:relative;padding:0 0 14px 26px;border-left:2px solid var(--line);margin-left:8px}
.rep .road>li:last-child{border-left-color:transparent}.rep .road>li::before{content:"";position:absolute;left:-8px;top:2px;width:14px;height:14px;border-radius:50%;background:#fff;border:3px solid #0033a0}
.rep .when{font-size:12px;font-weight:700;color:#0033a0;text-transform:uppercase;letter-spacing:.04em}.rep h3{margin:2px 0 4px;font-size:16px}
.rep ul{margin:4px 0 0;padding-left:18px;color:var(--ink2);font-size:14px}
.rep .rec{border-radius:12px;padding:12px 14px;margin-top:10px;border:1px solid var(--line);border-left-width:5px;break-inside:avoid}
.rep .rec.r{border-left-color:var(--red);background:var(--red-soft)}.rep .rec.y{border-left-color:var(--yellow);background:var(--yellow-soft)}.rep .rec.g{border-left-color:var(--green);background:var(--green-soft)}
.rep .rec p{margin:2px 0 0;font-size:14px;color:var(--ink2)}.rep .tag{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.04em}
.rep .two{display:grid;grid-template-columns:1fr 1fr;gap:20px}@media (max-width:640px){.rep .two{grid-template-columns:1fr}}
.rep svg.chart{width:100%;height:auto;display:block}.rep svg text{fill:var(--ink3);font-size:12px;font-family:var(--sans)}
.rep .nl{fill:var(--ink)!important;font-size:13px!important;font-weight:500}.rep .nv{fill:var(--ink3)}
.rep .foot{font-size:12px;color:var(--ink3);margin-top:18px}`;
document.head.insertAdjacentHTML("beforeend",`<style>${RCSS}</style>`);

// The plan as a readable page: goal, score, roadmap, now vs recommended, next steps, budget and charts
function buildReport(forFile){
  const M=model(), {E,R,T,debt,P,H}=M, G=goalPlan(E,R), recs=recommendations(M), rows=budgetRows(R), M0=DATA.map;
  const logo=`<svg viewBox="-4 -4 ${M0.w+8} ${M0.h+8}" aria-hidden="true">${Object.entries(M0.paths).map(([c,d])=>`<path d="${d}" fill="${c===E.liveCounty?"#ffd166":"#fff"}" stroke="#0033a0" stroke-width="5" stroke-linejoin="round"/>`).join("")}</svg>`;
  const head=`<header class="rh">${logo}<div><h1>Your CountyWise plan</h1><p>${new Date().toLocaleDateString("en-US",{dateStyle:"long"})} · Living in ${esc(place(E.liveCounty,E.liveCity))}, working in ${esc(place(E.workCounty,E.workCity))} · Household of ${E.adults+E.under5+E.schoolAge}</p></div></header>`;
  let body="";
  const BOr=billOutlook();
  if(BOr.has) body+=`<section class="card goal"><div class="when">Your hospital bill</div><p class="big">${esc(BOr.result)}</p><p class="sub">Household of ${BOr.size}, ${fmt(BOr.income)} a year: ${BOr.c.pct}% of the federal poverty line.${BOr.h?` Based on ${esc(BOr.h.name)}'s policy (${esc(BOr.h.date||"ask for current version")}): ${esc(BOr.h.url)}`:""}</p>
    <ol class="road">${BOr.steps.map(s=>`<li><div class="when">${esc(s.w)}</div><h3>${esc(s.t)}</h3><ul>${s.i.map(x=>`<li>${esc(x)}</li>`).join("")}</ul></li>`).join("")}</ol>
    <h2 style="margin-top:14px">Your letter to the hospital</h2><pre style="white-space:pre-wrap;font-family:var(--mono);font-size:13px;background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px">${esc(BOr.letter)}</pre></section>`;
  if(R.gross){
    const O=planOutlook(M), RP=recommendPlan(E,R,T), p=RP.p, n=nowPlan(M), net=R.net/12, SAVE=["debtExtra","cash","invest"];
    body+=`<section class="card goal"><div class="when">Your goal</div><p class="big">${esc(O.head)}</p><ul class="miles">${O.miles.map(([l,v])=>`<li><span>${esc(l)}</span><b>${esc(v)}</b></li>`).join("")}</ul></section>
    <section class="card"><h2>Money health score: ${H.score} / 100, ${scoreWord(H.score).toLowerCase()}</h2><p class="sub">${O.H2.score>H.score?`Follow this plan and it rises to about <b class="pos">${O.H2.score}</b> in 12 months.`:"Follow this plan to keep it there."}</p>
      <table>${H.parts.map(([l,v,t])=>`<tr><td><b>${l}</b><br><span class="sub">${esc(t)}</span></td><td class="${v>=.75?"pos":v>=.4?"mid":"neg"}" style="white-space:nowrap">${Math.round(v*20)} / 20</td></tr>`).join("")}</table></section>
    <section class="card"><h2>Your next 12 months and beyond</h2><p class="sub">Do these in order. Each step builds on the one before it.</p><ol class="road">${O.road.map(s=>`<li><div class="when">${esc(s.w)}</div><h3>${esc(s.t)}</h3><ul>${s.i.map(x=>`<li>${esc(x)}</li>`).join("")}</ul></li>`).join("")}</ol></section>
    <section class="card"><h2>What you do now vs. what we recommend</h2><p class="sub">Monthly. Both columns add up to your take home pay of ${fmt(net)}. Green means more money freed up or saved.</p>
      <table><thead><tr><th>Category</th><th>You now</th><th>Recommended</th><th>Change</th></tr></thead><tbody>${PLANROWS.filter(([k])=>n[k]>=1||p[k]>=1).map(([k,l])=>{const d=p[k]-n[k];return `<tr><td>${l}</td><td>${fmt(n[k])}</td><td><b>${fmt(p[k])}</b></td><td class="${Math.abs(d)<5?"":(d>0)===SAVE.includes(k)?"pos":"neg"}">${Math.abs(d)<5?"same":(d>0?"+":"−")+fmt(Math.abs(d))}</td></tr>`;}).join("")}
      <tr class="total"><td>Take home pay</td><td>${fmt(net)}</td><td>${fmt(net)}</td><td></td></tr></tbody></table></section>
    <section class="card"><h2>Recommendations, most important first</h2><p class="sub">Red: do these first. Yellow: worth doing next. Green: already going well.</p>${recs.map(r=>`<div class="rec ${r.lvl}"><div class="tag ${r.lvl==="r"?"neg":r.lvl==="y"?"mid":"pos"}">${r.lvl==="r"?"Do first":r.lvl==="y"?"Worth doing":"Going well"}</div><b>${esc(r.t)}</b><p>${esc(r.d)}</p>${r.steps&&r.steps.length?`<ul>${r.steps.map(s=>`<li>${esc(s)}</li>`).join("")}</ul>`:""}</div>`).join("")}</section>`;
  }
  body+=`<section class="card"><h2>Your month at a glance</h2><table><tr><td>Pay before taxes</td><td>${fmt(R.gross/12)}</td></tr><tr><td>Taxes (federal, Social Security and Medicare, Kentucky, local ${+R.localRate.rate.toFixed(3)}%)</td><td>${fmt(R.taxes/12)}</td></tr><tr><td>401k (you and your employer)</td><td>${fmt((R.k401Sum+R.matchSum)/12)}</td></tr><tr><td>Take home pay</td><td>${fmt(R.net/12)}</td></tr><tr class="total"><td>Left each month</td><td class="${R.left<0?"neg":"pos"}">${fmt(R.left/12)}</td></tr></table>
    <h2 style="margin-top:16px">Where every dollar goes</h2><svg id="rSankey" class="sankey chart" width="760" height="440"></svg></section>
  <section class="card two"><div><h2>Budget today</h2><table>${rows.map(r=>`<tr><td>${r.l}</td><td>${fmt(r.v/12)}</td><td>${R.net>0?Math.round(r.v/R.net*100):0}%</td></tr>`).join("")}</table></div>
    <div><h2>Goals</h2><table>${G.list.map(g=>`<tr><td>${esc(g.name)}</td><td>${fmt(g.saved)} of ${fmt(g.target)}</td></tr>`).join("")}</table>
    <h2 style="margin-top:16px">Debt</h2><p>${E.debts.some(d=>d.bal>0)?E.debts.filter(d=>d.bal>0).map(d=>`${esc(d.name||"Debt")}: ${fmt(d.bal)} at ${d.rate}%`).join("<br>"):"No debt."}</p></div></section>
  <section class="card"><h2>Your money in ${E.years} years if your habits stay the same (${PORTFOLIOS[E.portfolio]?PORTFOLIOS[E.portfolio].name:"custom"} mix)</h2><svg id="rProj" class="chart" width="760" height="300"></svg><p class="sub">Average ${fmt(P[0].pts[E.years])} · bad markets ${fmt(P[1].pts[E.years])} · good markets ${fmt(P[2].pts[E.years])}, in today's dollars. Following the plan above grows this to about ${R.gross?fmtK(followPlan(E,R,recommendPlan(E,R,T).p,E.years,E.rExp).total):"more"}.</p></section>
  <p class="foot">${forFile?"To change this plan, open CountyWise, press <b>Open saved plan</b> and choose this file. ":""}For learning only, not financial advice. Numbers are estimates built on public data (HUD, USDA, ALICE via the Atlanta Fed Policy Rules Database; IRS; Kentucky Department of Revenue; KACo; Census; Boldin historical returns). Made with CountyWise for the Kentucky PFM Challenge.</p>`;
  if(R.gross){const C=countyOutlook(M), B=benefitsFor(E,R);
    body+=`<section class="card"><h2>Where you live: ${esc(E.liveCounty)} County</h2><ul class="miles">${C.facts.map(([l,v])=>`<li><span>${l}</span><b>${esc(v)}</b></li>`).join("")}</ul>
      <h2 style="margin-top:14px">Best counties for your pay</h2><table>${C.top.map((v,i)=>`<tr><td>${i+1}. ${esc(v.c)} County</td><td>${leftTxt(v.left,C,v.c)}</td></tr>`).join("")}${C.me>=5?`<tr><td>${C.me+1}. ${esc(E.liveCounty)} County (yours)</td><td>your county</td></tr>`:""}</table><p class="sub">Typical costs and local taxes for your household in each county; commute costs not included.</p></section>
      <section class="card"><h2>Help you may qualify for</h2><p class="sub">Household at ${B.pct}% of the 2026 federal poverty line. Estimates from Kentucky's 2026 income limits; each program decides.</p>${B.list.length?`<ul>${B.list.map(b=>`<li><b>${esc(b.name.replace(/about (\d[\d,]*) dollars/,(m,n)=>"about $"+n))}.</b> ${esc(b.why)} ${esc(b.how)}</li>`).join("")}</ul>`:"<p>Above the 2026 limits for most programs.</p>"}</section>`;}
  $("report").innerHTML=`<div class="rep">${head}${body}</div>`;
  drawSankey($("rSankey"),R,null);
  drawLines($("rProj"),null,P.map((p,i)=>({l:p.l,c:p.c,pts:p.pts,thick:i===0})),{H:300,xTick:i=>i===0?"Now":i%(E.years<=10?1:E.years<=20?5:10)===0?"Year "+i:null,xTip:()=>""});
}

// ---- Toasts: pop ups that never move the page ----
let toastTimer=null, base=null;
function toast(html,kind){
  const t=document.createElement("div"); t.className="toast"+(kind==="err"?" err":"");
  t.innerHTML=`<span class="dot ${kind||""}"></span><div>${html}</div>`; $("toasts").appendChild(t);
  while($("toasts").children.length>3) $("toasts").firstChild.remove();
  setTimeout(()=>{t.classList.add("out");setTimeout(()=>t.remove(),200)},kind==="err"?6000:3800);
}
function maybeToast({E,R,P,H}){
  const now={left:R.left/12,fut:P[0].pts[E.years],score:H.score,on:R.gross>0};
  if(!base||!now.on||!base.on){base=now;return;}
  clearTimeout(toastTimer);
  toastTimer=setTimeout(()=>{
    const dl=now.left-base.left, df=now.fut-base.fut, ds=now.score-base.score;
    const extra=(Math.abs(df)>=1000?`<br>${E.years} year outlook ${df>0?"up":"down"} ${fmtK(Math.abs(df))}`:"")+(ds?`<br>Health score ${ds>0?"up":"down"} to ${now.score}`:"");
    if(Math.abs(dl)>=5) toast(`Left each month is now <b>${fmt(now.left)}</b> (${dl>0?"+":"−"}${fmt(Math.abs(dl))})`+extra,dl>0?"up":"down");
    else if(extra) toast(extra.slice(4),df+ds>0?"up":"down");
    base=now;
  },650);
}

// ---- Inputs ----
function unskip(el){const p=el.closest(".panel");if(p){const id=p.id.slice(2);if(S.skip[id]){delete S.skip[id];renderTabs();}}}
document.addEventListener("input",e=>{
  const el=e.target;
  if(el.dataset.k){
    const k=el.dataset.k; let v=el.value;
    if(k==="liveCounty"){if(!v)return; el.querySelector('option[value=""]')?.remove();}
    if(el.hasAttribute("data-money")){const n=+v.replace(/[^\d]/g,"").slice(0,9); el.value=money(n); v=n;} // live commas
    else if(el.hasAttribute("data-num")){v=parseFloat(v);if(!isFinite(v))return; if(el.min!==""&&v<+el.min)v=+el.min; if(el.max!==""&&v>+el.max)v=+el.max;}
    S[k]=v;
    if(k==="workCounty"||k==="workCity") S.workSet=true;
    if(["rLow","rExp","rHigh"].includes(k)) S.portfolio="custom";
    if(k==="liveCounty") S.countySet=true;
    if(k.endsWith("County")) syncCities();
    unskip(el); dirty=true; render(); return;
  }
  if(el.dataset.b){const k=el.dataset.b; let v=el.value;
    if(k==="amt"){v=+v.replace(/[^\d]/g,"").slice(0,8); el.value=money(v);}
    S.bill={...S.bill,[k]:v}; unskip(el); dirty=true; render(); return;}
  if(el.dataset.nowx){
    const n=+el.value.replace(/[^\d]/g,"").slice(0,7); el.value=money(n);
    if(n) S.now[el.dataset.nowx]=[n,0]; else delete S.now[el.dataset.nowx];
    unskip(el); dirty=true; render(); return;
  }
  if(el.dataset.nowr){const k=el.dataset.nowr, i=+el.value, w=nowStep(k,model().R); S.now[k]=i?[(i-1)*w,i*w]:[0,0]; unskip(el); dirty=true; render(); return;}
  const row=el.closest(".rowlist[data-list]");
  if(row&&el.dataset.f){const d=S[row.dataset.list][+row.dataset.i],f=el.dataset.f; d[f]=f==="name"?el.value:Math.max(0,parseFloat(el.value)||0); unskip(el); dirty=true; render();}
  if(el.id==="faqSearch") renderFAQ(el.value);
  if(el.id==="apiKey") APIKEY=el.value.trim();
});
document.addEventListener("change",e=>{
  if(e.target.dataset.tx!=null&&lastImport){lastImport.tx[+e.target.dataset.tx].cat=e.target.value;renderImport(model().R);}
  // Add a debt or goal from the dropdown; numbers start blank
  const id=e.target.id; if((id==="addDebt"||id==="addGoal")&&e.target.value){
    const name=e.target.value.trim(); e.target.value="";
    if(id==="addDebt") S.debts.push({name,bal:0,rate:0,min:0}); else S.goals.push({name,target:0,saved:0});
    unskip(e.target); renderLists(); dirty=true; render();
    const rows=document.querySelectorAll(id==="addDebt"?"#debts .rowlist":"#goals .rowlist"), last=rows[rows.length-1];
    if(last) last.querySelector(name?'[data-f]:not([data-f="name"])':'[data-f="name"]').focus();
  }
});
// Number boxes: scrolling the page never changes them, only typing or the arrows do
document.addEventListener("wheel",e=>{if(e.target.type==="number"&&e.target===document.activeElement) e.target.blur();},{passive:true});
function clearPlan(){S=structuredClone(BLANK);writeInputs();dirty=false;base=null;lastImport=null;$("imgPrev").innerHTML="";$("importOut").innerHTML="";$("readBtns").style.display="none";visited=new Set();showBill(false);go("location");toast("Started a blank plan.");}
document.addEventListener("click",e=>{
  const t=e.target.closest("button"); if(!t) return;
  const panelBtn=!!t.closest(".panel")&&!t.dataset.go&&!t.dataset.skip;
  if(panelBtn) unskip(t);
  if(t.dataset.tab) go(t.dataset.tab);
  else if(t.dataset.go==="billcheck") openBill();
  else if(t.dataset.go) go(t.dataset.go);
  else if(t.dataset.skip){S.skip[t.dataset.skip]=true;dirty=true;const i=TABS.findIndex(x=>x[0]===t.dataset.skip);toast(`Skipped ${TABS[i][1]}. We'll use typical values there.`);go(TABS[i+1][0]);}
  else if(t.id==="billOpen"){const open=$("billBox").hidden; t.dataset.closed=open?"":"1"; showBill(open); if(open) setTimeout(()=>$("billBox").scrollIntoView({behavior:"smooth",block:"start"}),60);}
  else if(t.dataset.ins){S.bill={...S.bill,ins:t.dataset.ins};dirty=true;render();}
  else if(t.id==="copyLetter"){const ta=$("billLetter");(navigator.clipboard?navigator.clipboard.writeText(ta.value):Promise.reject()).then(()=>toast("Letter copied. Paste it into an email or a document."),()=>{ta.select();toast("Select all and copy the letter.");});}
  else if(t.id==="billToDebt"){const O=billOutlook(), bal=O.owe==null?Math.round(O.amt*.5):O.owe, name=`Medical bill (${O.h?O.h.name:"hospital"})`;
    S.debts=S.debts.filter(d=>d.name!==name).concat([{name,bal,rate:0,min:Math.max(25,Math.round(bal/12))}]); delete S.skip.debt; renderLists(); dirty=true; render();
    toast(`Added ${fmt(bal)} to your debts${O.owe==null?" as a placeholder; update it when the hospital tells you the amount":""}, as an interest free 12 month plan.`);}
  else if(t.dataset.adults){S.adults=+t.dataset.adults;dirty=true;render();}
  else if(t.dataset.step){const k=t.dataset.step;S[k]=Math.min(3,Math.max(0,S[k]+ +t.dataset.d));dirty=true;render();}
  else if(t.dataset.port){S.portfolio=t.dataset.port;Object.assign(S,portfolioRates(t.dataset.port));writeInputs();dirty=true;render();}
  else if(t.dataset.s){S.strategy=t.dataset.s;dirty=true;render();}
  else if(t.dataset.pick) pickCounty(t.dataset.pick);
  else if(t.dataset.del!=null){S[t.dataset.list].splice(+t.dataset.del,1);renderLists();dirty=true;render();}
  else if(t.id==="zoomIn"){mapZoom=Math.min(4,mapZoom*2);render();}
  else if(t.id==="zoomOut"){mapZoom=Math.max(1,mapZoom/2);if(mapZoom===1)mapCenter=null;render();}
  else if(t.dataset.zero){S.now[t.dataset.zero]=[0,0];dirty=true;render();}
  else if(t.id==="sameBtn"){S.workCounty=S.liveCounty;S.workCity=S.liveCity;S.workSet=true;writeInputs();dirty=true;render();}
  else if(t.id==="saveBtn"||t.id==="saveEnd") save();
  else if(t.id==="openBtn") $("openFile").click();
  else if(t.id==="printBtn"||t.id==="printEnd"){buildReport();window.print();}
  else if(t.id==="pickImg") $("imgFile").click();
  else if(t.id==="readLocal") readLocal();
  else if(t.id==="readAI") readAI();
  else if(t.id==="applyImport") applyImport();
  else if(t.id==="helpBtn") openHelp();
  else if(t.id==="closeHelp") closeHelp();
  else if(t.id==="menuBtn"){const o=$("actions").classList.toggle("open");t.setAttribute("aria-expanded",String(o));t.textContent=o?"Close menu":"Menu";}
  else if(t.id==="welEx"){$("welcome").close();startExample();}
  else if(t.id==="helpEx"){closeHelp();setTimeout(startExample,260);}
  else if(t.id==="exExit") endExample();
  else if(t.id==="exBtn"){$("actions").classList.remove("open");$("menuBtn").textContent="Menu";parked?endExample():startExample();}
  else if(t.id==="showWelcome"){closeHelp();setTimeout(openWelcome,260);}
  else if(t.id==="askBtn") askClaude();
  else if(t.id==="resetBtn"&&parked){endExample();}
  else if(t.id==="resetBtn"){if(!dirty||confirm("Start over? Your unsaved changes will be lost.")) clearPlan();}
});
$("scrim").onclick=closeHelp;
document.addEventListener("keydown",e=>{
  if(e.key==="Escape"&&$("drawer").classList.contains("on")) closeHelp();
  if(e.key==="Tab"&&$("drawer").classList.contains("on")){ // keep focus inside the open drawer
    const f=[...$("drawer").querySelectorAll("button,input,textarea,summary")].filter(x=>x.offsetParent);
    if(e.shiftKey&&document.activeElement===f[0]){e.preventDefault();f[f.length-1].focus();}
    else if(!e.shiftKey&&document.activeElement===f[f.length-1]){e.preventDefault();f[0].focus();}
  }
});
$("imgFile").onchange=e=>{loadImage(e.target.files[0]);e.target.value="";};
const drop=$("drop");
["dragenter","dragover"].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add("over");}));
["dragleave","drop"].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove("over");}));
drop.addEventListener("drop",e=>loadImage(e.dataTransfer.files[0]));
window.addEventListener("beforeunload",e=>{if(parked?parked.dirty:dirty){e.preventDefault();e.returnValue="";}});
let rz; window.addEventListener("resize",()=>{clearTimeout(rz);rz=setTimeout(render,120)});

// ---- Save and open ----
// Saves one file that reads like a report in any browser and also carries the plan data, so Open saved plan can load it back
// Example mode: the user's own plan is set aside, untouched, and comes back on exit
const EXAMPLE={adults:1,under5:1,schoolAge:1,income1:28000,liveCounty:"Pike",liveCity:"Pikeville",workCounty:"Pike",workCity:"Pikeville",workSet:true,countySet:true,
  now:{housing:[750,0],food:[450,0],car:[400,0],care:[300,0],health:[0,0],phone:[120,0],fun:[150,0],other:[100,0]},
  k401:3,match:3,investShare:20,
  debts:[{name:"Credit card",bal:1800,rate:24,min:60}],startCash:300,goals:[{name:"Car",target:4000,saved:0}],
  bill:{amt:4200,hosp:"pmc",date:"2026-10-01",ins:"none"}};
let parked=null;
function startExample(){
  if(!parked) parked={S:structuredClone(S),dirty,visited:new Set(visited)};
  S=structuredClone({...BLANK,...EXAMPLE}); writeInputs(); dirty=false; base=null; visited=new Set(TABS.map(t=>t[0]));
  $("exBar").hidden=false; $("exBtn").textContent="Exit Example"; go("recommend"); toast("Showing the example. Use Exit Example when you're done.");
}
function endExample(quiet){
  if(!parked) return; S=parked.S; dirty=parked.dirty; visited=parked.visited; parked=null;
  writeInputs(); base=null; $("exBar").hidden=true; $("exBtn").textContent="See an example"; showBill(false); go("location"); if(!quiet) toast("Back to your own plan.");
}
function save(){
  if(parked){toast("You're viewing the example. Use Exit Example, then save your own plan.","err");return;}
  buildReport(true);
  const data=JSON.stringify({app:"countywise",version:4,saved:new Date().toISOString(),state:S}).replace(/</g,"\\u003c");
  const doc=`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>My CountyWise plan</title>
<link rel="icon" href="${$("favicon").href}"><link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Serif:wght@600&display=swap" rel="stylesheet">
<style>body{margin:0;background:#f3f5f9}${RCSS}</style></head><body>${$("report").innerHTML}
<script type="application/json" id="countywise-plan">${data}<\/script></body></html>`;
  const blob=new Blob([doc],{type:"text/html"});
  const a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download="countywise-plan.html";a.click();setTimeout(()=>URL.revokeObjectURL(a.href),1000);
  dirty=false; toast("Saved <b>countywise-plan.html</b>. Open it in any browser to read your plan, or use Open saved plan here to keep editing.");
}
const okList=(arr,fields)=>Array.isArray(arr)&&arr.every(d=>d&&typeof d.name==="string"&&fields.every(f=>typeof d[f]==="number"&&isFinite(d[f])&&d[f]>=0));
function validate(obj){
  if(!obj||!["countywise","bluegrass-budget"].includes(obj.app)||typeof obj.state!=="object"||!obj.state) return "This file isn't a CountyWise plan.";
  const s={...obj.state};
  for(const k in BLANK) if(!(k in s)) s[k]=structuredClone(BLANK[k]); // older files lack newer settings
  for(const k in BLANK){
    if(k==="debts"){if(!okList(s.debts,["bal","rate","min"])) return "The debt list in this file is damaged."; continue;}
    if(k==="goals"){if(!okList(s.goals,["target","saved"])) return "The goal list in this file is damaged."; continue;}
    if(k==="now"){if(typeof s.now!=="object"||!s.now||Array.isArray(s.now)||!Object.entries(s.now).every(([c,v])=>NOWCATS.some(x=>x[0]===c)&&Array.isArray(v)&&v.length===2&&v.every(x=>typeof x==="number"&&isFinite(x)&&x>=0))) return "This file's current spending is damaged."; continue;}
    if(k==="bill"){const b=s.bill; if(!b||typeof b!=="object"||typeof b.amt!=="number"||!isFinite(b.amt)||b.amt<0||typeof b.hosp!=="string"||!/^(\d{4}-\d{2}-\d{2})?$/.test(b.date)||!["none","ins","medicaid"].includes(b.ins)) return "This file's hospital bill details are damaged."; continue;}
    if(k==="skip"){if(typeof s.skip!=="object"||!s.skip||Array.isArray(s.skip)) return "This file's skipped steps are damaged."; continue;}
    if(typeof s[k]!==typeof BLANK[k]||(typeof s[k]==="number"&&!isFinite(s[k]))) return `The value for "${esc(k)}" isn't valid.`;
  }
  for(const [c] of PAIRS) if(!DATA.counties[s[c]]) return `"${esc(s[c])}" isn't a Kentucky county.`;
  if(![1,2].includes(s.adults)||s.under5<0||s.under5>3||s.schoolAge<0||s.schoolAge>3) return "The household size in this file is out of range.";
  if(!(s.portfolio in PORTFOLIOS)&&s.portfolio!=="custom") s.portfolio="custom";
  s.skip=Object.fromEntries(Object.keys(s.skip).filter(k=>TABS.some(t=>t[0]===k)).map(k=>[k,true]));
  return {state:s};
}
$("openFile").onchange=e=>{
  const f=e.target.files[0]; e.target.value=""; if(!f) return;
  if(parked) endExample(true); // opening a file leaves the example first
  if(dirty&&!confirm("Open this plan? Your unsaved changes will be replaced.")) return;
  const rd=new FileReader();
  rd.onload=()=>{
    let obj; try{const t=String(rd.result), m=t.match(/<script type="application\/json" id="countywise-plan">([\s\S]*?)<\/script>/); obj=JSON.parse(m?m[1]:t);}catch{toast("That file couldn't be read. Your current plan was kept.","err");return;}
    const v=validate(obj);
    if(typeof v==="string"){toast(v+" Your current plan was kept.","err");return;}
    S=structuredClone(Object.fromEntries(Object.keys(BLANK).map(k=>[k,v.state[k]])));
    writeInputs(); dirty=false; base=null; render(); toast("Plan opened.");
  };
  rd.onerror=()=>toast("That file couldn't be read. Your current plan was kept.","err");
  rd.readAsText(f);
};

writeInputs(); renderFAQ("");
// Welcome: shown every time the page opens or is refreshed
function openWelcome(){const d=$("welcome"); if(d.showModal&&!d.open) d.showModal(); $("welGo").focus();}
$("welGo").onclick=()=>$("welcome").close();
openWelcome();
// A refresh starts fresh: first step, top of the page, whatever the address bar remembered
if("scrollRestoration" in history) history.scrollRestoration="manual";
renderTabs(); go("location"); window.scrollTo(0,0);
</script>
</body>
</html>

Reaches out to

Websites this page contacts when it runs — fonts, chart libraries, data. Found by reading its source.

  • fonts.googleapis.com
  • fonts.gstatic.com
  • github.com
  • www.census.gov
  • kaco.org
  • help.boldin.com
  • ukhealthcare.uky.edu
  • nortonhealthcare.com
  • www.baptisthealth.com
  • uoflhealth.org
  • www.owensborohealth.org
  • www.commonspirit.org

Licence

Published on Globefin under the MIT License. You may copy, change, and reuse this page, including commercially — just keep the notice below with it.

Copyright © 2026 Kai Sanfilippo. Licensed under the MIT License. Published on Globefin.

Provided as is, without warranty. Any external libraries it loads keep their own licences. Terms →

Sandbox

Scripts run, but the demo has its own throwaway origin. It can't read your session or cookies, can't reach the page around it, and can't navigate your tab. Don't enter real passwords or personal data into any demo.