/* ============================================
   BÍ KÍP TỔNG ÔN DSA — Custom Styles
   ============================================ */

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

/* ---- CSS Variables ---- */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.08);
  --accent-1: #818cf8;
  --accent-2: #6366f1;
  --accent-3: #a78bfa;
  --accent-4: #22d3ee;
  --accent-5: #34d399;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-2: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  --gradient-3: linear-gradient(135deg, #22d3ee 0%, #818cf8 100%);
  --gradient-hero: linear-gradient(180deg, #0f172a 0%, #0a0e1a 100%);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
  --sidebar-width: 320px;
  --bar-default: #6366f1;
  --bar-comparing: #fbbf24;
  --bar-swapping: #ef4444;
  --bar-sorted: #34d399;
  --bar-pivot: #f472b6;
  --bar-selected: #22d3ee;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ---- Custom Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.5);
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--glass-border);
  overflow-y: auto;
  z-index: 50;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 1.25rem;
  font-weight: 800;
  background: var(--gradient-2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.sidebar-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.25rem;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
  overflow-y: auto;
}

.nav-chapter {
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}

.nav-chapter-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  text-align: left;
}

.nav-chapter-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--text-primary);
}

.nav-chapter-btn.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-1);
}

.nav-chapter-icon {
  width: 28px;
  height: 28px;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--gradient-1);
  color: white;
}

.nav-chapter-arrow {
  margin-left: auto;
  transition: transform 0.3s ease;
  font-size: 0.65rem;
  opacity: 0.5;
}

.nav-chapter-btn.active .nav-chapter-arrow {
  transform: rotate(90deg);
  opacity: 1;
}

.nav-sections {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  padding-left: 1rem;
}

.nav-sections.open {
  max-height: 600px;
}

.nav-section-link {
  display: block;
  padding: 0.375rem 0.75rem 0.375rem 1.75rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.2s ease;
  margin: 1px 0;
}

.nav-section-link:hover {
  color: var(--text-secondary);
  border-left-color: rgba(99, 102, 241, 0.3);
}

.nav-section-link.active {
  color: var(--accent-1);
  border-left-color: var(--accent-1);
  background: rgba(99, 102, 241, 0.05);
}

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  position: relative;
}

/* ---- Hero Section ---- */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
  background: var(--gradient-hero);
}

.hero::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,0.15) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: pulse-glow 4s ease-in-out infinite;
}

.hero::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139,92,246,0.1) 0%, transparent 70%);
  top: 30%;
  right: 10%;
  animation: pulse-glow 5s ease-in-out infinite reverse;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--accent-1);
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 2rem;
  position: relative;
  z-index: 1;
  animation: fadeInDown 0.6s ease-out;
}

.hero-title {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1;
  animation: fadeInUp 0.8s ease-out;
}

.hero-title .gradient-text {
  background: var(--gradient-2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  line-height: 1.8;
  position: relative;
  z-index: 1;
  animation: fadeInUp 1s ease-out;
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2.5rem;
  padding: 0.875rem 2rem;
  background: var(--gradient-2);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 0.75rem;
  text-decoration: none;
  position: relative;
  z-index: 1;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
  animation: fadeInUp 1.2s ease-out;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.hero-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
}

/* ---- Chapter Sections ---- */
.chapter-container {
  padding: 0 2rem 4rem;
  max-width: 900px;
  margin: 0 auto;
}

.chapter-header {
  padding: 4rem 0 2rem;
  position: relative;
}

.chapter-number {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent-1);
  margin-bottom: 0.5rem;
}

.chapter-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.chapter-title .gradient-text {
  background: var(--gradient-2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chapter-intro {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.8;
  border-left: 3px solid var(--accent-2);
  padding-left: 1.25rem;
}

/* ---- Section Styling ---- */
.section {
  margin-bottom: 3rem;
  scroll-margin-top: 2rem;
}

.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-title .icon {
  width: 32px;
  height: 32px;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.section-content p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.section-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.section-content h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.75rem 0 0.75rem;
  color: var(--text-primary);
}

.section-content ul,
.section-content ol {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  padding-left: 1.5rem;
  font-size: 0.95rem;
}

.section-content li {
  margin-bottom: 0.375rem;
}

/* ---- Glass Cards ---- */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: var(--shadow-glow);
}

.glass-card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---- Code Blocks ---- */
.code-block {
  position: relative;
  margin: 1.25rem 0;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--glass-border);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  background: rgba(30, 41, 59, 0.8);
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.code-block-header .lang-tag {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  color: var(--accent-4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.375rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.copy-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.copy-btn.copied {
  color: var(--accent-5);
  border-color: var(--accent-5);
}

.code-block pre {
  margin: 0;
  padding: 1.25rem;
  background: rgba(15, 23, 42, 0.9) !important;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.7;
}

.code-block code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
}

/* Inline code */
.section-content code:not([class*="language-"]) {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-3);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
}

/* ---- Tables ---- */
.table-container {
  overflow-x: auto;
  margin: 1.25rem 0;
  border-radius: 0.75rem;
  border: 1px solid var(--glass-border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table thead {
  background: rgba(99, 102, 241, 0.1);
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--accent-1);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--glass-border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.data-table tbody tr {
  transition: background 0.2s ease;
}

.data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.05);
}

.data-table .highlight {
  color: var(--accent-5);
  font-weight: 600;
}

.data-table .warn {
  color: var(--bar-comparing);
  font-weight: 600;
}

.data-table .danger {
  color: var(--bar-swapping);
  font-weight: 600;
}

/* ---- Algorithm Visualizer ---- */
.visualizer {
  margin: 1.5rem 0;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: rgba(15, 23, 42, 0.6);
}

.visualizer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(30, 41, 59, 0.5);
  border-bottom: 1px solid var(--glass-border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.visualizer-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-1);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.visualizer-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.viz-btn {
  padding: 0.375rem 0.75rem;
  border-radius: 0.375rem;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--accent-1);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.viz-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-1);
}

.viz-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.viz-btn.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: white;
}

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

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.speed-control input[type="range"] {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(99, 102, 241, 0.3);
  border-radius: 2px;
  outline: none;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-1);
  cursor: pointer;
}

.visualizer-canvas {
  padding: 2rem 1.5rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  min-height: 220px;
  position: relative;
}

.viz-bar {
  flex: 1;
  max-width: 50px;
  min-width: 12px;
  background: var(--bar-default);
  border-radius: 3px 3px 0 0;
  transition: height 0.3s ease, background 0.3s ease, transform 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.viz-bar .bar-value {
  position: absolute;
  top: -20px;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.viz-bar.comparing {
  background: var(--bar-comparing);
  transform: scaleY(1.02);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.viz-bar.swapping {
  background: var(--bar-swapping);
  transform: scaleY(1.04);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.viz-bar.sorted {
  background: var(--bar-sorted);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.3);
}

.viz-bar.pivot {
  background: var(--bar-pivot);
  box-shadow: 0 0 10px rgba(244, 114, 182, 0.4);
}

.viz-bar.selected {
  background: var(--bar-selected);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.4);
}

.visualizer-status {
  padding: 0.75rem 1rem;
  background: rgba(30, 41, 59, 0.3);
  border-top: 1px solid var(--glass-border);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.visualizer-status .step-text {
  color: var(--accent-4);
  font-weight: 500;
}

/* Visualizer Legend */
.viz-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  flex-wrap: wrap;
}

.viz-legend-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.viz-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ---- Linked List Visualizer ---- */
.ll-visualizer {
  overflow-x: auto;
  padding: 2rem 1rem;
}

.ll-container {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
}

.ll-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.ll-node-box {
  display: flex;
  border: 2px solid var(--accent-2);
  border-radius: 0.5rem;
  overflow: hidden;
  background: rgba(99, 102, 241, 0.1);
  transition: all 0.3s ease;
}

.ll-node-box.highlight {
  border-color: var(--accent-4);
  background: rgba(34, 211, 238, 0.1);
  box-shadow: 0 0 15px rgba(34, 211, 238, 0.2);
}

.ll-node-box.slow {
  border-color: var(--accent-5);
  background: rgba(52, 211, 153, 0.1);
  box-shadow: 0 0 15px rgba(52, 211, 153, 0.2);
}

.ll-node-box.fast {
  border-color: var(--bar-swapping);
  background: rgba(239, 68, 68, 0.1);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

.ll-data {
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  min-width: 36px;
  text-align: center;
}

.ll-next {
  padding: 0.5rem 0.5rem;
  border-left: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: 0.65rem;
  display: flex;
  align-items: center;
}

.ll-arrow {
  width: 35px;
  height: 2px;
  background: var(--accent-2);
  position: relative;
  margin: 0 -1px;
  align-self: center;
}

.ll-arrow::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-left: 7px solid var(--accent-2);
}

.ll-null {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--bar-swapping);
  background: rgba(239, 68, 68, 0.1);
  border: 2px dashed rgba(239, 68, 68, 0.3);
  border-radius: 0.375rem;
  align-self: center;
}

.ll-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---- Complexity Chart ---- */
.complexity-chart {
  position: relative;
  width: 100%;
  height: 250px;
  border-left: 2px solid var(--glass-border);
  border-bottom: 2px solid var(--glass-border);
  margin: 1.5rem 0;
  padding: 1rem;
}

.complexity-chart .axis-label {
  position: absolute;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.complexity-chart .x-label {
  bottom: -25px;
  right: 0;
}

.complexity-chart .y-label {
  top: -10px;
  left: -5px;
}

/* ---- Info Box (Tip/Warning/Note) ---- */
.info-box {
  padding: 1rem 1.25rem;
  border-radius: 0.625rem;
  margin: 1.25rem 0;
  border-left: 4px solid;
  font-size: 0.9rem;
}

.info-box.tip {
  background: rgba(52, 211, 153, 0.05);
  border-color: var(--accent-5);
  color: var(--accent-5);
}

.info-box.warning {
  background: rgba(251, 191, 36, 0.05);
  border-color: var(--bar-comparing);
  color: var(--bar-comparing);
}

.info-box.note {
  background: rgba(99, 102, 241, 0.05);
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.info-box.danger {
  background: rgba(239, 68, 68, 0.05);
  border-color: var(--bar-swapping);
  color: var(--bar-swapping);
}

.info-box-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.info-box p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 0;
}

/* ---- Keyword / Tag Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-purple {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-3);
  border: 1px solid rgba(139, 92, 246, 0.2);
}

.badge-blue {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-1);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.badge-green {
  background: rgba(52, 211, 153, 0.15);
  color: var(--accent-5);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.badge-yellow {
  background: rgba(251, 191, 36, 0.15);
  color: var(--bar-comparing);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--bar-swapping);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-cyan {
  background: rgba(34, 211, 238, 0.15);
  color: var(--accent-4);
  border: 1px solid rgba(34, 211, 238, 0.2);
}

/* ---- Comparison Blocks ---- */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
}

.compare-item {
  padding: 1.25rem;
  border-radius: 0.75rem;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
}

.compare-item-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---- Step Indicator ---- */
.step-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  counter-reset: step-counter;
}

.step-list li {
  counter-increment: step-counter;
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.step-list li::before {
  content: counter(step-counter);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-1);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---- Problem Card ---- */
.problem-card {
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  overflow: hidden;
  margin: 1.5rem 0;
  background: var(--bg-card);
  transition: all 0.3s ease;
}

.problem-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: var(--shadow-glow);
}

.problem-card-header {
  padding: 1rem 1.25rem;
  background: rgba(99, 102, 241, 0.08);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.problem-card-title {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.problem-card-body {
  padding: 1.25rem;
  display: none;
}

.problem-card-body.open {
  display: block;
  animation: fadeIn 0.3s ease;
}

.problem-card-toggle {
  font-size: 0.75rem;
  transition: transform 0.3s ease;
}

/* ---- Mobile Hamburger Menu ---- */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 1.2rem;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes borderGlow {
  0%, 100% { border-color: rgba(99, 102, 241, 0.2); }
  50% { border-color: rgba(99, 102, 241, 0.5); }
}

.animate-fade-in {
  animation: fadeIn 0.5s ease-out;
}

.animate-fade-in-up {
  animation: fadeInUp 0.5s ease-out;
}

.animate-slide-in {
  animation: slideInLeft 0.5s ease-out;
}

/* Section reveal animation */
.section[data-revealed="false"] {
  opacity: 0;
  transform: translateY(20px);
}

.section[data-revealed="true"] {
  animation: fadeInUp 0.5s ease-out forwards;
}

/* ---- Counting Sort specific ---- */
.freq-array {
  display: flex;
  gap: 2px;
  margin: 1rem 0;
  justify-content: center;
}

.freq-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.freq-cell .index {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.freq-cell .value {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
  border-radius: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-card);
  transition: all 0.3s ease;
}

.freq-cell .value.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-1);
  color: var(--accent-1);
}

/* ---- Divide & Conquer Tree ---- */
.dc-tree {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
}

.dc-level {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.dc-node {
  display: flex;
  gap: 2px;
  padding: 0.375rem;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 0.375rem;
}

.dc-node .dc-val {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.15);
  border-radius: 0.25rem;
  color: var(--accent-1);
}

.dc-arrow-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
}

/* ---- Footer ---- */
.book-footer {
  text-align: center;
  padding: 3rem 2rem;
  border-top: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .mobile-menu-btn {
    display: flex;
  }
  .mobile-overlay.active {
    display: block;
  }
  .compare-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .chapter-container {
    padding: 0 1rem 3rem;
  }
  .hero-title {
    font-size: 2rem;
  }
  .visualizer-controls {
    width: 100%;
    justify-content: center;
  }
}

/* ---- Print ---- */
@media print {
  .sidebar, .mobile-menu-btn, .mobile-overlay {
    display: none !important;
  }
  .main-content {
    margin-left: 0;
  }
  body {
    background: white;
    color: black;
  }
}
