/* character.css — Reusable character (Pushkin) widget */

/* === Layout === */

.char-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0;
}

/* Sidebar variant (sticky, right column) — used in profile edit */
.char-widget--sidebar {
    position: sticky;
    top: 90px;
    padding-top: 8px;
}

/* Inline variant (top of page, horizontal) — used on other pages */
.char-widget--inline {
    flex-direction: row;
    align-items: flex-start;
    text-align: left;
    gap: 20px;
    padding: 20px;
    margin-bottom: 24px;
    border-radius: 16px;
    background: var(--container-bg, #FDFAF5);
    border: 1px solid var(--border-color, #D9CEBC);
    box-shadow: 0 2px 12px var(--shadow-color, rgba(30,20,16,0.08));
}

/* Wizard variant (compact, inside the first-run modal) */
.char-widget--wizard {
    gap: 14px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.char-widget--wizard .char-widget__img {
    width: 64px;
    height: 64px;
    border-radius: 12px;
}

.char-widget--wizard .char-widget__bubble {
    padding: 10px 14px;
    max-width: none;
}

.char-widget--wizard .char-widget__speech {
    font-size: 0.95rem;
}

/* === Avatar === */

.char-widget__avatar {
    flex-shrink: 0;
    line-height: 0;
}

.char-widget__img {
    width: 100%;
    max-width: 260px;
    border-radius: 18px;
    box-shadow: 0 4px 20px var(--shadow-color, rgba(30,20,16,0.10));
    transition: opacity 0.25s ease;
    /* Gentle breathing animation */
    animation: charBreathe 4s ease-in-out infinite;
}

.char-widget--inline .char-widget__img {
    width: 90px;
    height: 90px;
    max-width: none;
    object-fit: cover;
    border-radius: 14px;
}

@keyframes charBreathe {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-4px) scale(1.012); }
}

/* === Speech bubble === */

.char-widget__bubble {
    position: relative;
    margin-top: 16px;
    padding: 14px 18px;
    background: var(--container-bg, #FDFAF5);
    border: 1px solid var(--border-color, #D9CEBC);
    border-radius: 16px;
    box-shadow: 0 2px 10px var(--shadow-color, rgba(30,20,16,0.06));
    max-width: 280px;
}

/* Tail pointing up toward the avatar */
.char-widget__bubble::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 16px;
    height: 16px;
    background: var(--container-bg, #FDFAF5);
    border-left: 1px solid var(--border-color, #D9CEBC);
    border-top: 1px solid var(--border-color, #D9CEBC);
    border-radius: 3px 0 0 0;
}

/* Inline variant: tail on the left side */
.char-widget--inline .char-widget__bubble {
    margin-top: 0;
    max-width: 520px;
}

.char-widget--inline .char-widget__bubble::before {
    top: 20px;
    left: -8px;
    transform: rotate(225deg);
}

.char-widget__speech {
    font-size: 1rem;
    color: var(--text-secondary, #6B5C4A);
    line-height: 1.5;
    margin: 0;
    /* Fade-in when text changes */
    animation: charSpeechFade 0.35s ease;
}

@keyframes charSpeechFade {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === State modifiers === */

/* Thinking state — during AI generation */
.char-widget.is-thinking .char-widget__img {
    animation: charThink 1.8s ease-in-out infinite;
}

@keyframes charThink {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25%      { transform: translateY(-3px) rotate(-1.5deg); }
    75%      { transform: translateY(-3px) rotate(1.5deg); }
}

/* Success state — after save */
.char-widget.is-success .char-widget__img {
    animation: charSuccess 0.6s ease;
}

@keyframes charSuccess {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.08) translateY(-6px); }
    100% { transform: scale(1) translateY(0); }
}

.char-widget.is-success .char-widget__bubble {
    border-color: var(--success-color, #20c997);
    background: rgba(32, 201, 151, 0.08);
}

.char-widget.is-success .char-widget__bubble::before {
    background: rgba(32, 201, 151, 0.08);
    border-color: var(--success-color, #20c997);
}

/* === Mobile === */

@media (max-width: 768px) {
    .char-widget--sidebar {
        position: static;
        flex-direction: row;
        align-items: center;
        text-align: left;
        gap: 16px;
    }

    .char-widget--sidebar .char-widget__img {
        max-width: 100px;
        animation: none; /* disable on mobile to save battery */
    }

    .char-widget--sidebar .char-widget__bubble {
        margin-top: 0;
        max-width: none;
        flex: 1;
    }

    .char-widget--sidebar .char-widget__bubble::before {
        top: 20px;
        left: -8px;
        transform: rotate(225deg);
    }

    .char-widget--sidebar .char-widget__speech {
        font-size: 0.9rem;
    }

    .char-widget--inline {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
        padding: 16px;
    }

    .char-widget--inline .char-widget__img {
        width: 70px;
        height: 70px;
    }

    .char-widget--inline .char-widget__bubble {
        max-width: 100%;
    }

    .char-widget--inline .char-widget__bubble::before {
        top: -8px;
        left: 50%;
        transform: translateX(-50%) rotate(45deg);
    }
}
