.mascot {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9000;
    width: 160px;
    height: 160px;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.mascot.is-visible {
    opacity: 1;
    visibility: visible;
}

.mascot[hidden] { display: none; }

/* ---------- Персонаж ---------- */
.mascot__viewer {
    width: 100%;
    height: 100%;
    background: transparent;
    pointer-events: auto;
    cursor: pointer;
    border-radius: 0;
    filter: drop-shadow(0 8px 18px rgba(244, 196, 84, 0.30));
    transition: transform 0.25s ease, filter 0.25s ease;
    touch-action: none; /* нужно для раскрутки пальцем/мышью */
}

.mascot__viewer:hover,
.mascot.is-hover .mascot__viewer {
    transform: translateY(-5px) scale(1.05);
    filter: drop-shadow(0 12px 24px rgba(15, 145, 206, 0.45));
}

.mascot__viewer:active { transform: translateY(-2px) scale(1.02); }

/* "закружилась голова" — от раскрутки персонажа */
.mascot.is-dizzy .mascot__viewer { animation: mascot-wobble 0.5s ease-in-out 3; }

@keyframes mascot-wobble {
    0%, 100% { transform: translateY(-2px) rotate(0deg); }
    25%      { transform: translateY(-2px) rotate(-6deg); }
    75%      { transform: translateY(-2px) rotate(6deg); }
}

/* "раздражение" — от слишком частых кликов, отдельная реакция */
.mascot.is-angry .mascot__viewer {
    animation: mascot-angry-shake 0.45s ease-in-out 2;
    filter: drop-shadow(0 0 16px rgba(224, 64, 64, 0.65));
}

@keyframes mascot-angry-shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    20%      { transform: translate(-4px, 0) rotate(-4deg); }
    40%      { transform: translate(4px, 0) rotate(4deg); }
    60%      { transform: translate(-3px, -2px) rotate(-3deg); }
    80%      { transform: translate(3px, -2px) rotate(3deg); }
}

/* ---------- Чат ---------- */
.mascot__chat {
    position: absolute;
    right: 100%;
    bottom: 24px;
    margin-right: 12px;
    width: 340px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    background: #12160f;
    border: 1px solid #f4c454;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
    color: #e8f5e0;
    font: 400 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.mascot__chat[data-open="true"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.mascot__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #f4c454;
    flex: 0 0 auto;
}

.mascot__title {
    font-size: 15px;
    font-weight: 600;
    color: #f4c454;
}

.mascot__close {
    width: 26px;
    height: 26px;
    border: 1px solid #f4c454;
    border-radius: 0;
    background: transparent;
    color: #f4c454;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.mascot__close:hover { background: #f4c454; color: #12160f; }

.mascot__log {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 120px;
}

.mascot__msg {
    max-width: 92%;
    padding: 9px 11px;
    border-radius: 0;
    border: 1px solid #f4c454;
    background: #171c14;
    white-space: pre-line;
    word-break: break-word;
}

.mascot__msg--user {
    align-self: flex-end;
    border-color: #0F91CE;
    background: #0f2733;
    color: #dff1fa;
}

.mascot__caret {
    display: inline-block;
    width: 8px;
    border-bottom: 2px solid #f4c454;
    animation: mascot-blink 0.9s step-end infinite;
}

@keyframes mascot-blink { 50% { opacity: 0; } }

.mascot__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #f4c454;
    flex: 0 0 auto;
}

.mascot__chip,
.mascot__cta {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #f4c454;
    border-radius: 0;
    background: #0F91CE;
    color: #ffffff;
    font: 600 14px/1.2 inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: filter 0.18s ease;
}

.mascot__chip:hover,
.mascot__cta:hover { filter: brightness(1.12); }

.mascot__chip[disabled] { opacity: 0.55; cursor: default; }

.mascot__cta {
    background: transparent;
    color: #f4c454;
}

.mascot__cta:hover { background: #f4c454; color: #12160f; filter: none; }

.mascot__close:focus-visible,
.mascot__chip:focus-visible,
.mascot__cta:focus-visible,
.mascot__viewer:focus-visible {
    outline: 2px solid #0F91CE;
    outline-offset: 2px;
}

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 640px) {
    .mascot {
        width: 96px;
        height: 96px;
        right: 12px;
        bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    /* Чат превращается в нижний bottom-sheet на весь экран по ширине */
    .mascot__chat {
        position: fixed;
        right: 0;
        left: 0;
        bottom: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
        max-height: min(78dvh, 78vh);
        border: none;
        border-top: 1px solid #f4c454;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        transform: translateY(100%);
        box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.55);
    }

    .mascot__chat[data-open="true"] {
        transform: translateY(0);
    }

    .mascot__head {
        padding: 14px 16px;
    }

    .mascot__title {
        font-size: 16px;
    }

    .mascot__close {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .mascot__log {
        padding: 14px 16px;
        min-height: 96px;
    }

    .mascot__msg {
        max-width: 88%;
        font-size: 15px;
    }

    .mascot__actions {
        padding: 12px 16px 16px;
        gap: 10px;
    }

    .mascot__chip,
    .mascot__cta {
        padding: 13px 14px;
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mascot__viewer, .mascot__chat { transition: none; }
    .mascot.is-dizzy .mascot__viewer { animation: none; }
    .mascot.is-angry .mascot__viewer { animation: none; }
    .mascot__caret { animation: none; }
}