/* ==========================================================================
   The Weight of Nodding - Interactive Book Reader Styles (Expanded Edition)
   Author: Anam Sajjad · BZU Multan · CERN Zenodo DOI: 10.5281/zenodo.24054373
   ========================================================================== */

:root {
  --font-serif: 'Lora', Georgia, 'Times New Roman', serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-title: 'Cinzel', serif;

  --trans-fast: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --trans-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  --drawer-width: 360px;
}

/* ---------------- Themes ---------------- */

/* Paper / Sepia (Default) */
body[data-theme="sepia"] {
  --bg-primary: #fbf7ee;
  --bg-surface: #f4edd8;
  --bg-surface-elevated: #efe4cb;
  --bg-popover: #fdfaf2;
  --text-primary: #2b2520;
  --text-secondary: #6e655a;
  --text-muted: #968c7f;
  --border-light: rgba(110, 101, 90, 0.16);
  --border-strong: rgba(110, 101, 90, 0.35);
  --accent: #1B365D;
  --accent-light: rgba(27, 54, 93, 0.1);
  --progress-bg: #1B365D;
  --quote-border: #1B365D;
  --card-bg: rgba(244, 237, 216, 0.7);
  --box-bg: #f4eedc;
  --shadow: 0 4px 20px rgba(70, 50, 30, 0.08);
}

/* Light Theme */
body[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-surface: #f8fafc;
  --bg-surface-elevated: #f1f5f9;
  --bg-popover: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-light: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.2);
  --accent: #1e3a8a;
  --accent-light: rgba(30, 58, 138, 0.08);
  --progress-bg: #1e3a8a;
  --quote-border: #1e3a8a;
  --card-bg: #f8fafc;
  --box-bg: #f1f5f9;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

/* Slate Dark Theme */
body[data-theme="dark"] {
  --bg-primary: #12161f;
  --bg-surface: #1a202c;
  --bg-surface-elevated: #242c3d;
  --bg-popover: #1e2638;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-light: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #38bdf8;
  --accent-light: rgba(56, 189, 248, 0.12);
  --progress-bg: #38bdf8;
  --quote-border: #38bdf8;
  --card-bg: #1a202c;
  --box-bg: #1c2436;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* OLED Midnight Theme */
body[data-theme="midnight"] {
  --bg-primary: #000000;
  --bg-surface: #0a0a0a;
  --bg-surface-elevated: #141414;
  --bg-popover: #111111;
  --text-primary: #f1f5f9;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border-light: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.25);
  --accent: #60a5fa;
  --accent-light: rgba(96, 165, 250, 0.15);
  --progress-bg: #60a5fa;
  --quote-border: #60a5fa;
  --card-bg: #0d0d0d;
  --box-bg: #111111;
  --shadow: 0 4px 25px rgba(0, 0, 0, 0.6);
}

/* ---------------- Global Reset & Typography ---------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.8;
  transition: background-color var(--trans-smooth), color var(--trans-smooth);
  overflow-x: hidden;
}

body[data-font="serif"] { font-family: var(--font-serif); }
body[data-font="display"] { font-family: var(--font-display); }
body[data-font="sans"] { font-family: var(--font-sans); line-height: 1.7; }

body[data-size="sm"] { font-size: 16px; }
body[data-size="md"] { font-size: 18px; }
body[data-size="lg"] { font-size: 20px; }
body[data-size="xl"] { font-size: 22px; }

/* ---------------- Top Reading Progress ---------------- */
#progress-bar-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 1000;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: var(--progress-bg);
  transition: width 0.1s ease-out;
}

/* ---------------- App Header ---------------- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 900;
  backdrop-filter: blur(8px);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans-fast);
}

.icon-btn:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.text-icon {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}

.header-title-box {
  display: flex;
  flex-direction: column;
  margin-left: 6px;
}

.header-book-title {
  font-family: var(--font-title);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: uppercase;
}

.header-current-chapter {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- Settings Popover ---------------- */
.settings-modal {
  position: fixed;
  top: 68px;
  right: 20px;
  background: var(--bg-popover);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  box-shadow: var(--shadow);
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-modal.hidden { display: none; }

.settings-section label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.theme-buttons, .size-buttons, .font-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.theme-buttons { grid-template-columns: repeat(4, 1fr); }
.font-buttons { grid-template-columns: repeat(3, 1fr); }

.theme-opt, .size-opt, .font-opt {
  padding: 6px 10px;
  font-size: 12px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.theme-opt.active, .size-opt.active, .font-opt.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.download-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dl-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-family: var(--font-sans);
  font-weight: 600;
  text-decoration: none;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  transition: all var(--trans-fast);
}

.dl-btn:hover {
  background: var(--accent);
  color: #ffffff;
}

/* ---------------- Search Modal ---------------- */
.search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  padding-top: 80px;
}

.search-modal.hidden { display: none; }

.search-box {
  width: 90%;
  max-width: 640px;
  background: var(--bg-popover);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}

.search-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text-primary);
}

.search-results {
  overflow-y: auto;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-result-item {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.search-result-item:hover {
  background: var(--bg-surface-elevated);
}

.search-res-part {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
}

.search-res-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.search-res-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.search-res-snippet mark {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: bold;
}

/* ---------------- About Author Modal ---------------- */
.about-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.about-modal.hidden { display: none; }

.about-card {
  position: relative;
  background: var(--bg-popover);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 32px;
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow);
}

.close-card-btn {
  position: absolute;
  top: 16px;
  right: 18px;
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.about-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  margin-bottom: 12px;
}

.about-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.about-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.about-author-info {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.about-author-info h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.about-author-info p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.about-author-info a {
  color: var(--accent);
  text-decoration: none;
}

.about-dedication-box {
  background: var(--bg-surface-elevated);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.about-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  text-align: center;
}

.meta-item {
  background: var(--bg-surface);
  padding: 10px 6px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.meta-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}

.meta-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ---------------- Table of Contents Drawer ---------------- */
.toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-light);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform var(--trans-smooth);
  display: flex;
  flex-direction: column;
}

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

.drawer-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.drawer-header-title h3 {
  font-family: var(--font-title);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-primary);
}

.drawer-tab {
  flex: 1;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-surface);
}

#drawer-tab-content {
  flex: 1;
  overflow-y: auto;
}

.toc-list {
  padding: 12px 10px;
}

.toc-list.hidden { display: none; }

.toc-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--trans-fast);
  margin-bottom: 4px;
  text-decoration: none;
}

.toc-item:hover {
  background: var(--bg-surface-elevated);
}

.toc-item.active {
  background: var(--accent-light);
}

.toc-item-part {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
}

.toc-item-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 2px 0;
  line-height: 1.4;
}

.toc-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.drawer-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-surface);
  font-size: 12px;
}

.drawer-footer-author {
  color: var(--text-primary);
}

.drawer-footer-note {
  font-size: 11px;
  color: var(--text-muted);
}

.backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 850;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans-fast);
}

.backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------------- Reader Layout ---------------- */
.reader-container {
  max-width: 740px;
  margin: 90px auto 100px;
  padding: 0 24px;
}

.chapter-hero {
  text-align: center;
  margin-bottom: 48px;
  padding-bottom: 24px;
}

.hero-badge {
  font-family: var(--font-title);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.hero-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.hero-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.meta-dot { color: var(--border-strong); }

.hero-divider {
  font-size: 16px;
  color: var(--accent);
  opacity: 0.6;
}

/* ---------------- Chapter Content & Typography ---------------- */
.chapter-content p {
  margin-bottom: 24px;
  text-align: justify;
  hyphens: auto;
}

.chapter-content h2,
.chapter-content h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.35;
  margin: 36px 0 14px;
}

.chapter-content ul,
.chapter-content ol {
  padding-left: 26px;
  margin: 0 0 24px;
}

.chapter-content li {
  margin-bottom: 10px;
  line-height: 1.75;
}

.chapter-content p:first-of-type::first-letter {
  font-family: var(--font-display);
  float: left;
  font-size: 58px;
  line-height: 0.85;
  padding-top: 4px;
  padding-right: 12px;
  padding-bottom: 2px;
  color: var(--accent);
  font-weight: 700;
}

.chapter-content blockquote {
  border-left: 3px solid var(--quote-border);
  padding: 8px 0 8px 22px;
  margin: 32px 0;
  font-style: italic;
  color: var(--text-secondary);
}

.chapter-content hr.divider {
  border: none;
  text-align: center;
  margin: 48px 0;
  height: 1px;
  background: var(--border-light);
}

/* ---------------- The Strategist's Margin Callout Box ---------------- */
.strategist-margin-box {
  background: var(--box-bg);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 24px 28px;
  margin: 48px 0;
  box-shadow: var(--shadow);
}

.margin-header {
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 12px;
}

.margin-badge {
  display: inline-block;
  font-family: var(--font-title);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.margin-header h3 {
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--text-primary);
  font-weight: 700;
}

.protocol-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin: 20px 0 10px;
}

.margin-body ol, .margin-body ul {
  padding-left: 20px;
  margin-bottom: 16px;
}

.margin-body li {
  margin-bottom: 10px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-primary);
}

.margin-body strong {
  color: var(--text-primary);
}

/* ---------------- Chapter Navigation Footer ---------------- */
.chapter-navigation {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 60px;
  padding-top: 32px;
  border-top: 1px solid var(--border-light);
}

.nav-chapter-btn {
  flex: 1;
  padding: 14px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: all var(--trans-fast);
  text-align: left;
}

.nav-chapter-btn.next { text-align: right; }

.nav-chapter-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--accent);
}

.nav-dir {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.nav-target-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------------- Book Footer ---------------- */
.book-footer {
  text-align: center;
  margin-top: 80px;
  padding-top: 32px;
  border-top: 1px solid var(--border-light);
}

.book-footer-quote {
  font-family: var(--font-display);
  font-size: 18px;
  font-style: italic;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.book-footer-author {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------------- Responsive Breakpoints ---------------- */
@media (max-width: 680px) {
  .reader-container {
    padding: 0 16px;
    margin-top: 75px;
  }
  .hero-title { font-size: 26px; }
  .chapter-content p { text-align: left; }
  .strategist-margin-box { padding: 18px; }
  .header-current-chapter { display: none; }
  .theme-buttons { grid-template-columns: repeat(2, 1fr); }
  .about-meta-grid { grid-template-columns: repeat(2, 1fr); }
}
