/* OK ITHAKI V249471
 * Mobile bar spacing, softer/static Bil, true Bil disable, complete notification EL/EN,
 * Sokrataki-to-Bil visible rename, classic time themes, closed-app message defaults,
 * and feed video sound enabled by default.
 * Database/media/messages/calls/friends are preserved.
 */
(function(){
  'use strict';
  if(window.__ITHAKI_V249471_COMPLETE__) return;
  window.__ITHAKI_V249471_COMPLETE__={version:'V249471',installedAt:Date.now()};
  window.__ITHAKI_V249473_FEED_AUDIO_OWNER__=true;

  var BIL_ID='ithBilGreenTurtleV249461';
  var BIL_MENU_ID='ithBilMenuV249461';
  var BIL_POP_ID='ithBilPopV249461';
  var BIL_KEY='ith_bil_enabled_v249461';
  var SOUND_KEY='ith_video_sound_enabled_v249220';
  var THEME_KEY='ith_screen_theme_v249145';
  var observer=null, scheduled=false, wrapped=false, soundUnlocked=false;

  function I(){return window.ITH||(window.ITH={});}
  function english(){try{return String(localStorage.getItem('ith_ui_lang_v249141')||localStorage.getItem('ith_ui_lang')||document.documentElement.lang||'el').toLowerCase().indexOf('en')===0}catch(e){return false}}
  function bilEnabled(){try{return localStorage.getItem(BIL_KEY)!=='0'}catch(e){return true}}
  function setNativeLanguage(){try{var b=window.OKITHAKI_ANDROID||window.AndroidBridge;if(b&&typeof b.setUiLanguage==='function')b.setUiLanguage(english()?'en':'el')}catch(e){}}
  function addCss(){
    if(document.getElementById('ithV249471Css'))return;
    var st=document.createElement('style');st.id='ithV249471Css';st.textContent=`
      @media(max-width:760px){
        body:not([data-page="feed"]) .top{transform:translateY(4px)!important;z-index:42!important}
        #nav.nav,.nav{bottom:calc(9px + env(safe-area-inset-bottom))!important;background:rgba(4,14,25,.17)!important;border-top:1px solid rgba(255,255,255,.055)!important;box-shadow:none!important;backdrop-filter:blur(15px) saturate(115%)!important;-webkit-backdrop-filter:blur(15px) saturate(115%)!important}
        #nav.nav button,.nav button{background:rgba(5,18,31,.38)!important;border-color:rgba(255,255,255,.075)!important;box-shadow:0 7px 20px rgba(0,0,0,.12)!important}
      }
      body.ithBilDisabledV249471 #${BIL_ID},body.ithBilDisabledV249471 #${BIL_MENU_ID},body.ithBilDisabledV249471 #${BIL_POP_ID}{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important}
      #${BIL_ID},#${BIL_ID} .bilFace467,#${BIL_ID} .sokraMiniV249252,#${BIL_ID} .bilAliveV249466,#${BIL_ID} .bilShell467,#${BIL_ID} .shell,#${BIL_ID} .bilFoot467,#${BIL_ID} .foot{animation:none!important;transform:none!important;transition:none!important}
      #${BIL_ID} .bilHead467,#${BIL_ID} .head{animation:ithBilHeadSoftV249471 9.2s ease-in-out infinite!important;transform-origin:50% 105%!important}
      #${BIL_ID} .bilEye467,#${BIL_ID} .eye{animation:ithBilBlinkSoftV249471 8.4s ease-in-out infinite!important}
      @keyframes ithBilHeadSoftV249471{0%,100%{transform:rotate(-.55deg)}50%{transform:rotate(.65deg)}}
      @keyframes ithBilBlinkSoftV249471{0%,48%,51%,100%{transform:scaleY(1)}49.5%{transform:scaleY(.25)}}
      #feedPage video{background:#000!important}
    `;document.head.appendChild(st);
  }

  function applyBilState(){
    if(window.__ITHAKI_V249475_OWNS_BIL__)return;
    if(!document.body)return;
    var enabled=bilEnabled();
    document.body.classList.toggle('ithBilDisabledV249471',!enabled);
    document.documentElement.setAttribute('data-bil-enabled-v249471',enabled?'1':'0');
    if(!enabled){[BIL_ID,BIL_MENU_ID,BIL_POP_ID].forEach(function(id){var x=document.getElementById(id);if(x)x.remove();});}
  }
  function disableBil(){
    try{localStorage.setItem(BIL_KEY,'0')}catch(e){}
    applyBilState();
    try{var t=I().toast||window.toast;if(typeof t==='function')t(english()?'Bil has been disabled.':'Ο Bil απενεργοποιήθηκε.')}catch(e){}
    return false;
  }
  function captureBilDisable(ev){
    try{var b=ev.target&&ev.target.closest&&ev.target.closest('[data-bil-action="toggle"]');if(!b)return;ev.preventDefault();ev.stopImmediatePropagation();disableBil();}catch(e){}
  }

  var EXACT_EN={
    'Ειδοποιήσεις':'Notifications','Ρυθμίσεις':'Settings','Ρυθμίσεις ειδοποιήσεων':'Notification settings','Καθαρές ειδοποιήσεις':'Clear notifications','Καθαρισμός':'Clear','Φόρτωση ειδοποιήσεων...':'Loading notifications...','Φόρτωση αιτημάτων...':'Loading requests...','Δεν υπάρχουν νέες ειδοποιήσεις.':'There are no new notifications.','Δεν υπάρχουν αιτήματα φιλίας σε αναμονή.':'There are no pending friend requests.','Αιτήματα φιλίας':'Friend requests','Νέο αίτημα φιλίας':'New friend request','Περιμένει απάντηση':'Waiting for a response','Αίτημα σε παλιό/άλλο device':'Request on an old/other device','Αποδοχή':'Accept','Αποδοχή εδώ':'Accept here','Απόρριψη':'Reject','Όχι τώρα':'Not now','Άνοιγμα μηνυμάτων':'Open messages','Άνοιγμα Ροής':'Open Feed','Μενού μέλους':'Member menu','Δοκιμή ξανά':'Try again','Διαγνωστικό':'Diagnostics','Κατάσταση':'Status','Εισερχόμενα':'Incoming','Εξερχόμενα':'Outgoing','ενεργός':'online','ανενεργός':'offline','Σημείωση':'Note','Αν κολλούσε πριν':'If it was stuck before','Αποθήκευση':'Save','Αποθηκεύτηκαν':'Saved','Ήσυχες ώρες':'Quiet hours','Αρχή':'Start','Τέλος':'End','Μηνύματα':'Messages','Κλήσεις':'Calls','Likes':'Likes','Αναφορές':'Mentions','Αιτήματα φιλίας':'Friend requests','Νέοι ακόλουθοι':'New followers','Ακόλουθοι':'Followers','Σχόλια':'Comments','Απαντήσεις':'Replies','Δημοσιεύσεις':'Posts','Όλες οι ειδοποιήσεις':'All notifications','Χωρίς ειδοποιήσεις':'No notifications','Ανοιχτή εφαρμογή':'Open app','Παρασκήνιο':'Background','Δεν κοιμάται':'Always awake','FCM προεπιλογή':'FCM default','Χωρίς ειδοποιήσεις κλειστή συσκευή':'No notifications while device is closed','Μέγιστο 8 δευτερόλεπτα':'Maximum 8 seconds','Η σύνδεση άργησε ή το endpoint δεν απάντησε.':'The connection was slow or the endpoint did not respond.','Δεν φόρτωσαν τα αιτήματα.':'Requests did not load.','Σας έστειλε αίτημα φιλίας':'Sent you a friend request','Το αίτημα φιλίας περιμένει αποδοχή από την άλλη συσκευή':'The friend request is waiting for acceptance on the other device','Πατάς Αποδοχή ή Απόρριψη.':'Tap Accept or Reject.','Η αποδοχή γίνεται στην άλλη συσκευή.':'Acceptance happens on the other device.','Περιμένει απάντηση από την άλλη συσκευή.':'Waiting for a response from the other device.','Ο Bil απενεργοποιήθηκε.':'Bil has been disabled.'
  };
  function renameBilText(s){return String(s||'').replace(/Bil|Bil|Σωκρατάκη|Σωκρατακη|Bil|Bil|Sokrataki|Socrates companion/gi,'Bil');}
  function dynamicEnglish(s){
    s=renameBilText(s);
    var m;
    if((m=s.match(/^Νέο μήνυμα από (.+)\.$/)))return 'New message from '+m[1]+'.';
    if((m=s.match(/^Αίτημα φιλίας από (.+)\.$/)))return 'Friend request from '+m[1]+'.';
    if((m=s.match(/^(.+) έκανε like στη δημοσίευσή σου\.$/)))return m[1]+' liked your post.';
    if((m=s.match(/^(.+) σε ακολουθεί\.$/)))return m[1]+' follows you.';
    if((m=s.match(/^(.+) σου έστειλε μήνυμα$/)))return m[1]+' sent you a message';
    if((m=s.match(/^(.+) σου έστειλε αίτημα φιλίας$/)))return m[1]+' sent you a friend request';
    if((m=s.match(/^(.+) άρχισε να σε ακολουθεί$/)))return m[1]+' started following you';
    return EXACT_EN[s]||s;
  }
  function translateLeaf(el){
    if(!el||/^(SCRIPT|STYLE|TEXTAREA|INPUT|OPTION)$/.test(el.tagName||''))return;
    ['title','aria-label','placeholder'].forEach(function(a){var v=el.getAttribute&&el.getAttribute(a);if(v){var n=renameBilText(v);if(english())n=dynamicEnglish(n);if(n!==v)el.setAttribute(a,n);}});
    if(el.childElementCount===0){var raw=el.textContent||'',trim=raw.trim();if(!trim||trim.length>500)return;var out=renameBilText(trim);if(english())out=dynamicEnglish(out);if(out!==trim)el.textContent=raw.replace(trim,out);}
  }
  function translateNotificationUi(root){
    setNativeLanguage();root=root||document;
    var targets=[];
    try{if(root.nodeType===1)targets.push(root);root.querySelectorAll&&root.querySelectorAll('#memberMenu,#memberMenu *,[id*="notif" i],[class*="notif" i],[class*="Notice"],#nav button,#nav small').forEach(function(x){targets.push(x)});}catch(e){}
    targets.forEach(translateLeaf);
    // Visible legacy companion names are Bil everywhere, without renaming JavaScript identifiers.
    try{document.querySelectorAll('button,span,small,b,label,h1,h2,h3,p,div.date,.btn').forEach(function(el){if((el.textContent||'').match(/Σωκρατάκ|Sokrataki|Socrates companion/i))translateLeaf(el);});}catch(e){}
  }
  function wrapNotificationRenderers(){
    if(wrapped)return;var ith=I(),names=['notifyCenter','openNotificationSettingsV249238','renderNotificationCenter','refreshNotificationBadgeV249238'];var any=false;
    names.forEach(function(name){var fn=ith[name];if(typeof fn!=='function'||fn.__v249471Wrapped)return;var w=function(){var r=fn.apply(this,arguments);setTimeout(function(){translateNotificationUi(document)},0);setTimeout(function(){translateNotificationUi(document)},120);if(r&&typeof r.then==='function')r.finally(function(){setTimeout(function(){translateNotificationUi(document)},0)});return r};w.__v249471Wrapped=true;ith[name]=w;any=true;});
    if(any)wrapped=true;
  }

  function restoreClassicThemes(){
    try{if(localStorage.getItem(THEME_KEY)==='outdoor')localStorage.setItem(THEME_KEY,'auto')}catch(e){}
    try{if(document.body&&document.body.dataset.screenTheme==='outdoor')document.body.dataset.screenTheme='night'}catch(e){}
    try{var b=document.getElementById('screenThemeBtn');if(b&&b.textContent.trim()==='☀️')b.textContent='◐'}catch(e){}
    try{document.querySelectorAll('[onclick*="outdoor"],[data-theme="outdoor"]').forEach(function(x){x.remove()})}catch(e){}
  }

  function unmuteVideo(v,tryPlay){
    if(!v||String(v.tagName).toLowerCase()!=='video')return;
    try{v.defaultMuted=false;v.muted=false;v.volume=1;v.removeAttribute('muted');v.setAttribute('playsinline','');v.setAttribute('webkit-playsinline','');v.controls=true;if(tryPlay){var p=v.play();if(p&&p.catch)p.catch(function(){})}}catch(e){}
  }
  function soundOn(root,tryPlay){
    if(window.__ITHAKI_V249473_FEED_AUDIO_OWNER__) return;
    try{localStorage.setItem(SOUND_KEY,'1')}catch(e){}
    if(document.body)document.body.classList.add('videoSoundOnV249220');
    try{
      var single=I().enforceSingleFeedAudioV249472;
      if(typeof single==='function'){single(!!tryPlay);return}
      root=root||document;var videos=[];
      if(root.matches&&root.matches('video'))videos=[root];
      else if(root.querySelectorAll)videos=Array.prototype.slice.call(root.querySelectorAll('#feedPage video,video.feedVideo'));
      var active=null,best=0;
      videos.forEach(function(v){try{var r=v.getBoundingClientRect(),s=Math.max(0,Math.min(innerHeight,r.bottom)-Math.max(0,r.top))*Math.max(0,Math.min(innerWidth,r.right)-Math.max(0,r.left));if(s>best){best=s;active=v}}catch(e){}});
      videos.forEach(function(v){if(v===active)unmuteVideo(v,tryPlay);else try{v.pause();v.muted=true;v.defaultMuted=true}catch(e){}});
    }catch(e){}
  }
  function isVisible(v){try{var r=v.getBoundingClientRect();return r.bottom>0&&r.top<innerHeight&&r.width>0&&r.height>0}catch(e){return false}}
  function unlockSound(){soundUnlocked=true;soundOn(document,true)}

  function run(){addCss();applyBilState();restoreClassicThemes();wrapNotificationRenderers();translateNotificationUi(document);soundOn(document,soundUnlocked);document.documentElement.setAttribute('data-ithaki-v249471','mobile-bars-bil-notifications-messages-sound');}
  function schedule(){if(scheduled)return;scheduled=true;setTimeout(function(){scheduled=false;run()},35)}
  function install(){
    addCss();try{if(localStorage.getItem(SOUND_KEY)==null)localStorage.setItem(SOUND_KEY,'1')}catch(e){};run();
    document.addEventListener('click',captureBilDisable,true);
    ['pointerdown','touchend','click'].forEach(function(n){document.addEventListener(n,unlockSound,{capture:true,passive:true,once:n!=='click'})});
    if(document.body&&!observer){observer=new MutationObserver(schedule);observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['title','aria-label','class','src','muted']});}
    window.addEventListener('ithaki:page-changed',schedule);window.addEventListener('storage',schedule);document.addEventListener('visibilitychange',function(){if(!document.hidden)schedule()},{passive:true});
    [50,200,500,1000,2200,5000,10000].forEach(function(ms){setTimeout(run,ms)});setInterval(run,5000);
    Object.assign(I(),{disableBilV249471:disableBil,applyBilStateV249471:applyBilState,translateNotificationUiV249471:translateNotificationUi,enableVideoSoundV249471:unlockSound});
  }
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
