/* L'aiutante in basso a destra: un omino a blocchi in vero 3D, solo CSS. */

.buddy { position: fixed; right: 18px; bottom: 16px; z-index: 20; }
/* solo l'omino: il pulsante c'è ma è invisibile */
.buddy-button { position: relative; display: block; width: 92px; height: 76px; padding: 0; border: 0; border-radius: 16px; background: none; cursor: pointer; transition: scale .25s; }
.buddy-button:hover { scale: 1.12; }
.buddy-button:active { scale: .96; }

.buddy-scene, .buddy-mover, .buddy-model { position: absolute; inset: 0; display: block; }
.buddy-scene { perspective: 420px; scale: 1.25; }
.buddy-mover, .buddy-model { transform-style: preserve-3d; }
.buddy-model { transform: rotateX(var(--tx, -16deg)) rotateY(var(--ty, -24deg)); transition: transform .25s ease-out; }

/* un parallelepipedo: sei facce intorno al suo centro */
.cube { position: absolute; left: 50%; top: 50%; transform-style: preserve-3d; }
.cube i { position: absolute; display: block; left: calc(var(--w) / -2); top: calc(var(--h) / -2); width: var(--w); height: var(--h); background: #de7a58; }
.cube .front { transform: translateZ(calc(var(--d) / 2)); }
.cube .back { transform: rotateY(180deg) translateZ(calc(var(--d) / 2)); background: #b9573a; }
.cube .left, .cube .right { left: calc(var(--d) / -2); width: var(--d); }
.cube .left { transform: rotateY(-90deg) translateZ(calc(var(--w) / 2)); background: #c46243; }
.cube .right { transform: rotateY(90deg) translateZ(calc(var(--w) / 2)); background: #b9573a; }
.cube .top, .cube .bottom { top: calc(var(--d) / -2); height: var(--d); }
.cube .top { transform: rotateX(90deg) translateZ(calc(var(--h) / 2)); background: #f29c7b; }
.cube .bottom { transform: rotateX(-90deg) translateZ(calc(var(--h) / 2)); background: #9c4630; }

/* la faccina > < */
.buddy-eyes { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke: #2b130a; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; transform-origin: 50% 42%; }

/* fumetto */
.buddy-bubble { position: absolute; right: 4px; bottom: calc(100% + 16px); width: max-content; max-width: min(250px, 100vw - 48px); padding: 14px 18px; background: #fff; border: 2px solid #4db2ff; border-radius: 18px 18px 4px 18px; box-shadow: 0 18px 40px -16px #2b3fb099; font-weight: 700; font-size: 15px; line-height: 1.45; visibility: hidden; opacity: 0; scale: .7; transform-origin: 100% 100%; transition: opacity .2s, scale .35s cubic-bezier(.2, .9, .25, 1.4), visibility .35s; }
.buddy.open .buddy-bubble { visibility: visible; opacity: 1; scale: 1; }

/* si muove: dondola sempre, e ogni tanto fa qualcosa */
.anim .buddy-mover { animation: buddy-bob 3.2s ease-in-out infinite; }
.anim .buddy.hop .buddy-mover { animation: buddy-hop .9s ease-in-out; }
.anim .buddy.spin .buddy-mover { animation: buddy-spin 1.1s cubic-bezier(.4, .1, .3, 1); }
.anim .buddy.wiggle .buddy-mover { animation: buddy-wiggle .9s ease-in-out; }
.anim .buddy.wave .arm-right { animation: buddy-wave 1.2s ease-in-out; }
.anim .buddy.blink .buddy-eyes { animation: buddy-blink .5s ease-in-out; }

@keyframes buddy-bob { 50% { transform: translateY(-4px); } }
@keyframes buddy-hop { 15% { transform: translateY(3px) scale(1.08, .9); } 45% { transform: translateY(-17px) scale(.95, 1.07); } 75% { transform: translateY(2px) scale(1.06, .93); } }
@keyframes buddy-spin { 50% { transform: translateY(-9px) rotateY(180deg); } 100% { transform: rotateY(360deg); } }
@keyframes buddy-wiggle { 20%, 60% { transform: rotateZ(-13deg); } 40%, 80% { transform: rotateZ(13deg); } }
@keyframes buddy-wave { 20%, 60% { translate: 2px -13px; } 40%, 80% { translate: 2px -4px; } }
@keyframes buddy-blink { 50% { scale: 1 .15; } }

@media (max-width: 820px) {
  .buddy { right: 10px; bottom: 10px; }
  .buddy-button { width: 76px; height: 64px; }
  .buddy-scene { scale: 1.05; inset: -6px -8px; }
}

/* spazio in fondo, così l'aiutante non copre «torna su» */
footer { padding-bottom: 130px; }
