/* ==========================================================
   Ponzi Buddy: forcepu.sh's on-page pal.
   A yellow speech balloon and a Windows 98-style menu.
   Everything is namespaced .pb-* so it can't collide with page styles.
   ========================================================== */
.pb-root {
    --pb-size: 150px;
    --pb-balloon: #ffffe1;
    --pb-ink: #000;
    --pb-chrome: #c0c0c0;
    --pb-hi: #fff;
    --pb-lo: #808080;
    --pb-select: #000080;
    position: fixed;
    right: 16px;
    bottom: 12px;
    z-index: 9000; /* under the intro screen and modals (9999+), over page content */
    width: var(--pb-size);
    font: 13px/1.35 Tahoma, Verdana, Arial, Helvetica, sans-serif;
    color: var(--pb-ink);
}
.pb-root[hidden] { display: none; }
body:not(.retro-mode) .pb-root { display: none !important; } /* he only lives in the retro look */

@media screen and (max-width: 600px) {
    .pb-root { --pb-size: 104px; }
    .pb-controls input { font-size: 16px; } /* below 16px, iOS zooms the page on focus */
}

/* --- The character --- */
.pb-body {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: grab;
    position: relative; /* paints him over the rope, which sits before him in the DOM */
    touch-action: none; /* dragging him shouldn't scroll the page */
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}
.pb-body:focus { outline: none; }
.pb-body:focus-visible .pb-img { outline: 2px dotted #000; outline-offset: 2px; }
.pb-root.pb-dragging .pb-body { cursor: grabbing; }
.pb-img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    transform-origin: 50% 100%;
    filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.3));
    -webkit-user-drag: none;
}

/* --- Animations (all transforms on .pb-img; the global reduced-motion rule turns them off) --- */
.pb-talk .pb-img { animation: pb-talk 0.42s ease-in-out infinite alternate; }
.pb-anim-enter .pb-img { animation: pb-enter 0.7s cubic-bezier(.2, 1.4, .4, 1) both; }
.pb-anim-leave .pb-img { animation: pb-leave 0.6s ease-in both; }
.pb-anim-wave .pb-img { animation: pb-wave 0.5s ease-in-out 3; }
.pb-anim-hop .pb-img { animation: pb-hop 0.5s ease-out 2; }
.pb-anim-look .pb-img { animation: pb-look 2.2s ease-in-out; }
.pb-anim-shiver .pb-img { animation: pb-shiver 0.08s linear 12; }
.pb-anim-shrug .pb-img { animation: pb-shrug 0.9s ease-in-out; }
.pb-anim-spin .pb-img { animation: pb-spin 0.9s ease-in-out; }
.pb-anim-giggle .pb-img { animation: pb-giggle 0.16s ease-in-out 8; }
.pb-anim-think .pb-img { animation: pb-think 2.4s ease-in-out; }
.pb-sing .pb-img { animation: pb-sway 0.9s ease-in-out infinite alternate; }
.pb-asleep .pb-img { transform: rotate(-9deg) translateY(4px); filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.3)) brightness(0.85) saturate(0.8); transition: transform 0.8s, filter 0.8s; }

@keyframes pb-talk { from { transform: translateY(0) scaleY(1); } to { transform: translateY(-3px) scaleY(1.02); } }
@keyframes pb-enter { from { transform: translateY(120%) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pb-leave { to { transform: translateY(120%) scale(0.6); opacity: 0; } }
@keyframes pb-wave { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-6deg); } 70% { transform: rotate(5deg); } }
@keyframes pb-hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 15% { transform: translateY(0) scale(1.06, 0.92); } 50% { transform: translateY(-22px) scale(0.97, 1.04); } 85% { transform: translateY(0) scale(1.04, 0.95); } }
@keyframes pb-look { 0%, 100% { transform: scaleX(1); } 20%, 80% { transform: scaleX(-1); } }
@keyframes pb-shiver { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(2px) rotate(0.6deg); } }
@keyframes pb-shrug { 0%, 100% { transform: scale(1, 1); } 40%, 60% { transform: scale(1.05, 0.94) translateY(2px); } }
@keyframes pb-spin { to { transform: rotateY(360deg); } }
@keyframes pb-giggle { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(2.5deg) translateY(-2px); } }
@keyframes pb-think { 0%, 100% { transform: rotate(0); } 25%, 75% { transform: rotate(-4deg) translateX(-3px); } }
@keyframes pb-sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }

/* The rope he swings in on (see swingIn in ponzi-buddy.js) */
.pb-rope {
    position: absolute;
    width: 4px;
    border-radius: 2px;
    background: repeating-linear-gradient(160deg, #d2ab6c 0 5px, #8a6332 5px 8px);
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.25);
    transform-origin: 50% 0;
    pointer-events: none;
}

/* Floating emoji (money, Zzz, music notes) */
.pb-float {
    position: absolute;
    top: 8%;
    pointer-events: none;
    font-size: 22px;
    animation: pb-float 2.2s ease-out forwards;
}
@keyframes pb-float {
    from { transform: translateY(0) scale(0.6); opacity: 0; }
    15% { opacity: 1; }
    to { transform: translateY(-70px) scale(1.1); opacity: 0; }
}

/* --- Speech balloon --- */
.pb-balloon {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    box-sizing: border-box;
    width: max-content;
    min-width: 140px;
    max-width: min(300px, calc(100vw - 24px));
    padding: 8px 10px;
    background: var(--pb-balloon);
    color: var(--pb-ink);
    border: 1px solid #000;
    border-radius: 8px;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
    text-align: left;
    overflow-wrap: anywhere;
}
.pb-balloon[hidden] { display: none; }
/* Tail: points down at the character by default */
.pb-balloon::before, .pb-balloon::after {
    content: "";
    position: absolute;
    right: calc(var(--pb-size) / 2 - 10px);
    border: 10px solid transparent;
}
.pb-balloon::before { top: 100%; border-top-color: #000; }
.pb-balloon::after { top: calc(100% - 1px); border-top-color: var(--pb-balloon); }
.pb-root.pb-left .pb-balloon { right: auto; left: 0; }
.pb-root.pb-left .pb-balloon::before, .pb-root.pb-left .pb-balloon::after { right: auto; left: calc(var(--pb-size) / 2 - 10px); }
/* Below the character when there's no room above */
.pb-root.pb-below .pb-balloon { bottom: auto; top: calc(100% + 10px); }
.pb-root.pb-below .pb-balloon::before { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: #000; }
.pb-root.pb-below .pb-balloon::after { top: auto; bottom: calc(100% - 1px); border-top-color: transparent; border-bottom-color: var(--pb-balloon); }

.pb-text { margin: 0; padding-right: 14px; white-space: pre-line; }
.pb-unsaid { visibility: hidden; } /* reserves the line's full size so the balloon doesn't grow word by word */
.pb-close {
    position: absolute;
    top: 2px;
    right: 3px;
    padding: 0 4px;
    border: 0;
    background: none;
    color: #555;
    font: bold 13px/1 Tahoma, Arial, sans-serif;
    cursor: pointer;
}
.pb-close:hover, .pb-close:focus-visible { color: #000; }
.pb-song-title { display: block; margin-bottom: 4px; font-weight: bold; }
.pb-song-credit { display: block; margin-top: 4px; font-size: 11px; color: #555; }
.pb-sung { color: #a4161a; }

/* Controls inside the balloon */
.pb-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pb-controls input {
    flex: 1 1 140px;
    min-width: 0;
    padding: 3px 4px;
    font: inherit;
    color: #000;
    background: #fff;
    border: 2px inset var(--pb-chrome);
    border-radius: 0;
}
.pb-btn, .pb-link {
    padding: 3px 10px;
    font: inherit;
    font-size: 12px;
    color: #000;
    background: var(--pb-chrome);
    border: 2px outset var(--pb-chrome);
    border-radius: 0;
    cursor: pointer;
    text-decoration: none;
}
.pb-btn:active, .pb-link:active { border-style: inset; }
.pb-btn:focus-visible, .pb-link:focus-visible, .pb-controls input:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }
.pb-list { display: grid; gap: 4px; width: 100%; }
.pb-list .pb-link { display: block; text-align: left; }

/* --- Right-click style menu --- */
.pb-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    min-width: 190px;
    margin: 0;
    padding: 2px;
    list-style: none;
    background: var(--pb-chrome);
    border: 2px solid;
    border-color: var(--pb-hi) #000 #000 var(--pb-hi);
    box-shadow: inset -1px -1px var(--pb-lo), inset 1px 1px #dfdfdf, 2px 2px 0 rgba(0, 0, 0, 0.3);
    font: 12px/1.2 Tahoma, Verdana, Arial, sans-serif;
}
.pb-menu[hidden] { display: none; }
.pb-root.pb-left .pb-menu { right: auto; left: 0; }
.pb-root.pb-below .pb-menu { bottom: auto; top: calc(100% + 6px); }
.pb-menu-title {
    padding: 3px 8px;
    margin-bottom: 2px;
    background: linear-gradient(90deg, #000080, #1084d0);
    color: #fff;
    font-weight: bold;
}
.pb-menu button {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    padding: 4px 18px 4px 22px;
    border: 0;
    background: none;
    color: #000;
    font: inherit;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}
.pb-menu button:hover, .pb-menu button:focus { background: var(--pb-select); color: #fff; outline: none; }
.pb-menu .pb-check { opacity: 0.8; }
.pb-menu hr { margin: 3px 1px; border: 0; border-top: 1px solid var(--pb-lo); border-bottom: 1px solid var(--pb-hi); }

.pb-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media print { .pb-root { display: none !important; } }
