.web-pet {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    pointer-events: auto;
    user-select: none;
    display: block !important;
    will-change: transform;
}

.pet-body {
    font-size: 32px;
    transition: transform 0.3s;
    animation: floating 3s infinite ease-in-out;
    transform: translate3d(0, 0, 0);
}

/* GIF Character Support */
.pet-visual {
    width: 64px;
    height: 64px;
    /* background-image set dynamically by JavaScript based on state */
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    display: inline-block;
    vertical-align: middle;
    /* Fix vertical position */
    font-size: 0;
    /* Hide emoji fallback */
}

/* Rollback: To restore emoji, comment out .pet-visual above and uncomment below */
/*
.pet-visual {
    font-size: 32px;
}
*/

.web-pet.face-right .pet-body {
    transform: scaleX(-1) translate3d(0, 0, 0);
}

.web-pet.wobbly-walk .pet-body {
    animation: wobbly-walk 0.5s infinite ease-in-out, floating 3s infinite ease-in-out;
}

@keyframes floating {

    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }

    50% {
        transform: translate3d(0, -8px, 0);
    }
}

@keyframes wobbly-walk {

    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }

    25% {
        transform: translate3d(0, -3px, 0);
    }

    75% {
        transform: translate3d(0, -3px, 0);
    }
}

.pet-balloon {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid #333;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    margin-bottom: 18px;
    /* Increased from 8px to move balloon 10px closer to pet */
    will-change: opacity, transform;
}

.pet-balloon.visible {
    opacity: 1;
    display: block !important;
}

/* Mobile adjustments for balloon */
@media (max-width: 768px) {
    .pet-balloon {
        font-size: 14px !important;
        /* Adjusted to 14px per user request */
        /* Increased from 11px for better readability */

        /* === ROLLBACK POINT: Anti-truncation fix (v4.2) === */
        /* OLD: white-space: nowrap; */
        white-space: normal;
        /* Allow text wrapping to prevent truncation */

        /* OLD: max-width: calc(100vw - 100px); */
        min-width: 150px;
        /* Default minimum width - adjusted dynamically by JS for short text */
        max-width: 250px;
        /* Allow wider balloons for longer text */
        /* === END ROLLBACK POINT === */

        padding: 3px 8px;
        /* Compact padding */
        line-height: 1.3;
        /* Tight line-height */
        overflow: hidden;
        /* Removed: text-overflow: ellipsis; - No more truncation */

        text-align: center;
        /* Center-align text on mobile */
    }

    /* Allow full wrapping for input boxes */
    .pet-balloon:has(input),
    .pet-balloon:has(button) {
        white-space: normal;
        /* Allow wrapping */
        max-height: none;
        /* Remove height limit */
        max-width: calc(100vw - 60px);
    }

    /* === Mobile Touch & Readability Improvements === */
    .pet-balloon input,
    .pet-balloon input[type="text"] {
        font-size: 15px !important;
        /* Adjusted to 15px per user request */
        padding: 8px 10px !important;
        /* Larger touch area */
        height: 44px !important;
        /* Standard touch target height */
        line-height: normal !important;
        border: 1px solid #999 !important;
        border-radius: 6px !important;
        margin: 5px 0 8px 0 !important;
        width: 100% !important;
        /* Full width on mobile */
        box-sizing: border-box !important;
    }

    .pet-balloon button {
        font-size: 14px !important;
        padding: 2px 8px !important;
        /* Compact padding */
        min-height: 25px !important;
        /* Height reduced to 25px per user request */
        min-width: 40px !important;
        /* Reduced min-width */
        margin: 0 4px !important;
        vertical-align: middle !important;
    }
}

/* Question balloon position adjustment for mobile */
.pet-balloon:has(input) {
    bottom: calc(50% - 35px) !important;
    /* 20px lower than default (15+5) */
}

/* Mobile position adjustment */
@media (max-width: 768px) {
    .web-pet {
        left: -12px !important;
        /* Move 12px left on mobile (total 22px from desktop) */
        /* Prevent long-press menu and highlight on mobile */
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Reduce spacing when balloon is below pet - aggressive approach */
.pet-balloon[style*='top'],
.pet-balloon[style*='Top'] {
    margin-top: -20px !important;
    /* Stronger reduction */
    margin-bottom: 0 !important;
    padding-top: 0 !important;
}

/* Double balloon for long text (18+ chars on mobile) */
.pet-balloon-container {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid #333;
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 18px;
    opacity: 0;
    will-change: opacity, transform;
}

.pet-balloon-container.visible {
    opacity: 1;
    display: block !important;
}

.pet-balloon-part {
    background: transparent;
    border: none;
    padding: 2px 8px;
    font-size: 13px;
    white-space: nowrap;
    line-height: 1.3;
    text-align: center;
}

@media (max-width: 768px) {
    .pet-balloon-container {
        max-width: calc(100vw - 100px);
        /* Force display below pet on mobile */
        bottom: auto !important;
        top: 100% !important;
        margin-top: 8px !important;
        margin-bottom: 0 !important;
    }
}

/* Mobile: Show double balloon below pet when at home position */
@media (max-width: 768px) {
    .web-pet.face-left .pet-balloon-container {
        bottom: auto;
        top: 100%;
        margin-top: 8px;
        margin-bottom: 0;
    }
}

/* ======================================== */
/* WebPet Menu Storage Feature (Phase 2)  */
/* ======================================== */

/* WebPet Menu Dock */
.webpet-menu-dock {
    position: relative;
    width: 100%;
    min-height: 150px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 100px 20px 20px 50px;
    /* Top padding reduced by 20px, left padding increased by 10px */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.02);
}

/* WebPet when stored in menu */
.web-pet.stored-in-menu {
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 1 !important;
}

/* Hide dock when menu is closed */
.mobile-menu-overlay:not(.active) .webpet-menu-dock {
    display: none;
}

/* Balloon display area - hidden, not used */
.webpet-menu-balloon-area {
    display: none;
}

/* Balloon positioning when stored - above WebPet like IDLE mode */
.web-pet.stored-in-menu .pet-balloon {
    position: absolute !important;
    bottom: 100% !important;
    top: auto !important;
    /* Force top auto to prevent conflict */
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin-bottom: 8px !important;
    max-width: 200px !important;
    white-space: normal !important;
    z-index: 2147483650 !important;
    /* Highest priority */
    min-width: 150px !important;
    /* Ensure minimum width */
}

/* Tablet/small desktop sizes (711px-925px) - verify stored balloon width */
@media (min-width: 711px) and (max-width: 925px) {
    .web-pet.stored-in-menu .pet-balloon {
        min-width: 150px !important;
        max-width: 200px !important;
    }
}

/* Desktop stored balloon - same style as mobile/tablet */
@media (min-width: 926px) {
    .web-pet.stored-in-menu .pet-balloon {
        max-width: 400px !important;
        /* Slightly larger for desktop */
    }
}

.web-pet.stored-in-menu .pet-balloon-container {
    position: absolute !important;
    bottom: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin-bottom: 8px !important;
}

/* ======================================== */
/* Mobile Menu Storage Button & Lang Switcher */
/* ======================================== */

/* Storage Button */
.webpet-storage-button {
    display: block;
    width: 100%;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    text-align: left;
    font-size: 16px;
    cursor: pointer;
    margin: 10px 0;
    transition: background 0.2s ease;
}

.webpet-storage-button:active {
    background: rgba(0, 0, 0, 0.1);
}

/* Language Switcher in Mobile Menu */
.mobile-menu-lang-switcher {
    padding: 15px 20px;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 14px;
    font-weight: 600;
    margin-top: 20px;
    /* Space from storage button */
}

.mobile-menu-lang-switcher a {
    color: inherit;
    text-decoration: none;
    padding: 0 8px;
    transition: opacity 0.2s ease;
}

.mobile-menu-lang-switcher a:hover {
    opacity: 0.7;
}

.mobile-menu-lang-switcher a.active {
    font-weight: bold;
    text-decoration: underline;
}

/* ======================================== */
/* Balloon Overflow When Stored in Menu */
/* ======================================== */

/* Ensure balloons overflow menu and appear at topmost layer */
.web-pet.stored-in-menu .pet-balloon,
.web-pet.stored-in-menu .pet-balloon-container {
    /* Use absolute positioning to work with bottom: 100% from line 253-261 */
    z-index: 2147483649 !important;
}


/* Long-Press Context Menu */
.webpet-context-menu {
    position: fixed;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 8px;
    z-index: 2147483648;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.webpet-context-option {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.webpet-context-option:active {
    background: rgba(0, 0, 0, 0.05);
}