#!/usr/bin/env python3
"""Anuncio de lancamento v2 — Borrello
Hierarquia identica a hotmart_capa_v2.jpg: CROMOTERAPIA (dourado) + RADIESTESIA (violeta)
dominantes, com bloco de data DISPONIVEL EM 01 DE AGOSTO 2026.
"""
from playwright.sync_api import sync_playwright
from pathlib import Path
import base64

BASE = Path("/opt/mia/workspace/clientes/francisco_borrello")
BG = BASE / "_bg_cromoterapia.png"
OUT_PNG = BASE / "anuncio_lancamento_v2.png"
OUT_JPG = BASE / "anuncio_lancamento_v2.jpg"

FONTS = Path("/home/mia/.fonts/px3lab")
BEBAS = FONTS / "BebasNeue-Regular.ttf"
INTER_BOLD = FONTS / "Inter-Bold.ttf"
INTER_REG = FONTS / "Inter-Regular.ttf"
INTER_SEMI = FONTS / "Inter-SemiBold.ttf"


def b64(p: Path) -> str:
    return base64.b64encode(p.read_bytes()).decode()


bg_b64 = b64(BG)
bebas_b64 = b64(BEBAS)
inter_bold_b64 = b64(INTER_BOLD)
inter_reg_b64 = b64(INTER_REG)
inter_semi_b64 = b64(INTER_SEMI)


HTML = f"""<!doctype html>
<html lang="pt-BR"><head><meta charset="utf-8">
<style>
@font-face {{ font-family: 'Bebas Neue'; src: url(data:font/ttf;base64,{bebas_b64}) format('truetype'); font-weight: 400; }}
@font-face {{ font-family: 'Inter'; src: url(data:font/ttf;base64,{inter_bold_b64}) format('truetype'); font-weight: 700; }}
@font-face {{ font-family: 'Inter'; src: url(data:font/ttf;base64,{inter_semi_b64}) format('truetype'); font-weight: 600; }}
@font-face {{ font-family: 'Inter'; src: url(data:font/ttf;base64,{inter_reg_b64}) format('truetype'); font-weight: 400; }}

* {{ box-sizing: border-box; margin: 0; padding: 0; }}
html, body {{ width: 1080px; height: 1080px; overflow: hidden; }}
body {{
  position: relative;
  font-family: 'Inter', sans-serif;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(6,4,14,0.72) 0%, rgba(6,4,14,0.55) 45%, rgba(6,4,14,0.78) 100%),
    url(data:image/png;base64,{bg_b64}) center/cover no-repeat;
}}

/* Glow dourado atras do CROMOTERAPIA */
.glow-gold {{
  position: absolute;
  top: 130px; left: 50%; transform: translateX(-50%);
  width: 900px; height: 320px;
  background: radial-gradient(ellipse at center, rgba(230,178,90,0.35) 0%, rgba(230,178,90,0.15) 40%, transparent 70%);
  filter: blur(30px);
  pointer-events: none;
}}

/* Glow violeta atras do RADIESTESIA */
.glow-violet {{
  position: absolute;
  top: 620px; left: 50%; transform: translateX(-50%);
  width: 900px; height: 260px;
  background: radial-gradient(ellipse at center, rgba(178,150,255,0.38) 0%, rgba(178,150,255,0.16) 42%, transparent 72%);
  filter: blur(30px);
  pointer-events: none;
}}

/* Cantos decorativos */
.corner {{
  position: absolute; width: 44px; height: 44px;
  border-color: rgba(230,178,90,0.55);
  border-style: solid; border-width: 0;
}}
.corner.tl {{ top: 32px; left: 32px; border-top-width: 2px; border-left-width: 2px; }}
.corner.tr {{ top: 32px; right: 32px; border-top-width: 2px; border-right-width: 2px; }}
.corner.bl {{ bottom: 32px; left: 32px; border-bottom-width: 2px; border-left-width: 2px; }}
.corner.br {{ bottom: 32px; right: 32px; border-bottom-width: 2px; border-right-width: 2px; }}

.wrap {{
  position: relative;
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 60px 60px;
}}

.tag {{
  border: 1px solid rgba(230,178,90,0.55);
  border-radius: 999px;
  padding: 10px 26px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 4px;
  color: #f4d9a4;
  margin-top: 20px;
  text-transform: uppercase;
}}

.cromo {{
  font-family: 'Bebas Neue', sans-serif;
  font-size: 178px;
  line-height: 0.95;
  letter-spacing: 2px;
  margin-top: 40px;
  background: linear-gradient(180deg, #f6dfa8 0%, #e2ae5a 45%, #b6832f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 45px rgba(230,178,90,0.35);
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.55));
}}

.bridge {{
  display: flex; align-items: center; justify-content: center;
  gap: 18px;
  margin-top: 26px;
  width: 100%;
}}
.bridge .line {{
  flex: 0 0 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(230,178,90,0.6), transparent);
}}
.bridge .txt {{
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 5.5px;
  color: #ffffff;
  text-transform: uppercase;
}}

.radi {{
  font-family: 'Bebas Neue', sans-serif;
  font-size: 168px;
  line-height: 0.95;
  letter-spacing: 3px;
  margin-top: 22px;
  background: linear-gradient(180deg, #ffffff 0%, #d8c9ff 55%, #a894f5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 45px rgba(178,150,255,0.4);
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.55));
}}

.pap {{
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 8px;
  color: #f4d9a4;
  margin-top: 20px;
  text-transform: uppercase;
}}

.desc {{
  margin-top: 32px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 20px;
  line-height: 1.5;
  text-align: center;
  color: rgba(255,255,255,0.82);
  max-width: 780px;
}}

.data-block {{
  margin-top: 34px;
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 40px;
  border-top: 1px solid rgba(230,178,90,0.28);
  border-bottom: 1px solid rgba(230,178,90,0.28);
}}
.data-label {{
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 6px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
}}
.data-main {{
  font-family: 'Bebas Neue', sans-serif;
  font-size: 84px;
  line-height: 1;
  letter-spacing: 3px;
  margin-top: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f4d9a4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 25px rgba(255,255,255,0.15);
}}
.data-year {{
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 8px;
  color: #e2ae5a;
  margin-top: 4px;
}}

.pill {{
  position: absolute;
  bottom: 52px;
  left: 50%; transform: translateX(-50%);
  border: 1px solid rgba(230,178,90,0.55);
  border-radius: 999px;
  padding: 12px 34px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 19px;
  color: #ffffff;
  background: rgba(6,4,14,0.35);
}}
.pill b {{ color: #f4d9a4; font-weight: 700; letter-spacing: 2px; margin-right: 4px; text-transform: uppercase; font-size: 15px; }}
</style></head>
<body>
  <div class="glow-gold"></div>
  <div class="glow-violet"></div>

  <div class="corner tl"></div>
  <div class="corner tr"></div>
  <div class="corner bl"></div>
  <div class="corner br"></div>

  <div class="wrap">
    <div class="tag">Lançamento Oficial</div>

    <div class="cromo">CROMOTERAPIA</div>

    <div class="bridge">
      <span class="line"></span>
      <span class="txt">Estelar das Luzes Angelicais com</span>
      <span class="line"></span>
    </div>

    <div class="radi">RADIESTESIA</div>

    <div class="pap">Passo a Passo</div>

    <div class="desc">O único método que une Radiestesia e Cromoterapia<br>em três camadas de cura.</div>

    <div class="data-block">
      <div class="data-label">Disponível em</div>
      <div class="data-main">01 DE AGOSTO</div>
      <div class="data-year">2 0 2 6</div>
    </div>
  </div>

  <div class="pill"><b>Prof.</b> Francisco Borrello</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.screenshot(path=str(OUT_PNG), clip={"x": 0, "y": 0, "width": 1080, "height": 1080})
        browser.close()

    from PIL import Image
    img = Image.open(OUT_PNG).convert("RGB")
    img.save(OUT_JPG, "JPEG", quality=92, optimize=True)
    print(f"OK -> {OUT_JPG}")


if __name__ == "__main__":
    render()
