


@font-face {
  font-family: 'OpenDyslexic';
  src: url('./fonts/OpenDyslexic-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('./fonts/OpenDyslexic-Italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('./fonts/OpenDyslexic-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('./fonts/OpenDyslexic-BoldItalic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}


:root{
  --reader-font-stack: 'OpenDyslexic3','OpenDyslexic','Atkinson Hyperlegible','Inter','Arial','Helvetica',sans-serif;
}
body, .reader-text {
  font-family: var(--reader-font-stack);
}


@font-face {
  font-family: 'OpenDyslexic';
  src: url('fonts/OpenDyslexic-Regular.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('fonts/OpenDyslexic-Bold.woff2') format('woff2');
  font-weight: bold;
  font-style: normal;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('fonts/OpenDyslexic-Italic.woff2') format('woff2');
  font-weight: normal;
  font-style: italic;
}


/* Embed OpenDyslexic via self-hosted WOFF2 for cross-platform support */





/* reader.css — extracted to enable strict CSP without 'unsafe-inline' */
body {
  font-family: 'OpenDyslexic', Arial, sans-serif;
  background: #f8f8f8;
  color: #000;
  padding: 20px;
  margin: 0;
  line-height: 1.6;
}
#controls {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #fff;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
#content {
  margin-top: 300px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  position: relative;
}
#story {
  white-space: pre-wrap;
  text-align: left;
  cursor: pointer;
}
#definitionPopup {
  position: absolute;
  background: #fff;
  border: 1px solid #ccc;
  padding: 5px 10px;
  font-size: 0.9em;
  border-radius: 5px;
  display: none;
  z-index: 2000;
  max-width: 300px;
}
.highlight-chapter { background: yellow; transition: background 2s ease; }
.reading-highlight { background: #ffff99; border-radius: 3px; }
footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: #eee;
  padding: 5px;
  font-size: 0.8em;
  text-align: center;
}


/* Voice test block */
.voice-test {
  max-width: 800px;
  margin: 12px auto 8px auto;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fafafa;
}
.voice-test p {
  margin: 0 0 8px 0;
}
#speakSelectionBtn {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
#speakSelectionBtn:hover {
  background: #f0f0f0;
}


/* Library panel */
#libraryPanel {
  max-width: 980px;
  margin: 320px auto 12px auto; /* below fixed controls */
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #ffffff;
}
.library-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.library-card {
  border: 1px solid #e3e3e3;
  border-radius: 10px;
  padding: 10px;
  background: #fafafa;
}
.library-card h3 {
  margin: 0 0 6px 0;
  font-size: 1.05rem;
}
.library-card .meta {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 6px;
}
.library-card button {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.library-card button:hover {
  background: #f0f0f0;
}


/* OPDS source picker */
.opds-sources {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0 10px 0;
}

#epubPanel {
  max-width: 980px;
  margin: 12px auto;
}

.epub-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.epub-controls button {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.epub-controls button:hover { background: #f0f0f0; }

.word{cursor:pointer}
.word.current{outline:1px solid;}
/* ---------- Reading Mode / Mobile optimizations ---------- */

/* Use a dynamic offset rather than a hard-coded 300px */
:root { --controls-offset: 300px; } /* JS will overwrite this after measuring */
#content { margin-top: var(--controls-offset); }

/* On small screens, reduce header bulk and allow horizontal scroll of controls */
@media (max-width: 768px) {
  #controls {
    position: sticky;           /* no longer fixed on mobile; sticks at top when shown */
    top: 0;
    overflow-x: auto;
    white-space: nowrap;
    padding: 6px;
    gap: 6px;
  }
  #content { margin-top: 0; }   /* we’ll compute exact offset with JS below */
}

/* Reading Mode: hide chrome and let content fill the screen */
body.reading #controls,
body.reading footer,
body.reading .voice-test,
body.reading #libraryPanel,
body.reading #epubPanel {
  display: none !important;
}

/* Fill the available viewport height (iOS-friendly 100dvh) */
body.reading #content {
  margin-top: 0 !important;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  min-height: 100dvh;
}

/* Tiny floating “Aa” button to re-open controls while in Reading Mode */
.fab {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2000;
  border: 1px solid #ccc;
  border-radius: 999px;
  padding: 10px 12px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font-weight: 700;
  cursor: pointer;
}

/* Optional: autohide header when scrolling down (non-reading mode) */
body.hide-controls #controls {
  transform: translateY(-100%);
  transition: transform .25s ease;
}
/* ----- Reading Mode & mobile header handling ----- */
:root { --controls-offset: 300px; }           /* fallback */
#content { margin-top: var(--controls-offset); }

/* Mobile: don’t waste space; header becomes sticky when shown */
@media (max-width: 768px) {
  #controls {
    position: sticky;
    top: 0;
    overflow-x: auto;
    white-space: nowrap;
    padding: 6px;
    gap: 6px;
  }
  #content { margin-top: 0; }
}

/* Hide chrome in Reading Mode */
body.reading #controls,
body.reading footer,
body.reading .voice-test,
body.reading #libraryPanel,
body.reading #epubPanel {
  display: none !important;
}

/* Make the story fill the screen on iPhone */
body.reading #content {
  margin-top: 0 !important;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  min-height: 100dvh;
}

/* Tiny floating button shown only in Reading Mode */
.fab {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2000;
  border: 1px solid #ccc;
  border-radius: 999px;
  padding: 10px 12px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font-weight: 700;
  cursor: pointer;
}

/* Optional: autohide header while scrolling (non-reading mode) */
body.hide-controls #controls {
  transform: translateY(-100%);
  transition: transform .25s ease;
}

/* Highlight main character (Red Letter MC) */
.mc-red {
  color: #b00000;      /* deep red */
  -webkit-text-fill-color: darkred !important; /* Safari/iOS */
  -webkit-text-stroke: 0px transparent;        /* avoids stroke override */
  font-weight: 600;    /* optional: bold it a bit */
}

/* Optional accessibility tweak: if you ever want an alternate style */
.mc-red[data-alt-style="true"] {
  text-decoration: underline;
}
