"""Editorial source for the illustrated reference. Documentation only."""
from pathlib import Path
import json

ROOT = Path(__file__).resolve().parent

SLICES = [
    {
        "number": 1, "id": "ILL-S01", "title": "Read the whole direction",
        "summary": "Begin with the promise of the experience, then choose the world, system, or object you want to inspect. The visual guide opens the complete writing; it does not replace it.",
        "paragraphs": [
            "SUBSTELLAR begins with a familiar place worth repairing. Gathering, making, travelling, discovering, and returning connect that place to a larger world. The underground is a geography of routes, water, life, resources, and communities. Space extends those same activities into environments with different demands.",
            "This illustrated overview gives every major content family a visible point of entry. Established text and supplied references remain intact. New concept boards show representative appearances and activities; diagrams explain the relationships; interface sheets show how the information could be presented. A representative board does not complete every dedicated object, region, or operating-state view.",
            "Read a chapter summary to understand its purpose, follow the related visuals, and open the full passage when you want the detail. Use stable section links when discussing a change. Browser review notes can be exported, while the text, catalogues, figure descriptions, and editable diagrams travel with the downloadable folder."
        ],
        "takeaways": ["A useful home and a dependable return make exploration meaningful.", "Depth, industry, and space are connected parts of one experience.", "The complete text remains the authority for names, relationships, and scope."],
        "chapters": ["The creative foundation", "The complete player journey", "Visual direction and the illustrated edition", "Source records and terminology"],
        "figures": [], "existing_visuals": ["solar-system", "progression"],
        "overview_result": "Ten reading guides, a chapter directory, a visual catalogue, and explicit coverage notes.",
        "still_dedicated": "Individual model views, regional variants, and final production assets retain their separate backlog."
    },
    {
        "number": 2, "id": "ILL-S02", "title": "Follow the workflows",
        "summary": "The diagrams and interface sheets make preparation, contribution, construction, travel, and return readable as sequences of decisions.",
        "paragraphs": [
            "Exploration supplies a reason to make something. A material becomes a fitting, a fitting improves a service, and that service changes the next journey. The existing progression chart relates industrial capability to the wider campaign. The new process figures trace the shorter loops inside it, including their alternatives and interruptions.",
            "Construction has visible stages and real material custody. The controller should explain what is needed, what has been supplied, what is committed, why work is blocked, and what the player can do next. Regional participation, shared ownership, and a useful return journal support the same experience when players leave and come back.",
            "Twelve interface references are grouped into four editable sheets: construction; community and return; navigation and preparation; and spacecraft, readiness, and accessibility. Their example screens illustrate the established information requirements. They are documentation layouts, with example states and any provisional quantities identified, rather than screenshots of an existing game interface."
        ],
        "takeaways": ["Useful outcomes connect the steps in each workflow.", "Blocked and paused states need understandable next actions.", "Diagrams and interface layouts use precise labels from the writing."],
        "chapters": ["Connected adventures and player experience", "Residents and settlement systems", "Tools equipment and preparation", "Power fuel and the cost of travel"],
        "figures": ["ILL-D02", "ILL-U01", "ILL-U02", "ILL-U03", "ILL-U04"],
        "existing_visuals": ["progression", "settlement-cycle", "resources-equipment"],
        "overview_result": "Construction-state figure and all twelve interface references on four sheets.",
        "still_dedicated": "Alternative screen sizes, every possible UI state, and final interaction assets are further visual work."
    },
    {
        "number": 3, "id": "ILL-S03", "title": "Make Old Valley useful",
        "summary": "The opening is a connected sequence of places and practical improvements: guesthouse, crossing, quarry, Copperwash, and the first workshop service.",
        "paragraphs": [
            "The guesthouse provides the first dependable return point. The authored crossing opens a route. The quarry introduces useful work and a bounded underground expedition. Copperwash Channels gives that expedition a local identity through pale rock, copper staining, roots, water, landmarks, and a readable return.",
            "The first workshop joins the Carpenter and repair bench, the Alloy hearth, and a hand-operated Hoist and lift installation. The bronze path turns accessible copper and planned tin into fittings for an improved cargo cradle. An iron alternative preserves the practical reward. The material-chain figure separates shared construction costs from preparation and shows why the two-stack hoist demonstration is useful.",
            "These scenes introduce Old Valley's later life. The full five-chapter sequence continues through a working settlement and the first market. A limited workshop service at the end of this opening does not silently complete the grain mill, wider service network, or market. The existing settlement-cycle diagram and full Old Valley chapter retain that longer progression."
        ],
        "takeaways": ["Each repaired place changes what the player can do.", "The first workshop creates a visible practical improvement.", "Settlements remain useful after their introductory story event."],
        "chapters": ["Old Valley", "Settlements and authored adventures", "First Playable — Old Valley, the Quarry, and the First Workshop"],
        "figures": ["ILL03-01", "ILL-D01", "ILL03-02", "ILL-D03"],
        "existing_visuals": ["EAR01_H", "settlement-cycle"],
        "overview_result": "Both commissioned opening boards, the route diagram, and the complete first-workshop material explanation.",
        "still_dedicated": "Final structure interiors, every construction stage, resident portraits, and the full market scene remain dedicated views."
    },
    {
        "number": 4, "id": "ILL-S04", "title": "Read Earth's second geography",
        "summary": "Seven realm identities contain thirty-five named experiences. Their transitions and lateral geography matter as much as their depth.",
        "paragraphs": [
            "The Overworld is the familiar home landscape. Shallows connects its roots and water to the first descent. Deepwilds concentrates living habitats. Underreach emphasizes mineral structure and working routes. Abyss introduces exposed voids and dark waters. Mantle makes heat and shelter legible. Core concludes the deep-crust journey through the fictional Heart environment.",
            "These are irregular regions with shelves, basins, pockets, and overlapping approaches. The additional geography figure explains this through a conceptual route and cross-section. It deliberately does not allocate permanent Y bands to the seven realms. The written working envelope remains 512 total block levels, from Y minus 192 through 319; it is not 512 blocks of underground depth.",
            "The existing Earth diagram lists every named experience and anchor. The retained Overworld, Deepwilds, Abyss, and four-realm overview art establish the major visual range. Read those pictures for terrain character, scale, shelter, and activity. The individual experience and transition views remain visible in the detailed visual register rather than being counted complete from a shared overview."
        ],
        "takeaways": ["Recognizable landforms and routes make the underground navigable.", "A region needs worthwhile activities and a dependable way home.", "The Core is the fictional Heart, not the literal planetary centre."],
        "chapters": ["The vertical world specification", "World generation and the Earth atlas", "Overworld", "Shallows", "Deepwilds", "Underreach", "Abyss", "Mantle", "Core"],
        "figures": ["ILL-D05"], "existing_visuals": ["earth-layers", "EAR01_H", "EAR03_H", "EAR05_H", "OV-EARTH"],
        "overview_result": "Realm comparison table, retained identity art, complete experience index, and an additional geography/route figure.",
        "still_dedicated": "A separate activity, refuge interior, and regional-variation view for every Earth experience remains beyond this overview pass."
    },
    {
        "number": 5, "id": "ILL-S05", "title": "Live through a Moon or Mars expedition",
        "summary": "Arrival, shelter, regional exploration, useful local work, and returning home give the existing destination chapters a clear visual sequence.",
        "paragraphs": [
            "The Moon starts with Earthrise Rim and Shadow Basin, then continues through Regolith Hollows, Basalt Galleries, and Glassfall Vaults. Its silence, dust, exposed routes, shelter, instruments, and protected supplies give familiar actions a different character. The first complete expedition arrives prepared from Earth; the lunar refuge is commissioned before the first committed underground descent.",
            "Mars joins Windcut Tablelands and Buried Delta to Ochre Galleries, Brine Scarps, and Rootstone Chambers. Weather, old drainage, field travel, and the Frontier Yard connect the surface to the underground. Materials and local services strengthen subsequent journeys without making local discoveries prerequisites for surviving the first arrival.",
            "The paired expedition figure sits alongside the existing layer diagrams and overview boards. Together they explain what the player does, what belongs to each region, and how the outpost supports the route. The complete Moon and Mars expansions retain the detailed expeditions, hazards, construction, progression, and revisit value."
        ],
        "takeaways": ["First-arrival supplies come from the world the player can already use.", "A refuge supports exploration and protects the return journey.", "Local materials improve sustained activity and create useful homecoming rewards."],
        "chapters": ["Moon", "Mars", "Moon — complete destination planning expansion", "Mars — complete destination planning expansion"],
        "figures": ["ILL-D06"], "existing_visuals": ["moon-layers", "mars-layers", "OV-MOON", "OV-MARS", "REF03"],
        "overview_result": "Complete regional comparison, existing layer/identity visuals, and a paired expedition workflow.",
        "still_dedicated": "Each outpost interior, weather condition, rover activity, and regional close-up remains a further illustration task."
    },
    {
        "number": 6, "id": "ILL-S06", "title": "Compare the farther worlds",
        "summary": "The destination atlas distinguishes each world's activities and purpose while preserving optional branches and the proposed continuation beyond Sol.",
        "paragraphs": [
            "Ceres makes fractured routes and anchored cargo work central. Europa places expeditions beneath ice in a pressure-shaped environment. Io turns thermal timing and shelter into practical fieldwork. Titan joins haze, shorelines, weather, and a useful harbour. Pluto closes the Solar System journey through cold, autonomy, instruments, and the Far Observatory.",
            "The proposed Afterlight continuation moves from Cairn's fractured places and interpretation to Morrow's living waters and cultivation. The existing overview boards already give these destinations distinct visual identities. This guide places their images, materials, signature projects, and campaign roles beside one another so their differences can be reviewed directly.",
            "The principal route remains Earth, Moon, Mars, Europa, Titan, and Pluto. Ceres and Io are optional branches. Cairn and Morrow remain a proposed later continuation. Mercury, Venus, Uranus, and Neptune retain their explicit further-design status; Jupiter and Saturn provide orbital and sky context for the documented moons. An atlas entry does not imply an additional completed landing campaign."
        ],
        "takeaways": ["Each destination changes the experience of preparation and fieldwork.", "Optional branches provide useful choices without becoming hidden universal gates.", "The atlas clearly separates documented campaigns, orbital context, and further design."],
        "chapters": ["Space exploration", "Ceres", "Europa", "Io", "Titan", "Pluto", "Afterlight", "Cairn", "Morrow"],
        "figures": [], "existing_visuals": ["solar-system", "OV-OUTER", "OV-FRONTIERS"],
        "overview_result": "One consistent destination comparison, annotated retained overview art links, and explicit scope for every represented body.",
        "still_dedicated": "Additional regional, outpost, interior, and activity images for the farther destinations remain named future work."
    },
    {
        "number": 7, "id": "ILL-S07", "title": "See how industry belongs in the world",
        "summary": "Machinery should look like useful equipment with a readable physical job. Its breadth grows through clear production relationships and distinct capabilities.",
        "paragraphs": [
            "The industrial catalogue contains sixty-six named functions across ten capability bands. Early craft becomes mechanical and powered workshops, attainable Tier 1 preparation, regional industry, deep thermal and chemical work, planetary services, and later specialist science. These bands are not rocket tiers or a requirement to finish every earlier machine before exploring.",
            "The early/regional board and the advanced board establish complementary visual languages. Benches, furnaces, forming equipment, power sources, loading, reaction vessels, optical work, composites, and optional advanced energy can share a coherent material vocabulary while retaining visibly different jobs. The network figure separates material flow, service power, storage, and freight.",
            "The full text provides the detailed machine roles and process narratives. An overview illustration makes the equipment easier to imagine; it does not approve unseen recipes or turn a decorative pipe into a new required process. Optional advanced industry remains optional, and first-flight preparation retains its accessible Earth-based path."
        ],
        "takeaways": ["A machine should explain its purpose through shape, access, material flow, and state.", "Shared services connect distinct processes without hiding their costs.", "Advanced machinery expands choices and sustained operations."],
        "chapters": ["Production transport and settlement technology", "Power fuel and the cost of travel", "Industry and progression", "Machinery and industrial systems", "Production chains, balance, and machine progression"],
        "figures": ["ILL03-03", "ILL-D04", "ILL03-04"], "existing_visuals": ["progression", "resources-equipment", "REF09", "REF10"],
        "overview_result": "Two machine-family boards, an industrial flow figure, and capability/role comparisons linked to the sixty-six-function catalogue.",
        "still_dedicated": "Individual orthographic, connection, and operating-state plates for every machine remain separate from representative family coverage."
    },
    {
        "number": 8, "id": "ILL-S08", "title": "Connect a resource to a useful object",
        "summary": "Materials, products, tools, and equipment belong to a clear gathering-to-use story. Their appearance should stay recognizable across different environments.",
        "paragraphs": [
            "The written catalogues cover nineteen Earth resource families, eighteen planetary materials, ten processed-product families, and thirty-two equipment families. They describe sources, uses, preparation, and the capabilities an object provides. These categories overlap with machinery and space-system entries; their totals are not a count of unique finished game assets.",
            "The material board distinguishes representative natural deposits, recovered samples, and processed appearances. The equipment board emphasizes recognizable silhouettes, working ends, carrying or attachment, and useful field roles. Existing suit and space-system references supply additional visual context. The figures and catalogues connect each pictured representative to its stable source identifier.",
            "Ore recognition, gathering, processing, and a worthwhile expedition should reinforce one another. A later material can improve a service without invalidating familiar resources. A loadout can answer a route's particular needs without becoming a universal gear score. Precise quantities remain in the relevant written example; the concept boards do not invent a new recipe table."
        ],
        "takeaways": ["Show a material's source, sample, and product as distinct useful forms.", "Equipment is organized around capabilities and preparation.", "A representative sheet introduces a visual family; dedicated item views stay indexed."],
        "chapters": ["Materials and the crafting economy", "Tools equipment and preparation", "Planetary materials and reference catalogue"],
        "figures": ["ILL03-05", "ILL03-06"], "existing_visuals": ["resources-equipment", "REF12", "REF15"],
        "overview_result": "Representative material and equipment boards, capability comparisons, and source-linked catalogue navigation.",
        "still_dedicated": "Every individual material sample, tool state, grip, attachment, and worn view retains its dedicated visual task."
    },
    {
        "number": 9, "id": "ILL-S09", "title": "Meet the living landscape",
        "summary": "Creature behaviour, useful plants, food, cultivation, encounters, and quiet activities make the world feel inhabited between major discoveries.",
        "paragraphs": [
            "The Earth roster contains twelve creature families, ten plant and fungal families, and four signature encounter proposals. Their identities include habitat, posture, behaviour, utility, and counterplay. Food, farming, fishing, gathering, and cultivation create reasons to return to a place and tend it.",
            "The creature board introduces representative silhouettes and behaviours at a readable player scale. The plant board connects habitat, harvestable growth, and cultivated forms. The retained Deepwilds image and realm art provide broader environmental context. Appearance proposed by a new board remains a visual interpretation of the written role, rather than a silent change to that role.",
            "Life is concentrated where habitat supports it. Quiet and sparse regions are part of the contrast. Encounters need recognizable signals and a useful player response, while a natural discovery or cultivated refuge can provide a satisfying expedition outcome without combat. The document's audio, weather, and presentation direction remains linked to these experiences."
        ],
        "takeaways": ["A habitat helps explain why a creature or plant is present.", "Behaviour and useful interaction matter as much as silhouette.", "Calm, domestic, and cultivated scenes belong beside danger and discovery."],
        "chapters": ["Life ecology and encounters", "Residents and settlement systems", "Connected adventures and player experience", "Deepwilds"],
        "figures": ["ILL03-07", "ILL03-08"], "existing_visuals": ["EAR03_H", "EAR01_H"],
        "overview_result": "Representative creature and plant boards, habitat/interaction notes, and links to the complete life and encounter catalogues.",
        "still_dedicated": "Each creature pose, warning behaviour, habitat, growth stage, encounter scene, and character portrait remains individually tracked."
    },
    {
        "number": 10, "id": "ILL-S10", "title": "Understand the Explorer as a complete expedition",
        "summary": "Your confirmed reference sheets connect the Explorer, its parts, preparation machines, equipment, and mission into one illustrated chapter.",
        "paragraphs": [
            "The Part Fabrication Table and Rocket Assembly Station have different jobs. Parts are prepared and checked, an authored vehicle is assembled in a linked berth, and the commissioned Explorer is supplied for its intended mission. The assembly figure connects those steps to the existing component and hardware references.",
            "The service figure distinguishes propellant, breathing supply, electrical power, and control. It also explains the relationship between the proposed craft envelope, pad, access, and cabin. The nine-block height, three-by-three body, and five-by-five fin envelope remain a proposed fit arrangement. The pad's half-block deck is distinct from its raised service pose. These labels describe the current design proposal rather than a measured finished model.",
            "The mission combines a working airlocked cabin, appropriate carried equipment, an Earth-prepared refuge, and protected return allocations. The first lunar landing uses supported natural ground, with no prebuilt lunar pad or factory required. The Moon workflow and mission-readiness interface complete the visual explanation of departure, fieldwork, and return. Tier 2 and Tier 3 retain their supplied overview artwork and deferred detailed expansion."
        ],
        "takeaways": ["The confirmed artwork anchors appearance while diagrams explain relationships.", "Assembly, services, access, cabin, cargo, and return readiness belong to one mission.", "Proposed dimensions and dedicated later-tier production views remain clearly identified."],
        "chapters": ["Spacecraft and orbital places", "Tier 1 space systems — complete first expedition", "Tier 1 — Model and Implementation Specifications"],
        "figures": ["ILL-D07", "ILL-D08"], "existing_visuals": ["REF01", "REF04", "REF09", "REF10", "REF11", "REF12", "REF15", "moon-layers"],
        "overview_result": "Source-linked hardware explanations, assembly and service diagrams, retained confirmed sheets, and mission/interface cross-links.",
        "still_dedicated": "Further exact cutaways, final model turnarounds, every operating-state view, and Tier 2/3 production art remain beyond this overview."
    }
]

CHAPTER_GUIDES = {
    "The creative foundation": (1, "The common promise: familiar survival, useful community, curiosity, and a place worth returning to."),
    "The complete player journey": (1, "Follow the long arc from the first descent to planetary exploration and the proposed Beyond Sol continuation."),
    "The vertical world specification": (4, "Understand the working height envelope and why named realms are not final universal depth bands."),
    "World generation and the Earth atlas": (4, "Read the common rules for regions, landforms, routes, resources, environmental cues, and authored placement."),
    "Overworld": (4, "The home landscape connects ordinary survival, useful settlements, and the first clues to the geography below."),
    "Shallows": (4, "Roots, chalk, water, mineral traces, and approachable routes establish the first underground expeditions."),
    "Deepwilds": (4, "Living habitats, dark intervals, cultivation, and a conservatory make the underground a landscape to revisit."),
    "Underreach": (4, "Mineral ridges, working routes, dark waterways, and a junction connect exploration to regional industry."),
    "Abyss": (4, "Exposed voids, water, pale shelves, and maintained refuge make visibility and return routes consequential."),
    "Mantle": (4, "Bounded heat, safe shelves, distinct mineral forms, and useful thermal work shape the deep expedition."),
    "Core": (4, "The fictional deep-crust Heart concludes Earth's strange geography through observation, shelter, and the observatory."),
    "Settlements and authored adventures": (3, "Useful places combine controlled structure identity, variable terrain, staged work, and optional player building."),
    "Old Valley": (3, "Read all five chapters, from the guesthouse and crossing to a working settlement and the first market."),
    "Residents and settlement systems": (3, "Residents, services, contribution, ownership, activity boundaries, and pause support a dependable shared place."),
    "Connected adventures and player experience": (2, "Discovery, journals, navigation, preparation, accessibility, and recovery connect individual expeditions."),
    "Life ecology and encounters": (9, "Creature and plant families, cultivation, food, encounters, lore, and sound give places their lived character."),
    "Materials and the crafting economy": (8, "Follow resources from recognizable deposits and gathering to processing, useful products, and enduring demand."),
    "Tools equipment and preparation": (8, "Choose excavation, traversal, light, navigation, protection, and supplies for a particular expedition."),
    "Production transport and settlement technology": (7, "Visible work, installations, transport, and useful automation connect local effort to a working settlement."),
    "Power fuel and the cost of travel": (7, "Understand the distinct supplies, preparation, habitat use, and protected allocations that support travel."),
    "Space exploration": (6, "The wider journey keeps recognizable destinations, optional branches, preparation, and reliable return."),
    "Moon": (5, "The original lunar profile establishes its regions and identity; the later expansion supplies the complete destination plan."),
    "Mars": (5, "The original frontier profile introduces weather, drainage, regions, and outpost work; the later expansion adds the full plan."),
    "Ceres": (6, "An optional industrial branch turns fractured ground, anchoring, routes, and cargo into distinctive fieldwork."),
    "Europa": (6, "The ice and Lantern Ocean require preparation, pressure-aware refuge, and a readable expedition beneath the surface."),
    "Io": (6, "An optional thermal branch uses timing, sheltered routes, and bounded working conditions to make difficult ground useful."),
    "Titan": (6, "Haze, shorelines, weather, and unusual material landscapes support a different kind of harbour and expedition."),
    "Pluto": (6, "Cold, autonomy, navigation, and the Far Observatory provide a satisfying Solar System conclusion."),
    "Afterlight": (6, "The proposed continuation beyond Sol introduces Cairn and Morrow while preserving a meaningful earlier stopping point."),
    "Cairn": (6, "Fractured places, interpretation, routes, and the Witness Engine define this proposed later investigation."),
    "Morrow": (6, "Living waters, observation, cultivation, and a useful conservatory turn the proposed later discovery into a place to tend."),
    "Spacecraft and orbital places": (10, "Read the broader vehicle and station roles alongside the confirmed Explorer reconciliation and later-tier deferrals."),
    "Planetary materials and reference catalogue": (8, "Compare local materials and what they improve without making first-arrival survival depend on them."),
    "Visual direction and the illustrated edition": (1, "The original palette, geometry, view requirements, and commissioning register explain the full illustration programme."),
    "Turning the creative direction into a future roadmap": (1, "The source explains how a later roadmap can select complete experiences from this reference."),
    "Source records and terminology": (1, "Source provenance and shared terms distinguish the established direction from historical context and proposed detail."),
    "Industry and progression": (7, "Ten industrial capability bands connect useful work to exploration, including an attainable early flight branch."),
    "Machinery and industrial systems": (7, "The complete sixty-six-function catalogue describes purpose, physical process, relationships, and limits."),
    "Production chains, balance, and machine progression": (7, "Example chains explain accessible first uses, optional efficiencies, interruption, and meaningful industrial choices."),
    "Moon — complete destination planning expansion": (5, "The complete lunar chapter joins arrival, regions, refuge, materials, industry, expeditions, recovery, and revisits."),
    "Mars — complete destination planning expansion": (5, "The complete frontier chapter joins regions, weather, travel, camps, the Frontier Yard, materials, and expeditions."),
    "Tier 1 space systems — complete first expedition": (10, "The Explorer and its machines, parts, equipment, supplies, services, and mission are described as one complete journey."),
    "First Playable — Old Valley, the Quarry, and the First Workshop": (3, "The bounded opening connects three essential Old Valley chapters, Copperwash, and a practical workshop improvement."),
    "Tier 1 — Model and Implementation Specifications": (10, "The reference translates confirmed appearance into proposed asset, component, connection, assembly, state, and fit specifications.")
}

EARTH = [
    ("Overworld", "Bluewater Quarry Coast; Rooted Uplands; Rivergate Country; Windscar Heights; Rainwood Hollows", "Home, repair, familiar gathering, and the first descent", "EAR01_H"),
    ("Shallows", "Rootlace Galleries; Chalkstep Terraces; Copperwash Channels; Glasswell Pools; Drybell Vaults", "Readable early routes, roots, water, and mineral traces", "OV-EARTH"),
    ("Deepwilds", "Lanternroot Forests; Sporemeadow Basins; Hanging Gardens; Bluefen Groves; Quietwood Hollows", "Living habitats, gathering, cultivation, and shelter", "EAR03_H"),
    ("Underreach", "Ironfold Ridges; Saltmirror Halls; Blackriver Galleries; Echoquartz Fields; Dustroad Expanse", "Mineral structure, work, transport, and regional connection", "OV-EARTH"),
    ("Abyss", "Pillarfall Reaches; Stillsea Basin; Moonmilk Shelves; Whisper Chasms; Drowned Stair Country", "Exposed routes, dark water, light, and maintained refuge", "EAR05_H"),
    ("Mantle", "Basalt Steps; Ember Gardens; Ashen Hollows; Redglass Margins; Steamvaults", "Thermal margins, safe shelves, preparation, and useful heat", "OV-EARTH"),
    ("Core", "Heartglass Groves; Pale Resonance Fields; Stillwater Sanctuaries; Blackroot Islands; The Heart Chamber", "Observation, strange materials, sanctuary, and the Heart", "OV-EARTH")
]

DESTINATIONS = [
    ("Moon", "Principal journey", "Earthrise Rim; Shadow Basin; Regolith Hollows; Basalt Galleries; Glassfall Vaults", "Arrival, refuge, survey, and a prepared return", "OV-MOON"),
    ("Mars", "Principal journey", "Windcut Tablelands; Buried Delta; Ochre Galleries; Brine Scarps; Rootstone Chambers", "Weather, routes, frontier work, and the Frontier Yard", "OV-MARS"),
    ("Ceres", "Optional branch", "Four documented regional experiences", "Anchored cargo work and fractured routes", "OV-OUTER"),
    ("Europa", "Principal journey", "Four documented regional experiences", "Ice, ocean pressure, refuge, and protected fieldwork", "OV-OUTER"),
    ("Io", "Optional branch", "Four documented regional experiences", "Thermal timing, shelter, and a bounded working site", "OV-OUTER"),
    ("Titan", "Principal journey", "Four documented regional experiences", "Haze, shorelines, weather, and a useful harbour", "OV-OUTER"),
    ("Pluto", "Solar System conclusion", "Four documented regional experiences", "Cold, navigation, autonomy, and the Far Observatory", "OV-FRONTIERS"),
    ("Cairn", "Proposed Afterlight continuation", "Four documented regional experiences", "Interpretation, fractured routes, and the Witness Engine", "OV-FRONTIERS"),
    ("Morrow", "Proposed Afterlight continuation", "Four documented regional experiences", "Living waters, cultivation, and an enduring conservatory", "OV-FRONTIERS")
]

def build():
    scope = json.loads((ROOT/'illustrated_03_scope_data.json').read_text())
    exact_destinations = {d['name']:d for d in scope['destinations']}
    data = {
        "edition": "Illustrated overview 03", "scope": "Balanced illustrated document website; all ten editorial and visual slices.",
        "image_board_cap": 8, "prior_source_words_preserved": 88193,
        "detailed_view_policy": "Representative overview coverage does not complete all dedicated views in the original commissioning register.",
        "slices": SLICES,
        "chapter_guides": [{"title": title, "slice": pair[0], "summary": pair[1]} for title, pair in CHAPTER_GUIDES.items()],
        "earth_regions": [{"realm": r, "experiences": e.split('; '), "experience": a, "art": v} for r,e,a,v in EARTH],
        "destinations": [{**exact_destinations[n], "role": role, "experience": exp, "art": art} for n,role,regions,exp,art in DESTINATIONS],
        "planetary_ecology": scope['planetary_ecology'],
        "planetary_ecology_scope": scope['scope_notes']
    }
    (ROOT/'illustrated_editorial.json').write_text(json.dumps(data,ensure_ascii=False,indent=2))
    lines = ["# Illustrated overview — ten reading guides", "", "This companion opens the complete reference through ten editorial and visual guides. Every earlier text source and artwork file remains preserved. Concept boards are representative overview illustrations; diagrams and interface sheets carry the precise relationships described in the writing.", ""]
    for s in SLICES:
        lines += [f"## {s['id']} — {s['title']}", "", s['summary'], ""]
        for p in s['paragraphs']: lines += [p, ""]
        lines += ["### What to look for", ""]
        lines += ["- "+x for x in s['takeaways']]
        lines += ["", "Overview coverage: "+s['overview_result'], "", "Dedicated views still tracked: "+s['still_dedicated'], ""]
    (ROOT/'illustrated_companion.txt').write_text('\n'.join(lines))
    print(json.dumps({"slices":len(SLICES),"chapter_guides":len(CHAPTER_GUIDES),"earth_experiences":sum(len(x['experiences']) for x in data['earth_regions'])}))

if __name__ == '__main__': build()
