/* System fonts only - no web fonts for better performance */

:root {
  --primary: #0066cc;
  --primary-dark: #0052a3;
  --secondary: #764ba2;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --info: #17a2b8;
  --text: #1a1a1a;
  --text-light: #6c757d;
  --bg: #ffffff;
  --bg-light: #f8f9fa;
  --border: #e0e0e0;
  --shadow: 0 4px 15px rgba(0,0,0,0.08);
  --shadow-hover: 0 8px 25px rgba(0,0,0,0.15);
  --font-base: 'System', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-content: Georgia, "Times New Roman", serif;
  --spacing: 0.25rem;
  --radius: 8px;
  --transition: all 0.3s ease;
  --contain: layout style paint;
}

/* Dark mode variables */
body.dark-mode {
  --primary: #4da3ff;
  --primary-dark: #3d8ce6;
  --secondary: #9b6fd6;
  --text: #e0e0e0;
  --text-light: #a0a0a0;
  --bg: #1a1a1a;
  --bg-light: #2a2a2a;
  --border: #404040;
  --shadow: 0 4px 15px rgba(0,0,0,0.4);
  --shadow-hover: 0 8px 25px rgba(0,0,0,0.6);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* Header Styles - Fixed height to prevent CLS */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,0.95);
  height: 70px;
  contain: layout style;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
  gap: 20px;
}

.logo {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  min-width: 150px;
}

.nav-main {
  display: flex;
  gap: 30px;
  align-items: center;
}

.nav-main a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}

.nav-main a:hover {
  color: var(--primary);
}

.nav-main a::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: width 0.3s;
}

.nav-main a:hover::after {
  width: 100%;
}

.search-header {
  position: relative;
}

.search-input {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 25px;
  width: 300px;
  height: 40px;
  font-size: 14px;
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text);
}

/* Main Content */
.main-content {
  min-height: calc(100vh - 200px);
  padding: 40px 0;
  contain: layout style;
}

/* Image styles to prevent CLS and optimize loading */
img {
  max-width: 100%;
  height: auto;
  display: block;
  aspect-ratio: attr(width) / attr(height);
  content-visibility: auto;
}

/* Native lazy loading */
img[loading="lazy"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

/* Optimize rendering for below-fold content */
.categories-grid,
.books-grid,
.chapters-grid {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Typography with fixed line-heights to prevent CLS */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 1rem;
  text-rendering: optimizeLegibility;
}

h1 { font-size: 2.5em; line-height: 1.2; min-height: 1.2em; }
h2 { font-size: 2em; line-height: 1.3; min-height: 1.3em; }
h3 { font-size: 1.5em; line-height: 1.4; min-height: 1.4em; }
h4 { font-size: 1.25em; line-height: 1.4; }
h5 { font-size: 1.1em; line-height: 1.5; }
h6 { font-size: 1em; line-height: 1.5; }

p {
  margin-bottom: 1.5em;
}

a {
  color: var(--primary);
  transition: var(--transition);
}

a:hover {
  color: var(--primary-dark);
}

/* Buttons */
button, .btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-cta {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  padding: 16px 32px;
  font-size: 18px;
}

.btn-cta:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-hover);
}

/* Cards */
.card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 25px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-hover);
}

/* Breadcrumb */
.breadcrumb {
  padding: 15px 0;
  font-size: 14px;
  color: var(--text-light);
}

.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* Chapter Layout */
.chapter-layout {
  display: grid;
  grid-template-columns: 250px 1fr 80px;
  gap: 40px;
  margin-top: 30px;
}

.sidebar {
  position: sticky;
  top: 100px;
  height: fit-content;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.toc-container {
  background: var(--bg-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.toc-container h3 {
  font-size: 16px;
  margin-bottom: 15px;
}

.toc {
  font-size: 14px;
}

.toc a {
  color: var(--text);
  text-decoration: none;
  display: block;
  padding: 5px 0;
  border-left: 2px solid transparent;
  padding-left: 10px;
  transition: var(--transition);
}

.toc a:hover {
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc a.active {
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

.chapter-content {
  max-width: 800px;
}

.content {
  font-family: var(--font-content);
  font-size: 18px;
  line-height: 1.8;
  color: var(--text);
}

.content h1, .content h2, .content h3 {
  font-family: var(--font-base);
  margin-top: 2em;
  margin-bottom: 1em;
}

.content p {
  margin-bottom: 1.5em;
  text-align: justify;
  hyphens: auto;
}

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

.content li {
  margin-bottom: 0.5em;
}

.content code {
  background: var(--bg-light);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
}

.content pre {
  background: var(--bg-light);
  padding: 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 1.5em;
}

.content blockquote {
  border-left: 4px solid var(--primary);
  padding-left: 20px;
  margin: 1.5em 0;
  font-style: italic;
  color: var(--text-light);
}

/* Word Cloud */
.wordcloud-section {
  margin: 40px 0;
  padding: 30px;
  background: var(--bg-light);
  border-radius: var(--radius);
}

.wordcloud {
  min-height: 300px;
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.wordcloud .word {
  display: inline-block;
  padding: 5px 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border-radius: 20px;
  transition: var(--transition);
  cursor: pointer;
  opacity: 0.8;
}

.wordcloud .word:hover {
  transform: scale(1.1);
  opacity: 1;
}

/* Chapter Navigation */
.chapter-navigation {
  display: flex;
  justify-content: space-between;
  margin: 60px 0;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.nav-prev, .nav-next {
  padding: 15px 25px;
  background: var(--bg-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.nav-prev:hover, .nav-next:hover {
  background: var(--primary);
  color: white;
}

/* Floating Actions */
.actions-sidebar {
  position: sticky;
  top: 100px;
  height: fit-content;
}

.floating-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 20px;
}

.action-btn:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

/* Progress Indicator */
.progress-indicator {
  margin-top: 20px;
  text-align: center;
}

.progress-text {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary);
}

.toc-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 15px;
  overflow: hidden;
}

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

/* Footer */
.footer {
  background: var(--bg-light);
  padding: 60px 0 30px;
  margin-top: 80px;
  border-top: 1px solid var(--border);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
  margin-bottom: 40px;
}

.footer-section h3 {
  font-size: 18px;
  margin-bottom: 15px;
}

.footer-links {
  list-style: none;
}

.footer-links li {
  margin-bottom: 10px;
}

.footer-links a {
  color: var(--text);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-light);
}

/* Forms */
.newsletter-form {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.newsletter-form input {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.newsletter-form button {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

/* Grids */
.books-grid, .chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 25px;
  margin: 40px 0;
}

.book-card, .chapter-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 25px;
  transition: var(--transition);
  text-decoration: none;
  color: var(--text);
  display: block;
}

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

.book-meta, .chapter-meta {
  display: flex;
  gap: 15px;
  margin: 10px 0;
  font-size: 14px;
  color: var(--text-light);
}

/* Home Page Specific */
.hero {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 100px 0;
  text-align: center;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
  margin: 40px 0;
}

.step {
  text-align: center;
}

.step-number {
  width: 60px;
  height: 60px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  margin: 0 auto 20px;
}

.testimonials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
  margin: 40px 0;
}

.testimonial {
  background: var(--bg-light);
  padding: 30px;
  border-radius: var(--radius);
  text-align: center;
}

.testimonial p {
  font-style: italic;
  margin-bottom: 20px;
}

.author {
  font-weight: 600;
  color: var(--primary);
}

.cta {
  background: var(--bg-light);
  padding: 80px 0;
  text-align: center;
  margin: 60px 0;
}

.cta h2 {
  font-size: 2.5em;
  margin-bottom: 20px;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --text: #e0e0e0;
    --text-light: #999;
    --bg: #1a1a1a;
    --bg-light: #2a2a2a;
    --border: #333;
  }
  
  .header {
    background: rgba(26,26,26,0.95);
  }
  
  .content {
    color: #e0e0e0;
  }
  
  .card, .book-card, .chapter-card {
    background: var(--bg-light);
  }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .chapter-layout {
    grid-template-columns: 200px 1fr;
  }
  
  .actions-sidebar {
    display: none;
  }
}

@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
  }
  
  .nav-main {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 20px;
  }
  
  .nav-main.active {
    display: flex;
  }
  
  .mobile-menu-toggle {
    display: block;
  }
  
  .search-input {
    width: 150px;
  }
  
  .chapter-layout {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    position: static;
    max-height: none;
  }
  
  .hero h1 {
    font-size: 2em;
  }
  
  .hero p {
    font-size: 1.1em;
  }
  
  .books-grid, .chapters-grid {
    grid-template-columns: 1fr;
  }
  
  .footer-grid {
    grid-template-columns: 1fr;
  }
  
  .content {
    font-size: 16px;
  }
  
  .content p {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 15px;
  }
  
  h1 { font-size: 1.8em; }
  h2 { font-size: 1.5em; }
  h3 { font-size: 1.25em; }
  
  .hero {
    padding: 60px 0;
  }
  
  .stats {
    flex-direction: column;
    gap: 15px;
  }
}

/* Print Styles */
@media print {
  .header, .footer, .sidebar, .actions-sidebar, 
  .chapter-navigation, .wordcloud-section {
    display: none;
  }
  
  .chapter-layout {
    grid-template-columns: 1fr;
  }
  
  .content {
    font-size: 12pt;
    line-height: 1.5;
  }
  
  a {
    color: black;
    text-decoration: none;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
  }
}

/* Loading States */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Performance Optimizations */
.contain-layout {
  contain: layout;
}

.contain-style {
  contain: style;
}

.contain-paint {
  contain: paint;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

img[loading="lazy"] {
  background: var(--bg-light);
}
/* Table of Contents */
.toc-container {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  max-height: 500px;
  overflow-y: auto;
}

.toc-container h3 {
  margin: 0 0 15px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.toc-list, .toc-nested {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-nested {
  margin-left: 20px;
}

.toc-item {
  margin: 8px 0;
}

.toc-link {
  color: var(--gray);
  text-decoration: none;
  display: block;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  font-size: 14px;
}

.toc-link:hover {
  background: rgba(0, 102, 204, 0.1);
  color: var(--primary);
}

.toc-link.active {
  background: var(--primary);
  color: white !important;
  font-weight: 600;
  padding-left: 15px;
  border-radius: 4px;
}

.toc-link.active .toc-text {
  color: white !important;
}

/* Ensure all nested/sub-item active links also have white text */
.toc-nested .toc-link.active {
  background: var(--primary);
  color: white !important;
}

.toc-nested .toc-link.active .toc-text {
  color: white !important;
}

/* Style for different TOC levels (h3 and h4 sub-sections) */
.toc-level-3 .toc-link {
  padding-left: 25px;
  font-size: 0.95em;
}

.toc-level-4 .toc-link {
  padding-left: 35px;
  font-size: 0.9em;
}

.toc-level-3 .toc-link.active,
.toc-level-4 .toc-link.active {
  background: var(--primary);
  color: white !important;
  padding-left: 25px;
}

.toc-level-4 .toc-link.active {
  padding-left: 35px;
}

.toc-level-3 .toc-link.active .toc-text,
.toc-level-4 .toc-link.active .toc-text {
  color: white !important;
}

/* Wordcloud Styles */
.wordcloud {
  min-height: 200px;
  padding: 20px;
  text-align: center;
  line-height: 2.5;
}

.wordcloud .word {
  display: inline-block;
  margin: 4px 8px;
  cursor: pointer;
  opacity: 0.8;
  font-weight: 500;
  transition: all 0.3s ease;
}

.wordcloud .word:hover {
  opacity: 1;
  transform: scale(1.1);
}

.wordcloud-empty {
  color: var(--gray);
  font-style: italic;
  padding: 40px;
  text-align: center;
}

.wordcloud-section {
  margin: 40px 0;
  padding: 30px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 8px;
}
EOF < /dev/null