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

html, body {
  height: 100%;
  background: #3a3028;
  font-family: Georgia, serif;
  color: #3a2e22;
  overflow: hidden; /* desktop: no body scroll */
}

/* ── Top bar ────────────────────────────────────────────── */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #2e2820;
  padding: 10px 20px;
  height: 44px;
  flex-shrink: 0;
}

.book-title {
  font-size: 12px;
  color: #9a8a76;
  font-style: italic;
  letter-spacing: 0.5px;
}

#hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: #9a8a76;
  border-radius: 1px;
  transition: background 0.2s;
}

#hamburger-btn:hover span { background: #c8b490; }
#hamburger-btn:focus-visible { outline: 2px solid #c8b490; outline-offset: 2px; }

/* ── TOC Drawer ─────────────────────────────────────────── */
#toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
}

#toc-overlay.open { display: block; }

#toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 80vw);
  background: #ede8dc;
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#toc-drawer.open { transform: translateX(0); }

.toc-heading {
  font-size: 9px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #8a7a66;
  padding: 20px 20px 12px;
  border-bottom: 1px solid #d4c9b0;
  flex-shrink: 0;
}

.toc-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 20px;
  font-family: Georgia, serif;
  font-size: 13px;
  color: #5a4a36;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: background 0.15s;
}

.toc-item:hover { background: rgba(0,0,0,0.04); }

.toc-item.active {
  color: #7a5c38;
  font-weight: bold;
  border-left-color: #a08060;
  padding-left: 18px;
}

.toc-subtitle {
  display: block;
  font-size: 11px;
  color: #9a8a76;
  font-weight: normal;
  margin-top: 1px;
}

/* ── Desktop reader shell ───────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#desktop-reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 0 0;
}

.reader-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  overflow: hidden;
  min-height: 0;
}

/* ── Nav arrows ─────────────────────────────────────────── */
.nav-arrow {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #c8b490;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
  transition: background 0.15s, opacity 0.15s;
  line-height: 1;
}

.nav-arrow:hover { background: #b8a480; }
.nav-arrow:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.nav-arrow:disabled, .nav-arrow.hidden { opacity: 0; pointer-events: none; }

/* ── Spread container ───────────────────────────────────── */
#spread-container {
  flex: 1;
  max-width: 900px;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ── Spreads ────────────────────────────────────────────── */
.spread {
  display: none;
  width: 100%;
  height: 100%;
  background: #f5f0e8;
  border-radius: 3px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  overflow: hidden;
}

.spread.active { display: flex; }

/* Cover spreads */
.spread.cover-spread { display: none; }
.spread.cover-spread.active {
  display: block;
  position: relative;
  background: transparent;
  box-shadow: none;
}

.spread.cover-spread img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Content spreads */
.spread.content-spread.active { display: flex; }

/* ── Pages ──────────────────────────────────────────────── */
.page {
  flex: 1;
  padding: 32px 28px 40px;
  position: relative;
  font-size: 15px;
  line-height: 1.75;
  color: #3a2e22;
  overflow: hidden;
}

.page-left {
  border-right: 3px solid #c8b99a;
  box-shadow: inset -6px 0 12px rgba(0,0,0,0.05);
}

.page-right { border-left: none; }

.page-num {
  position: absolute;
  bottom: 14px;
  font-size: 11px;
  color: #9a8a76;
}

.page-left .page-num { right: 20px; }
.page-right .page-num { left: 20px; }

.blank-page { background: #f5f0e8; }

/* ── Chapter label & subtitle ───────────────────────────── */
.chapter-label {
  font-size: 18px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #8a7a66;
  margin-bottom: 10px;
}

.chapter-subtitle {
  font-size: 26px;
  color: #6a5a48;
  font-style: italic;
  margin-bottom: 24px;
}

/* ── Content typography ─────────────────────────────────── */
.page p { margin-bottom: 1em; }
.page p:last-child { margin-bottom: 0; }

.section-break {
  text-align: center;
  color: #9a8a76;
  letter-spacing: 4px;
  margin: 1.25em 0;
  font-size: 14px;
}

.section-heading {
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #6a5a48;
  margin: 1.5em 0 0.75em;
}

blockquote {
  border-left: 2px solid #c8b490;
  margin: 1em 0;
  padding: 8px 16px;
  background: rgba(200,180,144,0.08);
  font-size: 14px;
  color: #5a4a36;
}

blockquote p { margin: 0; }

/* ── Progress bar (desktop) ─────────────────────────────── */
#progress-bar {
  height: 4px;
  background: #ddd8cc;
  margin: 12px 16px 0;
  border-radius: 2px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: #a08060;
  width: 0%;
  border-radius: 2px;
  transition: width 0.2s ease;
}

/* ── Mobile reader ──────────────────────────────────────── */
#mobile-reader {
  display: none;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 56px; /* space for sticky progress bar */
}

.mobile-cover {
  width: 100%;
  display: block;
  line-height: 0;
}

.mobile-cover img {
  width: 100%;
  display: block;
  max-height: 70vh;
  object-fit: contain;
}

.chapter {
  padding: 36px 20px 24px;
  border-top: 1px solid #d4c9b0;
}

.chapter .chapter-label {
  font-size: 16px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #8a7a66;
  margin-bottom: 8px;
}

.chapter .chapter-subtitle {
  font-size: 24px;
  color: #6a5a48;
  font-style: italic;
  margin-bottom: 28px;
}

.chapter p {
  font-size: 15px;
  line-height: 1.8;
  color: #3a2e22;
  margin-bottom: 1.1em;
}

.chapter .section-break {
  font-size: 15px;
  color: #9a8a76;
  text-align: center;
  letter-spacing: 4px;
  margin: 1.5em 0;
}

.chapter blockquote {
  border-left: 2px solid #c8b490;
  margin: 1.2em 0;
  padding: 10px 16px;
  background: rgba(200,180,144,0.08);
  font-size: 14px;
  color: #5a4a36;
}

/* ── Mobile progress bar ────────────────────────────────── */
#mobile-progress {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ede8dc;
  border-top: 1px solid #d4c9b0;
  padding: 6px 16px 8px;
  z-index: 10;
}

#mobile-progress-bar {
  height: 3px;
  background: #ddd8cc;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 5px;
}

#mobile-progress-fill {
  height: 100%;
  background: #a08060;
  width: 0%;
  border-radius: 2px;
}

#mobile-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #8a7a66;
  font-family: system-ui, sans-serif;
}

/* ── Responsive: mobile ─────────────────────────────────── */
@media (max-width: 700px) {
  html, body { overflow: auto; background: #f5f0e8; }

  #desktop-reader { display: none !important; }
  #mobile-reader { display: flex !important; }
}
