<!-- SOLIDABILITY-WORLD · part 39 -->
yer = SWEngine.getPlayer();
    const camera = SWEngine.getCamera();
    if (!layout || !player || !camera) return null;

    // Cast from camera through center of screen
    const dir = new THREE.Vector3();
    camera.getWorldDirection(dir);

    let best = null, bestScore = Infinity;
    layout.rooms.forEach(room => {
      const toRoom = new THREE.Vector3(
        room.position.x - player.position.x,
        0,
        room.position.z - player.position.z
      );
      const dist = toRoom.length();
      toRoom.normalize();
      const flatDir = new THREE.Vector3(dir.x, 0, dir.z).normalize();
      const angle = toRoom.angleTo(flatDir);
      // Score: prefer close + centered
      const score = angle * 10 + dist * 0.1;
      if (angle < 0.6 && score < bestScore) {
        bestScore = score;
        best = room;
      }
    });

    if (best) {
      focusedRoom = best;
      highlightRoom(best, true);
      setTimeout(() => highlightRoom(best, false), 2000);
    }
    return best;
  }

  function highlightRoom(room, on) {
    // Visual pulse on room — implementation hooks into world builder
    // For now: show glass as feedback
    if (on) SWGlass.show(room);
  }

  // SCAN: pulse revealing nearby components
  function scan() {
    const scene = SWEngine.getScene();
    const player = SWEngine.getPlayer();
    if (!scene || !player) return;

    // Expanding ring
    if (scanPulse) scene.remove(scanPulse);
    const geo = new THREE.RingGeometry(0.5, 1, 32);
    const mat = new THREE.MeshBasicMaterial({
      color: 0x00ffcc, transparent: true, opacity: 0.8, side: THREE.DoubleSide
    });
    scanPulse = new THREE.Mesh(geo, mat);
    scanPulse.rotation.x = -Math.PI / 2;
    scanPulse.position.set(player.position.x, player.position.y + 0.2, player.position.z);
    scene.add(scanPulse);

    let radius = 1;
    const expand = setInterval(() => {
      radius += 1.5;
      scanPulse.scale.set(radius, radius, 1);
      mat.opacity = Math.max(0, 0.8 - radius * 0.03);
      if (radius > 25) {
        clearInterval(expand);
        scene.remove(scanPulse);
        scanPulse = null;
      }
    }, 50);

    // Reveal: show labels for rooms in radius (they're already visible,
    // but this draws connection lines between related rooms)
    drawRelationships();
    setMode('SCAN');
    setTimeout(() => { if (mode === 'SCAN') setMode('WALK'); }, 3000);
  }

  function drawRelationships() {
    // Stub: draw lines between rooms that share dependencies
    // Full implementation in Phase 2 with dependency graph data
    console.log('SCAN: relationship mapping reserved for dependency data');
  }

  // RETURN: go back through history
  function pushHistory() {
    const player = SWEngine.getPlayer();
    if (!player) return;
    history.push({
      x: player.position.x,
      y: player.position.y,
      z: player.position.z
    });
    if (history.length > 20) history.shift();
  }

  function goReturn() {
    const prev = history.pop();
    if (prev) {
      const player = SWEngine.getPlayer();
      // Push current to allow "return forward" — simple version just goes back
      player.position.set(prev.x, prev.y, prev.z);
      return true;
    }
    return false;
  }

  // LOOK mode: camera orbit via drag
  function setupLookControls() {
    const container = document.getElementById('scene-container');
    let dragging = false, lastX = 0, lastY = 0;

    container.addEventListener('touchstart', e => {
      if (mode !== 'LOOK') return;
      if (e.touches.length === 1) {
        dragging = true;
        lastX = e.touches[0].clientX;
        lastY = e.touches[0].clientY;
      }
    }, { passive: true });

    container.addEventListener('touchmove', e => {
      if (!dragging || mode !== 'LOOK') return;
      const dx = e.touches[0].clientX - lastX;
      const dy = e.touches[0].clientY - lastY;
      lastX = e.touches[0].clientX;
      lastY = e.touches[0].clientY;
      lookYaw -= dx * 0.005;
      lookPitch = Math.max(0.1, Math.min(1.2, lookPitch + dy * 0.003));
    }, { passive: true });

    container.addEventListener('touchend', () => { dragging = false; });

    // Mouse for desktop
    let mouseDown = false;
    container.addEventListener('mousedown', e => {
      if (mode !== 'LOOK') return;
      mouseDown = true; lastX = e.clientX; lastY = e.clientY;
    });
    container.addEventListener('mousemove', e => {
      if (!mouseDown || mode !== 'LOOK') return;
      lookYaw -= (e.clientX - lastX) * 0.005;
      lookPitch = Math.max(0.1, Math.min(1.2, lookPitch + (e.clientY - lastY) * 0.003));
      lastX = e.clientX; lastY = e.clientY;
    });
    container.addEventListener('mouseup', () => { mouseDown = false; });
  }

  function updateLookCamera() {
    if (mode !== 'LOOK') return;
    const player = SWEngine.getPlayer();
    const camera = SWEngine.getCamera();
    if (!player || !camera) return;

    const dist = 12;
    camera.position.set(
      player.position.