#!/usr/bin/env python3
# Book 15 (Infosys) — THE MACHINE THAT THINKS IN STEPS. Science->business: algorithms
# (exact step-by-step instructions, loops, sorting, bugs) -> a global software-services giant from 7 friends.
import os
ART="/root/omahaindia.com/comics/site/book/infosys/art"; OUT="/root/omahaindia.com/comics/site/book/infosys/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"
GRACE=("Grace, a warm friendly software architect, smart casual blazer over a bright t-shirt, glasses pushed up, short curly hair, a lanyard badge, bright clever smile")
NEW={
 "00_cover":(1024,1180,1500,f"{STYLE}. BOOK COVER, {CHARLOTTE} standing with {GRACE} inside a bright airy software campus, gentle glowing steps and arrows of light forming a friendly thinking-machine around them, wonder, cinematic","charlotte"),
 "_ref_grace":(1024,1024,1501,f"{STYLE}. clean friendly character portrait, {GRACE}, plain soft teal background, bright smile, head and shoulders",None),
 "in_c1_screen":(1024,720,1510,f"{STYLE}. {CHARLOTTE} at home holding a glowing brass compass that twitches toward a softly glowing computer screen, EXPRESSION puzzled and intrigued, cozy lamp light","charlotte"),
 "in_c1_diary":(1024,720,1511,f"{STYLE}. an open magical diary glowing warm gold, faint glowing steps and arrows of light rising from the page, no people",None),
 "in_c1_swirl":(1024,720,1512,f"{STYLE}. {CHARLOTTE} pulled into a swirling spiral of golden light and floating glowing arrows and steps from a glowing diary, EXPRESSION thrilled, magical","charlotte"),
 "in_c2_arrive":(1024,720,1513,f"{STYLE}. {CHARLOTTE} landing wide-eyed in a bright airy modern software campus with green lawns and glass buildings, gentle glowing arrows of light in the air, EXPRESSION awe","charlotte"),
 "in_c2_grace":(1024,720,1514,f"{STYLE}. {GRACE} warmly welcoming {CHARLOTTE} on the campus, EXPRESSION Charlotte shy happy smile; keep the SAME architect from the reference, same blazer and badge","grace"),
 "in_c3_steps":(1024,720,1515,f"{STYLE}. {GRACE} showing {CHARLOTTE} a friendly robot that follows silly EXACT steps to make a sandwich, doing exactly what it is told, playful teaching, EXPRESSION Charlotte giggling; SAME architect","grace"),
 "in_c3_order":(1024,720,1516,f"{STYLE}. a cute row of numbered glowing footstep tiles in exact order that a little robot follows one by one, playful clear science, no numbers no text",None),
 "in_c4_loop":(1024,720,1517,f"{STYLE}. a friendly cartoon of a little arrow looping back around and around to repeat a task until it is done, playful, no people no text",None),
 "in_c4_army":(1024,720,1518,f"{STYLE}. a cute scene where one small instruction makes a whole tidy army of little helper sparks do the same job at once, playful, no people",None),
 "in_c5_sort":(1024,720,1519,f"{STYLE}. {CHARLOTTE} happily sorting a row of coloured cards into order following a clever step-by-step method, EXPRESSION focused and delighted, {GRACE} guiding; SAME architect","grace"),
 "in_c5_smart":(1024,720,1520,f"{STYLE}. a friendly comparison, a slow messy way to sort beside a clever quick method reaching the answer, playful clear science, no people no text",None),
 "in_c6_bug":(1024,720,1521,f"{STYLE}. a cute friendly little cartoon bug sitting on one wrong glowing step making the little robot go the wrong way, playful, no text",None),
 "in_c6_fix":(1024,720,1522,f"{STYLE}. {CHARLOTTE} with a magnifying glass spotting the wrong step and gently fixing it, EXPRESSION triumphant 'aha', {GRACE} smiling; SAME architect","grace"),
 "in_c7_world":(1024,720,1523,f"{STYLE}. a warm storybook world map where many companies send their problems to a bright campus and get clever step-by-step solutions back as glowing arrows, hopeful, no text",None),
 "in_c7_help":(1024,720,1524,f"{STYLE}. a bright room of friendly software people solving other companies' puzzles together on glowing screens, warm teamwork, no text",None),
 "in_c8_reveal":(1024,720,1525,f"{STYLE}. {CHARLOTTE} and {GRACE} standing proudly before a grand bright modern software company headquarters, EXPRESSION proud recognition; SAME architect","charlotte"),
 "in_c8_1981":(1024,720,1526,f"{STYLE}. warm sepia early-1980s scene, seven hopeful young engineers starting a tiny software company in a small room with almost no money, dreaming big together, inspiring, no text",None),
 "in_c10_look":(1024,720,1527,f"{STYLE}. {CHARLOTTE} outside looking with wonder at phones, traffic lights and screens all quietly following clever steps around her bright neighbourhood, 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 Machine With No Ideas","pages 1-8",[
   P("in_c1_screen","Grandpa Ben's compass twitched — at the glowing computer screen.","A computer? What's ITS secret?",None,"twitch"),
   P("in_c1_diary","The diary fell open. A line shimmered.",None,'"Find the machine that only thinks in exact little steps."'),
   WOW("A computer is amazingly powerful — yet it can't think of a single idea on its own. It only does EXACTLY what it's told, one tiny step at a time. So how does that build maps, games and whole companies? That's the puzzle."),
   P("in_c1_swirl","Golden light and glowing arrows swirled up and pulled her in.","Here we GO!",None,"WHOOSH","#2aa198"),
   NOTE("Charlotte's Secret Notebook","Two BIG questions:<br>➊ A computer can't think for itself — so how does it DO so much?<br>➋ How did a few friends build a giant company out of nothing you can hold? 💻"),
 ]),
 ("c2","CHAPTER 2","The Campus of Steps","pages 9-14",[
   P("in_c2_arrive","One blink, and she stood on a bright green campus of glass buildings, glowing arrows drifting in the air.","It's like a school for THINKING machines!"),
   P("in_c2_grace","A friendly woman waved. \"I'm Grace, a software architect. I teach machines to solve problems — step by step.\"","You teach machines to THINK?"),
   NOTE("Charlotte's Secret Notebook","Grace teaches machines to solve problems step by step — and she grins like she knows a secret, just like Gus and Mia did. Okay Grace… teach me! ✨"),
 ]),
 ("c3","CHAPTER 3","One Step at a Time","pages 15-24",[
   P("in_c3_steps","Grace's little robot made a sandwich by following EXACT steps. She said \"make a sandwich\" — and it put the whole loaf on the plate!","Ha! It did EXACTLY what you said!"),
   P("in_c3_order","\"A computer can't guess what you MEAN,\" Grace laughed. \"You must give it exact steps, in order. That list of steps is called an <b>algorithm</b>.\"","So thinking = exact steps in order!"),
   WOW("Here's the secret! 🤖 A computer never guesses — it follows <b>exact steps in exact order</b>. A clear list of steps that solves a problem is called an <b>algorithm</b>. Teaching a machine is really just writing very, very careful steps."),
   ("diagram",),
   NOTE("Charlotte's Secret Notebook · SOLVED (part 1)!","A computer only does EXACT steps in ORDER — it can't guess what you mean. A list of steps that solves a problem is an ALGORITHM. Careful steps = a thinking machine. ✅"),
 ]),
 ("c4","CHAPTER 4","The Repeat Trick","pages 25-32",[
   P("in_c4_loop","\"But what if a job needs doing a million times?\" said Grace. \"You don't write it a million times — you tell it to REPEAT until done. That's a loop.\"","One instruction… done a million times!"),
   P("in_c4_army","One tiny rule set a whole army of little helpers doing the same job at once.","Small rule, HUGE work!"),
   WOW("A clever trick called a <b>loop</b> lets one short instruction repeat a job as many times as needed. That's how a computer can check a million things or draw a whole world — a few careful steps, repeated. Small rules, giant results."),
   NOTE("Charlotte's Secret Notebook","A LOOP repeats a step over and over until done — so one short rule can do a job a million times. Small rule, huge work! 🔁"),
 ]),
 ("c5","CHAPTER 5","The Sorting Game","pages 33-40",[
   P("in_c5_sort","Grace gave Charlotte a shuffled row of cards. \"Put them in order — but use a clever METHOD, not luck.\"","Compare two, swap if wrong, again and again…"),
   P("in_c5_smart","Charlotte's clever method got there fast — much quicker than guessing.","A smart method BEATS brute force!"),
   WOW("The same job can be done a slow clumsy way or a <b>clever</b> way. Finding faster, smarter step-by-step methods is the real art — a clever algorithm can do in a blink what a clumsy one takes forever to do."),
   NOTE("Charlotte's Secret Notebook","The same task can be done a slow way or a CLEVER way. A smart step-by-step method beats brute force — finding clever methods is the real skill. ♟️"),
 ]),
 ("c6","CHAPTER 6","When a Step Goes Wrong","pages 41-48",[
   P("in_c6_bug","Suddenly the little robot marched the wrong way. A tiny cartoon bug sat on one wrong step.","One wrong step broke EVERYTHING!"),
   P("in_c6_fix","Charlotte hunted it down with a magnifying glass and fixed the step.","Found it! Fixed!",None,"aha!","#2aa198"),
   WOW("Because a computer follows steps EXACTLY, one tiny wrong step — a <b>bug</b> — can break the whole thing. Finding and fixing bugs is called <b>debugging</b>, and it's a huge part of a software person's careful work."),
   NOTE("Charlotte's Secret Notebook","One wrong step (a BUG) breaks everything, because the computer follows steps exactly. Finding and fixing it = DEBUGGING. Careful checking matters! 🐞"),
 ]),
 ("c7","CHAPTER 7","Thinking for the World","pages 49-56",[
   P("in_c7_world","\"Companies all over the world have hard problems,\" said Grace. \"They send them here, and we build the clever steps to solve them.\"","So you think for the whole WORLD?"),
   P("in_c7_help","Rooms full of clever people solved other companies' puzzles on glowing screens.","A whole company of problem-solvers!"),
   WOW("Here's the business! 🌏 A software-services company doesn't sell a thing you hold — it <b>rents out clever step-thinking</b> to companies everywhere, building the algorithms that run their banks, planes and shops. Thousands of careful minds, solving the world's puzzles."),
   NOTE("Charlotte's Secret Notebook","A software company sells no THING — it sells clever STEP-THINKING to companies worldwide, building the algorithms that run their business. Minds for hire! 🧠"),
 ]),
 ("c8","CHAPTER 8 · THE BIG DISCOVERY","The Seven Friends","pages 57-66",[
   P("in_c8_reveal","Grace led Charlotte outside. Above the campus glowed a famous name.","It's <b>Infosys!</b>"),
   P("in_c8_1981","\"It began in 1981,\" said Grace, \"with SEVEN friends and barely any money — just clever minds and a big dream.\"","Seven friends… with almost nothing?!"),
   WOW("A \"company\" is a long chain of <b>bold, careful choices.</b> Infosys began in 1981 with seven engineers and tiny savings. By being honest, training thousands of clever minds, and solving the world's problems step by step, it grew into one of the world's biggest software companies."),
   TL([("1981","Seven engineers start a tiny software company with almost no money."),
       ("1990s","It wins trust solving problems for companies around the world."),
       ("1990s-2000s","It builds a huge training campus and thousands of skilled minds."),
       ("Today","One of the world's largest software-services companies. 💻")]),
   NOTE("Charlotte's Secret Notebook","Infosys (1981) began with SEVEN friends and barely any money — just clever minds and honesty. Train great people + solve the world's puzzles = a giant. 🏆"),
 ]),
 ("c9","CHAPTER 9","The Castle of Minds","pages 67-76",[
   P("in_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: Clever People","Thousands of skilled, trained minds. A rival can't gather and teach that many overnight.",False),
         ("🤝","Wall Two: Trust","Companies hand over their secrets and problems only to a firm they deeply trust. That trust takes years.",False),
         ("🎓","Wall Three: Training & Know-how","A huge campus that turns beginners into experts, plus years of hard-won methods — hard to copy.",False),
         ("⚠️","The Crack in the Wall","What could hurt it? Losing its best people, or breaking a client's trust. When your treasure is minds and trust, keeping both is everything.",True)]),
   P("in_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 minds-company great, imagine how it could be RUINED — lose its best people, break a client's trust, stop learning — and carefully avoid every one. When your castle is made of minds, keeping them happy and honest IS the moat."),
   P("in_c9_verdict","Warren nodded. \"Clever, trusted, always learning — a fine castle, if it treasures its people and its honesty.\"","I SEE the whole picture!"),
   NOTE("Charlotte's Secret Notebook · The Big Secret","Infosys's WALLS: clever PEOPLE, deep TRUST, and great TRAINING. Charlie's trick — imagine how it could be ruined (lose people or trust), then never do that. Invert! 🏰"),
 ]),
 ("c10","CHAPTER 10","Steps All Around","pages 77-84",[
   P("in_c10_wake","Charlotte woke in her own bed. The campus was gone… but her screen glowed softly.","Was it real? It FELT real…"),
   P("in_c10_diary","On the diary's page, a new line glowed.",None,'"Now you see the careful steps behind the magic. Well done."'),
   P("in_c10_look","She ran outside. Every phone, traffic light and screen quietly followed clever steps someone had written.","The whole world is running on careful little steps!"),
   WOW("Next time a phone, a game or a traffic light just works, you'll know the secret: someone wrote careful, clever <b>steps</b> — an algorithm — and a patient machine followed them exactly. That's <b>the machine that thinks in steps.</b> 💻"),
   NOTE("Charlotte's Secret Notebook · What I Learned","➊ A computer only does EXACT steps in order — a list of them is an ALGORITHM.<br>➋ A LOOP repeats a step to do huge jobs.<br>➌ A clever method beats brute force.<br>➍ One wrong step is a BUG; fixing it is debugging.<br>➎ Infosys rents clever step-thinking to the world; Charlie's trick — figure out how you'd lose, then don't. 💛"),
 ]),
]
HOOK=("in_c1_swirl","EVERY ORDINARY THING HIDES A SECRET.",
 "Charlotte learned how machines think in steps. But the compass is twitching again — down, at a plain black rock. How can a dull black stone hold the power to light up a whole country?",
 "NEXT ADVENTURE · The Black Rock That Powers the Dark →")
DIAGRAM='''<div class="panel wide" style="background:#e9f6f4;"><svg viewBox="0 0 820 300"><rect width="820" height="300" fill="#e9f6f4"/>
<text x="410" y="36" text-anchor="middle" font-family="Bangers" font-size="24" fill="#2aa198">AN ALGORITHM = EXACT STEPS IN ORDER</text>
<g font-family="Baloo 2" font-size="15" fill="#171717">
<rect x="70" y="80" width="150" height="52" rx="10" fill="#fff" stroke="#171717" stroke-width="3"/><text x="145" y="112" text-anchor="middle">1. get bread</text>
<rect x="70" y="150" width="150" height="52" rx="10" fill="#fff" stroke="#171717" stroke-width="3"/><text x="145" y="182" text-anchor="middle">2. add filling</text>
<rect x="335" y="115" width="150" height="52" rx="10" fill="#fff" stroke="#171717" stroke-width="3"/><text x="410" y="147" text-anchor="middle">3. close it up</text>
<rect x="600" y="115" width="150" height="52" rx="10" fill="#eafaf0" stroke="#171717" stroke-width="3"/><text x="675" y="140" text-anchor="middle" fill="#2aa15a">DONE!</text><text x="675" y="158" text-anchor="middle" font-size="12" fill="#555">a sandwich</text></g>
<g stroke="#2aa198" stroke-width="4" fill="#2aa198"><path d="M145 132 L145 150"/><path d="M141 146 L145 156 L149 146Z"/><path d="M220 176 L335 145"/><path d="M331 140 L344 143 L332 150Z"/><path d="M485 141 L600 141"/><path d="M596 133 L610 141 L596 149Z"/></g>
</svg><div class="figcap">Exact steps, in the right order, turn a machine into a problem-solver. Miss a step and it fails.</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_grace"); 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/infosys/_head.html").read(); tail=open("/root/omahaindia.com/comics/site/book/infosys/_tail.html").read()
    open(OUT,"w").write(head+"".join(body)+hook+tail); print("built",OUT)
if __name__=="__main__": build()
