/* HENYEY site — typography after the 1964 physics-textbook tradition
   (Century Schoolbook, via the free TeX Gyre Schola), figures as
   black-ink line art with red accents; machine text stays monospace. */

@font-face { font-family: "Schola"; src: url("fonts/texgyreschola-regular.otf") format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Schola"; src: url("fonts/texgyreschola-italic.otf") format("opentype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Schola"; src: url("fonts/texgyreschola-bold.otf") format("opentype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Schola"; src: url("fonts/texgyreschola-bolditalic.otf") format("opentype"); font-weight: 700; font-style: italic; font-display: swap; }

:root {
  color-scheme: light;
  --paper: #fbf9f4;         /* book stock */
  --surface: #fbf9f4;       /* no white panels - everything on the stock */
  --card: #f0e5c9;          /* 5081 manila */
  --cardink: #7d97b8;       /* 5081 light-blue printing */
  --ink: #1d1a16;           /* text and figure ink */
  --ink-2: #4d4a45;
  --ink-3: #8b867d;
  --rule: #e3ddd0;
  --red: #a8332e;           /* the red of the covers, used sparingly */
  --band: rgba(160, 140, 96, 0.16);   /* convective shading */
  --greenbar: rgba(70, 110, 90, 0.05);
  --measure: 720px;          /* shared right edge: paragraphs, controls, printer */
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Schola", Georgia, "Times New Roman", serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #191713; --surface: #191713; --card: #2c2820; --cardink: #6d84a3;
  --ink: #eae5da; --ink-2: #b5afa3; --ink-3: #7e786d; --rule: #322e26;
  --red: #d0605c; --band: rgba(190, 170, 120, 0.14);
  --greenbar: rgba(120, 160, 140, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #191713; --surface: #191713; --card: #2c2820; --cardink: #6d84a3;
    --ink: #eae5da; --ink-2: #b5afa3; --ink-3: #7e786d; --rule: #322e26;
    --red: #d0605c; --band: rgba(190, 170, 120, 0.14);
    --greenbar: rgba(120, 160, 140, 0.05);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); line-height: 1.52; font-size: 15px;
}
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 0.88em; }

/* ---- title page ---- */
.hero { max-width: 1020px; margin: 0 auto; padding: 64px 24px 18px; position: relative; }
.theme-toggle {
  position: absolute; top: 20px; right: 24px; background: none; border: 1px solid var(--rule);
  color: var(--ink-2); border-radius: 50%; width: 36px; height: 36px; font-size: 17px; cursor: pointer;
}
.overline { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; color: var(--ink-3); margin: 0 0 10px; }
h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(26px, 4vw, 40px);
     letter-spacing: 0.04em; margin: 0; line-height: 1; }
.tagline { font-size: clamp(14.5px, 1.9vw, 16px); color: var(--ink-2); margin: 12px 0 2px; }
.volume { font-style: italic; color: var(--ink-2); margin: 0 0 18px; font-size: 13.5px; }
.hero::after { content: ""; display: block; height: 2px; background: var(--red); width: 96px; margin-top: 22px; }
.lede { max-width: var(--measure); text-align: justify; hyphens: auto; }
.lede-actions { margin-top: 24px; display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-block; font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.05em;
  padding: 9px 16px; border: 1px solid var(--red); border-radius: 4px; color: var(--red); cursor: pointer;
  background: none;
}
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { border-color: var(--rule); color: var(--ink-2); }
.btn:hover { text-decoration: none; filter: brightness(1.06); }

/* ---- chapters ---- */
main { max-width: 1020px; margin: 0 auto; padding: 0 24px 72px; }
.section { margin: 50px 0; }
.section h2 { font-size: 16.5px; margin-bottom: 9px; font-weight: 700; }
.secno { color: var(--ink); margin-right: 14px; }
.section > p, .prose p { max-width: var(--measure); text-align: justify; hyphens: auto; margin: 0 0 0.2em; }
.prose p + p { text-indent: 1.6em; margin-top: 0.2em; }
.section > p { color: var(--ink-2); }
.prose p { color: var(--ink); }
.fineprint { font-size: 11.9px; color: var(--ink-3); text-align: left !important; text-indent: 0 !important; margin-top: 0.9em !important; }

/* ---- deck ---- */
.controls { display: flex; flex-wrap: nowrap; gap: 10px 12px; margin: 16px 0 12px; align-items: end; overflow-x: auto; padding-bottom: 4px; max-width: var(--measure); justify-content: space-between; }
.controls label { display: flex; flex-direction: column; font-size: 10.5px; color: var(--ink-3); gap: 3px; font-family: var(--mono); white-space: nowrap; flex: none; }
.controls input, .controls select {
  font-family: var(--mono); font-size: 12.5px; padding: 6px 8px; width: 92px;
  border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); color: var(--ink);
}
#cards { display: grid; gap: 10px; margin: 14px 0; }
.punchcard { width: 100%; max-width: 540px; height: auto; display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.22)); }
.deck-listing {
  max-width: 540px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 4px; padding: 8px 12px; overflow-x: auto; margin: 4px 0 0;
}
.run-row { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.job-status { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }

/* ---- printer ---- */
.printer {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
  height: 320px; overflow: hidden; position: relative; margin-top: 14px;
}
.printer-scroll {
  position: absolute; inset: 0; overflow: auto; padding: 10px 14px;
  font-family: var(--mono); font-size: 11.2px; line-height: 1.5; white-space: pre; color: var(--ink-2);
  background-image: repeating-linear-gradient(to bottom, var(--greenbar) 0 35.4px, transparent 35.4px 70.8px);
}
.printer-scroll .hl { color: var(--ink); font-weight: 600; }

/* ---- figures ---- */
.chartgrid { display: grid; grid-template-columns: 1fr; gap: 20px; margin-top: 18px; }
.chartgrid.three { grid-template-columns: 1fr; gap: 4px; }
.chartcard { background: none; border: none; padding: 0 0 4px; margin: 0; max-width: 560px; }
.chartcard.wide { margin-top: 18px; }
.caption { font-size: 11.9px; color: var(--ink-2); margin: 6px 2px 2px; text-align: left; }
.caption b { font-weight: 700; }
.chartbox { width: 100%; }
.chartbox svg { display: block; width: 100%; height: auto; }
.scrub-row { display: flex; gap: 14px; align-items: center; margin: 4px 0 8px; }
.scrub-row input[type=range] { flex: 1; accent-color: var(--red); }
.tableview { margin-top: 16px; font-size: 13px; }
.tableview summary { cursor: pointer; color: var(--red); font-family: var(--mono); font-size: 12px; }
.tableview > div, #trackTable { overflow-x: auto; }
.tableview table { border-collapse: collapse; margin-top: 10px; font-family: var(--mono); font-size: 12px; }
.tableview th, .tableview td { padding: 3px 10px; border-bottom: 1px solid var(--rule); text-align: right; color: var(--ink-2); }
.tableview th { color: var(--ink-3); font-weight: 600; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 11.5px; padding: 6px 9px; border-radius: 4px; line-height: 1.45;
  max-width: 260px; box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
footer { border-top: 1px solid var(--rule); padding: 18px 24px 36px; text-align: center; }
footer p { color: var(--ink-3); font-size: 11.5px; font-family: var(--mono); }
@media (max-width: 700px) {
  .controls input { width: 84px; }
  .printer { height: 260px; }
  .printer-scroll { font-size: 9.6px; }
  .flowfig { overflow-x: auto; }
  .flowfig svg { min-width: 620px; }
}

/* ---- the program, annotated (source.html) ---- */
.src-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 26px; align-items: start; }
.codepane {
  font-family: var(--mono); font-size: 11.3px; line-height: 1.62;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
  padding: 8px 0 14px; overflow-x: auto; position: relative;
}
.codeline { display: flex; white-space: pre; scroll-margin-top: 80px; }
.codeline .ln { width: 50px; text-align: right; padding-right: 12px; color: var(--ink-3);
  user-select: none; flex: none; font-size: 9.5px; line-height: inherit; padding-top: 1px; }
.codeline .txt { flex: 1; min-width: 0; }
.codeline.cmt .txt { color: var(--ink-3); }
.codeline .lblf { color: var(--red); }
.codeline .kw { font-weight: 700; }
.codeline.noted .ln { color: var(--red); }
.codeline.hl { background: rgba(168, 51, 46, 0.10); }
.notespane { position: relative; font-family: var(--serif); }
.mnote { position: absolute; width: 100%; font-size: 12.2px; line-height: 1.42; color: var(--ink-2);
  padding-left: 12px; border-left: 2px solid var(--rule); cursor: pointer; }
.mnote b { color: var(--ink); }
.mnote:hover, .mnote.hl { border-left-color: var(--red); }
.mnote .eq { font-style: italic; }
.flowcard { max-width: var(--measure); }
.flowfig { background: none; border: none; padding: 8px 0 2px; }
.flowfig svg { display: block; width: 100%; height: auto; }
.flowfig text { font-family: var(--mono); font-size: 10.5px; fill: var(--ink); }
.flowfig .box { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.flowfig .dec { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.flowfig .arr { stroke: var(--ink); stroke-width: 1.2; fill: none; marker-end: url(#ah); }
.flowfig .yn { font-size: 9.5px; fill: var(--ink-2); }
.flowfig a .box:hover, .flowfig a .dec:hover { stroke: var(--red); stroke-width: 2; }
.flowfig a { cursor: pointer; }
.pagenav { font-family: var(--mono); font-size: 11.5px; margin-top: 8px; }
.pagenav a { margin-right: 14px; }
@media (max-width: 960px) {
  .src-layout { grid-template-columns: 1fr; }
  .notespane { display: none; }
  .mnote.inline { position: static; display: block; margin: 6px 8px 6px 50px;
    font-family: var(--serif); white-space: normal; }
}
