        const state = {
            view: 'home',
            user: null,
            filter: 'All',
            listings: [
                { id: 1, title: "Glasshouse Pavillion", price: "$2,450,000", loc: "Vancouver, BC", type: "Sale", img: "https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=1200", desc: "A architectural statement of transparency and strength. This pavilion features self-tinting glass walls and a reclaimed cedar framework.", tags: ["Modern", "Ocean View", "3 Bed"] },
                { id: 2, title: "The Brutalist Penthouse", price: "$6,200/mo", loc: "Berlin, DE", type: "Rent", img: "https://images.unsplash.com/photo-1512917774080-9991f1c4c750?auto=format&fit=crop&w=1200", desc: "Raw concrete aesthetics met with ultra-luxurious Italian marble. Located in the heart of Berlin's design district.", tags: ["Industrial", "City View", "2 Bed"] },
                { id: 3, title: "Serene Desert Courtyard", price: "$4,100,000", loc: "Joshua Tree, CA", type: "Sale", img: "https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?auto=format&fit=crop&w=1200", desc: "An inward-facing sanctuary designed for maximum privacy and astronomical observation.", tags: ["Minimalist", "Pool", "4 Bed"] },
                { id: 4, title: "Old World Revival Loft", price: "$1,850,000", loc: "Barcelona, ES", type: "Sale", img: "https://images.unsplash.com/photo-1600047509807-ba8f99d2cdde?auto=format&fit=crop&w=1200", desc: "Restored vaulted ceilings meet contemporary lighting systems in this Eixample district gem.", tags: ["Classic", "Historic", "2 Bed"] },
                { id: 5, title: "Zen Forest Retreat", price: "$950,000", loc: "Kyoto, JP", type: "Sale", img: "https://images.unsplash.com/photo-1494438639946-1ebd1d20bf85?auto=format&fit=crop&w=1200", desc: "Built using traditional Japanese carpentry methods without a single nail. Surrounded by bamboo groves.", tags: ["Organic", "Spa", "1 Bed"] },
                { id: 6, title: "The Horizon Estate", price: "$12,000,000", loc: "Malibu, CA", type: "Sale", img: "https://images.unsplash.com/photo-1513584684374-8bdb7489feef?auto=format&fit=crop&w=1200", desc: "A sprawling coastal estate with 200 feet of private beach access and a subterranean garage.", tags: ["Luxury", "Beachfront", "6 Bed"] }
            ]
        };

        // --- NAVIGATION ---
        function navigate(view, extra = null) {
            state.view = view;
            window.scrollTo({ top: 0, behavior: 'smooth' });
            render(extra);
        }

        function toggleMobileMenu() {
            const menu = document.getElementById('mobile-menu');
            menu.classList.toggle('translate-x-full');
        }

        function render(extra) {
            const app = document.getElementById('app');
            app.innerHTML = '';
            
            if (state.view === 'home') renderHome(app);
            else if (state.view === 'listings') renderListings(app);
            else if (state.view === 'services') renderServices(app);
            else if (state.view === 'inspiration') renderInspiration(app);
            else if (state.view === 'guidance') renderGuidance(app);
            else if (state.view === 'about') renderAbout(app);
            else if (state.view === 'legal') renderLegal(app, extra);

            updateAuthUI();
            lucide.createIcons();
            initReveal();
        }

        // --- PAGE RENDERING FUNCTIONS ---

        function renderHome(app) {
            app.innerHTML = `
                <!-- HERO -->
                <section class="relative h-[95vh] flex items-center px-6 overflow-hidden">
                    <img src="https://images.unsplash.com/photo-1600607687940-4e7a53697a69?auto=format&fit=crop&w=2400" class="absolute inset-0 w-full h-full object-cover grayscale-[10%] opacity-90 hero-zoom">
                    <div class="absolute inset-0 bg-gradient-to-r from-softWhite via-softWhite/30 to-transparent"></div>
                    <div class="max-w-[1400px] mx-auto w-full relative z-10">
                        <div class="max-w-3xl space-y-12 reveal active">
                            <div class="inline-flex items-center gap-3 px-6 py-2 bg-charcoal text-white rounded-full text-[9px] font-bold uppercase tracking-[0.4em]">
                                <span class="w-1.5 h-1.5 bg-sage rounded-full animate-pulse"></span> Now Touring: Vancouver 2026
                            </div>
                            <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-[0.85]">Find the <br> Right <span class="italic text-sage">Place.</span></h1>
                            <p class="text-xl md:text-2xl text-charcoal/60 leading-relaxed max-w-xl font-medium">thehomesdircet is a digital protection shield for your future lifestyle — clean, confident, and meticulously curated.</p>
                            <div class="flex flex-wrap gap-6 pt-6">
                                <button onclick="navigate('listings')" class="group bg-charcoal text-white px-12 py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px] hover:bg-sage transition-all flex items-center gap-4">
                                    Browse Properties <i data-lucide="chevron-right" class="w-4 transition-transform group-hover:translate-x-2"></i>
                                </button>
                                <button onclick="navigate('guidance')" class="bg-white text-charcoal px-12 py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px] shadow-2xl hover:bg-warmGrey transition-all">Get Market Advice</button>
                            </div>
                        </div>
                    </div>
                </section>

                <!-- STATS STRIP -->
                <section class="py-12 bg-warmGrey border-y border-black/5 px-6">
                    <div class="max-w-7xl mx-auto flex flex-wrap justify-between gap-12">
                        ${['1.4B Curated Listings', '24+ Countries Active', '98% Client Match', 'Top 10 Design Platform'].map(stat => `
                            <span class="text-[10px] font-bold uppercase tracking-[0.4em] text-charcoal/30">${stat}</span>
                        `).join('')}
                    </div>
                </section>

                <!-- CURATED SECTIONS -->
                <section class="py-40 px-6 max-w-[1400px] mx-auto">
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-12">
                        ${[
                            { t: 'The Collection', d: 'Hand-picked homes from across the globe.', icon: 'search', link: 'listings' },
                            { t: 'Interior Journal', d: 'Design trends for the high-end minimalist.', icon: 'feather', link: 'inspiration' },
                            { t: 'Bespoke Services', d: 'Maintenance and styling from experts.', icon: 'award', link: 'services' },
                            { t: 'Market Intel', d: 'The data behind the worlds best addresses.', icon: 'line-chart', link: 'guidance' }
                        ].map((item, i) => `
                            <div onclick="navigate('${item.link}')" class="group bg-warmGrey/40 p-12 rounded-[3rem] border border-black/5 hover:bg-white hover:shadow-2xl transition-all cursor-pointer reveal" style="transition-delay: ${i*100}ms">
                                <div class="w-16 h-16 bg-white rounded-2xl flex items-center justify-center text-sage mb-10 shadow-sm group-hover:scale-110 transition-transform"><i data-lucide="${item.icon}"></i></div>
                                <h3 class="font-bold text-lg mb-4 uppercase tracking-widest">${item.t}</h3>
                                <p class="text-charcoal/40 text-sm leading-relaxed">${item.d}</p>
                            </div>
                        `).join('')}
                    </div>
                </section>

                <!-- FEATURED HIGHLIGHTS (LONG) -->
                <section class="py-40 bg-white">
                    <div class="max-w-[1400px] mx-auto px-6 space-y-32">
                        <div class="flex flex-col md:flex-row justify-between items-end gap-10">
                            <div class="space-y-6">
                                <h2 class="font-serif text-7xl md:text-8xl tracking-tighter">The Weekly <br> Selection.</h2>
                                <p class="text-charcoal/40 font-medium italic text-xl">Our curators traveled to 12 cities to find these 4 masterpieces.</p>
                            </div>
                            <button onclick="navigate('listings')" class="group flex items-center gap-4 text-[11px] font-bold uppercase tracking-[0.4em] border-b-2 border-charcoal pb-2 hover:text-sage hover:border-sage transition-all">
                                See all listings <i data-lucide="arrow-right" class="w-4"></i>
                            </button>
                        </div>
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-12">
                            ${state.listings.slice(0, 4).map(l => renderListingCard(l)).join('')}
                        </div>
                    </div>
                </section>

                <!-- VISIONARY QUOTE -->
                <section class="py-60 px-6 text-center reveal">
                    <div class="max-w-5xl mx-auto space-y-12">
                        <span class="text-sage text-[10px] font-bold uppercase tracking-[1em]">Our Ethos</span>
                        <h2 class="font-classic text-5xl md:text-7xl italic leading-tight text-charcoal/80">"A home is not just an asset. It is the architectural manifestation of your internal philosophy."</h2>
                        <p class="text-[11px] font-bold uppercase tracking-[0.5em] text-charcoal/30">— The Design Committee, 2026</p>
                    </div>
                </section>

                <!-- HOW WE HELP (LONG) -->
                <section class="py-40 bg-charcoal text-white rounded-[5rem] mx-6">
                    <div class="max-w-7xl mx-auto px-6 md:px-20 grid grid-cols-1 lg:grid-cols-2 gap-32 items-center">
                        <div class="space-y-12 reveal">
                            <h2 class="font-serif text-7xl leading-[0.9]">A Digital <br> Shield.</h2>
                            <p class="text-white/40 text-xl font-light">We protect you from the noise of the standard market. Our vetting process ensures every listing is a genuine architectural masterpiece.</p>
                            <div class="space-y-10">
                                ${[
                                    { t: 'Visual Purity', d: 'High-quality interior imagery as standard.' },
                                    { t: 'Verified Specs', d: 'Every square foot is laser-measured and confirmed.' },
                                    { t: 'Direct Link', d: 'No middleman noise. Direct contact with verified brokers.' }
                                ].map(point => `
                                    <div class="flex gap-8 group">
                                        <div class="w-2 h-2 bg-sage rounded-full mt-3 group-hover:scale-[3] transition-transform"></div>
                                        <div class="space-y-2">
                                            <h4 class="font-bold uppercase tracking-widest text-sm text-white/80">${point.t}</h4>
                                            <p class="text-white/30 text-xs leading-relaxed">${point.d}</p>
                                        </div>
                                    </div>
                                `).join('')}
                            </div>
                        </div>
                        <div class="relative reveal">
                            <div class="aspect-[4/5] rounded-[4rem] overflow-hidden">
                                <img src="https://images.unsplash.com/photo-1512917774080-9991f1c4c750?auto=format&fit=crop&w=1200" class="w-full h-full object-cover grayscale brightness-75">
                            </div>
                            <div class="absolute -bottom-10 -left-10 bg-sage p-12 rounded-[3rem] shadow-2xl max-w-[280px]">
                                <i data-lucide="shield-check" class="w-12 h-12 mb-6"></i>
                                <h4 class="font-bold text-lg leading-tight mb-2">Confidence by Design.</h4>
                                <p class="text-[10px] font-bold uppercase tracking-widest text-white/60">Verified Platform 2026</p>
                            </div>
                        </div>
                    </div>
                </section>
            `;
        }

        function renderListings(app) {
            const filtered = state.filter === 'All' ? state.listings : state.listings.filter(l => l.type === state.filter);
            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-[1400px] mx-auto space-y-32">
                    <div class="flex flex-col lg:flex-row justify-between items-end gap-16 reveal active">
                        <div class="space-y-6">
                            <span class="text-[10px] font-bold uppercase tracking-[0.5em] text-sage">Global Collection</span>
                            <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-none">Catalog.</h1>
                        </div>
                        <div class="flex flex-col gap-10 items-end">
                            <p class="text-right text-charcoal/40 text-lg max-w-sm italic">"Luxury is not about price; it's about the intentionality of space."</p>
                            <div class="flex bg-warmGrey p-2 rounded-2xl shadow-inner border border-black/5">
                                ${['All', 'Sale', 'Rent'].map(f => `
                                    <button onclick="setFilter('${f}')" class="px-10 py-4 rounded-xl text-[11px] font-bold uppercase tracking-widest transition-all ${state.filter === f ? 'bg-white shadow-xl text-charcoal' : 'text-charcoal/30 hover:text-charcoal'}">${f}</button>
                                `).join('')}
                            </div>
                        </div>
                    </div>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-16">
                        ${filtered.map(l => renderListingCard(l)).join('')}
                    </div>

                    <div class="pt-40 text-center reveal">
                        <p class="text-[10px] font-bold uppercase tracking-[0.6em] text-charcoal/20 mb-12">New properties added daily</p>
                        <button onclick="showToast('Loading more masterpieces...')" class="border-2 border-charcoal/10 px-16 py-8 rounded-full font-bold uppercase tracking-widest text-[11px] hover:bg-charcoal hover:text-white transition-all">Load More Listings</button>
                    </div>
                </div>
            `;
        }

        function renderServices(app) {
            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-7xl mx-auto space-y-40">
                    <div class="text-center space-y-10 reveal active">
                        <span class="text-sage text-[11px] font-bold uppercase tracking-[0.6em]">Premium Care</span>
                        <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-none">Services.</h1>
                    </div>

                    <div class="grid grid-cols-1 lg:grid-cols-3 gap-16">
                        ${[
                            { t: 'Interior Staging', d: 'Expert curators who design your home to sell or to live.', icon: 'palette' },
                            { t: 'Security Systems', d: 'Invisible, high-tech protection for high-value properties.', icon: 'shield-check' },
                            { t: 'Art Advisory', d: 'Sourcing exclusive contemporary art for your walls.', icon: 'camera' },
                            { t: 'Smart Home Integration', d: 'Unified controls for lighting, climate, and sound.', icon: 'cpu' },
                            { t: 'Landscape Design', d: 'Minimalist gardens that require zero maintenance.', icon: 'wind' },
                            { t: 'Concierge Moving', d: 'White-glove relocation services globally.', icon: 'truck' }
                        ].map((s, i) => `
                            <div class="bg-warmGrey/30 p-12 rounded-[4rem] border border-black/5 hover:border-sage/30 transition-all group reveal" style="transition-delay: ${i*100}ms">
                                <div class="w-20 h-20 bg-white rounded-3xl flex items-center justify-center text-sage mb-10 shadow-sm group-hover:scale-110 transition-transform"><i data-lucide="${s.icon}" class="w-8 h-8"></i></div>
                                <h3 class="font-serif text-3xl mb-4 italic">${s.t}</h3>
                                <p class="text-charcoal/50 text-sm leading-relaxed mb-10">${s.d}</p>
                                <button onclick="showToast('Connecting to advisor...')" class="text-[10px] font-bold uppercase tracking-[0.4em] text-sage border-b-2 border-sage/20 pb-1 group-hover:border-sage transition-all">Inquire</button>
                            </div>
                        `).join('')}
                    </div>

                    <div class="bg-charcoal p-20 rounded-[5rem] text-white flex flex-col md:flex-row justify-between items-center gap-12 reveal">
                        <div class="space-y-4">
                            <h2 class="font-serif text-5xl">Partner with the best.</h2>
                            <p class="text-white/40 max-w-sm">We only work with vetted service providers who pass our 50-point quality audit.</p>
                        </div>
                        <button class="bg-sage px-12 py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px] shadow-2xl">Apply as Partner</button>
                    </div>
                </div>
            `;
        }

        function renderInspiration(app) {
            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-[1400px] mx-auto space-y-40">
                    <div class="flex flex-col lg:flex-row justify-between items-end gap-16 reveal active">
                        <div class="space-y-8">
                            <span class="text-sage text-[11px] font-bold uppercase tracking-[0.6em]">The Design Journal</span>
                            <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-none">Journal.</h1>
                        </div>
                        <div class="max-w-md space-y-6">
                            <p class="text-xl text-charcoal/40 leading-relaxed italic">"Style is a way to say who you are without having to speak."</p>
                        </div>
                    </div>

                    <!-- INTERACTIVE DESIGN LAB -->
                    <div class="bg-warmGrey rounded-[5rem] p-12 md:p-32 space-y-20 reveal">
                        <div class="flex flex-col md:flex-row justify-between items-end gap-8">
                            <div class="space-y-4">
                                <h3 class="font-serif text-5xl italic">Spatial Planner 2.0</h3>
                                <p class="text-charcoal/40 text-sm max-w-sm uppercase tracking-widest font-bold">Drag components to test your minimalist vision.</p>
                            </div>
                            <button onclick="resetGame()" class="text-[10px] font-bold uppercase tracking-widest border-b border-charcoal/20 pb-1">Reset Spatial State</button>
                        </div>
                        <div class="grid grid-cols-1 lg:grid-cols-4 gap-20">
                            <div class="lg:col-span-3">
                                <div id="canvas-area" class="w-full h-[600px] bg-white rounded-[3rem] relative overflow-hidden shadow-inner border border-black/5">
                                    <div class="absolute inset-0 pointer-events-none opacity-5"></div>
                                </div>
                            </div>
                            <div class="space-y-12">
                                <div class="grid grid-cols-2 gap-4">
                                    ${[
                                        { n: 'Sofa', e: '🛋️' }, { n: 'Lamp', e: '💡' },
                                        { n: 'Plant', e: '🌿' }, { n: 'Table', e: '☕' },
                                        { n: 'Art', e: '🖼️' }, { n: 'Rug', e: '🧶' }
                                    ].map(i => `
                                        <button onclick="addItem('${i.n}', '${i.e}')" class="p-8 bg-white rounded-3xl border border-black/5 hover:border-sage transition-all text-3xl shadow-sm hover:shadow-xl hover:-translate-y-1 active:scale-95">
                                            ${i.e}
                                        </button>
                                    `).join('')}
                                </div>
                                <div class="p-8 bg-white/50 rounded-3xl border border-black/5">
                                    <h4 class="font-bold text-[10px] uppercase tracking-[0.3em] text-sage mb-4">Marketplace Sync</h4>
                                    <p class="text-[11px] text-charcoal/40 leading-relaxed italic">Items placed here can be instantly sourced through our affiliate decor marketplace.</p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- LONG FORM JOURNAL CARDS -->
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-20">
                        ${[
                            { t: 'The Rise of Soft Brutalism', c: 'Design', d: 'Exploring why raw concrete is returning to luxury interiors, but with a warmer twist.', img: 'https://images.unsplash.com/photo-1518780664697-55e3ad937233?auto=format&fit=crop&w=1200' },
                            { t: 'Smart Homes that Disappear', c: 'Tech', d: 'The trend toward invisible technology that responds to voice and presence without screens.', img: 'https://images.unsplash.com/photo-1507089947368-19c1da9775ae?auto=format&fit=crop&w=1200' },
                            { t: '2026 Color Forecast', c: 'Aesthetic', d: 'Sage, Terracotta, and Deep Charcoal. Why earthy palettes are dominating the high-end market.', img: 'https://images.unsplash.com/photo-1556912177-c54030639a09?auto=format&fit=crop&w=1200' },
                            { t: 'Small Luxury: The $2M Studio', c: 'Real Estate', d: 'How prime locations in NYC and London are redefining luxury in under 500 square feet.', img: 'https://images.unsplash.com/photo-1536376074432-8d63d5929231?auto=format&fit=crop&w=1200' }
                        ].map((post, i) => `
                            <div class="group cursor-pointer reveal" style="transition-delay: ${i*100}ms">
                                <div class="aspect-video rounded-[3rem] overflow-hidden mb-8 relative">
                                    <img src="${post.img}" class="w-full h-full object-cover transition-transform duration-[2s] group-hover:scale-105">
                                    <div class="absolute top-8 left-8 bg-white/90 backdrop-blur-md px-6 py-2 rounded-full text-[9px] font-bold uppercase tracking-widest">${post.c}</div>
                                </div>
                                <h3 class="font-serif text-5xl mb-6 leading-tight hover:text-sage transition-colors">${post.t}</h3>
                                <p class="text-charcoal/40 text-lg italic leading-relaxed mb-8">${post.d}</p>
                                <button class="text-[10px] font-bold uppercase tracking-[0.5em] text-charcoal border-b border-charcoal/20 pb-2">Read Article</button>
                            </div>
                        `).join('')}
                    </div>
                </div>
            `;
            initGame();
        }

        function renderGuidance(app) {
            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-7xl mx-auto space-y-40">
                    <div class="text-center space-y-10 reveal active">
                        <span class="text-sage text-[11px] font-bold uppercase tracking-[0.6em]">Expert Advisory</span>
                        <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-none">Guidance.</h1>
                    </div>

                    <div class="grid grid-cols-1 lg:grid-cols-2 gap-32 items-center">
                        <div class="space-y-12 reveal">
                            <h2 class="font-serif text-6xl leading-tight">The 2026 Wealth <br> Migration Report.</h2>
                            <p class="text-xl text-charcoal/50 leading-relaxed italic">"We are seeing a massive shift of ultra-high-net-worth individuals moving away from traditional tax havens toward 'lifestyle havens' — cities that offer high aesthetic value and cultural richness."</p>
                            <div class="space-y-6">
                                ${[
                                    { q: 'Where should I invest $5M?', a: 'Focus on second-tier cultural hubs like Lisbon, Berlin, and Kyoto.' },
                                    { q: 'Is eco-certification mandatory?', a: 'By 2027, non-certified luxury homes will lose up to 15% in valuation.' }
                                ].map(faq => `
                                    <div class="p-10 bg-warmGrey/50 rounded-[2.5rem] border border-black/5">
                                        <h4 class="font-bold text-sm uppercase tracking-widest mb-2">${faq.q}</h4>
                                        <p class="text-sm text-charcoal/40 italic">${faq.a}</p>
                                    </div>
                                `).join('')}
                            </div>
                        </div>
                        <div class="bg-charcoal p-12 md:p-24 rounded-[5rem] text-white space-y-12 reveal">
                            <i data-lucide="award" class="w-16 h-16 text-sage"></i>
                            <h3 class="font-serif text-6xl italic leading-none">Consult an <br> Advisor.</h3>
                            <p class="text-white/40 text-sm leading-relaxed">Schedule a private 30-minute consultation with our international market experts to discuss your portfolio.</p>
                            <div class="space-y-4 pt-6">
                                <input type="text" placeholder="Full Name" class="w-full bg-white/5 border border-white/10 p-6 rounded-2xl text-sm outline-none focus:border-sage transition-all">
                                <button onclick="showToast('Request received.')" class="w-full bg-white text-charcoal py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px] shadow-2xl hover:bg-sage hover:text-white transition-all">Book Private Session</button>
                            </div>
                        </div>
                    </div>
                </div>
            `;
        }

        function renderAbout(app) {
            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-7xl mx-auto space-y-40">
                    <div class="grid grid-cols-1 lg:grid-cols-2 gap-32 items-center">
                        <div class="space-y-12 reveal active">
                            <span class="text-sage text-[11px] font-bold uppercase tracking-[0.6em]">The Vision</span>
                            <h1 class="font-serif text-8xl md:text-[10rem] tracking-tighter leading-none">Modern <br> Discovery.</h1>
                            <p class="text-2xl text-charcoal/40 italic leading-relaxed">thehomesdircet was founded to fix a broken experience. The market was cluttered with noisy data and low-quality imagery. We created a sanctuary for those who value architectural integrity over square footage.</p>
                        </div>
                        <div class="aspect-[4/5] bg-warmGrey rounded-[4rem] overflow-hidden reveal active">
                            <img src="https://images.unsplash.com/photo-1600607687940-4e7a53697a69?auto=format&fit=crop&w=1200" class="w-full h-full object-cover">
                        </div>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-3 gap-16 reveal">
                        ${[
                            { t: 'Curation First', d: 'We filter out 92% of listings that reach our desk. Only the essential remains.' },
                            { t: 'Data Privacy', d: 'We are a digital shield. Your search history and preferences are encrypted and never sold.' },
                            { t: 'Global Reach', d: 'Local expertise at a planetary scale. We speak the language of design in 40+ markets.' }
                        ].map(val => `
                            <div class="space-y-6">
                                <h4 class="font-serif text-4xl italic">${val.t}</h4>
                                <p class="text-charcoal/40 text-sm leading-relaxed">${val.d}</p>
                            </div>
                        `).join('')}
                    </div>
                </div>
            `;
        }

        function renderLegal(app, type) {
            const content = {
                'Privacy Policy': 'Your privacy is our highest priority. We use industry-standard encryption to protect your account. We never share your property searches with third parties or advertising networks. Your data belongs to you, and you can export or delete it at any time from your settings.',
                'Terms & Conditions': 'By using thehomesdircet, you agree to engage with our platform in good faith. Our listings are provided by verified brokers, but we encourage independent inspection. Our fees are transparently displayed at the point of inquiry.',
                'Cookies Policy': 'We use strictly necessary cookies to keep you logged in and functional cookies to remember your property filters. We do not use tracking cookies for external advertising purposes.',
                'Accessibility': 'thehomesdircet is designed for everyone. Our platform meets WCAG 2.1 Level AA standards, ensuring high contrast and screen reader compatibility for all property listings.'
            };

            app.innerHTML = `
                <div class="pt-40 pb-60 px-6 max-w-3xl mx-auto space-y-16">
                    <div class="space-y-6 text-center reveal active">
                        <span class="text-sage text-[11px] font-bold uppercase tracking-[0.6em]">Governance</span>
                        <h1 class="font-serif text-8xl tracking-tighter">${type}</h1>
                    </div>
                    <div class="prose prose-xl text-charcoal/50 italic leading-relaxed reveal active">
                        <p class="mb-12">Last Updated: January 2026</p>
                        <p>${content[type] || 'Full legal disclosure for thehomesdircet platform.'}</p>
                        <div class="mt-20 pt-20 border-t border-black/5 space-y-8">
                            <h3 class="font-serif text-4xl text-charcoal italic">Contact Legal Team</h3>
                            <p class="text-sm not-italic">For inquiries regarding our compliance or data handling, please contact legal@thehomesdircet.com.</p>
                        </div>
                    </div>
                </div>
            `;
        }

        // --- COMPONENTS & UTILS ---

        function renderListingCard(l) {
            return `
                <div onclick="openQuickView(${l.id})" class="group cursor-pointer reveal">
                    <div class="aspect-[3/4] rounded-[3rem] overflow-hidden bg-warmGrey relative mb-8">
                        <img src="${l.img}" class="w-full h-full object-cover transition-transform duration-[2s] group-hover:scale-110">
                        <div class="absolute inset-0 bg-charcoal/20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center">
                            <span class="bg-white px-10 py-5 rounded-2xl text-[10px] font-bold uppercase tracking-widest shadow-2xl transform translate-y-10 group-hover:translate-y-0 transition-transform">Detailed View</span>
                        </div>
                        <div class="absolute top-8 left-8">
                            <span class="bg-white/90 backdrop-blur-md px-5 py-2 rounded-full text-[9px] font-bold uppercase tracking-widest">${l.type}</span>
                        </div>
                    </div>
                    <div class="flex justify-between items-start">
                        <div class="space-y-2">
                            <h3 class="font-bold text-xl">${l.title}</h3>
                            <p class="text-[10px] font-bold uppercase tracking-widest text-charcoal/30 flex items-center gap-2">
                                <i data-lucide="map-pin" class="w-3"></i> ${l.loc}
                            </p>
                        </div>
                        <p class="font-serif text-2xl italic text-sage">${l.price}</p>
                    </div>
                </div>
            `;
        }

        function openQuickView(id) {
            const l = state.listings.find(x => x.id === id);
            renderModal(`
                <div class="grid grid-cols-1 lg:grid-cols-2 gap-20">
                    <div class="space-y-8">
                        <div class="aspect-square rounded-[3rem] overflow-hidden shadow-2xl">
                            <img src="${l.img}" class="w-full h-full object-cover">
                        </div>
                        <div class="grid grid-cols-2 gap-6">
                            <div class="bg-warmGrey p-8 rounded-[2rem] text-center">
                                <h4 class="text-[10px] font-bold uppercase tracking-widest opacity-30 mb-2">Beds</h4>
                                <p class="font-serif text-4xl italic">${l.tags[2]}</p>
                            </div>
                            <div class="bg-warmGrey p-8 rounded-[2rem] text-center">
                                <h4 class="text-[10px] font-bold uppercase tracking-widest opacity-30 mb-2">Market</h4>
                                <p class="font-serif text-4xl italic">Prime</p>
                            </div>
                        </div>
                    </div>
                    <div class="flex flex-col justify-center space-y-12">
                        <div class="space-y-6">
                            <div class="flex justify-between items-end">
                                <h2 class="font-serif text-7xl tracking-tighter leading-tight">${l.title}</h2>
                            </div>
                            <div class="flex flex-wrap gap-4">
                                ${l.tags.map(t => `<span class="px-6 py-2 rounded-full bg-sage/10 text-sage text-[9px] font-bold uppercase tracking-widest">${t}</span>`).join('')}
                            </div>
                        </div>
                        <p class="text-xl text-charcoal/40 leading-relaxed italic">"${l.desc}"</p>
                        <div class="space-y-6">
                            <div class="flex justify-between items-center py-6 border-b border-black/5">
                                <span class="text-[10px] font-bold uppercase tracking-[0.3em] text-charcoal/30">Asking Price</span>
                                <span class="font-serif text-4xl italic">${l.price}</span>
                            </div>
                            <div class="flex justify-between items-center py-6 border-b border-black/5">
                                <span class="text-[10px] font-bold uppercase tracking-[0.3em] text-charcoal/30">Listing ID</span>
                                <span class="font-bold text-xs">TSD-${Math.floor(Math.random()*10000)}</span>
                            </div>
                        </div>
                        <div class="pt-10 flex gap-6">
                            <button onclick="showToast('Advisor assigned.')" class="flex-1 bg-charcoal text-white py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px] shadow-2xl hover:bg-sage transition-all">Request Full Dossier</button>
                            <button class="w-20 bg-warmGrey flex items-center justify-center rounded-2xl hover:bg-sage hover:text-white transition-all"><i data-lucide="heart"></i></button>
                        </div>
                    </div>
                </div>
            `);
        }

        // --- AUTH & SYSTEM ---

        function updateAuthUI() {
            const sec = document.getElementById('auth-section');
            if (state.user) {
                sec.innerHTML = `
                    <div class="flex items-center gap-4">
                        <div class="w-10 h-10 bg-sage/10 text-sage rounded-full flex items-center justify-center font-bold text-xs">U</div>
                        <button onclick="logout()" class="text-[10px] font-bold uppercase tracking-widest text-charcoal/40 hover:text-charcoal transition-all">Sign Out</button>
                    </div>
                `;
            } else {
                sec.innerHTML = `<button onclick="openAuthModal()" class="bg-charcoal text-white px-10 py-4 rounded-xl text-[10px] font-bold uppercase tracking-widest shadow-xl hover:bg-sage transition-all">Member Sign In</button>`;
            }
        }

        function openAuthModal() {
            renderModal(`
                <div class="grid grid-cols-1 md:grid-cols-2">
                    <div class="p-20 space-y-12">
                        <div class="space-y-4">
                            <h2 class="font-serif text-6xl">Welcome Back.</h2>
                            <p class="text-charcoal/40 italic">Access your curated dashboard and saved properties.</p>
                        </div>
                        <div class="space-y-6">
                            <input id="l-email" type="email" placeholder="Email Address" class="w-full bg-warmGrey p-6 rounded-2xl outline-none focus:ring-1 focus:ring-sage">
                            <input type="password" placeholder="Password" class="w-full bg-warmGrey p-6 rounded-2xl outline-none focus:ring-1 focus:ring-sage">
                            <button onclick="login()" class="w-full bg-charcoal text-white py-6 rounded-2xl font-bold uppercase tracking-widest text-[11px]">Sign In to Platform</button>
                        </div>
                    </div>
                    <div class="hidden md:block bg-charcoal p-20 relative overflow-hidden">
                        <img src="https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=1200" class="absolute inset-0 w-full h-full object-cover opacity-20">
                        <div class="relative z-10 text-white space-y-6">
                            <h3 class="font-serif text-5xl italic leading-none">The Right <br> Address <br> Changes <br> Everything.</h3>
                        </div>
                    </div>
                </div>
            `);
        }

        function login() {
            state.user = { id: 1 };
            closeModal(null);
            render();
            showToast("Authenticated successfully.");
        }

        function logout() {
            state.user = null;
            render();
            showToast("Signed out.");
        }

        function setFilter(f) {
            state.filter = f;
            render();
        }

        // --- INTERACTIVE LAB LOGIC ---

        function initGame() {
            const canvas = document.getElementById('canvas-area');
            if(!canvas) return;
            canvas.addEventListener('mousedown', startDrag);
            canvas.addEventListener('touchstart', startDrag);
            window.addEventListener('mousemove', drag);
            window.addEventListener('touchmove', drag, { passive: false });
            window.addEventListener('mouseup', endDrag);
            window.addEventListener('touchend', endDrag);
        }

        let draggedItem = null;
        let offset = { x: 0, y: 0 };

        function addItem(name, emoji) {
            const canvas = document.getElementById('canvas-area');
            const el = document.createElement('div');
            el.className = 'draggable text-6xl p-6 bg-white/10 backdrop-blur-md rounded-3xl border border-white/20 transition-transform active:scale-95';
            el.innerHTML = emoji;
            el.style.left = '100px';
            el.style.top = '100px';
            canvas.appendChild(el);
        }

        function resetGame() {
            const canvas = document.getElementById('canvas-area');
            canvas.querySelectorAll('.draggable').forEach(i => i.remove());
        }

        function startDrag(e) {
            if(e.target.classList.contains('draggable')) {
                draggedItem = e.target;
                const rect = draggedItem.getBoundingClientRect();
                const clientX = e.clientX || e.touches[0].clientX;
                const clientY = e.clientY || e.touches[0].clientY;
                offset.x = clientX - rect.left;
                offset.y = clientY - rect.top;
            }
        }

        function drag(e) {
            if(!draggedItem) return;
            e.preventDefault();
            const canvas = document.getElementById('canvas-area');
            const rect = canvas.getBoundingClientRect();
            const clientX = e.clientX || e.touches?.[0]?.clientX;
            const clientY = e.clientY || e.touches?.[0]?.clientY;
            
            let x = clientX - rect.left - offset.x;
            let y = clientY - rect.top - offset.y;
            
            x = Math.max(0, Math.min(x, rect.width - draggedItem.offsetWidth));
            y = Math.max(0, Math.min(y, rect.height - draggedItem.offsetHeight));

            draggedItem.style.left = x + 'px';
            draggedItem.style.top = y + 'px';
        }

        function endDrag() {
            draggedItem = null;
        }

        // --- GLOBAL UTILS ---

        function renderModal(html) {
            document.getElementById('modal-body').innerHTML = html;
            document.getElementById('modal-overlay').classList.remove('hidden');
            document.getElementById('modal-overlay').classList.add('flex');
            lucide.createIcons();
        }

        function closeModal(e) {
            if(e && e.target !== e.currentTarget) return;
            document.getElementById('modal-overlay').classList.add('hidden');
            document.getElementById('modal-overlay').classList.remove('flex');
        }

        function showToast(msg) {
            const existing = document.querySelector('.toast-box');
            if(existing) existing.remove();
            
            const toast = document.createElement('div');
            toast.className = 'toast-box fixed bottom-12 left-1/2 -translate-x-1/2 z-[2000] bg-charcoal text-white px-12 py-5 rounded-full font-bold text-[10px] uppercase tracking-[0.4em] shadow-2xl transition-all animate-bounce';
            toast.innerText = msg;
            document.body.appendChild(toast);
            setTimeout(() => toast.remove(), 4000);
        }

        function initReveal() {
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) entry.target.classList.add('active');
                });
            }, { threshold: 0.1 });
            document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
        }

        // --- INITIALIZE ---
        window.onload = render;
