// app/bereal.jsx — Page principale "Paparazzis" (BeReal du mariage)
// Voir Feature 3 — BeReal du mariage.html pour la spec complète.

function BerealPage() {
  // Force un re-render quand les posts changent (publication, suppression…)
  const [tick, setTick] = React.useState(0);
  const bump = React.useCallback(() => setTick(t => t + 1), []);

  // Welcome overlay au tout premier accès
  const [showWelcome, setShowWelcome] = React.useState(() => !Store.get(BR_FIRST_VISIT, false));
  const dismissWelcome = () => { Store.set(BR_FIRST_VISIT, true); setShowWelcome(false); };

  // Phila 1er post overlay
  const [showPhilaFirst, setShowPhilaFirst] = React.useState(false);

  // Lightbox
  const [lightbox, setLightbox] = React.useState(null); // { post, prompt, isMine }

  // Composer
  const [composer, setComposer] = React.useState(null); // { prompt }

  // Vue : "mur" | "archive" | "archiveDetail" | "philaSecret"
  const [view, setView] = React.useState("mur");
  const [archiveDetailId, setArchiveDetailId] = React.useState(null);

  // Bannière "le prompt N°X est archivé"
  const [archivedBanner, setArchivedBanner] = React.useState(null);

  // Au mount : check bascule auto + détection nouveau prompt archivé
  React.useEffect(() => {
    if (brCheckBackupTrigger()) bump();
    // Notification "prompt archivé"
    const archived = brGetArchivedPrompts();
    const lastSeen = Store.get(BR_LAST_SEEN_FERM, 0);
    const newestArchive = archived[0];
    if (newestArchive) {
      const ferme = new Date(newestArchive.ferme_le).getTime();
      if (ferme > lastSeen && Date.now() - ferme < 7 * 86400000) {
        setArchivedBanner(newestArchive);
      }
    }
  }, []);

  const dismissArchivedBanner = () => {
    if (archivedBanner) Store.set(BR_LAST_SEEN_FERM, new Date(archivedBanner.ferme_le).getTime());
    setArchivedBanner(null);
  };

  // ─── Pause jour J ────────────────────────────────────────────────────
  if (brIsPauseDay()) {
    return <BrPauseView />;
  }

  // ─── Computed states ─────────────────────────────────────────────────
  const activePrompt = brGetActivePrompt();
  const isClubPhila = brIsClubPhila();

  // ─── Handlers ────────────────────────────────────────────────────────
  const onPublish = (postData) => {
    const post = {
      id: `p-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
      prompt_id: composer.prompt.id,
      statut: "publie",
      publie_le: new Date().toISOString(),
      ...postData,
    };
    brSavePost(post);
    // 1er post de l'invité ?
    const isFirstEver = !Store.get(BR_FIRST_POST, false);
    if (isFirstEver) {
      Store.set(BR_FIRST_POST, true);
      setShowPhilaFirst(true);
    }
    setComposer(null);
    bump();
  };

  // ─── Render ─────────────────────────────────────────────────────────
  return (
    <div style={{ position: "relative", overflow: "hidden", minHeight: "100vh" }}>
      <WashBg hue={-60} opacity={0.14}/>
      <Page cascade={false}>
        <AppHeader eyebrow={view === "mur" ? "Cette semaine" : view === "philaSecret" ? "Club Phila" : "Tout ce qu'on a vu"}
                   title={view === "philaSecret" ? "Le mur secret" : "Les Paparazzis"} />
        <div style={{ textAlign: "center", marginTop: 4, fontFamily: A.italic, fontStyle: "italic", fontSize: 15, color: A.inkSoft, lineHeight: 1.5, maxWidth: 440, margin: "8px auto 0", animation: "a-up .5s .2s ease both" }}>
          {view === "mur"
            ? "Un prompt par semaine, une photo, une légende. Tout reste — jusqu'au Carnet."
            : view === "philaSecret"
              ? "Réservé aux 5+ posts. Seuls les autres membres du Club voient vos réponses."
              : "Les semaines passées, conservées intactes."}
        </div>

        {/* Switch de vue */}
        <BrViewSwitch view={view} setView={setView} isClubPhila={isClubPhila} />

        {/* Bannière prompt archivé */}
        {view === "mur" && archivedBanner && (
          <BrArchivedBanner prompt={archivedBanner} onDismiss={dismissArchivedBanner} onOpen={() => { dismissArchivedBanner(); setArchiveDetailId(archivedBanner.id); setView("archiveDetail"); }} />
        )}

        {/* Contenu selon la vue */}
        {view === "mur" && (
          <BrActiveView
            prompt={activePrompt}
            onOpenComposer={(p) => setComposer({ prompt: p })}
            onOpenLightbox={setLightbox}
            isClubPhila={isClubPhila}
            onOpenPhilaSecret={() => setView("philaSecret")}
          />
        )}
        {view === "archive" && (
          <BrArchiveView
            onOpenDetail={(id) => { setArchiveDetailId(id); setView("archiveDetail"); }}
          />
        )}
        {view === "archiveDetail" && archiveDetailId && (
          <BrArchiveDetailView
            promptId={archiveDetailId}
            onBack={() => setView("archive")}
            onOpenLightbox={setLightbox}
          />
        )}
        {view === "philaSecret" && (
          <BrPhilaSecretView
            onBack={() => setView("mur")}
            onOpenComposer={(p) => setComposer({ prompt: p })}
            onOpenLightbox={setLightbox}
          />
        )}
      </Page>

      {/* Overlays */}
      {showWelcome && <BrWelcomeOverlay onDismiss={dismissWelcome} />}
      {showPhilaFirst && <BrPhilaFirstPostOverlay onDismiss={() => setShowPhilaFirst(false)} />}
      {composer && <BrComposer prompt={composer.prompt} onClose={() => setComposer(null)} onPublish={onPublish} />}
      {lightbox && <BrLightbox {...lightbox} onClose={() => setLightbox(null)} onDelete={(id) => { brRemovePost(id); bump(); }} />}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Switch de vue (Cette semaine ⇄ Prompts d'avant)
// ─────────────────────────────────────────────────────────────────────────
function BrViewSwitch({ view, setView, isClubPhila }) {
  const isDetail = view === "archiveDetail" || view === "philaSecret";
  return (
    <div style={{
      display: "flex", gap: 0,
      margin: "22px auto 0", maxWidth: 360,
      border: `1px solid ${A.ruleSoft}`,
      animation: "a-up .5s .25s ease both",
    }}>
      <SwitchBtn active={view === "mur" || (isDetail && view !== "archiveDetail")} onClick={() => setView("mur")} label="Cette semaine" />
      <SwitchBtn active={view === "archive" || view === "archiveDetail"} onClick={() => setView("archive")} label="Prompts d'avant" />
    </div>
  );
}

function SwitchBtn({ active, onClick, label }) {
  return (
    <button onClick={onClick} style={{
      flex: 1, padding: "10px 8px",
      background: active ? A.ink : "transparent",
      color: active ? A.or : A.ink, border: "none",
      fontFamily: A.mono, fontSize: 10, letterSpacing: 1.8, textTransform: "uppercase",
      fontWeight: 600, cursor: "pointer", transition: "all .15s",
    }}>{label}</button>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Bannière "le prompt N° X est désormais archivé"
// ─────────────────────────────────────────────────────────────────────────
function BrArchivedBanner({ prompt, onDismiss, onOpen }) {
  return (
    <div style={{
      marginTop: 18, padding: "12px 14px",
      background: A.sageWash, border: `1px solid ${A.sage}40`,
      borderLeft: `3px solid ${A.sage}`,
      display: "flex", alignItems: "center", gap: 12,
      animation: "a-up .4s ease both",
    }}>
      <div style={{ flex: 1 }}>
        <div style={{ fontFamily: A.mono, fontSize: 9, letterSpacing: 2, color: A.sage, fontWeight: 600 }}>
          PROMPT N° {prompt.numero} ARCHIVÉ
        </div>
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 13.5, color: A.ink, marginTop: 2 }}>
          "{prompt.question}" · Nouveau prompt lundi.
        </div>
      </div>
      <button onClick={onOpen} style={{
        padding: "8px 12px", background: A.ink, color: A.or, border: "none",
        fontFamily: A.mono, fontSize: 9, letterSpacing: 1.5, textTransform: "uppercase",
        cursor: "pointer", flexShrink: 0,
      }}>Voir</button>
      <button onClick={onDismiss} style={{
        background: "transparent", border: "none", color: A.inkMute,
        fontSize: 18, lineHeight: 1, cursor: "pointer", padding: "4px 6px", flexShrink: 0,
      }}>×</button>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Vue MUR — prompt actif + son wall
// ─────────────────────────────────────────────────────────────────────────
function BrActiveView({ prompt, onOpenComposer, onOpenLightbox, isClubPhila, onOpenPhilaSecret }) {
  if (!prompt) {
    return (
      <div style={{ marginTop: 28, padding: "40px 24px", background: A.paper, textAlign: "center", border: `1px solid ${A.ruleSoft}` }}>
        <div style={{ fontFamily: A.display, fontSize: 40, color: A.or, lineHeight: 1, marginBottom: 14 }}>✦</div>
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 16, color: A.inkSoft, lineHeight: 1.55 }}>
          Aucun prompt actif cette semaine.<br/>
          Rendez-vous lundi prochain.
        </div>
      </div>
    );
  }
  const myPost = brMyPostForPrompt(prompt.id);
  const posts = brGetPostsForPrompt(prompt.id);
  return (
    <>
      <BrPromptHeader prompt={prompt} />
      {!myPost ? (
        <BrCountdownBar prompt={prompt} onAct={() => onOpenComposer(prompt)} />
      ) : (
        <BrAnsweredBar onModify={() => onOpenComposer(prompt)} />
      )}
      <BrWall posts={posts} myPostId={myPost?.id} prompt={prompt} onOpenLightbox={onOpenLightbox} />

      {isClubPhila && <BrPhilaSecretCard onOpen={onOpenPhilaSecret} />}
    </>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// BrPromptHeader — affiche le prompt courant
// ─────────────────────────────────────────────────────────────────────────
function BrPromptHeader({ prompt }) {
  return (
    <div style={{
      marginTop: 22, padding: "14px 16px 16px",
      background: A.white, border: `1px solid ${A.ruleSoft}`,
      borderTop: `3px solid ${A.or}`,
      animation: "a-up .5s .35s ease both",
    }}>
      <div style={{ fontFamily: A.mono, fontSize: 9, letterSpacing: 2, color: A.orDeep, fontWeight: 600 }}>
        PROMPT N° {prompt.numero} · {brFormatRange(prompt)}
      </div>
      <div style={{ fontFamily: A.display, fontWeight: 700, fontSize: 22, color: A.ink, lineHeight: 1.15, marginTop: 6, letterSpacing: -0.3, textWrap: "balance" }}>
        {prompt.question}
      </div>
      {prompt.sous_texte && (
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 14, color: A.inkSoft, lineHeight: 1.45, marginTop: 8 }}>
          {prompt.sous_texte}
        </div>
      )}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// BrCountdownBar — "il te reste X jours pour poster"
// ─────────────────────────────────────────────────────────────────────────
function BrCountdownBar({ prompt, onAct }) {
  const diff = Math.max(0, new Date(prompt.ferme_le).getTime() - Date.now());
  const days = Math.floor(diff / 86400000);
  const hours = Math.floor((diff % 86400000) / 3600000);
  const label = days >= 1
    ? `Il te reste ${days} jour${days > 1 ? "s" : ""} pour poster`
    : `Plus que ${hours} h pour poster`;
  return (
    <button onClick={onAct} style={{
      width: "100%", marginTop: 10, padding: "12px 14px",
      background: A.ink, color: A.white, border: "none", cursor: "pointer",
      display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10,
      transition: "transform .15s",
      animation: "a-up .5s .45s ease both",
    }} onMouseEnter={(e) => e.currentTarget.style.transform = "translateY(-1px)"}
       onMouseLeave={(e) => e.currentTarget.style.transform = "translateY(0)"}>
      <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 14, color: "rgba(255,255,255,0.85)", textAlign: "left" }}>
        {label}
      </div>
      <div style={{ fontFamily: A.mono, fontSize: 10, letterSpacing: 2, color: A.or, textTransform: "uppercase", fontWeight: 600, flexShrink: 0 }}>
        Répondre ›
      </div>
    </button>
  );
}

function BrAnsweredBar({ onModify }) {
  return (
    <div style={{
      marginTop: 10, padding: "12px 14px",
      background: A.orPale, border: `1px solid ${A.or}40`,
      display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10,
      animation: "a-up .5s .45s ease both",
    }}>
      <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 14, color: A.ink }}>
        Bravo, tu as répondu — voici tout le monde.
      </div>
      <button onClick={onModify} style={{
        background: "transparent", border: "none", color: A.orDeep,
        fontFamily: A.mono, fontSize: 9, letterSpacing: 1.5, cursor: "pointer", textTransform: "uppercase", fontWeight: 600,
      }}>Modifier ›</button>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// BrWall — grille de polaroids
// ─────────────────────────────────────────────────────────────────────────
function BrWall({ posts, myPostId, prompt, onOpenLightbox }) {
  if (!posts.length) {
    return (
      <div style={{ marginTop: 24, padding: "32px 24px", background: A.paper, textAlign: "center", border: `1px solid ${A.ruleSoft}` }}>
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 15, color: A.inkSoft, lineHeight: 1.55 }}>
          Personne n'a encore répondu.<br/>Sois le premier paparazzi.
        </div>
      </div>
    );
  }
  // Si l'utilisateur a posté, on met son post en tête
  const sorted = myPostId
    ? [posts.find(p => p.id === myPostId), ...posts.filter(p => p.id !== myPostId)].filter(Boolean)
    : posts;
  return (
    <div style={{
      marginTop: 20,
      display: "grid", gridTemplateColumns: "1fr 1fr",
      gap: "26px 14px",
      paddingBottom: 12,
    }}>
      {sorted.map((post, i) => (
        <BrPolaroid
          key={post.id}
          post={post}
          isMine={post.id === myPostId}
          tilt={polaroidTilt(i, post.id)}
          delay={0.05 + i * 0.06}
          onClick={() => onOpenLightbox({ post, prompt, isMine: post.id === myPostId })}
        />
      ))}
    </div>
  );
}

function polaroidTilt(i, id) {
  // Rotation pseudo-aléatoire stable entre -2.2° et +2.2°
  let h = 0;
  for (let c = 0; c < id.length; c++) h = (h * 31 + id.charCodeAt(c)) | 0;
  const t = ((h % 100) / 100 - 0.5) * 4.4;
  return Number(t.toFixed(2));
}

function BrPolaroid({ post, isMine, tilt, delay, onClick }) {
  return (
    <button onClick={onClick} style={{
      background: A.white, padding: "8px 8px 24px",
      border: "none",
      boxShadow: "0 3px 8px rgba(26,22,18,0.14), 0 1px 0 rgba(26,22,18,0.06)",
      cursor: "pointer", textAlign: "center",
      transform: `rotate(${tilt}deg)`,
      transition: "transform .25s cubic-bezier(.2,.7,.3,1), box-shadow .25s",
      animation: `a-up .55s cubic-bezier(.2,.7,.3,1) ${delay}s both`,
      position: "relative",
    }} onMouseEnter={(e) => { e.currentTarget.style.transform = `rotate(${tilt}deg) translateY(-4px) scale(1.02)`; e.currentTarget.style.boxShadow = "0 12px 24px rgba(26,22,18,0.2), 0 1px 0 rgba(26,22,18,0.06)"; }}
       onMouseLeave={(e) => { e.currentTarget.style.transform = `rotate(${tilt}deg)`; e.currentTarget.style.boxShadow = "0 3px 8px rgba(26,22,18,0.14), 0 1px 0 rgba(26,22,18,0.06)"; }}>
      <BrPhotoFrame post={post} />
      {isMine && (
        <div style={{
          position: "absolute", top: 14, right: 14,
          fontFamily: A.mono, fontSize: 7.5, letterSpacing: 1.5, fontWeight: 600,
          background: A.ink, color: A.or, padding: "3px 6px", borderRadius: 1,
        }}>★ MOI</div>
      )}
      <div style={{
        marginTop: 6, fontFamily: A.italic, fontStyle: "italic",
        fontSize: 12, color: A.ink, lineHeight: 1.25,
        minHeight: 16,
        overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
      }}>
        {post.caption ? `"${post.caption}"` : <span style={{ color: A.inkMute, opacity: 0.5 }}>—</span>}
      </div>
      <div style={{
        fontFamily: A.mono, fontSize: 8, letterSpacing: 1.2, color: A.inkMute,
        marginTop: 3, textTransform: "uppercase",
      }}>
        {isMine ? "Toi" : (post.nom_invite || "Anonyme")}
      </div>
    </button>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Vue ARCHIVE — liste des prompts d'avant
// ─────────────────────────────────────────────────────────────────────────
function BrArchiveView({ onOpenDetail }) {
  const archived = brGetArchivedPrompts();
  if (!archived.length) {
    return (
      <div style={{ marginTop: 28, padding: "32px 24px", background: A.paper, textAlign: "center", border: `1px solid ${A.ruleSoft}` }}>
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 15, color: A.inkSoft, lineHeight: 1.55 }}>
          Aucun prompt archivé pour l'instant.<br/>
          Reviens à la fin de la semaine.
        </div>
      </div>
    );
  }
  return (
    <div style={{ marginTop: 22 }}>
      {archived.map((p, i) => {
        const posts = brGetPostsForPrompt(p.id);
        return (
          <BrArchiveRow key={p.id} prompt={p} posts={posts} delay={0.05 + i * 0.05} onClick={() => onOpenDetail(p.id)} />
        );
      })}
    </div>
  );
}

function BrArchiveRow({ prompt, posts, delay, onClick }) {
  // 4 mini-thumbs en damier (max 4 posts)
  const previews = posts.slice(0, 4);
  while (previews.length < 4) previews.push(null);
  return (
    <button onClick={onClick} style={{
      width: "100%", padding: "12px 8px", marginBottom: 4,
      background: "transparent", border: "none", borderBottom: `1px solid ${A.ruleSoft}`,
      cursor: "pointer", textAlign: "left",
      display: "flex", gap: 14, alignItems: "center",
      animation: `a-up .5s cubic-bezier(.2,.7,.3,1) ${delay}s both`,
      transition: "background .15s",
    }} onMouseEnter={(e) => e.currentTarget.style.background = A.paper}
       onMouseLeave={(e) => e.currentTarget.style.background = "transparent"}>
      <div style={{
        width: 56, height: 56, flexShrink: 0,
        display: "grid", gridTemplateColumns: "1fr 1fr", gridTemplateRows: "1fr 1fr",
        gap: 2, background: A.ruleSoft, padding: 2,
      }}>
        {previews.map((post, i) => post ? (
          <div key={i} style={{
            background: post.photo_url
              ? `url(${post.photo_url}) center/cover`
              : `linear-gradient(135deg, ${post.photo_color?.from || "#ddd"}, ${post.photo_color?.to || "#aaa"})`,
          }} />
        ) : (
          <div key={i} style={{ background: A.paper }} />
        ))}
      </div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{
          fontFamily: A.display, fontStyle: "italic", fontSize: 15, color: A.ink, lineHeight: 1.25,
          overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
        }}>
          "{prompt.question}"
        </div>
        <div style={{ fontFamily: A.mono, fontSize: 8.5, color: A.inkMute, letterSpacing: 1.5, marginTop: 4, textTransform: "uppercase" }}>
          N° {prompt.numero} · {brFormatRange(prompt)} · {posts.length} rép.
        </div>
      </div>
      <div style={{ color: A.inkMute, fontFamily: A.display, fontSize: 20 }}>›</div>
    </button>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Vue ARCHIVE DETAIL — un prompt archivé, son wall complet
// ─────────────────────────────────────────────────────────────────────────
function BrArchiveDetailView({ promptId, onBack, onOpenLightbox }) {
  const prompt = brGetPrompts().find(p => p.id === promptId);
  if (!prompt) return null;
  const posts = brGetPostsForPrompt(promptId);
  const myIds = brGetMyPostIds();
  const myPostId = posts.find(p => myIds.includes(p.id))?.id;
  return (
    <div>
      <button onClick={onBack} style={{
        marginTop: 16, padding: "8px 0", background: "transparent", border: "none",
        fontFamily: A.mono, fontSize: 10, letterSpacing: 2, color: A.orDeep,
        cursor: "pointer", textTransform: "uppercase", fontWeight: 600,
      }}>← Tous les prompts</button>
      <BrPromptHeader prompt={prompt} />
      <div style={{
        marginTop: 10, padding: "10px 14px",
        background: A.sageWash, border: `1px solid ${A.sage}40`,
        fontFamily: A.italic, fontStyle: "italic", fontSize: 13, color: A.inkSoft,
      }}>
        Ce prompt est désormais archivé · {posts.length} réponse{posts.length > 1 ? "s" : ""}.
      </div>
      <BrWall posts={posts} myPostId={myPostId} prompt={prompt} onOpenLightbox={onOpenLightbox} />
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Vue PAUSE JOUR J (20 - 22 août 2027)
// ─────────────────────────────────────────────────────────────────────────
function BrPauseView() {
  return (
    <div style={{ position: "relative", overflow: "hidden", minHeight: "100vh" }}>
      <WashBg hue={-60} opacity={0.18}/>
      <Page cascade={false}>
        <AppHeader eyebrow="21 août 2027" title="On se voit en vrai" />
        <div style={{
          marginTop: 36, padding: "40px 24px",
          background: A.ink, color: A.white, textAlign: "center",
          border: `1px solid ${A.or}`,
        }}>
          <div style={{ fontFamily: A.display, fontStyle: "italic", fontSize: 54, color: A.or, lineHeight: 1, marginBottom: 18 }}>
            ✦
          </div>
          <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 17, color: "rgba(255,255,255,0.85)", lineHeight: 1.55, maxWidth: 320, margin: "0 auto" }}>
            Le mur est en pause pendant le mariage.
            <br/><br/>
            Lâchez votre téléphone, dansez, mangez du tiramisu géant.
            <br/><br/>
            Rendez-vous le 23 août pour le mur du souvenir.
          </div>
          <div style={{ marginTop: 28, fontFamily: A.mono, fontSize: 10, letterSpacing: 3, color: A.or }}>
            — ENORA &amp; ANTOINE
          </div>
        </div>
      </Page>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────
// Vue PHILA SECRET — prompt secret + son wall (Club Phila seulement)
// ─────────────────────────────────────────────────────────────────────────
function BrPhilaSecretView({ onBack, onOpenComposer, onOpenLightbox }) {
  const prompt = { ...PHILA_SECRET_PROMPT, publie_le: new Date().toISOString(), ferme_le: new Date(Date.now() + 365 * 86400000).toISOString() };
  const myPost = brMyPostForPrompt(prompt.id);
  const posts = brGetPostsForPrompt(prompt.id);
  return (
    <div>
      <button onClick={onBack} style={{
        marginTop: 16, padding: "8px 0", background: "transparent", border: "none",
        fontFamily: A.mono, fontSize: 10, letterSpacing: 2, color: A.orDeep,
        cursor: "pointer", textTransform: "uppercase", fontWeight: 600,
      }}>← Retour au mur</button>

      <div style={{
        marginTop: 16, padding: "20px 22px",
        background: `linear-gradient(135deg, ${A.ink} 0%, #2A2620 100%)`,
        color: A.white, border: `1.5px solid ${A.or}`,
      }}>
        <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 12 }}>
          <Phila variant="head" size={36} />
          <div style={{ fontFamily: A.mono, fontSize: 9, letterSpacing: 2.5, color: A.or }}>
            PROMPT SECRET · CLUB PHILA
          </div>
        </div>
        <div style={{ fontFamily: A.display, fontStyle: "italic", fontWeight: 400, fontSize: 26, lineHeight: 1.1, color: A.white, letterSpacing: -0.3 }}>
          "{prompt.question}"
        </div>
        <div style={{ fontFamily: A.italic, fontStyle: "italic", fontSize: 14, color: "rgba(255,255,255,0.7)", lineHeight: 1.5, marginTop: 10 }}>
          {prompt.sous_texte}
        </div>
        {!myPost ? (
          <button onClick={() => onOpenComposer(prompt)} style={{
            marginTop: 16, padding: "12px 18px",
            background: A.or, color: A.ink, border: "none",
            fontFamily: A.mono, fontSize: 10, letterSpacing: 2.5, fontWeight: 600, textTransform: "uppercase",
            cursor: "pointer",
          }}>Répondre à Phila ›</button>
        ) : (
          <div style={{ marginTop: 14, fontFamily: A.italic, fontStyle: "italic", fontSize: 13, color: A.or }}>
            ★ Tu as répondu. Phila te remercie.
          </div>
        )}
      </div>

      <BrWall posts={posts} myPostId={myPost?.id} prompt={prompt} onOpenLightbox={onOpenLightbox} />
    </div>
  );
}

Object.assign(window, { BerealPage });
