/* === CHAPTER READING LAYOUT === */
/* Modern chapter reading experience with clean design */

:root {
  --reading-bg: #ffffff;
  --reading-text: #2d3748;
  --reading-text-muted: #718096;
  --reading-border: #e2e8f0;
  --reading-sidebar-bg: #f7fafc;
  --reading-accent: #0d8174;
  --reading-accent-hover: #0a6b5e;
  --reading-accent-light: #30c0a5;
  --reading-success: #38a169;
  --reading-warning: #d69e2e;
  --reading-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
    0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --reading-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --font-base-size: 16px;
  --line-height: 1.7;
}

/* Dark theme variables */
[data-theme="dark"] {
  --reading-bg: #1a202c;
  --reading-text: #e2e8f0;
  --reading-text-muted: #a0aec0;
  --reading-border: #2d3748;
  --reading-sidebar-bg: #2d3748;
  --reading-accent: #63b3ed;
  --reading-accent-hover: #4299e1;
}

/* PWA Install Toast Styling */
.toast {
  backdrop-filter: blur(10px);
  border: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.toast .toast-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toast .toast-body {
  background: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .toast .toast-body {
  background: rgba(45, 55, 72, 0.95);
  color: var(--reading-text);
}

/* Base layout adjustments */
body.chapter-reading {
  font-size: var(--font-base-size);
  line-height: var(--line-height);
  background-color: var(--reading-bg);
  color: var(--reading-text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Prevent body scroll when mobile sidebar is open */
body.sidebar-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* === CUSTOM READING NAVBAR === */
.reading-navbar {
  background: var(--reading-bg) !important;
  border-bottom: 1px solid var(--reading-border) !important;
  box-shadow: var(--reading-shadow);
  backdrop-filter: blur(10px);
  z-index: 1030;
  height: 76px;
  min-height: 76px;
}

.navbar-brand-reading {
  max-width: 250px;
}

.navbar-brand-reading .chapter-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--reading-text);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reading-progress-container {
  flex: 1;
  max-width: 300px;
  margin: 0 2rem;
  align-items: center;
}

.reading-progress {
  height: 4px;
  background-color: var(--reading-border);
  border-radius: 2px;
  overflow: hidden;
}

.reading-progress .progress-bar {
  background: linear-gradient(
    90deg,
    var(--reading-accent),
    var(--reading-accent-light)
  );
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--reading-text-muted);
  min-width: 30px;
}

/* Mobile toggle buttons */
#chapterToggle,
#tocToggle {
  border: 1px solid var(--reading-border);
  background: var(--reading-bg);
  color: var(--reading-text);
  transition: all 0.2s ease;
  position: relative;
  z-index: 1070;
}

#chapterToggle:hover,
#tocToggle:hover {
  background: var(--reading-accent);
  border-color: var(--reading-accent);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--reading-shadow);
}

#chapterToggle:focus,
#tocToggle:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 129, 116, 0.2);
}

/* Active state for toggle buttons */
#chapterToggle.active,
#tocToggle.active {
  background: var(--reading-accent);
  border-color: var(--reading-accent);
  color: white;
}

/* Mobile navbar adjustments */
@media (max-width: 991.98px) {
  .reading-navbar {
    padding: 0.5rem 1rem;
  }

  .navbar-brand-reading {
    max-width: 200px;
  }

  .navbar-brand-reading .chapter-title {
    font-size: 1rem;
  }

  .reading-progress-container {
    display: none !important;
  }

  /* Hide navbar toggle buttons on mobile */
  .reading-navbar #chapterToggle,
  .reading-navbar #tocToggle {
    display: none !important;
  }

  /* Ensure buttons are visible and clickable */
  .d-lg-none {
    display: block !important;
  }
}

/* Mobile Bottom Toggle Buttons */
@media (max-width: 991.98px) {
  .mobile-bottom-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1090;
    display: flex;
    justify-content: space-between;
    gap: 15px;
    background: transparent;
    padding: 10px 20px;
    border-radius: 25px;
    transition: all 0.3s ease;
    min-width: 100%;
  }

  .mobile-toggle-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--reading-accent);
    background: white;
    color: var(--reading-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(13, 129, 116, 0.2);
    cursor: pointer;
    user-select: none;
  }

  .mobile-toggle-btn:hover,
  .mobile-toggle-btn.active {
    background: var(--reading-accent);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(13, 129, 116, 0.4);
  }

  .mobile-toggle-btn:active {
    transform: scale(0.95);
  }

  /* Responsive adjustments for smaller screens */
  @media (max-width: 480px) {
    .mobile-bottom-controls {
      bottom: 15px;
      padding: 8px 15px;
      gap: 12px;
    }

    .mobile-toggle-btn {
      width: 45px;
      height: 45px;
      font-size: 1.1rem;
    }
  }

  /* Safe area for devices with notch/home indicator */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-bottom-controls {
      bottom: calc(20px + env(safe-area-inset-bottom));
    }
  }

  /* Dark theme adjustments */
  [data-theme="dark"] .mobile-bottom-controls {
    background: rgba(26, 32, 44, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  [data-theme="dark"] .mobile-toggle-btn {
    background: var(--reading-bg);
    color: var(--reading-accent);
  }

  [data-theme="dark"] .mobile-toggle-btn:hover,
  [data-theme="dark"] .mobile-toggle-btn.active {
    background: var(--reading-accent);
    color: white;
  }

  /* Hide mobile controls when sidebar is open */
  .sidebar-left.show ~ .mobile-bottom-controls,
  .sidebar-right.show ~ .mobile-bottom-controls {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
  }

  /* Animation for mobile controls */
  .mobile-bottom-controls {
    transition: all 0.3s ease;
  }

  /* Ensure controls stay above content but below sidebars */
  .mobile-bottom-controls {
    z-index: 1040;
  }

  /* When sidebar is open, lower the z-index */
  body.sidebar-open .mobile-bottom-controls {
    z-index: 1030;
  }
}

/* === SIDEBAR STYLES === */
.sidebar-left,
.sidebar-right {
  background-color: var(--reading-sidebar-bg);
  border-right: 1px solid var(--reading-border);
  height: calc(100vh - 76px);
  overflow-y: auto;
  overflow-x: hidden; /* Prevent horizontal scrolling */
  padding: 0;
  position: sticky;
  top: 76px;
  margin-top: 0;
  border-top: none;
  word-wrap: break-word; /* Ensure long words break properly */
  box-sizing: border-box; /* Include borders in width calculation */
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--reading-border);
}

/* Mobile Overlay */
.mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(2px);
}

.mobile-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Ensure proper responsive behavior */
@media (min-width: 992px) {
  .mobile-overlay {
    display: none !important;
  }
}

/* Touch/click improvements for mobile */
@media (max-width: 991.98px) {
  /* Better touch targets */
  #chapterToggle,
  #tocToggle {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Improve sidebar touch scrolling */
  .sidebar-left,
  .sidebar-right {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Prevent unwanted zoom on double tap */
  .sidebar-left *,
  .sidebar-right * {
    touch-action: manipulation;
  }

  /* Force remove any container gaps or padding */
  .container-fluid .row {
    margin: 0 !important;
  }

  .container-fluid .row .col-lg-3,
  .container-fluid .row .col-xl-2 {
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Ensure sidebars cover full viewport edge to edge */
  .sidebar-left,
  .sidebar-right {
    left: -100vw !important;
    right: auto !important;
    border-left: none !important;
    border-right: none !important;
  }

  .sidebar-right {
    left: auto !important;
    right: -100vw !important;
  }

  .sidebar-left.show {
    left: 0 !important;
  }

  .sidebar-right.show {
    right: 0 !important;
  }
}

/* Enhanced Fixed Sidebar Positioning for long content */
@media (min-width: 992px) {
  .sidebar-left {
    position: sticky !important;
    top: 76px !important;
    height: calc(100vh - 76px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important; /* Prevent horizontal overflow */
    z-index: 1020;
    margin-top: 0 !important;
    padding-top: 0 !important;
    max-width: 100%; /* Ensure sidebar doesn't exceed container width */
  }

  .sidebar-right {
    position: sticky !important;
    top: 76px !important;
    height: calc(100vh - 76px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important; /* Prevent horizontal overflow */
    z-index: 1020;
    margin-top: 0 !important;
    padding-top: 0 !important;
    max-width: 100%; /* Ensure sidebar doesn't exceed container width */
  }

  /* Ensure proper scrolling behavior */
  .sidebar-left .position-sticky,
  .sidebar-right .position-sticky {
    position: static !important;
  }

  /* Remove any Bootstrap grid gaps that might cause spacing issues */
  .sidebar-left.col-lg-3,
  .sidebar-right.col-lg-3,
  .sidebar-left.col-xl-2,
  .sidebar-right.col-xl-2 {
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-top: 0 !important;
    box-sizing: border-box !important;
  }
}

/* Mobile Sidebar Styles */
@media (max-width: 991.98px) {
  .sidebar-left,
  .sidebar-right {
    position: fixed !important;
    top: 0; /* Start from very top */
    left: -100vw; /* Use viewport width instead of percentage */
    width: 100vw; /* Full viewport width */
    max-width: 400px; /* Maximum width for larger phones */
    height: 100vh; /* Full viewport height */
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--reading-shadow-lg);
    margin: 0 !important; /* Remove any margins */
    padding: 0 !important; /* Remove Bootstrap padding */
    border-radius: 0; /* Remove any border radius */
    border: none !important; /* Remove all borders */
    padding-top: 76px; /* Add padding to account for navbar */
  }

  .sidebar-right {
    left: auto;
    right: -100vw; /* Use viewport width */
    transform: translateX(100%);
  }

  /* Show sidebars when active */
  .sidebar-left.show {
    left: 0;
    transform: translateX(0);
  }

  .sidebar-right.show {
    right: 0;
    transform: translateX(0);
  }

  /* Remove Bootstrap grid padding/margins on mobile */
  .sidebar-left.col-lg-3,
  .sidebar-right.col-lg-3,
  .sidebar-left.col-xl-2,
  .sidebar-right.col-xl-2 {
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Adjust main content when sidebar is open */
  .main-content.sidebar-open {
    margin-left: 0;
    margin-right: 0;
  }

  /* Mobile toggle buttons styling */
  .mobile-toggle {
    position: relative;
    z-index: 1060;
  }

  /* Hide desktop-only elements on mobile */
  .d-lg-none {
    display: block !important;
  }

  /* Ensure proper stacking order */
  .reading-navbar {
    z-index: 1070;
  }

  /* Sidebar header mobile adjustments */
  .sidebar-header {
    padding: 1rem 1.5rem 0.5rem;
    border-bottom: 1px solid var(--reading-border);
    background: var(--reading-sidebar-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    margin: 0 !important; /* Remove any margins */
    width: 100%; /* Ensure full width */
  }

  /* Adjust sidebar content padding on mobile */
  .sidebar-left .position-sticky,
  .sidebar-right .position-sticky {
    position: static !important;
    height: auto !important;
    padding: 0 !important; /* Remove padding */
    margin: 0 !important; /* Remove margins */
  }

  /* Ensure sidebar content takes full width */
  .sidebar-left > div,
  .sidebar-right > div {
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* TOC navigation mobile adjustments */
  .toc-nav {
    padding: 1rem 0.5rem;
    font-size: 0.8rem;
  }

  /* Chapter list mobile adjustments */
  .chapter-list {
    padding: 0.5rem 0;
  }

  .chapter-item {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }

  .chapter-number {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
    margin-right: 0.5rem;
  }

  .chapter-title {
    font-size: 0.8rem;
    line-height: 1.3;
  }

  /* Reading stats mobile adjustments */
  .reading-stats {
    margin: 1rem;
    padding: 0.75rem;
  }

  .reading-stats h6 {
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
  }

  /* Mobile sidebar animations */
  .sidebar-left,
  .sidebar-right {
    animation: none;
  }

  .sidebar-left.show,
  .sidebar-right.show {
    animation: slideInFromLeft 0.3s ease-out;
  }

  .sidebar-right.show {
    animation: slideInFromRight 0.3s ease-out;
  }
}

@keyframes slideInFromLeft {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

.sidebar-header {
  padding: 1rem 1.5rem 0.5rem;
  border-bottom: 1px solid var(--reading-border);
  margin-bottom: 0 !important;
  position: relative;
}

.sidebar-heading {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--reading-text);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Mobile close button for sidebar */
.sidebar-close {
  display: none;
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--reading-text-muted);
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  z-index: 10;
}

.sidebar-close:hover {
  background: var(--reading-border);
  color: var(--reading-text);
}

@media (max-width: 991.98px) {
  .sidebar-close {
    display: block;
  }

  .sidebar-header {
    padding: 1rem 3.5rem 0.5rem 1.5rem; /* Add more right padding for close button */
    width: 100%;
  }

  /* Ensure full width coverage on very small screens */
  @media (max-width: 480px) {
    .sidebar-left,
    .sidebar-right {
      max-width: 100vw !important; /* Full width on small screens */
      width: 100vw !important;
      border-radius: 0 !important;
    }

    /* Reduce padding on very small screens */
    .sidebar-header {
      padding: 0.75rem 3rem 0.5rem 1rem;
    }

    .chapter-list {
      padding: 0.5rem 0;
    }

    .chapter-item {
      padding: 0.5rem 1rem;
    }

    .toc-nav {
      padding: 0.75rem 0;
    }
  }

  /* Ensure no gaps on any mobile screen */
  @media (max-width: 991.98px) {
    html,
    body {
      overflow-x: hidden !important;
    }

    .container-fluid {
      padding: 0 !important;
      margin: 0 !important;
    }

    .row {
      margin: 0 !important;
    }
  }
} /* Chapter List Styles */
.chapter-list {
  padding: 1rem 0;
}

.chapter-item {
  display: flex;
  align-items: center;
  padding: 0.875rem 1.5rem;
  text-decoration: none;
  color: var(--reading-text);
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
  position: relative;
}

.chapter-item:hover {
  background-color: rgba(13, 129, 116, 0.05);
  color: var(--reading-accent);
  text-decoration: none;
}

.chapter-item.active {
  background-color: rgba(13, 129, 116, 0.1);
  color: var(--reading-accent);
  border-left: 3px solid var(--reading-accent);
}

.chapter-number {
  width: 28px;
  height: 28px;
  background: var(--reading-accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.75rem;
  flex-shrink: 0;
}

.chapter-item.active .chapter-number {
  background: var(--reading-accent);
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.2);
}

.chapter-info {
  flex: 1;
  min-width: 0;
}

.chapter-title {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chapter-duration {
  color: var(--reading-text-muted);
  font-size: 0.75rem;
}

/* ===== TABLE OF CONTENTS HIERARCHICAL STRUCTURE ===== */

/* TOC Navigation Container Enhancement */
.toc-nav {
  padding: 1.5rem 0;
  min-height: 50px;
  font-size: 0.875rem;
  line-height: 1.6;
  position: relative;
  background: transparent;
  overflow-x: hidden; /* Prevent horizontal scrolling in TOC */
  word-wrap: break-word; /* Break long words */
  max-width: 100%; /* Ensure TOC doesn't exceed container */
}

/* TOC Root Container */
.toc-nav .toc-root {
  padding-left: 0;
  position: relative;
  list-style: none;
  margin: 0;
}

/* Base TOC Item Styling */
.toc-nav .toc-item {
  position: relative;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  transition: all 0.3s ease;
  list-style: none;
}

/* TOC Links Base Styling */
.toc-nav .toc-link {
  display: block;
  text-decoration: none;
  color: #475569;
  padding: 0.5rem 1rem;
  transition: all 0.3s ease;
  position: relative;
  z-index: 2;
  font-weight: 500;
  line-height: 1.5;
}

.toc-nav .toc-link:hover {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.06);
  text-decoration: none;
  transform: translateX(4px);
}

.toc-nav .toc-link.active {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.12);
  font-weight: 600;
  transform: translateX(6px);
}

/* ===== HIERARCHICAL BULLET POINTS & INDENTATION ===== */

/* Level H1 - Main Sections */
.toc-nav .toc-item-h1 {
  margin: 1rem 0 0.75rem 0;
}

.toc-nav .toc-item-h1 .toc-link {
  font-weight: 700;
  font-size: 1rem;
  color: #1e293b;
  padding-left: 2.5rem;
}

.toc-nav .toc-item-h1 .toc-link::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: #2563eb;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}

/* Level H2 - Subsections */
.toc-nav .toc-item-h2 {
  margin: 0.6rem 0 0.4rem 1.5rem;
  position: relative;
}

.toc-nav .toc-item-h2 .toc-link {
  font-weight: 600;
  font-size: 0.9rem;
  color: #334155;
  padding-left: 2.5rem;
}

.toc-nav .toc-item-h2 .toc-link::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: #3b82f6;
  font-weight: 600;
}

/* Vertical connecting line for H2 items */
.toc-nav .toc-item-h2::after {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    rgba(37, 99, 235, 0.3) 0%,
    rgba(37, 99, 235, 0.2) 50%,
    rgba(37, 99, 235, 0.1) 100%
  );
  z-index: 1;
  border-radius: 1px;
}

/* Level H3 - Sub-subsections */
.toc-nav .toc-item-h3 {
  margin: 0.4rem 0 0.3rem 3rem;
  position: relative;
}

.toc-nav .toc-item-h3 .toc-link {
  font-weight: 500;
  font-size: 0.85rem;
  color: #475569;
  padding-left: 2.5rem;
}

.toc-nav .toc-item-h3 .toc-link::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 600;
}

/* Horizontal connecting line for H3 */
.toc-nav .toc-item-h3::before {
  content: "";
  position: absolute;
  left: -2.5rem;
  top: 0.9rem;
  width: 2rem;
  height: 2px;
  background: linear-gradient(
    to right,
    rgba(37, 99, 235, 0.2) 0%,
    rgba(37, 99, 235, 0.4) 50%,
    rgba(37, 99, 235, 0.6) 100%
  );
  z-index: 1;
  border-radius: 1px;
}

/* Small connection dot */
.toc-nav .toc-item-h3::after {
  content: "";
  position: absolute;
  left: -2.75rem;
  top: 0.75rem;
  width: 6px;
  height: 6px;
  background: #3b82f6;
  border-radius: 50%;
  z-index: 2;
  border: 2px solid #f8fafc;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.2);
}

/* Level H4 - Further subsections */
.toc-nav .toc-item-h4 {
  margin: 0.3rem 0 0.25rem 4.5rem;
  position: relative;
}

.toc-nav .toc-item-h4 .toc-link {
  font-weight: 500;
  font-size: 0.8rem;
  color: #64748b;
  padding-left: 2.5rem;
}

.toc-nav .toc-item-h4 .toc-link::before {
  content: "▫";
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: #9ca3af;
  font-weight: 500;
}

/* Horizontal connecting line for H4 */
.toc-nav .toc-item-h4::before {
  content: "";
  position: absolute;
  left: -2rem;
  top: 0.8rem;
  width: 1.5rem;
  height: 1px;
  background: linear-gradient(
    to right,
    rgba(107, 114, 128, 0.3) 0%,
    rgba(107, 114, 128, 0.5) 100%
  );
  z-index: 1;
}

/* Small connection dot for H4 */
.toc-nav .toc-item-h4::after {
  content: "";
  position: absolute;
  left: -2.25rem;
  top: 0.65rem;
  width: 4px;
  height: 4px;
  background: #9ca3af;
  border-radius: 50%;
  z-index: 2;
  border: 1px solid #f8fafc;
}

/* Level H5 & H6 - Deepest levels */
.toc-nav .toc-item-h5,
.toc-nav .toc-item-h6 {
  margin: 0.25rem 0 0.2rem 6rem;
  position: relative;
}

.toc-nav .toc-item-h5 .toc-link,
.toc-nav .toc-item-h6 .toc-link {
  font-weight: 400;
  font-size: 0.75rem;
  color: #64748b;
  padding-left: 2rem;
  opacity: 0.9;
}

.toc-nav .toc-item-h5 .toc-link::before {
  content: "▸";
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: #a1a1aa;
  font-weight: 400;
}

.toc-nav .toc-item-h6 .toc-link::before {
  content: "▹";
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: #a1a1aa;
  font-weight: 400;
}

/* ===== INTERACTIVE ENHANCEMENTS ===== */

/* Hover effects for all levels */
.toc-nav .toc-item:hover .toc-link {
  color: #2563eb;
  transform: translateX(4px);
}

.toc-nav .toc-item-h1:hover .toc-link::before,
.toc-nav .toc-item-h2:hover .toc-link::before,
.toc-nav .toc-item-h3:hover .toc-link::before {
  color: #2563eb;
  text-shadow: 0 1px 3px rgba(37, 99, 235, 0.4);
}

/* Active state visual feedback */
.toc-nav .toc-link.active::after {
  content: "";
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  /* background: #2563eb; */
}

/* Smooth animations on load */
@keyframes tocSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toc-nav {
  animation: tocSlideIn 0.4s ease-out;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
  .toc-nav {
    padding: 1rem 0;
    font-size: 0.8rem;
  }

  .toc-nav .toc-item-h2 {
    margin-left: 1rem;
  }

  .toc-nav .toc-item-h3 {
    margin-left: 2rem;
  }

  .toc-nav .toc-item-h4 {
    margin-left: 3rem;
  }

  .toc-nav .toc-item-h5,
  .toc-nav .toc-item-h6 {
    margin-left: 4rem;
  }

  /* Simplify TOC hierarchy on small screens */
  .toc-nav .toc-item-h4,
  .toc-nav .toc-item-h5,
  .toc-nav .toc-item-h6 {
    display: none; /* Hide deeper levels on mobile */
  }

  /* Adjust TOC link sizing for touch */
  .toc-nav .toc-link {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.4;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Better touch targets for TOC */
  .toc-nav .toc-item {
    margin-bottom: 0.25rem;
  }

  /* Improve readability */
  .toc-nav .toc-item-h1 .toc-link {
    font-size: 0.95rem;
    font-weight: 700;
  }

  .toc-nav .toc-item-h2 .toc-link {
    font-size: 0.875rem;
    font-weight: 600;
  }

  .toc-nav .toc-item-h3 .toc-link {
    font-size: 0.8rem;
    font-weight: 500;
  }
}
.toc-item-h4::before {
  content: "▫";
  color: #9ca3af;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.75rem;
  display: inline-block;
  width: 0.75rem;
  text-align: center;
  position: relative;
  z-index: 2;
  opacity: 0.8;
}

.toc-nav ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
  position: relative;
}

/* Root TOC list */
.toc-nav .toc-root {
  padding-left: 0;
  position: relative;
}

.toc-nav .toc-item {
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  position: relative;
  transition: all 0.2s ease;
}

/* Hierarchical styling with connecting lines */
.toc-item-h1 {
  margin: 0.75rem 0 0.5rem 0;
  font-weight: 600;
  position: relative;
}

.toc-item-h1::before {
  content: "●";
  color: #2563eb;
  font-weight: bold;
  margin-right: 0.75rem;
  font-size: 1rem;
  display: inline-block;
  width: 1.25rem;
  text-align: center;
}

.toc-item-h2 {
  margin: 0.5rem 0 0.25rem 1.5rem;
  font-weight: 500;
  position: relative;
}

.toc-item-h2::before {
  content: "○";
  color: #3b82f6;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.9rem;
  display: inline-block;
  width: 1rem;
  text-align: center;
}

/* Vertical connecting line for H2 items */
.toc-item-h2::after {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(
    to bottom,
    #e5e7eb 0%,
    #e5e7eb 50%,
    transparent 50%
  );
  z-index: 1;
}

.toc-item-h3 {
  margin: 0.35rem 0 0.2rem 3rem;
  font-weight: 500;
  position: relative;
}

.toc-item-h3::before {
  content: "▪";
  color: #6b7280;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.8rem;
  display: inline-block;
  width: 0.875rem;
  text-align: center;
}

/* Horizontal and vertical connecting lines for H3 */
.toc-item-h3::after {
  content: "";
  position: absolute;
  left: -2.25rem;
  top: 0.75rem;
  width: 1.5rem;
  height: 1px;
  background: #e5e7eb;
  z-index: 1;
}

.toc-item-h3::before {
  content: "▪";
  color: #6b7280;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.8rem;
  display: inline-block;
  width: 0.875rem;
  text-align: center;
  position: relative;
  z-index: 2;
}

/* Vertical line extending from parent H2 to H3 */
.toc-item-h2:has(+ .toc-item-h3)::after,
.toc-item-h3 + .toc-item-h3::after {
  content: "";
  position: absolute;
  left: -2.25rem;
  top: 0;
  bottom: -0.35rem;
  width: 1px;
  background: #e5e7eb;
  z-index: 1;
}

.toc-item-h4 {
  margin: 0.3rem 0 0.2rem 4.5rem;
  font-weight: normal;
  position: relative;
}

.toc-item-h4::before {
  content: "▫";
  color: #9ca3af;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.75rem;
  display: inline-block;
  width: 0.75rem;
  text-align: center;
  position: relative;
  z-index: 2;
}

/* Horizontal connecting line for H4 */
.toc-item-h4::after {
  content: "";
  position: absolute;
  left: -3.75rem;
  top: 0.6rem;
  width: 2.25rem;
  height: 1px;
  background: #e5e7eb;
  z-index: 1;
}

.toc-item-h5 {
  margin: 0.25rem 0 0.15rem 6rem;
  font-weight: normal;
  position: relative;
}

.toc-item-h5::before {
  content: "▸";
  color: #d1d5db;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.7rem;
  display: inline-block;
  width: 0.7rem;
  text-align: center;
  position: relative;
  z-index: 2;
}

/* Horizontal connecting line for H5 */
.toc-item-h5::after {
  content: "";
  position: absolute;
  left: -5.25rem;
  top: 0.5rem;
  width: 3rem;
  height: 1px;
  background: #f3f4f6;
  z-index: 1;
}

.toc-item-h6 {
  margin: 0.25rem 0 0.15rem 7.5rem;
  font-weight: normal;
  position: relative;
}

.toc-item-h6::before {
  content: "▹";
  color: #e5e7eb;
  font-weight: normal;
  margin-right: 0.75rem;
  font-size: 0.65rem;
  display: inline-block;
  width: 0.65rem;
  text-align: center;
  position: relative;
  z-index: 2;
}

/* Horizontal connecting line for H6 */
.toc-item-h6::after {
  content: "";
  position: absolute;
  left: -6.75rem;
  top: 0.5rem;
  width: 3.75rem;
  height: 1px;
  background: #f9fafb;
  z-index: 1;
}

/* Enhanced vertical connection lines for nested structures */
.toc-nav .toc-item {
  border-left: 1px solid transparent;
  padding-left: 0.5rem;
  transition: border-color 0.2s ease;
}

/* Vertical guide lines for better hierarchy visualization */
.toc-item-h2,
.toc-item-h3,
.toc-item-h4,
.toc-item-h5,
.toc-item-h6 {
  position: relative;
}

.toc-item-h2:before {
  content: "";
  position: absolute;
  left: -1.25rem;
  top: -0.25rem;
  bottom: -0.25rem;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    #e5e7eb 25%,
    #e5e7eb 75%,
    transparent 100%
  );
  z-index: 0;
}

.toc-item-h3:before {
  content: "";
  position: absolute;
  left: -2.75rem;
  top: -0.15rem;
  bottom: -0.15rem;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    #f3f4f6 30%,
    #f3f4f6 70%,
    transparent 100%
  );
  z-index: 0;
}

/* Hover effects for better interactivity */
.toc-nav .toc-item:hover {
  background-color: rgba(59, 130, 246, 0.05);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  margin: -0.2rem -0.5rem;
  transform: translateX(2px);
}

.toc-nav .toc-item:hover::before {
  transform: scale(1.1);
  filter: brightness(1.2);
}

/* Active state styling */
.toc-nav .toc-link.active {
  color: #2563eb;
  font-weight: 600;
  background-color: rgba(37, 99, 235, 0.1);
  padding: 0.25rem 0.5rem;
  border-radius: 0;
  margin: -0.25rem -0.5rem;
  border-left: 3px solid #0d8174;
  padding-left: 0.75rem;
}

/* Progressive indentation with subtle visual cues */
.toc-item-h1 .toc-link {
  font-size: 0.9rem;
  line-height: 1.4;
  color: #1f2937;
  font-weight: 600;
}

.toc-item-h2 .toc-link {
  font-size: 0.85rem;
  line-height: 1.4;
  color: #374151;
  font-weight: 500;
}

.toc-item-h3 .toc-link {
  font-size: 0.8rem;
  line-height: 1.3;
  color: #4b5563;
  font-weight: 500;
}

.toc-item-h4 .toc-link {
  font-size: 0.75rem;
  line-height: 1.3;
  color: #6b7280;
  font-weight: 400;
}

.toc-item-h5 .toc-link {
  font-size: 0.7rem;
  line-height: 1.2;
  color: #9ca3af;
  font-weight: 400;
}

.toc-item-h6 .toc-link {
  font-size: 0.65rem;
  line-height: 1.2;
  color: #d1d5db;
  font-weight: 400;
}

/* Smooth transitions for all TOC elements */
.toc-nav .toc-item,
.toc-nav .toc-link,
.toc-nav .toc-item::before,
.toc-nav .toc-item::after {
  transition: all 0.2s ease-in-out;
}

/* Enhanced connection lines with depth indication */
.toc-item-h3::before {
  background: linear-gradient(135deg, #e5e7eb 0%, #f3f4f6 50%, #e5e7eb 100%);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.05);
}

.toc-item-h4::before {
  background: linear-gradient(135deg, #f3f4f6 0%, #f9fafb 50%, #f3f4f6 100%);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.03);
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .toc-nav {
    font-size: 0.8rem;
  }

  .toc-item-h3 {
    margin-left: 2.5rem;
  }

  .toc-item-h4 {
    margin-left: 3.5rem;
  }

  .toc-item-h5 {
    margin-left: 4.5rem;
  }

  .toc-item-h6 {
    margin-left: 5.5rem;
  }
}

@media (max-width: 768px) {
  .toc-nav {
    font-size: 0.75rem;
    padding: 0.5rem;
  }

  .toc-item-h2 {
    margin-left: 1rem;
  }

  .toc-item-h3 {
    margin-left: 2rem;
  }

  .toc-item-h4 {
    margin-left: 3rem;
  }

  .toc-item-h5,
  .toc-item-h6 {
    display: none; /* Hide deeper levels on mobile */
  }
}

/* Loading and empty states */
.toc-loading {
  padding: 1rem;
  text-align: center;
  opacity: 0.7;
}

.toc-empty {
  padding: 1rem;
  text-align: center;
  color: var(--reading-text-muted);
  font-style: italic;
}

/* Nested sublists with proper indentation */
.toc-nav .toc-sublist {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
  padding-left: 1.25rem; /* Clear indentation for each level */
  margin-left: 0;
  position: relative;
}

/* Remove previous complex styling */
.toc-nav li {
  margin-bottom: 0.125rem;
  position: relative;
}

/* Heading container for bullet + text layout */
.toc-heading-container {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.125rem 0;
  transition: all 0.2s ease;
}

/* Bullet points styling */
.toc-bullet {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--reading-accent);
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  margin-top: 0.125rem;
  transition: all 0.2s ease;
}

/* TOC Links styling */
.toc-nav a {
  display: inline;
  color: var(--reading-text);
  text-decoration: none;
  line-height: 1.5;
  transition: color 0.2s ease;
  border-radius: 3px;
  padding: 0.125rem 0.25rem 0.125rem 0;
  word-break: break-word; /* Break long words to prevent overflow */
  overflow-wrap: break-word; /* Ensure text wraps properly */
  max-width: 100%; /* Prevent text from overflowing container */
}

.toc-nav a:hover {
  color: #2563eb;
  text-decoration: none;
}

.toc-nav a.active {
  color: #2563eb;
  font-weight: 600;
}

/* Remove old complex styling */

/* Hover and active states for all levels */
.toc-nav .toc-item:hover::before {
  color: #1d4ed8 !important;
}

.toc-nav .toc-item:hover a {
  color: #2563eb;
}

.toc-nav .toc-item.active::before {
  color: #1d4ed8 !important;
}

/* Hover and active states */
.toc-heading-container:hover .toc-link,
.toc-heading-container .toc-link.active {
  color: var(--reading-accent);
  background-color: rgba(49, 130, 206, 0.08);
  transform: translateX(2px);
}

.toc-heading-container:hover .toc-bullet,
.toc-heading-container .toc-link.active ~ .toc-bullet {
  color: var(--reading-accent);
  transform: scale(1.1);
}

/* Visual hierarchy indicators - subtle connecting lines */
.toc-nav .toc-sublist::before {
  content: "";
  position: absolute;
  left: 0.4rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(
    180deg,
    rgba(49, 130, 206, 0.15) 0%,
    rgba(49, 130, 206, 0.08) 50%,
    rgba(49, 130, 206, 0.03) 100%
  );
  transition: all 0.3s ease;
}

.toc-nav .toc-sublist:hover::before {
  background: linear-gradient(
    180deg,
    rgba(49, 130, 206, 0.3) 0%,
    rgba(49, 130, 206, 0.15) 50%,
    rgba(49, 130, 206, 0.08) 100%
  );
}

/* Placeholder items (if needed for structure) */
.toc-item.toc-placeholder {
  display: none;
}

/* Smooth transitions for all elements */
.toc-nav * {
  transition: all 0.2s ease;
}

/* Focus states for accessibility */
.toc-nav a:focus {
  outline: 2px solid var(--reading-accent);
  outline-offset: 1px;
  background-color: rgba(49, 130, 206, 0.1);
}

.toc-item-h5 .toc-level-indicator {
  background: rgba(236, 72, 153, 0.1);
  color: #ec4899;
}

.toc-item-h6 .toc-link {
  font-weight: 400;
  font-size: 0.65rem;
}

.toc-item-h6 .toc-level-indicator {
  background: rgba(107, 114, 128, 0.1);
  color: #6b7280;
}

/* Hover and active states */
.toc-item:hover .toc-link,
.toc-item .toc-link.active {
  color: var(--reading-accent);
  background-color: rgba(49, 130, 206, 0.05);
  transform: translateX(2px);
}

.toc-item:hover .toc-level-indicator,
.toc-item .toc-link.active + .toc-level-indicator {
  background-color: var(--reading-accent);
  color: white;
  transform: scale(1.05);
}

/* Indentation for nested levels using CSS custom properties */
.toc-nav .toc-sublist .toc-item {
  position: relative;
}

.toc-nav .toc-sublist .toc-sublist .toc-item {
  margin-left: 0.5rem;
}

.toc-nav .toc-sublist .toc-sublist .toc-sublist .toc-item {
  margin-left: 1rem;
}

.toc-nav .toc-sublist .toc-sublist .toc-sublist .toc-sublist .toc-item {
  margin-left: 1.5rem;
}

.toc-nav
  .toc-sublist
  .toc-sublist
  .toc-sublist
  .toc-sublist
  .toc-sublist
  .toc-item {
  margin-left: 2rem;
}

/* Connection lines for hierarchy */
.toc-nav .toc-sublist::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    180deg,
    rgba(49, 130, 206, 0.2) 0%,
    rgba(49, 130, 206, 0.1) 50%,
    rgba(49, 130, 206, 0.05) 100%
  );
  transition: all 0.3s ease;
}

.toc-nav .toc-sublist:hover::before {
  background: linear-gradient(
    180deg,
    rgba(49, 130, 206, 0.4) 0%,
    rgba(49, 130, 206, 0.2) 50%,
    rgba(49, 130, 206, 0.1) 100%
  );
}

/* Smooth transitions for all elements */
.toc-nav * {
  transition: all 0.2s ease;
}

/* Focus states for accessibility */
.toc-nav a:focus {
  outline: 2px solid var(--reading-accent);
  outline-offset: 2px;
  background-color: rgba(49, 130, 206, 0.1);
}

/* Loading state for TOC */
.toc-loading {
  padding: 1rem;
  text-align: center;
  opacity: 0.7;
}

/* TOC empty state */
.toc-empty {
  padding: 1rem;
  text-align: center;
  color: var(--reading-text-muted);
  font-style: italic;
}

/* Scrollbar styling for TOC sidebar */
.sidebar-right {
  scrollbar-width: thin;
  scrollbar-color: rgba(49, 130, 206, 0.3) transparent;
}

.sidebar-right::-webkit-scrollbar {
  width: 6px;
}

.sidebar-right::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-right::-webkit-scrollbar-thumb {
  background: rgba(49, 130, 206, 0.3);
  border-radius: 3px;
}

.sidebar-right::-webkit-scrollbar-thumb:hover {
  background: rgba(49, 130, 206, 0.5);
}

/* Improved hierarchy visual indicators */
.toc-nav .toc-sublist {
  position: relative;
}

.toc-nav .toc-sublist:not(:last-child)::after {
  content: "";
  position: absolute;
  left: -1px;
  bottom: -0.125rem;
  width: 12px;
  height: 2px;
  background: rgba(49, 130, 206, 0.1);
  border-radius: 1px;
}

/* Animation for TOC items */
@keyframes tocFadeIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toc-nav .toc-item {
  animation: tocFadeIn 0.3s ease forwards;
}

.toc-nav .toc-item:nth-child(1) {
  animation-delay: 0.05s;
}
.toc-nav .toc-item:nth-child(2) {
  animation-delay: 0.1s;
}
.toc-nav .toc-item:nth-child(3) {
  animation-delay: 0.15s;
}
.toc-nav .toc-item:nth-child(4) {
  animation-delay: 0.2s;
}
.toc-nav .toc-item:nth-child(5) {
  animation-delay: 0.25s;
}

/* Compact mode for TOC when there are many items */
.toc-nav.compact .toc-item {
  margin-bottom: 0.125rem;
}

.toc-nav.compact .toc-link {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  font-size: 0.8rem;
  padding-left: 16px !important;
}

.toc-nav.compact .toc-level-indicator {
  font-size: 0.6rem;
  padding: 0.0625rem 0.25rem;
}

/* Reading Stats */
.reading-stats {
  margin: 1.5rem;
  background: var(--reading-bg) !important;
  border: 1px solid var(--reading-border) !important;
  border-radius: 8px;
  box-shadow: var(--reading-shadow);
}

.reading-stats h6 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--reading-text);
  margin-bottom: 1rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-item small {
  color: var(--reading-text-muted);
  font-size: 0.75rem;
}

/* === MAIN CONTENT AREA === */
.reading-content {
  max-width: none;
  padding: 2rem;
  background-color: var(--reading-bg);
}

.content-wrapper {
  max-width: 750px;
  margin: 0 auto;
}

/* Chapter Header */
.chapter-header {
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--reading-border);
  margin-bottom: 3rem;
}

.chapter-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chapter-meta .badge {
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-weight: 500;
}

.chapter-title-main {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--reading-text);
  margin: 1.5rem 0 1rem;
}

.chapter-description {
  font-size: 1.125rem;
  color: var(--reading-text-muted);
  line-height: 1.6;
  margin-bottom: 0;
}

.learning-objectives {
  background: rgba(49, 130, 206, 0.05);
  border: 1px solid rgba(49, 130, 206, 0.1);
  border-radius: 8px;
  padding: 1.5rem;
}

.learning-objectives h6 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.learning-objectives ul {
  margin: 0;
}

.learning-objectives li {
  display: flex;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.learning-objectives li:last-child {
  margin-bottom: 0;
}

/* === CHAPTER CONTENT STYLING === */
.chapter-content {
  font-size: var(--font-base-size);
  line-height: var(--line-height);
  color: var(--reading-text);
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4,
.chapter-content h5,
.chapter-content h6 {
  color: var(--reading-text);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  scroll-margin-top: 100px;
}

.chapter-content h1 {
  font-size: 2rem;
}
.chapter-content h2 {
  font-size: 1.75rem;
}
.chapter-content h3 {
  font-size: 1.5rem;
}
.chapter-content h4 {
  font-size: 1.25rem;
}
.chapter-content h5 {
  font-size: 1.125rem;
}
.chapter-content h6 {
  font-size: 1rem;
}

.chapter-content p {
  margin-bottom: 1.5rem;
  line-height: var(--line-height);
}

.chapter-content ul,
.chapter-content ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem;
}

.chapter-content li {
  margin-bottom: 0.5rem;
  line-height: var(--line-height);
}

.chapter-content blockquote {
  border-left: 4px solid var(--reading-accent);
  background: rgba(49, 130, 206, 0.05);
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.chapter-content blockquote p:last-child {
  margin-bottom: 0;
}

.chapter-content code {
  background: rgba(0, 0, 0, 0.05);
  color: #e91e63;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: "JetBrains Mono", "Fira Code", monospace;
}

.chapter-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 1.5rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 2rem 0;
  position: relative;
}

.chapter-content pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.chapter-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  background: var(--reading-bg);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--reading-shadow);
}

.chapter-content th,
.chapter-content td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--reading-border);
}

.chapter-content th {
  background: var(--reading-sidebar-bg);
  font-weight: 600;
  color: var(--reading-text);
}

.chapter-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 2rem 0;
  box-shadow: var(--reading-shadow);
}

/* === CHAPTER NAVIGATION === */
.chapter-navigation {
  margin-top: 3rem;
  padding-top: 2rem;
}

.chapter-navigation .btn {
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.2s ease;
}

.chapter-navigation .btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--reading-shadow-lg);
}

.chapter-navigation strong {
  font-weight: 600;
  display: block;
  margin-top: 0.25rem;
}

/* === READING FOOTER === */
.reading-footer {
  background: var(--reading-sidebar-bg) !important;
  border-top: 1px solid var(--reading-border) !important;
  margin-top: auto;
}

.reading-footer .btn {
  border-radius: 6px;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  transition: all 0.2s ease;
}

.reading-footer .btn:hover {
  transform: translateY(-1px);
}

/* === RESPONSIVE DESIGN === */
/* === MOBILE OVERLAY === */
.mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1030;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* === MOBILE RESPONSIVENESS === */
@media (max-width: 1199.98px) {
  .sidebar-fixed-right {
    display: none !important;
  }

  .reading-content-fixed {
    margin-right: 0 !important;
    padding-right: 1rem;
  }

  /* TOC Toggle for tablet */
  #tocToggle {
    display: inline-block !important;
  }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
  .sidebar-fixed-left {
    width: 300px !important;
  }

  .reading-content-fixed {
    margin-left: 300px !important;
    margin-right: 0 !important;
  }

  .sidebar-fixed-right {
    display: none !important;
  }
}

@media (max-width: 991.98px) {
  .sidebar-fixed-left {
    position: fixed !important;
    top: 76px;
    left: -100%;
    width: 300px;
    height: calc(100vh - 76px);
    z-index: 1040;
    transition: left 0.3s ease;
    background: var(--reading-sidebar-bg);
    border-right: 1px solid var(--reading-border);
  }

  .sidebar-fixed-left.show {
    left: 0;
  }

  .reading-content-fixed {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    padding: 1.5rem 1rem;
  }

  .content-wrapper {
    max-width: 100%;
  }

  .chapter-title-main {
    font-size: 1.875rem;
  }

  .reading-progress-container {
    display: none !important;
  }

  /* Mobile TOC Sidebar */
  .sidebar-fixed-right {
    position: fixed !important;
    top: 76px;
    right: -100%;
    width: 300px;
    height: calc(100vh - 76px);
    z-index: 1040;
    transition: right 0.3s ease;
    display: block !important;
  }

  .sidebar-fixed-right.show {
    right: 0;
  }

  /* Mobile TOC optimizations */
  .toc-nav.compact .toc-item {
    margin-bottom: 0.1rem;
  }

  .toc-nav.compact .toc-bullet {
    font-size: 0.65rem;
    width: 10px;
  }

  .toc-nav.compact .toc-link {
    font-size: 0.75rem;
    padding-top: 0.1rem;
    padding-bottom: 0.1rem;
    padding-left: 16px !important;
  }

  /* Reduce indentation on tablet */
  .toc-nav .toc-sublist {
    padding-left: 1rem;
  }

  .toc-nav .toc-root {
    padding-left: 0.25rem;
  }
}

@media (max-width: 767.98px) {
  .reading-navbar .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .navbar-brand-reading {
    max-width: 200px;
  }

  .navbar-brand-reading .chapter-title {
    font-size: 1rem;
  }

  /* Very compact TOC for mobile */
  .toc-nav {
    padding: 0.75rem;
  }

  .toc-nav .toc-item {
    margin-bottom: 0.1rem;
  }

  .toc-nav .toc-bullet {
    font-size: 0.6rem;
    width: 8px;
    margin-top: 0.1rem;
  }

  .toc-nav .toc-link {
    font-size: 0.7rem;
    line-height: 1.3;
    padding: 0.1rem 0.2rem;
  }

  .toc-item-h1 .toc-link {
    font-size: 0.75rem;
  }
  .toc-item-h2 .toc-link {
    font-size: 0.7rem;
  }
  .toc-item-h3 .toc-link {
    font-size: 0.65rem;
  }
  .toc-item-h4 .toc-link {
    font-size: 0.6rem;
  }
  .toc-item-h5 .toc-link {
    font-size: 0.55rem;
  }
  .toc-item-h6 .toc-link {
    font-size: 0.5rem;
  }

  /* Ultra-compact nesting for mobile */
  .toc-nav .toc-sublist {
    padding-left: 0.75rem;
  }

  .toc-nav .toc-root {
    padding-left: 0.2rem;
  }

  .toc-nav .toc-sublist .toc-sublist .toc-item {
    margin-left: 0.2rem;
  }

  .toc-nav .toc-sublist .toc-sublist .toc-sublist .toc-item {
    margin-left: 0.3rem;
  }

  /* Reduce animation delays on mobile for faster loading */
  .toc-nav .toc-item:nth-child(n) {
    animation-delay: 0.02s;
  }

  .reading-content {
    padding: 1rem;
  }

  .chapter-header {
    margin-bottom: 2rem;
  }

  .chapter-title-main {
    font-size: 1.5rem;
  }

  .chapter-description {
    font-size: 1rem;
  }

  .chapter-content {
    font-size: 0.95rem;
  }

  .chapter-content h1 {
    font-size: 1.5rem;
  }
  .chapter-content h2 {
    font-size: 1.375rem;
  }
  .chapter-content h3 {
    font-size: 1.25rem;
  }
  .chapter-content h4 {
    font-size: 1.125rem;
  }

  .chapter-navigation .btn {
    padding: 0.875rem;
    font-size: 0.85rem;
  }

  .btn-group .btn {
    padding: 0.375rem 0.5rem;
  }

  .btn-group .btn i {
    font-size: 0.8rem;
  }
}

/* === FONT SIZE CONTROLS === */
.font-size-small {
  --font-base-size: 14px;
}
.font-size-normal {
  --font-base-size: 16px;
}
.font-size-large {
  --font-base-size: 18px;
}
.font-size-xlarge {
  --font-base-size: 20px;
}

/* === SMOOTH SCROLLING === */
html {
  scroll-behavior: smooth;
}

/* === FOCUS STYLES === */
.btn:focus,
.chapter-item:focus,
.toc-nav a:focus {
  outline: 2px solid var(--reading-accent);
  outline-offset: 2px;
}

/* === PRINT STYLES === */
@media print {
  .reading-navbar,
  .sidebar-left,
  .sidebar-right,
  .reading-footer,
  .chapter-navigation {
    display: none !important;
  }

  .reading-content {
    padding: 0;
    max-width: 100%;
  }

  .chapter-content {
    font-size: 12pt;
    line-height: 1.5;
  }
}

/* === CUSTOM SCROLLBARS === */
.sidebar-left::-webkit-scrollbar,
.sidebar-right::-webkit-scrollbar {
  width: 6px;
}

.sidebar-left::-webkit-scrollbar-track,
.sidebar-right::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-left::-webkit-scrollbar-thumb,
.sidebar-right::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.sidebar-left::-webkit-scrollbar-thumb:hover,
.sidebar-right::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* === ANIMATIONS === */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chapter-content > * {
  animation: fadeInUp 0.5s ease-out;
}

/* === LOADING STATES === */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid var(--reading-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
