#!/usr/bin/env python3
"""Piloto 04 Cloud PhotoRF 2.0 (1080x1080) — Ângulo C: CURIOSIDADE pura (topo de funil).

Direção aprovada pelo Renato após reprovar pilotos 01-03 por serem muito fundo de funil.
Público frio que NÃO conhece o Cloud PhotoRF 2.0: a arte precisa parar o scroll pelo
MISTÉRIO, não pela feature. Headline-reviravolta + hero enigmático (tela com fotos
passando sozinhas + mão humana parada ao lado) + CTA de curiosidade.

NÃO repete face-detection boxes da landing (mataria o mistério).
Revelação da feature fica pra landing.
"""
import base64
import sys
from pathlib import Path
from playwright.sync_api import sync_playwright

BASE = Path("/opt/mia/workspace/clientes/px3lab/lancamento_photorf2/criativos_oferta")
HERO = BASE / "hero_curiosidade_A.png"
LOGO = Path("/opt/mia/workspace/clientes/px3lab/cloudphotorf2_conafor/logos/cloudphotorf-logo-grande.png")
VERSION = sys.argv[1] if len(sys.argv) > 1 else "v1"
OUT = BASE / f"piloto_04_C_curiosidade_1x1_{VERSION}.png"

hero_b64 = base64.b64encode(HERO.read_bytes()).decode()
hero_src = f"data:image/png;base64,{hero_b64}"
logo_b64 = base64.b64encode(LOGO.read_bytes()).decode()
logo_src = f"data:image/png;base64,{logo_b64}"

HTML = f"""<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=Montserrat:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@500;600;700&display=swap" rel="stylesheet">
<style>
  * {{ margin: 0; padding: 0; box-sizing: border-box; }}
  html, body {{ margin: 0; padding: 0; overflow: hidden; }}
  body {{
    width: 1080px;
    height: 1080px;
    font-family: 'Montserrat', sans-serif;
    background: #0D0D0D;
    position: relative;
    color: #FFFFFF;
  }}

  /* ================= TOPO (eyebrow + logo pequena) ================= */
  .top-bar {{
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 118px;
    background: #0D0D0D;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 48px;
    z-index: 5;
  }}
  .eyebrow {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: #87C925;
    display: inline-flex;
    align-items: center;
    gap: 12px;
  }}
  .eyebrow::before {{
    content: '';
    width: 24px;
    height: 2px;
    background: #87C925;
    display: inline-block;
    opacity: 0.9;
    box-shadow: 0 0 8px rgba(135, 201, 37, 0.6);
  }}
  .logo-official {{
    height: 54px;
    width: auto;
    display: block;
    filter: drop-shadow(0 0 18px rgba(135, 201, 37, 0.35));
  }}

  /* ================= HERO ================= */
  .hero-wrap {{
    position: absolute;
    top: 118px; left: 0;
    width: 1080px;
    height: 540px;
    overflow: hidden;
    background: #000;
  }}
  .hero-img {{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 50%;
    filter: brightness(0.98) contrast(1.14) saturate(1.08);
  }}
  /* Vignette discreta para integrar nas bordas */
  .hero-vignette {{
    position: absolute;
    inset: 0;
    background:
      radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%),
      linear-gradient(180deg, rgba(13,13,13,0.0) 70%, rgba(13,13,13,0.95) 100%);
    z-index: 3;
    pointer-events: none;
  }}

  /* ================= DIVIDER luminoso ================= */
  .divider {{
    position: absolute;
    top: 658px; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg,
      rgba(135, 201, 37, 0) 0%,
      rgba(135, 201, 37, 0.95) 15%,
      rgba(135, 201, 37, 0.95) 85%,
      rgba(135, 201, 37, 0) 100%);
    box-shadow: 0 0 18px rgba(135, 201, 37, 0.75);
    z-index: 6;
  }}

  /* ================= BLOCO INFERIOR ================= */
  .bottom-block {{
    position: absolute;
    top: 660px; left: 0; right: 0;
    height: 420px;
    background: #0D0D0D;
    z-index: 4;
  }}

  /* ================= HEADLINE + SUB ================= */
  .content {{
    position: absolute;
    left: 54px;
    right: 54px;
    top: 692px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 22px;
  }}
  .headline {{
    font-family: 'Oswald', sans-serif;
    font-weight: 700;
    font-size: 82px;
    line-height: 0.94;
    letter-spacing: -0.015em;
    text-transform: uppercase;
    color: #FFFFFF;
  }}
  .headline .hl-accent {{
    color: #87C925;
    text-shadow: 0 0 28px rgba(135, 201, 37, 0.5);
  }}
  .sub {{
    font-family: 'Montserrat', sans-serif;
    font-weight: 500;
    font-size: 24px;
    line-height: 1.35;
    color: rgba(255,255,255,0.88);
    max-width: 960px;
  }}

  /* ================= CTA + URL ================= */
  .cta-wrap {{
    position: absolute;
    left: 54px;
    right: 54px;
    bottom: 44px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }}
  .cta {{
    display: inline-flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, #9FDB2E 0%, #6EA81D 100%);
    color: #0D0D0D;
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-size: 22px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 20px 32px;
    border-radius: 14px;
    box-shadow:
      0 12px 32px rgba(0,0,0,0.55),
      0 0 44px rgba(135, 201, 37, 0.4);
    border: 2px solid rgba(255,255,255,0.14);
    white-space: nowrap;
  }}
  .cta .arrow {{
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
  }}
  .url {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 15px;
    letter-spacing: 0.14em;
    color: rgba(135, 201, 37, 0.9);
    text-transform: lowercase;
    text-align: right;
    white-space: nowrap;
  }}
  .url strong {{
    color: #87C925;
    font-weight: 700;
  }}
</style>
</head>
<body>

  <div class="top-bar">
    <div class="eyebrow">PX3 LAB · CLOUD PHOTORF 2.0</div>
    <img class="logo-official" src="{logo_src}" alt="Cloud PhotoRF 2.0">
  </div>

  <div class="hero-wrap">
    <img class="hero-img" src="{hero_src}" alt="">
    <div class="hero-vignette"></div>
  </div>

  <div class="bottom-block"></div>
  <div class="divider"></div>

  <div class="content">
    <div class="headline">
      A SEPARAÇÃO<br>
      DAS FOTOS <span class="hl-accent">DEIXOU<br>
      DE SER PROBLEMA.</span>
    </div>
    <div class="sub">
      E não é terceirizar. Nem contratar mais gente.
    </div>
  </div>

  <div class="cta-wrap">
    <div class="cta">
      VEJA O ABSURDO
      <span class="arrow">→</span>
    </div>
    <div class="url">oferta.<strong>px3lab</strong>.com.br</div>
  </div>

</body>
</html>
"""

def render():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page(viewport={"width": 1080, "height": 1080}, device_scale_factor=1)
        page.set_content(HTML, wait_until="networkidle")
        page.wait_for_timeout(600)
        page.screenshot(path=str(OUT), clip={"x": 0, "y": 0, "width": 1080, "height": 1080}, omit_background=False)
        browser.close()
    print(f"OK -> {OUT}")

if __name__ == "__main__":
    render()
