/* OK ITHAKI V249526R10F6 — CONTENT TRANSLATION / THEME COLORS / WORKING REACTIONS */
(function(){
'use strict';
if(window.__ITHAKI_V249526R10F6_TRANSLATION_THEME_REACTIONS__)return;
window.__ITHAKI_V249526R10F6_TRANSLATION_THEME_REACTIONS__={
  version:'V249526R10F6',
  sameTranslationBridgeAsMessages:true,
  wallBottleLighthouseTargetLanguage:true,
  themeColorsAligned:true,
  supportedWallReactions:true,
  singleReactionOwner:true,
  at:Date.now()
};
window.CONTENT_TRANSLATION_WALL_BOTTLE_LIGHTHOUSE_R10F6=true;
window.THEME_COLORS_WALL_BOTTLE_LIGHTHOUSE_R10F6=true;
window.WALL_REACTIONS_WORKING_R10F6=true;
window.SINGLE_WALL_REACTION_OWNER_R10F6=true;

const $=id=>document.getElementById(id);
const I=()=>window.ITH=window.ITH||{};
const S=()=>window.state||I().state||{};
const esc=s=>String(s==null?'':s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const TARGET_KEY='ith_content_translate_target_r10f6';
const CACHE=new Map();
let reactionSocket=null,reactionReconnect=null,hydrateTimer=null,scanTimer=null;

const LANGS=[
  ['auto','Αυτόματο · Auto'],['el','Ελληνικά'],['en','English']
];
const UI={
 el:{translate:'Μετάφραση',translateView:'Μετάφραση οθόνης',original:'Πρωτότυπο',translating:'Μετάφραση…',unavailable:'Η μετάφραση δεν είναι διαθέσιμη για αυτή τη γλώσσα.',target:'Γλώσσα μετάφρασης',felt:'Το νιώθω',understand:'Σε καταλαβαίνω',strength:'Δύναμη',withYou:'Μαζί σου',hope:'Ελπίδα'},
 en:{translate:'Translate',translateView:'Translate view',original:'Original',translating:'Translating…',unavailable:'Translation is unavailable for this language.',target:'Translation language',felt:'I feel it',understand:'I understand',strength:'Strength',withYou:'With you',hope:'Hope'}
};
const REACTIONS=[['❤️','felt'],['🤝','understand'],['🌟','strength'],['🫶','withYou'],['🙏','hope']];

function uiLang(){
  try{
    const q=new URLSearchParams(location.search).get('lang');
    const x=String(localStorage.getItem('ith_ui_lang_v249141')||localStorage.getItem('ith_ui_lang')||q||document.documentElement.lang||'el').toLowerCase();
    return x.startsWith('en')?'en':'el';
  }catch(_e){return'el'}
}
function tr(k){return (UI[uiLang()]||UI.el)[k]||UI.el[k]||k}
function target(){try{return localStorage.getItem(TARGET_KEY)||'auto'}catch(_e){return'auto'}}
function setTarget(v){
  const next=LANGS.some(x=>x[0]===v)?v:'auto';
  try{localStorage.setItem(TARGET_KEY,next)}catch(_e){}
  document.querySelectorAll('[data-r10f6-language]').forEach(s=>{if(s.value!==next)s.value=next});
  document.dispatchEvent(new CustomEvent('ithaki:r10f6-translation-target',{detail:{target:next}}));
}
function api(path){
  let base=String(S().api||'').replace(/\/+$/,'');
  if(!base||/appassets\.androidplatform\.net/i.test(base))base='https://ok-ithaki.gr';
  return /^https?:/i.test(path)?path:base+path;
}
function room(){return String(S().room||localStorage.getItem('ith_room')||'ithaki-phone-test')}
function device(){return String(S().device||localStorage.getItem('ith_device')||'')}
function toast(message,ms=4300){
  try{if(typeof I().toast==='function')return I().toast(String(message),ms)}catch(_e){}
  const x=$('toast');if(!x)return;x.textContent=String(message);x.classList.add('show');clearTimeout(toast._t);toast._t=setTimeout(()=>x.classList.remove('show'),ms);
}
async function requestTranslate(text,dst){
  const clean=String(text||'').trim();if(!clean)return'';
  const key=(dst||'auto')+'\u0000'+clean;if(CACHE.has(key))return CACHE.get(key);
  let translated='';
  if((dst||'auto')==='auto'&&typeof I().translateText==='function'){
    translated=await I().translateText(clean);
  }else{
    const offline=dst==='el'||dst==='en';
    const r=await fetch(api('/api/bridge/translate'),{
      method:'POST',headers:{'Content-Type':'application/json'},credentials:'include',
      body:JSON.stringify({text:clean,source_lang:'auto',target_lang:dst,allow_external:!offline,translation_mode:offline?'offline':'hybrid',mode:offline?'offline':'hybrid',external_provider:'auto'})
    });
    if(!r.ok)throw new Error('HTTP '+r.status);
    const d=await r.json();translated=String(d.translated||d.translation||d.text||'').trim();
  }
  if(!translated)throw new Error('empty_translation');
  CACHE.set(key,translated);return translated;
}
function languageSelect(cls=''){
  return '<label class="ith536Lang '+cls+'"><span>🌐</span><select data-r10f6-language aria-label="'+esc(tr('target'))+'">'+LANGS.map(x=>'<option value="'+x[0]+'"'+(target()===x[0]?' selected':'')+'>'+esc(x[1])+'</option>').join('')+'</select></label>';
}
function translationControls(kind,id){
  return '<div class="ith536TranslateControls"><button type="button" data-r10f6-translate="'+esc(kind)+'" data-r10f6-id="'+esc(id||'')+'">🌐 <span>'+esc(tr('translate'))+'</span></button><button type="button" data-r10f6-original hidden>↩ '+esc(tr('original'))+'</button></div><div class="ith536Translated" hidden></div>';
}
async function translateElement(button,source){
  if(!source)return;
  const host=button.closest('.ith536TranslateHost')||button.parentElement;
  const out=host&&host.querySelector(':scope > .ith536Translated');
  const originalBtn=host&&host.querySelector('[data-r10f6-original]');
  if(!out)return;
  button.disabled=true;button.classList.add('busy');button.querySelector('span')&&(button.querySelector('span').textContent=tr('translating'));
  try{
    const translated=await requestTranslate(source.textContent,target());
    if(!translated||translated.trim()===source.textContent.trim()){
      out.textContent=tr('unavailable');out.classList.add('unavailable');
    }else{
      out.textContent=translated;out.classList.remove('unavailable');
    }
    out.hidden=false;if(originalBtn)originalBtn.hidden=false;
  }catch(e){out.textContent=tr('unavailable');out.classList.add('unavailable');out.hidden=false;toast(tr('unavailable'))}
  finally{button.disabled=false;button.classList.remove('busy');button.querySelector('span')&&(button.querySelector('span').textContent=tr('translate'))}
}
function makeTranslateHost(source,kind,id){
  if(!source||source.closest('.ith536TranslateHost'))return;
  const wrap=document.createElement('div');wrap.className='ith536TranslateHost';
  source.parentNode.insertBefore(wrap,source);wrap.appendChild(source);wrap.insertAdjacentHTML('beforeend',translationControls(kind,id));
}
function reactionFooterHtml(postId){
  return REACTIONS.map(([emoji,key])=>'<button type="button" data-r10f6-react="'+emoji+'" data-r10f6-post="'+esc(postId)+'" title="'+esc(tr(key))+'" aria-label="'+esc(tr(key))+'"><span>'+emoji+'</span><i>0</i></button>').join('');
}
function enhanceWall(){
  const root=$('ith526AnonymousWall');if(!root)return;
  const globalLanguage=!!window.__ITHAKI_R10F7_GLOBAL_LANGUAGE_OWNER__;
  const head=root.querySelector('.ith534Head');
  if(!globalLanguage&&head&&!head.querySelector('[data-r10f6-wall-tools]')){
    const tools=document.createElement('div');tools.className='ith536WallTools';tools.dataset.r10f6WallTools='1';tools.innerHTML=languageSelect('wall');
    head.insertBefore(tools,head.lastElementChild);
  }
  root.querySelectorAll('.ith534WallCard[data-wall]').forEach(card=>{
    const id=card.getAttribute('data-wall')||'';
    const footer=card.querySelector('.ith534Reactions');
    if(footer&&footer.dataset.r10f6Owner!=='1'){
      footer.dataset.r10f6Owner='1';footer.innerHTML=reactionFooterHtml(id);
    }
    const p=card.querySelector(':scope > .ith534PostText');
    if(!globalLanguage&&p&&!p.closest('.ith536TranslateHost'))makeTranslateHost(p,'wall-post',id);
    card.querySelectorAll('.ith534Reply[data-reply-id]').forEach(reply=>{
      const rp=reply.querySelector(':scope > p');
      if(!globalLanguage&&rp&&!rp.closest('.ith536TranslateHost'))makeTranslateHost(rp,'wall-reply',reply.dataset.replyId||'');
    });
  });
  scheduleHydrate();connectReactionSocket();
}
function enhanceBottle(){
  const overlay=$('bottleSeaOverlayV249274');if(!overlay)return;
  if(window.__ITHAKI_R10F7_GLOBAL_LANGUAGE_OWNER__)return;
  const top=overlay.querySelector('.bottleSeaTopV249274');
  if(top&&!top.querySelector('[data-r10f6-bottle-tools]')){
    const tools=document.createElement('div');tools.className='ith536OverlayTools';tools.dataset.r10f6BottleTools='1';tools.innerHTML=languageSelect('bottle')+'<button type="button" data-r10f6-translate-view="bottle">🌐 '+esc(tr('translateView'))+'</button>';
    top.insertBefore(tools,top.querySelector('.spacer')||top.lastElementChild);
  }
  overlay.querySelectorAll('.bottleItemV249274 p,.bottleItemV249274 .reply p,.bottleReplyBoxV249274 p').forEach((p,i)=>{
    if(!p.closest('.ith536TranslateHost'))makeTranslateHost(p,'bottle-text',String(i));
  });
}
function lighthouseStaticText(langCode){
  const x={
    el:{title:'Ο Φάρος',subtitle:'Χωρίς λέξεις. Μόνο φως.',hint:'Άγγιξε ένα ξένο φως. Δεν στέλνεις μήνυμα — μόνο έναν σιωπηλό παλμό.',light:'Άναψε ένα φως',home:'Αρχική',calendar:'Ημερολόγιο',support:'Υποστήριξη',more:'Περισσότερα'},
    en:{title:'The Lighthouse',subtitle:'No words. Only light.',hint:'Touch another light. You send no message — only a silent pulse.',light:'Light a candle',home:'Home',calendar:'Calendar',support:'Support',more:'More'},
    es:{title:'El Faro',subtitle:'Sin palabras. Solo luz.',hint:'Toca una luz ajena. No envías un mensaje, solo un pulso silencioso.',light:'Enciende una luz',home:'Inicio',calendar:'Calendario',support:'Apoyo',more:'Más'},
    fr:{title:'Le Phare',subtitle:'Sans mots. Seulement la lumière.',hint:'Touchez une autre lumière. Aucun message, seulement une impulsion silencieuse.',light:'Allumer une lumière',home:'Accueil',calendar:'Calendrier',support:'Soutien',more:'Plus'},
    de:{title:'Der Leuchtturm',subtitle:'Keine Worte. Nur Licht.',hint:'Berühre ein fremdes Licht. Keine Nachricht, nur ein stiller Impuls.',light:'Ein Licht anzünden',home:'Start',calendar:'Kalender',support:'Unterstützung',more:'Mehr'},
    it:{title:'Il Faro',subtitle:'Niente parole. Solo luce.',hint:'Tocca una luce altrui. Nessun messaggio, solo un impulso silenzioso.',light:'Accendi una luce',home:'Home',calendar:'Calendario',support:'Supporto',more:'Altro'}
  };return x[langCode]||x[uiLang()]||x.el;
}
function localizeLighthouse(){
  const overlay=$('lighthouseOverlayV249278');if(!overlay)return;
  const code=target()==='auto'?uiLang():target();const d=lighthouseStaticText(code);
  const title=overlay.querySelector('.lighthouseTitleWrapV249278 h1');if(title)title.textContent=d.title;
  const sub=overlay.querySelector('.lighthouseTitleWrapV249278 p');if(sub)sub.textContent=d.subtitle;
  const hint=overlay.querySelector('.lighthouseHintV249278');if(hint)hint.textContent=d.hint;
  const btn=$('lighthouseButtonLabelV249278');if(btn&&!/λάμπει|already|brilla|allumé|leuchtet|brilla/i.test(btn.textContent))btn.textContent=d.light;
  const labels=overlay.querySelectorAll('.lighthouseFooterTabsV249278 .item>div:last-child');
  [d.home,d.calendar,d.title,d.support,d.more].forEach((v,i)=>{if(labels[i])labels[i].textContent=v});
}
function enhanceLighthouse(){
  if(window.__ITHAKI_R10F7_GLOBAL_LANGUAGE_OWNER__)return;
  const overlay=$('lighthouseOverlayV249278');if(!overlay)return;
  const top=overlay.querySelector('.lighthouseTopBarV249278');
  if(top&&!top.querySelector('[data-r10f6-lighthouse-tools]')){
    const tools=document.createElement('div');tools.className='ith536OverlayTools lighthouse';tools.dataset.r10f6LighthouseTools='1';tools.innerHTML=languageSelect('lighthouse')+'<button type="button" data-r10f6-translate-view="lighthouse">🌐 '+esc(tr('translateView'))+'</button>';
    top.insertBefore(tools,top.lastElementChild);
  }
  localizeLighthouse();
}
async function translateView(which,button){
  const overlay=which==='bottle'?$('bottleSeaOverlayV249274'):$('lighthouseOverlayV249278');if(!overlay)return;
  button.disabled=true;const old=button.textContent;button.textContent='🌐 '+tr('translating');
  const selectors=which==='bottle'
    ? '.bottleSeaPanelV249274 h2,.bottleSeaPanelV249274 h3,.bottleSeaPanelV249274 p,.bottleSeaPanelV249274 .bottleSmallNoteV249274,.bottleSeaPanelV249274 .bottleTabsV249274 button,.bottleSeaPanelV249274 .bottleActionV249274,.bottleSeaPanelV249274 label'
    : '.lighthouseScreenV249278 h1,.lighthouseScreenV249278 p,.lighthouseScreenV249278 .lighthouseHintV249278,.lighthouseScreenV249278 .sub,.lighthouseScreenV249278 .lighthouseFooterTabsV249278 .item>div:last-child';
  const nodes=[...overlay.querySelectorAll(selectors)].filter(n=>n.textContent.trim()&&!n.closest('.ith536OverlayTools')).slice(0,40);
  for(const node of nodes){
    if(!node.dataset.r10f6Original)node.dataset.r10f6Original=node.textContent;
    try{const v=await requestTranslate(node.dataset.r10f6Original,target());if(v&&v.trim()!==node.dataset.r10f6Original.trim())node.textContent=v}catch(_e){}
  }
  if(which==='lighthouse')localizeLighthouse();
  button.disabled=false;button.textContent=old;
}
async function hydrateReactions(){
  const buttons=[...document.querySelectorAll('#ith526AnonymousWall [data-r10f6-react]')];if(!buttons.length)return;
  const ids=[...new Set(buttons.map(b=>b.dataset.r10f6Post).filter(Boolean))].slice(0,120);if(!ids.length)return;
  try{
    const r=await fetch(api('/api/v411/wall/reactions?room_id='+encodeURIComponent(room())+'&post_ids='+encodeURIComponent(ids.join(','))+'&device_id='+encodeURIComponent(device())),{cache:'no-store',credentials:'include'});
    if(!r.ok)return;const d=await r.json();
    (d.items||[]).forEach(item=>{
      document.querySelectorAll('#ith526AnonymousWall [data-r10f6-post="'+CSS.escape(String(item.post_id))+'"]').forEach(b=>{
        const emoji=b.dataset.r10f6React;const n=b.querySelector('i');if(n)n.textContent=String((item.counts||{})[emoji]||0);
        b.classList.toggle('active',Array.isArray(item.mine)&&item.mine.includes(emoji));
      });
    });
  }catch(_e){}
}
function scheduleHydrate(){clearTimeout(hydrateTimer);hydrateTimer=setTimeout(hydrateReactions,50)}
async function react(button){
  if(button.disabled)return;button.disabled=true;button.classList.add('pulse');
  const emoji=button.dataset.r10f6React,postId=button.dataset.r10f6Post;
  try{
    const r=await fetch(api('/api/v411/wall/reaction'),{method:'POST',headers:{'Content-Type':'application/json'},credentials:'include',body:JSON.stringify({room_id:room(),post_id:postId,device_id:device(),emoji})});
    if(!r.ok){let d={};try{d=await r.json()}catch(_e){}throw new Error(d.detail||('HTTP '+r.status))}
    const d=await r.json();
    document.querySelectorAll('#ith526AnonymousWall [data-r10f6-post="'+CSS.escape(postId)+'"]').forEach(b=>{
      const e=b.dataset.r10f6React,n=b.querySelector('i');if(n)n.textContent=String((d.counts||{})[e]||0);
      b.classList.toggle('active',Array.isArray(d.mine)&&d.mine.includes(e));
    });
  }catch(_e){toast(uiLang()==='en'?'The reaction was not saved.':'Η αντίδραση δεν καταχωρήθηκε.')}
  finally{setTimeout(()=>{button.disabled=false;button.classList.remove('pulse')},260)}
}
function connectReactionSocket(){
  if(!$('ith526AnonymousWall'))return;
  if(reactionSocket&&(reactionSocket.readyState===0||reactionSocket.readyState===1))return;
  try{
    const base=api('').replace(/^http:/,'ws:').replace(/^https:/,'wss:');
    reactionSocket=new WebSocket(base+'/ws/v411/wall/'+encodeURIComponent(room()));
    reactionSocket.onmessage=e=>{try{const m=JSON.parse(e.data);if(m.type==='v411_reaction')scheduleHydrate()}catch(_e){}};
    reactionSocket.onclose=()=>{reactionSocket=null;clearTimeout(reactionReconnect);if($('ith526AnonymousWall'))reactionReconnect=setTimeout(connectReactionSocket,2600)};
  }catch(_e){}
}
function closeReactionSocketIfNeeded(){if($('ith526AnonymousWall'))return;if(reactionSocket){try{reactionSocket.close()}catch(_e){}reactionSocket=null}}
function scan(){
  injectCss();enhanceWall();enhanceBottle();enhanceLighthouse();closeReactionSocketIfNeeded();
}
function injectCss(){
  if($('ith536TranslationThemeReactionStyle'))return;
  const style=document.createElement('style');style.id='ith536TranslationThemeReactionStyle';style.textContent=`
  .ith536Lang{display:inline-flex;align-items:center;gap:5px;min-width:0;padding:5px 7px;border:1px solid var(--line,rgba(255,255,255,.14));border-radius:12px;background:color-mix(in srgb,var(--bg,#06131f) 82%,transparent);color:var(--text,#eef7ff)}
  .ith536Lang select{max-width:132px;border:0;outline:0;background:transparent;color:inherit;font:inherit;font-size:12px}.ith536Lang option{color:#111;background:#fff}
  .ith536WallTools,.ith536OverlayTools{display:flex;align-items:center;gap:6px;flex-wrap:wrap}.ith536WallTools{margin-left:auto}.ith536OverlayTools{margin-left:auto;margin-right:6px}
  .ith536OverlayTools>button,.ith536TranslateControls button{border:1px solid var(--line,rgba(255,255,255,.14));border-radius:12px;background:rgba(255,255,255,.07);color:var(--text,#eef7ff);padding:7px 9px;font:inherit}
  .ith536TranslateHost{display:block}.ith536TranslateControls{display:flex;align-items:center;gap:6px;margin-top:7px}.ith536TranslateControls button{font-size:11px;padding:5px 8px}.ith536Translated{margin-top:7px;padding:9px 11px;border-left:3px solid var(--blue,#55d7ff);border-radius:11px;background:color-mix(in srgb,var(--blue,#55d7ff) 9%,transparent);color:var(--text,#eef7ff);white-space:pre-wrap;line-height:1.5}.ith536Translated.unavailable{border-left-color:var(--gold,#ffd36e);color:var(--muted,#a8b9c8)}
  #ith526AnonymousWall .ith534Reactions[data-r10f6-owner="1"] button{transition:transform .16s ease,background .16s ease,border-color .16s ease}#ith526AnonymousWall .ith534Reactions[data-r10f6-owner="1"] button:active,#ith526AnonymousWall .ith534Reactions[data-r10f6-owner="1"] button.pulse{transform:scale(1.14)}#ith526AnonymousWall .ith534Reactions[data-r10f6-owner="1"] button.active{background:color-mix(in srgb,var(--gold,#ffd36e) 18%,transparent)!important;border-color:var(--gold,#ffd36e)!important;box-shadow:0 0 0 1px color-mix(in srgb,var(--gold,#ffd36e) 28%,transparent)}
  #bottleSeaOverlayV249274{color:var(--text,#eef7ff)!important}#bottleSeaOverlayV249274 .bottleSeaPanelV249274{background:linear-gradient(180deg,color-mix(in srgb,var(--bg,#06131f) 96%,var(--blue,#55d7ff) 4%),var(--bg,#06131f))!important;color:var(--text,#eef7ff)!important;border-color:var(--line,rgba(255,255,255,.14))!important}#bottleSeaOverlayV249274 .bottleSeaTopV249274,#bottleSeaOverlayV249274 .bottleTabsV249274{background:color-mix(in srgb,var(--bg,#06131f) 88%,transparent)!important;border-color:var(--line,rgba(255,255,255,.14))!important;color:var(--text,#eef7ff)!important}#bottleSeaOverlayV249274 .bottleTabsV249274 button.active,#bottleSeaOverlayV249274 .bottleActionV249274{background:var(--green,#36f0a0)!important;color:color-mix(in srgb,var(--bg,#06131f) 90%,#000)!important;border-color:var(--green,#36f0a0)!important}#bottleSeaOverlayV249274 .parchmentV249274,#bottleSeaOverlayV249274 .bottleItemV249274,#bottleSeaOverlayV249274 .bottleReplyBoxV249274{background:color-mix(in srgb,var(--bg,#06131f) 78%,white 6%)!important;color:var(--text,#eef7ff)!important;border-color:var(--line,rgba(255,255,255,.14))!important}#bottleSeaOverlayV249274 h2,#bottleSeaOverlayV249274 h3,#bottleSeaOverlayV249274 b{color:var(--gold,#ffd36e)!important}#bottleSeaOverlayV249274 textarea{background:color-mix(in srgb,var(--bg,#06131f) 82%,white 5%)!important;color:var(--text,#eef7ff)!important;border-color:var(--line,rgba(255,255,255,.14))!important}
  #lighthouseOverlayV249278 .lighthouseScreenV249278{background:radial-gradient(circle at 50% 16%,color-mix(in srgb,var(--blue,#55d7ff) 18%,transparent),transparent 34%),linear-gradient(180deg,color-mix(in srgb,var(--bg,#06131f) 92%,#071b38 8%),var(--bg,#06131f))!important;color:var(--text,#eef7ff)!important}#lighthouseOverlayV249278 .lighthouseCounterV249278,#lighthouseOverlayV249278 .lighthouseSeenV249278,#lighthouseOverlayV249278 .lighthouseHintV249278,#lighthouseOverlayV249278 .lighthouseFooterTabsV249278{background:color-mix(in srgb,var(--bg,#06131f) 72%,transparent)!important;border-color:var(--line,rgba(255,255,255,.14))!important;color:var(--text,#eef7ff)!important}#lighthouseOverlayV249278 h1,#lighthouseOverlayV249278 b{color:var(--gold,#ffd36e)!important}#lighthouseOverlayV249278 .lighthouseMainBtnV249278{background:linear-gradient(180deg,var(--gold,#ffd36e),color-mix(in srgb,var(--gold,#ffd36e) 72%,var(--green,#36f0a0)))!important;color:color-mix(in srgb,var(--bg,#06131f) 92%,#000)!important}#lighthouseOverlayV249278 .lighthouseFooterTabsV249278 .item.active{color:var(--gold,#ffd36e)!important}
  @media(max-width:720px){.ith536WallTools{width:100%;order:4}.ith536OverlayTools{max-width:68vw;justify-content:flex-end}.ith536OverlayTools>button{font-size:0;padding:8px}.ith536OverlayTools>button:before{content:'🌐';font-size:16px}.ith536Lang select{max-width:104px}}
  `;document.head.appendChild(style);
}

document.addEventListener('change',e=>{const s=e.target.closest('[data-r10f6-language]');if(!s)return;setTarget(s.value);if($('lighthouseOverlayV249278'))localizeLighthouse()},true);
document.addEventListener('click',e=>{
  const reactBtn=e.target.closest('[data-r10f6-react]');if(reactBtn){e.preventDefault();e.stopImmediatePropagation();return react(reactBtn)}
  const trans=e.target.closest('[data-r10f6-translate]');if(trans){e.preventDefault();e.stopImmediatePropagation();const host=trans.closest('.ith536TranslateHost');const source=host&&host.firstElementChild;return translateElement(trans,source)}
  const original=e.target.closest('[data-r10f6-original]');if(original){e.preventDefault();e.stopImmediatePropagation();const host=original.closest('.ith536TranslateHost'),out=host&&host.querySelector(':scope > .ith536Translated');if(out)out.hidden=true;original.hidden=true;return}
  const view=e.target.closest('[data-r10f6-translate-view]');if(view){e.preventDefault();e.stopImmediatePropagation();return translateView(view.dataset.r10f6TranslateView,view)}
},true);

const observer=new MutationObserver(()=>{clearTimeout(scanTimer);scanTimer=setTimeout(scan,0)});
function boot(){injectCss();scan();observer.observe(document.documentElement,{childList:true,subtree:true});setInterval(()=>{enhanceWall();enhanceBottle();enhanceLighthouse()},5000)}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});else boot();
window.addEventListener('pageshow',scan);window.addEventListener('ithaki:page-changed',scan);window.addEventListener('ithaki:language-changed',scan);window.addEventListener('ithaki:theme-changed',scan);
})();
