#chat-panel {
    position: fixed;
    left: 140px;
    bottom: 21px;
    width: min(330px, calc(100vw - 158px));
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 28;
    font-family: "Cooper Black", "Comic Sans MS", "Arial Black", sans-serif;
    color: #2f210e;
    pointer-events: auto;
    user-select: none;
}

#chat-panel.collapsed {
    width: 154px;
}

#chat-toggle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 8px 11px;
    border: 3px solid #fff7c7;
    border-radius: 16px;
    background:
        radial-gradient(circle at 14% 20%, rgba(255,255,255,0.86) 0 8%, transparent 9%),
        linear-gradient(145deg, #fff3a8 0%, #f0c35a 48%, #d8892d 100%);
    color: #3b250d;
    font: inherit;
    cursor: pointer;
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.8),
        inset 0 -6px 0 rgba(120,67,22,0.16),
        0 5px 0 #74461d,
        0 10px 18px rgba(0,0,0,0.26);
    text-shadow: 1px 1px 0 rgba(255,255,255,0.72);
}

#chat-toggle:active {
    transform: translateY(3px);
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.7),
        inset 0 -4px 0 rgba(120,67,22,0.16),
        0 2px 0 #74461d,
        0 5px 10px rgba(0,0,0,0.22);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.92rem;
    line-height: 1;
}

.chat-icon {
    display: inline-grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 50%;
    background: linear-gradient(180deg, #70e6ff, #2c83ff);
    color: #fff;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,0.16);
}

.chat-minmax {
    font-size: 1rem;
    line-height: 1;
    transition: transform 180ms ease;
}

#chat-panel.expanded .chat-minmax {
    transform: rotate(180deg);
}

#chat-unread {
    position: absolute;
    top: -8px;
    right: -8px;
    display: none;
    min-width: 21px;
    height: 21px;
    place-items: center;
    padding: 0 5px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #ff3b44;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1;
    box-shadow: 0 3px 0 #93171d;
}

#chat-unread.show {
    display: grid;
    animation: chatBadgePop 440ms ease;
}

#chat-body {
    display: none;
    margin: 0;
    padding: 10px;
    border: 3px solid #fff7c7;
    border-radius: 16px;
    background:
        linear-gradient(180deg, rgba(255,251,218,0.96), rgba(255,229,150,0.94)),
        #ffe9a6;
    box-shadow:
        inset 0 2px 0 rgba(255,255,255,0.74),
        0 5px 0 #74461d,
        0 14px 24px rgba(0,0,0,0.28);
}

#chat-panel.expanded #chat-body {
    display: block;
    animation: chatOpen 180ms ease-out;
}

#chat-panel.expanded {
    width: min(330px, calc(100vw - 158px));
}

#chat-messages {
    height: 184px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 4px 6px;
    border: 2px solid rgba(92,54,20,0.22);
    border-radius: 10px;
    background: rgba(255,255,255,0.45);
    scrollbar-width: thin;
    user-select: text;
}

.chat-message {
    padding: 7px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,0.46);
    box-shadow: inset 0 -2px 0 rgba(104,72,20,0.08);
}

.chat-message + .chat-message {
    margin-top: 6px;
}

.chat-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
    font-size: 0.72rem;
}

.chat-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.78);
}

.chat-time {
    flex: 0 0 auto;
    color: rgba(77,50,20,0.58);
    font-family: Arial, sans-serif;
    font-size: 0.66rem;
}

.chat-text {
    color: #2c2114;
    font-family: Arial, sans-serif;
    font-size: 0.84rem;
    font-weight: 800;
    line-height: 1.22;
    overflow-wrap: anywhere;
    letter-spacing: 0;
    text-shadow: none;
}

#chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 7px;
    margin-top: 9px;
}

#chat-input {
    min-width: 0;
    height: 38px;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 2px solid #875326;
    border-radius: 10px;
    background: #fffdf0;
    color: #2d1c0a;
    font: 800 0.86rem Arial, sans-serif;
    outline: none;
}

#chat-input:focus {
    border-color: #2d8fff;
    box-shadow: 0 0 0 3px rgba(45,143,255,0.22);
}

#chat-send {
    min-height: 38px;
    border: 2px solid #ffffff;
    border-radius: 10px;
    background: linear-gradient(180deg, #6df283, #24aa44);
    color: #113718;
    font: 900 0.76rem "Arial Black", sans-serif;
    cursor: pointer;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,0.16), 0 3px 0 #1b6f2e;
}

#chat-send:disabled {
    opacity: 0.58;
    cursor: default;
    filter: grayscale(0.35);
}

.chat-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 17px;
    margin-top: 5px;
    font: 700 0.68rem Arial, sans-serif;
    color: rgba(72,45,18,0.72);
}

#chat-count.max {
    color: #b02727;
}

.chat-status.error { color: #b02727; }
.chat-status.ok { color: #18772d; }
.chat-status.cooldown { color: #6b4b08; }
.chat-status.sending { color: #225d9a; }

@keyframes chatOpen {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes chatBadgePop {
    0% { transform: scale(0.55); }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@media (max-width: 768px) {
    #chat-panel {
        left: 136px;
        bottom: 21px;
        width: min(230px, calc(100vw - 146px));
    }

    #chat-panel.collapsed {
        width: min(126px, calc(100vw - 146px));
    }

    #chat-panel.expanded {
        width: min(230px, calc(100vw - 146px));
    }

    #chat-messages {
        height: 130px;
    }

    #chat-toggle {
        min-height: 42px;
        padding: 7px 10px;
    }
}
