/* ============================================================
   System Design Illustrated — style.css  v3.0
   Dark-first editorial redesign. Inspired by the Gradient Descent
   interactive essay: black backgrounds, glow, Playfair Display.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@300;400;500&display=swap');

/* ── CSS variables (dark = default) ─────────────────────────── */
:root {
  /* Background layers */
  --bg:        #05030e;
  --surface:   #130f26;
  --surface-2: #1b1638;
  --surface-3: #22194a;

  /* Brand */
  --primary:      #7C3AED;
  --primary-soft: #A78BFA;
  --primary-faint:rgba(124, 58, 237, 0.12);
  --secondary:    #F59E0B;
  --accent:       #10B981;
  --info:         #06B6D4;

  /* Text */
  --text:      #EDE9FE;
  --text-soft: #9490B4;
  --text-muted:#5C577A;

  /* Borders / shadows */
  --border:    rgba(124, 58, 237, 0.32);
  --border-hi: rgba(167, 139, 250, 0.55);
  --shadow-sm: 0 2px 10px rgba(0,0,0,0.55);
  --shadow-md: 0 8px 28px rgba(0,0,0,0.65);
  --shadow-lg: 0 20px 56px rgba(124, 58, 237, 0.28);

  /* Typography */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-head:    'Playfair Display', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-code:    'JetBrains Mono', 'Fira Code', monospace;

  /* Shape */
  --radius:    8px;
  --radius-sm: 5px;
  --radius-lg: 14px;

  /* Motion */
  --transition: 0.3s cubic-bezier(0.22, 1, 0.36, 1);

  /* Topic palette */
  --t1: #7C3AED; --t2:  #EC4899; --t3:  #F59E0B;
  --t4: #10B981; --t5:  #3B82F6; --t6:  #EF4444;
  --t7: #8B5CF6; --t8:  #F97316; --t9:  #06B6D4;
  --t10:#22C55E; --t11: #EC4899; --t12: #6366F1;
}

/* ── Light theme override ──────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f5f3ff;
  --surface:   #ffffff;
  --surface-2: #f0ecff;
  --surface-3: #e8e3fa;
  --border:    rgba(124, 58, 237, 0.18);
  --border-hi: rgba(124, 58, 237, 0.4);
  --text:      #1a1535;
  --text-soft: #4a4668;
  --text-muted:#8884a0;
  --shadow-sm: 0 2px 8px rgba(33,29,53,0.07);
  --shadow-md: 0 8px 24px rgba(33,29,53,0.11);
  --shadow-lg: 0 20px 48px rgba(124,58,237,0.16);
  --primary-faint: rgba(124,58,237,0.08);
}

/* ── Reset ──────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Background lives on <html> so z-index:-1 aurora/canvas paint between
   the html background and body content (step 2 vs step 3 in paint order) */
html {
  scroll-behavior: smooth;
  background: var(--bg);
  transition: background 0.4s ease;
}
body {
  font-family: var(--font-body);
  background: transparent; /* html provides the background */
  color: var(--text);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  transition: color 0.4s ease;
  overflow-x: hidden;
}
h1,h2,h3,h4 { font-family: var(--font-head); line-height: 1.2; }
a { color: var(--primary-soft); text-decoration: none; }
img,svg { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--primary); color: #fff; }

/* ── Reading progress bar ─────────────────────────────────── */
.reading-progress {
  position: fixed; top: 0; left: 0;
  height: 2px; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  z-index: 1001;
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 14px var(--primary), 0 0 28px rgba(124,58,237,0.4);
  transition: width 80ms linear;
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 1000;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1180px; margin: 0 auto;
  padding: 0.8rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.logo {
  font-family: var(--font-head); font-weight: 700; font-size: 1.08rem;
  color: var(--text);
  display: flex; align-items: center; gap: 0.45rem; white-space: nowrap;
}
.logo .bolt { animation: glow 2.4s ease-in-out infinite; display: inline-block; }
.nav-links { display: flex; align-items: center; gap: 1.4rem; }
.nav-links a {
  color: var(--text-soft); font-weight: 500; font-size: 0.93rem;
  position: relative; transition: color var(--transition);
  font-family: var(--font-code); font-size: 0.82rem; letter-spacing: 0.04em;
}
.nav-links a:hover { color: var(--primary-soft); }
.nav-links a::after {
  content: ''; position: absolute; left: 0; bottom: -3px;
  width: 0; height: 1px; background: var(--primary-soft);
  transition: width var(--transition);
}
.nav-links a:hover::after { width: 100%; }
.theme-toggle {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 50%; width: 36px; height: 36px;
  cursor: pointer; display: grid; place-items: center;
  transition: transform var(--transition), box-shadow var(--transition);
}
.theme-toggle:hover {
  transform: rotate(22deg) scale(1.1);
  box-shadow: 0 0 14px var(--primary);
}
.icon-sun, .icon-moon { color: var(--text-soft); }

/* ── Hero ─────────────────────────────────────────────────── */
.hero {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 0;
  background: radial-gradient(ellipse 800px 500px at 20% 50%, rgba(124,58,237,0.18) 0%, transparent 65%), var(--bg);
  padding-top: 5rem; /* space for fixed navbar */
}
.hero-svg { display: none; }

/* Left text column */
.hero-inner {
  position: relative; z-index: 2;
  padding: 4rem 2rem 4rem clamp(1.5rem, 5vw, 5rem);
  text-align: left;
  max-width: none;
  margin: 0;
}

/* Right 3D panel — canvas lives here */
.hero-3d-panel {
  position: relative;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  z-index: 1;
}
.system-3d {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important; height: 100% !important;
  pointer-events: auto !important;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,0.7) 14%, black 30%);
  mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,0.7) 14%, black 30%);
}

/* Orbs stay as decorative bg in left column */
.hero-orb, .hero-grid { z-index: 0; }

/* Mobile: single column */
@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    padding-top: 5rem;
    background: radial-gradient(ellipse 600px 400px at 50% 20%, rgba(124,58,237,0.18) 0%, transparent 65%), var(--bg);
  }
  .hero-inner {
    padding: 3rem 1.5rem 2rem;
    text-align: center;
  }
  .hero h1 { font-size: clamp(2rem, 9vw, 3.2rem); }
  .hero-ctas { justify-content: center; }
  .hero-stats { justify-content: center; }
  .hero-3d-panel {
    height: 55vw; min-height: 280px; max-height: 420px;
  }
  .system-3d {
    -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
    opacity: 0.7;
  }
}
.hero-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: rgba(124,58,237,0.14); border: 1px solid rgba(124,58,237,0.35);
  border-radius: 999px; padding: 0.32rem 1rem;
  font-family: var(--font-code); font-size: 0.76rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--primary-soft);
  animation: fadeUp 0.7s both;
}
[data-theme="light"] .hero-badge {
  background: rgba(124,58,237,0.08) !important;
  border-color: rgba(124,58,237,0.25) !important;
  color: var(--primary) !important;
}
.hero h1 {
  font-size: clamp(2.6rem, 6vw, 4.4rem);
  font-weight: 700; letter-spacing: -0.025em;
  margin: 1.1rem 0 1rem;
  color: #fff; line-height: 1.08;
  animation: fadeUp 0.7s 0.1s both;
}
[data-theme="light"] .hero h1 { color: var(--text); }
.hero h1 .grad {
  background: linear-gradient(110deg, var(--primary-soft), var(--secondary) 60%, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.lead {
  font-size: 1.13rem; color: rgba(237,233,254,0.7); max-width: 580px;
  margin: 0 auto 2.4rem; animation: fadeUp 0.7s 0.2s both; line-height: 1.7;
}
[data-theme="light"] .hero p.lead { color: var(--text-soft); }
.hero-ctas {
  display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap;
  animation: fadeUp 0.7s 0.3s both;
}
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-code); font-weight: 500; font-size: 0.88rem;
  letter-spacing: 0.04em; padding: 0.82rem 1.6rem; border-radius: 5px;
  border: none; cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 0 0 1px rgba(124,58,237,0.4), 0 8px 24px rgba(124,58,237,0.35);
}
.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px rgba(167,139,250,0.6), 0 14px 32px rgba(124,58,237,0.5);
  background: #8B46FF;
}
.btn-ghost {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { transform: translateY(-3px); border-color: var(--primary-soft); box-shadow: 0 0 14px rgba(124,58,237,0.2); }
.hero-stats {
  display: flex; gap: 3rem; justify-content: center; flex-wrap: wrap;
  margin-top: 3.4rem; animation: fadeUp 0.7s 0.45s both;
}
.stat { text-align: center; }
.stat .num {
  font-family: var(--font-head); font-size: 2rem; font-weight: 700;
  background: linear-gradient(120deg, var(--primary-soft), var(--secondary));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  display: block;
}
.stat .lbl { font-family: var(--font-code); font-size: 0.76rem; color: var(--text-muted); letter-spacing: 0.2em; text-transform: uppercase; }

/* Hero scroll cue */
.hero-scroll-cue {
  position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 3;
  pointer-events: none;
}
.hero-scroll-cue .sc-text {
  font-family: var(--font-code); font-size: 10px; letter-spacing: 0.3em;
  text-transform: uppercase; color: rgba(167,139,250,0.45);
}
.hero-scroll-cue .sc-line {
  width: 1px; height: 44px;
  background: linear-gradient(180deg, rgba(167,139,250,0.9), transparent);
  animation: scrollPulse 2.2s ease-in-out infinite; transform-origin: top center;
}

/* ── Sections ─────────────────────────────────────────────── */
.section {
  max-width: 1180px; margin: 0 auto; padding: 5rem 1.5rem;
}
.section-title {
  text-align: center;
  font-size: clamp(1.9rem, 3.5vw, 2.8rem);
  font-weight: 700; margin-bottom: 0.6rem;
  position: relative; display: inline-block;
}
/* Centered glowing underline on section titles */
.section > .section-title::after,
#topics > .section-title::after {
  content: '';
  display: block; width: 48px; height: 2px; margin: 0.55rem auto 0;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 2px;
  box-shadow: 0 0 10px var(--primary);
}
.section-sub {
  text-align: center; color: var(--text-soft);
  max-width: 540px; margin: 0 auto 3.2rem;
  font-size: 1.02rem;
}

/* ── Topic cards grid ─────────────────────────────────────── */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.4rem;
}
.topic-card {
  position: relative; display: block;
  background: linear-gradient(145deg, var(--surface) 0%, color-mix(in srgb, var(--card-color, var(--primary)) 5%, var(--surface)) 100%);
  border: 1px solid rgba(124, 58, 237, 0.32);
  border-radius: var(--radius); padding: 1.65rem 1.6rem 1.5rem;
  color: var(--text); overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  --card-color: var(--primary);
}
.topic-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  height: 3px; width: 0;
  background: var(--card-color, var(--primary));
  transition: width 0.5s cubic-bezier(0.22,1,0.36,1);
}
.topic-card:hover {
  transform: translateY(-8px);
  border-color: color-mix(in srgb, var(--card-color,var(--primary)) 40%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--card-color,var(--primary)) 40%, transparent),
    0 20px 50px color-mix(in srgb, var(--card-color,var(--primary)) 22%, transparent),
    0 8px 20px rgba(0,0,0,0.35);
}
.topic-card:hover::before { width: 100%; }
.tc-top {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem;
}
.tc-num {
  font-family: var(--font-code); font-size: 0.76rem;
  color: var(--card-color, var(--primary));
  background: color-mix(in srgb, var(--card-color, var(--primary)) 14%, transparent);
  padding: 0.18rem 0.6rem; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--card-color, var(--primary)) 30%, transparent);
  letter-spacing: 0.08em;
}
.tc-icon {
  font-size: 1.7rem; transition: transform var(--transition), filter var(--transition);
  color: var(--card-color, var(--primary));
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--card-color, var(--primary)) 60%, transparent));
  width: 2.2rem; height: 2.2rem;
}
.topic-card:hover .tc-icon {
  transform: scale(1.2) rotate(-6deg);
  filter: drop-shadow(0 0 10px var(--card-color, var(--primary)));
}
.topic-card h3 { font-size: 1.12rem; font-weight: 600; margin-bottom: 0.5rem; line-height: 1.3; }
.topic-card p { font-size: 0.88rem; color: var(--text-soft); margin-bottom: 1rem; line-height: 1.6; }
.tc-tags { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tag {
  font-size: 0.72rem; font-weight: 500; padding: 0.2rem 0.65rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
  font-family: var(--font-code); letter-spacing: 0.05em;
}
.tag.difficulty {
  color: var(--card-color, var(--primary)); border-color: transparent;
  background: color-mix(in srgb, var(--card-color, var(--primary)) 14%, transparent);
}
.done-badge {
  position: absolute; top: 0.9rem; right: 0.9rem;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 700;
  box-shadow: 0 0 10px rgba(16,185,129,0.5);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Staggered reveals for topic grid */
.topics-grid .reveal:nth-child(1)  { transition-delay: 0.03s; }
.topics-grid .reveal:nth-child(2)  { transition-delay: 0.07s; }
.topics-grid .reveal:nth-child(3)  { transition-delay: 0.11s; }
.topics-grid .reveal:nth-child(4)  { transition-delay: 0.15s; }
.topics-grid .reveal:nth-child(5)  { transition-delay: 0.19s; }
.topics-grid .reveal:nth-child(6)  { transition-delay: 0.23s; }
.topics-grid .reveal:nth-child(7)  { transition-delay: 0.27s; }
.topics-grid .reveal:nth-child(8)  { transition-delay: 0.31s; }
.topics-grid .reveal:nth-child(9)  { transition-delay: 0.35s; }
.topics-grid .reveal:nth-child(10) { transition-delay: 0.39s; }
.topics-grid .reveal:nth-child(11) { transition-delay: 0.43s; }
.topics-grid .reveal:nth-child(12) { transition-delay: 0.47s; }

/* ── About / Archie section ───────────────────────────────── */
.about-grid {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center;
}
.why-list { list-style: none; display: grid; gap: 0.9rem; margin-top: 1.4rem; }
.why-list li {
  display: flex; gap: 0.85rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.9rem 1.1rem;
  transition: transform var(--transition), border-color var(--transition);
}
.why-list li:hover { transform: translateX(6px); border-color: var(--primary-soft); box-shadow: 0 0 12px rgba(124,58,237,0.12); }
.why-list .wl-icon { font-size: 1.2rem; line-height: 1.5; }
.why-list strong { display: block; font-family: var(--font-head); font-size: 0.97rem; }
.why-list span.desc { font-size: 0.86rem; color: var(--text-soft); }

/* ── Archie robot (pure CSS) ──────────────────────────────── */
.archie-stage { display: flex; flex-direction: column; align-items: center; padding: 2rem 0 0.5rem; }
.archie { position: relative; width: 190px; height: 250px; animation: float 3.4s ease-in-out infinite; }
.archie-antenna {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 5px; height: 26px; background: var(--text-soft); border-radius: 3px;
}
.archie-antenna-tip {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 14px; border-radius: 50%; background: var(--secondary);
  animation: antennaBlink 1.6s ease-in-out infinite;
  box-shadow: 0 0 8px var(--secondary);
}
.archie-head {
  position: absolute; top: 22px; left: 50%; transform: translateX(-50%);
  width: 110px; height: 86px;
  background: linear-gradient(150deg, var(--primary), #9F67F8);
  border-radius: 28px;
  box-shadow: inset 0 -8px 14px rgba(0,0,0,0.25), 0 0 20px rgba(124,58,237,0.35);
}
.archie-eye {
  position: absolute; top: 26px;
  width: 22px; height: 22px; background: #fff; border-radius: 50%;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
  overflow: hidden;
}
.archie-eye::after {
  content: ''; position: absolute; top: 5px; left: 5px;
  width: 12px; height: 12px; border-radius: 50%; background: #211D35;
  animation: eyeMove 4s ease-in-out infinite;
}
.archie-eye.left { left: 22px; } .archie-eye.right { right: 22px; }
.archie-mouth {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  width: 44px; height: 4px; background: rgba(255,255,255,0.55);
  border-radius: 999px;
}
.archie-torso {
  position: absolute; top: 115px; left: 50%; transform: translateX(-50%);
  width: 130px; height: 90px;
  background: linear-gradient(160deg, #2E1B6B, #1A0E42);
  border-radius: 20px;
  box-shadow: inset 0 4px 10px rgba(124,58,237,0.18), 0 0 14px rgba(124,58,237,0.2);
}
.archie-screen {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  width: 80px; height: 46px;
  background: #0b0920; border: 1.5px solid var(--primary-soft); border-radius: 7px;
  overflow: hidden; box-shadow: 0 0 8px rgba(124,58,237,0.4);
}
.archie-screen span {
  display: block; font-family: var(--font-code); font-size: 7px;
  color: var(--primary-soft); line-height: 1.8; padding: 4px 5px;
  animation: scroll 5s linear infinite;
}
.archie-arm {
  position: absolute; top: 128px; width: 20px; height: 62px;
  background: linear-gradient(160deg, #2E1B6B, #1A0E42); border-radius: 10px;
}
.archie-arm.left  { left: 24px; transform-origin: top center; animation: waveArm 3.4s ease-in-out infinite; }
.archie-arm.right { right: 24px; }
.archie-leg {
  position: absolute; bottom: 0; width: 26px; height: 45px;
  background: linear-gradient(160deg, #2E1B6B, #1A0E42); border-radius: 10px 10px 12px 12px;
}
.archie-leg.left { left: 66px; } .archie-leg.right { right: 66px; }
.archie-shadow {
  width: 130px; height: 18px; margin-top: 8px;
  background: radial-gradient(ellipse, rgba(124,58,237,0.3) 0%, transparent 70%);
  animation: shadowPulse 3.4s ease-in-out infinite;
}
.archie-caption {
  font-family: var(--font-code); font-size: 0.78rem; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 1rem;
}

/* ── Features section ─────────────────────────────────────── */
.features-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.2rem;
}
.feature-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem 1.4rem;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.feature-card:hover {
  transform: translateY(-5px); border-color: var(--border-hi);
  box-shadow: 0 12px 32px rgba(124,58,237,0.15);
}
.fc-icon { font-size: 1.6rem; margin-bottom: 0.8rem; display: block; }
.feature-card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.4rem; }
.feature-card p { font-size: 0.88rem; color: var(--text-soft); margin: 0; line-height: 1.6; }

/* ── Footer ───────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border); padding: 2rem 1.5rem;
  text-align: center; font-family: var(--font-code);
  font-size: 0.78rem; color: var(--text-muted); letter-spacing: 0.1em;
}
.footer-inner { max-width: 1180px; margin: 0 auto; }

/* ── Topic page header ────────────────────────────────────── */
.topic-header {
  padding: 7.5rem 1.5rem 2.8rem;
  background: radial-gradient(ellipse 800px 300px at 50% 0%, var(--primary-faint) 0%, transparent 75%), var(--bg);
  border-bottom: 1px solid var(--border);
}
.topic-header-inner { max-width: 860px; margin: 0 auto; }
.topic-meta { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-bottom: 1rem; align-items: center; }
.topic-meta .tag {
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.75);
  border-color: rgba(255,255,255,0.18); backdrop-filter: blur(4px);
}
[data-theme="light"] .topic-meta .tag {
  background: rgba(124,58,237,0.08); color: var(--primary);
  border-color: rgba(124,58,237,0.25);
}
.topic-header h1 {
  font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 0.9rem; color: var(--text);
}
.topic-header .topic-lead {
  font-size: 1.08rem; color: var(--text-soft); max-width: 640px; line-height: 1.7;
}

/* ── Topic content body ───────────────────────────────────── */
.topic-body {
  max-width: 860px; margin: 0 auto; padding: 3rem 1.5rem 5rem;
}

/* ── Section blocks (topic pages) ────────────────────────── */
.section-block {
  margin-bottom: 3.6rem;
}
.section-block > h2 {
  font-size: clamp(1.5rem, 3vw, 1.95rem);
  font-weight: 700; margin-bottom: 1.2rem;
  letter-spacing: -0.015em; line-height: 1.15;
  position: relative; padding-left: 1.1rem;
}
.section-block > h2::before {
  content: ''; position: absolute; left: 0; top: 0.15em;
  width: 4px; height: calc(100% - 0.3em);
  background: var(--topic-color, var(--primary));
  border-radius: 2px;
  box-shadow: 0 0 8px var(--topic-color, var(--primary));
}
.section-block > h3 { font-size: 1.18rem; margin: 1.8rem 0 0.7rem; font-weight: 600; }
.section-block p { margin-bottom: 1rem; color: var(--text); line-height: 1.75; }
.section-block ul:not(.key-points), .section-block ol { margin: 0 0 1rem 1.4rem; }
.section-block li { margin-bottom: 0.5rem; color: var(--text); line-height: 1.7; }

/* ── Two-col layout ───────────────────────────────────────── */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; margin: 1.6rem 0;
}

/* ── Diagram boxes ────────────────────────────────────────── */
.diagram-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.8rem 1.4rem 1.1rem;
  margin: 1.8rem 0; overflow-x: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: box-shadow var(--transition), border-color var(--transition);
}
.diagram-box:hover {
  border-color: var(--border-hi);
  box-shadow: 0 8px 32px rgba(124,58,237,0.18), inset 0 1px 0 rgba(255,255,255,0.06);
}
.diagram-box svg { display: block; margin: 0 auto; width: 100%; height: auto; max-width: 740px; }
.diagram-caption {
  text-align: center; font-size: 0.82rem; color: var(--text-muted);
  margin-top: 0.9rem; font-style: italic; font-family: var(--font-code);
  letter-spacing: 0.04em;
}

/* SVG helpers */
.svg-label { font-family: var(--font-body); font-size: 13px; font-weight: 600; fill: var(--text); }
.svg-soft  { font-family: var(--font-body); font-size: 11px; fill: var(--text-soft); }
.svg-mono  { font-family: var(--font-code); font-size: 11px; fill: var(--text-soft); }
.svg-box   { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; }
.svg-box-p { fill: rgba(124,58,237,0.12); stroke: var(--primary); stroke-width: 1.8; }
.svg-line  { stroke: var(--text-soft); stroke-width: 1.8; fill: none; }
.svg-dash  { stroke-dasharray: 7 6; animation: dashMove 1.2s linear infinite; }
.svg-node  { fill: var(--primary); animation: nodePulse 2.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; filter: drop-shadow(0 0 5px var(--primary)); }
.svg-draw  { stroke-dasharray: 320; stroke-dashoffset: 320; animation: drawPath 2.8s ease forwards infinite alternate; }
.svg-node  { filter: drop-shadow(0 0 5px currentColor); }

/* Packets — JS-driven via initDiagramPackets() */
.pkt { transform-box: fill-box; transform-origin: center; }
.pkt-1, .pkt-2 { opacity: 0; }

.grow-bar { transform-box: fill-box; transform-origin: bottom; animation: fillUp 2.2s ease-in-out infinite alternate; }
.seq { opacity: 0; animation: seqIn 0.7s ease forwards; }
.seq-1 { animation-delay: 0.2s; } .seq-2 { animation-delay: 0.9s; }
.seq-3 { animation-delay: 1.6s; } .seq-4 { animation-delay: 2.3s; }
.seq-5 { animation-delay: 3.0s; } .seq-6 { animation-delay: 3.7s; }
.seq-7 { animation-delay: 4.4s; } .seq-8 { animation-delay: 5.1s; }
.blink-slow { animation: antennaBlink 2s ease-in-out infinite; }
.spin-slow  { transform-box: fill-box; transform-origin: center; animation: spin 9s linear infinite; }
.bob        { transform-box: fill-box; transform-origin: center; animation: float 3s ease-in-out infinite; }

/* ── Callouts ─────────────────────────────────────────────── */
.callout {
  display: flex; gap: 1rem; align-items: flex-start;
  border-radius: var(--radius-sm); padding: 1.1rem 1.3rem;
  margin: 1.6rem 0; border: 1px solid;
  font-size: 0.92rem; line-height: 1.7;
  /* Fix: prevent any overflow clipping */
  min-height: 0; width: 100%;
}
.callout > * { min-width: 0; }
.callout p { margin: 0; color: var(--text-soft); line-height: 1.7; }
.callout strong { font-family: var(--font-head); display: block; margin-bottom: 0.25rem; font-size: 0.96rem; color: var(--text); }
.callout .co-icon { font-size: 1.25rem; line-height: 1.5; flex-shrink: 0; margin-top: 0.1rem; }

.callout.info {
  background: color-mix(in srgb, #3B82F6 8%, var(--surface));
  border-color: color-mix(in srgb, #3B82F6 30%, transparent);
}
.callout.tip {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.callout.warn {
  background: color-mix(in srgb, var(--secondary) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--secondary) 35%, transparent);
}
.callout.success {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.callout.archie {
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
  border-left: 3px solid var(--primary);
  box-shadow: 0 0 18px rgba(124,58,237,0.1);
}
.callout.archie .co-icon { animation: float 2.8s ease-in-out infinite; color: var(--primary-soft); }

/* ── Key insight block (new) ──────────────────────────────── */
.key-insight {
  position: relative;
  font-family: var(--font-display); font-style: italic;
  font-size: 1.25rem; line-height: 1.55; color: var(--text);
  padding: 1.8rem 2rem; margin: 2rem 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  max-width: 780px;
}
.key-insight::before {
  content: 'KEY INSIGHT';
  position: absolute; top: -0.55em; left: 1.5rem;
  font-family: var(--font-code); font-style: normal;
  font-size: 0.68rem; letter-spacing: 0.28em;
  background: var(--bg); padding: 0 0.75rem;
  color: var(--topic-color, var(--primary));
}
[data-theme="light"] .key-insight::before { background: var(--bg); }

/* ── Comparison tables ────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; margin: 1.6rem 0;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.compare-table { font-size: 0.88rem; min-width: 540px; background: var(--surface); }
.compare-table th {
  background: var(--topic-color, var(--primary));
  color: #fff; font-family: var(--font-code); font-weight: 500;
  font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase;
  text-align: left; padding: 0.8rem 1rem;
}
.compare-table td {
  padding: 0.72rem 1rem; border-top: 1px solid var(--border);
  vertical-align: top; color: var(--text); line-height: 1.6;
}
.compare-table tbody tr { transition: background var(--transition); }
.compare-table tbody tr:hover { background: var(--surface-2); }
.compare-table td:first-child { font-weight: 600; font-family: var(--font-code); font-size: 0.84rem; }

/* ── Code blocks ──────────────────────────────────────────── */
.code-block {
  background: #060414; color: #ccc8f0;
  font-family: var(--font-code); font-size: 0.84rem; line-height: 1.7;
  border-radius: var(--radius-sm); padding: 1.3rem 1.5rem;
  margin: 1.6rem 0; overflow-x: auto;
  border: 1px solid rgba(124,58,237,0.25);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(167,139,250,0.05);
  position: relative;
}
.code-block::before {
  content: attr(data-lang); position: absolute; top: 0.6rem; right: 1rem;
  font-size: 0.66rem; color: rgba(124,58,237,0.6); text-transform: uppercase; letter-spacing: 0.12em;
}
.code-block .c-k { color: #C084FC; }
.code-block .c-s { color: #6EE7B7; }
.code-block .c-c { color: #4C4878; }
.code-block .c-n { color: #FCD34D; }
[data-theme="light"] .code-block {
  background: #1a1035; color: #d8d4f8;
  border-color: rgba(124,58,237,0.3);
}

/* ── Steps ────────────────────────────────────────────────── */
.steps { display: grid; gap: 1rem; margin: 1.6rem 0; }
.step-item {
  display: flex; gap: 1rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1.1rem 1.3rem;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.step-item:hover {
  transform: translateX(6px);
  border-color: var(--topic-color, var(--primary));
  box-shadow: 0 0 16px rgba(124,58,237,0.12);
}
.step-num {
  /* flex:none prevents the parent's "flex:1 on div" rule from stretching this into an oval */
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--topic-color, var(--primary)); color: #fff;
  font-family: var(--font-code); font-weight: 600; font-size: 0.88rem;
  display: grid; place-items: center; margin-top: 0.1rem;
  box-shadow: 0 0 10px color-mix(in srgb, var(--topic-color, var(--primary)) 50%, transparent);
}
.step-item > div:not(.step-num) { flex: 1; min-width: 0; }
.step-item strong { font-family: var(--font-head); font-size: 1rem; display: block; margin-bottom: 0.25rem; }
.step-item p { margin: 0; font-size: 0.9rem; color: var(--text-soft); line-height: 1.65; }

/* ── Key points ───────────────────────────────────────────── */
.key-points { list-style: none; display: grid; gap: 0.5rem; margin: 1.2rem 0; }
.key-points li {
  padding-left: 1.4rem; position: relative;
  color: var(--text-soft); font-size: 0.94rem; line-height: 1.65;
}
.key-points li::before {
  content: '▸'; position: absolute; left: 0;
  color: var(--topic-color, var(--primary)); font-size: 0.75rem; top: 0.28em;
}

/* ── At-a-glance box ──────────────────────────────────────── */
.at-a-glance {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.6rem 1.8rem; margin: 1.8rem 0;
  box-shadow: 0 0 0 1px var(--border), 0 4px 16px rgba(124,58,237,0.08), inset 0 1px 0 rgba(255,255,255,0.04);
}
.at-a-glance h3 { font-size: 0.9rem; font-family: var(--font-code); letter-spacing: 0.2em; text-transform: uppercase; color: var(--topic-color, var(--primary)); margin-bottom: 1rem; }
.aag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 0.8rem; }
.mini-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.9rem 1rem;
  transition: transform 0.25s var(--transition), box-shadow 0.25s ease;
}
.mini-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(124,58,237,0.14); }
.mini-card .mc-label { font-family: var(--font-code); font-size: 0.7rem; color: var(--text-muted); letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 0.3rem; }
.mini-card .mc-val { font-family: var(--font-code); font-size: 1rem; font-weight: 500; color: var(--topic-color, var(--primary)); }
.mini-card .mc-desc { font-size: 0.8rem; color: var(--text-soft); margin-top: 0.2rem; line-height: 1.5; }

/* ── Q&A accordion ────────────────────────────────────────── */
.qa-block { margin: 1.6rem 0; }
.qa-question {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1rem 1.3rem;
  text-align: left; cursor: pointer; font-family: var(--font-head);
  font-size: 1rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.qa-question:hover { border-color: var(--topic-color, var(--primary)); box-shadow: 0 0 12px rgba(124,58,237,0.1); }
.qa-question.active { border-color: var(--topic-color, var(--primary)); background: var(--primary-faint); }
.qa-chevron { transition: transform 0.35s ease; font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }
.qa-question.active .qa-chevron { transform: rotate(180deg); }
.qa-answer {
  max-height: 0; overflow: hidden; padding: 0 1.3rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 0.93rem; color: var(--text-soft); line-height: 1.75;
  transition: max-height 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), padding 0.45s ease;
}
.qa-answer.open { padding: 1rem 1.3rem 1.2rem; max-height: 600px; }
.qa-answer p { margin: 0 0 0.7rem; }
.qa-answer p:last-child { margin: 0; }
.qa-answer pre { margin: 0.7rem 0 0; }

/* ── Reading links ────────────────────────────────────────── */
.reading-links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 1rem; margin-top: 1.2rem; }
.reading-link-card {
  display: flex; flex-direction: column; gap: 0.3rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1rem 1.1rem;
  text-decoration: none; color: var(--text);
  transition: transform 0.25s var(--transition), box-shadow 0.25s ease, border-color 0.25s ease;
}
.reading-link-card:hover {
  transform: translateY(-3px); border-color: var(--topic-color, var(--primary));
  box-shadow: 0 8px 24px rgba(124,58,237,0.16);
}
.reading-link-title { font-weight: 600; font-size: 0.92rem; line-height: 1.4; }
.reading-link-source {
  font-family: var(--font-code); font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.06em;
}

/* ── Quiz block ───────────────────────────────────────────── */
.quiz-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.8rem; margin: 2rem 0;
}
.quiz-block h3 { font-size: 1.05rem; margin-bottom: 1.2rem; }
.quiz-options { display: grid; gap: 0.6rem; }
.quiz-option {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.9rem 1.1rem;
  text-align: left; cursor: pointer; font-size: 0.92rem; color: var(--text);
  transition: border-color var(--transition), background var(--transition);
  font-family: var(--font-body);
}
.quiz-option:hover { border-color: var(--topic-color, var(--primary)); background: var(--primary-faint); }
.quiz-option.correct { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }
.quiz-option.wrong { border-color: #EF4444; background: color-mix(in srgb, #EF4444 10%, var(--surface)); color: #EF4444; }
.quiz-result { margin-top: 1rem; font-size: 0.9rem; color: var(--text-soft); min-height: 1.5rem; }
.quiz-result.pass { color: var(--accent); }
.quiz-result.fail { color: #F87171; }

/* ── Reveal animation ─────────────────────────────────────── */
.reveal {
  opacity: 0; transform: translateY(44px);
  transition: opacity 0.9s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.reveal.visible { opacity: 1; transform: none; }

/* ── Navigation (topic prev/next) ────────────────────────── */
.topic-nav {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-top: 2rem; margin-top: 1rem;
}
.topic-nav a {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-code); font-size: 0.84rem; letter-spacing: 0.06em;
  color: var(--text-soft); padding: 0.7rem 1.2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: color var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.topic-nav a:hover { color: var(--primary-soft); border-color: var(--primary-soft); box-shadow: 0 0 12px rgba(124,58,237,0.15); }
.topic-nav .nav-prev { justify-content: flex-start; }
.topic-nav .nav-next { justify-content: flex-end; margin-left: auto; }

/* ── Scroll timeline (interview guide) ───────────────────── */
.timeline { display: grid; gap: 0; position: relative; margin: 1.8rem 0; }
.timeline::before {
  content: ''; position: absolute; left: 17px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-item { display: flex; gap: 1.2rem; padding: 1.1rem 0 1.1rem 0; position: relative; }
.tl-dot {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  background: var(--topic-color, var(--primary)); color: #fff;
  display: grid; place-items: center; font-family: var(--font-code);
  font-size: 0.82rem; font-weight: 600; position: relative; z-index: 1;
  box-shadow: 0 0 12px color-mix(in srgb, var(--topic-color, var(--primary)) 60%, transparent);
  margin-top: 0.1rem;
}
.tl-content { flex: 1; min-width: 0; }
.tl-content h4 { font-size: 1.02rem; font-weight: 600; margin-bottom: 0.35rem; }
.tl-content p { font-size: 0.88rem; color: var(--text-soft); margin: 0; line-height: 1.65; }

/* ── Section header badge ─────────────────────────────────── */
.section-badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-code); font-size: 0.72rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--topic-color, var(--primary));
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--topic-color, var(--primary)) 28%, transparent);
  padding: 0.3rem 0.85rem 0.3rem 0.65rem;
  border-radius: 999px; margin-bottom: 0.75rem;
}
.section-badge::before { content: ''; display: block; width: 14px; height: 1px; background: currentColor; }

/* ── Mini progress / estimation table ────────────────────── */
.est-table { font-family: var(--font-code); font-size: 0.82rem; margin: 1.2rem 0; }
.est-table th { background: var(--surface-2); color: var(--text-soft); }

/* ── Animations / keyframes ───────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 4px var(--primary)); }
  50%       { filter: drop-shadow(0 0 10px var(--secondary)); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-7px); }
}
@keyframes antennaBlink {
  0%, 80%, 100% { opacity: 1; transform: translateX(-50%) scale(1); }
  90%           { opacity: 0.4; transform: translateX(-50%) scale(0.8); }
}
@keyframes eyeMove {
  0%,45%   { transform: translate(0,0); }
  50%      { transform: translate(3px,2px); }
  60%,95%  { transform: translate(0,0); }
  98%      { transform: translate(-3px,0); }
  100%     { transform: translate(0,0); }
}
@keyframes waveArm {
  0%,100% { transform: rotate(0deg); }
  25%     { transform: rotate(-22deg); }
  75%     { transform: rotate(18deg); }
}
@keyframes scroll {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-120px); }
}
@keyframes shadowPulse {
  0%,100% { transform: scaleX(1); opacity: 0.5; }
  50%     { transform: scaleX(0.78); opacity: 0.25; }
}
@keyframes popIn {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.18); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes dashMove {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -26; }
}
@keyframes nodePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}
@keyframes drawPath {
  from { stroke-dashoffset: 320; opacity: 0.4; }
  to   { stroke-dashoffset: 0;   opacity: 1;   }
}
@keyframes fillUp {
  from { transform: scaleY(0.2); opacity: 0.5; }
  to   { transform: scaleY(1);   opacity: 1;   }
}
@keyframes seqIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scrollPulse {
  0%, 100% { opacity: 0.3; transform: scaleY(1); }
  50%      { opacity: 1;   transform: scaleY(1.18); }
}
@keyframes gradientShift {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0%   50%; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .about-grid { grid-template-columns: 1fr; }
  .two-col    { grid-template-columns: 1fr; }
  .hero h1    { font-size: clamp(2rem, 8vw, 3rem); }
  .hero-stats { gap: 2rem; }
  .topic-body { padding: 2.4rem 1.2rem 4rem; }
  .topics-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  .hero { padding: 8rem 1.2rem 5rem; }
  .hero h1 { font-size: clamp(1.9rem, 10vw, 2.6rem); }
  .hero-stats { gap: 1.6rem; }
  .stat .num  { font-size: 1.6rem; }
  .section    { padding: 3rem 1.2rem; }
  .topics-grid { grid-template-columns: 1fr; }
  .topic-header { padding: 6rem 1.2rem 2rem; }
  .section-block > h2 { font-size: 1.35rem; }
  .aag-grid { grid-template-columns: 1fr 1fr; }
  .reading-links-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .topic-nav { flex-direction: column; }
  .topic-nav .nav-next { margin-left: 0; }
  .callout { gap: 0.8rem; padding: 0.9rem 1rem; }
  .timeline::before { left: 15px; }
  .tl-dot { width: 32px; height: 32px; }
  .features-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .nav-links { display: none; }
}

/* ── Interactive Demo Components ──────────────────────────── */
.demo-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 2rem 0;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.04);
}
.demo-header {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.75rem 1.2rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.demo-label {
  font-family: var(--font-code); font-size: 0.66rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--primary-soft);
  background: rgba(124,58,237,0.14);
  border: 1px solid rgba(124,58,237,0.3);
  padding: 0.18rem 0.6rem; border-radius: 999px;
}
.demo-title {
  font-family: var(--font-code); font-size: 0.84rem;
  color: var(--text-soft); letter-spacing: 0.03em;
}
.demo-canvas {
  display: block; width: 100%;
  background: rgba(5,3,14,0.96);
  border-bottom: 1px solid var(--border);
  cursor: crosshair;
}
.demo-controls {
  padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.85rem;
}
.demo-ctrl {
  display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap;
}
.ctrl-label {
  font-family: var(--font-code); font-size: 0.78rem;
  color: var(--text-soft); min-width: 140px; letter-spacing: 0.04em;
}
.ctrl-val {
  color: var(--primary-soft); font-weight: 600; margin-left: 0.35rem;
}
.ctrl-slider {
  flex: 1; min-width: 120px; max-width: 280px;
  -webkit-appearance: none; appearance: none;
  height: 3px; border-radius: 99px;
  background: var(--surface-3); outline: none; cursor: pointer;
}
.ctrl-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); cursor: pointer;
  box-shadow: 0 0 6px var(--primary);
}
.ctrl-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); cursor: pointer;
  border: none; box-shadow: 0 0 6px var(--primary);
}
.ctrl-select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.42rem 0.8rem; font-family: var(--font-code);
  font-size: 0.82rem; cursor: pointer; outline: none;
  transition: border-color var(--transition);
}
.ctrl-select:hover, .ctrl-select:focus { border-color: var(--primary-soft); }
.demo-btn {
  font-family: var(--font-code); font-size: 0.8rem; letter-spacing: 0.05em;
  padding: 0.48rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-soft); cursor: pointer;
  transition: border-color var(--transition), color var(--transition), box-shadow var(--transition);
}
.demo-btn:hover { border-color: var(--primary-soft); color: var(--primary-soft); box-shadow: 0 0 10px rgba(124,58,237,0.2); }
.demo-btn.accent { border-color: var(--primary); color: var(--primary-soft); background: rgba(124,58,237,0.1); }
.demo-btn.accent:hover { background: rgba(124,58,237,0.2); box-shadow: 0 0 14px rgba(124,58,237,0.3); }
.demo-btn.red { border-color: rgba(239,68,68,0.4); color: #F87171; }
.demo-btn.red:hover { border-color: #EF4444; box-shadow: 0 0 10px rgba(239,68,68,0.25); }
.demo-btn.muted { opacity: 0.6; }
.demo-btn.muted:hover { opacity: 1; }
.demo-stats {
  display: flex; gap: 1.2rem; flex-wrap: wrap; padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}
.demo-stat { display: flex; flex-direction: column; gap: 0.18rem; }
.ds-label { font-family: var(--font-code); font-size: 0.68rem; color: var(--text-muted); letter-spacing: 0.15em; text-transform: uppercase; }
.ds-val   { font-family: var(--font-code); font-size: 0.94rem; font-weight: 600; }
.ds-val.green  { color: #34D399; }
.ds-val.amber  { color: #FCD34D; }
.ds-val.red    { color: #F87171; }
.ds-val.purple { color: var(--primary-soft); }
/* Theme: light adjustments */
[data-theme="light"] .demo-canvas { background: #0d0b1e; }
[data-theme="light"] .demo-shell  { background: #fff; }
[data-theme="light"] .ctrl-slider { background: #e2dff5; }
/* Interactive demo wrapper in topic pages */
#demo-scale, #demo-lb, #demo-cache, #demo-replication, #demo-ratelimit {
  margin: 2.2rem 0;
}

/* ── Navbar logo ──────────────────────────────────────────── */
.logo-icon {
  flex-shrink: 0; color: var(--primary-soft);
  filter: drop-shadow(0 0 6px rgba(124,58,237,0.5));
}
.logo-text { display: flex; align-items: center; gap: 0.22em; }
.logo-accent { color: var(--primary-soft); }

/* ── Topic header breadcrumb + metadata ──────────────────── */
.breadcrumb {
  font-family: var(--font-code); font-size: 0.72rem; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 0.6rem;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary-soft); }
.topic-num-big {
  font-family: var(--font-code); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--primary-soft);
  background: rgba(124,58,237,0.12);
  border: 1px solid rgba(124,58,237,0.25);
  display: inline-block; padding: 0.25rem 0.75rem;
  border-radius: 999px; margin-bottom: 1rem;
}
.subtitle {
  font-size: 1.08rem; color: var(--text-soft); line-height: 1.7;
  max-width: 66ch; margin-top: 0.75rem;
}

/* ── Cards grid (3-up mini cards) ────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem; margin: 1.2rem 0;
}
.mc-icon {
  font-size: 1.5rem; display: block; margin-bottom: 0.5rem;
  line-height: 1;
}
.mc-icon:empty::before {
  content: '⬡'; font-size: 1.3rem; opacity: 0.35;
}

/* ── Company badges ──────────────────────────────────────── */
.company-badges {
  display: flex; flex-wrap: wrap; gap: 0.55rem;
  margin: 1rem 0 1.4rem;
}
.company-badge {
  font-family: var(--font-code); font-size: 0.73rem; font-weight: 600;
  letter-spacing: 0.07em;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.3rem 0.75rem; border-radius: 999px;
  transition: border-color var(--transition), color var(--transition);
}
.company-badge:hover { border-color: var(--primary-soft); color: var(--primary-soft); }

/* ── Anti-patterns list ──────────────────────────────────── */
.antipatterns {
  display: flex; flex-direction: column; gap: 1rem; margin: 1.2rem 0;
}
.antipattern-item {
  display: flex; align-items: flex-start; gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #EF4444;
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.antipattern-item:hover {
  border-left-color: #F87171;
  box-shadow: 0 4px 16px rgba(239,68,68,0.12);
}
.antipattern-icon {
  flex: none; width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.28);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; line-height: 1;
}
.antipattern-icon:empty::after { content: '✕'; color: #F87171; font-size: 0.85rem; font-weight: 700; }
.antipattern-text h4 { margin: 0 0 0.3rem; font-size: 0.95rem; color: var(--text); }
.antipattern-text p  { margin: 0; font-size: 0.88rem; color: var(--text-soft); line-height: 1.65; }

/* ── Latency bar ─────────────────────────────────────────── */
.latency-bar {
  display: inline-block; height: 10px; border-radius: 5px;
  vertical-align: middle; min-width: 4px;
  transition: width 0.4s ease;
}

/* ── Reading links wrapper ───────────────────────────────── */
.reading-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem; margin-top: 1.2rem;
}
.reading-link-icon {
  font-size: 1.3rem; margin-bottom: 0.3rem; display: block; line-height: 1;
}
.reading-link-icon:empty::before { content: '📖'; }

/* ── Quiz feedback ───────────────────────────────────────── */
.quiz-feedback {
  display: none; margin-top: 1rem; padding: 0.9rem 1.1rem;
  background: rgba(52,211,153,0.08);
  border: 1px solid rgba(52,211,153,0.28);
  border-radius: var(--radius-sm);
  color: #34D399; font-size: 0.9rem; line-height: 1.65;
}
.quiz-feedback.show { display: block; animation: fadeUp 0.35s ease both; }

/* ── Q&A accordion ───────────────────────────────────────── */
.qa-list { display: flex; flex-direction: column; gap: 0.6rem; margin: 1rem 0; }
.qa-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}
.qa-item:hover, .qa-item.open { border-color: var(--primary-soft); }
.qa-question {
  width: 100%; text-align: left;
  padding: 0.9rem 1.1rem;
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 0.96rem; font-weight: 600;
  line-height: 1.45; letter-spacing: 0.01em;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.qa-question::after {
  content: '+'; flex-shrink: 0;
  font-size: 1.25rem; color: var(--primary-soft);
  transition: transform 0.25s ease;
}
.qa-item.open .qa-question::after { transform: rotate(45deg); }
.qa-answer {
  max-height: 0; overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4,0,0.2,1), padding 0.25s ease;
  padding: 0 1.1rem;
}
.qa-item.open .qa-answer {
  max-height: 600px;
  padding: 0.1rem 1.1rem 1rem;
}
.qa-answer p { margin: 0.5rem 0; font-size: 0.9rem; color: var(--text-soft); line-height: 1.7; }

/* ── Bottom nav (topic page prev/next) ───────────────────── */
.bottom-nav {
  display: flex; align-items: stretch; justify-content: space-between;
  gap: 1rem; margin: 3rem 0 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1.8rem;
}
.bottom-nav a {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.9rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none; color: var(--text);
  min-width: 160px; max-width: 280px;
  transition: border-color var(--transition), box-shadow var(--transition), transform 0.2s ease;
  flex-shrink: 0;
}
.bottom-nav a:hover {
  border-color: var(--primary-soft);
  box-shadow: 0 4px 18px rgba(124,58,237,0.18);
  transform: translateY(-2px);
}
.bottom-nav a.next { margin-left: auto; text-align: right; }
.bn-dir {
  font-family: var(--font-code); font-size: 0.7rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--primary-soft); font-weight: 600;
}
.bn-title { font-size: 0.96rem; font-weight: 600; color: var(--text); }

@media (max-width: 600px) {
  .bottom-nav { flex-direction: column; }
  .bottom-nav a { max-width: 100%; }
  .bottom-nav a.next { margin-left: 0; text-align: left; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .reading-links { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   CRYSTAL AESTHETIC  —  shimmer · prism · glass · sparkle
   ═══════════════════════════════════════════════════════════ */

/* ── Crystal keyframes ───────────────────────────────────── */
@keyframes crystalBarGlow {
  0%, 100% { box-shadow: 0 0 8px var(--topic-color, var(--primary)); }
  50%       { box-shadow: 0 0 18px var(--topic-color, var(--primary)),
                          0 0 36px color-mix(in srgb, var(--topic-color, var(--primary)) 35%, transparent); }
}
@keyframes auroraFloat {
  0%   { transform: translate(0%,   0%)   scale(1);    }
  33%  { transform: translate(2.5%, -1.5%) scale(1.05); }
  66%  { transform: translate(-1.5%, 2%)   scale(0.97); }
  100% { transform: translate(0%,   0%)   scale(1);    }
}
@keyframes crystalBadgePulse {
  0%, 100% { box-shadow: 0 0 0   0   transparent; }
  50%       { box-shadow: 0 0 12px 1px color-mix(in srgb, currentColor 22%, transparent); }
}
@keyframes prismReadingBar {
  0%   { background-position: 0%   50%; }
  100% { background-position: 200% 50%; }
}
@keyframes cardShimmer {
  0%   { left: -60%; opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { left: 130%; opacity: 0; }
}

/* ── Aurora background orbs (injected by JS) ────────────── */
.aurora-orb {
  position: fixed; pointer-events: none;
  z-index: -1;   /* paint order step 2: after html bg, before all body content */
  border-radius: 50%;
  filter: blur(90px);
  mix-blend-mode: screen;
  will-change: transform;
  animation: auroraFloat var(--orb-dur, 20s) ease-in-out infinite;
  animation-delay: var(--orb-delay, 0s);
}
[data-theme="light"] .aurora-orb {
  mix-blend-mode: multiply;
  filter: blur(90px) saturate(1.5);
  opacity: 0.35;
}

/* ── Crystal particle canvas ────────────────────────────── */
#crystal-canvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: -1;   /* same layer as orbs — always behind body content */
  mix-blend-mode: screen;
  opacity: 0.6;
}
[data-theme="light"] #crystal-canvas {
  mix-blend-mode: multiply;
  opacity: 0.25;
}

/* ── Reading progress bar — rainbow prism ────────────────── */
.reading-progress {
  background: linear-gradient(90deg,
    var(--primary), #06B6D4, #10B981, #F59E0B, #EC4899, var(--primary));
  background-size: 300% 100%;
  animation: prismReadingBar 4s linear infinite;
  box-shadow: 0 0 14px var(--primary), 0 0 28px rgba(6,182,212,0.25);
}

/* ── Crystal-glow h2 accent bar ──────────────────────────── */
.section-block > h2::before {
  animation: crystalBarGlow 3.5s ease-in-out infinite;
}

/* ── Section badge — crystal pulse ───────────────────────── */
.section-badge {
  animation: crystalBadgePulse 3s ease-in-out infinite;
}

/* ── Topic cards — crystal glass ─────────────────────────── */
/* Shimmer streak lives entirely inside overflow:hidden card */
.topic-card::after {
  content: '';
  position: absolute;
  top: 0; left: -60%;
  width: 30%; height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255,255,255,0.07),
    rgba(167,139,250,0.09),
    rgba(255,255,255,0.04),
    transparent
  );
  transform: skewX(-18deg);
  pointer-events: none;
  opacity: 0;
}
.topic-card:hover::after {
  animation: cardShimmer 0.8s ease forwards;
}
/* Enhanced glow on hover — no animation conflict with transition */
.topic-card:hover {
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--card-color, var(--primary)) 45%, transparent),
    0 20px 50px color-mix(in srgb, var(--card-color, var(--primary)) 22%, transparent),
    0 8px 20px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ── Q&A accordion — subtle glass tint when open ─────────── */
.qa-item.open .qa-question {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 7%, transparent);
}
.qa-item.open .qa-answer {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 3%, transparent);
}
/* For the older accordion pattern in topic pages */
.qa-answer.open {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 4%, var(--surface));
}
.qa-question.active {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 8%, var(--surface)) !important;
}

/* ── Callout boxes — subtle glass ────────────────────────── */
.callout {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ── Diagram boxes — crystal depth on hover ──────────────── */
.diagram-box:hover {
  box-shadow:
    0 12px 48px color-mix(in srgb, var(--primary) 18%, transparent),
    0 0 0 1px var(--border-hi),
    inset 0 1px 0 rgba(255,255,255,0.07);
}

/* ── Feature cards ───────────────────────────────────────── */
.feature-card:hover {
  box-shadow: 0 14px 36px rgba(124,58,237,0.16), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ── Topic header — richer radial aurora ────────────────── */
.topic-header {
  background:
    radial-gradient(ellipse 900px 380px at 50% -5%,
      color-mix(in srgb, var(--topic-color, var(--primary)) 13%, transparent) 0%,
      transparent 70%),
    radial-gradient(ellipse 360px 200px at 82% 55%,
      rgba(6,182,212,0.05) 0%, transparent 70%),
    var(--bg);
}

/* ── Light theme crystal adjustments ────────────────────── */
[data-theme="light"] .diagram-box:hover {
  box-shadow:
    0 12px 40px rgba(124,58,237,0.12),
    0 0 0 1px rgba(124,58,237,0.25),
    inset 0 1px 0 rgba(255,255,255,0.8);
}
[data-theme="light"] .topic-card:hover {
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--card-color, var(--primary)) 35%, transparent),
    0 16px 40px color-mix(in srgb, var(--card-color, var(--primary)) 14%, transparent),
    0 4px 12px rgba(33,29,53,0.1);
}
[data-theme="light"] .section-block > h2::before {
  box-shadow: 0 0 12px color-mix(in srgb, var(--topic-color, var(--primary)) 60%, transparent);
}

/* ── Reduced-motion: disable all animation additions ─────── */
@media (prefers-reduced-motion: reduce) {
  .topic-card:hover::after { animation: none; }
  .aurora-orb              { animation: none; }
  #crystal-canvas          { display: none; }
  .section-block > h2::before { animation: none; }
  .section-badge           { animation: none; }
  .reading-progress {
    animation: none;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    background-size: auto;
  }
}
