// content-sub.jsx — Tier 4 sub-pyramids (Analyst markets, Strategist real estate)
// + the DNA assessment (questions, scoring, routing).

// Each sub-pyramid: levels bottom->top in array order index 0 = base.
// Each level has `cells` ordered left(conservative)->right(aggressive); the
// horizontal index maps onto the 5-stop risk gradient.
window.L180_SUBPYRAMIDS = {
  analyst: {
    key: "analyst",
    name: "The Analyst Path",
    domain: "Market Investing",
    dot: "🟢",
    theme: "#24CE62",
    tagline: "Your risk tolerance shapes your pyramid. Your discipline determines whether it stands.",
    gateway: "Risk Tolerance Assessment",
    axisNote: "Risk climbs as you go up — and as you move left to right within each level.",
    axisLeft: "Conservative", axisRight: "Aggressive",
    levels: [
      { name: "Protection Foundation", note: "Whole life insurance is the foundational asset — it replaces the money market as the Analyst's liquid, leverage-ready operational and emergency capital. You move money in and out and borrow against it to invest. Protection before positions.",
        cells: ["Whole Life Insurance", "Money Market", "High-Yield Cash / T-Bills", "Opportunity Fund"] },
      { name: "Core Allocation", note: "Where the invested portfolio begins.",
        cells: ["Treasuries", "Investment-Grade Bonds", "Broad Index ETFs", "Sector / Geo ETFs", "Materials & Gold"] },
      { name: "Targeted Allocation", note: "Tilting the core with intention.",
        cells: ["Quality / Dividend ETFs", "Low-Volatility Factor", "Value Tilts", "Growth Tilts", "Sector Overweights", "Thematic ETFs"] },
      { name: "Specialist & Trend-Aware", note: "You won't be right every time here. The goal is engagement, learning, and developing market sense.",
        cells: ["Defensive Rotation", "Trend-Following ETFs", "Macro Plays", "Tactical Sector Bets", "Aggressive Thematic"] },
      { name: "Conviction Positions", note: "Concentrated bets you can defend.",
        cells: ["Blue-Chip Dividend", "Blue-Chip Growth", "Alternative Investments", "BTC / ETH", "Conviction Stocks", "Higher-Risk Crypto"] },
      { name: "Peak / Speculative", note: "Optional. Many clients will never have a peak level.",
        cells: ["Covered Calls / CSPs", "Defined-Risk Spreads", "Long Calls / Puts", "Speculative Small Caps", "Naked Options / Microcap"] },
    ],
    education: [
      { t: "Borrow, don't liquidate", d: "Your whole life policy is the liquid, leverage-ready capital you draw against to invest — without selling out of the market." },
      { t: "Take wins off the table", d: "As positions run, de-risk gains back down into the foundation asset instead of letting them ride." },
      { t: "Always be learning", d: "A continuous education track and live webinars keep your market sense sharp as you climb." },
      { t: "Build to your risk profile", d: "Sample pyramids by risk tolerance show what a disciplined climb looks like at every level." },
    ],
  },
  strategist: {
    key: "strategist",
    name: "The Strategist Path",
    domain: "Real Estate",
    dot: "🔵",
    theme: "#1FC9E5",
    tagline: "Dirt, doors, and discipline.",
    gateway: "Real Estate Risk & Capacity Assessment",
    axisNote: "Passive to operator as you climb — passive to active within each level.",
    axisLeft: "Passive", axisRight: "Operator",
    levels: [
      { name: "Protection Foundation", note: "Whole life insurance is the foundational asset for every Strategist. Save with the intent to invest — protection, liquidity, and leverage-ready capital before you ever buy a door. This is the floor the whole real estate pyramid stands on.",
        cells: ["Whole Life Insurance", "Emergency Reserve", "Liquidity / Money Market", "Opportunity Fund"] },
      { name: "Passive REIT Foundation", note: "Real estate exposure without the toolbelt.",
        cells: ["REIT ETFs", "Public REITs", "Private REITs", "RE Crowdfunding", "Interval Funds"] },
      { name: "Secured Paper & Lending", note: "Be the bank.",
        cells: ["Tax Liens", "Performing Notes", "Private Mortgage Lending", "Non-Performing Notes", "Tax Deeds & Auctions"] },
      { name: "Individual Properties (Hold)", note: "Owning the dirt and the doors.",
        cells: ["Turnkey SFR", "Self-Managed SFR", "Land", "Short-Term Rentals", "BRRRR / Value-Add", "House Hacking"] },
      { name: "Active SFR & Flips", note: "Forcing equity with sweat and systems.",
        cells: ["Light Cosmetic Flips", "Standard Flips", "Heavy Rehab", "Wholesaling", "Wholetailing", "Distressed Plays"] },
      { name: "Syndications (Passive LP)", note: "Scale through other operators.",
        cells: ["Debt-Fund Synd.", "Stabilized Multifamily", "Storage / MHP / Industrial", "Value-Add Synd.", "Opportunistic Synd."] },
      { name: "Active Commercial & Development", note: "You are the operator now.",
        cells: ["Stabilized MF (Op)", "Commercial NNN", "Value-Add Commercial", "Lot Banking", "Ground-Up Development"] },
    ],
    education: [
      { t: "Fund deals from the foundation", d: "Policy loans against your whole life asset feed down-payments and deals — then get repaid as they cash-flow." },
      { t: "Run financing in parallel", d: "A financing pyramid runs alongside the asset pyramid, so capital is ready before the deal is." },
      { t: "Master the mechanics", d: "Underwriting, property management, 1031 exchanges, cost-segregation, and tenant law protect every level." },
    ],
  },

  builder: {
    key: "builder",
    name: "The Builder Path",
    domain: "Business & Enterprise",
    dot: "🟠",
    theme: "#F97316",
    tagline: "Save to invest. Invest in yourself first. Then build the engine.",
    gateway: "Operator Capacity & Capital Assessment",
    axisNote: "Passive, durable businesses on the left → active, high-leverage operations on the right.",
    axisLeft: "Passive", axisRight: "Active / High-Leverage",
    levels: [
      { name: "Protection Foundation", note: "Whole life insurance is the financial foundation. You save with the intent to invest — emergency capital, opportunity capital, and a liquid base you can borrow against to fund the business.",
        cells: ["Whole Life Insurance", "Emergency Reserve", "Operating Liquidity", "Opportunity Fund"] },
      { name: "Invest in Yourself First ($50K Rule)", note: "Before funding any business, put ~$50K into your own growth — your ability to build is directly correlated to your personal expansion. This is the highest-return asset you own.",
        cells: ["Courses & Programs", "Masterminds", "Inner Circles", "Live Events", "Coaching / Mentors"] },
      { name: "Cash-Flow Businesses (Passive / Semi-Passive)", note: "Boring, durable, cash-flowing. The first rung of ownership.",
        cells: ["Etsy / Print-on-Demand", "Vending / ATM", "Laundromats", "Car Washes", "Self-Storage"] },
      { name: "Online & Operated Businesses", note: "More upside, more hands-on.",
        cells: ["Dropshipping", "FBA (Amazon)", "E-Commerce Brand", "Marketing Agency", "Consulting Firm"] },
      { name: "Active Operating Companies", note: "You are the operator. Teams, systems, and scale.",
        cells: ["Service Businesses", "Insurance Agency", "Franchises", "SaaS / Software", "Multi-Location Ops"] },
      { name: "Scale & Exit", note: "Take wins off the table on the way up — the goal is a big exit, not a forever grind.",
        cells: ["Acquisitions / Roll-Ups", "Private Equity Recap", "Strategic Sale", "IPO / Going Public"] },
    ],
    education: [
      { t: "Self-fund the build", d: "The foundation asset is flexible startup and operating capital you control — no gatekeepers." },
      { t: "Take wins off the table", d: "De-risk big wins into safe assets on the way up, so a bad year never resets the climb." },
      { t: "Structure for protection", d: "Operating, holding, and IP entity structures separate risk from the assets you've built." },
      { t: "Leverage relationships", d: "Strategic alliances and partnerships compound output and accelerate the climb." },
    ],
  },

  professional: {
    key: "professional",
    name: "The Professional Path",
    domain: "Expertise & Career",
    dot: "🟣",
    theme: "#A855F7",
    tagline: "Your income is your #1 asset. Protect the earner, then compound the surplus.",
    gateway: "Income & Protection Assessment",
    axisNote: "Protection & guarantees on the left → growth & measured risk on the right.",
    axisLeft: "Protect", axisRight: "Grow",
    levels: [
      { name: "Protection Foundation", note: "Whole life insurance is the foundation — protection, emergency fund, and living benefits. Your income is your number one asset, so own-occupation disability is non-negotiable. Save with the intent to invest.",
        cells: ["Whole Life Insurance", "Own-Occupation Disability", "Emergency Fund", "Opportunity Fund"] },
      { name: "Invest in Yourself ($50K Rule)", note: "Skills compound faster than the market. $5K into your own growth — a degree, cert, or leadership skill — can lift income $20-30K/yr. That return beats the index. Climb the ranks first.",
        cells: ["Certifications", "Advanced Degree / MBA", "Leadership Training", "Technical Skills", "Executive Coaching"] },
      { name: "Tax-Advantaged Accumulation", note: "Max the tax-advantaged buckets your employer makes available.",
        cells: ["401(k) / TSP", "Roth IRA", "457 / 403(b)", "HSA", "Brokerage"] },
      { name: "Growth & Alternatives", note: "As income stabilizes, take measured risk — and weave in college planning per your values.",
        cells: ["Index Funds", "Target-Date / Balanced", "Passive Real Estate", "Sector Tilts", "529 / College Planning"] },
      { name: "Retirement De-Risking", note: "Take risk for income off the table. Pivot the whole life into a volatility buffer; layer in guaranteed income.",
        cells: ["Whole Life as Volatility Buffer", "Muni Bonds", "Bond Funds", "Annuities (Income)"] },
    ],
    education: [
      { t: "Protect the earner first", d: "Living benefits and own-occupation disability coverage protect the income everything else depends on." },
      { t: "Take wins off the table", d: "As retirement nears, move risk-for-income off the table and lock in what you've earned." },
      { t: "Pivot the foundation", d: "Whole life shifts from accumulation to a volatility buffer that lets your portfolio recover untouched." },
      { t: "Plan around your values", d: "College planning is woven in to the degree your values call for it — never one-size-fits-all." },
    ],
  },

  innovator: {
    key: "innovator",
    name: "The Innovator Path",
    domain: "Creation & IP",
    dot: "🔴",
    theme: "#DC2626",
    tagline: "Wealth built through ideas others won't make — funded by a stable floor.",
    gateway: "Creator Stage & Runway Assessment",
    axisNote: "Audience & content on the left → owned IP, licensing, and big exits on the right.",
    axisLeft: "Build Audience", axisRight: "Own the IP",
    levels: [
      { name: "Protection Foundation", note: "Whole life insurance is the foundation. A stable floor funds the creative leap — emergency capital, a creative runway fund, and liquidity you can borrow against between wins.",
        cells: ["Whole Life Insurance", "Emergency Reserve", "Creative Runway Fund", "Opportunity Fund"] },
      { name: "Invest in Yourself ($50K Rule)", note: "Your ability to create is everything — and for innovators it's often about the rooms you're in. Masterminds and strategic collaborations that take your idea to market matter more here than anywhere.",
        cells: ["Masterminds", "Strategic Collaborations", "Coaching / Mentors", "Skills & Tools", "Live Events"] },
      { name: "Audience & Content", note: "Build the audience that everything else compounds on.",
        cells: ["YouTube / Social", "Newsletter / Audience", "Podcast", "Brand Deals", "Sponsorships"] },
      { name: "Productized IP", note: "Turn ideas into products that pay you after the work is done.",
        cells: ["Courses", "Coaching Programs", "Live Events / Workshops", "Memberships", "Digital Products"] },
      { name: "Licensing & Royalties", note: "Assets that pay long after creation.",
        cells: ["Licensing Deals", "Royalty Streams", "Physical Products", "Patents / Trademarks", "Equity Partnerships"] },
      { name: "Platforms & Big Exits", note: "Create the tools and platforms others lean on. Take wins off the table along the way.",
        cells: ["Owned Platforms / Tools", "Productized Company", "Strategic Sale", "IPO / Major Exit"] },
    ],
    education: [
      { t: "Fund the next leap", d: "The foundation asset bankrolls the next creative leap without betting the house on it." },
      { t: "Take wins off the table", d: "After a big win, de-risk into safe assets so the next bet is never make-or-break." },
      { t: "Collaborate to compound", d: "Strategic alliances and collaborative partnerships multiply what one creator can produce alone." },
      { t: "Own the IP", d: "IP-holding entities and licensing structures turn creative work into assets that pay long after." },
    ],
  },
};

// The philosophy — universal principles that hold on every path, regardless of
// what sits inside the triangle. Rendered in the sub-pyramid footer for all paths.
window.L180_PRINCIPLES = [
  { t: "Protection before positions", d: "Whole life is the foundation stone. You secure the floor before you ever reach for the upside." },
  { t: "Borrow, don't liquidate", d: "The foundation asset is liquid, leverage-ready capital you build against — never something you're forced to sell out of." },
  { t: "Take wins off the table", d: "Every climb de-risks gains back down into safe assets, so one bad year never resets the whole pyramid." },
  { t: "Alignment, not products", d: "The point isn't a product — it's money aligned with the life you actually want. Clarity + alignment = the life you desire." },
];

// DNA types
window.L180_DNA = {
  strategist:   { key: "strategist",   name: "Strategist",   color: "#1FC9E5", domain: "Real Estate",  blurb: "Wired to control hard assets — dirt, doors, and leverage.", meaning: "You build wealth by controlling tangible assets. Your edge is leverage, negotiation, and forcing value where others only see risk.", routesTo: "strategist" },
  analyst:      { key: "analyst",      name: "Analyst",      color: "#24CE62", domain: "Markets",      blurb: "Wired to compound in markets with research and discipline.", meaning: "You build wealth by compounding in markets with research and patience. Your edge is discipline and a long horizon — not chasing.", routesTo: "analyst" },
  builder:      { key: "builder",      name: "Builder",      color: "#F97316", domain: "Business",     blurb: "Wired to build companies, teams, and cash-flowing engines.", meaning: "You build wealth by creating cash-flowing engines. Your edge is leverage through people, systems, and relentless reinvestment.", routesTo: "lens" },
  professional: { key: "professional", name: "Professional", color: "#A855F7", domain: "Expertise",    blurb: "Wired to convert mastery of a craft into premium income.", meaning: "You build wealth by converting elite skill into premium income. Your edge is mastery — and protecting the earner that makes it all work.", routesTo: "lens" },
  innovator:    { key: "innovator",    name: "Innovator",    color: "#DC2626", domain: "Creation",     blurb: "Wired to create original output — IP, invention, licensing.", meaning: "You build wealth by creating original value. Your edge is IP and leverage through what only you can make — funded by a stable floor.", routesTo: "lens" },
};

// Assessment. Each option awards points to one or more DNA types.
// The final question captures current reality (Path A–D logic).
window.L180_DNA_QUESTIONS = [
  {
    id: "energizes", q: "When you imagine building wealth, what energizes you most?",
    why: "Your instinctive draw is the strongest DNA signal.",
    opts: [
      { t: "Acquiring property — tangible doors and dirt", dna: { strategist: 3 } },
      { t: "Researching markets and optimizing a portfolio", dna: { analyst: 3 } },
      { t: "Building a company, a team, a product", dna: { builder: 3 } },
      { t: "Becoming elite at a craft that commands income", dna: { professional: 3 } },
      { t: "Creating something original — IP, art, invention", dna: { innovator: 3 } },
    ],
  },
  {
    id: "work", q: "How do you most want your money to work?",
    why: "Preferred mechanism reveals wiring beyond surface interest.",
    opts: [
      { t: "Leverage and control over hard assets", dna: { strategist: 2, builder: 1 } },
      { t: "Compounding in markets, hands mostly off", dna: { analyst: 2, professional: 1 } },
      { t: "Reinvested into a growing business", dna: { builder: 2, strategist: 1 } },
      { t: "Funding my expertise so I earn more", dna: { professional: 2, innovator: 1 } },
      { t: "Royalties and licensing from what I make", dna: { innovator: 2, analyst: 1 } },
    ],
  },
  {
    id: "week", q: "Your ideal productive week looks like…",
    why: "Where you want to spend energy predicts what you'll sustain.",
    opts: [
      { t: "Walking properties and running numbers on deals", dna: { strategist: 2 } },
      { t: "Reading research and rebalancing positions", dna: { analyst: 2 } },
      { t: "Leading a team and shipping the next thing", dna: { builder: 2 } },
      { t: "Deep work mastering my profession", dna: { professional: 2 } },
      { t: "Making something that didn't exist yesterday", dna: { innovator: 2 } },
    ],
  },
  {
    id: "risk", q: "How would you describe your relationship to risk?",
    why: "Sets the horizontal starting point inside your pyramid.",
    risk: true,
    opts: [
      { t: "Protect first — I want to sleep at night", risk: 0, dna: { analyst: 1 } },
      { t: "Mostly cautious, some calculated bets", risk: 1, dna: { professional: 1 } },
      { t: "Balanced — offense and defense", risk: 2, dna: { strategist: 1 } },
      { t: "Growth-leaning, I can stomach swings", risk: 3, dna: { builder: 1 } },
      { t: "Aggressive — fortune favors conviction", risk: 4, dna: { innovator: 1 } },
    ],
  },
  {
    id: "reality", q: "Where do you actually live today?",
    why: "DNA says who you're becoming. This says what you need now.",
    reality: true,
    opts: [
      { t: "I actively invest in real estate", reality: "strategist", active: true },
      { t: "I actively invest in the markets", reality: "analyst", active: true },
      { t: "I run a business with real revenue", reality: "builder", active: true },
      { t: "I earn strong income from my profession", reality: "professional", active: true },
      { t: "I'm building something not yet earning", reality: "innovator", active: false },
      { t: "None of these — I'm just getting started", reality: "none", active: false },
    ],
  },
];

// Scoring + routing. Returns { primary, secondary, scores, risk, riskLabel,
// reality, path, route }.
window.l180ScoreDNA = function (answers) {
  const scores = { strategist: 0, analyst: 0, builder: 0, professional: 0, innovator: 0 };
  let risk = 2, reality = "none", realityActive = false;
  L180_DNA_QUESTIONS.forEach((Q) => {
    const choice = answers[Q.id];
    if (choice == null) return;
    const opt = Q.opts[choice];
    if (!opt) return;
    if (opt.dna) for (const k in opt.dna) scores[k] += opt.dna[k];
    if (Q.risk && typeof opt.risk === "number") risk = opt.risk;
    if (Q.reality) { reality = opt.reality; realityActive = !!opt.active; }
  });
  const ranked = Object.keys(scores).sort((a, b) => scores[b] - scores[a]);
  const primary = ranked[0];
  const secondary = ranked[1];
  const dna = L180_DNA[primary];

  // Path logic (A–D)
  let path, route, pathNote;
  const matchesReality = reality === primary;
  if (primary === "strategist") {
    path = "A"; route = "strategist";
    pathNote = matchesReality
      ? "Active or aspiring Strategist — entering the Real Estate sub-pyramid at your current capacity."
      : "Strategist DNA. We'll enter the Real Estate sub-pyramid and calibrate the entry level to where you are today.";
  } else if (primary === "analyst") {
    path = "B"; route = "analyst";
    pathNote = matchesReality
      ? "Active or aspiring Analyst — entering the Markets sub-pyramid at your current portfolio level."
      : "Analyst DNA. We'll enter the Markets sub-pyramid and set the entry level to your current portfolio.";
  } else if (realityActive && (reality === "builder" || reality === "professional")) {
    path = "C"; route = "lens";
    pathNote = `${dna.name} DNA with an active engine — staying on the main pyramid with ${dna.name}-specific emphasis at Tiers 2, 3, and 5.`;
  } else {
    path = "D"; route = "lens";
    const dmap = {
      builder: "Builder DNA without a business yet — we serve you as a Professional today; your foundation asset becomes future startup capital.",
      professional: "Professional DNA — a light-touch setup until income stabilizes, then we scale.",
      innovator: "Innovator DNA without output yet — we serve you as a Professional today; your foundation asset funds the creative leap.",
    };
    pathNote = dmap[primary] || "We'll serve you where you live today and honor where you're heading.";
  }

  return {
    primary, secondary, scores, risk,
    riskLabel: L180_BRAND.riskLabels[risk],
    reality, realityActive, path, route, pathNote,
  };
};
