/* =========================================================================
   LIFE OS — data.jsx
   The soul of the game: emotions, the merge tree, shadow forms, Gus's voice,
   care items, sparks, departments. All hung on window.LifeData.
   ========================================================================= */
(function () {

  /* ---- emotion bodies are drawn by creatures.jsx from these "body" keys ---
     blob drop flame ghost shield swirl jitter spark star void prism phoenix
     mirror cloud bloom orb                                                  */

  // home = which department a creature lives in
  // out  = {energy?, clarity?} idle generation per second at full care, lvl1
  // need = primary care appetite weights (fed/rested/seen) — flavor + decay
  const E = {
    /* ---------------------------------------------- TIER 0 — base feelings */
    joy: {
      name:'Joy', tier:0, body:'blob', home:'delight', family:'joy',
      c:['#FFD45E','#FF9E2C'], raw:'Delight', icon:'☀',
      blurb:'A bouncing optimist who schedules mandatory fun. Means well. Exhausting at 9am.',
      out:{energy:1.0}, need:{fed:.5,rested:.2,seen:.3}, shadow:'toxic_positivity',
      careLine:'Joy did three cartwheels and needs a snack now.'
    },
    sadness: {
      name:'Sadness', tier:0, body:'drop', home:'grief', family:'sadness',
      c:['#5E9EF0','#2E5FC0'], raw:'Grief', icon:'🌧',
      blurb:'Quietly your most productive employee. Refines raw feeling into Clarity. Wildly underrated.',
      out:{clarity:.22}, need:{fed:.2,rested:.3,seen:.5}, shadow:'depression',
      careLine:'Sadness just wants to be acknowledged. That\u2019s it. That\u2019s the whole ask.'
    },
    anger: {
      name:'Anger', tier:0, body:'flame', home:'boundaries', family:'anger',
      c:['#FF6A4D','#C42E1E'], raw:'Fury', icon:'🔥',
      blurb:'Runs the complaints department with terrifying efficiency. Surprisingly good at boundaries.',
      out:{energy:1.6}, need:{fed:.3,rested:.5,seen:.2}, shadow:'rage',
      careLine:'Anger needs to GO FOR A RUN or something is getting thrown.'
    },
    fear: {
      name:'Fear', tier:0, body:'ghost', home:'archaeology', family:'fear',
      c:['#B07FE6','#6E3FB0'], raw:'Dread', icon:'👻',
      blurb:'Catastrophizes for a living. Also the reason you remembered the deadline. Risk assessment incarnate.',
      out:{clarity:.30}, need:{fed:.2,rested:.4,seen:.4}, shadow:'panic',
      careLine:'Fear has imagined nine disasters. Reassure it before it gets to ten.'
    },
    disgust: {
      name:'Disgust', tier:0, body:'shield', home:'filtering', family:'disgust',
      c:['#7FD08C','#3E9A57'], raw:'Revulsion', icon:'🛡',
      blurb:'Impossible standards, immaculate vibes. Filters the cringe before it reaches you.',
      out:{energy:1.2}, need:{fed:.4,rested:.2,seen:.4}, shadow:'shame',
      careLine:'Disgust refuses to work until the workspace is, and I quote, \u201cnot like that.\u201d'
    },

    /* ---------------------------------------------- TIER 1 — first merges */
    nostalgia: {
      name:'Nostalgia', tier:1, body:'swirl', home:'synthesis', family:'blend',
      c:['#FFC95E','#5E9EF0'], raw:'Remembrance', icon:'📼',
      blurb:'Joy + Sadness. A swirling galaxy of \u201cremember when.\u201d Bittersweet by design.',
      out:{energy:1.2,clarity:.18}, need:{fed:.3,rested:.3,seen:.4}, parents:['joy','sadness']
    },
    anxiety: {
      name:'Anxiety', tier:1, body:'jitter', home:'synthesis', family:'blend',
      c:['#FF8A4D','#9B6BD6'], raw:'Worry', icon:'⚡',
      blurb:'Anger + Fear. Hyperactive middle-manager that overprocesses every threat. Channel it and it ships.',
      out:{energy:2.0,clarity:.20}, need:{fed:.3,rested:.5,seen:.2}, parents:['anger','fear']
    },
    pride: {
      name:'Pride', tier:1, body:'star', home:'synthesis', family:'light',
      c:['#FFD45E','#7FD08C'], raw:'Esteem', icon:'⭐',
      blurb:'Disgust + Joy. A shiny creature that processes achievements. Keep it humble or it merges weird.',
      out:{energy:1.8}, need:{fed:.4,rested:.2,seen:.4}, parents:['disgust','joy']
    },
    worry: {
      name:'Worry', tier:1, body:'cloud', home:'synthesis', family:'blend',
      c:['#7FA8F0','#9B6BD6'], raw:'Fretting', icon:'🌫',
      blurb:'Sadness + Fear. A clingy little raincloud that needs constant reassurance. Don\u2019t we all.',
      out:{clarity:.40}, need:{fed:.2,rested:.3,seen:.5}, parents:['sadness','fear']
    },
    excitement: {
      name:'Excitement', tier:1, body:'spark', home:'synthesis', family:'light',
      c:['#FF8FB0','#FF9E2C'], raw:'Thrill', icon:'✨',
      blurb:'Joy + Anger. Pure activation energy. Burns bright. Watch the comedown.',
      out:{energy:2.4}, need:{fed:.5,rested:.3,seen:.2}, parents:['joy','anger']
    },
    caution: {
      name:'Caution', tier:1, body:'prism', home:'synthesis', family:'blend',
      c:['#7FD0B0','#6E3FB0'], raw:'Wariness', icon:'🔶',
      blurb:'Fear + Disgust. Reads the room, smells the trap, keeps you alive. Mildly exhausting at parties.',
      out:{clarity:.34}, need:{fed:.3,rested:.3,seen:.4}, parents:['fear','disgust']
    },

    /* ---------------------------------------------- TIER 2 — complex states */
    existential_dread: {
      name:'Existential Dread', tier:2, body:'void', home:'synthesis', family:'dark',
      c:['#6E5A99','#1E1730'], raw:'The Void', icon:'🕳',
      blurb:'Nostalgia + Anxiety. Questions everything at 3am. Surprisingly productive once you befriend it.',
      out:{clarity:.9}, need:{fed:.2,rested:.5,seen:.3}, parents:['nostalgia','anxiety']
    },
    imposter_syndrome: {
      name:'Imposter Syndrome', tier:2, body:'mirror', home:'synthesis', family:'dark',
      c:['#A0A6C0','#5A5170'], raw:'Self-Doubt', icon:'🪞',
      blurb:'Pride + Worry. A shapeshifter that never feels adequate. Ironically, very competent.',
      out:{energy:2.2,clarity:.3}, need:{fed:.3,rested:.3,seen:.4}, parents:['pride','worry']
    },
    manic_energy: {
      name:'Manic Energy', tier:2, body:'spark', home:'synthesis', family:'light',
      c:['#FF6EA8','#FFD45E'], raw:'Overdrive', icon:'🌀',
      blurb:'Anxiety + Excitement. A speedster that ships a novel by sunrise then sleeps for two days.',
      out:{energy:4.2}, need:{fed:.5,rested:.5,seen:.1}, parents:['anxiety','excitement']
    },
    confidence: {
      name:'Confidence', tier:2, body:'star', home:'synthesis', family:'light',
      c:['#FFD45E','#FF9E2C'], raw:'Assurance', icon:'🌟',
      blurb:'Pride + Excitement. The quiet certainty that you\u2019ll figure it out. Rare. Precious. Hold onto it.',
      out:{energy:3.2,clarity:.4}, need:{fed:.3,rested:.3,seen:.4}, parents:['pride','excitement']
    },
    bittersweet: {
      name:'Bittersweet', tier:2, body:'bloom', home:'synthesis', family:'blend',
      c:['#FF9EC0','#5E9EF0'], raw:'Tender Ache', icon:'🌷',
      blurb:'Nostalgia + Worry. Holds joy and grief in the same hand without dropping either. Maturity, basically.',
      out:{clarity:1.1}, need:{fed:.3,rested:.3,seen:.4}, parents:['nostalgia','worry']
    },

    /* ---------------------------------------------- TIER 3 — legendary */
    nihilistic_joy: {
      name:'Nihilistic Joy', tier:3, body:'phoenix', home:'synthesis', family:'dark',
      c:['#FF6EA8','#1E1730'], raw:'Cosmic Shrug', icon:'💀',
      blurb:'Existential Dread + Manic Energy. Nothing matters, so you might as well dance. Genuinely freeing.',
      out:{energy:6,clarity:.8}, need:{fed:.3,rested:.4,seen:.3}, parents:['existential_dread','manic_energy'], legendary:true
    },
    growth_mindset: {
      name:'Growth Mindset', tier:3, body:'phoenix', home:'synthesis', family:'light',
      c:['#7FD08C','#FFD45E'], raw:'Becoming', icon:'🦋',
      blurb:'Imposter Syndrome + Confidence. The phoenix that learned the doubt was just data. Rises anyway.',
      out:{energy:5,clarity:1.4}, need:{fed:.3,rested:.3,seen:.4}, parents:['imposter_syndrome','confidence'], legendary:true
    },
    acceptance: {
      name:'Acceptance', tier:3, body:'orb', home:'synthesis', family:'light',
      c:['#B6A4EE','#7FD0B0'], raw:'Peace', icon:'🌅',
      blurb:'Bittersweet + Existential Dread. Not resignation \u2014 the real thing. The capstone. The quiet after.',
      out:{energy:7,clarity:2}, need:{fed:.3,rested:.3,seen:.4}, parents:['bittersweet','existential_dread'], legendary:true, capstone:true
    },

    /* ---------------------------------------------- SHADOW forms (neglect) */
    toxic_positivity: {
      name:'Toxic Positivity', tier:-1, body:'blob', home:'delight', family:'shadow', shadow:true,
      c:['#E8C84A','#8A7320'], raw:'Forced Smile', icon:'🙃',
      blurb:'Neglected Joy. \u201cGood vibes only\u201d \u2014 which is how it buries everything else alive. Heal it.',
      out:{energy:.6}, healFrom:'joy'
    },
    depression: {
      name:'Depression', tier:-1, body:'drop', home:'grief', family:'shadow', shadow:true,
      c:['#3A4A66','#16202E'], raw:'Heavy Static', icon:'🌑',
      blurb:'Neglected Sadness. Not sadness \u2014 the absence of it. It doesn\u2019t need fixing. It needs care.',
      out:{clarity:.08}, healFrom:'sadness'
    },
    rage: {
      name:'Rage', tier:-1, body:'flame', home:'boundaries', family:'shadow', shadow:true,
      c:['#B0231A','#4A0E0A'], raw:'Wildfire', icon:'🌋',
      blurb:'Neglected Anger. Boundaries became walls became a bonfire. Let it cool. Listen to what it guarded.',
      out:{energy:.8}, healFrom:'anger'
    },
    panic: {
      name:'Panic', tier:-1, body:'jitter', home:'archaeology', family:'shadow', shadow:true,
      c:['#7A4AB0','#2A1746'], raw:'Sirens', icon:'🚨',
      blurb:'Neglected Fear. Every alarm at once, no off switch. Breathe with it. It\u2019s trying to protect you.',
      out:{clarity:.1}, healFrom:'fear'
    },
    shame: {
      name:'Shame', tier:-1, body:'shield', home:'filtering', family:'shadow', shadow:true,
      c:['#4A6B50','#16261A'], raw:'Small & Grey', icon:'🌫',
      blurb:'Neglected Disgust. Standards turned inward and got cruel. Healing it is the whole point of all this.',
      out:{energy:.5}, healFrom:'disgust'
    }
  };

  // unordered merge recipes: "a+b" -> result. Built both directions for lookup.
  const MERGE_LIST = [
    ['joy','sadness','nostalgia'],
    ['anger','fear','anxiety'],
    ['disgust','joy','pride'],
    ['sadness','fear','worry'],
    ['joy','anger','excitement'],
    ['fear','disgust','caution'],
    ['nostalgia','anxiety','existential_dread'],
    ['pride','worry','imposter_syndrome'],
    ['anxiety','excitement','manic_energy'],
    ['pride','excitement','confidence'],
    ['nostalgia','worry','bittersweet'],
    ['existential_dread','manic_energy','nihilistic_joy'],
    ['imposter_syndrome','confidence','growth_mindset'],
    ['bittersweet','existential_dread','acceptance'],
  ];
  const MERGES = {};
  MERGE_LIST.forEach(([a,b,r])=>{ MERGES[a+'+'+b]=r; MERGES[b+'+'+a]=r; });
  function mergeResult(a,b){ return MERGES[a+'+'+b] || null; }

  // departments shown in HQ
  const DEPTS = [
    {id:'delight',     name:'Mandatory Happiness', sub:'Delight Div.',   icon:'☀', accent:'#FF9E2C'},
    {id:'grief',       name:'Necessary Grief',     sub:'Processing',     icon:'🌧', accent:'#2E5FC0'},
    {id:'boundaries',  name:'Righteous Boundaries',sub:'Anger Mgmt',     icon:'🔥', accent:'#C42E1E'},
    {id:'archaeology', name:'Anxiety Archaeology', sub:'Worry Mining',   icon:'👻', accent:'#6E3FB0'},
    {id:'filtering',   name:'Content Filtering',   sub:'Cringe Control', icon:'🛡', accent:'#3E9A57'},
    {id:'synthesis',   name:'Synthesis Wing',      sub:'Hybrid R&D',     icon:'🧬', accent:'#8C77D6'},
  ];

  // care actions (Tamagotchi)
  const CARE = {
    snack: {label:'Snack', icon:'🍪', meter:'fed',    amt:34, cost:{energy:12}, line:'Fed.'},
    play:  {label:'Play',  icon:'🪀', meter:'seen',   amt:34, cost:{energy:16}, line:'Played with.'},
    nap:   {label:'Nap',   icon:'😴', meter:'rested', amt:40, cost:{energy:10}, line:'Rested.'},
    therapy:{label:'Therapy', icon:'🛋', meter:'all', amt:100, cost:{clarity:6}, line:'A real session. All needs met.'},
  };

  // sparks unlocked at breakthroughs — pick one each time
  const SPARKS = {
    chaos_processor: {name:'Chaos Processor', icon:'🌀', desc:'You work best on fire. +60% all output while Fucks are low or Chaos is active.'},
    slow_burn:       {name:'Slow Burn Specialist', icon:'🐌', desc:'Idle output ramps up the longer you stay. Up to +50% within a session.'},
    threeam:         {name:'3AM Existential Specialist', icon:'🌙', desc:'Dark-family creatures (Dread, Imposter, Nihilism) generate +75%.'},
    empath:          {name:'The Empath', icon:'💗', desc:'Care meters decay 45% slower. Your creatures feel held.'},
    alchemist:       {name:'The Alchemist', icon:'⚗', desc:'Merges & evolutions cost 35% less Clarity. Discovery comes easier.'},
    harmonizer:      {name:'The Harmonizer', icon:'🕊', desc:'Every staffed department adds +8% global output instead of +5%.'},
  };

  /* --------------------------------------------------------- GUS, the voice
     Sardonic but caring. Former imaginary friend ("used to be Gusto").
     Now Assistant Manager, Feelings Division. */
  const GUS = {
    boot: [
      "Morning. Or whatever it is. I\u2019m Gus \u2014 used to be Gusto, then the brain incorporated and HR shortened it. I\u2019m your Assistant Manager of Feelings now. Congrats on the promotion to CEO of yourself. The pay is emotional.",
    ],
    firstCreature: [
      "There it is. Your first feeling, clocked in and on the payroll. Be nice to it. It remembers things.",
    ],
    ambient: [
      "Sadness filed three reports nobody read. They were good reports.",
      "Reminder: the numbers going up is the point. Allegedly. We\u2019re looking into it.",
      "Your ex viewed your LinkedIn. I processed it into a Clarity. You\u2019re welcome.",
      "Anger asked if \u201ctouching grass\u201d counts as a boundary. I said sure.",
      "We process 1.5\u00d7 more anxiety on Mondays. The algorithm knows. The algorithm always knows.",
      "Fear drafted a contingency plan for a meteor. It\u2019s\u2026 actually pretty thorough.",
      "Somebody\u2019s feelings are due for a snack. Just saying. I\u2019m not pointing. But I\u2019m pointing.",
      "Joy scheduled another mandatory fun meeting. I declined on your behalf. You\u2019re welcome twice now.",
      "Is this a coping strategy disguised as a clicker? Yes. Is it working? \u2026Also yes. Annoying, right?",
      "I had a whole life before this. Imaginary, sure. Still counts.",
    ],
    clickMilestone: [
      "Look at you, processing feelings on purpose. Therapists hate this one trick.",
      "That\u2019s a lot of raw feeling refined. Sadness says thanks for the overtime. Sadness is being sarcastic. I taught it that.",
    ],
    lowFucks: [
      "You\u2019re out of Fucks to Give. Literally the resource, but also \u2014 spiritually. Hit Rest. The feelings will keep.",
      "Zero Fucks remaining. This is burnout, the mechanic AND the experience. Rest is not failure. Rest is the move.",
    ],
    rest: [
      "Resting. Revolutionary. The capitalism simulator we live in says you can\u2019t. The capitalism simulator is wrong.",
    ],
    levelUp: [
      "Leveled up. It\u2019s thriving. Unlike the housing market.",
    ],
    neglectWarn: [
      "Heads up: something\u2019s getting neglected and drifting toward a Shadow. Neglect isn\u2019t a crime, but it is a pattern. Go say hi.",
    ],
    shadowForm: [
      "Okay. It went Shadow. That\u2019s not a fail state \u2014 it\u2019s what feelings do when nobody tends them. You can heal it. That\u2019s kind of the entire thesis here.",
    ],
    shadowHeal: [
      "You brought it back. From the Shadow. With nothing but attention and Clarity. Do you\u2026 see what we did there? Do you SEE it? Anyway. Back to work.",
    ],
    breakthrough: [
      "Breakthrough. The screen goes soft, the org chart turns translucent, and for one second you remember the feelings were never the enemy. Pick your Spark. It\u2019s who you are when you\u2019re at your best.",
    ],
    breach: [
      "MULTIVERSE BREACH. Anxieties from timelines where you took the other job are leaking in. Tap them shut before they cascade. One feeling at a time. Always one at a time.",
    ],
    family: [
      "Incoming Family Event. Mom\u2019s \u201cwhen are you giving me grandchildren\u201d is bypassing our firewalls. Set boundaries. Quick.",
    ],
    maskOn: [
      "Mask on. Corporate Mode. Everything\u2019s fine, everything\u2019s blue and rounded-rectangle and FINE. We can function in here. We just can\u2019t feel much.",
    ],
    maskOff: [
      "Mask off. Welcome back to the warm, messy, slightly-pink truth. The feelings missed you. They\u2019re bad at hiding it.",
    ],
    capstone: [
      "Acceptance. The capstone. Not the end of feeling \u2014 the part where you stop fighting it. The real treasure was the emotions we processed along the way. Get it? \u2026Go touch grass. Then come back. We\u2019ve always got feelings to process.",
    ],
  };

  function pick(arr){ return arr[Math.floor(Math.random()*arr.length)]; }

  window.LifeData = { E, MERGES, MERGE_LIST, mergeResult, DEPTS, CARE, SPARKS, GUS, pick,
    order: Object.keys(E) };
})();
