/* =====================================================================
   BugOutBot v2 — Library (offline books) + Reader
   Dark nav card for "Continue reading", light reading cards for books,
   8-bit book sprites, reader themes that follow day / night / red.
   ===================================================================== */

.need-btn.is-library { --c: #e8b86e; }
[data-theme="red"] .need-btn.is-library { --c: #ff7a45; }

/* ---------- Library screen ---------- */
.lib-screen { display: flex; flex-direction: column; gap: 12px; padding-top: 2px; }
.lib-head { display: flex; flex-direction: column; gap: 6px; padding: 0 2px; }
.lib-intro { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ui-title); }
.lib-summary {
  align-self: flex-start; margin: 0;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
  padding: 4px 10px; border-radius: 999px;
  background: var(--ui-tile-neutral); color: var(--ui-sub);
}
.lib-body { display: flex; flex-direction: column; gap: 12px; }

/* Continue reading: a dark nav card like Home */
.lib-continue.need-btn { --c: #e8b86e; min-height: 64px; flex-direction: row; align-items: center; gap: 12px; padding: 10px 36px 10px 10px; border-radius: 14px; }
.lib-continue .need-icon { width: 44px; height: 44px; border-radius: 10px; }
.lib-continue .need-icon .need-svg { width: 32px; height: 32px; }
.lib-continue .need-title { font-size: 16px; }
.lib-continue .need-sub { font-size: 12px; margin-top: 1px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; }
.lib-continue .need-text { flex: 1; min-width: 0; }
.lib-continue::after { display: block !important; right: 16px; }

.lib-shelf { display: flex; flex-direction: column; gap: 8px; }
.lib-shelf-title { margin: 6px 2px 0 !important; font-size: 10.5px !important; }
.lib-shelf-note { margin: -2px 2px 2px; font-size: 12px; line-height: 1.35; color: var(--ui-sub); }

/* Light reading cards */
.lib-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px 10px 10px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-hairline);
  border-radius: 14px;
  box-shadow: var(--ui-elev);
}
.lib-card.is-saved { border-color: color-mix(in srgb, #4c8a3f 35%, var(--ui-hairline)); }
.lib-card-main {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 0; padding: 0; border: 0; background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lib-card-main:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 3px; border-radius: 10px; }
.lib-cover {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 56px; border-radius: 10px;
  background: var(--ui-tile-neutral);
  box-shadow: inset 0 0 0 1px var(--ui-hairline);
}
.lib-cover .need-svg { width: 40px; height: 40px; image-rendering: pixelated; shape-rendering: crispEdges; }
.lib-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.lib-card-title { font-size: 16px; font-weight: 800; line-height: 1.2; color: var(--ui-title); letter-spacing: -0.005em; }
.lib-card-subtitle { font-size: 12.5px; font-weight: 600; color: var(--ui-sub); }
.lib-card-meta { font-size: 11.5px; font-weight: 600; color: var(--ui-sub); line-height: 1.3; }
.lib-card-blurb {
  margin-top: 2px; font-size: 12.5px; line-height: 1.35; color: var(--ui-title); opacity: 0.86;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.lib-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-left: 60px; }
.lib-saved {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px;
  border-radius: 999px; font-size: 12.5px; font-weight: 800;
  color: #2f6b25; background: rgba(76, 138, 63, 0.13);
}
[data-theme="night"] .lib-saved { color: #a9d48e; background: rgba(120, 180, 90, 0.14); }
[data-theme="red"] .lib-saved { color: #ff8a52; background: rgba(255, 90, 40, 0.12); }
.lib-msg { margin: 0; padding-left: 60px; font-size: 12px; line-height: 1.35; color: var(--ui-sub); }
.lib-msg:empty { display: none; }
.lib-msg.is-error { color: #c0392b; font-weight: 600; }
[data-theme="night"] .lib-msg.is-error, [data-theme="red"] .lib-msg.is-error { color: #ff8a6a; }
.lib-screen > .lib-body > .lib-msg.is-error { padding-left: 2px; }
.lib-foot { margin: 6px 2px 0; font-size: 11.5px; line-height: 1.4; color: var(--ui-sub); }

/* Shared small buttons (library + reader) */
.lib-btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 14px;
  border: 1px solid var(--ui-hairline-strong);
  border-radius: 999px;
  background: var(--ui-surface); color: var(--ui-title);
  font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.lib-btn:active { transform: scale(0.97); background: var(--ui-surface-press); }
.lib-btn:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.lib-btn[disabled] { opacity: 0.45; cursor: default; transform: none; }
.lib-btn.is-quiet { border-color: transparent; background: transparent; color: var(--ui-sub); padding: 6px 8px; }
.lib-btn.is-save { border-color: color-mix(in srgb, var(--bob-accent) 55%, transparent); color: var(--bob-accent); }
.lib-btn.is-primary { background: var(--bob-accent); border-color: transparent; color: #1a1712; }
.lib-btn.is-primary:active { background: #ea5f22; }
.lib-btn-bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: color-mix(in srgb, var(--bob-accent) 18%, transparent);
  transition: width 0.2s ease;
}
.lib-btn-label { position: relative; }
.lib-spinner {
  display: none; position: relative;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: lib-spin 0.8s linear infinite;
}
.lib-btn.is-busy .lib-spinner { display: inline-block; }
.lib-btn.is-busy[disabled] { opacity: 1; }
@keyframes lib-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .lib-spinner { animation-duration: 2.4s; } }

/* ---------- Reader ---------- */
/* Solid top bar over the reading page so big text doesn't show through */
body:has(.lib-reader) .topbar { background: var(--bob-page); backdrop-filter: none; }

.lib-reader {
  --rd-size: 18px;
  --rd-bg: #fbf8f2; --rd-ink: #22201a; --rd-muted: #6e685b; --rd-line: rgba(34, 32, 26, 0.12);
  --rd-chip: rgba(34, 32, 26, 0.06); --rd-accent: #c2541f; --rd-note-bg: #fff1e2; --rd-note-line: rgba(194, 84, 31, 0.28);
  --rd-plate: #fffdf8;
  margin: -12px -14px -24px;
  min-height: calc(100dvh - var(--bob-top-h) - var(--bob-nav-h));
  background: var(--rd-bg); color: var(--rd-ink);
  padding-bottom: 28px;
}
.lib-reader[data-rtheme="sepia"] {
  --rd-bg: #f3e7cf; --rd-ink: #3b2d1c; --rd-muted: #7c6649; --rd-line: rgba(59, 45, 28, 0.15);
  --rd-chip: rgba(59, 45, 28, 0.07); --rd-accent: #a4481b; --rd-note-bg: #ecd9b6; --rd-note-line: rgba(164, 72, 27, 0.3);
  --rd-plate: #faf3e3;
}
.lib-reader[data-rtheme="dark"] {
  --rd-bg: #141712; --rd-ink: #d9d3c3; --rd-muted: #8e9587; --rd-line: rgba(217, 211, 195, 0.12);
  --rd-chip: rgba(217, 211, 195, 0.07); --rd-accent: #ff8a52; --rd-note-bg: #2a2018; --rd-note-line: rgba(255, 138, 82, 0.28);
  --rd-plate: #d9d3c3;
}
.lib-reader[data-rtheme="red"] {
  --rd-bg: #0d0200; --rd-ink: #ff7048; --rd-muted: #b5502a; --rd-line: rgba(255, 90, 40, 0.18);
  --rd-chip: rgba(255, 90, 40, 0.08); --rd-accent: #ff6b2b; --rd-note-bg: #1f0600; --rd-note-line: rgba(255, 90, 40, 0.3);
  --rd-plate: #2a0800;
}

.lib-toolbar {
  position: sticky; z-index: 20;
  top: calc(var(--bob-top-h, 52px) + var(--bob-safe-top, 0px) + 9px);
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  padding: 8px 12px;
  background: var(--rd-bg);
  border-bottom: 1px solid var(--rd-line);
}
.lib-tool-gap { flex: 1; }
.lib-tool, .lib-seg-btn {
  min-height: 34px; min-width: 38px; padding: 4px 9px;
  border: 1px solid var(--rd-line); border-radius: 9px;
  background: var(--rd-chip); color: var(--rd-ink);
  font: inherit; font-size: 13px; font-weight: 700; line-height: 1;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.lib-tool:active, .lib-seg-btn:active { transform: scale(0.96); }
.lib-tool:focus-visible, .lib-seg-btn:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: 1px; }
.lib-tool[disabled] { opacity: 0.4; cursor: default; }
.lib-tool-big { font-size: 15px; }
.lib-tool-toc { padding: 4px 10px; white-space: nowrap; }
.lib-seg { display: inline-flex; border: 1px solid var(--rd-line); border-radius: 10px; overflow: hidden; margin-left: 2px; }
.lib-seg-btn { border: 0; border-radius: 0; min-width: 0; padding: 4px 7px; font-size: 12px; background: transparent; }
.lib-seg-btn + .lib-seg-btn { border-left: 1px solid var(--rd-line); }
.lib-seg-btn.is-on { background: var(--rd-ink); color: var(--rd-bg); }
.lib-red-note { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--rd-muted); padding: 0 4px; }
.lib-red-note[hidden], .lib-seg[hidden] { display: none; }

.lib-page {
  max-width: 34em; margin: 0 auto;
  padding: 18px 20px 8px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
  font-size: var(--rd-size); line-height: 1.62;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word; hyphens: auto;
}
.lib-loading { color: var(--rd-muted); font-size: 15px; }
.lib-page p.lib-verse { padding-left: 0.9em; border-left: 2px solid var(--rd-line); font-size: 0.94em; line-height: 1.5; }
.lib-page p { margin: 0 0 0.85em; }
.lib-page ul { margin: 0 0 0.9em; padding-left: 1.2em; }
.lib-page li { margin: 0 0 0.35em; }
.lib-kicker {
  margin: 0 0 4px !important;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--rd-muted);
}
.lib-ch-title, .lib-title {
  margin: 0 0 0.8em;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 800; letter-spacing: -0.01em; line-height: 1.22;
  color: var(--rd-ink);
}
.lib-ch-title { font-size: 1.25em; }
.lib-title { font-size: 1.6em; margin-bottom: 0.25em; }
.lib-byline { color: var(--rd-muted); font-size: 0.9em; margin-bottom: 1em !important; }
.lib-sub {
  margin: 1.3em 0 0.5em;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95em; font-weight: 800; line-height: 1.3; color: var(--rd-ink);
}
.lib-pre {
  margin: 0 0 1em; padding: 0.2em 0 0.2em 0.9em;
  border-left: 2px solid var(--rd-line);
  white-space: pre-wrap; font-family: inherit; font-size: 0.92em; line-height: 1.5;
  font-style: italic; color: var(--rd-ink);
}
.lib-pre.is-table {
  font-style: normal; white-space: pre; overflow-x: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.68em;
  border-left: 0; padding: 0.6em 0.7em; border-radius: 8px; background: var(--rd-chip);
}
.lib-note {
  margin: 0 0 1em !important; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--rd-note-line); background: var(--rd-note-bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px; line-height: 1.45; color: var(--rd-ink);
}
.lib-note strong { color: var(--rd-accent); }
.lib-extra {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px; line-height: 1.45; color: var(--rd-muted);
}
.lib-source {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12px; line-height: 1.45; color: var(--rd-muted);
  padding-top: 8px; border-top: 1px solid var(--rd-line);
}
.lib-cover-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 14px; font-family: system-ui, -apple-system, sans-serif; }
.lib-reader .lib-btn { --ui-surface: var(--rd-chip); --ui-title: var(--rd-ink); --ui-hairline-strong: var(--rd-line); --ui-surface-press: var(--rd-line); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.lib-reader .lib-btn.is-primary { background: var(--rd-accent); color: #fffaf3; }
.lib-reader[data-rtheme="red"] .lib-btn.is-primary,
.lib-reader[data-rtheme="dark"] .lib-btn.is-primary { color: #1a0a02; }

.lib-toc-title {
  margin: 0.6em 0 0.4em;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--rd-muted);
}
.lib-toc { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rd-line); }
.lib-toc li { margin: 0; border-bottom: 1px solid var(--rd-line); }
.lib-toc-btn {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 10px 2px; border: 0; background: transparent; color: var(--rd-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.35; text-align: left; cursor: pointer;
}
.lib-toc-btn:active { background: var(--rd-chip); }
.lib-toc-btn:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: -2px; }
.lib-toc-n { flex: 0 0 1.8em; font-size: 12px; font-weight: 800; color: var(--rd-muted); text-align: right; }
.lib-toc-t { flex: 1; }
.lib-toc-btn.is-current .lib-toc-t { color: var(--rd-accent); font-weight: 700; }

.lib-fig {
  margin: 0.4em 0 1.1em; padding: 8px;
  border-radius: 10px; background: var(--rd-plate);
  border: 1px solid var(--rd-line); cursor: zoom-in;
}
.lib-fig img { display: block; width: 100%; height: auto; border-radius: 4px; background: #fff; }
.lib-fig figcaption {
  margin-top: 6px; font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px; line-height: 1.35; color: #4a463c; text-align: center;
}
.lib-reader[data-rtheme="dark"] .lib-fig img { filter: brightness(0.86); }
.lib-reader[data-rtheme="red"] .lib-fig img { filter: invert(1) sepia(1) hue-rotate(-30deg) saturate(4) brightness(0.55); background: transparent; }
.lib-reader[data-rtheme="red"] .lib-fig figcaption { color: var(--rd-muted); }

.lib-chnav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 1.2em 0 0; padding: 14px 0 0;
  border-top: 1px solid var(--rd-line);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.lib-chnav .lib-btn { min-height: 40px; padding: 8px 16px; }
.lib-chnav-n { font-size: 12px; font-weight: 700; color: var(--rd-muted); }

/* Save all (per shelf) */
.lib-saveall { margin: 4px 0 12px; padding: 10px 12px; border: 1px solid var(--ui-hairline); border-radius: 12px; background: var(--ui-surface, transparent); }
.lib-saveall-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lib-saveall-info { margin: 6px 0 0; font-size: 0.85rem; color: var(--ui-sub); }
.lib-saveall-info.is-error { color: #d9534f; }
.lib-saveall-prog { margin-top: 8px; height: 6px; border-radius: 3px; background: var(--ui-hairline); overflow: hidden; }
.lib-saveall-fill { display: block; height: 100%; width: 0; background: var(--bob-accent); transition: width .2s; }
.lib-saveall[data-state="done"] { border-color: color-mix(in srgb, #4c8a3f 35%, var(--ui-hairline)); }

/* bugcheck 2026-11-03: on the cover the contents list is already showing, so hide the greyed Contents
   button, and let A−/A+ scale the cover text too (it only changed chapter text before). */
.lib-tool-toc:disabled { visibility: hidden; }
.lib-coverpage .lib-toc-t { font-size: calc(var(--rd-size) * 0.94); }
.lib-coverpage .lib-extra, .lib-coverpage .lib-source, .lib-coverpage .lib-note { font-size: calc(var(--rd-size) * 0.82); }

/* Phone landscape: reader toolbar can sit a little tighter under the shorter top bar. */
@media (orientation: landscape) and (max-height: 500px) {
  .lib-toolbar { padding: 4px 12px; }
  .lib-tool, .lib-seg-btn { min-height: 32px; }
}
