ploxion-compagnon/app.blade.php

1092 lines
64 KiB
PHP

{{-- PL0XION compagnon — la partie DOUCE du xerboxion (inspirée de Finch : « le UI me rend
chill »). Un petit bion/wormion adorable qui respire, se balance, cligne des yeux, suit
ton curseur du regard, change d'humeur (endormi la nuit, comblé, curieux en aventure),
part explorer les ploxions, se nourrit d'une douceur, débloque des accessoires, et
réagit aux vrais tsoins captés. Ciel pastel, cartes blanches arrondies — l'opposé ASSUMÉ
du néon du reste du xer. Zéro LLM, déterministe, marche seul sur /local (jOSGame/jOSBoxion
optionnels). window.jOSApps['compagnon']. --}}
<style>
.px-comp{display:flex;flex-direction:column;height:100%;overflow:hidden;
font-family:ui-rounded,'SF Pro Rounded',system-ui,-apple-system,'Segoe UI',sans-serif;
color:#3d4a5c;background:linear-gradient(#bfe4ff 0%,#d5efff 32%,#eaf7e0 66%,#dff1c9 100%);}
.px-comp *{box-sizing:border-box;}
.px-comp .comp-scroll{flex:1;overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;padding:14px 14px 18px;}
/* Bandeau : nom éditable + humeur + niveau */
.px-comp .comp-head{display:flex;align-items:center;gap:10px;margin:2px 2px 12px;}
.px-comp .comp-id{flex:1;min-width:0;}
.px-comp .comp-name{font-size:1.28rem;font-weight:800;color:#38506b;cursor:pointer;
display:inline-flex;align-items:center;gap:6px;line-height:1.1;}
.px-comp .comp-name .pen{font-size:.78rem;opacity:.45;}
.px-comp .comp-mood{font-size:.82rem;color:#6a86a0;margin-top:2px;}
.px-comp .comp-lvl{flex-shrink:0;text-align:right;background:rgba(255,255,255,.72);
border-radius:16px;padding:7px 12px;box-shadow:0 3px 10px rgba(90,130,160,.14);}
.px-comp .comp-lvl b{display:block;font-size:1.05rem;color:#5a7d4a;}
.px-comp .comp-lvl small{font-size:.66rem;color:#8aa0b4;letter-spacing:.04em;}
/* Scène ciel : nuages + créature + prairie */
.px-comp .comp-stage{position:relative;height:210px;border-radius:24px;overflow:hidden;
background:linear-gradient(#a9dcff 0%,#c9ecff 55%,#e7f7d2 100%);
box-shadow:inset 0 -2px 0 rgba(255,255,255,.5),0 6px 18px rgba(110,150,180,.16);margin-bottom:16px;
transition:background .8s ease;}
.px-comp .comp-stage.night{background:linear-gradient(#2b3358 0%,#3f4a78 52%,#4c5a5e 100%);}
.px-comp .cloud{position:absolute;background:#fff;border-radius:50px;opacity:.9;
box-shadow:22px 6px 0 -6px #fff,-22px 6px 0 -4px #fff;will-change:transform;}
.px-comp .cloud.c1{width:52px;height:20px;top:22px;left:24px;}
.px-comp .cloud.c2{width:40px;height:15px;top:44px;right:30px;}
.px-comp .cloud.c3{width:34px;height:13px;top:14px;right:64px;opacity:.75;}
.px-comp .comp-stage.night .cloud{opacity:.28;}
.px-comp .sun{position:absolute;top:16px;right:18px;width:40px;height:40px;border-radius:50%;
background:radial-gradient(circle,#fff3bf 0%,#ffe08a 70%,rgba(255,224,138,0) 72%);transition:opacity .8s ease;}
.px-comp .comp-stage.night .sun{background:radial-gradient(circle,#fff 0%,#dfe6ff 62%,rgba(223,230,255,0) 66%);
width:26px;height:26px;box-shadow:0 0 0 2px rgba(255,255,255,.12);}
.px-comp .star{position:absolute;width:3px;height:3px;border-radius:50%;background:#fff;opacity:0;
transition:opacity .8s ease;}
.px-comp .comp-stage.night .star{opacity:.85;animation:comp-twinkle 3.2s ease-in-out infinite;}
@keyframes comp-twinkle{0%,100%{opacity:.35}50%{opacity:.9}}
.px-comp .hill{position:absolute;left:-10%;right:-10%;border-radius:50%;transition:filter .8s ease;}
.px-comp .hill.h1{bottom:-46px;height:88px;background:#bfe89a;}
.px-comp .hill.h2{bottom:-58px;height:96px;left:-30%;width:80%;background:#a9df84;}
.px-comp .hill.h3{bottom:-58px;height:96px;right:-30%;left:auto;width:80%;background:#a9df84;}
.px-comp .comp-stage.night .hill{filter:brightness(.62) saturate(.7);}
.px-comp .bush{position:absolute;bottom:4px;width:46px;height:30px;border-radius:24px 24px 0 0;
background:#8ed06b;box-shadow:14px 4px 0 -4px #8ed06b,-14px 4px 0 -4px #8ed06b;transition:filter .8s ease;}
.px-comp .bush.b1{left:18px;}
.px-comp .bush.b2{right:22px;width:38px;height:26px;background:#9bd97a;box-shadow:12px 4px 0 -4px #9bd97a,-12px 4px 0 -4px #9bd97a;}
.px-comp .comp-stage.night .bush{filter:brightness(.6) saturate(.7);}
/* La créature = un CUBE 3D (zone tapable = câlin) : scène en perspective, cube preserve-3d,
6 faces ; frimousse sur avant/droite/gauche, glyphe discret sur dos/haut/bas. */
.px-comp .comp-hug{position:absolute;left:50%;bottom:6px;transform:translateX(-50%);
width:168px;height:200px;cursor:pointer;-webkit-tap-highlight-color:transparent;}
.px-comp .comp-scene{position:absolute;left:50%;top:34px;transform:translateX(-50%);
width:120px;height:120px;perspective:600px;perspective-origin:50% 42%;}
.px-comp .cube-tilt{position:relative;width:100%;height:100%;transform-style:preserve-3d;
transform:rotateX(-12deg);}
.px-comp .cube-bob{position:relative;width:100%;height:100%;transform-style:preserve-3d;
animation:comp-bob 5.4s ease-in-out infinite;}
.px-comp .cube{position:relative;width:100%;height:100%;transform-style:preserve-3d;
animation:comp-spin 18s linear infinite;}
.px-comp .cube-face{position:absolute;width:120px;height:120px;border-radius:26px;
backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:visible;
border:1px solid rgba(255,255,255,.5);
box-shadow:inset 0 7px 15px rgba(255,255,255,.6),inset 0 -12px 20px rgba(210,150,120,.3),
0 8px 16px rgba(180,130,110,.2);}
.px-comp .cube-face .face-svg,.px-comp .cube-face .glyph-svg{width:100%;height:100%;display:block;overflow:visible;}
.px-comp .cube-front{background:radial-gradient(circle at 50% 40%,#fff3ec,#ffd9c2 82%);transform:rotateY(0deg) translateZ(60px);}
.px-comp .cube-right{background:radial-gradient(circle at 50% 40%,#ffe7d7,#f6c8ad 88%);transform:rotateY(90deg) translateZ(60px);}
.px-comp .cube-left{background:radial-gradient(circle at 50% 40%,#ffe7d7,#f6c8ad 88%);transform:rotateY(-90deg) translateZ(60px);}
.px-comp .cube-back{background:radial-gradient(circle at 50% 40%,#ffe1cf,#f2c2a4 88%);transform:rotateY(180deg) translateZ(60px);}
.px-comp .cube-top{background:radial-gradient(circle at 50% 50%,#fff7f1,#ffe3d1 90%);transform:rotateX(90deg) translateZ(60px);}
.px-comp .cube-bottom{background:radial-gradient(circle at 50% 50%,#f5cbb1,#e7b294 90%);transform:rotateX(-90deg) translateZ(60px);}
.px-comp .cube-shadow{position:absolute;left:50%;bottom:10px;width:100px;height:17px;border-radius:50%;
transform:translateX(-50%);
background:radial-gradient(ellipse at center,rgba(70,110,70,.24),rgba(70,110,70,0) 72%);
animation:comp-cshadow 5.4s ease-in-out infinite;}
.px-comp .comp-eyes{transform-box:fill-box;transform-origin:center;
animation:comp-blink 5.4s ease-in-out infinite;}
.px-comp .comp-pupils{transition:transform .14s ease-out;}
.px-comp .comp-zzz{transform-box:fill-box;transform-origin:center;opacity:0;
animation:comp-zzz 3.2s ease-in-out infinite;}
.px-comp .comp-hug.boop{animation:comp-boop .5s ease;}
@keyframes comp-spin{from{transform:rotateY(0deg)}to{transform:rotateY(360deg)}}
@keyframes comp-bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-10px)}}
@keyframes comp-cshadow{0%,100%{transform:translateX(-50%) scale(1);opacity:.9}50%{transform:translateX(-50%) scale(.82);opacity:.6}}
@keyframes comp-blink{0%,90%,100%{transform:scaleY(1)}95%{transform:scaleY(.08)}}
@keyframes comp-zzz{0%{opacity:0;transform:translate(0,3px) scale(.7)}30%{opacity:.9}
100%{opacity:0;transform:translate(5px,-16px) scale(1.1)}}
@keyframes comp-boop{0%{transform:translateX(-50%) scale(1)}30%{transform:translateX(-50%) scale(1.11) translateY(-5px)}
60%{transform:translateX(-50%) scale(.97)}100%{transform:translateX(-50%) scale(1)}}
/* Cube DJ : petit scale sur chaque temps (couche dédiée, ne touche ni tilt ni spin). */
.px-comp .cube-beat{position:relative;width:100%;height:100%;transform-style:preserve-3d;
transition:transform .12s ease;}
.px-comp .cube-beat.beat{transform:scale(1.07);}
/* Barre DJ (haut-gauche) : bouton principal (Spotify) + secours lo-fi */
.px-comp .comp-djbar{position:absolute;top:10px;left:10px;z-index:4;display:flex;gap:6px;
align-items:center;max-width:calc(100% - 20px);}
.px-comp .comp-dj{min-height:44px;padding:0 12px;border:0;border-radius:15px;background:rgba(255,255,255,.82);
color:#7a6aa8;font-family:inherit;font-weight:800;font-size:.82rem;cursor:pointer;display:inline-flex;
align-items:center;gap:6px;white-space:nowrap;box-shadow:0 3px 10px rgba(90,110,160,.2);
-webkit-tap-highlight-color:transparent;transition:background .2s ease,color .2s ease;}
.px-comp .comp-dj.on{background:#b6a4ef;color:#fff;box-shadow:0 4px 12px rgba(150,120,220,.4);}
.px-comp .comp-stage.night .comp-dj{background:rgba(60,70,110,.72);color:#dfe6ff;}
.px-comp .comp-stage.night .comp-dj.on{background:#b6a4ef;color:#fff;}
.px-comp .comp-lofi{min-height:44px;padding:0 10px;border:0;border-radius:13px;background:rgba(255,255,255,.68);
color:#8aa0b4;font-family:inherit;font-weight:700;font-size:.72rem;cursor:pointer;white-space:nowrap;
box-shadow:0 2px 8px rgba(90,110,160,.16);-webkit-tap-highlight-color:transparent;
transition:background .2s ease,color .2s ease;}
.px-comp .comp-lofi.on{background:#8ed06b;color:#fff;}
.px-comp .comp-stage.night .comp-lofi{background:rgba(60,70,110,.62);color:#c4cfe6;}
.px-comp .comp-stage.night .comp-lofi.on{background:#8ed06b;color:#fff;}
/* Now playing + mini-transport (bas de la scène), visible quand un player est branché */
.px-comp .comp-np{position:absolute;left:8px;right:8px;bottom:6px;z-index:4;display:none;
align-items:center;gap:4px;padding:4px 6px;border-radius:14px;background:rgba(255,255,255,.88);
box-shadow:0 4px 12px rgba(90,110,160,.2);}
.px-comp .comp-stage.dj-live .comp-np{display:flex;}
.px-comp .comp-stage.dj-live .comp-hint{display:none;}
.px-comp .comp-np .np-txt{flex:1;min-width:0;font-size:.74rem;color:#4a4368;font-weight:700;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-left:4px;}
.px-comp .comp-np .np-btn{flex-shrink:0;width:44px;height:44px;border:0;background:transparent;
color:#5a4f7a;font-size:1.02rem;cursor:pointer;border-radius:12px;display:flex;align-items:center;
justify-content:center;-webkit-tap-highlight-color:transparent;}
.px-comp .comp-np .np-btn.mid{background:#b6a4ef;color:#fff;border-radius:50%;}
.px-comp .comp-np .np-btn:active{transform:scale(.94);}
.px-comp .comp-stage.night .comp-np{background:rgba(40,48,80,.9);}
.px-comp .comp-stage.night .comp-np .np-txt{color:#e6ecff;}
.px-comp .comp-stage.night .comp-np .np-btn{color:#cdd6f2;}
.px-comp .comp-stage.night .comp-np .np-btn.mid{background:#b6a4ef;color:#fff;}
/* Barres d'EQ (visibles seulement quand le son tourne) */
.px-comp .comp-eq{position:absolute;left:50%;bottom:24px;transform:translateX(-50%);z-index:3;
display:none;gap:3px;align-items:flex-end;height:20px;pointer-events:none;}
.px-comp .comp-stage.dj-playing .comp-eq{display:flex;}
.px-comp .comp-eq i{display:block;width:4px;height:100%;border-radius:2px;transform-origin:bottom center;
transform:scaleY(.3);background:linear-gradient(#c9b6ff,#8ed06b);animation:comp-eq .9s ease-in-out infinite;}
.px-comp .comp-eq i:nth-child(2){animation-duration:.7s;animation-delay:.10s;}
.px-comp .comp-eq i:nth-child(3){animation-duration:1.1s;animation-delay:.05s;}
.px-comp .comp-eq i:nth-child(4){animation-duration:.6s;animation-delay:.15s;}
.px-comp .comp-eq i:nth-child(5){animation-duration:.85s;animation-delay:.20s;}
@keyframes comp-eq{0%,100%{transform:scaleY(.28)}50%{transform:scaleY(1)}}
/* Bulle de dialogue de l'oracle-cube (au-dessus du cube) */
.px-comp .comp-bubble{position:absolute;left:50%;top:6px;transform:translateX(-50%);z-index:5;
max-width:86%;background:rgba(255,255,255,.94);border-radius:15px;padding:8px 12px 9px;
text-align:center;pointer-events:none;opacity:0;transition:opacity .5s ease;
box-shadow:0 6px 16px rgba(90,110,160,.2);}
.px-comp .comp-bubble.show{opacity:1;}
.px-comp .comp-bubble:after{content:'';position:absolute;left:50%;bottom:-7px;transform:translateX(-50%);
border:7px solid transparent;border-bottom:0;border-top-color:rgba(255,255,255,.94);}
.px-comp .comp-bubble .bt{font-size:.82rem;line-height:1.25;color:#4a4368;font-weight:600;font-style:italic;}
.px-comp .comp-bubble .bs{display:block;margin-top:3px;font-size:.64rem;letter-spacing:.02em;color:#9a8fb8;}
.px-comp .comp-stage.night .comp-bubble{background:rgba(40,48,80,.92);}
.px-comp .comp-stage.night .comp-bubble:after{border-top-color:rgba(40,48,80,.92);}
.px-comp .comp-stage.night .comp-bubble .bt{color:#e6ecff;}
.px-comp .comp-stage.night .comp-bubble .bs{color:#b3a9d6;}
.px-comp .float{position:absolute;left:50%;bottom:120px;font-size:1.4rem;pointer-events:none;
transform:translate(-50%,0);animation:comp-rise 1.15s ease-out forwards;}
@keyframes comp-rise{0%{transform:translate(-50%,0) scale(.5);opacity:0}
18%{opacity:1}100%{transform:translate(-50%,-96px) scale(1.15);opacity:0}}
.px-comp .comp-hint{position:absolute;left:0;right:0;bottom:6px;text-align:center;
font-size:.68rem;color:rgba(70,100,80,.55);transition:color .8s ease;}
.px-comp .comp-stage.night .comp-hint{color:rgba(220,230,255,.6);}
/* Barre de progression du jour */
.px-comp .comp-prog{margin:0 2px 12px;}
.px-comp .comp-prog .lab{display:flex;justify-content:space-between;font-size:.74rem;color:#6f8aa0;margin-bottom:5px;}
.px-comp .comp-prog .lab b{color:#5a7d4a;}
.px-comp .comp-track{height:12px;border-radius:8px;background:rgba(255,255,255,.6);overflow:hidden;
box-shadow:inset 0 1px 3px rgba(90,120,150,.18);}
.px-comp .comp-fill{height:100%;border-radius:8px;background:linear-gradient(90deg,#9be08a,#7fd0a6);
transition:width .5s cubic-bezier(.2,.9,.3,1);width:0;}
/* Titres de section */
.px-comp .comp-h{font-size:.72rem;text-transform:uppercase;letter-spacing:.12em;color:#7f97ac;
font-weight:700;margin:4px 4px 8px;}
/* Cartes blanches rondes */
.px-comp .card{display:flex;align-items:center;gap:12px;background:#fff;border-radius:18px;
padding:12px 13px;margin-bottom:10px;box-shadow:0 4px 14px rgba(110,145,175,.14);
cursor:pointer;transition:transform .18s ease,opacity .3s ease,background .3s ease;
min-height:56px;-webkit-tap-highlight-color:transparent;}
.px-comp .card:active{transform:scale(.985);}
.px-comp .card .ic{flex-shrink:0;width:42px;height:42px;border-radius:50%;display:flex;
align-items:center;justify-content:center;font-size:1.18rem;}
.px-comp .card .tx{flex:1;min-width:0;}
.px-comp .card .tx b{display:block;font-size:.96rem;color:#3f4f61;font-weight:700;}
.px-comp .card .tx small{display:block;font-size:.74rem;color:#93a6b6;margin-top:1px;}
.px-comp .card .pts{flex-shrink:0;font-size:.74rem;font-weight:700;color:#e0a94a;margin-right:2px;white-space:nowrap;}
.px-comp .card .chk{flex-shrink:0;width:30px;height:30px;border-radius:50%;border:2px solid #cdddc6;
background:#f4faf0;display:flex;align-items:center;justify-content:center;color:transparent;
font-size:1rem;font-weight:800;transition:all .2s ease;}
.px-comp .card.done{background:#f1faec;opacity:.92;}
.px-comp .card.done .tx b{color:#6f8f5c;}
.px-comp .card.done .chk{background:#8ed06b;border-color:#8ed06b;color:#fff;}
.px-comp .card.done .tx b{text-decoration:line-through;text-decoration-color:rgba(120,150,100,.5);}
/* Carte soin : bonheur + douceur + garde-robe */
.px-comp .care{background:#fff;border-radius:20px;padding:14px;margin-bottom:14px;
box-shadow:0 4px 14px rgba(110,145,175,.14);}
.px-comp .care .care-lab{display:flex;justify-content:space-between;font-size:.76rem;color:#6f8aa0;margin-bottom:6px;}
.px-comp .care .care-lab b{color:#e0678f;}
.px-comp .care-track{height:12px;border-radius:8px;background:#fbeef3;overflow:hidden;
box-shadow:inset 0 1px 3px rgba(150,90,120,.14);}
.px-comp .care-fill{height:100%;border-radius:8px;background:linear-gradient(90deg,#ffb3c8,#ff8fb3);
width:0;transition:width .5s cubic-bezier(.2,.9,.3,1);}
.px-comp .wardrobe{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px;}
.px-comp .chip{display:inline-flex;align-items:center;gap:5px;padding:7px 11px;border-radius:14px;
background:#f4f7fb;font-size:.78rem;color:#5b7088;cursor:pointer;border:2px solid transparent;
transition:all .18s ease;-webkit-tap-highlight-color:transparent;}
.px-comp .chip.on{background:#eafaf0;border-color:#8ed06b;color:#4f7d3c;}
.px-comp .chip.lock{opacity:.62;cursor:default;}
.px-comp .chip .cx{font-size:1rem;}
/* Carte aventure */
.px-comp .adv{background:linear-gradient(135deg,#fff 0%,#fdf6ff 100%);border-radius:20px;
padding:15px;box-shadow:0 5px 16px rgba(130,120,170,.16);margin-bottom:14px;}
.px-comp .adv .aline{display:flex;align-items:center;gap:10px;}
.px-comp .adv .aic{width:44px;height:44px;border-radius:50%;background:#efe6ff;display:flex;
align-items:center;justify-content:center;font-size:1.3rem;flex-shrink:0;}
.px-comp .adv .atx{flex:1;min-width:0;}
.px-comp .adv .atx b{display:block;color:#5a4f7a;font-size:.95rem;}
.px-comp .adv .atx small{display:block;color:#9d94b8;font-size:.76rem;margin-top:2px;}
.px-comp .adv .clock{font-variant-numeric:tabular-nums;font-weight:800;color:#7a6aa8;font-size:1.02rem;}
.px-comp .btn{display:block;width:100%;margin-top:12px;padding:13px;border:0;border-radius:14px;
background:#8ed06b;color:#fff;font-weight:800;font-size:.95rem;cursor:pointer;
box-shadow:0 4px 12px rgba(120,190,100,.35);min-height:48px;font-family:inherit;}
.px-comp .btn.lav{background:#b6a4ef;box-shadow:0 4px 12px rgba(150,120,220,.32);}
.px-comp .btn.treat{background:#ffb0c4;box-shadow:0 4px 12px rgba(240,140,170,.34);}
.px-comp .btn:active{transform:scale(.99);}
.px-comp .adv .reward{margin-top:11px;background:#faf6ff;border-radius:14px;padding:10px 12px;
font-size:.84rem;color:#6a5f8c;line-height:1.4;}
/* Pied : phrase douce qui tourne */
.px-comp .comp-foot{flex-shrink:0;padding:11px 14px;text-align:center;font-size:.82rem;
color:#6a86a0;background:rgba(255,255,255,.5);border-top:1px solid rgba(255,255,255,.7);
min-height:42px;display:flex;align-items:center;justify-content:center;}
.px-comp .comp-foot span{transition:opacity .5s ease;}
@media (prefers-reduced-motion: reduce){
.px-comp .cube,.px-comp .cube-bob,.px-comp .cube-shadow,.px-comp .comp-eq i,
.px-comp .comp-eyes,.px-comp .comp-hug.boop,.px-comp .comp-zzz,.px-comp .star{animation:none!important;}
.px-comp .comp-eq i{transform:scaleY(.6)!important;}
.px-comp .cube-beat,.px-comp .comp-bubble{transition:none!important;}
.px-comp .comp-pupils{transition:none!important;}
.px-comp .float{animation:none!important;opacity:0;}
.px-comp .comp-fill,.px-comp .care-fill,.px-comp .comp-foot span{transition:none!important;}
}
/* ===== SKIN CHILL-TEKK (rs-4, RS-7 « rends-le plus chill-tekk ») — sombre + teal, tokens --xr-*,
override du pastel/clair. On garde le perso & la logique de cloudion, on re-teinte seulement. ===== */
.px-comp{background:var(--xr-bg,#080b12)!important;color:var(--xr-text,#dbe7f7)!important;font-family:var(--xr-font-ui,ui-rounded,system-ui,sans-serif);}
.px-comp .comp-name{color:var(--xr-text,#eaf3ff)!important;}
.px-comp .comp-mood,.px-comp .comp-hint,.px-comp .comp-h{color:var(--xr-muted,#7f93c8)!important;}
.px-comp .comp-lvl{background:var(--xr-panel,rgba(16,26,44,.82))!important;border:1px solid var(--xr-border,rgba(95,224,192,.22));box-shadow:0 0 16px rgba(95,224,192,.08)!important;}
.px-comp .comp-lvl b{color:var(--xr-accent,#5fe0c0)!important;} .px-comp .comp-lvl small{color:var(--xr-muted,#7f93c8)!important;}
/* scène : nuit chill-tekk teal, toujours + grille tech discrète + glow */
.px-comp .comp-stage{background:linear-gradient(#071119 0%,#0a2028 52%,#0b1622 100%)!important;box-shadow:inset 0 0 70px rgba(95,224,192,.06),0 6px 22px rgba(0,0,0,.55)!important;}
.px-comp .comp-stage::after{content:'';position:absolute;inset:0;pointer-events:none;z-index:0;
background-image:linear-gradient(rgba(95,224,192,.05) 1px,transparent 1px),linear-gradient(90deg,rgba(95,224,192,.05) 1px,transparent 1px);background-size:22px 22px;}
.px-comp .comp-stage .cloud{opacity:.12!important;background:rgba(150,205,220,.5)!important;box-shadow:22px 6px 0 -6px rgba(150,205,220,.4),-22px 6px 0 -4px rgba(150,205,220,.4)!important;}
.px-comp .comp-stage .sun{background:radial-gradient(circle,#e6fff8 0%,#5fe0c0 60%,rgba(95,224,192,0) 66%)!important;box-shadow:0 0 22px rgba(95,224,192,.45)!important;}
.px-comp .comp-stage .star{opacity:.7!important;background:var(--xr-accent,#8fe0d0)!important;animation:comp-twinkle 3.2s ease-in-out infinite;}
.px-comp .comp-stage .hill,.px-comp .comp-stage .bush{filter:brightness(.5) saturate(.55) hue-rotate(120deg)!important;}
.px-comp .comp-scene,.px-comp .cube,.px-comp .cube-tilt{filter:drop-shadow(0 0 12px rgba(95,224,192,.28));}
/* cartes / objectifs / soin / bulle → panneaux sombres + liseré teal */
.px-comp .card,.px-comp .care,.px-comp .comp-np,.px-comp .comp-bubble,.px-comp .wardrobe,.px-comp .adv{
background:var(--xr-panel,rgba(14,22,38,.85))!important;color:var(--xr-text,#dbe7f7)!important;
border:1px solid var(--xr-border,rgba(95,224,192,.16))!important;box-shadow:none!important;}
.px-comp .card.done{background:var(--xr-panel,rgba(20,40,34,.8))!important;border-color:var(--xr-accent,rgba(95,224,192,.4))!important;}
.px-comp .comp-bubble{color:var(--xr-text,#e7f2ff)!important;}
/* boutons / chips / DJ / lo-fi → dark + teal, actifs en accent */
.px-comp .btn,.px-comp .comp-dj,.px-comp .comp-lofi,.px-comp .chip{background:var(--xr-panel,rgba(20,34,52,.82))!important;color:var(--xr-text,#dbe7f7)!important;border:1px solid var(--xr-border,rgba(95,224,192,.28))!important;}
.px-comp .btn.on,.px-comp .comp-dj.on,.px-comp .chip.on{background:var(--xr-accent,#5fe0c0)!important;color:#04120e!important;border:0!important;font-weight:800;}
/* barres de progression → gradient teal */
.px-comp .comp-track,.px-comp .care-track{background:var(--xr-panel,rgba(20,32,48,.7))!important;}
.px-comp .comp-fill,.px-comp .care-fill{background:linear-gradient(90deg,var(--xr-accent,#5fe0c0),var(--xr-accent2,#8a7dff))!important;}
</style>
<script>
(function () {
'use strict';
var KEY = 'jos:compagnon';
// Petits helpers (marchent sans jOSb).
function esc(s){ try{ if(window.jOSb&&window.jOSb.esc) return window.jOSb.esc(s); }catch(e){}
var d=document.createElement('div'); d.textContent = s==null?'':s; return d.innerHTML; }
function today(){ var d=new Date(); return d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate(); }
function load(){ try{ var v=localStorage.getItem(KEY); return v?JSON.parse(v):null; }catch(e){ return null; } }
function persist(st){
try{ localStorage.setItem(KEY, JSON.stringify(st)); }catch(e){}
try{ if(window.jOSBoxion&&window.jOSBoxion.saveSoon) window.jOSBoxion.saveSoon('compagnon','state',st,'Compagnon',900); }catch(e){}
}
var REDUCE = false;
try { REDUCE = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch(e){}
// Contenu déterministe (zéro LLM).
var GOALS = [
{ id:'respire', ic:'🫧', bg:'#dff0ff', label:'Respire un instant', sub:'trois respirations lentes' },
{ id:'tsoin', ic:'⧗', bg:'#efe6ff', label:'Capte un tsoin', sub:'un moment doux à garder' },
{ id:'ploxion', ic:'▣', bg:'#e6f6ea', label:'Ouvre un ploxion', sub:'explore le xerboxion' },
{ id:'eau', ic:'💧', bg:'#e0f4ff', label:'Bois de l\'eau', sub:'un grand verre, tout frais' },
{ id:'idee', ic:'💡', bg:'#fff2d9', label:'Note une idée', sub:'même une toute minuscule' },
{ id:'douceur', ic:'🌸', bg:'#ffe6ee', label:'Fais-toi une douceur', sub:'une petite chose gentille' }
];
// Oracle-cube : phrases cryptiques tirées des papiers (chargées depuis /data/papers-cryptic.json ;
// ce tableau est le fallback en dur si le fetch échoue). { t: la phrase, src: le papier/§ }.
var CRYPTIC_FALLBACK = [
{ t:'ON plus I égale ION. Le chaos observé devient réel.', src:'Grammaire ionique §1' },
{ t:'Le tsoin n\'est pas ce qui reste — c\'est le résidu qui régénère le tout.', src:'Adressage Génératif §0' },
{ t:'Comprimer, c\'est faire de la place pour sauter.', src:'Machine à jump §1' },
{ t:'Le temps est la cohérence des choses entre elles.', src:'Carte 4D §2' },
{ t:'La forme d\'une chose est déjà sa nature.', src:'Grammaire des glyphes §1' }
];
var TRIPS = [
'a rapporté un koin tout brillant ✨',
'a retrouvé un vieux tsoin oublié ⧗',
'a visité trois ploxions et t\'envoie un bonjour',
'a rencontré un petit wormion tout rond ○',
'revient les bras pleins de fleurs de prairie 🌼',
'a rangé un bion égaré, tout propre maintenant'
];
// Accessoires déblocables par XP (persistés, rendus sur la créature).
var ACC = [
{ id:'chapeau', ic:'🎩', name:'petit chapeau', xp:60 },
{ id:'lunettes', ic:'🕶️', name:'lunettes wormion', xp:150 },
{ id:'noeud', ic:'🎀', name:'nœud tout doux', xp:300 }
];
var ADV_MS = 20 * 60 * 1000; // aventure douce de 20 minutes
// --- Bibou = un CUBE 3D CSS (« un cube avec une tête sur 3 faces »). On garde les briques
// d'expression (buildEyes/buildMouth) et les accessoires (buildAcc) pour dessiner LA MÊME
// frimousse sur les faces avant/droite/gauche ; le dos/haut/bas portent un glyphe discret
// (koin triangle / wormion ronds imbriqués). Le cube tourne lentement + flotte, ombre au sol.
function buildEyes(mood){
if (mood === 'sleep')
return '<path d="M74 112 Q82 118 90 112" fill="none" stroke="#3d4a5c" stroke-width="3.2" stroke-linecap="round"/>'
+ '<path d="M110 112 Q118 118 126 112" fill="none" stroke="#3d4a5c" stroke-width="3.2" stroke-linecap="round"/>';
if (mood === 'happy')
return '<path d="M73 115 Q82 105 91 115" fill="none" stroke="#3d4a5c" stroke-width="3.4" stroke-linecap="round"/>'
+ '<path d="M109 115 Q118 105 127 115" fill="none" stroke="#3d4a5c" stroke-width="3.4" stroke-linecap="round"/>';
// content / curieux : yeux ouverts, pupilles qui suivent + reflet
return '<g class="comp-eyes">'
+ '<ellipse cx="82" cy="112" rx="9" ry="10.5" fill="#fff"/>'
+ '<ellipse cx="118" cy="112" rx="9" ry="10.5" fill="#fff"/>'
+ '<g class="comp-pupils">'
+ '<circle cx="82" cy="113" r="6" fill="#3d4a5c"/><circle cx="84.4" cy="110.3" r="2.1" fill="#fff"/>'
+ '<circle cx="118" cy="113" r="6" fill="#3d4a5c"/><circle cx="120.4" cy="110.3" r="2.1" fill="#fff"/>'
+ '</g></g>';
}
function buildMouth(mood){
if (mood === 'happy')
return '<path d="M84 129 Q100 149 116 129 Q100 141 84 129 Z" fill="#c9738a"/>'
+ '<path d="M92 138 Q100 143 108 138" fill="#ff9db0" opacity="0.9"/>';
if (mood === 'curious')
return '<ellipse cx="100" cy="133" rx="5.2" ry="6.4" fill="#c98a72"/>';
if (mood === 'sleep')
return '<path d="M93 132 Q100 137 107 132" fill="none" stroke="#c98a72" stroke-width="2.6" stroke-linecap="round"/>';
// content
return '<path d="M90 129 Q100 139 110 129" fill="none" stroke="#c98a72" stroke-width="3" stroke-linecap="round"/>';
}
function buildAcc(acc){
acc = acc || {};
var s = '';
if (acc.noeud) // nœud tout doux, posé sur le côté de la tête
s += '<g><path d="M132 82 l-13 -7 v14 z" fill="#ff9ec2"/><path d="M132 82 l13 -7 v14 z" fill="#ff9ec2"/>'
+ '<circle cx="132" cy="82" r="3.6" fill="#ff77aa"/></g>';
if (acc.chapeau) // petit haut-de-forme
s += '<g><path d="M84 60 h32 v-13 a4 4 0 0 0 -4 -4 h-24 a4 4 0 0 0 -4 4 z" fill="#8a78c0"/>'
+ '<rect x="83" y="52" width="34" height="5" rx="1.5" fill="#f4c95d"/>'
+ '<rect x="76" y="60" width="48" height="7" rx="3.5" fill="#7a6aa8"/></g>';
if (acc.lunettes) // lunettes wormion (ronds imbriqués)
s += '<g fill="none" stroke="#6a5f8c" stroke-width="2.4">'
+ '<circle cx="82" cy="112" r="12"/><circle cx="82" cy="112" r="7" stroke="#a99ad6"/>'
+ '<circle cx="118" cy="112" r="12"/><circle cx="118" cy="112" r="7" stroke="#a99ad6"/>'
+ '<path d="M94 112 h12"/></g>';
return s;
}
// Une frimousse (joues + yeux + bouche) pour une face du cube, dans une viewBox centrée sur la
// tête. withAcc = face avant → porte aussi les accessoires (overflow visible = ils débordent
// joliment au-dessus de la face). Zzz posés en haut à droite quand il dort.
function faceArt(mood, withAcc, acc){
var zzz = (mood === 'sleep')
? '<text class="comp-zzz" x="150" y="86" font-size="15" font-weight="800" fill="#8aa0c4">z</text>'
+ '<text class="comp-zzz" x="160" y="74" font-size="19" font-weight="800" fill="#8aa0c4" style="animation-delay:.9s">z</text>'
: '';
return '<svg class="face-svg" viewBox="40 62 120 120" role="img" aria-label="frimousse">'
+ '<circle cx="70" cy="126" r="9.5" fill="#ffb3c1" opacity="0.85"/>'
+ '<circle cx="130" cy="126" r="9.5" fill="#ffb3c1" opacity="0.85"/>'
+ buildEyes(mood)
+ buildMouth(mood)
+ (withAcc ? buildAcc(acc || {}) : '')
+ zzz
+ '</svg>';
}
// Glyphe discret pour une face « dos »/haut/bas (pastel uni + trait doux).
function glyphArt(kind){
if (kind === 'koin') // triangle doux (koin)
return '<svg class="glyph-svg" viewBox="0 0 120 120" aria-hidden="true">'
+ '<polygon points="60,42 84,80 36,80" fill="none" stroke="#e0a982" stroke-width="4"'
+ ' stroke-linejoin="round" opacity="0.5"/></svg>';
// wormion : ronds imbriqués
return '<svg class="glyph-svg" viewBox="0 0 120 120" aria-hidden="true">'
+ '<circle cx="60" cy="60" r="27" fill="none" stroke="#e0a982" stroke-width="4" opacity="0.48"/>'
+ '<circle cx="60" cy="60" r="14" fill="none" stroke="#e0a982" stroke-width="4" opacity="0.38"/></svg>';
}
// Structure du cube, bâtie UNE SEULE FOIS (la rotation ne redémarre donc jamais). Les 3 faces à
// frimousse ont un conteneur [data-art] rempli/mis à jour par paintCreature ; dos/haut/bas fixes.
function buildCube(){
return '<div class="cube-shadow"></div>'
+ '<div class="comp-scene"><div class="cube-beat"><div class="cube-tilt"><div class="cube-bob">'
+ '<div class="cube" data-cube>'
+ '<div class="cube-face cube-front" data-art="front"></div>'
+ '<div class="cube-face cube-right" data-art="right"></div>'
+ '<div class="cube-face cube-left" data-art="left"></div>'
+ '<div class="cube-face cube-back">' + glyphArt('wormion') + '</div>'
+ '<div class="cube-face cube-top">' + glyphArt('koin') + '</div>'
+ '<div class="cube-face cube-bottom">' + glyphArt('wormion') + '</div>'
+ '</div></div></div></div></div>';
}
function mount(container, ctx) {
// ---- État (chargé + reset quotidien des objectifs) ---------------------------------------
var st = load() || {};
if (typeof st.name !== 'string' || !st.name) st.name = 'Bibou';
if (typeof st.happy !== 'number') st.happy = 0;
if (typeof st.xp !== 'number') st.xp = 0;
if (typeof st.wi !== 'number') st.wi = 0; // index mot doux (déterministe)
if (typeof st.trips !== 'number') st.trips = 0; // aventures accomplies
if (typeof st.memories !== 'number') st.memories = 0; // souvenirs (tsoins captés)
if (!st.acc || typeof st.acc !== 'object') st.acc = {}; // accessoires équipés
if (typeof st.dj !== 'boolean') st.dj = false; // musique DJ (off par défaut)
if (!st.adv) st.adv = { until: 0 };
if (st.day !== today() || !st.goals) { st.day = today(); st.goals = {}; }
persist(st);
var timers = [];
var djTimers = []; // timeouts des pulses visuels du beat (nettoyés à l'arrêt du son)
var listeners = [];
var lastMood = null;
var audio = null; // moteur Web Audio lo-fi (SECOURS, créé au play, fermé au stop / unmount)
var danceTimer = null; // pouls temporel qui fait danser le cube quand ça joue
var soundUnsub = null; // désabonnement jOSSound
var busHandler = null; // handler du bus spotify/track (retiré au unmount)
var busTrack = null; // dernier {title,artist,paused} reçu en live du bus
// ---- Squelette --------------------------------------------------------------------------
container.innerHTML =
'<div class="px-comp">'
+ '<div class="comp-scroll">'
+ '<div class="comp-head">'
+ '<div class="comp-id">'
+ '<div class="comp-name" data-name></div>'
+ '<div class="comp-mood" data-mood></div>'
+ '</div>'
+ '<div class="comp-lvl"><b data-lvl>1</b><small data-xp>0 pts</small></div>'
+ '</div>'
+ '<div class="comp-stage" data-stage>'
+ '<div class="sun"></div>'
+ '<div class="star" style="top:20px;left:40px"></div><div class="star" style="top:34px;left:78px"></div>'
+ '<div class="star" style="top:16px;left:120px"></div><div class="star" style="top:46px;left:150px"></div>'
+ '<div class="cloud c1"></div><div class="cloud c2"></div><div class="cloud c3"></div>'
+ '<div class="hill h2"></div><div class="hill h3"></div><div class="hill h1"></div>'
+ '<div class="bush b1"></div><div class="bush b2"></div>'
+ '<div class="comp-djbar">'
+ '<button class="comp-dj" data-dj type="button" aria-pressed="false">♪ mettre le son</button>'
+ '<button class="comp-lofi" data-lofi type="button" aria-pressed="false">lo-fi</button>'
+ '</div>'
+ '<div class="comp-bubble" data-bubble></div>'
+ '<div class="comp-eq" data-eq><i></i><i></i><i></i><i></i><i></i></div>'
+ '<div class="comp-np" data-np>'
+ '<span class="np-txt" data-nptxt></span>'
+ '<button class="np-btn" data-npprev type="button" aria-label="précédent">⏮</button>'
+ '<button class="np-btn mid" data-nptoggle type="button" aria-label="lecture ou pause">▶</button>'
+ '<button class="np-btn" data-npnext type="button" aria-label="suivant">⏭</button>'
+ '</div>'
+ '<div class="comp-hug" data-hug></div>'
+ '<div class="comp-hint" data-hint>tape-le pour un câlin 🤗</div>'
+ '</div>'
+ '<div class="comp-prog">'
+ '<div class="lab"><span>objectifs du jour</span><b data-pct>0 / ' + GOALS.length + '</b></div>'
+ '<div class="comp-track"><div class="comp-fill" data-fill></div></div>'
+ '</div>'
+ '<div class="comp-h">objectifs du jour</div>'
+ '<div data-goals></div>'
+ '<div class="comp-h">prendre soin</div>'
+ '<div class="care">'
+ '<div class="care-lab"><span>bonheur</span><b data-happypct>0%</b></div>'
+ '<div class="care-track"><div class="care-fill" data-happyfill></div></div>'
+ '<button class="btn treat" data-treat>🍬 donner une douceur</button>'
+ '<div class="wardrobe" data-wardrobe></div>'
+ '</div>'
+ '<div class="comp-h">aventure</div>'
+ '<div class="adv" data-adv></div>'
+ '</div>'
+ '<div class="comp-foot"><span data-foot></span></div>'
+ '</div>';
var root = container.querySelector('.px-comp');
var elName = root.querySelector('[data-name]');
var elMood = root.querySelector('[data-mood]');
var elLvl = root.querySelector('[data-lvl]');
var elXp = root.querySelector('[data-xp]');
var elGoals = root.querySelector('[data-goals]');
var elFill = root.querySelector('[data-fill]');
var elPct = root.querySelector('[data-pct]');
var elAdv = root.querySelector('[data-adv]');
var elFoot = root.querySelector('[data-foot]');
var elHug = root.querySelector('[data-hug]');
var elStage = root.querySelector('[data-stage]');
var elHint = root.querySelector('[data-hint]');
var elHappyFill = root.querySelector('[data-happyfill]');
var elHappyPct = root.querySelector('[data-happypct]');
var elWard = root.querySelector('[data-wardrobe]');
var elDj = root.querySelector('[data-dj]');
var elLofi = root.querySelector('[data-lofi]');
var elBubble = root.querySelector('[data-bubble]');
var elNp = root.querySelector('[data-np]');
var elNpTxt = root.querySelector('[data-nptxt]');
var elNpToggle = root.querySelector('[data-nptoggle]');
var elNpPrev = root.querySelector('[data-npprev]');
var elNpNext = root.querySelector('[data-npnext]');
// Bâtir le cube 3D une seule fois : la rotation reste continue, paintCreature ne remplit
// ensuite que les faces à frimousse (pas de recréation → aucun saut d'animation).
elHug.innerHTML = buildCube();
// Nuages : dérive douce (transform only), durées variées.
['c1','c2','c3'].forEach(function (c, i) {
var el = root.querySelector('.cloud.' + c);
if (el) el.style.animation = 'comp-drift ' + (13 + i * 4) + 's ease-in-out infinite alternate';
});
// keyframes de dérive injectées inline (transform pur, GPU-cheap)
if (!document.getElementById('comp-drift-kf')) {
var kf = document.createElement('style'); kf.id = 'comp-drift-kf';
kf.textContent = '@keyframes comp-drift{from{transform:translateX(-14px)}to{transform:translateX(14px)}}'
+ '@media (prefers-reduced-motion: reduce){.px-comp .cloud{animation:none!important}}';
document.head.appendChild(kf);
}
// ---- Niveau / XP : miroir doux de jOSGame si présent, sinon local ------------------------
function gLevel(){ try{ if(window.jOSGame&&window.jOSGame.level) return window.jOSGame.level(); }catch(e){}
return 1 + Math.floor((st.xp||0)/100); }
function gXp(){ try{ if(window.jOSGame&&window.jOSGame.xp) return window.jOSGame.xp(); }catch(e){}
return st.xp||0; }
function doneCount(){ var n=0; GOALS.forEach(function(g){ if(st.goals[g.id]) n++; }); return n; }
function isNight(){ var h=new Date().getHours(); return (h>=22 || h<6); }
// Humeur réelle : aventure=curieux, nuit=endormi, tout fait=comblé, sinon content.
function currentMood(){
if (st.adv && st.adv.until > Date.now()) return 'curious';
if (isNight()) return 'sleep';
if (doneCount() >= GOALS.length) return 'happy';
return 'content';
}
function moodText(){
if (st.adv && st.adv.until > Date.now()) return '🎒 curieux, parti en aventure…';
if (isNight()) return '🌙 tout endormi, chut…';
var n = doneCount(), tot = GOALS.length;
if (n >= tot) return '🌸 comblé — bravo pour aujourd\'hui';
if (n === 0) return '🌱 tout doux, on commence en douceur';
if (n < tot/2) return '🌿 en forme, ça pousse';
return '✨ rayonnant, continue';
}
function paintHead(){
elName.innerHTML = esc(st.name) + ' <span class="pen">✎</span>';
elMood.textContent = moodText();
elLvl.textContent = 'niv ' + gLevel();
elXp.textContent = gXp() + ' pts';
}
function paintProgress(){
var n = doneCount(), tot = GOALS.length;
elPct.textContent = n + ' / ' + tot;
elFill.style.width = Math.round(n/tot*100) + '%';
}
function paintHappy(){
var v = Math.max(0, Math.min(100, st.happy||0));
if (elHappyFill) elHappyFill.style.width = v + '%';
if (elHappyPct) elHappyPct.textContent = v + '%' + (v >= 100 ? ' · comblé' : '');
}
// ---- Cube : redessine LA MÊME frimousse sur les 3 faces d'un coup selon l'humeur, +
// accessoires sur l'avant, + bascule fond jour/nuit. Structure/rotation intactes. -----
function paintCreature(){
var m = currentMood();
var fr = elHug.querySelector('[data-art="front"]');
var ri = elHug.querySelector('[data-art="right"]');
var le = elHug.querySelector('[data-art="left"]');
if (fr) fr.innerHTML = faceArt(m, true, st.acc || {});
if (ri) ri.innerHTML = faceArt(m, false, null);
if (le) le.innerHTML = faceArt(m, false, null);
if (elStage) elStage.classList.toggle('night', m === 'sleep');
lastMood = m;
}
// Pupilles qui suivent un peu le curseur (face AVANT, la plus visible ; subtil, GPU-cheap).
function onMove(e){
if (REDUCE) return;
var pupils = elHug.querySelector('[data-art="front"] .comp-pupils');
if (!pupils) return;
var r = elStage.getBoundingClientRect();
if (!r.width) return;
var cx = r.left + r.width/2, cy = r.top + r.height*0.62;
var dx = (e.clientX - cx) / (r.width/2), dy = (e.clientY - cy) / (r.height/2);
var mx = Math.max(-1, Math.min(1, dx)) * 2.4;
var my = Math.max(-1, Math.min(1, dy)) * 1.8;
pupils.style.transform = 'translate(' + mx.toFixed(2) + 'px,' + my.toFixed(2) + 'px)';
}
if (!REDUCE) elStage.addEventListener('pointermove', onMove);
// ---- Objectifs (cartes cochables) --------------------------------------------------------
function renderGoals(){
elGoals.innerHTML = GOALS.map(function (g) {
var done = !!st.goals[g.id];
return '<div class="card' + (done?' done':'') + '" data-goal="' + g.id + '">'
+ '<div class="ic" style="background:' + g.bg + '">' + g.ic + '</div>'
+ '<div class="tx"><b>' + esc(g.label) + '</b><small>' + esc(g.sub) + '</small></div>'
+ '<div class="pts">⚡ 20</div>'
+ '<div class="chk">✓</div>'
+ '</div>';
}).join('');
elGoals.querySelectorAll('[data-goal]').forEach(function (el) {
el.addEventListener('click', function () { toggleGoal(el.getAttribute('data-goal')); });
});
}
function toggleGoal(id){
if (st.goals[id]) return; // objectif du jour : on coche une fois, en douceur
st.goals[id] = Date.now();
st.xp = (st.xp||0) + 20;
st.happy = (st.happy||0) + 5;
persist(st);
var g = GOALS.filter(function(x){ return x.id===id; })[0];
try { if (window.jOSGame && window.jOSGame.award)
window.jOSGame.award('side-done', { label: 'Objectif : ' + (g?g.label:id), icon: (g?g.ic:'✨') }); } catch(e){}
floatUp('❤️');
renderGoals(); paintProgress(); paintHead(); paintHappy(); renderWardrobe(); paintCreature();
var n = doneCount();
if (n === GOALS.length) { boop(); floatUp('🌟', 4); toast('tous les objectifs du jour, bravo 🌸'); }
}
// ---- Câlin (tap créature) ----------------------------------------------------------------
function boop(){
elHug.classList.remove('boop'); void elHug.offsetWidth; elHug.classList.add('boop');
}
function floatUp(sym, k){
var f = document.createElement('div'); f.className = 'float'; f.textContent = sym || '❤️';
var seed = (st.wi + (k||0));
f.style.left = (40 + Math.round((seed*17)%64)) + '%'; // position déterministe
elStage.appendChild(f);
var t = setTimeout(function(){ if (f.parentNode) f.remove(); }, 1250); timers.push(t);
}
function hug(){
// reprend le lo-fi de secours choisi (autoplay bloqué : le tap = le geste utilisateur),
// seulement s'il n'y a pas de vrai player branché
if (st.dj && !(audio && audio.running) && !activeSource()) { if (audioStart()) renderDj(); }
boop();
st.wi = (st.wi + 1) % 100000;
st.happy = (st.happy||0) + 2;
persist(st);
floatUp('❤️');
paintHappy();
sayCryptic('rand'); // l'oracle-cube lâche une phrase cryptique
}
elHug.addEventListener('click', hug);
// ---- Nourrir / soin : donner une douceur -------------------------------------------------
function treat(){
st.happy = (st.happy||0) + 7;
st.xp = (st.xp||0) + 2; // un petit pas vers les accessoires
persist(st);
boop(); floatUp('🍬', 3);
var t = setTimeout(function(){ floatUp('💛', 6); }, 260); timers.push(t);
paintHappy(); paintHead(); renderWardrobe();
var full = (Math.min(100, st.happy) >= 100);
toast(full ? 'comblé, merci 💛' : 'miam, merci 💛');
}
var elTreat = root.querySelector('[data-treat]');
if (elTreat) elTreat.addEventListener('click', treat);
// ---- Accessoires (garde-robe déblocable par XP) ------------------------------------------
function renderWardrobe(){
var xp = gXp();
elWard.innerHTML = ACC.map(function (a) {
var unlocked = xp >= a.xp;
if (!unlocked)
return '<div class="chip lock"><span class="cx">🔒</span>' + esc(a.name) + ' · ' + a.xp + 'pts</div>';
var on = !!(st.acc && st.acc[a.id]);
return '<div class="chip' + (on?' on':'') + '" data-acc="' + a.id + '">'
+ '<span class="cx">' + a.ic + '</span>' + esc(a.name) + '</div>';
}).join('');
elWard.querySelectorAll('[data-acc]').forEach(function (el) {
el.addEventListener('click', function () { toggleAcc(el.getAttribute('data-acc')); });
});
}
function toggleAcc(id){
st.acc = st.acc || {};
st.acc[id] = !st.acc[id];
persist(st); renderWardrobe(); paintCreature();
}
// ---- Aventure ----------------------------------------------------------------------------
function fmtLeft(ms){
var s = Math.max(0, Math.ceil(ms/1000));
var h = Math.floor(s/3600), m = Math.floor((s%3600)/60), ss = s%60;
function p(x){ return ('0'+x).slice(-2); }
return p(h)+':'+p(m)+':'+p(ss);
}
function renderAdv(){
var now = Date.now();
if (st.adv && st.adv.until > now) {
elAdv.innerHTML =
'<div class="aline">'
+ '<div class="aic">🎒</div>'
+ '<div class="atx"><b>' + esc(st.name) + ' explore les ploxions</b>'
+ '<small>reviens plus tard, il te ramène une surprise</small></div>'
+ '<div class="clock" data-clock>' + fmtLeft(st.adv.until - now) + '</div>'
+ '</div>';
} else if (st.adv && st.adv.reward) {
elAdv.innerHTML =
'<div class="aline">'
+ '<div class="aic">🌼</div>'
+ '<div class="atx"><b>de retour d\'aventure !</b>'
+ '<small>pendant que tu chill, il a exploré le xerboxion</small></div>'
+ '</div>'
+ '<div class="reward">' + esc(st.name) + ' ' + esc(st.adv.reward) + '</div>'
+ '<button class="btn" data-send>renvoyer en aventure</button>';
} else {
elAdv.innerHTML =
'<div class="aline">'
+ '<div class="aic">🎒</div>'
+ '<div class="atx"><b>envoyer en aventure</b>'
+ '<small>ton compagnon part explorer les ploxions pendant que tu chill</small></div>'
+ '</div>'
+ '<button class="btn lav" data-send>envoyer explorer</button>';
}
var send = elAdv.querySelector('[data-send]');
if (send) send.addEventListener('click', startAdv);
}
function startAdv(){
st.adv = { until: Date.now() + ADV_MS, reward: null };
persist(st);
renderAdv(); paintHead(); paintCreature();
toast('bon voyage 🌿');
}
function returnAdv(){
st.trips = (st.trips||0) + 1;
st.xp = (st.xp||0) + 15;
st.happy = (st.happy||0) + 4;
var idx = (st.trips - 1) % TRIPS.length; // récompense déterministe
st.adv = { until: 0, reward: TRIPS[idx] };
persist(st);
try { if (window.jOSGame && window.jOSGame.award)
window.jOSGame.award('side-done', { label: 'Retour d\'aventure', icon: '🎒' }); } catch(e){}
renderAdv(); paintHead(); paintHappy(); renderWardrobe(); paintCreature(); floatUp('✨');
sayCryptic('rand');
toast('de retour ! il t\'a ramené quelque chose 🌷');
}
// Tic d'aventure (1s) : met à jour l'horloge + déclenche le retour.
var advTick = setInterval(function(){
if (!st.adv || !st.adv.until) return;
var left = st.adv.until - Date.now();
if (left <= 0) { returnAdv(); return; }
var c = elAdv.querySelector('[data-clock]');
if (c) c.textContent = fmtLeft(left);
}, 1000);
timers.push(advTick);
// ---- Réagit aux VRAIS tsoins captés ------------------------------------------------------
function onTsoin(){
st.memories = (st.memories||0) + 1;
st.happy = (st.happy||0) + 3;
persist(st);
boop(); floatUp('⧗', 7);
paintHappy(); paintHead();
toast('+1 souvenir 💛');
}
['jos:tsoin:captured', 'tsoin:sealed'].forEach(function (ev) {
try { window.addEventListener(ev, onTsoin); listeners.push([ev, onTsoin]); } catch(e){}
});
// ---- Nom éditable ------------------------------------------------------------------------
elName.addEventListener('click', function () {
var v = null;
try { v = window.prompt('Comment s\'appelle ton compagnon ?', st.name); } catch(e){}
if (v == null) return;
v = v.trim().slice(0, 24);
if (!v) return;
st.name = v; persist(st); paintHead(); renderAdv();
});
// ---- Toast (jOSb si présent, sinon fallback) ---------------------------------------------
function toast(msg){
try { if (window.jOSb && window.jOSb.toast) { window.jOSb.toast(root, msg, { bottom: 54 }); return; } } catch(e){}
if (elHint) elHint.textContent = msg;
}
// ---- Oracle-cube : phrases CRYPTIQUES tirées des papiers (bulle au-dessus du cube + pied) -
var crypticLines = CRYPTIC_FALLBACK.slice();
var pi = (typeof st.fi === 'number') ? st.fi : 0;
function curCryptic(){
var len = crypticLines.length || 1;
return crypticLines[((pi % len) + len) % len] || CRYPTIC_FALLBACK[0];
}
function paintFoot(){
var span = elFoot; if (!span) return;
span.style.opacity = '0';
var t = setTimeout(function(){
span.textContent = '“' + curCryptic().t + '”';
span.style.opacity = '1';
}, 260); timers.push(t);
}
function paintBubble(){
if (!elBubble) return;
var c = curCryptic();
elBubble.classList.remove('show');
var t = setTimeout(function(){
elBubble.innerHTML = '<span class="bt">« ' + esc(c.t) + ' »</span>'
+ (c.src ? '<span class="bs">— ' + esc(c.src) + '</span>' : '');
elBubble.classList.add('show');
}, 240); timers.push(t);
}
function sayCryptic(mode){
var len = crypticLines.length || 1;
if (mode === 'rand') pi = Math.floor(Math.random() * len);
else if (mode === 'next') pi = (pi + 1) % len;
paintBubble(); paintFoot();
}
// Corpus complet en tâche de fond (fallback en dur si le fetch échoue).
try {
fetch('/data/papers-cryptic.json', { credentials: 'same-origin' })
.then(function (r) { return (r && r.ok) ? r.json() : null; })
.then(function (j) {
if (!j || !j.lignes) return;
var arr = j.lignes.filter(function (x) { return x && x.t; });
if (arr.length) { crypticLines = arr; sayCryptic('rand'); }
})
.catch(function () {});
} catch (e) {}
var cryptTick = setInterval(function () { sayCryptic('next'); }, 12000);
timers.push(cryptTick);
// ---- Cube DJ : boucle chill GÉNÉRATIVE en Web Audio (off par défaut, coupée à l'unmount) --
// pentatonique douce, tempo lent, kick + hi-hat légers, gain bas ~0.15, filtre lo-fi.
var A_BPM = 72, A_SPB = 60 / A_BPM, A_STEP = A_SPB / 2; // 8 pas = 1 mesure (8e de note)
var A_NOTES = [220.00, 261.63, 293.66, 329.63, 392.00, 440.00]; // La mineur pentatonique
var A_MELO = [0, null, 2, null, 4, null, 3, null]; // motif doux et clairsemé
function beatPulse(){
if (REDUCE) return; // le son reste dispo, seul le visuel se coupe
var b = elHug.querySelector('.cube-beat'); if (!b) return;
b.classList.remove('beat'); void b.offsetWidth; b.classList.add('beat');
var to = setTimeout(function(){ if (b) b.classList.remove('beat'); }, 170); djTimers.push(to);
}
function aKick(ctx, master, t){
var o = ctx.createOscillator(), g = ctx.createGain(); o.type = 'sine';
o.frequency.setValueAtTime(120, t);
o.frequency.exponentialRampToValueAtTime(48, t + 0.14);
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(0.9, t + 0.008);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.28);
o.connect(g); g.connect(master); o.start(t); o.stop(t + 0.3);
}
function aNote(ctx, master, freq, t){
var o = ctx.createOscillator(), g = ctx.createGain(); o.type = 'triangle';
o.frequency.value = freq;
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(0.3, t + 0.02);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.5);
o.connect(g); g.connect(master); o.start(t); o.stop(t + 0.55);
}
function aHat(ctx, master, buf, t){
var s = ctx.createBufferSource(); s.buffer = buf;
var hp = ctx.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 7000;
var g = ctx.createGain();
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(0.12, t + 0.005);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.06);
s.connect(hp); hp.connect(g); g.connect(master); s.start(t); s.stop(t + 0.08);
}
function audioStart(){
if (audio && audio.running) return true;
// Réutilise le mixer jOSJuice/jOSSound s'il expose un contexte, sinon AudioContext maison.
try {
var AC = window.AudioContext || window.webkitAudioContext;
if (!AC) return false;
var ctx = null, owns = false;
try { if (window.jOSJuice && window.jOSJuice.ctx) ctx = window.jOSJuice.ctx; } catch (e) {}
try { if (!ctx && window.jOSSound && window.jOSSound.ctx) ctx = window.jOSSound.ctx; } catch (e) {}
if (!ctx) { ctx = new AC(); owns = true; } // on ne ferme QUE le contexte qu'on a créé
try { if (ctx.state === 'suspended') ctx.resume(); } catch (e) {}
var master = ctx.createGain(); master.gain.value = 0.15;
var lp = ctx.createBiquadFilter(); lp.type = 'lowpass'; lp.frequency.value = 2200; lp.Q.value = 0.5;
master.connect(lp); lp.connect(ctx.destination);
var noise = ctx.createBuffer(1, Math.floor(ctx.sampleRate * 0.2), ctx.sampleRate);
var d = noise.getChannelData(0);
for (var i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
audio = { ctx: ctx, master: master, lp: lp, owns: owns, noise: noise, running: true, step: 0, next: ctx.currentTime + 0.12 };
audio.tick = setInterval(function () {
if (!audio || !audio.running) return;
var c = audio.ctx;
while (audio.next < c.currentTime + 0.12) {
var s = audio.step % 8, t = audio.next;
if (s === 0 || s === 4) aKick(c, audio.master, t);
if (s === 2 || s === 6) aHat(c, audio.master, audio.noise, t);
var n = A_MELO[s]; if (n != null) aNote(c, audio.master, A_NOTES[n], t);
audio.next += A_STEP; audio.step++;
}
}, 25);
return true;
} catch (e) { audio = null; return false; }
}
function aTeardown(a){ // débranche NOS nœuds ; ne ferme le contexte que s'il est à nous
try { a.master.disconnect(); } catch (e) {}
try { a.lp.disconnect(); } catch (e) {}
if (a.owns) { try { a.ctx.close(); } catch (e) {} }
}
function audioStop(now){
if (!audio) return;
var a = audio; audio = null; a.running = false;
try { clearInterval(a.tick); } catch (e) {}
djTimers.forEach(function (t) { try { clearTimeout(t); } catch (e) {} }); djTimers = [];
if (now) { aTeardown(a); return; } // unmount = coupe immédiate
try { a.master.gain.setTargetAtTime(0.0001, a.ctx.currentTime, 0.04); } catch (e) {}
setTimeout(function () { aTeardown(a); }, 200); // fondu court puis débranchement
}
// ---- Le VRAI son passe par le bus (ploxion Spotify / players) via window.jOSSound ---------
// Priorité au player réel ; la boucle lo-fi ci-dessus reste un secours explicite.
function getSources(){
try { if (window.jOSSound && typeof window.jOSSound.list === 'function') {
var a = window.jOSSound.list(); return (a && a.length) ? a : []; } } catch (e) {}
return [];
}
function activeSource(){
var list = getSources();
for (var i = 0; i < list.length; i++){ if (list[i] && list[i].id === 'spotify') return list[i]; }
return list[0] || null;
}
function srcPlaying(src){
if (!src) return false;
try { if (src.id === 'spotify' && busTrack && typeof busTrack.paused === 'boolean') return !busTrack.paused; } catch (e) {}
try { if (typeof src.isPaused === 'function') return !src.isPaused(); } catch (e) {}
return false;
}
function npInfo(src){
var title = '', artist = '';
try { if (src.id === 'spotify' && busTrack) { title = busTrack.title || ''; artist = busTrack.artist || ''; } } catch (e) {}
try { if (!title && typeof src.label === 'function') title = src.label() || ''; } catch (e) {}
try { if (!artist && typeof src.sub === 'function') artist = src.sub() || ''; } catch (e) {}
return { title: title, artist: artist };
}
// Le cube DANSE : pouls temporel doux (pas d'analyser audio) tant que ça joue ; calme en pause.
function startDance(){ if (REDUCE) return; if (danceTimer) return; beatPulse(); danceTimer = setInterval(beatPulse, 520); }
function stopDance(){ if (danceTimer) { try { clearInterval(danceTimer); } catch (e) {} danceTimer = null; } }
function renderDj(){
var src = activeSource();
var hasSrc = !!src;
var lofiOn = !!(audio && audio.running);
var playing = hasSrc ? srcPlaying(src) : lofiOn;
if (elDj){
if (hasSrc) elDj.textContent = (src.icon ? src.icon + ' ' : '♫ ') + (src.name || 'son');
else if (lofiOn) elDj.textContent = '♫ lo-fi';
else elDj.textContent = '♪ mettre le son';
elDj.classList.toggle('on', playing);
elDj.setAttribute('aria-pressed', playing ? 'true' : 'false');
}
if (elLofi){ elLofi.classList.toggle('on', lofiOn); elLofi.setAttribute('aria-pressed', lofiOn ? 'true' : 'false'); }
if (elNp && hasSrc){
var info = npInfo(src);
var title = info.title || src.name || 'Lecture';
if (elNpTxt) elNpTxt.textContent = info.artist ? (title + ' — ' + info.artist) : title;
if (elNpToggle) elNpToggle.textContent = playing ? '⏸' : '▶';
}
if (elStage){
elStage.classList.toggle('dj-live', hasSrc);
elStage.classList.toggle('dj-playing', playing);
}
if (playing) startDance(); else stopDance();
}
function srcDo(fn){
var s = activeSource(); if (!s) return;
try { if (typeof s[fn] === 'function') s[fn](); } catch (e) {}
var t = setTimeout(renderDj, 90); timers.push(t);
}
function djMain(){
var s = activeSource();
if (s) { srcDo('toggle'); return; } // « mettre le son » = play/pause du player déjà branché
var opened = false; // rien d'ouvert → on ouvre le ploxion Spotify
try { if (window.jOS && typeof window.jOS.openPloxion === 'function') { window.jOS.openPloxion('spotify'); opened = true; } } catch (e) {}
if (!opened) { try { if (window.jOSMobile && typeof window.jOSMobile.open === 'function') { window.jOSMobile.open('spotify','Spotify'); opened = true; } } catch (e) {} }
toast(opened ? 'Spotify arrive… 🎧' : 'ouvre Spotify, ou lance le lo-fi ♪');
}
function djLofi(){
if (audio && audio.running){ audioStop(); st.dj = false; persist(st); renderDj(); return; }
if (activeSource()){ toast('un player est déjà branché 🎧'); return; }
var ok = audioStart(); st.dj = !!ok; persist(st);
if (!ok) toast('le son n\'est pas dispo ici');
renderDj();
}
function onSources(){
try { if (activeSource() && audio && audio.running) { audioStop(); st.dj = false; persist(st); } } catch (e) {}
renderDj();
}
if (elDj) elDj.addEventListener('click', function (e) { try { e.stopPropagation(); } catch (x) {} djMain(); });
if (elLofi) elLofi.addEventListener('click', function (e) { try { e.stopPropagation(); } catch (x) {} djLofi(); });
if (elNpPrev) elNpPrev.addEventListener('click', function (e) { try { e.stopPropagation(); } catch (x) {} srcDo('prev'); });
if (elNpToggle) elNpToggle.addEventListener('click', function (e) { try { e.stopPropagation(); } catch (x) {} srcDo('toggle'); });
if (elNpNext) elNpNext.addEventListener('click', function (e) { try { e.stopPropagation(); } catch (x) {} srcDo('next'); });
// S'abonner aux changements de sources + au flux live du bus Spotify (unsub gardés).
try { if (window.jOSSound && typeof window.jOSSound.subscribe === 'function') soundUnsub = window.jOSSound.subscribe(onSources); } catch (e) {}
try { if (window.jOSPorts && typeof window.jOSPorts.on === 'function') {
busHandler = function (p) { busTrack = p || null; renderDj(); };
window.jOSPorts.on('spotify', 'track', busHandler);
} } catch (e) {}
var djPoll = setInterval(renderDj, 4000); timers.push(djPoll); // garde play/pause à jour
// ---- Rafraîchir le niveau si jOSGame bouge ailleurs --------------------------------------
function onGame(){ paintHead(); renderWardrobe(); }
try { window.addEventListener('jos:game', onGame); listeners.push(['jos:game', onGame]); } catch(e){}
// ---- Suivi doux de l'humeur (jour↔nuit) : re-rend la créature si l'humeur change ---------
var moodTick = setInterval(function(){
if (currentMood() !== lastMood) { paintCreature(); paintHead(); }
}, 30000);
timers.push(moodTick);
// ---- Premier rendu -----------------------------------------------------------------------
paintCreature(); paintHead(); renderGoals(); paintProgress(); paintHappy(); renderWardrobe(); renderAdv();
renderDj(); sayCryptic('rand');
// ---- Unmount : nettoie timers + listeners ------------------------------------------------
return { unmount: function () {
timers.forEach(function(t){ try{ clearInterval(t); clearTimeout(t); }catch(e){} });
timers = [];
listeners.forEach(function(l){ try{ window.removeEventListener(l[0], l[1]); }catch(e){} });
listeners = [];
try { if (!REDUCE) elStage.removeEventListener('pointermove', onMove); } catch(e){}
try { stopDance(); } catch(e){}
try { audioStop(true); } catch(e){}
try { if (soundUnsub) soundUnsub(); } catch(e){}
try { if (window.jOSPorts && window.jOSPorts.off && busHandler) window.jOSPorts.off('spotify','track', busHandler); } catch(e){}
try { st.fi = pi; persist(st); } catch(e){}
container.innerHTML = '';
}};
}
// ===== XUI (contrat v0) : describe() PUR, marche NON MONTÉ — lit l'état persisté
// (localStorage jos:compagnon) et recalcule l'humeur comme le mount. Ne lève jamais. =====
function describe(){
try {
var st = load() || {};
var name = (typeof st.name === 'string' && st.name) ? st.name : 'Bibou';
var goals = (st.day === today() && st.goals) ? st.goals : {};
var n = 0; GOALS.forEach(function(g){ if (goals[g.id]) n++; });
var tot = GOALS.length;
var h = new Date().getHours(), night = (h >= 22 || h < 6);
var inAdv = !!(st.adv && st.adv.until > Date.now());
var mood = inAdv ? '🎒 parti en aventure' : night ? '🌙 endormi' : (n >= tot) ? '🌸 comblé' : (n === 0) ? '🌱 tout doux' : '✨ en forme';
var lvl = 1 + Math.floor(((typeof st.xp === 'number' ? st.xp : 0)) / 100);
var items = [
{ p:1, kind:'stat', label:'🐣 ' + name, value: mood },
{ p:2, kind:'gauge', label:'objectifs du jour', value: n, max: tot },
{ p:3, kind:'stat', label:'niveau', value: lvl },
{ p:3, kind:'stat', label:'aventures · souvenirs', value: (st.trips || 0) + ' · ' + (st.memories || 0) }
];
if (inAdv) items.push({ p:4, kind:'text', label: name + ' explore les ploxions — retour dans ' + Math.max(1, Math.round((st.adv.until - Date.now()) / 60000)) + ' min' });
return { v:1, id:'compagnon', title:'Compagnon', icon:'🐣', items:items };
} catch (e) {
return { v:1, id:'compagnon', title:'Compagnon', icon:'🐣', items:[{ p:1, kind:'text', label:'Compagnon' }] };
}
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['compagnon'] = {
manifest: { id: 'compagnon', name: 'Compagnon', icon: '🐣' },
mount: mount,
describe: describe
};
})();
</script>