/* The palette is the package's: the README banner's navy runs and red centre runs on warm paper.
   Every text colour meets WCAG AA (4.5:1) on both the page and a panel, in both themes. */
:root {
  --bg: #faf8f3;
  --fg: #1d1d1f;
  --muted: #5f6368;
  --line: #dcd8ce;
  --panel: #ffffff;
  --accent: #2c5f7c;
  --accent-fg: #ffffff;
  --error: #b3261e;
  --warn: #a35f00;
  --ok: #1e7b3a;
  --mark-run: #2c5f7c;
  --mark-centre: #a93226;
  --mark-edge: #a6a49e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --fg: #e8e8e6;
    --muted: #a0a4a8;
    --line: #34373b;
    --panel: #1c1e21;
    --accent: #7fb0ea;
    --accent-fg: #0d1b2a;
    --error: #f2877f;
    --warn: #e2a95a;
    --ok: #7fd49a;
    --mark-run: #8db8d6;
    --mark-centre: #f0907f;
    --mark-edge: #5b5f66;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141517;
  --fg: #e8e8e6;
  --muted: #a0a4a8;
  --line: #34373b;
  --panel: #1c1e21;
  --accent: #7fb0ea;
  --accent-fg: #0d1b2a;
  --error: #f2877f;
  --warn: #e2a95a;
  --ok: #7fd49a;
  --mark-run: #8db8d6;
  --mark-centre: #f0907f;
  --mark-edge: #5b5f66;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }
h1 {
  margin: 0; font: 700 2.3rem/1 "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia,
    "DejaVu Serif", serif;
  letter-spacing: -0.01em;
}
/* The name beside the mark, as the package's social card sets its own: a bold serif, a quiet tagline. */
.brand { display: flex; align-items: center; gap: 14px; margin: 0 0 12px; }
.mark { flex: none; width: 58px; height: 58px; }
.mark__edges { fill: none; stroke: var(--mark-edge); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mark__runs circle, .mark__centre { stroke: var(--bg); stroke-width: 1.6; }
.mark__runs circle { fill: var(--mark-run); }
.mark__centre { fill: var(--mark-centre); }
.tagline {
  margin: 6px 0 0; color: var(--muted); font-style: italic;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "DejaVu Serif", serif;
}
h2 { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 20px 0 8px; }
a { color: var(--accent); }
.lede { color: var(--muted); margin: 0 0 12px; }
.step {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg); font-size: 0.95rem;
}
section {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px; margin: 20px 0;
}
/* The status box: a changing message, kept visually apart from the page text.
   data-state picks the icon and the accent: busy (spinner), ok (tick), error. */
.status {
  display: flex; align-items: center; gap: 10px; margin: 16px 0 0; padding: 10px 14px;
  border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px;
  background: var(--panel); color: var(--fg); font-size: 0.92rem;
}
.status__icon { flex: none; width: 18px; height: 18px; display: grid; place-items: center; font-weight: 700; }
.status[data-state="busy"] { border-left-color: var(--accent); }
/* While Python works, the mark's runs light up in a random run order, then clear in the same order. */
.status__icon svg { display: none; width: 18px; height: 18px; }
.status[data-state="busy"] .status__icon svg { display: block; }
.status__icon circle { fill: var(--mark-run); opacity: 0.15; animation: run-order 2.4s infinite; }
.status__icon circle:last-child { fill: var(--mark-centre); }
.status__icon circle:nth-child(1) { animation-delay: 0.45s; }
.status__icon circle:nth-child(2) { animation-delay: 0s; }
.status__icon circle:nth-child(3) { animation-delay: 0.75s; }
.status__icon circle:nth-child(4) { animation-delay: 0.3s; }
.status__icon circle:nth-child(5) { animation-delay: 0.9s; }
.status__icon circle:nth-child(6) { animation-delay: 0.15s; }
.status__icon circle:nth-child(7) { animation-delay: 0.6s; }
@keyframes run-order {
  0% { opacity: 0.15; }
  8%, 60% { opacity: 1; }
  75%, 100% { opacity: 0.15; }
}
.status[data-state="ok"] { border-left-color: var(--ok); }
.status[data-state="ok"] .status__icon::before { content: "✓"; color: var(--ok); }
.status[data-state="error"] { border-left-color: var(--error); color: var(--error); }
.status[data-state="error"] .status__icon::before { content: "!"; color: var(--error); }
@media (prefers-reduced-motion: reduce) {
  .status__icon circle { animation: none; opacity: 1; }
}
.error { color: var(--error); }
.hint { color: var(--muted); font-size: 0.92rem; }
.hint.error { color: var(--error); }
/* What the generated design is (resolution, aliasing, a raised run count), and what an
   analysis could not estimate. Warnings from the library are set apart by a rule. */
.facts, .warnings { margin: 4px 0 12px; padding-left: 1.2em; font-size: 0.92rem; }
.facts { color: var(--muted); }
.facts li, .warnings li { margin: 2px 0; overflow-wrap: anywhere; }
.warnings { border-left: 3px solid var(--warn); padding: 2px 0 2px 1.6em; color: var(--fg); }
/* The factor table no longer describes the design on the page. */
.stale { border-left: 3px solid var(--warn); padding: 2px 0 2px 10px; margin: 10px 0; font-size: 0.92rem; }
.equation { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; overflow-wrap: anywhere; }
.row { display: flex; flex-wrap: wrap; gap: 16px; margin: 12px 0; }
.row label, label[data-option] { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; min-width: 0; max-width: 100%; }
[hidden] { display: none !important; }
/* The terms a reader ticks for the model: one group per kind of term, wrapping on a phone. */
.terms { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; max-width: 100%; }
.terms legend { font-size: 0.9rem; padding: 0 4px; }
.terms h4 { margin: 8px 0 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.terms .group { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.terms label { display: inline-flex; align-items: center; gap: 4px; font-size: 0.9rem; }
.terms input { width: auto; padding: 0; }
input, select {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; max-width: 100%;
}
input[type="number"] { width: 7em; }
button, .button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--bg); color: inherit; text-decoration: none; display: inline-block;
}
.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: progress; }
.link { border: none; background: none; color: var(--accent); padding: 4px; }
.factors { border-collapse: collapse; margin-bottom: 4px; }
.factors th { text-align: left; font-weight: 600; font-size: 0.85rem; color: var(--muted); padding: 0 6px 4px 0; }
.factors td { padding: 2px 6px 2px 0; }
/* Fixed layout so the five columns share the width rather than each input
   asking for its own: on a phone the Units column used to run off the edge. */
.factors { width: 100%; max-width: 560px; table-layout: fixed; }
.factors th:nth-child(1) { width: 28%; }
.factors th:nth-child(2), .factors th:nth-child(3) { width: 24%; }
.factors th:nth-child(5) { width: 2rem; }
.factors input { width: 100%; min-width: 0; }
@media (max-width: 480px) {
  .factors td { padding-right: 4px; }
  /* Factor names are short; the units ("degC", "L/min") need the room. */
  .factors th:nth-child(1) { width: 20%; }
  .factors th:nth-child(2), .factors th:nth-child(3) { width: 22%; }
  .factors input { padding: 6px; }
}
.scroll { overflow-x: auto; margin: 12px 0; }
table.data { border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 4px 10px; text-align: right; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { padding: 0; }
button.sort {
  all: unset; box-sizing: border-box; display: block; width: 100%; padding: 4px 10px;
  cursor: pointer; font-weight: 600; text-align: inherit; white-space: nowrap;
}
button.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
button.sort::after { content: " ↕"; color: var(--muted); font-weight: 400; font-size: 0.8em; }
th[aria-sort="ascending"] button.sort::after { content: " ▲"; color: var(--accent); }
th[aria-sort="descending"] button.sort::after { content: " ▼"; color: var(--accent); }
@media (max-width: 480px) {
  table.data td, button.sort { padding: 4px 6px; }
  button.sort { white-space: normal; }
  button.sort::after { display: block; }
}
.drop {
  display: block; border: 2px dashed var(--line); border-radius: 10px; padding: 28px 16px;
  text-align: center; color: var(--muted); cursor: pointer;
}
.drop.over { border-color: var(--accent); color: var(--fg); }
.drop input { display: block; margin: 0 auto 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
footer { color: var(--muted); font-size: 0.88rem; }

/* The worked example: a button in the header, and a banner while the first paint is the
   copy computed when the page was built. */
.hero { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 4px 0 0; }
.hero .hint { flex: 1 1 260px; }
.banner {
  margin: 16px 0 0; padding: 10px 14px; border-radius: 8px; font-size: 0.92rem;
  background: var(--panel); border: 1px dashed var(--accent);
}

/* The steps, kept in reach while the page scrolls. */
.stepper {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 6px 18px; flex-wrap: wrap;
  margin: 16px -16px 0; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
  /* The bar and its rule span the window, so the wider step 4 scrolls under the bar rather than beside it.
     A border image drawn outside the box does not widen the page. */
  border-image: linear-gradient(to top, var(--line) 1px, var(--bg) 1px) fill 0 / 0 / 0 100vmax;
}
.stepper a { display: inline-flex; align-items: center; gap: 6px; color: var(--fg); text-decoration: none; font-size: 0.95rem; }
.stepper .step { width: 22px; height: 22px; font-size: 0.8rem; }
section { scroll-margin-top: 56px; }

/* Where the results come from: simulated, or entered. */
.tabs { display: flex; gap: 0; margin: 12px 0; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] {
  border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none;
  padding: 8px 14px; color: var(--muted);
}
.tabs [role="tab"][aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
details { margin: 10px 0; }
details summary { cursor: pointer; color: var(--accent); }

/* The run sheet's results are typed in place; a simulated value is in italics until it is edited. */
table.runs input {
  width: 6.5em; padding: 2px 6px; text-align: right; font: inherit; font-variant-numeric: tabular-nums;
}
table.runs input.sim { font-style: italic; color: var(--muted); }

/* The charts: one wide card for the coefficients, then two to a row where there is room. */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin: 16px 0 0; }
.chart { margin: 0; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; }
.chart.wide { grid-column: 1 / -1; }
.chart h3 { margin: 0 0 6px; font-size: 0.98rem; }
.chart figcaption { margin-top: 6px; }
.plot { width: 100%; min-height: 220px; }
@media (max-width: 480px) {
  .charts { grid-template-columns: 1fr; }
  .stepper { gap: 6px 12px; }
}

/* The comparison: measures grouped as the book groups them, the preferred direction as an arrow. */
table.compare td:nth-child(2) { text-align: center; color: var(--muted); }
table.compare th { vertical-align: bottom; padding: 4px 10px; font-weight: 600; text-align: right; }
table.compare th .link { font-weight: 400; font-size: 0.82rem; padding: 2px 0; }
table.compare tr.group td {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.04em; padding-top: 10px;
}
table.compare td { white-space: nowrap; }
/* The measure names wrap, and they and the group labels stay in view while the designs scroll past. */
table.compare td:first-child { white-space: normal; min-width: 9rem; }
table.compare th:first-child, table.compare tr:not(.group) td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
}
table.compare tr.group span { position: sticky; left: 10px; display: inline-block; }
/* Step 4 has a column per design: on a wide screen it takes the room its table needs. */
@media (min-width: 1000px) {
  #step-compare { --wide: min(1200px, 100vw - 64px); width: var(--wide); margin-left: calc((100% - var(--wide)) / 2); }
}
.charts > .hint.wide { grid-column: 1 / -1; margin: 0; }

/* Show the Python: the code a step's results came from, ready to copy. */
details.python { margin: 16px 0 0; border-top: 1px solid var(--line); padding-top: 8px; }
details.python pre {
  overflow-x: auto; margin: 8px 0; padding: 10px 12px; border-radius: 6px; font-size: 0.85rem;
  background: var(--bg); border: 1px solid var(--line);
}
details.python code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

/* Your designs: what this browser keeps, each to open or delete. */
.library { margin: 12px 0 0; font-size: 0.92rem; }
.library ul { list-style: none; padding: 0; margin: 6px 0 0; }
.library li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.library li .link { padding: 2px 0; text-align: left; }
.library li .link:disabled { color: var(--fg); font-weight: 600; cursor: default; opacity: 1; }
.banner.error { border-color: var(--error); color: var(--error); }

/* A link to the design: shown, selected, beside what it carries. */
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.92rem; }
.check input { width: auto; }
.share input { width: 100%; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.82rem; }
.share .hint { margin: 6px 0 0; }

/* The printed run sheet: only on paper, with nothing else of the page. */
#print-sheet { display: none; }
@media print {
  main > :not(#print-sheet) { display: none !important; }
  body { background: #fff; color: #000; font-size: 10pt; }
  main { max-width: none; padding: 0; }
  #print-sheet { display: block; border: none; padding: 0; margin: 0; background: none; }
  #print-sheet header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  #print-sheet h1 { font-size: 16pt; margin: 0 0 4px; }
  #print-sheet h2 { font-size: 11pt; margin: 12px 0 4px; }
  #print-sheet .qr { margin: 0; text-align: center; font-size: 8pt; max-width: 60mm; }
  #print-sheet .qr img { display: block; height: auto; margin: 0 auto 4px; }
  #print-sheet table { border-collapse: collapse; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
  #print-sheet th, #print-sheet td { border: 1px solid #888; padding: 5px 8px; text-align: right; }
  #print-sheet td.name, #print-sheet th:first-child { text-align: left; }
  #print-sheet td.result { min-width: 32mm; }
  #print-sheet td.notes { min-width: 50mm; }
  #print-sheet tr { break-inside: avoid; }
}
