#!/usr/bin/env python3
from pathlib import Path
import cairosvg

W, H = 1800, 2400
OUT_DIR = Path('/local/usr/hermes-workdir')
SVG_PATH = OUT_DIR / 'iphone17pm-teardown.svg'
PNG_PATH = OUT_DIR / 'iphone17pm-teardown.png'

svg = f'''<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{H}" viewBox="0 0 {W} {H}">
  <defs>
    <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#fbfcfe"/>
      <stop offset="100%" stop-color="#edf2f7"/>
    </linearGradient>
    <radialGradient id="glow" cx="50%" cy="40%" r="55%">
      <stop offset="0%" stop-color="#ffffff" stop-opacity="0.95"/>
      <stop offset="65%" stop-color="#ffffff" stop-opacity="0.35"/>
      <stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
    </radialGradient>

    <linearGradient id="glassGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#f9fbff" stop-opacity="0.35"/>
      <stop offset="100%" stop-color="#cfdced" stop-opacity="0.15"/>
    </linearGradient>
    <linearGradient id="displayGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#1d2127"/>
      <stop offset="100%" stop-color="#07090d"/>
    </linearGradient>
    <linearGradient id="frameGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#edf1f6"/>
      <stop offset="50%" stop-color="#cfd5dd"/>
      <stop offset="100%" stop-color="#8f97a2"/>
    </linearGradient>
    <linearGradient id="innerFrameGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#ffffff"/>
      <stop offset="100%" stop-color="#e7ecf2"/>
    </linearGradient>
    <linearGradient id="backGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#fafcff"/>
      <stop offset="100%" stop-color="#bcc8d8"/>
    </linearGradient>
    <linearGradient id="batteryGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#24272d"/>
      <stop offset="100%" stop-color="#101216"/>
    </linearGradient>
    <linearGradient id="boardGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#2e6a45"/>
      <stop offset="100%" stop-color="#143320"/>
    </linearGradient>
    <linearGradient id="thermalGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#707886" stop-opacity="0.45"/>
      <stop offset="100%" stop-color="#2f3640" stop-opacity="0.32"/>
    </linearGradient>
    <linearGradient id="coilGrad" x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stop-color="#f6f8fc" stop-opacity="0.85"/>
      <stop offset="100%" stop-color="#c9d4e0" stop-opacity="0.6"/>
    </linearGradient>

    <filter id="softShadow" x="-25%" y="-25%" width="150%" height="150%">
      <feDropShadow dx="0" dy="18" stdDeviation="18" flood-color="#2e3b50" flood-opacity="0.12"/>
    </filter>
    <filter id="cardShadow" x="-25%" y="-25%" width="150%" height="150%">
      <feDropShadow dx="0" dy="24" stdDeviation="22" flood-color="#253246" flood-opacity="0.16"/>
    </filter>
    <filter id="cameraShadow" x="-25%" y="-25%" width="150%" height="150%">
      <feDropShadow dx="0" dy="12" stdDeviation="10" flood-color="#0d1724" flood-opacity="0.24"/>
    </filter>

    <style>
      .title {{ font: 700 48px -apple-system,BlinkMacSystemFont,'SF Pro Display','Segoe UI',Arial,sans-serif; fill:#526478; letter-spacing:0.8px; }}
      .subtle {{ font: 500 26px -apple-system,BlinkMacSystemFont,'SF Pro Text','Segoe UI',Arial,sans-serif; fill:#8392a3; letter-spacing:0.3px; }}
      .label {{ font: 600 24px -apple-system,BlinkMacSystemFont,'SF Pro Text','Segoe UI',Arial,sans-serif; fill:#637588; }}
      .guide {{ stroke:#c4cfdb; stroke-width:2.5; stroke-dasharray:7 11; opacity:0.65; }}
      .chip {{ fill:#171a1f; stroke:#6e7783; stroke-opacity:0.35; stroke-width:2; rx:18; }}
    </style>
  </defs>

  <rect width="100%" height="100%" fill="url(#bg)"/>
  <rect width="100%" height="100%" fill="url(#glow)"/>

  <text x="900" y="140" text-anchor="middle" class="title">iPhone 17 Pro Max · Exploded Teardown View</text>
  <text x="900" y="205" text-anchor="middle" class="subtle">概念技术拆解图 · 工业设计风格示意</text>

  <line x1="420" y1="330" x2="420" y2="2070" class="guide"/>
  <line x1="1380" y1="330" x2="1380" y2="2070" class="guide"/>

  <g opacity="0.14">
    <rect x="390" y="280" width="1020" height="1890" rx="130" fill="none" stroke="#a9b8c8" stroke-width="4"/>
  </g>

  <!-- Front glass -->
  <g filter="url(#softShadow)">
    <rect x="430" y="320" width="940" height="1600" rx="108" fill="url(#glassGrad)" stroke="#fefeff" stroke-opacity="0.92" stroke-width="3"/>
    <path d="M500 430 C700 540, 760 680, 860 820" stroke="#ffffff" stroke-opacity="0.20" stroke-width="18" stroke-linecap="round" fill="none"/>
    <path d="M520 500 C720 640, 790 780, 920 960" stroke="#ffffff" stroke-opacity="0.12" stroke-width="8" stroke-linecap="round" fill="none"/>
  </g>

  <!-- Display -->
  <g filter="url(#softShadow)">
    <rect x="410" y="500" width="980" height="1660" rx="118" fill="url(#displayGrad)" stroke="#343b47" stroke-width="4"/>
    <rect x="438" y="528" width="924" height="1604" rx="98" fill="#13171d"/>
    <rect x="755" y="548" width="290" height="34" rx="17" fill="#08090d" opacity="0.95"/>
  </g>

  <!-- Mid frame -->
  <g filter="url(#cardShadow)">
    <rect x="390" y="740" width="1020" height="1620" rx="128" fill="url(#frameGrad)" stroke="#f9fbff" stroke-width="4"/>
    <rect x="418" y="768" width="964" height="1564" rx="104" fill="url(#innerFrameGrad)" stroke="#c3ccd6" stroke-width="2"/>
  </g>

  <!-- Internal assembly -->
  <g filter="url(#cardShadow)">
    <rect x="434" y="950" width="932" height="1140" rx="94" fill="#eef2f7" stroke="#ffffff" stroke-width="3"/>
    <rect x="468" y="984" width="864" height="1072" rx="74" fill="#f6f8fb" opacity="0.9"/>

    <!-- cameras mount -->
    <rect x="500" y="1032" width="342" height="342" rx="66" fill="#c3ccd7" opacity="0.55"/>

    <!-- logic board -->
    <rect x="1114" y="1100" width="124" height="858" rx="58" fill="url(#boardGrad)" stroke="#87ae93" stroke-opacity="0.45" stroke-width="3"/>
    <rect x="1132" y="1130" width="88" height="126" rx="18" class="chip"/>
    <rect x="1132" y="1284" width="88" height="92" rx="16" class="chip"/>
    <rect x="1140" y="1400" width="72" height="130" rx="16" class="chip"/>
    <rect x="1132" y="1560" width="88" height="92" rx="16" class="chip"/>
    <rect x="1140" y="1680" width="72" height="88" rx="16" class="chip"/>
    <rect x="1132" y="1790" width="88" height="128" rx="18" class="chip"/>
    <rect x="1098" y="1386" width="18" height="18" rx="4" fill="#d7b163"/>
    <rect x="1098" y="1646" width="18" height="18" rx="4" fill="#d7b163"/>
    <rect x="1098" y="1870" width="18" height="18" rx="4" fill="#d7b163"/>

    <!-- battery -->
    <rect x="632" y="1208" width="290" height="646" rx="42" fill="url(#batteryGrad)" stroke="#5e6672" stroke-opacity="0.45" stroke-width="3"/>
    <rect x="966" y="1208" width="290" height="646" rx="42" fill="url(#batteryGrad)" stroke="#5e6672" stroke-opacity="0.45" stroke-width="3"/>
    <rect x="796" y="1168" width="38" height="76" rx="10" fill="#b4beca"/>

    <!-- speaker + taptic -->
    <rect x="552" y="1886" width="208" height="146" rx="28" fill="#181b1f" stroke="#5f6670" stroke-opacity="0.4" stroke-width="3"/>
    <rect x="974" y="1902" width="240" height="116" rx="24" fill="#1b1d21" stroke="#676d77" stroke-opacity="0.4" stroke-width="3"/>
    <g fill="#d9dee6" opacity="0.72">
      <circle cx="1012" cy="1960" r="6"/><circle cx="1038" cy="1960" r="6"/><circle cx="1064" cy="1960" r="6"/>
      <circle cx="1090" cy="1960" r="6"/><circle cx="1116" cy="1960" r="6"/><circle cx="1142" cy="1960" r="6"/>
      <circle cx="1168" cy="1960" r="6"/>
    </g>

    <!-- cameras -->
    <g filter="url(#cameraShadow)">
      <circle cx="572" cy="1118" r="76" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
      <circle cx="572" cy="1118" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
      <circle cx="572" cy="1118" r="35" fill="#244153" fill-opacity="0.45"/>
      <circle cx="560" cy="1106" r="11" fill="#ffffff" fill-opacity="0.15"/>

      <circle cx="724" cy="1118" r="76" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
      <circle cx="724" cy="1118" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
      <circle cx="724" cy="1118" r="35" fill="#244153" fill-opacity="0.45"/>
      <circle cx="712" cy="1106" r="11" fill="#ffffff" fill-opacity="0.15"/>

      <circle cx="648" cy="1270" r="76" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
      <circle cx="648" cy="1270" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
      <circle cx="648" cy="1270" r="35" fill="#244153" fill-opacity="0.45"/>
      <circle cx="636" cy="1258" r="11" fill="#ffffff" fill-opacity="0.15"/>

      <circle cx="790" cy="1270" r="32" fill="#1b1d20" stroke="#cfd5dc" stroke-width="5"/>
      <circle cx="782" cy="1176" r="22" fill="#f7f8fa" stroke="#9ba7b3" stroke-width="4"/>
    </g>
  </g>

  <!-- Thermal / graphite -->
  <g filter="url(#softShadow)">
    <rect x="426" y="1328" width="948" height="1040" rx="98" fill="url(#thermalGrad)" stroke="#9aa7b6" stroke-opacity="0.32" stroke-width="2"/>
    <g stroke="#f5f8fc" stroke-opacity="0.08" stroke-width="6">
      <line x1="546" y1="1460" x2="1254" y2="1420"/>
      <line x1="546" y1="1540" x2="1254" y2="1500"/>
      <line x1="546" y1="1620" x2="1254" y2="1580"/>
      <line x1="546" y1="1700" x2="1254" y2="1660"/>
      <line x1="546" y1="1780" x2="1254" y2="1740"/>
      <line x1="546" y1="1860" x2="1254" y2="1820"/>
      <line x1="546" y1="1940" x2="1254" y2="1900"/>
      <line x1="546" y1="2020" x2="1254" y2="1980"/>
      <line x1="546" y1="2100" x2="1254" y2="2060"/>
      <line x1="546" y1="2180" x2="1254" y2="2140"/>
    </g>
  </g>

  <!-- MagSafe coil -->
  <g filter="url(#softShadow)">
    <rect x="418" y="1492" width="964" height="940" rx="100" fill="url(#coilGrad)" stroke="#ffffff" stroke-opacity="0.75" stroke-width="3"/>
    <circle cx="900" cy="2010" r="270" fill="none" stroke="#9eacbe" stroke-opacity="0.75" stroke-width="22"/>
    <circle cx="900" cy="2010" r="208" fill="none" stroke="#b3becc" stroke-opacity="0.55" stroke-width="14"/>
    <rect x="810" y="2244" width="180" height="64" rx="20" fill="#a4b0bf" fill-opacity="0.65"/>
    <g stroke="#ffffff" stroke-opacity="0.24" stroke-width="4">
      <line x1="710" y1="1888" x2="1090" y2="1888"/>
      <line x1="710" y1="1958" x2="1090" y2="1958"/>
      <line x1="710" y1="2028" x2="1090" y2="2028"/>
    </g>
  </g>

  <!-- Back glass -->
  <g filter="url(#cardShadow)">
    <rect x="404" y="1680" width="992" height="688" rx="118" fill="url(#backGrad)" stroke="#ffffff" stroke-opacity="0.92" stroke-width="3"/>
    <rect x="422" y="1698" width="956" height="652" rx="100" fill="#ffffff" fill-opacity="0.08"/>
  </g>

  <!-- Camera bump on back panel -->
  <g filter="url(#cameraShadow)">
    <rect x="474" y="1714" width="360" height="360" rx="72" fill="#c1c9d4" fill-opacity="0.68" stroke="#ffffff" stroke-opacity="0.4" stroke-width="3"/>
    <circle cx="562" cy="1800" r="74" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
    <circle cx="562" cy="1800" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
    <circle cx="562" cy="1800" r="35" fill="#244153" fill-opacity="0.45"/>
    <circle cx="714" cy="1800" r="74" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
    <circle cx="714" cy="1800" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
    <circle cx="714" cy="1800" r="35" fill="#244153" fill-opacity="0.45"/>
    <circle cx="638" cy="1952" r="74" fill="#14171b" stroke="#c8d1dd" stroke-width="10"/>
    <circle cx="638" cy="1952" r="56" fill="#030406" stroke="#4d5a6a" stroke-width="5"/>
    <circle cx="638" cy="1952" r="35" fill="#244153" fill-opacity="0.45"/>
    <circle cx="780" cy="1952" r="32" fill="#1b1d20" stroke="#cfd5dc" stroke-width="5"/>
    <circle cx="772" cy="1858" r="22" fill="#f7f8fa" stroke="#9ba7b3" stroke-width="4"/>
  </g>

  <g opacity="0.95">
    <text x="1460" y="410" class="label">前玻璃</text>
    <text x="1460" y="620" class="label">显示屏组件</text>
    <text x="1460" y="845" class="label">钛金属中框</text>
    <text x="1460" y="1060" class="label">电池 / 主板 / 摄像头</text>
    <text x="1460" y="1390" class="label">散热层</text>
    <text x="1460" y="1560" class="label">无线充电线圈</text>
    <text x="1460" y="1720" class="label">后盖玻璃</text>
  </g>

  <g stroke="#afbccb" stroke-width="2" fill="none" opacity="0.85">
    <path d="M1430 402 C1388 402, 1370 402, 1334 402"/>
    <path d="M1430 612 C1388 612, 1370 612, 1334 612"/>
    <path d="M1430 837 C1388 837, 1370 837, 1330 837"/>
    <path d="M1430 1052 C1388 1052, 1370 1052, 1330 1052"/>
    <path d="M1430 1382 C1388 1382, 1370 1382, 1332 1382"/>
    <path d="M1430 1552 C1388 1552, 1370 1552, 1332 1552"/>
    <path d="M1430 1712 C1388 1712, 1370 1712, 1332 1712"/>
  </g>

  <text x="900" y="2350" text-anchor="middle" class="subtle">Clean technical concept render · centered exploded structure · PNG deliverable</text>
</svg>'''

SVG_PATH.write_text(svg, encoding='utf-8')
cairosvg.svg2png(bytestring=svg.encode('utf-8'), write_to=str(PNG_PATH), output_width=W, output_height=H)
print(f'Wrote {SVG_PATH}')
print(f'Wrote {PNG_PATH}')
