
// ===== OK ITHAKI V249345 HEIGHT + LEXICON + REAL WALL =====
(function(){
  if(window.__ITHAKI_V249345_HEIGHT_LEXICON_WALL__) return;
  window.__ITHAKI_V249345_HEIGHT_LEXICON_WALL__ = 1;
  const BUILD = 'V249345';
  const $ = id => document.getElementById(id);
  const GOLD = '#d8aa45';
  const room = () => { try { return (window.state && state.room) || localStorage.getItem('ith_room') || 'ithaki-phone-test'; } catch { return 'ithaki-phone-test'; } };
  const dev = () => { try { return (window.state && state.device) || localStorage.getItem('ith_device') || 'dev_web'; } catch { return 'dev_web'; } };
  const apiBase = () => { try { return (window.state && state.api) || location.origin; } catch { return location.origin; } };
  const esc = s => String(s ?? '').replace(/[&<>"']/g, m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[m]));
  const api = async(path,opt={}) => {
    const r = await fetch(apiBase()+path, Object.assign({cache:'no-store', headers:{'Content-Type':'application/json'}}, opt));
    let d=null; try{ d=await r.json(); }catch{ d={ok:false,status:r.status}; }
    if(!r.ok) throw new Error((d && (d.detail||d.message)) || ('HTTP '+r.status));
    return d;
  };
  function vh(){ return Math.max(520, Math.round((window.visualViewport && visualViewport.height) || window.innerHeight || document.documentElement.clientHeight || 720)); }
  function setVH(){ try{ document.documentElement.style.setProperty('--ith-vh344', vh()+'px'); }catch{} }
  function toast(msg){ try{ window.toast ? window.toast(msg) : console.log(msg); }catch{} }

  function css(){
    if($('ithV249345Css')) return;
    const st=document.createElement('style'); st.id='ithV249345Css'; st.textContent=`
      :root{--ith-vh344:100dvh;--ith-gold344:${GOLD};--ith-bottom344:calc(env(safe-area-inset-bottom,0px) + 74px)}
      #ithBuild344{position:fixed;right:8px;top:calc(env(safe-area-inset-top,0px) + 2px);z-index:2147483640;font:900 10px/1 system-ui;color:#ffd978;background:rgba(0,0,0,.48);border:1px solid rgba(255,217,120,.35);border-radius:999px;padding:4px 7px;pointer-events:none}
      #ithBook344{position:fixed;top:calc(env(safe-area-inset-top,0px) + 9px);left:50%;transform:translateX(-50%);z-index:2147482600;height:44px;min-width:122px;border-radius:999px;border:1px solid rgba(255,217,120,.62);background:rgba(4,10,18,.76);color:#fff2c8;font:950 15px/1 system-ui;display:flex;align-items:center;justify-content:center;gap:8px;box-shadow:0 12px 34px rgba(0,0,0,.38),inset 0 0 0 1px rgba(255,255,255,.06);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
      #ithBook344:active{transform:translateX(-50%) scale(.96)}
      #ithFeature344{position:fixed;left:10px;top:calc(env(safe-area-inset-top,0px) + 62px);z-index:2147482400;display:flex;gap:7px;pointer-events:auto}
      #ithFeature344 button{border-radius:999px;border:1px solid rgba(255,217,120,.45);background:rgba(3,8,16,.66);color:#ffe6a6;font:900 12px/1 system-ui;padding:9px 11px;box-shadow:0 8px 22px rgba(0,0,0,.32);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px)}
      #ithFeature344 button:active{transform:scale(.96)}
      /* FEED HEIGHT DOCTOR: use exact px height, not only width */
      #feedPage{background:#000!important}
      #feedPage .ithHeightCard344{height:var(--ith-vh344)!important;min-height:var(--ith-vh344)!important;max-height:var(--ith-vh344)!important;width:100vw!important;margin:0 0 46px 0!important;padding:0!important;border:0!important;border-radius:0!important;overflow:hidden!important;background:#000!important;box-shadow:none!important;scroll-snap-align:start!important;scroll-snap-stop:always!important}
      #feedPage .ithHeightWrap344{height:100%!important;min-height:100%!important;max-height:100%!important;width:100%!important;margin:0!important;padding:0!important;border:0!important;border-radius:0!important;overflow:hidden!important;background:#000!important}
      #feedPage video.ithHeightVideo344{position:absolute!important;inset:0!important;width:100%!important;height:var(--ith-vh344)!important;min-height:var(--ith-vh344)!important;max-height:none!important;object-fit:cover!important;object-position:center center!important;background:#000!important;border:0!important;border-radius:0!important;margin:0!important;padding:0!important;display:block!important}
      #feedPage .mediaOpenBtn,#feedPage [class*="fullscreen" i],#feedPage [id*="fullscreen" i],#feedPage [class*="zoom" i],#feedPage [id*="zoom" i],#feedPage button[title*="full" i],#feedPage button[title*="zoom" i],#feedPage button[title*="μεγ" i],#feedPage button[aria-label*="full" i],#feedPage button[aria-label*="zoom" i]{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important;width:0!important;height:0!important;overflow:hidden!important}
      #feedPage video::-webkit-media-controls-fullscreen-button{display:none!important}
      #previewModal.show,.previewModal.show{overflow-y:auto!important;-webkit-overflow-scrolling:touch!important;align-items:unset!important;justify-content:unset!important;padding-bottom:calc(env(safe-area-inset-bottom,0px) + 34px)!important}
      #previewModal.show .row:last-child,.previewModal.show .row:last-child{position:sticky!important;bottom:0!important;z-index:2147483600!important;background:rgba(7,17,30,.98)!important;border-radius:16px!important;padding:10px!important;display:flex!important;gap:8px!important;flex-wrap:wrap!important}
      #ithPreviewCancel344{position:fixed!important;top:calc(env(safe-area-inset-top,0px) + 8px)!important;left:10px!important;z-index:2147483647!important;border:0!important;border-radius:16px!important;background:#d83b3b!important;color:#fff!important;font-weight:1000!important;padding:11px 15px!important;box-shadow:0 12px 30px rgba(0,0,0,.45)!important}
      .ithModal344{position:fixed;inset:0;z-index:2147483300;background:#02070e;color:#fff;overflow-y:auto;-webkit-overflow-scrolling:touch;font-family:system-ui,-apple-system,Segoe UI,sans-serif}.ithModal344 *{box-sizing:border-box}.ithClose344{position:fixed;right:12px;top:calc(env(safe-area-inset-top,0px) + 12px);z-index:10;width:42px;height:42px;border-radius:50%;border:1px solid rgba(255,217,120,.45);background:rgba(0,0,0,.55);color:#fff;font-size:25px}
      .wall344{min-height:var(--ith-vh344);padding:calc(env(safe-area-inset-top,0px) + 28px) 12px calc(env(safe-area-inset-bottom,0px) + 106px);background:radial-gradient(circle at 50% 0,rgba(45,109,160,.24),transparent 32%),radial-gradient(circle at 0 44%,rgba(216,170,69,.14),transparent 26%),linear-gradient(160deg,#07111d,#04070b 64%,#010204)}
      .wallHead344{text-align:center;padding:10px 44px 14px}.wallLogo344{display:flex;align-items:center;justify-content:center;gap:9px;margin-bottom:8px}.wallLogo344 img{width:42px;height:42px;object-fit:cover;border-radius:14px;border:1px solid rgba(255,217,120,.38)}.wallLogo344 b{font-size:26px}.wallLogo344 span{color:#d8aa45;font-weight:900}.wallHead344 h1{font-size:clamp(31px,8vw,44px);margin:6px 0 4px}.wallHead344 p{margin:0;color:#d8dce5}.wallShield344{color:#d8aa45;font-size:13px;margin-top:8px}.wallLive344{display:flex;justify-content:space-between;align-items:center;margin:6px auto 14px;max-width:760px;color:#cfd9e8;font-size:13px}.wallLive344 b{color:#87d98b}.wallList344{display:grid;gap:12px;max-width:760px;margin:0 auto}.wallCard344{border:1px solid rgba(255,217,120,.20);background:linear-gradient(145deg,rgba(16,30,45,.82),rgba(6,11,18,.78));border-radius:22px;padding:14px;box-shadow:0 14px 38px rgba(0,0,0,.32),inset 0 1px 0 rgba(255,255,255,.06)}.wallMeta344{display:flex;align-items:center;gap:10px}.wallMask344{width:42px;height:42px;border-radius:50%;display:grid;place-items:center;border:1px solid rgba(255,217,120,.48);background:rgba(216,170,69,.14);font-size:22px}.wallMeta344 b{font-size:17px}.wallMeta344 small{display:block;color:#aeb7c4}.wallDots344{margin-left:auto;background:none;border:0;color:#bec6d0;font-size:24px}.wallText344{font-size:17px;line-height:1.38;margin:13px 0;color:#fff}.wallActions344{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}.wallActions344 button{border-radius:13px;border:1px solid rgba(255,255,255,.16);background:rgba(0,0,0,.20);color:#f5f0e5;padding:9px 6px;font-weight:900}.wallActions344 b{color:#ffd978;margin-left:5px}.wallReport344{display:block;margin:8px auto 0;border:0;background:none;color:#aeb7c4}.wallNew344{display:block;margin:15px auto 10px;width:min(560px,84vw);height:54px;border-radius:999px;border:0;background:linear-gradient(135deg,#c99536,#f0c56f);color:#fff;font-size:18px;font-weight:1000;box-shadow:0 14px 34px rgba(0,0,0,.34)}.wallComposer344{position:sticky;bottom:calc(env(safe-area-inset-bottom,0px) + 6px);max-width:820px;margin:0 auto;border-radius:24px;border:1px solid rgba(255,217,120,.28);background:rgba(8,18,30,.96);padding:12px;box-shadow:0 -12px 40px rgba(0,0,0,.45);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}.wallComposer344 .anon{display:flex;justify-content:flex-end;color:#d8aa45;font-size:13px;font-weight:900}.wallComposer344 textarea{width:100%;min-height:92px;max-height:160px;resize:vertical;border:1px solid rgba(255,255,255,.16);border-radius:16px;background:rgba(0,0,0,.20);color:#fff;font-size:16px;padding:12px;outline:0}.wallComposer344 .counter{text-align:right;color:#aeb7c4;font-size:12px}.wallComposerBtns344{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:10px}.wallComposerBtns344 button{height:50px;border-radius:15px;font-weight:1000;font-size:16px}.wallCancel344{background:#08111e;border:1px solid rgba(216,170,69,.5);color:#d8aa45}.wallSend344{border:0;background:linear-gradient(135deg,#c99536,#f0c56f);color:#fff}
    `;
    document.head.appendChild(st);
  }

  function openLexicon(){
    const fns=[
      ()=>window.ITH&&ITH.openTranslationBookV249345&&ITH.openTranslationBookV249345(),
      ()=>window.ITH&&ITH.openTranslationBookV249338&&ITH.openTranslationBookV249338(),
      ()=>window.openTranslationBookV249338&&window.openTranslationBookV249338(),
      ()=>window.openTranslationBookV249336&&window.openTranslationBookV249336(),
      ()=>window.openTranslationBookV249335&&window.openTranslationBookV249335(),
      ()=>window.openTranslationBookV249324&&window.openTranslationBookV249324()
    ];
    for(const fn of fns){try{const r=fn(); if(r!==undefined) return r;}catch{}}
    try{alert('Λεξικό');}catch{}
  }

  function ensureUI(){
    css(); setVH();
    ['ithBuild339','ithBuild340','ithBuild341','ithBuild342','ithBuild343','ithTrueFeed341','ithTrueFeedList341','ithRestoreNote342','ithBook339','ithBook343','ithFeature343'].forEach(id=>{try{$(id)?.remove()}catch{}});
    try{document.body.classList.remove('ithTrueFeedOn341')}catch{}
    if(!$('ithBuild344')){const b=document.createElement('div');b.id='ithBuild344';b.textContent=BUILD;document.body.appendChild(b)}
    if(!$('ithBook344')){const b=document.createElement('button');b.id='ithBook344';b.type='button';b.innerHTML='<span>📖</span><span>Λεξικό</span>';b.onclick=openLexicon;document.body.appendChild(b)}
    if(!$('ithFeature344')){const f=document.createElement('div');f.id='ithFeature344';f.innerHTML='<button type="button" data-open="wall">🧱 Τοίχος</button><button type="button" data-open="light">🕯️ Φάρος</button>';f.onclick=e=>{const b=e.target.closest('button');if(!b)return;b.dataset.open==='wall'?openWall():openLighthouse();};document.body.appendChild(f)}
  }

  function forceFeedHeight(){
    const feed=$('feedPage'); if(!feed) return;
    const h=vh(); document.documentElement.style.setProperty('--ith-vh344', h+'px');
    try{
      feed.style.setProperty('height',h+'px','important');
      feed.style.setProperty('max-height',h+'px','important');
      feed.style.setProperty('overflow','hidden','important');
    }catch{}
    const videos=[...feed.querySelectorAll('video')];
    videos.forEach(v=>{
      try{
        v.controls=false; v.removeAttribute('controls'); v.setAttribute('playsinline',''); v.setAttribute('webkit-playsinline','');
        v.setAttribute('controlsList','nodownload nofullscreen noremoteplayback'); v.disablePictureInPicture=true; v.disableRemotePlayback=true;
        v.classList.add('ithHeightVideo344');
        v.style.setProperty('height',h+'px','important');
        v.style.setProperty('min-height',h+'px','important');
        v.style.setProperty('max-height','none','important');
        v.style.setProperty('object-fit','cover','important');
        v.style.setProperty('width','100%','important');
      }catch{}
      let card=v.closest('article.card.post.mediaPost,.post.mediaPost,article.feedSlideV249316,article[data-kind="video"],.feedItem,.mediaPost,article') || v.parentElement;
      if(card && card!==feed){
        card.classList.add('ithHeightCard344');
        try{
          card.style.setProperty('height',h+'px','important');
          card.style.setProperty('min-height',h+'px','important');
          card.style.setProperty('max-height',h+'px','important');
          card.style.setProperty('overflow','hidden','important');
          card.style.setProperty('width','100vw','important');
          card.style.setProperty('background','#000','important');
        }catch{}
      }
      let p=v.parentElement, n=0;
      while(p && p!==feed && p!==card && n++<6){
        p.classList.add('ithHeightWrap344');
        try{
          p.style.setProperty('height','100%','important');
          p.style.setProperty('min-height','100%','important');
          p.style.setProperty('max-height','100%','important');
          p.style.setProperty('overflow','hidden','important');
          p.style.setProperty('background','#000','important');
        }catch{}
        p=p.parentElement;
      }
    });
    feed.querySelectorAll('.mediaOpenBtn,[class*="fullscreen" i],[id*="fullscreen" i],[class*="zoom" i],[id*="zoom" i],button[title*="full" i],button[title*="zoom" i],button[title*="μεγ" i]').forEach(el=>{try{el.remove()}catch{try{el.style.setProperty('display','none','important')}catch{}}});
  }

  function preview(){
    const pm=$('previewModal'); if(!pm) return;
    const show=pm.classList.contains('show')||String(pm.innerHTML||'').trim().length>20;
    if(!show){$('ithPreviewCancel344')?.remove();return;}
    pm.classList.add('show');
    if(!$('ithPreviewCancel344')){const c=document.createElement('button');c.id='ithPreviewCancel344';c.textContent='Άκυρο';c.type='button';c.onclick=()=>{try{if(window.ITH&&ITH.closePreview)ITH.closePreview();else{pm.classList.remove('show');pm.innerHTML='';}}catch{pm.classList.remove('show');pm.innerHTML='';}c.remove();};document.body.appendChild(c)}
  }

  let ws344=null;
  function live(onmsg){
    if(ws344 && ws344.readyState<=1) return ws344;
    try{
      ws344=new WebSocket(apiBase().replace(/^http/,'ws')+'/ws/live_v249345');
      ws344.onmessage=e=>{try{const m=JSON.parse(e.data);if(m.type&&!['ready','pong'].includes(m.type))onmsg&&onmsg(m)}catch{}};
      ws344.onclose=()=>{ws344=null};
    }catch{}
    return ws344;
  }

  async function openWall(){
    ensureUI(); let root=$('ithWall344'); if(!root){root=document.createElement('div');root.id='ithWall344';root.className='ithModal344';document.body.appendChild(root)}
    root.innerHTML=`<button class="ithClose344">×</button><section class="wall344">
      <header class="wallHead344"><div class="wallLogo344"><img src="/ok_ithaki_ship_logo.png" onerror="this.style.display='none'"><div><b>OK</b><span> ITHAKI</span></div></div><h1>Ανώνυμος Τοίχος 🛡️</h1><p>Μοιράσου σκέψεις ανώνυμα με ασφάλεια</p><div class="wallShield344">⚓ 100% Ανώνυμο · χωρίς όνομα στο μήνυμα</div></header>
      <div class="wallLive344"><span>🟢 Ζωντανά τώρα: <b id="wallLive344">0</b></span><span>Ανανεώνεται ζωντανά</span></div>
      <div class="wallList344" id="wallList344"><div class="wallCard344">Φόρτωση...</div></div>
      <button class="wallNew344" id="wallNew344">+ Νέα ανώνυμη ανάρτηση</button>
      <div class="wallComposer344"><div class="anon">🛡️ 100% Ανώνυμο</div><textarea id="wallText344" maxlength="500" placeholder="Γράψε ανώνυμα..."></textarea><div class="counter"><span id="wallCount344">0</span> / 500</div><div class="wallComposerBtns344"><button class="wallCancel344" id="wallCancel344">Ακύρωση</button><button class="wallSend344" id="wallSend344">Δημοσίευση ➤</button></div></div>
    </section>`;
    root.querySelector('.ithClose344').onclick=()=>root.remove();
    $('wallNew344').onclick=()=>$('wallText344')?.focus();
    $('wallCancel344').onclick=()=>{const t=$('wallText344'); if(t){t.value='';$('wallCount344').textContent='0'}};
    $('wallText344').oninput=()=>{$('wallCount344').textContent=String(($('wallText344').value||'').length)};
    $('wallSend344').onclick=async()=>{const t=($('wallText344')?.value||'').trim(); if(!t)return toast('Γράψε πρώτα κάτι.'); try{await api('/api/wall/post_v249345',{method:'POST',body:JSON.stringify({room_id:room(),owner_token:dev(),text:t})});$('wallText344').value='';$('wallCount344').textContent='0';await loadWall();}catch(e){toast('Δεν στάλθηκε: '+e.message)}};
    window.__wallReact344=async(post_id,kind,btn)=>{try{const r=await api('/api/wall/react_v249345',{method:'POST',body:JSON.stringify({room_id:room(),owner_token:dev(),post_id,kind})}); if(btn){btn.querySelector('b').textContent=String(kind==='understand'?r.understand:(kind==='reply'?r.replies:r.support));}}catch(e){toast('Δεν μετρήθηκε.')}};
    window.__wallReport344=async(post_id)=>{try{await api('/api/wall/report_v249345',{method:'POST',body:JSON.stringify({room_id:room(),owner_token:dev(),post_id,reason:'user_report'})});toast('Έγινε αναφορά.')}catch(e){}};
    async function loadWall(){
      try{
        const d=await api('/api/wall/list_v249345?room_id='+encodeURIComponent(room())+'&limit=80');
        $('wallLive344').textContent=d.live_now||0;
        const sample=[
          {text:'Μερικές μέρες νιώθω ότι κανείς δεν με καταλαβαίνει. Απλώς ήθελα να το γράψω κάπου.',support:28,replies:12,understand:41,created_at:Date.now()/1000-7200,post_id:'sample1'},
          {text:'Προσπαθώ να αλλάξω, αλλά με φοβίζει το αύριο. Έχει κάποιος περάσει κάτι παρόμοιο;',support:19,replies:8,understand:27,created_at:Date.now()/1000-18000,post_id:'sample2'},
          {text:'Ευγνώμων για τη μικρή χαρά της ημέρας. Ένα ηλιοβασίλεμα αρκεί καμιά φορά.',support:35,replies:6,understand:53,created_at:Date.now()/1000-86400,post_id:'sample3'}
        ];
        const posts=(d.posts&&d.posts.length?d.posts:sample);
        $('wallList344').innerHTML=posts.map(p=>{
          const when=new Date((p.created_at||0)*1000).toLocaleString('el-GR',{day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'});
          return `<article class="wallCard344"><div class="wallMeta344"><div class="wallMask344">🎭</div><div><b>Ανώνυμος</b><small>${esc(when)}</small></div><button class="wallDots344">•••</button></div><p class="wallText344">${esc(p.text)}</p><div class="wallActions344"><button onclick="__wallReact344('${esc(p.post_id)}','support',this)">❤️ Στήριξη <b>${p.support||0}</b></button><button onclick="__wallReact344('${esc(p.post_id)}','reply',this)">💬 Απάντηση <b>${p.replies||0}</b></button><button onclick="__wallReact344('${esc(p.post_id)}','understand',this)">🕯️ Κατανόηση <b>${p.understand||0}</b></button></div><button class="wallReport344" onclick="__wallReport344('${esc(p.post_id)}')">⚐ Αναφορά</button></article>`;
        }).join('');
      }catch(e){$('wallList344').innerHTML='<div class="wallCard344">Δεν φορτώθηκε ο Τοίχος.</div>';}
    }
    await loadWall();
    live(m=>{if(!$('ithWall344'))return;if(m.type&&m.type.startsWith('wall_'))loadWall();});
  }

  async function openLighthouse(){
    try{ if(window.ITH && window.ITH.openLighthouseV249339) return window.ITH.openLighthouseV249339(); }catch{}
    alert('Ο Φάρος θα ανοίξει εδώ. V249345');
  }

  function loop(){ ensureUI(); forceFeedHeight(); preview(); }
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',loop,{once:true}); else loop();
  [80,180,420,900,1600,2600,4200,6500].forEach(t=>setTimeout(loop,t));
  setInterval(loop,650);
  try{new MutationObserver(loop).observe(document.documentElement,{childList:true,subtree:true,attributes:true})}catch{}
  addEventListener('resize',()=>{setVH();forceFeedHeight()});
  if(window.visualViewport) visualViewport.addEventListener('resize',()=>{setVH();forceFeedHeight()});
  window.ITH=window.ITH||{};
  Object.assign(window.ITH,{openWallV249345:openWall,openAnonymousWallV249345:openWall,openLighthouseV249345:openLighthouse,forceFeedHeightV249345:forceFeedHeight,openLexiconV249345:openLexicon});
})();
// ===== END OK ITHAKI V249345 HEIGHT + LEXICON + REAL WALL =====
