/* Layout: a chapter rail on the left, one reading column on the right;
   photographs sit in the column like prints in a file, captions typed beneath. */
:root {
  --paper: #f1f3f2;
  --panel: #e5e9e9;
  --ink: #18202c;
  --muted: #56606e;
  --rule: #cbd1d2;
  --link: #1d4477;
  --mark: #f0d648;      /* legal-pad yellow */
  --on-mark: #18202c;
  --print: #ffffff;     /* photo border */
  --shade: rgba(12, 16, 22, 0.86);

  --display: "Old Standard TT", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --body: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --typed: "Courier Prime", "Courier New", Courier, monospace;

  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --text: 40rem;
  --wide: 54rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11151b; --panel: #1a2029; --ink: #e4e2da; --muted: #9aa3ae;
    --rule: #2c333d; --link: #96b8e8; --mark: #e6cb3f; --on-mark: #18202c;
    --print: #262c35; --shade: rgba(5, 7, 10, 0.9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11151b; --panel: #1a2029; --ink: #e4e2da; --muted: #9aa3ae;
  --rule: #2c333d; --link: #96b8e8; --mark: #e6cb3f; --on-mark: #18202c;
  --print: #262c35; --shade: rgba(5, 7, 10, 0.9);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.125rem;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; z-index: 10;
  height: env(safe-area-inset-top, 0px); background: var(--paper);
}
img { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: 0.15em; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
p, h1, h2, figure, blockquote { margin: 0; }

/* ---------- chapter navigation ---------- */
.rail {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
}
.rail ol {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 1.25rem; overflow-x: auto; scrollbar-width: none;
}
.rail ol::-webkit-scrollbar { display: none; }
.rail a {
  display: block; padding-block: 0.8rem; white-space: nowrap;
  font-family: var(--typed); font-size: 0.8rem; line-height: 1.3;
  color: var(--muted); text-decoration: none;
}
.rail a span { display: none; }
.rail a:hover { color: var(--ink); }
.rail a[aria-current="true"] { color: var(--ink); box-shadow: inset 0 -3px 0 var(--mark); }
.rail .home { display: none; }

/* ---------- page frame ---------- */
.page {
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  padding-block: 2.5rem 4rem;
  max-width: 78rem; margin-inline: auto;
}
main { min-width: 0; display: flex; flex-direction: column; gap: 5rem; }

@media (min-width: 68rem) {
  .frame { display: grid; grid-template-columns: 15rem minmax(0, 1fr); max-width: 82rem; margin-inline: auto; }
  .rail {
    align-self: start; top: 0; height: 100vh; overflow-y: auto;
    border-bottom: 0; border-right: 1px solid var(--rule);
    padding-block: 3rem 2rem; padding-right: 1.25rem;
  }
  .rail .home {
    display: block; margin-bottom: 1.75rem;
    font-family: var(--display); font-weight: 700; font-size: 1.15rem; line-height: 1.2;
    color: var(--ink); text-decoration: none;
  }
  .rail ol { flex-direction: column; gap: 0; overflow: visible; }
  .rail a { padding-block: 0.45rem; padding-left: 0.75rem; white-space: normal; font-size: 0.78rem; }
  .rail a span { display: block; font-family: var(--body); font-size: 0.98rem; color: inherit; }
  .rail a[aria-current="true"] { box-shadow: inset 3px 0 0 var(--mark); }
  .page { padding-left: 3.5rem; padding-block: 4rem 5rem; margin-inline: 0; }
  html { scroll-padding-top: 2rem; }
}

/* ---------- opening ---------- */
.opening { display: grid; gap: 2rem; align-items: end; max-width: var(--wide); }
.opening .name {
  font-family: var(--typed); font-size: 0.9rem; letter-spacing: 0.04em;
  margin-bottom: 1rem;
}
.opening .name b { background: var(--mark); color: var(--on-mark); padding: 0.15em 0.45em; font-weight: 400; }
h1 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2.6rem, 8vw, 4.75rem); line-height: 1; letter-spacing: -0.015em;
  text-wrap: balance;
}
h1 em { font-style: italic; }
.lede { margin-top: 1.5rem; font-size: 1.3rem; line-height: 1.5; max-width: 32rem; }
.opening figure img { max-width: min(100%, 20rem); }
@media (min-width: 46rem) {
  .opening { grid-template-columns: minmax(0, 1fr) minmax(0, 17rem); gap: 3rem; }
}

/* ---------- chapters ---------- */
.chapter { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.chapter > * { max-width: var(--text); min-width: 0; }
.chapter > header { border-top: 1px solid var(--ink); padding-top: 1rem; max-width: var(--wide); margin-bottom: 0.5rem; }
.years {
  display: inline-block; font-family: var(--typed); font-size: 0.9rem;
  background: var(--mark); color: var(--on-mark); padding: 0.1em 0.5em; margin-bottom: 0.75rem;
}
h2 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 2.9rem); line-height: 1.1; text-wrap: balance;
}

/* ---------- photographs and documents ---------- */
/* Pictures are plain blocks (never flex or grid items), so their height always follows their width. */
figure { display: block; margin-block: 0.5rem; }
figure > figcaption, figure > .pair + figcaption { margin-top: 0.6rem; }
figure img {
  display: block; width: auto; height: auto; max-width: 100%; cursor: zoom-in;
  background: var(--print); padding: 5px; border: 1px solid var(--rule);
}
figcaption, .credit {
  font-family: var(--typed); font-size: 0.82rem; line-height: 1.5; color: var(--muted);
  max-width: 38rem;
}
.chapter > .wide { max-width: var(--wide); }
.chapter > .pair, .chapter > .trio { max-width: var(--wide); }
.pair, .trio { display: grid; gap: 1.25rem; align-items: start; margin-block: 0.5rem; }
.pair { grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.trio { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
.pair figure, .trio figure { margin: 0; }

/* a small picture with its note alongside */
.chapter > .beside { max-width: 48rem; }
.beside { display: grid; gap: 1.25rem; align-items: start; margin-block: 0.5rem; }
.beside figure { margin: 0; }
.beside > div { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
@media (min-width: 40rem) {
  .beside { grid-template-columns: minmax(0, var(--fig, 15rem)) minmax(0, 1fr); gap: 1.75rem; }
}

/* ---------- quotations ---------- */
blockquote { font-family: var(--display); font-size: 1.3rem; line-height: 1.45; font-style: italic; }
blockquote p + p { margin-top: 0.9rem; }
blockquote footer, .transcript-label {
  font-family: var(--typed); font-style: normal; font-size: 0.82rem; line-height: 1.5;
  color: var(--muted); margin-top: 0.8rem;
}
.transcript {
  background: var(--panel); padding: 1.5rem clamp(1rem, 4vw, 2rem);
  display: flex; flex-direction: column; gap: 1rem;
}
.transcript p { text-indent: 1.5em; }
.transcript .transcript-label { text-indent: 0; margin: 0; }

/* ---------- closing ---------- */
.colophon {
  border-top: 1px solid var(--rule); padding-top: 1.5rem; max-width: var(--wide);
  font-family: var(--typed); font-size: 0.82rem; line-height: 1.6; color: var(--muted);
  display: flex; flex-direction: column; gap: 0.75rem;
}

/* ---------- photo viewer ---------- */
dialog.viewer {
  border: 0; padding: 0; margin: 0; width: 100vw; height: 100vh; height: 100dvh;
  max-width: none; max-height: none; background: var(--shade); color: #e9e7df;
}
dialog.viewer::backdrop { background: transparent; }
.viewer-inner {
  min-height: 100%; display: grid; align-content: center; justify-items: center; gap: 1rem;
  padding: calc(3.5rem + env(safe-area-inset-top, 0px)) var(--gutter-r) calc(1.5rem + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
}
.viewer-inner img { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 11rem); max-height: calc(100dvh - 11rem); background: #fff; padding: 6px; cursor: zoom-out; }
.viewer-inner p { font-family: var(--typed); font-size: 0.85rem; line-height: 1.5; max-width: 46rem; text-align: center; margin: 0; }
.viewer-close {
  position: absolute; top: calc(0.75rem + env(safe-area-inset-top, 0px)); right: var(--gutter-r);
  font-family: var(--typed); font-size: 0.9rem; color: #e9e7df; background: none;
  border: 1px solid currentColor; padding: 0.35rem 0.8rem; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@media print { .rail, dialog { display: none; } }

/* several pictures sharing one caption */
.group > .pair { width: 100%; margin: 0; }
.group > .pair .cell { display: block; min-width: 0; }
figcaption sup, p sup { line-height: 0; }
