/* Parser-blocking shell bootstrap: no DOM/body, layout, or network dependencies. */ (() => { const root = document.documentElement; const key = 'plotdirector.displayMode'; const media = window.matchMedia('(display-mode: standalone)'); let established = false; try { established = sessionStorage.getItem(key) === 'standalone'; } catch { } root.dataset.standalone = String(established); let verified = false; const verify = () => { const current = media.matches || navigator.standalone === true; const changed = !verified || current !== established; established = current; verified = true; root.dataset.standalone = String(established); try { sessionStorage.setItem(key, established ? 'standalone' : 'browser'); } catch { } if (changed) window.dispatchEvent(new CustomEvent('plotdirector:pwa-mode-changed', { detail: { standalone: established } })); }; window.PlotDirectorPwa = Object.freeze({ get standalone() { return established; } }); // Verify synchronously before the body can paint, including first-ever launch. // Session storage is window scoped: an installed window cannot poison a browser tab. verify(); media.addEventListener('change', verify); window.addEventListener('pageshow', verify); })();