/* style.css — every style of the site (spec/SPEC.md §10). OWNED BY T01.
 * White background only: no dark mode. */

:root {
  color-scheme: light;
  --bg: #FFFFFF;  --ink: #1B1D20;  --muted: #6A6F75;  --line: #DADDE0;  --soft: #F5F6F7;
  --accent: #1F6FB2;                 /* links, figure titles, SOP */
  --sav: #2E7D4F;                    /* saving / supply of funds (S) */
  --dem: #B23A48;                    /* demand for funds / borrowers (D) */
  --money: #D9822B;                  /* new money, credit without saving, unsustainable */
  --sop: #1F6FB2;
  --f-text: "Source Serif 4", Georgia, serif;
  --f-ui: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 18px/1.6 var(--f-text); }

/* ---------- focus (SPEC §10.4, §11) ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- page (§10.3) ---------- */
.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
}
.part {
  font: 600 13px/1.4 var(--f-ui);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin: 40px 0 0;
}
h1 {
  font-family: var(--f-text);
  font-weight: 600;
  font-size: clamp(28px, 5vw, 40px);
  line-height: 1.15;
  margin: 8px 0 16px;
}
h2 { font-family: var(--f-text); font-weight: 600; font-size: 24px; margin: 48px 0 12px; }
h3 {
  font-family: var(--f-ui);
  font-weight: 600;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 28px 0 8px;
}
p { margin: 0 0 18px; }
.lead { font-size: 21px; color: var(--ink); line-height: 1.5; }
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ---------- site header / pager / footer (SPEC §9) ---------- */
#site-header {
  height: 52px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  font: 15px/1.2 var(--f-ui);
}
#site-header a { color: var(--ink); text-decoration: none; font-weight: 600; }
#site-header a:hover, #site-header a:focus-visible { color: var(--accent); }
#site-header .toc { position: relative; }
#site-header .toc summary { cursor: pointer; color: var(--accent); }
#site-header .toc ol {
  position: absolute;
  right: 0;
  z-index: 10;
  list-style: none;
  margin: 6px 0 0;
  padding: 10px 14px;
  min-width: 230px;
  max-height: 70vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
}
#site-header .toc a { display: block; padding: 4px 0; font-weight: 400; }
#site-header .toc a[aria-current="page"] { color: var(--accent); font-weight: 600; }
#pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font: 15px/1.4 var(--f-ui);
}
#pager a { text-decoration: none; }
#pager a:hover, #pager a:focus-visible { text-decoration: underline; }
#pager .pager-next { margin-left: auto; text-align: right; }
#site-footer {
  margin-top: 24px;
  padding-top: 16px;
  padding-bottom: 32px;
  border-top: 1px solid var(--line);
  font: 13px/1.5 var(--f-ui);
  color: var(--muted);
}

/* ---------- home lists (used by T02 / T04) ---------- */
.chapters { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 32px 0; }
.chapters a { display: block; height: 100%; box-sizing: border-box; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); }
.chapters a:hover, .chapters a:focus-visible { border-color: var(--accent); }
.chapters .ch-part { display: block; font: 600 12px/1.4 var(--f-ui); text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.chapters .ch-title { display: block; font: 600 17px/1.3 var(--f-text); margin-top: 4px; }
.allnighter { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 24px 0; }
.allnighter li { border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 15px/1.4 var(--f-ui); }
.allnighter time { display: block; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.allnighter .tag { display: block; margin-top: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
@media (max-width: 640px) { .allnighter { grid-template-columns: repeat(2, 1fr); } }

/* ---------- figures and widgets (§10.4) ---------- */
.fig { margin: 40px 0; padding-top: 16px; border-top: 1px solid var(--line); }
.fig-title { font: 600 16px/1.4 var(--f-ui); margin: 0; }
.fig-num { color: var(--accent); margin-right: 8px; }
.stage { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0; }
.stage svg { display: block; width: 100%; min-width: 560px; height: auto; fill: var(--ink); }
.stage svg text { font-family: var(--f-ui); }
.step-caption { font: 16px/1.5 var(--f-ui); min-height: 3.2em; margin: 8px 0; }
.step-n { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin-right: 8px; }
.controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ctl {
  font: 14px/1 var(--f-ui);
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #FFFFFF;
  color: var(--ink);
  cursor: pointer;
}
.ctl:hover { border-color: var(--accent); }
.ctl.is-current { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctl:disabled { opacity: .35; cursor: default; border-color: var(--line); }
.ctl.play { margin-left: 6px; }
.fig-source { font: 13px/1.4 var(--f-ui); color: var(--muted); }
.widget-controls { font-family: var(--f-ui); display: grid; grid-template-columns: 1fr; gap: 10px; margin: 12px 0; }
.widget-controls label { font-size: 15px; }
.widget-controls input[type="range"] { width: 100%; accent-color: var(--accent); }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 0; }
.readouts > div { background: var(--soft); padding: 10px 12px; border-radius: 6px; }
.readouts dt { font: 12px/1.4 var(--f-ui); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.readouts dd { margin: 0; font: 600 22px/1.3 var(--f-ui); font-variant-numeric: tabular-nums; }

/* ---------- text blocks (§10.5) ---------- */
.takeaways { background: var(--soft); border-left: 3px solid var(--accent); padding: 16px 20px; margin: 40px 0; }
.takeaways h2 { margin: 0; font-size: 18px; }
.takeaways ul { margin: 8px 0 0; padding-left: 20px; }
.takeaways li { margin: 6px 0; }
.contrast { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 32px 0; }
.contrast > div { border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
.contrast > div:last-child { border-top: 3px solid var(--accent); }
.contrast h3 { margin-top: 0; }
.contrast p:last-child { margin-bottom: 0; }
.note { border-left: 3px solid var(--line); padding-left: 16px; color: var(--muted); font-size: 16px; }
.table-wrap { overflow-x: auto; margin: 24px 0; }
table.data { font-family: var(--f-ui); font-size: 15px; border-collapse: collapse; width: 100%; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { font-weight: 600; }
table.data td:nth-child(n+2), table.data th:nth-child(n+2),
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
blockquote { font: italic 19px/1.6 var(--f-text); border-left: 3px solid var(--accent); padding-left: 16px; margin: 32px 0; }
blockquote p:last-child { margin-bottom: 0; }
blockquote cite { display: block; margin-top: 8px; font: normal 14px/1.4 var(--f-ui); color: var(--muted); }
.formula { font: 18px/1.5 var(--f-ui); text-align: center; background: var(--soft); padding: 12px; border-radius: 6px; overflow-x: auto; margin: 24px 0; }

/* ---------- only mode for screenshots (§10.6) ---------- */
body.only-mode #site-header, body.only-mode #pager, body.only-mode #site-footer,
body.only-mode main > *:not(.is-only) { display: none !important; }
body.only-mode main { padding-top: 16px; }
body.only-mode .fig.is-only { border-top: 0; margin: 0; }

/* ---------- responsive (§10.7) ---------- */
@media (max-width: 640px) {
  .contrast { grid-template-columns: 1fr; }
}

/* T15: figuras en el celular (mobile.js + data/mobile-crops.js) */
@media (max-width: 600px) {
  .stage.is-cropped { position: relative; overflow: hidden; margin-left: -16px; margin-right: -16px; }
  .stage.is-cropped > svg[data-fig] {
    position: absolute; left: 0; top: 0; width: 800px; min-width: 0;
    opacity: 0; pointer-events: none;
  }
  .stage.is-cropped > svg.crop {
    display: block; width: 100%; min-width: 0; height: auto; margin: 0 auto 8px;
  }
}

