<!-- SOLID CITY · part 1267 -->
 return m;
})();

/* ---------------- sky, sun, stars, galaxy ---------------- */
var skyUni = { uAlt: { value: 0 }, uDip: { value: 0 }, uSun: { value: SUN_DIR } };
var sky = new T.Mesh(new T.SphereGeometry(1, 32, 20), new T.ShaderMaterial({
  uniforms: skyUni, side: T.BackSide, depthWrite: false, fog: false,
  vertexShader: 'varying vec3 vD; void main(){ vD = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); gl_Position.z = gl_Position.w*0.99999; }',
  fragmentShader: [
    'uniform float uAlt; uniform float uDip; uniform vec3 uSun; varying vec3 vD;',
    'void main(){',
    ' float e = vD.y + uDip;',             // elevation relative to the true horizon
    ' float space = smoothstep(9000.0, 60000.0, uAlt);',
    ' vec3 zen = vec3(0.035,0.02,0.07); vec3 mid = vec3(0.20,0.06,0.10); vec3 hor = vec3(0.95,0.45,0.18);',
    ' vec3 c = mix(hor, mid, smoothstep(0.0, 0.18, e)); c = mix(c, zen, smoothstep(0.12, 0.6, e));',
    ' c = mix(c, vec3(0.05,0.03,0.04), smoothstep(0.0,-0.25,e));',
    ' float s = max(dot(normalize(vD), normalize(uSun)), 0.0);',
    ' c += vec3(1.0,0.62,0.25) * pow(s, 9.0) * 0.55 + vec3(1.0,0.85,0.5) * smoothstep(0.9993, 0.9997, s);',
    ' vec3 spc = vec3(0.0) + vec3(1.0,0.85,0.55)*smoothstep(0.9993,0.9997,s);',
    ' float limb = exp(-abs(e)*55.0);',     // thin blue-gold limb seen from orbit
    ' spc += mix(vec3(0.2,0.45,1.0), vec3(1.0,0.5,0.2), 0.35) * limb * 0.9;',
    ' gl_FragColor = vec4(mix(c, spc, space), 1.0);',
    '}'].join('\n')
}));
sky.frustumCulled = false; sky.renderOrder = -10; scene.add(sky);
var stars = (function () {
  var N = MOBILE ? 2600 : 4200, G = MOBILE ? 4200 : 7000, pos = new Float32Array((N + G) * 3), col = new Float32Array((N + G) * 3), r2 = mulberry(77);
  var v = new T.Vector3(), c = new T.Color();
  for (var k = 0; k < N; k++) {
    v.set(r2() * 2 - 1, r2() * 2 - 1, r2() * 2 - 1).normalize(); pos.set([v.x, v.y, v.z], k * 3);
    var b = 0.45 + r2() * 0.55; c.setRGB(b, b * (0.85 + r2() * 0.15), b * (0.8 + r2() * 0.25)); col.set([c.r, c.g, c.b], k * 3);
  }
  // galaxy band: a tilted great circle with gaussian spread, red/gold/violet
  var ax = new T.Vector3(0.3, 0.85, 0.42).normalize(), u = new T.Vector3(1, 0, 0).cross(ax).normalize(), w = ax.clone().cross(u);
  for (k = 0; k < G; k++) {
    var a = r2() * Math.PI * 2, sp = (r2() + r2() + r2() - 1.5) * 0.16 * (1 + 0.6 * Math.sin(a * 3));
    v.copy(u).multiplyScalar(Math.cos(a)).addScaledVector(w, Math.sin(a)).addScaledVector(ax, sp).normalize();
    pos.set([v.x, v.y, v.z], (N + k) * 3);
    var h = r2(); c.setRGB(h < .4 ? 1 : h < .75 ? 0.95 : 0.7, h < .4 ? 0.55 : h < .75 ? 0.82 : 0.55, h < .4 ? 0.5 : h < .75 ? 0.5 : 1); c.multiplyScalar(0.35 + r2() * 0.5 * (1 - Math.abs(sp) * 3));
    col.set([c.r, c.g, c.b], (N + k) * 3);
  }
  var g = new T.BufferGeometry(); g.setAttribute('position', new T.BufferAttribute(pos, 3)); g.setAttribute('color', new T.BufferAttribute(col, 3));
  var m = new T.Points(g, new T.PointsMaterial({ size: MOBILE ? 1.6 : 1.4, sizeAttenuation: false, vertexColors: true, transparent: true, opacity: 0.4, depthWrite: false, fog: false }));
  m.frustumCulled = false; m.renderOrder = -9; scene.add(m);
  return m;
})();

/* ---------------- textures (canvas, no downloads) ---------------- */
function canvasTex(w, h, draw, repeat) {
  var c = document.createElement('canvas'); c.width = w; c.height = h; draw(c.getContext('2d'), w, h);
  var t = new T.CanvasTexture(c); t.encoding = T.sRGBEncoding; t.anisotropy = 4;
  if (repeat) { t.wrapS = t.wrapT = T.RepeatWrapping; t.repeat.set(repeat[0], repeat[1]); }
  return t;
}
var r3 = mulberry(4242);
// Solidivism motherboard floor
var TEX_BOARD = canvasTex(512, 512, function (g, w, h) {
  g.fillStyle = '#0a0809'; g.fillRect(0, 0, w, h);
  g.strokeStyle = 'rgba(120,20,30,.55)'; g.lineWidth = 2;
  for (var k = 0; k < 70; k++) { var x = r3() * w, y = r3() * h; g.beginPath(); g.moveTo(x, y); var hz = r3() < .5; var L = 40 + r3() * 160; g.lineTo(hz ? x + L : x, hz ? y : y + L); g.lineTo(hz ? x + L + 20 : x + 20, hz ? y + 20 : y + L + 20); g.stroke(); g.fillStyle = '#c99a3a'; g.fillRect(x - 3, y - 3, 6, 6); }
  g.strokeStyle = 'rgba(232,195,106,.18)'; g.lineWidth = 1; for (k = 0; k <= 8; k++) { g.beginPath(); g.moveTo(k * 64, 0); g.lineTo(k * 64, h); g.moveTo(0, k * 64); g.lineTo(w, k * 64); g.stroke(); }
  for (k = 0; k < 14; k++) { g.fillStyle = '#151214'; var cw = 30 + r3() * 50; g.fillRect(r3() * w, r3() * h, cw, cw * .6); }
}, [6, 6]);
// tower windows (emissive)
var TEX_WIN = canvasTex(128, 256, function (g, w, h) {
  g.fillStyle = '#000'; g.fillRect(0, 0, w, h);
  for (var y = 4; y < h; y += 10) for (var x = 4; x < w; x += 10) { var p = r3(); if (p < 0.3) { g.fillStyle = p < 0.08 ? '#ff3048' : p < 0.22 ? '#e8b04a' : '#5a3a20'; g.fillRect(x, y, 6, 5); } }
}, [1, 1]);
var TEX_BLDG = canvasTex(128, 256, function (g, w, h) {
  g.fillStyle = '#121014'; g.fillRect(0, 0, w, h);
  f