// Camus — product video scenes (30s, 1920×1080). Time-driven; scrubber-safe.

const V = { W: 1920, H: 1080, DUR: 50.5 };
const vFont = "-apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif";
const CREAM = "#FDF6E9", INK = "#2E3242";
const ICON_SRC = "camus/icon/Camus App Icon 1024.png";

const MESSY = "hey so about the meeting tomorrow — i think we should maybe push it because the deck isnt rly ready and honestly half the team is out anyway. can we do thursday instead?? lmk";
const POLISHED = "Hi — quick note about tomorrow's meeting. The deck isn't quite ready yet, and several of the team are out, so I'd suggest we postpone. Would Thursday work instead? Let me know.";

/* ---------- shared bits ---------- */
const FullBG = ({ style }) => <div style={{ position: "absolute", inset: 0, ...style }}></div>;

const WallBG = () => (
  <FullBG style={{
    background: `radial-gradient(120% 90% at 12% 8%, #3d2a6e 0%, transparent 55%),
      radial-gradient(110% 80% at 88% 18%, #14416e 0%, transparent 55%),
      radial-gradient(130% 100% at 70% 95%, #6e2a52 0%, transparent 60%),
      radial-gradient(100% 90% at 20% 90%, #173a35 0%, transparent 55%), #0b0b14`,
  }} />
);

const fadeInOut = (lt, dur, fin = 0.5, fout = 0.5) =>
  Math.min(1, lt / fin, Math.max(0, (dur - lt) / fout));

const Keycap = ({ label, pop }) => (
  <span style={{
    display: "inline-grid", placeItems: "center", width: 92, height: 92,
    borderRadius: 18, background: "rgba(255,255,255,.10)",
    boxShadow: "inset 0 1px 0 rgba(255,255,255,.35), 0 10px 30px rgba(0,0,0,.4)",
    color: "#fff", fontSize: 40, fontWeight: 600, fontFamily: vFont,
    transform: `scale(${0.5 + 0.5 * Easing.easeOutBack(pop)}) translateY(${(1 - pop) * 20}px)`,
    opacity: Math.min(1, pop * 2),
    backdropFilter: "blur(20px)",
  }}>{label}</span>
);

/* Simplified Mail window for the video (large scale) */
const VMail = ({ hlChars = 0, replaced = false, flash = 0 }) => {
  const text = replaced ? POLISHED : MESSY;
  const hl = Math.round(hlChars);
  return (
    <div style={{
      width: 1080, borderRadius: 26, overflow: "hidden", fontFamily: vFont,
      background: "rgba(30,30,36,.78)", backdropFilter: "blur(30px)",
      boxShadow: "0 40px 120px rgba(0,0,0,.55), inset 0 .5px 0 rgba(255,255,255,.18)",
      color: "rgba(255,255,255,.92)",
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 22, padding: "22px 28px", background: "rgba(255,255,255,.05)", borderBottom: "1px solid rgba(255,255,255,.08)" }}>
        <div style={{ display: "flex", gap: 13 }}>
          {["#ff5f57", "#febc2e", "#28c840"].map((c) => <span key={c} style={{ width: 19, height: 19, borderRadius: 10, background: c }}></span>)}
        </div>
        <span style={{ fontSize: 22, fontWeight: 600, color: "rgba(255,255,255,.6)" }}>Re: Q3 planning review</span>
      </div>
      <div style={{ padding: "30px 40px 14px", fontSize: 23, color: "rgba(255,255,255,.5)", display: "grid", gap: 14 }}>
        <div style={{ paddingBottom: 12, borderBottom: "1px solid rgba(255,255,255,.08)" }}>To:&nbsp;&nbsp;<span style={{ color: "rgba(255,255,255,.85)", background: "rgba(255,255,255,.1)", borderRadius: 99, padding: "2px 16px" }}>Dana Whitfield</span></div>
      </div>
      <div style={{ padding: "26px 40px 48px", fontSize: 27, lineHeight: 1.6 }}>
        <p style={{ margin: "0 0 24px" }}>Hi Dana,</p>
        <p style={{ margin: 0, borderRadius: 6, background: flash > 0 ? `rgba(10,132,255,${0.34 * flash})` : "none", transition: "none" }}>
          {hl > 0 && !replaced ? (
            <>
              <span style={{ background: "rgba(10,132,255,.38)", borderRadius: 4 }}>{text.slice(0, hl)}</span>
              {text.slice(hl)}
            </>
          ) : text}
        </p>
        <p style={{ margin: "24px 0 0", color: "rgba(255,255,255,.55)" }}>Best,<br />Alex</p>
      </div>
    </div>
  );
};

/* Video version of the command palette */
const VPalette = ({ appear, highlight, pressed }) => {
  const rows = CAMUS_DATA.ACTIONS;
  return (
    <div style={{
      width: 620, borderRadius: 42, fontFamily: vFont, overflow: "hidden",
      background: "rgba(28,28,32,.55)", backdropFilter: "blur(40px) saturate(2)",
      boxShadow: "0 50px 140px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.28)",
      color: "rgba(255,255,255,.92)",
      transform: `scale(${0.86 + 0.14 * Easing.easeOutBack(appear)}) translateY(${(1 - appear) * 16}px)`,
      opacity: Math.min(1, appear * 2.5),
      transformOrigin: "top left",
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 16, padding: "24px 26px", borderBottom: "1px solid rgba(255,255,255,.1)" }}>
        <Glyph name="sparkle" size={28} color="#0A84FF" />
        <span style={{ fontSize: 25, color: "rgba(255,255,255,.45)" }}>Improve, reply, or type anything…</span>
        <span style={{ marginLeft: "auto", fontSize: 19, color: "rgba(255,255,255,.4)", background: "rgba(255,255,255,.1)", borderRadius: 9, padding: "4px 12px" }}>⌃⇧C</span>
      </div>
      <div style={{ padding: 12, display: "grid", gap: 2 }}>
        {rows.map((a, i) => {
          const hot = i === 0 && highlight > 0;
          return (
            <div key={a.id} style={{
              display: "flex", alignItems: "center", gap: 18, padding: "13px 16px",
              borderRadius: 16, fontSize: 24, fontWeight: 500,
              background: hot ? (pressed ? "rgba(10,132,255,.45)" : "rgba(255,255,255,.12)") : "transparent",
              transform: hot && pressed ? "scale(.985)" : "none",
            }}>
              <Glyph name={a.icon} size={26} color={a.hue || "#0A84FF"} strokeWidth={1.8} />
              {a.name}
              <span style={{ marginLeft: "auto", fontSize: 18, color: "rgba(255,255,255,.35)" }}>{a.shortcut}</span>
            </div>
          );
        })}
      </div>
    </div>
  );
};

/* Video version of the result panel */
const VResult = ({ chars, done, replacePressed }) => {
  const n = Math.round(chars);
  return (
    <div style={{
      width: 640, borderRadius: 42, fontFamily: vFont, padding: "26px 30px",
      background: "rgba(28,28,32,.55)", backdropFilter: "blur(40px) saturate(2)",
      boxShadow: "0 50px 140px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.28)",
      color: "rgba(255,255,255,.92)",
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 14, marginBottom: 16 }}>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 10, fontSize: 20, fontWeight: 600, color: "#fff", background: "linear-gradient(180deg, #4DA3FF, #0A84FF 50%, #0868c8)", borderRadius: 99, padding: "6px 20px" }}>
          <Glyph name="sparkle" size={20} color="#fff" /> Improve
        </span>
        {!done && <span style={{ fontSize: 19, color: "rgba(255,255,255,.45)" }}>writing…</span>}
      </div>
      <div style={{ fontSize: 26, lineHeight: 1.55, minHeight: 200 }}>
        {POLISHED.slice(0, n)}
        {!done && <span style={{ display: "inline-block", width: 3.5, height: "1.05em", verticalAlign: "text-bottom", background: "#0A84FF", borderRadius: 2, marginLeft: 2 }}></span>}
      </div>
      <div style={{ display: "flex", gap: 12, marginTop: 20, opacity: done ? 1 : 0.3 }}>
        <span style={{
          fontSize: 22, fontWeight: 600, color: "#fff", borderRadius: 16, padding: "12px 26px",
          background: "linear-gradient(180deg, #4DA3FF, #0A84FF 50%, #0868c8)",
          boxShadow: replacePressed ? "0 0 0 6px rgba(10,132,255,.35)" : "0 4px 18px rgba(10,132,255,.45)",
          transform: replacePressed ? "scale(.96)" : "none",
        }}>Replace ↩</span>
        <span style={{ fontSize: 22, color: "rgba(255,255,255,.85)", background: "rgba(255,255,255,.1)", borderRadius: 16, padding: "12px 26px" }}>Copy</span>
        <span style={{ fontSize: 22, color: "rgba(255,255,255,.85)", background: "rgba(255,255,255,.1)", borderRadius: 16, padding: "12px 22px" }}>↻</span>
      </div>
    </div>
  );
};

/* ============ SCENES ============ */

/* 1 · Brand open (0–3.5) */
const SceneOpen = () => (
  <Sprite start={0} end={3.5}>
    {({ localTime: lt, duration }) => {
      const pop = Easing.easeOutBack(clamp(lt / 0.8, 0, 1));
      const o = fadeInOut(lt, duration, 0.4, 0.45);
      return (
        <>
          <FullBG style={{ background: CREAM }} />
          <div style={{ position: "absolute", inset: 0, display: "grid", placeItems: "center", opacity: o }}>
            <div style={{ display: "grid", justifyItems: "center", gap: 30 }}>
              <img src={ICON_SRC} alt="" style={{ width: 300, height: 300, transform: `scale(${pop})` }} />
              <div style={{ fontFamily: vFont, fontSize: 96, fontWeight: 700, letterSpacing: "-0.04em", color: INK, opacity: clamp((lt - 0.4) / 0.5, 0, 1) }}>Camus</div>
              <div style={{ fontFamily: vFont, fontSize: 36, color: "rgba(46,50,66,.6)", opacity: clamp((lt - 0.8) / 0.5, 0, 1) }}>Type it messy. Ship it polished.</div>
            </div>
          </div>
        </>
      );
    }}
  </Sprite>
);

/* 2 · The old way (3.5–9) */
const SceneProblem = () => {
  const steps = ["Select & copy", "Switch to your LLM app of choice", "Paste, type “rewrite this”", "Wait. Copy the result", "Switch back, find your place"];
  return (
    <Sprite start={3.5} end={9}>
      {({ localTime: lt, duration }) => {
        const o = fadeInOut(lt, duration, 0.4, 0.45);
        const collapse = clamp((lt - 3.6) / 0.6, 0, 1);
        return (
          <>
            <FullBG style={{ background: "#101018" }} />
            <div style={{ position: "absolute", inset: 0, opacity: o, fontFamily: vFont }}>
              <div style={{ position: "absolute", top: 130, width: "100%", textAlign: "center", fontSize: 58, fontWeight: 700, letterSpacing: "-0.03em", color: "#fff" }}>
                The old way to use AI on your writing
              </div>
              <div style={{ position: "absolute", top: 300, left: 0, right: 0, display: "grid", justifyContent: "center", gap: 26 }}>
                {steps.map((s, i) => {
                  const appear = clamp((lt - 0.5 - i * 0.45) / 0.4, 0, 1);
                  return (
                    <div key={i} style={{
                      display: "flex", alignItems: "center", gap: 22, width: 760,
                      background: "rgba(255,255,255,.06)", borderRadius: 20, padding: "20px 30px",
                      fontSize: 30, color: "rgba(255,255,255,.85)",
                      opacity: appear * (1 - collapse), transform: `translateY(${(1 - Easing.easeOutCubic(appear)) * 26 + collapse * (i - 2) * -14}px) scale(${1 - collapse * 0.06})`,
                    }}>
                      <span style={{ width: 46, height: 46, borderRadius: 23, background: "rgba(255,255,255,.1)", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 24, flex: "none" }}>{i + 1}</span>
                      <span style={{ textDecoration: collapse > 0.4 ? "line-through" : "none", textDecorationColor: "#E85E72", textDecorationThickness: 3 }}>{s}</span>
                    </div>
                  );
                })}
              </div>
              <div style={{
                position: "absolute", bottom: 120, width: "100%", textAlign: "center",
                fontSize: 44, fontWeight: 600, color: "#E85E72", fontFamily: vFont,
                opacity: clamp((lt - 3.1) / 0.4, 0, 1),
              }}>
                Five context switches. For a two-second thought.
              </div>
            </div>
          </>
        );
      }}
    </Sprite>
  );
};

/* 3 · Select + hotkey (9–14.5) */
const SceneSelect = () => (
  <Sprite start={9} end={14.5}>
    {({ localTime: lt, duration }) => {
      const o = fadeInOut(lt, duration, 0.45, 0.01);
      const hl = clamp((lt - 1.0) / 1.4, 0, 1) * MESSY.length;
      return (
        <>
          <WallBG />
          <div style={{ position: "absolute", inset: 0, opacity: o }}>
            <div style={{ position: "absolute", left: 140, top: 150 }}>
              <VMail hlChars={hl} />
            </div>
            <div style={{ position: "absolute", right: 150, top: 240, width: 420, fontFamily: vFont, color: "#fff", fontSize: 50, fontWeight: 700, letterSpacing: "-0.03em", lineHeight: 1.15, opacity: clamp((lt - 0.4) / 0.4, 0, 1) }}>
              With Camus:<br />
              <span style={{ color: "rgba(255,255,255,.55)", fontWeight: 500, fontSize: 38 }}>select anywhere…</span>
            </div>
            <div style={{ position: "absolute", right: 150, top: 470, display: "flex", gap: 18 }}>
              {["⌃", "⇧", "C"].map((k, i) => (
                <Keycap key={k} label={k} pop={clamp((lt - 2.8 - i * 0.22) / 0.45, 0, 1)} />
              ))}
            </div>
            <div style={{ position: "absolute", right: 150, top: 600, fontFamily: vFont, fontSize: 38, color: "rgba(255,255,255,.55)", opacity: clamp((lt - 3.6) / 0.4, 0, 1) }}>
              …press the hotkey.
            </div>
          </div>
        </>
      );
    }}
  </Sprite>
);

/* 4 · Palette (14.5–19) */
const ScenePalette = () => (
  <Sprite start={14.5} end={19}>
    {({ localTime: lt, duration }) => {
      const o = fadeInOut(lt, duration, 0.01, 0.01);
      return (
        <>
          <WallBG />
          <div style={{ position: "absolute", inset: 0, opacity: o }}>
            <div style={{ position: "absolute", left: 140, top: 150, filter: "brightness(.75)" }}>
              <VMail hlChars={MESSY.length} />
            </div>
            <div style={{ position: "absolute", left: 620, top: 430 }}>
              <VPalette
                appear={clamp(lt / 0.5, 0, 1)}
                highlight={clamp((lt - 1.6) / 0.3, 0, 1)}
                pressed={lt > 3.4}
              />
            </div>
            <div style={{ position: "absolute", right: 130, top: 230, width: 400, fontFamily: vFont, fontSize: 48, fontWeight: 700, letterSpacing: "-0.03em", color: "#fff", lineHeight: 1.2, opacity: clamp((lt - 0.7) / 0.5, 0, 1) }}>
              Your prompts,<br />at your cursor.
            </div>
          </div>
        </>
      );
    }}
  </Sprite>
);

/* 5 · Stream + replace (19–26) */
const SceneResult = () => (
  <Sprite start={19} end={26}>
    {({ localTime: lt, duration }) => {
      const o = fadeInOut(lt, duration, 0.01, 0.5);
      const chars = clamp((lt - 0.3) / 2.6, 0, 1) * POLISHED.length;
      const done = lt > 3.1;
      const replacePressed = lt > 4.0 && lt < 4.35;
      const replaced = lt > 4.35;
      const flash = replaced ? clamp(1 - (lt - 4.35) / 1.4, 0, 1) : 0;
      return (
        <>
          <WallBG />
          <div style={{ position: "absolute", inset: 0, opacity: o }}>
            <div style={{ position: "absolute", left: 140, top: 150, filter: replaced ? "none" : "brightness(.75)" }}>
              <VMail hlChars={0} replaced={replaced} flash={flash} />
            </div>
            {!replaced && (
              <div style={{ position: "absolute", left: 620, top: 430 }}>
                <VResult chars={chars} done={done} replacePressed={replacePressed} />
              </div>
            )}
            <div style={{ position: "absolute", right: 130, top: 230, width: 420, fontFamily: vFont, fontSize: 48, fontWeight: 700, letterSpacing: "-0.03em", color: "#fff", lineHeight: 1.2 }}>
              {replaced ? "Replaced. In place." : "Watch it write."}
              <div style={{ fontSize: 30, fontWeight: 500, color: "rgba(255,255,255,.55)", marginTop: 18, lineHeight: 1.45 }}>
                {replaced ? "Your clipboard untouched. Your flow unbroken." : "Streams live — no spinner, no waiting room."}
              </div>
            </div>
          </div>
        </>
      );
    }}
  </Sprite>
);

/* ---------- montage helpers (scenes 6–7) ---------- */
const VWin = ({ width, header, children }) => (
  <div style={{
    width, borderRadius: 26, overflow: "hidden", fontFamily: vFont,
    background: "rgba(30,30,36,.78)", backdropFilter: "blur(30px)",
    boxShadow: "0 40px 120px rgba(0,0,0,.55), inset 0 .5px 0 rgba(255,255,255,.18)",
    color: "rgba(255,255,255,.92)",
  }}>
    <div style={{ display: "flex", alignItems: "center", gap: 22, padding: "20px 28px", background: "rgba(255,255,255,.05)", borderBottom: "1px solid rgba(255,255,255,.08)" }}>
      <div style={{ display: "flex", gap: 13 }}>
        {["#ff5f57", "#febc2e", "#28c840"].map((c) => <span key={c} style={{ width: 19, height: 19, borderRadius: 10, background: c }}></span>)}
      </div>
      {header}
    </div>
    {children}
  </div>
);

const VMontageText = ({ messy, polished, sweep, streamN, done, flash }) => {
  if (streamN > 0) {
    return (
      <span style={{ borderRadius: 6, background: flash > 0 ? `rgba(10,132,255,${0.30 * flash})` : "none" }}>
        {polished.slice(0, Math.round(streamN))}
        {!done && <span style={{ display: "inline-block", width: 3.5, height: "1.05em", verticalAlign: "text-bottom", background: "#0A84FF", borderRadius: 2, marginLeft: 2 }}></span>}
      </span>
    );
  }
  const n = Math.round(sweep * messy.length);
  return (
    <span>
      {n > 0 && <span style={{ background: "rgba(10,132,255,.38)", borderRadius: 4 }}>{messy.slice(0, n)}</span>}
      {messy.slice(n)}
    </span>
  );
};

const VActionChip = ({ pop, pressed, hue, icon, label, writing, opacity }) => (
  <div style={{
    display: "flex", alignItems: "center", gap: 14, padding: "14px 28px",
    borderRadius: 99, fontSize: 25, fontWeight: 600, fontFamily: vFont, color: "#fff",
    background: pressed ? `linear-gradient(180deg, ${hue}, ${hue} 55%, rgba(0,0,0,.25))` : "rgba(28,28,32,.62)",
    backgroundBlendMode: pressed ? "overlay" : "normal",
    backdropFilter: "blur(30px) saturate(2)",
    boxShadow: "0 20px 60px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.3)",
    transform: `scale(${0.6 + 0.4 * Easing.easeOutBack(clamp(pop, 0, 1))})`,
    opacity: Math.min(1, pop * 2) * opacity,
  }}>
    <Glyph name={icon} size={26} color={pressed ? "#fff" : hue} strokeWidth={1.8} />
    {label}{writing ? "…" : ""}
  </div>
);

const MontageScene = ({ start, end, title, sub, messy, polished, action, chipPos, renderWin }) => (
  <Sprite start={start} end={end}>
    {({ localTime: lt, duration }) => {
      const o = fadeInOut(lt, duration, 0.45, 0.45);
      const sweep = Easing.easeOutCubic(clamp((lt - 0.7) / 0.9, 0, 1));
      const chipPop = clamp((lt - 1.7) / 0.4, 0, 1);
      const pressed = lt > 2.3;
      const streamP = clamp((lt - 2.55) / 1.6, 0, 1);
      const streamN = lt > 2.55 ? streamP * polished.length : 0;
      const done = streamP >= 1;
      const flash = done ? clamp(1 - (lt - 4.15) / 1.1, 0, 1) : 0;
      const chipO = done ? clamp(1 - (lt - 4.15) / 0.4, 0, 1) : 1;
      const textEl = <VMontageText messy={messy} polished={polished} sweep={sweep} streamN={streamN} done={done} flash={flash} />;
      return (
        <>
          <WallBG />
          <div style={{ position: "absolute", inset: 0, opacity: o }}>
            <div style={{ position: "absolute", left: 140, top: 170 }}>{renderWin(textEl)}</div>
            <div style={{ position: "absolute", left: chipPos.x, top: chipPos.y }}>
              <VActionChip pop={chipPop} pressed={pressed} hue={action.hue} icon={action.icon} label={action.name} writing={streamN > 0 && !done} opacity={chipO} />
            </div>
            <div style={{ position: "absolute", right: 130, top: 250, width: 430, fontFamily: vFont, color: "#fff", opacity: clamp((lt - 0.4) / 0.4, 0, 1) }}>
              <div style={{ fontSize: 48, fontWeight: 700, letterSpacing: "-0.03em", lineHeight: 1.18 }}>{title}</div>
              <div style={{ fontSize: 30, fontWeight: 500, color: "rgba(255,255,255,.55)", marginTop: 18 }}>{sub}</div>
            </div>
          </div>
        </>
      );
    }}
  </Sprite>
);

/* 6 · Slack · Friendly (26–31.5) */
const SceneSlack = () => (
  <MontageScene
    start={26} end={31.5}
    title="Soften a Slack message."
    sub={<span>One prompt: <b style={{ color: "#F2814F" }}>Friendly</b>. ⌃⇧3.</span>}
    messy={CAMUS_DATA.APPS.slack.doc[0].text}
    polished={CAMUS_DATA.REWRITES.slack.friendly}
    action={{ name: "Friendly", icon: "smile", hue: "#F2814F" }}
    chipPos={{ x: 560, y: 868 }}
    renderWin={(textEl) => (
      <VWin width={1000} header={<span style={{ fontSize: 23, fontWeight: 600, color: "rgba(255,255,255,.6)" }}># eng-deploys</span>}>
        <div style={{ display: "flex", minHeight: 430 }}>
          <div style={{ width: 230, background: "rgba(255,255,255,.04)", borderRight: "1px solid rgba(255,255,255,.08)", padding: "24px 0", fontSize: 22 }}>
            <div style={{ padding: "0 24px 18px", fontWeight: 700, fontSize: 24 }}>Acme Corp</div>
            {["general", "eng-deploys", "design"].map((c) => (
              <div key={c} style={{ padding: "8px 24px", color: c === "eng-deploys" ? "#fff" : "rgba(255,255,255,.4)", fontWeight: c === "eng-deploys" ? 600 : 400, background: c === "eng-deploys" ? "rgba(255,255,255,.08)" : "none" }}># {c}</div>
            ))}
          </div>
          <div style={{ flex: 1, display: "flex", flexDirection: "column", padding: "24px 30px 30px" }}>
            <div style={{ display: "flex", gap: 16, fontSize: 23, marginBottom: 24 }}>
              <span style={{ width: 46, height: 46, borderRadius: 12, background: "rgba(255,255,255,.1)", display: "grid", placeItems: "center", fontWeight: 700 }}>P</span>
              <div>
                <div><b>Priya N.</b> <span style={{ color: "rgba(255,255,255,.35)", fontSize: 19 }}>9:41</span></div>
                <div style={{ color: "rgba(255,255,255,.75)" }}>Morning! Standup in 20 — anything blocking?</div>
              </div>
            </div>
            <div style={{ marginTop: "auto", border: "1px solid rgba(255,255,255,.14)", borderRadius: 16, padding: "20px 24px", fontSize: 25, lineHeight: 1.55, background: "rgba(255,255,255,.04)" }}>
              {textEl}
            </div>
          </div>
        </div>
      </VWin>
    )}
  />
);

/* 7 · GitHub · Shorten (31.5–37) */
const SceneGithub = () => (
  <MontageScene
    start={31.5} end={37}
    title="PR descriptions, shipped."
    sub={<span>One prompt: <b style={{ color: "#8A93AE" }}>Shorten</b>. ⌃⇧2.</span>}
    messy={CAMUS_DATA.APPS.github.doc[0].text}
    polished={CAMUS_DATA.REWRITES.github.shorten}
    action={{ name: "Shorten", icon: "shorten", hue: "#8A93AE" }}
    chipPos={{ x: 540, y: 836 }}
    renderWin={(textEl) => (
      <VWin width={1040} header={
        <div style={{ flex: 1, maxWidth: 560, margin: "0 auto", background: "rgba(255,255,255,.08)", borderRadius: 12, padding: "8px 20px", fontSize: 21, color: "rgba(255,255,255,.55)", textAlign: "center" }}>
          github.com/acme/app/pull/482
        </div>
      }>
        <div style={{ padding: "28px 36px 36px" }}>
          <div style={{ fontSize: 30, fontWeight: 600, letterSpacing: "-.01em" }}>
            Fix token refresh race on logout <span style={{ color: "rgba(255,255,255,.4)", fontWeight: 400 }}>#482</span>
          </div>
          <div style={{ display: "flex", alignItems: "center", gap: 14, margin: "14px 0 24px", fontSize: 21, color: "rgba(255,255,255,.5)" }}>
            <span style={{ background: "#1f883d", color: "#fff", borderRadius: 99, padding: "5px 18px", fontWeight: 600 }}>Open</span>
            alex-r wants to merge 3 commits into main
          </div>
          <div style={{ border: "1px solid rgba(255,255,255,.14)", borderRadius: 16, overflow: "hidden" }}>
            <div style={{ padding: "12px 22px", background: "rgba(255,255,255,.05)", borderBottom: "1px solid rgba(255,255,255,.1)", fontSize: 21, display: "flex", gap: 20 }}>
              <b>Write</b><span style={{ color: "rgba(255,255,255,.4)" }}>Preview</span>
            </div>
            <div style={{ padding: "22px 24px 34px", fontSize: 25, lineHeight: 1.55 }}>{textEl}</div>
          </div>
        </div>
      </VWin>
    )}
  />
);

/* 8 · CLI agent · Improve the prompt itself (37–42.5) */
const SceneCLI = () => (
  <MontageScene
    start={37} end={42.5}
    title="Even your prompts get prompts."
    sub={<span>Rewrite the ask before your CLI agent runs with it. <b style={{ color: "#6FB6FF" }}>Improve</b>. ⌃⇧1.</span>}
    messy={"make the auth thing faster and also fix that login bug i think its the cache or something idk"}
    polished={"Profile the auth flow and reduce sign-in latency. Then fix the intermittent login failure — likely in the cache-invalidation path. Add a regression test for both."}
    action={{ name: "Improve", icon: "sparkle", hue: "#0A84FF" }}
    chipPos={{ x: 600, y: 488 }}
    renderWin={(textEl) => (
      <VWin width={1020} header={<span style={{ fontSize: 22, fontWeight: 600, color: "rgba(255,255,255,.55)", fontFamily: "ui-monospace, 'SF Mono', Menlo, monospace" }}>agent — ~/acme-app</span>}>
        <div style={{ padding: "28px 34px 40px", fontFamily: "ui-monospace, 'SF Mono', Menlo, monospace", fontSize: 23, lineHeight: 1.65, background: "rgba(10,12,16,.55)" }}>
          <div style={{ color: "rgba(255,255,255,.38)" }}>✔ Read 4 files · src/auth/**</div>
          <div style={{ color: "rgba(255,255,255,.38)", marginBottom: 22 }}>✔ Ran tests — 2 failing · awaiting instructions</div>
          <div style={{ display: "flex", gap: 14 }}>
            <span style={{ color: "#6FB6FF", flex: "none" }}>❯</span>
            <span style={{ color: "rgba(255,255,255,.92)" }}>{textEl}</span>
          </div>
        </div>
      </VWin>
    )}
  />
);

/* 9 · Everywhere montage + closing CTA (42.5–50.5, holds as the final frame) */
const SceneEverywhere = () => {
  const apps = [
    "Mail", "Slack", "Safari", "Notion", "Xcode", "Figma", "Terminal",
    "Zed", "Obsidian", "Discord", "Telegram", "WhatsApp", "Notes",
  ];
  const uses = [
    ["Polish an email", "#0A84FF"], ["Defuse a thread", "#F2814F"], ["Summarize a wall of text", "#F0A93C"],
    ["Commit messages", "#8A93AE"], ["Reply in kind", "#E85E72"], ["Sound like you", "#B08D52"],
  ];
  return (
    <Sprite start={42.5} end={50.5}>
      {({ localTime: lt }) => {
        const o = Math.min(1, lt / 0.4);
        const taglineP = clamp((lt - 1.9) / 0.5, 0, 1);
        const ctaP = Easing.easeOutBack(clamp((lt - 3.3) / 0.5, 0, 1));
        const fineP = clamp((lt - 3.7) / 0.4, 0, 1);
        return (
          <>
            <FullBG style={{ background: CREAM }} />
            <div style={{ position: "absolute", inset: 0, opacity: o, fontFamily: vFont, textAlign: "center" }}>
              <div style={{ marginTop: 124, fontSize: 76, fontWeight: 700, letterSpacing: "-0.035em", color: INK }}>
                One hotkey. Everywhere you write.
              </div>
              <div style={{ display: "flex", justifyContent: "center", gap: 16, marginTop: 56, flexWrap: "wrap", padding: "0 150px" }}>
                {apps.map((a, i) => {
                  const p = Easing.easeOutBack(clamp((lt - 0.4 - i * 0.09) / 0.45, 0, 1));
                  return (
                    <span key={a} style={{
                      fontSize: 28, fontWeight: 600, color: INK, background: "#fff",
                      borderRadius: 99, padding: "14px 34px",
                      boxShadow: "0 6px 24px rgba(46,40,30,.12), inset 0 0 0 1px rgba(46,50,66,.08)",
                      transform: `scale(${p})`, opacity: Math.min(1, p * 1.5),
                      display: "inline-block", whiteSpace: "nowrap",
                    }}>{a}</span>
                  );
                })}
              </div>
              <div style={{
                marginTop: 40, fontSize: 32, fontWeight: 600, color: INK,
                opacity: taglineP * 0.62,
                transform: `translateY(${(1 - Easing.easeOutCubic(taglineP)) * 16}px)`,
              }}>
                …and every app where you can read or type.
              </div>
              <div style={{ display: "flex", justifyContent: "center", gap: 16, marginTop: 38, flexWrap: "wrap", padding: "0 260px" }}>
                {uses.map(([u, c], i) => {
                  const p = clamp((lt - 2.5 - i * 0.12) / 0.4, 0, 1);
                  return (
                    <span key={u} style={{
                      fontSize: 24, fontWeight: 600, color: "#fff", background: c,
                      borderRadius: 99, padding: "11px 28px",
                      opacity: p, transform: `translateY(${(1 - Easing.easeOutCubic(p)) * 18}px)`,
                      display: "inline-block", whiteSpace: "nowrap",
                    }}>{u}</span>
                  );
                })}
              </div>
              <div style={{ display: "grid", justifyItems: "center", gap: 22, marginTop: 64 }}>
                <div style={{
                  fontSize: 32, fontWeight: 600, color: "#fff", borderRadius: 99, padding: "18px 44px",
                  background: "linear-gradient(180deg, #4DA3FF, #0A84FF 50%, #0868c8)",
                  boxShadow: "0 10px 40px rgba(10,132,255,.4)",
                  transform: `scale(${0.6 + 0.4 * ctaP})`,
                  opacity: Math.min(1, ctaP * 1.6),
                }}>Download the beta — free</div>
                <div style={{ fontSize: 24, color: "rgba(46,50,66,.55)", whiteSpace: "nowrap", opacity: fineP }}>
                  macOS 26+ · Rewrite anything in one keystroke.
                </div>
              </div>
            </div>
          </>
        );
      }}
    </Sprite>
  );
};

function CamusVideo() {
  return (
    <Stage width={V.W} height={V.H} duration={V.DUR} background="#0b0b14" persistKey="camus-video" autoplay={true} loop={false}>
      <SceneOpen />
      <SceneProblem />
      <SceneSelect />
      <ScenePalette />
      <SceneResult />
      <SceneSlack />
      <SceneGithub />
      <SceneCLI />
      <SceneEverywhere />
    </Stage>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<CamusVideo />);
