"""Génère illustrations/08-selfies.svg : leur conversation de selfies dans des toilettes stylées.
Un écran de messagerie qui défile tout seul : chacun à son tour envoie un selfie dans un
miroir de toilettes en faisant un cœur avec le pouce et l'index.
Point de vue de LUI : lui = bulles à droite (envoyés), Océane = bulles à gauche."""
import math, random, re, sys

out = sys.argv[1]
random.seed(3)
here = __file__.rsplit("/", 1)[0]
src06 = open(f"{here}/06-parapluies.py").read()
LUI_TETE = re.search(r"LUI_TETE = '''(.*?)'''", src06, re.S).group(1)
ELLE_TETE = re.search(r"ELLE_TETE = '''(.*?)'''", src06, re.S).group(1)

PW, PH = 180, 225        # taille d'une photo
STEP = 262               # hauteur d'un message (photo + légende)
TOP = 66
DUREE_ETAPE = 3.2        # secondes par selfie

SKIN_LUI = "#E3AE90"; SKIN_ELLE = "#C98E6E"

# ------------------------------------------------------------------ décors
def tiles(size, fn):
    g = []
    for y in range(0, PH + size, size):
        for x in range(0, PW + size, size):
            g.append(fn(x, y, size))
    return "".join(g)

def bg_azulejos():
    def t(x, y, s):
        c = x + s / 2, y + s / 2
        return (f'<rect x="{x}" y="{y}" width="{s}" height="{s}" fill="#EFE3C8" stroke="#C9B88E" stroke-width=".8"/>'
                f'<circle cx="{c[0]}" cy="{c[1]}" r="{s * .18}" fill="#2D4F86"/>'
                + "".join(f'<ellipse cx="{c[0] + s * .28 * dx}" cy="{c[1] + s * .28 * dy}" rx="{s * .12}" ry="{s * .12}" fill="#3E68A8"/>' for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)))
                + "".join(f'<path d="M{x + s * cx_} {y + s * cy_}m-{s * .14} 0a{s * .14} {s * .14} 0 0 0 {s * .28} 0" fill="#C8902E"/>' for cx_, cy_ in ((0, 0), (1, 0)) if False))
    teal = "".join(f'<rect x="{x}" y="{y}" width="20" height="20" fill="#3E7A88" stroke="#E8EEF0" stroke-width=".8"/>' for x in range(96, PW, 20) for y in range(40, PH, 20))
    return (f'<rect width="{PW}" height="{PH}" fill="#3E7A88"/>{tiles(24, t)}<rect x="96" y="40" width="{PW}" height="{PH}" fill="#3E7A88"/>{teal}'
            f'<rect x="0" y="0" width="{PW}" height="40" fill="#8A6A3A"/><rect x="8" y="60" width="40" height="{PH}" fill="#1A1E28"/>'
            f'<rect x="120" y="8" width="26" height="14" rx="2" fill="#F6F0E2"/><ellipse cx="90" cy="30" rx="120" ry="60" fill="#FFD27A" opacity=".25"/>')

def bg_terrazzo():
    dots = "".join(f'<path d="M{random.uniform(0, PW):.1f} {random.uniform(0, PH):.1f}l{random.uniform(2, 5):.1f} {random.uniform(-2, 2):.1f}l{random.uniform(-2, 1):.1f} {random.uniform(2, 4):.1f}Z" fill="{random.choice(["#E8879A", "#FFFFFF", "#9AD0C2", "#F4C86A", "#D4537E"])}"/>' for _ in range(150))
    return (f'<rect width="{PW}" height="{PH}" fill="#F6C6CF"/>{dots}'
            f'<text x="90" y="30" text-anchor="middle" font-family="\'Brush Script MT\',\'Segoe Script\',cursive" font-size="22" fill="none" stroke="#FF3F8E" stroke-width="1.4" filter="url(#lueur)" class="neon">hey toi</text>'
            f'<path d="M6 {PH}V70A84 64 0 0 1 174 70V{PH}" fill="none" stroke="#C9A25A" stroke-width="5"/>')

def bg_dore():
    g = f'<rect width="{PW}" height="{PH}" fill="#EDE6D6"/>'
    g += f'<rect x="0" y="150" width="{PW}" height="{PH}" fill="#1F6B52"/>'
    g += "".join(f'<path d="M{x} 150V{PH}" stroke="#2E8A6A" stroke-width="1"/>' for x in range(0, PW, 14))
    g += "".join(f'<path d="M0 {y}H{PW}" stroke="#2E8A6A" stroke-width="1"/>' for y in range(150, PH, 10))
    g += '<circle cx="40" cy="14" r="4" fill="#FFF6D6"/><circle cx="140" cy="14" r="4" fill="#FFF6D6"/><ellipse cx="40" cy="14" rx="20" ry="8" fill="#FFE9A8" opacity=".35"/><ellipse cx="140" cy="14" rx="20" ry="8" fill="#FFE9A8" opacity=".35"/>'
    g += '<rect x="150" y="40" width="30" height="185" fill="#3A2E2A"/>'
    return g

def bg_dore_frame():
    curls = "".join(f'<path d="M{x} 212q6-10 12 0t12 0" fill="none" stroke="#8A6420" stroke-width="2"/>' for x in range(-4, PW, 24))
    return (f'<path d="M0 200Q90 190 180 200V225H0Z" fill="#D4A63A"/><path d="M0 204Q90 194 180 204" fill="none" stroke="#F6D77A" stroke-width="3"/>{curls}'
            f'<path d="M0 220H180" stroke="#8A6420" stroke-width="2"/>')

def bg_jungle():
    leaves = []
    for _ in range(46):
        x, y = random.uniform(-10, PW + 10), random.uniform(-10, PH + 10)
        rot = random.uniform(0, 360); s = random.uniform(.7, 1.5)
        col = random.choice(["#2E6B3E", "#3E8A4E", "#24573A", "#4FA060", "#1E4A30"])
        leaves.append(f'<g transform="translate({x:.1f} {y:.1f}) rotate({rot:.0f}) scale({s:.2f})"><path d="M0 0Q8-10 20 0Q8 10 0 0Z" fill="{col}"/><path d="M1 0H19" stroke="#163A26" stroke-width=".6"/></g>')
    return (f'<rect width="{PW}" height="{PH}" fill="#173326"/>{"".join(leaves)}'
            f'<circle cx="20" cy="60" r="7" fill="#FFE2A0"/><ellipse cx="20" cy="60" rx="34" ry="40" fill="#FFD27A" opacity=".25"/>'
            f'<path d="M14 66H26L24 78H16Z" fill="#C9A25A"/>')

def bg_club():
    st = []
    for _ in range(60):
        x, y = random.uniform(-10, PW), random.uniform(-10, PH)
        w, h = random.uniform(10, 30), random.uniform(8, 20)
        col = random.choice(["#FF3F8E", "#3FE0FF", "#FCE04A", "#39FF88", "#FFFFFF", "#B98CFF", "#FF7A3D"])
        st.append(f'<g transform="rotate({random.uniform(-25, 25):.0f} {x + w / 2:.1f} {y + h / 2:.1f})"><rect x="{x:.1f}" y="{y:.1f}" width="{w:.1f}" height="{h:.1f}" rx="2" fill="{col}" opacity=".85"/>'
                  f'<path d="M{x + 3:.1f} {y + h / 2:.1f}h{w - 6:.1f}" stroke="#15121C" stroke-width="1.4" stroke-dasharray="3 2"/></g>')
    tags = "".join(f'<path d="M{random.uniform(0, 140):.0f} {random.uniform(10, 200):.0f}c8-14 14 10 22-4s12 8 20-6" fill="none" stroke="{c}" stroke-width="2.2" stroke-linecap="round"/>' for c in ("#39FF88", "#FF3F8E", "#FFFFFF"))
    return (f'<rect width="{PW}" height="{PH}" fill="#15121C"/>{"".join(st)}{tags}'
            f'<rect width="{PW}" height="{PH}" fill="#FF2A4A" opacity=".18"/>'
            f'<text x="150" y="30" text-anchor="middle" font-family="\'Arial Black\',Arial,sans-serif" font-size="16" fill="none" stroke="#FF3F8E" stroke-width="1.2" filter="url(#lueur)">REX</text>')

def bg_talavera():
    def t(x, y, s):
        c = x + s / 2, y + s / 2
        return (f'<rect x="{x}" y="{y}" width="{s}" height="{s}" fill="#FAF6EC" stroke="#D8CFB8" stroke-width=".8"/>'
                f'<circle cx="{c[0]}" cy="{c[1]}" r="{s * .22}" fill="#1F4FA0"/><circle cx="{c[0]}" cy="{c[1]}" r="{s * .1}" fill="#F4C430"/>'
                + "".join(f'<path d="M{c[0]} {c[1]}m{s * .26 * dx} {s * .26 * dy}l{s * .1 * dx - s * .06 * dy} {s * .1 * dy + s * .06 * dx}l{s * .06 * dy} {-s * .06 * dx}Z" fill="#1F4FA0"/>' for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)))
                + "".join(f'<path d="M{x + s * a} {y + s * b}m{-s * .16 if a else 0} 0a{s * .16} {s * .16} 0 0 {1 if b == 0 else 0} {s * .32 if a == 0 else 0} 0" fill="none"/>' for a, b in ()) +
                f'<path d="M{x} {y + s * .2}A{s * .2} {s * .2} 0 0 0 {x + s * .2} {y}L{x} {y}Z" fill="#E8742A"/>'
                f'<path d="M{x + s} {y + s * .8}A{s * .2} {s * .2} 0 0 0 {x + s * .8} {y + s}L{x + s} {y + s}Z" fill="#E8742A"/>')
    return f'<rect width="{PW}" height="{PH}" fill="#FAF6EC"/>{tiles(30, t)}'

def bg_talavera_frame():
    return f'<rect x="4" y="4" width="{PW - 8}" height="{PH - 8}" fill="none" stroke="#7A4E2E" stroke-width="10"/><rect x="0" y="0" width="{PW}" height="{PH}" fill="none" stroke="#5A3A22" stroke-width="3"/>'

def bg_avion():
    return (f'<rect width="{PW}" height="{PH}" fill="#D9DCE2"/><path d="M0 0H{PW}V18Q90 30 0 18Z" fill="#C3C8D0"/>'
            f'<rect x="132" y="34" width="38" height="22" rx="4" fill="#F2F4F7" stroke="#A8AEB8"/>'
            f'<circle cx="142" cy="45" r="6" fill="none" stroke="#D9342B" stroke-width="1.6"/><path d="M138 49L146 41" stroke="#D9342B" stroke-width="1.6"/><path d="M139 45H145" stroke="#5A5A66" stroke-width="2"/>'
            f'<path d="M156 40v10M152 44h8" stroke="#5A5A66" stroke-width="2" stroke-linecap="round"/>'
            f'<rect x="10" y="36" width="24" height="12" rx="3" fill="#F2F4F7" stroke="#A8AEB8"/><circle cx="22" cy="42" r="3" fill="#F4C430"/>'
            f'<rect width="{PW}" height="{PH}" fill="#BFD9F2" opacity=".18"/>'
            f'<rect x="1.5" y="1.5" width="{PW - 3}" height="{PH - 3}" rx="10" fill="none" stroke="#B8BEC8" stroke-width="3"/>')

def bg_retro():
    cols = ["#E8742A", "#C8501E", "#8A4A22", "#E0A030"]
    st = "".join(f'<path d="M{x} 0q6 28 0 56t0 56 0 56 0 56 0 56" fill="none" stroke="{cols[i % 4]}" stroke-width="12"/>' for i, x in enumerate(range(-6, PW + 12, 12)))
    bulbs = "".join(f'<circle cx="{x}" cy="12" r="6" fill="#FFF3C4" class="ampoule" style="animation-delay:{-i * .2:.1f}s"/>' for i, x in enumerate(range(14, PW, 22)))
    return f'<rect width="{PW}" height="{PH}" fill="#E8742A"/>{st}<rect x="0" y="0" width="{PW}" height="24" fill="#5A3A22"/>{bulbs}'

# ------------------------------------------------------------------ personnes
def body(cx, color, extra=""):
    return (f'<path d="M{cx - 8} 96H{cx + 8}V122H{cx - 8}Z" fill="{{skin}}"/>'
            f'<path d="M{cx - 64} {PH}C{cx - 64} 156 {cx - 44} 126 {cx} 120C{cx + 44} 126 {cx + 64} 156 {cx + 64} {PH}Z" fill="{color}"/>{extra}')

def outfit(name, cx):
    if name == "sweat":
        return body(cx, "#1E1E22", f'<path d="M{cx - 22} 122Q{cx} 140 {cx + 22} 122" fill="none" stroke="#33333A" stroke-width="7" stroke-linecap="round"/><path d="M{cx - 7} 132V160M{cx + 7} 132V160" stroke="#D8D8DE" stroke-width="1.4"/>')
    if name == "parka":
        return body(cx, "#2C3550", f'<path d="M{cx - 20} 122Q{cx} 108 {cx + 20} 122L{cx + 24} 134Q{cx} 120 {cx - 24} 134Z" fill="#232B44"/><path d="M{cx - 5} 124L{cx} 134L{cx + 5} 124Z" fill="#F1EEE6"/><path d="M{cx} 134V{PH}" stroke="#4A5578" stroke-width="1.4"/>')
    if name == "surchemise":
        return body(cx, "#5E6B3F", f'<path d="M{cx - 10} 120L{cx + 10} 120L{cx + 5} 150L{cx - 5} 150Z" fill="#F1EEE6"/><path d="M{cx - 14} 120L{cx - 3} 121L{cx} 144ZM{cx + 14} 120L{cx + 3} 121L{cx} 144Z" fill="#4A5532"/><path d="M{cx} 150V{PH}" stroke="#3C4529" stroke-width="1"/><path d="M{cx - 42} 160h18v14h-18Z" fill="none" stroke="#3C4529"/>')
    if name == "tee":
        return body(cx, "#F1EEE6", f'<path d="M{cx - 12} 121Q{cx} 130 {cx + 12} 121" fill="none" stroke="#D8D2C6" stroke-width="2"/>')
    if name == "rayures":
        return body(cx, "url(#rayures)", f'<path d="M{cx - 10} 120L{cx} 136L{cx + 10} 120" fill="#E3D3BD"/><path d="M{cx} 136V{PH}" stroke="#CDB99E"/>')
    if name == "pull_vert":
        return body(cx, "#5F7A5A", f'<path d="M{cx - 16} 122Q{cx} 132 {cx + 16} 122" fill="none" stroke="#4E6A4A" stroke-width="5"/>' + "".join(f'<path d="M{cx + dx} 140q4 8 0 16t0 16 0 16 0 16" fill="none" stroke="#4E6A4A" stroke-width="2"/>' for dx in (-30, -10, 10, 30)))
    if name == "debardeur":
        return (body(cx, "{skin}") +
                f'<path d="M{cx - 50} {PH}C{cx - 50} 170 {cx - 40} 150 {cx - 26} 146Q{cx} 160 {cx + 26} 146C{cx + 40} 150 {cx + 50} 170 {cx + 50} {PH}Z" fill="#E0A030"/>'
                f'<path d="M{cx - 26} 146L{cx - 22} 124M{cx + 26} 146L{cx + 22} 124" stroke="#E0A030" stroke-width="3"/>')
    if name == "gilet":
        return (body(cx, "#E23B3B") +
                f'<path d="M{cx - 14} 122L{cx + 14} 122L{cx + 10} {PH}L{cx - 10} {PH}Z" fill="#FFFFFF"/>'
                + "".join(f'<path d="M{cx - 14} {y}H{cx + 14}" stroke="#E23B3B" stroke-width="3"/>' for y in range(130, PH, 9))
                + f'<path d="M{cx - 14} 122L{cx - 10} {PH}M{cx + 14} 122L{cx + 10} {PH}" stroke="#C42A2A" stroke-width="4"/>')
    raise ValueError(name)

def phone(x, y, case):
    return (f'<rect x="{x}" y="{y}" width="30" height="56" rx="6" fill="{case}"/>'
            f'<rect x="{x + 3}" y="{y + 3}" width="14" height="14" rx="4" fill="#2A2A30"/>'
            f'<circle cx="{x + 7}" cy="{y + 7}" r="2.6" fill="#0E0E14"/><circle cx="{x + 13}" cy="{y + 7}" r="2.6" fill="#0E0E14"/><circle cx="{x + 7}" cy="{y + 13}" r="2.6" fill="#0E0E14"/>'
            f'<circle cx="{x + 13}" cy="{y + 13}" r="1.2" fill="#FFF6C2" class="flash"/>')

def finger_heart(x, y, skin, sleeve, rings):
    r = "".join(f'<path d="M{x - 6} {y + 2 + 4 * k}h11" stroke="#D4D4DC" stroke-width="1.5"/>' for k in range(rings))
    return (f'<path d="M{x + 14} {PH}Q{x + 18} {y + 40} {x + 4} {y + 10}" fill="none" stroke="{sleeve}" stroke-width="18" stroke-linecap="round"/>'
            f'<ellipse cx="{x}" cy="{y + 6}" rx="9" ry="10" fill="{skin}"/>'
            f'<path d="M{x - 4} {y - 1}Q{x - 9} {y - 12} {x - 3} {y - 16}" fill="none" stroke="{skin}" stroke-width="5.4" stroke-linecap="round"/>'
            f'<path d="M{x + 5} {y - 1}Q{x + 2} {y - 12} {x - 6} {y - 14}" fill="none" stroke="{skin}" stroke-width="5.6" stroke-linecap="round"/>'
            f'<path d="M{x - 4} {y + 4}h8M{x - 4} {y + 9}h8" stroke="#00000022" stroke-width="1"/>{r}'
            f'<g transform="translate({x - 4} {y - 30})"><path class="mini-coeur" d="M0 3C0-1-6-1-6 3C-6 6 0 9 0 11C0 9 6 6 6 3C6-1 0-1 0 3Z" fill="#FF3F6E"/></g>')

def selfie(who, outfit_name, decor, case):
    cx = 92
    skin = SKIN_LUI if who == "lui" else SKIN_ELLE
    sleeve = {"sweat": "#1E1E22", "parka": "#2C3550", "surchemise": "#5E6B3F", "tee": skin, "rayures": skin,
              "pull_vert": "#5F7A5A", "debardeur": skin, "gilet": "#E23B3B"}[outfit_name]
    g = decor
    g += outfit(outfit_name, cx).replace("{skin}", skin)
    if who == "lui":
        g += f'<g transform="translate({cx} 78)">{LUI_TETE}</g>'
    else:
        g += f'<g transform="translate({cx} 80) scale(1.2)">{ELLE_TETE}</g>'
    # main qui tient le téléphone (à gauche) + bras
    g += f'<path d="M{cx - 46} {PH}Q{cx - 50} 190 {cx - 36} 166" fill="none" stroke="{sleeve}" stroke-width="18" stroke-linecap="round"/>'
    g += phone(cx - 52, 126, case)
    g += f'<ellipse cx="{cx - 22}" cy="166" rx="7" ry="9" fill="{skin}"/><path d="M{cx - 28} 158h6M{cx - 28} 164h6M{cx - 28} 170h6" stroke="{skin}" stroke-width="4" stroke-linecap="round"/>'
    if who == "lui":
        g += f'<path d="M{cx - 30} 162h8M{cx - 30} 168h8" stroke="#D4D4DC" stroke-width="1.4"/>'
    g += finger_heart(cx + 40, 112, skin, sleeve, 1 if who == "lui" else 0)
    # reflet du miroir
    g += f'<path d="M{PW - 60} 0L{PW} 0L{PW} 50L{PW - 110} {PH}H{PW - 150}Z" fill="#FFFFFF" opacity=".08"/>'
    return g

MESSAGES = [
    ("lui", "sweat", bg_azulejos(), "", "#9DB8A0", "toilettes azulejos ✨", "21:04"),
    ("elle", "rayures", bg_terrazzo(), "", "#F4F0EC", "et moi les roses 💗", "21:06"),
    ("lui", "parka", bg_dore(), bg_dore_frame(), "#9DB8A0", "miroir de roi 👑", "12:31"),
    ("elle", "pull_vert", bg_jungle(), "", "#F4F0EC", "toilettes jungle 🌿", "12:40"),
    ("lui", "surchemise", bg_club(), "", "#9DB8A0", "au Rex 🪩", "02:17"),
    ("elle", "debardeur", bg_talavera(), bg_talavera_frame(), "#F4F0EC", "¡hola desde México! 🌵", "14:52"),
    ("lui", "tee", bg_avion(), "", "#9DB8A0", "à 10 000 m ✈️", "07:45"),
    ("elle", "gilet", bg_retro(), "", "#F4F0EC", "ambiance 70s 🕺", "19:20"),
]

def message(i, m):
    who, outf, decor, frame, case, caption, time = m
    y = TOP + i * STEP
    x = 14 if who == "elle" else 400 - 14 - PW
    cid = f"ph{i}"
    pic = selfie(who, outf, decor, case) + frame
    bubble_col = "#FFFFFF" if who == "elle" else "#FFD3E0"
    tx = x + 10 if who == "elle" else x + PW - 10
    anchor = "start" if who == "elle" else "end"
    vu = '<path d="M{0} {1}l3 3 6-6M{2} {1}l3 3 6-6" fill="none" stroke="#3E8FD8" stroke-width="1.4" stroke-linecap="round"/>'.format(x + PW - 30, y + PH + 22, x + PW - 25) if who == "lui" else ""
    return (f'<clipPath id="{cid}"><rect x="0" y="0" width="{PW}" height="{PH}" rx="14"/></clipPath>'
            f'<rect x="{x - 4}" y="{y - 4}" width="{PW + 8}" height="{PH + 34}" rx="16" fill="{bubble_col}"/>'
            f'<g transform="translate({x} {y})"><g clip-path="url(#{cid})">{pic}</g></g>'
            f'<text x="{tx}" y="{y + PH + 20}" text-anchor="{anchor}" font-family="-apple-system,\'Segoe UI\',Roboto,Arial,sans-serif" font-size="12" fill="#3A2A30">{caption}</text>'
            f'<text x="{x + PW - 6 if who == "elle" else x + PW - 34}" y="{y + PH + 20}" text-anchor="end" font-family="-apple-system,\'Segoe UI\',Roboto,Arial,sans-serif" font-size="9" fill="#9A8A90">{time}</text>{vu}')

n = len(MESSAGES)
msgs = "".join(message(i, m) for i, m in enumerate(MESSAGES + MESSAGES[:2]))

# défilement : on monte d'un message toutes les DUREE_ETAPE s ; la fin = le début (boucle parfaite)
frames = []
for k in range(n + 1):
    t0 = k / n * 100
    frames.append(f"{t0:.2f}%{{transform:translateY({-k * STEP}px)}}")
    if k < n:
        frames.append(f"{t0 + 100 / n * .82:.2f}%{{transform:translateY({-k * STEP}px)}}")
scroll_css = f"@keyframes defile{{{''.join(frames)}}}"

svg = f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 500" width="400" height="500">
<title>Nos selfies dans les toilettes</title>
<defs>
  <pattern id="rayures" width="14" height="20" patternUnits="userSpaceOnUse">
    <rect width="14" height="20" fill="#EFE2D0"/><rect x="0" width="2.2" height="20" fill="#E79AA3"/><rect x="3.6" width="1.4" height="20" fill="#93B592"/>
    <rect x="6.6" width="2.2" height="20" fill="#E8A066"/><rect x="10.4" width="1.4" height="20" fill="#B59AC6"/>
  </pattern>
  <pattern id="fond-coeurs" width="40" height="40" patternUnits="userSpaceOnUse">
    <rect width="40" height="40" fill="#FFF3F6"/><path transform="translate(10 10) scale(.6)" d="M0 3C0-1-6-1-6 3C-6 6 0 9 0 11C0 9 6 6 6 3C6-1 0-1 0 3Z" fill="#FBD9E2"/>
    <path transform="translate(30 30) scale(.5)" d="M0 3C0-1-6-1-6 3C-6 6 0 9 0 11C0 9 6 6 6 3C6-1 0-1 0 3Z" fill="#FBD9E2"/>
  </pattern>
  <filter id="lueur" x="-50%" y="-50%" width="200%" height="200%">
    <feGaussianBlur stdDeviation="1.4" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
  </filter>
  <clipPath id="ecran"><rect x="0" y="56" width="400" height="444"/></clipPath>
</defs>
<style>
  .fil{{animation:defile {DUREE_ETAPE * n}s ease-in-out infinite}}
  {scroll_css}
  .mini-coeur{{animation:mini 1s ease-in-out infinite;transform-box:fill-box;transform-origin:center}}
  @keyframes mini{{0%,100%{{transform:scale(.8)}}50%{{transform:scale(1.25)}}}}
  .flash{{animation:flash 2s ease-in-out infinite}}
  @keyframes flash{{0%,100%{{opacity:.4}}50%{{opacity:1}}}}
  .neon{{animation:neon 3s linear infinite}}
  @keyframes neon{{0%,90%,94%,100%{{opacity:1}}92%{{opacity:.3}}}}
  .ampoule{{animation:ampoule 1.4s ease-in-out infinite alternate}}
  @keyframes ampoule{{from{{opacity:.6}}to{{opacity:1}}}}
  .points circle{{animation:points 1.2s ease-in-out infinite}}
  @keyframes points{{0%,100%{{opacity:.3;transform:translateY(0)}}50%{{opacity:1;transform:translateY(-2px)}}}}
</style>

<rect width="400" height="500" fill="url(#fond-coeurs)"/>
<g clip-path="url(#ecran)"><g class="fil">{msgs}</g></g>

<!-- barre du haut de la conversation -->
<rect width="400" height="56" fill="#FFFFFF"/>
<path d="M0 56H400" stroke="#EADDE2"/>
<path d="M22 20L14 28L22 36" fill="none" stroke="#3E8FD8" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="52" cy="28" r="17" fill="#FFD3E0"/>
<path transform="translate(52 21) scale(1.3)" d="M0 3C0-1-6-1-6 3C-6 6 0 9 0 11C0 9 6 6 6 3C6-1 0-1 0 3Z" fill="#FF3F6E"/>
<text x="78" y="26" font-family="-apple-system,'Segoe UI',Roboto,Arial,sans-serif" font-size="15" font-weight="600" fill="#2A1E24">Océane ☂️☂️☂️💊</text>
<g class="points" fill="#9A8A90"><circle cx="81" cy="40" r="2"/><circle cx="88" cy="40" r="2" style="animation-delay:.2s"/><circle cx="95" cy="40" r="2" style="animation-delay:.4s"/></g>
<text x="103" y="43" font-family="-apple-system,'Segoe UI',Roboto,Arial,sans-serif" font-size="10" fill="#9A8A90">en train d'aller aux toilettes</text>
<path d="M352 20h18v14h-18zM370 24l8-4v14l-8-4" fill="none" stroke="#3E8FD8" stroke-width="2" stroke-linejoin="round"/>
</svg>
'''
open(out, "w").write(svg)
print("ok", len(svg))
