/* ══════════════════════════════════════
   READER — Immersive book chapter layout
   ══════════════════════════════════════ */

/* ── Override base styles for reading ── */
body {
  background-color: #f8f6f1;
  color: #181510;
  font-family: var(--serif, 'Libre Baskerville'), Georgia, serif;
  font-size: var(--reader-font-size, 21px);
  line-height: 1.9;
  min-height: 100vh;
  transition: background-color 0.4s, color 0.4s;
}

/* Paper grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 1;
  mix-blend-mode: multiply;
  background-repeat: no-repeat;
  background-size: cover;
}

/* ── Article container ── */
article {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 100px 32px 220px;
}

/* ── Breadcrumb back to site ── */
.reader-breadcrumb {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 40px;
}

.reader-breadcrumb a {
  color: #b0a898;
  text-decoration: none;
  transition: color 0.2s;
}

.reader-breadcrumb a:hover {
  color: #8a6a3a;
}

.breadcrumb-sep {
  color: #d8d3c8;
  margin: 0 8px;
}

/* ── Decorative roman numeral ── */
.reader-chapter-num {
  font-family: var(--serif, 'Libre Baskerville'), Georgia, serif;
  font-size: 52px;
  font-weight: normal;
  color: #d8d3c8;
  line-height: 1;
  margin-bottom: 20px;
  letter-spacing: 0.06em;
}

/* ── Protagonist name ── */
.reader-protagonist {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a6a3a;
  margin-bottom: 12px;
}

/* ── Reading time ── */
.reader-meta {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 13px;
  color: #b0a898;
  margin-bottom: 8px;
}

/* ── Chapter title ── */
article h1 {
  font-family: var(--serif, 'Libre Baskerville'), Georgia, serif;
  font-size: clamp(26px, 4vw, 40px);
  font-weight: normal;
  color: #0e0b08;
  line-height: 1.2;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
  transition: color 0.4s;
}

/* ── Reader byline (book chapters) ── */
.reader-byline {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #b0a898;
  margin: 0 0 56px 0;
  transition: color 0.4s;
}
.reader-byline a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(176, 168, 152, 0.4);
  text-underline-offset: 3px;
}
.reader-byline a:hover { color: #0e0b08; }
body.dark .reader-byline { color: #6b6560; }
body.dark .reader-byline a:hover { color: #f0e8d8; }

/* ── Prose paragraphs ── */
article p {
  margin-bottom: 1.6em;
}

article p em {
  color: #0e0b08;
  font-style: italic;
  transition: color 0.4s;
}

/* Drop cap on first paragraph of body content */
article section p:first-of-type::first-letter,
article > p:first-of-type::first-letter {
  float: left;
  font-size: 3.8em;
  line-height: 0.8;
  margin: 0.08em 0.1em 0 0;
  color: #8a6a3a;
  transition: color 0.4s;
}

/* ── Section breaks (Markdown --- -> <hr>) ── */
article hr {
  border: none;
  height: 72px;
  margin: 0;
}

/* ── Progress bar ── */
#progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: #8a6a3a;
  z-index: 300;
  transition: width 0.1s linear, background 0.4s;
}

/* ══════════════════════════════════════
   FLOATING TOOLBAR
   ══════════════════════════════════════ */
#reader-toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 250;
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(248, 246, 241, 0.92);
  border: 1px solid #d8d3c8;
  border-radius: 8px;
  padding: 4px;
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.4s ease, transform 0.4s ease, background 0.4s, border-color 0.4s;
  pointer-events: none;
}

#reader-toolbar.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 13px;
  color: #9a9088;
  transition: color 0.2s, background 0.2s;
}

.toolbar-btn:hover {
  color: #181510;
  background: rgba(0,0,0,0.05);
}

.toolbar-btn.active {
  color: #8a6a3a;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: #d8d3c8;
  margin: 0 2px;
  transition: background 0.4s;
}

/* ══════════════════════════════════════
   BOTTOM NAVIGATION
   ══════════════════════════════════════ */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: stretch;
  background: rgba(248, 246, 241, 0.97);
  border-top: 1px solid #d8d3c8;
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.4s ease, transform 0.4s ease, background 0.4s, border-color 0.4s;
  pointer-events: none;
}

#bottom-nav.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 20px;
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 15px;
  color: #9a9088;
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  min-height: 56px;
  transition: color 0.2s, background 0.2s;
}

.nav-btn:hover {
  color: #181510;
  background: rgba(0,0,0,0.03);
}

.nav-btn.next {
  color: #8a6a3a;
}

.nav-btn.next:hover {
  color: #6a4e28;
}

.nav-divider {
  width: 1px;
  background: #d8d3c8;
  transition: background 0.4s;
}

.nav-count {
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-family: var(--mono, 'JetBrains Mono'), monospace;
  font-size: 11px;
  color: #b0a898;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s;
}

.nav-count:hover {
  color: #8a6a3a;
}

.nav-arrow {
  font-size: 18px;
}

/* ══════════════════════════════════════
   CHAPTER DRAWER
   ══════════════════════════════════════ */
#drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#drawer-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

#chapter-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 220;
  max-height: 70vh;
  background: #f8f6f1;
  border-top: 1px solid #d8d3c8;
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), background 0.4s, border-color 0.4s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chapter-drawer.open {
  transform: translateY(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  flex-shrink: 0;
}

.drawer-title {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9a9088;
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  color: #9a9088;
  font-size: 18px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.drawer-close:hover {
  color: #181510;
  background: rgba(0,0,0,0.05);
}

.drawer-list {
  overflow-y: auto;
  padding: 0 12px 20px;
  -webkit-overflow-scrolling: touch;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  text-decoration: none;
  color: #181510;
  border-radius: 8px;
  transition: background 0.2s, color 0.4s;
}

.drawer-item:hover {
  background: rgba(0,0,0,0.03);
}

.drawer-item.current {
  background: rgba(138,106,58,0.08);
}

.drawer-item-num {
  font-family: var(--mono, 'JetBrains Mono'), monospace;
  font-size: 11px;
  color: #b0a898;
  letter-spacing: 0.04em;
  min-width: 24px;
  text-align: right;
  flex-shrink: 0;
}

.drawer-item.current .drawer-item-num {
  color: #8a6a3a;
}

.drawer-item-body {
  flex: 1;
  min-width: 0;
}

.drawer-item-title {
  font-family: var(--serif, 'Libre Baskerville'), Georgia, serif;
  font-size: 15px;
  line-height: 1.3;
  display: block;
  transition: color 0.4s;
}

.drawer-item.current .drawer-item-title {
  color: #8a6a3a;
}

.drawer-item-time {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 11px;
  color: #b0a898;
  margin-top: 2px;
  display: block;
}

/* ══════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════ */
#reader-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 310;
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 14px;
  color: #181510;
  background: rgba(248, 246, 241, 0.97);
  border: 1px solid #d8d3c8;
  border-radius: 10px;
  padding: 12px 20px;
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s, background 0.4s, border-color 0.4s, color 0.4s;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
}

#reader-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: all;
}

.toast-action {
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: #8a6a3a;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  transition: background 0.2s;
  white-space: nowrap;
}

.toast-action:hover {
  background: rgba(138,106,58,0.1);
}

/* ══════════════════════════════════════
   START-FROM-BEGINNING BANNER
   ══════════════════════════════════════ */
#start-banner {
  position: fixed;
  top: 2px;
  left: 0;
  right: 0;
  z-index: 290;
  font-family: var(--sans, 'DM Sans'), sans-serif;
  font-size: 13px;
  color: #9a9088;
  background: rgba(248, 246, 241, 0.97);
  border-bottom: 1px solid #d8d3c8;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.4s, transform 0.4s, background 0.4s, border-color 0.4s, color 0.4s;
  pointer-events: none;
}

#start-banner.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

#start-banner a {
  color: #8a6a3a;
  text-decoration: none;
  font-weight: 500;
}

#start-banner a:hover {
  text-decoration: underline;
}

.banner-close {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  cursor: pointer;
  color: #b0a898;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
}

.banner-close:hover {
  color: #181510;
}

/* ══════════════════════════════════════
   CHAPTER FOOTER
   ══════════════════════════════════════ */
article footer {
  margin-top: 100px;
  padding-top: 40px;
  border-top: 1px solid #d8d3c8;
  font-size: 16px;
  color: #9a9088;
  font-style: italic;
  transition: border-color 0.4s;
}

article footer a {
  color: #8a6a3a;
  text-decoration: none;
  display: block;
  margin-top: 16px;
  font-size: 17px;
  font-style: normal;
}

article footer a:hover {
  text-decoration: underline;
}

/* ── Cookie banner override for reader bg ── */
.cookie-banner {
  background: rgba(248, 246, 241, 0.98);
}

/* ══════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════ */
body.dark {
  background-color: #1a1915;
  color: #d4cfc4;
}

body.dark::before {
  mix-blend-mode: screen;
  opacity: 0.5;
}

body.dark article h1 {
  color: #e8e3d8;
}

body.dark article p em {
  color: #e8e3d8;
}

body.dark article section p:first-of-type::first-letter,
body.dark article > p:first-of-type::first-letter {
  color: #c9a84c;
}

body.dark #progress {
  background: #c9a84c;
}

body.dark .reader-breadcrumb a { color: #6b6560; }
body.dark .reader-breadcrumb a:hover { color: #c9a84c; }
body.dark .breadcrumb-sep { color: #2e2b24; }

body.dark .reader-chapter-num { color: #2e2b24; }
body.dark .reader-protagonist { color: #c9a84c; }
body.dark .reader-meta { color: #6b6560; }

body.dark article footer { border-top-color: #2e2b24; }
body.dark article footer a { color: #c9a84c; }

/* Dark toolbar */
body.dark #reader-toolbar {
  background: rgba(26, 25, 21, 0.92);
  border-color: #2e2b24;
}
body.dark .toolbar-btn { color: #6b6560; }
body.dark .toolbar-btn:hover { color: #d4cfc4; background: rgba(255,255,255,0.05); }
body.dark .toolbar-btn.active { color: #c9a84c; }
body.dark .toolbar-sep { background: #2e2b24; }

/* Dark bottom nav */
body.dark #bottom-nav {
  background: rgba(26, 25, 21, 0.97);
  border-top-color: #2e2b24;
}
body.dark .nav-btn { color: #6b6560; }
body.dark .nav-btn:hover { color: #d4cfc4; background: rgba(255,255,255,0.03); }
body.dark .nav-btn.next { color: #c9a84c; }
body.dark .nav-btn.next:hover { color: #e8c960; }
body.dark .nav-divider { background: #2e2b24; }
body.dark .nav-count { color: #6b6560; }
body.dark .nav-count:hover { color: #c9a84c; }

/* Dark drawer */
body.dark #drawer-backdrop { background: rgba(0,0,0,0.5); }
body.dark #chapter-drawer { background: #1a1915; border-top-color: #2e2b24; }
body.dark .drawer-title { color: #6b6560; }
body.dark .drawer-close { color: #6b6560; }
body.dark .drawer-close:hover { color: #d4cfc4; background: rgba(255,255,255,0.05); }
body.dark .drawer-item { color: #d4cfc4; }
body.dark .drawer-item:hover { background: rgba(255,255,255,0.03); }
body.dark .drawer-item.current { background: rgba(201,168,76,0.1); }
body.dark .drawer-item-num { color: #6b6560; }
body.dark .drawer-item.current .drawer-item-num { color: #c9a84c; }
body.dark .drawer-item-title { color: #d4cfc4; }
body.dark .drawer-item.current .drawer-item-title { color: #c9a84c; }
body.dark .drawer-item-time { color: #4a4640; }

/* Dark toast */
body.dark #reader-toast {
  background: rgba(26, 25, 21, 0.97);
  border-color: #2e2b24;
  color: #d4cfc4;
}
body.dark .toast-action { color: #c9a84c; }
body.dark .toast-action:hover { background: rgba(201,168,76,0.1); }

/* Dark banner */
body.dark #start-banner {
  background: rgba(26, 25, 21, 0.97);
  border-bottom-color: #2e2b24;
  color: #6b6560;
}
body.dark #start-banner a { color: #c9a84c; }
body.dark .banner-close { color: #4a4640; }
body.dark .banner-close:hover { color: #d4cfc4; }

/* Dark cookie banner */
body.dark .cookie-banner { background: rgba(26, 25, 21, 0.98); }

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 600px) {
  article {
    padding: 80px 24px 160px;
  }

  body {
    font-size: var(--reader-font-size, 19px);
  }

  .nav-btn span:not(.nav-arrow) {
    display: none;
  }

  .nav-btn .nav-arrow {
    font-size: 22px;
  }

  #reader-toolbar {
    top: 10px;
    right: 10px;
  }

  .reader-chapter-num {
    font-size: 40px;
  }

  #start-banner {
    font-size: 12px;
    padding: 8px 40px 8px 16px;
  }
}
