#!/usr/bin/env python3
"""
Criativo 07 Cloud PhotoRF 2.0 - Feed 1:1 (1080x1080)
Mensagem: "SEM FACE? AINDA ASSIM, IDENTIFICADO."
Angulo: POSITIVO / RESOLUCAO - pill verde "FORMANDO 089 · IDENTIFICADO POR SEQUÊNCIA",
brackets verdes na silhueta de costas, tag "ID · 089 · MATCH", conector tech
sugerindo "contexto + sequência = identificação".
Publico: FRIO - donos de empresa de fotografia escolar/eventos
Autor: Juliana (juliana-ops)
Foto base: gpt-image-2.5-sunburst (outorga vista por trás, formanda sem rosto)

Chassi visual mantido dos pilotos 01-06:
  - preto #0a0a0c + verde neon #A6E22E
  - Barlow Condensed 900 + Montserrat + JetBrains Mono
  - selo PREPARE-SE PARA O ABSURDO!
  - logo wordmark grande (height 48px)
  - CTA verde no rodape + data 07.10.26

COMPOSICAO 07 (varia dos 6 anteriores):
  - 01/02/03 foram split texto esq / foto dir
  - 04 foi split foto esq / texto dir
  - 05 foi HERO foto full + texto overlay esq
  - 06 foi split FOTO ESQ / TEXTO DIR vertical
  - 07 vai HERO FOTO FULL-BLEED + overlay texto em CAIXA
    SEMITRANSPARENTE no quadrante inferior ESQUERDO (estilo
    editorial/documentário - mais imersivo pra foto emocional)
"""

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

BASE = Path(__file__).resolve().parent
OUT = BASE / "07_sem_face.png"

ASSET_FOTO = BASE / "foto_base_sem_face_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: #0a0a0c;
    overflow: hidden;
  }}

  /* ============== FOTO FULL-BLEED ============== */
  .photo-full {{
    position: absolute; inset: 0;
    overflow: hidden;
  }}
  .photo-full img {{
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: 50% 42%;
    filter: contrast(1.08) saturate(1.08) brightness(0.92);
  }}
  /* vinheta global pra texto respirar */
  .vinheta {{
    position: absolute; inset: 0;
    background:
      radial-gradient(ellipse 90% 70% at 50% 35%, rgba(0,0,0,0) 0%, rgba(0,0,0,0.35) 100%),
      linear-gradient(180deg, rgba(10,10,12,0.55) 0%, rgba(10,10,12,0.0) 22%, rgba(10,10,12,0.0) 50%, rgba(10,10,12,0.92) 100%);
    z-index: 2;
  }}
  /* grid tech sutil ao fundo (quase imperceptivel) */
  .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;
    mix-blend-mode: overlay;
    z-index: 3;
    pointer-events: none;
  }}

  /* ===================== 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;
    text-shadow: 0 2px 10px rgba(0,0,0,0.85);
  }}
  .selo-campanha .absurdo {{ color: #A6E22E; }}
  .selo-campanha .bar {{
    display: inline-block;
    width: 4px; height: 22px;
    background: #A6E22E;
    transform: skewX(-18deg);
    margin-right: 4px;
    box-shadow: 0 0 8px rgba(166,226,46,0.6);
  }}
  .wordmark {{
    height: 48px;
    opacity: 0.98;
    filter: drop-shadow(0 2px 10px rgba(0,0,0,0.8));
  }}

  /* ===================== TAG SCAN (canto sup DIR da foto) ===================== */
  .scan-tag {{
    position: absolute;
    top: 170px; right: 60px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 12px;
    color: #A6E22E;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    background: rgba(10,10,12,0.82);
    padding: 8px 12px;
    border-radius: 4px;
    z-index: 9;
    border: 1px solid rgba(166,226,46,0.5);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5), 0 0 12px rgba(166,226,46,0.25);
    display: inline-flex; align-items: center; gap: 8px;
  }}
  .scan-tag .dot {{
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #A6E22E;
    box-shadow: 0 0 8px rgba(166,226,46,0.95);
  }}
  .scan-tag .sep {{ color: #4e5a2b; }}

  /* ===================== BRACKET VERDE isolando a formanda ===================== */
  .target {{
    position: absolute;
    top: 165px;
    left: 320px;
    width: 460px;
    height: 540px;
    z-index: 7;
    pointer-events: none;
    filter: drop-shadow(0 0 28px rgba(166,226,46,0.4));
  }}
  .target .b {{
    position: absolute;
    width: 48px; height: 48px;
    border: 5px solid #A6E22E;
    filter: drop-shadow(0 0 12px rgba(166,226,46,0.8));
  }}
  .target .b.tl {{ top: 0; left: 0; border-right: none; border-bottom: none; }}
  .target .b.tr {{ top: 0; right: 0; border-left: none; border-bottom: none; }}
  .target .b.bl {{ bottom: 0; left: 0; border-right: none; border-top: none; }}
  .target .b.br {{ bottom: 0; right: 0; border-left: none; border-top: none; }}

  .target .b::after {{
    content: "";
    position: absolute;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #A6E22E;
    box-shadow: 0 0 10px rgba(166,226,46,0.9);
  }}
  .target .b.tl::after {{ top: -6px; left: -6px; }}
  .target .b.tr::after {{ top: -6px; right: -6px; }}
  .target .b.bl::after {{ bottom: -6px; left: -6px; }}
  .target .b.br::after {{ bottom: -6px; right: -6px; }}

  /* pulso de scan dentro do bracket */
  .target .pulse {{
    position: absolute;
    left: 14px; right: 14px;
    top: 46%;
    height: 2px;
    background: linear-gradient(90deg,
      rgba(166,226,46,0) 0%,
      rgba(166,226,46,0.95) 50%,
      rgba(166,226,46,0) 100%);
    box-shadow: 0 0 14px rgba(166,226,46,0.85);
  }}

  /* pill flutuante sobre a cabeça do capelo */
  .pill-id {{
    position: absolute;
    top: 118px;
    left: 320px;
    width: 460px;
    z-index: 9;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    background: rgba(10,10,12,0.92);
    backdrop-filter: blur(6px);
    border: 1.5px solid rgba(166,226,46,0.7);
    border-radius: 999px;
    padding: 12px 18px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 13px;
    color: #A6E22E;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    box-shadow: 0 6px 22px rgba(0,0,0,0.6), 0 0 20px rgba(166,226,46,0.35);
    white-space: nowrap;
  }}
  .pill-id .dot {{
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #A6E22E;
    box-shadow: 0 0 10px rgba(166,226,46,0.9);
  }}
  .pill-id .sep {{ color: #4e5a2b; }}

  /* ===================== CAIXA DE COPY (quadrante inferior esquerdo) ===================== */
  .copy-box {{
    position: absolute;
    left: 60px;
    bottom: 170px;
    width: 650px;
    z-index: 9;
    padding: 32px 34px;
    background: linear-gradient(180deg, rgba(10,10,12,0.65) 0%, rgba(10,10,12,0.88) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(166,226,46,0.22);
    border-left: 4px solid #A6E22E;
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.55), 0 0 30px rgba(166,226,46,0.08);
  }}
  .kicker {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 0.18em;
    color: #A6E22E;
    margin-bottom: 14px;
    text-transform: uppercase;
    display: flex; align-items: center; gap: 10px;
  }}
  .kicker::before {{
    content: "";
    display: inline-block; width: 28px; height: 2px; background: #A6E22E;
  }}

  .headline {{
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 900;
    font-size: 92px;
    line-height: 0.86;
    letter-spacing: -0.02em;
    color: #ffffff;
    text-transform: uppercase;
    margin-bottom: 22px;
    text-shadow: 0 2px 20px rgba(0,0,0,0.85);
  }}
  .headline .q {{ color: #A6E22E; }}
  .headline .p {{ color: #A6E22E; }}
  .headline .verde {{
    color: #A6E22E;
    display: inline-block;
  }}

  .sub {{
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 16.5px;
    line-height: 1.5;
    color: #ededed;
    text-shadow: 0 1px 10px rgba(0,0,0,0.75);
  }}
  .sub strong {{ color: #ffffff; font-weight: 800; }}
  .sub .verdebold {{ color: #A6E22E; 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.35);
    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: #d3d3d6;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    text-shadow: 0 1px 6px rgba(0,0,0,0.9);
  }}
  .meta-line .date {{
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 900;
    font-size: 44px;
    color: #ffffff;
    letter-spacing: 0.02em;
    line-height: 1;
    text-shadow: 0 2px 12px rgba(0,0,0,0.9);
  }}
  .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;
    box-shadow: 0 0 8px rgba(166,226,46,0.6);
  }}
</style>
</head>
<body>
<div class="canvas">
  <!-- FOTO FULL-BLEED -->
  <div class="photo-full">
    <img src="{FOTO_B64}" alt="">
  </div>
  <div class="vinheta"></div>
  <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>

  <!-- TAG SCAN -->
  <div class="scan-tag">
    <span class="dot"></span>ID <span class="sep">&middot;</span> 089 <span class="sep">&middot;</span> MATCH
  </div>

  <!-- PILL FLUTUANTE sobre a formanda -->
  <div class="pill-id">
    <span class="dot"></span>FORMANDO 089 <span class="sep">&middot;</span> IDENTIFICADO POR SEQU&Ecirc;NCIA
  </div>

  <!-- BRACKET isolando formanda sem face -->
  <div class="target">
    <div class="b tl"></div>
    <div class="b tr"></div>
    <div class="b bl"></div>
    <div class="b br"></div>
    <div class="pulse"></div>
  </div>

  <!-- CAIXA DE COPY (inferior esquerdo) -->
  <div class="copy-box">
    <div class="kicker">Contexto + sequ&ecirc;ncia</div>
    <h1 class="headline">
      SEM FACE<span class="q">?</span><br>
      AINDA ASSIM,<br>
      <span class="verde">IDENTIFICADO<span class="p">.</span></span>
    </h1>
    <p class="sub">
      Foto da outorga, foto das m&atilde;os dadas na alian&ccedil;a, foto de costas no palco.
      Sem rosto vis&iacute;vel, o <strong>Cloud PhotoRF 2.0</strong> entende pela sequ&ecirc;ncia
      quem &eacute; o formando. <span class="verdebold">Nada se perde.</span>
    </p>
  </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()
