/* ═══════════════════════════════════════════════════════════════════════════
   Reader — style.css
   Mobile-first, three themes: sepia (default), light, dark
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Sepia (default) */
  --bg:             #f5f0e8;
  --surface:        #ede7d6;
  --text:           #3a2e1e;
  --text-muted:     #7a6a52;
  --accent:         #8b5e3c;
  --accent-light:   #c49a6c;
  --border:         #d6cdb8;
  --header-bg:      #e8e0cc;
  --footer-bg:      #e8e0cc;
  --progress-track: #d6cdb8;
  --progress-fill:  #8b5e3c;

  --font-size:   18px;
  --font-family: Georgia, 'Times New Roman', serif;
  --line-height: 1.7;
}

[data-theme="light"] {
  --bg:             #ffffff;
  --surface:        #f4f4f4;
  --text:           #1a1a1a;
  --text-muted:     #666666;
  --accent:         #1a6fc4;
  --accent-light:   #5aa3e8;
  --border:         #e0e0e0;
  --header-bg:      #f8f8f8;
  --footer-bg:      #f8f8f8;
  --progress-track: #e0e0e0;
  --progress-fill:  #1a6fc4;
}

[data-theme="dark"] {
  --bg:             #1a1a1a;
  --surface:        #242424;
  --text:           #e8e0cc;
  --text-muted:     #9a9080;
  --accent:         #c49a6c;
  --accent-light:   #e0b888;
  --border:         #383028;
  --header-bg:      #212121;
  --footer-bg:      #212121;
  --progress-track: #383028;
  --progress-fill:  #c49a6c;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  transition: background 0.3s, color 0.3s;
  -webkit-text-size-adjust: 100%;
}

/* ── App Shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 52px;
  min-height: 52px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  transition: transform 0.3s ease, opacity 0.3s ease, background 0.3s;
  z-index: 10;
  position: relative;
  flex-shrink: 0;
  gap: 8px;
}

#header.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.header-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-book-title {
  font-size: 13px;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Inline settings controls ─────────────────────────────────────────────── */
.ctrl-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.ctrl-btn:hover, .ctrl-btn:active { background: var(--border); }

#font-size-value {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 30px;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  flex-shrink: 0;
}

#font-family-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  height: 30px;
  transition: background 0.15s;
}

#font-family-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Header icon buttons (theme, fullscreen) */
.header-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 36px;
  min-height: 36px;
}

.header-btn:hover, .header-btn:active { background: var(--border); }

.header-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ── Main Reading Area ────────────────────────────────────────────────────── */
#reader-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  transition: background 0.3s;
}

/* epub.js iframe host */
#epub-viewer {
  width: 90%;
  height: 100%;
  margin: 0 auto;
}

/* PDF.js canvas host */
#pdf-viewer {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 5%;
}

#pdf-viewer canvas {
  max-width: 100%;
  height: auto;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ── Reader overlay navigation arrows ─────────────────────────────────────── */
/* Visible on left/right edges when chrome is showing.
   They sit above the epub iframe (z-index 6) but the centre of the reader
   is fully uncovered — text remains selectable and copyable. */
.reader-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  background: rgba(0, 0, 0, 0.10);
  border: none;
  color: var(--text);
  font-size: 36px;
  line-height: 1;
  width: 44px;
  height: 110px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.reader-nav-btn:hover, .reader-nav-btn:active {
  background: rgba(0, 0, 0, 0.20);
}

.reader-nav-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

#reader-prev { left: 0;  border-radius: 0 8px 8px 0; }
.reader-nav-right { right: 0; border-radius: 8px 0 0 8px; }

/* Loading state */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  gap: 16px;
  transition: opacity 0.4s;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 14px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
#footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  height: 56px;
  min-height: 56px;
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  transition: transform 0.3s ease, background 0.3s;
}

#footer.hidden {
  transform: translateY(100%);
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 16px;
  min-width: 40px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.nav-btn:hover, .nav-btn:active { background: var(--border); }

.nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Progress bar */
#progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#progress-bar-track {
  flex: 1;
  height: 6px;
  background: var(--progress-track);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#progress-bar-fill {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease;
}

#progress-pct {
  font-size: 12px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Error Screen ─────────────────────────────────────────────────────────── */
#error-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 100;
  padding: 32px;
  text-align: center;
}

#error-screen .error-icon { font-size: 48px; }

#error-screen h2 {
  font-size: 18px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#error-screen p {
  font-size: 14px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.5;
}

/* Fullscreen button — accent colour when active */
#btn-fullscreen.active svg { fill: var(--accent); }

/* In fullscreen the reader expands to full viewport */
:fullscreen #reader-container,
:-webkit-full-screen #reader-container {
  max-width: 100% !important;
}
:fullscreen #epub-viewer,
:-webkit-full-screen #epub-viewer {
  max-width: 100% !important;
  margin: 0 !important;
}

/* ── Epub edge-strip tap overlays ────────────────────────────────────────── */
/* Left 20% and right 20% host-page strips handle tap/swipe navigation.
   The centre 60% is overlay-free so epub text remains selectable. */
#tap-left, #tap-right {
  position: absolute;
  top: 0; bottom: 0;
  width: 20%;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
#tap-left  { left: 0; }
#tap-right { right: 0; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}
