﻿/* ======================================================
   CHAT PANEL STYLING
   ====================================================== */

#chat-panel {
    display: flex; /* default hidden, toggled on in MP */
    flex-direction: column;
    flex: 0 0 auto;       /* don't reserve fixed height in flexbox */
    height: 54%;
    max-height: 35vh;     /* cap to viewport instead of parent */
    flex: 0 0 54%;      /* fixes it to exactly 54% height, no flex growth */
    background: #000;
    overflow: hidden;
    margin: 0 auto; /* keep it centered inside right panel */
    border-radius: 16px;
    width: calc(var(--chat-col) - 20px); /* subtract 50px */
}


.chat-empty {
    padding: 10px;
    font-size: .75rem;
    color: mediumpurple;
    background: black;
    border: 1px dashed rgba(20,35,70,.15);
    border-radius: 10px;
}

/* Chat room title (replaces LexiLayers Chat text) */
.chat-title {
    margin: 0;
    padding: 4px 10px;
    background: linear-gradient(to bottom, #b5c7bb 0%, #2a9d4e 40%, #73cb62 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-align: center;
    letter-spacing: 0.5px;
}

.chat-title {
    box-shadow: 0 0 10px rgba(20, 135, 198, 0.7);
}


/* scrollable area for messages */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden; /* ✅ prevents horizontal scroll */
    overflow-anchor: none; /* ✅ disable browser scroll anchoring - we manage scroll manually */
    contain: strict; /* ✅ full containment - isolate from ALL external layout changes */
    isolation: isolate; /* ✅ creates new stacking context */
    transform: translateZ(0); /* ✅ force GPU layer for scroll stability */
    word-wrap: break-word; /* ✅ breaks long words */
    overflow-wrap: anywhere; /* ✅ modern browsers */
    white-space: pre-wrap; /* ✅ keeps line breaks but wraps text */
    padding: 6px 8px;
    font-size: 0.8rem;
    box-sizing: border-box;
    background: linear-gradient(180deg, #193764, #142a4b3d);
    min-height: 0; /* 👈 prevents flex overflow growth */
}

    /* Works for Chrome, Edge, Safari */
    #chat-messages::-webkit-scrollbar {
        width: 6px; /* thinner scrollbar */
    }

    #chat-messages::-webkit-scrollbar-track {
        background: rgba(15, 30, 60, 0.4); 
        border-radius: 6px;
    }

    #chat-messages::-webkit-scrollbar-thumb {
        background: rgba(100, 150, 255, 0.6); 
        border-radius: 6px;
        transition: background 0.3s ease;
    }

        #chat-messages::-webkit-scrollbar-thumb:hover {
            background: rgb(82 183 50 / 92%) rgba(15, 30, 60, 0.4); 
        }

/* Works for Firefox */
#chat-messages {
    scrollbar-width: thin; /* makes it thinner */
    scrollbar-color: rgb(35 203 42 / 41%) rgba(15, 30, 60, 0.4);
}


/* input bar */
#chat-input-area {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-top: 1px solid #222;
    background: linear-gradient(180deg, #193764, #0f2444);
}

#chat-input {
    flex: 1;
    padding: 6px;
    background: #111;
    border: 1px solid #333;
    color: #fff;
    min-width: 0; /* ✅ prevents flex item overflow */
}

#chat-send {
    margin-left: 6px;
    padding: 6px 10px;
    background: #1487c6;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

    #chat-send:hover {
        background: #1ca0e0;
    }

/* ============================================
   CHAT LINE ENHANCEMENTS
   ============================================ */

/* Base chat line layout */
.chat-line {
    margin-bottom: 4px;
    line-height: 1.1em;
}

    /* Player messages (default) */
    .chat-line .user {
        font-weight: 600;
    }

    /* 🕹️ In-game (round info, welcome, challenge, etc.) */
    .chat-line.game {
        font-style: italic;
        color: #83fe08;
        opacity: 0.8;
    }

        .chat-line.system .inner-html,
        .chat-line.game .inner-html {
            color: inherit;
            font: inherit;
        }


    /* 📢 Global / system messages (admin announcements) */
    .chat-line.system {
        font-weight: bold;
        color: orange;
    }

        .chat-line.system::before {
            content: "📢 Sytem broadcast! ";
        }

        .chat-line.system + .chat-line.system::before {
            content: none;
        }


    /* ✉️ Optionally add icons before each type */
    .chat-line.game::before {
        content: none;
    }
     

    /* Optional: make admin/system lines slightly separated */
    .chat-line.system,
    .chat-line.game {
        display: block;
        margin-top: 6px;
    }

    /* 🏆 Broadcast/Achievement messages (high scores) - matches info-feed style */
    .chat-line.broadcast {
        display: block;
        background: rgba(255, 215, 0, 0.15);
        padding: 8px 10px;
        border-radius: 8px;
        border-left: 3px solid #ffd700;
        margin: 6px 0;
        font-size: 0.65rem;
        line-height: 1.1;
    }

        .chat-line.broadcast .inner-html {
            color: #fff;
            font-weight: 500;
        }

        .chat-line.broadcast .broadcast-timestamp {
            font-size: 0.7rem;
            color: rgba(255, 255, 255, 0.5);
            margin-top: 4px;
        }


/* ======================================================
   📱 Mobile Chat Panel (clean unified version)
   ====================================================== */
@media (max-width: 600px) {

    /* Match overall style of rank/scoreboard panels */
    #chat-panel {
        position: fixed;

        top: 50px; /* below header area */
        width: 85%;
        max-width: 420px;
        height: 55vh !important;
        max-height: 46vh !important;
        background: rgba(15, 30, 60, 0.45);
        backdrop-filter: blur(4px);
        border-left: 2px solid rgba(255,255,255,0.12);
        border-top-left-radius: 16px;
        border-bottom-left-radius: 16px;
        box-shadow: -4px 0 16px rgba(0,0,0,0.4);
        bottom: auto !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        margin: 0;
        flex: none; /* disable desktop flex sizing */
        z-index: 950;
        transform: translateX(100%);
        opacity: 0;
        transition: transform 0.3s ease, opacity 0.3s ease;
        pointer-events: none;
    }

        /* When chat is opened */
        #chat-panel.open {
            transform: translateX(0);
            opacity: 1;
            pointer-events: auto;
            z-index: 950;
        }

    /* Scrollable message area */
    #chat-messages {
        flex: 1;
        overflow-y: auto;
        overflow-anchor: none; /* ✅ disable browser scroll anchoring */
        contain: strict; /* ✅ full containment */
        isolation: isolate; /* ✅ creates new stacking context */
        transform: translateZ(0); /* ✅ force GPU layer */
        -webkit-overflow-scrolling: touch;
        padding: 8px;
        background: rgba(15, 30, 60, 0.35);
        backdrop-filter: blur(8px);
    }


    /* Input bar styling */
    #chat-input-area {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px;
        background: rgba(10, 30, 60, 0.8);
        border-top: 1px solid rgba(255,255,255,0.1);
    }

    #chat-input {
        flex: 1;
        padding: 6px;
        background: #111;
        border: 1px solid #333;
        color: #fff;
        border-radius: 6px;
        min-width: 0;
    }

    #chat-send {
        margin-left: 6px;
        padding: 6px 10px;
        background: #1487c6;
        color: #fff;
        border: none;
        border-radius: 6px;
        font-weight: 600;
        cursor: pointer;
    }

        #chat-send:hover {
            background: #1ca0e0;
        }
}
