/*
 * The reader chrome — everything AROUND the book. The book's own document is styled by
 * themes.js and injected through foliate's setStyles().
 *
 * Reading fonts are self-hosted, not fetched: a reader that needs the network to render a
 * page is not an offline reader, and the CSP here has no remote host to fetch from.
 * The @font-face rules land in Phase 1b with the font files; until then the stacks below
 * fall back to a real system serif rather than to sans.
 */

:root {
  --reader-page: #f7f3ea;
  --reader-text: #1b1b1b;
  --reader-muted: #6b6459;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--reader-page);
  color: var(--reader-text);
  font-family: Literata, Georgia, 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
  /* The tap zones are the primary control. Text selection still works on long-press;
     this only stops the double-tap-to-zoom and the callout that fight with paging. */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#view-host {
  position: absolute;
  inset: 0;
  display: flex;
}

foliate-view {
  flex: 1;
  min-width: 0;
}

#status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--reader-muted);
  background: var(--reader-page);
  pointer-events: none;
}

/*
 * 🔴 This rule is load-bearing. Without it the reader is PERMANENTLY BLANK.
 *
 * `status(null)` hides this panel with `statusEl.hidden = true`. But `[hidden] { display: none }`
 * comes from the USER-AGENT stylesheet, and the author rule above (`#status { display: flex }`)
 * outranks it — so the attribute is set, the element stays `display: flex`, and because it is
 * `inset: 0` with an OPAQUE background it covers the fully-rendered book forever. The reader shows
 * "Opening…" over a book that opened perfectly.
 *
 * This shipped from Phase 1 and hit both shells identically, because the bug is in the engine and
 * the engine is shared. Nothing could catch it: every step reported success, `status(null)` really
 * was called, and `render:verify` correctly reported `painted: 1` — the page WAS painted, just
 * underneath. Confirmed 08/23/2026 by reading the computed style rather than the trace:
 * `hidden === true` while `getComputedStyle(el).display === "flex"`.
 *
 * Never set `display` on this element without keeping this override next to it.
 */
#status[hidden] {
  display: none;
}

#status[data-kind='error'] {
  color: #b3261e;
  font-weight: 600;
}

/* Respect the phone's notch and gesture bar without the book text sliding under them. */
@supports (padding: env(safe-area-inset-top)) {
  #view-host {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
      env(safe-area-inset-left);
  }
}
