#!/usr/bin/env python3
"""Create the Survivor Pool Vision Doc in Word format with clean, readable tables."""

from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT

doc = Document()

style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(11)

def add_heading_styled(text, level=1):
    h = doc.add_heading(text, level=level)
    for run in h.runs:
        run.font.color.rgb = RGBColor(0xC0, 0x39, 0x2B)
    return h

def add_table_styled(headers, rows):
    table = doc.add_table(rows=1 + len(rows), cols=len(headers))
    table.style = 'Light Grid Accent 1'
    table.alignment = WD_TABLE_ALIGNMENT.CENTER
    for i, header in enumerate(headers):
        cell = table.rows[0].cells[i]
        cell.text = header
        for p in cell.paragraphs:
            p.alignment = WD_ALIGN_PARAGRAPH.CENTER
            for run in p.runs:
                run.bold = True
                run.font.size = Pt(10)
    for r_idx, row in enumerate(rows):
        for c_idx, val in enumerate(row):
            cell = table.rows[r_idx + 1].cells[c_idx]
            cell.text = str(val)
            for p in cell.paragraphs:
                p.alignment = WD_ALIGN_PARAGRAPH.CENTER
                for run in p.runs:
                    run.font.size = Pt(10)
    doc.add_paragraph()
    return table

# TITLE
title = doc.add_heading('LOBSTER SURVIVOR POOL 2026', level=0)
for run in title.runs:
    run.font.color.rgb = RGBColor(0xC0, 0x39, 0x2B)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
subtitle = doc.add_paragraph('FIFA World Cup 2026 — Knockout Stage Survivor Pool')
subtitle.alignment = WD_ALIGN_PARAGRAPH.CENTER
subtitle.runs[0].font.size = Pt(14)
subtitle.runs[0].font.color.rgb = RGBColor(0x7F, 0x8C, 0x8D)
doc.add_paragraph()

# CONCEPT
add_heading_styled('THE CONCEPT', 1)
doc.add_paragraph(
    'A survivor-style prediction pool for the 2026 FIFA World Cup (June 11 - July 19). '
    'Players pay to enter, pick teams to win, and survive round by round. '
    'Last lobster standing takes the pot.'
)
doc.add_paragraph(
    'What makes it different: it starts during GROUP STAGE, has a "Lobster Trap" buy-back mechanic, '
    'and the strategy of when to burn your best teams creates a real game within the game.'
)

# HOW IT WORKS
add_heading_styled('HOW IT WORKS', 1)

add_heading_styled('Phase 1 — Group Stage Picks (Before First Game)', 2)
doc.add_paragraph(
    'The 2026 World Cup features 48 teams in 12 groups of 4. Before the first whistle:'
)
doc.add_paragraph('Each player picks 2 teams they believe will advance out of group play.', style='List Bullet')
doc.add_paragraph('Both teams advance? You survive — but those 2 teams are BURNED (can\'t use again).', style='List Bullet')
doc.add_paragraph('One or both fail to advance? You\'re ELIMINATED.', style='List Bullet')
doc.add_paragraph()
p = doc.add_paragraph()
p.add_run('The Strategic Tension: ').bold = True
p.add_run('Do you burn powerhouses like Brazil and France to guarantee survival, leaving yourself '
    'short-handed in knockout play? Or gamble on mid-tier teams and save the big dogs for later?')

add_heading_styled('Phase 2 — Knockout Stage (R32 through Final, 5 Rounds)', 2)
doc.add_paragraph('Pick 1 team to WIN each round (5 rounds total).', style='List Bullet')
doc.add_paragraph('Can\'t reuse ANY team — including your 2 group stage picks.', style='List Bullet')
doc.add_paragraph('Your pick loses? You\'re OUT.', style='List Bullet')
doc.add_paragraph('Penalties count as a win.', style='List Bullet')
doc.add_paragraph()
p = doc.add_paragraph()
p.add_run('Total picks across the tournament: 7').bold = True
p.add_run(' (2 group stage + 5 knockout rounds)')

# LOBSTER TRAP
add_heading_styled('THE LOBSTER TRAP — BUY-BACK MECHANIC', 1)
doc.add_paragraph(
    'Players eliminated during group stage get ONE shot at redemption:'
)

add_table_styled(
    ['', 'Original Players', 'Buy-Back Players'],
    [
        ['Entry Fee', '$100', '$150'],
        ['Group Stage Picks', '2 teams (burned)', 'Same 2 teams (still burned)'],
        ['Round of 32', 'Pick 1 winner', 'Pick 2 winners (BOTH must hit)'],
        ['R16 Onward', 'Normal (1 pick/round)', 'Normal (1 pick/round)'],
        ['Teams Available', '48 minus burned', '48 minus burned'],
    ]
)

doc.add_paragraph('48-hour window after group stage ends — get in or get left behind.', style='List Bullet')
doc.add_paragraph('One buy-back per player. No third chances.', style='List Bullet')
doc.add_paragraph('Extra $50 goes straight to the pot — everyone benefits.', style='List Bullet')
doc.add_paragraph('Buy-backs close before Round of 32 kicks off.', style='List Bullet')

# DETAILED RULES
add_heading_styled('COMPLETE RULES — DETAILED', 1)

rules = [
    ('1. Entry Fee', '$100 per player. 100% goes to the prize pool. No rake, no admin cut.'),
    ('2. Player Cap', '50-100 players. Invite-only with access code.'),
    ('3. Group Stage Picks', 
     'Before the first game, each player selects 2 teams they believe will advance out of group play. '
     'Both must advance for the player to survive. Those 2 teams are permanently burned — '
     'they cannot be used again in knockout rounds.'),
    ('4. Knockout Picks', 
     'Each knockout round, players pick 1 team to WIN their match. '
     'Picks lock 1 hour before the first game of each round. No exceptions. '
     'If your pick wins (including via penalties), you survive. If they lose or draw (without penalties), you\'re eliminated.'),
    ('5. No Repeat Teams', 
     'Once you pick a team (group stage or knockout), that team is burned forever. '
     'You cannot use them again. With 7 total picks and 48 teams, planning ahead is everything.'),
    ('6. Elimination', 
     'If your group stage picks fail OR your knockout pick loses, you are immediately eliminated. '
     'No appeals, no exceptions.'),
    ('7. Lobster Trap Buy-Back', 
     'Players eliminated in group stage only may re-enter for $150. '
     'Buy-back window: 48 hours after group stage concludes. '
     'Buy-back players must pick 2 winners in Round of 32 (both must win) vs 1 for original survivors. '
     'Original burned teams remain burned. One buy-back per player maximum.'),
    ('8. Winning', 
     'Last player(s) standing after the Final wins the pot. '
     'If multiple players survive all rounds, the pot splits evenly among survivors.'),
    ('9. Pick Deadlines', 
     'All picks lock 1 hour before the first game of each round. '
     'If a player fails to submit a pick, they are automatically eliminated.'),
    ('10. Payment', 
     'Entry fee must be received before the tournament starts. '
     'US players: Venmo or PayPal. International players: PayPal or Revolut. '
     'Spot is not confirmed until payment is received.'),
]

for title_text, body_text in rules:
    p = doc.add_paragraph()
    p.add_run(title_text).bold = True
    doc.add_paragraph(body_text)

# MONEY
add_heading_styled('THE MONEY', 1)

add_table_styled(
    ['Scenario', 'Players', 'Buy-Backs', 'Total Pot'],
    [
        ['Conservative', '30', '8', '$4,200'],
        ['Target', '50', '15', '$7,250'],
        ['If It Goes Viral', '100', '30', '$14,500'],
    ]
)

# INVITE-ONLY
add_heading_styled('INVITE-ONLY — PRIVATE POOL', 1)
doc.add_paragraph('Site is NOT indexed by search engines (noindex, nofollow).', style='List Bullet')
doc.add_paragraph('Password/invite code required to join.', style='List Bullet')
doc.add_paragraph('Only way in: someone you know sends you the link + code.', style='List Bullet')
doc.add_paragraph('Grassroots sharing only — no social media ads, no public posts.', style='List Bullet')
doc.add_paragraph('Admin can rotate the invite code or shut enrollment anytime.', style='List Bullet')

# LEGAL
add_heading_styled('LEGAL — STAYING CLEAN', 1)
doc.add_paragraph('No rake — 100% of fees go to prizes.', style='List Bullet')
doc.add_paragraph('Organizer participates on equal terms — a player, not the house.', style='List Bullet')
doc.add_paragraph('Invite-only among friends and acquaintances.', style='List Bullet')
doc.add_paragraph('Not advertised publicly.', style='List Bullet')
doc.add_paragraph('Clean records of all money in and out.', style='List Bullet')
doc.add_paragraph('Compliant with NJ social gambling exception (N.J.S.A. 2C:37-2).', style='List Bullet')

# TIMELINE
add_heading_styled('TIMELINE', 1)
add_table_styled(
    ['When', 'What'],
    [
        ['Now – April', 'Finalize rules, build the app'],
        ['May 1', 'App goes LIVE — start sharing'],
        ['May – June 10', 'Get to 50 players'],
        ['June 10', 'Registration closes, group picks lock'],
        ['June 11', 'World Cup kicks off'],
        ['~July 1', 'Group stage ends, eliminations processed'],
        ['~July 1-3', 'Lobster Trap buy-back window (48 hours)'],
        ['~July 3', 'Knockout begins'],
        ['July 19', 'FINAL — Winner crowned'],
    ]
)

# PAYMENT
add_heading_styled('PAYMENT — INTERNATIONAL FRIENDLY', 1)
add_table_styled(
    ['Region', 'Options'],
    [
        ['US Players', 'Venmo, PayPal, Apple Pay, Zelle'],
        ['International', 'PayPal, Revolut, Bank Transfer'],
    ]
)

# FOOTER
doc.add_paragraph()
p = doc.add_paragraph('Built by Rob Lobster for Joe Lynch')
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.runs[0].font.italic = True
p.runs[0].font.color.rgb = RGBColor(0x7F, 0x8C, 0x8D)
p = doc.add_paragraph('March 29, 2026')
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.runs[0].font.italic = True
p.runs[0].font.color.rgb = RGBColor(0x7F, 0x8C, 0x8D)

output_path = '/Users/joemac/.openclaw/workspace/projects/lobster-survivor-pool-vision.docx'
doc.save(output_path)
print(f'Saved to {output_path}')
