# Seamless Corp Card Overlay — Skill Documentation

## What it does

`scripts/seamless_overlay.py` replaces original English text on High Orbit corporation cards with Hungarian translations. Unlike the previous `apply_corp_translations.py` (which painted flat gray boxes), this approach:

1. **Inpaints the name region** using OpenCV — removes yellow/red original text cleanly so the illustration background shows through
2. **Samples background color** from actual card pixels (not hardcoded gray)
3. **Multi-color text rendering** — per-line fill + stroke colors for corp names (yellow/red gradient style)
4. **Auto-fits font size** to name region height/width

## Key findings from analysis

### Corp card orientation
Cards are stored **portrait (822×1122)**, designed **landscape (1122×822)**.  
Workflow: rotate 90° CCW → apply overlays → rotate 90° CW → save.

### Coordinate system (landscape space)
All region coordinates are in **rotated landscape space**:
```
x: 0──────────────────────1122
y: 0  ← TOP of landscape card
   |
  822  ← BOTTOM
```

### Layout zones (landscape)
| Zone | x range | y range |
|------|---------|---------|
| Corp art / start col | 0–300 | varies |
| Corp name | 278–942 | 55–320 |
| Effect text | 300–960 | 318–615 |
| Action text | 300–960 | 452–660 |
| Flavor strip | 15–1095 | 697–742 |

### Inpainting mask for name region
Yellow text pixels: `R>150, G>100, B<120, (R-B)>60`  
Red text pixels: `R>130, (R-G)>55, (R-B)>55`  
Dark outline pixels: `R<60, G<60, B<60`  
→ dilate with 4×4 kernel × 2 iterations → `cv2.inpaint(radius=7, INPAINT_TELEA)`

### Name rendering colors (per card)
```python
YELLOW = (220, 170, 20)   # fill for dominant/first line
RED    = (190,  25, 20)   # stroke for dominant line / fill for secondary
```
First line: yellow fill + red stroke  
Second line: red fill + yellow stroke  
Font: `arialbd.ttf` (Arial Bold), auto-sized to fit region

### Background/text color sampling
- Background: median of pixels brighter than 185 (the card background)
- Foreground: median of pixels darker than 80 (the text)

### Start region quirks
- PEC has a wider text box: x2 needs to be **345** (not 303)
- All cards: start text ends much lower than the icons — need y2 ≈ 695
- JoC has tall icons extending to y=560; start_region begins at y=560

## Usage

```bash
# All 5 corps (output to output/corps/)
python scripts/seamless_overlay.py

# One card, test mode (output/corps/test/)
python scripts/seamless_overlay.py --card "Lagrange Collective" --test

# Verbose (shows sampled colors)
python scripts/seamless_overlay.py --card "Spacetek"
```

## Extending to new cards

Add an entry to the `CORPS` dict with:
- `file`: filename in SOURCE_DIR
- `name_lines`: list of `(text, fill_rgb, stroke_rgb, stroke_width)` per line
- `name_region`: `(x1, y1, x2, y2)` — right of logo, upper card
- `start_text`: list of paragraph strings
- `start_region`: left column, below icons, cover full text height
- `effect` / `effect_region`: main effect text box
- `action` / `action_region`: action text box (or None)
- `flavor` / `flavor_region`: bottom flavor strip

## Known limitations

- Start text in the left column sits interleaved with card icons (icons have variable heights across cards). We can't cover icons, so we start the fill just below the tallest icon for each card.
- JoC icons extend to y=560; original start text is partially within the icon area and may show slightly at y<560.
- The `")"` closing parenthesis of long action texts may render 1–2px outside the fill boundary (harmless cosmetic artifact).
- The CORPORATION label and TR value (far right of landscape card) are untranslated — they are card template design elements.
