/* Clutch Coach: "Show me how", a 30-second guided tour of the sample report (sghadimi.com). Five steps. Each lights one part of the page, scrolls it into view and says what it is for; step 4 plays a coaching moment so the correction is seen on the video. Start: the "Show me how" button, or ?tour=1. */ (() => { const $ = s => document.querySelector(s); const STEPS = [ { el: '#hero', title: 'A finished report', text: 'This is the sample workout, already analysed: player #8’s form score, field goals, entry angle, drift and top speed. Everything here came from one phone video.' }, { el: '.steps3', title: 'Three taps for your own video', text: 'Upload a video, then tap the rim, the four corners of the paint and your player. Build report does the rest on this device; nothing is uploaded.' }, { el: '.tl', title: 'The whole session on one line', text: 'Every shot, sprint and form fix is on the timeline. Tap anywhere on it to jump the video there.' }, { el: '.stagewrap', title: 'Coaching moments', text: 'Each coaching moment is a time-tagged fix with a drill and reps. The first one is playing now, with the correction drawn on the video. The full list sits under the timeline.', play: true }, { el: '.rail', title: 'Take it with you', text: 'Download the report as a page for the player, copy a short summary, or switch to Clips to play and export the reel.' }, ]; let i = -1, card = null, lit = null; const visible = el => el && !el.hidden && el.offsetParent !== null; function build() { card = document.createElement('div'); card.className = 'tour-card'; card.setAttribute('role', 'dialog'); card.setAttribute('aria-live', 'polite'); card.setAttribute('aria-label', 'Guided tour'); card.innerHTML = '
' + '

' + '
'; document.body.appendChild(card); card.querySelector('.tour-x').onclick = stop; card.querySelector('.tour-back').onclick = () => go(i - 1); card.querySelector('.tour-next').onclick = () => (i >= STEPS.length - 1 ? stop() : go(i + 1)); } function go(n) { if (n < 0) return; i = n; if (location.hash && location.hash !== '#studio') location.hash = '#studio'; const s = STEPS[i]; if (s.play) { const m = document.querySelector('#moments .mcard'); if (m) m.click(); } const el = $(s.el); if (lit) lit.classList.remove('tour-lit'); lit = visible(el) ? el : null; if (lit) { lit.classList.add('tour-lit'); const top = $('.top'); const go = () => scrollTo({ top: Math.max(0, lit.getBoundingClientRect().top + scrollY - (top ? top.offsetHeight : 0) - 10), behavior: matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' }); if (s.play) setTimeout(go, 350); else go(); } card.querySelector('.tour-n').textContent = `${i + 1} of ${STEPS.length}`; card.querySelector('.tour-t').textContent = s.title; card.querySelector('.tour-p').textContent = s.text; card.querySelector('.tour-back').disabled = i === 0; card.querySelector('.tour-next').textContent = i === STEPS.length - 1 ? 'Done' : 'Next'; card.querySelector('.tour-next').focus({ preventScroll: true }); } function start() { if (!card) build(); card.hidden = false; document.body.classList.add('touring'); go(0); } function stop() { if (lit) lit.classList.remove('tour-lit'); lit = null; if (card) card.hidden = true; document.body.classList.remove('touring'); const v = $('#vid'); if (v && !v.paused) { const b = $('#playBtn'); if (b) b.click(); } const t = $('#tourBtn'); if (t) t.focus(); } document.addEventListener('keydown', e => { if (e.key === 'Escape' && card && !card.hidden) stop(); }); const btn = $('#tourBtn'); if (btn) btn.addEventListener('click', start); // ?tour=1 starts it once the sample report is on screen if (/[?&]tour=1/.test(location.search)) { const t0 = Date.now(), wait = setInterval(() => { if (visible($('#hero')) || Date.now() - t0 > 15000) { clearInterval(wait); start(); } }, 300); } })();