/* Interactive Mascot and Chat styling */

.mascot-widget {
    position: fixed;
    bottom: 0px;
    left: 40px;
    right: auto;
    width: 168px;
    z-index: 10000;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s ease, opacity 0.3s ease;
    user-select: none;
}

.mascot-widget:hover {
    transform: scale(1.08) translateY(-4px);
}

.mascot-avatar {
    width: 168px;
    height: 125px;
    background-image: url("/assets/tera-theme/tera-mascot-cat-spritesheet.png?v=spritesheet");
    background-size: calc(168px * 112) 125px;
    background-repeat: no-repeat;
    background-position: 0px 0px;
    filter: drop-shadow(0 0 12px rgba(217, 183, 106, 0.35));
}

/* Flipping classes when pacing left/right */
.mascot-avatar.flip-h {
    transform: scaleX(-1);
}

.mascot-speech-bubble {
    position: absolute;
    bottom: 135px;
    background: rgba(9, 7, 18, 0.88);
    border: 1px solid rgba(217, 183, 106, 0.35);
    border-radius: 12px;
    padding: 8px 12px;
    width: 260px;
    color: #fff7fb;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 8px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(8px);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10000;
}

.mascot-speech-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.mascot-speech-bubble .bubble-arrow {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: rgba(9, 7, 18, 0.88);
    border-right: 1px solid rgba(217, 183, 106, 0.35);
    border-bottom: 1px solid rgba(217, 183, 106, 0.35);
}

.mascot-speech-bubble .bubble-text {
    display: block;
    max-height: min(190px, 34vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    pointer-events: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    scrollbar-gutter: stable;
    padding-right: 2px;
}

.mascot-speech-bubble .bubble-text::-webkit-scrollbar {
    width: 4px;
}

.mascot-speech-bubble .bubble-text::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.12);
}

.mascot-speech-bubble .bubble-text::-webkit-scrollbar-thumb {
    background: rgba(217, 183, 106, 0.38);
    border-radius: 999px;
}

/* Chat Drawer Layout */
.mascot-chat-drawer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 430px;
    background: rgba(9, 7, 18, 0.90);
    border: 1px solid rgba(217, 183, 106, 0.30);
    border-radius: 18px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65), inset 0 0 20px rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(20px);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
    overflow: hidden;
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mascot-chat-drawer.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.mascot-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 18px 18px 0 0;
}

.mascot-chat-title-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mascot-chat-status-dot {
    width: 8px;
    height: 8px;
    background-color: #ffd66b; /* Gold glowing */
    border-radius: 50%;
    box-shadow: 0 0 8px #ffd66b;
    animation: mascotPulse 2s infinite;
}

.mascot-chat-name {
    font-weight: 600;
    color: #ffd66b;
    font-size: 17px;
    letter-spacing: 0.5px;
}

.mascot-chat-close-btn {
    border: none;
    background: transparent;
    color: var(--muted, #b8a9c8);
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.mascot-chat-close-btn:hover {
    color: var(--accent, #ff7ac8);
}

.mascot-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mascot-chat-icon-btn {
    border: 1px solid rgba(217, 183, 106, 0.2);
    background: rgba(217, 183, 106, 0.06);
    color: rgba(217, 183, 106, 0.7);
    border-radius: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    padding: 0;
}

.mascot-chat-icon-btn:hover {
    background: rgba(217, 183, 106, 0.15);
    color: #ffd66b;
    border-color: rgba(217, 183, 106, 0.5);
}

/* Chat logs & messages — collapsed by default */
.mascot-chat-log {
    max-height: 0;
    overflow: hidden;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-gutter: stable;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), padding 0.35s ease;
}

/* When expanded, show the log */
.mascot-chat-drawer.chat-expanded .mascot-chat-log {
    max-height: min(400px, calc(100vh - 170px));
    padding: 16px;
    overflow-y: auto;
}

/* Custom Scrollbar for Chat */
.mascot-chat-log::-webkit-scrollbar {
    width: 6px;
}
.mascot-chat-log::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
.mascot-chat-log::-webkit-scrollbar-thumb {
    background: rgba(217, 183, 106, 0.2);
    border-radius: 3px;
}
.mascot-chat-log::-webkit-scrollbar-thumb:hover {
    background: rgba(217, 183, 106, 0.4);
}

.mascot-chat-message {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    overflow: visible;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.mascot-chat-message .msg-content {
    white-space: pre-wrap;
}

.mascot-chat-message.system-msg {
    align-self: center;
    max-width: 90%;
    text-align: center;
}

.mascot-chat-message.system-msg .msg-content {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--muted, #b8a9c8);
    font-size: 13px;
    border-radius: 8px;
    padding: 6px 12px;
}

.mascot-chat-message.user-msg {
    align-self: flex-end;
}

.mascot-chat-message.user-msg .msg-content {
    background: linear-gradient(135deg, var(--accent, #ff7ac8), color-mix(in srgb, var(--accent) 70%, #000));
    color: #fff;
    border-radius: 14px 14px 2px 14px;
    padding: 8px 12px;
    font-size: 15px;
    box-shadow: 0 4px 12px rgba(255, 122, 200, 0.15);
}

.mascot-chat-message.bot-msg {
    align-self: flex-start;
}

.mascot-chat-message.bot-msg .msg-content {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(217, 183, 106, 0.15);
    color: #fff7fb;
    border-radius: 14px 14px 14px 2px;
    padding: 8px 12px;
    font-size: 15px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Typing indicator */
.mascot-chat-message.bot-msg.typing .msg-content {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--muted, #b8a9c8);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Chat Input Form */
.mascot-chat-form {
    display: flex;
    padding: 10px 12px;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(217, 183, 106, 0.08);
    border-radius: 0 0 18px 18px;
    align-items: center;
}

#mascot-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(217, 183, 106, 0.18);
    border-radius: 22px;
    padding: 9px 16px;
    color: #fff7fb;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

#mascot-chat-input::placeholder {
    color: rgba(184, 169, 200, 0.5);
    font-style: italic;
}

#mascot-chat-input:focus {
    border-color: rgba(122, 215, 255, 0.5);
    box-shadow: 0 0 0 3px rgba(122, 215, 255, 0.08);
}

.mascot-send-btn {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd66b, #d9b76a);
    color: #0c0812;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    box-shadow: 0 4px 14px rgba(217, 183, 106, 0.3);
    padding: 0;
}

.mascot-send-btn:hover {
    transform: scale(1.1) translateY(-1px);
    box-shadow: 0 6px 20px rgba(217, 183, 106, 0.5);
    filter: brightness(1.1);
}

.mascot-send-btn:active {
    transform: scale(0.95);
}

@keyframes mascotPulse {
    0%, 100% { opacity: 0.6; box-shadow: 0 0 4px #ffd66b; }
    50% { opacity: 1; box-shadow: 0 0 10px #ffd66b; }
}

/* Custom sizing and alignment for the header divider in the chat drawer */
.mascot-chat-drawer .panel-divider {
    position: absolute;
    left: 50%;
    top: -47px !important;
    z-index: 10002;
    width: calc(100% - 40px);
    height: 112px !important;
    transform: translateX(-50%);
    pointer-events: none;
    background: none;
    opacity: 1;
}

.mascot-chat-drawer .tera-divider-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 50%;
}

/* Force reload the original dragon mascot for the Scroll to Top button to bypass cache */
body[data-theme="tera-rising"] .shell-mascot {
    background-image: url("/assets/tera-theme/tera-mascot-creature.png?v=dragon") !important;
}

@media (max-width: 768px) {
    .mascot-widget {
        bottom: 58px !important;
        transform: scale(0.78) !important;
        transform-origin: bottom left !important;
        z-index: 1000000 !important;
        transition: bottom 0.22s ease, transform 0.2s ease, opacity 0.3s ease;
    }

    body.mascot-chat-is-open .mascot-widget {
        bottom: 200px !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
    }

    body.mascot-chat-is-open .mascot-speech-bubble {
        bottom: 180px !important;
    }

    .mascot-chat-drawer {
        left: 10px !important;
        right: 10px !important;
        bottom: 68px !important;
        width: auto !important;
        max-height: min(440px, calc(100vh - 84px)) !important;
        transform-origin: bottom center !important;
        z-index: 1000005 !important;
    }

    .mascot-chat-drawer.open {
        transform: none !important;
    }

    .mascot-chat-drawer.chat-expanded .mascot-chat-log {
        max-height: min(260px, calc(100vh - 180px));
    }

    .mascot-chat-form {
        padding: 10px;
    }

    #mascot-chat-input {
        min-height: 44px;
        font-size: 16px;
    }
}
