';
function fmt(n){ return '€' + Math.round(n).toLocaleString('it-IT'); }
function calc(){
var coperti=parseInt(document.getElementById('inp-coperti').value);
var scontrino=parseInt(document.getElementById('inp-scontrino').value);
var pctTuristi=parseInt(document.getElementById('inp-turisti').value) / 100;
var mensile=coperti * scontrino * 26;
var upliftS=mensile * 0.12;
var hasTuristi=pctTuristi > 0.20;
var upliftT=hasTuristi ? mensile * pctTuristi * 0.35:0;
var totale=upliftS + upliftT;
var roi=(totale / 14.99).toFixed(1);
var paybackDays=totale > 0 ? Math.ceil(14.99 / (totale / 26)):null;
document.getElementById('val-coperti').textContent=coperti;
document.getElementById('val-scontrino').textContent=scontrino;
document.getElementById('val-turisti').textContent=Math.round(pctTuristi * 100);
var prevS=document.getElementById('res-scontrino').textContent;
var prevT=document.getElementById('res-turisti').textContent;
var prevTot=document.getElementById('res-totale').textContent;
var prevROI=document.getElementById('res-roi').textContent;
animateROINumber(document.getElementById('res-scontrino'), prevS, '+' + fmt(upliftS), 320);
animateROINumber(document.getElementById('res-totale'), prevTot, '+' + fmt(totale), 320);
animateROINumber(document.getElementById('res-roi'), prevROI, roi + ':1', 280);
var statTuristi=document.getElementById('stat-turisti');
var noteTuristi=document.getElementById('note-turisti');
if(hasTuristi){
animateROINumber(document.getElementById('res-turisti'), prevT, '+' + fmt(upliftT), 320);
statTuristi.classList.remove('mc-roi-stat--muted');
noteTuristi.textContent='';
}else{
var resTuristi=document.getElementById('res-turisti');
if(resTuristi._mcAnim) cancelAnimationFrame(resTuristi._mcAnim);
resTuristi._mcAnim=null;
resTuristi.textContent='—';
statTuristi.classList.add('mc-roi-stat--muted');
noteTuristi.textContent='Attivo con >20% turisti';
}
var paybackEl=document.getElementById('res-payback');
if(paybackEl){
var paybackText=paybackDays!==null&&paybackDays <=60
? 'Si ripaga in ' + paybackDays + (paybackDays===1 ? ' giorno':' giorni')
: 'Si ripaga in meno di 2 mesi';
paybackEl.textContent=paybackText;
}}
['inp-coperti','inp-scontrino','inp-turisti','inp-tipo'].forEach(function(id){
var el=document.getElementById(id);
if(el) el.addEventListener('input', calc);
});
calc();
}
function initWordReveal(){
var headings=$$('.entry-content h2, .entry-content h3');
if(!headings.length) return;
headings.forEach(function(h){
if(h.closest('.menucini-toc')) return;
h.classList.remove('curtain-reveal');
var words=h.innerHTML.split(/(\s+)/);
h.innerHTML=words.map(function(w, i){
if(!w.trim()) return w;
var delay=Math.min(i * 60, 600);
return '' + w + '';
}).join('');
});
var io=new IntersectionObserver(function(entries){
entries.forEach(function(entry){
if(!entry.isIntersecting) return;
entry.target.querySelectorAll('.word-reveal').forEach(function(w){
w.classList.add('is-visible');
});
io.unobserve(entry.target);
});
}, { threshold: 0.15, rootMargin: '0px 0px -30px 0px' });
headings.forEach(function(h){ io.observe(h); });
}
function initTOCIndicator(){
var toc=$('.menucini-toc');
if(!toc) return;
var tocList=toc.querySelector('.toc-list')||toc.querySelector('ol')||toc.querySelector('ul');
if(!tocList) return;
var indicator=document.createElement('div');
indicator.className='mc-toc-indicator';
tocList.style.position='relative';
tocList.appendChild(indicator);
var links=Array.prototype.slice.call(toc.querySelectorAll('a[href^="#"]'));
if(!links.length) return;
var headings=links.map(function(a){
var id=a.getAttribute('href').slice(1);
return document.getElementById(id);
}).filter(Boolean);
function updateActive(){
var scrollY=window.scrollY + window.innerHeight * 0.25;
var activeIdx=0;
headings.forEach(function(h, i){
if(h.getBoundingClientRect().top + window.scrollY <=scrollY) activeIdx=i;
});
links.forEach(function(a, i){
a.classList.toggle('mc-toc-active', i===activeIdx);
});
var activeLink=links[activeIdx];
if(activeLink){
var listRect=tocList.getBoundingClientRect();
var linkRect=activeLink.getBoundingClientRect();
indicator.style.top=(linkRect.top - listRect.top + tocList.scrollTop) + 'px';
indicator.style.height=linkRect.height + 'px';
}}
updateActive();
on(window, 'scroll', updateActive, { passive: true });
}
function initSmoothAnchors(){
on(document, 'click', function(e){
var a=e.target.closest('a[href^="#"]');
if(!a) return;
var id=a.getAttribute('href').slice(1);
if(!id) return;
var target=document.getElementById(id);
if(!target) return;
e.preventDefault();
var start=window.scrollY;
var end=target.getBoundingClientRect().top + window.scrollY - 80;
var dist=end - start;
var startT=null;
var dur=Math.min(900, Math.max(350, Math.abs(dist) * 0.5));
function easeSpring(t){ return 1 - Math.pow(1 - t, 4); }
function step(ts){
if(!startT) startT=ts;
var t=Math.min(1, (ts - startT) / dur);
window.scrollTo(0, start + dist * easeSpring(t));
if(t < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
}
function initFloatingCTAClick(){
var bar=document.getElementById('mc-float-cta');
if(!bar) return;
on(bar, 'click', function(e){
if(e.target.closest('.mc-float-cta__dismiss')) return;
window.open('https://www.menucini.com/', '_blank', 'noopener');
});
}
function animateROINumber(el, fromVal, toVal, duration){
if(!el) return;
if(el._mcAnim) cancelAnimationFrame(el._mcAnim);
var startT=null;
var isEuro=String(fromVal).indexOf('€') >=0||String(toVal).indexOf('€') >=0;
var from=parseFloat(String(fromVal).replace(/[^\d.-]/g,''))||0;
var to=parseFloat(String(toVal).replace(/[^\d.-]/g,''))||0;
el.classList.add('mc-counting');
function ease(t){ return t < 0.5 ? 2*t*t:1-Math.pow(-2*t+2,2)/2; }
function step(ts){
if(!startT) startT=ts;
var t=Math.min(1, (ts - startT) / duration);
var val=from + (to - from) * ease(t);
if(isEuro){
var prefix=val >=0 ? '+€':'-€';
el.textContent=prefix + Math.round(Math.abs(val)).toLocaleString('it-IT');
}else if(String(toVal).indexOf(':1') >=0){
el.textContent=val.toFixed(1) + ':1';
}else{
el.textContent=String(toVal);
}
if(t < 1) el._mcAnim=requestAnimationFrame(step);
else { el.textContent=String(toVal); el.classList.remove('mc-counting'); el._mcAnim=null; }}
el._mcAnim=requestAnimationFrame(step);
}
function getSweep(){
var el=document.getElementById('mc-sweep');
if(!el){
el=document.createElement('div');
el.id='mc-sweep';
document.body.insertAdjacentElement('afterbegin', el);
}
return el;
}
function runSipario(){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var name='Menucini';
var letters=name.split('').map(function(ch, i){
return '' + ch + '';
}).join('');
var isDark=document.documentElement.classList.contains('dark-mode');
var el=document.createElement('div');
el.id='mc-sipario';
if(!isDark) el.classList.add('mc-sipario-light');
el.innerHTML =
'' +
'
' +
'
' + letters + '
' +
'' +
'
Il Giornale dell’Ospitalità
' +
'
';
document.body.insertAdjacentElement('afterbegin', el);
setTimeout(function(){
el.classList.add('mc-sipario-lifting');
setTimeout(function(){
el.remove();
}, 800);
}, 2000);
}
function runSweepOut(href){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches){
window.location.href=href;
return;
}
var sweep=getSweep();
var content=document.querySelector('#content')||document.querySelector('main')||document.body;
sweep.style.transition='none';
sweep.style.opacity='0';
sweep.style.pointerEvents='all';
sweep.getBoundingClientRect();
sweep.style.transition='opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94)';
sweep.style.opacity='1';
content.classList.add('mc-page-leaving');
content.getBoundingClientRect();
content.classList.add('mc-fade-out');
sessionStorage.setItem('mc_transition', 'velo');
setTimeout(function(){
window.location.href=href;
}, 340);
}
function runSweepIn(){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var sweep=getSweep();
var content=document.querySelector('#content')||document.querySelector('main')||document.body;
content.classList.remove('mc-page-leaving', 'mc-fade-out');
sweep.style.transition='none';
sweep.style.opacity='1';
sweep.style.pointerEvents='all';
content.classList.add('mc-page-entering');
sweep.getBoundingClientRect();
requestAnimationFrame(function(){
requestAnimationFrame(function(){
sweep.style.transition='opacity 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94)';
sweep.style.opacity='0';
content.classList.add('mc-fade-in');
setTimeout(function(){
sweep.remove();
content.classList.remove('mc-page-entering', 'mc-fade-in');
}, 450);
});
});
}
function getLama(){
var el=document.getElementById('mc-lama');
if(!el){
el=document.createElement('div');
el.id='mc-lama';
document.body.insertAdjacentElement('afterbegin', el);
}
return el;
}
function runLaLamaOut(href){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches){
window.location.href=href;
return;
}
var el=getLama();
el.style.transition='none';
el.style.transform='translateX(-115%) skewX(-10deg)';
el.style.transformOrigin='0 50%';
el.getBoundingClientRect();
el.style.transition='transform 180ms cubic-bezier(0.55, 0, 0.45, 1)';
el.style.transform='translateX(0) skewX(-10deg)';
sessionStorage.setItem('mc_transition', 'lama');
setTimeout(function(){ window.location.href=href; }, 200);
}
function runLaLamaIn(){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var el=getLama();
el.style.transition='none';
el.style.transform='translateX(0) skewX(-10deg)';
el.style.transformOrigin='0 50%';
el.getBoundingClientRect();
requestAnimationFrame(function(){
requestAnimationFrame(function(){
el.style.transition='transform 220ms cubic-bezier(0.25, 0.46, 0.45, 0.94)';
el.style.transform='translateX(115%) skewX(-10deg)';
setTimeout(function(){ el.remove(); }, 240);
});
});
}
function initTransitionOut(){
on(document, 'click', function(e){
if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey) return;
var a=e.target.closest('a[href]');
if(!a) return;
if(a.target==='_blank') return;
var href=a.getAttribute('href');
if(!href) return;
if(href.charAt(0)==='#') return;
if(/^(mailto:|tel:|javascript:)/.test(href)) return;
var url;
try { url=new URL(href, window.location.href); } catch(e){ return; }
if(url.hostname!==window.location.hostname) return;
if(url.pathname===window.location.pathname&&url.search===window.location.search) return;
if(/^\/(wp-admin|wp-login|wp-json)/.test(url.pathname)) return;
e.preventDefault();
runSweepOut(href);
});
}
function initPageAnimations(){
var isTransition=sessionStorage.getItem('mc_transition');
var siparioPlayed=sessionStorage.getItem('mc_sipario_played');
if(isTransition==='velo'){
sessionStorage.removeItem('mc_transition');
runSweepIn();
}else if(isTransition==='lama'){
sessionStorage.removeItem('mc_transition');
runLaLamaIn();
}else if(!siparioPlayed){
sessionStorage.setItem('mc_sipario_played', '1');
runSipario();
}
initTransitionOut();
}
function initMicroAnimations(){
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
$$('.single .entry-content img').forEach(function(img){
if(img.closest('.menucini-toc,.menucini-sommelier,.mc-venue-card')) return;
if(img.parentElement.classList.contains('img-cornice')) return;
var wrap=document.createElement('span');
wrap.className='img-cornice mc-shimmer';
img.parentNode.insertBefore(wrap, img);
wrap.appendChild(img);
function onImgLoad(){
img.classList.add('mc-loaded');
wrap.classList.remove('mc-shimmer');
}
if(img.complete&&img.naturalWidth > 0){
onImgLoad();
}else{
img.addEventListener('load', onImgLoad);
img.addEventListener('error', function(){ wrap.classList.remove('mc-shimmer'); });
}});
var numRe=/^[+\-€]?\d[\d.,]*\s*[%€+xX]|^[+\-]\d|^\d{2,}/;
$$('.single .entry-content strong').forEach(function(el){
if(el.closest('.switchboard-reading-time,.menucini-toc')) return;
var txt=el.textContent.trim();
if(numRe.test(txt)&&!/^\d+\.\s*$/.test(txt)){
el.classList.add('stat-number');
}});
var allP=$$('.single .entry-content > p');
for (var i=allP.length - 1; i >=0; i--){
if(allP[i].querySelector('a[href*="menucini.com"]')){
allP[i].classList.add('mc-firma');
break;
}}
var articleIO=new IntersectionObserver(function(entries){
entries.forEach(function(entry){
if(!entry.isIntersecting) return;
var el=entry.target;
if(el.classList.contains('img-cornice')) el.classList.add('in-frame');
if(el.tagName==='HR') el.classList.add('drawn');
if(el.classList.contains('pull-quote')) el.classList.add('is-visible');
if(el.classList.contains('stat-number')) el.classList.add('stat-pop');
if(el.classList.contains('mc-firma')) el.classList.add('is-visible');
articleIO.unobserve(el);
});
}, { threshold: 0.3, rootMargin: '0px 0px -20px 0px' });
$$('.img-cornice').forEach(function(el){ articleIO.observe(el); });
$$('.single .entry-content hr').forEach(function(el){ articleIO.observe(el); });
$$('.pull-quote').forEach(function(el){ articleIO.observe(el); });
$$('.stat-number').forEach(function(el){ articleIO.observe(el); });
$$('.mc-firma').forEach(function(el){ articleIO.observe(el); });
var footer=$('#colophon')||$('.site-footer');
if(footer){
footer.style.position='relative';
footer.classList.add('congedo-ready');
var footerIO=new IntersectionObserver(function(entries){
if(entries[0].isIntersecting){
footer.classList.add('congedo-visible');
footerIO.disconnect();
}}, { threshold: 0.1 });
footerIO.observe(footer);
}
var toc=$('.menucini-toc');
if(toc){
on(toc, 'click', function(e){
var a=e.target.closest('a[href^="#"]');
if(!a) return;
var r=document.createElement('span');
r.className='toc-ripple';
r.style.left=e.offsetX + 'px';
r.style.top=e.offsetY + 'px';
a.style.position='relative';
a.appendChild(r);
setTimeout(function(){ r.remove(); }, 500);
var id=a.getAttribute('href').slice(1);
var target=document.getElementById(id);
if(target){
setTimeout(function(){
target.classList.add('bussola-flash');
setTimeout(function(){ target.classList.remove('bussola-flash'); }, 1000);
}, Math.min(500, Math.abs(target.getBoundingClientRect().top) * 0.4));
}});
}}
function initGlossary(){
var search=$('#mc-glossary-search');
if(!search) return;
var letters=$$('.mc-letter-btn');
var sections=$$('.mc-glossary-section');
var cards=$$('.mc-glossary-card');
var emptyMsg=$('.mc-glossary-empty');
var presentLetters={};
sections.forEach(function(s){
var id=s.id.replace('glossary-', '');
presentLetters[id]=true;
});
letters.forEach(function(btn){
if(!presentLetters[btn.dataset.letter]) btn.classList.add('disabled');
});
letters.forEach(function(btn){
on(btn, 'click', function(){
var letter=btn.dataset.letter;
var target=document.getElementById('glossary-' + letter);
if(!target) return;
search.value='';
cards.forEach(function(c){ c.classList.remove('hidden'); });
sections.forEach(function(s){ s.classList.remove('hidden'); });
letters.forEach(function(b){ b.classList.remove('active'); });
btn.classList.add('active');
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
on(search, 'input', function(){
var q=search.value.trim().toLowerCase();
letters.forEach(function(b){ b.classList.remove('active'); });
var visibleSections={};
var anyVisible=false;
cards.forEach(function(card){
var term=(card.dataset.term||'').toLowerCase();
var text=card.textContent.toLowerCase();
var match = !q||term.indexOf(q)!==-1||text.indexOf(q)!==-1;
card.classList.toggle('hidden', !match);
if(match){
var sec=card.closest('.mc-glossary-section');
if(sec) visibleSections[sec.id]=true;
anyVisible=true;
}});
sections.forEach(function(s){
s.classList.toggle('hidden', !visibleSections[s.id]);
});
if(emptyMsg) emptyMsg.classList.toggle('visible', !anyVisible);
});
}
function initCompare(){
var toggle=$('#mc-diff-toggle');
if(!toggle) return;
var table=$('#mc-compare-table');
if(!table) return;
var rows=$$('tbody tr:not(.mc-compare-category)', table);
var diffMode=false;
on(toggle, 'click', function(){
diffMode = !diffMode;
toggle.classList.toggle('active', diffMode);
toggle.textContent=diffMode ? 'Mostra tutte le funzionalità':'Mostra solo differenze';
rows.forEach(function(row){
if(!diffMode){ row.classList.remove('mc-same'); return; }
var cells=Array.prototype.slice.call(row.querySelectorAll('td'));
cells.shift();
var values=cells.map(function(c){ return c.textContent.trim(); });
var allSame=values.every(function(v){ return v===values[0]; });
row.classList.toggle('mc-same', allSame);
});
});
}
function initQuiz(){
var quiz=$('#mc-quiz');
if(!quiz) return;
var cards=$$('.mc-quiz-card', quiz);
var bar=$('#mc-quiz-bar');
var stepLabel=$('#mc-quiz-step');
var resultDiv=$('#mc-quiz-result');
if(!cards.length||!resultDiv) return;
var answers={};
var total=cards.length;
function showCard(idx){
cards.forEach(function(c, i){
c.style.display=i===idx ? '':'none';
if(i===idx) c.style.animation='none';
if(i===idx){ void c.offsetHeight; c.style.animation=''; }});
var pct=((idx + 1) / total * 100);
if(bar) bar.style.setProperty('--quiz-progress', pct + '%');
if(stepLabel) stepLabel.textContent=(idx + 1) + ' / ' + total;
}
on(quiz, 'click', function(e){
var btn=e.target.closest('.mc-quiz-opt');
if(!btn) return;
var q=parseInt(btn.dataset.q, 10);
var val=btn.dataset.value;
answers[q]=val;
$$('.mc-quiz-opt[data-q="' + q + '"]', quiz).forEach(function(b){
b.classList.toggle('selected', b===btn);
});
setTimeout(function(){
if(q < total){
showCard(q);
}else{
showResult();
}}, 300);
});
function showResult(){
cards.forEach(function(c){ c.style.display='none'; });
var progress=quiz.querySelector('.mc-quiz-progress');
if(progress) progress.style.display='none';
var features=[];
var relatedLinks=[];
var title='Menucini Standard è perfetto per te!';
var desc='';
var cta='Prova Menucini gratis per 14 giorni';
var ctaUrl='https://www.menucini.com/';
var venue=answers[1]||'ristorante';
var venueMap={
ristorante: { label: 'Ristorante', link: '/miglior-menu-digitale-ristorante/', linkText: 'Miglior menu digitale per ristorante' },
pizzeria: { label: 'Pizzeria', link: '/menu-digitale-pizzeria/', linkText: 'Menu digitale per pizzeria' },
bar: { label: 'Bar', link: '/menu-digitale-bar/', linkText: 'Menu digitale per bar' },
hotel: { label: 'Hotel', link: '/menu-digitale-hotel/', linkText: 'Menu digitale per hotel' },
altro: { label: 'Locale', link: '/menu-digitale/', linkText: 'Guida al menu digitale' }};
var venueInfo=venueMap[venue]||venueMap.ristorante;
relatedLinks.push({ href: venueInfo.link, text: venueInfo.linkText });
var budget=answers[2]||'basso';
if(budget==='gratis'){
desc='Vuoi partire senza spendere? Menucini offre 14 giorni di prova gratuita senza carta di credito. A soli \u20ac14.99/mese dopo la prova, hai tutto quello che serve al tuo ' + venueInfo.label.toLowerCase() + '.';
relatedLinks.push({ href: '/menu-digitale-gratis/', text: 'Menu digitale gratis: le opzioni' });
}else if(budget==='basso'){
desc='Con un budget fino a \u20ac15/mese, Menucini Standard (\u20ac14.99/mese, o \u20ac12.99 con piano annuale) \u00e8 la scelta ideale. Include tutte le funzionalit\u00e0 premium senza sorprese.';
relatedLinks.push({ href: '/menu-digitale-prezzi/', text: 'Prezzi menu digitale a confronto' });
}else{
desc='Con il tuo budget hai accesso a tutte le funzionalit\u00e0 Menucini, incluso lo Smart Cube NFC+QR per un\'esperienza premium al tavolo.';
features.push('Smart Cube NFC+QR');
relatedLinks.push({ href: '/porta-menu-qr-code/', text: 'Smart Stand e porta menu QR' });
}
var tech=answers[3]||'medio';
if(tech==='basso'){
features.push('Setup in 5 minuti');
features.push('Interfaccia semplicissima');
title='Menucini: semplice come usare WhatsApp!';
relatedLinks.push({ href: '/come-funziona-menu-digitale-qr-code/', text: 'Come funziona un menu digitale' });
}else if(tech==='alto'){
features.push('Dashboard completa');
features.push('Analytics avanzati');
}
var intl=answers[4]||'no';
if(intl==='molti'){
features.push('50+ lingue automatiche');
features.push('Rilevamento lingua cliente');
title='Menucini multilingue: i turisti ti ringrazieranno!';
relatedLinks.push({ href: '/menu-digitale-multilingue/', text: 'Menu digitale multilingue' });
}else if(intl==='alcuni'){
features.push('Traduzione automatica');
relatedLinks.push({ href: '/menu-digitale-multilingue/', text: 'Menu digitale multilingue' });
}
var order=answers[5]||'no';
if(order==='whatsapp'){
features.push('Ordini via WhatsApp');
relatedLinks.push({ href: '/ordini-whatsapp-ristorante/', text: 'Ordini WhatsApp per ristorante' });
}else if(order==='completo'){
features.push('Ordini via WhatsApp');
features.push('Comanda digitale');
relatedLinks.push({ href: '/whatsapp-business-ristorante/', text: 'WhatsApp Business per ristorante' });
}
if(features.indexOf('QR Code menu')===-1) features.unshift('QR Code menu');
features.push('Gestione allergeni');
features.push('Aggiornamenti in tempo reale');
var titleEl=$('#mc-quiz-result-title');
var descEl=$('#mc-quiz-result-desc');
var featEl=$('#mc-quiz-result-features');
var ctaEl=$('#mc-quiz-result-cta');
var linksEl=$('#mc-quiz-related-links');
if(titleEl) titleEl.textContent=title;
if(descEl) descEl.textContent=desc;
if(featEl) featEl.innerHTML=features.map(function(f){
return '' + f + '';
}).join('');
if(ctaEl) ctaEl.innerHTML='' + cta + ' \u2192';
if(linksEl) linksEl.innerHTML=relatedLinks.map(function(l){
return '' + l.text + ' \u2192';
}).join('');
resultDiv.style.display='';
}
var restartBtn=$('#mc-quiz-restart');
if(restartBtn){
on(restartBtn, 'click', function(){
answers={};
resultDiv.style.display='none';
var progress=quiz.querySelector('.mc-quiz-progress');
if(progress) progress.style.display='';
$$('.mc-quiz-opt', quiz).forEach(function(b){ b.classList.remove('selected'); });
showCard(0);
});
}
showCard(0);
}
function restructureArchive(){
var isIndex=document.body.classList.contains('blog') ||
document.body.classList.contains('home');
if(!isIndex) return;
var cards=$$('.ast-row .ast-article-post');
if(cards.length < 5) return;
var row=$('.ast-row');
if(!row) return;
var prima=document.createElement('div');
prima.className='mc-prima-pagina';
var layout=document.createElement('div');
layout.className='mc-pp-layout';
var featuredCol=document.createElement('div');
featuredCol.className='mc-pp-featured';
featuredCol.appendChild(cards[0]);
var sidebar=document.createElement('div');
sidebar.className='mc-pp-sidebar';
var sideTitle=document.createElement('div');
sideTitle.className='mc-pp-sidebar-title';
sideTitle.textContent='Da leggere anche';
sidebar.appendChild(sideTitle);
for (var i=1; i <=3&&i < cards.length; i++){
var card=cards[i];
var titleEl=card.querySelector('.entry-title a')||card.querySelector('.entry-title');
var title=titleEl ? titleEl.textContent.trim():'';
var href=(card.querySelector('.entry-title a')||card.querySelector('a')).href||'#';
var catMatch=card.className.match(/\bcategory-([\w-]+)\b/);
var catSlug=(catMatch&&catMatch[1]!=='uncategorized') ? catMatch[1]:'';
card.classList.add('mc-pp-consumed');
var brief=document.createElement('div');
brief.className='mc-pp-brief';
if(catSlug) brief.dataset.catSlug=catSlug;
if(catSlug){
var catEl=document.createElement('div');
catEl.className='mc-pp-brief-cat';
catEl.textContent=toDisplayLabel(catSlug);
brief.appendChild(catEl);
}
var bTitle=document.createElement('div');
bTitle.className='mc-pp-brief-title';
bTitle.textContent=title;
brief.appendChild(bTitle);
var bLink=document.createElement('a');
bLink.className='mc-pp-brief-link';
bLink.href=href;
bLink.textContent='\u2192 Leggi';
brief.appendChild(bLink);
sidebar.appendChild(brief);
}
layout.appendChild(featuredCol);
layout.appendChild(sidebar);
prima.appendChild(layout);
row.parentNode.insertBefore(prima, row);
var divider=document.createElement('div');
divider.className='mc-section-divider';
var fleuron=document.createElement('span');
fleuron.className='mc-sd-fleuron';
fleuron.textContent='\u2767';
divider.appendChild(fleuron);
row.parentNode.insertBefore(divider, row);
}
function injectPullQuoteStat(){
var isIndex=document.body.classList.contains('blog') ||
document.body.classList.contains('home');
if(!isIndex||$('.mc-pull-stat')) return;
var stats=[
'In Italia, il 73% dei clienti consulta il menu online prima di scegliere dove mangiare.',
'Un menu digitale riduce i tempi di ordinazione del 35%, secondo le stime di settore.',
'Il 68% dei ristoratori italiani considera la digitalizzazione una priorit\u00e0 per il 2026.',
'I ristoranti con menu multilingue registrano fino al 40% in pi\u00f9 di clienti stranieri.',
'Il food cost ideale per un ristorante italiano si aggira tra il 28% e il 32% del prezzo di vendita.'
];
var stat=stats[Math.floor(Math.random() * stats.length)];
var el=document.createElement('div');
el.className='mc-pull-stat reveal-target';
var p=document.createElement('p');
p.textContent=stat;
el.appendChild(p);
var row=$('.ast-row');
var newsletter=$('.newsletter-section');
if(newsletter){
newsletter.parentNode.insertBefore(el, newsletter);
}else if(row){
row.insertAdjacentElement('afterend', el);
}}
function createCasiStudioFilmstrip(){
var isIndex=document.body.classList.contains('blog') ||
document.body.classList.contains('home');
if(!isIndex||$('.mc-filmstrip')) return;
var casiCards=$$('.ast-row .ast-article-post.category-casi-studio:not(.mc-pp-consumed)');
if(casiCards.length < 2) return;
var section=document.createElement('div');
section.className='mc-filmstrip reveal-target';
var divider=document.createElement('div');
divider.className='mc-section-divider';
var label=document.createElement('span');
label.className='mc-sd-label';
label.textContent='Casi Studio';
divider.appendChild(label);
var track=document.createElement('div');
track.className='mc-filmstrip-track';
casiCards.forEach(function(card){
var img=card.querySelector('img.wp-post-image');
var titleEl=card.querySelector('.entry-title a')||card.querySelector('.entry-title');
var title=titleEl ? titleEl.textContent.trim():'';
var href=(card.querySelector('.entry-title a')||card.querySelector('a'));
var link=href ? href.href:'#';
var fc=document.createElement('div');
fc.className='mc-filmstrip-card';
if(img){
var imgClone=document.createElement('img');
imgClone.src=img.src;
imgClone.alt=img.alt||title;
imgClone.loading='lazy';
fc.appendChild(imgClone);
}
var body=document.createElement('div');
body.className='mc-filmstrip-card-body';
var t=document.createElement('div');
t.className='mc-filmstrip-card-title';
var a=document.createElement('a');
a.href=link;
a.textContent=title;
t.appendChild(a);
body.appendChild(t);
fc.appendChild(body);
track.appendChild(fc);
card.classList.add('mc-filmstrip-consumed');
});
section.appendChild(track);
var newsletter=$('.newsletter-section');
var row=$('.ast-row');
if(newsletter){
newsletter.parentNode.insertBefore(section, newsletter);
newsletter.parentNode.insertBefore(divider, section);
}else if(row){
row.insertAdjacentElement('afterend', divider);
divider.insertAdjacentElement('afterend', section);
}}
function injectEditionRail(){
var isIndex=document.body.classList.contains('blog') ||
document.body.classList.contains('home');
if(!isIndex||$('.mc-edition-rail')) return;
var now=new Date();
var monthNum=now.getMonth() + 1;
var rail=document.createElement('div');
rail.className='mc-edition-rail';
rail.textContent=MESI[now.getMonth()].toUpperCase() + ' ' + now.getFullYear() + ' \u00b7 Edizione N\u00b0 ' + monthNum;
document.body.appendChild(rail);
}
function initCardTilt(){
if(!window.matchMedia('(hover: hover)').matches) return;
var cards=$$('.ast-article-post');
if(!cards.length) return;
cards.forEach(function(card){
var raf=0;
card.addEventListener('mousemove', function(e){
if(raf) return;
raf=requestAnimationFrame(function(){
var rect=card.getBoundingClientRect();
var x=((e.clientX - rect.left) / rect.width * 100);
var y=((e.clientY - rect.top) / rect.height * 100);
card.style.setProperty('--glow-x', x + '%');
card.style.setProperty('--glow-y', y + '%');
raf=0;
});
}, { passive: true });
card.addEventListener('mouseleave', function(){
if(raf){ cancelAnimationFrame(raf); raf=0; }
card.style.setProperty('--glow-x', '50%');
card.style.setProperty('--glow-y', '50%');
});
});
}
function initCardImages(){
var empties=[];
$$('.ast-article-post').forEach(function(card){
var sec=card.querySelector('.ast-blog-featured-section');
if(!sec||sec.querySelector('img')) return;
var link=card.querySelector('.entry-title a[href]');
if(!link) return;
var url=link.getAttribute('href');
var slug=url.replace(/\/$/, '').split('/').pop();
if(!slug) return;
sec.classList.add('mc-shimmer');
empties.push({ sec: sec, slug: slug, title: link.textContent.trim() });
});
if(!empties.length) return;
var slugs=empties.map(function(e){ return e.slug; });
var apiUrl='/wp-json/wp/v2/posts?slug=' + slugs.join(',') + '&_fields=slug,featured_media,_links&_embed=wp:featuredmedia&per_page=' + slugs.length;
fetch(apiUrl).then(function(r){ return r.json(); }).then(function(posts){
var map={};
posts.forEach(function(p){
var embedded=p._embedded&&p._embedded['wp:featuredmedia'];
if(embedded&&embedded[0]&&embedded[0].source_url){
map[p.slug]=embedded[0].source_url;
}});
empties.forEach(function(item, idx){
var imgUrl=map[item.slug];
if(!imgUrl){
item.sec.classList.remove('mc-shimmer');
var ini=document.createElement('div');
ini.className='mc-card-initial';
ini.textContent=item.title.charAt(0).toUpperCase();
item.sec.appendChild(ini);
return;
}
var img=document.createElement('img');
img.className='mc-card-img wp-post-image';
img.src=imgUrl;
img.alt=item.title;
img.loading=idx < 2 ? 'eager':'lazy';
if(idx < 2) img.setAttribute('fetchpriority', 'high');
img.decoding='async';
item.sec.appendChild(img);
function reveal(){
img.classList.add('mc-loaded');
item.sec.classList.remove('mc-shimmer');
}
if(img.complete) reveal();
else img.addEventListener('load', reveal);
img.addEventListener('error', function(){
item.sec.classList.remove('mc-shimmer');
var ini=document.createElement('div');
ini.className='mc-card-initial';
ini.textContent=item.title.charAt(0).toUpperCase();
item.sec.appendChild(ini);
img.remove();
});
});
}).catch(function(){
empties.forEach(function(item){
item.sec.classList.remove('mc-shimmer');
});
});
}
function initShimmer(){
var cards=$$('.ast-article-post');
if(!cards.length) return;
cards.forEach(function(card){
var imgWrap=card.querySelector('.ast-blog-featured-section, .post-thumb');
if(!imgWrap) return;
var img=imgWrap.querySelector('img');
if(!img) return;
if(img.complete&&img.naturalWidth > 0) return;
imgWrap.classList.add('mc-shimmer');
imgWrap.style.aspectRatio=imgWrap.style.aspectRatio||'16/10';
function onLoad(){
imgWrap.classList.add('mc-shimmer-fade');
setTimeout(function(){ imgWrap.classList.remove('mc-shimmer', 'mc-shimmer-fade'); }, 400);
}
img.addEventListener('load', onLoad);
if(img.complete&&img.naturalWidth > 0) onLoad();
});
}
document.addEventListener('DOMContentLoaded', function(){
if(document.documentElement.classList.contains('dark-mode')){ document.documentElement.setAttribute('data-mode','sera'); }
initHeader();
initDarkMode();
initPageAnimations();
initCursor();
initScrollHeader();
initReadingProgress();
fixTables();
initWhatsAppShare();
initTOC();
initRelatedPosts();
injectMarquee();
initMarquee();
injectBlogHero();
restructureArchive();
injectNewsletter();
addReadingTime();
addCardNumbers();
addFeaturedBadge();
initBookmarks();
injectCategoryFilter();
injectPullQuoteStat();
createCasiStudioFilmstrip();
injectFooter();
injectOrgSchema();
(function(){
var metas=document.querySelectorAll('meta[name="google-site-verification"]');
metas.forEach(function(m){
if(m.content&&m.content.indexOf('google-site-verification=')===0){
m.remove();
}});
})();
(function(){
var scripts=document.querySelectorAll('script[type="application/ld+json"]');
scripts.forEach(function(s){
try {
var data=JSON.parse(s.textContent);
var graph=data['@graph']||[data];
var changed=false;
graph.forEach(function(item){
if(item['@type']==='BlogPosting'&&item.headline){
item.headline=item.headline.replace(/\s*-\s*Menucini Blog$/i, '');
changed=true;
}});
if(changed){
if(data['@graph']) data['@graph']=graph;
s.textContent=JSON.stringify(data);
}} catch(e){}});
})();
(function(){
var firstCardImg=document.querySelector('.ast-row article:first-child img.wp-post-image, .mc-pp-featured img.wp-post-image');
if(firstCardImg){
firstCardImg.setAttribute('fetchpriority', 'high');
firstCardImg.setAttribute('loading', 'eager');
var origSrc=firstCardImg.getAttribute('data-speedycache-original-src')||firstCardImg.getAttribute('data-src');
if(origSrc&&firstCardImg.src!==origSrc){
firstCardImg.src=origSrc;
}}
var ppImg=document.querySelector('.mc-pp-card-img, .mc-card-img');
if(ppImg&&ppImg!==firstCardImg){
ppImg.setAttribute('fetchpriority', 'high');
ppImg.setAttribute('loading', 'eager');
var origSrc2=ppImg.getAttribute('data-speedycache-original-src')||ppImg.getAttribute('data-src');
if(origSrc2&&ppImg.src!==origSrc2){
ppImg.src=origSrc2;
}}
})();
(function(){
var cardImgs=document.querySelectorAll('.mc-card-img, .ast-blog-featured-section img');
cardImgs.forEach(function(img){
if(!img.getAttribute('sizes')){
img.setAttribute('sizes', '(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw');
}
if(!img.getAttribute('width')){
img.setAttribute('width', '580');
img.setAttribute('height', '317');
}});
})();
(function(){
var jq=document.querySelector('script[src*="jquery.min.js"]');
if(jq&&!jq.async&&!jq.defer){
var link=document.createElement('link');
link.rel='preload';
link.as='script';
link.href=jq.src;
document.head.appendChild(link);
}})();
injectSectionLabel();
injectEditionRail();
initROICalc();
initFoodCostCalc();
initFloatingCTA();
initFloatingCTAClick();
initWordReveal();
initMicroAnimations();
initTOCIndicator();
initSmoothAnchors();
initSeasonalBanner();
initGlossary();
initCompare();
initQuiz();
initAboutTools();
initCardTilt();
initCardImages();
initShimmer();
requestAnimationFrame(function(){ requestAnimationFrame(initReveal); });
});
function initAboutTools(){
var grid=document.getElementById('mc-about-tools-grid');
if(!grid) return;
var tools=[
['Calcolatore ROI', '/calcolatore-roi-menu-digitale/', 'Scopri quanto puoi risparmiare passando al menu digitale.'],
['Calcolatore Food Cost', '/calcolatore-food-cost/', 'Calcola il food cost dei tuoi piatti in pochi secondi.'],
['Quiz', '/quiz-menu-digitale/', 'Quale menu digitale fa per te? Rispondi e scoprilo.'],
['Glossario', '/glossario/', 'Tutti i termini della ristorazione digitale spiegati.'],
['Confronto Piattaforme', '/confronto-menu-digitale/', 'Confronta le principali soluzioni di menu digitale.']
];
tools.forEach(function(t){
var a=document.createElement('a');
a.className='mc-about-tool';
a.href=t[1];
a.innerHTML='' + t[0] + '' + t[2] + '';
grid.appendChild(a);
});
var cta=document.createElement('p');
cta.style.cssText='text-align:center;margin-top:var(--sp-md)';
cta.innerHTML='Prova Menucini gratis per 14 giorni \u2192';
grid.parentNode.insertBefore(cta, grid.nextSibling);
}
function initFoodCostCalc(){
var ph=document.getElementById('mc-foodcost-placeholder');
if(!ph) return;
var INGREDIENTS=[
{id:'mozzarella_fior_di_latte',name:'Mozzarella fior di latte',price:9,unit:'kg',cat:'Proteine'},
{id:'mozzarella_bufala',name:'Mozzarella di bufala DOP',price:16,unit:'kg',cat:'Proteine'},
{id:'prosciutto_crudo',name:'Prosciutto crudo',price:25,unit:'kg',cat:'Proteine'},
{id:'prosciutto_cotto',name:'Prosciutto cotto',price:14,unit:'kg',cat:'Proteine'},
{id:'petto_pollo',name:'Petto di pollo',price:9,unit:'kg',cat:'Proteine'},
{id:'macinato_manzo',name:'Macinato di manzo',price:12,unit:'kg',cat:'Proteine'},
{id:'filetto_manzo',name:'Filetto di manzo',price:40,unit:'kg',cat:'Proteine'},
{id:'salmone',name:'Salmone',price:22,unit:'kg',cat:'Proteine'},
{id:'gamberi',name:'Gamberi',price:18,unit:'kg',cat:'Proteine'},
{id:'uova',name:'Uova',price:3.5,unit:'kg',cat:'Proteine'},
{id:'parmigiano',name:'Parmigiano Reggiano',price:20,unit:'kg',cat:'Latticini'},
{id:'pecorino',name:'Pecorino Romano',price:16,unit:'kg',cat:'Latticini'},
{id:'ricotta',name:'Ricotta',price:5,unit:'kg',cat:'Latticini'},
{id:'burro',name:'Burro',price:10,unit:'kg',cat:'Latticini'},
{id:'panna',name:'Panna fresca',price:5,unit:'L',cat:'Latticini'},
{id:'pelati',name:'Pomodori pelati',price:2.5,unit:'kg',cat:'Verdure'},
{id:'pomodori_freschi',name:'Pomodori freschi',price:3,unit:'kg',cat:'Verdure'},
{id:'insalata',name:'Insalata mista',price:4,unit:'kg',cat:'Verdure'},
{id:'patate',name:'Patate',price:1.2,unit:'kg',cat:'Verdure'},
{id:'zucchine',name:'Zucchine',price:2.5,unit:'kg',cat:'Verdure'},
{id:'melanzane',name:'Melanzane',price:2.5,unit:'kg',cat:'Verdure'},
{id:'funghi',name:'Funghi champignon',price:5,unit:'kg',cat:'Verdure'},
{id:'cipolla',name:'Cipolla',price:1.5,unit:'kg',cat:'Verdure'},
{id:'farina_00',name:'Farina 00',price:1.2,unit:'kg',cat:'Dispensa'},
{id:'pasta_secca',name:'Pasta secca',price:2,unit:'kg',cat:'Dispensa'},
{id:'riso_carnaroli',name:'Riso Carnaroli',price:4,unit:'kg',cat:'Dispensa'},
{id:'olio_evo',name:'Olio EVO',price:10,unit:'L',cat:'Dispensa'},
{id:'pane',name:'Pane',price:4,unit:'kg',cat:'Dispensa'},
{id:'sale',name:'Sale fino',price:0.5,unit:'kg',cat:'Dispensa'},
{id:'lievito',name:'Lievito fresco',price:4,unit:'kg',cat:'Dispensa'}
];
var BENCHMARKS={
ristorante: [28, 35],
pizzeria: [22, 30],
bar: [20, 28],
hotel: [30, 38],
trattoria: [30, 36]
};
var recipes=[];
var editingIdx=-1;
function load(){
try { recipes=JSON.parse(localStorage.getItem('mc_foodcost_recipes'))||[]; } catch(e){ recipes=[]; }}
function save(){
localStorage.setItem('mc_foodcost_recipes', JSON.stringify(recipes));
}
function getVenue(){
return localStorage.getItem('mc_foodcost_venue')||'ristorante';
}
function setVenue(v){
localStorage.setItem('mc_foodcost_venue', v);
}
function findIngredient(id){
for (var i=0; i < INGREDIENTS.length; i++){
if(INGREDIENTS[i].id===id) return INGREDIENTS[i];
}
return null;
}
function toBase(qty, inputUnit){
if(inputUnit==='g') return qty / 1000;
if(inputUnit==='mL') return qty / 1000;
return qty;
}
function calcIngCost(ing){
if(ing.preset){
var db=findIngredient(ing.preset);
if(!db) return 0;
if(ing.inputUnit==='pz') return ing.qty * db.price;
return toBase(ing.qty, ing.inputUnit) * db.price;
}
if(ing.customPrice!=null){
if(ing.inputUnit==='pz') return ing.qty * ing.customPrice;
return toBase(ing.qty, ing.inputUnit) * ing.customPrice;
}
return 0;
}
function fmt(n){ return n.toFixed(2).replace('.', ','); }
function fmtPct(n){ return n.toFixed(1).replace('.', ',') + '%'; }
function verdictClass(pct){
if(pct < 25) return 'ottimo';
if(pct < 35) return 'media';
if(pct < 40) return 'attenzione';
return 'critico';
}
function verdictLabel(pct){
if(pct < 25) return 'Ottimo';
if(pct < 35) return 'Nella media';
if(pct < 40) return 'Attenzione';
return 'Critico';
}
ph.innerHTML='';
ph.className='mc-fc';
var editorPanel=document.createElement('div');
editorPanel.className='mc-fc-panel';
editorPanel.id='mc-fc-editor';
var dashPanel=document.createElement('div');
dashPanel.className='mc-fc-panel';
dashPanel.id='mc-fc-dashboard';
var benchPanel=document.createElement('div');
benchPanel.className='mc-fc-panel';
benchPanel.id='mc-fc-benchmark';
ph.appendChild(editorPanel);
ph.appendChild(dashPanel);
ph.appendChild(benchPanel);
function renderEditor(recipe){
var r=recipe||{ id: '', name: '', portions: 1, ingredients: [], sellingPrice: 0 };
var html='
' + (r.id ? 'Modifica piatto':'Nuovo piatto') + '
' +
'
' + '' + '' + '
' +
'
' + '
Ingrediente
' + '
Qt\u00e0
' + '
Unit\u00e0
' + '
\u20ac/unit\u00e0
' + '
Subtotale
' + '
' + '
' +
'' +
'' +
'
' + '' + '' + (r.id ? '':'') + '
';
editorPanel.innerHTML=html;
var tbody=document.getElementById('fc-rows');
function buildOptions(selectedId){
var opts='';
var lastCat='';
for (var i=0; i < INGREDIENTS.length; i++){
var ing=INGREDIENTS[i];
if(ing.cat!==lastCat){
if(lastCat) opts +='';
opts +='';
opts +='';
return opts;
}
function addRow(ing){
var tr=document.createElement('tr');
var isCustom=ing&&!ing.preset;
var presetId=(ing&&ing.preset)||'';
var customName=(ing&&ing.customName)||'';
var customPrice=(ing&&ing.customPrice!=null) ? ing.customPrice:'';
var customUnit=(ing&&ing.customUnit)||'kg';
var qty=(ing&&ing.qty)||'';
var inputUnit=(ing&&ing.inputUnit)||'g';
if(isCustom&&customName){
tr.innerHTML =
'
';
}
var MESI=['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'];
var now=new Date();
var issueText='N\u00b0 '+(now.getMonth()+1)+' \u00b7 '+MESI[now.getMonth()]+' '+now.getFullYear();
var hero=document.createElement('section');
hero.className='mc-hero-v2';
hero.innerHTML=''
+'
'
+''
+'4'
+'\u2190'
+'qui!'
+'
'+issueText+'
'
+'
Gestire un ristorante \u00e8 complicato. Qui lo rendiamo pi\u00f9 semplice.
'
+'
Normativa, costi, strumenti digitali e strategie operative. Scritto per chi ha un locale, non per chi ne parla.
';
fold.parentNode.insertBefore(bridge, fold.nextSibling);
}
/* ── Build Carta del Giorno ── */
function buildCartaDelGiorno(){
var grid=document.querySelector('.ast-row');
if(!grid) return;
// Pick a post based on day of month
var cards=Array.from(document.querySelectorAll('.ast-row .ast-article-post:not(.mc-pp-consumed)'));
if(cards.length<1) return;
var pick=cards[new Date().getDate()%cards.length];
var titleEl=pick.querySelector('.entry-title a')||pick.querySelector('.entry-title');
var link=pick.querySelector('.entry-title a');
if(!titleEl) return;
var MESI=['gennaio','febbraio','marzo','aprile','maggio','giugno','luglio','agosto','settembre','ottobre','novembre','dicembre'];
var now=new Date();
var dateStr=now.getDate()+' '+MESI[now.getMonth()]+' '+now.getFullYear();
var carta=document.createElement('div');
carta.className='mc-carta-del-giorno';
carta.innerHTML=''
+'
'
+''
+'Leggi \u2192';
// Insert before the grid section label
var sectionLabel=document.querySelector('.section-label');
var target=sectionLabel||grid;
target.parentNode.insertBefore(carta, target);
}
/* ── Build Coffee Cup ── */
function buildCoffeeCup(){
var cup=document.createElement('div');
cup.className='mc-coffee-progress';
cup.setAttribute('aria-hidden','true');
cup.innerHTML=''
+'
il tuo caff\u00e8
';
document.body.appendChild(cup);
}
/* ── Build Floating Ingredients ── */
function buildIngredients(){
if(isMobile) return;
var wrap=document.createElement('div');
wrap.className='mc-ingredients';
wrap.setAttribute('aria-hidden','true');
wrap.innerHTML=
''
+''
+''
+'';
document.body.appendChild(wrap);
}
/* ── GSAP Animations ── */
function initAnimations(){
if(typeof gsap==='undefined') return;
// Hero entrance
var h1=document.querySelector('.mc-hero-editorial .hero-tagline');
if(h1&&!h1.querySelector('.mc-hero-char')){
var text=h1.textContent;
h1.innerHTML=text.split('').map(function(ch){
if(ch===' ') return ' ';
return ''+ch+'';
}).join('')+'';
}
if(noMotion){
document.querySelectorAll('.mc-hero-char').forEach(function(c){ c.style.opacity=1; c.style.transform='none'; });
var ul=document.querySelector('.mc-hero-underline'); if(ul) ul.style.transform='scaleX(1)';
return;
}
var chars=document.querySelectorAll('.mc-hero-char');
var underline=document.querySelector('.mc-hero-underline');
var tl=gsap.timeline();
tl.from('.mc-hero-editorial .hero-issue',{opacity:0,y:20,duration:0.5,ease:'power2.out'},0)
.to(chars,{opacity:1,y:0,duration:0.45,stagger:0.018,ease:'power2.out'},0.1);
if(underline) tl.to(underline,{scaleX:1,duration:0.8,ease:'power2.inOut'},0.5);
tl.from('.mc-hero-editorial .hero-sub',{opacity:0,y:20,duration:0.6,ease:'power2.out'},0.6)
.from('.mc-hero-search',{opacity:0,y:15,scale:0.95,duration:0.7,ease:'power2.out'},0.75)
.from('.mc-hero-quicklinks a',{opacity:0,y:15,duration:0.5,stagger:0.08,ease:'power2.out'},0.9)
.from('.mc-hero-spotlight .spotlight-card',{opacity:0,x:70,rotationY:-8,duration:1.1,ease:'power2.out'},0.3);
// Annotations
gsap.from('.mc-annotation',{opacity:0,duration:0.5,stagger:0.2,delay:1.5,ease:'power2.out'});
gsap.from('.mc-margin-line',{scaleY:0,transformOrigin:'top',duration:0.8,delay:1.2,ease:'power2.out'});
// Hero interactions (desktop only)
if(canHover){
var hero=document.querySelector('.mc-hero-v2');
var glow=document.querySelector('.mc-hero-glow');
var card=document.querySelector('.mc-hero-spotlight .spotlight-card');
var shine=document.querySelector('.spotlight-shine');
var pills=document.querySelectorAll('.mc-hero-quicklinks a');
if(hero&&glow){
var glowX=gsap.quickTo(glow,'x',{duration:0.6,ease:'power2.out'});
var glowY=gsap.quickTo(glow,'y',{duration:0.6,ease:'power2.out'});
hero.addEventListener('mousemove',function(e){
var r=hero.getBoundingClientRect();
glowX(e.clientX-r.left);glowY(e.clientY-r.top);
},{passive:true});
}
if(card){
var tiltX=gsap.quickTo(card,'rotationX',{duration:0.4,ease:'power2.out'});
var tiltY=gsap.quickTo(card,'rotationY',{duration:0.4,ease:'power2.out'});
card.addEventListener('mousemove',function(e){
var r=card.getBoundingClientRect();
var x=(e.clientX-r.left)/r.width, y=(e.clientY-r.top)/r.height;
tiltX((y-0.5)*-8); tiltY((x-0.5)*8);
if(shine){ shine.style.setProperty('--shine-x',(x*100)+'%'); shine.style.setProperty('--shine-y',(y*100)+'%'); }
},{passive:true});
card.addEventListener('mouseleave',function(){ tiltX(0); tiltY(0); });
}
pills.forEach(function(p){
p.addEventListener('mousemove',function(e){
var r=p.getBoundingClientRect();
gsap.to(p,{x:(e.clientX-r.left-r.width/2)*0.3,y:(e.clientY-r.top-r.height/2)*0.3,duration:0.3,ease:'power2.out'});
},{passive:true});
p.addEventListener('mouseleave',function(){ gsap.to(p,{x:0,y:0,duration:0.5,ease:'elastic.out(1,0.4)'}); });
});
}
// Scroll animations
function reveal(t,tr,v,e){ gsap.from(t,Object.assign({scrollTrigger:{trigger:tr||t,start:'top 88%',toggleActions:'play none none none'},ease:'power2.out'},v,e||{})); }
reveal('.mc-newspaper-fold','.mc-newspaper-fold',{opacity:0,scaleX:0.3,duration:0.6});
reveal('.mc-explore-header','.mc-explore',{y:35,opacity:0,duration:0.7});
reveal('.mc-explore-card','.mc-explore-grid',{y:50,opacity:0,duration:0.8,stagger:0.12});
reveal('.mc-carta-del-giorno','.mc-carta-del-giorno',{opacity:0,y:30,rotation:-6,scale:0.9,duration:0.9});
// Grid cards — batch trigger (1 instance instead of ~12)
ScrollTrigger.batch('.ast-row .ast-article-post:not(.mc-pp-consumed)',{
start:'top 90%',
onEnter:function(batch){
gsap.from(batch,{y:50,opacity:0,duration:0.7,stagger:0.15,ease:'power2.out'});
batch.forEach(function(c){c.classList.add('mc-revealed');});
}
});
// Newsletter
gsap.from('.newsletter-section',{
scrollTrigger:{trigger:'.newsletter-section',start:'top 88%',toggleActions:'play none none none'},
scale:0.92,opacity:0,duration:1,ease:'power2.out',
onComplete:function(){
var el=document.querySelector('.newsletter-proof');
if(!el) return;
var m=el.textContent.match(/(\d+)/);
if(!m) return;
var target=parseInt(m[1],10);
var span=document.createElement('span');
span.className='counter-num';
el.innerHTML=el.innerHTML.replace(m[1],'0');
var numEl=el.querySelector('.counter-num');
gsap.to({v:0},{v:target,duration:1.8,ease:'power1.out',snap:{v:1},onUpdate:function(){ numEl.textContent=Math.round(this.targets()[0].v); }});
}
});
// Coffee cup scroll progress
var cup=document.querySelector('.mc-coffee-progress');
var liquid=document.querySelector('.mc-coffee-liquid');
var steam=document.querySelector('.mc-coffee-steam');
if(cup&&liquid){
ScrollTrigger.create({trigger:document.body,start:'top -10%',
onEnter:function(){cup.classList.add('is-visible');},
onLeaveBack:function(){cup.classList.remove('is-visible');}
});
gsap.to(liquid,{scrollTrigger:{trigger:document.body,start:'top top',end:'bottom bottom',scrub:0.3},attr:{y:12,height:28},ease:'none'});
if(steam) gsap.to(steam,{scrollTrigger:{trigger:document.body,start:'80% bottom',end:'bottom bottom',scrub:0.3},opacity:0.5,ease:'none'});
}
// Floating ingredients parallax
if(!isMobile){
var speeds=[0.15,-0.1,0.12,-0.08];
document.querySelectorAll('.mc-ingredient').forEach(function(el,i){
gsap.to(el,{scrollTrigger:{trigger:document.body,start:'top top',end:'bottom bottom',scrub:1},
y:speeds[i]*window.innerHeight,ease:'none'});
});
}
}
/* ── Init sequence ── */
function initV2(){
buildHeroV2();
buildBridge();
buildCartaDelGiorno();
buildCoffeeCup();
buildIngredients();
loadGSAP(initAnimations);
}
// Run after existing DOMContentLoaded handlers complete
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded',function(){ setTimeout(initV2,50); });
}else{
setTimeout(initV2,50);
}
// CSS overrides for visual polish
(function(){
var s=document.createElement('style');
s.textContent='.mc-ingredient{opacity:0.15 !important;}'
+'@media(max-width:1024px){.mc-margin-line,.mc-annotation{display:block !important;}}'
+'.mc-annotation--qui{left:-60px !important;}'
+'.mc-annotation--circle{left:-48px !important;}'
+'.mc-annotation--arrow{left:-40px !important;}'
+'[data-mode="sera"]{--ast-global-color-0:#C4622D;--ast-global-color-1:#A04E22;--ast-global-color-2:#F0E6D3;--ast-global-color-3:#C8B99A;--ast-global-color-4:#1A1510;--ast-global-color-5:#221E18;--ast-global-color-6:#2C271F;--ast-global-color-7:#221E18;--ast-global-color-8:#8C7B6B;}'
+'[data-mode="sera"] body{background:var(--c-ivory) !important;color:var(--c-ink) !important;}'
+'[data-mode="sera"] #masthead,[data-mode="sera"] .site-header{background:var(--c-ivory) !important;border-bottom-color:var(--c-linen-d) !important;}'
+'[data-mode="sera"] .scrolled #masthead,[data-mode="sera"] .scrolled .site-header{background:rgba(26,21,16,0.92) !important;}'
+'.mc-hero-search input[type="search"]{padding:11px 16px 11px 48px !important;background:var(--c-linen) !important;border-radius:var(--r-pill) !important;border-color:var(--c-linen-d) !important;}'
+'.mc-hero-search input[type="search"]:focus{border-color:var(--c-terracotta) !important;background:var(--c-white) !important;}';
document.head.appendChild(s);
})();
})();