:root {
  --bg: #fdfdfb; --fg: #1d2127; --muted: #5d6673; --rule: #dcdfe4;
  --accent: #1f4f8f; --keybg: #eef3fb; --keyborder: #2a4f87; --sidebg: #f3f4f1;
  --measure: 80ch;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181c; --fg: #e4e6ea; --muted: #9aa3b0; --rule: #31363e;
          --accent: #8db6f0; --keybg: #1c2636; --keyborder: #6f9ddb; --sidebg: #1b1e23; }
  img.fig { filter: invert(1) hue-rotate(180deg); }
}
* { box-sizing: border-box; }
html { font-size: 18px; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Charter", "Iowan Old Style", "Palatino Linotype", Georgia, serif; line-height: 1.6;
  display: grid; grid-template-columns: 17rem minmax(0, 1fr); }
a { color: var(--accent); }
.topbar, .navtoggle { display: none; }
.sidebar { position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  background: var(--sidebg); border-right: 1px solid var(--rule); padding: 1.5rem 1.2rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: .88rem; }
.sidebar .brand, .topbar .brand { font-weight: 700; text-decoration: none; color: var(--fg); display: block; margin-bottom: 1rem; }
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: .1rem 0; }
.sidebar li a { display: block; padding: .3rem .5rem; border-radius: 4px; text-decoration: none; color: var(--fg); }
.sidebar li a:hover { background: var(--rule); }
.sidebar li.current > a { background: var(--rule); font-weight: 600; }
main { padding: 2.5rem 1.5rem 4rem; }
article, .pager { max-width: var(--measure); margin: 0 auto; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 .4rem; }
h2 { font-size: 1.35rem; margin: 2.2rem 0 .6rem; border-bottom: 1px solid var(--rule); padding-bottom: .2rem; }
h3 { font-size: 1.1rem; margin: 1.6rem 0 .4rem; }
.lecture-head .sub { color: var(--muted); margin: 0; }
.actions { margin: .6rem 0 1.6rem; font-family: system-ui, sans-serif; font-size: .85rem; }
.btn { display: inline-block; padding: .25rem .7rem; border: 1px solid var(--accent); border-radius: 4px;
  text-decoration: none; margin-right: .4rem; }
.btn:hover { background: var(--keybg); }
.header-section-number { margin-right: .5em; color: var(--muted); }
/* equations */
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.keyeq { display: inline-block; background: var(--keybg); border: 1px solid var(--keyborder);
  border-radius: 3px; padding: .15em .5em; }
/* minipage rows */
.row { display: flex; gap: 1.5rem; align-items: center; margin: .8rem 0; }
.row .mp-text { flex: 1 1 0; min-width: 0; }
.row .mp-fig { flex: 0 1 auto; max-width: 66%; text-align: center; }
.row p { margin: .4rem 0; }
img.fig { max-width: 100%; height: auto; }
.center { text-align: center; margin: 1rem 0; }
@media (max-width: 640px) { .row { flex-direction: column; align-items: stretch; } .row .mp-fig { max-width: 100%; } }
/* problems */
.prob { display: grid; grid-template-columns: 3.2rem 1fr; gap: .5rem; margin: 1rem 0; }
.prob .num { font-weight: 700; padding-top: .35rem; }
.prob .num p { margin: 0; }
.prob .answer-link { font-family: system-ui, sans-serif; font-size: .85rem; margin-top: .2rem; }
ul.answers { list-style: none; padding: 0; }
.answer { display: grid; grid-template-columns: 3.4rem 1fr auto; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--rule); align-items: baseline; }
.answer .num { font-weight: 700; }
.answer .links { font-family: system-ui, sans-serif; font-size: .8rem; display: flex; gap: 1rem; }
.answer:target { background: var(--keybg); }
.pager { display: flex; justify-content: space-between; margin-top: 3rem; padding-top: 1rem;
  border-top: 1px solid var(--rule); font-family: system-ui, sans-serif; font-size: .9rem; }
@media (max-width: 860px) {
  body { display: block; }
  .topbar { display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; background: var(--sidebg);
    border-bottom: 1px solid var(--rule); font-family: system-ui, sans-serif; position: sticky; top: 0; z-index: 5; }
  .topbar .brand { margin: 0; }
  .burger { cursor: pointer; font-size: 1.3rem; }
  .sidebar { display: none; position: fixed; inset: 2.8rem 0 0 0; height: auto; z-index: 4; width: 100%; }
  .navtoggle:checked ~ .sidebar { display: block; }
  .sidebar > .brand { display: none; }
  main { padding: 1.5rem 1rem 3rem; }
  .answer { grid-template-columns: 3rem 1fr; } .answer .links { grid-column: 2; }
}
@media print {
  body { display: block; background: #fff; color: #000; font-size: 11pt; }
  .sidebar, .topbar, .pager, .actions { display: none; }
  main { padding: 0; } article { max-width: none; }
  a { color: #000; text-decoration: none; }
  img.fig { filter: none; }
  .row, .prob, .keyeq { break-inside: avoid; }
}
img.fig { zoom: 1.25; }
.prob .row { align-items: flex-start; }
.answer { grid-template-columns: 3.4rem 1fr; }
.answer .links { grid-column: 2; }
.answer .ans { overflow-x: auto; }

.sidebar ul.sections { list-style: none; margin: .2rem 0 .5rem .6rem; padding: 0 0 0 .5rem; border-left: 2px solid var(--rule); }
.sidebar ul.sections a { font-size: .82rem; padding: .15rem .4rem; color: var(--muted); }
.sidebar .secnum { display: inline-block; width: 1.3em; color: var(--muted); }
.sidebar li.problems { margin-top: .4rem; padding-top: .3rem; border-top: 1px dashed var(--rule); }
.sidebar li.problems a { font-style: italic; }
/* book numbering */
.sidebar .chnum { display: inline-block; width: 1.5em; color: var(--muted); }
.sidebar .secnum { width: 2.2em; }
.sidebar li.extra { margin-top: .2rem; }
.sidebar li.extra:first-of-type { margin-top: 1rem; padding-top: .6rem; border-top: 1px solid var(--rule); }
.chapter-label { margin: 0; color: var(--muted); font-family: system-ui, sans-serif; font-size: .85rem;
  text-transform: uppercase; letter-spacing: .06em; }
ol.contents { list-style: none; padding: 0; counter-reset: ch; }
ol.contents > li { counter-increment: ch; margin: .8rem 0; }
ol.contents .chtitle::before { content: counter(ch) "\00a0\00a0"; color: var(--muted); }
ol.contents .chtitle { font-weight: 600; font-size: 1.05rem; text-decoration: none; }
ol.contents ul { margin: .1rem 0 0 2.2rem; padding: 0; list-style: none; font-size: .92rem; }
p.small { font-size: .85rem; color: var(--muted); }

/* interactive tools */
.tool { border: 1px solid var(--rule); border-radius: 6px; padding: .8rem 1rem; margin: 1rem 0; font-family: system-ui, sans-serif; }
.tool-controls { display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; align-items: center; font-size: .9rem; margin-bottom: .6rem; }
.tool-controls input[type=range] { vertical-align: middle; width: 9rem; }
.tool canvas { width: 100%; height: 260px; display: block; margin-bottom: .6rem; color: inherit; }
.tool .t-info { margin: .2rem 0 0; }

/* plot figures (raster images) and captions */
.plotfig { margin: 1.2rem 0; text-align: center; }
.plotfig p { margin: 0; }
img.plot { max-width: 100%; height: auto; }
.figcaption { font-size: .9rem; color: var(--muted); text-align: left; max-width: 40rem; margin: .4rem auto 0; }
/* footnotes */
section.footnotes { margin-top: 2.5rem; font-size: .88rem; color: var(--muted); }
section.footnotes hr { border: 0; border-top: 1px solid var(--rule); width: 30%; margin-left: 0; }
section.footnotes ol { padding-left: 1.4rem; }
.footnote-ref sup { font-size: .75em; }
a.footnote-back { text-decoration: none; margin-left: .3rem; }
