# Battleground V2 - Real Gamification

## Problem
Current Battleground is feature-complete but not behavior-changing. Leaderboards alone don't create engagement.

## Solution
Add real stakes through XP Duels, sound/visual feedback, and manager-controlled challenges.

---

## Feature 1: XP Duels (Head-to-Head Challenges)

### How it works:
1. **Challenge someone** - "I bet I make more calls than you today"
2. **AI calculates odds** - Based on historical performance
   - If Tony (avg 20 calls/day) challenges a newbie (avg 8 calls/day), odds might be 3:1
   - Newbie only needs to hit 60% of Tony's calls to win
3. **Both stake XP** - Challenger picks amount (50-500 XP)
4. **Winner takes the pot** - Adjusted by odds

### Duel Types:
| Type | Metric | Duration |
|------|--------|----------|
| Call Blitz | Most calls | 1 hour |
| Daily Grind | Most calls | Today |
| Closer Duel | Most conversions | This week |
| Speed Demon | Fastest response time | Today |

### AI Odds Calculation:
```
Base odds = Challenger's 30-day avg / Target's 30-day avg
Adjusted for: day of week, time of day, current streak
Display as: "Tony is 2.5:1 favorite"
```

### Safeguards:
- Max stake: 500 XP per duel
- Max loss per day: 50% of daily XP earned
- Can't challenge someone already in a duel
- Manager can disable for specific users

### UI:
- Duel card shows: both players, metric, stakes, odds, time remaining
- Live progress bar during duel
- Victory animation + sound when won
- "Revenge" button after losing

---

## Feature 2: Sound & Visual Celebrations

### Conversion Celebration:
- When anyone converts: **sound plays for whole team**
- Big animated banner: "TONY JUST CLOSED! +500 XP"
- Confetti animation
- 3-second takeover (can dismiss)

### Duel Victory:
- Different sound for duel wins
- Loser gets "defeated" animation (tasteful, not humiliating)
- Winner's avatar gets temporary crown

### Streak Milestones:
- 5-day streak: flame animation
- 10-day streak: fire sound + badge
- 30-day streak: legendary animation

---

## Feature 3: Manager Challenges (Real Stakes)

### Manager creates custom challenges:
- "First to close a formwork lead gets $50"
- "Beat yesterday's team total, pizza party"
- "Bottom performer this week buys coffee"

### Challenge Builder:
- Pick metric (calls, conversions, response time)
- Pick duration (hour, day, week)
- Pick reward (XP multiplier, real prize, or "shame" punishment)
- Optional: set minimum threshold

### Real Prize Integration:
- Manager marks prize as "claimed" when awarded
- History of who won what

---

## Feature 4: Simplified Daily View

### Remove clutter:
- Hide Hall of Fame (move to separate tab)
- Hide Team Pulse (or make it opt-in)
- Focus on: Today's Duels, Active Challenges, Your Position

### New Default View:
```
+----------------------------------+
|  YOUR RANK: #2 of 5              |
|  [====>    ] 340 XP today        |
+----------------------------------+
|  ACTIVE DUELS (1)                |
|  vs Sarah: Calls | You: 12 Her: 9|
|  Stakes: 200 XP | 2hrs left      |
+----------------------------------+
|  MANAGER CHALLENGE               |
|  "First conversion = early knock"|
|  Progress: 0/1 | 3 competing     |
+----------------------------------+
|  [CHALLENGE SOMEONE]             |
+----------------------------------+
```

---

## Database Schema

```sql
-- XP Duels
CREATE TABLE duels (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  challenger_id UUID REFERENCES auth.users(id),
  target_id UUID REFERENCES auth.users(id),
  duel_type VARCHAR(50) NOT NULL, -- 'calls_hour', 'calls_day', 'conversions_week', 'response_time'
  stake_amount INTEGER NOT NULL,
  challenger_odds DECIMAL(4,2), -- e.g., 2.50 means 2.5:1 favorite
  status VARCHAR(20) DEFAULT 'pending', -- pending, accepted, active, completed, declined
  challenger_score INTEGER DEFAULT 0,
  target_score INTEGER DEFAULT 0,
  winner_id UUID,
  starts_at TIMESTAMPTZ,
  ends_at TIMESTAMPTZ,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Manager Challenges
CREATE TABLE manager_challenges (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  created_by UUID REFERENCES auth.users(id),
  title VARCHAR(200) NOT NULL,
  description TEXT,
  metric VARCHAR(50) NOT NULL,
  target_value INTEGER,
  duration_hours INTEGER,
  reward_type VARCHAR(50), -- 'xp_multiplier', 'real_prize', 'shame'
  reward_description TEXT,
  status VARCHAR(20) DEFAULT 'active',
  winner_id UUID,
  starts_at TIMESTAMPTZ DEFAULT NOW(),
  ends_at TIMESTAMPTZ,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Challenge participants
CREATE TABLE challenge_participants (
  challenge_id UUID REFERENCES manager_challenges(id),
  user_id UUID REFERENCES auth.users(id),
  current_score INTEGER DEFAULT 0,
  joined_at TIMESTAMPTZ DEFAULT NOW(),
  PRIMARY KEY (challenge_id, user_id)
);
```

---

## API Endpoints

```
POST /api/battleground/duels/challenge
  - Create duel challenge
  - Body: { targetId, duelType, stakeAmount }
  - Returns: duel with calculated odds

POST /api/battleground/duels/:id/accept
  - Accept a duel challenge

POST /api/battleground/duels/:id/decline
  - Decline a duel challenge

GET /api/battleground/duels/active
  - Get user's active duels

POST /api/battleground/manager/challenges
  - Create manager challenge (manager only)

GET /api/battleground/manager/challenges
  - List active manager challenges
```

---

## Implementation Order

1. [ ] Database schema for duels + manager challenges
2. [ ] AI odds calculation service
3. [ ] Duel API endpoints
4. [ ] Duel UI components (challenge modal, active duel card, result modal)
5. [ ] Sound effects integration
6. [ ] Conversion celebration overlay
7. [ ] Manager challenge builder
8. [ ] Simplified Battleground layout

---

## Estimated Effort
- Phase 1 (Duels): 2-3 days
- Phase 2 (Sounds/Celebrations): 1 day
- Phase 3 (Manager Challenges): 1-2 days

---

## Success Metrics
- Duels accepted per day
- Time spent on Battleground page
- Calls made during active duels vs normal
- Manager challenge participation rate
