<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Roost</title>
    <meta name="description" content="Roost — the messaging app where your birds travel in real-time based on distance.">
    <meta property="og:title" content="Roost">
    <meta property="og:description" content="Open this profile in Roost.">
    <meta property="og:type" content="profile">
    <link rel="stylesheet" href="/styles.css?v=3">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <script>
        var APP_STORE_URL = "https://apps.apple.com/us/app/roost-social/id6746680855";
        var PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=com.rookery.courier";
        var REDIRECT_SECONDS = 1;

        // Pick the destination store for this device.
        //   Android            -> Google Play
        //   iOS (incl. iPadOS) -> App Store   (UNCHANGED from before)
        //   desktop / unknown  -> null        (no forced redirect; show both buttons)
        // iPadOS 13+ Safari reports as "MacIntel" with no "iPad" token in the UA, so it
        // is caught by the platform + maxTouchPoints clause rather than the regex.
        var ua = navigator.userAgent || "";
        var isAndroid = /Android/i.test(ua);
        var isIOS = /iPhone|iPad|iPod/i.test(ua) ||
                    (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
        var STORE_URL = isAndroid ? PLAY_STORE_URL : (isIOS ? APP_STORE_URL : null);
        window.__STORE_URL__ = STORE_URL;

        // Detect whether this 404 response is for a /profile/<username> URL. If so, we
        // switch this page into "Universal Links fallback" mode: personalize <title>,
        // emit a <meta http-equiv="refresh"> so users without the app land in the right
        // app store, and expose a visible fallback link in the body.
        var profileMatch = window.location.pathname.match(/^\/profile\/([^\/]+)\/?$/);
        var profileUsername = profileMatch ? decodeURIComponent(profileMatch[1]) : "";
        window.__IS_PROFILE_FALLBACK__ = !!profileUsername;
        window.__PROFILE_USERNAME__ = profileUsername;

        if (profileUsername) {
            document.title = "@" + profileUsername + " on Roost";
            if (STORE_URL) {
                document.write(
                    '<meta http-equiv="refresh" content="' +
                    REDIRECT_SECONDS + ';url=' + STORE_URL + '">'
                );
            }
            var og = document.querySelector('meta[property="og:title"]');
            if (og) og.setAttribute("content", "@" + profileUsername + " on Roost");
        }

        // Same idea for /invite/<6-char-alnum> referral-code URLs.
        var inviteMatch = window.location.pathname.match(/^\/invite\/([A-Za-z0-9]{6})\/?$/);
        var inviteCode = inviteMatch ? inviteMatch[1].toUpperCase() : "";
        window.__IS_INVITE_FALLBACK__ = !!inviteCode;
        window.__INVITE_CODE__ = inviteCode;

        if (inviteCode && !profileUsername) {
            document.title = "You're invited to Roost";
            if (STORE_URL) {
                document.write(
                    '<meta http-equiv="refresh" content="' +
                    REDIRECT_SECONDS + ';url=' + STORE_URL + '">'
                );
            }
            var ogi = document.querySelector('meta[property="og:title"]');
            if (ogi) ogi.setAttribute("content", "You're invited to Roost");
            var ogd = document.querySelector('meta[property="og:description"]');
            if (ogd) ogd.setAttribute("content", "Join Roost with code " + inviteCode + ".");
        }
    </script>
</head>
<body>
    <header>
        <nav class="navbar">
            <div class="nav-container">
                <div class="nav-logo">
                    <h1><a href="/" style="color:inherit;text-decoration:none;">Roost</a></h1>
                </div>
                <div class="nav-links">
                    <a href="/privacy">Privacy Policy</a>
                    <a href="/terms">Terms of Use</a>
                    <a href="/support">Support</a>
                    <a href="/faq">FAQ</a>
                </div>
            </div>
        </nav>
    </header>

    <main class="main-content">
        <div class="container">
            <div class="hero-section">
                <div class="content-wrapper">
                    <div class="text-content" id="profile-view" style="display:none;">
                        <h1 class="hero-title">Opening <span class="brand-highlight">Roost</span>…</h1>
                        <p class="hero-subtitle" id="profile-subtitle">Taking you to the App Store to get Roost.</p>
                        <p class="hero-subtitle" id="profile-store-links"></p>
                    </div>
                    <div class="text-content" id="invite-view" style="display:none;">
                        <h1 class="hero-title">You're invited to <span class="brand-highlight">Roost</span></h1>
                        <p class="hero-subtitle">Use this code in the app:</p>
                        <p class="hero-subtitle"><strong id="invite-code-display" style="font-size:1.5em;letter-spacing:0.1em;">CODE</strong></p>
                        <p class="hero-subtitle" id="invite-subtitle">Taking you to the App Store to get Roost.</p>
                        <p class="hero-subtitle" id="invite-store-links"></p>
                    </div>
                    <div class="text-content" id="notfound-view">
                        <h1 class="hero-title">Page not found</h1>
                        <p class="hero-subtitle">We couldn't find the page you were looking for.</p>
                        <p class="hero-subtitle"><a href="/">Back to roostsocial.app</a></p>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <footer class="footer">
        <div class="container">
            <div class="footer-content">
                <p>&copy; 2026 Good Egg LLC. All rights reserved.</p>
                <div class="footer-links">
                    <a href="/privacy">Privacy Policy</a>
                    <a href="/terms">Terms of Use</a>
                    <a href="/support">Support</a>
                    <a href="/faq">FAQ</a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        (function () {
            var store = window.__STORE_URL__;
            var onAndroid = store === PLAY_STORE_URL;
            var onIOS = store === APP_STORE_URL;
            // Human name for the single-store mobile case ("the App Store" / "Google Play").
            var storeName = onAndroid ? "Google Play" : "the App Store";

            // Returns the call-to-action markup for a fallback view:
            //   mobile  -> one text link to that platform's store (matches prior behavior)
            //   desktop -> both store badges, since there is no forced redirect
            function storeLinksHtml() {
                if (onIOS) {
                    return '<a href="' + APP_STORE_URL + '">Get Roost on the App Store</a>';
                }
                if (onAndroid) {
                    return '<a href="' + PLAY_STORE_URL + '">Get Roost on Google Play</a>';
                }
                return '<a class="app-store-badge" href="' + APP_STORE_URL + '" target="_blank" rel="noopener" aria-label="Download Roost on the App Store"><img src="/app-store-badge.svg" alt="Download on the App Store" style="height:48px;" /></a>' +
                       ' <a class="google-play-badge" href="' + PLAY_STORE_URL + '" target="_blank" rel="noopener" aria-label="Get Roost on Google Play"><img src="/GetItOnGooglePlay_Badge_Web_color_English.svg" alt="Get it on Google Play" style="height:48px;" /></a>';
            }

            if (window.__IS_PROFILE_FALLBACK__) {
                var profile = document.getElementById("profile-view");
                var notfound = document.getElementById("notfound-view");
                if (profile) profile.style.display = "";
                if (notfound) notfound.style.display = "none";

                var sub = document.getElementById("profile-subtitle");
                if (sub) sub.textContent = store
                    ? "@" + window.__PROFILE_USERNAME__ + " — opening Roost, or taking you to " + storeName + "."
                    : "@" + window.__PROFILE_USERNAME__ + " — get Roost to view this profile.";

                var links = document.getElementById("profile-store-links");
                if (links) links.innerHTML = storeLinksHtml();
            } else if (window.__IS_INVITE_FALLBACK__) {
                var invite = document.getElementById("invite-view");
                var notfoundI = document.getElementById("notfound-view");
                if (invite) invite.style.display = "";
                if (notfoundI) notfoundI.style.display = "none";

                var disp = document.getElementById("invite-code-display");
                if (disp) disp.textContent = window.__INVITE_CODE__;

                var subI = document.getElementById("invite-subtitle");
                if (subI) subI.textContent = store
                    ? "Taking you to " + storeName + " to get Roost."
                    : "Get Roost to join with this code.";

                var linksI = document.getElementById("invite-store-links");
                if (linksI) linksI.innerHTML = storeLinksHtml();
            }
        })();
    </script>
</body>
</html>

