/* The scroll story (home page). One sticky stage behind every beat: the WebGL canvas, a DOM layer
   for sharp recreations, a veil so the words always read, and a live layer for anything a visitor
   can press. Each beat is a real section with its words; its height sets how long it plays.
   Without JavaScript the stage stays out of the way and the beats read as plain text in order. */

/* the bar floats over the stage on the home page */
body:has(.story-main) .bar { position: fixed; left: 0; right: 0; top: 0; z-index: 30; }
body:has(.story-main) .bar::before {
  content: ''; position: absolute; inset: 0 calc(50% - 50vw) -24px; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, rgba(14, 15, 17, 0.86), rgba(14, 15, 17, 0.5) 60%, rgba(14, 15, 17, 0));
}
.story-main { position: relative; }

.story { position: relative; }
.story-stage { display: none; }
.story-js .story-stage {
  display: block; position: sticky; top: 0; height: 100vh; margin-bottom: -100vh; overflow: hidden; z-index: 0;
}
.story-gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; }
.story.has-gl .story-gl { opacity: 1; }
.story.no-gl .story-gl { display: none; }
.story-dom, .story-live { position: absolute; inset: 0; pointer-events: none; }
.story-live > .beat-art > * { pointer-events: auto; }
.beat-art { display: none; }
.beat-art.is-mounted { display: block; }

/* a quiet floor under the words */
.story-veil {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(14, 15, 17, 0.9) 0%, rgba(14, 15, 17, 0.68) 26%, rgba(14, 15, 17, 0) 46%),
    linear-gradient(0deg, rgba(14, 15, 17, 0.7) 0%, rgba(14, 15, 17, 0) 22%);
}

/* without WebGL: a still, composed field (beats 1 to 3), faded out by beat 4 */
.story-flat { display: none; position: absolute; inset: 0; }
.story.no-gl .story-flat { display: block; }
.story-flat i {
  position: absolute; aspect-ratio: 8 / 5; border-radius: 10px; background: #17181b;
  border: 2px solid rgba(98, 189, 140, 0.35); box-shadow: 0 0 60px -10px rgba(98, 189, 140, 0.25);
}
.story-flat i:nth-child(1) { right: 7%; top: 22%; aspect-ratio: 640 / 690; width: 26%; border-color: rgba(226, 166, 76, 0.6); box-shadow: 0 0 90px -10px rgba(226, 166, 76, 0.35); }
.story-flat i:nth-child(2) { width: 16%; right: 40%; top: 12%; opacity: 0.5; }
.story-flat i:nth-child(3) { width: 12%; right: 2%; top: 70%; opacity: 0.4; border-color: rgba(141, 145, 153, 0.4); box-shadow: none; }
.story-flat i:nth-child(4) { width: 10%; right: 38%; top: 64%; opacity: 0.3; border-color: rgba(112, 166, 219, 0.4); box-shadow: none; }
.story-flat i:nth-child(5) { width: 8%; right: 30%; top: 6%; opacity: 0.25; }
.story-flat i:nth-child(6) { width: 9%; right: 52%; top: 40%; opacity: 0.2; border-color: rgba(220, 136, 171, 0.4); box-shadow: none; }

/* ---- the beats ---- */
.beat { position: relative; z-index: 1; display: flex; flex-direction: column; pointer-events: none; }
.beat-copy {
  pointer-events: auto; position: relative; max-width: 30rem;
  margin-left: max(124px, 8.5vw); padding: 24px 0;
}
.story-js .beat:not(.beat-start) .beat-copy { position: sticky; top: 30vh; }
.beat-copy.is-off { pointer-events: none; }
.beat h2 { font-size: clamp(36px, 4.2vw, 62px); line-height: 1.02; letter-spacing: -0.03em; font-weight: 600; margin: 0; text-wrap: balance; }
.beat-copy > p { margin: 18px 0 0; font-size: clamp(17px, 1.4vw, 20px); line-height: 1.5; color: var(--fg-2); max-width: 30ch; }
.beat-more {
  display: inline-block; margin-top: 22px; font-size: 15px; color: var(--fg); text-decoration: none;
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat; padding-bottom: 2px;
  transition: background-size 400ms var(--ease);
}
.beat-more::after { content: ' \2192'; color: var(--fg-3); }
.beat-more:hover, .beat-more:focus-visible { background-size: 100% 1px; }

.beat-start .beat-copy {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: flex-end; max-width: 40rem;
  padding: 120px 0 clamp(48px, 10vh, 120px);
}
.beat-start h1 { margin: 0 0 clamp(28px, 3.4vw, 48px); line-height: 0; }
.start-mark .lockup { height: clamp(72px, 9.5vw, 148px); width: auto; }
/* the headline waits for the light to settle; the engine fades it in. If the engine never runs, it
   still arrives on its own a few seconds in. */
.beat-start .beat-copy { opacity: 0; animation: story-late 900ms var(--ease) 4.5s forwards; }
@keyframes story-late { to { opacity: 1; } }
.beat-join .beat-copy .join { max-width: 520px; }

/* ---- the dot rail ---- */
.story-rail { display: none; }
.story.is-live .story-rail { display: block; position: sticky; top: 50vh; height: 0; z-index: 12; }
.story-rail ol { list-style: none; margin: 0; padding: 0; position: absolute; left: 22px; top: 0; transform: translateY(-50%); display: grid; gap: 4px; }
.story-rail a { display: flex; align-items: center; gap: 12px; height: 22px; padding-right: 8px; text-decoration: none; color: var(--fg-3); }
.story-rail .dot {
  width: 7px; height: 7px; border-radius: 50%; background: rgba(228, 229, 232, 0.28); flex: none; margin-left: 4px;
  transition: transform 300ms var(--ease), background-color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.story-rail .lab {
  font-size: 13px; white-space: nowrap; opacity: 0; transform: translateX(-4px);
  transition: opacity 240ms var(--ease), transform 240ms var(--ease);
  background: rgba(14, 15, 17, 0.8); padding: 2px 6px; border-radius: 5px;
}
.story-rail a:hover .lab, .story-rail a:focus-visible .lab { opacity: 1; transform: none; color: var(--fg); }
.story-rail a:hover .dot { background: var(--fg-2); }
.story-rail a[aria-current] .dot { background: var(--fg); transform: scale(1.45); box-shadow: 0 0 0 4px rgba(228, 229, 232, 0.08); }
.story-rail:hover a[aria-current] .lab { opacity: 1; transform: none; }

/* ---- beat 3: the question, lifted out of the tile as a real card ---- */
.ask-card {
  position: absolute; left: 0; top: 0; width: 360px; padding: 11px 13px 13px; border-radius: 8px;
  background: rgba(23, 24, 27, 0.95); border: 1px solid var(--amber-line);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 24px 60px -12px rgba(0, 0, 0, 0.7), 0 0 80px -20px rgba(226, 166, 76, 0.35);
  font-size: 12.5px; line-height: 1.5; --k: 1; transform-origin: 0 0;
  opacity: 0; transform: translateY(8px) scale(var(--k));
  transition: opacity 500ms var(--ease), transform 500ms var(--ease);
}
.ask-card[hidden] { display: none; }
.ask-card.in { opacity: 1; transform: scale(var(--k)); }
.ask-h { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--fg); margin-bottom: 6px; }
.ask-h .ic { width: 13px; height: 13px; color: var(--amber); flex: none; }
.ask-who { font-weight: 500; }
.ask-what { margin-left: auto; color: var(--amber); font-size: 11.5px; }
.ask-q { margin: 0 0 11px; color: var(--fg); }
.ask-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-btn {
  font: 500 12px/1 var(--font-ui); color: var(--fg); cursor: pointer; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.04);
  transition: background 200ms var(--ease), border-color 200ms var(--ease), transform 140ms var(--ease);
}
.ask-btn:hover { border-color: rgba(255, 255, 255, 0.32); background: rgba(255, 255, 255, 0.08); }
.ask-btn.primary { background: #6aa3d8; border-color: #6aa3d8; color: #0d1a26; }
.ask-btn.primary:hover { background: #82b3e0; border-color: #82b3e0; }
.ask-btn.press { transform: scale(0.96); }
.ask-ptr {
  position: absolute; left: 0; top: 0; width: 22px; height: 22px; pointer-events: none !important;
  opacity: 0; transition: opacity 300ms var(--ease); filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}
.ask-ptr.on { opacity: 1; }
.story.no-gl .ask-card { left: auto; }

/* ---- beats 4 and 5: the window. The engine sets --o --t --x --spin --s --dx --dy --lab on the rig ---- */
.sw-rig {
  --o: 0; --t: 0; --x: 0; --spin: 0; --s: 1; --dx: 0px; --dy: 0px; --lab: 0;
  --tx: 46deg; --tz: -24deg; --d: 104px;
  position: absolute; left: 0; top: 0; width: 800px;
  opacity: var(--o); visibility: hidden;
  transform-style: preserve-3d; transform-origin: 50% 50%;
  transform:
    perspective(2400px) translate(var(--dx), var(--dy))
    translateY(calc(var(--t) * -2% + var(--x) * 6%))
    scale(calc(var(--s) * (1 - var(--t) * 0.22 - var(--x) * 0.12)))
    rotateX(calc(var(--t) * var(--tx)))
    rotateZ(calc(var(--t) * var(--tz) + var(--spin) * 1deg));
}
.sw-rig.is-on { visibility: visible; }
.sw-rig .demo-frame { border-radius: 12px; }
.sw-rig .demo-frame, .sw-rig .pui-stage, .sw-rig .pui-win, .sw-rig .pui-grid, .sw-rig .pui-tile { transform-style: preserve-3d; }
.sw-rig.is-x .demo-frame, .sw-rig.is-x .pui-win, .sw-rig.is-x .pui-tile { overflow: visible; }
.sw-rig .pui-top { position: relative; }
.sw-rig .pui-term { scrollbar-width: none; }
.sw-count { visibility: hidden; }
/* the small window keeps the lead and the agent that is about to ask; lines run off the edge like
   a real terminal (the light-drawn tiles do not wrap either) */
.sw-rig .demo-frame.sm .demo-grid { grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr); }
.sw-rig .demo-frame.sm .demo-a { grid-row: auto; }
.sw-rig .demo-frame.sm .demo-c { display: flex; }
.sw-rig .demo-frame .pui-term { white-space: pre; }
.sw-rig.is-asking .sw-count { visibility: visible; }

/* the floor the window floats over while it is tilted */
.sw-floor {
  position: absolute; left: -34%; right: -34%; top: -42%; bottom: -42%;
  transform: translateZ(-140px); pointer-events: none; opacity: var(--t);
  background:
    radial-gradient(closest-side, rgba(0, 0, 0, 0.55), transparent 72%) center / 78% 70% no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 56px 56px;
  -webkit-mask-image: radial-gradient(closest-side, #000 30%, transparent 100%);
  mask-image: radial-gradient(closest-side, #000 30%, transparent 100%);
}
.sw-rig .pui-win { position: relative; box-shadow: 0 calc(30px + var(--t) * 50px) calc(80px + var(--t) * 60px) rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4); }
.sw-rig .pui-win::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(128deg, rgba(255, 255, 255, 0.07), transparent 38%, transparent 70%, rgba(255, 255, 255, 0.03));
  opacity: var(--t);
}

/* the layers, lifted by --x; depths in app pixels */
.sw-rig .pui-top { transform: translate3d(0, calc(var(--x) * -34px), calc(var(--x) * var(--d) * 0.8)); }
.sw-rig .pui-grid > .pui-tile {
  transform: translate3d(calc(var(--x) * var(--ddx, 0px)), calc(var(--x) * var(--ddy, 0px)), calc(var(--x) * var(--d) * var(--k, 1.6)));
  box-shadow: inset 0 1px 0 var(--hi), 0 calc(var(--x) * 34px) calc(var(--x) * 70px) rgba(0, 0, 0, calc(var(--x) * 0.55));
}
.sw-rig .pui-grid > .demo-a { --ddx: -28px; }
.sw-rig .pui-grid > .demo-b { --k: 2; --ddx: 34px; --ddy: -14px; }
.sw-rig .pui-grid > .demo-c { --k: 2.4; --ddx: 34px; --ddy: 22px; }
.sw-rig .pui-tile > .pui-term {
  transform: translateZ(calc(var(--x) * var(--d) * 1.3)); border-radius: 6px;
  background: rgba(23, 24, 27, calc(var(--x) * 0.88));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, calc(var(--x) * 0.09)), 0 calc(var(--x) * 24px) calc(var(--x) * 50px) rgba(0, 0, 0, calc(var(--x) * 0.5));
}
.sw-rig .pui-tile > .pui-th { transform: translateZ(calc(var(--x) * var(--d) * 0.5)); }
.sw-rig #sw-wk { transform: translateZ(calc(var(--x) * var(--d) * 2)); }
.sw-rig #sw-pend {
  position: relative; transform: translateZ(calc(var(--x) * var(--d) * 3.2)); border-radius: 8px;
  background: rgba(23, 24, 27, calc(var(--x) * 0.94));
  box-shadow:
    0 0 0 1px rgba(226, 166, 76, calc(var(--x) * 0.55)),
    0 0 calc(var(--x) * 90px) rgba(226, 166, 76, calc(var(--x) * 0.28)),
    0 calc(var(--x) * 40px) calc(var(--x) * 80px) rgba(0, 0, 0, calc(var(--x) * 0.5));
}

/* callouts, written in the plane of the layer they name */
.sw-lab {
  position: absolute; z-index: 2; white-space: nowrap; pointer-events: none;
  font: 500 34px/1 var(--font-ui); letter-spacing: -0.015em; color: rgba(228, 229, 232, 0.9);
  opacity: var(--lab); display: flex; align-items: center; gap: 14px;
}
.sw-lab::before { content: ''; width: 80px; height: 1px; background: rgba(255, 255, 255, 0.34); order: 2; }
.sw-lab-l { right: calc(100% + 22px); }
.sw-lab-r { left: calc(100% + 22px); }
.sw-lab-r::before { order: 0; }
.sw-lab-top { top: 5px; }
.sw-lab-term { top: calc(100% + 18px); right: auto; left: 10px; transform: translateZ(calc(var(--x) * var(--d) * 1.3)); }
.sw-lab-term::before { display: none; }
.sw-lab-tile { top: 50%; }
.sw-lab-q { top: auto; bottom: calc(100% + 14px); left: 4px; color: var(--amber); }
.sw-lab-q::before { display: none; }

/* ---- phones: words at the bottom over the veil, art above, a thin rail ---- */
@media (max-width: 899px) {
  .story-veil {
    background:
      linear-gradient(0deg, rgba(14, 15, 17, 0.96) 0%, rgba(14, 15, 17, 0.86) 34%, rgba(14, 15, 17, 0) 50%),
      linear-gradient(180deg, rgba(14, 15, 17, 0.7) 0%, rgba(14, 15, 17, 0) 12%);
  }
  .beat-copy { margin: 0 20px 0 28px; }
  .story-js .beat { justify-content: flex-end; }
  .story-js .beat:not(.beat-start) .beat-copy { top: auto; bottom: 0; padding-bottom: 28px; }
  .beat h2 { font-size: clamp(30px, 8.4vw, 40px); }
  .beat-copy > p { font-size: 16px; margin-top: 12px; }
  .beat-more { margin-top: 14px; }
  .beat-start .beat-copy { justify-content: flex-start; padding-top: 96px; min-height: 0; }
  .story-js .beat-start { justify-content: flex-start; }
  .start-mark .lockup { height: clamp(52px, 15vw, 76px); }
  .beat-start .beat-copy::before {
    content: ''; position: absolute; inset: -24px -20px -90px -28px; z-index: -1; pointer-events: none;
    background: linear-gradient(180deg, rgba(14, 15, 17, 0.94) 0%, rgba(14, 15, 17, 0.86) 72%, rgba(14, 15, 17, 0));
  }
  .sw-rig { --tx: 40deg; --tz: -14deg; --d: 44px; }
  .story-rail ol { left: 7px; gap: 2px; }
  .story-rail a { height: 16px; gap: 8px; }
  .story-rail .dot { width: 5px; height: 5px; margin-left: 0; }
  .story-rail .lab { display: none; }
  .story-rail a:focus-visible .lab { display: inline; }
  .ask-card { font-size: 13.5px; }
  .ask-btn { font-size: 13px; }
  .story-flat i:nth-child(1) { width: 62%; right: 19%; top: 12%; }
  .story-flat i:nth-child(2) { width: 30%; right: 64%; top: 8%; }
}

/* reduced motion: every beat shows a still frame; nothing fades or slides */
@media (prefers-reduced-motion: reduce) {
  .beat-start .beat-copy { opacity: 1; animation: none; }
  .ask-card, .ask-btn, .ask-ptr, .story-rail .dot, .story-rail .lab, .beat-more { transition: none; }
}

/* the lockup sits on a soft wash so the field behind it never crosses the letters */
@media (min-width: 900px) {
  .beat-start .beat-copy { position: relative; isolation: isolate; }
  .beat-start .beat-copy::before {
    content: ''; position: absolute; z-index: -1; pointer-events: none;
    left: -14vw; right: -10vw; bottom: -12vh; height: 78vh;
    background: radial-gradient(72% 62% at 42% 64%, rgba(14, 15, 17, 0.94), rgba(14, 15, 17, 0.8) 52%, rgba(14, 15, 17, 0));
  }
}
