#!/usr/bin/env python3
# Book 14 (Larsen & Toubro) — THE BUILDERS OF GIANTS. Science->business: forces & structures
# (triangles, foundations, concrete+steel, cranes) -> the business of building a nation's biggest things.
import os
ART="/root/omahaindia.com/comics/site/book/lt/art"; OUT="/root/omahaindia.com/comics/site/book/lt/index.html"
STYLE=("children's storybook manga illustration, warm painted animation style, soft cinematic light, clean linework, NO text NO letters NO words")
CHARLOTTE=("Charlotte, the SAME young Indian CHILD girl from the reference, round young face, warm tan skin, freckles, glossy black hair in two low twin ponytails, big curious dark eyes, bright TEAL t-shirt, NO facial hair")
GRAHAM="Ben, a kind scholarly elderly American gentleman, round wire spectacles, tweed suit and bow tie"
BUFFETT="Warren, a folksy cheerful elderly American man, thinning white hair, big friendly glasses, grey suit"
MUNGER="Charlie, a stocky wise elderly American man, very thick black-framed glasses, dark suit"
BRUNO=("Bruno, a warm friendly construction engineer, yellow hard hat, bright orange hi-vis vest over a shirt, a rolled blueprint under his arm, sturdy build, confident kind smile")
NEW={
 "00_cover":(1024,1180,1400,f"{STYLE}. BOOK COVER, {CHARLOTTE} standing with {BRUNO} before an enormous half-built bridge and towering cranes against a bright sky, awe and wonder, cinematic","charlotte"),
 "_ref_bruno":(1024,1024,1401,f"{STYLE}. clean friendly character portrait, {BRUNO}, plain soft background, warm smile, head and shoulders",None),
 "lt_c1_block":(1024,720,1410,f"{STYLE}. {CHARLOTTE} at home holding a glowing brass compass that twitches toward a tall wobbly tower of toy blocks, EXPRESSION puzzled and intrigued, cozy lamp light","charlotte"),
 "lt_c1_diary":(1024,720,1411,f"{STYLE}. an open magical diary glowing warm gold, faint glowing girders and bridges of light rising from the page, no people",None),
 "lt_c1_swirl":(1024,720,1412,f"{STYLE}. {CHARLOTTE} pulled into a swirling spiral of golden light and floating steel girders from a glowing diary, EXPRESSION thrilled, magical","charlotte"),
 "lt_c2_arrive":(1024,720,1413,f"{STYLE}. {CHARLOTTE} landing wide-eyed at an enormous busy construction site with towering cranes and steel frames, EXPRESSION awe, bright day","charlotte"),
 "lt_c2_bruno":(1024,720,1414,f"{STYLE}. {BRUNO} warmly welcoming {CHARLOTTE} at the site, EXPRESSION Charlotte shy happy smile; keep the SAME engineer from the reference, same hard hat and hi-vis vest","bruno"),
 "lt_c3_triangle":(1024,720,1415,f"{STYLE}. {BRUNO} showing {CHARLOTTE} how a wobbly square frame becomes rock-solid when a diagonal bar makes it into triangles, teaching, EXPRESSION Charlotte fascinated; SAME engineer","bruno"),
 "lt_c3_bridge":(1024,720,1416,f"{STYLE}. a beautiful bridge made of many strong triangles of light holding firm, playful clear science, no people",None),
 "lt_c4_dig":(1024,720,1417,f"{STYLE}. a cutaway showing a tall building's wide deep foundations gripping into the ground like roots spreading the weight, friendly clear science, no people",None),
 "lt_c4_spread":(1024,720,1418,f"{STYLE}. a cute comparison, a thin leg sinking into soft ground beside a wide foot standing firm, showing how spreading weight helps, playful, no people",None),
 "lt_c5_team":(1024,720,1419,f"{STYLE}. {BRUNO} showing {CHARLOTTE} a block of concrete hugging steel bars inside it, a friendly team, teaching, EXPRESSION Charlotte curious 'aha'; SAME engineer","bruno"),
 "lt_c5_push":(1024,720,1420,f"{STYLE}. a cute science cartoon, concrete strong when squeezed and steel strong when stretched, the two together unbeatable, playful, no people no text",None),
 "lt_c6_crane":(1024,720,1421,f"{STYLE}. a giant tower crane easily lifting an enormous steel beam high into the sky, {CHARLOTTE} tiny below looking up amazed, EXPRESSION awe","charlotte"),
 "lt_c6_lever":(1024,720,1422,f"{STYLE}. a friendly cartoon of a simple lever and pulley lifting a huge heavy block with a gentle pull, playful clear science, no people",None),
 "lt_c7_plan":(1024,720,1423,f"{STYLE}. {BRUNO} and {CHARLOTTE} looking over a big glowing blueprint of a metro and a bridge, thousands of tiny workers building together, EXPRESSION Charlotte impressed; SAME engineer","bruno"),
 "lt_c7_metro":(1024,720,1424,f"{STYLE}. a huge finished metro station and a soaring bridge full of happy people, proud and bright, no text",None),
 "lt_c8_reveal":(1024,720,1425,f"{STYLE}. {CHARLOTTE} and {BRUNO} standing proudly before a grand modern engineering company headquarters, EXPRESSION proud recognition; SAME engineer","charlotte"),
 "lt_c8_1938":(1024,720,1426,f"{STYLE}. warm sepia 1930s scene, two hopeful young European engineers starting a small engineering firm in India with drawings and tools, dreaming of building big, inspiring, no text",None),
 "lt_c10_look":(1024,720,1427,f"{STYLE}. {CHARLOTTE} outside looking with wonder at a bridge, a tall building and a crane on the skyline of her bright town, EXPRESSION delighted wonder, morning","charlotte"),
}
def P(img,cap=None,b1=None,b2=None,sfx=None,sfxc="#e8425a",tall=False): return ("panel",img,cap,b1,b2,sfx,sfxc,tall)
def WOW(t): return ("wow",t)
def NOTE(t,b): return ("note",t,b)
def TL(r): return ("timeline",r)
def MOAT(c): return ("moat",c)
CHAPTERS=[
 ("c1","CHAPTER 1","The Tower That Wouldn't Fall","pages 1-8",[
   P("lt_c1_block","Grandpa Ben's compass twitched — at a tall wobbly tower of blocks Charlotte had built.","Why does mine keep FALLING over?",None,"twitch"),
   P("lt_c1_diary","The diary fell open. A line shimmered.",None,'"Find how the biggest things in the world stay standing."'),
   WOW("Some things people build are almost too big to believe — bridges over wide rivers, towers that touch clouds, tunnels under cities. How does anything so ENORMOUS stay up? That's the puzzle."),
   P("lt_c1_swirl","Golden light and girders swirled up and pulled her in.","Here we GO!",None,"WHOOSH","#2a7de1"),
   NOTE("Charlotte's Secret Notebook","Two BIG questions:<br>➊ What makes a giant building or bridge stand strong instead of toppling like my blocks?<br>➋ How do people even BUILD something that huge? 🏗️"),
 ]),
 ("c2","CHAPTER 2","The Land of Giants","pages 9-14",[
   P("lt_c2_arrive","One blink, and she stood at the biggest building site she'd ever seen — cranes taller than trees.","Everything here is a GIANT!"),
   P("lt_c2_bruno","An engineer in a hard hat waved. \"I'm Bruno. I help build the giant things — bridges, metros, towers.\"","You build the GIANTS?!"),
   NOTE("Charlotte's Secret Notebook","Bruno builds giant things — and grins like he knows a secret, just like Gus and Mia did. Okay Bruno… teach me how they stand! ✨"),
 ]),
 ("c3","CHAPTER 3","The Strongest Shape","pages 15-24",[
   P("lt_c3_triangle","Bruno pushed a square frame — it wobbled flat. Then he added one diagonal bar. It turned to triangles and went rock-solid.","One bar… and it can't wobble!"),
   P("lt_c3_bridge","\"Triangles can't squish. That's why bridges and towers are full of them.\"","Triangles everywhere — now I SEE it!"),
   WOW("Here's a big secret! 📐 A square can lean and flatten, but a <b>triangle can't change shape</b> without breaking. So builders fill giant structures with triangles — that's what makes them stiff and strong."),
   ("diagram",),
   NOTE("Charlotte's Secret Notebook · SOLVED (part 1)!","A SQUARE wobbles; a TRIANGLE can't squish. Fill a structure with triangles and it stays strong. My block tower had no triangles — that's why it fell! ✅"),
 ]),
 ("c4","CHAPTER 4","Standing Up Tall","pages 25-32",[
   P("lt_c4_dig","\"But strong isn't enough,\" said Bruno. \"Before we go UP, we go DOWN — deep, wide foundations that grip the ground.\"","You dig DOWN to build UP?"),
   P("lt_c4_spread","\"A thin leg sinks in soft ground. A wide foot spreads the weight so it holds. Big buildings need big feet.\"","Spread the weight — don't sink!"),
   WOW("A giant building would sink or topple without deep, wide <b>foundations</b> that spread its huge weight into the ground — like giant roots or a wide foot. The tallest towers hide their biggest work underground."),
   NOTE("Charlotte's Secret Notebook","Before building UP, builders dig DOWN — wide, deep foundations that spread the weight into the ground so nothing sinks. Big feet for big buildings! 🦶"),
 ]),
 ("c5","CHAPTER 5","The Team of Two","pages 33-40",[
   P("lt_c5_team","Bruno cracked open a block of concrete — steel bars ran inside it.","Metal INSIDE the stone?"),
   P("lt_c5_push","\"Concrete is super strong when SQUEEZED but weak when stretched. Steel is the opposite. Put them together and each covers the other's weakness.\"","A perfect TEAM!",None,"clank","#2aa15a"),
   WOW("The magic of modern building: <b>concrete</b> is strong when squeezed, <b>steel</b> is strong when pulled. Hide steel bars inside concrete and you get something strong <i>both</i> ways — that's how bridges and towers carry giant loads."),
   NOTE("Charlotte's Secret Notebook","Concrete = strong squeezed. Steel = strong stretched. Steel bars INSIDE concrete cover each other's weakness — a perfect team that holds up giants. 🤝"),
 ]),
 ("c6","CHAPTER 6","The Giant Helpers","pages 41-48",[
   P("lt_c6_crane","A tower crane lifted an enormous beam high into the sky, as if it weighed nothing.","How does it lift something SO heavy?!"),
   P("lt_c6_lever","\"Clever machines — levers and pulleys — turn a gentle pull into a giant lift,\" said Bruno.","A little pull… a HUGE lift!"),
   WOW("No human could lift a steel beam — but a <b>crane</b> using levers and pulleys turns a small motor's gentle pull into an enormous lift. Clever machines are how a few people raise the heaviest giants."),
   NOTE("Charlotte's Secret Notebook","Cranes use levers and pulleys to turn a gentle pull into a giant lift — that's how tiny people raise enormous beams. ⚙️"),
 ]),
 ("c7","CHAPTER 7","Building the Impossible","pages 49-56",[
   P("lt_c7_plan","Bruno unrolled a huge blueprint — a whole metro and bridge, and thousands of people building it together.","So many people… one giant plan!"),
   P("lt_c7_metro","Soon a gleaming metro and a soaring bridge filled with happy people.","They built the IMPOSSIBLE!"),
   WOW("A giant project is really thousands of people, machines and clever plans working in exact order for years. Getting it right — safe, on time, enormous — is so hard that only a few companies in the world can. That skill is a superpower."),
   NOTE("Charlotte's Secret Notebook","Giant things = thousands of people + machines + a careful plan, in exact order, for years. Doing it safely is SO hard only a few can — that's the real skill. 🏗️"),
 ]),
 ("c8","CHAPTER 8 · THE BIG DISCOVERY","The Two Engineers","pages 57-66",[
   P("lt_c8_reveal","Bruno led Charlotte outside. Above the building glowed a famous name.","It's <b>Larsen & Toubro!</b>"),
   P("lt_c8_1938","\"It began in 1938,\" said Bruno, \"started by two young engineers who came to India — Mr. Larsen and Mr. Toubro — with big dreams and little money.\"","Two friends, building giants!"),
   WOW("A \"company\" is a long chain of <b>bold, careful choices.</b> Larsen & Toubro began in 1938 with two engineers from Denmark and grew, project by project, into the company that builds India's biggest things — because it learned to do the impossible, safely."),
   TL([("1938","Two young engineers start a small firm in India."),
       ("Mid-1900s","They take on bigger and bigger building projects."),
       ("Today (part)","Metros, airports, bridges, giant machines across India."),
       ("Today","One of India's largest engineering & construction companies. 🏗️")]),
   NOTE("Charlotte's Secret Notebook","L&T (1938) began with TWO engineers and grew, project by project, into India's giant-builder. Skill + care + years of hard, exact work. 🏆"),
 ]),
 ("c9","CHAPTER 9","The Castle of Skill","pages 67-76",[
   P("lt_c9_castle","Two kind old men appeared with a glow. Warren pointed at a castle. \"What keeps rivals out, Charlotte?\"","Walls! But made of what?"),
   MOAT([("🧠","Wall One: Hard-Won Skill","Building giants safely takes decades of learning. A rival can't buy that skill overnight.",False),
         ("🏅","Wall Two: A Trusted Name","People give the biggest, riskiest projects to a builder they trust to finish, safely and on time.",False),
         ("🏗️","Wall Three: Machines & Scale","Giant cranes, factories and thousands of trained people — a web that takes years and a fortune to match.",False),
         ("⚠️","The Crack in the Wall","What could hurt it? Promising more than it can safely build, or getting careless on safety. With giants, one careless choice is the biggest danger.",True)]),
   P("lt_c9_munger","Charlie tapped his head. \"Don't just ask how to WIN. Ask how you'd LOSE — then don't. Invert!\"","Think backwards?"),
   WOW("<b>Charlie's Inversion:</b> to keep a great builder great, imagine how it could be RUINED — overpromise, cut safety corners, run out of skilled people — and carefully avoid every one. Building giants makes carefulness the whole moat."),
   P("lt_c9_verdict","Warren nodded. \"Skilled, trusted, mighty — a fine castle, if it never gambles with safety.\"","I SEE the whole picture!"),
   NOTE("Charlotte's Secret Notebook · The Big Secret","L&T's WALLS: hard-won SKILL, a TRUSTED name, and giant MACHINES & scale. Charlie's trick — imagine how it could be ruined (overpromise, unsafe), then never do that. Invert! 🏰"),
 ]),
 ("c10","CHAPTER 10","Giants All Around","pages 77-84",[
   P("lt_c10_wake","Charlotte woke in her own bed. The site was gone… but a toy crane sat on her shelf.","Was it real? It FELT real…"),
   P("lt_c10_diary","On the diary's page, a new line glowed.",None,'"Now you know why the giants stand. Well done."'),
   P("lt_c10_look","She ran outside. Every bridge, tower and crane held a hidden secret now — triangles, deep feet, steel and stone.","Every giant is standing on clever science!"),
   WOW("Next time you cross a bridge or look up at a tower, you'll know its secrets: triangles that can't wobble, deep feet spreading the weight, steel and concrete teaming up, and clever cranes — built by people brave and careful enough to build giants. That's <b>the builders of giants.</b> 🏗️"),
   NOTE("Charlotte's Secret Notebook · What I Learned","➊ TRIANGLES can't squish — they make structures strong.<br>➋ Deep, wide FOUNDATIONS spread the weight so nothing sinks.<br>➌ CONCRETE (squeezed) + STEEL (stretched) team up.<br>➍ CRANES use levers & pulleys for giant lifts.<br>➎ L&T builds India's giants; Charlie's trick — figure out how you'd lose, then don't. 💛"),
 ]),
]
HOOK=("lt_c1_swirl","EVERY ORDINARY THING HIDES A SECRET.",
 "Charlotte learned how giants stand. But the compass is twitching again — toward a company that builds nothing you can touch at all, yet the whole world runs on it. How do you build with pure THINKING?",
 "NEXT ADVENTURE · The Machine That Thinks in Steps →")
DIAGRAM='''<div class="panel wide" style="background:#eef4fb;"><svg viewBox="0 0 820 320"><rect width="820" height="320" fill="#eef4fb"/>
<text x="410" y="36" text-anchor="middle" font-family="Bangers" font-size="24" fill="#2a7de1">WHY A TRIANGLE BEATS A SQUARE</text>
<g stroke="#e8425a" stroke-width="6" fill="none"><rect x="90" y="90" width="150" height="150"/><line x1="90" y1="240" x2="210" y2="90" stroke="#e8425a" stroke-width="3" stroke-dasharray="8 6"/></g>
<text x="165" y="275" text-anchor="middle" font-family="Baloo 2" font-size="15" fill="#e8425a">SQUARE: leans & flattens</text>
<g stroke="#2aa15a" stroke-width="6" fill="none"><path d="M540 240 L620 90 L700 240 Z"/></g>
<text x="620" y="275" text-anchor="middle" font-family="Baloo 2" font-size="15" fill="#2aa15a">TRIANGLE: can't change shape</text>
<text x="410" y="170" text-anchor="middle" font-family="Nunito" font-size="16" fill="#123">Builders fill</text><text x="410" y="192" text-anchor="middle" font-family="Nunito" font-size="16" fill="#123">giants with</text><text x="410" y="214" text-anchor="middle" font-family="Bangers" font-size="20" fill="#2a7de1">triangles</text>
</svg><div class="figcap">A square can wobble flat; a triangle can't — so strong structures are full of triangles.</div></div>'''
try:
    from book_extra import EXTRA, NEW2; NEW.update(NEW2)
except Exception: EXTRA={}
def render_panel(pn,pageno=None):
    _,img,cap,b1,b2,sfx,sfxc,tall=pn
    pg=f'<div class="pageno">{pageno}</div>' if pageno else ''
    p=[f'<div class="panel wide">{pg}<img src="art/{img}.jpg" alt="" loading="lazy">']
    if cap: p.append(f'<div class="cap tl tilt">{cap}</div>')
    if b1: p.append(f'<div class="bubble dl" style="left:12px;bottom:12px;">{b1}</div>')
    if b2: p.append(f'<div class="bubble dr" style="right:12px;top:12px;">{b2}</div>')
    if sfx: p.append(f'<div class="sfx" style="left:40%;top:14px;font-size:32px;color:{sfxc};">{sfx}</div>')
    p.append('</div>'); return "".join(p)
def render_item(it,pageno=None):
    t=it[0]
    if t=="panel": return render_panel(it,pageno)
    if t=="diagram": return DIAGRAM
    if t=="wow": return f'<div class="wow">{it[1]}</div>'
    if t=="note": return f'<div class="note"><div class="nt">{it[1]}</div><p>{it[2]}</p></div>'
    if t=="timeline":
        rows="".join(f'<div class="tl"><div class="yr">{y}</div><p>{x}</p></div>' for y,x in it[1]); return f'<div class="timeline">{rows}</div>'
    if t=="moat":
        cards="".join(f'<div class="mc{" bad" if bad else ""}"><h4>{ic} {ti}</h4><p>{tx}</p></div>' for ic,ti,tx,bad in it[1]); return f'<div class="moat">{cards}</div>'
    return ""
def referenced_images():
    imgs=set()
    for cls,_,_,_,items in CHAPTERS:
        for it in items:
            if it[0]=="panel": imgs.add(it[1])
    imgs.add(HOOK[0]); imgs.add("00_cover"); imgs.add("_ref_bruno"); return imgs
def build():
    body=[]; pageno=0
    for cls,num,title,pglabel,items in CHAPTERS:
        start=pageno+1
        inner=[f'<div class="chapbar {cls}"><div class="n">{num}</div><h2>{title}</h2></div>']
        for it in items:
            if it[0]=="panel": pageno+=1; inner.append(render_item(it,pageno))
            else: inner.append(render_item(it))
        body.append(f'<div class="sheet" data-pg="pages {start}-{pageno}">{"".join(inner)}</div>')
    hook=f'<div class="sheet" data-pg="the end… for now"><div class="hook"><img src="art/{HOOK[0]}.jpg" alt=""><div class="hc"><h3>{HOOK[1]}</h3><p>{HOOK[2]}</p><div class="b2">{HOOK[3]}</div></div></div></div>'
    head=open("/root/omahaindia.com/comics/site/book/lt/_head.html").read(); tail=open("/root/omahaindia.com/comics/site/book/lt/_tail.html").read()
    open(OUT,"w").write(head+"".join(body)+hook+tail); print("built",OUT)
if __name__=="__main__": build()
