/* ============================================================
   LLM Explainer — main stylesheet
   Dark theme, clean typography, scrollytelling layout
   ============================================================ */

:root {
  --bg: #0a0a0f;
  --bg-elev: #13131c;
  --text: #f5f6fa;
  --text-dim: #a0a3b1;
  --text-faint: #5c5f70;
  --accent: #7c8cff;
  --accent-2: #4fd1c5;
  --border: rgba(255, 255, 255, 0.08);
  --max-width: 1380px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 70px; /* keep anchored sections clear of the fixed bar */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

strong {
  color: var(--text);
  font-weight: 600;
}

/* subtle highlight under emphasized terms */
.section-text strong {
  background: linear-gradient(transparent 65%, rgba(124, 140, 255, 0.25) 65%);
}

/* ---------- Skip to content link (hidden until focused) ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: #7c8cff;
  color: #0a0a0f;
  padding: 8px 16px;
  font-weight: 600;
  border-radius: 0 0 6px 0;
  z-index: 10000;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

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

/* ---------- Progress bar ---------- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  z-index: 100;
  transition: width 0.1s linear;
}

/* ---------- Fixed top navigation bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 clamp(16px, 4vw, 32px);
  background: rgba(10, 10, 15, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 95;
}

.topbar-brand {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.1;
  gap: 1px;
  color: var(--text);
  text-decoration: none;
}

.topbar-title {
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.topbar-brand:hover .topbar-title {
  color: var(--accent);
}

.topbar-by {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-2);
  white-space: nowrap;
}

.topbar-links {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-links::-webkit-scrollbar {
  display: none;
}

.topbar-links a {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 7px;
  white-space: nowrap;
  transition: color 0.2s ease, background 0.2s ease;
}

.topbar-links a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

/* Edge fades hinting the nav scrolls horizontally (only added by JS when it
   actually overflows, e.g. on narrow / mobile screens). */
.topbar-links.fade-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
}

.topbar-links.fade-left {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 26px);
  mask-image: linear-gradient(to right, transparent, #000 26px);
}

.topbar-links.fade-left.fade-right {
  -webkit-mask-image: linear-gradient(
    to right,
    transparent,
    #000 26px,
    #000 calc(100% - 26px),
    transparent
  );
  mask-image: linear-gradient(
    to right,
    transparent,
    #000 26px,
    #000 calc(100% - 26px),
    transparent
  );
}

.topbar-links a.active {
  color: var(--accent);
  background: rgba(124, 140, 255, 0.13);
}

/* ---------- Side nav dots ---------- */
.section-nav {
  position: fixed;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 90;
}

.nav-dot {
  position: relative;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--text-faint);
  background: transparent;
  transition: all 0.25s ease;
}

.nav-dot:hover,
.nav-dot.active {
  border-color: var(--accent);
  background: var(--accent);
  transform: scale(1.25);
}

.nav-dot::after {
  content: attr(data-label);
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--bg-elev);
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid var(--border);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.nav-dot:hover::after,
.nav-dot:focus::after {
  opacity: 1;
}

/* ---------- Hero ---------- */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 24px;
  position: relative;
  background: radial-gradient(
    ellipse at 50% 0%,
    rgba(124, 140, 255, 0.12),
    transparent 60%
  );
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 0.78rem;
  color: var(--accent-2);
  margin-bottom: 1.2rem;
}

.hero h1 {
  font-size: clamp(2.2rem, 6vw, 4.2rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 14ch;
  background: linear-gradient(180deg, #ffffff, #b9bdd6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-by {
  margin-top: 0.9rem;
  display: inline-block;
  align-self: center;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-2);
  padding: 6px 16px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 45%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
}

.hero-sub {
  margin-top: 1.2rem;
  font-size: clamp(1.1rem, 2.6vw, 1.5rem);
  font-weight: 500;
  color: var(--accent-2);
  letter-spacing: 0.01em;
}

.hero-tagline {
  margin-top: 1.1rem;
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  color: var(--text-dim);
  max-width: 50ch;
}

.scroll-hint {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.scroll-arrow {
  width: 22px;
  height: 22px;
  border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint);
  transform: rotate(45deg);
  animation: bob 1.8s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: rotate(45deg) translate(0, 0); opacity: 0.4; }
  50% { transform: rotate(45deg) translate(5px, 5px); opacity: 1; }
}

/* ---------- Sections ---------- */
.section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 80px 24px;
  border-top: 1px solid var(--border);
}

.section-inner {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 0.78fr 1.22fr;
  gap: 48px;
  align-items: center;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.section-inner.visible {
  opacity: 1;
  transform: translateY(0);
}

/* alternate text/viz order for visual rhythm */
.section:nth-child(even) .section-text {
  order: 2;
}

/* Keep the wide column on the visualization, even when sides are swapped. */
.section:nth-child(even) .section-inner {
  grid-template-columns: 1.22fr 0.78fr;
}

.section-text {
  position: relative;
}

/* Large faded number sitting behind the heading. */
.section-number {
  position: absolute;
  top: -0.62em;
  left: -0.04em;
  z-index: 0;
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(4.5rem, 11vw, 8.5rem);
  line-height: 1;
  letter-spacing: 0.01em;
  color: rgba(124, 140, 255, 0.09);
  pointer-events: none;
  user-select: none;
}

.section-text h2,
.section-text p {
  position: relative;
  z-index: 1;
}

.section-text h2 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.1rem;
  line-height: 1.15;
}

.section-text p {
  color: var(--text-dim);
  font-size: 1.05rem;
  margin-bottom: 1rem;
  max-width: 46ch;
}

/* Highlighted "key idea / example" callout inside a section */
.section-aside {
  position: relative;
  z-index: 1;
  margin-top: 1.4rem;
  padding: 0.9rem 1.1rem;
  max-width: 46ch;
  background: rgba(124, 140, 255, 0.06);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}

.section-aside p {
  margin-bottom: 0;
  font-size: 0.97rem;
  color: var(--text-dim);
}

.section-aside .aside-label {
  display: block;
  margin-bottom: 0.35rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.section-aside code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.05em 0.35em;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

/* ---------- Viz placeholder ---------- */
.viz {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 82vh;
  border-radius: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* placeholder shimmer until a scene mounts */
.viz:empty::after {
  content: "Visualization";
  color: var(--text-faint);
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.viz canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* file:// fallback notice */
.viz-notice {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 28px;
  max-width: 36ch;
}

.viz-notice strong {
  color: var(--accent);
  font-size: 1.05rem;
}

.viz-notice span {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
}

.viz-notice code {
  font-family: var(--mono);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--accent-2);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* ---------- Tokens viz (Section 1) ---------- */
.tok-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 28px;
  text-align: center;
}

.tok-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-faint);
}

.tok-sentence {
  font-size: clamp(1.2rem, 2.6vw, 1.9rem);
  font-weight: 600;
  line-height: 1.5;
}

.tok-src-word {
  color: var(--text-dim);
  padding: 2px 5px;
  border-radius: 6px;
  transition: color 0.3s ease, background 0.3s ease;
}

.tok-src-word.active {
  background: rgba(255, 255, 255, 0.07);
}

.tok-arrow {
  font-size: 1.5rem;
  color: var(--text-faint);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.tok-arrow.show {
  opacity: 1;
  transform: translateY(0);
}

.tok-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: flex-start;
}

.tok-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(14px) scale(0.85);
  transition: opacity 0.45s cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tok-item.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.tok-box {
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 700;
  color: #fff;
  padding: 14px 20px;
  min-width: 56px;
  border-radius: 12px;
  border: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  box-shadow: 0 4px 20px color-mix(in srgb, var(--c) 28%, transparent);
}

.tok-id {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--c);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.tok-id.show {
  opacity: 1;
  transform: translateY(0);
}

.tok-replay {
  margin-top: 6px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.tok-replay:hover {
  background: rgba(124, 140, 255, 0.16);
  border-color: var(--accent);
}

/* ---------- Embeddings viz (Section 2) ---------- */
.emb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.emb-token {
  font-size: clamp(1.6rem, 3.2vw, 2.4rem);
  font-weight: 700;
  color: #ffd479;
  padding: 16px 30px;
  border-radius: 14px;
  border: 2px solid #ffd479;
  background: color-mix(in srgb, #ffd479 16%, transparent);
  box-shadow: 0 6px 28px color-mix(in srgb, #ffd479 30%, transparent);
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.emb-token.pulse {
  animation: emb-pulse 1s ease-in-out 2;
}

@keyframes emb-pulse {
  0%, 100% { transform: scale(1); }
  50% {
    transform: scale(1.12);
    box-shadow: 0 8px 44px color-mix(in srgb, #ffd479 55%, transparent);
  }
}

.emb-token.burst {
  transform: scale(1.8);
  opacity: 0;
}

.emb-array-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transition: transform 0.6s ease, opacity 0.5s ease;
}

.emb-array-wrap.show {
  opacity: 1;
}

.emb-array-wrap.fly {
  transform: scale(0.22) translateY(-6px);
  opacity: 0;
}

.emb-array {
  font-family: var(--mono);
  font-size: clamp(0.8rem, 1.7vw, 1.1rem);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  max-width: 92%;
  color: #cfd3e6;
}

.emb-bracket {
  color: var(--accent-2);
  font-size: 1.3em;
}

.emb-num {
  opacity: 0;
  transform: scale(0.3);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.emb-num.show {
  opacity: 1;
  transform: scale(1);
}

.emb-dim-label {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.emb-fly {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, 0);
  font-family: var(--mono);
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.6s ease;
}

.emb-fly.go {
  transform: translate(-50%, 150px) scale(0.18);
  opacity: 0;
}

.emb-replay {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.emb-replay:hover {
  background: rgba(124, 140, 255, 0.16);
  border-color: var(--accent);
}

.emb-axis-label {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
}

.emb-point-label {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.emb-point-label.show {
  opacity: 1;
}

/* ---------- Self-Attention viz (Section 4) ---------- */
.att-overlay {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}

.att-select {
  pointer-events: auto;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(19, 19, 28, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.att-select:hover,
.att-select:focus {
  border-color: var(--accent);
}

.att-select option {
  background: #13131c;
  color: var(--text);
}

.att-hint {
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.att-label {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.85);
  user-select: none;
  white-space: nowrap;
  opacity: 0.85;
  transition: font-size 0.15s ease, font-weight 0.15s ease, opacity 0.15s ease;
}

.att-label.sel {
  font-size: 1.3rem;
  font-weight: 700;
  opacity: 1;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 1), 0 0 12px currentColor;
}

/* ---------- Transformer Block viz (Section 5) ---------- */
.tb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tb-diagram {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 28px 24px;
}

.tb-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.tb-skip {
  fill: none;
  stroke: #8089a8;
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: 0.5;
}

.tb-box {
  position: relative;
  z-index: 2;
  width: min(340px, 70%);
  padding: 12px 18px;
  border-radius: 12px;
  border: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 16%, #13131c);
  color: #fff;
  font-weight: 600;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 12px color-mix(in srgb, var(--c) 18%, transparent);
  transition: transform 0.2s ease, box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.tb-box:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 18px color-mix(in srgb, var(--c) 35%, transparent);
}

.tb-box.active {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 60%, transparent),
    0 6px 24px color-mix(in srgb, var(--c) 40%, transparent);
}

.tb-info {
  font-size: 0.75rem;
  opacity: 0.5;
}

/* connector arrow between consecutive boxes */
.tb-box:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  width: 1.5px;
  height: 10px;
  background: rgba(255, 255, 255, 0.18);
  transform: translateX(-50%);
}

.tb-box.tb-pulse {
  animation: tb-pulse 0.5s ease;
}

@keyframes tb-pulse {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 55%, transparent),
      0 6px 26px color-mix(in srgb, var(--c) 60%, transparent);
  }
  100% {
    transform: scale(1);
  }
}

.tb-particles {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.tb-dot {
  position: absolute;
  top: 0;
  left: 0;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #7c8cff;
  will-change: transform;
}

.tb-tooltip {
  position: absolute;
  z-index: 4;
  max-width: 240px;
  padding: 10px 13px;
  border-radius: 10px;
  background: rgba(10, 10, 15, 0.96);
  border: 1px solid color-mix(in srgb, var(--c) 50%, var(--border));
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.45;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.96);
  transform-origin: center;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tb-tooltip.show {
  opacity: 1;
  transform: scale(1);
}

/* little caret pointing at the box */
.tb-tooltip::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  background: rgba(10, 10, 15, 0.96);
  border: 1px solid color-mix(in srgb, var(--c) 50%, var(--border));
  transform: translateY(-50%) rotate(45deg);
}

.tb-tooltip.left::after {
  right: -5px;
  border-left: none;
  border-bottom: none;
}

.tb-tooltip.right::after {
  left: -5px;
  border-right: none;
  border-top: none;
}

/* ---------- Stacking Layers viz (Section 6) ---------- */
.sl-layer-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.85);
  user-select: none;
}

.sl-desc-label {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text);
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(10, 10, 15, 0.7);
  border: 1px solid color-mix(in srgb, var(--c) 55%, var(--border));
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 25%, transparent);
  user-select: none;
}

/* ---------- Next Token Prediction viz (Section 7) ---------- */
.np-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 28px clamp(20px, 5%, 48px);
}

.np-input {
  font-size: clamp(1.1rem, 2.4vw, 1.6rem);
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.np-added {
  color: var(--accent-2);
}

.np-added.flash {
  animation: np-flash 0.7s ease;
}

@keyframes np-flash {
  0% {
    color: #fff;
    text-shadow: 0 0 14px var(--accent-2);
  }
  100% {
    color: var(--accent-2);
    text-shadow: none;
  }
}

.np-dots {
  color: var(--text-faint);
}

.np-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 4px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: np-blink 1s step-end infinite;
}

@keyframes np-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.np-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.np-row {
  display: grid;
  grid-template-columns: 64px 1fr 46px;
  align-items: center;
  gap: 12px;
}

.np-token {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--text-dim);
  text-align: right;
}

.np-track {
  height: 22px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
}

.np-bar {
  height: 100%;
  width: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.np-row.picked .np-bar {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5),
    0 0 16px var(--accent-2);
}

.np-pct {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
  text-align: right;
}

.np-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.np-temp-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.np-temp-label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.np-temp-label strong {
  color: var(--text);
}

.np-temp-val {
  font-family: var(--mono);
  color: var(--accent);
  margin-left: 4px;
}

.np-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none;
  cursor: pointer;
}

.np-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.np-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
}

.np-buttons {
  display: flex;
  align-self: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.np-sample {
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, var(--accent), #6f7dff);
  border: none;
  padding: 10px 22px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(124, 140, 255, 0.3);
}

.np-sample:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(124, 140, 255, 0.45);
}

.np-sample:active {
  transform: translateY(0);
}

/* Secondary "Reset" button beside Sample */
.np-reset {
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease,
    border-color 0.2s ease, color 0.2s ease;
}

.np-reset:hover {
  transform: translateY(-1px);
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.np-reset:active {
  transform: translateY(0);
}

/* ---------- Training viz (Section 9) ---------- */
.train-stage {
  position: absolute;
  inset: 0;
}

.train-readout {
  position: absolute;
  top: 14px;
  left: 18px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--mono);
  pointer-events: none;
}

.train-loss-label,
.train-step-label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.train-step-label {
  margin-left: 6px;
}

.train-loss-val {
  font-size: 1.05rem;
  color: var(--accent-2);
}

.train-step-val {
  font-size: 1.05rem;
  color: var(--text);
}

.train-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px clamp(20px, 5%, 48px) 20px;
  background: linear-gradient(to top, var(--bg-elev) 62%, transparent);
}

/* ---------- Neural Network viz (Section 4) ---------- */
.nn-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 16px;
  gap: 8px;
}

.nn-svg {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: visible;
}

.nn-edge {
  opacity: var(--edge-opacity, 0.3);
  stroke-linecap: round;
  transition: opacity 0.5s ease, stroke 0.5s ease, stroke-width 0.5s ease;
}

.nn-edge.fire {
  opacity: 1;
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.55));
}

.nn-node {
  fill: #1c2030;
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 1.5;
  transition: fill 0.25s ease, stroke 0.25s ease, filter 0.25s ease;
}

.nn-node-in {
  stroke: var(--accent-2);
}

.nn-node-out {
  stroke: #b66bff;
}

.nn-node.lit {
  fill: var(--accent);
  stroke: #fff;
  filter: drop-shadow(0 0 8px rgba(124, 140, 255, 0.9));
}

.nn-node-in.lit {
  fill: var(--accent-2);
}

.nn-node-out.lit {
  fill: #b66bff;
}

.nn-axis {
  fill: var(--text-faint);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.04em;
}

.nn-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.nn-status {
  flex: 1;
  min-width: 180px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.nn-buttons {
  display: flex;
  gap: 12px;
}

.nn-pulse,
.nn-train {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease,
    border-color 0.2s ease, color 0.2s ease;
}

.nn-pulse {
  color: #fff;
  border: none;
  background: linear-gradient(90deg, var(--accent), #6f7dff);
  box-shadow: 0 4px 16px rgba(124, 140, 255, 0.3);
}

.nn-pulse:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(124, 140, 255, 0.45);
}

.nn-train {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}

.nn-train:hover {
  transform: translateY(-1px);
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.nn-pulse:active,
.nn-train:active {
  transform: translateY(0);
}

/* ---------- Footer ---------- */
.site-footer {
  padding: 76px 24px 60px;
  border-top: 1px solid var(--border);
  background: radial-gradient(
    ellipse at 50% 130%,
    rgba(124, 140, 255, 0.13),
    transparent 70%
  );
}

.footer-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.footer-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 18px rgba(124, 140, 255, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.footer-brand:hover .footer-mark {
  transform: translateY(-1px) rotate(-4deg);
  box-shadow: 0 6px 24px rgba(124, 140, 255, 0.6);
}

.footer-brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.footer-title {
  font-weight: 700;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.footer-by {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.footer-tagline {
  max-width: 44ch;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.6;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.footer-links a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-dot {
  color: var(--text-faint);
}

.footer-meta {
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .section-inner,
  .section:nth-child(even) .section-inner {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  /* keep natural order on mobile: text above viz */
  .section:nth-child(even) .section-text {
    order: 0;
  }

  .topbar {
    height: 52px;
  }

  .topbar-brand {
    font-size: 0.9rem;
  }

  .topbar-links a {
    font-size: 0.8rem;
    padding: 6px 8px;
  }

  .viz {
    aspect-ratio: 4 / 3;
    max-height: 50vh;
  }

  /* The DOM/SVG scenes stack their content vertically and need more height
     than the 4/3 box gives on a narrow screen, so they were getting clipped.
     Let these grow to a comfortable height instead. #viz-4 (Neural Network)
     is included too: a taller box matches the network's aspect and removes
     the large blank margins it had in the short 4/3 box. */
  #viz-1,
  #viz-4,
  #viz-6,
  #viz-8 {
    aspect-ratio: auto;
    max-height: none;
    height: auto;
    min-height: 400px;
  }

  #viz-1 .tok-stage {
    min-height: 400px;
  }

  /* Smaller in-scene labels on the Stacking viz so they don't crowd the
     slabs in the narrow mobile frame. */
  .sl-desc-label {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  .sl-layer-label {
    font-size: 0.72rem;
  }

  .section-nav {
    right: 14px;
    gap: 12px;
  }

  .nav-dot::after {
    display: none;
  }

  .section-text p {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .section {
    padding: 64px 18px;
  }

  .section-nav {
    display: none;
  }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .section-inner {
    transition: none;
    opacity: 1;
    transform: none;
  }
  .scroll-arrow {
    animation: none;
  }
}
