:root {
  --bg: #f6f2e9;
  --panel: #fbf8f2;
  --ink: #2a2520;
  --muted: #847a6c;
  --rule: #ddd3c1;
  --accent: #8a2e1c;
  --accent-soft: rgba(138, 46, 28, 0.09);
  --accent-firm: rgba(138, 46, 28, 0.22);
  --boswell: #8a2e1c;
  --editor: #4f6b52;
  --hill: #4c5f73;
  --current: rgba(138, 46, 28, 0.06);
  --sb-track: rgba(42, 37, 32, 0.045);
  --sb-thumb: rgba(132, 122, 108, 0.55);
  --sb-thumb-hover: rgba(132, 122, 108, 0.85);
  --header-h: 34px;
  --year-w: 64px;
  --dur: 300ms;
  --mark-opacity: .75;
  /* search hits: amber, so they never read as the pink of "current" */
  --hit: rgba(226, 168, 28, 0.32);
  --hit-cur: rgba(226, 150, 0, 0.75);
  --hit-tick: rgba(214, 145, 0, 0.95);
  --hit-tick-cur: rgb(150, 70, 0);
  --serif: "EB Garamond", Garamond, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916; --panel: #211f1b; --ink: #e8e1d4; --muted: #9a907f; --rule: #3a352d;
    --accent: #d77a5f; --accent-soft: rgba(215, 122, 95, 0.14); --accent-firm: rgba(215, 122, 95, 0.32); --boswell: #d77a5f;
    --editor: #8fb393; --hill: #94a9bf; --current: rgba(215, 122, 95, 0.09);
    --sb-track: rgba(232, 225, 212, 0.05); --sb-thumb: rgba(154, 144, 127, 0.5); --sb-thumb-hover: rgba(154, 144, 127, 0.8);
    --hit: rgba(240, 190, 60, 0.28); --hit-cur: rgba(240, 180, 40, 0.6); --hit-tick: rgba(240, 190, 60, 0.95); --hit-tick-cur: rgb(255, 225, 140);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1916; --panel: #211f1b; --ink: #e8e1d4; --muted: #9a907f; --rule: #3a352d;
  --accent: #d77a5f; --accent-soft: rgba(215, 122, 95, 0.14); --accent-firm: rgba(215, 122, 95, 0.32); --boswell: #d77a5f;
  --editor: #8fb393; --hill: #94a9bf; --current: rgba(215, 122, 95, 0.09);
    --sb-track: rgba(232, 225, 212, 0.05); --sb-thumb: rgba(154, 144, 127, 0.5); --sb-thumb-hover: rgba(154, 144, 127, 0.8);
    --hit: rgba(240, 190, 60, 0.28); --hit-cur: rgba(240, 180, 40, 0.6); --hit-tick: rgba(240, 190, 60, 0.95); --hit-tick-cur: rgb(255, 225, 140);
  color-scheme: dark;
}
@media (prefers-reduced-motion: reduce) { :root { --dur: 0ms; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font-family: var(--serif); }

#rails { display: flex; height: 100vh; width: 100vw; }

/* ---------------------------------------------------------------- rails */
.rail {
  position: relative; height: 100%; flex: none; overflow: hidden;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--rule);
  transition: width var(--dur) cubic-bezier(.2, .7, .2, 1);
  background: var(--panel);
}
.rail.reading { background: var(--bg); }
.rail > header {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; font: 600 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--rule); white-space: nowrap; overflow: hidden;
}
.rail.focused > header { color: var(--accent); }
.scroller {
  flex: 1; overflow-y: auto; overflow-x: hidden; overflow-anchor: none; outline: none;
  /* its own compositing layer: without it Safari repaints across rails on every
     scroll step (158 ms a frame instead of 17 when measured) */
  will-change: transform;
}
.inner { container-type: inline-size; padding: 35vh 0 70vh; }

/* Styled scroll bars, which macOS Safari and Chrome keep visible at rest, so
   every rail shows where it is even when nothing is moving. Chrome ignores
   these if scrollbar-width/-color are set, so those are for Firefox only. */
.scroller::-webkit-scrollbar { width: 16px; }  /* wide enough to aim at a search tick without straying into the next rail */
.scroller::-webkit-scrollbar-track { background: var(--sb-track); }
.scroller::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: 8px; min-height: 32px; border: 3px solid transparent; background-clip: padding-box; }
.scroller::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); background-clip: padding-box; }
@supports not selector(::-webkit-scrollbar) {
  .scroller { scrollbar-width: auto; scrollbar-color: var(--sb-thumb) var(--sb-track); }
}

/* ---------------------------------------------------------------- reading */
.reading .inner { padding-left: 76px; padding-right: 40px; font-size: 18.5px; line-height: 1.58; }
.voldiv { border: 0; border-top: 1px solid var(--rule); margin: 3em 0 2.5em; }
/* no automatic hyphenation: across all five volumes it costs ~3.5 s of layout */
.para { position: relative; margin: 0; text-indent: 1.3em; }
.para.verse { text-indent: 0; padding-left: 2.2em; margin: .5em 0; }
.pg {
  display: inline-block; width: 0; height: .95em; vertical-align: -0.12em;
  border-left: 1.5px solid var(--accent); margin: 0 2px; opacity: .55;
}
.pg::before {
  content: attr(data-label); position: absolute; left: -66px; width: 52px; text-align: right;
  font: 500 11px/1.6 var(--sans); letter-spacing: .02em; color: var(--muted); text-indent: 0;
  font-variant-numeric: tabular-nums;
}
.nm {
  color: var(--accent); font: 600 10px/0 var(--sans); padding: 0 1px; cursor: pointer;
  vertical-align: super;
}
.nm.hl, .say.hl { background: var(--accent-soft); outline: 1px solid var(--accent); border-radius: 2px; }
.say { background: var(--accent-soft); border-radius: 2px; cursor: pointer; box-decoration-break: clone; }
/* the current note's marker becomes a badge (halo via box-shadow, so no reflow);
   the current saying's shading deepens */
.nm.cur { background: var(--accent); color: var(--bg); border-radius: 3px; box-shadow: 0 0 0 2.5px var(--accent); }
.say.cur { background: var(--accent-firm); }

/* ---------------------------------------------------------------- companions */
.item { padding: 7px 14px 9px; border-left: 3px solid transparent; cursor: pointer; }
.item.cur { background: var(--current); border-left-color: var(--accent); }
.loc { font: 500 11px/1.4 var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.who { font: 600 10px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase; margin-left: 6px; }

.note .nb { font-size: 15px; line-height: 1.45; margin-top: 2px; }
.note.hill { border-left-color: transparent; }
.note.boswell .who { color: var(--boswell); }
.note.editor .who { color: var(--editor); }
.note.boswell .nb { font-style: normal; }

.saying .kw { font: 600 10.5px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.saying blockquote { margin: 3px 0 2px; font-size: 16px; line-height: 1.42; }
.saying.approx .loc::after { content: " \00b7 page only"; }

.yearhead {
  position: sticky; top: 0; z-index: 1; padding: 10px 14px 4px; background: var(--panel);
  font: 600 13px/1 var(--sans); color: var(--ink); font-variant-numeric: tabular-nums;
}
.event .ev { font-size: 15px; line-height: 1.4; }

/* Index rail: one row per reference of the chosen heading, in book order */
.ixrow .ixpath { font: 500 10.5px/1.35 var(--sans); color: var(--muted); margin-top: 1px; }
.ixrow .ixl { font-size: 15px; line-height: 1.4; margin-top: 1px; }
.ixrow .ixh { font-variant: small-caps; }
/* the whole index: Hill's lines for one place, each opening with its heading */
.ixgroup .ixline { font-size: 14.5px; line-height: 1.35; margin-top: 3px; }
.ixgroup .ixh { font: 600 10.5px/1.3 var(--sans); letter-spacing: .04em; color: var(--accent); cursor: pointer; }
.ixgroup .ixh:hover { text-decoration: underline; }
.ixgroup .ixh.minor { font-weight: 500; color: var(--muted); }
.ixgroup.approx .loc::after { content: " \00b7 page only"; }
.rail > header .ixall {
  flex: none; border: 1px solid var(--rule); background: var(--bg); color: var(--accent);
  font: 600 10.5px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer; padding: 4px 7px 4px 5px; border-radius: 4px;
}
.rail > header .ixall:hover { border-color: var(--accent); background: var(--current); }
.rail > header .title { min-width: 0; }
.ixrow.approx .loc::after { content: " \00b7 page only"; }
/* the passage the current index row points to, shaded once the rail lands;
   the one under the pointer, outlined in the same colour */
::highlight(ix-cur) { background-color: var(--accent-firm); }
::highlight(ix-hover) { background-color: var(--accent-soft); }
/* the page an index row points to (shadow, not border: no reflow) */
.pg.cur, .pg.hl { opacity: 1; box-shadow: -1.5px 0 0 var(--accent); }

/* glance forms: narrow rails change shape rather than squeeze prose. Notes and
   sayings keep their full text at the same size, enough to judge whether an
   entry is worth widening the rail for; timeline entries clamp to one line. */
@container (max-width: 240px) {
  .item { padding: 5px 10px 7px 8px; }
  .event .ev {
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
    font-size: 13px; line-height: 1.35;
  }
  .saying .kw { font-size: 10px; }
  .yearhead { padding: 6px 10px 2px; font-size: 12px; }
}

/* ---------------------------------------------------------------- year rail */
.yearrail { width: var(--year-w); background: var(--panel); cursor: ns-resize; user-select: none; touch-action: none; }
.years { position: absolute; inset: var(--header-h) 0 0 0; display: flex; flex-direction: column; }
.yr {
  flex: 1 1 0; min-height: 0; position: relative;
  font: 500 11px/1 var(--sans); color: var(--muted); font-variant-numeric: tabular-nums;
}
/* rows are often only a few px tall: years are labelled only where they fit */
.yr .y { position: absolute; left: 7px; top: 0; transform: translateY(-50%); background: var(--panel); padding: 1px 2px 1px 0; visibility: hidden; z-index: 1; }
.yr.lab .y { visibility: visible; }
.yr.vs { border-top: 1px solid var(--muted); }
.yr .bar { position: absolute; right: 6px; top: 0.5px; bottom: 0.5px; background: var(--rule); border-radius: 1px; }
.yr.cur { color: var(--accent); }
.yr.cur .bar { background: var(--accent); opacity: .45; }
.yind { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--accent); pointer-events: none; z-index: 2; }
.yind span {
  position: absolute; top: 3px; left: 4px; font: 500 10px/1.25 var(--sans); color: var(--accent);
  background: var(--panel); padding: 1px 2px; white-space: nowrap; z-index: 3;
}
.yind b { font-weight: 700; font-size: 11px; }
.yind.up span { top: auto; bottom: 3px; }

/* the reading line, where every rail's current item sits, is marked by a pair
   of arrowheads at each rail's edges rather than drawn across the content.
   35% of the way down the scroller (READ_LINE in app.js). */
.mk {
  position: absolute; z-index: 3; pointer-events: none; width: 0; height: 0;
  top: calc(var(--header-h) + (100% - var(--header-h)) * 0.35 - 4.5px);
  border-style: solid; border-color: transparent; opacity: var(--mark-opacity);
}
.mk.l { left: 0; border-width: 4.5px 0 4.5px 7px; border-left-color: var(--accent); }
.mk.r { right: 16px; border-width: 4.5px 7px 4.5px 0; border-right-color: var(--accent); }  /* just inside the scroll bar */

#leader {
  position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 6;
  opacity: 0; transition: opacity 160ms ease-out; overflow: visible;
}
#leader.on { opacity: 1; }
#leader path { fill: none; stroke: var(--accent); stroke-width: 1.25; }
#leader circle { fill: var(--accent); }

/* ---------------------------------------------------------------- search */
.rail > header .title { overflow: hidden; text-overflow: ellipsis; }
.search { margin-left: auto; display: flex; align-items: center; gap: 2px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.search input {
  font: 13px/1.2 var(--sans); width: 170px; padding: 3px 8px; border: 1px solid var(--rule); border-radius: 5px;
  background: var(--panel); color: var(--ink); outline: none;
}
.search input:focus { border-color: var(--muted); }
.search .count { font: 11px var(--sans); color: var(--muted); margin: 0 4px 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.search button { border: 0; background: none; color: var(--muted); font: 16px/1 var(--sans); cursor: pointer; padding: 2px 4px; border-radius: 3px; }
.search button:hover { color: var(--ink); background: var(--current); }
::highlight(search-hit) { background-color: var(--hit); }
::highlight(search-cur) { background-color: var(--hit-cur); color: var(--ink); }
.rail > .ticks { position: absolute; right: 0; pointer-events: none; z-index: 4; }
.rail > .ticks { cursor: pointer; }
.tickhot { position: absolute; right: 0; height: 5px; background: var(--hit-tick-cur); border-radius: 1px; z-index: 5; pointer-events: none; }
.ticklabel {
  position: absolute; transform: translateY(-50%); z-index: 6; pointer-events: none; white-space: nowrap;
  font: 600 10.5px/1 var(--sans); font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: 3px 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* index headings and sub-entries matching the search, under the box */
.ixmenu {
  position: fixed; z-index: 10; width: 360px; max-height: 60vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14); padding: 4px 0;
}
.ixmenu .mi {
  padding: 4px 10px; font-size: 15px; line-height: 1.3; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ixmenu .mi.sub { font-size: 14px; }
.ixmenu .mi .mh { color: var(--muted); }
.ixmenu .mi.sub:first-of-type, .ixmenu .mi:not(.sub) + .mi.sub { border-top: 1px solid var(--rule); margin-top: 3px; padding-top: 6px; }
.ixmenu .mi.on { background: var(--current); }
/* No content-visibility: auto on the ~14,000 index items: their heights would
   change as each is first rendered while scrolling, and every change makes the
   rails re-measure and re-place (24 times in 4 s of scrolling in Safari, with
   blank, unpainted rails as the result) */
/* the whole index while one heading is shown: hidden, but its layout is kept */
.ixwhole.off { content-visibility: hidden; }
