/* ============================================================
   OpenDyslexic — self-hosted woff. SIL Open Font License 1.1.
   Loaded once; available to anyone who switches the reader font to
   "Dyslexic" via the settings sheet.
   ============================================================ */
@font-face {
  font-family: "OpenDyslexic";
  src: url("/fonts/OpenDyslexic-Regular.woff") format("woff");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("/fonts/OpenDyslexic-Bold.woff") format("woff");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("/fonts/OpenDyslexic-Italic.woff") format("woff");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("/fonts/OpenDyslexic-Bold-Italic.woff") format("woff");
  font-weight: 700; font-style: italic; font-display: swap;
}

/* ============================================================
   FocusReader — design tokens
   Warm paper aesthetic. Editorial. Calm.
   ============================================================ */

:root {
  /* paper / surfaces */
  --bg: #F4EEE2;
  --bg-soft: #EFE7D6;
  --bg-deep: #E7DDC6;
  --bg-page: #FBF7EE;       /* the actual reader "page" */
  --bg-dark: #1F1B14;       /* dark mode reader */
  --card: #FBF7EE;

  /* ink */
  --ink: #1A1611;
  --ink-soft: #46402F;
  --ink-muted: #8A7F66;
  --ink-faint: #B8AC91;

  /* accent — like a reading lamp */
  --accent: #B85C28;
  --accent-deep: #8C3F12;
  --accent-soft: #F2D8BD;
  --accent-tint: #FAEEDC;

  /* secondary */
  --leaf: #4E7140;          /* progress, success */
  --berry: #8B3A53;         /* highlights */
  --sky: #4E6E89;           /* informational */

  /* feedback */
  --line: #DDD3BE;
  --line-soft: #E6DDC8;
  --highlight: #FBE6A2;

  /* type — two fonts only.
     Instrument Serif for landing display headings + italic accents.
     Geist for absolutely everything else: UI, body, reader content.
     Mono contexts (timers, percentages) use Geist with tabular-nums. */
  --font-display: "Instrument Serif", Georgia, serif;
  --font-ui: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-reader: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-dyslexic: "Geist", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist", system-ui, -apple-system, sans-serif;

  /* radii */
  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* shadows — soft, paper-like */
  --shadow-1: 0 1px 0 rgba(38,28,12,0.04), 0 1px 2px rgba(38,28,12,0.04);
  --shadow-2: 0 1px 0 rgba(38,28,12,0.04), 0 8px 24px -8px rgba(38,28,12,0.12);
  --shadow-3: 0 2px 0 rgba(38,28,12,0.04), 0 24px 48px -16px rgba(38,28,12,0.18);

  /* motion */
  --ease: cubic-bezier(.2,.7,.2,1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================ */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.gap-4 { gap: 16px; } .gap-5 { gap: 24px; } .gap-6 { gap: 32px; }
.flex-1 { flex: 1; }
.text-muted { color: var(--ink-muted); }
.text-soft { color: var(--ink-soft); }
/* "mono" contexts now use Geist with tabular-nums so digits align without
   loading a separate monospace family. */
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: 0;
}
.serif { font-family: var(--font-display); }

/* ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  font-size: 14px; font-weight: 500; letter-spacing: -0.005em;
  background: transparent; color: var(--ink);
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(0.5px); }

.btn-primary { background: var(--ink); color: var(--bg-page); border-color: var(--ink); }
.btn-primary:hover { background: #2A2418; border-color: #2A2418; }

.btn-accent { background: var(--accent); color: #FFF8EF; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn-outline { border-color: var(--line); background: transparent; }
.btn-outline:hover { background: var(--bg-soft); border-color: var(--ink-muted); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(26,22,17,0.06); }

.btn-lg { padding: 14px 22px; font-size: 16px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--r-pill); }

/* ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: 12px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.4);
}
.chip-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--accent); }

/* ============================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
}
.card-elev { box-shadow: var(--shadow-2); }

/* ============================================================ */
.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-page);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 96px; }

/* Headings: Instrument Serif elsewhere. Inside the reader we force Geist
   so book content (chapter titles + body) is all sans, per design feedback. */
h1, h2, h3 { line-height: 1.05; }
h1 { margin-block: 0; }

[data-screen-label="reader"] h1,
[data-screen-label="reader"] h2,
[data-screen-label="reader"] h3,
[data-screen-label="reader"] .reader-page,
[data-screen-label="reader"] .reader-page * {
  font-family: var(--font-reader) !important;
  font-style: normal !important;
}
/* The first-letter drop cap in reader was italic-serif; restore it as a
   bold sans-serif accent so it still draws the eye without breaking the
   sans rule. */
[data-screen-label="reader"] .reader-page > p:first-of-type > span > span:first-child {
  font-weight: 700 !important;
}

/* ============================================================ */
.reader-page {
  font-family: var(--font-reader);
  font-size: 21px;
  line-height: 1.7;
  color: var(--ink);
  letter-spacing: -0.003em;
}

.anchor b, .anchor strong { font-weight: 600; }

.focus-mode p { transition: opacity .35s var(--ease); }

.ruler-band {
  position: absolute;
  left: 0; right: 0;
  background: linear-gradient(180deg, transparent, var(--highlight) 30%, var(--highlight) 70%, transparent);
  pointer-events: none;
  mix-blend-mode: multiply;
  transition: transform .12s linear, height .15s var(--ease);
}

.sentence-active { background: linear-gradient(180deg, transparent 55%, var(--highlight) 55%); }

.rsvp-word { font-family: var(--font-reader); font-size: 72px; line-height: 1; letter-spacing: -0.02em; }
.rsvp-pivot { color: var(--accent); }

.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--accent); transition: stroke-dashoffset .4s var(--ease); }

.dot-rule {
  height: 1px;
  background-image: radial-gradient(circle, var(--ink-faint) 1px, transparent 1px);
  background-size: 6px 1px;
  background-repeat: repeat-x;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes flameFlicker {
  0%,100% { transform: scaleY(1) translateY(0); opacity: 1; }
  50% { transform: scaleY(1.05) translateY(-1px); opacity: 0.92; }
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.fade-in { animation: fadeIn .35s var(--ease) both; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }

/* ============================================================
   Reader toggles — Tint + Focus
   ============================================================ */

/* TINT: a warm-paper background under the reading column.
   Theme-aware so it blends instead of clashing — sepia got a warmer amber
   wash, paper keeps the yellow it had, and dark mode is opted out entirely
   (dark text on a yellow wash is illegible).
   Uses a CSS variable defaulted in :root, overridden per theme below. */
:root { --tint-wash: linear-gradient(180deg, rgba(251, 230, 162, 0.55) 0%, rgba(251, 230, 162, 0.32) 100%); }
[data-screen-label="reader"].fr-tint-on .fr-reader-column {
  background: var(--tint-wash);
  border-radius: 8px;
  transition: background .3s var(--ease);
}
/* Sepia base is already a warm amber — a yellow wash on top muddies it.
   Use a softer translucent ink wash that deepens the existing tone instead. */
[data-screen-label="reader"][data-theme="sepia"] {
  --tint-wash: linear-gradient(180deg, rgba(120, 80, 32, 0.10) 0%, rgba(120, 80, 32, 0.04) 100%);
}
/* FOCUS: dim the chrome (top toolbar + bottom HUD) so the reading page
   is the only thing your eye is drawn to. Move the mouse over them or
   tap them and they come back to full opacity. */
[data-screen-label="reader"].fr-focus-on .fr-reader-top {
  opacity: 0.28;
  transition: opacity .35s var(--ease);
}
[data-screen-label="reader"].fr-focus-on .fr-reader-top:hover,
[data-screen-label="reader"].fr-focus-on .fr-reader-top:focus-within {
  opacity: 1;
}
/* Bottom HUD stays visible in focus mode — it holds the primary controls
   (Pomodoro toggle, Audio toggle, sound picker). Fading it to 35% made the
   buttons hard to see on the user's desktop. Top bar still fades because
   it's mostly secondary chrome (book metadata, settings cog). */
/* Also fade the nav rail + side rail trigger when focus mode is on */
[data-screen-label="reader"].fr-focus-on .fr-nav-rail button,
[data-screen-label="reader"].fr-focus-on .fr-side-rail-trigger {
  opacity: 0.35;
  transition: opacity .35s var(--ease);
}
[data-screen-label="reader"].fr-focus-on .fr-nav-rail button:hover,
[data-screen-label="reader"].fr-focus-on .fr-side-rail-trigger:hover {
  opacity: 1;
}
/* On touch devices (no hover), tapping anywhere brings chrome back */
@media (hover: none) {
  [data-screen-label="reader"].fr-focus-on .fr-reader-top:active,
  [data-screen-label="reader"].fr-focus-on .fr-reader-hud > div:active { opacity: 1; }
}

/* ============================================================
   Auth modal
   ============================================================ */
.auth-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-page);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
  box-sizing: border-box;
}
.auth-input::placeholder { color: var(--ink-faint); }
.auth-input.invalid {
  border-color: var(--accent-deep);
  background: rgba(184, 92, 40, 0.04);
}
.auth-input.invalid:focus { box-shadow: 0 0 0 2px rgba(184, 92, 40, 0.18); }
.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent);
}

/* ============================================================
   MOBILE LAYOUT (max-width: 820px)
   Class-based selectors only. Inline-style React components that
   need a mobile variant carry the corresponding class on the root.
   ============================================================ */

.fr-drawer-scrim { display: none; }
.fr-mobile-topbar { display: none; }
.fr-hud-nav { display: none; }

@media (max-width: 820px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* ---------- AppShell: collapse to drawer ---------- */
  .fr-app-shell { grid-template-columns: 1fr !important; }
  .fr-drawer-scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(20,16,8,0.4);
    z-index: 55;
    opacity: 0; pointer-events: none;
    transition: opacity .2s var(--ease);
  }
  .fr-drawer-scrim.open { opacity: 1; pointer-events: auto; }

  .fr-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    width: min(86vw, 320px) !important;
    height: 100dvh !important;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .25s var(--ease);
    border-right: 1px solid var(--line) !important;
    box-shadow: 8px 0 24px -8px rgba(38,28,12,0.25);
    overflow-y: auto !important;
    padding: 14px 12px !important;
    gap: 14px !important;
  }
  .fr-sidebar.open { transform: translateX(0); }
  .fr-sidebar nav { gap: 2px !important; }
  .fr-sidebar nav button { padding: 11px 12px !important; font-size: 14px !important; }
  .fr-sidebar .fr-sidebar-spacer { flex: 0 1 8px !important; }
  .fr-sidebar-goal { padding: 12px !important; }

  .fr-mobile-topbar {
    display: flex;
    position: sticky; top: 0; z-index: 40;
    align-items: center; justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line-soft);
    backdrop-filter: blur(10px);
    gap: 10px;
  }
  .fr-mobile-topbar > .fr-mobile-brand {
    flex: 1 1 auto;
    display: flex; justify-content: center; align-items: center;
    overflow: hidden;
    min-width: 0;
  }

  /* ---------- Page-level padding shrink ---------- */
  .fr-page-pad      { padding: 20px 14px 0 !important; }
  .fr-page-pad-tight { padding: 0 14px 56px !important; }

  .fr-greeting h1 { font-size: 30px !important; line-height: 1.15 !important; }
  .fr-greeting p  { font-size: 14px !important; }
  .fr-greeting > .row { flex-wrap: wrap !important; gap: 12px !important; }
  .fr-greeting-meta { flex: 1 1 100% !important; }
  .fr-greeting-actions { flex-wrap: wrap !important; gap: 10px !important; width: 100%; }
  .fr-greeting-actions > * { flex: 1 1 auto; }

  /* ---------- Library Resume card ---------- */
  .fr-resume-card {
    grid-template-columns: 1fr !important;
    padding: 18px !important;
    gap: 14px !important;
    justify-items: stretch !important;
    text-align: left;
  }
  .fr-resume-card h3 { font-size: 22px !important; line-height: 1.15 !important; }
  .fr-resume-cover { justify-self: start !important; }
  .fr-resume-meta { flex-wrap: wrap !important; font-size: 12px !important; gap: 8px 14px !important; }
  .fr-resume-actions { flex-direction: row !important; flex-wrap: wrap !important; gap: 8px !important; }
  .fr-resume-actions > * { flex: 1 1 auto; }

  /* Library grid + toolbar */
  .fr-book-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 18px !important; }
  .fr-library-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .fr-library-toolbar > * { width: 100% !important; max-width: 100% !important; }
  .fr-library-toolbar input { min-width: 0 !important; }

  /* ---------- Upload page ----------
     minmax(0, 1fr) — NOT bare 1fr — so the track can shrink below children's
     min-content. Without the minmax(0, ...) clamp, an inline tab strip or a
     nowrap chip forces the column to balloon past the viewport. */
  .fr-upload-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 18px !important; padding: 20px 14px 56px !important; }
  .fr-upload-grid > * { min-width: 0 !important; max-width: 100% !important; }

  /* ---------- Library list view ----------
     The desktop layout has 5+ fixed-width columns that don't fit a phone.
     Hide everything except cover, title, and arrow; surface progress/time/
     last-opened as a compact mono caption stacked under the title. */
  .fr-book-list-head { display: none !important; }
  .fr-book-list-row {
    padding: 14px 14px !important;
    gap: 12px !important;
  }
  .fr-book-list-row .fr-book-list-progress-col,
  .fr-book-list-row .fr-book-list-time-col,
  .fr-book-list-row .fr-book-list-opened-col {
    display: none !important;
  }
  .fr-book-list-row .fr-book-list-title { flex: 1 1 0 !important; min-width: 0 !important; }
  .fr-book-list-row .fr-book-list-title > span { white-space: nowrap !important; }
  .fr-upload-card { padding: 16px !important; }
  .fr-upload-tabs { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .fr-upload-tabs::-webkit-scrollbar { display: none; }
  .fr-upload-tabs > div { flex-wrap: nowrap !important; }
  .fr-upload-tabs button { padding: 7px 11px !important; font-size: 12px !important; white-space: nowrap !important; }
  .fr-upload-drop { padding: 36px 18px !important; }
  .fr-upload-drop > div:nth-child(2) { font-size: 22px !important; }
  .fr-upload-chips { flex-wrap: wrap !important; justify-content: center !important; }
  .fr-tips-card { padding: 18px !important; }
  .fr-tips-card p { font-size: 15px !important; word-break: break-word; line-height: 1.4 !important; }
  .fr-quota-card { padding: 18px !important; }
  .fr-recent-card { padding: 18px !important; }
  .fr-recent-card .row span:first-child + .col span { font-size: 13px !important; max-width: 100%; }

  /* ---------- Stats / Insights ---------- */
  .fr-kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .fr-kpi-grid .card { padding: 14px !important; }
  .fr-kpi-grid .card > div:nth-child(2) { font-size: 22px !important; }

  .fr-stats-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .fr-stats-grid > .fr-span-2 { grid-column: span 1 !important; }
  .fr-stats-card { padding: 16px !important; }

  .fr-milestones { grid-template-columns: repeat(3, 1fr) !important; gap: 12px !important; }
  .fr-milestones .col > div:first-child { width: 44px !important; height: 44px !important; font-size: 18px !important; }

  .fr-heatmap { font-size: 9px !important; }
  .fr-heatmap > div:last-child > div:last-child > div { gap: 2px !important; }

  /* ---------- Highlights page ---------- */
  .fr-highlights-card { padding: 16px !important; }
  .fr-highlights-empty { padding: 28px 18px !important; max-width: 100% !important; }
  .fr-highlights-empty h3 { font-size: 20px !important; }
  .fr-highlights-empty p { max-width: 100% !important; font-size: 14px !important; }

  /* ---------- Auth modal ---------- */
  .auth-modal-grid {
    grid-template-columns: 1fr !important;
    margin: 0 !important;
    border-radius: 16px !important;
    max-width: 100% !important;
  }
  .auth-modal-grid > div:first-of-type { padding: 22px 18px 24px !important; }
  .auth-brand-pane { display: none !important; }
  /* Big serif headline overwhelms the modal on phones — knock it down so
     the form fields are visible without scrolling. */
  .auth-title { font-size: 24px !important; line-height: 1.15 !important; margin-bottom: 6px !important; }
  .auth-subtitle { font-size: 13px !important; margin-bottom: 18px !important; }

  /* ---------- Landing page nav ----------
     Selector previously required header to be a direct child of body > div,
     but the actual DOM nests it deeper (body > #root > Landing div > header).
     Target via the row.gap-5 nav and the header itself, both of which exist
     only on landing. */
  body header > div {
    padding: 12px 14px !important;
    gap: 8px !important;
    flex-wrap: nowrap !important;
    max-width: 100vw !important;
  }
  /* Hide the desktop nav links (Features/Science/Pricing/FAQ) — they don't
     fit on a phone and have no mobile drawer equivalent on landing. */
  body header nav.row { display: none !important; }
  /* CTA buttons in header: tighter, never overflow */
  body header > div > div.row button {
    font-size: 12px !important;
    padding: 6px 10px !important;
    white-space: nowrap !important;
  }

  body section {
    padding: 48px 18px !important;
    gap: 24px !important;
    grid-template-columns: 1fr !important;
    max-width: 100vw !important;
  }
  /* CRITICAL: grid/flex items have min-width: auto by default, which means
     they refuse to shrink below their intrinsic content width. When the hero's
     right-column mockup has fixed-width / absolute-positioned children, the
     LEFT column inherits that intrinsic width too — pushing paragraph + buttons
     off-screen. Forcing min-width: 0 lets them collapse to the viewport. */
  body section > * { min-width: 0 !important; }
  body section p { max-width: 100% !important; }
  body section h1, body section h2, body section h3 { word-break: break-word; }

  /* Hero / Pricing CTA rows wrap, and each button takes a full row so the
     long 'Try without signing up →' label can't fall off the right edge. */
  body section .row.gap-3,
  body section .row.gap-2,
  body section .row.gap-4 { flex-wrap: wrap !important; }
  body section .row.gap-3 > button,
  body section .row.gap-3 > a { flex: 1 1 100% !important; min-width: 0 !important; white-space: normal !important; }
  body h1[style*="88"], body h1[style*="font-size: 88"] { font-size: 38px !important; line-height: 1.1 !important; }
  body h2[style*="56"], body h2[style*="font-size: 56"] { font-size: 28px !important; }
  body h2[style*="48"], body h2[style*="font-size: 48"] { font-size: 26px !important; }

  /* The hero page mock cards — kill the rotation/absolute floats on phone */
  .landing-hero-page { position: relative !important; }
  .landing-hero-page > div { transform: none !important; position: relative !important; }
  .landing-hero-page > div[style*="absolute"]:first-child,
  .landing-hero-page > div[style*="absolute"]:last-child { display: none !important; }

  /* Reader showcase mockup */
  body section [style*="perspective"] { transform: none !important; }

  body section > div { grid-template-columns: 1fr !important; }
  body footer > div { grid-template-columns: 1fr 1fr !important; gap: 24px !important; padding: 0 18px !important; }
  body footer { padding: 40px 0 24px !important; }

  /* ---------- Reader screen ---------- */
  .fr-reader-top {
    grid-template-columns: auto auto 1fr !important;
    padding: 8px 10px !important;
    gap: 8px !important;
  }
  .fr-reader-meta { min-width: 0 !important; flex: 1 1 auto !important; overflow: hidden; }
  .fr-reader-meta > span { font-size: 12px !important; max-width: 48vw !important; }
  .fr-reader-meta > span:nth-child(2) { font-size: 10px !important; }

  /* Top toolbar: hide the 6-pill cluster and the theme button on mobile.
     Replaced by a single Settings button that opens the bottom sheet. */
  .fr-reader-toolbar { display: none !important; }
  .fr-reader-theme-btn { display: none !important; }
  .fr-mobile-sheet-trigger { display: inline-flex !important; }

  /* Top bar reflows: just back + title + settings */
  .fr-reader-top {
    grid-template-columns: auto 1fr auto !important;
    padding: 8px 12px !important;
    gap: 10px !important;
  }
  .fr-reader-meta > span:first-child { max-width: 48vw !important; }

  /* Reading column: full width, padding sized so text doesn't spill
     under the bottom HUD. Use 100dvw so we don't horizontal-scroll. */
  .fr-reader-column {
    max-width: 100dvw !important;
    width: 100%;
    padding: 20px 16px 130px !important;
    box-sizing: border-box;
  }
  /* Don't override font-size or line-height — the typography sliders own
     those. Only keep the width clamp so paragraphs don't escape the column. */
  .fr-reader-column .reader-page { max-width: 100% !important; }
  .fr-reader-column > div > h1 {
    font-size: 26px !important;
    line-height: 1.15 !important;
    margin-bottom: 18px !important;
    word-break: break-word;
  }

  /* Hide desktop side rail + side-rail trigger (use HUD instead) */
  .fr-nav-rail { display: none !important; }
  .fr-side-rail-trigger {
    right: 12px !important;
    bottom: 78px !important;
    top: auto !important;
    transform: none !important;
    width: 40px !important; height: 40px !important;
  }

  /* Bottom HUD */
  .fr-reader-hud {
    bottom: 12px !important;
    left: 12px !important; right: 12px !important;
    justify-content: stretch !important;
  }
  .fr-reader-hud > div {
    width: 100% !important;
    padding: 8px 10px !important;
    gap: 8px !important;
    border-radius: 999px !important;
  }
  /* Ambient-sound picker stays hidden on phones — it lives in the sheet. */
  .fr-hud-sound { display: none !important; }
  .fr-hud-nav { display: inline-flex !important; gap: 6px; }
  .fr-hud-nav button {
    width: 30px; height: 30px; border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.15);
    background: transparent;
    color: inherit;
    display: grid; place-items: center;
    cursor: pointer;
  }
  .fr-hud-nav button[disabled] { opacity: 0.35; }

  /* Hide the floating TTS bar on mobile — all TTS controls live in the
     bottom sheet (Settings) now. The Settings button shows a pulse dot
     when TTS is active so the user can find Pause quickly. */
  .fr-tts-bar { display: none !important; }
}

/* ---------- Very small phones (≤ 380px) ---------- */
@media (max-width: 380px) {
  .fr-book-grid { grid-template-columns: 1fr !important; }
  .fr-kpi-grid { grid-template-columns: 1fr !important; }
  .fr-milestones { grid-template-columns: repeat(2, 1fr) !important; }
  .fr-greeting h1 { font-size: 26px !important; }
  body h1 { font-size: 30px !important; }
  body section h2 { font-size: 24px !important; }
  .fr-reader-column { padding: 18px 14px 130px !important; }
  .fr-reader-meta > span:first-child { max-width: 36vw !important; }
}

/* ---------- Tablet (821 – 1024px): hybrid layout ---------- */
@media (min-width: 821px) and (max-width: 1024px) {
  /* Library: 3-col grid feels right for tablet */
  .fr-book-grid { grid-template-columns: repeat(3, 1fr) !important; }
  /* Stats main grid stays 2-col but tighter */
  .fr-stats-grid { gap: 16px !important; }
  .fr-kpi-grid { grid-template-columns: repeat(4, 1fr) !important; }
  /* Sidebar narrower so content gets more room */
  .fr-app-shell { grid-template-columns: 200px minmax(0, 1fr) !important; }
  /* Upload page: keep two columns but narrower */
  .fr-upload-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) !important; }
}

/* mobile-only progress/time/last-opened caption inside library list rows.
   Default: hidden. The mobile breakpoint reveals it inline. */
.fr-book-list-meta-mobile { display: none; }
@media (max-width: 820px) {
  .fr-book-list-meta-mobile { display: inline-block !important; }
}

/* selection */
::selection { background: var(--accent-soft); color: var(--ink); }

/* ============================================================
   Reader bottom sheet (mobile only)
   ============================================================ */
.fr-sheet, .fr-sheet-scrim { display: none; }

@media (max-width: 820px) {
  .fr-sheet-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 90;
    background: rgba(20,16,8,0.45);
    opacity: 0; pointer-events: none;
    transition: opacity .22s var(--ease);
  }
  .fr-sheet-scrim.open { opacity: 1; pointer-events: auto; }

  .fr-sheet {
    display: flex; flex-direction: column;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
    max-height: 86vh;
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    border: 1px solid;
    border-bottom: none;
    box-shadow: 0 -16px 40px -12px rgba(38,28,12,0.35);
    transform: translateY(105%);
    transition: transform .28s cubic-bezier(.2,.7,.2,1);
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .fr-sheet.open { transform: translateY(0); }

  .fr-sheet-handle {
    align-self: center;
    width: 44px; height: 4px; border-radius: 999px;
    background: currentColor;
    opacity: 0.18;
    margin: 8px 0 4px;
    flex-shrink: 0;
  }
  .fr-sheet-header {
    padding: 8px 18px 4px;
    flex-shrink: 0;
  }
  .fr-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 18px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .fr-sheet-body > section:first-of-type { border-top: none !important; }
}

/* Reader overflow safety — clamp images and long URLs at every size */
.reader-page img, .reader-page figure { max-width: 100% !important; height: auto; }
.reader-page p, .reader-page li { overflow-wrap: anywhere; word-break: break-word; }
.reader-page pre, .reader-page code { white-space: pre-wrap; word-break: break-word; }

/* ============================================================
   Mobile overflow guards for app pages — multiple reports of content
   escaping the viewport (upload tabs, library cards, etc.). Apply blanket
   safety rules: nothing inside the shell main area may exceed viewport,
   horizontal scroll on the body is killed entirely.
   ============================================================ */
@media (max-width: 820px) {
  html, body { overflow-x: hidden !important; }
  .fr-app-shell { max-width: 100vw; overflow-x: hidden; }
  .fr-app-shell main, .fr-app-shell main > * { min-width: 0 !important; max-width: 100% !important; }

  /* Library cards — center cover + text together so alignment reads as
     one column instead of "cover centered, text left". Picks ONE axis.   */
  .fr-book-grid { gap: 22px !important; }
  .fr-book-grid > * { text-align: left; }
  .fr-book-grid > div > div:last-child { padding: 0 2px; }

  /* Upload page — tab bar scrolls horizontally instead of clipping,
     drop zone and helper text never exceed viewport. */
  .fr-upload-tabs { overflow-x: auto; flex-wrap: nowrap !important; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .fr-upload-tabs::-webkit-scrollbar { display: none; }
  .fr-upload-tabs > * { flex-shrink: 0 !important; }
  .fr-upload-card, .fr-upload-drop, .fr-tips-card, .fr-plan-card { max-width: 100% !important; }
  .fr-upload-card input, .fr-upload-card textarea { max-width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
  /* URL input + Import button stack on phones so neither gets clipped. */
  .fr-url-row { flex-wrap: wrap !important; }
  .fr-url-row > * { min-width: 0 !important; }
  .fr-url-row > button { width: 100%; }
}
