/* film.css
   The landing film. Two layouts from one set of chapters:
   - still (the default, reduced motion, no WebGL): each chapter is a full
     screen still frame, a poster rendered from the film's own scene, with its
     words over it;
   - live (html.film-live): one pinned stage, the Loop in WebGL behind, the
     camera moving with the scroll and the words arriving when it settles.
   Side layout in landscape (words left, Loop right); stacked in portrait
   (Loop above, words below). */

html.mode-app .film { display: none; }
html.mode-film .site-header, html.mode-film #app, html.mode-film .skip { display: none; }

.film { position: relative; background: var(--bg); color: var(--ink); }

/* ── Chrome: the top bar, the chapter ticks, the disclosure ──────────── */
.film-bar {
  position: fixed; inset: 0 0 auto 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) var(--film-x) 14px; pointer-events: none;
}
.film-bar > * { pointer-events: auto; }
.film-bar-mark { font-size: 24px; transition: opacity 700ms ease; }
html.at-hero .film-bar-mark { opacity: 0; }
.scroll-cue { transition: opacity 700ms ease; }
html.film-live:not(.at-hero) .scroll-cue { opacity: 0; }
.film-bar-signin {
  background: none; border: 0; padding: 10px 2px; min-height: 44px; cursor: pointer; color: var(--ink);
  font-family: var(--font-body); font-weight: 500; font-size: 15px;
  text-decoration: underline; text-decoration-color: rgba(243, 237, 231, 0.3); text-underline-offset: 5px; text-decoration-thickness: 1px;
  transition: text-decoration-color 160ms ease;
}
.film-bar-signin:hover { text-decoration-color: var(--ink); }
.film-ticks {
  position: fixed; left: var(--film-x); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; gap: 6px; align-items: center;
}
.film-ticks button { width: 18px; height: 24px; padding: 0; border: 0; background: none; cursor: pointer; position: relative; }
.film-ticks button::before { content: ''; position: absolute; left: 0; right: 0; top: 11px; height: 2px; border-radius: 1px; background: rgba(243, 237, 231, 0.28); transition: background-color 600ms ease, transform 600ms ease; }
.film-ticks button.is-on { width: 34px; }
.film-ticks button.is-on::before { background: var(--accent); }
.film-disclosure {
  position: fixed; right: var(--film-x); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  font-size: 12px; color: var(--ink-2); margin: 0;
}

:root { --film-x: clamp(20px, 6.5vw, 112px); }

/* ── Type ─────────────────────────────────────────────────────────────── */
.hero-wordmark { font-family: 'Pacifico', cursive; color: var(--accent); font-size: clamp(40px, 4.4vw, 66px); line-height: 1.3; margin: 0 0 6px -2px; }
.ch-title {
  font-family: var(--font-display); font-weight: 600; color: var(--ink);
  font-size: clamp(34px, 4.3vw, 66px); line-height: 1.02; letter-spacing: -0.032em; text-wrap: balance;
}
.ch-title-xl { font-size: clamp(46px, 6.4vw, 104px); line-height: 0.96; letter-spacing: -0.04em; }
.ch-lede { margin-top: 22px; font-size: clamp(17px, 1.3vw, 20px); line-height: 1.5; color: var(--ink-2); max-width: 36ch; text-wrap: pretty; }
.ch-small { margin-top: 26px; font-size: 15px; color: var(--ink-2); max-width: 36ch; }
.ch-fine { margin-top: 18px; font-size: 13px; color: var(--ink-2); }
.ch-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 34px; }

.phrases, .ring-labels, .facts { margin-top: 30px; display: grid; gap: 14px; }
.phrases li, .ring-labels li { display: flex; align-items: center; gap: 14px; font-size: clamp(18px, 1.55vw, 23px); line-height: 1.3; color: var(--ink); }
.anchor-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 4px rgba(11, 10, 9, 0.9); }
.anchor-line { display: none; }
.ring-labels li span:last-child, .phrases li span:last-child { text-shadow: 0 0 14px var(--bg), 0 0 4px var(--bg); }
.ring-ico { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid rgba(243, 237, 231, 0.55); flex: none; }
.ring-labels li[data-ring="0"] .ring-ico { border-color: var(--accent); }
.facts { gap: 0; border-top: 1px solid var(--line); max-width: 30em; }
.facts li { padding: 16px 0; border-bottom: 1px solid var(--line); font-size: clamp(17px, 1.4vw, 21px); line-height: 1.4; color: var(--ink); }

/* The example proposal of chapter 4. */
.demo-card {
  margin: 30px 0 0; width: min(340px, 100%); padding: 22px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--line-strong); display: grid; gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.demo-tag { font-size: 13px; color: var(--ink-2); }
.demo-title { font-family: var(--font-display); font-weight: 600; font-size: 24px; letter-spacing: -0.02em; line-height: 1.1; }
.demo-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.demo-chips li { display: inline-flex; align-items: baseline; gap: 8px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface-2); }
.demo-sym { font-weight: 600; font-size: 15px; }
.demo-usd { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.demo-approve { display: flex; align-items: center; gap: 12px; margin-top: 2px; padding: 8px 18px 8px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 600; justify-self: start; }
.demo-ring { width: 36px; height: 36px; transform: rotate(-90deg); }
.demo-ring circle { fill: none; stroke: rgba(42, 22, 11, 0.25); stroke-width: 3; }
.demo-ring .demo-ring-fill { stroke: var(--on-accent); stroke-dasharray: 119.4; stroke-dashoffset: 30; stroke-linecap: round; }

/* The scroll cue. */
.scroll-cue { position: absolute; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; justify-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); z-index: 3; }
.scroll-cue-line { width: 1px; height: 34px; background: linear-gradient(rgba(243, 237, 231, 0), rgba(243, 237, 231, 0.6)); transform-origin: top; animation: cue 2.6s cubic-bezier(.6, 0, .3, 1) infinite; }
@keyframes cue { 0% { transform: scaleY(0); } 50% { transform: scaleY(1); transform-origin: top; } 51% { transform-origin: bottom; } 100% { transform: scaleY(0); transform-origin: bottom; } }

/* ── Still layout (the default) ───────────────────────────────────────── */
.stage { position: relative; }
.stage-canvas { display: none; }
.stage-backdrop { display: none; }
.ch { position: relative; min-height: 100vh; min-height: 100svh; display: flex; overflow: hidden; isolation: isolate; }
.ch-poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
.ch::after { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.ch-copy { position: relative; }
.ch-loop { display: none; }

html.reveal .ch .r { opacity: 0; transition: opacity 900ms ease, transform 900ms ease; }
html.reveal .ch.is-in .r { opacity: 1; }
html.reveal .ch.is-in .r:nth-child(2) { transition-delay: 120ms; }
html.reveal .ch.is-in .r:nth-child(3) { transition-delay: 240ms; }
html.reveal .ch.is-in .r:nth-child(4) { transition-delay: 360ms; }

/* Side: words left, the Loop right. */
@media (orientation: landscape) {
  .ch { align-items: center; padding: 96px var(--film-x) 88px; }
  .ch::after { background: linear-gradient(90deg, rgba(11, 10, 9, 0.88) 0%, rgba(11, 10, 9, 0.62) 34%, rgba(11, 10, 9, 0) 58%); }
  .ch-copy { width: min(600px, 46vw); }
  .ch[data-ch="0"] .ch-copy { width: min(660px, 50vw); }
  .ch-approve .ch-copy { width: min(460px, 34vw); }
  .ch-begin { justify-content: flex-end; }
  .ch-begin::after { background: none; }
  .ch-begin .ch-copy { width: min(440px, 44vw); }
  .ch-begin .ch-loop { display: block; position: absolute; left: 0; top: 0; bottom: 0; width: 56%; z-index: -1; }
  .ch-begin .ch-loop-img { position: absolute; left: 50%; top: 50%; width: min(48vw, 78vh, 720px); transform: translate(-50%, -50%); }
}
/* Stacked: the Loop above, the words below. */
@media (orientation: portrait) {
  .ch { align-items: flex-end; padding: 0 20px calc(64px + env(safe-area-inset-bottom)); }
  .ch::after { background: linear-gradient(0deg, rgba(11, 10, 9, 0.94) 0%, rgba(11, 10, 9, 0.78) 34%, rgba(11, 10, 9, 0) 56%); }
  .ch-copy { width: 100%; padding-top: 52vh; }
  .ch[data-ch="0"] .ch-copy { padding-top: 46vh; }
  .ch-approve .ch-copy { padding-top: 34vh; }
  .ch-begin { flex-direction: column; align-items: stretch; justify-content: flex-end; padding-top: calc(64px + env(safe-area-inset-top)); }
  .ch-begin::after { background: none; }
  .ch-begin .ch-copy { padding-top: 0; }
  .ch-begin .ch-loop { display: block; height: 150px; position: relative; margin-bottom: 8px; }
  .ch-begin .ch-loop-img { position: absolute; left: 50%; top: 50%; width: 200px; transform: translate(-50%, -50%); }
  .ch-title-xl { font-size: clamp(42px, 11.6vw, 64px); }
  .ch-title { font-size: clamp(32px, 9vw, 48px); }
  .ch-lede { margin-top: 16px; }
  .ch-actions { margin-top: 26px; }
  .ch-actions .btn { flex: 1 1 140px; }
  .phrases, .ring-labels { margin-top: 22px; gap: 10px; }
  .demo-card { margin-top: 22px; }
  .film-disclosure { right: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); font-size: 12px; }
  .scroll-cue { display: none; }
}

/* ── Live layout ──────────────────────────────────────────────────────── */
html.film-live .film { height: calc(100vh + var(--film-scroll, 0px)); height: calc(100svh + var(--film-scroll, 0px)); }
html.film-live .stage { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; }
html.film-live .stage-backdrop {
  display: block; position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(ellipse 60% 70% at var(--loop-x, 68%) var(--loop-y, 50%), #19140f 0%, #0f0d0b 45%, var(--bg) 75%);
}
html.film-live .stage-canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; opacity: 0; transition: opacity 1200ms ease; }
html.film-live.canvas-on .stage-canvas { opacity: 1; }
html.film-live .ch { position: absolute; inset: 0; min-height: 0; z-index: 2; pointer-events: none; }
html.film-live .ch.is-active { pointer-events: auto; }
html.film-live .ch-poster { display: none; }
html.film-live .ch[data-ch="0"] .ch-poster { display: block; transition: opacity 1200ms ease; }
html.film-live.canvas-on .ch[data-ch="0"] .ch-poster { opacity: 0; }
html.film-live .ch-begin .ch-loop { display: none; }
html.film-live .ch::after { z-index: 0; }
html.film-live .ch-copy { z-index: 1; }
html.film-live .ch-poster img { z-index: 0; }

/* Anchored labels follow the ribbon and the rings in the side layout. */
@media (orientation: landscape) {
  html.film-live .anchored { position: relative; height: 0; margin: 0; }
  html.film-live .anchored li { position: absolute; left: 0; top: 0; white-space: nowrap; will-change: translate; }
  html.film-live .anchored li.flip { flex-direction: row-reverse; }
  html.film-live .phrases.anchored li { gap: 0; }
  html.film-live .phrases.anchored .anchor-line { display: block; width: var(--lead, 40px); height: 1px; margin: 0 14px 0 0; background: linear-gradient(90deg, rgba(242, 179, 143, 0.9), rgba(243, 237, 231, 0.25)); }
  html.film-live .ch-approve .ch-copy { width: min(460px, 34vw); }
  html.film-live .demo-card.anchored-card { position: absolute; left: 0; top: 0; margin: 0; will-change: translate; }
  html.film-live .ch-begin .ch-copy { margin-left: auto; }
}
@media (orientation: portrait) {
  html.film-live .ch { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  html.film-live .demo-card.anchored-card { position: absolute; left: 0; top: 0; margin: 0; width: min(320px, calc(100vw - 40px)); will-change: translate; }
  html.film-live .ch-approve .ch-copy { padding-top: 0; }
  html.film-live .ch-begin { padding-top: 0; }
}

/* Posters are rendered from the live page with every word hidden. */
html.poster .ch-copy, html.poster .team-names, html.poster .film-bar, html.poster .film-ticks, html.poster .film-disclosure, html.poster .scroll-cue, html.poster .ch::after { display: none !important; }
html.poster-cutout, html.poster-cutout body, html.poster-cutout .film, html.poster-cutout .stage-backdrop { background: transparent !important; }

@media (prefers-reduced-motion: reduce) {
  .scroll-cue-line { animation: none; transform: none; }
  html.reveal .ch .r { transition: opacity 700ms ease; }
}

/* One scrim for the live stage, above the canvas and under the words: it
   follows the words (left for chapters 1 to 5, right for the sign-in). */
html.film-live .ch::after { display: none; }
html.film-live .stage::before, html.film-live .stage::after { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; transition: opacity 900ms ease; }
@media (orientation: landscape) {
  html.film-live .stage::before { background: linear-gradient(90deg, rgba(11, 10, 9, 0.86) 0%, rgba(11, 10, 9, 0.55) 32%, rgba(11, 10, 9, 0) 54%); }
  html.film-live .stage::after { background: linear-gradient(270deg, rgba(11, 10, 9, 0.8) 0%, rgba(11, 10, 9, 0.4) 34%, rgba(11, 10, 9, 0) 52%); opacity: 0; }
  html.film-live.at-begin .stage::before { opacity: 0; }
  html.film-live.at-begin .stage::after { opacity: 1; }
}
@media (orientation: portrait) {
  html.film-live .stage::before { background: linear-gradient(0deg, rgba(11, 10, 9, 0.95) 0%, rgba(11, 10, 9, 0.8) 36%, rgba(11, 10, 9, 0) 58%); }
  html.film-live .stage::after { display: none; }
}

/* The opening frame is never faded in: it paints with the page. */
html.reveal .ch[data-ch="0"] .r { opacity: 1; transition: none; }

/* Chapter 2: your own team of agents. Each role is a real part of the engine:
   the Planner is the intake and the mandate, the Guard lib/agent-guard.js,
   the Trader lib/agent-executor.js, the Watcher lib/agent-runner.js. */
.roles { margin-top: 28px; display: grid; gap: 14px; max-width: 30em; }
.roles li { display: grid; grid-template-columns: 12px minmax(0, 1fr); column-gap: 14px; align-items: baseline; }
.role-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); align-self: center; grid-row: 1; }
.role-name { grid-column: 2; font-family: var(--font-display); font-weight: 600; font-size: clamp(17px, 1.4vw, 20px); letter-spacing: -0.01em; color: var(--ink); }
.role-line { grid-column: 2; font-size: clamp(15px, 1.15vw, 17px); line-height: 1.45; color: var(--ink-2); }
.team-names { display: none; }
@media (orientation: landscape) {
  .ch-team .ch-copy { width: min(520px, 38vw); }
  .ch-team .ch-lede { max-width: none; }
  html.film-live .team-names { display: block; position: absolute; inset: 0; margin: 0; z-index: 1; pointer-events: none; }
  html.film-live .team-names li {
    position: absolute; left: 0; top: 0; white-space: nowrap; will-change: translate;
    font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -0.01em; color: var(--ink);
    text-shadow: 0 0 14px var(--bg), 0 0 4px var(--bg);
  }
}
@media (orientation: portrait) {
  .ch-team .ch-copy { padding-top: 40vh; }
  .roles { margin-top: 20px; gap: 10px; }
  .ch-team .ch-lede { margin-top: 12px; }
}
