// Runs before app.js, as a plain old script (no modern syntax, so even an old iPod reads it).
// 1. The few newer functions app.js uses that Safari only got in 15.4.
// 2. If app.js never started (a browser too old to read it), say so instead of leaving buttons that do nothing.
(function () {
  function at(i) { i = Math.trunc(i) || 0; if (i < 0) i += this.length; return this[i]; }
  if (!Array.prototype.at) Object.defineProperty(Array.prototype, 'at', { value: at, writable: true, configurable: true });
  if (!String.prototype.at) Object.defineProperty(String.prototype, 'at', { value: at, writable: true, configurable: true });
  if (!Array.prototype.findLast) Object.defineProperty(Array.prototype, 'findLast', { writable: true, configurable: true, value: function (f, t) { for (var i = this.length - 1; i >= 0; i--) if (f.call(t, this[i], i, this)) return this[i]; } });
  // shortcut: JSON copy, enough for the plain server data app.js clones; swap for a real polyfill if it ever clones Dates/Maps
  if (!window.structuredClone) window.structuredClone = function (v) { return v === undefined ? v : JSON.parse(JSON.stringify(v)); };
  if (window.crypto && !crypto.randomUUID) crypto.randomUUID = function () {
    var b = crypto.getRandomValues(new Uint8Array(16)), h = [];
    b[6] = (b[6] & 15) | 64; b[8] = (b[8] & 63) | 128;
    for (var i = 0; i < 16; i++) h.push((b[i] + 256).toString(16).slice(1));
    return h.slice(0, 4).join('') + '-' + h.slice(4, 6).join('') + '-' + h.slice(6, 8).join('') + '-' + h.slice(8, 10).join('') + '-' + h.slice(10).join('');
  };
  // Module scripts run before DOMContentLoaded, so by then app.js has set the flag, unless this browser couldn't run it.
  document.addEventListener('DOMContentLoaded', function () {
    if (window.appStarted) return;
    var main = document.getElementById('main');
    // A modern browser (replaceAll came with the ?? and ?. that app.js needs) only gets here when app.js failed to load,
    // e.g. no connection as a phone wakes up: that used to say "too old" too.
    if (main) main.innerHTML = String.prototype.replaceAll ? '<div class="empty"><h2>The site didn\'t finish loading</h2><p>Check your connection, then <a href="/">reload the page</a>.</p></div>'
      : '<div class="empty"><h2>This browser is too old for the site</h2><p>Update your device (Settings &rsaquo; General &rsaquo; Software Update), or open the site on a newer phone, tablet or computer.</p></div>';
  });
})();
