/* Lost Cabin Consulting: book reader (read/*.html), loaded after styles.css.
   A slim toolbar under the site header, then the book's pages, white on a dark stage, one under
   the other. assets/js/reader.js draws the pages with PDF.js (assets/vendor/pdfjs-6.4.299). */

/* The reader is a page of Free Tools: its menu link shows as current. */
.nav a[aria-current='true'] { color: var(--gold); }

.reader-head { padding-bottom: 14px; }
.reader-head h1 { margin-bottom: 0.3em; }
.reader-crumbs { margin: 0 0 6px; font-size: 0.86rem; color: var(--muted); }
.reader-crumbs a { color: var(--muted); }
.reader-crumbs a:hover { color: var(--gold); }

.reader { --bar-h: 52px; --page-gap: 14px; --stage-pad: 16px; }
.reader:focus { outline: none; }

/* ---------- Toolbar (stays under the site header while reading) ---------- */
.reader-bar { position: sticky; top: var(--header-h); z-index: 50; background: var(--navy-900); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.reader-bar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; min-height: var(--bar-h); }
.reader-title { flex: 1 1 0; min-width: 0; margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--parchment); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-group { display: flex; align-items: center; gap: 4px; flex: none; }
.rbtn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 34px; height: 34px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 4px;
  background: transparent; color: var(--parchment); font: 500 0.85rem/1 var(--font-body); cursor: pointer;
}
.rbtn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rbtn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.rbtn:disabled { opacity: 0.4; cursor: default; }
.reader-zoom { min-width: 58px; font-variant-numeric: tabular-nums; }
.reader-pageno { display: inline-flex; align-items: center; gap: 6px; margin: 0 4px; font-size: 0.9rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
/* The go-to box shows the printed page ("28", "v", "Cover"); reader.js sets --chars to fit it. */
.reader-pageno input {
  width: calc(var(--chars, 3) * 1ch + 1.4em); min-width: 3.4em; max-width: 9em; height: 34px; padding: 0 4px;
  text-align: center; text-overflow: ellipsis;
  font: 500 0.95rem/1 var(--font-body); color: var(--parchment);
  background: var(--navy-850); border: 1px solid var(--line-strong); border-radius: 4px;
}
.reader-pageno input:hover:not(:disabled) { border-color: var(--gold-line); }
.reader-pageno input:disabled { opacity: 0.6; }
.reader-narrow { display: none; }
/* The PDF button lines up with the other controls. */
.reader-dl { flex: none; display: inline-flex; align-items: center; gap: 0.3em; height: 34px; }

/* ---------- Stage: the dark area that holds the pages ---------- */
.reader-stage { background: var(--navy-950); border-bottom: 1px solid var(--line); padding: 14px 0 28px; }
.reader-note { max-width: 760px; margin: 0 auto 14px; padding: 0 16px; text-align: center; font-size: 0.86rem; color: var(--muted); }
.reader-note a { color: var(--muted); }
.reader-note a:hover { color: var(--gold); }
.reader-status { max-width: 360px; margin: 40px auto; padding: 0 16px; text-align: center; font-size: 0.92rem; color: var(--muted); }
.reader-status p { margin: 0; }
.reader-progress { height: 3px; margin-top: 10px; background: var(--line); border-radius: 2px; overflow: hidden; }
.reader-progress span { display: block; width: 0; height: 100%; background: var(--gold); transition: width 0.2s ease-out; }
.reader-error { max-width: 560px; margin: 24px auto; padding: 14px 18px; background: var(--navy-850); border: 1px solid var(--gold-line); border-left: 3px solid var(--gold); border-radius: 6px; font-size: 0.95rem; }
.reader-stage > .reader-error { margin-left: 16px; margin-right: 16px; }
@media (min-width: 600px) { .reader-stage > .reader-error { margin-left: auto; margin-right: auto; } }
.reader-error p { margin: 0 0 0.6em; }
.reader-error .item-foot { margin: 0; }
.reader-end { margin: 18px auto 0; padding: 0 16px; text-align: center; font-size: 0.86rem; color: var(--muted); }

/* Pages zoomed wider than the screen scroll sideways here, never the whole page. */
.reader-scroller { overflow-x: auto; overflow-y: hidden; }
.reader-pages {
  display: flex; flex-direction: column; align-items: center; gap: var(--page-gap);
  width: max-content; min-width: 100%; padding: 0 var(--stage-pad);
}
.rpage {
  --user-unit: 1;
  --total-scale-factor: calc(var(--scale-factor, 1) * var(--user-unit));
  --scale-round-x: 1px;
  --scale-round-y: 1px;
  position: relative; flex: none; direction: ltr; overflow: hidden;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}
.rpage > canvas { position: absolute; top: 0; left: 0; display: block; width: 100%; height: 100%; }
/* The page number shows on a page until its picture is drawn. */
.rpage-label { position: absolute; top: 50%; left: 0; right: 0; margin-top: -0.7em; text-align: center; font-size: 0.85rem; color: #8a8f99; pointer-events: none; }
.rpage.is-drawn .rpage-label { display: none; }
.rpage.is-failed .rpage-label { color: #8a5a1f; }

/* Links inside the book (contents, cross references). */
.rlinks { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.rlinks a { position: absolute; display: block; pointer-events: auto; border-radius: 2px; }
.rlinks a:hover { background: rgba(212, 169, 95, 0.18); }
.rlinks a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; background: rgba(212, 169, 95, 0.18); }

/* ---------- Selectable text over each page (PDF.js text layer) ----------
   Adapted from PDF.js 6.4.299 web/pdf_viewer.css (Apache-2.0), written without CSS nesting so
   older browsers read it too. The text is transparent: only the selection shows. */
.textLayer {
  position: absolute; inset: 0; overflow: hidden; overflow: clip; z-index: 0;
  text-align: initial; opacity: 1; line-height: 1; letter-spacing: normal; word-spacing: normal;
  -webkit-text-size-adjust: none; -moz-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 span, .textLayer br {
  color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%;
  -webkit-user-select: text; -moz-user-select: text; 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 span[role='img'] { -webkit-user-select: none; -moz-user-select: none; user-select: none; cursor: default; }
.textLayer ::-moz-selection { background: rgba(0, 0, 255, 0.25); color: transparent; }
.textLayer ::selection { background: rgba(0, 0, 255, 0.25); color: transparent; }
.textLayer br::-moz-selection { background: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; -webkit-user-select: none; -moz-user-select: none; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }

/* ---------- Phones and narrow windows ---------- */
/* The page heading above already names the book: the toolbar drops its title before it gets cut off. */
@media (max-width: 960px) {
  .reader-title { display: none; }
  .reader-bar-row { justify-content: space-between; }
}
@media (max-width: 600px) {
  .reader { --bar-h: 50px; --page-gap: 10px; --stage-pad: 8px; }
  .reader-bar .wrap { padding: 0 10px; }
  .reader-wide { display: none; }
  .reader-narrow { display: inline; }
  .reader-zoom { display: none; }
  .reader-pageno { margin: 0 2px; gap: 5px; }
  .reader-pageno input { min-width: 3em; max-width: 4.6em; }
  .reader-stage { padding-top: 12px; }
}
@media (pointer: coarse) {
  .rbtn { min-width: 38px; height: 38px; }
  .reader-pageno input { height: 38px; font-size: 1rem; }
  .reader-dl { height: 38px; }
}
/* The smallest phones (320 to 360px): tighter spacing so the bar still fits on one line. */
@media (max-width: 360px) {
  .reader-bar .wrap { padding: 0 6px; }
  .reader-bar-row { gap: 4px; }
  .reader-group { gap: 2px; }
  .rbtn { min-width: 32px; padding: 0 4px; }
  .reader-pageno { gap: 4px; margin: 0 1px; }
  .reader-pageno input { min-width: 2.6em; max-width: 4em; padding: 0 2px; }
  .reader-dl { padding: 0 8px; }
}
/* A phone held sideways: the site header scrolls away (it comes back with the menu), so only the
   slim toolbar stays on screen while reading. reader.js reads the toolbar position from here. */
@media (max-height: 500px) {
  .site-header { position: relative; }
  body.menu-open .site-header { position: sticky; }
  .reader-bar { top: 0; }
}
