/* ================= INSTALL (PWA) ================= */ let installEvt=null; addEventListener('beforeinstallprompt',e=>{e.preventDefault();installEvt=e;}); addEventListener('appinstalled',()=>{installEvt=null;track('pwa_installed',true);if(UI.pendGame){const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;beginGame(...p);}toast(tr('install.installed_open_series_of_tubes_from'),'good');}); const isStandalone=()=>{try{return navigator.standalone===true||!!(window.matchMedia&&matchMedia('(display-mode: standalone)').matches);}catch(e){return false;}}; const isIOS=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||(navigator.platform==='MacIntel'&&navigator.maxTouchPoints>1); function installRow(){if(isStandalone())return ''; return `
📲 ${tr('install.best_played_as_an_app')}
${tr('install.full_screen_works_offline_one_tap')}${isIOS()?' '+tr('install.install_it_before_you_start_a'):''}
${btn(tr('common.install'),'install',{},'pink sm')}
`;} /* Phones get a real pitch before a new game: an installed app is full screen, works offline, and on iPhone keeps its save away from Safari's clean-ups. Storage is separate on iOS, so installing first matters. */ const SHARE_SVG=''; const needPitch=()=>isPhone()&&!isStandalone(); function installSteps(){ if(isIOS())return `
  1. ${tr('install.tap_share_icon_in_the_browser',{icon:SHARE_SVG})}
  2. ${tr('install.tap_add_to_home_screen_you')}
  3. ${tr('install.open_series_of_tubes_from_your')}
`; if(installEvt)return ''; return `
  1. ${tr('install.open_your_browser_menu')}
  2. ${tr('install.tap_install_app_or_add_to')}
  3. ${tr('install.open_series_of_tubes_from_your_e03f')}
`;} function pitchHtml(starting){const ios=isIOS(); return `
${starting?`
${tr('install.before_you_start')}
`:''}

📲 ${tr('install.play_it_as_an_app')}

${tr('install.series_of_tubes_is_made_for')}

${installSteps()}
${installEvt?btn(tr('install.install_the_app'),'install',{},'pink big'):''}${starting?btn(tr('install.play_in_the_browser_anyway'),'pitchSkip',{},installEvt?'ghost':'ghost big'):btn(tr('common.got_it'),'closeModal',{},installEvt?'ghost':'pink')}
`;} if('serviceWorker' in navigator&&location.protocol==='https:'&&!IS_DEV)addEventListener('load',()=>{navigator.serviceWorker.register('/sw.js').catch(()=>{});});