# Phase 5: Levels 26-30 + Graduation

**Priority**: MEDIUM - Campaign finale and graduation  
**Estimated Effort**: 16-22 hours  
**Status**: Not Started  
**Dependencies**: Phase 4 (Levels 21-25)

---

## 🎯 Phase Goals

Implement levels 26-30, covering the **Ultimate Mastery Arc**. These are the final five levels of The Academy, culminating in the epic Level 30 graduation ceremony. Implement progressive intensity scaling, dynamic difficulty, and the graduation system.

---

## 📋 What This Phase Delivers

### Arc Implemented:
**Ultimate Mastery Arc (L26-30)**: Final challenges leading to graduation

### Level-by-Level:
- **L26**: Ultimate Test I (240min / 4 hours) - Intensity Stage 1
- **L27**: Ultimate Test II (255min / 4.25 hours) - Intensity Stage 2
- **L28**: Ultimate Test III (270min / 4.5 hours) - Intensity Stage 3
- **L29**: Ultimate Test IV (285min / 4.75 hours) - Intensity Stage 4
- **L30**: Graduation (300min / 5 hours) - Final exam + ceremony

### New Systems:
1. **Progressive Intensity System**: 4 stages (Moderate → Challenging → Intense → Extreme)
2. **Dynamic Difficulty Adjustment**: Adapts to user's path and preferences
3. **Graduation Ceremony**: Oath, certificate, stats report, photo gallery, library report
4. **Freeplay Mode**: Unlocked after graduation
5. **Ascended Mode**: Ultra-hard post-graduation mode

**End Result**: Complete campaign with satisfying conclusion and post-game content.

---

## 🏗️ Implementation Tasks

### Task 1: Progressive Intensity System (5-6 hours)

**File to Create**: `src/features/academy/intensityManager.js`

**Responsibilities**:
- Calculate intensity based on level (26-30)
- Adjust feature frequency/complexity
- Generate intensity-scaled tasks
- Track intensity progression

**Intensity Stages**:
```javascript
const intensityStages = {
  1: {
    level: 26,
    name: "Moderate",
    description: "Warm up for the ultimate tests",
    multipliers: {
      edgeCount: 1.0,
      interruptionFrequency: 1.0,
      popupFrequency: 1.0,
      denialDuration: 1.0,
      featureCount: 4 // max 4 features at once
    }
  },
  2: {
    level: 27,
    name: "Challenging",
    description: "Ramping up the pressure",
    multipliers: {
      edgeCount: 1.2,
      interruptionFrequency: 1.3,
      popupFrequency: 1.3,
      denialDuration: 1.2,
      featureCount: 5
    }
  },
  3: {
    level: 28,
    name: "Intense",
    description: "Testing your limits",
    multipliers: {
      edgeCount: 1.4,
      interruptionFrequency: 1.6,
      popupFrequency: 1.6,
      denialDuration: 1.4,
      featureCount: 6
    }
  },
  4: {
    level: 29,
    name: "Extreme",
    description: "Maximum challenge before graduation",
    multipliers: {
      edgeCount: 1.6,
      interruptionFrequency: 2.0,
      popupFrequency: 2.0,
      denialDuration: 1.6,
      featureCount: 7 // all features
    }
  }
};
```

**Methods**:
```javascript
class IntensityManager {
  getIntensityStage(level) {
    // Return intensity config for level 26-30
  }
  
  scaleAction(action, intensityStage) {
    // Apply multipliers to action params
    // e.g., edge count, interruption frequency
  }
  
  generateIntensifiedSession(level, baseTasks) {
    // Take base task list
    // Apply intensity scaling
    // Return intensified task list
  }
  
  calculateDifficulty(level, path, preferences) {
    // Combine level, path focus, and preferences
    // Return difficulty score
  }
}
```

**Testing Checklist**:
- [ ] Intensity stages defined
- [ ] Multipliers apply correctly
- [ ] Actions scale with intensity
- [ ] Difficulty calculation works

---

### Task 2: Dynamic Difficulty Adjustment (3-4 hours)

**File to Update**: `src/features/academy/intensityManager.js`

**Responsibilities**:
- Adjust difficulty based on path
- Respect user preferences
- Generate path-specific challenges for L26-30

**Path-Specific Adjustments**:
```javascript
const pathIntensityAdjustments = {
  Endurance: {
    focus: 'duration',
    adjustments: {
      // Longer sessions, more edges
      edgeCount: +20,
      breakDuration: -30, // shorter breaks
      sessionPacing: 'steady'
    }
  },
  Denial: {
    focus: 'frustration',
    adjustments: {
      denialDuration: +300, // +5 minutes
      edgesToBrink: +10,
      releaseProhibited: true
    }
  },
  Humiliation: {
    focus: 'psychological',
    adjustments: {
      degradingCaptions: true,
      humiliationTasks: +5,
      egoReduction: 'maximum'
    }
  },
  Obedience: {
    focus: 'control',
    adjustments: {
      commandFrequency: +10, // more commands
      instantCompliance: true,
      complexCommands: true
    }
  },
  Sensitivity: {
    focus: 'sensation',
    adjustments: {
      minimalTouch: true,
      edgeControl: 'precise',
      slowEdging: true
    }
  },
  MultiSensory: {
    focus: 'overload',
    adjustments: {
      allFeatures: true,
      simultaneousFeatures: 7,
      complexityMax: true
    }
  }
};
```

**Methods**:
```javascript
class IntensityManager {
  // ... existing methods ...
  
  applyPathAdjustments(baseTasks, path) {
    // Modify tasks based on path focus
  }
  
  generatePathSpecificChallenge(level, path) {
    // Create unique challenge for path at this level
  }
}
```

**Testing Checklist**:
- [ ] Path adjustments apply
- [ ] Each path has unique L26-30 experience
- [ ] Adjustments respect preferences

---

### Task 3: Graduation System (5-7 hours)

**File to Create**: `src/features/academy/graduationManager.js`

**Responsibilities**:
- Execute Level 30 (5-hour final exam)
- Generate graduation ceremony
- Create certificate
- Compile stats report
- Curate photo gallery
- Compile library report
- Unlock freeplay and Ascended mode
- Display graduation modal

**Graduation Ceremony Components**:

**1. Final Oath**:
```javascript
const graduationOath = {
  base: "I am a graduate of The Academy.",
  custom: (stats) => `
    I have completed ${stats.totalLevels} levels.
    I have edged ${stats.totalEdges} times.
    I have gooned for ${stats.totalHours} hours.
    I have mastered ${stats.selectedPath}.
    I am a dedicated gooner.
    I will continue to goon.
    I embrace my addiction.
  `
};
```

**2. Certificate**:
```javascript
const certificate = {
  title: "Certificate of Completion",
  subtitle: "The Academy",
  body: `
    This certifies that [USERNAME] has successfully completed
    The Academy's comprehensive gooner training program.
    
    Path: [PATH]
    Total Time: [HOURS] hours
    Total Edges: [EDGES]
    Library Size: [VIDEOS] videos, [IMAGES] images
    Curator Rank: [RANK]
    
    Graduated: [DATE]
  `
};
```

**3. Stats Report**:
```javascript
const statsReport = {
  general: {
    totalLevels: 30,
    totalSessionTime: 0, // seconds
    totalEdges: 0,
    averageSessionLength: 0,
    longestSession: 0,
    failedAttempts: 0
  },
  features: {
    webcamTimeUsed: 0,
    ttsCommandsHeard: 0,
    hypnoTimeWatched: 0,
    captionsDisplayed: 0,
    interruptionsCompleted: 0,
    popupsViewed: 0
  },
  library: {
    totalVideos: 0,
    totalImages: 0,
    taggedFiles: 0,
    tagCoverage: 0, // %
    curatorRank: 'Master',
    topTags: []
  },
  path: {
    selectedPath: '',
    pathLevelsCompleted: 4, // L22-25
    pathSpecificStats: {} // depends on path
  }
};
```

**4. Photo Gallery**:
```javascript
// Collect photos from:
// - Dress-up game completions
// - Webcam snapshots (if enabled)
// - Achievement unlocks
// Display as gallery during ceremony
```

**5. Library Report**:
```javascript
const libraryReport = {
  summary: "Your curated library contains X videos and Y images.",
  coverage: "Z% of your library is tagged.",
  curatorRank: "You achieved Master rank as a curator.",
  topCategories: ["amateur", "POV", "edging"],
  recommendations: "Continue curating to reach 100% coverage."
};
```

**Methods**:
```javascript
class GraduationManager {
  async executeGraduationLevel() {
    // Run 5-hour Level 30 session
    // Track all stats during session
  }
  
  async startCeremony() {
    // Show graduation modal
    // Display oath → certificate → stats → photos → library
  }
  
  generateCertificate(stats) {
    // Fill template with user stats
    // Return HTML certificate
  }
  
  compileStatsReport() {
    // Aggregate all stats from academyProgress
  }
  
  compilePhotoGallery() {
    // Collect photos from dress-up, webcam, achievements
  }
  
  compileLibraryReport() {
    // Generate summary from libraryData
  }
  
  unlockPostGraduationContent() {
    // Unlock freeplay mode
    // Unlock Ascended mode
    // Save to gameData
  }
  
  saveCertificate() {
    // Optionally save certificate as image/PDF
  }
}
```

**Graduation Modal UI**:
```html
<div id="graduation-modal" class="modal">
  <h1>🎓 CONGRATULATIONS! 🎓</h1>
  <h2>You have graduated from The Academy!</h2>
  
  <div id="graduation-oath">
    <h3>Recite Your Oath:</h3>
    <p id="oath-text"></p>
    <button id="recite-oath">I Recite This Oath</button>
  </div>
  
  <div id="graduation-certificate" class="hidden">
    <h3>Your Certificate</h3>
    <div id="certificate-content"></div>
    <button id="download-certificate">Download Certificate</button>
  </div>
  
  <div id="graduation-stats" class="hidden">
    <h3>Your Academy Statistics</h3>
    <div id="stats-report"></div>
  </div>
  
  <div id="graduation-photos" class="hidden">
    <h3>Your Journey</h3>
    <div id="photo-gallery"></div>
  </div>
  
  <div id="graduation-library" class="hidden">
    <h3>Your Curated Library</h3>
    <div id="library-report"></div>
  </div>
  
  <div id="post-graduation" class="hidden">
    <h3>What's Next?</h3>
    <p>You have unlocked:</p>
    <ul>
      <li>✅ Freeplay Mode - Create custom sessions</li>
      <li>✅ Ascended Mode - Ultra-hard challenges</li>
      <li>✅ All duration tiers (Quick, Standard, Extended, Marathon)</li>
    </ul>
    <button id="enter-freeplay">Enter Freeplay</button>
    <button id="try-ascended">Try Ascended Mode</button>
  </div>
</div>
```

**Testing Checklist**:
- [ ] Level 30 runs full 5-hour session
- [ ] Graduation ceremony triggers
- [ ] Oath displays and is recitable
- [ ] Certificate generates with correct stats
- [ ] Stats report compiles accurately
- [ ] Photo gallery displays
- [ ] Library report displays
- [ ] Freeplay unlocks
- [ ] Ascended mode unlocks

---

### Task 4: Level Data for L26-30 (2-3 hours)

**File to Update**: `src/data/modes/academyLevelData.js`

Add levels 26-30:

```javascript
const academyLevels = {
  // ... L1-25 ...
  
  26: {
    name: "Ultimate Test I",
    arc: "Ultimate Mastery",
    duration: 14400, // 240 minutes (4 hours)
    intensityStage: 1,
    requirements: {
      minLevel: 26,
      completedLevels: [25]
    },
    unlocks: {
      level: 27
    },
    sessionStructure: {
      main: [
        { type: 'apply-intensity', stage: 1 },
        { type: 'path-specific-challenge', level: 26 },
        { type: 'sensory-overload', duration: 14400 },
        { type: 'edge', params: { count: 200 } }
      ]
    }
  },
  
  27: {
    name: "Ultimate Test II",
    arc: "Ultimate Mastery",
    duration: 15300, // 255 minutes
    intensityStage: 2,
    requirements: {
      minLevel: 27,
      completedLevels: [26]
    },
    unlocks: {
      level: 28
    },
    sessionStructure: {
      main: [
        { type: 'apply-intensity', stage: 2 },
        { type: 'path-specific-challenge', level: 27 },
        { type: 'sensory-overload', duration: 15300 },
        { type: 'edge', params: { count: 240 } }
      ]
    }
  },
  
  28: {
    name: "Ultimate Test III",
    arc: "Ultimate Mastery",
    duration: 16200, // 270 minutes
    intensityStage: 3,
    requirements: {
      minLevel: 28,
      completedLevels: [27]
    },
    unlocks: {
      level: 29
    },
    sessionStructure: {
      main: [
        { type: 'apply-intensity', stage: 3 },
        { type: 'path-specific-challenge', level: 28 },
        { type: 'sensory-overload', duration: 16200 },
        { type: 'edge', params: { count: 280 } }
      ]
    }
  },
  
  29: {
    name: "Ultimate Test IV",
    arc: "Ultimate Mastery",
    duration: 17100, // 285 minutes
    intensityStage: 4,
    requirements: {
      minLevel: 29,
      completedLevels: [28]
    },
    unlocks: {
      level: 30
    },
    sessionStructure: {
      main: [
        { type: 'apply-intensity', stage: 4 },
        { type: 'path-specific-challenge', level: 29 },
        { type: 'sensory-overload', duration: 17100 },
        { type: 'edge', params: { count: 320 } }
      ]
    }
  },
  
  30: {
    name: "Graduation",
    arc: "Ultimate Mastery",
    duration: 18000, // 300 minutes (5 hours)
    intensityStage: 4,
    isGraduation: true,
    requirements: {
      minLevel: 30,
      completedLevels: [29]
    },
    unlocks: {
      graduation: true,
      freeplay: true,
      ascendedMode: true,
      arcsCompleted: ['Ultimate Mastery']
    },
    sessionStructure: {
      warmup: [
        { type: 'caption', text: 'This is it. Your final test.' }
      ],
      main: [
        { type: 'apply-intensity', stage: 4 },
        { type: 'path-specific-challenge', level: 30 },
        { type: 'sensory-overload', duration: 18000 },
        { type: 'edge', params: { count: 300 } }
      ],
      cooldown: [
        { type: 'start-graduation-ceremony' }
      ]
    }
  }
};
```

**Testing Checklist**:
- [ ] L26-30 defined
- [ ] Intensity stages apply
- [ ] L30 triggers graduation
- [ ] Graduation unlocks saved

---

### Task 5: Freeplay & Ascended Mode Foundations (1-2 hours)

**Basic Implementation** (full features in Phase 6/7):

**Freeplay Mode**:
- Allow users to create custom sessions
- Select any features, any duration
- No progression requirements

**Ascended Mode**:
- Ultra-hard version of any level
- 2x intensity multipliers
- Additional challenges
- For post-graduation mastery

**Data Structure**:
```javascript
academyProgress: {
  // ... existing ...
  freeplayUnlocked: false,
  ascendedModeUnlocked: false,
  ascendedLevelsCompleted: []
}
```

**Testing Checklist**:
- [ ] Freeplay mode accessible after graduation
- [ ] Ascended mode accessible after graduation
- [ ] Basic functionality works

---

## 📏 Measurable Test Criteria

After Phase 5, ALL of these must pass:

### Level 26 (Ultimate Test I):
- [ ] 4-hour session runs
- [ ] Intensity Stage 1 applies (1.0x multipliers)
- [ ] Path-specific challenge loads
- [ ] Sensory overload coordinated
- [ ] Completing L26 unlocks L27

### Level 27 (Ultimate Test II):
- [ ] 4.25-hour session runs
- [ ] Intensity Stage 2 applies (1.2-1.3x multipliers)
- [ ] Difficulty increase noticeable
- [ ] Completing L27 unlocks L28

### Level 28 (Ultimate Test III):
- [ ] 4.5-hour session runs
- [ ] Intensity Stage 3 applies (1.4-1.6x multipliers)
- [ ] Difficulty significantly harder
- [ ] Completing L28 unlocks L29

### Level 29 (Ultimate Test IV):
- [ ] 4.75-hour session runs
- [ ] Intensity Stage 4 applies (1.6-2.0x multipliers)
- [ ] Maximum difficulty before graduation
- [ ] Completing L29 unlocks L30

### Level 30 (Graduation):
- [ ] 5-hour final session runs
- [ ] Path-specific final challenge loads
- [ ] All features coordinate perfectly
- [ ] Session completes successfully
- [ ] Graduation ceremony triggers

### Graduation Ceremony:
- [ ] Oath displays correctly
- [ ] Certificate generates with accurate stats
- [ ] Stats report compiles (30 levels, total time, edges, path)
- [ ] Photo gallery displays (if photos exist)
- [ ] Library report displays (tag coverage, curator rank)
- [ ] Certificate downloadable
- [ ] Freeplay unlocks
- [ ] Ascended mode unlocks
- [ ] Ultimate Mastery arc completes
- [ ] `graduationCompleted` flag set to true

### Overall:
- [ ] All levels L26-30 playable
- [ ] Intensity progression works
- [ ] Path adjustments apply
- [ ] No console errors
- [ ] Progress saves after each level
- [ ] Can complete L26 → L30 sequentially
- [ ] Graduation persistent after refresh

---

## 🎯 Success Criteria

**Phase 5 Complete When:**
1. Levels 26-30 fully functional
2. Ultimate Mastery arc complete
3. Progressive intensity system works
4. Graduation ceremony executes perfectly
5. Certificate, stats, photos, library all display
6. Freeplay and Ascended mode unlock
7. All measurable tests pass
8. Campaign finale satisfying and complete

---

## 📂 Files Created/Modified

### New Files:
- `src/features/academy/intensityManager.js`
- `src/features/academy/graduationManager.js`

### Modified Files:
- `src/data/modes/academyLevelData.js`
- `src/core/gameDataManager.js`
- `training-academy.html`

---

## 🚀 Next Phase

After Phase 5: **Phase 6: Stats/Achievements/Library Systems** (Cross-cutting systems)
