(function() {
  'use strict';
  
  var SORO_BLOG_TITLE = 'ournextfloridahome.com';
  var SORO_ARTICLES = [{"id":"05cbbdc2-bb38-4114-abe9-65dba56ae9b7","title":"Gulf Access Versus Freshwater Canals Which Fits?","slug":"gulf-access-versus-freshwater-canals","excerpt":"Compare gulf access versus freshwater canals in Cape Coral, including boating, costs, bridges, maintenance, and resale factors that shape your choice.","content":null,"date":"November 16, 2026","isoDate":"2026-11-16T01:53:17.382+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/5e768127-f20a-482f-a8c3-ffe04b35f853.webp"},{"id":"a4a7edce-0b25-4999-8308-08f63bb06b02","title":"Florida Relocation Checklist Before You Buy","slug":"florida-relocation-checklist-before-you-buy","excerpt":"Use this Florida relocation checklist to plan housing, insurance, taxes, schools, and the real costs of settling into Fort Myers, Cape Coral, or nearby.","content":null,"date":"November 14, 2026","isoDate":"2026-11-14T01:53:16.595+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/0eebc055-9275-4890-83c7-8e0ea15f089f.webp"},{"id":"7b3ad5bf-41bf-4ff0-949c-580155783fbb","title":"Florida Condo Fees: What Buyers Need to Know","slug":"florida-condo-fees","excerpt":"Florida condo fees can shape a budget and resale options. Learn what they cover, how to review reserves, and questions Southwest Florida buyers should ask.","content":null,"date":"November 12, 2026","isoDate":"2026-11-12T01:53:35.46+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/538a7b19-d180-4c2a-9437-85b98f72c1b0.webp"},{"id":"acfa08e0-9c7b-4ffb-a0fc-b31830704c89","title":"Should You Move to Fort Myers, Florida Now?","slug":"move-to-fort-myers-florida","excerpt":"Thinking about a move to Fort Myers Florida? Get a candid look at costs, neighborhoods, weather, insurance, and the lifestyle before you buy a home here.","content":null,"date":"November 10, 2026","isoDate":"2026-11-10T01:53:41.878+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/eff10bda-1060-4775-8ec2-99806024680b.webp"},{"id":"7c70d121-5c02-4def-b6f6-b8b91bc65ec4","title":"Property Search That Finds the Right Florida Home","slug":"property-search-right-florida-home","excerpt":"A smarter property search for Southwest Florida buyers: narrow the right homes, verify key details, and act confidently when the fit is real for your move.","content":null,"date":"November 8, 2026","isoDate":"2026-11-08T01:52:29.706+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/66ef156e-4dbb-47f5-8095-85f6a78ba9fe.webp"},{"id":"aa06b997-37bb-44f5-ac5a-b9e6847d433e","title":"Home Valuation: What Florida Sellers Need to Know","slug":"home-valuation-florida-sellers","excerpt":"A home valuation explains what buyers may pay now, how Florida-specific costs affect price, and how to prepare a Fort Myers or Cape Coral sale smartly.","content":null,"date":"November 6, 2026","isoDate":"2026-11-06T01:52:28.551+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/c61d85fe-639e-4731-bfcb-de7cb5616bf7.webp"},{"id":"a5d809a1-2753-4842-9118-a5352fcf60e8","title":"Homes for Sale in Southwest Florida That Fit You","slug":"homes-for-sale-southwest-florida","excerpt":"Browse homes for sale in Southwest Florida with a clear plan for location, costs, insurance, inspections, and the lifestyle you actually want to live.","content":null,"date":"November 4, 2026","isoDate":"2026-11-04T01:21:05.326+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/6490a44b-94ed-4d22-990c-bd660549438c.webp"},{"id":"8f3ff1ee-ca20-4597-9735-586a1d80b9a3","title":"What Buyers Miss in Cape Coral Florida Real Estate","slug":"cape-coral-florida-real-estate-buyers-guide","excerpt":"Cape Coral Florida real estate offers canals, pools, and space, but smart buyers also weigh flood zones, insurance, bridges, utilities, and commute.","content":null,"date":"November 3, 2026","isoDate":"2026-11-03T01:21:12.611+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/333e9320-ee92-4342-b4be-c0f9043bd015.webp"},{"id":"b844e503-682c-40c4-8883-1c129cf8af9f","title":"Southwest Florida Housing Market Forecast","slug":"southwest-florida-housing-market-forecast","excerpt":"Our Southwest Florida housing market forecast explains what buyers and sellers should watch in Fort Myers, Cape Coral, and nearby communities this year.","content":null,"date":"November 2, 2026","isoDate":"2026-11-02T01:21:35.885+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/cd777628-4496-42a8-ab00-f7657eeb8152.webp"},{"id":"788a8aa7-e0c5-4f7f-b3da-242087aeb7d7","title":"Buying a Home From Another State the Smart Way","slug":"buying-a-home-from-another-state","excerpt":"Buying a home from another state? Get practical Southwest Florida advice on tours, inspections, insurance, timing, and building the right local first team.","content":null,"date":"November 1, 2026","isoDate":"2026-11-01T01:21:50.748+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/b999b652-27c7-4f44-bc5b-4595d7d37f6e.webp"},{"id":"c36b170a-ab19-486b-9d36-42468b8b26fc","title":"Florida Homestead Exemption Buyers Need to Know","slug":"florida-homestead-exemption-buyers","excerpt":"Florida homestead exemption buyers can lower future property taxes, but timing, portability, and reassessment make the details matter before closing date.","content":null,"date":"October 31, 2026","isoDate":"2026-10-31T03:33:12.905+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/f556d902-fff1-4b1b-98b1-ce5393fd7f19.webp"},{"id":"80ea6dfe-1dce-4307-81a1-23c07185f0e9","title":"Fort Myers 55 Plus Communities: What to Know","slug":"fort-myers-55-plus-communities","excerpt":"Compare Fort Myers 55 plus communities with advice on costs, HOA rules, amenities, storm risk, and choosing a Florida home that fits your next chapter.","content":null,"date":"October 30, 2026","isoDate":"2026-10-30T03:40:22.301+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/230e4f52-6984-4311-b64d-c60f16bcb9eb.webp"},{"id":"6c16c1dc-91ae-4d14-b652-aefcbb27b944","title":"Best Fort Myers Family Neighborhoods to Consider","slug":"best-fort-myers-family-neighborhoods","excerpt":"Compare the best Fort Myers family neighborhoods for schools, commutes, amenities, costs, and Southwest Florida realities before you make a move today.","content":null,"date":"October 29, 2026","isoDate":"2026-10-29T03:43:40.236+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/4e77d1a7-ae89-42bd-8241-c143076b6deb.webp"},{"id":"eb5c980d-2de7-4bfb-8301-f601cb9b4396","title":"What Fort Myers Cost of Living Really Costs","slug":"fort-myers-cost-of-living","excerpt":"See what Fort Myers cost of living looks like for housing, insurance, utilities, transportation, and everyday life before you make a move to Florida.","content":null,"date":"October 28, 2026","isoDate":"2026-10-28T03:43:53.055+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/849ce769-1db9-4eeb-b9ed-db1b865d56a2.webp"},{"id":"31badaee-fe54-4ca5-94f0-337910b53940","title":"How to Prepare a House for Sale in Florida","slug":"prepare-house-for-sale-florida","excerpt":"Learn how to prepare house for sale Florida buyers will notice, from storm readiness and curb appeal to pricing, inspections, and showing strategy now.","content":null,"date":"October 27, 2026","isoDate":"2026-10-27T03:43:27.561+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/207b82a1-3164-4c07-bd30-5603bc1e53c0.webp"},{"id":"332c02e9-4d19-479d-aad0-ca5153406807","title":"Florida Seller Closing Costs: What to Budget","slug":"florida-seller-closing-costs","excerpt":"Florida seller closing costs can run higher than expected. See what sellers commonly pay, what is negotiable, and how to plan your net proceeds carefully.","content":null,"date":"October 26, 2026","isoDate":"2026-10-26T03:43:27.174+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/b5eafddc-51d0-4a7f-80d6-9405dc4f1263.webp"},{"id":"24a37b3e-95f9-4f4e-abf5-eb29e41b7ed0","title":"How to Price My Fort Myers Home for a Sale","slug":"price-my-fort-myers-home","excerpt":"Ready to price my Fort Myers home? See what buyers compare, how insurance and condition affect value, and how to set a smart asking price with confidence.","content":null,"date":"October 25, 2026","isoDate":"2026-10-25T03:40:32.351+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/c2e690a5-cfc6-4dc5-b597-bb892b78b518.webp"},{"id":"549f2370-8378-4156-8b5b-24b131fbe8b9","title":"Your Fort Myers Home Value Estimate, Explained","slug":"fort-myers-home-value-estimate","excerpt":"Get a clearer Fort Myers home value estimate by weighing condition, waterfront access, insurance, timing, and current neighborhood sales before you price.","content":null,"date":"October 24, 2026","isoDate":"2026-10-24T03:51:07.324+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/ec418c92-b605-4a05-95ef-7b0fd08e0119.webp"},{"id":"7ee0a0e5-5c3f-43f9-b50b-69ff7c4a3192","title":"Florida Waterfront Home Insurance: What to Budget","slug":"florida-waterfront-home-insurance-what-to-budget","excerpt":"Florida waterfront home insurance affects the real cost of a coastal property. See what drives premiums, inspections, deductibles, and buyer choices today.","content":null,"date":"October 23, 2026","isoDate":"2026-10-23T03:42:59.17+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/9b4cdee8-1508-4ff0-aa7d-2eb684b99e74.webp"},{"id":"79c1aed7-1ad6-4961-b293-00931326f790","title":"How to Read a Cape Coral Flood Zone Map","slug":"cape-coral-flood-zone-map","excerpt":"Use a Cape Coral flood zone map to compare homes, ask better insurance questions, and understand what a property's designation can - and cannot - tell you.","content":null,"date":"October 22, 2026","isoDate":"2026-10-22T03:43:26.702+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/7275a61e-2535-4818-aec6-81bf3e43e4d6.webp"},{"id":"6d8cf39d-9dec-4a43-804f-0a4dea8fcfe5","title":"What to Check in Fort Myers Pool Homes Before You Buy","slug":"fort-myers-pool-homes-what-to-check-before-buying","excerpt":"Thinking about Fort Myers pool homes? Learn what to inspect, budget for, and compare before you buy, from pool age to insurance and outdoor living costs.","content":null,"date":"October 21, 2026","isoDate":"2026-10-21T03:43:23.808+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/d8ad2154-3aaa-42ed-87a0-8dee1827b8ec.webp"},{"id":"49180e3a-16ea-42f1-8a15-45a4e556250c","title":"Cape Coral Golf Course Homes: What Buyers Should Know","slug":"cape-coral-golf-course-homes","excerpt":"Cape Coral golf course homes pair fairway views with a Florida lifestyle. Learn the costs, community rules, risks, and questions to ask before buying here.","content":null,"date":"October 20, 2026","isoDate":"2026-10-20T03:51:05.257+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/45d4d371-0c2b-4ab3-b818-144e15d48537.webp"},{"id":"1b1c8ccc-b855-447f-a215-3e0b5a7bee91","title":"What to Check in Fort Myers Waterfront Condos for Sale","slug":"fort-myers-waterfront-condos-for-sale","excerpt":"Find Fort Myers waterfront condos for sale with a clear view of costs, water access, rules, insurance, storm history, and the lifestyle that fits you want.","content":null,"date":"October 19, 2026","isoDate":"2026-10-19T03:51:22.18+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/workflows/b6ac7d55-4a23-44ef-8bee-3ee237ccad6b.webp"},{"id":"cfaa6935-705d-481b-98d8-b6d1796b70b5","title":"Cape Coral Waterfront Homes for Sale Explained","slug":"cape-coral-waterfront-homes-for-sale","excerpt":"Browse Cape Coral waterfront homes for sale with clear guidance on canals, boating access, insurance, seawalls, and the costs that shape a smart purchase.","content":null,"date":"October 18, 2026","isoDate":"2026-10-18T03:52:46.093+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/37b99174-e476-48de-8209-e4a3030fa816/cfaa6935-705d-481b-98d8-b6d1796b70b5.webp"},{"id":"714dd30b-1ff1-4d7e-b8ae-812a1011f2b0","title":"Fort Myers Relocation Guide for a Smarter Move","slug":"fort-myers-relocation-guide","excerpt":"Use this Fort Myers relocation guide to compare neighborhoods, budget for Florida ownership, assess flood risk, and plan a move that fits your new life.","content":null,"date":"October 17, 2026","isoDate":"2026-10-17T18:20:20.76+00:00","image":"https://afocirmbqdxnkyescnev.supabase.co/storage/v1/object/public/featured-images/7bf40bb9-7d39-4a74-bb8d-ffcccffbcdf1/714dd30b-1ff1-4d7e-b8ae-812a1011f2b0.webp"}];
  var SORO_TOKEN = '7a4df267-d8b4-46bd-88d1-0cb55c4721d8';
  var SORO_API_BASE = 'https://app.trysoro.com';
  var SORO_T = {"allArticles":"All Articles","backToAll":"Back to all articles","loading":"Loading article...","error":"Failed to load article. Please try again.","empty":"Published articles may take up to 60 minutes to appear here.","blogArticles":"Blog articles","pagination":"Pagination","previousPage":"Previous page","nextPage":"Next page","page":"Page {n}"};
  
  // Content cache (loaded on demand)
  var contentCache = {};
  
  // Pre-populate cache with any server-included content (for SEO deep links)
  SORO_ARTICLES.forEach(function(article) {
    if (article.content) {
      contentCache[article.id] = article.content;
    }
  });
  
  // Find the container
  var container = document.getElementById('soro-blog');
  if (!container) {
    console.error('Soro Blog: No element with id="soro-blog" found');
    return;
  }
  
  // Save the original page title so we can restore it
  var originalTitle = document.title;
  var originalDescription = '';
  var descMeta = document.querySelector('meta[name="description"]');
  if (descMeta) originalDescription = descMeta.getAttribute('content') || '';
  
  // Detect if running inside a srcdoc iframe (website builders like GoDaddy, Wix, etc.)
  var isSrcdocIframe = false;
  var parentBaseUrl = null;
  try {
    isSrcdocIframe = window.location.href === 'about:srcdoc' || 
                     window.location.pathname === '/srcdoc' ||
                     (window.self !== window.top && window.location.origin === 'null');
  } catch(e) {
    isSrcdocIframe = true; // cross-origin means we're in an iframe
  }
  
  // Try to get the parent page URL for building article links
  if (isSrcdocIframe) {
    try {
      var pUrl = new URL(window.parent.location.href);
      pUrl.searchParams.delete('post');
      parentBaseUrl = pUrl.origin + pUrl.pathname + pUrl.search;
    } catch(e) {
      parentBaseUrl = null;
    }
  }
  
  // Detect deep-linked article from URL query param: ?post=slug
  function getRequestedSlug() {
    try {
      if (isSrcdocIframe) {
        // In srcdoc iframe, check parent URL if accessible
        try {
          var params = new URLSearchParams(window.parent.location.search);
          return params.get('post') || null;
        } catch(e) {
          return null;
        }
      }
      var params = new URLSearchParams(window.location.search);
      return params.get('post') || null;
    } catch(e) {
      return null;
    }
  }
  
  // Build article URL with query param (preserves existing params)
  function getArticleUrl(slug) {
    try {
      if (isSrcdocIframe && parentBaseUrl) {
        // Build full parent page URL with ?post= param so new tab works
        var sep = parentBaseUrl.indexOf('?') !== -1 ? '&' : '?';
        return parentBaseUrl + sep + 'post=' + encodeURIComponent(slug);
      }
      if (isSrcdocIframe) {
        return '#post=' + encodeURIComponent(slug);
      }
      var url = new URL(window.location.href);
      url.searchParams.set('post', slug);
      return url.pathname + url.search;
    } catch(e) {
      return '#post=' + encodeURIComponent(slug);
    }
  }
  
  // Get the base list URL (current page without post param)
  function getListUrl() {
    try {
      if (isSrcdocIframe && parentBaseUrl) {
        return parentBaseUrl;
      }
      if (isSrcdocIframe) {
        return '#';
      }
      var url = new URL(window.location.href);
      url.searchParams.delete('post');
      var search = url.search;
      return url.pathname + (search ? search : '');
    } catch(e) {
      return window.location.pathname;
    }
  }
  
  // Safe pushState wrapper (fails silently in srcdoc iframes)
  function safePushState(state, title, url) {
    if (isSrcdocIframe) return;
    try {
      history.pushState(state, title, url);
    } catch(e) {
      // pushState not available (srcdoc iframe, cross-origin, etc.)
    }
  }
  
  // Update page meta tags for SEO (title, description, canonical, JSON-LD)
  // Skip in srcdoc iframes since we can't meaningfully update the parent page
  function updatePageMeta(article) {
    if (isSrcdocIframe) return;
    if (article) {
      // Article view: set article-specific meta
      document.title = article.title + ' | ' + SORO_BLOG_TITLE;
      
      var desc = document.querySelector('meta[name="description"]');
      if (!desc) {
        desc = document.createElement('meta');
        desc.setAttribute('name', 'description');
        document.head.appendChild(desc);
      }
      desc.setAttribute('content', article.excerpt);
      
      // Set canonical URL to the article deep link
      var canonical = document.querySelector('link[rel="canonical"][data-soro]');
      if (!canonical) {
        canonical = document.createElement('link');
        canonical.setAttribute('rel', 'canonical');
        canonical.setAttribute('data-soro', 'true');
        document.head.appendChild(canonical);
      }
      canonical.setAttribute('href', window.location.href);
      
      // JSON-LD: single BlogPosting
      injectJsonLd({
        '@context': 'https://schema.org',
        '@type': 'BlogPosting',
        'headline': article.title,
        'description': article.excerpt,
        'datePublished': article.isoDate,
        'image': article.image || undefined,
        'url': window.location.href
      });
    } else {
      // List view: restore original meta
      document.title = originalTitle;
      
      var desc = document.querySelector('meta[name="description"]');
      if (desc && originalDescription) {
        desc.setAttribute('content', originalDescription);
      }
      
      // Remove soro canonical
      var canonical = document.querySelector('link[rel="canonical"][data-soro]');
      if (canonical) canonical.remove();
      
      // JSON-LD: Blog with all articles
      var blogPosting = SORO_ARTICLES.map(function(a) {
        var item = {
          '@type': 'BlogPosting',
          'headline': a.title,
          'description': a.excerpt,
          'datePublished': a.isoDate,
          'url': window.location.origin + getArticleUrl(a.slug)
        };
        if (a.image) item.image = a.image;
        return item;
      });
      
      injectJsonLd({
        '@context': 'https://schema.org',
        '@type': 'Blog',
        'name': SORO_BLOG_TITLE,
        'blogPost': blogPosting
      });
    }
  }
  
  // Inject styles
  var styleId = 'soro-blog-styles-light';
  if (!document.getElementById(styleId)) {
    var style = document.createElement('style');
    style.id = styleId;
    style.textContent = `
      .soro-blog {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
        max-width: 800px;
        margin: 0 auto;
        color: #1a1a1a;
        background: transparent;
      }
      .soro-blog * {
        box-sizing: border-box;
      }
      .soro-blog a {
        text-decoration: none;
        color: inherit;
      }
      .soro-blog-header {
        display: none;
        align-items: center;
        margin-bottom: 16px;
      }
      .soro-blog-back {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        background: transparent;
        border: 1px solid #e5e5e5;
        color: #666;
        cursor: pointer;
        font-size: 14px;
        padding: 8px 16px;
        border-radius: 6px;
        transition: background 0.2s, border-color 0.2s;
        text-decoration: none;
      }
      .soro-blog-back:hover {
        background: #f5f5f5;
        border-color: #d0d0d0;
      }
      .soro-blog-list {
        display: flex;
        flex-direction: column;
        gap: 24px;
      }
      .soro-blog-card {
        display: flex;
        gap: 20px;
        padding: 20px;
        background: transparent;
        border: 1px solid #e5e5e5;
        border-radius: 12px;
        cursor: pointer;
        transition: box-shadow 0.2s, border-color 0.2s;
        text-decoration: none;
        color: inherit;
      }
      .soro-blog-card:hover {
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        border-color: #d0d0d0;
      }
      .soro-blog-card-image {
        width: 140px;
        height: 100px;
        object-fit: cover;
        border-radius: 8px;
        flex-shrink: 0;
      }
      .soro-blog-card-content {
        flex: 1;
        min-width: 0;
      }
      .soro-blog-card-title {
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 8px 0;
        line-height: 1.3;
        color: #1a1a1a;
      }
      h2.soro-blog-card-title {
        font-size: 18px;
      }
      .soro-blog-card-excerpt {
        font-size: 14px;
        color: #666;
        margin: 0 0 12px 0;
        line-height: 1.5;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
      .soro-blog-card-date {
        font-size: 12px;
        color: #999;
      }
      .soro-blog-article {
        display: none;
      }
      .soro-blog-article.visible {
        display: block;
      }
      .soro-blog-article-title {
        font-size: 32px;
        font-weight: 700;
        margin: 0 0 12px 0;
        line-height: 1.2;
        color: #1a1a1a;
      }
      .soro-blog-article-date {
        font-size: 14px;
        color: #666;
        margin-bottom: 24px;
      }
      .soro-blog-article-image {
        width: 100%;
        max-height: 400px;
        object-fit: cover;
        border-radius: 12px;
        margin-bottom: 24px;
      }
      .soro-blog-article-content {
        font-size: 16px;
        line-height: 1.7;
        color: #1a1a1a;
      }
      .soro-blog-article-content h1,
      .soro-blog-article-content h2,
      .soro-blog-article-content h3 {
        margin-top: 32px;
        margin-bottom: 16px;
        line-height: 1.3;
        color: #1a1a1a;
      }
      .soro-blog-article-content h2 {
        font-size: 24px;
      }
      .soro-blog-article-content h3 {
        font-size: 20px;
      }
      .soro-blog-article-content p {
        margin: 0 0 16px 0;
      }
      .soro-blog-article-content ul,
      .soro-blog-article-content ol {
        margin: 0 0 16px 0;
        padding-left: 24px;
        padding-right: 0;
      }
      .soro-blog-article-content li {
        margin-bottom: 8px;
      }
      .soro-blog-article-content a {
        color: #0066cc;
      }
      .soro-blog-article-content img {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
      }
      .soro-blog-empty {
        text-align: center;
        padding: 48px 24px;
        color: #666;
      }
      .soro-blog-loading {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 48px 24px;
        color: #666;
      }
      .soro-blog-spinner {
        width: 24px;
        height: 24px;
        border: 2px solid #e5e5e5;
        border-top-color: #1a1a1a;
        border-radius: 50%;
        animation: soro-spin 0.8s linear infinite;
        margin-right: 12px;
      }
      @keyframes soro-spin {
        to { transform: rotate(360deg); }
      }
      .soro-blog-error {
        text-align: center;
        padding: 48px 24px;
        color: #dc2626;
      }
      @media (max-width: 600px) {
        .soro-blog-card {
          flex-direction: column;
          gap: 12px;
        }
        .soro-blog-card-image {
          width: 100%;
          height: 180px;
        }
        .soro-blog-article-title {
          font-size: 24px;
        }
      }
    `;
    document.head.appendChild(style);
  }
  
  // Inject or update JSON-LD structured data
  function injectJsonLd(data) {
    var jsonLdId = 'soro-blog-jsonld';
    var existing = document.getElementById(jsonLdId);
    if (existing) existing.remove();
    
    var script = document.createElement('script');
    script.id = jsonLdId;
    script.type = 'application/ld+json';
    script.textContent = JSON.stringify(data);
    document.head.appendChild(script);
  }
  
  // State
  var currentView = 'list';
  var currentArticle = null;
  var isLoading = false;
  
  // Fetch article content on demand
  function fetchArticleContent(articleId, callback) {
    // Check cache first (includes server-pre-rendered content for deep links)
    if (contentCache[articleId]) {
      callback(null, contentCache[articleId]);
      return;
    }
    
    var url = SORO_API_BASE + '/api/embed/' + SORO_TOKEN + '/article/' + articleId;
    
    fetch(url)
      .then(function(response) {
        if (!response.ok) throw new Error('Failed to load article');
        return response.json();
      })
      .then(function(data) {
        contentCache[articleId] = data.content;
        callback(null, data.content);
      })
      .catch(function(error) {
        callback(error, null);
      });
  }
  
  // Render article list — cards are real <a> links for SEO crawlability
  function renderList() {
    if (SORO_ARTICLES.length === 0) {
      return '<div class="soro-blog-empty"><p>' + SORO_T.empty + '</p></div>';
    }
    
    var html = '<section class="soro-blog-list" role="feed" aria-label="' + SORO_T.blogArticles + '">';
    SORO_ARTICLES.forEach(function(article) {
      var articleUrl = getArticleUrl(article.slug);
      var targetAttr = isSrcdocIframe ? ' target="_blank" rel="noopener"' : '';
      html += '<a href="' + articleUrl + '"' + targetAttr + ' class="soro-blog-card" data-slug="' + escapeHtml(article.slug) + '" itemscope itemtype="https://schema.org/BlogPosting">';
      if (article.image) {
        html += '<img class="soro-blog-card-image" src="' + article.image + '" alt="' + escapeHtml(article.title) + '" loading="lazy" itemprop="image">';
      }
      html += '<div class="soro-blog-card-content">';
      html += '<h2 class="soro-blog-card-title" itemprop="headline">' + escapeHtml(article.title) + '</h2>';
      html += '<p class="soro-blog-card-excerpt" itemprop="description">' + escapeHtml(article.excerpt) + '</p>';
      html += '<time class="soro-blog-card-date" datetime="' + article.isoDate + '" itemprop="datePublished">' + article.date + '</time>';
      html += '</div></a>';
    });
    html += '</section>';
    return html;
  }
  
  function renderArticle(article, content) {
    var html = '<article class="soro-blog-article visible" itemscope itemtype="https://schema.org/BlogPosting">';
    html += '<header>';
    html += '<h1 class="soro-blog-article-title" itemprop="headline">' + escapeHtml(article.title) + '</h1>';
    html += '<time class="soro-blog-article-date" datetime="' + article.isoDate + '" itemprop="datePublished">' + article.date + '</time>';
    html += '</header>';
    if (article.image) {
      html += '<img class="soro-blog-article-image" src="' + article.image + '" alt="' + escapeHtml(article.title) + '" itemprop="image">';
    }
    html += '<div class="soro-blog-article-content" itemprop="articleBody">' + content + '</div>';
    html += '</article>';
    return html;
  }
  
  function renderLoading() {
    return '<div class="soro-blog-loading"><div class="soro-blog-spinner"></div>' + SORO_T.loading + '</div>';
  }
  
  function renderError() {
    return '<div class="soro-blog-error"><p>' + SORO_T.error + '</p></div>';
  }
  
  function escapeHtml(str) {
    var div = document.createElement('div');
    div.textContent = str;
    return div.innerHTML;
  }
  
  // Make all links inside article content open in a new tab
  // This is critical for embeds running on external sites or inside iframes
  function processContentLinks(parentEl) {
    var links = parentEl.querySelectorAll('.soro-blog-article-content a');
    for (var i = 0; i < links.length; i++) {
      links[i].setAttribute('target', '_blank');
      links[i].setAttribute('rel', 'noopener noreferrer');
    }
  }
  
  // Navigate to article view (updates URL without full reload)
  function showArticle(slug) {
    var article = null;
    for (var i = 0; i < SORO_ARTICLES.length; i++) {
      if (SORO_ARTICLES[i].slug === slug) {
        article = SORO_ARTICLES[i];
        break;
      }
    }
    if (!article) {
      // Unknown slug (deleted or unpublished article) — show the list instead of a blank widget
      showList();
      return;
    }

    currentArticle = article;
    currentView = 'article';
    
    // Update URL (pushState so back button works)
    var articleUrl = getArticleUrl(slug);
    if (!isSrcdocIframe && window.location.pathname + window.location.search !== articleUrl) {
      safePushState({ post: slug }, '', articleUrl);
    }
    
    // Update page meta for SEO
    updatePageMeta(article);
    
    var header = container.querySelector('.soro-blog-header');
    var content = container.querySelector('.soro-blog-content');
    header.style.display = 'flex';
    
    // Check if content is already available (pre-rendered or cached)
    if (contentCache[article.id]) {
      content.innerHTML = renderArticle(article, contentCache[article.id]);
      processContentLinks(content);
    } else {
      // Show loading, then fetch
      isLoading = true;
      content.innerHTML = renderLoading();
      
      fetchArticleContent(article.id, function(error, articleContent) {
        isLoading = false;
        if (error) {
          content.innerHTML = renderError();
        } else {
          content.innerHTML = renderArticle(article, articleContent);
          processContentLinks(content);
        }
      });
    }
    
    container.scrollIntoView({ behavior: 'smooth', block: 'start' });
  }
  
  // Navigate to list view
  function showList() {
    currentView = 'list';
    currentArticle = null;
    isLoading = false;
    
    // Update URL
    var listUrl = getListUrl();
    if (!isSrcdocIframe && window.location.pathname + window.location.search !== listUrl) {
      safePushState({ post: null }, '', listUrl);
    }
    
    // Restore page meta
    updatePageMeta(null);
    
    var header = container.querySelector('.soro-blog-header');
    var content = container.querySelector('.soro-blog-content');
    header.style.display = 'none';
    content.innerHTML = renderList();
    
    // Intercept card link clicks
    var cards = content.querySelectorAll('.soro-blog-card');
    cards.forEach(function(card) {
      card.addEventListener('click', function(e) {
        e.preventDefault();
        var slug = card.getAttribute('data-slug');
        if (isSrcdocIframe) {
          // In srcdoc iframe, open article in a new tab with real URL
          var url = getArticleUrl(slug);
          window.open(url, '_blank');
        } else {
          showArticle(slug);
        }
      });
    });
  }
  
  // Initial render
  var backArrow = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>';
  container.innerHTML = '<div class="soro-blog">' +
    '<div class="soro-blog-header" style="display: none;">' +
      '<a href="' + getListUrl() + '" class="soro-blog-back" aria-label="' + SORO_T.backToAll + '">' +
        backArrow +
        SORO_T.allArticles +
      '</a>' +
    '</div>' +
    '<div class="soro-blog-content"></div>' +
  '</div>';
  var root = container.querySelector('.soro-blog');

  // Handle browser back/forward buttons (not applicable in srcdoc iframes).
  // A single-page site can remove the widget without a reload and add it again later, running
  // this script anew. A widget no longer on the page stops listening, so it neither fails on its
  // emptied element nor changes the title of the page the visitor is on.
  if (!isSrcdocIframe) {
    window.addEventListener('popstate', function onPopState() {
      if (!root.isConnected) {
        window.removeEventListener('popstate', onPopState);
        return;
      }
      var slug = getRequestedSlug();
      if (slug) {
        showArticle(slug);
      } else {
        showList();
      }
    });
  }

  // Add back button handler (intercept for SPA navigation)
  container.querySelector('.soro-blog-back').addEventListener('click', function(e) {
    e.preventDefault();
    showList();
  });
  
  // Check if URL has a deep-linked article on initial load
  var initialSlug = getRequestedSlug();
  if (initialSlug) {
    showArticle(initialSlug);
  } else {
    showList();
  }
})();