:root {
  --paper: #f4f2ed;
  --ink: #1d1b18;
  --muted: #66615a;
  --rule: #d8d2c6;
  --soft: #e9e5dc;
  --need: #c8603a;
  --left: #8f2d22;
  --lux: #245a63;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.55;
  font-optical-sizing: auto;
}
a { color: var(--lux); text-underline-offset: 2px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 24px; }
.wrap-wide { max-width: 1040px; margin: 0 auto; padding: 0 24px; }

/* ---------- masthead ---------- */
.masthead { padding: 64px 0 28px; }
.masthead h1 {
  font-size: clamp(2.1rem, 5.2vw, 3.7rem);
  line-height: 1.04;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 18px;
  max-width: 17ch;
}
.dek { font-size: 1.25rem; max-width: 40em; margin: 0 0 14px; color: #34302a; }
.byline { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); margin: 0; max-width: 60em; }

/* ---------- hero ---------- */
.hero { padding-bottom: 40px; border-bottom: 1px solid var(--rule); }
.hero-lede { font-size: 1.35rem; line-height: 1.45; max-width: 36em; margin: 12px 0 22px; }
.c-need { color: #a63d2a; }
.c-future { color: var(--lux); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 6px; margin-bottom: 10px; font-family: var(--sans); }
.legend button {
  font: 500 0.78rem/1 var(--sans);
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; color: var(--ink);
  border: 1px solid transparent; border-radius: 999px;
  padding: 6px 10px 6px 8px; cursor: pointer;
}
.legend button:hover { border-color: var(--rule); }
.legend button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 2px; flex: none; }

.readout { font-family: var(--sans); font-size: 0.85rem; color: var(--muted); min-height: 2.6em; margin: 4px 0 12px; }
.readout strong { color: var(--ink); }
.readout .step { display: inline-block; margin-right: 10px; font-variant-numeric: tabular-nums; color: var(--ink); }
.readout .step + .step::before { content: "→ "; color: var(--muted); }

.budget { display: grid; gap: 14px; }
.strip-row { display: grid; grid-template-columns: 172px 1fr; align-items: center; gap: 14px; }
.strip-head { font-family: var(--sans); font-size: 0.82rem; line-height: 1.25; }
.strip-head strong { display: block; font-weight: 600; }
.strip-head span { color: var(--muted); font-variant-numeric: tabular-nums; }
.strip { display: flex; height: 46px; border-radius: 3px; overflow: hidden; }
.seg {
  flex-grow: 0; flex-shrink: 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  font: 600 0.78rem/1 var(--sans); color: #fff;
  font-variant-numeric: tabular-nums;
  border-right: 1px solid rgba(244, 242, 237, 0.55);
  transition: opacity 0.2s;
}
.seg:last-child { border-right: 0; }
.seg[data-k="health"] span, .seg[data-k="hh"] span, .seg[data-k="ent"] span,
.seg[data-k="cloth"] span, .seg[data-k="other"] span { color: var(--ink); }
.budget.focus .seg { opacity: 0.16; }
.budget.focus .seg.on { opacity: 1; }

/* ---------- chapters ---------- */
.chapter {
  max-width: 1040px; margin: 0 auto; padding: 56px 24px;
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 0 24px;
  border-bottom: 1px solid var(--rule);
}
.num { font: 400 4.2rem/0.9 var(--serif); color: #b8b0a2; padding-top: 4px; }
.body { max-width: 800px; }
.body > p, .body > h2, .globe h3 { max-width: 640px; }
h2 { font-size: clamp(1.55rem, 3vw, 2.1rem); line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 16px; }
h3 { font-size: 1.25rem; font-weight: 600; margin: 0 0 14px; }
p { margin: 0 0 16px; }
.note, .axis-note { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); line-height: 1.5; }
.axis-note { margin-top: 4px; }

figure { margin: 0; }
figcaption { font: 600 0.85rem/1.3 var(--sans); margin-bottom: 10px; }
figcaption em { font-weight: 400; font-style: normal; color: var(--muted); }
.chart { margin: 22px 0 14px; }

details.data { margin: 18px 0 0; font-family: var(--sans); font-size: 0.8rem; }
details.data summary { cursor: pointer; color: var(--muted); }
details.data table { border-collapse: collapse; margin-top: 10px; width: 100%; font-variant-numeric: tabular-nums; }
details.data th, details.data td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--soft); }
details.data th[scope="row"], details.data thead th:first-child { text-align: left; font-weight: 500; }
details.data > div { overflow-x: auto; }

/* ---------- 1: income vs spending ---------- */
.is-key, .d-key { display: flex; gap: 18px; font: 0.78rem var(--sans); color: var(--muted); margin-bottom: 10px; }
.is-key span, .d-key span { display: inline-flex; align-items: center; gap: 6px; }
.sw.inc { background: #c9c1b2; }
.sw.spd { background: var(--need); }
.is-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; margin-bottom: 10px; }
.is-label { font: 500 0.82rem var(--sans); }
.is-bars { display: grid; gap: 3px; }
.bar { height: 18px; position: relative; border-radius: 2px; min-width: 2px; }
.bar.inc { background: #c9c1b2; }
.bar.spd { background: var(--need); }
.bar span {
  position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  font: 500 0.74rem var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* ---------- toggles & filters ---------- */
.toggle, .filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 18px; }
.toggle button, .filters button {
  font: 500 0.8rem/1 var(--sans); color: var(--ink);
  background: transparent; border: 1px solid var(--rule); border-radius: 999px;
  padding: 8px 13px; cursor: pointer;
}
.toggle button[aria-checked="true"], .filters button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* ---------- column charts ---------- */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 8px; }
.cols { display: flex; align-items: flex-end; gap: 5px; height: 190px; padding-top: 20px; }
.cols.short { height: 130px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.colbar { width: 100%; background: #cfc6b6; border-radius: 2px 2px 0 0; transition: height 0.45s cubic-bezier(.2,.7,.2,1); }
.col.hi .colbar { background: var(--need); }
.col.hi:last-child .colbar { background: var(--lux); }
.val { font: 500 0.66rem/1.1 var(--sans); color: var(--muted); margin-bottom: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col.hi .val { color: var(--ink); font-weight: 600; }
.tick { font: 0.68rem/1 var(--sans); color: var(--muted); margin-top: 6px; white-space: nowrap; }

/* ---------- global stats ---------- */
.globe { margin-top: 40px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px 28px; }
.stats > div { border-top: 2px solid var(--ink); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.stats .big { font: 600 1.7rem/1.05 var(--serif); letter-spacing: -0.01em; }
.stats > div > span:last-child { font: 0.84rem/1.45 var(--sans); color: #3c3832; }
.stats cite { display: block; font-style: normal; color: var(--muted); font-size: 0.74rem; margin-top: 6px; }
.stats.three { margin-top: 36px; }

/* ---------- 3: ratio ladder ---------- */
.ratio { margin: 8px 0 12px; }
.r-row { display: grid; grid-template-columns: 200px 1fr; gap: 12px; align-items: center; height: 26px; }
.r-label { font: 0.8rem/1.2 var(--sans); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-track { position: relative; height: 100%; }
.r-head { height: 22px; }
.r-axis { position: absolute; inset: 0; }
.r-axis span { position: absolute; transform: translateX(-50%); font: 0.68rem var(--sans); color: var(--muted); bottom: 2px; }
.r-one, .r-all, .e-zero, .e-one { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--rule); }
.r-one { background: #9d968a; }
.r-all { background: var(--ink); width: 1px; opacity: 0.35; }
.r-bar { position: absolute; top: 7px; height: 12px; border-radius: 2px; background: var(--need); }
.r-row.left .r-bar { background: var(--left); }
.r-row.lux .r-bar { background: var(--lux); }
.r-val { position: absolute; top: 50%; transform: translateY(-50%); font: 600 0.72rem var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums; }
.r-row.ref { border-top: 1px dashed var(--ink); border-bottom: 1px dashed var(--ink); height: 30px; margin: 3px 0; }
.r-row.ref .r-label { font-weight: 700; }
.r-row.ref .r-bar { background: var(--ink); }
.key { display: flex; flex-wrap: wrap; gap: 8px 18px; font: 0.78rem var(--sans); color: var(--muted); margin: 10px 0; }
.key span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 4: elasticity ---------- */
.elast { margin: 18px 0; }
.e-row { display: grid; grid-template-columns: 200px 1fr; gap: 12px; align-items: center; height: 28px; }
.e-head { height: 26px; }
.e-label { font: 0.8rem/1.2 var(--sans); text-align: right; }
.e-track { position: relative; height: 100%; }
.e-zones { position: absolute; inset: 0; }
.e-zones .z { position: absolute; top: 0; bottom: 0; }
.e-zones .z span { position: absolute; bottom: 4px; left: 6px; font: 600 0.7rem var(--sans); text-transform: uppercase; letter-spacing: 0.06em; }
.z.inf span { color: var(--left); }
.z.nec span { color: var(--need); }
.z.lux span { color: var(--lux); }
.e-one { background: #9d968a; }
.e-zero { background: var(--ink); opacity: 0.5; }
.e-bar { position: absolute; top: 8px; height: 12px; border-radius: 2px; background: var(--need); }
.e-row.inf .e-bar { background: var(--left); }
.e-row.lux .e-bar { background: var(--lux); }
.e-row.range .e-bar { background: repeating-linear-gradient(90deg, var(--need) 0 6px, var(--lux) 6px 12px); }
.e-row.cereal .e-label { font-weight: 600; }
.e-val { position: absolute; top: 50%; transform: translateY(-50%); font: 600 0.72rem var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- 5: lines ---------- */
.lines { width: 100%; height: auto; display: block; overflow: visible; }
.lines .grid { stroke: var(--soft); stroke-width: 1; }
.lines .yt { font: 9px var(--sans); fill: var(--muted); text-anchor: end; }
.lines .xt { font: 9px var(--sans); fill: var(--muted); text-anchor: middle; }
.lines .ln { fill: none; stroke-width: 2.4; stroke-linejoin: round; }
.lines .ln.rent, .lines .pt.rent { stroke: var(--need); }
.lines .ln.own, .lines .pt.own { stroke: var(--lux); }
.lines .pt { fill: var(--paper); stroke-width: 1.6; }
.lines .end, .lines .start { font: 600 9.5px var(--sans); }
.lines .end.rent, .lines .start.rent { fill: var(--need); }
.lines .end.own, .lines .start.own { fill: var(--lux); }
#rentown { margin: 0; }

/* ---------- mini column groups ---------- */
#infobars, .cols-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin: 24px 0; }

/* ---------- 7: dumbbells ---------- */
.dumb { margin: 10px 0 8px; }
.d-row { display: grid; grid-template-columns: 220px 1fr; gap: 14px; align-items: center; height: 34px; }
.d-label { font: 0.8rem/1.2 var(--sans); text-align: right; }
.d-track { position: relative; height: 100%; background: linear-gradient(var(--soft), var(--soft)) center / 100% 1px no-repeat; margin-right: 30px; }
.d-line { position: absolute; top: 50%; height: 3px; transform: translateY(-50%); background: #b9b09f; }
.d-row.up .d-line { background: linear-gradient(90deg, var(--need), var(--lux)); }
.d-row.down .d-line { background: linear-gradient(90deg, var(--lux), var(--need)); }
.dot { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); }
.d-key .dot { position: static; transform: none; display: inline-block; }
.dot.lo { background: var(--need); }
.dot.hi { background: var(--lux); }
.dot.mid { background: #b9b09f; width: 8px; height: 8px; }
.d-v { position: absolute; top: 50%; font: 600 0.7rem var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums; }
.d-v.lo { color: #a63d2a; }
.d-v.hi { color: var(--lux); }
.d-row.up .d-v.lo, .d-row.flat .d-v.lo { transform: translate(calc(-100% - 10px), -50%); }
.d-row.up .d-v.hi { transform: translate(10px, -50%); }
.d-row.down .d-v.lo { transform: translate(10px, -50%); }
.d-row.down .d-v.hi { transform: translate(calc(-100% - 10px), -50%); }

/* ---------- takeaways & sources ---------- */
.takeaway .label { font: 600 0.75rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.takeaways { padding-left: 1.2em; margin: 0; max-width: 680px; }
.takeaways li { margin-bottom: 16px; padding-left: 4px; }
.takeaways li::marker { font-weight: 600; }
.sources ul { font: 0.84rem/1.55 var(--sans); padding-left: 1.1em; max-width: 760px; }
.sources li { margin-bottom: 8px; }
.foot { font: 0.78rem var(--sans); color: var(--muted); padding-top: 24px; padding-bottom: 48px; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  body { font-size: 17.5px; }
  .masthead { padding: 36px 0 18px; }
  .wrap, .wrap-wide { padding: 0 18px; }
  .hero-lede { font-size: 1.15rem; }
  .strip-row { grid-template-columns: 1fr; gap: 5px; }
  .strip-head { display: flex; justify-content: space-between; gap: 10px; }
  .strip-head strong { display: inline; }
  .strip { height: 40px; }
  .seg { font-size: 0.7rem; }
  .chapter { grid-template-columns: 1fr; padding: 40px 18px; }
  .num { font-size: 2.6rem; margin-bottom: 6px; }
  .pair, .stats, #infobars, .cols-group { grid-template-columns: 1fr; }
  .stats { gap: 20px; }
  .is-row { grid-template-columns: 1fr; gap: 4px; }
  .is-bars { margin-right: 64px; }
  .r-row, .e-row, .d-row { grid-template-columns: 1fr; gap: 2px; height: auto; margin-bottom: 8px; }
  .r-label, .e-label, .d-label { text-align: left; white-space: normal; }
  .r-track, .e-track { height: 22px; margin-right: 46px; }
  .r-head .r-label, .e-head .e-label { display: none; }
  .r-head .r-track { height: 18px; }
  .e-head .e-track { height: 22px; }
  .r-row.ref { height: auto; padding: 4px 0; }
  .d-track { height: 26px; margin: 0 34px; }
  .cols { height: 160px; gap: 3px; }
  .val { font-size: 0.58rem; }
}

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