"""Build a self-contained reading aid. Python 3.10+, standard library only."""
import json
from html import escape
from pathlib import Path

ROOT = Path(__file__).resolve().parent
data = json.loads((ROOT / 'cases.json').read_text(encoding='utf-8'))
cards = []
options = []
for case in data['cases']:
    e = {key: escape(value, quote=True) for key, value in case.items()}
    options.append(f'<option value="{e["id"]}">{e["goal"]}</option>')
    cards.append(f'''<section class="case" data-case="{e['id']}">
<h2>{e['goal']}</h2><p class="action">{e['action']}</p>
<p>{e['why']}</p><p class="check"><strong>Before you act:</strong> {e['check']}</p>
<p class="source">Source: <a href="{escape(data['sources'][case['source']], quote=True)}">{'Official support' if case['source'] == 'support' else 'Google Play description'}</a></p></section>''')
page = '''<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,follow"><meta name="description" content="Four documented choices before continuing, resetting or moving a Poker Feud career."><meta name="date" content="2026-09-28"><title>Poker Feud save decision guide</title>
<style>
*{box-sizing:border-box}body{margin:0;background:#f3f2ec;color:#202b25;font:17px/1.6 system-ui,sans-serif}main{max-width:960px;margin:auto;padding:30px 24px}h1{font-size:clamp(1.7rem,4vw,2.6rem);line-height:1.15;margin:8px 0 18px}h2{font-size:1.2rem;line-height:1.3;margin:0 0 12px}a{color:#285c4c;text-underline-offset:3px}p{margin:12px 0}.kicker,.source,.scope,footer{font-size:.86rem}.kicker{letter-spacing:.08em;text-transform:uppercase}.controls{padding:18px 0;margin-bottom:8px}label{display:block;font-weight:650}select,button{font:inherit;min-height:44px;max-width:100%;padding:8px 12px;border:1px solid #6a7e70;border-radius:6px;background:white;color:inherit}select{width:100%;margin:8px 0}button{cursor:pointer}button:hover{background:#e3eee7}:focus-visible{outline:3px solid #8f461b;outline-offset:3px}.grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}.case{background:#fff;border:1px solid #87978d;border-top:5px solid #4b7a63;border-radius:9px;padding:20px;break-inside:avoid}.case[hidden]{display:none}.action{font-weight:700}.check{border-top:1px solid #d1d9d3;padding-top:12px}.source{margin-bottom:0}.note{padding:14px 18px;border-left:4px solid #ad714a;background:#fff8ef}footer{margin-top:24px;border-top:1px solid #9caaa1;padding-top:14px}#status{font-size:.9rem}button+button{margin-left:8px}
@media(max-width:620px){main{padding:22px 16px}.grid{grid-template-columns:1fr}.case{padding:18px}}
@media print{@page{size:A4;margin:12mm}body{background:white;font-size:10pt;line-height:1.4}main{max-width:none;padding:0}h1{font-size:23pt;margin-bottom:10px}h2{font-size:12pt}.controls,#status{display:none!important}.grid{grid-template-columns:1fr 1fr;gap:10px}.case,.case[hidden]{display:block!important;padding:12px;border:1px solid #75897b}.case p{margin:8px 0}.source,.scope,footer,.kicker{font-size:8.5pt}.note{padding:10px}footer{margin-top:14px}a{color:inherit}a:after{content:none}}
</style></head><body><main>
<p class="kicker">GTO Gecko · documented choices</p>
<h1>Poker Feud: keep or restart your career?</h1>
<p>Choose your goal before using a reset, deleting the app or moving phones.</p>
<p class="scope">''' + escape(data['scope']) + ' Checked <time datetime="' + escape(data['checked']) + '">' + escape(data['checked']) + '''</time>.</p>
<div class="controls" hidden><label for="goal">What do you want to do?</label><select id="goal"><option value="all">Show all four choices</option>''' + ''.join(options) + '''</select><button id="all" type="button">Show all</button><button id="print" type="button">Print all choices</button></div>
<p id="status" role="status" aria-live="polite">All four choices are shown.</p>
<div class="grid">''' + '\n'.join(cards) + '''</div>
<p class="note"><strong>A screenshot is not a save file.</strong> For help, record your device model, operating-system version, game version and what happened. Keep the original installation while checking a possible transfer with support.</p>
<footer>This guide cannot read or change your app. It stores and sends nothing. Source links require internet; the guide itself works offline. GTO Solutions AS makes GTO Gecko and Poker Feud. Play money has no cash value. <a href="https://gtogecko.com/blog/poker-feud-saves">Read the article and limitations</a>.</footer>
</main><script>
'use strict';
const select=document.querySelector('#goal');
const cases=[...document.querySelectorAll('.case')];
function show(){for(const card of cases)card.hidden=select.value!=='all'&&card.dataset.case!==select.value;document.querySelector('#status').textContent=select.value==='all'?'All four choices are shown.':'Showing: '+select.options[select.selectedIndex].textContent+'. Print includes all four choices.';}
document.querySelector('.controls').hidden=false;
select.addEventListener('change',show);
document.querySelector('#all').addEventListener('click',()=>{select.value='all';show();select.focus();});
document.querySelector('#print').addEventListener('click',()=>window.print());
</script></body></html>
'''
(ROOT / 'guide.html').write_text(page, encoding='utf-8', newline='\n')
print('Built guide.html from four documented cases.')
