diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..84610f4
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,16 @@
+name: Game checks
+on: [push, pull_request]
+permissions:
+ contents: read
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - run: npm ci --ignore-scripts
+ - run: npm test
+ - run: node scripts/build-offline.cjs --check
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..26abc52
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 keptlive
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index bd2584a..b821e35 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
A browser road-trip game for spotting license plates from all 50 US states.
-[Play the game](https://keptlive.github.io/plate-tracker/)
+[Play the game](https://plates.kept.live)
## Play
@@ -30,7 +30,8 @@ Open http://localhost:8080. Keep the same local origin to retain saved progress.
## Deployment
-The intended GitHub Pages configuration serves the repository root from `main`.
+GitHub Pages serves the repository root from `main` at https://plates.kept.live
+(the custom domain is set in the `CNAME` file and the repository Pages settings).
All JavaScript, images and state data must be deployed together. The scripts in
`index.html` load in dependency order.
@@ -40,7 +41,43 @@ All 50 state cards and outlines, state facts and photos, an image lightbox,
hometown distances, achievements, progress indicators, celebrations, saved
progress, individual removal and confirmed reset.
-## Licensing
+## Refresh controls and offline play
-This repository does not yet specify a reuse license. Image provenance and
-reuse terms need review before applying a license to those assets.
+- Search by state name or abbreviation. Use All, Missing or Found to narrow the cards.
+ A just-found card stays visible in Missing while you read it; flip it back or
+ change the filter/search to refresh the list.
+- Keyboard: Tab to a card, then Enter or Space to find/flip it. On its back,
+ use Remove for the same confirmation as holding a card. Escape closes a popup;
+ focus returns to the opener. Browser zoom and reduced-motion settings are respected.
+- All 31 achievements remain available. Hometown changes update geography awards.
+- Once the page says **Ready for offline play**, the game, facts and 74 local photos
+ can be reopened without the game server. Hometown searches still need internet.
+ Google Fonts is not included in the offline cache; a system font may be used.
+ Browser cache eviction can remove the offline copy. Progress still uses the same
+ local storage keys and origin; it does not sync between devices.
+- Unreadable saved data is kept intact and a warning is shown. Reset All explicitly
+ resets collection/achievement storage, while keeping your hometown.
+
+## Development checks
+
+Node 22 is used in CI. The game itself still needs no build or npm dependencies.
+The npm packages are test tools only.
+
+```sh
+npm ci --ignore-scripts
+npm test
+npm run build:offline
+node scripts/build-offline.cjs --check
+```
+
+Commit the regenerated `sw.js` whenever any cached game file changes. CI rejects a
+stale cache manifest. An update waits until existing game tabs close, so a running
+session does not mix old and new assets. Localhost previews do not install a worker
+unless opened with `?offline-test`; use a fresh preview origin for repeated development.
+See [review notes](docs/refresh-review.md) for the baseline, checks and remaining gaps.
+
+## License
+
+The code is released under the [MIT License](LICENSE). The photos in `images/` come from
+Wikimedia Commons and keep their own Creative Commons or public-domain licenses
+(see `images/attribution.txt`); the MIT License does not cover them.
diff --git a/app.js b/app.js
index ff5087c..db199c8 100644
--- a/app.js
+++ b/app.js
@@ -2,11 +2,89 @@
const STORAGE_KEY = 'plateTracker';
const ACH_KEY = 'plateTrackerAch';
const HOME_KEY = 'plateTrackerHome';
-let checked = new Set(JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]'));
-let unlockedAch = new Set(JSON.parse(localStorage.getItem(ACH_KEY) || '[]'));
-let userOrigin = JSON.parse(localStorage.getItem(HOME_KEY) || 'null');
+const storageProblems = new Set();
+function readStored(key, fallback, validate) {
+ try {
+ const raw = localStorage.getItem(key);
+ if (raw === null) return fallback;
+ const value = JSON.parse(raw);
+ if (!validate(value)) throw new Error('Invalid saved data');
+ return value;
+ } catch (error) { storageProblems.add(key); return fallback; }
+}
+function writeStored(key, value) {
+ // Keep unreadable original data intact until the player explicitly resets it.
+ if (storageProblems.has(key)) { reportStorage(); return; }
+ try { localStorage.setItem(key, JSON.stringify(value)); }
+ catch (error) { storageProblems.add(key); }
+ reportStorage();
+}
+function reportStorage() {
+ document.getElementById('saveStatus').textContent = storageProblems.size
+ ? 'Saved data could not be read or updated. You can keep playing, but changes may not survive closing this page. Existing saved data has been kept.'
+ : 'Progress is saved in this browser.';
+}
+const stateCodes = new Set(STATES.map(s => s.abbr));
+const achievementIds = new Set(ACHIEVEMENTS.map(a => a.id));
+const validList = value => Array.isArray(value) && value.every(item => typeof item === 'string');
+const validHome = value => value === null || (typeof value === 'object' && typeof value.name === 'string' && value.name.length <= 300 && Number.isFinite(value.lat) && Math.abs(value.lat) <= 90 && Number.isFinite(value.lon) && Math.abs(value.lon) <= 180);
+let checked = new Set(readStored(STORAGE_KEY, [], validList).filter(code => stateCodes.has(code)));
+let unlockedAch = new Set(readStored(ACH_KEY, [], validList).filter(id => achievementIds.has(id)));
+let userOrigin = readStored(HOME_KEY, null, validHome);
+const reducedMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;
+let stateFilter = 'all';
+let pendingFilterRefresh = false;
+// Dialog stack handles nested photo views, background isolation and return focus.
+const dialogStack = [];
+let queuedAchievements = [];
+function syncDialogs() {
+ const top = dialogStack.at(-1)?.element;
+ document.getElementById('mainContent').inert = !!top;
+ document.querySelector('.bottom-bar').inert = !!top;
+ document.body.style.overflow = top ? 'hidden' : '';
+ for (const item of dialogStack) item.element.inert = item.element !== top;
+}
+function openDialog(element, preferred) {
+ if (dialogStack.some(item => item.element === element)) return;
+ dialogStack.push({element, opener: document.activeElement});
+ element.classList.add('active');
+ syncDialogs();
+ (preferred || element.querySelector('button')).focus();
+}
+function closeDialog(element) {
+ if (dialogStack.at(-1)?.element !== element) return;
+ const {opener} = dialogStack.pop();
+ element.classList.remove('active');
+ element.inert = false;
+ syncDialogs();
+ if (opener?.isConnected) opener.focus();
+ if (!dialogStack.length && queuedAchievements.length) {
+ const pending = queuedAchievements;
+ queuedAchievements = [];
+ setTimeout(() => showAchievementPopup(pending.filter(a => a.test(checked, STATES, userOrigin))), 0);
+ }
+ if (!dialogStack.length && pendingFilterRefresh) {
+ pendingFilterRefresh = false;
+ applyFilters();
+ }
+}
+document.addEventListener('keydown', event => {
+ const top = dialogStack.at(-1)?.element;
+ if (!top) return;
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ if (top.id === 'modal') dismissModal();
+ else if (top.id === 'lightbox') closeLightbox();
+ else closeDialog(top);
+ } else if (event.key === 'Tab') {
+ const controls = [...top.querySelectorAll('button, input, [tabindex="0"]')].filter(el => !el.disabled && el.getClientRects().length);
+ if (!controls.length) return;
+ const index = controls.indexOf(document.activeElement);
+ if (event.shiftKey && index <= 0) { event.preventDefault(); controls.at(-1).focus(); }
+ else if (!event.shiftKey && (index < 0 || index === controls.length - 1)) { event.preventDefault(); controls[0].focus(); }
+ }
+});
let isAnimating = {};
-let longPressTimer = null;
let modalCallback = null;
let svgBoxes = {};
@@ -64,21 +142,23 @@ STATES.forEach(st => {
const wrapper = document.createElement('div');
wrapper.className = 'card-wrapper' + (isChecked ? ' checked' : '');
wrapper.dataset.abbr = st.abbr;
+ wrapper.setAttribute('role', 'group');
+ wrapper.setAttribute('aria-label', st.name);
const svgData = svgBoxes[st.abbr] || { vb: '0 0 100 100', sw: 2 };
const svgMarkup = STATE_PATHS[st.abbr]
- ? ``
+ ? ``
: '';
wrapper.innerHTML = `
-
+
\u2713 Found
${st.abbr}
${st.name}
${svgMarkup}
-
+
${svgMarkup}
${st.name}
\u{1F3DB}
Capital
${st.capital}
@@ -86,69 +166,84 @@ STATES.forEach(st => {
\u{1F43E}
Animal
${st.animal}
\u{1F33C}
Flower
${st.flower}
\u{1F4CD}
Distance
${getDistLabel(st)}
-
+
+
`;
- // Touch / click handling
+ // Click activation works with touch, mouse and keyboard without pointerup
+ // accidentally marking a state while the user scrolls the collection.
let didLongPress = false;
-
- function onPointerDown(e) {
- didLongPress = false;
- if (checked.has(st.abbr)) {
- longPressTimer = setTimeout(() => {
- didLongPress = true;
- showModal('Remove License Plate', `Remove ${st.name} from your found list?`, () => {
- checked.delete(st.abbr);
- save();
- wrapper.classList.remove('checked');
- const card = wrapper.querySelector('.card');
- if (card.classList.contains('flipped')) card.classList.remove('flipped');
- updateProgress();
- recheckAchievements();
- }, 'Remove License Plate');
- }, 600);
- }
+ let startPoint = null;
+ let moved = false;
+ let pressTimer;
+ const front = wrapper.querySelector('.card-front');
+ const back = wrapper.querySelector('.card-back');
+ function removePlate() {
+ showModal('Remove License Plate', `Remove ${st.name} from your found list?`, () => {
+ checked.delete(st.abbr);
+ wrapper.classList.remove('checked', 'raised');
+ wrapper.querySelector('.card').classList.remove('flipped');
+ syncCardFaces(wrapper);
+ recheckAchievements();
+ save();
+ updateProgress();
+ applyFilters();
+ }, 'Remove License Plate');
}
-
- function onPointerUp(e) {
- clearTimeout(longPressTimer);
- if (didLongPress) return;
- if (e.target.closest('.info-btn')) return; // handled separately
+ function activate() {
if (isAnimating[st.abbr]) return;
-
const card = wrapper.querySelector('.card');
- if (card.classList.contains('flipped')) {
- flipWithLock(card, st.abbr, false);
- return;
- }
- flipWithLock(card, st.abbr, true);
-
- if (!checked.has(st.abbr)) {
+ const toBack = !card.classList.contains('flipped');
+ if (toBack && !checked.has(st.abbr)) {
checked.add(st.abbr);
- save();
wrapper.classList.add('checked');
+ save();
updateProgress();
spawnMiniConfetti(wrapper);
- checkNewAchievements();
}
+ flipWithLock(card, st.abbr, toBack);
+ checkNewAchievements();
+ // Keep the just-found facts visible until a Missing filter is used again.
+ if (!toBack) applyFilters();
+ updateFilterStatus();
}
-
- function onPointerLeave() { clearTimeout(longPressTimer); }
-
- wrapper.addEventListener('pointerdown', onPointerDown);
- wrapper.addEventListener('pointerup', onPointerUp);
- wrapper.addEventListener('pointerleave', onPointerLeave);
- wrapper.addEventListener('pointercancel', onPointerLeave);
+ wrapper.addEventListener('pointerdown', e => {
+ if (e.isPrimary === false || e.button !== 0 || e.target.closest('button')) return;
+ didLongPress = false;
+ moved = false;
+ startPoint = [e.clientX, e.clientY];
+ if (checked.has(st.abbr)) pressTimer = setTimeout(() => {
+ didLongPress = true;
+ (wrapper.querySelector('.card.flipped') ? back : front).focus();
+ removePlate();
+ }, 600);
+ });
+ wrapper.addEventListener('pointermove', e => {
+ if (startPoint && Math.hypot(e.clientX - startPoint[0], e.clientY - startPoint[1]) > 10) {
+ moved = true;
+ clearTimeout(pressTimer);
+ }
+ });
+ for (const type of ['pointerup', 'pointerleave', 'pointercancel']) wrapper.addEventListener(type, () => {
+ clearTimeout(pressTimer);
+ startPoint = null;
+ });
+ wrapper.addEventListener('pointercancel', () => { moved = true; });
+ wrapper.addEventListener('click', e => {
+ if (e.target.closest('button')) return;
+ if (didLongPress || moved) { didLongPress = false; moved = false; return; }
+ activate();
+ });
wrapper.addEventListener('contextmenu', e => e.preventDefault());
-
- // Info button handler — use click (more reliable on mobile with 3D transforms)
- wrapper.querySelector('.info-btn').addEventListener('click', (e) => {
- e.stopPropagation();
- e.preventDefault();
- clearTimeout(longPressTimer);
- showInfoPopup(st.abbr);
+ for (const face of [front, back]) face.addEventListener('keydown', e => {
+ if (e.target !== face) return;
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); activate(); }
});
+ back.tabIndex = -1;
+ back.setAttribute('aria-label', `${st.name} facts. Press Enter to flip back.`);
+ wrapper.querySelector('.remove-btn').addEventListener('click', removePlate);
+ wrapper.querySelector('.info-btn').addEventListener('click', () => showInfoPopup(st.abbr));
grid.appendChild(wrapper);
});
@@ -163,19 +258,62 @@ function flipWithLock(card, abbr, toBack) {
card.classList.remove('flipped');
setTimeout(() => { wrapper.classList.remove('raised'); }, 600);
}
- setTimeout(() => { isAnimating[abbr] = false; }, 600);
+ syncCardFaces(wrapper);
+ setTimeout(() => { isAnimating[abbr] = false; }, reducedMotion() ? 0 : 600);
}
+function syncCardFaces(wrapper) {
+ const front = wrapper.querySelector('.card-front');
+ const back = wrapper.querySelector('.card-back');
+ const flipped = wrapper.querySelector('.card').classList.contains('flipped');
+ const focusWasInside = wrapper.contains(document.activeElement);
+ front.inert = flipped;
+ front.setAttribute('aria-hidden', String(flipped));
+ front.tabIndex = flipped ? -1 : 0;
+ back.inert = !flipped;
+ back.setAttribute('aria-hidden', String(!flipped));
+ back.tabIndex = flipped ? 0 : -1;
+ const st = STATES.find(s => s.abbr === wrapper.dataset.abbr);
+ front.setAttribute('aria-label', `${st.name}: ${checked.has(st.abbr) ? 'found; show facts' : 'mark as found'}`);
+ front.setAttribute('aria-pressed', String(checked.has(st.abbr)));
+ if (focusWasInside) (flipped ? back : front).focus();
+}
+function updateFilterStatus() {
+ const visible = [...grid.children].filter(el => !el.hidden).length;
+ document.getElementById('filterStatus').textContent = `${visible} states shown / ${50 - checked.size} left to find`;
+}
+function applyFilters() {
+ if (dialogStack.length) { pendingFilterRefresh = true; return; }
+ const query = document.getElementById('stateSearch').value.trim().toLowerCase();
+ for (const wrapper of grid.children) {
+ const st = STATES.find(s => s.abbr === wrapper.dataset.abbr);
+ const match = (st.name.toLowerCase().includes(query) || st.abbr.toLowerCase().includes(query)) &&
+ (stateFilter === 'all' || (stateFilter === 'found') === checked.has(st.abbr));
+ if (!match && wrapper.contains(document.activeElement)) document.getElementById('stateSearch').focus();
+ wrapper.hidden = !match;
+ }
+ document.getElementById('emptyState').hidden = [...grid.children].some(el => !el.hidden);
+ updateFilterStatus();
+}
+document.getElementById('stateSearch').addEventListener('input', applyFilters);
+document.querySelectorAll('[data-filter]').forEach(button => button.addEventListener('click', () => {
+ stateFilter = button.dataset.filter;
+ document.querySelectorAll('[data-filter]').forEach(b => b.setAttribute('aria-pressed', String(b === button)));
+ applyFilters();
+}));
+
// === PERSISTENCE ===
function save() {
- localStorage.setItem(STORAGE_KEY, JSON.stringify([...checked]));
- localStorage.setItem(ACH_KEY, JSON.stringify([...unlockedAch]));
+ writeStored(STORAGE_KEY, [...checked]);
+ writeStored(ACH_KEY, [...unlockedAch]);
}
function updateProgress() {
const count = checked.size;
document.getElementById('progressCount').textContent = `${count} / 50`;
document.getElementById('progressFill').style.width = (count / 50 * 100) + '%';
+ document.getElementById('progressBar').setAttribute('aria-valuenow', count);
+ document.getElementById('achBtn').setAttribute('aria-label', `View achievements: ${unlockedAch.size} of ${ACHIEVEMENTS.length} unlocked`);
document.getElementById('achCount').textContent = `${unlockedAch.size}/${ACHIEVEMENTS.length}`;
}
@@ -222,10 +360,15 @@ function showInfoPopup(abbr) {
`;
popup.querySelector('.info-body').innerHTML = html;
- popup.classList.add('active');
+ popup.setAttribute('aria-label', `${st.name} information`);
+ openDialog(popup);
// Wire up image click → lightbox
popup.querySelectorAll('.info-img').forEach(img => {
+ img.tabIndex = 0;
+ img.setAttribute('role', 'button');
+ img.setAttribute('aria-label', `Enlarge ${img.alt} photo`);
+ img.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openLightbox(img.src, img.alt); } });
img.addEventListener('click', (e) => {
e.stopPropagation();
openLightbox(img.src, img.alt);
@@ -239,11 +382,12 @@ const lightboxEl = document.getElementById('lightbox');
function openLightbox(src, label) {
lightboxEl.querySelector('img').src = src;
lightboxEl.querySelector('.lightbox-label').textContent = label;
- lightboxEl.classList.add('active');
+ lightboxEl.querySelector('img').alt = label;
+ openDialog(lightboxEl);
}
function closeLightbox() {
- lightboxEl.classList.remove('active');
+ closeDialog(lightboxEl);
lightboxEl.querySelector('img').src = '';
}
@@ -257,10 +401,10 @@ lightboxEl.addEventListener('click', (e) => {
});
document.getElementById('infoClose').addEventListener('click', () => {
- document.getElementById('infoPopup').classList.remove('active');
+ closeDialog(document.getElementById('infoPopup'));
});
document.getElementById('infoPopup').addEventListener('click', (e) => {
- if (e.target === e.currentTarget) e.currentTarget.classList.remove('active');
+ if (e.target === e.currentTarget) closeDialog(e.currentTarget);
});
// === ACHIEVEMENT SYSTEM ===
@@ -297,6 +441,10 @@ function recheckAchievements() {
// Achievement popup — reuses the existing modal system
function showAchievementPopup(achievements) {
if (achievements.length === 0) return;
+ if (dialogStack.length) {
+ queuedAchievements = [...new Map([...queuedAchievements, ...achievements].map(a => [a.id, a])).values()];
+ return;
+ }
const box = document.querySelector('.modal-box');
const titleEl = document.getElementById('modalTitle');
const textEl = document.getElementById('modalText');
@@ -327,15 +475,14 @@ function showAchievementPopup(achievements) {
confirmBtn.textContent = 'Yes';
confirmBtn.style.background = '';
};
- document.getElementById('modal').classList.add('active');
- modalOpenedAt = Date.now();
+ openDialog(document.getElementById('modal'), document.getElementById('modalCancel').style.display === 'none' ? document.getElementById('modalConfirm') : document.getElementById('modalCancel'));
spawnFireworks();
}
// Achievement panel
document.getElementById('achBtn').addEventListener('click', showAchievementPanel);
document.getElementById('achPanelClose').addEventListener('click', () => {
- document.getElementById('achPanel').classList.remove('active');
+ closeDialog(document.getElementById('achPanel'));
});
function showAchievementPanel() {
@@ -361,61 +508,60 @@ function showAchievementPanel() {
});
body.innerHTML = html;
- panel.classList.add('active');
+ openDialog(panel);
}
// === MODAL ===
-let modalOpenedAt = 0;
function showModal(title, text, onConfirm, confirmLabel) {
document.getElementById('modalTitle').textContent = title;
document.getElementById('modalText').textContent = text;
document.getElementById('modalConfirm').textContent = confirmLabel || 'Yes';
modalCallback = onConfirm;
- document.getElementById('modal').classList.add('active');
- modalOpenedAt = Date.now();
+ openDialog(document.getElementById('modal'), document.getElementById('modalCancel').style.display === 'none' ? document.getElementById('modalConfirm') : document.getElementById('modalCancel'));
}
function closeModal() {
- // Ignore clicks within 400ms of opening (blocks synthetic click from card tap)
- if (Date.now() - modalOpenedAt < 400) return;
- document.getElementById('modal').classList.remove('active');
+ closeDialog(document.getElementById('modal'));
+ document.querySelector('.modal-box').classList.remove('ach');
+ document.getElementById('modalTitle').classList.remove('ach');
+ document.getElementById('modalCancel').style.display = '';
+ document.getElementById('modalConfirm').style.background = '';
}
-
-document.getElementById('modalCancel').addEventListener('click', () => {
- closeModal();
- modalCallback = null;
-});
+function dismissModal() { closeModal(); modalCallback = null; }
+document.getElementById('modalCancel').addEventListener('click', dismissModal);
document.getElementById('modalConfirm').addEventListener('click', () => {
- closeModal();
- if (modalCallback) modalCallback();
+ const callback = modalCallback;
modalCallback = null;
+ closeModal();
+ if (callback) callback();
});
-document.getElementById('modal').addEventListener('click', (e) => {
- if (e.target === e.currentTarget) {
- closeModal();
- modalCallback = null;
- }
-});
+document.getElementById('modal').addEventListener('click', e => { if (e.target === e.currentTarget) dismissModal(); });
+document.getElementById('achPanel').addEventListener('click', e => { if (e.target === e.currentTarget) closeDialog(e.currentTarget); });
// === RESET ===
document.getElementById('resetBtn').addEventListener('click', () => {
- if (checked.size === 0) return;
+ if (checked.size === 0 && !storageProblems.has(STORAGE_KEY) && !storageProblems.has(ACH_KEY)) return;
showModal('Reset All?', 'This will clear all your found states and achievements. Are you sure?', () => {
+ storageProblems.delete(STORAGE_KEY);
+ storageProblems.delete(ACH_KEY);
checked.clear();
unlockedAch.clear();
save();
document.querySelectorAll('.card-wrapper').forEach(w => {
- w.classList.remove('checked');
+ w.classList.remove('checked', 'raised');
w.querySelector('.card').classList.remove('flipped');
+ syncCardFaces(w);
});
updateProgress();
renderAchievementSection();
+ applyFilters();
});
});
// === MINI CONFETTI (per state found) ===
function spawnMiniConfetti(el) {
+ if (reducedMotion()) return;
const rect = el.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
@@ -448,6 +594,7 @@ function spawnMiniConfetti(el) {
// === CONFETTI + FIREWORKS ===
function spawnConfetti() {
+ if (reducedMotion()) return;
const colors = ['#ffd200','#ff6b35','#ff6b6b','#667eea','#764ba2','#4ecdc4','#96c93d','#f093fb'];
for (let i = 0; i < 80; i++) {
const c = document.createElement('div');
@@ -470,6 +617,7 @@ function spawnConfetti() {
}
function spawnFireworks() {
+ if (reducedMotion()) return;
spawnConfetti();
// Canvas fireworks burst
let canvas = document.getElementById('fwCanvas');
@@ -571,16 +719,21 @@ function initHometown() {
async function geocode() {
const q = input.value.trim();
- if (!q) return;
+ if (!q || goBtn.disabled) return;
+ const status = document.getElementById('hometownStatus');
+ status.textContent = 'Looking up hometown...';
goBtn.textContent = '...';
goBtn.disabled = true;
+ const controller = new AbortController();
+ const lookupTimeout = setTimeout(() => controller.abort(), 10000);
try {
const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(q)}&countrycodes=us&format=json&limit=1&addressdetails=1`;
- const res = await fetch(url, { headers: { 'Accept': 'application/json' } });
+ const res = await fetch(url, { headers: { 'Accept': 'application/json' }, signal: controller.signal });
+ if (!res.ok) throw new Error('Lookup unavailable');
const data = await res.json();
+ if (!Array.isArray(data)) throw new Error('Invalid response');
if (!data.length) {
- input.value = '';
- input.placeholder = 'City not found, try again...';
+ status.textContent = 'No hometown found. Try a city and state.';
return;
}
const place = data[0];
@@ -588,15 +741,22 @@ function initHometown() {
const city = addr.city || addr.town || addr.village || addr.hamlet || place.display_name.split(',')[0];
const stateAbbr = STATE_NAME_TO_ABBR[addr.state || ''] || '';
const zip = addr.postcode || '';
- const homeName = stateAbbr && zip ? `${city}, ${stateAbbr} ${zip}` : city;
- userOrigin = { name: homeName, lat: parseFloat(place.lat), lon: parseFloat(place.lon) };
- localStorage.setItem(HOME_KEY, JSON.stringify(userOrigin));
+ const homeName = stateAbbr ? `${city}, ${stateAbbr}${zip ? ' ' + zip : ''}` : city;
+ const candidate = { name: homeName, lat: parseFloat(place.lat), lon: parseFloat(place.lon) };
+ if (!validHome(candidate)) throw new Error('Invalid location');
+ userOrigin = candidate;
+ storageProblems.delete(HOME_KEY);
+ writeStored(HOME_KEY, userOrigin);
showSet();
updateAllDistances();
+ status.textContent = 'Hometown updated. Distances are straight-line estimates, not driving distances.';
+ editBtn.focus();
recheckAchievements();
+ checkNewAchievements();
} catch(e) {
- input.placeholder = 'Error, try again...';
+ status.textContent = 'Hometown lookup is unavailable. Keep playing and try again when connected.';
} finally {
+ clearTimeout(lookupTimeout);
goBtn.textContent = 'Go';
goBtn.disabled = false;
}
@@ -648,6 +808,8 @@ function renderAchievementSection() {
// === INIT ===
initHometown();
+recheckAchievements();
+applyFilters();
updateProgress();
// Detect achievements that qualify but were never shown (e.g. earned before code update or between sessions)
const initNew = [];
@@ -662,5 +824,5 @@ updateProgress();
renderAchievementSection();
// Show popups for any achievements earned but never notified
if (initNew.length > 0) {
- setTimeout(() => showAchievementPopup(initNew), 500);
+ setTimeout(() => showAchievementPopup(initNew.filter(a => a.test(checked, STATES, userOrigin))), 500);
}
diff --git a/docs/refresh-review.md b/docs/refresh-review.md
new file mode 100644
index 0000000..433cef1
--- /dev/null
+++ b/docs/refresh-review.md
@@ -0,0 +1,24 @@
+# Plate Tracker review and refresh — October 24, 2026
+
+Baseline: GitHub main cc782d0, clean existing WSL checkout; live Pages homepage HTTP 200. Preserved feature inventory: 50 state cards and outlines, tap-to-find and reversible flip, hold-to-remove with confirmation, capital/nickname/animal/flower/distance facts, expanded state facts and related states, local animal/flower photos and lightbox, hometown lookup/edit, 31 achievements in both inline and popup lists, progress, confetti/fireworks, confirmed reset, existing plateTracker/plateTrackerAch/plateTrackerHome storage keys. Existing dark glass cards, yellow/orange accents and Fredoka typography retained.
+
+Findings to address:
+- Unguarded JSON/storage reads and writes can prevent startup or gameplay.
+- Cards have no keyboard activation; hidden card faces remain in the accessibility tree; dialogs lack focus containment/Escape/return focus; icon buttons lack names; zoom disabled.
+- Confirmation callbacks execute even when the 400ms close guard rejects the close; dismissing achievement popups leaves confirmation styling/cancel state behind.
+- Info-button pointerdown can begin removal; scrolling gestures and non-primary buttons can activate cards.
+- Hometown changes revoke but do not grant qualifying achievements; saved achievement counts may disagree with current state.
+- Three columns on narrow phones leave card-back facts clipped/tiny.
+- No state search/filter or offline cache.
+
+Boundaries: no state facts, image bytes, existing achievement definitions, or storage key migrations. Distances are straight-line distances to the existing representative state coordinates, not driving distances. Wikimedia attribution only names the site, not individual source pages/authors/licenses; provenance remains unresolved and no blanket image license is added. No full factual review of all state/animal/flower copy in this refresh.
+
+Completed refresh and validation:
+- Search and All/Missing/Found filters; larger phone cards and readable facts; explicit Remove control alongside preserved hold-to-remove; keyboard finding/flipping; named controls, focus containment/return and nested dialogs; zoom and reduced-motion support.
+- Validated local saves with non-destructive fallback/warnings; immediate confirmation cleanup; gesture guards; consistent achievement reconciliation and hometown awards; bounded hometown requests with duplicate-submit guard and useful errors.
+- Versioned same-origin offline shell plus all 74 local photos. Hometown requests remain network-only. No forced activation; old sessions finish before new worker activation. CI checks that cached content and version agree.
+- 15 automated regressions pass using jsdom and a worker fixture: baseline inventory/assets, legacy saves, corrupt/blocked storage, keyboard actions, immediate removal/reset/cancel, search/filters, nested photo focus, hometown awards/failures/duplicates, scroll/hold behavior, delayed popup ordering, offline scope and cache cleanup.
+- Actual browser checks: desktop and 320px/390px phone layouts, keyboard activation, achievement popup dismissal, facts, image enlargement, nested Escape/return focus, persistence after reload. Stopped the local HTTP server, reloaded successfully from the installed worker, and opened a loaded state photo (natural width 250) without that server. The offline test covers the game origin, not a forced loss of all internet access.
+- Source data, state outlines, image bytes and achievement definitions are unchanged. Existing storage keys are retained. No public deployment is included in this review branch.
+
+Remaining review boundaries: individual image provenance/licensing, full source verification of educational facts, and physical iOS/Android testing. Desktop browser viewport checks are not device certification. External hometown lookup availability is outside the game's control; failures preserve the prior home.
diff --git a/index.html b/index.html
index 67b72c8..80cef8b 100644
--- a/index.html
+++ b/index.html
@@ -2,8 +2,11 @@
-
+
License Plate Tracker
+
+
+
+
@@ -236,9 +240,9 @@
-
+
-
License Plate Tracker
+
License Plate Tracker
Tap a card when you spot its plate!
@@ -247,43 +251,59 @@
States Found
0 / 50
-
+
-
+
-
+
Home:
-
+
+
Optional: hometown search uses OpenStreetMap. Distances are approximate straight-line miles.
+
+
+
+
+
+
+
+
+
+
+
Tap a card to mark it found and flip it. Tap again to flip back. Hold a found card to remove it, or use its Remove button.