#!/usr/bin/env python3
"""
Criativo 10 Cloud PhotoRF 2.0 - Feed 1:1 (1080x1080)
CONCEITO: "WINDOWS OU MAC. VOCE ESCOLHE."

Angulo POSITIVO (verde, confianca + flexibilidade):
O Cloud PhotoRF 2.0 roda nativamente nos dois sistemas. Mesma interface,
mesma performance, mesma potencia de IA. O fotografo escolhe o equipamento
com o qual tem mais afinidade.

Visual:
  - Foto full-width (dois laptops lado a lado, mesma tela) no centro/alto
  - Pills identificando "MAC" (esquerda) e "WIN" (direita) sobre cada laptop
  - Pill grande verde no topo da foto: "MULTIPLATAFORMA - NATIVO"
  - Headline em 2 linhas, "VOCE ESCOLHE." em verde
  - Sub + CTA + data no rodape

Padrao travado dos 9 aprovados:
  - Preto #1A1419 / #0a0a0c, verde #A6E22E
  - Barlow Condensed 900 + Montserrat + JetBrains Mono
  - Selo "PREPARE-SE PARA O ABSURDO!" no topo
  - Wordmark 48px, stage top 170px
  - Data "07.10" JetBrains Mono rodape direito
  - CTA verde rodape esquerdo
  - Grid tech sutil
  - Brackets VERDES
"""

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

BASE = Path(__file__).resolve().parent
OUT = BASE / "10_windows_mac.png"

ASSET_FOTO = BASE / "fotos_raw" / "dual_laptops.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)

# ============================================================================
# LAYOUT (em px, canvas 1080x1080)
# ============================================================================
# header:          56 - 104
# scan-tag:        125 - 155 (abaixo do wordmark, canto direito)
# stage headline:  170 - ~310  (2 linhas 76px line-height 0.90)
# foto wrap:       420 - 780 (360px altura, full width centralizada)
# pill multi:      ~795 (abaixo da foto, centro)
# sub:             bottom 150
# footer (CTA + data): bottom 56
# ============================================================================

FOTO_W = 920
FOTO_H = 360
FOTO_TOP = 405
FOTO_LEFT = (1080 - FOTO_W) // 2  # 80


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(ellipse 100% 70% at 50% 25%, #1a1419 0%, #0a0a0c 60%, #050508 100%);
    overflow: hidden;
  }}

  /* grid tech sutil de fundo */
  .grid-bg {{
    position: absolute; inset: 0;
    background-image:
      linear-gradient(rgba(135,201,37,0.05) 1px, transparent 1px),
      linear-gradient(90deg, rgba(135,201,37,0.05) 1px, transparent 1px);
    background-size: 60px 60px;
    z-index: 1;
    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));
  }}

  /* ===================== STAGE (kicker + headline) - top ===================== */
  .stage {{
    position: absolute;
    top: 170px; left: 60px; right: 60px;
    z-index: 9;
  }}
  .kicker {{
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0.22em;
    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: 76px;
    line-height: 0.90;
    letter-spacing: -0.025em;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 2px 20px rgba(0,0,0,0.6);
    white-space: nowrap;
  }}
  .headline .verde {{
    color: #A6E22E;
    display: inline;
    text-shadow: 0 0 24px rgba(166,226,46,0.35);
  }}

  /* ===================== FOTO WRAP ===================== */
  .foto-wrap {{
    position: absolute;
    top: {FOTO_TOP}px;
    left: {FOTO_LEFT}px;
    width: {FOTO_W}px;
    height: {FOTO_H}px;
    z-index: 6;
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.70), 0 0 0 1px rgba(166,226,46,0.18);
    overflow: visible;
  }}
  .foto-inner {{
    position: absolute; inset: 0;
    border-radius: 14px;
    overflow: hidden;
    z-index: 1;
  }}
  .foto-inner img {{
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center 48%;
    filter: contrast(1.05) saturate(1.08) brightness(0.98);
  }}
  /* gradient overlay bottom pra ancorar pill multi */
  .foto-inner::after {{
    content: "";
    position: absolute; inset: 0;
    background:
      linear-gradient(180deg, rgba(10,10,12,0.15) 0%, rgba(10,10,12,0) 25%, rgba(10,10,12,0) 70%, rgba(10,10,12,0.55) 100%);
    pointer-events: none;
    z-index: 2;
  }}

  /* brackets grandes nos cantos da foto */
  .foto-wrap .bk {{
    position: absolute;
    width: 32px; height: 32px;
    border: 4px solid #A6E22E;
    filter: drop-shadow(0 0 14px rgba(166,226,46,0.95));
    z-index: 9;
  }}
  .foto-wrap .bk.tl {{ top: -4px; left: -4px; border-right: none; border-bottom: none; }}
  .foto-wrap .bk.tr {{ top: -4px; right: -4px; border-left: none; border-bottom: none; }}
  .foto-wrap .bk.bl {{ bottom: -4px; left: -4px; border-right: none; border-top: none; }}
  .foto-wrap .bk.br {{ bottom: -4px; right: -4px; border-left: none; border-top: none; }}

  /* pills identificando MAC (esquerda) e WIN (direita) sobre cada laptop */
  .os-pill {{
    position: absolute;
    top: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: #A6E22E;
    background: rgba(10,10,12,0.88);
    border: 1px solid rgba(166,226,46,0.6);
    padding: 6px 12px;
    border-radius: 4px;
    text-transform: uppercase;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6), 0 0 10px rgba(166,226,46,0.3);
    display: inline-flex; align-items: center; gap: 7px;
    line-height: 1.1;
  }}
  .os-pill .dot {{
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #A6E22E;
    box-shadow: 0 0 8px rgba(166,226,46,0.9);
  }}
  .os-pill.mac {{ left: 20px; }}
  .os-pill.win {{ right: 20px; }}

  /* ===================== PILL MULTIPLATAFORMA (abaixo da foto, centro) ===================== */
  .pill-multi {{
    position: absolute;
    top: 795px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 12px;
    background: #A6E22E;
    color: #0a0a0c;
    border-radius: 999px;
    padding: 13px 22px 13px 14px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    box-shadow: 0 12px 32px rgba(0,0,0,0.65), 0 0 28px rgba(166,226,46,0.75);
    white-space: nowrap;
    z-index: 11;
  }}
  .pill-multi .check {{
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #0a0a0c;
    color: #A6E22E;
    font-size: 13px;
    font-weight: 900;
  }}

  /* ===================== TAG 'RUN - ANYWHERE' (topo direita) ===================== */
  .scan-tag {{
    position: absolute;
    right: 60px;
    top: 125px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 11px;
    color: #A6E22E;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    background: rgba(10,10,12,0.85);
    padding: 6px 10px;
    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 10px rgba(166,226,46,0.25);
    display: inline-flex; align-items: center; gap: 6px;
  }}
  .scan-tag .dot {{
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #A6E22E;
    box-shadow: 0 0 8px rgba(166,226,46,0.95);
  }}
  .scan-tag .sep {{ color: #4e5a2b; }}

  /* ===================== SUB (abaixo do pill) ===================== */
  .sub {{
    position: absolute;
    left: 60px; right: 60px;
    bottom: 150px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 14.5px;
    line-height: 1.46;
    color: #e8e8ea;
    z-index: 9;
    text-align: center;
  }}
  .sub strong {{ color: #ffffff; font-weight: 800; }}
  .sub .verdebold {{ color: #A6E22E; font-weight: 800; }}

  /* ===================== RODAPE ===================== */
  .footer {{
    position: absolute;
    left: 60px; right: 60px; bottom: 56px;
    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">
  <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 lateral (DEBAIXO do wordmark) -->
  <div class="scan-tag">
    <span class="dot"></span>RUN <span class="sep">&middot;</span> ANYWHERE
  </div>

  <!-- STAGE (headline em 2 linhas) -->
  <div class="stage">
    <div class="kicker">O software roda nativamente nos dois sistemas</div>
    <h1 class="headline">
      WINDOWS OU MAC.<br>
      <span class="verde">VOC&Ecirc; ESCOLHE.</span>
    </h1>
  </div>

  <!-- FOTO (dois laptops lado a lado) -->
  <div class="foto-wrap">
    <div class="foto-inner">
      <img src="{FOTO_B64}" alt="MacBook e laptop Windows rodando o mesmo software">
    </div>
    <div class="bk tl"></div>
    <div class="bk tr"></div>
    <div class="bk bl"></div>
    <div class="bk br"></div>
    <!-- pills identificando cada laptop -->
    <div class="os-pill mac"><span class="dot"></span>OS &middot; MAC</div>
    <div class="os-pill win"><span class="dot"></span>OS &middot; WIN</div>
  </div>

  <!-- PILL grande "MULTIPLATAFORMA - NATIVO" -->
  <div class="pill-multi">
    <span class="check">&#10003;</span>
    MULTIPLATAFORMA &middot; NATIVO
  </div>

  <!-- SUB -->
  <p class="sub">
    O <strong>Cloud PhotoRF 2.0</strong> roda nativamente nos dois sistemas. Mesma interface, mesma performance, mesma pot&ecirc;ncia de IA.<br>
    Voc&ecirc; trabalha no equipamento com o qual <span class="verdebold">tem mais afinidade</span>.
  </p>

  <!-- 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)
    else:
        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()
