/* The Splash Manual: its own small stylesheet, for the screen and for
   print (tools/manual-pdf.mjs prints it to manual/splash-manual.pdf). */

:root {
  --page: #fbfaf7;
  --panel: #ffffff;
  --ink: #1b1d22;
  --muted: #5b6270;
  --line: #dcdfe6;
  --accent: #1f5fbf;
  --code-bg: #f1f2f5;
  --code-ink: #23262d;
  --stage: #15171c;
  --tip: #eaf3ff;
  --tip-line: #9dbdf0;
  --svg-ink: #1b1d22;
  --svg-soft: #9aa3b2;
  --heat: 31, 95, 191;
  --warn: #a4570b;
  --good: #1b7a45;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #121418;
    --panel: #1a1d23;
    --ink: #e9ecf2;
    --muted: #a3abba;
    --line: #2d323c;
    --accent: #8fb8ff;
    --code-bg: #1f232b;
    --code-ink: #e3e7ee;
    --tip: #172335;
    --tip-line: #34507c;
    --svg-ink: #e9ecf2;
    --svg-soft: #6f7888;
    --heat: 143, 184, 255;
    --warn: #ffc27a;
    --good: #7bdca4;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #121418;
  --panel: #1a1d23;
  --ink: #e9ecf2;
  --muted: #a3abba;
  --line: #2d323c;
  --accent: #8fb8ff;
  --code-bg: #1f232b;
  --code-ink: #e3e7ee;
  --tip: #172335;
  --tip-line: #34507c;
  --svg-ink: #e9ecf2;
  --svg-soft: #6f7888;
  --heat: 143, 184, 255;
  --warn: #ffc27a;
  --good: #7bdca4;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font:
    17px/1.6 Georgia,
    "Iowan Old Style",
    "Palatino Linotype",
    serif;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}
h1,
h2,
h3,
h4,
.kicker,
nav,
figcaption,
table,
.button {
  font-family:
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
}
h1 {
  font-size: clamp(32px, 7vw, 48px);
  line-height: 1.05;
  margin: 8px 0 12px;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 28px;
  line-height: 1.2;
  margin: 56px 0 8px;
}
h3 {
  font-size: 20px;
  margin: 32px 0 6px;
}
h4 {
  font-size: 16px;
  margin: 20px 0 4px;
}
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.level {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 2px;
}
.lead {
  font-size: 19px;
  color: var(--muted);
}
a {
  color: var(--accent);
}
p,
li {
  max-width: 68ch;
}
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 40px 0;
}

/* Code and math */
code,
pre,
kbd {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.88em;
}
code {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 1px 5px;
  border-radius: 5px;
}
pre {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.5;
  break-inside: avoid;
}
pre code {
  background: none;
  padding: 0;
  font-size: 1em;
}
.math {
  display: block;
  text-align: center;
  font-size: 1.12em;
  margin: 16px 0;
  padding: 10px 12px;
  overflow-x: auto;
  font-style: normal;
  break-inside: avoid;
}
.math var,
p var,
li var,
td var {
  font-style: italic;
}
.mat {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 0 14px;
  padding: 2px 8px;
  border-left: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  border-radius: 6px;
  vertical-align: middle;
  font-size: 0.95em;
}

/* Tips and notes */
.tip {
  background: var(--tip);
  border-left: 4px solid var(--tip-line);
  padding: 10px 14px;
  border-radius: 6px;
  margin: 16px 0;
  break-inside: avoid;
}
.tip p {
  margin: 4px 0;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 16px 0;
}
table {
  border-collapse: collapse;
  font-size: 15px;
  width: 100%;
  break-inside: auto;
}
tr {
  break-inside: avoid;
}
th,
td {
  text-align: left;
  vertical-align: top;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
th {
  font-weight: 650;
}

/* Figures */
figure {
  margin: 24px 0;
  break-inside: avoid;
}
figure img,
figure svg {
  display: block;
  max-width: 100%;
  height: auto;
}
figcaption {
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.45;
}
.shots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.shots img {
  width: 100%;
  border-radius: 8px;
  background: var(--stage);
}
.shots.two {
  grid-template-columns: repeat(2, 1fr);
}
.shots.one {
  grid-template-columns: 1fr;
  max-width: 320px;
  margin: 0 auto;
}
figure img.ui {
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 100%;
}
.shot-label {
  font-size: 13px;
  text-align: center;
  color: var(--muted);
  margin-top: 4px;
}
.diagram {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.diagram svg {
  margin: 0 auto;
  color: var(--svg-ink);
}

/* The gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  break-inside: avoid;
  display: flex;
  flex-direction: column;
}
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--stage);
  display: block;
}
.card .body {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.card h4,
.card h5 {
  margin: 0;
}
.card h5 {
  font-size: 1em;
}
.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: auto;
}
.gallery-grid {
  margin-top: 8px;
}
details.fold.program {
  margin: 6px 0;
}
details.fold.program pre {
  margin: 6px 0;
  font-size: 12px;
}
details.gallery-group > .gallery {
  margin: 8px 14px 14px;
}
.card p {
  margin: 0;
  font-size: 15px;
}
.card pre {
  font-size: 12.5px;
  padding: 10px 12px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.button {
  align-self: flex-start;
  margin-top: auto;
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--page);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

/* Contents */
nav.toc {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  margin: 24px 0;
}
nav.toc ol {
  margin: 6px 0;
  padding-left: 22px;
}
nav.toc li {
  margin: 3px 0;
}
.cover-art {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 20px 0;
}
.cover-art img {
  width: 100%;
  border-radius: 8px;
  display: block;
  background: var(--stage);
}
footer {
  color: var(--muted);
  font-size: 14px;
  margin-top: 48px;
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }
  h2 {
    font-size: 24px;
  }
  .shots {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .shots.two {
    gap: 6px;
  }
  .cover-art {
    grid-template-columns: repeat(2, 1fr);
  }
  .math {
    font-size: 1em;
  }
}

/* Newcomer material: figure parts, approximation notes, the
   glossary and the reading list. */
.diagram svg text {
  fill: currentColor;
  font-family: sans-serif;
  font-size: 12px;
}
.diagram svg .sv-title {
  font-weight: 700;
  font-size: 13px;
}
.diagram svg .sv-muted {
  fill: var(--muted);
  font-size: 11px;
}
.diagram svg .sv-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}
.diagram svg .sv-soft {
  fill: none;
  stroke: var(--svg-soft);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}
.diagram svg .sv-box {
  fill: none;
  stroke: var(--svg-soft);
  stroke-width: 1;
}
.diagram svg .sv-acc {
  fill: var(--accent);
  fill-opacity: 0.22;
  stroke: var(--accent);
  stroke-width: 1.5;
}
.diagram svg .sv-warm {
  fill: #e8384f;
  fill-opacity: 0.3;
  stroke: #e8384f;
  stroke-width: 1.5;
}
.diagram svg .sv-dot {
  fill: currentColor;
}
.diagram svg .sv-on {
  fill: var(--accent);
  stroke: var(--accent);
}
.approx {
  border-left: 4px solid var(--svg-soft);
  background: var(--code-bg);
  padding: 8px 12px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 0.95em;
  break-inside: avoid;
}
.approx p {
  margin: 4px 0;
}
p code,
li code {
  overflow-wrap: anywhere;
}
dl.glossary dt {
  font-weight: 700;
  margin-top: 14px;
  break-after: avoid;
}
dl.glossary dd {
  margin: 2px 0 0 0;
}
ul.reading li {
  margin: 8px 0;
}

/* "Why this number?" notes, the level map, demo placeholders (web only),
   the numbered references and roomier Figures 2 and 3. */
.why {
  background: var(--code-bg);
  border-left: 4px solid var(--accent);
  padding: 8px 14px;
  border-radius: 6px;
  margin: 16px 0;
  break-inside: avoid;
  font-size: 0.95em;
}
.why p {
  margin: 4px 0;
}
.why .where {
  color: var(--muted);
  font-size: 0.92em;
}
.demo-placeholder {
  border: 2px dashed var(--svg-soft);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px 14px;
  margin: 18px 0;
}
.demo-placeholder p {
  margin: 4px 0;
}
.demo-placeholder .demo-tag {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
/* Drafts. A figure still to be made is a dashed box that says what it will show; a figure that is
   wrong is followed by a small marked note. Both show on the screen and in a printed draft, and
   come out of a page when its figure is made. */
.draft-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  margin: 24px 0;
  padding: 18px 14px;
  border: 2px dashed var(--svg-soft);
  border-radius: 10px;
  background: var(--panel);
}
.draft-figure figcaption {
  margin: 0;
  text-align: center;
}
.draft-mark {
  margin: 8px 0 18px;
  padding: 4px 10px;
  border-left: 4px solid var(--warn);
  border-radius: 0 6px 6px 0;
  background: var(--code-bg);
  color: var(--warn);
  font-family:
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}
ol.refs li {
  margin: 8px 0;
  overflow-wrap: anywhere;
}
pre.steps {
  border-left: 4px solid var(--accent);
}
.diagram.wide svg {
  width: 100%;
  max-width: 560px;
}

/* A lighter layout. Folds (definitions, derivations, "Why this number?"
   notes, long tables), glossary pop-ups, and live demos. To change what folds, change the class
   on the element: details.fold. manual/fold.js opens a fold for a link into it and for print. */
details.fold {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
details.fold > summary {
  cursor: pointer;
  padding: 9px 14px 9px 36px;
  position: relative;
  font-weight: 650;
  list-style: none;
  border-radius: 8px;
}
details.fold > summary::-webkit-details-marker {
  display: none;
}
details.fold > summary::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: translateY(-65%) rotate(-45deg);
  transition: transform 0.15s;
}
details.fold[open] > summary::before {
  transform: translateY(-65%) rotate(45deg);
}
details.fold > summary:hover {
  background: var(--code-bg);
}
details.fold > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
details.fold > :not(summary) {
  margin-left: 14px;
  margin-right: 14px;
}
details.fold[open] {
  padding-bottom: 6px;
}
details.fold.why {
  background: var(--code-bg);
  border-left: 4px solid var(--accent);
}
details.fold.tip {
  background: var(--tip);
  border-left: 4px solid var(--tip-line);
}
details.fold.approx {
  background: var(--code-bg);
  border-left: 4px solid var(--svg-soft);
}
details.fold .table-wrap {
  margin-top: 8px;
}
details.fold details.fold {
  background: var(--panel);
}
.fold-all button {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
}
.muted {
  color: var(--muted);
  font-size: 14px;
}
.kind {
  margin: 4px 0 8px;
}
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
  margin-right: 4px;
}
.chip.choice {
  color: var(--accent);
  border: 1px solid var(--accent);
}
.chip.limit {
  color: var(--warn);
  border: 1px solid var(--warn);
}
.chip.both {
  color: var(--good);
  border: 1px solid var(--good);
}
.chip.open {
  color: var(--muted);
  border: 1px dashed var(--svg-soft);
}
.where {
  color: var(--muted);
  font-size: 0.92em;
}

/* Glossary words in the running text, and their pop-up */
.term {
  border-bottom: 1px dotted var(--accent);
  cursor: help;
}
.term:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}
#term-pop {
  position: absolute;
  z-index: 20;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 400;
}
#term-pop[hidden] {
  display: none;
}
#term-pop strong,
#term-pop span,
#term-pop a {
  display: block;
}
#term-pop strong {
  margin-bottom: 2px;
}
#term-pop a {
  margin-top: 4px;
  font-size: 13px;
}

/* Live demos (web only; the PDF prints a still of each and a link) */
.demo-live {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin: 20px 0;
}
.demo-live h4 {
  margin: 0 0 4px;
}
.demo-live .hint {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 10px;
}
.demo-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
@media (max-width: 640px) {
  .demo-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
.demo-live canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: var(--page);
  border: 1px solid var(--line);
}
.demo-live canvas[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.demo-live #ss-turn {
  margin-top: 12px;
}
.controls {
  display: grid;
  gap: 10px;
  min-width: 0;
}
.controls label {
  display: grid;
  grid-template-columns: 6.5em minmax(0, 1fr) 4em;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.controls output {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  text-align: right;
}
.demo-live input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.demo-live select,
.demo-live button,
.demo-live input[type="text"] {
  font: 14px sans-serif;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
}
.demo-live button {
  cursor: pointer;
}
.demo-live button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--page);
  border-color: var(--ink);
}
.demo-live input[type="text"] {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  width: 100%;
  min-width: 0;
}
.demo-live :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.readout {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  padding: 8px 10px;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.verdict {
  font-size: 14px;
  font-weight: 600;
}
.verdict.ok {
  color: var(--good);
}
.verdict.bad {
  color: var(--warn);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.chips button {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  padding: 4px 9px;
}
.tree {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 10px 12px;
}
.tree .node {
  padding-left: 16px;
  border-left: 1px dashed var(--line);
  margin-left: 4px;
}
.tree .op {
  color: var(--accent);
  font-weight: 600;
}
.tree .kind {
  color: var(--muted);
  font-size: 11px;
  margin-left: 6px;
}
.err {
  color: var(--warn);
  font-size: 14px;
}
.demo-still {
  display: none;
}

/* Print: letter pages; page numbers come from the PDF tool's footer. */
@page {
  size: letter;
  margin: 0.7in 0.75in 0.8in;
}
@media print {
  :root {
    --page: #ffffff;
    --panel: #ffffff;
    --ink: #111111;
    --muted: #4a4f59;
    --line: #cfd3da;
    --accent: #174ea6;
    --code-bg: #f2f3f5;
    --code-ink: #1d1f24;
    --tip: #eef4fd;
    --tip-line: #8fb0e6;
    --svg-ink: #111111;
    color-scheme: light;
  }
  body {
    font-size: 11pt;
    line-height: 1.5;
  }
  main {
    max-width: none;
    padding: 0;
  }
  h2 {
    break-before: page;
    margin-top: 0;
  }
  h2,
  h3,
  h4 {
    break-after: avoid;
  }
  .no-print {
    display: none;
  }
  a {
    text-decoration: none;
  }
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .card img {
    max-height: 2.6in;
  }
  pre {
    white-space: pre-wrap;
    word-break: break-word;
    break-inside: auto;
    font-size: 7.8pt;
    padding: 8px 10px;
    line-height: 1.4;
  }
  .card pre {
    break-inside: avoid;
  }
  .cover {
    min-height: 8.5in;
  }
  .demo-placeholder,
  .demo-live,
  .fold-all,
  #term-pop {
    display: none;
  }
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .gallery-grid .card {
    break-inside: avoid;
  }
  .gallery-grid .card img {
    max-height: 1.5in;
  }
  .gallery-grid .card .body {
    padding: 6px 8px 8px;
  }
  .gallery-grid .card p {
    font-size: 8.5pt;
    line-height: 1.3;
  }
  /* The programs and their Run it links are printed (the PDF has no fold to open), so a reader
     can type a program in, or tap its link. */
  .gallery-grid details.program > summary {
    display: none;
  }
  .gallery-grid details.program pre {
    font-size: 6.8pt;
    line-height: 1.3;
    padding: 4px 6px;
    margin: 4px 0;
  }
  .gallery-grid .card-links {
    font-size: 8.5pt;
    margin: 2px 0 0;
  }
  .gallery-grid .card-links .button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    text-decoration: underline;
  }
  .demo-still {
    display: block;
    break-inside: avoid;
    margin: 12px 0;
  }
  .demo-still img {
    max-width: 4.2in;
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .term {
    border-bottom: 0;
  }
  details.fold {
    border-color: var(--line);
    break-inside: auto;
  }
  details.fold > summary::before {
    display: none;
  }
  details.fold > summary {
    padding-left: 14px;
  }
  h2.coming {
    break-before: auto;
    margin-top: 1em;
  }
  .diagram.wide svg {
    width: 4.7in;
    max-width: 100%;
  }
}

/* The budget tables (Level 2, "How many splats?"): they scroll inside their own box, with the toy's
   name staying in view. Color is never the only sign: worse values are bold, better ones plain. */
.budget-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.budget-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
table.budget {
  min-width: 560px;
  margin: 0;
}
table.budget.summary {
  min-width: 440px;
}
.table-note {
  margin: 14px 0 0;
  font-size: 15px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
table.budget td,
table.budget th {
  white-space: nowrap;
}
table.budget thead th {
  white-space: normal;
  min-width: 90px;
}
table.budget thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--tip);
  font-size: 13px;
}
table.budget tbody th {
  position: sticky;
  left: 0;
  background: var(--panel);
  border-left: 0;
  font-weight: 600;
  white-space: nowrap;
  z-index: 1;
}
table.budget small.drawn {
  display: block;
  font-weight: 400;
  font-size: 0.78em;
  color: var(--muted);
  white-space: normal;
  max-width: 15em;
}

table.budget td.pair {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.budget td.worse {
  color: var(--warn);
  font-weight: 700;
}
table.budget td.better {
  color: var(--good);
}
.swatch {
  display: inline-block;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 13px;
}
.swatch.worse {
  color: var(--warn);
  font-weight: 700;
}
.swatch.better {
  color: var(--good);
}
@media print {
  .budget-wrap {
    max-height: none;
    overflow: visible;
    border: 0;
  }
  table.budget {
    min-width: 0;
    font-size: 9pt;
  }
  table.budget thead th,
  table.budget tbody th {
    position: static;
  }
}

/* The grammar as tracks (Level 3). */
.rr-text {
  margin: 10px 0 4px;
  min-height: 2.4em;
}
.rr-rules {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 12px 12px;
  background: var(--panel);
}
.rr-rule h5 {
  margin: 14px 0 4px;
  font:
    600 14px ui-monospace,
    Menlo,
    Consolas,
    monospace;
  color: var(--muted);
}
.rr-scroll {
  overflow-x: auto;
}
.rr-svg {
  display: block;
  max-width: none;
  font:
    13px ui-monospace,
    Menlo,
    Consolas,
    monospace;
}
.rr-rail {
  fill: none;
  stroke: var(--svg-soft, var(--muted));
  stroke-width: 1.6;
}
.rr-end {
  fill: var(--muted);
}
.rr-t rect,
.rr-words rect {
  fill: var(--panel);
  stroke: var(--ink);
  stroke-width: 1.2;
}
.rr-nt rect {
  fill: var(--tip);
  stroke: var(--accent);
  stroke-width: 1.2;
}
.rr-svg text {
  fill: var(--ink);
}
.rr-note {
  fill: var(--muted);
  font-style: italic;
  font-size: 11px;
}
.rr-nt a {
  cursor: pointer;
}
.rr-nt a:hover rect,
.rr-nt a:focus-visible rect {
  stroke-width: 2.4;
}
/* A walk: what it passed is bold and colored; color is never the only sign (the box is thicker). */
.rr-svg .on.rr-t rect,
.rr-svg .on.rr-nt rect,
.rr-svg .on.rr-words rect {
  stroke: var(--heat-solid, #e8384f);
  stroke-width: 3;
  fill: color-mix(in srgb, var(--heat-solid, #e8384f) 14%, var(--panel));
}
.rr-svg text.on {
  fill: var(--heat-solid, #e8384f);
  font-weight: 700;
}
.rr-svg path.on {
  stroke: var(--heat-solid, #e8384f);
  stroke-width: 3;
}
label.inline {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

/* The second set of demos (Levels 1 to 3). */
.demo-live fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px 8px;
  margin: 0;
  display: grid;
  gap: 6px;
  min-width: 0;
}
.demo-live legend {
  font-size: 13px;
  font-weight: 600;
  padding: 0 6px;
  color: var(--muted);
}
.sw {
  display: inline-block;
  width: 1em;
  height: 1em;
  border-radius: 4px;
  border: 1px solid var(--line);
  vertical-align: -0.12em;
}
.sw.big {
  width: 1.6em;
  height: 1.6em;
  vertical-align: -0.4em;
}
table.numbers {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}
table.numbers th[scope="row"] {
  font-weight: 600;
  white-space: nowrap;
  border-left: 0;
  background: transparent;
}
table.numbers td {
  white-space: pre;
}
table.numbers tr.changed th,
table.numbers tr.changed td {
  color: var(--warn);
  font-weight: 700;
}
table.numbers tr.changed th::after {
  content: " ◀ changed";
  font-weight: 400;
  font-size: 11px;
}
table.blend tr.later {
  opacity: 0.45;
}
table.blend td,
table.blend th {
  white-space: nowrap;
}
.order {
  margin: 0;
  padding-left: 1.4em;
  display: grid;
  gap: 4px;
  font-size: 14px;
}
.order button {
  padding: 2px 8px;
  font-size: 12px;
  margin-left: 6px;
}
.readout.result {
  margin: 10px 0 0;
}
.code-lines {
  display: grid;
  gap: 6px;
}
.demo-live button.code-line {
  text-align: left;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.35;
  padding: 6px 8px;
  white-space: pre;
  overflow-x: auto;
  background: var(--code-bg);
  color: var(--code-ink);
}
.demo-live button.code-line code {
  background: none;
  padding: 0;
  font: inherit;
  white-space: pre;
}
.demo-live button.code-line.hot,
.demo-live button.code-line[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 18%, var(--code-bg));
  color: var(--ink);
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}
.field-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}
.field-row {
  display: grid;
  grid-template-columns: 4.2em minmax(0, 1fr);
  gap: 2px 8px;
  align-items: center;
}
.field-row .note {
  grid-column: 2;
  font-size: 12px;
  color: var(--muted);
}
.demo-live .err,
.demo-live .diff-head {
  margin: 8px 0 4px;
  font-size: 14px;
}
.demo-live .diff-head {
  color: var(--muted);
}
#pj-top {
  margin-top: 10px;
}
@media print {
  .rr-rules,
  .rr-text {
    display: none;
  }
}
.demo-live [hidden] {
  display: none !important;
}
.demo-live button.code-line {
  display: block;
  width: 100%;
  text-align: left;
}
.demo-live button.code-line code {
  display: block;
  text-align: left;
  overflow-x: auto;
}
.demo-live button.code-line {
  overflow: visible;
}
.code-lines {
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}
.demo-live button.code-line {
  min-width: 0;
  max-width: 100%;
}

.numgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 6px;
  margin-top: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}
.numgrid > div {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px;
  align-items: baseline;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.numgrid .k {
  color: var(--muted);
}
.numgrid .v {
  text-align: right;
  font-weight: 600;
}
.numgrid > div.changed {
  border-color: var(--warn);
  box-shadow: inset 4px 0 0 var(--warn);
}
.numgrid > div.changed .v {
  color: var(--warn);
}

/* One page per chapter: the contents button, Previous and Next, and the cover's full contents. */
.manual-nav {
  margin-top: 0;
}
.outline-sub {
  margin: 0 0 6px 14px;
  padding: 0 0 0 10px;
  list-style: none;
  border-left: 2px solid var(--line);
}
.outline-sub a {
  padding: 7px 10px;
  font-size: 0.88rem;
}
.outline-panel a[aria-current="page"] {
  color: var(--accent);
  font-weight: 700;
}
.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
  max-width: calc(50% - 6px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}
.pager a:hover {
  border-color: var(--accent);
}
.pager a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pager-next {
  margin-left: auto;
  text-align: right;
}
.pager-word {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.pager-title {
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
nav.toc ol.toc-sections {
  margin: 2px 0 8px;
  font-size: 0.92em;
  list-style: disc;
}
nav.toc > ol > li {
  margin: 8px 0;
}
nav.toc > ol > li > a {
  font-weight: 600;
}

nav.toc > ol {
  list-style: none;
  padding-left: 0;
}

@media print {
  .pager,
  .manual-nav {
    display: none !important;
  }
}

.labs-note {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---- r7a: live figures, and the pictures on the "more", "unique" and "built" pages ---------------
   A live figure (manual/demos4.js) has a still inside it for the PDF and a canvas for the web page;
   the script adds .live when the canvas is running. */
.fig-stack {
  position: relative;
  max-width: 540px;
  margin: 0 auto;
}
.fig-stack svg {
  display: block;
  width: 100%;
  height: auto;
}
.fig-stack .fig-live {
  display: none;
}
.diagram.live .fig-still {
  display: none;
}
.diagram.live .fig-live {
  display: block;
  position: absolute;
  top: 7.9%;
  left: 66.7%;
  width: 30.5%;
  height: auto;
}
@media print {
  .diagram.live .fig-still {
    display: inline;
  }
  .diagram.live .fig-live {
    display: none;
  }
}
.built-diagram svg {
  max-width: 420px;
  width: 100%;
  height: auto;
}
.item-pic {
  margin: 10px 0 16px;
}
.item-pic img {
  display: block;
  width: 100%;
  max-width: 540px;
  height: auto;
  border-radius: 8px;
  background: #14161c;
}
.item-pic figcaption {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
.link-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.link-steps li {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow-wrap: anywhere;
}
.link-steps .size {
  color: var(--muted);
  font-size: 0.85rem;
}
.link-steps code {
  font-size: 0.8rem;
}

/* ---- Chapters 6 to 10 and the back matter ---- */
ul.reading li {
  overflow-wrap: anywhere;
}

/* The last five demos, the Chapter 9 picture row, the "more" page's pictures, and the PDF's
   clickable contents. */
.demo-live .controls + .row,
.demo-live .row + .readout,
.demo-live canvas + .controls,
.demo-live .photo-pair + .controls {
  margin-top: 10px;
}
.demo-live canvas[tabindex] {
  touch-action: none;
}
.demo-live .controls label.check {
  display: flex;
  gap: 8px;
}
.photo-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}
.photo-pair figure {
  margin: 0;
}
.photo-pair figcaption {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}
.table-wrap {
  min-width: 0;
}
.dt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 10px;
}
.dt-table th,
.dt-table td {
  padding: 2px 3px;
  text-align: center;
}
.dt-table input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 6px 3px;
  font-size: 13px;
  text-align: center;
}
.qd-meter {
  display: grid;
  gap: 6px;
}
.qd-block {
  display: grid;
  grid-template-columns: 4.5em minmax(0, 1fr) 7.5em;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.qd-bar {
  position: relative;
  display: block;
  height: 12px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.qd-bar > span {
  display: block;
  height: 100%;
  background: var(--good);
  border-radius: 5px;
}
.qd-bar > span.over {
  background: var(--warn);
}
.qd-bar > i {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--ink);
}
.qd-nums {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.demo-live[data-demo="moving-joints"] .controls label {
  grid-template-columns: 8em minmax(0, 1fr) 6.5em;
}
.demo-live .controls output {
  white-space: nowrap;
}
.demo-live[data-demo="qr-damage"] .qd-meter {
  margin-bottom: 8px;
}
/* Two pictures in one row, the same size, level with each other (Chapter 9's QR codes). They stack,
   each at most 300 px wide and centered, on a phone. */
.shots.even {
  align-items: start;
}
.shots.even img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
  height: auto;
}
@media (max-width: 480px) {
  .shots.even {
    grid-template-columns: minmax(0, 1fr);
    max-width: 300px;
    margin: 0 auto;
  }
}
