<!-- LIVE · part 91 -->
(hit.object.matrixWorld)
      : new THREE.Vector3(0,1,0);

    normal.normalize();

    var dot = Math.max(-1, Math.min(1, normal.dot(new THREE.Vector3(0,1,0))));
    var slope = Math.acos(dot) * 180 / Math.PI;

    return {
      hit:true,
      valid:slope <= maxSlope,

      point:hit.point.clone(),
      height:hit.point.y,
      normal:normal,
      slope:slope,

      surface:entry,
      kind:entry ? entry.kind : 'unknown',

      playerDelta:position.y - hit.point.y,
      rayDistance:hit.distance
    };
  };

  /*
   * Separate long-range query.
   *
   * This is intentionally NOT supportBelow().
   * Later this can be used for spawning, LAND, teleport validation,
   * recovery, etc.
   */
  WF.findLandingSurface = function(x, z, searchTopY, options){
    options = options || {};

    var maxSlope =
      options.maxSlope === undefined ? 60 : options.maxSlope;

    if(WF.colliders.length === 0){
      return {
        hit:false,
        valid:false,
        reason:'no_surfaces'
      };
    }

    var origin = new THREE.Vector3(x, searchTopY, z);
    var meshes = WF.colliders.map(function(e){ return e.mesh; });

    ray.set(origin, DOWN);
    ray.near = 0;
    ray.far = Math.max(0, searchTopY - WF.killY);

    var hits = ray.intersectObjects(meshes, false);

    if(!hits.length){
      return {
        hit:false,
        valid:false,
        reason:'no_landing_surface'
      };
    }

    var hit = hits[0];
    var entry = WF.colliderByUUID[hit.object.uuid] || null;

    var normal = hit.face
      ? hit.face.normal.clone().transformDirection(hit.object.matrixWorld)
      : new THREE.Vector3(0,1,0);

    normal.normalize();

    var dot = Math.max(-1, Math.min(1, normal.y));
    var slope = Math.acos(dot) * 180 / Math.PI;

    return {
      hit:true,
      valid:slope <= maxSlope,
      point:hit.point.clone(),
      height:hit.point.y,
      normal:normal,
      slope:slope,
      surface:entry,
      kind:entry ? entry.kind : 'unknown'
    };
  };

  /*
   * Register the known 20,000 x 20,000 base plane.
   * Observation only — nothing on the mesh is changed.
   */
  WF.findBasePlane = function(){
    var candidate = null;

    scene.traverse(function(obj){
      if(candidate) return;

      if(
        obj &&
        obj.isMesh &&
        obj.geometry &&
        obj.geometry.type === 'PlaneGeometry'
      ){
        var params = obj.geometry.parameters || {};
        var w = Number(params.width || 0);
        var h = Number(params.height || 0);

        if(w >= 19000 && h >= 19000){
          candidate = obj;
        }
      }
    });

    return candidate;
  };

  WF.registerBasePlane = function(){
    var plane = WF.findBasePlane();
    if(!plane) return null;

    return WF.registerSurface(
      plane,
      'ground',
      {name:'base_plane'}
    );
  };

  /*
   * Mountains already have an existing authoritative runtime list:
   * window._mountains.
   *
   * We observe that list. We DO NOT sweep arbitrary scene geometry
   * and declare it walkable.
   */
  WF.syncMountains = function(){
    var list = window._mountains || [];
    var added = 0;

    for(var i=0; i<list.length; i++){
      var mesh = list[i];

      if(
        mesh &&
        mesh.isMesh &&
        mesh.userData &&
        mesh.userData.isSolidTerrain &&
        !WF.colliderByUUID[mesh.uuid]
      ){
        WF.registerSurface(
          mesh,
          'terrain',
          {name:'mountain'}
        );
        added++;
      }
    }

    return added;
  };

  WF.ensureDebugger = function(){
    var el = document.getElementById('world-foundation-debug');

    if(el) return el;

    el = document.createElement('div');
    el.id = 'world-foundation-debug';

    el.style.cssText = [
      'position:fixed',
      'top:125px',
      'left:8px',
      'max-width:calc(100vw - 16px)',
      'background:rgba(0,0,0,.88)',
      'color:#7CFF7C',
      'font:11px/1.35 monospace',
      'padding:8px',
      'border:1px solid #7CFF7C',
      'border-radius:4px',
      'z-index:2147483647',
      'white-space:pre',
      'pointer-events:none',
      'display:none'
    ].join(';');

      el.style.display = 'none'; /* gameplay HUD cleanup */
    document.body.appendChild(el);
    return el;
  };

  WF.toggleDebug = function(){
    WF.debug.enabled = !WF.debug.enabled;

    var el = WF.ensureDebugger();
    el.style.display = WF.debug.enabled ? 'block' : 'none';

    if(typeof say === 'function'){
      say(
        'foundation debug ' +
        (WF.debug.enabled ? 'on' : 'off')
      );
    }
  };

  WF.updateDebug = function(){
    if(!WF.debug.enabled) return;
    if(typeof kingPos === 'undefined' || !kingPos) return;

    /*
     * Synchronization is idempotent.
     * No arbitrary 11-second assumption is required.
     */
    WF.syncMountains();

    var support = WF.supportBelow(
      kingPos,
      {
        startOffset:2,
        maxDrop:8,
        maxSlope:60
      }
    );

    WF.debug.support = su