/* ---------- In-browser reader ---------- */
/* Full-screen layer above the index-card modal. Chrome is built from the same
   semantic tokens as the rest of the site, so it follows the light/dark
   toggle with no reader-specific palette of its own. */

.reader-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: var(--overlay-blur);
  display: none;
  z-index: 200;          /* above .modal-backdrop (100) */
  padding: 0;
}
.reader-backdrop.open { display: flex; }

/* the page behind must not scroll while the reader owns the screen */
body.reader-open { overflow: hidden; }

.reader {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-modal);
  width: min(1080px, 100%);
  height: min(94vh, 100%);
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- toolbar ---------- */
.reader-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.reader-title {
  font-family: 'Noto Serif Ethiopic', serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ivory);
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-tools { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

.reader-icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  min-width: 38px;
  min-height: 38px;      /* stays a comfortable tap target on phones */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 10px;
  text-decoration: none;
}
.reader-icon-btn:hover { border-color: var(--brass); color: var(--brass); }
.reader-icon-btn:disabled { opacity: 0.4; cursor: default; }
.reader-icon-btn:disabled:hover { border-color: var(--border); color: var(--ink); }
.reader-zoom-label,
.reader-page-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem;
  color: var(--dim-soft);
  min-width: 62px;
  text-align: center;
  user-select: none;
}

/* ---------- page stage ---------- */
/* .reader-stage is a plain block scroll container (not flex-centered) on
   purpose: centering a flex container clips its start-side overflow from the
   scroll range, so a zoomed page could never be scrolled back to its top. The
   list stacks normally here; each .reader-page centers itself via margin. */
.reader-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background:
    radial-gradient(circle at 50% 0%, rgba(var(--gold-rgb), 0.05), transparent 60%),
    var(--bg);
}
.reader-pages {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 22px;
}
.reader-page {
  position: relative;
  /* margin, not align-items:center on the list — same overflow-clipping
     reason as above, this time on the horizontal axis when zoomed wide */
  margin: 0 auto;
}
.reader-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  box-shadow: var(--shadow-card);
  background: #fff;      /* paper shows through before the first paint */
}
/* Dark theme dims the paper instead of inverting it: these are scanned
   Amharic pages, and inverting turns photographs and plates into negatives. */
[data-theme="dark"] .reader-canvas { filter: brightness(0.86) contrast(1.03); }
/* Dark theme dims the paper instead of inverting it: these are scanned
   Amharic pages, and inverting turns photographs and plates into negatives. */
[data-theme="dark"] .reader-canvas { filter: brightness(0.86) contrast(1.03); }

/* ---------- status / loading ---------- */
.reader-status {
  position: absolute;
  inset: 0;
  display: none;         /* JS flips this to flex */
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-direction: column;
  text-align: center;
  padding: 24px;
  color: var(--dim);
  font-size: 0.9rem;
  pointer-events: none;
}
.reader-stage-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.reader-spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--brass);
  animation: reader-spin 0.8s linear infinite;
}
@keyframes reader-spin { to { transform: rotate(360deg); } }

/* ---------- footer pager ---------- */
.reader-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  /* clears the iOS Safari home indicator */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

@media (max-width: 640px) {
  .reader-backdrop { padding: 0; }
  .reader {
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
  }
  .reader-bar { padding: 8px 10px; gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .reader-title { font-size: 0.85rem; }
  /* zoom controls are redundant next to pinch-zoom, and the bar is tight */
  .reader-zoom-group { display: none; }
  .reader-stage { padding: 8px; }
}
