@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #111638;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --text-primary: #e8eaf6;
  --text-secondary: #9fa4c4;
  --text-muted: #9ea3c7;
  --accent-purple: #7c3aed;
  --accent-purple-light: #a78bfa;
  --accent-amber: #f59e0b;
  --accent-teal: #06b6d4;
  --accent-green: #10b981;
  --accent-rose: #f43f5e;
  --gradient-hero: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);
  --gradient-warm: linear-gradient(135deg, #f59e0b 0%, #f43f5e 100%);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px rgba(124, 58, 237, 0.3);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

img {
  -webkit-user-drag: none;
}

h1,
h2,
h3,
h4,
h5 {
  font-family: 'Outfit', sans-serif;
  line-height: 1.3;
}

/* ===== PARTICLES BACKGROUND ===== */
#particles-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.4;
}

/* ===== SIDEBAR NAV ===== */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 300px;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar.collapsed {
  transform: translateX(-300px);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
}

.sidebar-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-list {
  list-style: none;
  padding: 12px 10px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(124, 58, 237, 0.15);
  color: #a78bfa;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent-purple);
  border-radius: 4px;
}

.nav-num {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--bg-glass);
  flex-shrink: 0;
  font-family: 'JetBrains Mono', monospace;
}

.nav-item.active .nav-num {
  background: rgba(124, 58, 237, 0.3);
  color: #a78bfa;
}

/* ===== LANGUAGE SWITCHER ===== */
.lang-switcher {
  display: flex;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0.25rem;
  margin: 0.75rem 1rem 0;
}

.lang-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.lang-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.07);
}

.lang-btn.active {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.35);
}

/* Ripple effect on click */
.lang-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%), rgba(255, 255, 255, 0.25) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.lang-btn:active::after {
  opacity: 1;
  transition: opacity 0s;
}

/* ===== MOBILE NAV TOGGLE ===== */
.nav-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition);
}

.nav-overlay.show {
  display: block;
  opacity: 1;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: 300px;
  position: relative;
  z-index: 1;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

.main-content.expanded {
  margin-left: 0;
}

/* ===== CHAPTER CONTENT ===== */
.chapter {
  display: none;
  animation: fadeIn 0.5s ease;
}

.chapter.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chapter-hero {
  position: relative;
  overflow: hidden;
}

.chapter-hero img {
  max-width: 100%;
  max-height: 100vh;
  /* width: auto; */
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.chapter-hero-overlay {
  position: relative;
  z-index: 2;
  padding: 32px 48px 36px;
  width: 100%;
  background: linear-gradient(to bottom, rgba(10, 14, 39, 0.85) 0%, var(--bg-primary) 100%);
  margin-top: -40px;
}

.chapter-hero-overlay .ch-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent-amber);
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.chapter-hero-overlay h1 {
  font-size: 2.6rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.chapter-hero-overlay .ch-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
}

.chapter-body {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 32px 80px;
}

.chapter-body h2 {
  font-size: 1.7rem;
  font-weight: 700;
  margin: 48px 0 20px;
  color: var(--text-primary);
  position: relative;
  padding-left: 20px;
}

.chapter-body h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 4px;
  height: 28px;
  background: var(--gradient-hero);
  border-radius: 4px;
}

.chapter-body h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 32px 0 14px;
  color: var(--accent-purple-light);
}

.chapter-body p {
  margin-bottom: 18px;
  color: var(--text-secondary);
  font-size: 1.02rem;
}

/* ===== STORY DIALOGUE ===== */
.dialogue {
  display: flex;
  gap: 16px;
  margin: 24px 0;
  padding: 20px;
  background: var(--bg-glass);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.dialogue-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.dialogue-avatar.ava {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: #fff;
}

.dialogue-avatar.max {
  background: linear-gradient(135deg, #06b6d4, #10b981);
  color: #fff;
}

.dialogue-content {
  flex: 1;
}

.dialogue-name {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.dialogue-name.ava {
  color: var(--accent-purple-light);
}

.dialogue-name.max {
  color: var(--accent-teal);
}

.dialogue-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}

/* ===== CODE BLOCKS ===== */
.code-block {
  margin: 24px 0;
  border-radius: var(--radius);
  background: #0d1117;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.code-lang {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent-teal);
  font-weight: 600;
  text-transform: uppercase;
}

.code-copy {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: var(--transition);
}

.code-copy:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple-light);
}

.code-block pre {
  padding: 20px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  line-height: 1.7;
  color: #c9d1d9;
}

/* ===== SYNTAX HIGHLIGHTING ===== */
.kw {
  color: #ff7b72;
}

/* keywords */
.fn {
  color: #d2a8ff;
}

/* functions */
.str {
  color: #a5d6ff;
}

/* strings */
.num {
  color: #79c0ff;
}

/* numbers */
.cmt {
  color: #6b7b8d;
  font-style: italic;
}

/* comments */
.op {
  color: #ff7b72;
}

/* operators */
.type {
  color: #ffa657;
}

/* types */
.var {
  color: #ffa657;
}

/* variables */

/* ===== CONCEPT CARDS ===== */
.concept-card {
  margin: 28px 0;
  padding: 24px 28px;
  border-radius: var(--radius);
  background: var(--bg-glass);
  border-left: 4px solid var(--accent-purple);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 4px solid var(--accent-purple);
}

.concept-card.tip {
  border-left-color: var(--accent-green);
}

.concept-card.warning {
  border-left-color: var(--accent-amber);
}

.concept-card.info {
  border-left-color: var(--accent-teal);
}

.concept-card h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.concept-card p {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

/* ===== FLOWCHARTS (MERMAID) ===== */
.flowchart-container {
  margin: 32px 0;
  padding: 28px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
  overflow-x: auto;
}

.flowchart-container h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* Mermaid subgraph & cluster safety — prevent title overlap with top nodes */
.mermaid { line-height: 1.4; }
.mermaid svg { height: auto; min-width: 100%; }
.mermaid .cluster rect { rx: 10; ry: 10; }
.mermaid .cluster-label foreignObject { overflow: visible !important; }
.mermaid .cluster-label .nodeLabel,
.mermaid .cluster-label span {
  background: rgba(10, 6, 30, 0.92);
  padding: 3px 12px;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.mermaid .nodeLabel { line-height: 1.35; }

/* ===== INLINE IMAGES ===== */
.chapter-img {
  margin: 32px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.chapter-img img {
  width: 100%;
  display: block;
}

.chapter-img figcaption {
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  background: var(--bg-glass);
}

/* ===== QUIZ SECTION ===== */
.quiz-section {
  margin: 40px 0;
  padding: 32px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(6, 182, 212, 0.08));
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.quiz-section h3 {
  color: var(--accent-amber);
  margin-top: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-question {
  margin: 20px 0;
}

.quiz-question p {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-option {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.quiz-option:hover {
  border-color: var(--accent-purple);
  background: rgba(124, 58, 237, 0.1);
}

.quiz-option.correct {
  border-color: var(--accent-green);
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}

.quiz-option.wrong {
  border-color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.1);
  color: var(--accent-rose);
}

.quiz-feedback {
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: none;
}

.quiz-feedback.show {
  display: block;
}

.quiz-feedback.correct {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent-green);
}

.quiz-feedback.wrong {
  background: rgba(244, 63, 94, 0.1);
  color: var(--accent-rose);
}

/* ===== EXERCISE BOX ===== */
.exercise-box {
  margin: 32px 0;
  padding: 28px;
  border-radius: var(--radius);
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.exercise-box h4 {
  color: var(--accent-amber);
  font-size: 1.05rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.exercise-box ol,
.exercise-box ul {
  padding-left: 20px;
  color: var(--text-secondary);
}

.exercise-box li {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

/* ===== COMPARISON TABLE ===== */
.compare-table {
  width: 100%;
  margin: 24px 0;
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
}

.compare-table th {
  padding: 14px 18px;
  background: rgba(124, 58, 237, 0.15);
  color: var(--accent-purple-light);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: left;
}

.compare-table td {
  padding: 12px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.compare-table tr:hover td {
  background: var(--bg-glass);
}

.compare-table code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
  color: #ffa657;
}

/* ===== CHAPTER NAV FOOTER ===== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 32px 0;
  margin-top: 48px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
  font-weight: 500;
}

.chapter-nav-btn:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple-light);
  background: rgba(124, 58, 237, 0.1);
}

.chapter-nav-btn.primary {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
  color: #fff;
}

.chapter-nav-btn.primary:hover {
  background: #6d28d9;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 300px;
  right: 0;
  height: 3px;
  z-index: 50;
  background: rgba(255, 255, 255, 0.05);
}

.progress-fill {
  height: 100%;
  background: var(--gradient-hero);
  transition: width 0.5s ease;
  width: 10%;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-300px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .nav-toggle {
    display: flex;
  }

  .progress-bar {
    left: 0;
  }

  .chapter-hero-overlay {
    padding: 24px;
  }

  .chapter-hero-overlay h1 {
    font-size: 1.8rem;
  }

  .chapter-body {
    padding: 32px 20px 60px;
  }
}

@media (max-width: 600px) {

  .chapter-hero-overlay h1 {
    font-size: 1.5rem;
  }

  .dialogue {
    flex-direction: column;
    gap: 10px;
  }

  .chapter-nav {
    flex-direction: column;
    gap: 12px;
  }

  .chapter-nav-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ===== MERMAID OVERRIDE ===== */
.mermaid {
  background: transparent !important;
}

.mermaid svg {
  max-width: 100%;
}

/* ===== SCROLL ANIMATIONS ===== */
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== COVER PAGE ===== */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 40px 24px;
  position: relative;
}

.cover-page img {
  width: 100%;
  max-width: 500px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  margin-bottom: 40px;
}

.cover-page h1 {
  font-size: 3.2rem;
  font-weight: 800;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 16px;
}

.cover-page .subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 540px;
  margin-bottom: 36px;
}

.cover-page .start-btn {
  padding: 16px 40px;
  border-radius: 50px;
  border: none;
  background: var(--gradient-hero);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 8px 30px rgba(124, 58, 237, 0.4);
  font-family: 'Outfit', sans-serif;
}

.cover-page .start-btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

/* --- Volume Marker --- */
.vol-marker {
  display: inline-block;
  padding: 6px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-amber);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 1.5rem;
}

/* --- Series Checklist --- */
.series-checklist {
  margin: 3rem 0;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
}

.series-checklist h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 1.5rem !important;
  text-align: center;
  border: none !important;
  padding: 0 !important;
}

.series-checklist h3::before {
  display: none !important;
}

.series-checklist h3 span {
  color: var(--accent-purple-light);
}

.checklist-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.checklist-item.completed {
  color: var(--accent-green);
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.15);
}

.checklist-item.current {
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.08);
  border-color: rgba(124, 58, 237, 0.25);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.15);
}

.check-box {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.checklist-item.completed .check-box {
  border-color: var(--accent-green);
  background: var(--accent-green);
  color: #fff;
}

.checklist-item.current .check-box {
  border-color: #7c3aed;
  background: #7c3aed;
  color: #fff;
}

.cover-characters {
  display: flex;
  gap: 32px;
  margin-top: 36px;
  align-items: center;
}

.cover-characters img {
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius);
  box-shadow: none;
}

@media (max-width: 600px) {
  .cover-page h1 {
    font-size: 2rem;
  }

  .cover-page .subtitle {
    font-size: 1rem;
  }
}

/* ===== CHAPTER TRANSITIONS ===== */
.chapter.active {
  animation: chapterIn 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes chapterIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== QUIZ ANIMATIONS ===== */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-6px);
  }

  40% {
    transform: translateX(6px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }
}

@keyframes pulse-glow {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  }

  50% {
    box-shadow: 0 0 20px 4px rgba(16, 185, 129, 0.25);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.quiz-option {
  transition: var(--transition);
}

.quiz-question.answered .quiz-option {
  pointer-events: none;
  cursor: default;
}

.quiz-question.answered .quiz-option:not(.correct):not(.wrong) {
  opacity: 0.45;
}

/* ===== SCROLL PROGRESS (within chapter) ===== */
#scrollProgress {
  position: fixed;
  top: 3px;
  left: 300px;
  right: 0;
  height: 2px;
  background: var(--accent-teal);
  z-index: 51;
  transition: width 0.1s linear;
  width: 0%;
}

@media (max-width: 900px) {
  #scrollProgress {
    left: 0;
  }
}

/* ===== ENHANCED HOVER EFFECTS ===== */
.concept-card {
  transition: transform var(--transition), box-shadow var(--transition);
}

.concept-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.code-block {
  transition: box-shadow var(--transition);
}

.code-block:hover {
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.15);
}

.dialogue {
  transition: transform var(--transition), background var(--transition);
}

.dialogue:hover {
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.07);
}

.exercise-box {
  transition: transform var(--transition);
}

.exercise-box:hover {
  transform: translateY(-2px);
}

.compare-table {
  transition: box-shadow var(--transition);
}

.compare-table:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

/* ===== TOOLTIP STYLE FOR NAV ===== */
.nav-item {
  transition: var(--transition), transform 0.15s ease;
}

.nav-item:active {
  transform: scale(0.97);
}

/* ===== START BUTTON PULSE ===== */
.cover-page .start-btn {
  animation: btnPulse 2.5s ease-in-out infinite;
}

@keyframes btnPulse {

  0%,
  100% {
    box-shadow: 0 8px 30px rgba(124, 58, 237, 0.4);
  }

  50% {
    box-shadow: 0 8px 50px rgba(124, 58, 237, 0.65), 0 0 20px rgba(6, 182, 212, 0.3);
  }
}

.cover-page .start-btn:hover {
  animation: none;
}

/* ===== AUTHOR BADGE (Cover Page) ===== */
.author-badge {
  position: relative;
  margin: 20px 0 28px;
  padding: 3px;
  border-radius: 16px;
  background: linear-gradient(135deg, #7c3aed, #06b6d4, #f59e0b, #7c3aed);
  background-size: 300% 300%;
  animation: gradientShift 6s ease infinite;
}

@keyframes gradientShift {

  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

.author-badge-inner {
  background: var(--bg-secondary);
  border-radius: 14px;
  padding: 16px 32px;
  text-align: center;
}

.author-badge-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.author-badge-name {
  display: block;
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.author-badge-links {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.author-badge-links a {
  color: var(--accent-teal);
  text-decoration: none;
  font-size: 0.8rem;
  transition: var(--transition);
}

.author-badge-links a:hover {
  color: var(--accent-purple-light);
}

.cover-footer {
  margin-top: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 300px;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
  z-index: 150;
  transition: left var(--transition);
}

.progress-fill {
  height: 100%;
  background: var(--gradient-hero);
  width: 0%;
  transition: width 0.2s ease;
}

/* ===== SCROLL PROGRESS (within chapter) ===== */
#scrollProgress {
  position: fixed;
  top: 3px;
  left: 300px;
  right: 0;
  height: 2px;
  background: var(--accent-primary);
  z-index: 151;
  transition: width 0.1s linear;
  width: 0%;
}

@media (max-width: 900px) {
  .progress-bar {
    left: 0;
  }

  #scrollProgress {
    left: 0;
  }
}

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-footer a {
  color: var(--accent-teal);
  text-decoration: none;
  font-size: 0.72rem;
}

.sidebar-footer a:hover {
  color: var(--accent-purple-light);
}

/* ===== NAV DIVIDER ===== */
.nav-item.nav-divider {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ===== BOOK PAGES (Dedication, Preface, Next Book) ===== */
.book-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 80px 32px;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* --- Dedication Page --- */
.dedication-page {
  text-align: center;
  min-height: 90vh;
}

.dedication-ornament {
  font-size: 2rem;
  color: var(--accent-amber);
  margin-bottom: 24px;
  animation: sparkle 3s ease-in-out infinite;
}

.dedication-ornament.bottom {
  margin-top: 40px;
  margin-bottom: 0;
}

@keyframes sparkle {

  0%,
  100% {
    opacity: 0.5;
    transform: rotate(0deg);
  }

  50% {
    opacity: 1;
    transform: rotate(180deg);
  }
}

.dedication-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--gradient-warm);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.dedication-divider {
  width: 60px;
  height: 2px;
  margin: 16px auto 40px;
  background: linear-gradient(90deg, transparent, var(--accent-amber), transparent);
}

.dedication-text p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  line-height: 2;
  margin-bottom: 16px;
  max-width: 540px;
}

.dedication-sign {
  margin-top: 24px;
  font-size: 1rem;
  color: var(--accent-purple-light);
  font-weight: 600;
  font-style: normal !important;
}

/* --- Preface Page --- */
.preface-page {
  align-items: flex-start;
  justify-content: flex-start;
}

.preface-title {
  font-family: 'Outfit', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
  align-self: center;
}

.preface-divider {
  width: 60px;
  height: 2px;
  margin: 12px auto 40px;
  background: linear-gradient(90deg, transparent, var(--accent-purple), transparent);
  align-self: center;
}

.preface-body {
  width: 100%;
}

.preface-body p {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 18px;
  line-height: 1.8;
}

.preface-body h3 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 36px 0 16px;
  position: relative;
  padding-left: 20px;
}

.preface-body h3::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 4px;
  height: 24px;
  background: var(--gradient-hero);
  border-radius: 4px;
}

.preface-body ul {
  padding-left: 20px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.preface-body li {
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.preface-drop-cap::first-letter {
  float: left;
  font-size: 3.5rem;
  line-height: 1;
  margin-right: 8px;
  font-weight: 800;
  font-family: 'Outfit', sans-serif;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.preface-features {
  display: grid;
  gap: 16px;
  margin: 20px 0 28px;
}

.preface-feature {
  display: flex;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: var(--transition);
}

.preface-feature:hover {
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.08);
}

.feature-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.preface-feature strong {
  color: var(--text-primary);
  font-size: 0.95rem;
  display: block;
  margin-bottom: 4px;
}

.preface-feature p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.preface-quote {
  margin: 32px 0;
  padding: 24px 32px;
  border-left: 3px solid var(--accent-purple);
  background: rgba(124, 58, 237, 0.06);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.preface-quote blockquote {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.6;
}

.preface-quote cite {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: normal;
}

.preface-signature {
  margin-top: 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 24px;
}

.preface-author-card {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(6, 182, 212, 0.1));
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.preface-author-info strong {
  font-size: 1.05rem;
  color: var(--text-primary);
  display: block;
  margin-bottom: 2px;
}

.preface-author-info span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.preface-author-links {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.preface-author-links a {
  color: var(--accent-teal);
  text-decoration: none;
  font-size: 0.8rem;
  transition: var(--transition);
}

.preface-author-links a:hover {
  color: #fff;
}

.preface-date {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 12px;
}

/* --- Next Book Page --- */
.next-book-page {
  justify-content: flex-start;
  padding-top: 60px;
}

.next-book-badge {
  display: inline-block;
  padding: 6px 20px;
  border-radius: 50px;
  background: var(--gradient-warm);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.next-book-badge.active {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

.next-book-title {
  font-family: 'Outfit', sans-serif;
  font-size: 2rem;
  font-weight: 800;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

.next-book-divider {
  width: 60px;
  height: 2px;
  margin: 16px auto 40px;
  background: linear-gradient(90deg, transparent, var(--accent-teal), transparent);
}

.next-book-card {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(6, 182, 212, 0.08));
  border: 1px solid rgba(124, 58, 237, 0.2);
  padding: 40px;
}

.next-book-label {
  font-size: 0.7rem;
  color: var(--accent-amber);
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 8px;
}

.next-book-name {
  font-family: 'Outfit', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, #f43f5e, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.next-book-tagline {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.next-book-description p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.next-book-projects,
.next-book-tech {
  margin-top: 28px;
}

.next-book-projects h4,
.next-book-tech h4 {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.project-item {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: var(--transition);
}

.project-item:hover {
  transform: translateY(-2px);
  border-color: rgba(124, 58, 237, 0.3);
}

.project-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.project-item strong {
  color: var(--text-primary);
  font-size: 0.85rem;
  display: block;
  margin-bottom: 2px;
}

.project-item p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tech-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tech-tag {
  padding: 6px 14px;
  border-radius: 50px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--accent-teal);
  transition: var(--transition);
}

.tech-tag:hover {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--accent-teal);
}

.next-book-cta {
  width: 100%;
  text-align: center;
  margin-top: 40px;
}

.next-book-cta p {
  color: var(--text-muted);
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.cta-links {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.cta-btn {
  padding: 14px 28px;
  border-radius: 50px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
  font-family: 'Outfit', sans-serif;
}

.cta-btn.primary {
  background: var(--gradient-hero);
  color: #fff;
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.3);
}

.cta-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(124, 58, 237, 0.5);
}

.cta-btn.secondary {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

.cta-btn.secondary:hover {
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

/* --- Book End Credits --- */
.book-end-credits {
  width: 100%;
  margin-top: 60px;
  text-align: center;
}

.credits-divider {
  width: 100px;
  height: 1px;
  margin: 0 auto 32px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.book-end-credits h3 {
  font-size: 1.2rem;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.author-bio-card {
  display: inline-block;
  padding: 24px 32px;
  border-radius: var(--radius);
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
  max-width: 560px;
}

.author-bio-card h4 {
  color: var(--text-primary);
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.author-bio-card p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 12px;
  line-height: 1.7;
}

.author-contact-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.author-contact-grid a {
  color: var(--accent-teal);
  text-decoration: none;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}

.author-contact-grid a:hover {
  color: #fff;
}

.copyright-notice {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.8;
}

.copyright-notice strong {
  color: var(--text-secondary);
}

/* ===== Narrow-phone safety net (tables / code / mermaid scroll) ===== */
@media (max-width: 720px) {
  .chapter-body table {
    display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap; max-width: 100%;
  }
  .chapter-body pre,
  .chapter-body code,
  .chapter-body .mermaid {
    max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .chapter-body pre { font-size: 0.78rem; }
  .chapter-body img { max-width: 100%; height: auto; }
  .chapter-body iframe { max-width: 100%; }
}

/* ===== PDF / PRINT STYLES ===== */
@media print {

  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #0a0e27 !important;
  }

  .sidebar,
  .nav-toggle,
  .nav-overlay,
  #particles-canvas,
  .progress-bar,
  #scrollProgress,
  .chapter-nav,
  .start-btn,
  .code-copy {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .chapter {
    display: block !important;
    page-break-after: always;
  }

  .chapter:last-child {
    page-break-after: avoid;
  }

  .chapter-hero {
    page-break-inside: avoid;
  }

  .chapter-body h2 {
    page-break-after: avoid;
  }

  .code-block,
  .flowchart-container,
  .quiz-section,
  .dialogue,
  .concept-card,
  .exercise-box,
  .compare-table {
    page-break-inside: avoid;
  }

  .book-page {
    page-break-after: always;
  }

  .reveal {
    opacity: 1 !important;
    transform: none !important;
  }

  a {
    color: var(--accent-teal) !important;
  }
}