#!/usr/bin/env python3
"""Builds the Surch candidate landing page.
   - index.html + css/ + js/ + assets/   (separate files, open index.html locally)
   - preview.html                        (one self-contained file, everything inlined)
   Shared styles come from the employer site (../surch-site/src/landing.css) so the two
   stay identical and merge cleanly later."""
import base64, html, mimetypes, os, re, shutil

ROOT = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.join(ROOT, "src")
SHARED_CSS = os.path.join(ROOT, "..", "surch-site", "src", "landing.css")
def rd(p): return open(p, encoding="utf-8").read()
BRIDGE = os.path.join(ROOT, "..", "surch-shared", "bridge.js")
MOTION_JS = os.path.join(ROOT, "..", "surch-shared", "motion.js")     # shared motion runtime
MOTION_CSS = os.path.join(ROOT, "..", "surch-shared", "motion.css")   # shared motion tokens   # shared with the employer portal

STAR = '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6 6.6.8-4.9 4.6 1.3 6.6L12 17.3l-5.9 3.2 1.3-6.6L2.5 9.3l6.6-.8z"/></svg>'
APPLE = '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M16.4 1.4c0 1.1-.5 2.3-1.2 3.1-.7.9-2 1.6-3 1.6h-.3v-.4c0-1.1.6-2.3 1.2-3 .8-.9 2.1-1.6 3.2-1.7zm4.5 15.7c0 .1-.5 1.6-1.5 3.1-.9 1.3-1.9 2.7-3.4 2.7s-1.9-.9-3.6-.9-2.3.9-3.7.9-2.3-1.3-3.4-2.8c-1.3-1.8-2.3-4.6-2.3-7.3 0-4.3 2.8-6.5 5.5-6.5 1.4 0 2.7.9 3.6.9.9 0 2.2-1 3.9-1 .6 0 2.9.1 4.4 2.2-.1.1-2.4 1.4-2.4 4.2 0 3.3 2.9 4.4 2.9 4.5z"/></svg>'
PLAY = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#00c3ff" d="M3.6 1.8 13.5 12 3.6 22.2c-.4-.2-.6-.7-.6-1.2V3c0-.5.2-.9.6-1.2z"/><path fill="#00e676" d="M3.6 1.8c.4-.3 1-.3 1.6 0L17 8.6 13.5 12z"/><path fill="#ff3d47" d="M13.5 12 17 15.4 5.2 22.2c-.6.3-1.2.3-1.6 0z"/><path fill="#ffd400" d="M17 8.6l3.6 2.1c1 .6 1 1.9 0 2.5L17 15.4 13.5 12z"/></svg>'
LOGOS = [("star-brands","Star Brands",1),("mww","MWW experts in fresh",0),("purple-supplies","Purple Supplies",0),
         ("simply-doors","Simply Doors & Windows",0),("ngw-group","The NGW Group",0),("oakland","Oakland International",0),
         ("perfect-personnel","Perfect Personnel",0),("newform","Newform Windows Ltd",0),("simply-eco","Simply Eco Packaging",1)]

_S = 'viewBox="0 0 56 56" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"'
ICONS = [
  # 1 create account: form window
  f'<svg {_S}><rect x="10" y="5" width="34" height="46" rx="3"/><path d="M10 12h34M36 8.5h1.5M39.5 8.5H41"/><rect x="16" y="18" width="20" height="4" rx="2"/><rect x="16" y="26" width="24" height="4" rx="2"/><rect x="16" y="34" width="18" height="4" rx="2"/><rect x="16" y="42" width="22" height="4" rx="2"/></svg>',
  # 2 complete profile: profile sheet + pen
  f'<svg {_S}><path d="M38 24V8a3 3 0 0 0-3-3H9a3 3 0 0 0-3 3v40a3 3 0 0 0 3 3h26a3 3 0 0 0 3-3v-6"/><circle cx="22" cy="16" r="6"/><path d="M14 27c1.6-3 4.6-4.5 8-4.5s6.4 1.5 8 4.5M12 33h3M18 33h12M12 39h3M18 39h9M12 45h3M18 45h7"/><path d="M47 19l4 4-14 15-6 2 2-6z"/><path d="M44 22l4 4"/></svg>',
  # 3 find the right job: JOB sheet + magnifier
  f'<svg {_S}><path d="M34 26V7a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v40a2 2 0 0 0 2 2h18"/><path d="M11 10v6a2 2 0 0 1-4 0" transform="translate(2 0)"/><path d="M17 10.5a3 3 0 1 1 0 5 3 3 0 0 1 0-5z"/><path d="M24 10h3a1.6 1.6 0 0 1 0 3.2H24zM24 13.2h3.4a1.6 1.6 0 0 1 0 3.2H24z"/><path d="M10 22h18M10 27h13M10 32h10M10 37h8"/><circle cx="36" cy="38" r="9"/><path d="M36 33v5l3 2M42.5 44.5 50 52"/></svg>',
  # 4 apply: laptop + profile + tick
  f'<svg {_S}><path d="M10 40V15a2 2 0 0 1 2-2h22M44 26v14"/><path d="M4 40h48v3a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3z"/><rect x="16" y="18" width="22" height="18" rx="1.5"/><circle cx="27" cy="24.5" r="3"/><path d="M21 33c1.2-2.3 3.4-3.5 6-3.5s4.8 1.2 6 3.5"/><circle cx="44" cy="13" r="8"/><path d="M40.5 13.2l2.4 2.4 4.6-5"/></svg>',
]
STEPS = [("Create an account","Sign up free in under a minute with your email or mobile number."),
         ("Complete your profile","Add your experience and skills to raise your Surch Score."),
         ("Find the right job","Get matched to roles that fit your skills, location and pay."),
         ("Apply in one tap","Send your profile straight to the employer and track every step.")]
TESTIS = [
  ("Jamie T.","Recent Graduate","Surch changed the way I approached my job hunt right out of university. The Surch Score helped me understand what employers are looking for and how to make my profile stand out. Thanks to Surch, I landed interviews at companies I once thought were out of my reach!"),
  ("Alex R.","Experienced IT Professional","Using Surch was a breath of fresh air! The platform not only helped me find jobs that matched my skills perfectly but also made the application process so much smoother. The direct contact with employers via in app messaging accelerated the hiring process and I secured a fantastic position in no time."),
]


# ---------- auth pieces ----------
I = {
 "mail":'<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M4 4.5h16A2.5 2.5 0 0 1 22.5 7v10a2.5 2.5 0 0 1-2.5 2.5H4A2.5 2.5 0 0 1 1.5 17V7A2.5 2.5 0 0 1 4 4.5zm.6 2.3 7.4 5.4 7.4-5.4z"/></svg>',
 "lock":'<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 1.8a5 5 0 0 1 5 5V9h.5A2.5 2.5 0 0 1 20 11.5v8a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 4 19.5v-8A2.5 2.5 0 0 1 6.5 9H7V6.8a5 5 0 0 1 5-5zm0 2.2a2.8 2.8 0 0 0-2.8 2.8V9h5.6V6.8A2.8 2.8 0 0 0 12 4z"/></svg>',
 "user":'<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="12" cy="7.5" r="4.5"/><path d="M3.5 21c.6-4.4 4.1-7.5 8.5-7.5s7.9 3.1 8.5 7.5z"/></svg>',
 "phone":'<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M6.6 2.5c.6-.2 1.3.1 1.6.7l1.9 3.7c.3.6.2 1.3-.3 1.7L8.2 10a12.5 12.5 0 0 0 5.8 5.8l1.4-1.6c.4-.5 1.1-.6 1.7-.3l3.7 1.9c.6.3.9 1 .7 1.6l-.8 2.6c-.3.9-1.1 1.5-2 1.5C10 21.5 2.5 14 2.5 5.4c0-.9.6-1.7 1.5-2z"/></svg>',
 "back":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M11 6l-6 6 6 6"/></svg>',
 "tick":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12.5l4.2 4.2L18.5 8"/></svg>',
 "key":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="8" cy="15" r="4.5"/><path d="M11.2 11.8 20 3M16.5 6.5l2.5 2.5M14 9l2 2"/></svg>',
 "msg":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="6" y="2" width="12" height="20" rx="2.5"/><path d="M10.5 18.5h3M9 8.5h6M9 11.5h4"/></svg>',
 "chev":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 10l5 5 5-5"/></svg>',
}
EYE_OFF = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.6 5.1A10.8 10.8 0 0 1 12 5c6.4 0 10 7 10 7a17 17 0 0 1-3.2 4.1M6.6 6.6A17 17 0 0 0 2 12s3.6 7 10 7a9.6 9.6 0 0 0 5.4-1.6"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2M3 3l18 18"/></svg>'
EYE = f'<button type="button" class="lp-eye" data-eye aria-label="Show password" aria-pressed="false">{EYE_OFF}</button>'
UK = '<svg class="cd-flag" viewBox="0 0 60 60" aria-hidden="true"><g><path fill="#012169" d="M-15 0h90v60h-90z"/><path stroke="#fff" stroke-width="12" d="M-15 0l90 60M75 0l-90 60"/><path stroke="#C8102E" stroke-width="5" d="M-15 0l90 60M75 0l-90 60"/><path stroke="#fff" stroke-width="18" d="M30 0v60M-15 30h90"/><path stroke="#C8102E" stroke-width="10" d="M30 0v60M-15 30h90"/></g></svg>'
def cc(k):
    return (f'<button type="button" class="cd-cc" data-cc aria-haspopup="listbox" aria-expanded="false" aria-label="Country code: United Kingdom +44">'
            f'<span class="cd-cc-f">{UK}</span><span class="cd-cc-d" hidden></span></button>')
SOCIALS = [("Facebook",'<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="11" fill="#1877F2"/><path fill="#fff" d="M13.4 22.9v-7.6h2.5l.4-3h-2.9v-1.9c0-.8.3-1.5 1.5-1.5h1.5V6.3c-.3 0-1.2-.1-2.2-.1-2.2 0-3.7 1.3-3.7 3.8v2.3H8v3h2.5v7.6z"/></svg>'),
           ("LinkedIn",'<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#0A66C2" d="M3.4 8.6h3.9V21H3.4zM5.3 2.5a2.3 2.3 0 1 1 0 4.5 2.3 2.3 0 0 1 0-4.5zM9.7 8.6h3.7v1.7h.1c.5-1 1.8-2 3.7-2 3.9 0 4.6 2.6 4.6 5.9V21h-3.9v-6c0-1.4 0-3.3-2-3.3s-2.3 1.6-2.3 3.2V21H9.7z"/></svg>'),
           ("Google",'<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#4285F4" d="M22.6 12.2c0-.8-.1-1.5-.2-2.2H12v4.2h5.9a5 5 0 0 1-2.2 3.3v2.7h3.6c2.1-1.9 3.3-4.8 3.3-8z"/><path fill="#34A853" d="M12 23c3 0 5.5-1 7.3-2.7l-3.6-2.8c-1 .7-2.2 1.1-3.7 1.1-2.9 0-5.3-1.9-6.2-4.5H2.1v2.8A11 11 0 0 0 12 23z"/><path fill="#138bed" d="M5.8 14.1a6.6 6.6 0 0 1 0-4.2V7.1H2.1a11 11 0 0 0 0 9.8z"/><path fill="#EA4335" d="M12 5.4c1.6 0 3.1.6 4.2 1.7l3.2-3.2A11 11 0 0 0 2.1 7.1l3.7 2.8C6.7 7.3 9.1 5.4 12 5.4z"/></svg>'),
           ("Apple",'<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#000" d="M16.4 1.4c0 1.1-.5 2.3-1.2 3.1-.7.9-2 1.6-3 1.6h-.3v-.4c0-1.1.6-2.3 1.2-3 .8-.9 2.1-1.6 3.2-1.7zm4.5 15.7c0 .1-.5 1.6-1.5 3.1-.9 1.3-1.9 2.7-3.4 2.7s-1.9-.9-3.6-.9-2.3.9-3.7.9-2.3-1.3-3.4-2.8c-1.3-1.8-2.3-4.6-2.3-7.3 0-4.3 2.8-6.5 5.5-6.5 1.4 0 2.7.9 3.6.9.9 0 2.2-1 3.9-1 .6 0 2.9.1 4.4 2.2-.1.1-2.4 1.4-2.4 4.2 0 3.3 2.9 4.4 2.9 4.5z"/></svg>')]
SOCIAL = '<div class="cd-social">' + "".join(f'<button type="button" data-social="{n}" aria-label="Continue with {n}">{svg}</button>' for n,svg in SOCIALS) + '</div>'
OTP = "".join(f'<input inputmode="numeric" maxlength="1" pattern="[0-9]*" autocomplete="{"one-time-code" if i==0 else "off"}" aria-label="Digit {i+1}">' for i in range(4))

SHOW = {
 "login": ("For job seekers", "Your next role is closer than you think.",
           ["New matches waiting, picked for your skills","Apply in one tap from your profile","Track every application in one place"],
           '<span class="cd-fc cd-fc-match"><i class="lg">N</i><span><b>New match · 94%</b><small>UI/UX Designer · Nomad · London</small></span></span>',
           '<span class="cd-fc cd-fc-chip"><i class="ok">'+'TICK'+'</i>Interview booked · Tue, 11:00 AM</span>'),
 "signup": ("Join Surch free", "Build a profile employers notice.",
           ["Free for job seekers, always","Raise your Surch Score as you complete your profile","Get matched to roles that fit your skills and location"],
           '<span class="cd-fc cd-fc-prog"><span><b>Profile strength</b><small>72% complete</small></span><span class="bar"><i></i></span></span>',
           '<span class="cd-fc cd-fc-chip"><i class="ok">'+'TICK'+'</i>3 employers viewed your profile</span>'),
}
def show(k, A):
    eyebrow, h, pts, card, chip = SHOW[k]
    tick = I["tick"]
    lis = "".join(f'<li>{tick}{html.escape(t)}</li>' for t in pts)
    ring = ('<span class="cd-fc cd-fc-score"><svg viewBox="0 0 44 44" aria-hidden="true"><circle cx="22" cy="22" r="18" fill="none" stroke="#efe9f6" stroke-width="5"/>'
            '<circle cx="22" cy="22" r="18" fill="none" stroke="url(#cdSg_'+k+')" stroke-width="5" stroke-linecap="round" stroke-dasharray="68 113" transform="rotate(-90 22 22)"/>'
            '<defs><linearGradient id="cdSg_'+k+'" x1="0" x2="1"><stop offset="0" stop-color="#2594ef"/><stop offset="1" stop-color="#a35cf5"/></linearGradient></defs></svg>'
            '<span><b>599</b><small>Surch Score</small></span></span>')
    return (f'<aside class="cd-show"><div class="cd-show-top"><span class="cd-eyebrow">{eyebrow}</span><h2>{html.escape(h)}</h2><ul>{lis}</ul></div>'
            f'<div class="cd-show-art" aria-hidden="true"><span class="cd-sun"></span><img src="{A("assets/c/hero-cut.webp")}" alt="" width="355" height="408">'
            f'{ring}{card.replace("TICK", tick)}{chip.replace("TICK", tick)}</div></aside>')

def auth(A):
    m = rd(os.path.join(SRC, "auth.html"))
    m = re.sub(r"\{\{SHOW:(\w+)\}\}", lambda x: show(x.group(1), A), m)
    m = m.replace("{{SOCIAL}}", SOCIAL).replace("{{EYE}}", EYE).replace("{{OTP}}", OTP)
    m = re.sub(r"\{\{CC:(\w+)\}\}", lambda x: cc(x.group(1)), m)
    m = re.sub(r"\{\{RULES:(\w+)\}\}", lambda x: f'<ul class="cd-rules" id="{x.group(1)}" aria-live="polite"><li data-r="len">{I["tick"]}At least 8 characters</li><li data-r="num">{I["tick"]}Includes a number</li><li data-r="case">{I["tick"]}Upper and lower case letters</li></ul>', m)
    m = re.sub(r"\{\{I:(\w+)\}\}", lambda x: I[x.group(1)], m)
    return m

_O='viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"'
OI = {
 "x":f'<svg {_O}><path d="M6 6l12 12M18 6 6 18"/></svg>',
 "arrow":f'<svg class="ob-arr" {_O}><path d="M5 12h14M13 6l6 6-6 6"/></svg>',
 "search":f'<svg {_O}><circle cx="10.5" cy="10.5" r="6.5"/><path d="M20 20l-4.6-4.6M8 10.5h5M10.5 8v5"/></svg>',
 "team":f'<svg {_O}><circle cx="9" cy="8" r="3.2"/><path d="M3 19c.6-3.3 3-5 6-5s5.4 1.7 6 5"/><circle cx="17" cy="9" r="2.6"/><path d="M16.5 14c2.4.2 4 1.7 4.5 4.5"/></svg>',
 "check":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12.5l4.2 4.2L18.5 8"/></svg>',
 "spark":'<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M10 3l1.7 5.3L17 10l-5.3 1.7L10 17l-1.7-5.3L3 10l5.3-1.7z"/><path d="M18 14l.9 2.1L21 17l-2.1.9L18 20l-.9-2.1L15 17l2.1-.9z"/></svg>',
 "mail":f'<svg {_O}><rect x="3" y="5" width="18" height="14" rx="2.5"/><path d="M4 7l8 6 8-6"/></svg>',
 "pen":f'<svg {_O}><path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13.5 6.5l4 4"/></svg>',
 "bell":f'<svg {_O}><path d="M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z"/><path d="M10 20.5a2.2 2.2 0 0 0 4 0"/></svg>',
 "upload":f'<svg {_O}><path d="M12 15V4M7.5 8.5 12 4l4.5 4.5M5 15v3a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3"/></svg>',
}
def onboard(A):
    m = rd(os.path.join(SRC, "onboard.html"))
    return re.sub(r"\{\{OI:(\w+)\}\}", lambda x: OI[x.group(1)], m)

_J='viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"'
JI = {
 "search":f'<svg {_J}><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/></svg>',
 "pin":f'<svg {_J}><path d="M12 21s-7-6.2-7-11.5a7 7 0 0 1 14 0C19 14.8 12 21 12 21z"/><circle cx="12" cy="9.5" r="2.5"/></svg>',
 "x":f'<svg {_J}><path d="M6 6l12 12M18 6 6 18"/></svg>',
 "sliders":f'<svg {_J}><path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0"/><circle cx="16" cy="6" r="2"/><circle cx="10" cy="12" r="2"/><circle cx="18" cy="18" r="2"/></svg>',
 "bookmark":f'<svg {_J}><path d="M7 3.5h10a1 1 0 0 1 1 1V20l-6-3.8L6 20V4.5a1 1 0 0 1 1-1z"/></svg>',
 "back":f'<svg {_J}><path d="M19 12H5M11 6l-6 6 6 6"/></svg>',
 "chev":f'<svg class="jb-chev" {_J}><path d="M6 15l6-6 6 6"/></svg>',
 "heart":f'<svg {_J}><path d="M12 20s-7.5-4.6-9-9.3C2 7.4 4.2 4.5 7.3 4.5c2 0 3.5 1.1 4.7 2.7 1.2-1.6 2.7-2.7 4.7-2.7 3.1 0 5.3 2.9 4.3 6.2C19.5 15.4 12 20 12 20z"/></svg>',
 "tick":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12.5l4.2 4.2L18.5 8"/></svg>',
}
FGROUPS = [
 ("type","Job Type",["Full Time","Part-time"]),
 ("emp","Employment Type",["Permanent","Temporary","Fixed term","Internship","Apprenticeship"]),
 ("arr","Work Arrangement",["Work from Home","Work from Office","Hybrid"]),
 ("SALARY","Salary",[]),
 ("SKILLS","Desirable Skills",[]),
 ("exp","Work Experience",["No Experience","1-3 Years","3-5 Years","5-8 Years","8-10 Years","10+ Years"]),
 ("shift","Working Shift",["Morning Shift","General Shift","Evening Shift","Night Shift","Rotational Shift"]),
]
def filters():
    out=[]
    for k,(key,label,opts) in enumerate(FGROUPS):
        gid=f"jbG{k}"
        if key=="SALARY":
            body=('<div class="cd-seg jb-per" role="group" aria-label="Pay period"><button type="button" data-per="hour" aria-pressed="false">Hourly</button><button type="button" data-per="year" aria-pressed="true">Yearly</button></div>'
                  '<label class="jb-range"><span class="lp-sr">Minimum pay</span><input type="range" id="jbSal" min="0" max="100000" step="5000" value="0"></label>'
                  '<div class="jb-rl"><span id="jbSalMin">Any</span><span id="jbSalMax">£100k+</span></div>'
                  '<p class="jb-salv" id="jbSalV" aria-live="polite">Any salary</p>')
        elif key=="SKILLS":
            body=('<div class="lp-ain jb-skin">'+JI["search"]+'<input id="jbSkill" type="text" placeholder="Add a skill, e.g. Figma" list="jbSkillList" autocomplete="off" aria-describedby="jbSkillH"><datalist id="jbSkillList"></datalist></div>'
                  '<p class="jb-hint" id="jbSkillH">Press Enter to add. Jobs matching any skill are shown.</p><div class="jb-skills" id="jbSkills"></div>')
        else:
            body="".join(f'<label class="jb-chk"><span>{html.escape(o)}</span><input type="checkbox" data-fk="{key}" value="{html.escape(o)}"><span class="jb-box" aria-hidden="true">{JI["tick"]}</span></label>' for o in opts)
        out.append(f'<div class="jb-fg"><h3><button type="button" aria-expanded="true" aria-controls="{gid}">{label}{JI["chev"]}</button></h3><div class="jb-fgb" id="{gid}">{body}</div></div>')
    return "".join(out)
def jobs_html(A):
    m = rd(os.path.join(SRC, "jobs.html")).replace("{{FILTERS}}", filters())
    return re.sub(r"\{\{JI:(\w+)\}\}", lambda x: JI[x.group(1)], m)

TIPS = [
 ("profile","Profile Writing Tips","Stand Out with a Strong Candidate Profile",[
   ("Complete every section","A fully completed profile raises your Surch Score and makes you more visible to employers."),
   ("Be specific and results-focused","Rather than just listing duties, describe what you achieved."),
   ("Use keywords naturally","Include the skills and job titles employers in your industry search for."),
   ("Write a strong personal summary","Think of it as your elevator pitch: who you are and what you’re great at."),
   ("Keep it up to date","Small, regular updates help keep your Surch Score high.")]),
 ("cover","Cover Letter Advice","Make a Memorable First Impression",[
   ("Tailor it to each job","Mention the specific role and company by name."),
   ("Hook them early","Open with a strong, relevant first line."),
   ("Tell your story","Share experiences that match what the job needs."),
   ("Keep it brief and focused","Three or four concise paragraphs is plenty."),
   ("Format it professionally","Use a clean layout, and proofread before you send.")]),
 ("interview","Virtual Interview Tips","Nail Your Online Interviews",[
   ("Test your setup","Check your camera, microphone, internet and lighting beforehand."),
   ("Choose a neutral background","Keep distractions to a minimum."),
   ("Dress the part","Looking professional helps you feel confident."),
   ("Make eye contact","Look at the camera, not the screen, when you speak."),
   ("Have notes, but don’t read","Keep a few prompts nearby and speak naturally.")]),
 ("search","Job Search Strategies","Be Smarter, Not Just Busier",[
   ("Set clear goals","Know which roles, locations and salary you’re aiming for."),
   ("Use filters and Surch Alerts","Get notified as soon as relevant jobs are posted."),
   ("Track your applications","Keep a record so you know when to follow up."),
   ("Stay active","Logging in and applying regularly boosts your visibility."),
   ("Network online","Personal connections can open doors that adverts don’t.")]),
 ("etiquette","Professional Etiquette","Build a Reputation That Gets You Hired",[
   ("Be responsive","Replying promptly shows professionalism."),
   ("Follow instructions","Always meet the application requirements."),
   ("Say thank you","A short follow-up after an interview leaves a good impression."),
   ("Mind your social media","Keep your public profiles clean and professional.")]),
 ("growth","Career Growth & Development","Stay Ready, Always",[
   ("Keep learning","Take courses and earn certifications in your field."),
   ("Ask for feedback","Use it to improve your next application or interview."),
   ("Update your profile regularly","Add new skills and achievements as you gain them."),
   ("Follow industry trends","Stay aware of what’s changing so you remain competitive.")]),
]
TIP_SUM = {
 "profile":"Make every section count and keep your Surch Score climbing.",
 "cover":"Short, tailored letters that get you remembered for the right reasons.",
 "interview":"Set up, look sharp and come across confidently on camera.",
 "search":"Spend your time on the roles that fit, and follow up at the right moment.",
 "etiquette":"Small habits that make employers want to work with you.",
 "growth":"Keep learning and keep your profile ready for the next step.",
}
def tips_html(A):
    tick='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12.5l4.2 4.2L18.5 8"/></svg>'
    arrow='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>'
    back='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M11 6l-6 6 6 6"/></svg>'
    total=sum(len(t[3]) for t in TIPS)
    cards=[];navs=[];arts=[]
    for i,(k,t,sub,items) in enumerate(TIPS):
        mins=max(1,round(sum(len(a)+len(b) for a,b in items)/900*2))
        img=A(f"assets/tips/tip-{i+1}.webp")
        cards.append(f'<li class="tg-card"><a href="#/tips/{k}" data-route="tips/{k}" class="tg-link"><span class="tg-img"><img src="{img}" alt="" loading="lazy"></span>'
                     f'<span class="tg-body"><span class="tg-kick">Guide {i+1:02d}</span><b class="tg-t">{html.escape(t)}</b><span class="tg-s">{html.escape(TIP_SUM[k])}</span>'
                     f'<span class="tg-meta"><span>{len(items)} tips · {mins} min read</span><span class="tg-prog" data-prog="{k}" aria-hidden="true"><i></i></span></span>'
                     f'<span class="tg-go">Read guide{arrow}</span></span></a></li>')
        navs.append(f'<li><a href="#/tips/{k}" data-route="tips/{k}" data-tnav="{k}"><span class="tn-n">{i+1:02d}</span><span class="tn-t">{html.escape(t)}</span><span class="tn-c" data-count="{k}">0/{len(items)}</span></a></li>')
        tips="".join(f'<li class="tr-tip" data-tip="{k}-{n}"><span class="tr-n" aria-hidden="true">{n+1:02d}</span><div><h3>{html.escape(a)}</h3><p>{html.escape(b)}</p></div>'
                     f'<button type="button" class="tr-done" data-done="{k}-{n}" aria-pressed="false" aria-label="Mark “{html.escape(a)}” as done">{tick}<span>Done</span></button></li>' for n,(a,b) in enumerate(items))
        prev=TIPS[i-1] if i>0 else None;nxt=TIPS[i+1] if i<len(TIPS)-1 else None
        pn=(f'<a href="#/tips/{prev[0]}" data-route="tips/{prev[0]}" class="tr-pn">{back}<span><small>Previous guide</small>{html.escape(prev[1])}</span></a>' if prev else '<span></span>')+\
           (f'<a href="#/tips/{nxt[0]}" data-route="tips/{nxt[0]}" class="tr-pn nx"><span><small>Next guide</small>{html.escape(nxt[1])}</span>{arrow}</a>' if nxt else f'<a href="#/jobs" data-route="jobs" class="tr-pn nx"><span><small>You’ve read every guide</small>Put it into practice: find jobs</span>{arrow}</a>')
        arts.append(f'<article class="tr-art" data-guide="{k}" aria-labelledby="trT{i}" hidden><header class="tr-head"><div class="tr-hc"><span class="tg-kick">Guide {i+1:02d} of {len(TIPS)}</span><h2 id="trT{i}" tabindex="-1">{html.escape(t)}</h2><p>{html.escape(sub)}</p>'
                    f'<div class="tr-bar"><span class="tr-bt" data-bt="{k}">0 of {len(items)} done</span><span class="tg-prog lg" data-prog="{k}"><i></i></span></div></div><figure class="tr-img"><img src="{img}" alt=""></figure></header>'
                    f'<ol class="tr-tips">{tips}</ol><nav class="tr-pns" aria-label="More guides">{pn}</nav></article>')
    return (f'<div class="cv" data-cv="tips" id="tpPage">'
      f'<section class="tg-hero" aria-labelledby="tpT"><div class="lp-wrap tg-hero-in"><div class="tg-hero-c"><span class="cd-eyebrow tg-eb">Career Tips</span><h1 id="tpT" tabindex="-1">Advice that helps you <span class="or">get hired</span></h1>'
      f'<p>Short, practical guides from the Surch team. Read one in a couple of minutes and tick off each tip as you put it into practice.</p>'
      f'<ul class="tg-stats"><li><b>{len(TIPS)}</b>guides</li><li><b>{total}</b>practical tips</li><li><b data-done-total>0</b>done by you</li></ul></div>'
      f'<a href="#/tips/{TIPS[0][0]}" data-route="tips/{TIPS[0][0]}" class="tg-feat"><img src="{A("assets/tips/tip-1.webp")}" alt=""><span class="tg-feat-b"><span class="tg-kick">Start here</span><b>{html.escape(TIPS[0][1])}</b><span class="tg-go">Read guide{arrow}</span></span></a></div></section>'
      f'<div class="tg-hub" id="tgHub"><section class="lp-wrap tg-grid-wrap" aria-labelledby="tgGT"><div class="tg-ghead"><h2 id="tgGT">All guides</h2><p>Pick a topic to get started.</p></div><ul class="tg-grid">{"".join(cards)}</ul></section></div>'
      f'<div class="tg-reader lp-wrap" id="tgReader" hidden><aside class="tr-side"><a href="#/tips" data-route="tips" class="tr-all">{back}All guides</a><p class="tr-st">Your progress</p><div class="tr-ov"><span class="tg-prog lg" data-prog="__all"><i></i></span><span data-all-count>0 of {total} tips</span></div><ol class="tr-nav">{"".join(navs)}</ol></aside>'
      f'<div class="tr-main">{"".join(arts)}</div></div>'
      f'<section class="lp-wrap tp-cta-wrap"><div class="tp-cta"><div><h2>Ready to put these tips into practice?</h2><p data-tp-guest>Create your free Surch account, build your profile and get matched to the right jobs.</p><p data-tp-user hidden>Keep your profile fresh and check out the latest jobs matched to you.</p></div>'
      f'<div class="tp-cta-btns"><a href="#/signup" class="lp-btn lp-btn-or" data-route="signup" data-tp-guest>Create free account</a><a href="#/jobs" class="lp-btn tp-ghost" data-route="jobs">Browse jobs</a></div></div></section></div>')

def profile_html(A):
    return rd(os.path.join(SRC, "profile.html"))

def companies_html(A):
    m = rd(os.path.join(SRC, "companies.html"))
    return re.sub(r"\{\{JI:(\w+)\}\}", lambda x: JI[x.group(1)], m)


# ---------- hero product showcase (devices) ----------
SI = {
 "home":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 11l8-7 8 7v9H4z"/></svg>',
 "search":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/></svg>',
 "users":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="8" r="3.2"/><path d="M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"/><circle cx="17" cy="9" r="2.5"/><path d="M16.5 14.2c2.6.3 4.5 2.6 4.5 5.8"/></svg>',
 "clip":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="5" y="4" width="14" height="17" rx="2"/><path d="M9 4h6v3H9zM9 11h6M9 15h4"/></svg>',
 "user":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8"/></svg>',
 "msg":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5h16v11H9l-5 4z"/></svg>',
 "cal":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><rect x="4" y="5" width="16" height="15" rx="2"/><path d="M4 10h16M9 3v4M15 3v4"/></svg>',
 "chart":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M5 20V10M10 20V4M15 20v-7M20 20v-4"/></svg>',
 "gear":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/></svg>',
 "collapse":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 5v14M20 12H10M14 8l-4 4 4 4"/></svg>',
 "bell":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 16V11a6 6 0 0 1 12 0v5l2 2H4z"/><path d="M10 20a2 2 0 0 0 4 0"/></svg>',
 "brief":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="3" y="7" width="18" height="13" rx="2"/><path d="M9 7V5h6v2M3 12h18"/></svg>',
 "monitor":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8M12 16v4"/></svg>',
 "plus":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>',
 "tick":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>',
 "back":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M11 6l-6 6 6 6"/></svg>',
 "close":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>',
 "heart":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><path d="M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z"/></svg>',
 "pin":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 21s-7-6.2-7-11.5a7 7 0 0 1 14 0C19 14.8 12 21 12 21z"/><circle cx="12" cy="9.5" r="2.5"/></svg>',
 "up":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4M7 9l5-5 5 5M4 20h16"/></svg>',
 "file":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5"/></svg>',
 "signal":'<svg viewBox="0 0 40 12" fill="currentColor"><rect x="0" y="8" width="3" height="4" rx="1"/><rect x="5" y="6" width="3" height="6" rx="1"/><rect x="10" y="3" width="3" height="9" rx="1"/><rect x="15" y="0" width="3" height="12" rx="1"/><rect x="24" y="1" width="14" height="10" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.4"/><rect x="26" y="3" width="9" height="6" rx="1"/></svg>',
 "moon":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg>',
 "cash":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="3" y="6" width="18" height="12" rx="2"/><path d="M3 10h18"/></svg>',
 "star":'<svg viewBox="0 0 24 24" fill="#2594ef"><path d="M12 3l2.7 5.6 6.1.8-4.5 4.2 1.1 6.1L12 16.8 6.6 19.7l1.1-6.1L3.2 9.4l6.1-.8z"/></svg>',
 "staro":'<svg viewBox="0 0 24 24" fill="none" stroke="#2594ef" stroke-width="1.8" stroke-linejoin="round"><path d="M12 3l2.7 5.6 6.1.8-4.5 4.2 1.1 6.1L12 16.8 6.6 19.7l1.1-6.1L3.2 9.4l6.1-.8z"/></svg>',
 "bag":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="3" y="7" width="18" height="13" rx="2"/><path d="M9 7V5h6v2"/></svg>',
 "house":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><path d="M4 11l8-7 8 7M6 9.5V20h12V9.5"/></svg>',
 "menu":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M5 7h14M5 12h14M5 17h14"/></svg>',
 "save":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><path d="M7 4h10v16l-5-4-5 4z"/></svg>',
 "sliders":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M4 7h10M18 7h2M4 17h4M12 17h8"/><circle cx="16" cy="7" r="2"/><circle cx="10" cy="17" r="2"/></svg>',
 "vsl":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 4v16M12 4v16M18 4v16"/><path d="M4 9h4M10 15h4M16 8h4"/></svg>',
 "dots":'<svg viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="19" cy="12" r="1.8"/></svg>',
 "vdots":'<svg viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="5" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="12" cy="19" r="1.8"/></svg>',
 "gift":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="4" y="9" width="16" height="11" rx="1"/><path d="M3 9h18v3H3zM12 9v11M12 9S10 4 7.5 5.5 9 9 12 9zm0 0s2-5 4.5-3.5S15 9 12 9z"/></svg>',
 "doc":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="5" y="4" width="14" height="17" rx="2"/><path d="M9 3h6v3H9zM9 11h2M13 11h2M9 15h2M13 15h2"/></svg>',
 "info":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="9"/><path d="M12 8h.01M11 12h1v4h1"/></svg>',
 "chat":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><path d="M9 14a6 6 0 1 1 5-5.9M3 21l1.5-2A6 6 0 1 1 15 15"/></svg>',
 "group":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="8" r="2.6"/><circle cx="5.5" cy="10" r="2"/><circle cx="18.5" cy="10" r="2"/><path d="M7.5 18a4.5 4.5 0 0 1 9 0M2.5 18a3 3 0 0 1 4-2.8M21.5 18a3 3 0 0 0-4-2.8"/></svg>',
 "clock":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/></svg>',
 "chev":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>',
 "arrowr":'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>',
 "nomad":'<svg viewBox="0 0 48 48"><path d="M24 2l19 11v22L24 46 5 35V13z" fill="#2fb98f"/><path d="M24 2l19 11v22L24 24z" fill="#1f8f8a"/><path d="M15 33V16l18 17V16" fill="none" stroke="#fff" stroke-width="4.2" stroke-linejoin="round" stroke-linecap="round"/></svg>',
}
INI_COL = {"ST":"#2e7d5b","MI":"#a8386a"}
def showcase_card(spec):
    photo, name, date, score = spec.split("|")
    av = (f'<span class="ini" style="background:{INI_COL.get(photo,"#151515")}">{photo}</span>' if photo.isupper()
          else f'<img src="{{{{A:assets/c/av-{photo}.webp}}}}" alt="">')
    star = SI["staro"] if int(score) < 800 else SI["star"]
    sc = f'{score}/999' if int(score) < 800 else f'<em>{score}</em>/999'
    return (f'<div class="dv-card2" data-p="{photo}"><i class="dv-kb">{SI["vdots"]}</i>{av}<div class="dv-cn"><b>{name}</b><a>View Profile</a></div><span class="dv-cbx"></span>'
            f'<div class="dv-meta"><span>Applied on<b>{date}</b></span><span>Score<b>{star}{sc}</b></span></div></div>')
def showcase_html():
    m = rd(os.path.join(SRC, "showcase.html"))
    m = re.sub(r"\{\{SI:(\w+)\}\}", lambda x: SI[x.group(1)], m)
    m = re.sub(r"\{\{CARD:([^}]+)\}\}", lambda x: showcase_card(x.group(1)), m)
    return m

def blocks(A):
    logos = "".join(f'<span class="lp-pill{" t" if t else ""}"><img src="{A("assets/logos/"+f+".png")}" alt="{html.escape(n)}" loading="lazy"></span>' for f,n,t in LOGOS)
    steps = "".join(f'<li class="cd-step">{ICONS[i]}<span class="n" aria-hidden="true">{i+1:02d}.</span><div><h3><span class="lp-sr">Step {i+1}: </span>{html.escape(t)}</h3><p>{html.escape(d)}</p></div></li>' for i,(t,d) in enumerate(STEPS))
    testis = "".join(f'<article class="lp-tcard"><h3>{html.escape(n)}</h3><p class="r">{html.escape(r)}</p><div class="lp-stars" role="img" aria-label="5 out of 5 stars">{STAR*5}</div><p>{html.escape(q)}</p></article>' for n,r,q in TESTIS)
    store = (f'<a href="#" class="lp-store" data-soon="The App Store listing">{APPLE}<span><small>Download on the</small><b>App Store</b></span></a>'
             f'<a href="#" class="lp-store" data-soon="The Google Play listing">{PLAY}<span><small>GET IT ON</small><b>Google Play</b></span></a>')
    store_sm = (f'<a href="#" class="lp-store" data-soon="The Google Play listing">{PLAY}<span><small>GET IT ON</small><b>Google Play</b></span></a>'
                f'<a href="#" class="lp-store" data-soon="The App Store listing">{APPLE}<span><small>Download on the</small><b>App Store</b></span></a>')
    return {"SHOWCASE": showcase_html(), "DASH": rd(os.path.join(SRC, "dash.html")), "MSGS": rd(os.path.join(SRC, "messages.html")), "PROFILE": profile_html(A), "COMPANIES": companies_html(A), "TIPS": tips_html(A), "JOBS": jobs_html(A), "ONBOARD": onboard(A), "AUTH": auth(A), "LOGOS": logos, "STEPS": steps, "TESTIS": testis, "STORES": store, "STORES_SM": store_sm}

def render(A):
    m = rd(os.path.join(SRC, "candidate.html"))
    for k,v in blocks(A).items(): m = m.replace("{{"+k+"}}", v)
    m = re.sub(r"\{\{A:([^}]+)\}\}", lambda x: A(x.group(1)), m)
    assert "{{" not in m, re.findall(r"\{\{[^}]+\}\}", m)
    return m

FONT = ('<link rel="preconnect" href="https://fonts.googleapis.com">\n<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>\n'
        '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700;12..96,800&display=swap">')
TITLE = "Surch – Find your next job"
DESC = "Find your dream job with Surch: AI-enhanced job search, the Surch Score and one-tap applications."
def page(head, body, tail):
    return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{TITLE}</title>
<meta name="description" content="{DESC}">
{FONT}
{head}
</head>
<body style="margin:0">
{body}
{tail}
</body>
</html>
"""

# 1. separate files
os.makedirs(os.path.join(ROOT,"css"), exist_ok=True); os.makedirs(os.path.join(ROOT,"js"), exist_ok=True)
shutil.copy(SHARED_CSS, os.path.join(ROOT,"css","landing.css"))
shutil.copy(os.path.join(SRC,"candidate.css"), os.path.join(ROOT,"css","candidate.css"))
shutil.copy(os.path.join(SRC,"candidate.js"), os.path.join(ROOT,"js","candidate.js"))
shutil.copy(os.path.join(SRC,"auth.js"), os.path.join(ROOT,"js","auth.js"))
shutil.copy(os.path.join(SRC,"onboard.js"), os.path.join(ROOT,"js","onboard.js"))
shutil.copy(os.path.join(SRC,"jobs.js"), os.path.join(ROOT,"js","jobs.js"))
shutil.copy(os.path.join(SRC,"companies.js"), os.path.join(ROOT,"js","companies.js"))
shutil.copy(os.path.join(SRC,"profile.js"), os.path.join(ROOT,"js","profile.js"))
shutil.copy(os.path.join(SRC,"dash.js"), os.path.join(ROOT,"js","dash.js"))
shutil.copy(BRIDGE, os.path.join(ROOT,"js","bridge.js"))
shutil.copy(MOTION_JS, os.path.join(ROOT,"js","motion.js"))
shutil.copy(MOTION_CSS, os.path.join(ROOT,"css","motion.css"))
shutil.copy(os.path.join(SRC,"motion-c.js"), os.path.join(ROOT,"js","motion-c.js"))
shutil.copy(os.path.join(SRC,"assist-c.js"), os.path.join(ROOT,"js","assist-c.js"))
shutil.copy(os.path.join(SRC,"showcase.js"), os.path.join(ROOT,"js","showcase.js"))
shutil.copy(os.path.join(SRC,"messages.js"), os.path.join(ROOT,"js","messages.js"))
shutil.copy(os.path.join(SRC,"info.js"), os.path.join(ROOT,"js","info.js"))
open(os.path.join(ROOT,"index.html"),"w",encoding="utf-8").write(page(
    '<link rel="icon" href="assets/surch-logo.png">\n<link rel="stylesheet" href="css/motion.css">\n<link rel="stylesheet" href="css/landing.css">\n<link rel="stylesheet" href="css/candidate.css">',
    render(lambda p: p), '<script src="js/bridge.js"></script>\n<script src="js/motion.js"></script>\n<script src="js/candidate.js"></script>\n<script src="js/onboard.js"></script>\n<script src="js/jobs.js"></script>\n<script src="js/companies.js"></script>\n<script src="js/profile.js"></script>\n<script src="js/dash.js"></script>\n<script src="js/messages.js"></script>\n<script src="js/info.js"></script>\n<script src="js/auth.js"></script>\n<script src="js/motion-c.js"></script>\n<script src="js/assist-c.js"></script>\n<script src="js/showcase.js"></script>'))

# 2. single file
cache = {}
def A_inline(p):
    if p not in cache:
        f = os.path.join(ROOT, p); mt = "image/svg+xml" if p.endswith(".svg") else (mimetypes.guess_type(f)[0] or "image/webp")
        cache[p] = f"data:{mt};base64," + base64.b64encode(open(f,"rb").read()).decode()
    return cache[p]
body = render(A_inline)
open(os.path.join(ROOT,"preview.html"),"w",encoding="utf-8").write(page(
    "<style>\n" + rd(MOTION_CSS) + "\n" + rd(SHARED_CSS) + "\n" + rd(os.path.join(SRC,"candidate.css")) + "\n</style>",
    body, "<script>\n" + rd(BRIDGE) + "\n" + rd(MOTION_JS) + "\n" + rd(os.path.join(SRC,"candidate.js")) + "\n" + rd(os.path.join(SRC,"onboard.js")) + "\n" + rd(os.path.join(SRC,"jobs.js")) + "\n" + rd(os.path.join(SRC,"companies.js")) + "\n" + rd(os.path.join(SRC,"profile.js")) + "\n" + rd(os.path.join(SRC,"dash.js")) + "\n" + rd(os.path.join(SRC,"messages.js")) + "\n" + rd(os.path.join(SRC,"info.js")) + "\n" + rd(os.path.join(SRC,"auth.js")) + "\n" + rd(os.path.join(SRC,"motion-c.js")) + "\n" + rd(os.path.join(SRC,"assist-c.js")) + "\n" + rd(os.path.join(SRC,"showcase.js")) + "\n</script>"))
print("built index.html + preview.html", round(os.path.getsize(os.path.join(ROOT,"preview.html"))/1024), "KB")
