/* Lobby Chat Widget — Discord / Messenger style overlay */

#lobby-chat-root.lobby-chat {
    position: fixed !important;
    right: 1rem !important;
    bottom: 1rem !important;
    left: auto !important;
    top: auto !important;
    z-index: 9999;
    /* Prefer % over 100vw — vw can exceed the visual viewport and cause sideways scroll. */
    width: min(30rem, calc(100% - 2rem));
    max-width: calc(100% - 2rem);
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    isolation: isolate;
    box-sizing: border-box;
}

#lobby-chat-root.lobby-chat:not(.is-minimized) {
    width: min(30rem, calc(100% - 2rem));
}

#lobby-chat-root.lobby-chat.is-minimized {
    width: auto;
    max-width: none;
}

#lobby-chat-root.lobby-chat > * {
    pointer-events: auto;
}

.lobby-chat-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 28rem;
    min-width: 22rem;
    min-height: 18rem;
    max-width: min(44rem, calc(100% - 2rem));
    box-sizing: border-box;
    max-height: calc(100vh - 4rem);
    resize: both;
    background: rgba(11, 16, 32, 0.97);
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-radius: 0.75rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    overflow: hidden;
    transform-origin: bottom right;
    transition:
        transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.24s ease;
}

.lobby-chat.is-minimized .lobby-chat-panel {
    display: none !important;
}

.lobby-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.7rem 0.8rem;
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.14), rgba(11, 16, 32, 0.2));
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    flex-shrink: 0;
}

.lobby-chat-header-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.lobby-chat-emoji {
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
}

.lobby-chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.lobby-chat-title-text {
    font-size: 0.92rem;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lobby-chat-online {
    font-size: 0.74rem;
    font-weight: 500;
    color: #86efac;
    letter-spacing: 0.02em;
}

.lobby-chat-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.lobby-chat-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65rem;
    height: 1.65rem;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 0.45rem;
    background: rgba(7, 11, 20, 0.55);
    color: #cbd5e1;
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.lobby-chat-header-btn:hover {
    background: rgba(220, 38, 38, 0.18);
    border-color: rgba(220, 38, 38, 0.35);
    color: #fecaca;
}

.lobby-chat-header-btn:active {
    transform: scale(0.94);
}

.lobby-chat-header-btn-minimize {
    font-size: 1.1rem;
}

.lobby-chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.lobby-chat-messages-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.lobby-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.7rem 0.8rem 0.5rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(220, 38, 38, 0.45) transparent;
}

.lobby-chat-messages::-webkit-scrollbar {
    width: 0.35rem;
}

.lobby-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(220, 38, 38, 0.45);
    border-radius: 999px;
}

.lobby-chat-message {
    margin-bottom: 0.5rem;
    line-height: 1.45;
    word-break: break-word;
    animation: lobby-chat-fade-in 0.2s ease;
}

@keyframes lobby-chat-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lobby-chat-name {
    color: #f0a8a0;
    font-weight: 600;
    margin-right: 0.35rem;
}

.lobby-chat-text {
    color: #f1f5f9;
}

.lobby-chat-empty {
    margin: 0;
    font-size: 0.82rem;
    color: #94a3b8;
}

.lobby-chat-jump {
    position: absolute;
    left: 50%;
    bottom: 0.55rem;
    transform: translateX(-50%) translateY(0);
    z-index: 2;
    padding: 0.4rem 0.85rem;
    border: 1px solid rgba(220, 38, 38, 0.45);
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.96);
    color: #fecaca;
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    transition:
        opacity 0.2s ease,
        transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.2s ease;
    white-space: nowrap;
}

.lobby-chat-jump[hidden] {
    display: block;
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
    pointer-events: none;
}

.lobby-chat-jump:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
}

.lobby-chat-jump:hover {
    background: rgba(220, 38, 38, 0.22);
    border-color: rgba(220, 38, 38, 0.6);
}

.lobby-chat-footer {
    padding: 0.55rem 0.7rem 0.7rem;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(7, 11, 20, 0.72);
    flex-shrink: 0;
}

.lobby-chat-identity {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.45rem;
}

.lobby-chat-as {
    font-size: 0.78rem;
    color: #94a3b8;
    text-transform: lowercase;
}

.lobby-chat-character {
    flex: 1;
    min-width: 0;
    padding: 0.35rem 0.5rem;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 0.45rem;
    background: #070b14;
    color: #f1f5f9;
    font-size: 0.82rem;
}

.lobby-chat-compose {
    display: flex;
    gap: 0.45rem;
}

.lobby-chat-input {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0.55rem;
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-radius: 0.45rem;
    background: #070b14;
    color: #f1f5f9;
    font-size: 0.84rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.lobby-chat-input::placeholder {
    color: #64748b;
}

.lobby-chat-input:focus {
    outline: none;
    border-color: rgba(220, 38, 38, 0.6);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.12);
}

.lobby-chat-input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.lobby-chat-send {
    padding: 0.45rem 0.85rem;
    border: 0;
    border-radius: 0.45rem;
    background: linear-gradient(180deg, #dc2626, #991b1b);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: filter 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
}

.lobby-chat-send:hover:not(:disabled) {
    filter: brightness(1.08);
}

.lobby-chat-send:active:not(:disabled) {
    transform: scale(0.97);
}

.lobby-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.lobby-chat-guest-note,
.lobby-chat-no-chars,
.lobby-chat-verify-note {
    margin: 0;
    font-size: 0.82rem;
    color: #94a3b8;
}

.lobby-chat-guest-note a,
.lobby-chat-verify-note a,
.lobby-chat-guest-link {
    color: #fecaca;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 0.12em;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

.lobby-chat-guest-note a:hover,
.lobby-chat-verify-note a:hover,
.lobby-chat-guest-link:hover {
    color: #fff;
}

.lobby-chat-error {
    margin: 0.45rem 0 0;
    font-size: 0.78rem;
    color: #fca5a5;
}

.lobby-chat-collapsed {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.95rem;
    border: 1px solid rgba(220, 38, 38, 0.4);
    border-radius: 999px;
    background: rgba(11, 16, 32, 0.96);
    color: #f8fafc;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
    transition:
        transform 0.24s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.24s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
    transform-origin: bottom right;
}

.lobby-chat-collapsed[hidden] {
    display: none !important;
    pointer-events: none;
}

.lobby-chat.is-minimized .lobby-chat-collapsed {
    display: inline-flex;
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.lobby-chat-collapsed:hover {
    border-color: rgba(220, 38, 38, 0.6);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
}

.lobby-chat-collapsed-label {
    letter-spacing: 0.01em;
}

.lobby-chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: linear-gradient(180deg, #dc2626, #991b1b);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    animation: lobby-chat-badge-pop 0.25s ease;
}

@keyframes lobby-chat-badge-pop {
    0% { transform: scale(0.6); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.lobby-chat-unread-badge[hidden] {
    display: none;
}

/* Guest homepage: compact live teaser + floating chat bubbles */
.lobby-chat-teaser {
    display: none;
    width: min(19.5rem, calc(100% - 1.5rem));
    padding: 0;
    border: 1px solid rgba(220, 38, 38, 0.4);
    border-radius: 0.85rem;
    background: rgba(11, 16, 32, 0.94);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.48);
    color: #f8fafc;
    text-align: left;
    overflow: hidden;
    backdrop-filter: blur(10px);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.lobby-chat.is-teaser .lobby-chat-teaser {
    display: block;
}

.lobby-chat.is-teaser .lobby-chat-panel {
    display: none !important;
}

.lobby-chat.is-teaser .lobby-chat-collapsed {
    display: none !important;
}

.lobby-chat-teaser[hidden] {
    display: none !important;
}

.lobby-chat-teaser-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.55rem 0.55rem 0.7rem;
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.16), rgba(11, 16, 32, 0.15));
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.lobby-chat-teaser-head-text {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 0;
    flex: 1;
}

.lobby-chat-teaser-title {
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.lobby-chat-teaser-online {
    font-size: 0.72rem;
    font-weight: 500;
    color: #86efac;
}

.lobby-chat-teaser-pulse {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
    animation: lobby-chat-pulse 1.8s ease-out infinite;
    flex-shrink: 0;
}

.lobby-chat-teaser-minimize {
    flex-shrink: 0;
}

@keyframes lobby-chat-pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    70% { box-shadow: 0 0 0 0.55rem rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.lobby-chat-teaser-body {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.lobby-chat-teaser-body:hover .lobby-chat-teaser-cta {
    color: #fff;
}

.lobby-chat-teaser-feed {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 3.8rem;
    max-height: 5.2rem;
    padding: 0.5rem 0.7rem 0.35rem;
    overflow: hidden;
}

.lobby-chat-teaser-empty {
    margin: 0;
    font-size: 0.78rem;
    color: #94a3b8;
}

.lobby-chat-teaser-row {
    display: grid;
    gap: 0.08rem;
    line-height: 1.3;
}

.lobby-chat-teaser-name {
    color: #f0a8a0;
    font-size: 0.72rem;
    font-weight: 700;
}

.lobby-chat-teaser-text {
    color: #e2e8f0;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lobby-chat-teaser-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.7rem 0.55rem;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.lobby-chat-teaser-cta {
    font-size: 0.76rem;
    font-weight: 700;
    color: #fecaca;
}

.lobby-chat-teaser-hint {
    font-size: 0.72rem;
    color: #94a3b8;
}

.lobby-chat-teaser-handle {
    width: 2.25rem;
    height: 0.28rem;
    margin: 0 auto 0.4rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.35);
}

.lobby-chat-bubbles {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.65rem);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.45rem;
    width: min(17rem, calc(100% - 1.5rem));
    pointer-events: none;
    z-index: 2;
}

.lobby-chat-bubble {
    pointer-events: auto;
    max-width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-radius: 0.85rem 0.85rem 0.2rem 0.85rem;
    background: rgba(17, 24, 39, 0.96);
    color: #f8fafc;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
    text-align: left;
    cursor: pointer;
    animation: lobby-chat-bubble-in 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.lobby-chat-bubble.is-leaving {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

@keyframes lobby-chat-bubble-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.lobby-chat-bubble-name {
    display: block;
    color: #f0a8a0;
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 0.12rem;
}

.lobby-chat-bubble-text {
    display: block;
    font-size: 0.8rem;
    line-height: 1.35;
    color: #e2e8f0;
}

body.en2-guest-entry-site #lobby-chat-root.lobby-chat {
    right: clamp(0.75rem, 2vw, 1.25rem) !important;
    bottom: clamp(0.85rem, 2.4vh, 1.35rem) !important;
    left: auto !important;
    z-index: 40;
    width: auto;
    max-width: calc(100% - 1.5rem);
    align-items: flex-end;
}

@media (max-width: 640px) {
    #lobby-chat-root.lobby-chat {
        right: max(0.55rem, env(safe-area-inset-right, 0px)) !important;
        bottom: max(0.55rem, env(safe-area-inset-bottom, 0px)) !important;
        left: auto !important;
        width: auto !important;
        max-width: calc(100% - 1.1rem);
        align-items: flex-end;
    }

    #lobby-chat-root.lobby-chat:not(.is-minimized):not(.is-teaser) {
        left: max(0.5rem, env(safe-area-inset-left, 0px)) !important;
        right: max(0.5rem, env(safe-area-inset-right, 0px)) !important;
        width: auto !important;
        max-width: none;
        align-items: stretch;
    }

    #lobby-chat-root.lobby-chat.is-minimized,
    #lobby-chat-root.lobby-chat.is-teaser {
        left: auto !important;
        align-items: flex-end;
        width: auto !important;
    }

    body.en2-guest-entry-site #lobby-chat-root.lobby-chat {
        z-index: 28;
    }

    body.en2-guest-entry-site #lobby-chat-root.lobby-chat.is-teaser,
    body.en2-guest-entry-site #lobby-chat-root.lobby-chat.is-minimized {
        right: max(0.55rem, env(safe-area-inset-right, 0px)) !important;
        bottom: max(0.55rem, env(safe-area-inset-bottom, 0px)) !important;
        left: auto !important;
        width: auto !important;
        max-width: calc(100% - 1.1rem);
    }

    .lobby-chat-panel {
        height: min(52dvh, 20rem);
        min-width: 0;
        max-width: none;
        width: 100%;
        resize: none;
        border-radius: 12px;
    }

    /* Compact, low-distraction mobile teaser */
    .lobby-chat-teaser {
        width: min(13.75rem, calc(100% - 1.2rem));
        border-radius: 0.75rem;
        background: rgba(11, 16, 32, 0.82);
        border-color: rgba(220, 38, 38, 0.28);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
        backdrop-filter: blur(8px);
    }

    .lobby-chat-teaser-head {
        padding: 0.38rem 0.35rem 0.38rem 0.55rem;
        gap: 0.3rem;
        background: linear-gradient(180deg, rgba(220, 38, 38, 0.1), rgba(11, 16, 32, 0.08));
    }

    .lobby-chat-teaser-title {
        font-size: 0.74rem;
    }

    .lobby-chat-teaser-online,
    .lobby-chat-teaser-hint,
    .lobby-chat-teaser-name {
        font-size: 0.62rem;
    }

    .lobby-chat-teaser-pulse {
        width: 0.42rem;
        height: 0.42rem;
    }

    .lobby-chat-teaser-minimize {
        width: 1.4rem;
        height: 1.4rem;
        font-size: 0.95rem;
    }

    .lobby-chat-teaser-feed {
        min-height: 0;
        max-height: none;
        padding: 0.35rem 0.55rem 0.2rem;
        gap: 0;
    }

    .lobby-chat-teaser-row {
        gap: 0.05rem;
    }

    .lobby-chat-teaser-text,
    .lobby-chat-teaser-cta {
        font-size: 0.7rem;
    }

    .lobby-chat-teaser-foot {
        padding: 0.3rem 0.55rem 0.4rem;
    }

    .lobby-chat-teaser-hint {
        display: none;
    }

    .lobby-chat-teaser-handle {
        display: none;
    }

    .lobby-chat-emoji {
        font-size: 0.95rem;
    }

    .lobby-chat-bubbles {
        width: min(12.5rem, calc(100% - 1.2rem));
        bottom: calc(100% + 0.4rem);
        gap: 0.3rem;
    }

    .lobby-chat-bubble {
        padding: 0.38rem 0.5rem;
        border-radius: 0.7rem 0.7rem 0.15rem 0.7rem;
        background: rgba(17, 24, 39, 0.9);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
        border-color: rgba(220, 38, 38, 0.28);
    }

    .lobby-chat-bubble-name {
        font-size: 0.62rem;
        margin-bottom: 0.05rem;
    }

    .lobby-chat-bubble-text {
        font-size: 0.7rem;
        line-height: 1.25;
    }

    body.en2-guest-entry-site .lobby-chat-collapsed {
        padding: 0.45rem 0.7rem;
        font-size: 0.74rem;
        gap: 0.35rem;
        border-radius: 999px;
        background: rgba(11, 16, 32, 0.78);
        border-color: rgba(220, 38, 38, 0.3);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
        backdrop-filter: blur(8px);
    }

    body.en2-guest-entry-site .lobby-chat-collapsed-label {
        max-width: 5.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lobby-chat-header {
        padding: 0.65rem 0.7rem;
    }

    .lobby-chat-title-text {
        font-size: 0.88rem;
    }

    .lobby-chat-jump {
        max-width: calc(100% - 1.5rem);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .lobby-chat-input {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lobby-chat-panel,
    .lobby-chat-collapsed,
    .lobby-chat-jump,
    .lobby-chat-message,
    .lobby-chat-header-btn,
    .lobby-chat-send,
    .lobby-chat-teaser,
    .lobby-chat-bubble,
    .lobby-chat-teaser-pulse {
        transition: none;
        animation: none;
    }

    .lobby-chat-messages {
        scroll-behavior: auto;
    }
}
