#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Luciferase E 版背景三挡：低 / 中 / 高设计感。不改正文与版式，只换背景层。"""
from pathlib import Path
import re

ROOT = Path('/Users/liuxinyuan/Desktop/Hermes输出-工作类')
BASE = ROOT / '对外物料/Luciferase_A4_E版_编辑式_20261029.html'
base = BASE.read_text(encoding='utf-8')

VARIANTS = {
    'low': {
        'name': '低设计感',
        'bg': '''
<rect width="210" height="297" fill="#F2F6F7"/>
''',
        'css': '''
.v-low .hero{background:#071D33}
'''
    },
    'mid': {
        'name': '中设计感',
        'bg': '''
<rect width="210" height="297" fill="#F2F6F7"/>
<rect y="108" width="210" height="50" fill="#DDF0F2" opacity=".90"/>
<g fill="none" stroke="#5EA7B7" opacity=".30">
  <circle cx="170" cy="58" r="40"/>
  <circle cx="170" cy="58" r="28"/>
  <circle cx="170" cy="58" r="16"/>
</g>
<g fill="none" stroke="#9FD5DF" opacity=".26">
  <circle cx="180" cy="245" r="28"/>
</g>
''',
        'css': '''
.v-mid .hero{background:#071D33}
'''
    },
    'high': {
        'name': '高设计感',
        'bg': '''
<rect y="20" width="210" height="135" fill="#061725"/>
<g fill="none" stroke="#00D2E8" opacity=".20">
  <circle cx="175" cy="55" r="34"/>
  <circle cx="175" cy="55" r="24"/>
  <circle cx="175" cy="55" r="14"/>
</g>
<g fill="#00D2E8" opacity=".20">
  <circle cx="40" cy="112" r="1.2"/><circle cx="52" cy="112" r="1.2"/><circle cx="64" cy="112" r="1.2"/>
  <circle cx="40" cy="124" r="1.2"/><circle cx="52" cy="124" r="1.2"/><circle cx="64" cy="124" r="1.2"/>
</g>
''',
        'css': '''
.v-high .hero{background:transparent}
.v-high .evidence{color:#EAF8FA}
.v-high .big3 .n{color:#fff}
.v-high .big3 .lb{color:#B9D6E0}
.v-high .big3 .lb b{color:#fff}
.v-high .bar-row{color:#D6E9EE}
.v-high .bar-row .name{color:#EAF8FA;font-size:7.5pt;font-weight:600}
.v-high .bar-row .track{background:rgba(255,255,255,.22)}
.v-high .bar-row .val{color:#fff;font-size:7.5pt}
.v-high .chart .ch h2{color:#fff}
.v-high .chart .ch span{color:#A7C7D2}
.v-high .b{background:#00D2E8}
.v-high .b.alt{background:#6C8B97}
.v-high .b .v{color:#fff}
.v-high .b.alt .v{color:#D7E8EC}
.v-high .grp .gl{color:#B9D6E0}
.v-high .legend,.v-high .note{color:#D6E9EE}
.v-high .note{font-size:6.6pt}
'''
    },
}

GENERAL = '''
.page{position:relative;isolation:isolate}
.bg{position:absolute;inset:0;width:100%;height:100%;z-index:0;pointer-events:none}
.page > *:not(.bg){position:relative;z-index:1}
'''

for key, v in VARIANTS.items():
    html = base.replace('<body>', f'<body class="v-{key}">', 1)
    # insert bg as first child of page
    html = html.replace('<div class="page">', '<div class="page"><svg class="bg" viewBox="0 0 210 297" preserveAspectRatio="none" aria-hidden="true">' + v['bg'] + '</svg>', 1)
    html = html.replace('</style>', GENERAL + v['css'] + '</style>', 1)
    name = f'Luciferase_A4_E_{key}_{v["name"]}_20261029'
    out = ROOT / '对外物料' / f'{name}.html'
    out.write_text(html, encoding='utf-8')
    print('saved', out, len(html))
