...
``` Now the CSS details. I'll write a decent amount. HUD structure: ```
GALACTIC COLONY
DAY 03 · CYCLE 07/16
SELF-SUSTAIN
...
``` Build buttons: each shows name, cost, count/max, level pips, and effect summary. Clicking builds. Upgrades via a separate small "▲ UPG" button per type. To keep the bottom bar from being too crowded: 7 build buttons in a row with compact cards. Plus a row of action buttons (Repair, O2 Purge, Ration, Core Boost). Let me now write JS carefully. ```js const TYPES = [ 'hab','solar','green','mine','lab','shield','med' ]; ``` defs object with: name, max, base cost {min, res}, prod function, powerCost, cap, color, icon, desc. state: ``` let S; function newGame(){ S = {day:1,cycle:0, o2:70,maxO2:110? ...} } ``` maxO2 computed from habitats: maxO2 = 60 + 12*sumHabTier. Start with 1 habitat tier1 = 12 → 72. Hmm start O2 70/72 nearly full. Let's maxO2 = 60 + 10*sumHabTier. Start 1 hab → 70. Start O2 = 60. Fine. maxPower = 40 + 9*solarCount + 6*sumSolarTier? Let's do maxPower = 40 + 12*sumSolarTier (tier1 each = 1) → 1 solar = 52. power start 30. Buildings array: each entry {type, tier, dmg, born(t), id, animSeed}. Counts: count(type), sumTier(type). Production: - solar: p = 3.4 * tierMul(tier) * (1-0.3*dmg) * weather.solar - green: food 1.9*tierMul, o2 0.5*tierMul, powerCost 1.0*tierMul*0.8? Keep powerCost flat per building times tierMul? Higher tier consumes more but produces more. Use powerCost * (0.7+0.45*tier)? Simpler: powerCost * tierMul where tierMul = [0,1,1.6,2.3][tier]. So tierMul also multiplies powerCost. Ratio stays same. Fine. - green: tierMul for power 1.0 - mine: min 2.4, power 1.3 - lab: res 1.3, power 1.5 - shield: coverage (tier) ; power 2.0 - med: cures tier*1 ; power 1.2 - hab: o2 recycler 0.4 per tier; cap 4 + tier (t1=5,t2=6,t3=7) tierMul = [0,1,1.6,2.3]. Colonist consumption: food 0.055/person, o2 0.035/person. Growth conditions: food > pop*0.55, o2 > pop*0.45, pop < cap, disease < pop*0.3 → chance 0.055 + labCount*0.004 per cycle. Supply drop can add 1-2 colonists (arrivals) if cap available. Now events object with active list: each active has {kind, cyclesLeft, mult}. weather.solar computed from actives. Let me write the event system: ``` const EVENTS=[ {id:'meteor', w:1.0, name:'METEOR SHOWER', apply(){...}}, ... ] ``` apply returns log message. Some events create visual state (S.fx.meteor = cycles etc.). Visual weather state: S.wx = {solar:1, dust:0, flare:0, raid:0, meteor:0, storm particles...} I'll keep arrays of particles for rendering: meteors[], dustP[], ships[]. Rendering of events: when event fires, spawn particles; they decay over their own life. OK, writing final code. Also need start screen + pause? Not required. Restart button: on game-over panel, and also an "ABORT/RESET" small button. localStorage key 'galactic_colony_best' storing {day, score}. Let me write out the whole thing now, then review. One more: "Build buttons with increasing costs" — cost scales with number built of that type: cost = base * 1.5^count. Also mineral income: start 90 minerals, mine gives 2.4*tierMul each cycle. Plus supply drops. Player must spend minerals on buildings; strategy = build solar+greenhouse early, then mine for minerals to fund bigger structures. Good. Research: needed for greenhouse(5), mine(10), lab(12)... but you can't build a lab without research? Lab costs 70 min + 12 res — research comes only from labs and breakthrough events. Problem: chicken-egg. Fix: research also produced passively by... let's give lab cost 0 res, and add research from "first discovery" — simpler: Lab costs minerals only (90 min). And research is produced by labs, then spent on greenhouse/mine upgrades and actions. But mine costs 10 res and you can't get res before mine... greenhouse gives food only. So: research sources = Lab (buildable with minerals only) + breakthrough events. Mine costs research 10 — you need a lab first (lab 90 min). Start minerals 90 → build lab → get research → build mine. That works and is a nice tech gate. Let me set start minerals 110 so you can build solar(35)+green(55)... hmm ordering matters. Let me set starting: minerals 140, and costs: solar 30, hab 45, green 50+4res, mine 55+8res, lab 75, shield 85+16res, med 70+14res. Start: 1 habitat pre-built (tier1) so pop cap 5? But pop 12 > cap 5 → colonists beyond cap cause distress (overcrowding penalty). Start with 2 habitats pre-built (cap 10) and pop 10. Hmm keep pop 10, cap 10. Let me finalize start: - Buildings pre-built: 2 hab (t1), 2 solar (t1), 1 green (t1), 1 mine (t1)? Mine needs res. Let's pre-build: 2 hab, 2 solar, 1 green. Pop 10. O2 62/80 (maxO2 = 60+10*2=80). Power 34/maxPower 40+12*2=64. Food 55. Minerals 140. Research 6. - Demand: green 1.0 → fine. Power gain 6.8/cycle. O2 drain: 10*0.035=0.35; green o2 0.5 + hab 0.4*2=0.8 → +0.95/cycle → O2 hits cap. Good, O2 stable early. Food drain 0.55 vs 1.9 → fine. Events will create pressure. Nice. Day 30 at 16 cycles/day, 1000ms/cycle = 480 cycles = 8 min. Good. Let me also add speed: default 1000ms; add "×2 speed" toggle button? Optional; include a "FAST-FORWARD" toggle for players who want faster days. I'll include it (nice QoL, shows polish). Now, self-sustain win: requires 22 infra? I set infrastructure = min(totalBuildings/20,1)*15. Total possible buildings = 6+8+7+6+6+4+3 = 40 max. Requiring 20 total buildings is a mid-game thing; combined with all upgrades (20 levels*0.5=10 cap) → 100. Let's require: lifeSupport 30 + food 25 + power 20 + infra 15 + safety 10 = 100 max, minus penalties. So reaching 100 needs everything near-max. With 20+ buildings and ~20 upgrade levels. Cost of 20 buildings + 20 upgrades is substantial (~1500 minerals) — at 3 mines tier2 (~7.7/cycle) → ~200 cycles. Plus day-30 = 480 cycles. Feasible. Good, both win paths viable. Actually careful: penalties make 100 hard; that's fine as it's the fast-win alt. Also add "upgrades" counted: sum(tier-1) * 0.5, cap 10. Let me write the code. For rendering buildings I'll write functions drawHab(ctx,x,y,s,seed,t,tier,dmg) etc. Keep them reasonably detailed. Also mining machine animation: drill rotating, dust puff particles spawned occasionally from mine buildings. Colonist activity: walking, occasional work sparks at buildings. Let me write. I'll now produce the full file. I need to be careful about JS syntax errors. Write methodically. Also: alerts toast — a DOM element with animation. Let me write the code in final form. For the HUD, use CSS grid with pointer-events none on the container except panels. I'll write: ```css :root{--cyan:#5ff2ff;--amber:#ffb24d;--green:#6dff8f;--red:#ff4d6d;--violet:#b98cff;--ink:#04080f;} ``` Panels: `background: linear-gradient(...) , rgba(6,12,22,.72); backdrop-filter: blur(6px); border:1px solid rgba(...); box-shadow: glow;` Resource cards: name, value, bar, delta. Build buttons: use buttons with `data-type`. On click, attempt build. Let me handle keyboard? Not needed. Let me write the log: array of {t, msg, sev, day}. Render last 7 as DOM nodes, newest on top with fade-in animation. Now the code. Also "Alerts" — big banner for critical events (win/lose/blackout). Let me produce final answer with full file. I'll double-check logic after writing. Writing render loop with requestAnimationFrame and delta time; sim ticks accumulate via accumulator using tickMs. Let me write the code now in full. Potential pitfall: `Math.max(0, available - demand*eff)` when eff<1 gives 0 — good. Blackout: eff < 0.02 → blackoutCycles++ else if eff<0.4 → warn. Hmm but if demand is 0 (no consumers) eff=1, power builds up. Good. Lose when power literally 0: I'll say if eff<0.02 (i.e., power 0 and demand>0) blackoutCycles++; at 6 → lose. Also show countdown "LIFE SUPPORT FAILURE IMMINENT 3". Also if o2 <= 0: suffocation cycles; at 6 → lose. Colonists death: when o2<=0, each cycle lose 1 colonist (if pop>0) — and if pop==0 → lose immediately. Alright, writing. For canvas resize: `function fit(){ const dpr=Math.min(2,devicePixelRatio||1); cvs.width=W*dpr; ... ctx.setTransform(dpr,0,0,dpr,0,0) }` where W=window.innerWidth, H=innerHeight. Use CSS full viewport. Positions computed from W,H each frame — fine. Stars: precompute array of {x:rand,y:rand*0.62,r,tw,phase} in normalized coords, multiply by W/H. Terrain: procedural ridge path precomputed normalized points, drawn with W,H. Let me write ridge: two layers of jagged mountains using normalized arrays generated with seeded random. Seeded rng: mulberry32. OK writing final. Let me go. I'll include a "night cycle"? No, planet is tidally locked-ish; keep sky shifting hue slowly. Final code writing — long but structured. Let me be efficient and clear. Let me draft the JS sim functions: ```js const DEFS={ hab:{name:'Habitat',max:6,min:45,res:0,pw:0,icon:'⌂',col:'#7fe3ff', prod:{o2:0.4},cap:4, blurb:'Life support + O₂ recycler. Houses colonists.'}, solar:{name:'Solar Array',max:8,min:30,res:0,pw:0,icon:'▤',col:'#ffc861', prod:{power:3.4}, blurb:'Generates power. Weak in dust storms, boosted by flares.'}, green:{name:'Greenhouse',max:7,min:50,res:4,pw:1.0,icon:'❒',col:'#69e08a', prod:{food:1.9,o2:0.5}, blurb:'Grows food and scrubs oxygen. Draws power.'}, mine:{name:'Mine',max:6,min:55,res:8,pw:1.3,icon:'⛏',col:'#c8a06a', prod:{min:2.4}, blurb:'Extracts minerals. Needs a Lab for research unlocks.'}, lab:{name:'Lab',max:6,min:75,res:0,pw:1.5,icon:'◈',col:'#8fb9ff', prod:{res:1.3}, blurb:'Generates research. Unlocks advanced structures.'}, shield:{name:'Shield Gen',max:4,min:85,res:16,pw:2.0,icon:'⛨',col:'#b98cff', prod:{}, blurb:'Deflects alien raids. Heavy power draw.'}, med:{name:'Med Bay',max:3,min:70,res:14,pw:1.2,icon:'✚',col:'#ff8ea6', prod:{}, blurb:'Cures disease and stabilises colonists.'}, }; ``` buildCost(type) = {min: base.min*1.55^n, res: base.res*1.45^n}. upgradeCost(type) = {min: base.min*1.1* (1.7^currentTier), res: max(4, base.res)*0.9*(1.6^tier)}. tierMul = [0,1,1.6,2.3]. Now sim tick code. Write it. Also need `S.fx` for visual events and `S.wx` for modifiers. Let me write it all out now. For the "colony health score" I'll name it "COLONY INTEGRITY" (0-100) and "SURVIVAL SCORE" for records. Let me write the final HTML. I'll take care to close all tags and braces. After writing, review checklist: - newGame resets everything - start screen: state 'title'; canvas runs idle anim (buildings from a demo set? just pre-built colony) - start button → state 'play' - tick only in play - win/lose → state 'over', show summary, restart button - best record saved - fast speed toggle - log - upgrades with pips Go. One detail: colonist rendering count — cap drawn colonists at ~28 for perf; use pop for logic. Dust storm particles: cap 160. Let me write render functions compactly but with flair. drawHab(x,y,s,seed,tier,dmg): dome with arcs, windows lit, antenna beacon. drawSolar: pylon + 3 tilted panels with glint sweep; rotate slightly with wind. drawGreen: glass dome with grid, plants inside pulsing, base ring. drawMine: A-frame derrick, rotating drill bit, cart on rail moving back and forth, dust puffs. drawLab: hexagonal module + rotating holo dish + scan beam. drawShield: tapered tower with 3 rotating rings, coil glow; when active, dome energy arcs. drawMed: rounded dome + cross emblem + pulsing ring + stretcher light. I'll implement helper `glowCircle(x,y,r,color,alpha)`. Time to write final answer. Regarding the "Repair" action: cost = 12 + 9*totalDamage minerals. Repairs all. Good. Actions: - REPAIR (min) - O₂ PURGE: 12 res → +30 o2 - RATION: 8 res → +26 food - CORE VENT: 18 res → +45 power (immediately add to power pool) Also "COLONIST CALL" no. Also maybe "Emergency Mine Scan": 10 res → +18 minerals. Add as "SURVEY". Four actions is fine: Repair, O₂ Purge, Ration, Core Vent, Survey (5). Good. Now write. For the gauge display of self-sustain: a horizontal bar with ticks + number, plus "STABLE" glow at 100. Alright, final code. I'll write the log messages with day/cycle stamps. Also alerts: `alert(msg,sev)` pushes log + shows toast for crit. Let me write the code out. Also I must ensure the game is interactive/strategic: player must manage brownouts by building solar, and repair after raids. Yes. Let me write CSS for build button disabled state (opacity .45, cursor not-allowed) and a "flash" success animation: on successful build, add class 'ok' briefly then remove; error → shake + red. Implement via JS toggling classes with setTimeout. Final: write it. I'll now carefully produce the file. ```html Galactic Colony
GALACTIC COLONYSECTOR 7 · VESPER-9 OUTPOST
SELF-SUSTAIN INDEX
0%
DAY 01 · CYCLE 0/16
COLONY INTEGRITY
100%
SURVIVAL SCORE 0 · BEST 0
TRANSMISSION LOG
    GALACTIC COLONYCOLONISE THE DEAD WORLD · SURVIVE 30 DAYS
    You woke the outpost on Vesper-9: thin oxygen, cold sun, hostile natives.
    Build power and food first, then mines, labs and shields. Watch for brownouts, raids, storms and disease.
    Win: survive 30 days, or push the SELF-SUSTAIN INDEX to 100%. Lose: colonists, oxygen or power collapse.
    FIELD MANUAL
    Order of operations: Solar → Greenhouse → Mine → Lab → Shield → Med Bay.