/* Stuff, money, value — a reading page with small live models. Phone first. */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d2228;
  --text-dim: #59636f;
  --rule: #d9d4c7;
  --accent: #2357a8;
  --focus: #e0a800;
  /* The page's three colours: money, stuff, prices. */
  --money: #2f6fd0;
  --stuff: #c4561d;
  --price: #13865f;
  --welfare: #7a4fb3;
  --grid: #e6e1d6;
  --ok: #13865f;
  --warn: #b3261e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #242a33;
    --text: #e3e7ec;
    --text-dim: #9aa5b1;
    --rule: #343b46;
    --accent: #7fb0ff;
    --money: #6ea8ff;
    --stuff: #f08a4b;
    --price: #3cc28f;
    --welfare: #b48cf0;
    --grid: #2a3039;
    --ok: #3cc28f;
    --warn: #ff8a80;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1c2027;
  --surface-2: #242a33;
  --text: #e3e7ec;
  --text-dim: #9aa5b1;
  --rule: #343b46;
  --accent: #7fb0ff;
  --money: #6ea8ff;
  --stuff: #f08a4b;
  --price: #3cc28f;
  --welfare: #b48cf0;
  --grid: #2a3039;
  --ok: #3cc28f;
  --warn: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}

main, header.page, footer.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

strong { font-weight: 650; }

/* --- Header ------------------------------------------------------------- */

header.page { padding-top: 28px; }
header.page .eyebrow {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
header.page h1 { font-size: 2rem; line-height: 1.15; margin: 0.2rem 0 0.6rem; }
header.page .lede { font-size: 1.08rem; margin: 0 0 0.9rem; }

.key { margin: 0 0 1rem; color: var(--text-dim); font-size: 0.95rem; }
.key b { font-weight: 650; }
.c-money { color: var(--money); }
.c-stuff { color: var(--stuff); }
.c-price { color: var(--price); }
.c-welfare { color: var(--welfare); }

nav.steps ol {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
nav.steps a, nav.steps span {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.85rem;
  text-decoration: none;
  background: var(--surface);
}
nav.steps span { color: var(--text-dim); border-style: dashed; background: transparent; }

/* --- Steps -------------------------------------------------------------- */

section.step { padding: 1.4rem 0 0.6rem; border-top: 1px solid var(--rule); }
section.step h2 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 0.6rem; }
section.step h2 .num {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
section.step p, section.step li { max-width: 68ch; }
section.step ul { padding-left: 1.2rem; }

/* --- Widgets ------------------------------------------------------------ */

.widget {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 14px 14px 10px;
  margin: 1rem 0 1.1rem;
}

.controls { display: grid; gap: 10px 18px; grid-template-columns: 1fr; margin-bottom: 8px; }
@media (min-width: 620px) { .controls.two { grid-template-columns: 1fr 1fr; } }

.control .lab { font-size: 0.88rem; color: var(--text-dim); }
.slider label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.slider output { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.slider input[type="range"] {
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--accent);
}
.hint { margin: 0; font-size: 0.8rem; color: var(--text-dim); }

.segmented .seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.segmented button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.segmented button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  font-weight: 650;
}

details.world, details.sums {
  margin: 8px 0 4px;
  border-top: 1px dashed var(--rule);
  padding-top: 4px;
}
details.world > summary, details.sums > summary {
  cursor: pointer;
  min-height: 40px;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  color: var(--accent);
}
details.world .controls { margin-top: 6px; }

/* --- Charts ------------------------------------------------------------- */

.chart { margin: 6px 0 4px; }
.chart .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.chart .legend .item { display: inline-flex; align-items: center; gap: 6px; }
.chart .legend svg { flex: none; }
.chart .plot { position: relative; }
.chart .plot svg { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
.chart .axis text { fill: var(--text-dim); font-size: 11.5px; font-family: inherit; }
.chart .axis path, .chart .axis .tick line { stroke: var(--grid); }
.chart .axis.x path { stroke: var(--rule); }
.chart .marker line { stroke: var(--text-dim); stroke-dasharray: 3 3; }
.chart .marker text { fill: var(--text-dim); font-size: 11px; }
.chart .hover line { stroke: var(--text-dim); }
.chart .zero { stroke: var(--text-dim); stroke-opacity: 0.6; }
.chart .tip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.8rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.12);
  white-space: nowrap;
  z-index: 2;
}
.chart .tip b { display: block; margin-bottom: 2px; }
.chart .caption, .changebars .caption { font-size: 0.8rem; color: var(--text-dim); margin: 4px 0 0; }

.changebars { margin: 8px 0 4px; }
.widget-sub { font-size: 1rem; margin: 1.2rem 0 0.2rem; padding-top: 0.8rem; border-top: 1px dashed var(--rule); }
.cb-row {
  display: grid;
  grid-template-columns: minmax(6.5rem, 34%) 1fr 4.6rem;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 0.88rem;
}
.cb-label { color: var(--text); line-height: 1.3; }
.cb-row.selected .cb-label { font-weight: 700; }
.cb-row.selected .cb-label::before { content: "▸ "; color: var(--accent); }
.chart .axis-title { fill: var(--text-dim); font-size: 11.5px; }
table.sums tr.selected td { font-weight: 700; }
table.sums tr.selected td:first-child::before { content: "▸ "; color: var(--accent); }
.cb-track { position: relative; height: 20px; }
.cb-track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -4px;
  bottom: -4px;
  border-left: 1px solid var(--text-dim);
  opacity: 0.6;
}
.cb-bar { position: absolute; top: 2px; bottom: 2px; min-width: 2px; border-radius: 3px; background: var(--bar); }
.cb-bar.outline { background: transparent; border: 2px dashed var(--bar); }
.cb-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }

/* --- Readouts ----------------------------------------------------------- */

.readout { margin: 8px 0 2px; }
.check {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.check .ok { color: var(--ok); font-weight: 650; }
.check .warn { color: var(--warn); font-weight: 650; }

.table-wrap { overflow-x: auto; margin: 6px 0; }
table.sums {
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}
table.sums th, table.sums td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.sums th:first-child, table.sums td:first-child { text-align: left; }
table.sums thead th { color: var(--text-dim); font-weight: 600; }
table.sums.wrap-head thead th { white-space: normal; vertical-align: bottom; min-width: 4.5rem; }
table.sums tfoot td { font-weight: 650; }
.sums select { font: inherit; min-height: 40px; padding: 4px 8px; border-radius: 8px; }

/* --- Coming next, footer, errors ---------------------------------------- */

.coming ol { padding-left: 1.4rem; color: var(--text-dim); }

footer.page {
  border-top: 1px solid var(--rule);
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  padding-bottom: 2rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.load-error {
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

/* --- Step 6: the demand curve ------------------------------------------- */

.demand .area { fill: var(--welfare); fill-opacity: 0.28; }
.demand .curve { fill: none; stroke: var(--welfare); stroke-width: 2.5; }
.demand .rect { fill: none; stroke-width: 1.5; stroke-dasharray: 5 4; }
.demand .rect.small { stroke: var(--text-dim); }
.demand .rect.big { stroke: var(--stuff); }
.demand .note { fill: var(--text-dim); font-size: 11px; }
