:root {
  --bg: var(--tg-theme-bg-color, #f4f1ea);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1c);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --link: var(--tg-theme-link-color, #2678b6);
  --button: var(--tg-theme-button-color, #2678b6);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --shelf-wood: #8a5a3c;
  --shelf-wood-dark: #6e4530;
  --danger: #c0392b;
  --ok: #2e8b57;
}

* { box-sizing: border-box; }

/* Without this, any class below that sets `display` (flex, in particular)
   silently wins over the browser's own "hidden means display:none" default
   whenever both apply to the same element at equal specificity -- author
   CSS always beats the UA stylesheet at a tie, regardless of source order.
   That's exactly what happened here: .sheet-backdrop's `display: flex` was
   overriding `hidden` on #action-sheet-backdrop, so the dark full-screen
   overlay rendered (and ate every tap) even when no menu was open. This
   single !important rule -- the same one Telegram Mini Apps' own recommended
   base CSS uses -- makes `el.hidden = true` always win, for every element,
   permanently, so this bug class can't come back for any future addition. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.view { min-height: 100vh; padding-bottom: 40px; }

.topbar {
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; }
.muted { color: var(--hint); font-size: 13px; margin: 4px 0 0; }

.topbar.shelf-topbar { display: flex; align-items: center; justify-content: space-between; }
.link-btn { border: none; background: rgba(0,0,0,0.06); color: var(--text); padding: 8px 12px; border-radius: 10px; font-size: 13px; flex-shrink: 0; }

/* ---------- Shelf ---------- */

/* A warm, dark wood backdrop behind the whole shelf -- like the inside of
   a real wooden bookcase, rather than the app's plain default background.
   Scoped to #view-shelf only (not the rest of the app) so reading/Q&A/
   quiz panels elsewhere keep their normal, theme-following background --
   deliberately hardcoded browns rather than the Telegram theme variables
   (same choice already made for --shelf-wood/--shelf-wood-dark below) so
   the shelf reads as "wood" consistently in both light and dark Telegram
   themes. The repeating-linear-gradient layer adds faint horizontal grain
   lines on top of the vertical light-to-dark gradient, suggesting a wood
   plank's texture without needing an actual image asset.
   Text/control colors below are overridden to warm cream tones for
   contrast against this dark background, since --text/--hint/--link are
   tuned for the app's normal light backdrop and would be hard to read here. */
#view-shelf {
  min-height: 100vh;
  color: #f1e3cf;
  background:
    repeating-linear-gradient(180deg, rgba(0,0,0,0.06) 0px, rgba(0,0,0,0.06) 2px, transparent 2px, transparent 5px),
    linear-gradient(180deg, #6b4630 0%, #5a3922 45%, #46301f 100%);
}
#view-shelf .topbar { background: linear-gradient(180deg, #6b4630, #5a3922); }
#view-shelf .topbar h1 { color: #f8ecd9; }
#view-shelf .muted { color: #d9c2a3; }
#view-shelf .link-btn { background: rgba(255,255,255,0.18); color: #f8ecd9; }
#view-shelf .book-title-label { color: #f1e3cf; }
#view-shelf .empty-state { color: #e7d3ba; }

.shelf-request-btn { display: block; margin: 4px 16px 4px; }

.empty-state { text-align: center; padding: 60px 20px; }

.shelf-grid {
  padding: 10px 14px 30px;
}

/* Each shelf-row is one "shelf" of small book covers standing side by
   side, closet-style; a shelf-ledge div (a wood plank) is inserted after
   every row by app.js's renderShelf() so it always lines up with the
   actual rendered row height, even when titles wrap to 1 vs 2 lines --
   a pure-CSS repeating-background approach can't track variable row
   heights reliably, this can. */
.shelf-row {
  display: flex;
  gap: 14px;
  padding: 6px 6px 12px;
}
.shelf-row .book-tile-wrap { flex: 1 1 0; min-width: 0; max-width: 76px; position: relative; }

.shelf-ledge {
  height: 12px;
  margin: 0 4px 14px;
  border-radius: 2px;
  background: linear-gradient(to bottom, var(--shelf-wood), var(--shelf-wood-dark));
  box-shadow: 0 3px 6px rgba(0,0,0,0.3), inset 0 -3px 0 rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.15);
}

.book-tile { display: flex; flex-direction: column; align-items: center; cursor: pointer; border: none; background: none; padding: 0; width: 100%; }
.book-menu-btn {
  position: absolute; top: -4px; right: 4px; z-index: 3;
  width: 22px; height: 22px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  border-radius: 3px 6px 6px 3px;
  background: linear-gradient(135deg, var(--shelf-wood), var(--shelf-wood-dark));
  box-shadow: -2px 0 0 rgba(0,0,0,0.15) inset, 0 2px 5px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  position: relative;
}
.book-cover .status-dot {
  position: absolute; top: 4px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.6);
}
.book-title-label {
  margin-top: 5px;
  font-size: 10.5px;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ---------- Reusable small inline text-entry row (reader "jump to page",
   the shelf's rename-from-⋮-menu form) ---------- */

.name-editor { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.name-editor input {
  flex: 1; min-width: 120px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.15); font-size: 14px; color: var(--text); background: var(--secondary-bg);
}

/* ---------- Action sheet (⋮ book menu: rename / cover color / delete) ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.action-sheet {
  background: var(--secondary-bg); width: 100%; max-width: 480px;
  border-radius: 16px 16px 0 0; padding: 6px 0 24px;
}
.action-sheet .sheet-title {
  padding: 12px 20px 8px; font-size: 12px; color: var(--hint);
  text-transform: uppercase; letter-spacing: 0.02em;
}
.action-sheet > button {
  display: block; width: 100%; text-align: left; padding: 14px 20px;
  border: none; background: none; color: var(--text); font-size: 15px;
}
.action-sheet > button.danger { color: var(--danger); }
.action-sheet > button:not(:last-child) { border-bottom: 1px solid rgba(0,0,0,0.08); }

.color-swatch-row { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 20px 18px; }
.color-swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.color-swatch.selected { border-color: var(--text); }

/* ---------- Bookmarks list ---------- */

.bookmarks-list { display: flex; flex-direction: column; gap: 8px; padding: 8px 16px 24px; }
.bookmark-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: none; border-radius: 12px; background: var(--secondary-bg); color: var(--text); text-align: left; width: 100%;
}
.bookmark-cover {
  width: 32px; height: 44px; border-radius: 3px 6px 6px 3px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--shelf-wood), var(--shelf-wood-dark));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px;
}
.bookmark-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bookmark-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-chevron { color: var(--hint); font-size: 18px; flex-shrink: 0; }

/* ---------- Panels / buttons ---------- */

.panel {
  margin: 12px 16px;
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 16px;
}
/* Explicit, rather than relying on the default: some in-app WebViews
   (Telegram's included) are inconsistent about honoring text selection
   on tap-and-hold unless it's asked for directly. Applies to summaries,
   chapter lists, quiz text, and Ask AI answers/citations. */
.panel, .panel * { -webkit-user-select: text; user-select: text; }

.progress-track { height: 8px; border-radius: 4px; background: rgba(0,0,0,0.08); overflow: hidden; }
.progress-fill { height: 100%; background: var(--button); transition: width 0.2s; }

.action-grid { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px; }
.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  text-align: left;
}
.action-btn .icon { font-size: 20px; }
.action-btn span:nth-child(2) { flex: 1; }
.badge { font-size: 11px; color: var(--hint); }
.badge.ok { color: var(--ok); }
.badge.err { color: var(--danger); }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  font-size: 14px;
  margin: 4px 4px 4px 0;
}
.btn.secondary { background: rgba(0,0,0,0.08); color: var(--text); }
.btn:disabled { opacity: 0.5; }

.chapter-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.chapter-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(0,0,0,0.06); font-size: 14px; }
.chapter-list li:last-child { border-bottom: none; }

.diff-row { display: flex; gap: 8px; margin: 10px 0; }
.diff-btn { flex: 1; padding: 10px; border-radius: 10px; border: 2px solid rgba(0,0,0,0.1); background: var(--secondary-bg); color: var(--text); font-size: 13px; }
.diff-btn.selected { border-color: var(--button); color: var(--button); font-weight: 600; }

.qa-mode-row { display: flex; gap: 8px; margin-bottom: 12px; }
.qa-mode-btn { flex: 1; padding: 9px; border-radius: 10px; border: 2px solid rgba(0,0,0,0.1); background: var(--secondary-bg); color: var(--text); font-size: 12.5px; }
.qa-mode-btn.selected { border-color: var(--button); color: var(--button); font-weight: 600; }
.qa-mode-hint { font-size: 11px; color: var(--hint); margin: -6px 0 12px; }

.qa-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.qa-msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.5; max-width: 92%; }
.qa-msg.q { background: var(--button); color: var(--button-text); align-self: flex-end; }
.qa-msg.a { background: var(--secondary-bg); align-self: flex-start; }
.cite-marker {
  display: inline-block; font-size: 10px; vertical-align: super; line-height: 1;
  color: var(--link); font-weight: 700; margin: 0 1px; cursor: pointer;
}
.qa-sources {
  display: block; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(0,0,0,0.1);
  font-size: 11.5px; opacity: 0.85;
}
.qa-sources .src-line { display: flex; gap: 4px; margin-top: 3px; }
.qa-sources .src-line .n { font-weight: 700; flex-shrink: 0; }
.qa-export-btn {
  display: block; margin-top: 8px; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(0,0,0,0.15);
  background: var(--bg); color: var(--link); font-size: 12px; font-weight: 600; cursor: pointer;
}
.qa-export-btn:disabled { opacity: 0.6; cursor: default; }
.qa-input-row { display: flex; gap: 8px; }
.qa-input-row input { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.15); font-size: 14px; }
.qa-top-row { display: flex; gap: 8px; margin-bottom: 10px; }

.quiz-select-row { display: flex; gap: 8px; margin: 8px 0; }

.quiz-q { margin-bottom: 18px; }
.quiz-q .q-text { font-weight: 600; margin-bottom: 8px; }
.quiz-opt {
  display: block; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 6px;
  border-radius: 8px; border: 1px solid rgba(0,0,0,0.15); background: var(--secondary-bg); color: var(--text); font-size: 14px;
}
.quiz-opt.correct { background: rgba(46,139,87,0.18); border-color: var(--ok); }
.quiz-opt.wrong { background: rgba(192,57,43,0.18); border-color: var(--danger); }
.quiz-opt:disabled { opacity: 0.85; }
.quiz-explain { font-size: 12px; color: var(--hint); margin-top: 6px; }
.quiz-score { font-weight: 600; margin-bottom: 12px; }
.quiz-summary {
  text-align: center; padding: 20px 12px; margin-bottom: 16px; border-radius: 12px; background: var(--secondary-bg);
}
.quiz-summary-pct { font-size: 36px; font-weight: 700; margin: 0 0 8px; color: var(--link); }
.quiz-summary-row { margin: 4px 0; font-size: 14px; }

.flash-review-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.flash-card {
  padding: 24px 16px; margin-bottom: 12px; border-radius: 12px; background: var(--secondary-bg);
  font-size: 17px; line-height: 1.5; text-align: center; min-height: 60px;
}
.flash-card-back { background: rgba(0,0,0,0.04); font-size: 15px; }
.flash-rate-row { display: flex; gap: 6px; margin-top: 8px; }
.flash-rate-btn {
  flex: 1; padding: 10px 4px; border-radius: 10px; border: none; font-size: 13px; color: #fff;
}
.flash-rate-btn.again { background: var(--danger); }
.flash-rate-btn.hard { background: #d68910; }
.flash-rate-btn.good { background: var(--link); }
.flash-rate-btn.easy { background: var(--ok); }

/* ---------- Reader notes panel (📝 Notes button) ---------- */

.reader-notes-panel {
  margin: 8px 16px; padding: 12px; border-radius: 12px; background: var(--secondary-bg);
}
.reader-note-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(0,0,0,0.06);
}
.reader-note-row:last-child { border-bottom: none; }
.reader-note-text { flex: 1; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
#reader-note-input {
  width: 100%; margin-top: 8px; padding: 8px 10px; border-radius: 8px; box-sizing: border-box;
  border: 1px solid rgba(0,0,0,0.15); font-size: 14px; color: var(--text); background: var(--bg);
  font-family: inherit; resize: vertical;
}

.error-text { color: var(--danger); font-size: 13px; margin: 8px 0; }

/* ---------- Reader ---------- */

.reader-topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.pager-btn { border: none; background: var(--secondary-bg); color: var(--text); font-size: 22px; width: 40px; height: 40px; border-radius: 50%; }

/* Every reader tool visible at once: two rows that share the width, each
   tool an icon over a short label (the single scrolling row hid half of them). */
.reader-toolbar { display: flex; flex-direction: column; gap: 6px; padding: 0 10px 8px; }
.tool-row { display: flex; gap: 6px; align-items: stretch; }
.tool-btn {
  flex: 1 1 0; min-width: 0; border: none; background: var(--secondary-bg); color: var(--text);
  border-radius: 10px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; font: inherit; font-size: 11px; line-height: 1.15; cursor: pointer;
}
.tool-btn .ic { width: 18px; height: 18px; flex-shrink: 0; }
.tool-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoom-group {
  flex: 1.35 1 0; min-width: 0; display: flex; align-items: center; justify-content: space-between;
  background: var(--secondary-bg); border-radius: 10px; padding: 0 2px;
}
.zoom-btn { border: none; background: none; color: var(--text); font-size: 20px; width: 34px; height: 100%; min-height: 40px; cursor: pointer; }
#reader-zoom-label { flex-shrink: 0; font-size: 12px; text-align: center; }

/* #reader-canvas-wrap scrolls (overflow:auto) rather than the canvas being
   capped at max-width:100% -- that cap was the actual zoom bug: it let the
   canvas's pixel buffer grow on zoom-in but forced its ON-SCREEN size back
   down to the container width every time, so tapping +/- visibly did
   nothing. Letting the page container overflow and scroll is what makes a
   zoomed-in page actually look and behave zoomed in. */
/* Centred with auto margins, not justify-content: a centred flex item wider
   than its box overflows on BOTH sides, and the left part can't be scrolled
   to (a zoomed page's first words were cut off). Auto margins centre a page
   that fits and start-align one that doesn't. The box never grows past the
   screen, so the fit-to-width measurement can't feed on the last page's size. */
#reader-canvas-wrap { display: flex; padding: 8px; overflow: auto; touch-action: pan-x pan-y; width: 100%; max-width: 100vw; box-sizing: border-box; }
#reader-page-container { position: relative; display: inline-block; margin: 0 auto; flex-shrink: 0; }
#reader-zoom-label { cursor: pointer; }
#reader-canvas { display: block; box-shadow: 0 2px 10px rgba(0,0,0,0.2); background: #fff; }

/* Minimal pdf.js text-layer styles (hand-written subset of pdf.js's own
   text_layer_builder.css, since we only load the core pdf.min.js bundle
   from cdnjs, not the full pdf_viewer.css). Text spans are positioned
   exactly over their matching glyphs on the canvas below and made
   invisible (color: transparent) but selectable, so the page LOOKS like a
   normal rendered image but its text can actually be selected and copied. */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
}
.textLayer span, .textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.textLayer ::selection { background: rgba(38, 120, 182, 0.35); }

.spinner-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); }

/* ---------------------------------------------------------------------
   Drugs tab: bottom tab bar, sub-tabs, chips, name suggestions
   ---------------------------------------------------------------------
   Everything here is built from the --tg-theme-* tokens at the top of
   this file, so it follows the user's own Telegram theme (light or dark)
   rather than carrying a second palette of its own. */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--secondary-bg);
  border-top: 1px solid rgba(128, 128, 128, 0.22);
  /* Clears the iPhone home-indicator strip, which otherwise sits on top
     of the tab labels. */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 40;
}

.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 7px;
  border: 0;
  background: none;
  color: var(--hint);
  font: inherit;
  cursor: pointer;
}

.tabbar .tab span { font-size: 20px; line-height: 1; }
.tabbar .tab small { font-size: 11px; }
.tabbar .tab.is-active { color: var(--link); }

/* Only applied while the bar is actually up (see app.js's syncTabBar), so
   the reader and the other pushed views keep the full height. */
body.has-tabbar { padding-bottom: 60px; }

.subtabs {
  display: flex;
  gap: 8px;
  padding: 0 14px 4px;
}

.subtabs .subtab {
  flex: 1;
  padding: 9px 6px;
  border: 1px solid rgba(128, 128, 128, 0.28);
  border-radius: 10px;
  background: var(--secondary-bg);
  color: var(--hint);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.subtabs .subtab.is-active {
  background: var(--button);
  border-color: var(--button);
  color: var(--button-text);
}

.drug-add-row input { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 11px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid rgba(128, 128, 128, 0.28);
  font-size: 13px;
}

.chip-x {
  border: 0;
  background: none;
  color: var(--hint);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.suggestions {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  border: 1px solid rgba(128, 128, 128, 0.28);
  border-radius: 10px;
  overflow: hidden;
}

/* The same list rendered under an error message rather than under an
   input -- it reads as a row of options there, not a dropdown. */
.suggestions.is-inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  border: 0;
}

.suggestions .suggestion {
  padding: 10px 12px;
  border: 0;
  background: var(--secondary-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.suggestions:not(.is-inline) .suggestion + .suggestion {
  border-top: 1px solid rgba(128, 128, 128, 0.18);
}

.suggestions.is-inline .suggestion {
  border: 1px solid rgba(128, 128, 128, 0.28);
  border-radius: 999px;
  padding: 7px 12px;
}

/* Matches the book Q&A log's column so an answer thread looks the same
   wherever it appears in the app. */
.qa-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px;
}

.qa-thread:empty { display: none; }

#lookup-thread .qa-msg, #ask-thread .qa-msg { white-space: pre-wrap; }
#interaction-result .qa-msg { white-space: pre-wrap; max-width: 100%; }


/* ---------- Ask tab: book checklists ---------- */
.ask-heading { margin: 14px 0 6px; font-weight: 600; font-size: 14px; }
.ask-select {
  width: 100%; box-sizing: border-box; padding: 9px 10px; border-radius: 8px; font: inherit; font-size: 14px;
  border: 1px solid rgba(128, 128, 128, 0.28); background: var(--bg); color: var(--text);
}
.check-list { display: flex; flex-direction: column; margin-top: 6px; }
.check-list:empty { display: none; }
.check-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 2px; font-size: 14px;
  border-bottom: 1px solid rgba(128, 128, 128, 0.16); min-width: 0;
}
.check-row:last-child { border-bottom: 0; }
.check-row input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--button); }
.check-row .check-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check-row .check-meta { flex-shrink: 0; font-size: 12px; color: var(--hint); }
.check-row .check-meta.is-error { color: #c0392b; }
.check-row.is-disabled .check-title { color: var(--hint); }
.check-row .mini-btn {
  flex-shrink: 0; padding: 5px 9px; border-radius: 8px; font: inherit; font-size: 12px; cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.28); background: var(--bg); color: var(--link);
}
.check-row .mini-btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- Book covers ---------- */
.cover-btn {
  flex-shrink: 0; width: 34px; height: 46px; padding: 0; border-radius: 4px; overflow: hidden; cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.3); background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.cover-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-ph { font-size: 18px; }
.cover-viewer {
  position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, 0.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box;
}
.cover-viewer[hidden] { display: none; }
.cover-viewer img { max-width: 100%; max-height: 78vh; border-radius: 6px; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.5); }
.cover-viewer-title { color: #fff; font-weight: 600; text-align: center; margin: 0 0 12px; overflow-wrap: anywhere; }
.cover-viewer-status, .cover-viewer-hint { color: rgba(255, 255, 255, 0.75); font-size: 13px; margin: 10px 0 0; }
.rename-input {
  flex: 1; min-width: 0; padding: 7px 9px; border-radius: 8px; font: inherit; font-size: 14px;
  border: 1px solid rgba(128, 128, 128, 0.35); background: var(--bg); color: var(--text);
}

/* ---------- Mixed Persian/Arabic + English text ----------
   richText() renders each line as its own block with dir= set by the
   line's dominant script, so a Persian sentence that starts with "SSRI"
   still runs right-to-left and aligns right. */
.rich > div { min-height: 1em; overflow-wrap: anywhere; }
.rich > div[dir="rtl"] { text-align: right; }
.rich > div[dir="ltr"] { text-align: left; }
.rich .gap { min-height: 0.6em; }
.rich .cite-marker { unicode-bidi: isolate; cursor: pointer; }
.rich strong { font-weight: 700; }
#ask-thread .qa-msg.a, #lookup-thread .qa-msg.a, #qa-log .qa-msg.a, #interaction-result .qa-msg { white-space: normal; }
.qa-msg.q { unicode-bidi: plaintext; text-align: start; }
.quiz-question, .quiz-option, .flash-front, .flash-back { unicode-bidi: plaintext; text-align: start; }
.qa-sources .src-line { cursor: pointer; }
.qa-sources .src-line span:last-child { unicode-bidi: plaintext; }

/* ---------- + button above the tab bar (it sat underneath it) ---------- */
body.has-tabbar .fab { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
.fab { z-index: 60; }

/* ---------- Shelf tabs ---------- */
.shelf-tabs { padding-top: 4px; padding-bottom: 8px; }
.shelf-spec-bar { padding: 0 16px 8px; }
.book-cover.has-img { padding: 0; overflow: hidden; }
.book-cover.has-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Ask tab extras ---------- */
.ask-spec-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ask-spec-actions .mini-btn {
  padding: 6px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.28); background: var(--bg); color: var(--link);
}
.suggest-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.suggest-form input, .suggest-form textarea {
  width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 14px;
  border: 1px solid rgba(128, 128, 128, 0.3); background: var(--bg); color: var(--text);
}

/* ---------- Reader: the cited passage ---------- */
.reader-source {
  margin: 6px 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
  background: var(--secondary-bg); border-left: 4px solid var(--button); max-height: 30vh; overflow-y: auto;
}
.reader-source-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.reader-source .mini-btn { border: 0; background: none; color: var(--hint); font-size: 16px; cursor: pointer; }
.textLayer span.src-hl { background: rgba(255, 213, 0, 0.45); border-radius: 2px; }

/* ---------- Ask tab composer ---------- */
.ask-compose { position: relative; }
.ask-compose-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.ask-compose-head .muted { margin: 0; }
.ask-topic-note { margin: 0 0 8px; }
#ask-question, .compose-box {
  display: block; width: 100%; box-sizing: border-box; min-height: 96px; max-height: 40vh; resize: none;
  padding: 12px 14px; border-radius: 14px; font: inherit; font-size: 16px; line-height: 1.45;
  border: 1.5px solid rgba(128, 128, 128, 0.32); background: var(--bg); color: var(--text);
  unicode-bidi: plaintext;
}
#ask-question:focus, .compose-box:focus { outline: none; border-color: var(--button); box-shadow: 0 0 0 3px rgba(38, 120, 182, 0.15); }
.ask-send-btn { display: block; width: 100%; margin-top: 10px; padding: 12px; font-size: 16px; border-radius: 12px; }
.ask-compose-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mini-btn.ask-like, .ask-compose-tools .mini-btn, .ask-compose-head .mini-btn, .ask-pick-head .mini-btn,
.web-tools .mini-btn, .web-kbd .mini-btn, .web-site-actions .mini-btn {
  padding: 7px 11px; border-radius: 9px; font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.28); background: var(--bg); color: var(--link);
}
.ask-turn-tools { display: flex; justify-content: flex-end; margin-top: 8px; }
.ask-turn-tools .mini-btn {
  padding: 5px 10px; border-radius: 8px; font: inherit; font-size: 12px; cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.28); background: var(--bg); color: var(--link);
}
.topic-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid rgba(128, 128, 128, 0.16); }
.topic-row:last-child { border-bottom: 0; }
.topic-row .topic-main { flex: 1; min-width: 0; text-align: start; background: none; border: 0; padding: 0; font: inherit; color: var(--text); cursor: pointer; }
.topic-row .topic-title { display: block; font-size: 14px; unicode-bidi: plaintext; overflow-wrap: anywhere; }
.topic-row .topic-meta { display: block; font-size: 12px; color: var(--hint); margin-top: 2px; }
.topic-row .mini-btn { flex-shrink: 0; border: 0; background: none; color: var(--hint); font-size: 16px; cursor: pointer; }

/* ---------- Drugs tab inputs ---------- */
.drug-input-row { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
.drug-input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; font: inherit; font-size: 16px;
  border: 1.5px solid rgba(128, 128, 128, 0.32); background: var(--bg); color: var(--text); unicode-bidi: plaintext;
}
.drug-input:focus { outline: none; border-color: var(--button); box-shadow: 0 0 0 3px rgba(38, 120, 182, 0.15); }
.drug-input-row .btn { border-radius: 12px; padding: 0 18px; }
#interaction-check { margin-top: 14px; }
.tabbar .tab small { white-space: nowrap; }

/* ---------- Ask: choose-resources page / chat page ---------- */
.ask-pick-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ask-pick-bar {
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); z-index: 5;
  padding: 10px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.ask-pick-bar .ask-send-btn { margin-top: 0; }
.ask-res-bar { padding: 4px 16px 8px; }
.ask-choose-btn { width: 100%; border-radius: 12px; padding: 12px; font-weight: 600; }
.ask-res-list {
  margin: 8px 2px 0; font-size: 12px; line-height: 1.45; color: var(--hint); unicode-bidi: plaintext;
}
.ask-res-list b { font-weight: 600; color: var(--text); }

/* ---------- Web sources (admin browser) ---------- */
.web-urlbar { display: flex; gap: 8px; padding: 0 16px; }
.web-urlbar .drug-input { font-size: 14px; padding: 10px 12px; }
.web-tools { display: flex; gap: 6px; padding: 10px 16px 6px; flex-wrap: wrap; }
.web-screen { position: relative; margin: 4px auto; width: fit-content; max-width: calc(100% - 32px); border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(128, 128, 128, 0.3); background: #fff; line-height: 0; }
/* Sized to leave room beside it: a swipe on the picture scrolls the website, not the app. */
#web-shot { display: block; aspect-ratio: 390 / 740; height: min(60vh, calc((100vw - 32px) * 740 / 390)); width: auto; max-width: 100%;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; -webkit-touch-callout: none;
  }
.web-busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.18); font-size: 32px; line-height: 1; }
.web-hint { padding: 0 16px; }
.web-kbd { display: flex; gap: 6px; align-items: center; padding: 8px 16px 2px; }
.web-kbd .drug-input { flex: 1; min-width: 0; font-size: 15px; padding: 10px 12px; transition: border-color .2s, box-shadow .2s; }
.web-kbd.is-on .drug-input { border-color: var(--button); box-shadow: 0 0 0 3px var(--primary-soft); }
.web-kbd .mini-btn { padding: 9px 13px; font-size: 15px; }
.web-save-name { width: 100%; box-sizing: border-box; margin-top: 10px; }
.web-sites { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.web-site { border: 1px solid rgba(128, 128, 128, 0.25); border-radius: 12px; padding: 12px; }
.web-site-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.web-site-status { font-size: 12px; color: var(--hint); margin: 4px 0 8px; }
.web-site-status .bad { color: #c0392b; }
.web-site-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.web-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.web-form label { font-size: 13px; font-weight: 600; }
.web-form .drug-input { font-size: 14px; padding: 10px 12px; }
.web-form .hint { font-size: 12px; color: var(--hint); font-weight: 400; }
.web-check { display: flex; align-items: center; gap: 8px; font-weight: 400 !important; }
.web-test-result { font-size: 12px; border-top: 1px solid rgba(128, 128, 128, 0.2); padding-top: 6px; margin-top: 6px; word-break: break-word; }
.web-row-icon { font-size: 20px; width: 34px; text-align: center; }
.web-form label { display: flex; flex-direction: column; gap: 4px; }
.web-form label.web-check { flex-direction: row; }
.web-form .ask-select { width: 100%; }


/* ---------- Welcome splash (splash.js) ---------- */
#splash {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #5DB6F7 0%, #1C74D2 100%);
  transition: opacity 0.7s ease, filter 0.7s ease, transform 0.7s ease;
  /* failsafe: gone after 8 s even if splash.js never runs or never finishes */
  animation: splash-failsafe 0.6s ease 8s forwards;
}
#splash svg { width: min(92vw, 64vh); height: auto; display: block; overflow: visible; }
#splash.is-leaving { opacity: 0; filter: blur(8px); transform: scale(1.06); pointer-events: none; }
@keyframes splash-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
@media (prefers-reduced-motion: reduce) { #splash { transition: opacity 0.5s ease; } #splash.is-leaving { filter: none; transform: none; } }

/* ---------- Admin browser: tab bar ---------- */
.web-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 16px 8px; scroll-padding: 0 16px; scrollbar-width: none; }
.web-tabs::-webkit-scrollbar { display: none; }
.web-tab {
  flex: 0 0 auto; max-width: 62%; display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--secondary-bg); color: inherit; position: relative;
}
.web-tab.is-active { border-color: var(--button); box-shadow: inset 0 -2px 0 var(--button); }
.web-tab-open {
  border: 0; background: none; color: inherit; font: inherit; font-size: 13px;
  padding: 7px 4px 7px 10px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.web-tab.is-active .web-tab-open { font-weight: 600; }
.web-tab-close { border: 0; background: none; color: inherit; opacity: .55; font-size: 12px; padding: 7px 9px 7px 4px; cursor: pointer; }
.web-tab.is-new::before {
  content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--button); box-shadow: 0 0 0 2px var(--bg); animation: web-tab-pulse 1.2s ease-in-out infinite;
}
@keyframes web-tab-pulse { 50% { transform: scale(1.35); } }
.lookup-web { margin-top: 12px; }

/* ---------- Icons (Lucide line icons from the sprite in index.html) ----------
   Drawn in the surrounding text colour, so they follow the Sky / Midnight theme. */
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.22em; flex-shrink: 0; overflow: visible;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-fill { fill: currentColor; }
.ic-on { color: var(--ok, #2fb36d); fill: currentColor; }
.topbar h1 .ic { color: var(--button); width: 1em; height: 1em; vertical-align: -0.12em; margin-right: 2px; }
.tabbar .tab span .ic { width: 23px; height: 23px; vertical-align: 0; }
.action-btn .icon { display: inline-flex; color: var(--button); }
.action-btn .icon .ic { width: 22px; height: 22px; vertical-align: 0; }
.fab { display: flex; align-items: center; justify-content: center; }
.fab .ic { width: 28px; height: 28px; stroke-width: 2.5; vertical-align: 0; }
.cover-ic { width: 42%; height: auto; aspect-ratio: 1; opacity: 0.92; stroke-width: 1.6; }
.bookmark-cover .cover-ic, .cover-ph .cover-ic { width: 18px; height: 18px; }
.big-ic { width: 54px; height: 54px; color: var(--button); stroke-width: 1.6; }
.web-row-icon { color: var(--button); }
.web-busy .ic { width: 34px; height: 34px; color: #fff; }
.spinner-line .ic { color: var(--button); animation: ic-turn 1.6s ease-in-out infinite; }
@keyframes ic-turn { 0%, 35% { transform: rotate(0); } 50%, 85% { transform: rotate(180deg); } 100% { transform: rotate(360deg); } }
.spinner-line .ic { transform-box: fill-box; transform-origin: center; }
.subtab .ic, .mini-btn .ic, .link-btn .ic, .tool-btn .ic, .btn .ic { margin-right: 1px; }
.mini-btn .ic:only-child { margin-right: 0; }
.flash-rate-btn .ic { width: 1.25em; height: 1.25em; }
.quiz-summary-row .ic { color: var(--button); }
@media (prefers-reduced-motion: reduce) { .spinner-line .ic { animation: none; } }

.web-notice { margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.4;
  background: #fff4e5; color: #7a4a00; border: 1px solid #f3c98b; }
html[data-theme="midnight"] .web-notice { background: #3a2a10; color: #ffd9a0; border-color: #6b4a17; }
.web-tap { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
  border: 3px solid var(--button); background: rgba(43, 140, 232, 0.25); pointer-events: none;
  animation: web-tap 0.6s ease-out forwards; }
@keyframes web-tap { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

/* ---------- Reader tools: highlights, selection bar, search, chapters, night ---------- */
.textLayer mark { color: transparent; border-radius: 2px; padding: 0; }
.textLayer mark.hl-yellow { background: rgba(255, 214, 0, 0.42); }
.textLayer mark.hl-green { background: rgba(60, 200, 110, 0.38); }
.textLayer mark.hl-blue { background: rgba(60, 150, 255, 0.36); }
.textLayer mark.hl-pink { background: rgba(255, 90, 160, 0.36); }
.textLayer mark.search-hl { background: rgba(255, 140, 0, 0.5); outline: 1px solid rgba(255, 120, 0, 0.8); }
.reader-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.reader-list { display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto; margin: 6px 0; }
.reader-list-row { display: flex; align-items: center; gap: 6px; }
.reader-list-main { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 8px; text-align: left;
  border: 0; background: var(--bg); color: var(--text); padding: 9px 10px; border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; }
.reader-list-main.is-current { box-shadow: inset 3px 0 0 var(--button); font-weight: 600; }
.reader-list-page { flex-shrink: 0; color: var(--hint); font-size: 12px; padding-top: 2px; }
.reader-list-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.reader-list-text mark.search-hl { background: rgba(255, 170, 0, 0.45); color: inherit; border-radius: 2px; }
.hl-dot { flex-shrink: 0; width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; }
.hl-dot.hl-yellow, .selbar-color[data-color="yellow"] { background: #ffd600; }
.hl-dot.hl-green, .selbar-color[data-color="green"] { background: #3cc86e; }
.hl-dot.hl-blue, .selbar-color[data-color="blue"] { background: #3c96ff; }
.hl-dot.hl-pink, .selbar-color[data-color="pink"] { background: #ff5aa0; }
#reader-explain blockquote { margin: 0 0 10px; padding: 8px 10px; border-left: 3px solid var(--button); background: var(--bg); border-radius: 0 8px 8px 0; font-size: 13px; color: var(--hint); }
.sel-card { padding: 8px 10px; border-radius: 10px; background: var(--bg); margin-bottom: 6px; }
.sel-card p { margin: 2px 0; }
.reader-selbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 16px;
  background: var(--secondary-bg); box-shadow: 0 6px 24px rgba(13, 59, 102, 0.28); max-width: calc(100vw - 24px);
  -webkit-user-select: none; user-select: none;
}
.selbar-colors { display: flex; gap: 7px; padding-right: 8px; border-right: 1px solid var(--border); }
.selbar-color { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 1px rgba(0,0,0,0.15); cursor: pointer; padding: 0; }
.selbar-color.is-current { box-shadow: 0 0 0 2px var(--button); }
.selbar-actions { display: flex; gap: 2px; }
.selbar-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; color: var(--link);
  font: inherit; font-size: 11px; font-weight: 600; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.selbar-btn .ic { width: 20px; height: 20px; }
.reader-toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 81;
  background: #0d3b66; color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }
#view-reader.is-night #reader-canvas-wrap { background: #0b1220; }
#view-reader.is-night #reader-canvas { filter: invert(0.9) hue-rotate(180deg); }

/* ---------- Book search boxes (Shelf and Choose resources) ---------- */
.book-search { position: relative; display: flex; align-items: center; margin: 4px 0 10px; }
.shelf-search { margin: 0 16px 10px; }
.book-search .ic { position: absolute; left: 12px; color: var(--hint); pointer-events: none; }
.book-search input { width: 100%; box-sizing: border-box; padding: 10px 12px 10px 38px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--secondary-bg); color: var(--text); font: inherit; font-size: 15px; }
.book-search input:focus { outline: none; border-color: var(--button); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- Shelf: tap a title to see it whole; grid / list views ---------- */
.book-title-label { cursor: pointer; width: 100%; }
.book-title-label.is-expanded { -webkit-line-clamp: unset; display: block; overflow: visible; }
.shelf-tools { display: flex; align-items: center; gap: 8px; margin: 0 16px 10px; }
.shelf-tools .book-search { flex: 1; margin: 0; }
.view-toggle { display: flex; background: var(--secondary-bg); border: 1px solid var(--border); border-radius: 12px; padding: 3px; flex-shrink: 0; }
.view-btn { border: 0; background: none; color: var(--hint); padding: 7px 9px; border-radius: 9px; cursor: pointer; display: flex; }
.view-btn .ic { width: 19px; height: 19px; vertical-align: 0; }
.view-btn.is-active { background: var(--primary-soft); color: var(--link); }
.shelf-grid.is-list { display: flex; flex-direction: column; gap: 8px; padding: 2px 16px 90px; }
.book-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 40px 8px 8px;
  background: var(--secondary-bg); border: 1px solid var(--border); border-radius: 14px; }
.book-row .book-tile { width: 44px; flex-shrink: 0; }
.book-row .book-cover { width: 44px; }
.book-row .book-cover .cover-ic { width: 50%; }
.book-row .book-row-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; margin: 0; text-align: left;
  border: 0; background: none; font: inherit; font-size: 14.5px; font-weight: 600; line-height: 1.3; -webkit-line-clamp: unset;
  overflow-wrap: anywhere; color: var(--shelf-ink, var(--text)); padding: 0; }
.book-row-meta { font-size: 12px; font-weight: 400; color: var(--shelf-hint, var(--hint)); }
.book-row .book-menu-btn { top: 50%; right: 8px; transform: translateY(-50%); background: var(--primary-soft); color: var(--link); width: 28px; height: 28px; }
/* A file-name title ("Judith_S_Beck_Cognitive_...") has no spaces to wrap at:
   it may break anywhere, and the shelf never scrolls sideways. */
.book-title-label { overflow-wrap: anywhere; word-break: break-word; }
#view-shelf { overflow-x: hidden; }

/* ---------- Recommended books (admin) ---------- */
.rec-books { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.rec-books .ask-select { margin: 6px 0 4px; width: 100%; }
.rec-row { align-items: center; }
.rec-num { width: 20px; flex-shrink: 0; color: var(--hint); font-size: 12px; font-weight: 600; }
.rec-row .check-title strong { font-weight: 600; }
.rec-row .check-title .muted { font-size: 12px; }
.rec-have { flex-shrink: 0; font-size: 12px; font-weight: 600; color: var(--ok, #2fb36d); }

/* ---------- Account: login sheet, guest banner, admin accounts ---------- */
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.link-btn.icon-only { padding: 8px 10px; }
.account-btn span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.account-btn.is-guest { background: var(--button) !important; color: var(--button-text) !important; border-color: transparent !important; }
.guest-banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 16px 10px; padding: 8px 10px 8px 12px;
  border-radius: 12px; background: var(--primary-soft); color: var(--link); font-size: 13px; }
.guest-banner .mini-btn { flex-shrink: 0; }
.login-sheet { position: fixed; inset: 0; z-index: 900; background: rgba(8, 24, 44, 0.55); display: flex; align-items: flex-end; justify-content: center; }
.login-card { position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; box-sizing: border-box;
  background: var(--secondary-bg); color: var(--text); border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2); }
.login-card h2 { margin: 0; font-family: var(--font-head); font-size: 21px; color: var(--head-ink, var(--text)); }
.login-card .drug-input { width: 100%; box-sizing: border-box; margin: 4px 0; }
#login-pane, #account-pane { display: flex; flex-direction: column; gap: 8px; }
#login-pane[hidden], #account-pane[hidden] { display: none; }
.login-close { position: absolute; top: 12px; right: 12px; border: 0; background: var(--bg); color: var(--hint); width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.guest-limits { margin-top: 6px; padding: 12px; border-radius: 14px; background: var(--bg); font-size: 13.5px; }
.guest-limits p { margin: 0 0 6px; }
.guest-limits ul { margin: 0 0 6px; padding-left: 18px; }
.guest-limits li { margin: 3px 0; }
.acc-created { margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--primary-soft); }
.acc-created p { margin: 0 0 8px; font-size: 13.5px; }
.acc-cred { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 4px 0; font-size: 14px; }
.acc-cred code { font-size: 15px; font-weight: 700; background: var(--secondary-bg); padding: 3px 8px; border-radius: 6px; user-select: all; }
.acc-list { display: flex; flex-direction: column; gap: 10px; }
.acc-row { padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.acc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.acc-meta { font-size: 12.5px; margin: 3px 0 8px; }
.acc-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.acc-tag { font-size: 12px; font-weight: 600; color: var(--hint); display: inline-flex; align-items: center; gap: 3px; }
.acc-tag.on { color: var(--ok, #2fb36d); }
.acc-tag.off { color: var(--danger, #c0392b); }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-card { background: var(--bg); border-radius: 12px; padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; }
.stat-card span { font-size: 11.5px; color: var(--hint); }
.stat-card strong { font-size: 18px; font-family: var(--font-head); }
.stat-card.warn strong { color: var(--danger, #c0392b); }
.stat-label { margin: 14px 0 6px; font-size: 12.5px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: 0.04em; }
.day-bars { display: flex; align-items: flex-end; gap: 4px; height: 80px; }
.day-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.day-bar i { display: block; width: 100%; max-width: 22px; background: var(--button); border-radius: 4px 4px 0 0; min-height: 2px; }
.day-bar span { font-size: 10px; color: var(--hint); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13.5px; }
.kv code { font-size: 12px; overflow-wrap: anywhere; }
.acc-events { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.acc-event { display: flex; flex-direction: column; gap: 1px; padding: 6px 8px; border-radius: 8px; background: var(--bg); font-size: 12.5px; }
.acc-event.bad { box-shadow: inset 3px 0 0 var(--danger, #c0392b); }
.ev-when { color: var(--hint); font-size: 11.5px; }
.ev-what code { font-size: 11.5px; overflow-wrap: anywhere; }
.ev-err { color: var(--danger, #c0392b); }
#view-accounts .drug-input { width: 100%; box-sizing: border-box; margin: 4px 0; }
.acc-tag.paid { color: #b7791f; display: block; margin-top: 2px; }

/* ---------- Specialty books: "Add to my library" toggle ---------- */
.lib-toggle { margin-top: 5px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid var(--border); background: var(--secondary-bg); color: var(--link); border-radius: 9px;
  font: inherit; font-size: 10px; font-weight: 600; line-height: 1.15; padding: 4px 3px; cursor: pointer; }
.lib-toggle .ic { width: 12px; height: 12px; flex-shrink: 0; vertical-align: 0; }
.lib-toggle.is-on { background: var(--button); border-color: transparent; color: var(--button-text); }
.lib-toggle:disabled { opacity: 0.6; }
.book-row .lib-toggle { width: auto; flex-shrink: 0; margin: 0; font-size: 12px; padding: 7px 10px; }
.book-row:has(.lib-toggle) { padding-right: 8px; }

/* Ask picker: a book's status sits under its title; the title never collapses to one letter. */
.check-row .check-title { min-width: 7em; }
.check-sub { display: block; margin-top: 3px; font-size: 12px; font-weight: 400; color: var(--hint); }
.check-sub.is-error { color: #c0392b; }
.check-sub .ic { width: 13px; height: 13px; vertical-align: -0.15em; }

/* ---- multi-volume books: one title, its volumes under it ---- */
.vol-group { border-bottom: 1px solid rgba(128, 128, 128, 0.16); }
.vol-group:last-child { border-bottom: 0; }
.vol-group .check-row.vol-head { border-bottom: 0; font-weight: 600; }
.vol-group .vol-icon { color: var(--button); display: inline-flex; flex-shrink: 0; }
.vol-group .vol-head .check-sub { font-weight: 400; }
.vol-children { margin-left: 8px; border-left: 2px solid var(--button); padding-left: 8px; margin-bottom: 6px; min-width: 0; }
/* An indented row has less room: tighter, so its buttons stay inside the card. */
.vol-children .check-row { padding-top: 6px; padding-bottom: 6px; gap: 7px; }
.vol-children .check-row .check-title { min-width: 4.2em; }
.vol-children .check-row .check-meta { font-size: 11px; }

/* the upload sheet */
.vol-label { display: block; font-size: 13px; color: var(--hint); margin-top: 12px; }
.vol-toggle { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 15px; }
.vol-toggle input { width: 18px; height: 18px; accent-color: var(--button); }
#vol-files { margin: 8px 0 12px; }
.vol-file { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(128, 128, 128, 0.16); }
.vol-file:last-child { border-bottom: 0; }
.vol-file > .ic { flex-shrink: 0; color: var(--hint); }
.vol-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.vol-num { flex-shrink: 0; font-size: 13px; color: var(--hint); display: flex; align-items: center; gap: 6px; }
.vol-num[hidden] { display: none; }
.vol-num input { width: 56px; padding: 6px; border-radius: 8px; border: 1px solid rgba(128, 128, 128, 0.3); background: var(--bg); color: var(--text); font: inherit; }
#vol-sheet .btn { width: 100%; margin-top: 8px; }
#refused-note { resize: vertical; font: inherit; min-height: 56px; }

/* The website / Android app: login is required, so no guest option and no close button. */
#login-sheet.is-web-login #login-guest,
#login-sheet.is-web-login .guest-limits,
#login-sheet.is-web-login #login-close { display: none; }
#login-sheet.is-web-login { background: var(--bg); align-items: center; }
#web-login-logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 0 12px; box-shadow: 0 6px 18px rgba(28,116,210,0.25); }
@media (min-width: 600px) { #login-sheet.is-web-login .login-card { border-radius: 20px; } }

/* ---- access details (profile sheet, User management) ---- */
.access-card { border: 1px solid rgba(128,128,128,0.2); border-radius: 12px; padding: 8px 12px; margin: 10px 0; background: var(--bg); }
.access-card.is-ended { border-color: rgba(192,57,43,0.45); }
.access-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.access-row + .access-row { border-top: 1px solid rgba(128,128,128,0.14); }
.access-row .ic { color: var(--link); flex-shrink: 0; }
.access-row span { color: var(--hint); min-width: 84px; }
.access-row b { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.access-card.is-ended .access-row:last-child b { color: #c0392b; }
.acc-access, .acc-cost-line { font-size: 13px; margin: 3px 0; display: flex; align-items: center; gap: 6px; }
.acc-access .ic, .acc-cost-line .ic { width: 15px; height: 15px; color: var(--link); }
.acc-access.is-ended { color: #c0392b; }
.acc-access.is-ended .ic { color: #c0392b; }
.acc-row[data-acc-open] { cursor: pointer; }
.acc-days-row { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.acc-days-row .ask-select { flex: 1; margin: 0; }
.acc-days-row .drug-input { width: 110px; margin: 0; }
.cost-rows { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.cost-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(40px, 1fr) auto auto; gap: 8px; align-items: center; font-size: 13px; }
.cost-name { overflow-wrap: anywhere; }
.cost-bar { height: 8px; border-radius: 4px; background: rgba(128,128,128,0.15); overflow: hidden; }
.cost-bar i { display: block; height: 100%; background: var(--button); border-radius: 4px; }
.cost-calls { font-size: 12px; }
.account-spec-hint { margin: 4px 0 10px; font-size: 13px; }
#account-specialty { width: 100%; margin: 4px 0 0; }
.tool-btn.is-on { color: var(--link); background: color-mix(in srgb, var(--button) 14%, var(--secondary-bg)); }

/* ---- Back button on every inner screen, profile button on every tab ---- */
.app-back {
  display: inline-flex; align-items: center; gap: 2px; border: none; cursor: pointer;
  background: var(--secondary-bg); color: var(--link); font: inherit; font-size: 14px; font-weight: 600;
  padding: 6px 12px 6px 8px; border-radius: 999px; margin: 0 0 8px; box-shadow: 0 1px 3px rgba(13, 59, 102, 0.08);
}
.app-back .ic { width: 18px; height: 18px; }
.reader-topbar .app-back { margin: 0; flex-shrink: 0; }
.reader-topbar { gap: 8px; }
.reader-topbar #reader-page-label { flex: 1; text-align: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar.shelf-topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar.shelf-topbar .topbar-actions { flex-shrink: 0; }

/* ---- Get an account (two sellers), language, user search ---- */
.buy-account { margin: 14px 0 6px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid rgba(128,128,128,0.18); }
.buy-account p { margin: 0 0 8px; }
.buy-buttons { display: flex; flex-direction: column; gap: 8px; }
.buy-btn { width: 100%; min-width: 0; display: flex !important; align-items: center; gap: 8px; text-align: left; padding: 10px !important; margin: 0 !important; }
.buy-btn .ic { flex-shrink: 0; width: 20px; height: 20px; }
.buy-btn span { display: flex; flex-direction: column; min-width: 0; }
.buy-btn b { font-size: 14px; }
.buy-btn small { font-size: 12px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guest-language { margin-top: 10px; }
.lang-select { width: 100%; margin: 4px 0 0; }
#login-sheet.is-web-login .guest-language { display: none; }
.acc-search { margin: 4px 0 8px; }
.acc-pw-find { margin: 0 0 10px; font-size: 14px; }
.acc-pw-find summary { cursor: pointer; color: var(--link); display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.acc-pw-find summary .ic { width: 16px; height: 16px; }
.acc-pw-find .drug-input { flex: 1; width: auto; }
#acc-pw-result { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---- Reader full screen: only the page, plus a small floating bar ---- */
.reader-topbar .fs-btn .ic { width: 20px; height: 20px; }
body.reader-fs .reader-topbar,
body.reader-fs .reader-toolbar,
body.reader-fs #tabbar,
body.reader-fs .reader-source,
body.reader-fs .reader-notes-panel,
body.reader-fs #reader-goto-row { display: none !important; }
body.reader-fs #reader-canvas-wrap {
  padding: calc(4px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 4px 72px;
  min-height: 100vh; box-sizing: border-box;
}
.reader-fs-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 90;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px) + var(--tg-safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 999px;
  background: rgba(12, 21, 36, 0.78); color: #fff; box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.reader-fs-bar[hidden] { display: none; }
#reader-fs-label { font-size: 13px; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.fs-pager { border: none; background: rgba(255,255,255,0.12); color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.fs-pager .ic { width: 18px; height: 18px; }

/* ---- Highlighter mode, floating bar fading in full screen ---- */
#reader-canvas-wrap.is-hl-mode { touch-action: none; }
#reader-canvas-wrap.is-hl-mode .textLayer span { cursor: crosshair; }
.tool-btn { position: relative; }
.hl-swatch { position: absolute; top: 5px; right: 6px; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--secondary-bg); }
.hl-swatch.hl-yellow { background: #f5c400; } .hl-swatch.hl-green { background: #2fb565; }
.hl-swatch.hl-blue { background: #3b8cf0; } .hl-swatch.hl-pink { background: #f0559a; }
.reader-fs-bar { transition: opacity 0.35s ease; }
.reader-fs-bar.is-faded { opacity: 0; pointer-events: none; }
body.reader-fs #reader-canvas-wrap { min-height: 100vh; align-items: center; padding-bottom: 4px; }

/* ---- Page scroller, highlighter palette ---- */
#view-reader { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
.reader-scrubber {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--secondary-bg); border-top: 1px solid rgba(128, 128, 128, 0.18);
  box-shadow: 0 -4px 14px rgba(13, 59, 102, 0.06);
}
.scrub-label, .scrub-total { font-size: 13px; min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; color: var(--hint); }
.scrub-label { color: var(--link); font-weight: 600; }
.page-scrub { flex: 1; min-width: 0; accent-color: var(--button); height: 28px; margin: 0; }
body.reader-fs .reader-scrubber { display: none; }
body.reader-fs #view-reader { padding-bottom: 0; }
/* the selection menu and notices sit above the scroller */
.reader-selbar { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
.reader-toast { bottom: calc(132px + env(safe-area-inset-bottom, 0px)); }

.hl-palette {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 75;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 999px;
  background: var(--secondary-bg); box-shadow: 0 6px 20px rgba(13, 59, 102, 0.22); max-width: calc(100vw - 24px);
}
.hl-palette[hidden] { display: none; }
.hl-palette-label { font-size: 12px; color: var(--hint); white-space: nowrap; }
.hl-pick { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.9); cursor: pointer; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(128,128,128,0.3); }
.hl-pick[data-hl-pick="yellow"] { background: #f5c400; } .hl-pick[data-hl-pick="green"] { background: #2fb565; }
.hl-pick[data-hl-pick="blue"] { background: #3b8cf0; } .hl-pick[data-hl-pick="pink"] { background: #f0559a; }
.hl-pick.is-current { box-shadow: 0 0 0 3px var(--button); }
.hl-done { border: none; background: var(--button); color: var(--button-text, #fff); font: inherit; font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer; }
/* when a highlight's menu is open it takes that spot */
.reader-selbar:not([hidden]) ~ .hl-palette { display: none; }

/* full screen: the bar is a card with the scroller under the buttons; the palette above it */
.reader-fs-bar { flex-direction: column; border-radius: 22px; padding: 6px 10px 8px; gap: 2px; width: min(380px, calc(100vw - 24px)); box-sizing: border-box; }
.fs-row { display: flex; align-items: center; justify-content: space-between; gap: 4px; width: 100%; }
.reader-fs-bar .page-scrub { width: 100%; height: 24px; accent-color: #6db3ff; }
#reader-fs-hl.is-on { background: rgba(255,255,255,0.28); }
body.reader-fs .hl-palette { bottom: calc(118px + env(safe-area-inset-bottom, 0px) + var(--tg-safe-area-inset-bottom, 0px)); }
body.reader-fs .reader-selbar { bottom: calc(118px + env(safe-area-inset-bottom, 0px)); }

/* ---- Zoomed in: the page's text as an e-book page, wrapped to the screen ---- */
#reader-page-container.is-reflow { display: block; width: 100%; max-width: 760px; }
#reader-page-container.is-reflow #reader-canvas { display: none; }
.textLayer.reflow {
  position: static; inset: auto; width: auto !important; height: auto !important; overflow: visible;
  line-height: 1.6; padding: 20px 18px 32px; background: #fff; color: #1b2330; border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12); font-family: Georgia, "Times New Roman", serif;
  overflow-wrap: break-word; text-align: left;
}
.textLayer.reflow span {
  position: static !important; transform: none !important; font-size: inherit !important; font-family: inherit !important;
  color: inherit !important; white-space: pre-wrap; display: inline; line-height: inherit;
}
.textLayer.reflow span.rf-head { font-weight: 700; line-height: 1.3; }
.textLayer.reflow .rf-p { height: 0.75em; }
.textLayer.reflow mark { color: inherit !important; }
#view-reader.is-night .textLayer.reflow { background: #0f1a2b; color: #d9e4f2; }

/* ---- Full screen: an always-visible exit ---- */
.fs-exit-top { display: none; }
body.reader-fs .fs-exit-top {
  display: inline-flex; align-items: center; gap: 6px; position: fixed; z-index: 95;
  top: calc(10px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)); right: 12px;
  border: none; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600;
  background: rgba(12, 21, 36, 0.72); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,0.25); cursor: pointer;
}
.fs-exit-top .ic { width: 16px; height: 16px; }
body.reader-fs #reader-canvas-wrap { padding-top: calc(52px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)); }

/* ---- Jump to page: the page box in the scroller and the full-screen bar ---- */
.page-input {
  width: 64px; padding: 6px 4px; border-radius: 8px; border: 1px solid rgba(128,128,128,0.3); text-align: center;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--link); background: var(--bg); -moz-appearance: textfield;
}
.page-input::-webkit-outer-spin-button, .page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.scrub-total { white-space: nowrap; }
.fs-page { display: inline-flex; align-items: center; gap: 4px; }
.fs-page .page-input { width: 56px; background: rgba(255,255,255,0.14); color: #fff; border-color: rgba(255,255,255,0.25); padding: 5px 2px; }
#reader-fs-label { min-width: 0; font-size: 13px; }

/* ---- Highlighter: scroll the page up and down (a drag highlights instead) ---- */
.hl-scroll { display: inline-flex; gap: 4px; padding-left: 6px; border-left: 1px solid rgba(128,128,128,0.25); }
.hl-scroll-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer; flex-shrink: 0;
  background: var(--bg); color: var(--link); display: inline-flex; align-items: center; justify-content: center;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
.hl-scroll-btn .ic { width: 20px; height: 20px; }
.hl-scroll-btn:active { background: color-mix(in srgb, var(--button) 20%, var(--bg)); }
.hl-palette { gap: 6px; padding: 6px 8px; }
.hl-pick { width: 28px; height: 28px; }
.hl-palette-label { display: none; }
@media (min-width: 400px) { .hl-palette-label { display: inline; } }

/* ---- Report a problem: the bug button on every screen ---- */
.bug-btn {
  position: fixed; z-index: 60; left: 12px;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(128,128,128,0.25);
  background: var(--secondary-bg); color: var(--hint); opacity: 0.85; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 3px 10px rgba(13, 59, 102, 0.15);
}
.bug-btn .ic { width: 20px; height: 20px; }
.bug-btn:active { opacity: 1; color: var(--link); }
.bug-btn:disabled { opacity: 0.4; }
body.reader-fs .bug-btn, body.needs-login .bug-btn { display: none; }
#bug-sheet { z-index: 950; }
#bug-sheet h2 .ic { color: var(--button); vertical-align: -0.12em; }
#bug-text { resize: vertical; font: inherit; min-height: 90px; }
.bug-shots { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; align-items: stretch; }
.bug-shot { position: relative; width: 104px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--hint); }
.bug-shot img { width: 104px; height: 150px; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid rgba(128,128,128,0.25); background: var(--bg); }
.bug-shot-x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(12,21,36,0.7); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.bug-shot-x .ic { width: 14px; height: 14px; }
.bug-attach { width: 104px; height: 150px; border-radius: 8px; border: 1.5px dashed rgba(128,128,128,0.45); background: var(--bg); color: var(--link); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 12px; cursor: pointer; text-align: center; padding: 6px; }
.bug-attach[hidden] { display: none; }
.bug-attach .ic { width: 22px; height: 22px; }

/* "From page X to page Y" (Summarize, Flashcards) */
.page-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-range label { display: flex; align-items: center; gap: 6px; }
.page-range input { width: 76px; padding: 8px; border-radius: 8px; }
.page-range .btn { flex: 1 1 100%; }
.page-range-hint { margin: 4px 0 0; font-size: 0.85em; }

/* A specialty with no books yet */
.coming-soon { text-align: center; padding: 24px 12px; }
.coming-soon p { margin: 4px 0; }

/* Interaction checker: severity cards */
.ix-result { display: flex; flex-direction: column; gap: 10px; }
.ix-bottom { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent, #2f7de1) 10%, transparent); }
.ix-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.ix-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8em; font-weight: 600; white-space: nowrap; }
.ix-contraindicated { background: #d92d20; color: #fff; }
.ix-major { background: #ef6c00; color: #fff; }
.ix-moderate { background: #f5c518; color: #3a2e00; }
.ix-minor { background: #2e9e5b; color: #fff; }
.ix-possible { background: #8a94a6; color: #fff; }
.ix-card { border: 1px solid color-mix(in srgb, currentColor 15%, transparent); border-left-width: 5px; border-radius: 10px; padding: 10px 12px; }
.ix-card-contraindicated { border-left-color: #d92d20; }
.ix-card-major { border-left-color: #ef6c00; }
.ix-card-moderate { border-left-color: #f5c518; }
.ix-card-minor { border-left-color: #2e9e5b; }
.ix-card-possible { border-left-color: #8a94a6; }
.ix-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ix-pair { overflow-wrap: anywhere; }
.ix-title { margin: 6px 0 4px; font-weight: 600; }
.ix-field { display: flex; flex-direction: column; margin-top: 6px; }
.ix-field-name { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.03em; opacity: 0.65; }
.ix-quotes { margin-top: 8px; }
.ix-quotes summary { cursor: pointer; font-size: 0.9em; opacity: 0.8; }
.ix-quotes blockquote { margin: 6px 0 0; padding: 6px 10px; border-left: 3px solid color-mix(in srgb, currentColor 25%, transparent); font-size: 0.92em; }
.ix-quotes cite { display: block; margin-top: 4px; font-size: 0.85em; opacity: 0.65; font-style: normal; }
.ix-sources { margin: 8px 0 0; font-size: 0.82em; opacity: 0.65; overflow-wrap: anywhere; }
.ix-none { margin: 0; }
.ix-note { margin: 0; font-size: 0.85em; }

/* A summary/quiz/flashcards job that finished while the user was elsewhere */
#job-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 14px;
  background: var(--secondary-bg, #fff); color: var(--text, #111); border: 1px solid var(--border, #ddd);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  max-width: 560px; margin: 0 auto;
}
#job-banner[hidden] { display: none; }
#job-banner .job-banner-text { flex: 1; display: flex; gap: 8px; align-items: flex-start; min-width: 0; font-size: 0.92em; }
#job-banner .job-banner-text > span { overflow-wrap: anywhere; }
#job-banner .btn { width: auto; padding: 8px 14px; margin: 0; }
.job-bg-hint { font-size: 0.85em; margin-top: 4px; }
.job-ready-label { margin: 8px 0 0; font-size: 0.85em; }

/* Searchable specialty lists */
.sel-search-wrap { position: relative; display: block; }
.sel-search-wrap[hidden] { display: none; }
.sel-search-cover { position: absolute; inset: 0; width: 100%; height: 100%; background: transparent; border: 0; padding: 0; margin: 0; cursor: pointer; }
.sel-search-cover:disabled { cursor: default; }
.sel-search-sheet {
  background: var(--secondary-bg); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; max-height: 78vh; padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sel-search-head { display: flex; gap: 8px; align-items: center; padding: 12px 14px 8px; }
.sel-search-input {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 16px;
}
.sel-search-list { overflow-y: auto; padding: 0 6px 12px; }
.sel-search-item {
  display: block; width: 100%; text-align: start; padding: 12px 12px; border: 0; background: none;
  color: var(--text); font-size: 15px; border-radius: 10px;
}
.sel-search-item:active, .sel-search-item:hover { background: var(--primary-soft); }
.sel-search-item.is-current { font-weight: 600; color: var(--link); }
.sel-search-empty { padding: 12px; }

/* ---- Calculators ---- */
.beta-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  background: var(--primary-soft, rgba(38,120,182,0.15)); color: var(--link); vertical-align: middle; }
.calc-search { margin-top: 0; }
.calc-cat { margin: 16px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--hint); display: flex; align-items: center; gap: 6px; }
.calc-cat:first-child { margin-top: 4px; }
.calc-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--border, rgba(128,128,128,0.2)); }
.calc-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 10px 4px; color: var(--text); font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.calc-open .muted { font-size: 12.5px; }
.calc-fav { background: none; border: 0; padding: 0 10px; color: var(--hint); cursor: pointer; opacity: 0.55; }
.calc-fav.is-on { color: #e0a100; opacity: 1; }
.calc-fav.is-on .ic { fill: currentColor; }
.calc-title { margin: 12px 0 2px; font-size: 19px; }
.calc-about { margin: 0 0 12px; }
.calc-field { display: block; margin: 12px 0; }
.calc-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.calc-hint { display: block; font-size: 12px; color: var(--hint); margin-top: 3px; font-weight: 400; }
.calc-num-row { display: flex; gap: 8px; align-items: center; }
.calc-num, .calc-date { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 10px; font: inherit; font-size: 16px;
  border: 1.5px solid rgba(128,128,128,0.32); background: var(--bg); color: var(--text); box-sizing: border-box; }
.calc-date { width: 100%; }
.calc-num:focus, .calc-date:focus { outline: none; border-color: var(--button); }
.calc-unit { padding: 10px 8px; border-radius: 10px; border: 1.5px solid rgba(128,128,128,0.32); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; max-width: 46%; }
.calc-unit-label { color: var(--hint); font-size: 14px; white-space: nowrap; min-width: 44px; }
.calc-check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--border, rgba(128,128,128,0.2)); cursor: pointer; }
.calc-check input { width: 20px; height: 20px; margin: 1px 0 0; flex-shrink: 0; accent-color: var(--button); }
.calc-check-text { flex: 1; font-size: 14.5px; }
.calc-pts { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.calc-opt { padding: 8px 12px; border-radius: 10px; border: 1.5px solid rgba(128,128,128,0.32); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.calc-opt.is-on { border-color: var(--button); background: var(--button); color: var(--button-text); }
.calc-result { margin: 16px 0 8px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border, rgba(128,128,128,0.25)); border-left: 5px solid var(--hint); background: var(--bg); }
.calc-result.is-empty { border-left-color: rgba(128,128,128,0.35); }
.calc-result.is-empty p, .calc-result .calc-error { margin: 0; }
.calc-result.tone-ok { border-left-color: #2e9e5b; }
.calc-result.tone-warn { border-left-color: #ef9a00; }
.calc-result.tone-bad { border-left-color: #d92d20; }
.calc-result.tone-info { border-left-color: var(--link); }
.calc-res-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; font-size: 14px; }
.calc-res-row.is-main { font-size: 16px; }
.calc-res-row.is-main strong { font-size: 24px; }
.calc-res-label { color: var(--hint); }
.calc-res-row.is-main .calc-res-label { color: var(--text); font-weight: 600; }
.calc-res-value { text-align: right; font-variant-numeric: tabular-nums; }
.calc-interp { margin: 8px 0 0; font-weight: 600; }
.calc-notes { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--hint); }
.calc-notes li { margin: 3px 0; }
.calc-ref, .calc-disclaimer { font-size: 12px; margin: 8px 0 0; }

/* ---- Patient case practice ---- */
.action-btn .beta-badge { margin-top: 2px; }
.case-intro { margin-top: 0; }
.case-card { display: flex; gap: 12px; align-items: center; margin: 12px 0; padding: 12px; border-radius: 12px; background: var(--bg); }
.case-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft, rgba(38,120,182,0.15)); color: var(--link); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.case-thread { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.case-msg { max-width: 88%; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.case-who { display: block; font-size: 11px; font-weight: 700; opacity: 0.7; margin-bottom: 2px; }
.case-student { align-self: flex-end; background: var(--button); color: var(--button-text); border-bottom-right-radius: 4px; }
.case-patient { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.case-finding { align-self: flex-start; background: none; border: 1px dashed rgba(128,128,128,0.5); border-radius: 10px; font-size: 13.5px; }
.case-typing .case-who { animation: case-blink 1s infinite; font-size: 18px; margin: 0; }
@keyframes case-blink { 50% { opacity: 0.2; } }
.case-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip-btn { padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(128,128,128,0.35); background: var(--bg); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.chip-btn:disabled { opacity: 0.45; }
.case-input-row { align-items: flex-end; }
.case-input-row textarea { resize: none; min-height: 46px; font-size: 15px; }
.case-wide { width: 100%; box-sizing: border-box; display: block; margin-bottom: 8px; }
.case-feedback p { margin: 8px 0 4px; }
.case-list { margin: 4px 0 8px; padding-left: 20px; font-size: 14px; }
.case-list li { margin: 4px 0; }
.case-row .check-title { flex: 1; min-width: 0; }

/* ---- Patients ---- */
.subtabs { overflow-x: auto; scrollbar-width: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs .subtab { flex: 1 0 auto; white-space: nowrap; padding-left: 12px; padding-right: 12px; }
.pt-intro { margin-top: 0; }
.pt-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 4px; background: none; border: 0;
  border-bottom: 1px solid var(--border, rgba(128,128,128,0.2)); color: var(--text); font: inherit; cursor: pointer; }
.pt-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pt-row-main .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-row-counts { display: flex; gap: 4px; flex-shrink: 0; }
.pt-clear { color: #2e9e5b; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.pt-empty { text-align: center; color: var(--hint); padding: 18px 0 6px; }
.pt-actions { margin-top: 14px; }
.pt-privacy { font-size: 12px; margin-top: 10px; }
.pt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pt-grid .calc-num, #pt-view .calc-field > .calc-num { width: 100%; }
.pt-wide { max-width: none; width: 100%; }
.pt-top { display: flex; justify-content: space-between; align-items: center; min-height: 34px; }
.pt-head-main { flex: 1; min-width: 0; }
.pt-missing { font-size: 13px; margin: 0 0 6px; }
.pt-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pt-chip-input { flex: 1; min-width: 130px; padding: 7px 10px; border-radius: 999px; border: 1px dashed rgba(128,128,128,0.45);
  background: none; color: var(--text); font: inherit; font-size: 13px; }
.pt-chip-input:focus { outline: none; border-style: solid; border-color: var(--button); }
.pt-drug { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; padding: 10px 10px 10px 12px; margin: 8px 0;
  border-radius: 12px; border: 1px solid var(--border, rgba(128,128,128,0.25)); border-left: 5px solid #2e9e5b; background: var(--bg); }
.pt-drug-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; grid-column: 1 / -1; overflow-wrap: anywhere; }
.pt-dose { min-width: 0; padding: 8px 10px; border-radius: 9px; border: 1px solid rgba(128,128,128,0.3); background: var(--secondary-bg); color: var(--text); font: inherit; font-size: 14px; }
.pt-dose:focus { outline: none; border-color: var(--button); }
.pt-drug.is-unresolved { border-left-color: #8a94a6; border-left-style: dashed; }
.pt-unres { font-size: 12px; color: var(--hint); flex-basis: 100%; }
.pt-drug.sev-contraindicated { border-left-color: #d92d20; animation: pt-glow-red 1.8s ease-in-out infinite; }
.pt-drug.sev-major { border-left-color: #ef6c00; animation: pt-glow-orange 2.2s ease-in-out infinite; }
.pt-drug.sev-moderate { border-left-color: #f5c518; box-shadow: 0 0 0 1px rgba(245,197,24,0.35); }
.pt-drug.sev-minor { border-left-color: #2e9e5b; }
.pt-drug.sev-possible { border-left-color: #8a94a6; }
@keyframes pt-glow-red { 0%, 100% { box-shadow: 0 0 0 1px rgba(217,45,32,0.35), 0 0 4px rgba(217,45,32,0.15); } 50% { box-shadow: 0 0 0 1px rgba(217,45,32,0.6), 0 0 16px rgba(217,45,32,0.55); } }
@keyframes pt-glow-orange { 0%, 100% { box-shadow: 0 0 0 1px rgba(239,108,0,0.3), 0 0 3px rgba(239,108,0,0.12); } 50% { box-shadow: 0 0 0 1px rgba(239,108,0,0.5), 0 0 12px rgba(239,108,0,0.45); } }
@media (prefers-reduced-motion: reduce) { .pt-drug { animation: none !important; } }
.pt-add-row { margin-top: 6px; }
.pt-review-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.pt-review-note { font-size: 12.5px; margin: 4px 0 10px; }
.pt-type { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--hint); }
.pt-dismiss { margin-top: 8px; opacity: 0.8; }
.ix-card.is-dismissed { opacity: 0.7; }
.pt-ok { margin: 12px 0; }
.pt-ok summary { cursor: pointer; font-size: 14px; }
.pt-ok .ix-result { margin-top: 8px; }
.pt-delete { color: var(--danger); }
.pt-reason-title { flex: 1; }
.pt-reason-other { padding: 6px 8px 0; }
/* Plans (Basic / Pro / Max): the table buyers compare, and the profile's usage card */
.plan-table { display: grid; gap: 8px; margin-top: 10px; }
.plan-card { border: 1px solid rgba(128,128,128,0.25); border-radius: 12px; padding: 8px 12px; background: var(--bg); }
.plan-card.is-current { border-color: var(--ok, #2fb36d); }
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-prices { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; margin: 4px 0; }
.plan-card ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.plan-card li { margin: 1px 0; }
.access-row.is-full b { color: #c0392b; }
.acc-cost-line.is-over { color: #c0392b; }
.tier-tag { display: block; margin-top: 2px; }
.acc-tier-row { margin-top: 8px; }
#acc-budget { font-size: 13px; margin-top: 6px; }

/* Credit meter: fills as the month's credits are used. */
.credit-meter { display: grid; gap: 6px; padding: 12px 14px; border-radius: 14px; background: var(--secondary-bg); border: 1px solid rgba(127,127,127,.18); margin: 8px 0; }
.credit-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.credit-top span { display: inline-flex; align-items: center; gap: 6px; }
.credit-top .ic { width: 16px; height: 16px; color: var(--link); }
.credit-bar { height: 10px; border-radius: 999px; background: rgba(127,127,127,.2); overflow: hidden; }
.credit-bar i { display: block; height: 100%; border-radius: inherit; background: var(--button); transition: width .4s ease; }
.credit-meter.is-warn .credit-bar i { background: #f2994a; }
.credit-meter.is-crit .credit-bar i { background: #eb5757; }
.credit-meter.is-crit .credit-top b { color: #eb5757; }
.credit-sub { font-size: 13px; }
.acc-credit-line .credit-meter { padding: 8px 10px; margin: 4px 0; }
.plan-packs { border-style: dashed; }
.plan-note { font-size: 13px; margin: 4px 2px 10px; }

/* "From page [ ] to page [ ]" for summaries and flashcards */
.page-range-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(128,128,128,0.18); }
.page-range { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 6px 0 4px; }
.page-range label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.page-range input { width: 84px; padding: 8px; font-size: 15px; border-radius: 10px; border: 1px solid rgba(128,128,128,0.3); background: var(--secondary-bg); color: var(--text); }
.page-range-hint { font-size: 12px; margin: 0 0 10px; }
.flash-source { display: inline-flex; gap: 4px; padding: 3px; border-radius: 12px; background: rgba(128,128,128,0.12); margin: 4px 0 2px; }
.flash-source .seg-btn { border: 0; background: transparent; padding: 7px 16px; border-radius: 9px; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; }
.flash-source .seg-btn.is-on { background: var(--secondary-bg); box-shadow: 0 1px 3px rgba(0,0,0,0.12); font-weight: 600; }

/* Admin "Add a user": plan / length / credit buttons */
.choice-grid { display: grid; gap: 8px; margin: 4px 0 12px; }
.choice-grid.choice-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-grid.choice-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choice-btn { display: grid; gap: 2px; justify-items: center; padding: 10px 4px; border-radius: 12px; border: 1.5px solid rgba(128,128,128,0.25); background: var(--secondary-bg); color: var(--text); font: inherit; cursor: pointer; min-width: 0; }
.choice-btn strong { font-size: 14px; }
.choice-btn span { font-size: 12px; color: var(--hint); }
.choice-btn.is-on { border-color: var(--button); background: color-mix(in srgb, var(--button) 12%, var(--secondary-bg)); }
.choice-btn.is-on span { color: var(--link); }
.acc-new-total { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; align-items: baseline; padding: 10px 12px; border-radius: 12px; background: rgba(128,128,128,0.08); font-size: 13px; margin: 0 0 12px; }
.acc-new-total b { font-size: 15px; }

.plan-cost-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.plan-cost-table th, .plan-cost-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(128,128,128,0.18); }
.plan-cost-table th { font-weight: 600; color: var(--hint); font-size: 12px; }
