/* The maths book's additions to the Making Software frame (base.css).
   Equations are native MathML. Every symbol carries a colour and a data-s name; the plain-English sentence under
   the equation and the symbol key use the same colours and names, and hovering any one lights up all of them. */

:root {
  /* symbol colours: blue = the model, ochre = her words, green = a count or a step, plum = the maths machinery */
  --s-model: #293edb;
  --s-her:   #8a6a00;
  --s-step:  #23774a;
  --s-math:  #8a3b8f;
  --her-wash: #fbf0bf;
  --her:      #f5d85c;
  --model-wash: #eceefc;
  --orange:  #a0572a;
  --math-font: "STIX Two Math", "Latin Modern Math", "Cambria Math", ui-serif, serif;
}

/* ── Equations ───────────────────────────────────────────────────────── */
math { font-family: var(--math-font); }
.sheet p math, .sheet li math { font-size: 15px; }
figure.eq { margin: 32px 0 0; text-align: center; }
figure.eq math[display="block"] { font-size: 19px; margin: 0 auto; }
.s-model { color: var(--s-model); }
.s-her   { color: var(--s-her); }
.s-step  { color: var(--s-step); }
.s-math  { color: var(--s-math); }
[data-s] { border-radius: 2px; transition: background-color 150ms; }
[data-s].lit { background: var(--highlight); }

/* the sentence that reads the equation aloud */
.sheet p.say {
  margin: 16px auto 0; max-width: 520px; text-align: center; text-wrap: balance;
  font-size: 14px; line-height: 24px; color: var(--ink);
}
.say [data-s] { font-weight: 500; }

/* the symbol key: symbol · how to say it · what it means */
.key {
  margin: 24px 0 0; padding: 12px 0 0; border-top: 1px solid var(--rule);
  display: grid; grid-template-columns: 56px 128px minmax(0, 1fr); gap: 6px 16px; align-items: baseline;
}
.key > .k-sym { text-align: center; font-size: 17px; }
.key > .k-sym math { font-size: 17px; }
.key > .k-say { font: 400 10px/16px var(--mono); text-transform: uppercase; color: var(--ink-muted); }
.key > .k-mean { font-size: 12px; line-height: 20px; color: rgb(0 0 0 / 0.75); }
.key > .k-head { font: 400 10px/16px var(--mono); text-transform: uppercase; color: #000; }
@media (max-width: 639px) {
  .key { grid-template-columns: 44px minmax(0, 1fr); }
  .key > .k-say { display: none; }
}

/* a derivation: numbered lines, maths on the left, the reason on the right */
ol.derive { list-style: none; counter-reset: d; margin: 32px 0 0 !important; padding: 0 !important; }
ol.derive > li {
  counter-increment: d; margin: 0 !important; padding: 14px 0 !important;
  display: grid; grid-template-columns: 28px minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: center;
  border-top: 1px solid var(--rule);
}
ol.derive > li:last-child { border-bottom: 1px solid var(--rule); }
ol.derive > li::before { content: counter(d); font: 400 10px var(--mono); color: var(--ink-muted); }
ol.derive .m { text-align: left; font-size: 17px; overflow-x: auto; overflow-y: hidden; padding: 2px 0; scrollbar-width: none; }
ol.derive .m math { font-size: 17px; }
ol.derive .why { font-size: 12px; line-height: 20px; text-align: left; color: rgb(0 0 0 / 0.75); }
ol.derive > li.result .m { font-size: 19px; }
ol.derive > li.result { background: linear-gradient(90deg, var(--her-wash), transparent 70%); }
@media (max-width: 639px) {
  ol.derive > li { grid-template-columns: 20px minmax(0, 1fr); }
  ol.derive .why { grid-column: 2; }
}

/* small mono kicker before a paragraph: IN HER RUN */
.sheet p.kicker {
  margin-top: 32px; text-align: left;
  font: 400 10px/16px var(--mono); text-transform: uppercase; color: var(--ink-muted);
}
.sheet p.kicker + p { margin-top: 8px; }

/* numbers set in a table, as the original sets its few tables */
table.nums { width: 100%; margin-top: 24px; border-collapse: collapse; font: 400 11px/18px var(--mono); }
table.nums th {
  text-align: right; font-weight: 400; font-size: 10px; text-transform: uppercase; color: var(--ink-muted);
  border-bottom: 1px solid #000; padding: 4px 0 4px 12px;
}
table.nums td { text-align: right; padding: 5px 0 5px 12px; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
table.nums th:first-child, table.nums td:first-child { text-align: left; padding-left: 0; }
table.nums tr.total td { border-bottom: 1px solid #000; border-top: 1px solid #000; font-weight: 500; }
table.nums td.hi { color: var(--s-model); }
table.nums td.her { background: var(--her-wash); }

/* ── Diagram images ──────────────────────────────────────────────────── */
figure.img { padding: 0 16px; }
figure.img img { display: block; margin: 0 auto; max-width: 100%; height: auto; }
@media (max-width: 767px) {
  /* scale diagrams to fit down to 560 px wide; below that (phones) keep them legible and let them scroll sideways */
  figure.img { overflow-x: auto; scrollbar-width: thin; }
  figure.img img { max-width: none; width: max(100%, 560px); }
}

/* ── Interactive widgets ─────────────────────────────────────────────── */
.widget { padding: 0 16px; outline: none; }
.widget .controls {
  margin-top: 12px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 20px;
  font: 400 10px/16px var(--mono); text-transform: uppercase; color: #000;
}
.widget .controls label { display: inline-flex; align-items: center; gap: 8px; }
.widget input[type="range"] { width: 180px; accent-color: var(--accent); }
.widget .controls button { text-transform: uppercase; }
.widget .controls button:hover { color: var(--accent); }
.widget .controls button.on { color: var(--accent); text-decoration: underline 1px; text-underline-offset: 3px; }
.widget .readout { font: 400 10px/16px var(--mono); text-transform: uppercase; text-align: center; margin-top: 8px; }
.widget .readout b { font-weight: 500; color: var(--accent); font-variant-numeric: tabular-nums; }
.widget svg { display: block; margin: 0 auto; max-width: 100%; height: auto; overflow: visible; }
.widget svg text { font: 400 10px var(--mono); text-transform: uppercase; }
.widget .note { font: 400 10px/16px var(--mono); text-transform: uppercase; text-align: center; color: var(--orange); margin-top: 4px; }

/* the token strip */
.toks { display: flex; flex-wrap: wrap; gap: 3px; justify-content: flex-start; padding: 8px 0; }
.tok {
  font: 400 11px/20px var(--mono); padding: 0 4px; white-space: pre;
  border: 1px solid var(--rule); color: rgb(0 0 0 / 0.35); background: #fff;
  transition: background-color 200ms, color 200ms, border-color 200ms;
}
.tok.special { font-size: 9px; letter-spacing: 0.2px; }
.tok.her.target   { background: var(--her); color: #000; border-color: #000; }
.tok.user.target  { background: var(--model-wash); color: #000; border-color: var(--s-model); }
.tok.nl::after { content: "↵"; }
.toks .brk { flex-basis: 100%; height: 4px; }
.tok-legend { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; font: 400 10px/16px var(--mono); text-transform: uppercase; margin-top: 4px; }
.tok-legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--rule); }
.tok-legend .l-her::before { background: var(--her); border-color: #000; }
.tok-legend .l-user::before { background: var(--model-wash); border-color: var(--s-model); }

/* ── Index ───────────────────────────────────────────────────────────── */
.toc .soon { color: var(--ink-muted); }
.toc .soon a { color: var(--ink-muted); text-decoration: none; font-weight: 400; pointer-events: none; }

/* Shared fixes requested by chapter authors (2026-10-19) */
figure.eq { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }   /* a wide equation never widens the page */
.key > .k-sym.k-word, .key > .k-sym.k-word math { font-size: 12px; }        /* whole-word symbols (RMSNorm) in keys */
.widget i.m, .readout i.m, .controls i.m { text-transform: none; font-family: var(--math-font); font-style: italic; }  /* maths inside uppercase readouts */
.lc { text-transform: none; }  /* keep η, β, ε lowercase inside uppercase mono labels and readouts */
figure.eq mtd { text-align: left; }  /* MathML Core ignores columnalign; keeps piecewise and stacked equations aligned */
@media (max-width: 639px) {
  /* wide widget drawings (those with an explicit width) stay legible on phones and scroll sideways in their own box */
  .widget { overflow-x: auto; scrollbar-width: thin; }
  .widget svg[width] { min-width: 560px; }
}
@media (max-width: 639px) {
  table.nums { display: block; overflow-x: auto; scrollbar-width: thin; }  /* wide tables scroll in place on phones */
}

/* Further reading, shared by chapters 7–9 (2026-10-23) */
.sheet ol.refs { margin-top: 16px; padding-left: 0; list-style: none; counter-reset: r; }
.sheet ol.refs > li { counter-increment: r; position: relative; padding-left: 28px; margin-top: 16px; font-size: 14px; line-height: 22px; text-align: left; overflow-wrap: anywhere; }
.sheet ol.refs > li::before { content: counter(r); position: absolute; left: 0; top: 2px; font: 400 10px var(--mono); color: var(--ink-muted); }
.sheet ol.refs .use, .sheet ol.refs .uses { display: block; margin-top: 4px; font-size: 13px; line-height: 20px; color: rgb(0 0 0 / 0.7); }
.sheet ol.refs > li:target { background: var(--highlight); }
.sheet a.cite { white-space: nowrap; }
