#!/usr/bin/env python3
# ---------------------------------------------------------------------------
# hero-inner.html — INNER SERVICE hero, ROUND 2.
#
# Adi picked A1 (2026-08-30) and asked for four changes:
#   1. .tp:after — drop the diagonal wedge; a straight edge is enough.
#   2. .in — the type was cramped, with nothing above or below it.
#   3. .ph — the photograph is too small; take the room from .cp.
#   4. .cp — carry the SAME content as home_v1's .call, not a bespoke block.
#
# Everything else about A1 is unchanged: the three panels of the reference,
# the breadcrumb on a white strip above the band, the fixed hexagon.
#
# The shared CSS (base, page-head, header stand-in, hexagon, breadcrumb,
# title) is LIFTED at build time from round 1's generator rather than copied,
# so the two rounds cannot drift apart. The old bespoke .cc contact block is
# cut out on the way through — round 2 uses home_v1's .call instead.
# ---------------------------------------------------------------------------
import io, sys, os

OUT   = "/srv/apps/leaguelaw/wp-content/prototype/hero-inner.html"
R1GEN = "/srv/apps/leaguelaw/prototyping/gen_heroinner.py"

PHOTO = "/wp-content/uploads/passengerclaim.png"   # 1688x1125, monochrome
TEL   = "tel:+12508880002"


# --- lift the shared CSS out of round 1 ------------------------------------
def lift_shared_css():
    src = io.open(R1GEN, encoding="utf-8").read()
    i = src.find('CSS = r"""')
    assert i >= 0, "round 1 generator has no CSS block"
    i += len('CSS = r"""')
    j = src.find("  /* ---------- A1", i)
    assert j > i, "could not find the end of the shared CSS"
    css = src[i:j]
    # cut the round-1 bespoke contact block; round 2 uses home_v1's .call
    a = css.find("  /* contact block")
    b = css.find("  .phtag {")
    assert 0 < a < b, "could not find the .cc block to remove"
    css = css[:a] + css[b:]
    assert ".hex { aspect-ratio:.8660254;" in css, "hexagon rule did not survive the lift"
    assert ".cc " not in css, ".cc rules survived the cut"
    return css


# --- round 2's own CSS ------------------------------------------------------
A1CSS = r"""
  /* =====================================================================
     A1 — round 2.
     min-height, not height: if the type ever grows the band grows with it
     instead of squeezing the content flat, which is what went wrong in
     round 1 (the type block measured 236px inside a 300px band with 76px
     of padding — 12px over, so the padding was eaten from both ends).
     ===================================================================== */
  .a1 .band { display:flex; min-height:380px; }

  /* padding-left resolves against the BAND (full width), so the type starts
     exactly on the container's left edge at any viewport */
  /* =====================================================================
     THE PANEL MODEL — the three panels close on the container exactly:
        380 (type) + 420 (photograph) + 480 (contact) = 1280
     and each one bleeds to its own edge of the screen on top of that.
     Round 1 got this wrong: .tp was a flat 520px while its left padding grew
     with the viewport, so the TYPE COLUMN SHRANK as the screen got wider —
     416px at 1380, 153px at 1920, where the title wrapped to four lines and
     pushed the band to 399px. Adding the gutter to the WIDTH as well as the
     padding holds the column at 416px at every width.
     ===================================================================== */
  .a1 .tp { width:calc((100% - 1280px)/2 + 380px); flex:none;
            background:var(--orange); color:#fff;
            padding:48px 44px 48px calc((100% - 1280px)/2);
            position:relative; display:flex; flex-direction:column; justify-content:center; }
  /* CHANGE 1 — the diagonal wedge is gone. The orange panel now meets the
     photograph on a straight vertical edge. (Round 1 pushed a 38px clipped
     triangle out over the picture; it needed z-index to paint at all, and it
     cut into the frame at exactly the height a face sits at.) */
  .a1 .tp .in { display:block; }
  .a1 .tp .htitle { font-size:38px; }
  .a1 .tp .hsub { font-size:20px; margin-top:14px; }
  .a1 .tp .hrule { margin:16px 0; width:110px; }
  .a1 .tp .hex { margin-bottom:18px; }

  /* CHANGE 3 — the photograph. 330x300 -> 400x380: +21% wide, +27% tall,
     +54% area. The room comes out of .cp, which no longer needs 430px of
     panel to itself now that its content is centred. */
  .a1 .ph { width:420px; flex:none; position:relative; overflow:hidden; }
  /* the source is 1688x1125 (3:2) in a 420x380 (1.11:1) box, so cover scales
     it to match the HEIGHT and crops 150px off the width — which makes any
     vertical object-position inert here. Left at the default rather than
     carrying a number that does nothing. */
  .a1 .ph img { width:100%; height:100%; object-fit:cover; }

  /* padding-left is the gap between the photograph and the contact block.
     Without it the block's own left edge — and so the left input field — sat
     flush against the picture; only the centred TEXT looked as if it had air.
     The content box here is a constant 480px, so the 60px is load-bearing:
     .call is exactly the 420px that is left. */
  .a1 .cp { flex:1; background:var(--brown); display:flex; align-items:center;
            justify-content:flex-end; padding:40px 0 40px 60px;
            padding-right:calc((100% - 1280px)/2); }

  /* =====================================================================
     CHANGE 4 — .cp carries home_v1's .call, part for part:
       lead . big number . availability . two fields . one swarm button .
       office note — centred, in that order.
     Two things had to change for the ground it sits on, and only two:
       - the button. home_v1's swarmbtn is BROWN on orange; on this brown
         panel that is brown on brown. Inverted to white with the brown
         label (10.86:1) and the orange swarm kept. Filling it with brand
         orange instead would put white 13px bold on 3.03:1 — under the
         4.5:1 floor for text that size.
       - the swarm particles are 9 x 10.392, not home_v1's 9 x 10.5. Same
         reason as the big hexagon: 9/0.8660254 = 10.392. home_v1's pair is
         1.0% off ratio.
     What did NOT need changing is the interesting part: the #FBE3D8 tint on
     the availability line and the office note reads 2.47:1 on home_v1's
     orange — a real defect — and 8.84:1 here on brown. Same colour, same
     copy, legal ground.
     ===================================================================== */
  .a1 .cp .call { width:420px; max-width:100%; text-align:center; }
  /* every line-height here is declared for the same reason as .crumbs — these
     are the values `normal` renders on the option sheet, pinned so the block is
     the same height on any host page */
  .a1 .call .lead { font-family:Raleway,sans-serif; font-weight:600; font-size:16px; line-height:19px;
                    letter-spacing:.08em; text-transform:uppercase; color:#fff; margin-bottom:6px; }
  /* home_v1's own 54px, kept. It measures 381.6px of the 420px column —
     18.2px of air each side. That measurement is the floor under the panel
     model: the call column cannot go below ~390 without shrinking the number
     itself, which is why .cp's content box is 480 (60 gap + 420 column). */
  .a1 .call .big { display:block; font-family:Raleway,sans-serif; font-weight:800; font-size:54px;
                   letter-spacing:.02em; color:#fff; line-height:1.15; }
  .a1 .call .big:hover { text-decoration:underline; }
  .a1 .call .avail { font-size:13.5px; line-height:18px; color:#FBE3D8; margin:4px 0 22px; }
  .a1 .call .frow2 { display:flex; gap:10px; justify-content:center; margin-bottom:12px; }
  .a1 .call input { flex:1; min-width:0; border:0; font-family:"Open Sans",sans-serif; font-size:13.5px;
                    padding:12px 14px; color:#444; outline:none; background:#fff; }
  .a1 .call input::placeholder { color:#999; }
  .a1 .call .btns { display:flex; gap:10px; justify-content:center; }
  .a1 .call .officenote { font-size:12px; line-height:17px; color:#FBE3D8; margin-top:14px; }
  .a1 .call .officenote a { text-decoration:underline; }

  .swarmbtn { display:inline-block; position:relative; background:#fff; color:var(--brown);
              font-family:Raleway,sans-serif; font-weight:700; font-size:13px; letter-spacing:.06em;
              text-transform:uppercase; padding:12px 44px 12px 20px; cursor:pointer; border:0; }
  .swarmbtn i { position:absolute; display:block; width:9px; height:10.392px; background:var(--orange);
                clip-path:polygon(50% 0,100% 25%,100% 75%,50% 100%,0 75%,0 25%); transition:all .25s ease; }
  .swarmbtn .w1 { right:12px; top:6px;  transform:rotate(14deg); }
  .swarmbtn .w2 { right:26px; top:16px; transform:rotate(-20deg); }
  .swarmbtn .w3 { right:8px;  top:24px; transform:rotate(32deg); }
  .swarmbtn:hover .w1 { right:16px;   top:5px;    transform:rotate(0); }
  .swarmbtn:hover .w2 { right:21.5px; top:14.6px; transform:rotate(0); }
  .swarmbtn:hover .w3 { right:10.5px; top:14.6px; transform:rotate(0); }

"""

CRUMBS = ('<nav class="crumbs %s"><a href="/">Home</a><i></i><a href="/our-services/">What We Do</a>'
          '<i></i><a href="/our-services/bc-injury-claims/">Injury Claims</a><i></i>'
          '<span class="here">Car Accident Claims</span></nav>')

TITLE = '<h1 class="htitle">Car Accident Claims</h1>'


def hexicon(size="m", tone="w"):
    return '<span class="hex %s %s"><i class="fa fa-car"></i></span>' % (size, tone)


def header(cur="Injuries"):
    nav = "".join('<a href="#"%s>%s</a>' % (' class="cur"' if n == cur else '', n)
                  for n in ["Injuries", "Estates", "Business", "Marine", "Real Estate", "Your Team"])
    return ('<header class="sh"><div class="wrap"><a class="logo" href="#">'
            '<img src="/wp-content/uploads/logo.png" alt="League and Williams Lawyers"></a>'
            '<nav class="snav">%s</nav><div class="sphone"><span class="cn">CALL NOW</span>'
            '<span class="num">250-888-0002</span></div></div></header>' % nav)


def photo():
    return ('<img src="%s" alt=""><span class="phtag">Placeholder &middot; November shoot</span>'
            % PHOTO)


def call_block():
    """home_v1's .call, part for part. Same markup, same order, same copy."""
    return (
        '<div class="call">'
          '<div class="lead">Talk to a real person now</div>'
          '<a class="big" href="' + TEL + '">250-888-0002</a>'
          '<div class="avail">Free consultations for injury &amp; estate litigation</div>'
          '<form class="callform" action="#" onsubmit="return false">'
            '<div class="frow2">'
              '<input type="text" name="name" placeholder="Your name" autocomplete="name">'
              '<input type="tel" name="phone" placeholder="Your number" autocomplete="tel">'
            '</div>'
            '<div class="btns"><button class="swarmbtn" type="submit">Call Me Back'
              '<i class="w1"></i><i class="w2"></i><i class="w3"></i></button></div>'
          '</form>'
          '<div class="officenote">Head office &mdash; Victoria &middot; '
            '<a href="#locations">6 offices across BC &darr;</a></div>'
        '</div>')


def A1():
    return (
        '<section class="a1">' + header() +
        '<div class="cbar"><div class="wrap">' + (CRUMBS % "dark") + '</div></div>'
        '<div class="band">'
          '<div class="tp"><div class="in">' + hexicon("m", "w") +
            '<span class="hrule"></span>' + TITLE +
            '<span class="hrule"></span>'
            '<p class="hsub">Injuries</p></div></div>'
          '<div class="ph">' + photo() + '</div>'
          '<div class="cp">' + call_block() + '</div>'
        '</div></section>')


HEAD = """<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<title>League Law &mdash; inner service hero, round 2</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@300;400;500;600;700;800&amp;family=Open+Sans:wght@400;600;700&amp;display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>__CSS__</style>
</head>
<body>

<div class="page-head">
  <h1>Inner service hero &mdash; round 2 (A1, revised)</h1>
  <p>A1 picked, with the six changes Adi asked for. Round 1&rsquo;s six options are still on the
  server at <code>hero-inner-r1.html</code>; open it beside this one to read the changes as changes
  (both use the <code>.a1</code> namespace, so they cannot share a page).</p>

  <div class="box"><b>The six changes.</b>
  <table>
    <tr><th>#</th><th>asked</th><th>done</th></tr>
    <tr><td>1</td><td><code>.tp</code> &mdash; the slanted <code>::after</code> is not needed, a straight line is enough</td>
        <td>The wedge is <b>removed</b>. The orange panel meets the photograph on a straight vertical edge.
        It was a 38px clipped triangle that had to be given <code>z-index</code> to paint at all, and it
        cut into the frame at head height.</td></tr>
    <tr><td>2</td><td><code>.in</code> &mdash; too full, no space above or below</td>
        <td>It was <b>12px over</b>: the type measured 236px inside a 300px band that already spent 76px
        on padding. Fixed at the cause &mdash; the band is now <code>min-height</code>, not a fixed
        height, so type can never squeeze the padding out again &mdash; and the padding went
        <b>38&rarr;48px</b> with the rules at 16px.</td></tr>
    <tr><td>3</td><td><code>.ph</code> &mdash; the photograph is too small; take the room from <code>.cp</code></td>
        <td><b>330&times;300 &rarr; 420&times;380</b>: +27% wide, +27% tall, <b>+61% area</b>. The width came
        out of <code>.cp</code> and then out of <code>.tp</code> as well (change&nbsp;5); the height out of
        the band.</td></tr>
    <tr><td>4</td><td><code>.cp</code> &mdash; carry the same content as <code>.call</code> in home_v1</td>
        <td>Lifted part for part: lead line, phone at display size, availability, two fields, the swarm
        button, the office note &mdash; centred, in that order. Two adaptations, both forced, both below.</td></tr>
    <tr><td>5</td><td><code>.tp</code> is too wide</td>
        <td><b>460 &rarr; 380</b>, a <b>336px</b> type column. The widest line the title actually sets is
        <code>CAR&nbsp;ACCIDENT</code> at <b>313.27px</b>, so 336 leaves 22.7px and the wrap is unchanged.
        The 80px went to the photograph (20) and to change&nbsp;6 (60).</td></tr>
    <tr><td>6</td><td><code>.cp</code> needs a padding-left</td>
        <td><b>60px.</b> It is load-bearing, not decoration: the contact block&rsquo;s own left edge &mdash;
        and so the left input field &mdash; was sitting <b>flush against the photograph</b>. Only the
        centred text looked as though it had air. Measured gap now <b>60.00px</b> at every width.</td></tr>
  </table>
  <b>The panels still close on the container exactly</b> &mdash;
  <b>380 (type) + 420 (photograph) + 480 (contact) = 1280</b> &mdash; each bleeding to its own edge of the
  screen on top of that, so none of them drifts as the screen widens.
  </div>

  <div class="box warn"><b>The two things that could not be copied straight across &mdash; and the one that could.</b>
  <table>
    <tr><th>part</th><th>home_v1</th><th>here</th><th>why</th></tr>
    <tr><td>the button</td><td>brown on orange &mdash; white label, 10.86:1</td>
        <td><b>white, brown label</b> &mdash; 10.86:1, orange swarm kept</td>
        <td>The panel is brown, so home_v1&rsquo;s brown button is invisible on it. Filling it with brand
        orange instead would put a white 13px bold label on <b>3.03:1</b> &mdash; under the 4.5:1 floor
        for text that size. Inverting keeps the same ratio the button has on the homepage.</td></tr>
    <tr><td>swarm particles</td><td>9 &times; 10.5 &mdash; ratio 0.857</td><td><b>9 &times; 10.392</b> &mdash; ratio 0.8660</td>
        <td>Same arithmetic as the big hexagon: 9 / 0.8660254 = 10.392. home_v1&rsquo;s pair is 1.0% off,
        which is small but it is the same mistake this sheet exists to stop making.</td></tr>
    <tr><td>availability + office note</td><td><code>#FBE3D8</code> on orange &mdash; <b>2.47:1</b></td>
        <td><code>#FBE3D8</code> on brown &mdash; <b>8.84:1</b></td>
        <td>Nothing changed but the ground under it. The tint that is a real contrast defect on the
        homepage band is comfortably legal here. <b>The homepage still wants fixing</b> &mdash; moving
        the content here does not fix it there.</td></tr>
  </table>
  </div>

  <div class="box"><b>What it costs on the first screen.</b>
  Measured below the 93px header; a 700px viewport has <b>607px</b> to give away.
  <table>
    <tr><th></th><th>breadcrumb strip</th><th>band</th><th>hero total</th><th>left for the page</th></tr>
    <tr><td>round 1</td><td>41px</td><td>300px</td><td>341px</td><td>266px</td></tr>
    <tr><td><b>round 2</b></td><td>41px</td><td><b>__BAND__px</b></td><td><b>__HERO__px</b></td><td><b>__LEFT__px</b></td></tr>
  </table>
  The bigger photograph and home_v1&rsquo;s contact block are both paid for out of the same 80px. If that
  is too much, the phone can come down from 54px and the band with it &mdash; say so and it is one number.
  </div>

  <div class="box ask"><b>Still only Adi&rsquo;s or the firm&rsquo;s to settle</b> (carried over from round 1):
    <ul>
      <li><b>Does Darren&rsquo;s ban on the intro image reach inner pages?</b> Documented for the homepage
      first screen only. A1 puts a photograph in the hero.</li>
      <li><b>The availability line.</b> This is home_v1&rsquo;s approved &ldquo;Free consultations for
      injury &amp; estate litigation&rdquo;. A car-accident page would rather say it about car accidents
      &mdash; the firm&rsquo;s sentence to write, not ours.</li>
      <li><b>The office note.</b> It comes across with the rest of <code>.call</code>, and it carries the
      same open question it carries on the homepage: <i>which number</i> does a six-office firm show.</li>
    </ul>
  </div>
</div>

<div class="roundhead">Round 2 &mdash; A1, revised</div>
"""


def build(band, hero, left):
    css = lift_shared_css() + A1CSS
    head = (HEAD.replace("__CSS__", css)
                .replace("__BAND__", str(band))
                .replace("__HERO__", str(hero))
                .replace("__LEFT__", str(left)))
    out = [head]
    out.append(
        '\n<div class="opt">\n'
        '  <div class="opt-label"><span class="tag">A1</span>'
        '<span class="name">The reference, mapped &mdash; revised</span>'
        '<span class="h">Brand orange &middot; photograph &middot; brown</span>'
        '<span class="what">Straight edge between panel and photograph; the type given room; the '
        'photograph 54% bigger; and the contact panel carrying home_v1&rsquo;s contact block part for '
        'part instead of a bespoke one.</span></div>\n'
        '  <div class="stage">__STAGE__</div>\n'
        '  <p class="opt-note">The orange block still carries <b>only large type</b> &mdash; the title at '
        '38px and the sub-line at 20px bold &mdash; because white on brand orange is <b>3.03:1</b>: it '
        'clears the 3:1 floor for large text and fails the 4.5:1 floor for anything smaller. All the small '
        'contact copy sits on brown (<b>10.86:1</b>). That is the same reason the reference&rsquo;s own '
        'arrangement works: bright block for the title, dark block for the details.</p>\n'
        '</div>\n'.replace("__STAGE__", A1()))

    out.append("\n</body>\n</html>\n")
    return "".join(out)


if __name__ == "__main__":
    band = int(os.environ.get("BAND", "380"))
    hero = 41 + band
    html = build(band, hero, 607 - hero)
    dest = sys.argv[1] if len(sys.argv) > 1 else OUT
    io.open(dest, "w", encoding="utf-8").write(html)
    print("wrote %s (%d bytes)" % (dest, len(html)))
