diff --git a/public/css/style.css b/public/css/style.css index 31a375c..43ec97c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -52,7 +52,7 @@ svg.ic { width: 1.25em; height: 1.25em; flex: none; } #board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; } /* portrait phones / narrow windows: board on top, panels underneath */ -@media (orientation: portrait), (max-width: 760px) { +@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) { #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top" "stage" "side"; } #stage { aspect-ratio: var(--aspect-p, 16 / 26); max-height: 58dvh; width: 100%; } #side { border-left: 0; border-top: 1px solid var(--line); padding: 8px 10px calc(8px + var(--safe-b)); gap: 8px; } @@ -96,7 +96,7 @@ button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba( #btnWave.attn { animation: glow 1.4s infinite; } @keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(77, 227, 255, .25); } } -@media (orientation: portrait), (max-width: 760px) { +@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) { #topbar { padding: 6px 8px; } .stat { padding: 0 8px; font-size: 15px; } #btnWave { flex: 1 1 auto; } @@ -135,7 +135,7 @@ button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba( .tbtn.poor .cost { color: var(--red); } .tbtn.poor { opacity: .72; } @media (pointer: coarse) { .tbtn .key { display: none; } } -@media (orientation: portrait), (max-width: 760px) { +@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) { #palette { position: sticky; top: -8px; z-index: 2; margin: -8px -10px 0; padding: 8px 10px 6px; background: rgba(8, 13, 26, .97); } #palette { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 10px; } #palette::-webkit-scrollbar { display: none; } @@ -231,7 +231,7 @@ input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono); @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } } /* compact info panel on stacked (portrait / narrow) layouts: must come after the base rules above */ -@media (orientation: portrait), (max-width: 760px) { +@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) { .kv { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-bottom: 6px; } .kvp { display: inline-flex; gap: 6px; } .info .desc { font-size: 12.5px; margin: 0 0 4px; } @@ -242,10 +242,38 @@ input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono); } /* stacked layouts: keep the top bar to two rows even with the co-op chip */ -@media (orientation: portrait), (max-width: 760px) { +@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) { .chip { padding: 0 8px; font-size: 12.5px; } .chip #netPing { display: none; } #netChip { margin-left: auto; } .spacer { display: none; } #btnWave { flex: 1 1 130px; } } + +/* narrow portrait phones: the room chip moves into the players panel, stats shrink so the bar stays two rows */ +@media (max-width: 420px) { + #netChip { display: none; } + .stat { padding: 0 7px; gap: 4px; font-size: 14px; } + .stat .lbl { font-size: 10px; letter-spacing: .06em; } + #topbar { gap: 5px 6px; padding: 5px 6px; } +} +/* small landscape phones: one slim top bar, narrower side panel */ +@media (orientation: landscape) and (max-height: 520px) and (max-width: 700px) { + :root { --side-w: 200px; --btn: 38px; } + #netChip { display: none; } + .stat .lbl { display: none; } + .stat { padding: 0 6px; font-size: 14px; } + button.icon { min-width: 36px; padding: 0 6px; } + #topbar { gap: 4px; padding: 3px 6px; } + .tbtn .nm { font-size: 10.5px; } +} + +/* very small phones (320px) */ +@media (max-width: 340px) { + :root { --btn: 38px; } + .stat .lbl { display: none; } + .stat { padding: 0 6px; } + #btnWave { flex: 1 1 80px; padding: 0 8px; } + button.icon { min-width: 38px; padding: 0 4px; } + #topbar { gap: 4px; padding: 4px; } +} diff --git a/public/js/main.js b/public/js/main.js index 308376e..61f93a9 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -334,7 +334,7 @@ const ctrl = app.ctrl, box = $('players'); if (!ctrl || ctrl.kind !== 'remote') { box.hidden = true; return; } box.hidden = false; - let html = '

Room ' + (ctrl.room || '') + '

'; + let html = '

Room ' + (ctrl.room || '') + '

'; for (const p of ctrl.players) { html += '
' + (ctrl.you && p.pid === ctrl.you.pid ? '(you)' : '') + (p.host ? 'host' : '') + (p.online ? '' : 'offline') + '
'; @@ -392,7 +392,7 @@ chip.hidden = false; $('netRoom').textContent = ctrl.room || ''; const p = ctrl.rtt ? ctrl.rtt + ' ms' : ''; - if (L.ping !== p) { L.ping = p; $('netPing').textContent = p; chip.classList.toggle('bad', ctrl.rtt > 220); } + if (L.ping !== p) { L.ping = p; $('netPing').textContent = p; chip.classList.toggle('bad', ctrl.rtt > 220); const pp = $('plPing'); if (pp) pp.textContent = p ? '\u00b7 ' + p : ''; } } renderWavePanel(view); updateInfoDynamic(); @@ -880,7 +880,10 @@ updateResumeButton(); Audio.music('theme'); } - if (root.navigator.serviceWorker && root.location.protocol.startsWith('http')) { /* reserved for offline support */ } + // installable + offline-capable solo play (service workers need https or localhost) + if (root.navigator.serviceWorker && (root.location.protocol === 'https:' || /^(localhost|127\.0\.0\.1|\[::1\])$/.test(root.location.hostname))) { + root.navigator.serviceWorker.register('sw.js').catch(() => {}); + } } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else boot(); diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..f423f55 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,25 @@ +/* Netwall service worker: network-first so updates always win, cache as an offline fallback (solo play offline). */ +const CACHE = 'netwall-v1'; +const CORE = ['./', 'index.html', 'css/style.css', 'js/sim.js', 'js/audio.js', 'js/controllers.js', 'js/render.js', 'js/main.js', + 'manifest.webmanifest', 'icons/icon.svg', 'icons/icon-192.png', 'assets/music/tracks.json']; + +self.addEventListener('install', (e) => { + e.waitUntil(caches.open(CACHE).then((c) => c.addAll(CORE)).then(() => self.skipWaiting()).catch(() => self.skipWaiting())); +}); +self.addEventListener('activate', (e) => { + e.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim())); +}); +self.addEventListener('fetch', (e) => { + const req = e.request; + if (req.method !== 'GET') return; + const url = new URL(req.url); + if (url.origin !== self.location.origin) return; + e.respondWith( + fetch(req) + .then((res) => { + if (res.ok && res.type === 'basic') { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {}); } + return res; + }) + .catch(() => caches.match(req).then((r) => r || caches.match('index.html'))), + ); +});