/* Chapters that follow the hero: Engineer and Builder.
   Shares tokens (--ink, --accent, --panel-*, --display…) with hero.css.
   Every element's resting style here is its final, visible state; js/chapters.js
   only adds the motion, so the page reads fine without it. */

.chapters {
  --pad: max(20px, 5.5vw);
  --line: color-mix(in srgb, var(--ink) 14%, transparent);
  position: relative;
  z-index: 1;
  /* Glows and drifting text may extend past the edges; clip them so the page
     never scrolls sideways. clip (not hidden) keeps sticky pinning working. */
  overflow-x: clip;
}

.chapter {
  padding: 0 var(--pad);
}

.tag {
  margin: 0 0 1rem;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.chips li {
  padding: 0.42em 0.85em;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ---------- Odometer digits (js/chapters.js builds the columns) ---------- */

.odo {
  display: inline-flex;
  line-height: 1;
}

.odo__col {
  position: relative;
  display: inline-block;
  height: 1em;
  overflow: hidden;
}

/* Invisible final digit: sets the column's width. */
.odo__ghost {
  visibility: hidden;
}

.odo__stack {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.odo__stack span {
  height: 1em;
}

/* ---------- Opener ---------- */

.opener {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  min-height: 100svh;
  padding: 18vh 0 14vh;
}

.opener__num {
  position: absolute;
  top: 18vh;
  left: 0;
  margin: 0;
  color: var(--accent);
  font-family: var(--display);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  letter-spacing: 0.04em;
}

.opener__title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(5.5rem, 18.5vw, 17rem);
  font-weight: 400;
  line-height: 0.86;
  text-transform: uppercase;
}

.opener__title .char {
  display: inline-block;
}

.opener__lede {
  max-width: 9em;
  margin: 0;
  padding-bottom: 1.2rem;
  font-size: clamp(1.25rem, 2.1vw, 1.9rem);
  line-height: 1.3;
  text-align: right;
}

/* ---------- HRX ---------- */

.hrx {
  padding: 5svh 0 14vh;
  text-align: center;
}

.hrx__title {
  max-width: 14em;
  margin: 0 auto;
  font-family: var(--display);
  font-size: clamp(2rem, min(4.5vw, 7svh), 4.25rem);
  font-weight: 400;
  line-height: 1;
  text-transform: uppercase;
  text-wrap: balance;
}

.hrx__title .word {
  display: inline-block;
}

/* Sized by screen height too, so the headline and the screenshot always fit
   on one screen together; the cards follow below. */
.hrx__stage {
  position: relative;
  width: min(980px, 100%, calc((100svh - 300px) * 1.62));
  margin: clamp(20px, 3svh, 48px) auto 0;
  perspective: 1600px;
  isolation: isolate;
}

/* Accent glow behind the screenshot; stronger in dark mode. */
.hrx__glow {
  position: absolute;
  z-index: -1;
  inset: -22% -16% -14%;
  opacity: var(--shot-glow);
  pointer-events: none;
}

/* Inner layer carries the gradient so scroll can fade it independently. */
.hrx__glow-inner {
  width: 100%;
  height: 100%;
  background: radial-gradient(
    closest-side,
    color-mix(in srgb, var(--accent) 42%, transparent) 0%,
    color-mix(in srgb, var(--accent) 16%, transparent) 50%,
    transparent 100%
  );
}

.hrx__shot {
  display: block;
  transform-origin: 50% 100%;
}

.browser {
  display: block;
  overflow: hidden;
  border-radius: 18px;
  background: #111;
  box-shadow:
    0 30px 70px -22px rgba(30, 20, 10, 0.45),
    0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
  transition: box-shadow 0.3s;
}

.browser__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #1b1b1d;
}

.browser__bar i {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #3a3a3d;
}

.browser__url {
  margin-left: 14px;
  padding: 5px 14px;
  border-radius: 999px;
  background: #2a2a2d;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
}

.browser img {
  display: block;
  width: 100%;
  height: auto;
}

/* Sticker: the outer layer turns with scroll, the face does the "slap". */
.sticker {
  position: absolute;
  top: clamp(24px, 6%, 60px);
  left: clamp(-70px, -5vw, -16px);
  width: clamp(112px, 12vw, 168px);
  aspect-ratio: 1;
  pointer-events: none;
}

.sticker__face {
  display: grid;
  place-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  text-align: center;
  transform: rotate(-12deg);
  box-shadow: 0 18px 36px -12px color-mix(in srgb, var(--accent) 55%, transparent);
}

.sticker__num {
  font-family: var(--display);
  font-size: clamp(2.3rem, 4vw, 3.6rem);
  line-height: 0.9;
}

.sticker__label {
  margin-top: 4px;
  font-size: clamp(0.625rem, 0.85vw, 0.75rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.25;
  text-transform: uppercase;
}

.pill__arrow {
  display: inline-block;
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.pill:hover .pill__arrow {
  transform: translate(3px, -3px);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  width: min(1100px, 100%);
  margin: 34px auto 0;
  padding: 0;
  list-style: none;
  perspective: 1200px;
  text-align: left;
}

.card {
  padding: 24px 24px 26px;
  border-radius: 24px;
  background: var(--glow);
  transform-origin: 50% 100%;
}

.card__num {
  color: var(--accent);
  font-family: var(--display);
  font-size: 1.9rem;
}

.card__title {
  margin: 10px 0 6px;
  font-size: 1.125rem;
  font-weight: 700;
}

.card__body {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.hrx__engine {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.hrx__engine strong {
  color: var(--ink);
}

/* ---------- automation panel ---------- */

.automation {
  padding: 4vh 0 10vh;
}

.automation__panel {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  grid-template-areas:
    "copy flow"
    "rows rows";
  gap: clamp(24px, 3vw, 44px) clamp(32px, 5vw, 72px);
  padding: clamp(28px, 4vw, 60px);
  border-radius: 44px;
  background: var(--panel-bg);
  color: var(--panel-ink);
}

.automation__title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.4rem, 3.9vw, 3.9rem);
  font-weight: 400;
  line-height: 1;
  text-transform: uppercase;
  text-wrap: balance;
}

.automation__copy {
  grid-area: copy;
}

/* With motion, the panel pins while the graph sorts itself out
   (js/automation.js adds .is-pinned when the panel fits the screen). */
.automation.is-pinned::after {
  content: "";
  display: block;
  height: 110svh;
}

.automation.is-pinned .automation__panel {
  position: sticky;
  top: max(84px, calc(50svh - var(--panel-h, 600px) / 2));
}

.flow {
  grid-area: flow;
  align-self: center;
  margin: 0;
}

.flow__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.flow__edge {
  fill: none;
  stroke: var(--panel-ink);
  stroke-width: 1.5;
}

.flow__node {
  fill: var(--panel-bg);
  stroke: var(--panel-ink);
  stroke-opacity: 0.7;
  stroke-width: 1.4;
}

.flow__node--end {
  fill: var(--accent);
  stroke: none;
}

.flow__call {
  fill: var(--accent);
}

.flow__legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--panel-muted);
  font-size: 0.8125rem;
}

.flow__legend b {
  color: var(--panel-ink);
  font-variant-numeric: tabular-nums;
}

.flow__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.flow__sep {
  opacity: 0.5;
}

.automation__body {
  max-width: 26em;
  margin: 22px 0 0;
  color: var(--panel-muted);
  font-size: clamp(1rem, 1.25vw, 1.125rem);
  line-height: 1.55;
}

.automation__rows {
  grid-area: rows;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(20px, 3vw, 48px);
  margin: 0;
}

.automation__row {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 16px;
}

.automation__rule {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.5px;
  background: var(--panel-line);
  transform-origin: 0 50%;
}

.automation__num {
  font-family: var(--display);
  font-size: clamp(3rem, 4.6vw, 4.6rem);
  line-height: 0.9;
}

.automation__num--accent {
  color: var(--accent);
}

.automation__row dd {
  margin: 0;
  color: var(--panel-muted);
  font-size: clamp(0.9375rem, 1.1vw, 1.0625rem);
  text-align: right;
}

/* ---------- Also shipped ---------- */

.also {
  padding: 4vh 0 6vh;
}

.also__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}

.also__tag {
  margin: 0;
}

.also__note {
  color: var(--muted);
  font-size: 0.875rem;
}

.also__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  perspective: 1400px;
}

.mini {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(26px, 2.6vw, 36px);
  border-radius: 32px;
  background: var(--glow);
  overflow: hidden;
  isolation: isolate;
}

/* Hover spotlight: follows the cursor (JS sets --mx / --my). */
.mini::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(
    320px circle at var(--mx, 50%) var(--my, 50%),
    color-mix(in srgb, var(--accent) 14%, transparent),
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.mini.is-hovered::after {
  opacity: 1;
}

.mini__kicker {
  margin: 0 0 18px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mini__big {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(4rem, 7.2vw, 6.5rem);
  line-height: 0.82;
  text-transform: uppercase;
}

.mini__big small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-family: var(--body);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.mini__word {
  display: inline-block;
  transform-origin: 0 100%;
}

.mini__copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1.5px solid var(--line);
}

.mini__title {
  margin: 0 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
}

.mini__body {
  max-width: 30em;
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.mini .chips {
  margin: auto 0 0;
  padding-top: 16px;
}

/* Card 1: faint field of "data points", densest on the right. */
.mini__dots {
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: -10%;
  width: 140%;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--ink) 22%, transparent) 1.2px, transparent 1.6px);
  background-size: 14px 14px;
  -webkit-mask-image: linear-gradient(115deg, transparent 30%, #000 75%);
  mask-image: linear-gradient(115deg, transparent 30%, #000 75%);
  opacity: 0.55;
  pointer-events: none;
}

/* The scan line that sweeps down the card (hidden until it plays). */
.mini__scan {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 18px 4px color-mix(in srgb, var(--accent) 55%, transparent);
  opacity: 0;
  pointer-events: none;
}

/* Decoding letters keep their final width; the glyph is drawn on top. */
.dec {
  position: relative;
  display: inline-block;
}

.dec.is-scrambling {
  color: transparent;
}

.dec.is-scrambling {
  overflow: hidden;
}

.dec.is-scrambling::after {
  content: attr(data-glyph);
  position: absolute;
  inset: 0;
  color: var(--accent);
  text-align: center;
}

/* Before the scan starts, the raw characters sit quietly in muted ink. */
.is-raw .dec.is-scrambling::after {
  color: color-mix(in srgb, var(--muted) 55%, transparent);
}

/* Card 2: coverage ring and test marks. */
.mini__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.ring {
  flex: none;
  width: clamp(88px, 8vw, 116px);
  height: auto;
}

.ring circle {
  fill: none;
  stroke-width: 10;
}

.ring__track {
  stroke: var(--line);
}

.ring__fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.mini__num {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.ticks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.tick {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  color: transparent;
  font-size: 0.75rem;
  font-weight: 700;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}

.tick.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.tick.is-popping {
  transform: scale(1.25);
}

/* ---------- Hand-off to Builder ---------- */

/* With motion on (html.has-motion), the track is tall and the stage pins
   while the pill floods the screen. Without it, it's a plain closing line. */
.handoff {
  position: relative;
  margin: 0 calc(var(--pad) * -1);
}

.handoff__stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 14vh var(--pad) 20vh;
  overflow: hidden;
}

.has-motion .handoff {
  height: 240svh;
}

.has-motion .handoff__stage {
  position: sticky;
  top: 0;
  height: 100svh;
  padding-top: 0;
  padding-bottom: 0;
}

.handoff__line {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.4rem, 5.8vw, 5.25rem);
  line-height: 0.95;
  text-transform: uppercase;
}

.handoff__a,
.handoff__b {
  display: block;
}

.handoff__b {
  color: var(--accent);
}

.handoff__next {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 22px 34px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--display);
  font-size: clamp(1.4rem, 2vw, 1.9rem);
  text-transform: uppercase;
}

.handoff__label {
  position: relative;
  z-index: 1;
}

/* Starts as a dot inside the pill and grows to cover the screen. */
.handoff__flood {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  pointer-events: none;
}

/* What the flood reveals: the next chapter's name. */
.handoff__reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--on-accent);
  font-family: var(--display);
  font-size: clamp(5rem, 16vw, 15rem);
  line-height: 0.86;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
}

.handoff__num {
  margin-bottom: clamp(0.9rem, 2.4vw, 2.2rem); /* room for the word's bars */
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  letter-spacing: 0.04em;
}

/* BUILDER resolves out of vertical bars (js/builder.js sets the mask). */
.handoff__word {
  display: block;
  transform-origin: 50% 50%;
}

.handoff__tagline {
  margin-top: 1.4rem;
  font-size: clamp(1.4rem, 2.6vw, 2.4rem);
  line-height: 1;
}

/* ---------- Teaching: spark → forty builders ---------- */

/* Resting state: every seat a solid builder, every stat shown. With motion,
   js/chapters.js pins the stage (.is-pinned) and drives it with the scroll. */
.teach {
  --seat: clamp(30px, 3.5vw, 54px);
  --seat-gap: calc(var(--seat) * 0.3);
  --seat-bg: color-mix(in srgb, var(--ink) 7%, var(--bg));
  --seat-line: color-mix(in srgb, var(--ink) 14%, transparent);
  padding: 10vh 0;
}

.teach.is-pinned {
  height: 340svh;
  padding: 0;
}

.teach__stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(32px, 6vw, 110px);
}

.teach.is-pinned .teach__stage {
  position: sticky;
  top: 0;
  height: 100svh;
}

.teach__title {
  position: relative;
  margin: 0 0 1.4rem;
  font-family: var(--display);
  font-size: clamp(3.4rem, 8vw, 8.5rem);
  font-weight: 400;
  line-height: 0.92;
  text-transform: uppercase;
}

/* Where the spark is born: just after the full stop. */
.teach__origin {
  display: inline-block;
  width: 0.3em;
}

.teach__line {
  max-width: 30em;
  margin: 0 0 2rem;
  font-size: clamp(1rem, 1.35vw, 1.25rem);
  line-height: 1.5;
}

.teach__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.8rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.875rem;
}

.teach__stats li {
  transition: opacity 0.35s ease;
}

.teach__stats li.is-dim {
  opacity: 0.28;
}

.teach__stats b {
  margin-right: 0.2em;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(1.6rem, 2.4vw, 2.3rem);
  font-weight: 400;
}

.teach__field {
  position: relative;
}

.teach__topic {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.teach__topic em {
  color: var(--accent);
  font-style: normal;
}

.teach__now[hidden] {
  display: none;
}

.teach__seats {
  display: grid;
  grid-template-columns: repeat(8, var(--seat));
  gap: var(--seat-gap);
}

/* --f: 0 = a curious "?", 1 = a builder (solid accent). */
.teach-seat {
  --f: 1;
  position: relative;
  display: grid;
  place-items: center;
  width: var(--seat);
  height: var(--seat);
  overflow: hidden;
  border: 1.5px solid var(--seat-line);
  border-radius: 22%;
  background: var(--seat-bg);
  color: var(--muted);
  font-family: var(--display);
  font-size: calc(var(--seat) * 0.5);
}

.teach-seat::after {
  content: "";
  position: absolute;
  inset: -2px;
  background: var(--accent);
  opacity: var(--f);
}

.teach-seat span {
  opacity: calc(1 - var(--f) * 2);
}

/* The spark and its copies, flying from the headline to their seats. */
.teach__sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.teach-spark {
  position: absolute;
  top: 0;
  left: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 24%, transparent);
  opacity: 0;
  will-change: transform, opacity;
}

@media (max-width: 899px) {
  .teach {
    /* Eight seats across, sized to the screen. */
    --seat: min(34px, (100vw - 2 * max(20px, 5.5vw)) / 10.4);
  }

  .teach__stage {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 20px;
  }

  .teach.is-pinned .teach__stage {
    padding-top: 56px; /* clear of the navbar */
  }

  .teach__title {
    margin-bottom: 0.8rem;
    font-size: clamp(2.6rem, 12vw, 4.2rem);
  }

  .teach__line {
    margin-bottom: 1rem;
    font-size: 0.95rem;
  }

  .teach__stats {
    gap: 0.4rem 1.1rem;
    font-size: 0.8125rem;
  }

  .teach__stats b {
    font-size: 1.45rem;
  }

  .teach__field {
    justify-self: center;
  }

  .teach__topic {
    margin-bottom: 0.7rem;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 899px) {
  .opener {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    min-height: 80svh;
  }

  .opener__lede {
    max-width: none;
    text-align: left;
  }

  .sticker {
    left: -8px;
    top: -36px;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .automation__panel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "copy"
      "flow"
      "rows";
    border-radius: 28px;
  }

  .automation__rows {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .also__grid {
    grid-template-columns: 1fr;
  }

  .handoff__stage {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
  }
}
