<!-- SOLIDABILITY-WORLD · part 43 -->
setMode('AI_DRIVE');
    pushHistory();
    narrate(`Starting guided tour. I'll visit ${tourQueue.length} key components and explain each one. ` +
      `Tap STOP or move the joystick anytime to take over.`);
    tourNext();
  }

  function tourNext() {
    if (!touring || tourIndex >= tourQueue.length) {
      touring = false;
      aiDriving = false;
      narrate(`Tour complete. You've seen ${tourQueue.length} components.`);
      setMode('WALK');
      return;
    }
    const room = tourQueue[tourIndex];
    const descriptions = {
      'auth': 'This is Authentication — it guards who gets in. 15 routes handle login, sessions, and access control.',
      'forum': 'This is Forum & Boards — the social heart. 19 routes power threads, posts, and discussions.',
      'ai': 'This is AI Systems — 36 routes for Solid chat, SABLE, and PROVOLTA. This one is verified healthy.',
      'legal': 'This is the Legal Center — terms, privacy, compliance. 9 routes, verified.'
    };
    // Full map: generate description from file data
    let desc;
    if (room.filePath) {
      const funcCount = (room.functions || []).length;
      const routeCount = room.routes.length;
      const depCount = (room.dependencies || []).length;
      desc = `${room.filePath} — complexity ${room.complexity}. ` +
        `${funcCount} functions, ${routeCount} routes, ${depCount} dependencies. ` +
        `Located in the ${room.district} district.`;
    } else {
      desc = descriptions[room.key] || `${room.label} — ${room.routes.length} routes.`;
    }

    // Navigate then explain on arrival
    const arrived = () => {
      narrate(`<b>${room.label}.</b> ${desc}`);
      SWGlass.show(room);
      tourIndex++;
      // Pause at each room, then continue
      setTimeout(() => { if (touring) tourNext(); }, 9000);
    };

    // Hook arrival
    const origStop = stopNavigate;
    // Use aiDriveTo with arrival callback via polling
    if (aiDriveTo(room, `Stop ${tourIndex + 1} of ${tourQueue.length} on the tour.`)) {
      const checkArrival = setInterval(() => {
        if (!navigating) {
          clearInterval(checkArrival);
          if (touring) arrived();
        }
      }, 500);
    } else {
      tourIndex++;
      tourNext();
    }
  }

  function stopTour() {
    touring = false;
    tourQueue = [];
  }

  // Find a Problem: locate rooms with defects or rough status
  function findProblem() {
    const layout = SWWorld.getLayout();
    if (!layout) return;

    // Priority: defect > rough > untested
    const defect = layout.rooms.find(r => r.verification.status === 'defect');
    const rough = layout.rooms.find(r => r.verification.status === 'rough');
    const untested = layout.rooms.find(r => r.verification.status === 'untested');

    const target = defect || rough || untested;
    if (!target) {
      narrate(`I've scanned all ${layout.rooms.length} rooms. ` +
        `No defects or abnormal behavior detected. All components are verified or quiet.`);
      return;
    }

    const statusDesc = {
      'defect': 'a confirmed problem',
      'rough': 'abnormal behavior',
      'untested': 'no verification record — unknown status'
    }[target.verification.status];

    aiDriving = true;
    setMode('AI_DRIVE');
    narrate(`Found ${statusDesc} in <b>${target.label}</b>. ` +
      `Navigating there to show you the evidence.`);
    aiDriveTo(target, `This room has ${statusDesc}.`);
  }

  // Take me upstairs / downstairs
  function goUpstairs() {
    const layout = SWWorld.getLayout();
    const player = SWEngine.getPlayer();
    if (!layout || !player) return;
    if (!layout.building || !layout.stairs) { narrate(`This world is a single open level — there are no stairs.`); return; }
    const fh = layout.building.floorHeight;
    const currentFloor = Math.round(player.position.y / fh);
    const targetFloor = currentFloor + 1;
    if (targetFloor >= layout.building.floors) {
      narrate(`Already on the top floor (Floor ${currentFloor + 1}).`);
      return;
    }
    // Navigate to stair top
    aiDriving = true;
    setMode('AI_DRIVE');
    pushHistory();
    narrate(`Taking you upstairs via the stairs.`);
    const stairTop = { x: layout.stairs.position.x, y: fh, z: layout.stairs.position.z - 8 };
    const path = findPath(
      { x: player.position.x, y: player.position.y, z: player.position.z },
      stairTop
    );
    if (path && path.length) {
      navPath = path; navIndex = 0; navigating = true;
      showPathTrail(path);
    } else {
      narrate(`Cannot find a path upstairs from here.`);
      aiDriving = false; setMode('WALK');
    }
  }

  // Stop AI DRIVE immediately
  function stopAI() {
    if (aiDriving || navigating || touring) {
      stopTour();
      stopNavigate();
      aiDriving = false;
      // Stop investigator too
      if (typeof SWInvestigator !== 'undefined' && SWInvestigator.isInvestigating()) {
        SWInvestigator.stop();
      }
      clearNarration()