/* ==========================================================================
   Engine page — refined scroll animation
   ========================================================================== */

.engine-page {
  --stage-progress: 0;
  --phase: 0;
}

.engine-body {
  --bg: #e7f2f5;
  --bg-2: #edf6f8;
  --ink: #0c1f26;
  --ink-soft: #355360;
  --line: rgba(16, 90, 108, 0.22);
  --accent-hot: #0d7f8d;
  --accent-sky: #43afc0;
  --accent-bright: #14b2c5;
  --lane-ingest: #0d7f8d;
  --lane-compress: #14b2c5;
  --lane-serve: #2a8796;
  font-family: "Sora", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 80% -10%, rgba(74, 172, 196, 0.26) 0%, transparent 36%),
    radial-gradient(circle at 0% 30%, rgba(105, 203, 222, 0.12) 0%, transparent 42%),
    linear-gradient(180deg, #eaf5f7 0%, #e4f0f4 45%, #eaf6f8 100%);
  color: var(--ink);
}

.engine-body .grain { opacity: 0.028; }

.engine-body .topbar {
  border-color: rgba(16, 112, 132, 0.22);
  background: linear-gradient(180deg, rgba(231, 246, 250, 0.9), rgba(226, 241, 246, 0.86));
  box-shadow: 0 10px 28px rgba(20, 79, 95, 0.1);
}

.engine-body .brand,
.engine-body .topbar nav,
.engine-body .top-newsletter {
  font-family: "Sora", "Avenir Next", "Segoe UI", sans-serif;
}

.engine-body .masthead p,
.engine-body .kicker,
.engine-body .step,
.engine-body .row-index,
.engine-body .code-card pre,
.engine-body .compressed-meta,
.engine-body .stage-label,
.engine-body .phase-dot,
.engine-body .lane-name,
.engine-body .lane-index,
.engine-body .cap-filename,
.engine-body .cap-meta,
.engine-body .cap-tokens,
.engine-body .code-title,
.engine-body .code-role {
  font-family: "JetBrains Mono", "SF Mono", "Menlo", monospace;
}

/* ---------- Hero ---------- */
.engine-hero {
  width: min(1240px, 94vw);
  margin-inline: auto;
  padding-top: clamp(54px, 8vw, 106px);
}

.engine-hero h1 {
  max-width: 12ch;
  letter-spacing: -0.04em;
  line-height: 0.9;
}

.engine-hero h1 .cycle-line {
  display: block;
  color: #0e7585;
  text-shadow: 0 4px 14px rgba(26, 113, 129, 0.24);
}

.engine-hero .lede {
  max-width: 72ch;
}

/* ---------- Scroll stage ---------- */
.engine-scroll {
  min-height: 380vh;
  margin-top: clamp(42px, 8vw, 92px);
}

.engine-stage {
  width: min(1460px, 97vw);
  margin-inline: auto;
  min-height: min(86vh, 880px);
  position: sticky;
  top: 78px;
  border: 1px solid rgba(19, 110, 130, 0.22);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 40%, rgba(143, 213, 226, 0.22), rgba(153, 216, 228, 0.04) 48%),
    linear-gradient(165deg, rgba(244, 252, 254, 0.92), rgba(223, 240, 246, 0.94));
  box-shadow:
    0 30px 60px rgba(13, 63, 76, 0.14),
    0 2px 0 rgba(255, 255, 255, 0.6) inset,
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
  overflow: hidden;
}

/* ---------- Chrome (top bar with phase indicator) ---------- */
.stage-chrome {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid rgba(16, 110, 129, 0.14);
  background: linear-gradient(180deg, rgba(249, 253, 255, 0.78), rgba(239, 249, 252, 0.42));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.stage-label {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #15616f;
}

.phase-num {
  font-weight: 600;
  color: var(--accent-hot);
  font-variant-numeric: tabular-nums;
  transition: color 260ms ease;
}

.phase-sep,
.phase-total {
  color: rgba(21, 97, 111, 0.42);
  font-weight: 500;
}

.phase-title {
  margin-left: 10px;
  color: #0c1f26;
  letter-spacing: 0.08em;
  font-weight: 500;
  transition: opacity 220ms ease;
}

.stage-phases {
  display: inline-flex;
  gap: 18px;
}

.phase-dot {
  position: relative;
  padding-left: 14px;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(21, 97, 111, 0.48);
  transition: color 260ms ease;
}

.phase-dot::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid rgba(21, 97, 111, 0.32);
  background: transparent;
  transform: translateY(-50%);
  transition: background 260ms ease, border-color 260ms ease, box-shadow 260ms ease;
}

.phase-dot.is-active {
  color: #0c1f26;
}

.phase-dot.is-active::before {
  background: var(--accent-hot);
  border-color: var(--accent-hot);
  box-shadow: 0 0 0 4px rgba(13, 127, 141, 0.14);
}

.phase-dot b {
  font-weight: 500;
}

/* ---------- Scrubber (thin progress track under chrome) ---------- */
.stage-scrubber {
  position: absolute;
  top: 54px;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 19;
  pointer-events: none;
}

.scrubber-track {
  position: absolute;
  inset: 0;
  background: rgba(16, 110, 129, 0.1);
}

.scrubber-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0;
  background: linear-gradient(90deg, var(--accent-hot), var(--accent-bright));
  transition: width 80ms linear;
  box-shadow: 0 0 12px rgba(20, 178, 197, 0.4);
}

.scrubber-tick {
  position: absolute;
  top: -2px;
  width: 1px;
  height: 6px;
  background: rgba(21, 97, 111, 0.38);
}

/* ---------- Stage halo ---------- */
.stage-halo {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 84%, rgba(77, 188, 212, 0.16), transparent 36%),
    radial-gradient(circle at 84% 10%, rgba(37, 142, 165, 0.14), transparent 34%);
  z-index: 1;
}

/* ---------- Phase layers (all stacked, crossfade) ---------- */
.map-core,
.compressed-stage,
.source-stage {
  position: absolute;
  inset: 72px 22px 22px;
  border-radius: 18px;
  overflow: hidden;
}

.map-core {
  background:
    linear-gradient(180deg, rgba(247, 253, 255, 0.65), rgba(226, 243, 248, 0.72));
  transform-origin: center 40%;
  z-index: 2;
  will-change: opacity, transform;
}

.map-core::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(19, 103, 120, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 103, 120, 0.07) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.42;
}

/* ---------- Lane columns (vertical, full-height tints) ---------- */
.map-lane-cols {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 1;
  pointer-events: none;
}

.lane-col {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 18px 22px;
  gap: 6px;
}

.lane-col + .lane-col {
  border-left: 1px dashed rgba(16, 110, 129, 0.14);
}

.lane-col::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(13, 127, 141, 0.05) 0%,
    transparent 30%,
    transparent 70%,
    rgba(13, 127, 141, 0.035) 100%
  );
  pointer-events: none;
}

.lane-col[data-lane="compress"]::after {
  background: linear-gradient(
    180deg,
    rgba(20, 178, 197, 0.07) 0%,
    transparent 25%,
    transparent 70%,
    rgba(20, 178, 197, 0.05) 100%
  );
}

.lane-index {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: rgba(21, 97, 111, 0.48);
  font-weight: 600;
}

.lane-name {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: #155c6c;
  font-weight: 600;
}

/* ---------- SVG graph ---------- */
#map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.map-edge {
  fill: none;
  stroke: rgba(15, 111, 129, 0.55);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-dasharray: 3 6;
  animation: edge-flow 1.6s linear infinite;
}

.map-edge.is-hub {
  stroke: rgba(13, 127, 141, 0.85);
  stroke-width: 2;
  stroke-dasharray: 4 5;
  animation-duration: 1.1s;
}

.map-edge.is-out {
  animation-direction: reverse;
}

@keyframes edge-flow {
  to { stroke-dashoffset: -18; }
}

.map-node-group {
  transition: opacity 300ms ease;
}

.map-node {
  fill: #ffffff;
  stroke: rgba(13, 104, 123, 0.58);
  stroke-width: 1.4;
  filter: drop-shadow(0 4px 10px rgba(15, 88, 104, 0.08));
}

.map-node.is-core {
  fill: url(#capsule-fill);
  stroke: var(--accent-bright);
  stroke-width: 1.8;
  filter: drop-shadow(0 10px 22px rgba(20, 178, 197, 0.32));
}

.capsule-halo {
  fill: url(#capsule-glow);
  animation: capsule-pulse 2.6s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}

@keyframes capsule-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

.map-node-dot {
  fill: var(--accent-hot);
}

.map-node.is-core + .map-node-dot-core,
.map-node-dot-core {
  fill: var(--accent-bright);
}

.map-node-label {
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 12px;
  fill: #0c3642;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.map-node-label.is-core {
  font-size: 14px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.map-node-meta {
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 10px;
  fill: #4a7e8b;
  letter-spacing: 0.04em;
}

.map-node-meta.is-core {
  font-size: 10.5px;
  fill: #0c5665;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ---------- Phase 2: Compressed capsule cards ---------- */
.compressed-stage,
.source-stage {
  pointer-events: none;
  z-index: 3;
  will-change: opacity;
}

.source-stage {
  z-index: 4;
}

.compressed-card,
.code-card {
  position: absolute;
  transform-origin: center;
  will-change: transform, opacity, left, top;
}

.compressed-card {
  width: clamp(200px, 22vw, 280px);
  min-height: 134px;
  border-radius: 14px;
  border: 1px solid rgba(22, 113, 131, 0.22);
  background: linear-gradient(170deg, #ffffff 0%, rgba(236, 250, 253, 0.96) 100%);
  box-shadow:
    0 18px 34px rgba(20, 79, 95, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 14px 15px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compressed-card::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 0;
  width: 3px;
  background: var(--lane-compress);
  border-radius: 0 2px 2px 0;
}

.compressed-card[data-lane="ingest"]::before { background: var(--lane-ingest); }
.compressed-card[data-lane="serve"]::before { background: var(--lane-serve); }

.cap-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.cap-filename {
  margin: 0;
  font-size: 0.74rem;
  color: #0c3642;
  font-weight: 600;
  max-width: 72%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

.cap-type {
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #2a7786;
  padding: 2px 7px;
  border: 1px solid rgba(20, 113, 131, 0.22);
  border-radius: 4px;
  background: rgba(236, 250, 253, 0.8);
}

.cap-meta {
  font-size: 0.64rem;
  color: #4a7583;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.cap-bar-wrap {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cap-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: rgba(16, 110, 129, 0.08);
  overflow: hidden;
}

.cap-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--w, 80%);
  background: linear-gradient(90deg, var(--accent-hot), var(--accent-bright));
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(20, 178, 197, 0.35);
}

.cap-tokens {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.6rem;
  color: #4a7583;
  letter-spacing: 0.04em;
}

.cap-tokens b {
  color: var(--accent-hot);
  font-weight: 600;
}

.cap-tokens .cap-ratio {
  color: var(--accent-hot);
  font-weight: 600;
}

/* ---------- Phase 3: Raw source code cards ---------- */
.code-card {
  width: clamp(230px, 22vw, 320px);
  height: clamp(320px, 46vh, 460px);
  border-radius: 14px;
  border: 1px solid rgba(19, 95, 111, 0.38);
  background: linear-gradient(180deg, #0a242e 0%, #081d25 100%);
  box-shadow:
    0 24px 42px rgba(9, 43, 54, 0.32),
    inset 0 1px 0 rgba(140, 196, 209, 0.14);
  color: #d9eef3;
  padding: 12px 13px 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.code-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 80px;
  background: linear-gradient(180deg, transparent 0%, #081d25 90%);
  pointer-events: none;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 9px;
  border-bottom: 1px solid rgba(111, 170, 185, 0.16);
}

.code-title {
  font-size: 0.72rem;
  color: #b4dfe8;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.code-role {
  font-size: 0.56rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6ebbcf;
  padding: 2px 6px;
  border: 1px solid rgba(110, 187, 207, 0.26);
  border-radius: 4px;
}

.code-card pre {
  margin: 0;
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 0.66rem;
  line-height: 1.55;
  white-space: pre;
  color: #d5ecf2;
  overflow: hidden;
  flex: 1;
}

.tok-key { color: #66c7ff; }
.tok-fn { color: #8ce09a; }
.tok-str { color: #f4d48d; }
.tok-var { color: #e4edf1; }
.tok-op { color: #7ecce2; }
.tok-cmt { color: #6694a2; font-style: italic; }

/* ---------- Static page sections (unchanged layout) ---------- */
.engine-notes,
.engine-evidence,
.waitlist-band,
.footer {
  width: min(1240px, 94vw);
}

.engine-notes {
  margin: clamp(62px, 9vw, 102px) auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.engine-notes article {
  border-top: 1px solid rgba(16, 95, 112, 0.24);
  padding-top: 18px;
}

.engine-notes h3 {
  margin-top: 9px;
  font-size: clamp(1.56rem, 2.9vw, 2.24rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
}

.engine-notes p:last-child {
  margin-top: 10px;
  color: #2d4c58;
  line-height: 1.5;
}

.engine-evidence {
  margin: clamp(58px, 9vw, 106px) auto 0;
}

.engine-evidence h2 {
  margin-top: 10px;
  font-size: clamp(1.9rem, 4.3vw, 3rem);
  letter-spacing: -0.03em;
}

.engine-body .metric-line {
  border-bottom-color: rgba(16, 94, 112, 0.22);
}

.engine-body .line-track {
  background: rgba(18, 95, 113, 0.1);
}

.engine-body .line-track span {
  background: linear-gradient(90deg, #0d7f8d, #35abc0);
}

.engine-body .footer {
  margin-top: 48px;
  border-top-color: rgba(16, 90, 107, 0.26);
  color: #2b4c58;
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .engine-stage { min-height: min(88vh, 820px); }
  .compressed-card { width: clamp(180px, 26vw, 230px); }
  .code-card { width: clamp(210px, 30vw, 280px); height: clamp(300px, 42vh, 400px); }
}

@media (max-width: 980px) {
  .engine-scroll { min-height: 420vh; }
  .engine-stage {
    top: 64px;
    border-radius: 18px;
    min-height: 680px;
  }
  .map-core,
  .compressed-stage,
  .source-stage {
    inset: 72px 14px 14px;
  }
  .stage-chrome {
    padding: 0 14px;
    height: 48px;
  }
  .stage-scrubber {
    top: 48px;
  }
  .map-core,
  .compressed-stage,
  .source-stage {
    inset: 64px 14px 14px;
  }
  .stage-phases {
    display: none;
  }
  .lane-col {
    padding: 14px 12px;
  }
  .lane-name {
    font-size: 0.62rem;
    letter-spacing: 0.14em;
  }
  .lane-index {
    font-size: 0.56rem;
  }
  .engine-notes {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .engine-hero { width: min(1240px, 92vw); }
  .engine-stage {
    width: 100vw;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .compressed-card,
  .code-card {
    width: min(82vw, 320px);
  }
  .code-card {
    height: clamp(260px, 38vh, 340px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .engine-scroll {
    min-height: auto;
  }
  .engine-stage {
    position: relative;
    top: 0;
    min-height: 1400px;
  }
  .map-edge,
  .capsule-halo {
    animation: none !important;
  }
}
