#tte-tartar.tte-wrap {
    --tte-green: #b9efc7;
    --tte-ink: #111;
    position: relative;
    display: grid;
    grid-template-columns: minmax(145px, 190px) minmax(260px, 1fr);
    gap: 12px 8px;
    align-items: end;
    margin: 40px 0 18px;
    padding: 8px 0 4px;
    min-height: 250px;
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
}

.tte-character-zone {
    display: contents;
}

.tte-stage {
    grid-column: 1;
    grid-row: 1 / span 2;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    min-height: 210px;
    position: relative;
    z-index: 2;
}

.tte-avatar {
    display: block;
    max-width: 100%;
    max-height: 250px;
    height: auto;
    object-fit: contain;
    transform-origin: 50% 100%;
    filter: drop-shadow(0 12px 18px rgba(0,0,0,.16));
}

.tte-avatar.is-talking { animation: tteLocalTalk .42s ease-in-out infinite alternate; }
@keyframes tteLocalTalk {
    from { transform: translateY(0) scale(1); }
    to   { transform: translateY(-4px) scale(1.025); }
}

.tte-avatar-placeholder {
    width: 150px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #222;
    color: #fff;
    font-weight: 800;
}

.tte-messages {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    min-height: 96px;
    max-height: 190px;
    overflow-y: auto;
    overflow-x: visible;
    padding: 6px 10px 10px 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    scroll-behavior: smooth;
    scrollbar-width: none;
}
.tte-messages::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.tte-msg {
    width: fit-content;
    max-width: min(430px, 88%);
    padding: 9px 14px;
    border-radius: 999px;
    line-height: 1.32;
    font-size: 14px;
    font-weight: 650;
    box-shadow: 0 10px 26px rgba(0,0,0,.12);
    animation: tteBubblePop .34s cubic-bezier(.18,.9,.35,1.25) both;
    position: relative;
}

@keyframes tteBubblePop {
    0% { opacity: 0; transform: scale(.72) translateY(8px); }
    70% { opacity: 1; transform: scale(1.04) translateY(-1px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.tte-bot {
    margin-left: 0;
    margin-right: auto;
    background: #fff;
    color: #111;
}
.tte-bot::after {
    content: '';
    position: absolute;
    left: -5px;
    bottom: 12px;
    width: 14px;
    height: 14px;
    background: inherit;
    border-radius: 3px;
    transform: rotate(45deg);
    z-index: -1;
}

.tte-user {
    margin-left: auto;
    margin-right: 2%;
    background: var(--tte-green);
    color: var(--tte-ink);
    box-shadow: 0 10px 24px rgba(0,0,0,.11);
}
/* User bubbles intentionally have no tail. */
.tte-user::after { display: none; }

.tte-controls {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    min-width: 0;
    z-index: 4;
}

.tte-form {
    display: flex;
    gap: 8px;
    margin: 0;
}
.tte-form input {
    flex: 1;
    min-width: 0;
    padding: 11px 15px;
    border-radius: 999px;
    border: 1px solid rgba(0,0,0,.16);
    background: #fff;
    color: #111;
    box-shadow: 0 7px 20px rgba(0,0,0,.07);
    outline: none;
}
.tte-form input:focus {
    border-color: rgba(0,0,0,.34);
    box-shadow: 0 7px 20px rgba(0,0,0,.09), 0 0 0 3px rgba(185,239,199,.42);
}

.tte-form button,
.tte-actions button,
.tte-snack {
    cursor: pointer;
    border: 0;
    font-weight: 750;
}

#tte-send {
    border-radius: 999px;
    padding: 10px 16px;
    background: #111;
    color: #fff;
}

.tte-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 9px;
}
.tte-actions button {
    border-radius: 999px;
    padding: 8px 12px;
    background: rgba(255,255,255,.92);
    color: #111;
    box-shadow: 0 6px 16px rgba(0,0,0,.08);
    transition: transform .16s ease, box-shadow .16s ease;
}
#tte-comment { background: #fff; }
#tte-treat { background: #f7e3a1; }
.tte-actions button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(0,0,0,.11); }

.tte-treat-menu {
    position: absolute;
    z-index: 20;
    right: 0;
    bottom: calc(100% + 10px);
    width: min(430px, 94vw);
    padding: 9px;
    border-radius: 20px;
    background: rgba(255,255,255,.97);
    box-shadow: 0 16px 40px rgba(0,0,0,.18);
    animation: tteMenuPop .2s ease-out both;
}
.tte-treat-menu[hidden] { display: none; }
.tte-treat-menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 7px 7px 10px;
    color: #111;
    font-size: 13px;
}
.tte-treat-close {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: #f1f1f3;
    color: #111;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.tte-treat-close:hover { background: #e7e7ea; }
@keyframes tteMenuPop {
    from { opacity: 0; transform: translateY(8px) scale(.97); }
    to { opacity: 1; transform: none; }
}
.tte-snack {
    width: 100%;
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 10px;
    align-items: center;
    text-align: left;
    padding: 9px 11px;
    border-radius: 14px;
    background: transparent;
    color: #111;
}
.tte-snack:hover { background: rgba(0,0,0,.055); }
.tte-snack-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 30px;
    background: #f6f6f7;
}
.tte-snack strong,
.tte-snack small { display: block; }
.tte-snack small { margin-top: 2px; opacity: .58; font-weight: 600; }

.tte-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    min-height: 18px;
    margin-top: 5px;
}
.tte-status,
.tte-balance {
    color: #d2a126;
    font-size: 12px;
    font-weight: 750;
    text-shadow: 0 1px 2px rgba(0,0,0,.24);
}
.tte-balance { white-space: nowrap; }

.tte-form button:disabled,
.tte-actions button:disabled,
.tte-snack:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 620px) {
    #tte-tartar.tte-wrap {
        grid-template-columns: 118px minmax(0, 1fr);
        gap: 8px 5px;
        min-height: 205px;
        margin: 30px 0 12px;
    }
    .tte-stage { min-height: 170px; }
    .tte-avatar { max-height: 205px; }
    .tte-messages { max-height: 165px; }
    .tte-msg { max-width: 96%; font-size: 13px; padding: 8px 12px; }
    .tte-form { gap: 6px; }
    .tte-form input { padding: 10px 13px; }
    #tte-send { padding: 9px 13px; }
    .tte-actions { gap: 6px; }
    .tte-actions button { padding: 7px 10px; font-size: 12px; }
    .tte-treat-menu { right: -4px; }
}


/* v0.3.5: preserve scrolling while giving Tar-Tar's left tail room */
.tte-chat,
.tte-chat-area,
.tte-bubble-stack,
.tte-message-list,
.tte-conversation,
.tte-messages {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

.tte-chat::-webkit-scrollbar,
.tte-chat-area::-webkit-scrollbar,
.tte-bubble-stack::-webkit-scrollbar,
.tte-message-list::-webkit-scrollbar,
.tte-conversation::-webkit-scrollbar,
.tte-messages::-webkit-scrollbar {
  display: none !important;
}

.tte-chat-column {
  overflow: visible !important;
}

.tte-bubble,
.tte-message,
.tte-tartar-bubble,
.tte-assistant-bubble {
  overflow: visible !important;
}

/* Keep the left-pointing Tar-Tar tail inside the scroll viewport instead of clipping it. */
.tte-chat,
.tte-chat-area,
.tte-bubble-stack,
.tte-message-list,
.tte-conversation,
.tte-messages {
  padding-left: 14px !important;
}


/* v0.3.6-safe: subtle coin prices */
.tte-price-line,
.tte-snack-price {
  display: block;
  margin-top: 2px;
  color: #d7a928 !important;
  font-size: 10px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: .02em;
}


/* v0.4.0: widget-style panel with Tar-Tar peeking from behind */
#tte-tartar.tte-wrap {
    --tte-widget-blue: #00c8ff;
    --tte-widget-glow: rgba(0, 200, 255, .34);
    --tte-widget-panel: rgba(8, 18, 28, .84);
    max-width: 470px;
    padding-top: 14px;
    padding-bottom: 10px;
    isolation: isolate;
    grid-template-columns: 122px minmax(0, 1fr);
    gap: 10px 6px;
    align-items: end;
    min-height: 238px;
}

#tte-tartar.tte-wrap::before {
    content: "";
    position: absolute;
    left: 88px;
    right: 0;
    top: 58px;
    bottom: 0;
    z-index: 1;
    border: 2px solid var(--tte-widget-blue);
    border-radius: 18px;
    background: var(--tte-widget-panel);
    box-shadow:
        0 0 10px var(--tte-widget-glow),
        0 0 26px rgba(0, 200, 255, .18),
        0 0 48px rgba(0, 200, 255, .10),
        inset 0 0 20px rgba(0, 200, 255, .05);
}

.tte-stage {
    min-height: 190px;
    justify-content: flex-end;
    align-items: flex-end;
    z-index: 0;
    overflow: visible;
}

.tte-avatar {
    max-height: 208px;
    transform: translateX(14px) translateY(18px);
    filter: drop-shadow(0 10px 18px rgba(0,0,0,.20));
}

.tte-messages,
.tte-controls {
    position: relative;
    z-index: 2;
    background: transparent;
}

.tte-messages {
    min-height: 96px;
    max-height: 154px;
    padding: 0 12px 0 18px !important;
    margin-top: -4px;
    gap: 8px;
}

.tte-msg {
    overflow-wrap: break-word;
    line-height: 1.38;
    box-shadow: 0 6px 18px rgba(0,0,0,.16);
}

.tte-bot {
    border-radius: 22px;
    max-width: 96%;
}
.tte-bot::after {
    left: -6px;
    bottom: 14px;
}

.tte-user {
    max-width: 86%;
}

.tte-controls {
    padding: 10px 12px 12px 16px;
}

.tte-form {
    gap: 7px;
}

.tte-form input {
    min-height: 42px;
    border-radius: 999px;
    border: 1px solid rgba(15, 34, 48, .26);
    box-shadow: 0 5px 14px rgba(0,0,0,.12);
}

#tte-send {
    min-height: 42px;
    min-width: 42px;
    padding: 0 13px;
    border-radius: 999px;
    box-shadow: 0 6px 14px rgba(0,0,0,.15);
}

.tte-actions {
    margin-top: 8px;
    gap: 7px;
}

.tte-actions button {
    padding: 7px 11px;
    font-size: 11px;
    box-shadow: 0 5px 12px rgba(0,0,0,.12);
}

.tte-meta {
    margin-top: 8px;
    padding-left: 2px;
}

.tte-treat-menu {
    z-index: 5;
}

@media (max-width: 620px) {
    #tte-tartar.tte-wrap {
        max-width: 100%;
        grid-template-columns: 94px minmax(0, 1fr);
        gap: 8px 5px;
        min-height: 0;
        padding-top: 8px;
        margin: 22px 0 12px;
    }

    #tte-tartar.tte-wrap::before {
        left: 66px;
        right: 0;
        top: 46px;
        bottom: 0;
        border-radius: 16px;
    }

    .tte-stage {
        grid-column: 1;
        grid-row: 1;
        min-height: 122px;
    }

    .tte-avatar {
        max-height: 138px;
        transform: translateX(10px) translateY(13px);
    }

    .tte-messages {
        grid-column: 2;
        grid-row: 1;
        min-height: 74px;
        max-height: 112px;
        padding: 0 10px 0 16px !important;
        margin-top: 0;
        gap: 7px;
        align-self: start;
    }

    .tte-msg {
        font-size: 13px;
        line-height: 1.4;
        padding: 9px 13px;
    }

    .tte-controls {
        grid-column: 1 / -1;
        grid-row: 2;
        padding: 8px 10px 10px 12px;
        margin-top: 2px;
    }

    .tte-form input {
        min-height: 40px;
        padding: 10px 13px;
    }

    #tte-send {
        min-height: 40px;
        min-width: 40px;
        padding: 0 12px;
        font-size: 12px;
    }

    .tte-actions {
        gap: 6px;
        margin-top: 7px;
    }

    .tte-actions button {
        padding: 6px 10px;
        font-size: 10.5px;
        box-shadow: 0 4px 10px rgba(0,0,0,.10);
        opacity: .96;
    }

    .tte-meta {
        margin-top: 7px;
    }

    .tte-treat-menu {
        left: 8px;
        right: 8px;
        width: auto;
        bottom: calc(100% + 8px);
    }
}


/* v0.4.1: move Tar-Tar up into the top-left corner of the widget */
.tte-stage {
    align-items: flex-start;
    justify-content: flex-end;
    min-height: 178px;
}

.tte-avatar {
    max-height: 214px;
    transform: translateX(12px) translateY(-8px);
}

@media (max-width: 620px) {
    .tte-stage {
        align-items: flex-start;
        min-height: 112px;
    }

    .tte-avatar {
        max-height: 134px;
        transform: translateX(8px) translateY(-6px);
    }
}


/* v0.4.2: lift Tar-Tar higher on the top-left edge */
.tte-stage {
    align-items: flex-start;
    justify-content: flex-end;
    min-height: 168px;
}

.tte-avatar {
    max-height: 216px;
    transform: translateX(10px) translateY(-34px);
}

@media (max-width: 620px) {
    .tte-stage {
        align-items: flex-start;
        min-height: 102px;
    }

    .tte-avatar {
        max-height: 136px;
        transform: translateX(6px) translateY(-20px);
    }
}


/* v0.4.3: move Tar-Tar much higher so his head sits up near the bubble */
.tte-stage {
    align-items: flex-start;
    justify-content: flex-end;
    min-height: 126px;
    overflow: visible;
}

.tte-avatar {
    max-height: 224px;
    transform: translateX(8px) translateY(-92px);
}

@media (max-width: 620px) {
    .tte-stage {
        align-items: flex-start;
        min-height: 74px;
        overflow: visible;
    }

    .tte-avatar {
        max-height: 142px;
        transform: translateX(4px) translateY(-58px);
    }
}


/* v0.4.4: lift Tar-Tar clearly above the speech bubble */
.tte-stage {
    align-items: flex-start;
    justify-content: flex-end;
    min-height: 96px;
    overflow: visible;
}

.tte-avatar {
    max-height: 230px;
    transform: translateX(6px) translateY(-142px);
}

@media (max-width: 620px) {
    .tte-stage {
        align-items: flex-start;
        min-height: 56px;
        overflow: visible;
    }

    .tte-avatar {
        max-height: 146px;
        transform: translateX(2px) translateY(-92px);
    }
}


/* v0.4.5: nudge Tar-Tar slightly higher and substantially rightward */
.tte-avatar {
    max-height: 230px;
    transform: translateX(34px) translateY(-154px);
}

@media (max-width: 620px) {
    .tte-avatar {
        max-height: 146px;
        transform: translateX(22px) translateY(-100px);
    }
}


/* v0.4.6: keep talking animation in-place and move Tar-Tar in front of the panel */
.tte-stage {
    position: relative;
    z-index: 4; /* Tar-Tar now sits in front of the chat window */
    overflow: visible;
}

.tte-messages,
.tte-controls {
    z-index: 2;
}

.tte-avatar {
    position: relative;
    z-index: 5;
    --tte-avatar-x: 34px;
    --tte-avatar-y: -154px;
    width: 152px;
    height: 152px;
    max-width: none;
    max-height: none;
    object-fit: contain;
    object-position: center bottom;
    transform: translateX(var(--tte-avatar-x)) translateY(var(--tte-avatar-y));
}

/* Override the earlier talk animation so it preserves placement */
.tte-avatar.is-talking {
    animation: tteLocalTalkFixed .42s ease-in-out infinite alternate !important;
}

@keyframes tteLocalTalkFixed {
    from {
        transform: translateX(var(--tte-avatar-x)) translateY(var(--tte-avatar-y)) scale(1);
    }
    to {
        transform: translateX(var(--tte-avatar-x)) translateY(calc(var(--tte-avatar-y) - 4px)) scale(1.025);
    }
}

@media (max-width: 620px) {
    .tte-stage {
        z-index: 4;
        overflow: visible;
    }

    .tte-avatar {
        --tte-avatar-x: 22px;
        --tte-avatar-y: -100px;
        width: 116px;
        height: 116px;
        max-width: none;
        max-height: none;
        object-fit: contain;
        object-position: center bottom;
        transform: translateX(var(--tte-avatar-x)) translateY(var(--tte-avatar-y));
    }

    .tte-avatar.is-talking {
        animation: tteLocalTalkFixed .42s ease-in-out infinite alternate !important;
    }
}
/* v0.4.7-mobile — phone-specific composition.
   Desktop styles above are intentionally untouched. */
@media screen and (max-width: 620px) {
    #tte-tartar.tte-wrap {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 460px;
        min-width: 0;
        box-sizing: border-box;
        margin: 25px auto 18px;
        padding: 4px 8px 10px;
        gap: 0;
        min-height: 0;
        overflow: visible;
        isolation: isolate;
    }

    /* The border starts beneath Tar-Tar's head, not halfway across the inputs. */
    #tte-tartar.tte-wrap::before {
        left: 0;
        right: 0;
        top: 62px;
        bottom: 0;
        border-radius: 18px;
    }

    #tte-tartar .tte-character-zone {
        display: grid;
        grid-template-columns: clamp(84px, 27%, 112px) minmax(0, 1fr);
        align-items: center;
        column-gap: 0;
        width: 100%;
        min-width: 0;
        position: relative;
        z-index: 4;
    }

    #tte-tartar .tte-stage {
        grid-column: 1;
        grid-row: 1;
        position: relative;
        z-index: 5;
        width: 100%;
        height: 157px;
        min-height: 157px;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: visible;
    }

    #tte-tartar .tte-avatar {
        position: relative;
        z-index: 6;
        box-sizing: border-box;
        width: clamp(105px, 30vw, 135px);
        height: 148px;
        max-width: none;
        max-height: none;
        object-fit: contain;
        object-position: center center;
        flex: none;
        --tte-avatar-x: 0px;
        --tte-avatar-y: 0px;
        transform: translate(0, 0);
        margin: 0 -10px 0 -2px;
    }

    /* Reuse v0.4.6's image swap and animation, without desktop offsets. */
    #tte-tartar .tte-avatar.is-talking {
        --tte-avatar-x: 0px;
        --tte-avatar-y: 0px;
    }

    #tte-tartar .tte-avatar-placeholder {
        width: 84px;
        height: 84px;
        flex: none;
        font-size: 12px;
    }

    #tte-tartar .tte-messages {
        grid-column: 2;
        grid-row: 1;
        align-self: center;
        display: flex;
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
        min-height: 92px;
        max-height: 168px;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 7px 6px 10px 13px !important;
        margin: 0;
        gap: 6px;
        scrollbar-width: none;
        overscroll-behavior: contain;
    }

    #tte-tartar .tte-msg {
        box-sizing: border-box;
        width: fit-content;
        max-width: 100%;
        font-size: 13px;
        line-height: 1.34;
        padding: 9px 11px;
        border-radius: 17px;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: normal;
    }
    #tte-tartar .tte-bot { margin-left: 0; margin-right: auto; }
    #tte-tartar .tte-bot::after { left: -5px; bottom: 19px; }
    #tte-tartar .tte-user { max-width: 94%; margin-left: auto; margin-right: 0; }

    #tte-tartar .tte-controls {
        box-sizing: border-box;
        position: relative;
        z-index: 3;
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        padding: 10px 7px 12px;
        margin: 0;
    }

    #tte-tartar .tte-form {
        display: flex;
        align-items: stretch;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        gap: 7px;
        margin: 0;
    }

    #tte-tartar .tte-form input {
        box-sizing: border-box;
        display: block;
        flex: 1 1 0;
        width: 0;
        min-width: 0;
        min-height: 45px;
        padding: 10px 12px;
        font-size: 16px; /* prevent iOS focus zoom */
        line-height: 1.25;
    }

    #tte-tartar #tte-send {
        flex: 0 0 auto;
        box-sizing: border-box;
        width: auto;
        min-width: 62px;
        min-height: 45px;
        padding: 0 11px;
        font-size: 12px;
        line-height: 1.2;
    }

    #tte-tartar .tte-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        width: 100%;
        min-width: 0;
        gap: 7px;
        margin-top: 9px;
        align-items: stretch;
    }

    #tte-tartar .tte-actions button {
        box-sizing: border-box;
        min-width: 0;
        width: 100%;
        min-height: 44px;
        padding: 9px 7px;
        font-size: 11px;
        line-height: 1.22;
        white-space: normal;
        overflow-wrap: anywhere;
        text-align: center;
    }

    #tte-tartar .tte-price-line { margin-top: 3px; }

    #tte-tartar .tte-meta {
        flex-wrap: wrap;
        min-width: 0;
        gap: 5px 10px;
        margin: 8px 0 0;
        padding: 0 2px;
    }
    #tte-tartar .tte-balance {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    #tte-tartar .tte-treat-menu {
        box-sizing: border-box;
        left: 0;
        right: 0;
        width: auto;
        max-width: 100%;
        bottom: calc(100% + 8px);
    }
}

@media screen and (max-width: 350px) {
    #tte-tartar .tte-character-zone {
        grid-template-columns: 81px minmax(0, 1fr);
    }
    #tte-tartar .tte-avatar {
        width: 106px;
        height: 140px;
    }
    #tte-tartar .tte-msg { font-size: 12px; padding: 8px 9px; }
    #tte-tartar .tte-actions button { font-size: 10px; }
}

/* v0.4.8 — Snack menu layers above Tar-Tar only while it is open.
   The menu lives within .tte-controls, so raising the menu's own z-index
   cannot cross the lower stacking context of its parent. */
#tte-tartar.tte-wrap.tte-menu-open .tte-controls {
    z-index: 10;
}
