/* ==========================================================================
   CONCEPTS IN ENTERPRISE RESOURCE PLANNING (4TH EDITION)
   Bilingual Academic & Interactive Reading Platform
   Designed to the exact standard of learning-domain-driven-design.pages.dev
   ========================================================================== */

:root {
  --font-body: 'Newsreader', Georgia, serif;
  --font-ui: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Light Theme (Default) */
  --bg-page: #fbfbfd;
  --bg-surface: #ffffff;
  --bg-sidebar: #f5f5f7;
  --bg-subtle: #f4efe6;
  --bg-card: #ffffff;
  
  --text-main: #1d1d1f;
  --text-sub: #515154;
  --text-muted: #515154;
  --text-dim: #86868b;
  
  --border-color: #e5e5ea;
  --border-light: #f0f0f4;
  --border-strong: #cfbeaa;
  
  --primary: #0066cc;
  --primary-hover: #0077ed;
  --primary-subtle: #edf5fd;
  
  --accent: #ff6b35;
  --accent-subtle: #fff4ed;
  
  --success: #34c759;
  --success-subtle: #edfbf1;
  --warning: #ff9500;
  --warning-subtle: #fff8eb;
  --danger: #ff3b30;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.12);
  
  --content-width: 840px;
  --sidebar-width: 310px;
  --font-size-base: 18px;
  --line-height-base: 1.8;
}

[data-theme="sepia"] {
  --bg-page: #fbf7ee;
  --bg-surface: #f4ede1;
  --bg-sidebar: #ece4d4;
  --bg-subtle: #ebdcc3;
  --bg-card: #fdf8ed;
  
  --text-main: #3d352e;
  --text-sub: #574632;
  --text-muted: #6e6459;
  --text-dim: #998f82;
  
  --border-color: #dfd5c4;
  --border-light: #e8dfd0;
  --border-strong: #c2ab8f;
  
  --primary: #8f5b2b;
  --primary-hover: #a86c34;
  --primary-subtle: #e9decb;
  
  --accent: #c05621;
  --accent-subtle: #f0ded1;
  
  --success: #38761d;
  --success-subtle: #dfead8;
  --warning: #b45f06;
  --warning-subtle: #f5e8d6;
  --danger: #cc0000;

  --shadow-sm: 0 2px 8px rgba(58, 44, 30, 0.06);
  --shadow-md: 0 8px 24px rgba(58, 44, 30, 0.08);
  --shadow-lg: 0 16px 40px rgba(58, 44, 30, 0.12);
}

[data-theme="dark"] {
  --bg-page: #0f1115;
  --bg-surface: #181a20;
  --bg-sidebar: #13151a;
  --bg-subtle: #24292e;
  --bg-card: #1f2328;
  
  --text-main: #e6edf3;
  --text-sub: #b1bac4;
  --text-muted: #9ba1ad;
  --text-dim: #606775;
  
  --border-color: #272a33;
  --border-light: #1f222b;
  --border-strong: #484f58;
  
  --primary: #388bfd;
  --primary-hover: #58a6ff;
  --primary-subtle: #162438;
  
  --accent: #f0883e;
  --accent-subtle: #2d1e15;
  
  --success: #3fb950;
  --success-subtle: #14281a;
  --warning: #d29922;
  --warning-subtle: #2c2211;
  --danger: #f85149;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   BASE & RESET
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--text-main);
  background-color: var(--bg-page);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.has-audio-player .article-container,
body.has-audio-player .container {
  padding-bottom: 120px;
}

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

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.1s linear;
}

/* ==========================================================================
   TOP HEADER (Sticky Navigation Bar)
   ========================================================================== */

header.site-header {
  position: sticky;
  top: 0;
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
  z-index: 900;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-family: var(--font-ui);
}

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

/* Sidebar Toggle */
.sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.sidebar-toggle:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

/* Portal Nav Button */
.portal-nav-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.portal-nav-btn:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

.portal-nav-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Chapter Quick Nav */
.chapter-nav-dropdown {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  white-space: nowrap;
}

.chapter-nav-current {
  font-weight: 700;
  color: var(--text-main);
}

.chapter-nav-sep {
  color: var(--text-dim);
}

.chapter-nav-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s;
}

.chapter-nav-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Book Meta */
.book-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.book-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-publisher {
  background: #0066cc;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  font-family: var(--font-ui);
  flex-shrink: 0;
}

.book-title {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Header Pill Buttons & Groups */
.header-pill-group {
  display: flex;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.pill-btn {
  background: transparent;
  border: none;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  color: var(--text-main);
}

.pill-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-weight: 700;
}

/* Audiobook Button */
.header-btn.btn-audiobook {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.12) 0%, rgba(99, 102, 241, 0.12) 100%);
  color: #7c3aed;
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.header-btn.btn-audiobook:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.22) 0%, rgba(99, 102, 241, 0.22) 100%);
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

.header-btn.btn-audiobook.active {
  background: #7c3aed;
  color: #ffffff;
  border-color: #6d28d9;
}

/* Tools Group */
.header-tools-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.tool-icon-btn:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

/* Font Size & Theme Controls */
.font-size-control,
.theme-picker {
  display: flex;
  align-items: center;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.font-btn,
.theme-btn {
  background: transparent;
  border: none;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.font-btn:hover,
.theme-btn:hover {
  color: var(--text-main);
}

.theme-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-weight: 700;
}

/* Header Settings & Quick Theme Buttons */
.btn-settings-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-settings-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--primary);
}

.btn-quick-theme {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-quick-theme:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

/* ==========================================================================
   VIEW A: PORTAL OVERVIEW (HERO & CHAPTER CARDS GRID)
   ========================================================================== */

.portal-view {
  width: 100%;
}

.hero {
  max-width: 1000px;
  margin: 48px auto 36px;
  padding: 0 24px;
  text-align: center;
}

.hero-eyebrow {
  font-family: var(--font-ui);
  text-transform: uppercase;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 12px;
  display: inline-block;
}

.hero-title {
  font-family: var(--font-ui);
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-main);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-size: 1.25rem;
  font-style: italic;
  color: var(--text-sub);
  max-width: 820px;
  margin: 0 auto 24px;
  line-height: 1.6;
}

.hero-author {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.hero-meta-pill {
  background: var(--bg-subtle);
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-light);
  font-weight: 600;
  color: var(--text-sub);
  font-size: 0.85rem;
}

/* Container for Parts */
.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.part-block {
  margin-bottom: 54px;
}

.part-header {
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-strong);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.part-title {
  font-family: var(--font-ui);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.part-tag {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* Chapters Grid (3 Columns) */
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 22px;
}

.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 24px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.chapter-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-4px);
}

.card-top {
  margin-bottom: 16px;
}

.card-num {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 8px;
}

.card-title {
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-main);
  margin-bottom: 10px;
}

.card-desc {
  font-size: 0.95rem;
  color: var(--text-sub);
  line-height: 1.55;
}

.card-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-btn {
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.15s;
}

.chapter-card:hover .card-btn {
  transform: translateX(4px);
}

/* Site Footer */
footer.site-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  padding: 40px 24px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ==========================================================================
   VIEW B: READER VIEW (SIDEBAR TOC + ARTICLE CONTAINER)
   ========================================================================== */

.reader-view {
  width: 100%;
}

.app-layout {
  display: flex;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* Sidebar Table of Contents */
aside.toc-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 20px 16px;
  font-family: var(--font-ui);
  font-size: 13px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), margin-left 0.3s ease;
  z-index: 850;
  display: flex;
  flex-direction: column;
}

aside.toc-sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  pointer-events: none;
}

.toc-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

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

.sidebar-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: all 0.15s ease;
  line-height: 1;
}

.sidebar-close-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
  border-color: var(--primary);
}

.toc-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 14px;
}

.toc-search-box input {
  border: none;
  background: transparent;
  width: 100%;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-main);
  outline: none;
}

.toc-nav {
  flex: 1;
  overflow-y: auto;
}

.toc-nav ul {
  list-style: none;
}

.toc-nav li {
  margin-bottom: 3px;
}

.toc-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  line-height: 1.4;
  transition: all 0.15s ease;
}

.toc-nav a:hover {
  background: var(--border-color);
  color: var(--text-main);
}

.toc-nav a.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 700;
}

.toc-part-header {
  font-weight: 700;
  color: var(--text-main);
  font-size: 12px;
  padding: 10px 8px 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-mod-item {
  padding-left: 12px;
  font-size: 12.5px;
}

/* Sidebar Progress Box */
.sidebar-progress-box {
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  margin-top: 12px;
}

.sidebar-progress-track {
  height: 5px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.sidebar-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease;
}

.sidebar-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Article Container */
main.article-container {
  flex: 1;
  padding: 40px 48px 96px;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  min-width: 0;
}

article.book-chapter {
  width: 100%;
  max-width: var(--content-width);
}

/* Bilingual Mode: 2 Columns Side by Side */
.view-mode-bilingual article.book-chapter {
  max-width: 1360px;
}

.bilingual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  margin-top: 24px;
}

.content-col {
  min-width: 0;
}

.content-col-header {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.badge-col {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-col-vi {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.25);
}

.badge-col-en {
  background: rgba(14, 165, 233, 0.1);
  color: #0284c7;
  border: 1px solid rgba(14, 165, 233, 0.25);
}

/* Toggle Original Column Buttons */
.btn-toggle-orig {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-toggle-orig:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.reading-banner-clean {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 24px;
}

.reading-banner-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-ui);
}

.reading-banner-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.25);
}

.btn-restore-orig {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-restore-orig:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.header-btn.btn-quick-toggle-orig {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.header-btn.btn-quick-toggle-orig:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.header-btn.btn-quick-toggle-orig.is-hidden-mode {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border-color: rgba(37, 99, 235, 0.35);
}

/* ==========================================================================
   ARTICLE TYPOGRAPHY (Newsreader + Plus Jakarta Sans)
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-ui);
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.part-banner {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
}

h1.chapter-title {
  font-size: 2.2rem;
  margin-top: 6px;
  margin-bottom: 14px;
  line-height: 1.25;
}

.chapter-subtitle {
  font-size: 1.18rem;
  font-style: italic;
  color: var(--text-sub);
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--border-color);
}

h2 {
  font-size: 1.65rem;
  margin-top: 48px;
  margin-bottom: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-color);
}

h3 {
  font-size: 1.3rem;
  margin-top: 36px;
  margin-bottom: 16px;
}

h4 {
  font-size: 1.08rem;
  margin-top: 24px;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

p {
  margin-bottom: 22px;
  text-align: justify;
  hyphens: auto;
}

p.lead {
  font-size: 1.15em;
  line-height: 1.7;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 24px;
}

ul, ol {
  margin-bottom: 24px;
  padding-left: 28px;
}

li {
  margin-bottom: 10px;
}

strong {
  font-weight: 700;
  color: var(--text-main);
}

em {
  font-style: italic;
}

/* Quotes & Epigraphs */
.epigraph {
  background: var(--bg-surface);
  border-left: 4px solid var(--primary);
  padding: 20px 24px;
  border-radius: 0 10px 10px 0;
  margin: 28px 0 36px;
  box-shadow: var(--shadow-sm);
}

.epigraph blockquote {
  font-size: 1.15rem;
  font-style: italic;
  line-height: 1.65;
  color: var(--text-main);
  margin-bottom: 10px;
}

.epigraph cite {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: normal;
  text-align: right;
  font-weight: 600;
}

/* Callout Boxes */
.callout {
  border-radius: 12px;
  padding: 20px 24px;
  margin: 28px 0;
  border: 1px solid;
}

.callout-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout.note {
  background: var(--primary-subtle);
  border-color: rgba(0, 102, 204, 0.25);
  color: var(--text-main);
}

.callout.note .callout-header {
  color: var(--primary);
}

.callout.tip {
  background: var(--success-subtle);
  border-color: rgba(52, 199, 89, 0.25);
}

.callout.tip .callout-header {
  color: var(--success);
}

.callout.sidebar-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.callout.sidebar-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: var(--accent);
}

.callout.sidebar-box .callout-header {
  color: var(--accent);
  font-size: 1rem;
}

/* Figures & Diagrams */
figure.book-figure {
  margin: 36px 0;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

figure.book-figure:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

figure.book-figure img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0 auto 14px;
}

figcaption {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  font-weight: 500;
}

figcaption strong {
  color: var(--primary);
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  margin: 28px 0;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  background: var(--bg-surface);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  text-align: left;
}

table.data-table th {
  background: var(--bg-sidebar);
  padding: 14px 18px;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 2px solid var(--border-color);
}

table.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr:hover td {
  background: var(--primary-subtle);
}

/* Chapter Bottom Navigation */
.chapter-nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 2px solid var(--border-color);
  font-family: var(--font-ui);
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.chapter-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Back to Top Floating Button */
#back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 800;
}

#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

#back-to-top:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

/* ==========================================================================
   FLOATING AUDIOBOOK PLAYER BAR (BEDTIME AUDIO READER)
   ========================================================================== */

.audiobook-player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.1);
  transform: translateY(110%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), background 0.3s ease;
  user-select: none;
}

[data-theme="sepia"] .audiobook-player-bar {
  background: rgba(251, 247, 238, 0.96);
  border-top-color: var(--border-color);
}

[data-theme="dark"] .audiobook-player-bar {
  background: rgba(24, 26, 32, 0.96);
  border-top-color: var(--border-color);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
}

.audiobook-player-bar.active {
  transform: translateY(0);
}

.audio-player-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.audio-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 250px;
  max-width: 320px;
}

.audio-equalizer {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
  width: 24px;
  padding: 2px;
  flex-shrink: 0;
}

.audio-equalizer span {
  width: 3px;
  height: 4px;
  background: var(--primary);
  border-radius: 2px;
  transition: height 0.2s ease;
}

.audio-equalizer.playing span {
  animation: eq-bounce 1s ease-in-out infinite alternate;
}

.audio-equalizer.playing span:nth-child(1) { animation-duration: 0.6s; animation-delay: 0.1s; }
.audio-equalizer.playing span:nth-child(2) { animation-duration: 0.9s; animation-delay: 0.25s; }
.audio-equalizer.playing span:nth-child(3) { animation-duration: 0.7s; animation-delay: 0.15s; }
.audio-equalizer.playing span:nth-child(4) { animation-duration: 0.85s; animation-delay: 0.3s; }

@keyframes eq-bounce {
  0% { height: 4px; opacity: 0.6; }
  50% { height: 18px; opacity: 1; }
  100% { height: 8px; opacity: 0.8; }
}

.audio-title-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.audio-track-title {
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-track-status {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* Center Controls */
.audio-controls-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex: 1;
  max-width: 540px;
}

.audio-btns-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.audio-ctrl-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.audio-ctrl-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
  transform: scale(1.08);
}

.audio-play-main-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 102, 204, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.audio-play-main-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(0, 102, 204, 0.45);
}

.audio-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-family: var(--font-ui);
}

.audio-time-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 52px;
}

.audio-progress-track {
  flex: 1;
  height: 6px;
  background: var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: height 0.15s ease;
}

.audio-progress-track:hover {
  height: 8px;
}

.audio-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 6px;
  transition: width 0.15s ease;
}

/* Audio Right Tools */
.audio-tools-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
  justify-content: flex-end;
  font-family: var(--font-ui);
}

.audio-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  outline: none;
  font-family: var(--font-ui);
}

.sleep-timer-wrapper {
  position: relative;
}

.audio-timer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  font-family: var(--font-ui);
  white-space: nowrap;
  transition: all 0.2s ease;
}

.audio-timer-btn:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.audio-timer-btn.active {
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
  border-color: rgba(139, 92, 246, 0.4);
}

.sleep-timer-dropdown {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-xl);
  padding: 6px;
  min-width: 190px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 1050;
  animation: timerPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes timerPop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sleep-timer-dropdown.show {
  display: flex;
}

.sleep-timer-header {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  padding: 4px 8px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 3px;
}

.timer-option-btn {
  text-align: left;
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  color: var(--text-main);
  cursor: pointer;
  transition: background 0.15s;
}

.timer-option-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

.timer-option-btn.active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.audio-ambient-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  font-family: var(--font-ui);
  white-space: nowrap;
  transition: all 0.2s ease;
}

.audio-ambient-btn:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.audio-ambient-btn.active {
  background: rgba(14, 165, 233, 0.15);
  color: #0284c7;
  border-color: rgba(14, 165, 233, 0.4);
}

.audio-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
}

.audio-close-btn:hover {
  background: var(--border-color);
  color: var(--text-main);
}

/* Speaking Sentence Highlight */
.speaking-sentence-active {
  background: rgba(254, 240, 138, 0.45);
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.4);
  border-radius: 4px;
  padding: 2px 4px;
  transition: all 0.25s ease;
}

[data-theme="sepia"] .speaking-sentence-active {
  background: rgba(217, 119, 6, 0.18);
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.35);
}

[data-theme="dark"] .speaking-sentence-active {
  background: rgba(234, 179, 8, 0.18);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.35);
  color: #fef08a;
}

/* ==========================================================================
   MODALS (Lightbox, Glossary, Compliance, Template, Bookmarks)
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  display: flex;
  opacity: 1;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: var(--shadow-xl);
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-ui);
}

.modal-card-lg {
  max-width: 900px;
}

.modal-card-sm {
  max-width: 440px;
}

/* Settings Modal Elements */
.settings-modal-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 22px;
  overflow-y: auto;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.settings-pill-row {
  display: flex;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  gap: 4px;
}

.settings-pill-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  text-align: center;
  white-space: nowrap;
}

.settings-pill-btn:hover {
  color: var(--text-main);
}

.settings-pill-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-weight: 700;
}

.settings-theme-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.settings-theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 9px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s ease;
}

.settings-theme-btn .theme-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  display: inline-block;
}

.settings-theme-btn .theme-dot.light { background: #ffffff; }
.settings-theme-btn .theme-dot.sepia { background: #fbf0d9; border-color: #d8c39e; }
.settings-theme-btn .theme-dot.dark { background: #14171d; border-color: #3e4451; }

.settings-theme-btn:hover {
  border-color: var(--primary);
}

.settings-theme-btn.active {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-subtle);
}

.settings-font-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.settings-font-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s ease;
  text-align: center;
}

.settings-font-btn:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--primary);
}

.settings-tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.settings-tool-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.settings-tool-card:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.settings-tool-card .tool-card-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.settings-tool-card .tool-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close-btn:hover {
  background: var(--border-color);
  color: var(--text-main);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--border-color);
}

/* Lightbox Content */
.lightbox-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-width: 95vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
}

.lightbox-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-ui);
}

.lightbox-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lightbox-tool-btn,
.lightbox-close-btn {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-main);
}

.lightbox-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-body img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  transition: transform 0.2s ease;
}

/* Sidebar Backdrop on Mobile */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 800;
  display: none;
}

.sidebar-backdrop.active {
  display: block;
}

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES (Multi-Breakpoint Modern System)
   ========================================================================== */

/* 1. Standard Laptops & Large Desktops (<= 1366px) */
@media (max-width: 1366px) {
  .book-meta {
    display: none;
  }
  .header-btn.btn-quick-toggle-orig {
    display: none;
  }
}

/* 2. Compact Laptops & Small Desktops (<= 1300px) */
@media (max-width: 1300px) {
  .header-tools-group {
    display: none;
  }
  .theme-picker {
    display: none;
  }
  .btn-quick-theme {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border-radius: 8px;
  }
  .btn-settings-toggle {
    display: flex;
  }
}

/* 3. Tablets & Small Laptops (<= 1024px) */
@media (max-width: 1024px) {
  header.site-header {
    height: 54px;
    padding: 0 14px;
    gap: 8px;
  }

  .book-meta {
    display: none;
  }

  /* Move secondary controls to Settings Modal */
  .header-tools-group {
    display: none;
  }
  .font-size-control {
    display: none;
  }
  #header-trans-mode-group {
    display: none;
  }

  /* Compact View Mode Pills */
  #header-view-mode-group {
    padding: 2px;
  }
  #header-view-mode-group .pill-btn {
    padding: 4px 7px;
    font-size: 11.5px;
  }

  /* Show settings toggle button */
  .btn-settings-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 5px 9px;
  }

  /* Compact Next Chapter Link */
  #headerChapterNav #headerNextChapter,
  #headerChapterNav .chapter-nav-sep {
    display: none !important;
  }

  /* Sidebar Drawer on Tablet & Mobile (Hidden by default!) */
  aside.toc-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 310px;
    max-width: 84vw;
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xl);
    margin-left: 0 !important;
  }

  aside.toc-sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: flex;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
    backdrop-filter: blur(2px);
    display: none;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .bilingual-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  main.article-container {
    padding: 24px 18px 80px;
  }

  /* Bedtime Audiobook Player Responsive */
  .audio-player-inner {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "meta tools"
      "controls controls";
    padding: 8px 12px 14px;
    gap: 6px 8px;
  }
  .audio-meta {
    grid-area: meta;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }
  .audio-tools-right {
    grid-area: tools;
    min-width: 0;
    gap: 4px;
    flex-shrink: 0;
  }
  .audio-controls-center {
    grid-area: controls;
    width: 100%;
    max-width: 100%;
    gap: 4px;
  }
  .audio-select {
    display: none;
  }
  .audio-ambient-btn .ambient-label {
    display: none;
  }
}

/* 4. Mobile Devices & Small Tablets (<= 768px) */
@media (max-width: 768px) {
  header.site-header {
    height: 52px;
    padding: 0 10px;
    gap: 6px;
  }

  .header-left {
    gap: 6px;
  }

  .header-right {
    gap: 6px;
  }

  /* Icon-only Navigation Buttons */
  .sidebar-toggle {
    padding: 0;
    width: 36px;
    height: 36px;
    min-width: 36px;
    justify-content: center;
    border-radius: 8px;
  }
  .sidebar-toggle span {
    display: none;
  }

  .portal-nav-btn {
    padding: 0;
    width: 36px;
    height: 36px;
    min-width: 36px;
    justify-content: center;
    border-radius: 8px;
  }
  .portal-nav-btn span {
    display: none;
  }

  /* Compact Chapter Nav */
  #headerChapterNav {
    gap: 4px;
    font-size: 12px;
  }
  #headerChapterNav .chapter-nav-sep,
  #headerChapterNav #headerNextChapter {
    display: none !important;
  }
  #headerCurChapter {
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11.5px;
    font-weight: 700;
  }

  /* Hide Large Pill Group on Mobile */
  #header-view-mode-group {
    display: none;
  }

  /* Show Compact One-Touch Original Toggle Button */
  .header-btn.btn-quick-toggle-orig {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border-radius: 8px;
  }
  .header-btn.btn-quick-toggle-orig #quick-toggle-text {
    display: none;
  }
  .header-btn.btn-quick-toggle-orig #quick-toggle-icon {
    font-size: 13px;
    font-weight: 700;
  }

  /* Audiobook Button Icon-only */
  .header-btn.btn-audiobook {
    padding: 0;
    width: 36px;
    height: 36px;
    min-width: 36px;
    justify-content: center;
    border-radius: 8px;
  }
  .header-btn.btn-audiobook span {
    display: none;
  }

  /* Settings Button Icon-only */
  .btn-settings-toggle {
    padding: 0;
    width: 36px;
    height: 36px;
    min-width: 36px;
    justify-content: center;
    border-radius: 8px;
  }
  .btn-settings-toggle .btn-text {
    display: none;
  }

  /* Hero & Portal Cards */
  .hero {
    margin: 32px auto 24px;
    padding: 0 16px;
  }
  .hero-eyebrow {
    font-size: 0.75rem;
  }
  .hero-title {
    font-size: 1.85rem;
    line-height: 1.25;
  }
  .hero-subtitle {
    font-size: 0.95rem;
  }
  .hero-author {
    flex-direction: column;
    gap: 8px;
    align-items: center;
  }
  .chapters-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .chapter-card {
    padding: 20px 16px;
  }
  .chapter-card-header {
    flex-direction: column;
    gap: 6px;
  }
  .chapter-badge {
    align-self: flex-start;
  }
  .modal-card {
    max-width: 95vw;
    margin: 10px;
    max-height: 90vh;
  }
}

/* 5. Compact Smartphones (<= 520px & 375px) */
@media (max-width: 520px) {
  html, body {
    overflow-x: hidden !important;
    width: 100%;
  }

  header.site-header {
    height: 50px;
    padding: 0 8px;
    gap: 6px;
  }

  .header-left {
    gap: 6px;
  }

  .header-right {
    gap: 6px;
  }

  /* Hide Chapter Nav on Smallest Screens to maximize touch room */
  #headerChapterNav {
    display: none !important;
  }

  .sidebar-toggle,
  .portal-nav-btn,
  .header-btn,
  .btn-quick-theme,
  .btn-settings-toggle {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 8px;
  }

  main.article-container {
    padding: 16px 12px 70px;
  }

  .section-h2 {
    font-size: 1.35rem;
  }
  .section-h3 {
    font-size: 1.12rem;
  }
  .en-col {
    font-size: 0.94rem;
  }
  .vi-col {
    font-size: 1.02rem;
  }

  .settings-modal-body {
    padding: 14px 16px;
    gap: 14px;
  }
  .settings-pill-btn {
    font-size: 11px;
    padding: 6px 4px;
  }
  .settings-theme-btn {
    font-size: 11.5px;
    padding: 8px 4px;
  }
  .settings-tools-grid {
    grid-template-columns: 1fr;
  }
}
