/* global React, ReactDOM, FramerMotion */
/* Página /social — Captixy Social (piloto com consultores imobiliários) */
const { motion: msx, MotionConfig: MCsx } = FramerMotion;
const {
  IconArrowRight: IARsx,
  IconCheck: ICsx,
  Navbar: NBsx,
  Footer: FTsx,
  EASE_EXPO: EEsx,
} = window;

/* Contacto do piloto: por agora só email. */
const SOCIAL_CONTACTO = {
  email: "contact@captixy.com",
  emailAssunto: "Piloto Captixy Social",
};

/* Ícones de traço (sem dependências), herdam a cor do texto. */
function Ico({ d, className = "h-5 w-5" }) {
  return (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" className={className} aria-hidden="true">
      {d}
    </svg>
  );
}
const I = {
  relogio: <><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></>,
  euro: <><path d="M17 6.5A7 7 0 1 0 17 17.5" /><path d="M4 10h9M4 14h9" /></>,
  semCara: <><path d="M3 3l18 18" /><path d="M10.6 5.1A8.5 8.5 0 0 1 21 12c-.6 1.3-1.4 2.4-2.4 3.4M6.3 6.3C4.6 7.6 3.5 9.6 3 12c1.5 3.5 5 6 9 6 1.6 0 3.1-.4 4.4-1.1" /></>,
  camara: <><rect x="7" y="2.5" width="10" height="19" rx="2.5" /><path d="M11 18.5h2" /></>,
  enviar: <><path d="M21 3 10 14" /><path d="M21 3l-7 18-4-7-7-4 18-7z" /></>,
  receber: <><path d="M12 3v12" /><path d="m7 10 5 5 5-5" /><path d="M5 21h14" /></>,
  camadas: <><path d="m12 3 9 5-9 5-9-5 9-5z" /><path d="m3 13 9 5 9-5" /></>,
  tesoura: <><circle cx="6" cy="6" r="3" /><circle cx="6" cy="18" r="3" /><path d="M8.6 7.6 20 18M8.6 16.4 20 6" /></>,
  legendas: <><rect x="3" y="5" width="18" height="14" rx="2.5" /><path d="M7 13h4M13 13h4M7 16h7" /></>,
  etiqueta: <><path d="M3 12V4h8l10 10-8 8L3 12z" /><circle cx="7.5" cy="8.5" r="1.3" /></>,
  sol: <><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" /></>,
  grafico: <><path d="M4 20V10M10 20V4M16 20v-7M22 20H2" /></>,
  whatsapp: <><path d="M3.5 20.5 5 16a8.5 8.5 0 1 1 3 3l-4.5 1.5z" /><path d="M9 9.5c.5 2 2.5 4 4.5 4.5l1.2-1.2 2 .8c-.3 1.2-1.3 2-2.5 1.9C11 15.2 8.8 13 8.5 10.8 8.4 9.6 9.2 8.6 10.4 8.3l.8 2L10 11.5" /></>,
  email: <><rect x="3" y="5" width="18" height="14" rx="2.5" /><path d="m4 7 8 6 8-6" /></>,
};

/* Imóvel de exemplo usado nas ilustrações do topo */
const EXEMPLO = {
  linha1: "T3 EM",
  linha2: "GONDOMAR",
  dados: "T3 · 145 m² · GONDOMAR",
  preco: "349 000 €",
};

const PILOTO_LISTA = [
  "Até 4 reels por mês",
  "Os três formatos, à tua escolha",
  "Em troca: feedback honesto",
  "Preço definido contigo em janeiro",
];

const PERGUNTAS = [
  {
    p: "Preciso de equipamento?",
    r: "Basta o telemóvel. Um tripé ajuda.",
  },
  {
    p: "E se eu não quiser aparecer?",
    r: "Usamos o formato sem cara, só com a tua voz.",
  },
  {
    p: "Os vídeos ficam meus?",
    r: "Sim. Recebes o ficheiro e publicas onde quiseres.",
  },
  {
    p: "Respeita as regras da marca da minha agência?",
    r: "Sim. Cores, logótipo e textos acertados contigo antes.",
  },
  {
    p: "Quanto vai custar depois do piloto?",
    r: "Ainda não está fechado: definimos com quem participa no piloto.",
  },
];

/* ============================================================
   REEL PREVIEW
   Ilustração CSS de um momento do reel. Quando houver vídeos de demo,
   basta passar `src` (e opcionalmente `poster`) para mostrar um <video> real.
============================================================ */
function ReelPreview({
  variant = "titulo",
  label,
  caption,
  src,
  poster,
  passo = 1,
  className = "",
}) {
  return (
    <figure className={`sx-reel ${className}`}>
      <div className="sx-phone">
        {src ? (
          <video
            className="sx-screen sx-video"
            src={src}
            poster={poster}
            autoPlay
            muted
            loop
            playsInline
            preload="metadata"
            aria-label={label}
          />
        ) : (
          <div
            className={`sx-screen sx-screen--${variant}`}
            role="img"
            aria-label={label}
          >
            <div aria-hidden="true" className="sx-screen-inner">
              {variant === "titulo" && <EcraTitulo />}
              {variant === "corte" && <EcraCorte />}
              {variant === "cartao" && <EcraCartao />}
              <ReelChrome passo={passo} escuro={false} />
            </div>
          </div>
        )}
      </div>
      {caption && (
        <figcaption className="sx-reel-caption">
          <span className="sx-reel-num">{passo}</span>
          {caption}
        </figcaption>
      )}
    </figure>
  );
}

/* Interface de reel por cima da ilustração: barras de progresso e ações laterais. */
function ReelChrome({ passo, escuro }) {
  return (
    <>
      <span className={`sx-rc-barras ${escuro ? "sx-rc--escuro" : ""}`}>
        {[1, 2, 3].map((n) => (
          <span key={n} className={n <= passo ? "is-cheia" : ""} />
        ))}
      </span>
      <span className={`sx-rc-acoes ${escuro ? "sx-rc--escuro" : ""}`}>
        <span />
        <span />
        <span />
      </span>
      <span className={`sx-rc-conta ${escuro ? "sx-rc--escuro" : ""}`}>@o.teu.nome</span>
    </>
  );
}

const SX_FOTO = "assets/social/";

/* Ecrãs do reel de exemplo, com fotografias reais (créditos em assets/social/CREDITOS.md). */
function EcraTitulo() {
  return (
    <>
      <span className="sx-caixa"><img src={`${SX_FOTO}consultor.webp`} alt="" loading="lazy" decoding="async" /></span>
      <div className="sx-t-titulo">
        <span className="sx-t-l1">{EXEMPLO.linha1}</span>
        <span className="sx-t-l2">{EXEMPLO.linha2}</span>
      </div>
      {/* recorte da cabeça por cima do título: o título fica "atrás" do consultor */}
      <span className="sx-caixa sx-caixa--frente"><img className="sx-t-recorte" src={`${SX_FOTO}consultor-cabeca.webp`} alt="" loading="lazy" decoding="async" /></span>
      <span className="sx-vinheta" />
      <span className="sx-legenda">
        HOJE <span className="sx-destaque sx-destaque--claro">MOSTRO-VOS</span>
      </span>
    </>
  );
}

function EcraFoto({ foto, tag, children }) {
  return (
    <>
      <img className="sx-foto" src={`${SX_FOTO}${foto}.webp`} alt="" loading="lazy" decoding="async" />
      <span className="sx-vinheta" />
      {tag && (
        <span className="sx-c-tag">
          <span className="sx-c-rec" /> {tag}
        </span>
      )}
      {children && <span className="sx-legenda">{children}</span>}
    </>
  );
}

function EcraCorte() {
  return (
    <EcraFoto foto="cozinha" tag="cozinha">
      A <span className="sx-destaque sx-destaque--claro">COZINHA</span> ESTÁ
    </EcraFoto>
  );
}

function EcraCartao() {
  return (
    <>
      <img className="sx-foto" src={`${SX_FOTO}sala-desfocada.webp`} alt="" loading="lazy" decoding="async" />
      <span className="sx-k-veu" />
      <div className="sx-k">
        <span className="sx-k-dados">{EXEMPLO.dados}</span>
        <span className="sx-k-preco">{EXEMPLO.preco}</span>
        <span className="sx-k-linha" />
        <span className="sx-k-cta">
          <strong>Agende a sua visita</strong>
          <br />Pedro Matos
          <br />912 345 678
        </span>
      </div>
    </>
  );
}

/* ============================================================
   PEÇAS
============================================================ */
function Revela({ children, delay = 0, className = "", as = "div" }) {
  const Comp = msx[as];
  return (
    <Comp
      initial={{ opacity: 0, y: 24 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true, amount: 0.15 }}
      transition={{ duration: 0.75, delay, ease: EEsx }}
      className={className}
    >
      {children}
    </Comp>
  );
}

function Etiqueta({ children }) {
  return (
    <p className="sx-eyebrow">
      <span aria-hidden="true" className="sx-eyebrow-line" />
      {children}
    </p>
  );
}

/* Títulos no estilo do site: sans leve com a parte final em serifa itálica. */
function Titulo({ texto, destaque }) {
  return (
    <>
      {texto}
      {destaque ? (
        <>
          {" "}
          <em>{destaque}</em>
        </>
      ) : null}
    </>
  );
}

function CabecalhoSecao({ etiqueta, titulo, destaque, id, texto }) {
  return (
    <Revela className="sx-cabecalho">
      {etiqueta && <Etiqueta>{etiqueta}</Etiqueta>}
      <h2 id={id} className="sx-h2">
        <Titulo texto={titulo} destaque={destaque} />
      </h2>
      {texto ? <p className="sx-lead sx-lead--compacto">{texto}</p> : null}
    </Revela>
  );
}

function BotaoPrimario({ href, children }) {
  return (
    <a href={href} className="sx-btn sx-btn--primario">
      {children}
      <IARsx className="h-4 w-4" />
    </a>
  );
}

function BotaoSecundario({ href, children }) {
  return (
    <a href={href} className="sx-btn sx-btn--secundario">
      {children}
      <span aria-hidden="true">↓</span>
    </a>
  );
}

function Cartao({ titulo, texto, etiqueta, icone, delay, children, as }) {
  return (
    <Revela delay={delay} className="sx-card" as={as}>
      {icone ? (
        <span className="sx-card-icone">
          <Ico d={icone} />
        </span>
      ) : null}
      {etiqueta && <span className="sx-card-etiqueta">{etiqueta}</span>}
      <h3 className="sx-h3">{titulo}</h3>
      <p className="sx-card-texto">{texto}</p>
      {children}
    </Revela>
  );
}

/* Linha do tempo de um formato: segmentos "tu" (coral claro) e "casa" (teal). */
function Faixa({ faixa, voz, musica }) {
  return (
    <div className="sx-faixa" aria-hidden="true">
      <div className="sx-faixa-video">
        {faixa.map((f, i) => (
          <span key={i} className={`sx-seg sx-seg--${f}`}>
            {f === "tu" ? "tu" : "casa"}
          </span>
        ))}
      </div>
      <div className="sx-faixa-audio">
        {voz || !musica ? <span className="sx-onda" /> : null}
        {musica ? <span className="sx-onda sx-onda--musica" /> : null}
        <span className="sx-faixa-label">{musica ? "música" : "a tua voz"}</span>
      </div>
    </div>
  );
}

/* ============================================================
   SECÇÕES
============================================================ */
/* ============================================================
   HERO DO SOCIAL — o estúdio a montar o reel
   Clips em bruto → reel no telemóvel (cenas, legendas palavra a palavra) →
   linha do tempo com cabeça de leitura e onda de som → o que tratamos.
============================================================ */
// Tempos reais do reel de demonstração (plano.json gerado pelo motor do Social).
const SX_DEMO_VIDEO = "assets/social/demo-reel.mp4";
const SX_SCENES = [
  { clip: 0, dur: 3000 },
  { clip: 1, dur: 2580 },
  { clip: 2, dur: 2430 },
  { clip: 3, dur: 2700 },
  { clip: 4, dur: 2420 },
  { clip: 5, dur: 3780 },
  { clip: 6, dur: 2790 },
];
const SX_TOTAL = 19700;
const SX_CLIPS = [
  { nome: "consultor_intro.mp4", dur: "0:18", cor: "#4A5563", thumb: "consultor_intro" },
  { nome: "exterior.mp4", dur: "0:07", cor: "#3F4A3A", thumb: "exterior" },
  { nome: "jardim.mp4", dur: "0:08", cor: "#3F4A3A", thumb: "jardim" },
  { nome: "cozinha.mp4", dur: "0:10", cor: "#6B6257", thumb: "cozinha" },
  { nome: "suite.mp4", dur: "0:10", cor: "#575C66", thumb: "suite" },
  { nome: "quarto.mp4", dur: "0:10", cor: "#575C66", thumb: "quarto" },
  { nome: "cartão final", dur: "auto", cor: "#0E4D47", thumb: null },
];
const SX_WORDS = [["Olá,", 98], ["eu", 651], ["sou", 771], ["o", 927], ["Ricardo.", 988], ["Hoje", 2332], ["mostro-vos", 2596], ["esta", 3149], ["moradia", 3365], ["T4", 3762], ["em", 4183], ["Cascais.", 4291], ["Tem", 5685], ["um", 5877], ["jardim", 5949], ["enorme,", 6202], ["com", 6827], ["piscina.", 6995], ["A", 8270], ["cozinha", 8378], ["é", 8726], ["moderna", 8799], ["e", 9303], ["cheia", 9376], ["de", 9640], ["luz.", 9736], ["A", 10938], ["suite", 11082], ["tem", 11370], ["vista", 11526], ["para", 11851], ["o", 11983], ["jardim.", 12043], ["E", 13305], ["o", 13425], ["quarto", 13498], ["tem", 13834], ["uma", 13966], ["varanda.", 14099], ["Agende", 15457], ["já", 15830], ["a", 15998], ["sua", 16058], ["visita.", 16190]];
// Cada item fica marcado quando aparece pela primeira vez no reel.
const SX_TREAT = [
  ["Título atrás de ti", 300],
  ["Legendas palavra a palavra", 1000],
  ["Cortes no momento certo", 3000],
  ["Imagem estabilizada e clareada", 5600],
  ["Som nivelado e música por baixo", 8000],
  ["Preço e contacto no fim", 16900],
];
const sxThumb = (c) => `assets/social/demo/${c.thumb}.webp`;

function SxWave({ playRef, reduced }) {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const c = ref.current;
    if (!c) return undefined;
    const ctx = c.getContext("2d");
    const dpr = Math.min(2, window.devicePixelRatio || 1);
    let raf = 0;
    const draw = (time) => {
      const w = c.clientWidth, h = c.clientHeight;
      if (c.width !== w * dpr) { c.width = w * dpr; c.height = h * dpr; }
      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
      ctx.clearRect(0, 0, w, h);
      const n = Math.floor(w / 4);
      const head = playRef.current * w;
      for (let i = 0; i < n; i += 1) {
        const x = i * 4;
        const seed = Math.sin(i * 12.9898) * 43758.5453;
        const base = 0.25 + (seed - Math.floor(seed)) * 0.55;
        const speaking = (x / w) * SX_TOTAL;
        const gap = SX_WORDS.some(([, t]) => Math.abs(speaking - t) < 260) ? 1 : 0.55;
        const live = Math.abs(x - head) < 26 && !reduced ? 0.35 * Math.sin(time / 90 + i) : 0;
        const amp = Math.max(0.08, Math.min(1, base * gap + live));
        const bh = amp * h;
        ctx.fillStyle = x < head ? "rgba(45,212,191,0.95)" : "rgba(247,248,255,0.22)";
        ctx.fillRect(x, (h - bh) / 2, 2, bh);
      }
      if (!reduced) raf = requestAnimationFrame(draw);
    };
    raf = requestAnimationFrame(draw);
    return () => cancelAnimationFrame(raf);
  }, [reduced]);
  return <canvas ref={ref} className="h-10 w-full" aria-hidden="true" />;
}

function SxStudioHero() {
  const { useMotionValue: sUMV, useSpring: sUS, useTransform: sUT, useReducedMotion: sURM, useScroll: sUSc } = FramerMotion;
  const reduced = Boolean(sURM()) || window.SKIP_ANIM;
  const videoRef = React.useRef(null);
  const [t, setT] = React.useState(0);
  const [som, setSom] = React.useState(false);
  const playRef = React.useRef(0);
  React.useEffect(() => {
    const v = videoRef.current;
    if (!v) return undefined;
    if (reduced) v.pause();
    let raf = 0;
    const loop = () => {
      const ms = Math.min(SX_TOTAL, (v.currentTime || 0) * 1000);
      playRef.current = ms / SX_TOTAL;
      setT(ms);
      raf = requestAnimationFrame(loop);
    };
    raf = requestAnimationFrame(loop);
    return () => cancelAnimationFrame(raf);
  }, [reduced]);
  const alternarSom = () => {
    const v = videoRef.current;
    if (!v) return;
    v.muted = !v.muted;
    if (!v.muted) { v.currentTime = 0; v.play().catch(() => {}); }
    setSom(!v.muted);
  };

  let acc = 0, sceneIdx = 0;
  for (let i = 0; i < SX_SCENES.length; i += 1) { if (t >= acc) sceneIdx = i; acc += SX_SCENES[i].dur; }
  const scene = SX_SCENES[sceneIdx];
  const wordIdx = SX_WORDS.reduce((k, [, ws], i) => (t >= ws ? i : k), 0);

  // paralaxe
  const mx = sUMV(0), my = sUMV(0);
  const sx = sUS(mx, { stiffness: 60, damping: 18 }), sy = sUS(my, { stiffness: 60, damping: 18 });
  const L = (k) => ({ x: sUT(sx, (v) => v * k), y: sUT(sy, (v) => v * k) });
  const lClips = L(26), lPhone = L(10), lTreat = L(20);
  const onMove = (e) => {
    if (reduced) return;
    const r = e.currentTarget.getBoundingClientRect();
    mx.set((e.clientX - r.left) / r.width - 0.5);
    my.set((e.clientY - r.top) / r.height - 0.5);
  };
  const secRef = React.useRef(null);
  const { scrollYProgress } = sUSc({ target: secRef, offset: ["start start", "end start"] });
  const stageY = sUT(scrollYProgress, [0, 1], [0, reduced ? 0 : -60]);
  const rise = (d) => (reduced ? {} : { initial: { opacity: 0, y: 28 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.85, delay: d, ease: EEsx } });

  return (
    <section id="topo" ref={secRef} onMouseMove={onMove} aria-labelledby="sx-hero-titulo" className="sx-studio relative overflow-hidden px-5 pb-20 pt-32 md:px-10 lg:px-16" style={{ background: "radial-gradient(110% 80% at 75% 5%, #0E2A33 0%, #070B1F 58%)" }}>
      <CaptixyHeroStyles />
      <div className="cx3d-grid pointer-events-none absolute inset-0" aria-hidden="true" />
      <div aria-hidden="true" className="pointer-events-none absolute right-[-10%] top-[-5%] h-[600px] w-[600px] rounded-full bg-[#2DD4BF] opacity-[0.14] blur-[140px]" />

      <div className="relative z-10 mx-auto grid max-w-7xl items-center gap-14 lg:grid-cols-[0.85fr_1.15fr]">
        <div className="min-w-0">
          <msx.div {...rise(0)} className="mb-7 flex items-center gap-4">
            <span className="inline-block h-px w-8 bg-[#2DD4BF]" />
            <CaptixyRotatingWord words={["Tu gravas", "Nós montamos", "Tu publicas"]} />
          </msx.div>
          <msx.h1 {...rise(0.08)} id="sx-hero-titulo" className="serif text-[clamp(46px,6.2vw,92px)] font-normal leading-[0.96] tracking-[-0.025em] text-[#F7F8FF]">
            Grava 20 segundos. <em className="serif italic text-[#5EEAD4]">Recebe um reel pronto a publicar.</em>
          </msx.h1>
          <msx.p {...rise(0.16)} className="mt-7 max-w-md text-[17px] leading-[1.65] text-[#F7F8FF]/68">
            Falas do imóvel e gravas a casa com o telemóvel. Nós montamos o reel: cortes, legendas, o título atrás de ti e o teu contacto no fim.
          </msx.p>
          <msx.div {...rise(0.24)} className="mt-9 flex flex-wrap gap-3">
            <a href="#piloto" className="inline-flex items-center gap-2 rounded-full bg-[#2DD4BF] px-6 py-3.5 text-[15px] font-semibold text-[#04201C] shadow-[0_18px_44px_-14px_rgba(45,212,191,0.7)] transition-transform hover:-translate-y-0.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#070B1F]">
              Quero uma vaga no piloto <IARsx className="h-4 w-4" />
            </a>
            <a href="#como-funciona" className="inline-flex items-center rounded-full bg-white/[0.07] px-6 py-3.5 text-[15px] font-medium text-[#F7F8FF] ring-1 ring-white/20 transition-colors hover:bg-white/[0.12] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70">Ver como funciona</a>
          </msx.div>
          <msx.p {...rise(0.32)} className="mt-7 flex items-center gap-2 text-sm text-[#F7F8FF]/55">
            <span aria-hidden="true" className="h-2 w-2 rounded-full bg-[#2DD4BF]" />
            Piloto gratuito em novembro e dezembro · 3 vagas · para consultores imobiliários
          </msx.p>
        </div>

        {/* Estúdio */}
        <msx.div style={{ y: stageY }} className="relative min-w-0" aria-label="Exemplo: os clips do consultor são montados num reel com legendas, cortes e cartão final">
          <div className="grid min-w-0 items-center gap-5 md:grid-cols-[170px_auto_190px]">
            {/* clips em bruto */}
            <msx.ul style={lClips} className="hidden flex-col gap-2.5 md:flex" aria-label="Os teus clips">
              <li className="mb-1 text-xs text-[#F7F8FF]/45">Os teus clips</li>
              {SX_CLIPS.map((c, i) => {
                const on = scene.clip === i;
                return (
                  <li key={c.nome} className="flex items-center gap-2.5 rounded-xl bg-[#0B1430]/90 p-2 transition-all duration-500" style={{ boxShadow: on ? "0 0 0 1px rgba(45,212,191,0.7), 0 10px 30px -10px rgba(45,212,191,0.6)" : "0 0 0 1px rgba(255,255,255,0.07)", transform: on ? "translateX(8px)" : "none", opacity: on ? 1 : 0.62 }}>
                    <span className="relative h-10 w-7 shrink-0 overflow-hidden rounded-md" style={{ background: c.thumb ? `center / cover url(${sxThumb(c)})` : `linear-gradient(160deg, ${c.cor}, #0B0F1F)` }}>
                      {on && !reduced && <span className="absolute inset-x-0 bottom-0 h-0.5 bg-[#2DD4BF]" />}
                    </span>
                    <span className="min-w-0">
                      <span className="block truncate text-[12px] font-semibold text-[#F7F8FF]">{c.nome}</span>
                      <span className="block text-[10.5px] text-[#F7F8FF]/45">{c.dur}</span>
                    </span>
                  </li>
                );
              })}
            </msx.ul>

            {/* o reel verdadeiro, gerado pelo motor */}
            <msx.div style={lPhone} className="relative mx-auto w-[240px] sm:w-[262px]">
              <div className="sx-phone" style={{ aspectRatio: "9 / 16", boxShadow: "0 0 0 1px rgba(45,212,191,0.45), 0 50px 110px -30px rgba(45,212,191,0.55), 0 30px 60px -24px rgba(0,0,0,0.8)" }}>
                <video
                  ref={videoRef}
                  className="h-full w-full object-cover"
                  style={{ borderRadius: "clamp(12px, 2.8vw, 22px)" }}
                  src={SX_DEMO_VIDEO}
                  poster="assets/social/demo-reel-poster.webp"
                  autoPlay={!reduced}
                  controls={reduced}
                  muted
                  loop
                  playsInline
                  preload="auto"
                  aria-label="Reel de exemplo gerado pelo Captixy Social: consultor apresenta uma moradia T4 em Cascais, com título atrás dele, legendas, cortes para o jardim, cozinha, suite e quarto, e cartão final com preço e contacto"
                />
              </div>
              <button
                type="button"
                onClick={alternarSom}
                aria-pressed={som}
                className="absolute -bottom-4 left-1/2 inline-flex -translate-x-1/2 items-center gap-2 whitespace-nowrap rounded-full bg-[#2DD4BF] px-4 py-2 text-[13px] font-semibold text-[#04201C] shadow-[0_14px_30px_-10px_rgba(45,212,191,0.8)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white"
              >
                {som ? "Tirar o som" : "Ouvir com som"}
              </button>
            </msx.div>

            {/* o que tratamos */}
            <msx.ul style={lTreat} className="hidden flex-col gap-2 md:flex" aria-label="O que fazemos ao vídeo">
              <li className="mb-1 text-xs text-[#F7F8FF]/45">O que tratamos</li>
              {SX_TREAT.map(([x, quando]) => {
                const done = reduced || t >= quando;
                return (
                  <li key={x} className="flex items-start gap-2 text-[12.5px] leading-snug transition-all duration-500" style={{ color: done ? "#F7F8FF" : "rgba(247,248,255,0.35)", transform: done ? "none" : "translateX(6px)" }}>
                    <span className="mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-[9px] transition-colors duration-500" style={{ background: done ? "#2DD4BF" : "rgba(255,255,255,0.08)", color: "#04201C" }}>{done ? "✓" : ""}</span>
                    {x}
                  </li>
                );
              })}
            </msx.ul>
          </div>

          {/* linha do tempo */}
          <div className="mt-7 rounded-2xl bg-[#0B1430]/85 p-4 ring-1 ring-white/[0.07]" aria-hidden="true">
            <div className="flex items-center justify-between text-[11px] text-[#F7F8FF]/45">
              <span>reel_moradia_T4_cascais.mp4 · 1080×1920</span>
              <span>0:{String(Math.floor(t / 1000)).padStart(2, "0")} / 0:{String(Math.round(SX_TOTAL / 1000)).padStart(2, "0")}</span>
            </div>
            <div className="relative mt-3">
              <div className="flex h-7 min-w-0 gap-1 overflow-hidden rounded-lg">
                {SX_SCENES.map((sc, i) => (
                  <div key={i} className="flex min-w-0 items-center overflow-hidden whitespace-nowrap px-2 text-[10.5px] font-semibold text-white/85 transition-opacity" style={{ flex: sc.dur, background: SX_CLIPS[sc.clip].thumb ? `linear-gradient(90deg, rgba(0,0,0,0.55), rgba(0,0,0,0.2)), center / cover url(${sxThumb(SX_CLIPS[sc.clip])})` : SX_CLIPS[sc.clip].cor, opacity: i === sceneIdx ? 1 : 0.55 }}>
                    {SX_CLIPS[sc.clip].nome.replace(".mp4", "").replace("_intro", "")}
                  </div>
                ))}
              </div>
              <SxWave playRef={playRef} reduced={reduced} />
              <div className="pointer-events-none absolute -bottom-1 -top-1 w-px bg-[#5EEAD4] shadow-[0_0_12px_rgba(94,234,212,0.9)]" style={{ left: `${(t / SX_TOTAL) * 100}%` }} />
            </div>
            <div className="mt-2 truncate text-[12px] text-[#F7F8FF]/50">
              {SX_WORDS.map(([w], i) => (
                <span key={w + i} className="mr-1 transition-colors" style={{ color: i === wordIdx ? "#5EEAD4" : i < wordIdx ? "rgba(247,248,255,0.75)" : undefined }}>{w}</span>
              ))}
            </div>
          </div>
        </msx.div>
      </div>
    </section>
  );
}

function Hero() {
  return <SxStudioHero />;
}

/* ---------- O problema: só texto ---------- */
const SX_PROBLEMAS = [
  { titulo: "Editar come as noites", texto: "Cortar, legendar e acertar o som leva horas por vídeo." },
  { titulo: "Um editor custa e demora", texto: "E raramente está disponível quando a casa entra no mercado." },
  { titulo: "Nem toda a gente gosta da câmara", texto: "Há um formato só com a tua voz e as imagens da casa." },
];

function Problema() {
  return (
    <section aria-labelledby="sx-problema" className="sx-band">
      <div className="sx-wrap sx-section">
        <CabecalhoSecao id="sx-problema" titulo="Sabes que tens de fazer vídeos." destaque="O problema é o resto." texto="Os reels vendem casas, mas fazê-los bem tira tempo que devias passar com clientes." />
        <div className="sx-problemas">
          {SX_PROBLEMAS.map((c, i) => (
            <Revela key={c.titulo} delay={i * 0.06} className="sx-problema">
              <h3 className="sx-h3">{c.titulo}</h3>
              <p className="sx-tile-texto">{c.texto}</p>
            </Revela>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- Como funciona: diagrama de fluxo ---------- */
const SX_FLUXO = [
  { icone: I.camara, titulo: "Gravas", sub: "20 s a falar + 5 s por divisão", tu: true },
  { icone: I.enviar, titulo: "Envias", sub: "Drive, WeTransfer ou WhatsApp", tu: true },
  { icone: I.tesoura, titulo: "Editamos", sub: "Cortes, legendas, título, som",  },
  { icone: I.receber, titulo: "Recebes o reel", sub: "Pronto a publicar, com dicas", tempo: "até 48 h" },
];

function ComoFunciona() {
  return (
    <section id="como-funciona" aria-labelledby="sx-como" className="sx-anchor">
      <div className="sx-wrap sx-section">
        <CabecalhoSecao id="sx-como" etiqueta="Como funciona" titulo="Do telemóvel ao reel." destaque="Tu só gravas e envias." texto="Gravas com o telemóvel, envias como te der mais jeito e recebes o reel pronto a publicar." />
        <Revela>
          <ol className="sx-fluxo" role="list">
            {SX_FLUXO.map((p, i) => (
              <li key={p.titulo} className={`sx-fluxo-no ${p.tu ? "is-tu" : "is-nos"}`}>
                <span className="sx-fluxo-icone"><Ico d={p.icone} /></span>
                <span className="sx-fluxo-quem">{p.tu ? "Tu" : "Nós"}</span>
                <strong className="sx-fluxo-titulo">{p.titulo}</strong>
                <span className="sx-fluxo-sub">{p.sub}</span>
                {p.tempo ? <span className="sx-fluxo-tempo">{p.tempo}</span> : null}
                {i < SX_FLUXO.length - 1 ? <span aria-hidden="true" className="sx-fluxo-seta" /> : null}
              </li>
            ))}
          </ol>
        </Revela>
      </div>
    </section>
  );
}

/* ---------- O que inclui: anatomia de um reel (diagrama de linha do tempo) ---------- */
const SX_ANATOMIA = [
  { n: 1, titulo: "Título atrás de ti", texto: "O nome da zona fica atrás de ti, como nos grandes criadores.", x: 6 },
  { n: 2, titulo: "Legendas palavra a palavra", texto: "Na cor da tua marca. Quem vê sem som percebe tudo.", x: 30 },
  { n: 3, titulo: "Cortes no momento certo", texto: "Dizes “suite” e aparece a suite.", x: 44 },
  { n: 4, titulo: "Imagem e som tratados", texto: "Estabilizado, mais luz, voz nivelada e música por baixo.", x: 66 },
  { n: 5, titulo: "Preço e contacto no ecrã", texto: "Tipologia, preço e o teu contacto a meio e no fim.", x: 90 },
];
const SX_SEGMENTOS = [
  ["tu", "Tu", 16],
  ["casa", "Exterior", 14],
  ["casa", "Cozinha", 16],
  ["casa", "Suite", 16],
  ["casa", "Quarto", 16],
  ["cartao", "Preço", 22],
];

function Inclui() {
  return (
    <section id="inclui" aria-labelledby="sx-inclui" className="sx-anchor sx-band">
      <div className="sx-wrap sx-section">
        <CabecalhoSecao id="sx-inclui" etiqueta="O que inclui" titulo="Edição a sério," destaque="sem abrires uma app." texto="Tudo o que um editor faria num reel imobiliário, em cada segundo do vídeo." />
        <Revela className="sx-anatomia">
          <div className="sx-anatomia-diagrama" aria-hidden="true">
            <div className="sx-anatomia-pinos">
              {SX_ANATOMIA.map((a) => (
                <span key={a.n} className="sx-pino" style={{ left: `${a.x}%` }}>{a.n}</span>
              ))}
            </div>
            <div className="sx-pista">
              <span className="sx-pista-nome">Imagem</span>
              <div className="sx-pista-corpo">
                {SX_SEGMENTOS.map(([t, l, w], i) => (
                  <span key={i} className={`sx-seg2 sx-seg2--${t}`} style={{ flexGrow: w }}>{l}</span>
                ))}
              </div>
            </div>
            <div className="sx-pista">
              <span className="sx-pista-nome">Legendas</span>
              <div className="sx-pista-corpo sx-pista-legendas">
                {Array.from({ length: 34 }).map((_, i) => (
                  <span key={i} style={{ flexGrow: 2 + ((i * 7) % 5) }} />
                ))}
              </div>
            </div>
            <div className="sx-pista">
              <span className="sx-pista-nome">Som</span>
              <div className="sx-pista-corpo sx-pista-som">
                <span className="sx-onda" />
                <span className="sx-onda sx-onda--musica" />
              </div>
            </div>
            <div className="sx-regua">
              {["0 s", "10 s", "20 s", "30 s"].map((t) => <span key={t}>{t}</span>)}
            </div>
          </div>
          <ol className="sx-anatomia-lista" role="list">
            {SX_ANATOMIA.map((a) => (
              <li key={a.n}>
                <span className="sx-pino sx-pino--lista" aria-hidden="true">{a.n}</span>
                <span>
                  <strong>{a.titulo}</strong>
                  <span>{a.texto}</span>
                </span>
              </li>
            ))}
          </ol>
          <p className="sx-anatomia-extra">
            <Ico d={I.grafico} className="h-4 w-4" /> E com cada reel, dicas concretas para o próximo sair ainda melhor.
          </p>
        </Revela>
      </div>
    </section>
  );
}

/* ---------- Formatos: só a linha do tempo de cada um ---------- */
const SX_FORMATOS = [
  { titulo: "Contigo a falar", texto: "Cria mais confiança: tu na abertura e no fecho.", faixa: ["tu", "casa", "casa", "casa", "tu"] },
  { titulo: "Sem cara, com a tua voz", texto: "Só a tua voz por cima das imagens da casa.", faixa: ["casa", "casa", "casa", "casa", "casa"], voz: true },
  { titulo: "Montagem com música", texto: "A visita com música e o nome de cada divisão.", faixa: ["casa", "casa", "casa", "casa", "casa"], musica: true },
];

function Formatos() {
  return (
    <section id="formatos" aria-labelledby="sx-formatos" className="sx-anchor">
      <div className="sx-wrap sx-section">
        <CabecalhoSecao id="sx-formatos" etiqueta="Três formatos" titulo="Escolhes o formato." destaque="Ou deixas connosco." texto="Usamos o que funcionar melhor com o que gravaste." />
        <div className="sx-grid-3">
          {SX_FORMATOS.map((f, i) => (
            <Revela key={f.titulo} delay={i * 0.06} className="sx-tile sx-formato">
              <h3 className="sx-h3">{f.titulo}</h3>
              <p className="sx-tile-texto">{f.texto}</p>
              <Faixa faixa={f.faixa} voz={f.voz} musica={f.musica} />
            </Revela>
          ))}
        </div>
      </div>
    </section>
  );
}

function Piloto() {
  return (
    <section id="piloto" aria-labelledby="sx-piloto" className="sx-anchor">
      <div className="sx-wrap sx-section sx-section--sem-topo">
        <Revela className="sx-piloto">
          <div aria-hidden="true" className="sx-piloto-glow" />
          <div className="sx-piloto-texto">
            <Etiqueta>Piloto · 3 vagas</Etiqueta>
            <h2 id="sx-piloto" className="sx-h2">
              Grátis em <em>novembro e dezembro.</em>
            </h2>
            <p className="sx-lead sx-lead--compacto">Procuro 3 consultores para testar o serviço e dar feedback sem filtros.</p>
            <div className="sx-vagas" aria-hidden="true">
              {[0, 1, 2].map((n) => (
                <span key={n} className="sx-vaga" />
              ))}
            </div>
          </div>
          <div className="sx-piloto-lado">
            <ul className="sx-lista" role="list">
              {PILOTO_LISTA.map((item) => (
                <li key={item}>
                  <span aria-hidden="true" className="sx-lista-icon">
                    <ICsx className="h-3.5 w-3.5" />
                  </span>
                  <span>{item}</span>
                </li>
              ))}
            </ul>
            <div className="mt-8">
              <BotaoPrimario href="#contacto">Quero uma das vagas</BotaoPrimario>
            </div>
          </div>
        </Revela>
      </div>
    </section>
  );
}

function Perguntas() {
  return (
    <section id="perguntas" aria-labelledby="sx-perguntas" className="sx-anchor">
      <div className="sx-wrap sx-section sx-section--sem-topo">
        <div className="sx-faq-grelha">
          <CabecalhoSecao id="sx-perguntas" titulo="Perguntas" destaque="frequentes" />
          <div className="sx-faq">
            {PERGUNTAS.map(({ p, r }) => (
              <details key={p} className="sx-faq-item">
                <summary>
                  <span>{p}</span>
                  <span aria-hidden="true" className="sx-faq-mais" />
                </summary>
                <p>{r}</p>
              </details>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

/* ---------- Contacto: por agora, só email ---------- */
function Contacto() {
  const { email, emailAssunto } = SOCIAL_CONTACTO;
  const mailto = `mailto:${email}?subject=${encodeURIComponent(emailAssunto)}`;
  const [copiado, setCopiado] = React.useState(false);
  async function copiar() {
    try {
      await navigator.clipboard.writeText(email);
      setCopiado(true);
      window.setTimeout(() => setCopiado(false), 2000);
    } catch {
      window.location.href = mailto;
    }
  }
  return (
    <section id="contacto" aria-labelledby="sx-contacto" className="sx-anchor sx-band">
      <div className="sx-wrap sx-section">
        <Revela className="sx-email">
          <div aria-hidden="true" className="sx-piloto-glow" />
          <span className="sx-email-icone" aria-hidden="true"><Ico d={I.email} className="h-7 w-7" /></span>
          <h2 id="sx-contacto" className="sx-h2">
            Fala <em>comigo.</em>
          </h2>
          <a className="sx-email-valor" href={mailto}>{email}</a>
          <div className="sx-email-acoes">
            <BotaoPrimario href={mailto}>Enviar email</BotaoPrimario>
            <button type="button" onClick={copiar} className="sx-btn sx-btn--secundario" aria-live="polite">
              {copiado ? "Copiado ✓" : "Copiar email"}
            </button>
          </div>
        </Revela>
      </div>
    </section>
  );
}

/* ============================================================
   ESTILOS LOCAIS (só desta página; não mexem no styles.css partilhado)
   Cores e tipos vêm dos tokens do site (styles.css + tema "social").
============================================================ */
function SocialStyles() {
  return (
    <style>{`
      .cx-social {
        --sx-bg: var(--bg, #070B1F);
        --sx-band: var(--bg-soft, #111530);
        --sx-card: rgba(255,255,255,0.03);
        --sx-card-hover: rgba(255,255,255,0.055);
        --sx-border: rgba(185,190,214,0.14);
        --sx-text: var(--primary, #F7F8FF);
        --sx-muted: var(--cream, #B9BED6);
        --sx-accent: var(--orange, #2DD4BF);
        --sx-accent-soft: var(--orange-soft, #5EEAD4);
        --sx-accent-rgb: var(--accent-rgb, 45,212,191);
        --sx-warm: #FF8289;
        --sx-on-accent: #04121A;
        background: var(--sx-bg);
        color: var(--sx-text);
        overflow-x: clip;
      }
      .cx-social em { font-family: 'Instrument Serif', 'Times New Roman', serif; font-style: italic; font-weight: 400; color: var(--sx-accent-soft); letter-spacing: -0.01em; }

      .sx-wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
      @media (min-width: 768px) { .sx-wrap { padding-left: 32px; padding-right: 32px; } }
      .sx-wrap--estreito { max-width: 860px; }
      .sx-section { padding-top: clamp(56px, 7vw, 96px); padding-bottom: clamp(56px, 7vw, 96px); display: flex; flex-direction: column; gap: clamp(28px, 3.5vw, 44px); }
      .sx-section--sem-topo { padding-top: clamp(16px, 2vw, 24px); }
      .sx-anchor { scroll-margin-top: 96px; }
      .sx-band { background: var(--sx-band); border-top: 1px solid rgba(255,255,255,0.05); border-bottom: 1px solid rgba(255,255,255,0.05); }
      .sx-cabecalho { max-width: 46rem; }

      .sx-eyebrow { display: inline-flex; align-items: center; gap: 12px; margin: 0 0 18px; font-size: 12px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--sx-accent-soft); }
      .sx-eyebrow-line { display: inline-block; width: 28px; height: 1px; background: var(--sx-accent); }
      .sx-produto { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 22px; padding: 6px 14px 6px 6px; border-radius: 999px; font-size: 13px; color: var(--sx-muted); background: rgba(255,255,255,0.04); box-shadow: 0 0 0 1px var(--sx-border); }
      .sx-produto-marca { padding: 4px 10px; border-radius: 999px; font-weight: 700; color: var(--sx-on-accent); background: linear-gradient(135deg, var(--sx-accent-soft), var(--sx-accent)); }
      .sx-produto-sep { display: none; }
      .sx-h1 { margin: 0; font-weight: 400; font-size: clamp(42px, 6.2vw, 82px); line-height: 0.98; letter-spacing: -0.045em; max-width: 13ch; color: var(--sx-text); }
      .sx-h1 em { display: block; margin-top: 0.06em; font-size: 1.04em; line-height: 0.95; }
      .sx-h2 { margin: 0; font-weight: 400; font-size: clamp(30px, 4.2vw, 54px); line-height: 1.04; letter-spacing: -0.04em; color: var(--sx-text); }
      .sx-h3 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; letter-spacing: -0.01em; color: var(--sx-text); }
      .sx-lead { margin: 26px 0 0; max-width: 540px; font-size: clamp(16px, 1.3vw, 18px); line-height: 1.65; color: var(--sx-muted); }
      .sx-lead--compacto { margin-top: 18px; }
      .sx-hero-ctas { margin-top: 34px; display: flex; flex-wrap: wrap; gap: 12px; }
      .sx-nota { margin: 22px 0 0; display: inline-flex; align-items: center; gap: 10px; font-size: 14px; color: var(--sx-muted); }
      .sx-dot { position: relative; width: 8px; height: 8px; border-radius: 999px; background: var(--sx-accent); flex: none; }
      .sx-dot::after { content: ""; position: absolute; inset: -4px; border-radius: 999px; border: 2px solid rgba(var(--sx-accent-rgb),0.5); animation: sx-pulso 2.2s ease-out infinite; }
      @keyframes sx-pulso { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
      .sx-link { color: var(--sx-accent-soft); text-decoration: underline; text-underline-offset: 3px; }
      .sx-link:hover { color: #fff; }

      .sx-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; padding: 12px 24px; border-radius: 999px; font-size: 15px; font-weight: 700; text-decoration: none; transition: transform .25s ease, background-color .25s ease, box-shadow .25s ease, filter .25s ease; }
      .sx-btn:hover { transform: translateY(-2px); }
      .sx-btn--primario { color: var(--sx-on-accent); background: linear-gradient(135deg, var(--sx-accent-soft) 0%, var(--sx-accent) 100%); box-shadow: 0 18px 40px -16px rgba(var(--sx-accent-rgb),0.75); }
      .sx-btn--primario:hover { filter: brightness(1.06); box-shadow: 0 22px 48px -16px rgba(var(--sx-accent-rgb),0.85); }
      .sx-btn--secundario { color: var(--sx-text); border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.04); }
      .sx-btn--secundario:hover { background: rgba(255,255,255,0.09); }
      .cx-social a:focus-visible, .cx-social summary:focus-visible { outline: 2px solid var(--sx-accent-soft); outline-offset: 3px; border-radius: 12px; }

      .sx-grid-3 { display: grid; grid-template-columns: 1fr; gap: 14px; margin: 0; padding: 0; list-style: none; }
      @media (min-width: 720px) { .sx-grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
      @media (min-width: 1024px) { .sx-grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; } }
      .sx-card { position: relative; height: 100%; display: flex; flex-direction: column; gap: 10px; padding: 24px; border-radius: 22px; background: var(--sx-card); border: 1px solid var(--sx-border); transition: border-color .3s ease, background-color .3s ease, transform .3s ease; }
      .sx-card:hover { border-color: rgba(var(--sx-accent-rgb),0.35); background: var(--sx-card-hover); }
      .sx-card-icone { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; margin-bottom: 8px; border-radius: 13px; color: var(--sx-accent-soft); background: rgba(var(--sx-accent-rgb),0.1); box-shadow: inset 0 0 0 1px rgba(var(--sx-accent-rgb),0.22); }
      .sx-card-etiqueta { font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sx-accent-soft); }
      .sx-card-texto { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--sx-muted); }

      /* passos: linha que liga os três cartões em ecrãs largos */
      .sx-passos { counter-reset: passo; }
      @media (min-width: 1024px) {
        .sx-passos { position: relative; }
        .sx-passos::before { content: ""; position: absolute; top: 45px; left: 12%; right: 12%; height: 1px; background: linear-gradient(90deg, transparent, rgba(var(--sx-accent-rgb),0.45), transparent); }
        .sx-passos .sx-card { background: color-mix(in srgb, var(--sx-bg) 86%, white 3%); }
      }

      /* hero */
      .sx-hero { position: relative; overflow: hidden; padding-top: clamp(116px, 15vh, 156px); padding-bottom: clamp(64px, 8vw, 104px); background: radial-gradient(120% 90% at 85% 0%, #142246 0%, var(--sx-bg) 58%); }
      .sx-hero-glow { position: absolute; right: -8%; top: -10%; width: 52vw; height: 52vw; max-width: 720px; max-height: 720px; border-radius: 999px; background: radial-gradient(circle, rgba(var(--sx-accent-rgb),0.16) 0%, transparent 66%); pointer-events: none; }
      .sx-hero-glow--2 { right: auto; left: -18%; top: 40%; width: 40vw; height: 40vw; background: radial-gradient(circle, rgba(123,97,255,0.12) 0%, transparent 66%); }
      .sx-hero-grid { position: relative; display: grid; grid-template-columns: 1fr; gap: 56px; align-items: center; }
      @media (min-width: 1024px) { .sx-hero-grid { grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr); gap: 40px; } }

      /* telemóveis (ilustração) */
      .sx-reels { position: relative; display: flex; justify-content: center; align-items: flex-start; gap: clamp(8px, 2vw, 18px); }
      .sx-reel { margin: 0; flex: 1 1 0; max-width: 188px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; }
      .sx-reel--a { padding-top: clamp(20px, 4vw, 40px); animation: sx-flutua 7s ease-in-out infinite; }
      .sx-reel--b { animation: sx-flutua 7s ease-in-out -2.3s infinite; }
      .sx-reel--b .sx-phone { box-shadow: 0 0 0 1px rgba(var(--sx-accent-rgb),0.45), 0 40px 80px -28px rgba(var(--sx-accent-rgb),0.45), 0 30px 60px -24px rgba(0,0,0,0.8); }
      .sx-reel--c { padding-top: clamp(28px, 6vw, 60px); animation: sx-flutua 7s ease-in-out -4.6s infinite; }
      @keyframes sx-flutua { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
      .sx-reel-caption { display: flex; align-items: flex-start; justify-content: center; gap: 8px; font-size: clamp(12px, 1.3vw, 14px); line-height: 1.35; text-align: left; color: var(--sx-muted); }
      .sx-reel-num { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--sx-on-accent); background: var(--sx-accent); }
      @media (max-width: 480px) { .sx-reel-caption { flex-direction: column; align-items: center; text-align: center; } }
      .sx-phone { width: 100%; aspect-ratio: 9 / 18.5; border-radius: clamp(16px, 3.4vw, 28px); padding: clamp(4px, 0.8vw, 6px); background: #03050C; box-shadow: 0 0 0 1px rgba(255,255,255,0.12), 0 30px 60px -24px rgba(0,0,0,0.8); container-type: inline-size; }
      .sx-screen { position: relative; display: block; width: 100%; height: 100%; overflow: hidden; border-radius: clamp(12px, 2.8vw, 22px); }
      .sx-video { object-fit: cover; background: #000; }
      .sx-screen-inner { position: absolute; inset: 0; }
      .sx-legenda { position: absolute; z-index: 3; left: 6%; right: 6%; bottom: 22%; text-align: center; font-weight: 800; font-size: 8.5cqw; letter-spacing: 0.01em; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7); }
      .sx-legenda--claro { color: #111827; text-shadow: none; }
      .sx-destaque { color: #C7243A; }
      .sx-destaque--claro { color: var(--sx-accent-soft); }

      .sx-rc-barras { position: absolute; z-index: 4; top: 3.5%; left: 6%; right: 6%; display: flex; gap: 3%; }
      .sx-rc-barras span { flex: 1; height: 2px; border-radius: 2px; background: rgba(255,255,255,0.35); }
      .sx-rc-barras span.is-cheia { background: #fff; }
      .sx-rc-acoes { position: absolute; z-index: 4; right: 5%; bottom: 30%; display: flex; flex-direction: column; gap: 7cqw; }
      .sx-rc-acoes span { width: 9cqw; height: 9cqw; border-radius: 999px; background: rgba(255,255,255,0.85); }
      .sx-rc-conta { position: absolute; z-index: 4; left: 7%; bottom: 7%; font-size: 6cqw; font-weight: 700; color: rgba(255,255,255,0.92); }
      .sx-rc--escuro.sx-rc-barras span { background: rgba(17,24,39,0.2); }
      .sx-rc--escuro.sx-rc-barras span.is-cheia { background: #111827; }
      .sx-rc--escuro.sx-rc-acoes span { background: rgba(17,24,39,0.55); }
      .sx-rc--escuro.sx-rc-conta { color: rgba(17,24,39,0.8); }

      .sx-foto { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
      .sx-vinheta { position: absolute; inset: 0; z-index: 2; background: linear-gradient(180deg, rgba(0,0,0,0.28) 0%, transparent 18%, transparent 55%, rgba(0,0,0,0.62) 100%); pointer-events: none; }
      /* Caixa 9:16 com a altura do ecrã, centrada: foto e recorte partilham a mesma geometria. */
      .sx-caixa { position: absolute; top: 0; bottom: 0; left: 50%; height: 100%; aspect-ratio: 720 / 1280; transform: translateX(-50%); }
      .sx-caixa > img { position: absolute; inset: 0; width: 100%; height: 100%; }
      .sx-caixa--frente { z-index: 2; }
      .sx-caixa > img.sx-t-recorte { inset: auto; left: 18.6%; top: 18.67%; width: 61.4%; height: auto; }
      .sx-screen--titulo { background: #8C98A6; }
      .sx-t-titulo { position: absolute; top: 12%; left: 0; right: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; line-height: 0.9; font-weight: 800; }
      .sx-t-l1 { font-size: 23cqw; color: #fff; letter-spacing: -0.02em; }
      .sx-t-l2 { font-size: 14.5cqw; letter-spacing: -0.01em; color: var(--sx-accent-soft); }

      .sx-screen--corte { background: #D9D6D0; }
      .sx-c-tag { position: absolute; z-index: 4; top: 8%; left: 7%; display: inline-flex; align-items: center; gap: 2cqw; padding: 1.5cqw 3cqw; border-radius: 999px; font-size: 6cqw; font-weight: 700; color: #111827; background: rgba(255,255,255,0.92); }
      .sx-c-rec { width: 3cqw; height: 3cqw; border-radius: 999px; background: #14B8A6; }

      .sx-screen--cartao { background: #0A1222; }
      .sx-k-veu { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(7,11,31,0.55), rgba(7,11,31,0.82)); }
      .sx-k { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5cqw; padding: 0 6%; text-align: center; color: #fff; }
      .sx-k-dados { padding: 1.5cqw 3cqw; border-radius: 999px; font-size: 6cqw; font-weight: 800; color: var(--sx-on-accent); background: var(--sx-accent); white-space: nowrap; }
      .sx-k-preco { font-size: 15cqw; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
      .sx-k-linha { width: 30%; height: 1px; background: rgba(255,255,255,0.25); }
      .sx-k-cta { font-size: 6.8cqw; line-height: 1.55; color: #D6DAE8; }
      .sx-k-cta strong { color: #fff; }

      /* formatos: linha do tempo */
      .sx-faixa { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 6px; }
      .sx-faixa-video { display: flex; gap: 3px; }
      .sx-seg { flex: 1; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
      .sx-seg--tu { color: #3A0D13; background: var(--sx-warm); }
      .sx-seg--casa { color: rgba(var(--sx-accent-rgb),1); background: rgba(var(--sx-accent-rgb),0.14); box-shadow: inset 0 0 0 1px rgba(var(--sx-accent-rgb),0.3); }
      .sx-faixa-audio { position: relative; display: flex; align-items: center; gap: 8px; height: 18px; }
      .sx-onda { flex: 1; height: 100%; border-radius: 4px; background: repeating-linear-gradient(90deg, rgba(185,190,214,0.55) 0 2px, transparent 2px 5px); mask: linear-gradient(180deg, transparent 0, #000 30%, #000 70%, transparent 100%); -webkit-mask: linear-gradient(180deg, transparent 0, #000 30%, #000 70%, transparent 100%); }
      .sx-onda--musica { background: repeating-linear-gradient(90deg, rgba(var(--sx-accent-rgb),0.6) 0 3px, transparent 3px 7px); }
      .sx-faixa-label { flex: none; font-size: 11px; color: var(--sx-muted); }

      /* piloto */
      .sx-piloto { position: relative; overflow: hidden; display: grid; grid-template-columns: 1fr; gap: 36px; padding: clamp(28px, 5vw, 56px); border-radius: 30px; background: linear-gradient(135deg, rgba(var(--sx-accent-rgb),0.12) 0%, rgba(255,255,255,0.02) 55%); border: 1px solid rgba(var(--sx-accent-rgb),0.35); }
      .sx-piloto-glow { position: absolute; right: -10%; bottom: -40%; width: 60%; aspect-ratio: 1; border-radius: 999px; background: radial-gradient(circle, rgba(var(--sx-accent-rgb),0.18), transparent 65%); pointer-events: none; }
      .sx-piloto-texto, .sx-piloto-lado { position: relative; }
      @media (min-width: 900px) { .sx-piloto { grid-template-columns: 1.1fr 1fr; gap: 56px; align-items: center; } }
      .sx-vagas { margin-top: 24px; display: flex; gap: 8px; }
      .sx-vaga { width: 40px; height: 6px; border-radius: 999px; background: var(--sx-accent); box-shadow: 0 0 16px rgba(var(--sx-accent-rgb),0.5); }
      .sx-lista { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 14px; }
      .sx-lista li { display: flex; gap: 12px; align-items: flex-start; font-size: 16px; line-height: 1.5; color: var(--sx-text); }
      .sx-lista-icon { flex: none; margin-top: 1px; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 999px; color: var(--sx-on-accent); background: var(--sx-accent); }

      /* perguntas */
      .sx-faq { display: flex; flex-direction: column; border-top: 1px solid var(--sx-border); }
      .sx-faq-item { border-bottom: 1px solid var(--sx-border); }
      .sx-faq-item summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; padding: 18px 4px; font-size: 18px; font-weight: 700; color: var(--sx-text); transition: color .2s ease; }
      .sx-faq-item summary:hover { color: var(--sx-accent-soft); }
      .sx-faq-item summary::-webkit-details-marker { display: none; }
      .sx-faq-mais { position: relative; flex: none; width: 30px; height: 30px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.2); transition: background-color .25s ease, border-color .25s ease; }
      .sx-faq-item[open] .sx-faq-mais { background: var(--sx-accent); border-color: var(--sx-accent); }
      .sx-faq-mais::before, .sx-faq-mais::after { content: ""; position: absolute; left: 50%; top: 50%; width: 11px; height: 1.5px; background: var(--sx-text); transform: translate(-50%, -50%); transition: transform .25s ease; }
      .sx-faq-item[open] .sx-faq-mais::before, .sx-faq-item[open] .sx-faq-mais::after { background: var(--sx-on-accent); }
      .sx-faq-mais::after { transform: translate(-50%, -50%) rotate(90deg); }
      .sx-faq-item[open] .sx-faq-mais::after { transform: translate(-50%, -50%) rotate(0deg); }
      .sx-faq-item p { margin: 0 0 22px; padding: 0 4px; max-width: 64ch; font-size: 16px; line-height: 1.65; color: var(--sx-muted); }

      /* contacto */
      .sx-contacto { display: grid; grid-template-columns: 1fr; gap: 32px; }
      @media (min-width: 900px) { .sx-contacto { grid-template-columns: 1fr 1fr; align-items: center; } }
      .sx-contacto-links { display: flex; flex-direction: column; gap: 12px; }
      .sx-contacto-link { display: flex; align-items: center; gap: 16px; min-height: 72px; padding: 14px 20px; border-radius: 18px; background: var(--sx-card); border: 1px solid var(--sx-border); text-decoration: none; color: var(--sx-text); transition: border-color .25s ease, background-color .25s ease, transform .25s ease; }
      a.sx-contacto-link:hover { border-color: rgba(var(--sx-accent-rgb),0.6); background: rgba(var(--sx-accent-rgb),0.06); transform: translateY(-2px); }
      .sx-contacto-icone { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 14px; color: var(--sx-accent-soft); background: rgba(var(--sx-accent-rgb),0.1); }
      .sx-contacto-corpo { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
      .sx-contacto-seta { flex: none; color: var(--sx-muted); }
      .sx-contacto-tipo { font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sx-muted); }
      .sx-contacto-valor { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
      .sx-placeholder { border: 2px dashed #FBBF5C; background: rgba(251,191,92,0.08); }
      .sx-placeholder .sx-contacto-valor { color: #FBBF5C; }
      .sx-contacto-nota { margin: 4px 0 0; font-size: 14px; color: var(--sx-muted); }
      .sx-assinatura { margin: 20px 0 0; font-size: 14px; color: var(--sx-muted); }


      /* ---- problema (texto), fluxo, anatomia, formatos, contacto ---- */
      .sx-tile { position: relative; height: 100%; display: flex; flex-direction: column; gap: 10px; padding: 24px; border-radius: 22px; background: var(--sx-card); border: 1px solid var(--sx-border); }
      .sx-tile-texto { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--sx-muted); }
      .sx-problemas { display: grid; grid-template-columns: 1fr; gap: 0; border-top: 1px solid var(--sx-border); }
      @media (min-width: 900px) { .sx-problemas { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 40px; } }
      .sx-problema { display: flex; flex-direction: column; gap: 8px; padding: 22px 0; border-bottom: 1px solid var(--sx-border); }
      @media (min-width: 900px) { .sx-problema { border-bottom: 0; padding-top: 28px; } }

      .sx-fluxo { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 26px; }
      @media (min-width: 900px) { .sx-fluxo { grid-template-columns: repeat(4, minmax(0,1fr)); gap: 28px; } }
      .sx-fluxo-no { position: relative; display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto auto; column-gap: 16px; row-gap: 2px; align-items: start; }
      @media (min-width: 900px) { .sx-fluxo-no { grid-template-columns: 1fr; row-gap: 6px; } }
      .sx-fluxo-icone { grid-row: span 4; display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 16px; color: var(--sx-accent-soft); background: rgba(var(--sx-accent-rgb),0.1); box-shadow: inset 0 0 0 1px rgba(var(--sx-accent-rgb),0.3); }
      .sx-fluxo-no.is-nos .sx-fluxo-icone { color: var(--sx-on-accent); background: linear-gradient(135deg, var(--sx-accent-soft), var(--sx-accent)); box-shadow: 0 16px 32px -16px rgba(var(--sx-accent-rgb),0.8); }
      @media (min-width: 900px) { .sx-fluxo-icone { grid-row: auto; margin-bottom: 10px; } }
      .sx-fluxo-quem { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sx-muted); }
      .sx-fluxo-no.is-nos .sx-fluxo-quem { color: var(--sx-accent-soft); }
      .sx-fluxo-titulo { font-size: 19px; color: var(--sx-text); }
      .sx-fluxo-sub { font-size: 14.5px; line-height: 1.5; color: var(--sx-muted); }
      .sx-fluxo-tempo { grid-column: 2; justify-self: start; margin-top: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--sx-text); background: rgba(255,255,255,0.06); box-shadow: inset 0 0 0 1px var(--sx-border); }
      @media (min-width: 900px) { .sx-fluxo-tempo { grid-column: auto; } }
      .sx-fluxo-seta { position: absolute; left: 25px; top: 60px; bottom: -22px; width: 2px; background: linear-gradient(180deg, rgba(var(--sx-accent-rgb),0.5), rgba(var(--sx-accent-rgb),0.1)); }
      @media (min-width: 900px) { .sx-fluxo-seta { left: 64px; right: -20px; top: 25px; bottom: auto; width: auto; height: 2px; background: linear-gradient(90deg, rgba(var(--sx-accent-rgb),0.55), rgba(var(--sx-accent-rgb),0.12)); } .sx-fluxo-seta::after { content: ""; position: absolute; right: 0; top: -4px; border: 5px solid transparent; border-left: 7px solid rgba(var(--sx-accent-rgb),0.6); border-right: 0; } }

      .sx-anatomia { display: flex; flex-direction: column; gap: 28px; padding: clamp(20px, 3.5vw, 36px); border-radius: 26px; background: var(--sx-card); border: 1px solid var(--sx-border); }
      .sx-anatomia-diagrama { position: relative; display: flex; flex-direction: column; gap: 8px; padding-top: 34px; }
      .sx-anatomia-pinos { position: absolute; top: 0; left: 84px; right: 0; height: 28px; }
      @media (max-width: 640px) { .sx-anatomia-pinos { left: 0; } }
      .sx-pino { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 999px; font-size: 12px; font-weight: 800; color: var(--sx-on-accent); background: var(--sx-accent); box-shadow: 0 0 0 4px rgba(var(--sx-accent-rgb),0.15); }
      .sx-anatomia-pinos .sx-pino { position: absolute; top: 0; transform: translateX(-50%); }
      .sx-anatomia-pinos .sx-pino::after { content: ""; position: absolute; top: 26px; left: 50%; width: 1px; height: 128px; background: linear-gradient(180deg, rgba(var(--sx-accent-rgb),0.6), transparent); }
      .sx-pista { display: flex; align-items: center; gap: 12px; }
      .sx-pista-nome { flex: none; width: 72px; font-size: 12px; font-weight: 700; color: var(--sx-muted); }
      @media (max-width: 640px) { .sx-pista-nome { display: none; } }
      .sx-pista-corpo { flex: 1; min-width: 0; display: flex; gap: 3px; height: 34px; }
      .sx-seg2 { min-width: 0; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 7px; font-size: 11px; font-weight: 700; white-space: nowrap; }
      .sx-seg2--tu { color: #3A0D13; background: var(--sx-warm); }
      .sx-seg2--casa { color: rgba(var(--sx-accent-rgb),1); background: rgba(var(--sx-accent-rgb),0.14); box-shadow: inset 0 0 0 1px rgba(var(--sx-accent-rgb),0.3); }
      .sx-seg2--cartao { color: var(--sx-on-accent); background: var(--sx-accent-soft); }
      .sx-pista-legendas { height: 14px; gap: 4px; }
      .sx-pista-legendas span { border-radius: 3px; background: rgba(247,248,255,0.55); }
      .sx-pista-som { height: 30px; flex-direction: column; gap: 3px; }
      .sx-regua { display: flex; justify-content: space-between; margin-left: 84px; font-size: 11px; color: var(--sx-muted); }
      @media (max-width: 640px) { .sx-regua { margin-left: 0; } }
      .sx-anatomia-lista { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 16px 32px; }
      @media (min-width: 720px) { .sx-anatomia-lista { grid-template-columns: repeat(2, minmax(0,1fr)); } }
      @media (min-width: 1024px) { .sx-anatomia-lista { grid-template-columns: repeat(3, minmax(0,1fr)); } }
      .sx-anatomia-lista li { display: flex; gap: 12px; align-items: flex-start; }
      .sx-pino--lista { flex: none; margin-top: 1px; }
      .sx-anatomia-lista strong { display: block; font-size: 16px; color: var(--sx-text); }
      .sx-anatomia-lista li > span:last-child > span { display: block; margin-top: 2px; font-size: 14.5px; line-height: 1.5; color: var(--sx-muted); }
      .sx-anatomia-extra { margin: 0; display: flex; align-items: center; gap: 8px; padding-top: 18px; border-top: 1px solid var(--sx-border); font-size: 14.5px; color: var(--sx-muted); }
      .sx-anatomia-extra svg { color: var(--sx-accent-soft); flex: none; }

      .sx-formato .sx-faixa { margin-top: auto; }

      .sx-faq-grelha { display: grid; grid-template-columns: 1fr; gap: 28px; }
      @media (min-width: 900px) { .sx-faq-grelha { grid-template-columns: 0.8fr 1.2fr; gap: 56px; align-items: start; } .sx-faq-grelha .sx-cabecalho { position: sticky; top: 120px; } }

      .sx-email { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: clamp(36px, 6vw, 72px) 20px; border-radius: 30px; text-align: center; background: linear-gradient(135deg, rgba(var(--sx-accent-rgb),0.14) 0%, rgba(255,255,255,0.02) 60%); border: 1px solid rgba(var(--sx-accent-rgb),0.35); }
      .sx-email > :not(.sx-piloto-glow) { position: relative; }
      .sx-email-icone { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 20px; color: var(--sx-on-accent); background: linear-gradient(135deg, var(--sx-accent-soft), var(--sx-accent)); box-shadow: 0 20px 40px -16px rgba(var(--sx-accent-rgb),0.8); }
      .sx-email-valor { font-size: clamp(20px, 3vw, 30px); font-weight: 700; color: var(--sx-text); text-decoration: none; overflow-wrap: anywhere; }
      .sx-email-valor:hover { color: var(--sx-accent-soft); }
      .sx-email-acoes { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 6px; }
      .cx-social button.sx-btn { cursor: pointer; font-family: inherit; }

      @media (prefers-reduced-motion: reduce) {
        .sx-btn, .sx-card, .sx-contacto-link, .sx-faq-mais::before, .sx-faq-mais::after { transition: none; }
        .sx-btn:hover, a.sx-contacto-link:hover { transform: none; }
        .sx-reel--a, .sx-reel--b, .sx-reel--c, .sx-dot::after { animation: none; }
      }
    `}</style>
  );
}

/* ============================================================
   APP
============================================================ */
function SocialApp() {
  // A página é desenhada no cliente: ao abrir /social#piloto, o browser ainda não
  // tinha a secção quando tentou fazer scroll. Repetimos depois de montar.
  React.useEffect(() => {
    const id = decodeURIComponent(window.location.hash.slice(1));
    if (!id) return;
    const t = window.setTimeout(() => {
      document.getElementById(id)?.scrollIntoView({ block: "start" });
    }, 60);
    return () => window.clearTimeout(t);
  }, []);

  return (
    <MCsx reducedMotion="user">
      <SocialStyles />
      <NBsx />
      <main className="cx-social">
        <Hero />
        <Problema />
        <ComoFunciona />
        <Inclui />
        <Formatos />
        <Piloto />
        <Perguntas />
        <Contacto />
      </main>
      <FTsx />
    </MCsx>
  );
}

window.ReelPreview = ReelPreview;

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