/* =========================
   THEME VARIABLES
   ========================= */
body[data-theme="dark"] {
  --bg: #0e0e0f;
  --panel: #161617;
  --text: #f1f1f1;
  --border: #2a2a2c;
  --sidebar: #141415;
  --btn: #2c2c2e;
  --btn-hover: #3a3a3c;
  --accent: #2563eb;
}

body[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #1a1a1a;
  --border: #d0d0d0;
  --sidebar: #f5f5f5;
  --btn: #e0e0e0;
  --btn-hover: #cfcfcf;
  --accent: #2563eb;
}

/* =========================
   BASE
   ========================= */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, serif;
}

/* =========================
   TOP BAR
   ========================= */
.top-bar {
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  flex-shrink: 0;
}

.top-bar button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

/* =========================
   LAYOUT
   ========================= */
.reader-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* =========================
   SIDEBAR
   ========================= */
.sidebar {
  width: 280px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.book-cover {
  width: 100%;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.book-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

/* =========================
   CHAPTER LIST
   ========================= */
.chapter-tab {
  padding: 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.chapter-tab:hover {
  background: var(--btn-hover);
}

.chapter-tab.active {
  background: var(--accent);
  color: #ffffff;
}

/* =========================
   READER COLUMN
   ========================= */
.content-column {
  flex: 1;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  min-width: 0;
}


#reader {
  max-width: 720px;
  width: 100%;
  padding-bottom: 2em; /* larger than footer height */
  font-size: var(--reader-font-size, 1.05rem);
  line-height: 1.85;
}

#reader p {
  margin-bottom: 1.2em;
  text-indent: 1.25em;
}

#reader p:first-child,
#reader p.continued {
  text-indent: 0;
}


/* =========================
   BOTTOM NAV (ARROWS + PAGE NUMBER)
   ========================= */
.reader-nav {
  flex-shrink: 0;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;

  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.6rem 1rem;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.reader-nav button {
  background: var(--btn);
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem 0.8rem;
}

.reader-layout {
  flex: 1;
  display: flex;
  min-height: 0; /* critical for scroll containers */
}

.reader-nav button:hover {
  background: var(--btn-hover);
}

#progress-label {
  font-size: 0.9rem;
  opacity: 0.85;
}

/* =========================
   READER MENU (Aa)
   ========================= */
.menu {
  position: fixed;
  top: 52px;
  right: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  width: 180px;
  z-index: 50;

  max-height: calc(100vh - 52px - 80px);
  overflow-y: auto;
}

.menu.hidden {
  display: none;
}

.menu-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.menu-section:last-child {
  margin-bottom: 0;
}

.menu button {
  background: var(--btn);
  border: none;
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.zoom-controls {
  display: flex;
  gap: 0.4rem;
}

#reader p.dialogue {
  margin-left: 1.0em;
  font-style: italic; /* optional */
}

/* =========================
   HIDE RAW CHAPTER SOURCES
   ========================= */
.chapter-source {
  display: none;
}

/* =========================
   MOBILE CHAPTER SIDEBAR
   ========================= */

/* Mobile behavior */
@media (max-width: 1024px) {
  /* Sidebar becomes a full-screen overlay */
  .sidebar {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  /* Open state (controlled by JS) */
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Show chapter toggle button on mobile */
  #chapter-toggle {
    display: inline-flex;
  }

  /* Reader takes full width */
  .reader-layout {
    display: block;
  }
}

/* =========================
   DESKTOP OVERRIDES
   ========================= */
@media (min-width: 1025px) {
  /* Hide chapter toggle button on desktop */
  #chapter-toggle {
    display: none;
  }

  /* Sidebar behaves normally on desktop */
  .sidebar {
    position: relative;
    transform: none !important;
  }
}

/* =========================
   MOBILE READER DENSITY FIX
   ========================= */
@media (max-width: 1024px) {
  #reader {
    line-height: 1.55;
    padding-top: 1.25rem;
    padding-bottom: 3.5rem;
  }

  #reader p {
    margin-bottom: 0.9em;
  }
}

/* =========================
   CLOSE BUTTON VISIBILITY
   ========================= */

/* Hide the X on desktop */
@media (min-width: 1025px) {
  .close-sidebar {
    display: none;
  }
}

/* =========================
   CLOSE BUTTON (MOBILE ONLY)
   ========================= */
@media (max-width: 1024px) {
  .close-sidebar {
    position: absolute;
    top: 12px;
    right: 12px;

    width: 36px;
    height: 36px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #dc2626; /* red */
    color: #ffffff;     /* white X */

    font-size: 20px;
    font-weight: 700;

    border: none;
    border-radius: 6px;

    cursor: pointer;
    z-index: 50;
  }

  /* push sidebar content down so nothing is covered */
  .sidebar {
    padding-top: 60px;
  }
}

/* =========================
   MOBILE INITIAL LAYOUT FIX
   ========================= */
@media (max-width: 1024px) {
  .reader-layout {
    display: flex;
    height: calc(100dvh - 48px);
  }

  .content-column {
    flex: 1;
    overflow-y: auto;
  }
}

/* =========================
   MOBILE TOP BAR ADJUSTMENT
   ========================= */

@media (max-width: 768px) {

  .back-btn {
    display: none;
  }

}

@media (max-width: 768px) {

  .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
	flex-shrink: 0;
  }

  .top-bar-actions {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

}

/* =========================
   MOBILE TEXT MARGINS FIX
   ========================= */
@media (max-width: 1024px) {
  #reader {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }
}

/* =========================
   TEXT TO SPEECH HIGHLIGHT
   ========================= */

.word {
  transition: background 0.1s ease;
}

.word.active-word {
  background: yellow;
  color: #000;
}

/* =========================
   TTS BUTTON (TOP BAR)
   ========================= */

.tts-btn {
  background: #2563eb;   /* blue */
  color: #ffffff;        /* white icon */
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.tts-btn:hover {
  background: #1d4ed8;
}

/* =========================
   TOP BAR BUTTON GROUPING
   ========================= */

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.top-bar-actions #chapter-toggle {
  margin-right: auto;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =========================
   TTS TRANSITION OVERLAY
   ========================= */

#tts-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999; /* higher than sidebar */
}

#tts-overlay.hidden {
  display: none;
}

#tts-overlay .dot {
  font-size: 2.5rem;
  opacity: 0.2;
  animation: blink 1.4s infinite both;
}

#tts-overlay .dot:nth-child(2) {
  animation-delay: 0.2s;
}

#tts-overlay .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}







