/* Project data, translations and helpers — exported to window for use by tessera-app.jsx */

const hexToRgba = (hex, a) => {
  const h = hex.replace('#','');
  const v = h.length === 3 ? h.split('').map(c=>c+c).join('') : h;
  const r = parseInt(v.slice(0,2),16), g = parseInt(v.slice(2,4),16), b = parseInt(v.slice(4,6),16);
  return `rgba(${r},${g},${b},${a})`;
};

const isLightHex = (hex) => {
  const h = hex.replace('#','');
  const v = h.length === 3 ? h.split('').map(c=>c+c).join('') : h;
  const r = parseInt(v.slice(0,2),16)/255, g = parseInt(v.slice(2,4),16)/255, b = parseInt(v.slice(4,6),16)/255;
  // luminance approx
  return (0.299*r + 0.587*g + 0.114*b) > 0.55;
};

const cssVarsFor = (p) => {
  const light = isLightHex(p.bg);
  const t = p.text;
  return {
    '--bg': p.bg,
    '--bg-alt': p.bgAlt || p.bg,
    '--accent': p.accent,
    '--text': t,
    '--text-muted': hexToRgba(t, 0.6),
    '--text-faint': hexToRgba(t, 0.28),
    '--line': hexToRgba(t, 0.08),
    '--line-strong': hexToRgba(t, 0.18),
    '--vignette': light ? 'rgba(0,0,0,0.10)' : 'rgba(0,0,0,0.45)',
    '--device-bg': light ? hexToRgba(t, 0.03) : 'rgba(0,0,0,0.35)',
    '--nav-bg': light ? hexToRgba(p.bg, 0.92) : hexToRgba(p.bg, 0.85),
    '--theme': light ? 'light' : 'dark',
  };
};

/* PICTOGRAMS — simple geometric SVG marks per project */
const Pictos = {
  wiccan: (
    <svg viewBox="0 0 32 32" fill="none" aria-hidden="true">
      <circle cx="16" cy="16" r="11" stroke="currentColor" strokeWidth="1.3"/>
      <path d="M19.5 8.2 A 8 8 0 0 0 19.5 23.8 A 10.5 10.5 0 0 1 19.5 8.2 Z" fill="currentColor"/>
    </svg>
  ),
  dialy: (
    <svg viewBox="0 0 32 32" fill="none" aria-hidden="true">
      <g transform="rotate(45 16 16)">
        <rect x="5" y="5" width="22" height="22" stroke="currentColor" strokeWidth="1.3" fill="none"/>
        <rect x="11" y="11" width="10" height="10" stroke="currentColor" strokeWidth="1" fill="none" opacity="0.5"/>
      </g>
      <circle cx="16" cy="16" r="2.4" fill="currentColor"/>
    </svg>
  ),
  staq: (
    <svg viewBox="0 0 32 32" fill="none" aria-hidden="true">
      <rect x="4.5" y="20.5" width="23" height="6.5" stroke="currentColor" strokeWidth="1.3"/>
      <rect x="7" y="13" width="18" height="6.5" stroke="currentColor" strokeWidth="1.3"/>
      <rect x="9.5" y="5.5" width="13" height="6.5" stroke="currentColor" strokeWidth="1.3"/>
    </svg>
  ),
};

const PROJECTS = [
  {
    id: 'wiccan',
    name: 'Wiccan',
    logo: 'assets/logo-wiccan.png',
    logoMono: 'assets/logo-wiccan-mono.png',
    logoScale: 1.4,
    accent: '#3ecfb2',
    bg: '#0d1f2d',
    bgAlt: '#0a1822',
    text: '#ffffff',
    pictoKey: 'wiccan',
    tagline: { fr: "Cuisiner ensemble, un rituel.", en: "Cooking together, a ritual." },
    description: {
      fr: "Application de recettes collaborative. Mode cuisine animé pas à pas, import OCR de recettes, partage de groupe.",
      en: "Collaborative recipe app. Animated step-by-step cooking mode, OCR recipe import, group sharing."
    },
    features: [
      { fr: { h: "Mode cuisine animé", d: "Pas à pas chronométré, mains libres, transitions fluides." },
        en: { h: "Animated cooking mode", d: "Timed step-by-step, hands-free, fluid transitions." } },
      { fr: { h: "Import OCR", d: "Photographiez une recette papier, structurez-la en un geste." },
        en: { h: "OCR import", d: "Photograph a paper recipe, structure it in one gesture." } },
      { fr: { h: "Rituel partagé", d: "Groupes privés, planification commune, mémoire collective." },
        en: { h: "Shared ritual", d: "Private groups, joint planning, collective memory." } },
    ],
    techNodes: [
      { name: 'OCR Engine', d: {
        fr: "En une simple photo de ta recette, Wiccan la retranscrit automatiquement, de ses ingrédients à ses étapes.",
        en: "From a single photo of your recipe, Wiccan transcribes it automatically — ingredients and steps alike."
      }},
      { name: 'Vector Store', d: {
        fr: "Wiccan mémorise chaque recette de façon intelligente pour retrouver instantanément ce dont tu as besoin, même avec une description approximative.",
        en: "Wiccan memorises every recipe semantically so you can find exactly what you need, even from a fuzzy description."
      }},
      { name: 'Claude API', d: {
        fr: "L'intelligence au cœur de Wiccan. Elle comprend le contexte, suggère des variantes et adapte les recettes à tes contraintes.",
        en: "The intelligence at the heart of Wiccan. It reads context, suggests variations and adapts recipes to your constraints."
      }},
      { name: 'Recipe DB', d: {
        fr: "Toutes tes recettes, celles de ta communauté, organisées et accessibles en permanence.",
        en: "All your recipes — and your community's — organised and always at hand."
      }},
      { name: 'User Group', d: {
        fr: "Wiccan permet de créer une communauté de partage et de commentaires autour de recettes partagées.",
        en: "Wiccan lets you build a community of sharing and commentary around shared recipes."
      }},
    ],
    captions: {
      app: { fr: 'Application mobile', en: 'Mobile application' },
      step: { fr: 'Mode cuisine', en: 'Cooking mode' },
      ocr: { fr: 'Scanner recette', en: 'Recipe scanner' },
    },
    techIntro: {
      fr: "Chaque pièce du système est choisie pour sa précision. Les modèles de langage orchestrent, les outils spécialisés exécutent, l'utilisateur garde la main.",
      en: "Each piece of the system is chosen for precision. Language models orchestrate, specialized tools execute, the user keeps control."
    },
    previews: [
      {
        type: 'html', src: 'assets/wiccan-demo-accueil.html#embed',
        label: { fr: 'Accueil & import OCR', en: 'Home & OCR import' },
        kind: { fr: 'Démo · 01', en: 'Demo · 01' },
        h: { fr: 'Ton livre de recettes, en poche', en: 'Your recipe book, in your pocket' },
        d: {
          fr: "Le Livre Famille s'ouvre sur les recettes du moment, filtrables d'un geste. Importe une page de livre en photo, ou retrouve un plat avec une description approximative. Touche l'écran, la démo est vivante.",
          en: "The Family Book opens on the recipes of the moment, filterable in one tap. Import a book page from a photo, or find a dish from a fuzzy description. Tap the screen, the demo is live."
        }
      },
      {
        type: 'html', src: 'assets/wiccan-demo-recette.html#embed',
        label: { fr: 'Mode cuisine pas à pas', en: 'Step-by-step cooking mode' },
        kind: { fr: 'Démo · 02', en: 'Demo · 02' },
        h: { fr: 'Mode cuisine animé', en: 'Animated cooking mode' },
        d: {
          fr: "De la fiche recette au dernier geste : une étape à la fois, des illustrations animées, un minuteur intégré. La recette se déroule comme un rituel, sans qu'on ait à y penser.",
          en: "From the recipe sheet to the last gesture: one step at a time, animated illustrations, a built-in timer. The recipe unfolds like a ritual, with nothing to think about."
        }
      },
      {
        type: 'html', src: 'assets/wiccan-demo-communaute.html#embed',
        label: { fr: 'Communauté & livre partagé', en: 'Community & shared book' },
        kind: { fr: 'Démo · 03', en: 'Demo · 03' },
        h: { fr: 'Rituel partagé', en: 'Shared ritual' },
        d: {
          fr: "Le fil de la communauté, les likes et les commentaires, un livre partagé entre proches. Les recettes circulent, s'enrichissent et deviennent un patrimoine.",
          en: "The community feed, likes and comments, a book shared between loved ones. Recipes circulate, grow richer and become a shared heritage."
        }
      },
    ],
  },
  {
    id: 'dialy',
    name: 'Dialy',
    logo: 'assets/logo-dialy.png',
    logoMono: 'assets/logo-dialy-mono.png',
    logoScale: 1.55,
    accent: '#b99b23',
    bg: '#2d2d1d',
    bgAlt: '#2d3328',
    text: '#ffffff',
    pictoKey: 'dialy',
    tagline: { fr: "Transformer le quotidien en quête.", en: "Turning daily life into a quest." },
    description: {
      fr: "Gestionnaire de vie gamifié inspiré de l'esthétique Pip-Boy. Système XP et niveaux, 6 catégories PERKS, gestion de projets avec rétroplanning, intelligence IA au cœur.",
      en: "Gamified life manager inspired by the Pip-Boy aesthetic. XP and level system, 6 PERKS categories, project management with retroplanning, AI at its core."
    },
    features: [
      { fr: { h: "Système XP & niveaux", d: "Chaque action quotidienne compte. Progression mesurée, motivation tangible." },
        en: { h: "XP & level system", d: "Every daily action counts. Measured progress, tangible motivation." } },
      { fr: { h: "6 catégories PERKS", d: "Foyer, intendance, entretien, administration, soin et duo. Équilibrez votre fiche." },
        en: { h: "6 PERKS categories", d: "Home, supplies, upkeep, admin, care and duo. Balance your sheet." } },
      { fr: { h: "Rétroplanning IA", d: "Décomposez vos quêtes en jalons, l'IA estime et planifie." },
        en: { h: "AI retroplanning", d: "Break quests into milestones, AI estimates and schedules." } },
    ],
    techNodes: [
      { name: 'Claude API', d: {
        fr: "Le cerveau de DIALY. Il comprend tes objectifs, analyse ta progression et t'accompagne comme un vrai coach personnel.",
        en: "The brain of DIALY. It understands your goals, analyses your progress and coaches you like a real personal coach."
      }},
      { name: 'Quest & XP', d: {
        fr: "Le moteur qui transforme tes tâches en quêtes, comptabilise ton expérience et te fait progresser jour après jour.",
        en: "The engine that turns your tasks into quests, tallies your experience and pushes you forward day after day."
      }},
      { name: 'LLM Planner', d: {
        fr: "DIALY planifie automatiquement ta semaine, anticipe tes charges et optimise ton rétroplanning en temps réel.",
        en: "DIALY plans your week automatically, anticipates load and optimises your retroplanning in real time."
      }},
      { name: 'Assistant IA', d: {
        fr: "Ton majordome personnel et familial. Il coordonne la vie du foyer, partage les tâches entre ses membres et veille à ce que rien ne soit oublié.",
        en: "Your personal and family butler. It coordinates household life, splits chores between members and makes sure nothing slips."
      }},
      { name: 'Foyer', d: {
        fr: "Crée ton cercle de vie. Partage objectifs, tâches et victoires avec les membres de ton foyer.",
        en: "Build your life circle. Share goals, tasks and wins with the members of your household."
      }},
    ],
    captions: {
      app: { fr: 'Interface Pip-Boy', en: 'Pip-Boy interface' },
      step: { fr: 'Fiche personnage', en: 'Character sheet' },
      ocr: { fr: 'Quêtes & jalons', en: 'Quests & milestones' },
    },
    techIntro: {
      fr: "Une mécanique de jeu sérieuse. Les modèles raisonnent sur tes objectifs, les systèmes propriétaires comptabilisent et orchestrent.",
      en: "A serious play mechanic. Models reason about your goals, proprietary systems tally and orchestrate."
    },
    previews: [
      {
        type: 'video', src: 'assets/dialy-demo-01.mp4',
        label: { fr: 'Système XP & niveaux', en: 'XP & level system' },
        kind: { fr: 'Démo · 01', en: 'Demo · 01' },
        h: { fr: 'Système XP & niveaux', en: 'XP & level system' },
        d: {
          fr: "Chaque action quotidienne compte. Progression mesurée, motivation tangible — ton quotidien devient une partie qu'on a envie de jouer.",
          en: "Every daily action counts. Measured progress, tangible motivation — your day-to-day becomes a game you want to play."
        }
      },
      {
        type: 'video', src: 'assets/dialy-demo-02.mp4',
        label: { fr: '6 catégories PERKS', en: '6 PERKS categories' },
        kind: { fr: 'Démo · 02', en: 'Demo · 02' },
        h: { fr: '6 catégories PERKS', en: '6 PERKS categories' },
        d: {
          fr: "Foyer, intendance, entretien, administration, soin et duo. Chaque perk a son personnage : on voit d'un coup d'œil où l'on excelle et où l'on s'oublie.",
          en: "Home, supplies, upkeep, admin, care and duo. Every perk has its own character: see at a glance where you excel and where you neglect."
        }
      },
      {
        type: 'video', src: 'assets/dialy-demo-03.mp4',
        label: { fr: 'Fonctionnalités', en: 'Features' },
        kind: { fr: 'Démo · 03', en: 'Demo · 03' },
        h: { fr: 'Le quotidien, de la voix à l\'agenda', en: 'Daily life, from voice to calendar' },
        d: {
          fr: "Un récap de la semaine, un majordome qui note une tâche à la voix ou au clavier, une liste de to-do et un agenda mensuel. Tout ce qu'il faut pour piloter sa journée au même endroit.",
          en: "A weekly recap, a butler that logs a task by voice or keyboard, a to-do list and a monthly calendar. Everything you need to run your day in one place."
        }
      },
    ],
  },
  {
    id: 'staq',
    name: 'StaQ',
    logo: 'assets/logo-staq.png',
    logoMono: 'assets/logo-staq-mono.png',
    logoScale: 1.0,
    accent: '#FF5E46',
    bg: '#faf8f4',
    bgAlt: '#f1ede4',
    text: '#2e2820',
    pictoKey: 'staq',
    tagline: { fr: "Chaque projet a sa structure.", en: "Every project has its structure." },
    description: {
      fr: "Gestionnaire de projets modulaire qui se construit brique par brique. Une interface qui s'adapte aux besoins d'un projet et de ses utilisateurs.",
      en: "Modular project manager built brick by brick. An interface that adapts to the needs of a project and its users."
    },
    features: [
      { fr: { h: "Interface simplifiée", d: "StaQ ne te noie pas sous les informations. Tu construis ton espace de travail brique par brique, selon tes besoins réels, pas selon un modèle imposé." },
        en: { h: "Streamlined interface", d: "StaQ doesn't drown you in information. You build your workspace brick by brick, around real needs — not an imposed template." } },
      { fr: { h: "Adaptabilité", d: "Chaque projet est différent. StaQ s'y adapte : tu choisis tes outils, tu ajustes ta grille, tu scales selon l'ampleur du chantier." },
        en: { h: "Adaptability", d: "Every project differs. StaQ adapts: pick your tools, tune your grid, scale with the size of the build." } },
      { fr: { h: "Collaboration simplifiée", d: "Partage uniquement ce qui est utile, à qui en a besoin. Brique par brique, collaborateur par collaborateur." },
        en: { h: "Streamlined collaboration", d: "Share only what is useful, with those who need it. Brick by brick, collaborator by collaborator." } },
    ],
    techNodes: [
      { name: 'Claude API', d: {
        fr: "L'assistant IA de StaQ comprend le contexte de chaque projet. Il lit tes briques, anticipe tes besoins et peut agir directement dans ton espace de travail.",
        en: "StaQ's AI reads the context of every project. It parses your bricks, anticipates needs and can act directly in your workspace."
      }},
      { name: 'Supabase Realtime', d: {
        fr: "Les modifications de chaque brique partagée sont synchronisées instantanément entre tous les collaborateurs, sans rechargement.",
        en: "Edits to every shared brick sync instantly across all collaborators — no reload."
      }},
      { name: 'Zustand', d: {
        fr: "Le gestionnaire d'état de StaQ. Il garde en mémoire ce que tu es en train de faire, quelle brique est ouverte, quel projet est actif, en temps réel et sans latence.",
        en: "StaQ's state manager. It remembers what you're doing, which brick is open, which project is active — real-time, zero latency."
      }},
      { name: 'IndexedDB', d: {
        fr: "StaQ fonctionne même sans connexion. Tes données sont mises en cache localement et se synchronisent dès que tu es de retour en ligne.",
        en: "StaQ works offline. Your data is cached locally and syncs back the moment you reconnect."
      }},
    ],
    captions: {
      app: { fr: 'Espace de travail', en: 'Workspace' },
      step: { fr: 'Briques actives', en: 'Active bricks' },
      ocr: { fr: 'Partage granulaire', en: 'Granular sharing' },
    },
    techIntro: {
      fr: "Une pile temps réel, locale d'abord. Les briques se synchronisent quand le réseau le permet, et tiennent toutes seules quand il flanche.",
      en: "A real-time, local-first stack. Bricks sync when the network allows and stand alone when it falters."
    },
    previews: [
      {
        type: 'video', src: 'assets/staq-demo-01.mp4',
        label: { fr: 'Interface simplifiée', en: 'Streamlined interface' },
        kind: { fr: 'Démo · 01', en: 'Demo · 01' },
        h: { fr: 'Interface simplifiée', en: 'Streamlined interface' },
        d: {
          fr: "StaQ ne te noie pas sous les informations. Tu construis ton espace de travail brique par brique, selon tes besoins réels, pas selon un modèle imposé.",
          en: "StaQ doesn't drown you in information. You build your workspace brick by brick, around real needs — not an imposed template."
        }
      },
      {
        type: 'image', src: '',
        label: { fr: 'Adaptabilité', en: 'Adaptability' },
        kind: { fr: 'Démo · 02', en: 'Demo · 02' },
        h: { fr: 'Adaptabilité', en: 'Adaptability' },
        d: {
          fr: "Chaque projet est différent. StaQ s'y adapte : tu choisis tes outils, tu ajustes ta grille, tu scales selon l'ampleur du chantier.",
          en: "Every project differs. StaQ adapts: pick your tools, tune your grid, scale with the size of the build."
        }
      },
      {
        type: 'image', src: '',
        label: { fr: 'Collaboration simplifiée', en: 'Streamlined collaboration' },
        kind: { fr: 'Démo · 03', en: 'Demo · 03' },
        h: { fr: 'Collaboration simplifiée', en: 'Streamlined collaboration' },
        d: {
          fr: "Partage uniquement ce qui est utile, à qui en a besoin. Brique par brique, collaborateur par collaborateur.",
          en: "Share only what is useful, with those who need it. Brick by brick, collaborator by collaborator."
        }
      },
      {
        type: 'image', src: '',
        label: { fr: 'Agents intelligents', en: 'Intelligent agents' },
        kind: { fr: 'Démo · 04', en: 'Demo · 04' },
        h: { fr: 'Agents intelligents', en: 'Intelligent agents' },
        d: {
          fr: "Des agents disponibles pour chaque besoin, accessibles en un clic. Lecture des emails, analyse des agendas, détection des risques projet, extraction des données documents.",
          en: "Agents ready for every need, one click away. Reading emails, scanning calendars, surfacing project risks, extracting data from documents."
        },
        q: {
          fr: "Faire tout soi-même, c'est le luxe des gens débordés.",
          en: "Doing everything yourself is the luxury of the overwhelmed."
        }
      },
    ],
  },
];

const T = {
  project: { fr: 'Projet', en: 'Project' },
  presentation: { fr: 'Présentation', en: 'Presentation' },
  technique: { fr: 'Architecture technique', en: 'Technical architecture' },
  presentationLede: { fr: "Une lecture intime du projet.", en: "An intimate reading of the project." },
  techniqueLede: { fr: "Le squelette qui le fait tenir.", en: "The skeleton that holds it up." },
  techHint: { fr: 'Survolez chaque cercle pour la description.', en: 'Hover each circle for the description.' },
  techCoreTitle: { fr: 'Au cœur\ndu système', en: 'At the core\nof the system' },
  contact: { fr: 'Contact', en: 'Contact' },
  available: { fr: 'Disponible pour collaborations', en: 'Available for collaborations' },
  rights: { fr: 'Tous droits réservés', en: 'All rights reserved' },
  role: { fr: 'Designer graphique × Chef de projet IA', en: 'Graphic designer × AI project lead' },
  craftedIn: { fr: 'Conçu à la main · Paris', en: 'Hand-crafted · Paris' },
  index: { fr: 'Index projets', en: 'Project index' },
  prev: { fr: 'Précédent', en: 'Previous' },
  next: { fr: 'Suivant', en: 'Next' },
};

Object.assign(window, { PROJECTS, T, Pictos, cssVarsFor, hexToRgba, isLightHex });
