#!/usr/bin/env python3
"""
Criativo 04 Cloud PhotoRF 2.0 - Feed 1:1 (1080x1080)
Mensagem: "3 ETAPAS DE VERIFICACAO. ZERO ERRO."
Angulo: POSITIVO / APROVACAO - brackets VERDES + 3 checks em escadinha
Publico: FRIO (aquisicao) - donos de empresa de fotografia escolar/eventos
Autor: Juliana (juliana-ops)
Foto base: gpt-image-2.5-sunburst (formanda retrato + bokeh tech)

Chassi visual mantido dos pilotos 01/02/03.

COMPOSICAO (varia 03): INVERTIDA
  - 03 foi texto esq / foto dir (brackets verdes)
  - 04 e foto ESQ / texto DIR (brackets verdes)
  - 3 checks em escadinha HORIZONTAL na base da foto (nao cobre rosto)
  - Scan line verde horizontal sutil
"""

import base64
from pathlib import Path
from playwright.sync_api import sync_playwright

BASE = Path(__file__).resolve().parent
OUT = BASE / "04_tripla_verificacao.png"

ASSET_FOTO = BASE / "foto_base_tripla_verificacao_raw.png"
ASSET_LOGO = Path("/opt/mia/workspace/clientes/px3lab/landing_lancamento_novo/preview-lp/assets/logo-wordmark.png")


def b64_img(path: Path) -> str:
    data = path.read_bytes()
    ext = path.suffix.lstrip(".").lower()
    if ext == "jpg":
        ext = "jpeg"
    return f"data:image/{ext};base64," + base64.b64encode(data).decode()


FOTO_B64 = b64_img(ASSET_FOTO)
LOGO_B64 = b64_img(ASSET_LOGO)


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=Barlow+Condensed:wght@700;800;900&family=Montserrat:wght@600;800;900&family=JetBrains+Mono:wght@500;700&display=swap" rel="stylesheet">
<style>
  * {{ box-sizing: border-box; margin: 0; padding: 0; }}
  html, body {{ width: 1080px; height: 1080px; overflow: hidden; background: #0a0a0c; font-family: 'Montserrat', sans-serif; -webkit-font-smoothing: antialiased; }}

  .canvas {{
    position: relative;
    width: 1080px;
    height: 1080px;
    background:
      radial-gradient(circle at 28% 48%, rgba(135,201,37,0.11) 0%, rgba(10,10,12,0) 55%),
      linear-gradient(180deg, #0f0f12 0%, #0a0a0c 100%);
    overflow: hidden;
  }}

  .grid-bg {{
    position: absolute; inset: 0;
    background-image:
      linear-gradient(rgba(135,201,37,0.045) 1px, transparent 1px),
      linear-gradient(90deg, rgba(135,201,37,0.045) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 40%, transparent 100%);
    -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 40%, transparent 100%);
  }}

  /* HEADER */
  .header {{
    position: absolute;
    top: 56px; left: 60px; right: 60px;
    display: flex; align-items: center; justify-content: space-between;
    z-index: 10;
  }}
  .selo-campanha {{
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 900;
    font-size: 22px;
    letter-spacing: 0.14em;
    color: #ffffff;
    text-transform: uppercase;
    display: flex; align-items: center; gap: 10px;
  }}
  .selo-campanha .absurdo {{ color: #A6E22E; }}
  .selo-campanha .bar {{
    display: inline-block;
    width: 4px; height: 22px;
    background: #A6E22E;
    transform: skewX(-18deg);
    margin-right: 4px;
  }}
  .wordmark {{ height: 48px; opacity: 0.95; }}

  /* STAGE: FOTO ESQ + TEXTO DIR */
  .stage {{
    position: absolute;
    top: 170px; bottom: 220px; left: 60px; right: 60px;
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 44px;
    align-items: center;
  }}

  /* FOTO */
  .photo-wrap {{
    position: relative;
    width: 440px; height: 580px;
    border-radius: 14px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 30px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(166,226,46,0.35);
  }}
  .photo-wrap img.foto {{
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: 42% 42%;
    filter: contrast(1.05) saturate(1.08);
  }}
  .photo-wrap::after {{
    content: "";
    position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(10,10,12,0) 50%, rgba(10,10,12,0.92) 100%);
  }}

  /* Brackets VERDES */
  .brk {{
    position: absolute;
    width: 54px; height: 54px;
    border: 5px solid #A6E22E;
    z-index: 3;
    filter: drop-shadow(0 0 10px rgba(166,226,46,0.5));
  }}
  .brk.tl {{ top: 24px; left: 24px; border-right: none; border-bottom: none; }}
  .brk.tr {{ top: 24px; right: 24px; border-left: none; border-bottom: none; }}
  .brk.bl {{ bottom: 24px; left: 24px; border-right: none; border-top: none; }}
  .brk.br {{ bottom: 24px; right: 24px; border-left: none; border-top: none; }}

  /* linha de scan horizontal verde sobre a foto */
  .scan-line {{
    position: absolute;
    left: 0; right: 0;
    top: 36%;
    height: 2px;
    background: linear-gradient(90deg,
      rgba(166,226,46,0) 0%,
      rgba(166,226,46,0.9) 50%,
      rgba(166,226,46,0) 100%);
    box-shadow: 0 0 12px rgba(166,226,46,0.7);
    z-index: 4;
  }}

  /* 3 CHECKS em COLUNA na BASE da foto (nao cobre rosto) */
  .checks {{
    position: absolute;
    left: 24px; right: 24px;
    bottom: 90px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 6;
  }}
  .check {{
    display: flex; align-items: center; gap: 10px;
    background: rgba(10,10,12,0.88);
    backdrop-filter: blur(6px);
    border: 1.5px solid rgba(166,226,46,0.55);
    border-radius: 8px;
    padding: 8px 14px 8px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 12px;
    color: #A6E22E;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4), 0 0 10px rgba(166,226,46,0.18);
    white-space: nowrap;
  }}
  .check .mark {{
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #A6E22E;
    color: #0a0a0c;
    font-size: 14px;
    font-weight: 900;
    line-height: 1;
    font-family: 'Montserrat', sans-serif;
    box-shadow: 0 0 8px rgba(166,226,46,0.7);
    flex-shrink: 0;
  }}
  .check .num {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: #8a8a90;
    font-size: 11px;
    margin-left: auto;
    letter-spacing: 0.08em;
  }}

  /* Tag QA.TRIPLA no topo */
  .launch-tag {{
    position: absolute;
    top: 24px; left: 90px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 12px;
    color: #A6E22E;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    background: rgba(0,0,0,0.65);
    padding: 6px 10px;
    border-radius: 4px;
    z-index: 4;
    border: 1px solid rgba(166,226,46,0.3);
  }}

  /* LADO DIREITO: COPY */
  .copy {{
    display: flex; flex-direction: column; justify-content: center;
    height: 100%;
  }}
  .kicker {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 18px;
    letter-spacing: 0.18em;
    color: #A6E22E;
    margin-bottom: 22px;
    text-transform: uppercase;
    display: flex; align-items: center; gap: 12px;
  }}
  .kicker::before {{
    content: "";
    display: inline-block; width: 36px; height: 2px; background: #A6E22E;
  }}

  .headline {{
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 900;
    font-size: 108px;
    line-height: 0.88;
    letter-spacing: -0.02em;
    color: #ffffff;
    text-transform: uppercase;
    margin-bottom: 28px;
  }}
  .headline .num {{
    color: #A6E22E;
    display: inline-block;
    font-size: 128px;
    line-height: 0.82;
  }}
  .headline .p {{ color: #A6E22E; }}
  .headline .highlight {{
    color: #A6E22E;
    display: inline-block;
    position: relative;
  }}

  .sub {{
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 19px;
    line-height: 1.42;
    color: #d6d6d6;
    max-width: 500px;
  }}
  .sub strong {{ color: #ffffff; font-weight: 800; }}

  /* RODAPE */
  .footer {{
    position: absolute;
    left: 60px; right: 60px; bottom: 60px;
    display: flex; align-items: center; justify-content: space-between;
    z-index: 10;
  }}
  .cta {{
    background: #A6E22E;
    color: #0a0a0c;
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-size: 21px;
    letter-spacing: 0.04em;
    padding: 20px 32px;
    border-radius: 10px;
    text-transform: uppercase;
    display: inline-flex; align-items: center; gap: 12px;
    box-shadow: 0 10px 30px rgba(166,226,46,0.3);
    white-space: nowrap;
  }}
  .cta .arrow {{ font-size: 24px; line-height: 1; }}

  .meta-line {{
    display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  }}
  .meta-line .label {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 12px;
    color: #8a8a90;
    letter-spacing: 0.18em;
    text-transform: uppercase;
  }}
  .meta-line .date {{
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 900;
    font-size: 44px;
    color: #ffffff;
    letter-spacing: 0.02em;
    line-height: 1;
  }}
  .meta-line .date .accent {{ color: #A6E22E; }}
  .meta-line .bar2 {{
    display: inline-block;
    width: 3px; height: 36px; background: #A6E22E;
    transform: skewX(-14deg);
    margin-right: 10px;
    vertical-align: middle;
  }}
</style>
</head>
<body>
<div class="canvas">
  <div class="grid-bg"></div>

  <!-- HEADER -->
  <div class="header">
    <div class="selo-campanha">
      <span class="bar"></span>
      PREPARE-SE PARA O <span class="absurdo">ABSURDO!</span>
    </div>
    <img class="wordmark" src="{LOGO_B64}" alt="Cloud PhotoRF 2.0">
  </div>

  <!-- STAGE: FOTO ESQ + TEXTO DIR -->
  <div class="stage">
    <div class="photo-wrap">
      <img class="foto" src="{FOTO_B64}" alt="">
      <div class="scan-line"></div>
      <div class="brk tl"></div>
      <div class="brk tr"></div>
      <div class="brk bl"></div>
      <div class="brk br"></div>
      <div class="launch-tag">QA &middot; TRIPLA &middot; OK</div>
      <div class="checks">
        <div class="check"><span class="mark">&check;</span>FACE OK <span class="num">01/03</span></div>
        <div class="check"><span class="mark">&check;</span>QUALIDADE OK <span class="num">02/03</span></div>
        <div class="check"><span class="mark">&check;</span>ID MATCH <span class="num">03/03</span></div>
      </div>
    </div>

    <div class="copy">
      <div class="kicker">Checagem autom&aacute;tica &middot; tripla</div>
      <h1 class="headline">
        <span class="num">3</span> ETAPAS<br>
        DE VERIFICA&Ccedil;&Atilde;O<span class="p">.</span><br>
        <span class="highlight">ZERO ERRO.</span>
      </h1>
      <p class="sub">
        Antes de destinar cada foto ao formando,<br>
        o <strong>Cloud PhotoRF 2.0</strong> verifica <strong>3 vezes</strong>.<br>
        Sua equipe n&atilde;o descobre foto perdida<br>
        depois que o &aacute;lbum j&aacute; foi entregue.
      </p>
    </div>
  </div>

  <!-- FOOTER -->
  <div class="footer">
    <div class="cta">
      QUERO CONHECER O SOFTWARE
      <span class="arrow">&rarr;</span>
    </div>
    <div class="meta-line">
      <span class="label">Lan&ccedil;amento</span>
      <span class="date"><span class="bar2"></span>07<span class="accent">.</span>10<span class="accent">.</span>26</span>
    </div>
  </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=2)
        page.set_content(HTML, wait_until="networkidle")
        page.wait_for_timeout(400)
        page.screenshot(path=str(OUT), clip={"x": 0, "y": 0, "width": 1080, "height": 1080}, omit_background=False)
        browser.close()
    from PIL import Image
    img = Image.open(OUT)
    if img.size != (1080, 1080):
        img = img.resize((1080, 1080), Image.LANCZOS)
        img.save(OUT, "PNG", optimize=True)
    print(f"[OK] Gerado: {OUT} ({OUT.stat().st_size // 1024} KB, {img.size})")
    return OUT


if __name__ == "__main__":
    render()
