/* Chapter reader: the book browser's palette (site.css) on a full-height layout.
   The header holds the chapter's place and tools, the side panel this volume's
   contents and every other volume, and the main area the chapter's pages. */
body.reader { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.rbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow); position: relative; z-index: 3; min-width: 0; }
.rbar .ap-home { width: 40px; height: 40px; padding: 4px; border-radius: 10px; flex: none; grid-row: auto; }
.rhead { flex: 1 1 auto; min-width: 0; }
.rcrumb { font-size: 0.8rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcrumb a { color: var(--text-soft); text-decoration: none; }
.rcrumb a:hover { text-decoration: underline; }
.rhead h1 { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtools { display: flex; align-items: center; gap: 8px; flex: none; }
.grp { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.grp .ibtn { border: 0; border-radius: 0; }
.grp .ibtn + .ibtn { border-left: 1px solid var(--border); }
.ibtn { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 8px; font: inherit; font-size: 0.86rem;
  font-weight: 600; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; text-decoration: none; }
.ibtn:hover { background: var(--chip-bg); }
.ibtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ibtn[aria-pressed="true"] { color: var(--accent); }
.ibtn[aria-disabled="true"] { opacity: 0.35; pointer-events: none; }
.ibtn:focus-visible, .pageno input:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.pageno { display: inline-flex; align-items: center; gap: 5px; font-size: 0.86rem; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.pageno input { width: 3.2em; height: 36px; padding: 0 6px; text-align: center; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.rtools .btn.small { height: 36px; }

.rbody { display: grid; grid-template-columns: 300px 1fr; min-height: 0; position: relative; }
body.side-closed .rbody { grid-template-columns: 0 1fr; }
body.side-closed #side { visibility: hidden; }
#side { min-height: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 12px 24px; }
.stabs { display: flex; gap: 6px; margin-bottom: 12px; position: sticky; top: -12px; padding: 12px 0 6px; margin-top: -12px;
  background: var(--surface); z-index: 1; }
.stabs .chip { flex: 1; font-size: 0.85rem; padding: 6px 10px; }
.vhead { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; padding: 8px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 12px; color: inherit; text-decoration: none; }
.vhead:hover { border-color: var(--border-hover); }
.vhead img { width: 64px; height: auto; aspect-ratio: 7 / 10; border-radius: 4px; background: #10203a; display: block; }
.vhead .k { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.vhead .t { font-weight: 700; font-size: 0.92rem; line-height: 1.25; }
.vhead .go { font-size: 0.8rem; color: var(--accent); }
.chlist, .vlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.chlist li { display: flex; align-items: stretch; gap: 4px; }
.chlist li > a:first-child { flex: 1; min-width: 0; }
.chlist a.app { flex: none; display: grid; place-items: center; padding: 0 8px; font-size: 0.75rem; font-weight: 650; color: var(--accent);
  border: 1px solid var(--border); border-left-width: 1px; border-radius: 8px; grid-template-columns: none; }
.chlist a.app:hover { border-color: var(--accent); }
.side-h { margin: 14px 4px 6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.related { margin: 4px 0 6px; padding: 10px; border: 1px solid var(--border); border-radius: 12px; scroll-margin-top: 56px; transition: box-shadow .3s; }
.related.flash { box-shadow: 0 0 0 3px var(--ring); }
.related h2 { margin: 0 0 2px; font-size: 0.92rem; }
.rel-note { margin: 0 0 8px; font-size: 0.78rem; color: var(--text-faint); }
.rlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rlist li { display: grid; gap: 5px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.rlist li:last-child { border-bottom: 0; padding-bottom: 0; }
.rlist .rt { display: grid; grid-template-columns: 1.6rem 1fr; gap: 6px; font-size: 0.86rem; line-height: 1.3; }
.rlist .ic { font-size: 1.1rem; }
.rlist .a { display: block; font-size: 0.76rem; color: var(--text-faint); }
.rlist .ra { display: flex; gap: 6px; padding-left: 1.9rem; }
.rlist .ra .btn { font-size: 0.78rem; padding: 3px 9px; font-weight: 550; }
.rlist .rsub { display: block; margin-top: 4px; padding: 0; border: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
/* Related apps strip above the pages: one scrollable row, visible without the side panel. */
.relstrip { position: sticky; left: 0; top: 0; z-index: 3; display: flex; align-items: center; gap: 8px; padding: 8px 12px; overflow-x: auto;
  scrollbar-width: thin; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 0.84rem; white-space: nowrap; }
.relstrip .rs-h { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); flex: none; }
.relstrip .rs-i { display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 2px 4px 2px 8px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--chip-bg); }
.relstrip a { text-decoration: none; color: var(--text); font-weight: 600; padding: 4px 2px; }
.relstrip a.rs-app:hover { color: var(--accent); }
.relstrip a.rs-ch { color: var(--accent); font-size: 0.78rem; padding: 4px 8px; border-left: 1px solid var(--border); }
.relstrip .rs-more { flex: none; font: inherit; font-size: 0.8rem; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 6px 4px; }
.dl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chlist a { display: grid; grid-template-columns: 1.8rem 1fr; gap: 6px; padding: 7px 8px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-size: 0.88rem; line-height: 1.3; border-left: 3px solid transparent; }
.chlist a:hover { background: var(--chip-bg); }
.chlist a .n { color: var(--text-faint); font-variant-numeric: tabular-nums; font-weight: 650; }
.chlist a .a { display: block; font-size: 0.78rem; color: var(--text-faint); margin-top: 1px; }
.chlist a[aria-current="page"] { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 650; }
.chlist a.off { color: var(--text-faint); }
.vlist a { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; padding: 6px; border-radius: 10px;
  color: var(--text); text-decoration: none; }
.vlist a:hover { background: var(--chip-bg); }
.vlist a[aria-current="true"] { background: var(--accent-soft); }
.vlist img { width: 44px; height: auto; aspect-ratio: 7 / 10; border-radius: 3px; background: #10203a; display: block; }
.vlist .k { font-size: 0.7rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.vlist .t { font-size: 0.86rem; font-weight: 650; line-height: 1.25; }
.vgroup { margin: 12px 4px 4px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.side-foot { margin: 14px 4px 0; font-size: 0.85rem; }

#view { min-height: 0; overflow: auto; overscroll-behavior: contain; position: relative; outline: none;
  background: color-mix(in srgb, var(--bg) 82%, #808894); }
#pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 12px 40px; width: max-content; min-width: 100%; }
.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18), 0 6px 20px -8px rgba(0, 0, 0, 0.3); flex: none;
  --user-unit: 1; --scale-round-x: 1px; --scale-round-y: 1px; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page .links { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.page .links a { position: absolute; pointer-events: auto; border-radius: 2px; }
.page .links a:hover { background: rgba(37, 99, 235, 0.12); outline: 1px solid rgba(37, 99, 235, 0.4); }
.page .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #8a94a6; font-size: 0.9rem; }
.rnote { max-width: 34rem; margin: 12vh auto 0; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); }
.rnote h2 { margin: 0 0 6px; font-size: 1.1rem; }
.rnote p { margin: 0 0 10px; color: var(--text-soft); }

/* pdf.js text layer (from pdfjs-dist web/pdf_viewer.css, trimmed): transparent
   text over the canvas so a reader can select, copy and find words. */
.textLayer { position: absolute; text-align: initial; inset: 0; overflow: clip; opacity: 1; line-height: 1; z-index: 1;
  -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; caret-color: CanvasText;
  --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 0, 255, 0.25); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }

.btn .sm { display: none; }
.chinfo { margin: 0 0 10px; padding: 0 4px; font-size: 0.84rem; color: var(--text-soft); display: grid; gap: 6px; }
.chinfo .acts { display: flex; flex-wrap: wrap; gap: 6px; }
.chinfo .acts .btn { font-size: 0.8rem; padding: 4px 9px; font-weight: 550; }
.chinfo .rel a { white-space: nowrap; }
.citebox { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 18px 20px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-hover); }
.citebox::backdrop { background: rgba(8, 14, 26, 0.5); }
.citebox h2 { margin: 0 0 8px; font-size: 1.05rem; }
.citebox .how { margin: 0 0 10px; font-size: 0.9rem; }
.citebox .stabs { position: static; margin: 0 0 8px; padding: 0; }
.citebox .stabs .chip { flex: none; }
.citebox pre { margin: 0 0 12px; padding: 12px; max-height: 16rem; overflow: auto; font-size: 0.8rem; line-height: 1.45;
  background: var(--chip-bg); border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.scrim { display: none; }
/* On a narrow screen only Fit stays (pinch zoom does the rest), so a zoomed
   page can always be put back to the screen's width. */
@media (max-width: 1000px) {
  .rtools .zoom .ibtn:not(#zoom-fit) { display: none; }
}
@media (max-width: 480px) {
  .pageno { display: none; }
  .rtools .btn.dl { min-width: 44px; padding: 0 10px; }
  .btn .lg { display: none; }
  .btn .sm { display: inline; }
  .pageno input { width: 2.6em; }
  .rtools { gap: 6px; }
}
@media (max-width: 860px) {
  .rbody, body.side-closed .rbody { grid-template-columns: 1fr; }
  #side { position: absolute; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 5; box-shadow: var(--shadow-hover);
    transform: translateX(-102%); transition: transform .18s ease; visibility: hidden; }
  body.side-open #side { transform: none; visibility: visible; }
  body.side-open .scrim { display: block; position: absolute; inset: 0; z-index: 4; background: rgba(8, 14, 26, 0.45); }
  .rbar { gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
  .rhead { flex-basis: calc(100% - 110px); }
  .rtools { width: 100%; justify-content: space-between; }
  #pages { padding: 10px 6px 30px; gap: 10px; }
}
@media (max-width: 420px) {
  .rbar .ap-home { display: none; }
  .rhead { flex-basis: calc(100% - 60px); }
}
@media (pointer: coarse) {
  .ibtn, .pageno input, .rtools .btn.small { min-width: 44px; height: 44px; }
  .chlist a, .vlist a { min-height: 44px; }
  .chlist a.app { min-width: 44px; }
  .rlist .ra .btn, .chinfo .acts .btn { min-height: 44px; padding: 0 14px; }
  .relstrip a, .relstrip .rs-more { min-height: 40px; display: inline-flex; align-items: center; }
  .rcrumb a, .chinfo .rel a, .side-foot a { display: inline-block; padding: 12px 2px; margin: -12px 0; }
  .rcrumb { overflow: visible; }
}
@media print {
  .rbar, #side { display: none; }
  body.reader { display: block; height: auto; overflow: visible; }
}
