/* Earth Economy — shared styles. Every page uses these tokens. */
:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #fcfcfb;
  --surface-2: #f0efe9;
  --border: #e2e0d8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7973;
  --accent: #b3261e;          /* masthead rule / highlights (ET-style red) */
  --link: #1c5cab;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab; --seq-5: #0d366b;
  --div-neg: #e34948; --div-mid: #d9d8d2; --div-pos: #2a78d6;
  --grid: #e8e6df;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #ef5a50; --link: #6da7ec;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-1: #184f95; --seq-2: #256abf; --seq-3: #3987e5; --seq-4: #6da7ec; --seq-5: #b7d3f6;
    --div-neg: #e66767; --div-mid: #4a4a46; --div-pos: #3987e5;
    --grid: #2c2c29; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #ef5a50; --link: #6da7ec;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-1: #184f95; --seq-2: #256abf; --seq-3: #3987e5; --seq-4: #6da7ec; --seq-5: #b7d3f6;
  --div-neg: #e66767; --div-mid: #4a4a46; --div-pos: #3987e5;
  --grid: #2c2c29; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); }
a { color: var(--link); }
img { max-width: 100%; }

/* ---------- masthead + nav ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; height: 52px; }
.brand { font: 700 17px/1 var(--serif); color: var(--text); text-decoration: none; white-space: nowrap; }
.brand b { color: var(--accent); }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--text-2); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--text-2); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 13px; }

/* ---------- page header ---------- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.page-head { padding: 40px 0 20px; border-bottom: 3px double var(--border); margin-bottom: 28px; }
.kicker { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 700; color: var(--accent); margin: 0 0 8px; }
h1 { font: 700 clamp(28px, 4.5vw, 44px)/1.12 var(--serif); margin: 0 0 12px; letter-spacing: -.01em; }
.dek { font: 400 19px/1.5 var(--serif); color: var(--text-2); max-width: 820px; margin: 0; }
h2 { font: 700 26px/1.2 var(--serif); margin: 48px 0 6px; }
h3 { font: 600 17px/1.3 var(--font); margin: 0 0 4px; }
.section-dek { color: var(--text-2); max-width: 820px; margin: 0 0 18px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 20px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .v { font: 700 28px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.tile .l { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.tile .s { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---------- chart cards ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.card { grid-column: span 12; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 12px; box-shadow: var(--shadow); min-width: 0; }
.card.half { grid-column: span 6; }
.card.third { grid-column: span 4; }
.card.two-third { grid-column: span 8; }
@media (max-width: 900px) { .card.half, .card.third, .card.two-third { grid-column: span 12; } }
.card .sub { color: var(--text-2); font-size: 14px; margin: 0 0 10px; }
.chart { width: 100%; height: 420px; }
.chart.tall { height: 620px; }
.chart.short { height: 300px; }
.card .src { font-size: 12px; color: var(--text-3); margin: 8px 0 0; }
.card-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 10px; }
.card-tools select, .card-tools input, .card-tools button {
  font: inherit; font-size: 13px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
.card-tools button.on { background: var(--text); color: var(--surface); }
.tbl-toggle { font-size: 12px; color: var(--link); background: none; border: 0; cursor: pointer; padding: 0; margin-top: 6px; }

/* ---------- writer's notes (the knowledge layer) ---------- */
.notes { background: var(--surface-2); border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; padding: 14px 18px; margin: 16px 0; }
.notes h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.notes ul { margin: 0; padding-left: 18px; }
.notes li { margin: 4px 0; }
.notes.caveat { border-left-color: var(--s4); }
.notes.caveat h4 { color: var(--text-2); }
.explainer { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px 18px; margin: 16px 0; font-size: 15px; }
.explainer b { font-family: var(--serif); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; cursor: pointer; user-select: none; }
table.data td.n, table.data th.n { text-align: right; }
table.data tr:hover td { background: var(--surface-2); }

/* ---------- hub cards (index) ---------- */
.hub { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.hub a { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.hub a:hover { border-color: var(--accent); }
.hub a .t { font: 700 18px/1.2 var(--serif); }
.hub a .d { font-size: 14px; color: var(--text-2); margin-top: 6px; }

footer { margin-top: 64px; padding: 24px 0 40px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 13px; }

/* ---------- phone + small tablet ---------- */
.card-tools label { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.card-tools select, .card-tools input { max-width: 100%; min-width: 0; }
.nav-wrap { position: relative; flex: 1; min-width: 0; display: flex; }
@media (max-width: 640px) {
  .topbar .inner { flex-wrap: wrap; height: auto; gap: 0 12px; padding: 0 12px; }
  .brand { flex: 1; padding: 12px 0 8px; }
  .theme-btn { min-height: 32px; }
  .nav-wrap { order: 3; flex-basis: 100%; margin: 0 -12px; }
  .nav-wrap::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 28px; pointer-events: none;
    background: linear-gradient(to right, transparent, var(--surface)); }
  .nav { padding: 0 24px 4px 6px; }
  .nav a { padding: 8px 10px; }
  .page-head { padding: 24px 0 16px; margin-bottom: 20px; }
  .dek { font-size: 17px; }
  h2 { font-size: 22px; margin-top: 36px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .v { font-size: 22px; overflow-wrap: anywhere; }
  .tile .l { font-size: 12.5px; }
  .grid { gap: 12px; }
  .card { padding: 14px 12px 10px; }
  .chart { height: 360px; }
  .chart.short { height: 260px; }
  .card-tools { gap: 6px 10px; }
  .card-tools label { flex: 1 1 100%; }
  .card-tools label select, .card-tools label input { flex: 1; }
  /* 16px stops iOS from zooming the page when a field is focused */
  .card-tools select, .card-tools input, .card-tools button, input, select { font-size: 16px; min-height: 36px; }
  .tbl-toggle { padding: 8px 0; font-size: 13px; }
  .notes, .explainer { padding: 12px 14px; }
  .hub { grid-template-columns: 1fr; }
}
.ctl label { max-width: 100%; }
.ctl select, .ctl input { min-width: 0; max-width: 100%; }
@media (max-width: 640px) {
  .ctl label { flex: 1 1 100%; }
  .ctl label select, .ctl label input { flex: 1; font-size: 16px; min-height: 36px; }
}
.card-tools.chips button { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; cursor: pointer; }
.card-tools.chips button.x::after { content: " ×"; opacity: .6; }
@media (max-width: 640px) { .card-tools.chips button { font-size: 13px; min-height: 32px; } }
