/* =============================================================================
   CME 295 · Transformers & LLMs — Learning Site
   Design system + components. Dark-first, with a light theme via [data-theme].
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Brand gradient */
  --grad-1: #6366f1; /* indigo  */
  --grad-2: #8b5cf6; /* violet  */
  --grad-3: #22d3ee; /* cyan    */
  --grad-warm: #f472b6; /* pink accent */
  --cardinal: #b3242b; /* Stanford cardinal */

  /* Dark theme (default) */
  --bg: #060814;
  --bg-2: #0a0e1f;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-solid: #11152a;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f9;
  --text-dim: #aab2c8;
  --text-faint: #6b7488;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  --glow: 0 0 0 1px rgba(139, 92, 246, 0.25), 0 18px 50px -16px rgba(99, 102, 241, 0.45);

  /* Type */
  --font-display: "Sora", "Inter", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;

  /* Layout */
  --maxw: 1180px;
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 28px;
  --nav-h: 68px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="light"] {
  --bg: #f7f8fc;
  --bg-2: #eef1f9;
  --surface: rgba(20, 24, 48, 0.025);
  --surface-2: rgba(20, 24, 48, 0.05);
  --surface-solid: #ffffff;
  --border: rgba(15, 20, 45, 0.1);
  --border-strong: rgba(15, 20, 45, 0.18);
  --text: #0e1430;
  --text-dim: #4a5374;
  --text-faint: #8089a3;
  --shadow: 0 24px 50px -24px rgba(30, 30, 80, 0.25);
  --glow: 0 0 0 1px rgba(139, 92, 246, 0.2), 0 18px 44px -18px rgba(99, 102, 241, 0.3);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }
* { margin: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--nav-h) + 14px); }
html:focus-within { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background 0.5s var(--ease), color 0.3s var(--ease);
}

img,
svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; padding: 0; }

::selection { background: rgba(139, 92, 246, 0.35); color: #fff; }

/* ---------- Ambient background ---------- */
.bg-aurora {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
}
.bg-aurora::before,
.bg-aurora::after {
  content: "";
  position: absolute;
  width: 60vw;
  height: 60vw;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.5;
  will-change: transform;
}
.bg-aurora::before {
  top: -20vw;
  left: -10vw;
  background: radial-gradient(circle, var(--grad-1), transparent 65%);
  animation: drift1 22s ease-in-out infinite alternate;
}
.bg-aurora::after {
  bottom: -25vw;
  right: -10vw;
  background: radial-gradient(circle, var(--grad-3), transparent 65%);
  animation: drift2 26s ease-in-out infinite alternate;
}
[data-theme="light"] .bg-aurora::before,
[data-theme="light"] .bg-aurora::after { opacity: 0.28; }

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 56px 56px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 25%, transparent 80%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 25%, transparent 80%);
  opacity: 0.5;
}

@keyframes drift1 {
  to { transform: translate(12vw, 10vh) scale(1.15); }
}
@keyframes drift2 {
  to { transform: translate(-10vw, -8vh) scale(1.2); }
}

/* ---------- Utilities ---------- */
.container { width: min(var(--maxw), 92vw); margin-inline: auto; }
.gradient-text {
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2) 45%, var(--grad-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  backdrop-filter: blur(8px);
}
.eyebrow .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--grad-3);
  box-shadow: 0 0 12px var(--grad-3);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; transform: scale(0.8); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 1.5rem;
  border-radius: 100px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease);
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary {
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2) 55%, var(--grad-3));
  color: #fff;
  box-shadow: 0 12px 30px -10px rgba(99, 102, 241, 0.7);
  background-size: 160% 160%;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px -10px rgba(139, 92, 246, 0.8);
  background-position: 100% 0;
}
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  backdrop-filter: blur(10px);
}
.btn-ghost:hover { transform: translateY(-2px); background: var(--surface-2); border-color: var(--grad-2); }

/* ---------- Navbar ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease), backdrop-filter 0.3s;
  border-bottom: 1px solid transparent;
}
.nav.scrolled {
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(18px) saturate(150%);
  border-bottom-color: var(--border);
}
.nav .container { display: flex; align-items: center; gap: 1.5rem; width: min(1280px, 94vw); }
.brand { display: flex; align-items: center; gap: 0.7rem; font-family: var(--font-display); font-weight: 700; }
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff;
  font-size: 1.05rem;
  box-shadow: 0 8px 22px -8px rgba(99, 102, 241, 0.8);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 1.02rem; letter-spacing: 0.02em; }
.brand-text span { font-size: 0.66rem; color: var(--text-faint); font-family: var(--font-mono); letter-spacing: 0.12em; }
.nav-links { display: flex; gap: 0.35rem; margin-left: auto; align-items: center; }
.nav-links a {
  padding: 0.5rem 0.9rem;
  border-radius: 100px;
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 500;
  transition: color 0.2s, background 0.2s;
}
.nav-links a:hover { color: var(--text); background: var(--surface); }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: all 0.25s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--grad-2); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }
.lang-btn { width: auto; padding: 0 0.85rem; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; }

.nav-toggle { display: none; }

/* ---------- Hero ---------- */
.hero { position: relative; padding: clamp(3.5rem, 9vw, 7rem) 0 clamp(3rem, 6vw, 5rem); overflow: hidden; }
.hero-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none; opacity: 0.9;
  -webkit-mask-image: radial-gradient(120% 90% at 75% 35%, #000 30%, transparent 75%);
  mask-image: radial-gradient(120% 90% at 75% 35%, #000 30%, transparent 75%);
}
.hero-inner { max-width: 880px; position: relative; z-index: 1; }
.hero h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 6.5vw, 5rem);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 1.4rem 0 1.2rem;
}
.hero p.lede {
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  color: var(--text-dim);
  max-width: 640px;
  margin-bottom: 2.2rem;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; }
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(1.5rem, 4vw, 3rem);
  margin-top: 3.5rem;
  padding-top: 2.2rem;
  border-top: 1px solid var(--border);
}
.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3.5vw, 2.3rem);
  font-weight: 700;
  line-height: 1;
}
.stat span { font-size: 0.82rem; color: var(--text-faint); letter-spacing: 0.04em; }

/* ---------- Section scaffolding ---------- */
.section { padding: clamp(3.5rem, 8vw, 6.5rem) 0; position: relative; }
.section-head { max-width: 680px; margin-bottom: 3rem; }
.section-head.center { margin-inline: auto; text-align: center; }
.section-head h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 4vw, 2.9rem);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0.9rem 0 0.8rem;
}
.section-head p { color: var(--text-dim); font-size: 1.05rem; }

/* ---------- Outcome cards ---------- */
.outcomes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.2rem;
}
.outcome {
  padding: 1.8rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.35s var(--ease), border-color 0.35s, background 0.35s;
}
.outcome:hover { transform: translateY(-5px); border-color: var(--border-strong); background: var(--surface-2); }
.outcome .ico {
  width: 48px; height: 48px;
  border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(99,102,241,0.22), rgba(34,211,238,0.18));
  border: 1px solid var(--border);
  margin-bottom: 1.1rem;
}
.outcome .ico svg { width: 24px; height: 24px; stroke: var(--grad-3); }
.outcome h3 { font-family: var(--font-display); font-size: 1.1rem; margin-bottom: 0.5rem; }
.outcome p { font-size: 0.92rem; color: var(--text-dim); }

/* ---------- Companion handbook band ---------- */
.companion { position: relative; display: block; overflow: hidden; border-radius: var(--radius-lg); border: 1px solid var(--border-strong); background: linear-gradient(135deg, color-mix(in srgb, #10b981 13%, var(--surface)), var(--surface) 60%); padding: clamp(1.6rem, 4vw, 3rem); box-shadow: var(--shadow); transition: transform 0.3s var(--ease), border-color 0.3s; }
.companion:hover { transform: translateY(-3px); border-color: color-mix(in srgb, #10b981 55%, var(--border-strong)); }
.companion-glow { position: absolute; right: -8%; top: -50%; width: 45%; height: 200%; background: radial-gradient(circle, rgba(16, 185, 129, 0.18), transparent 70%); pointer-events: none; }
.companion-main { position: relative; max-width: 760px; }
.companion h2 { font-size: clamp(1.6rem, 4vw, 2.5rem); margin: 0.3rem 0 0.7rem; line-height: 1.1; background: linear-gradient(120deg, #10b981, #22d3ee); -webkit-background-clip: text; background-clip: text; color: transparent; }
.companion p { color: var(--text-dim); margin-bottom: 1.2rem; max-width: 660px; }
.companion-stats { display: flex; flex-wrap: wrap; gap: 1.6rem; margin-bottom: 1.5rem; font-size: 0.9rem; color: var(--text-dim); align-items: baseline; }
.companion-stats b { font-family: var(--font-display); font-size: 1.35rem; color: var(--text); margin-right: 0.15rem; }
.companion-btn { background: linear-gradient(135deg, #10b981, #22d3ee) !important; box-shadow: 0 10px 30px -10px rgba(16, 185, 129, 0.7) !important; }

/* ---------- Interactive attention demo ---------- */
.attn {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.attn-svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; overflow: visible; }
.attn-sentence {
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 0.6rem 0.7rem;
  justify-content: center; align-items: center;
  padding: 3.2rem 1.6rem 2.4rem;
}
.attn-token {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.4vw, 1.45rem);
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s var(--ease), background 0.25s var(--ease), border-color 0.25s, box-shadow 0.25s;
}
.attn-token:hover { transform: translateY(-2px); }
.attn-token .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  background: linear-gradient(90deg, var(--grad-2), var(--grad-3));
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.35s var(--ease);
}
.attn-token.is-query {
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2) 55%, var(--grad-3)) !important;
  color: #fff;
  border-color: transparent !important;
  box-shadow: 0 10px 26px -10px rgba(139, 92, 246, 0.8);
  transform: translateY(-3px) scale(1.04);
}
.attn-token.is-query .bar { opacity: 0; }
.attn-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  justify-content: center;
  padding: 0 1.5rem 1.7rem;
  font-size: 0.86rem; color: var(--text-dim);
}
.attn-foot .attn-q { font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-faint); }
.attn-foot strong { font-family: var(--font-display); color: var(--text); padding: 0.1rem 0.5rem; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); }
.attn-foot .attn-tip { width: 100%; text-align: center; font-size: 0.78rem; color: var(--text-faint); margin-top: 0.2rem; }

/* ---------- Curriculum cards ---------- */
.lectures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.3rem;
}
.lecture-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.7rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform 0.4s var(--ease), border-color 0.4s, box-shadow 0.4s;
}
.lecture-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 0 0, var(--accent-soft, rgba(99,102,241,0.12)), transparent 55%);
  opacity: 0;
  transition: opacity 0.4s var(--ease);
}
.lecture-card:hover { transform: translateY(-6px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.lecture-card:hover::before { opacity: 1; }
.lecture-card > * { position: relative; z-index: 1; }
.lc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.lc-num {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent, var(--grad-2)), transparent 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0.9;
}
.lc-meta { text-align: right; font-size: 0.72rem; color: var(--text-faint); font-family: var(--font-mono); }
.lc-meta .dur { display: inline-flex; align-items: center; gap: 0.3rem; }
.lecture-card h3 { font-family: var(--font-display); font-size: 1.22rem; margin-bottom: 0.5rem; line-height: 1.2; }
.lecture-card .tagline { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 1.1rem; flex: 1; }
.lc-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.2rem; }
.lc-tag {
  font-size: 0.7rem;
  padding: 0.25rem 0.6rem;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.lc-go {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.86rem; font-weight: 600;
  color: var(--accent, var(--grad-3));
  transition: gap 0.25s var(--ease);
}
.lecture-card:hover .lc-go { gap: 0.8rem; }

/* Accent palette per lecture */
.accent-indigo  { --accent: #818cf8; --accent-soft: rgba(99,102,241,0.16); }
.accent-violet  { --accent: #a78bfa; --accent-soft: rgba(139,92,246,0.16); }
.accent-cyan    { --accent: #22d3ee; --accent-soft: rgba(34,211,238,0.16); }
.accent-emerald { --accent: #34d399; --accent-soft: rgba(16,185,129,0.16); }
.accent-amber   { --accent: #fbbf24; --accent-soft: rgba(245,158,11,0.16); }
.accent-rose    { --accent: #fb7185; --accent-soft: rgba(244,63,94,0.16); }
.accent-sky     { --accent: #38bdf8; --accent-soft: rgba(56,189,248,0.16); }
.accent-teal    { --accent: #2dd4bf; --accent-soft: rgba(45,212,191,0.16); }
.accent-fuchsia { --accent: #e879f9; --accent-soft: rgba(232,121,249,0.16); }

/* ---------- Instructors / resources ---------- */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.3rem; }
.panel {
  padding: 2rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.panel h3 { font-family: var(--font-display); font-size: 1.3rem; margin-bottom: 0.4rem; }
.panel p { color: var(--text-dim); font-size: 0.95rem; margin-bottom: 1.4rem; }
.people { display: flex; gap: 1rem; flex-wrap: wrap; }
.person { display: flex; align-items: center; gap: 0.8rem; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700;
  background: linear-gradient(135deg, var(--grad-2), var(--grad-3));
  color: #fff;
}
.person b { font-size: 0.95rem; }
.person span { font-size: 0.78rem; color: var(--text-faint); display: block; }
.res-list { display: flex; flex-direction: column; gap: 0.7rem; }
.res-link {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: all 0.25s var(--ease);
}
.res-link:hover { border-color: var(--grad-2); transform: translateX(4px); }
.res-link .ri { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); flex: none; }
.res-link .ri svg { width: 18px; height: 18px; stroke: var(--grad-3); }
.res-link .rt b { font-size: 0.92rem; display: block; }
.res-link .rt span { font-size: 0.78rem; color: var(--text-faint); }
.res-link .arr { margin-left: auto; color: var(--text-faint); transition: transform 0.25s; }
.res-link:hover .arr { transform: translate(3px, -3px); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 3rem 0 2.5rem; margin-top: 2rem; }
.footer .container { display: flex; flex-wrap: wrap; gap: 2rem; justify-content: space-between; align-items: start; }
.footer p { color: var(--text-faint); font-size: 0.85rem; max-width: 420px; }
.footer a { color: var(--text-dim); }
.footer a:hover { color: var(--text); }
.footer .disc { font-size: 0.76rem; margin-top: 1rem; }
.foot-links { display: flex; gap: 1.4rem; flex-wrap: wrap; font-size: 0.88rem; }

/* ---------- Reveal animation ---------- */
.reveal { opacity: 0; transform: translateY(26px); transition: opacity 0.8s var(--ease), transform 0.8s var(--ease); }
.reveal.in { opacity: 1; transform: none; }
.reveal.d1 { transition-delay: 0.08s; }
.reveal.d2 { transition-delay: 0.16s; }
.reveal.d3 { transition-delay: 0.24s; }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  .bg-aurora::before, .bg-aurora::after { animation: none; }
  html { scroll-behavior: auto; }
}

/* ---------- Command palette (⌘K) ---------- */
.cmdk-trigger { width: auto; gap: 0.5rem; padding: 0 0.7rem; }
.cmdk-trigger svg { width: 16px; height: 16px; }
.cmdk-kbd { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); }
.cmdk {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(3rem, 12vh, 9rem) 1rem 1rem;
}
.cmdk[hidden] { display: none; }
.cmdk-backdrop { position: absolute; inset: 0; background: rgba(3, 5, 14, 0.6); backdrop-filter: blur(6px); animation: fade 0.2s var(--ease); }
.cmdk-panel {
  position: relative; width: min(620px, 100%);
  background: var(--surface-solid); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 40px 90px -20px rgba(0,0,0,0.7);
  overflow: hidden; animation: pop 0.22s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-12px) scale(0.98); } }
.cmdk-input { display: flex; align-items: center; gap: 0.7rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.cmdk-input svg { width: 19px; height: 19px; stroke: var(--text-faint); flex: none; }
.cmdk-input input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-size: 1.05rem; font-family: var(--font-body); }
.cmdk-list { max-height: min(52vh, 420px); overflow-y: auto; padding: 0.5rem; scrollbar-width: thin; }
.cmdk-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.65rem 0.8rem; border-radius: var(--radius-sm);
  cursor: pointer;
}
.cmdk-item.sel { background: var(--surface-2); }
.cmdk-lead {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--accent, var(--text-dim));
}
.cmdk-item.sel .cmdk-lead { background: var(--accent, var(--grad-2)); color: #0a0e1f; border-color: transparent; }
.cmdk-text { flex: 1; min-width: 0; }
.cmdk-text b { display: block; font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-text span { font-size: 0.76rem; color: var(--text-faint); }
.cmdk-go { color: var(--text-faint); opacity: 0; transition: opacity 0.15s; }
.cmdk-item.sel .cmdk-go { opacity: 1; color: var(--accent, var(--grad-3)); }
.cmdk-empty { padding: 1.4rem; text-align: center; color: var(--text-faint); font-size: 0.9rem; }
.cmdk-foot { display: flex; gap: 1.2rem; padding: 0.7rem 1.2rem; border-top: 1px solid var(--border); font-size: 0.74rem; color: var(--text-faint); }
.cmdk-foot kbd { font-family: var(--font-mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0.05rem 0.35rem; margin-right: 0.15rem; }
@media (max-width: 600px) { .cmdk-kbd { display: none; } }

/* =============================================================================
   LEARN PAGE
   ========================================================================== */
/* Reading progress (top of viewport) */
.read-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  z-index: 200;
  background: linear-gradient(90deg, var(--grad-1), var(--grad-2), var(--grad-3));
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.6);
  transition: width 0.1s linear;
}
/* Keyboard hint chips in the sidebar footer */
.kbd-hints { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.9rem; justify-content: center; }
.kbd-hints kbd {
  font-family: var(--font-mono); font-size: 0.68rem;
  padding: 0.15rem 0.45rem; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-faint);
}
.learn-shell { display: grid; grid-template-columns: 312px 1fr; min-height: calc(100vh - var(--nav-h)); }

.sidebar {
  position: sticky;
  top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem 3rem;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  backdrop-filter: blur(8px);
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.search-box { position: relative; margin-bottom: 1.2rem; }
.search-box svg { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--text-faint); }
.search-box input {
  width: 100%;
  padding: 0.7rem 0.9rem 0.7rem 2.4rem;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--grad-2); }
.search-box input::placeholder { color: var(--text-faint); }

.progress-wrap { padding: 0 0.4rem 1.2rem; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--text-faint); margin-bottom: 0.45rem; font-family: var(--font-mono); }
.progress-track { height: 6px; border-radius: 100px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 100px; background: linear-gradient(90deg, var(--grad-1), var(--grad-3)); transition: width 0.6s var(--ease); }

.nav-group { margin-bottom: 0.3rem; }
.nav-lecture {
  display: flex; align-items: center; gap: 0.7rem;
  width: 100%;
  padding: 0.7rem 0.7rem;
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.nav-lecture:hover { background: var(--surface); color: var(--text); }
.nav-lecture.active { background: var(--surface-2); color: var(--text); }
.nav-lecture .nl-num {
  width: 26px; height: 26px; flex: none;
  border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent, var(--text-dim));
}
.nav-lecture.active .nl-num { background: var(--accent, var(--grad-2)); color: #0a0e1f; border-color: transparent; }
.nav-lecture.done .nl-check { color: #34d399; }
.nl-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nl-check { width: 16px; height: 16px; opacity: 0; transition: opacity 0.2s; }
.nav-lecture.done .nl-check { opacity: 1; }
.nl-caret { width: 14px; height: 14px; color: var(--text-faint); transition: transform 0.25s; }
.nav-group.open .nl-caret { transform: rotate(90deg); }
.nav-sublist {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s var(--ease);
  margin-left: 1.95rem;
}
.nav-group.open .nav-sublist { grid-template-rows: 1fr; }
.nav-sublist > div { overflow: hidden; }
.nav-sub {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.42rem 0.7rem;
  border-left: 1.5px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-faint);
  transition: color 0.2s, border-color 0.2s;
}
.nav-sub:hover { color: var(--text); }
.nav-sub.active { color: var(--accent, var(--grad-3)); border-color: var(--accent, var(--grad-3)); }

.sidebar-foot { margin-top: 1.4rem; padding: 0 0.5rem; }

/* ----- Content area ----- */
.content { min-width: 0; }
.content-inner { max-width: 820px; margin-inline: auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1.2rem, 4vw, 3rem) 5rem; animation: contentIn 0.55s var(--ease) both; }
@keyframes contentIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .content-inner { animation: none; } }

.lec-head { margin-bottom: 2.2rem; }
.lec-head .crumbs { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-faint); letter-spacing: 0.08em; margin-bottom: 1rem; }
.lec-head .crumbs b { color: var(--accent, var(--grad-3)); }
.lec-head h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 3.1rem);
  letter-spacing: -0.025em;
  line-height: 1.08;
  margin-bottom: 0.7rem;
}
.lec-tagline { font-size: 1.1rem; color: var(--text-dim); margin-bottom: 1.3rem; }
.lec-meta-row { display: flex; flex-wrap: wrap; gap: 1.2rem; font-size: 0.82rem; color: var(--text-faint); font-family: var(--font-mono); }
.lec-meta-row span { display: inline-flex; align-items: center; gap: 0.4rem; }
.lec-meta-row svg { width: 15px; height: 15px; }

.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #05070f;
  box-shadow: var(--shadow);
  margin: 1.8rem 0 0.9rem;
}
.video-frame iframe { width: 100%; height: 100%; border: 0; }
/* Lite-YouTube facade */
.yt-facade { display: block; width: 100%; height: 100%; padding: 0; cursor: pointer; position: relative; }
.yt-thumb { width: 100%; height: 100%; object-fit: cover; opacity: 0.78; transition: opacity 0.3s var(--ease), transform 0.6s var(--ease); }
.yt-scrim { position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, transparent, rgba(5,7,15,0.45)); }
.yt-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 74px; height: 74px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2) 55%, var(--grad-3));
  box-shadow: 0 12px 40px -8px rgba(99, 102, 241, 0.8);
  transition: transform 0.25s var(--ease);
}
.yt-play svg { width: 30px; height: 30px; color: #fff; margin-left: 3px; }
.yt-facade:hover .yt-thumb { opacity: 1; transform: scale(1.03); }
.yt-facade:hover .yt-play { transform: translate(-50%, -50%) scale(1.1); }
.yt-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.85rem; color: var(--text-faint);
  margin-bottom: 2.2rem;
  transition: color 0.2s;
}
.yt-link:hover { color: var(--accent, var(--grad-3)); }
.yt-link svg { width: 14px; height: 14px; }

.overview-box {
  padding: 1.5rem 1.6rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent, var(--grad-2));
  margin-bottom: 2.6rem;
}
.overview-box .ob-label { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent, var(--grad-3)); margin-bottom: 0.6rem; }
.overview-box p { color: var(--text-dim); font-size: 1rem; }
.overview-box p + p { margin-top: 0.7rem; }

/* Topic blocks */
.topic { scroll-margin-top: calc(var(--nav-h) + 20px); margin-bottom: 2.6rem; }
.topic-head { display: flex; align-items: baseline; gap: 0.8rem; margin-bottom: 1rem; padding-bottom: 0.7rem; border-bottom: 1px solid var(--border); }
.topic-head .ti {
  font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700;
  color: var(--accent, var(--grad-3));
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.1rem 0.5rem; flex: none;
}
.topic-head h2 { font-family: var(--font-display); font-size: clamp(1.3rem, 3vw, 1.7rem); letter-spacing: -0.015em; line-height: 1.2; }
.topic-body { color: var(--text); }
.topic-body p { margin-bottom: 1rem; color: var(--text-dim); }
.topic-body strong { color: var(--text); font-weight: 650; }
.topic-body em { color: var(--text); font-style: italic; }
.topic-body ul, .topic-body ol { margin: 0 0 1.1rem 0; padding-left: 1.3rem; }
.topic-body ul { list-style: none; padding-left: 0; }
.topic-body ul li { position: relative; padding-left: 1.5rem; margin-bottom: 0.55rem; color: var(--text-dim); }
.topic-body ul li::before {
  content: ""; position: absolute; left: 0.2rem; top: 0.65rem;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent, var(--grad-3));
}
.topic-body ol { padding-left: 1.4rem; }
.topic-body ol li { margin-bottom: 0.55rem; color: var(--text-dim); }
.topic-body ol li::marker { color: var(--accent, var(--grad-3)); font-family: var(--font-mono); font-weight: 700; }
.topic-body code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: var(--surface-2); padding: 0.12em 0.42em; border-radius: 6px;
  border: 1px solid var(--border); color: var(--text);
}
.topic-body blockquote {
  border-left: 3px solid var(--accent, var(--grad-2));
  padding: 0.7rem 1.1rem;
  margin: 0 0 1.1rem;
  background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.topic-body blockquote strong { color: var(--accent, var(--grad-3)); }
/* Tables & inline code inside body content (used heavily by the handbook) */
.topic-body table { width: 100%; border-collapse: collapse; margin: 1.1rem 0 1.5rem; font-size: 0.88rem; display: block; overflow-x: auto; }
.topic-body th, .topic-body td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; vertical-align: top; }
.topic-body thead th { background: var(--surface-2); color: var(--text); font-family: var(--font-display); font-weight: 600; white-space: nowrap; }
.topic-body tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.topic-body code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface-2); border: 1px solid var(--border); padding: 0.08em 0.4em; border-radius: 6px; }
.topic-body blockquote code { background: transparent; border: none; padding: 0; }

/* MathJax: the global `svg { display:block }` reset breaks inline math by
   forcing each formula onto its own line — restore inline flow here. */
mjx-container svg { display: inline-block; max-width: none; }
mjx-container { line-height: 0; }
.topic-body mjx-container[display="true"],
.overview-box mjx-container[display="true"] {
  display: block;
  text-align: center;
  overflow-x: auto; overflow-y: hidden;
  padding: 0.9rem 0.4rem; margin: 0.4rem 0 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: normal;
}

/* ---------- Handbook: long-form reading rhythm (scoped, won't touch lecture pages) ---------- */
.handbook .lec { max-width: 62rem; margin-inline: auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1.2rem, 4vw, 3rem) 5rem; }
.handbook .topic { margin-bottom: 2.6rem; }
.handbook .topic-body { font-size: 1.04rem; }
.handbook .topic-body p { line-height: 1.92; margin-bottom: 1.15rem; color: var(--text-dim); }
.handbook .topic-body ul li, .handbook .topic-body ol li { line-height: 1.85; margin-bottom: 0.7rem; }
/* the very first paragraph of a chapter sets the scene — give it room and presence */
.handbook .topic:first-of-type .topic-body > p:first-child {
  font-size: 1.24rem; line-height: 1.8; color: var(--text); font-weight: 450; margin-bottom: 1.45rem;
}
.handbook .topic:first-of-type .topic-body > p:first-child strong { color: var(--text); }
/* blockquote = the one-line insight / 金句; make it a real visual beat */
.handbook .topic-body blockquote {
  border-left: 3px solid #10b981;
  background: color-mix(in srgb, #10b981 9%, var(--surface));
  padding: 1.05rem 1.35rem; margin: 1.7rem 0; border-radius: 0 14px 14px 0;
  font-size: 1.09rem; line-height: 1.75; color: var(--text); font-weight: 450;
}
.handbook .topic-body blockquote strong { color: #34d399; }
/* a little more air around the centered formula cards */
.handbook .topic-body mjx-container[display="true"] { margin: 1.1rem 0 1.5rem; padding: 1.05rem 0.6rem; }

/* Takeaways */
.takeaways {
  margin-top: 2rem;
  padding: 1.7rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}
.takeaways h3 { font-family: var(--font-display); font-size: 1.15rem; display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.1rem; }
.takeaways h3 svg { width: 20px; height: 20px; stroke: var(--accent, var(--grad-3)); }
.takeaways li { position: relative; padding-left: 1.9rem; margin-bottom: 0.7rem; color: var(--text-dim); font-size: 0.94rem; }
.takeaways li::before {
  content: "✓";
  position: absolute; left: 0; top: 0;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft, rgba(99,102,241,0.18));
  color: var(--accent, var(--grad-3));
  font-size: 0.74rem; font-weight: 800;
}

/* Further reading */
.refs {
  margin-top: 1.3rem;
  padding: 1.6rem 1.7rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.refs h3 { font-family: var(--font-display); font-size: 1.1rem; display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.refs h3 svg { width: 19px; height: 19px; stroke: var(--accent, var(--grad-3)); }
.refs ul { display: grid; gap: 0.5rem; }
.refs li { padding-left: 0; }
.refs a {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.92rem; color: var(--text-dim);
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.refs a:hover { color: var(--accent, var(--grad-3)); border-color: var(--accent, var(--grad-3)); }
.refs a svg { flex: none; opacity: 0.6; }

/* Prev / next */
.lec-nav { display: flex; gap: 1rem; margin-top: 3rem; }
.lec-nav a {
  flex: 1;
  padding: 1.1rem 1.3rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.3s var(--ease);
}
.lec-nav a:hover { border-color: var(--border-strong); transform: translateY(-3px); background: var(--surface-2); }
.lec-nav .dir { font-size: 0.74rem; color: var(--text-faint); font-family: var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; }
.lec-nav .t { font-family: var(--font-display); font-weight: 600; margin-top: 0.3rem; }
.lec-nav .next { text-align: right; }
.lec-nav a.disabled { opacity: 0.35; pointer-events: none; }

.complete-btn {
  display: inline-flex; align-items: center; gap: 0.6rem;
  margin-top: 2rem;
  padding: 0.85rem 1.5rem;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-weight: 600; font-size: 0.92rem;
  transition: all 0.25s var(--ease);
}
.complete-btn:hover { transform: translateY(-2px); border-color: #34d399; }
.complete-btn svg { width: 18px; height: 18px; }
.complete-btn.done { background: rgba(52,211,153,0.14); border-color: #34d399; color: #34d399; }

/* Mobile sidebar toggle */
.sidebar-backdrop { display: none; }
.mobile-bar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .nav-links { display: none; }
  .nav-links.open {
    display: flex; flex-direction: column;
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    background: var(--bg-2); border-bottom: 1px solid var(--border);
    padding: 1rem; gap: 0.3rem;
    margin-left: 0;
  }
  .nav-links.open a { padding: 0.8rem 1rem; }
  .nav-toggle { display: grid; }
  .split { grid-template-columns: 1fr; }

  .learn-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 300px; height: 100vh; z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.35s var(--ease);
    background: var(--bg-2);
    padding-top: 1.5rem;
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 150;
    background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .mobile-bar {
    display: flex; align-items: center; gap: 0.8rem;
    position: sticky; top: var(--nav-h); z-index: 90;
    padding: 0.7rem 1rem;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .mobile-bar .menu-btn { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.86rem; font-weight: 600; }
  .mobile-bar .menu-btn svg { width: 18px; height: 18px; }
  .mobile-bar .mb-title { font-size: 0.84rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 560px) {
  .hero-stats { gap: 1.4rem; }
  .lec-nav { flex-direction: column; }
  .brand-text span { display: none; }
}
