<!-- SOLID CITY · part 3428 -->
---------
   Polished chrome, black-and-red marble, twin lightning. All canvas-generated:
   no image files, no network, featherweight. Per the King's clarification these
   textures/materials are for INTERIOR surfaces (in this module: the hangar's
   floor and the inner face of its back wall); the kit exports them so future
   builders can finish interiors the same way. Never on exteriors or terrain. */
function makeCanvas(w, h) { var c = document.createElement('canvas'); c.width = w; c.height = h; return c; }

function marbleTexture(T, size) {
  size = size || 512;
  var c = makeCanvas(size, size), g = c.getContext('2d');
  g.fillStyle = '#07070a'; g.fillRect(0, 0, size, size);
  var i, x, y, r;
  // deep stone clouds
  for (i = 0; i < 46; i++) {
    x = Math.random() * size; y = Math.random() * size; r = 40 + Math.random() * 130;
    var rg = g.createRadialGradient(x, y, 0, x, y, r);
    var warm = Math.random() < 0.4;
    rg.addColorStop(0, warm ? 'rgba(38,12,16,0.20)' : 'rgba(26,28,36,0.22)');
    rg.addColorStop(1, 'rgba(0,0,0,0)');
    g.fillStyle = rg; g.beginPath(); g.arc(x, y, r, 0, 7); g.fill();
  }
  function vein(colorCore, colorEdge, width, steps) {
    var px = Math.random() * size, py = Math.random() * size, ang = Math.random() * Math.PI * 2;
    for (var rep = -1; rep <= 1; rep++) for (var rep2 = -1; rep2 <= 1; rep2++) {
      if (rep === 0 && rep2 === 0) { /* drawn below in main pass */ }
    }
    g.lineJoin = 'round'; g.lineCap = 'round';
    for (var pass = 0; pass < 2; pass++) {
      g.strokeStyle = pass ? colorCore : colorEdge; g.lineWidth = pass ? width * 0.45 : width;
      for (var off = -1; off <= 1; off++) for (var off2 = -1; off2 <= 1; off2++) {
        // re-walk the same vein at tile offsets so the texture wraps seamlessly
        var sx = px + off * size, sy = py + off2 * size, a = ang;
        g.beginPath(); g.moveTo(sx, sy);
        var vx = sx, vy = sy;
        for (var s2 = 0; s2 < steps; s2++) {
          a += (Math.random() - 0.5) * 0.9;
          vx += Math.cos(a) * (size / steps) * 1.7; vy += Math.sin(a) * (size / steps) * 1.7;
          g.lineTo(vx, vy);
          if (Math.random() < 0.16) { // a short branch vein
            var bx = vx, by = vy, ba = a + (Math.random() < 0.5 ? 0.8 : -0.8);
            g.moveTo(bx, by);
            for (var b = 0; b < 3; b++) { ba += (Math.random() - 0.5) * 0.7; bx += Math.cos(ba) * 14; by += Math.sin(ba) * 14; g.lineTo(bx, by); }
            g.moveTo(vx, vy);
          }
        }
        g.stroke();
      }
    }
  }
  for (i = 0; i < 13; i++) vein('rgba(226,44,64,0.55)', 'rgba(140,12,28,0.40)', 3.2, 26);   // RED veins — the King's marble
  for (i = 0; i < 6; i++) vein('rgba(190,200,215,0.20)', 'rgba(120,130,150,0.12)', 1.6, 22);  // faint silver veins
  var t = new T.CanvasTexture(c);
  t.wrapS = t.wrapT = T.RepeatWrapping; t.anisotropy = 4;
  if (T.sRGBEncoding !== undefined) t.encoding = T.sRGBEncoding;
  return t;
}

function lightningBolt(g, x0, y0, x1, y1, jag, seed) {
  // midpoint-displacement bolt: realistic jagged path from (x0,y0) to (x1,y1)
  var pts = [[x0, y0], [x1, y1]];
  var s = seed || 1;
  function rnd() { s = (s * 16807) % 2147483647; return s / 2147483647; }
  for (var iter = 0; iter < 6; iter++) {
    var next = [pts[0]];
    for (var i = 0; i < pts.length - 1; i++) {
      var a = pts[i], b = pts[i + 1];
      var mx = (a[0] + b[0]) / 2, my = (a[1] + b[1]) / 2;
      var dx = b[0] - a[0], dy = b[1] - a[1], len = Math.hypot(dx, dy) || 1;
      var off = (rnd() - 0.5) * jag * len;
      next.push([mx + (-dy / len) * off, my + (dx / len) * off]);
      next.push(b);
    }
    pts = next;
  }
  g.beginPath(); g.moveTo(pts[0][0], pts[0][1]);
  for (var j = 1; j < pts.length; j++) g.lineTo(pts[j][0], pts[j][1]);
  g.stroke();
  return pts;
}

function lightningTexture(T, size) {
  size = size || 512;
  var c = makeCanvas(size, size), g = c.getContext('2d');
  // dark storm-marble backdrop so the emblem blends with the marble surfaces
  g.fillStyle = '#0a0a10'; g.fillRect(0, 0, size, size);
  for (var i = 0; i < 22; i++) {
    var x = Math.random() * size, y = Math.random() * size, r = 30 + Math.random() * 90;
    var rg = g.createRadialGradient(x, y, 0, x, y, r);
    rg.addColorStop(0, 'rgba(24,26,38,0.25)'); rg.addColorStop(1, 'rgba(0,0,0,0)');
    g.fillStyle = rg; g.beginPath(); g.arc(x, y, r, 0, 7); g.fill();
  }
  g.lineJoin = 'round'; g.lineCap = 'round';
  function drawTwin() {
    // TWIN bolts — two strikes side by side, the King's motif
    var bolts = [
      { x0: size * 0.40, x1: size * 0.34, seed: 1237 },
      { x0: size * 0.62, x1: size * 0.68, seed: 8911 }
    ];
    for (var pass = 0; pass < 3; pass++) {
      for (var b = 0; b < bolts.length; b++) {
        var bt = bolts[b];
        if (pass === 0) { g.strokeStyle = 'rgba(110,190,255,0.30)'; g.lineWidth = size * 0.045; g.shadowColor = '#6fc4ff'; g.shadowBlur = size * 0.07; }
        if (pass === 1) { g.strokeS