/* Hide game-only HUD panels when not in game */
    body:not(.in-game) #leaderboard,
    body:not(.in-game) #my-score-div,
    body:not(.in-game) #unit-status,
    body:not(.in-game) #counter {
        display: none !important;
    }

    /* Show game HUD panels when in game */
    body.in-game #leaderboard,
    body.in-game #my-score-div {
        display: block !important;
    }

    body.in-game #unit-status {
        display: flex !important;
    }

    body.in-game #connection-status {
        display: flex;
    }

    body.in-game #inventory-slots,
    body.in-game #inventory-slots .inventory-item-button,
    body.in-game #inventory-slots .item-div {
        pointer-events: auto;
    }

    .leaderboard-container {
        position: absolute;
        inset: 0;
        pointer-events: none;
    }

    #leaderboard {
        right: 0px;
        top: 54px;
        width: min(220px, calc(100vw - 12px));
        text-align: right;
        padding: 10px;
        position: absolute;
        color: white;
        user-select: none;
        pointer-events: none;
        z-index: 999;
    }

    .ui-text-scoreboard {
        font-size: 26px;
        line-height: 1.15;
    }

    #scoreboard-header {
        border-bottom: 1px solid white;
        display: flex;
        align-items: center;
        gap: 2px;
        margin-bottom: 0px;
        width: fit-content;
        margin-left: auto;
        pointer-events: auto;
    }

    #leaderboard-toggle {
        display: inline;
        cursor: pointer;
    }

    .leaderboard-arrow {
        width: 10px;
        height: 10px;
        display: block;
        stroke-width: 2.25;
    }

    #leaderboard-title {
        cursor: pointer;
        text-decoration-line: none;
        font-size: 14px;
        font-weight: 600;
    }

    #scoreboard {
        height: 175px;
        overflow: auto;
        padding-top: 10px;
        /* Keep the leaderboard shell click-through while allowing its scroll
           surface to receive wheel and scrollbar pointer input. */
        pointer-events: auto;
        touch-action: pan-y;
        overscroll-behavior: contain;
        user-select: text;
        cursor: default;
    }

    #scoreboard .scoreboard-mobile {
        width: 100px;
        height: 100px;
    }

    #scoreboard .scoreboard-user-entry {
        display: grid;
        grid-template-columns: minmax(0, 1fr) max-content;
        align-items: center;
        width: 100%;
        padding: 3px 0;
        font-size: 16px;
        line-height: 1.2;
        gap: 9px;
    }

    #scoreboard .scoreboard-player-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
        text-align: right;
    }

    #scoreboard .scoreboard-player-score {
        font-size: 12px;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        opacity: 0.8;
        text-align: right;
        white-space: nowrap;
    }

    #scoreboard .scoreboard-player-score span {
        display: inline-block;
    }

    @media (min-width: 1024px) {
        .ui-text-scoreboard {
            font-size: 32px;
        }

        #scoreboard-header {
            gap: 4px;
        }

        #leaderboard-title {
            font-size: 18px;
            font-weight: 500;
        }
    }

    @media only screen and (max-width: 1000px) {
        #leaderboard {
            top: 52px;
        }

        #scoreboard .scoreboard-mobile {
            height: 100px;
            font-size: 13px;
        }
    }

    .backpack-container {
        position: fixed;
        right: 12px;
        bottom: 12px;
        left: auto;
        text-align: right;
        z-index: 1000;
        pointer-events: none;
        max-width: calc(100vw - 24px);
    }

    #my-score-div {
        width: 215px;
        min-width: 0;
        min-height: 66px;
        max-width: 100%;
        margin: 0;
        padding: 8px 10px;
        border: 1px solid rgba(190, 196, 205, 0.48);
        border-radius: 11px;
        background: rgba(7, 9, 12, 0.62);
        font-size: 18px;
        line-height: 1.35;
        white-space: nowrap;
    }

    .score-div {
        right: 0px;
        bottom: 0px;
        text-align: left;
        user-select: none;
    }

    #players-attribute-div,
    #players-attribute-div #pt-attribute-points,
    #players-attribute-div #pt-attribute-value-points,
    #players-attribute-div #pt-attribute-UvOpuABaRI,
    #players-attribute-div #pt-attribute-value-UvOpuABaRI {
        font-size: 19px;
    }

    .game-ui {
        z-index: 1000;
        color: white;
        margin: 10px;
        display: none;
        width: fit-content;
        margin-left: auto;
        padding-left: 10px;
        text-align: right;
    }

    @media (max-width: 1024px) {
        .game-ui {
            font-size: 12px;
            margin: 3px;
            margin-left: auto;
        }

        #my-score-div {
            font-weight: 500;
            width: 205px;
            min-width: 0;
            min-height: 62px;
            font-size: 17px;
            padding: 7px 9px;
        }

        #players-attribute-div,
        #players-attribute-div #pt-attribute-points,
        #players-attribute-div #pt-attribute-value-points,
        #players-attribute-div #pt-attribute-UvOpuABaRI,
        #players-attribute-div #pt-attribute-value-UvOpuABaRI {
            font-size: 18px;
        }
    }

    @media (max-width: 768px) {
        .backpack-container {
            right: 12px;
            bottom: 12px;
            left: auto;
            max-width: calc(100vw - 24px);
            text-align: right;
        }

        .score-div {
            text-align: right;
        }
    }

    @media (max-width: 1024px) {
        html.phone-client #leaderboard {
            top: 44px;
            right: 4px;
            width: min(154px, calc(100vw - 8px));
            padding: 5px;
        }

        html.phone-client .ui-text-scoreboard {
            font-size: 18px;
        }

        html.phone-client #scoreboard-header {
            gap: 2px;
        }

        html.phone-client #leaderboard-title {
            font-size: 12px;
            font-weight: 600;
        }

        html.phone-client #scoreboard {
            height: 112px;
            padding-top: 5px;
        }

        html.phone-client #scoreboard .scoreboard-user-entry {
            padding: 2px 0;
            font-size: 12px;
            line-height: 1.1;
            gap: 5px;
        }

        html.phone-client #scoreboard .scoreboard-player-score {
            font-size: 10px;
        }
    }

    #attribute-bars {
        margin-left: 2px;
        margin-right: 2px;
        position: relative;
        margin: auto;
        min-width: 200px;
    }

    #attribute-bars .progress {
        position: relative;
        margin-bottom: 0px;
        height: 24px;
        background-color: #495057bd;
    }

    #attribute-bars .progress-bar {
        margin: 3px;
    }

    #attribute-bars .progress-label {
        z-index: 1;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        margin: 0;
        padding: 0 22px;
        line-height: 24px;
        text-align: left;
        box-sizing: border-box;
    }

    #attribute-bars .unit-attribute-name,
    #attribute-bars .unit-attribute-value {
        display: block;
        line-height: 1;
    }

    /* Ensure Phaser canvas is always visible */
    canvas {
        display: block !important;
        visibility: visible !important;
        touch-action: none;
    }

    /* Inventory slot styling */
    .inventory-slot {
        width: 45px;
        height: 45px;
        background: rgba(0, 0, 0, 0.5);
        border: 2px solid transparent;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 2px;
        overflow: visible;
    }

    .inventory-slot.active {
        border: 2px solid white;
        box-shadow: none;
        background: rgba(0, 0, 0, 0.4);
    }

    .inventory-slot-number {
        position: absolute;
        top: -17px;
        left: 50%;
        z-index: 10002;
        color: #ffffff;
        font-size: 12px;
        font-weight: 700;
        line-height: 1;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
        transform: translateX(-50%);
        pointer-events: none;
    }

    .inventory-item-image {
        display: block;
        height: 35px;
        max-width: 35px;
        object-fit: contain;
    }

    #inventory-slots {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #inventory-slots .item-div {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .popover {
        z-index: 120000;
    }

    .popover-body {
        font-size: 16px;
        width: 250px;
    }

    #item-ammo {
        position: absolute;
        right: 5px;
        bottom: 4px;
        z-index: 10002;
        color: #fff;
        font-size: 16px;
        font-weight: 900;
        line-height: 1;
        font-family: Arial, sans-serif;
        text-align: right;
        white-space: nowrap;
        transform: none;
        text-shadow: 0 1px 2px #000, 1px 0 2px #000;
        pointer-events: none;
    }

    .item-key-stroke {
        display: none !important;
        /* Sits ABOVE the slot, horizontally centered over it, a bit higher —
           attached to the inventory, not floating away. */
        position: absolute;
        top: -26px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 10002; /* above the cooldown overlay (10001) */
        margin: 0;
        pointer-events: none;
        line-height: 1;
        background: rgba(0, 0, 0, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 4px;
        padding: 2px 6px;
        font-size: 12px;
        color: #fff;
    }

    .ui-text-inventory {
        display: none !important;
    }

    #chat-box {
        text-align: left;
        position: fixed;
        bottom: 8px !important;
        left: 8px !important;
        margin-left: 0;
        z-index: 1000;
    }

    #chat-box #hide-chat {
        height: 15px;
    }

    #chat-box #tabs {
        height: 35px;
    }

    #chat-box .tab-content {
        height: 250px;
    }

    #chat-tab-container {
        width: min(350px, 100vw) !important;
        height: 230px !important;
    }

    #show-chat {
        bottom: 8px !important;
        left: 8px !important;
        margin: 0 !important;
    }

    #chat-tab-container a.nav-link {
        color: white;
    }

    #chat-tab-container a.nav-link.active {
        color: white;
        background-color: rgba(0, 0, 0, 0.5);
        border-radius: 5px 5px 0 0;
    }

    #chat-history {
        word-wrap: break-word;
        overflow-y: auto;
    }

    #chat-history .author {
        color: #99F000;
    }

    #chat-player-list {
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    }

    .chat-player-entry {
        display: flex;
        align-items: center;
        padding: 3px 6px;
        border-radius: 3px;
        cursor: default;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-player-entry:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .chat-player-avatar {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        margin-right: 6px;
        flex-shrink: 0;
        object-fit: cover;
    }

    .chat-player-name {
        color: #ccc;
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #chat-message-input {
        width: 100%;
        display: none;
    }

    #chat-input-field-div {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 2500;
    }

    body:not(.in-game) #chat-box,
    body:not(.in-game) #show-chat,
    body:not(.in-game) #chat-input-field-div,
    body:not(.in-game) #mobile-chat-overlay,
    body:not(.in-game) #mobile-chat-modal {
        display: none !important;
    }

    #mobile-chat-overlay {
        position: fixed;
        top: 58px;
        left: 10px;
        z-index: 120001;
        width: 220px;
        pointer-events: auto;
        cursor: pointer;
        font-family: Arial, sans-serif;
        font-size: 12px;
        color: #fff;
    }

    #mobile-chat-messages {
        max-height: 109px;
        overflow: hidden;
        background: rgba(55, 65, 81, 0.2);
        border-radius: 6px;
        padding: 4px 8px;
        word-break: break-word;
        overflow-wrap: break-word;
        transition: background 0.3s ease;
    }

    #mobile-chat-messages.mobile-overlay-active {
        background: rgba(55, 65, 81, 0.55);
    }

    #mobile-chat-messages:hover {
        background: rgba(55, 65, 81, 0.4);
    }

    #mobile-chat-placeholder {
        background: rgba(55, 65, 81, 0.2);
        border-radius: 6px;
        padding: 6px 8px;
        color: #D1D5DB;
        font-size: 12px;
    }

    #mobile-chat-placeholder:hover {
        background: rgba(55, 65, 81, 0.1);
    }

    .mobile-overlay-msg {
        line-height: 1.4;
    }

    .mobile-msg-author {
        color: #99F000;
        font-weight: 500;
    }

    .mobile-msg-text {
        color: #fff;
    }

    .mobile-msg-system {
        color: yellow;
    }

    #mobile-chat-modal {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 120002;
        flex-direction: column;
        background: rgba(22, 24, 26, 0.93);
        color: #fff;
        font-family: Arial, sans-serif;
        font-size: 14px;
    }

    #mobile-chat-close {
        position: absolute;
        top: 8px;
        right: 10px;
        z-index: 10;
        background: #2563eb;
        border: none;
        color: #fff;
        font-size: 24px;
        width: 36px;
        height: 36px;
        border-radius: 6px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    #mobile-chat-close:hover {
        background: #1d4ed8;
    }

    #mobile-chat-modal-messages {
        flex: 1;
        overflow-y: auto;
        padding: 50px 14px 10px;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .mobile-modal-msg {
        padding: 2px 0;
        line-height: 1.5;
        font-size: 14px;
    }

    #mobile-chat-form {
        display: flex;
        align-items: center;
        padding: 8px 10px;
        gap: 8px;
        background: rgba(30, 30, 30, 0.95);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    #mobile-chat-input {
        flex: 1;
        background: rgba(55, 65, 81, 0.5);
        border: none;
        border-radius: 6px;
        color: #fff;
        font-size: 14px;
        padding: 10px 12px;
        outline: none;
        font-family: Arial, sans-serif;
    }

    #mobile-chat-input::placeholder {
        color: #9CA3AF;
        font-style: italic;
    }

    #mobile-chat-send {
        background: #2563eb;
        border: none;
        border-radius: 6px;
        color: #fff;
        width: 40px;
        height: 40px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        flex-shrink: 0;
    }

    #mobile-chat-send:hover {
        background: #1d4ed8;
    }

    @media (max-width: 768px) {
        #chat-box,
        #show-chat,
        #chat-input-field-div {
            display: none !important;
        }
    }

    @media (min-width: 769px) {
        #chat-box {
            display: block !important;
        }
    }

    #chat-box {
        color: #fff;
        font-family: Arial, sans-serif;
    }

    #chat-tab-container {
        width: min(350px, calc(100vw - 16px)) !important;
        height: 286px !important;
        overflow: hidden;
        border-radius: 5px;
        background: #16181A;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    }

    #chat-box #tabs,
    .mobile-chat-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr)) 34px;
        min-height: 35px;
        height: auto;
        margin: 0;
        background: #2D3540;
    }

    .chat-scope-tab,
    #hide-chat {
        min-width: 0;
        border: 0;
        border-bottom: 2px solid transparent;
        border-radius: 0;
        background: transparent;
        color: #fff;
        font: 600 12px/1 Arial, sans-serif;
        padding: 9px 5px;
        text-align: center;
        cursor: pointer;
    }

    .chat-scope-tab.is-active {
        background: rgba(22, 24, 26, 0.7);
        border-bottom-color: rgba(255, 255, 255, 0.7);
    }

    .chat-scope-tab {
        transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
    }

    .chat-tab-transition {
        will-change: transform;
    }

    .chat-tab-transition-forward {
        animation: chat-tab-content-forward 140ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    .chat-tab-transition-backward {
        animation: chat-tab-content-backward 140ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    @keyframes chat-tab-content-forward {
        from {
            transform: translateX(6px);
        }
        to {
            transform: translateX(0);
        }
    }

    @keyframes chat-tab-content-backward {
        from {
            transform: translateX(-6px);
        }
        to {
            transform: translateX(0);
        }
    }

    @media (prefers-reduced-motion: reduce) {
        .chat-scope-tab,
        .chat-tab-transition,
        .chat-tab-transition-forward,
        .chat-tab-transition-backward {
            animation: none;
            transition: none;
        }
    }

    #chat-history,
    #mobile-chat-modal-messages,
    #chat-player-list {
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }

    #hide-chat {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        font-size: 18px;
    }

    #chat-box .tab-content {
        height: 215px;
        background: rgba(22, 24, 26, 0.92);
        border-radius: 0;
        overflow: hidden;
    }

    #chat-main-pane {
        min-width: 0;
        height: 100%;
    }

    #chat-player-list {
        width: 126px;
        min-width: 126px;
        overflow-y: auto;
        border-right: 1px solid #374151;
        padding: 4px;
        background: rgba(45, 53, 64, 0.45);
    }

    #chat-history {
        flex: 1;
        min-width: 0;
        padding: 8px;
        overflow-y: auto;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .chat-message-row {
        display: grid;
        grid-template-columns: 26px minmax(0, 1fr);
        gap: 6px;
        align-items: start;
        min-width: 0;
        padding: 3px 0;
        font-size: 12px;
        line-height: 1.35;
    }

    .chat-message-avatar,
    .chat-player-avatar {
        width: 24px;
        height: 24px;
        margin: 0;
        border: 0;
        border-radius: 50%;
        object-fit: cover;
        background: #374151;
        cursor: pointer;
    }

    .chat-message-body {
        min-width: 0;
    }

    .chat-message-author {
        border: 0;
        background: transparent;
        color: #99F000;
        font: 600 12px/1.35 Arial, sans-serif;
        padding: 0;
        cursor: pointer;
        pointer-events: auto;
    }

    .chat-message-text {
        color: #fff;
        overflow-wrap: anywhere;
    }

    .chat-system-message {
        grid-column: 1 / -1;
        color: #ffd166;
    }

    .chat-player-entry {
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr);
        gap: 6px;
        align-items: center;
        width: 100%;
        border: 0;
        border-radius: 3px;
        background: transparent;
        padding: 4px;
        cursor: pointer;
    }

    .chat-player-entry:hover,
    .chat-player-entry.is-active {
        background: rgba(255, 255, 255, 0.1);
    }

    .chat-dm-user,
    .chat-empty-state {
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr);
        gap: 6px;
        align-items: center;
        width: 100%;
        border: 0;
        border-radius: 3px;
        background: transparent;
        color: #fff;
        padding: 4px;
        font-size: 12px;
        text-align: left;
    }

    .chat-dm-user {
        cursor: pointer;
    }

    .chat-dm-user:hover,
    .chat-dm-user.active {
        background: rgba(255, 255, 255, 0.1);
    }

    .chat-dm-user img {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        object-fit: cover;
    }

    .chat-empty-state {
        grid-template-columns: 1fr;
        color: #D1D5DB;
    }

    .chat-player-name {
        min-width: 0;
        overflow: hidden;
        color: #fff;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #chat-message-input {
        display: block;
        width: 100%;
        min-height: 36px;
        background: rgba(22, 24, 26, 0.96);
    }

    #chat-message-input form,
    #mobile-chat-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 34px;
        gap: 4px;
        align-items: center;
        padding: 4px;
        border-top: 1px solid #374151;
    }

    #chat-message-input {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 34px;
        gap: 4px;
        align-items: center;
        padding: 4px;
        border-top: 1px solid #374151;
    }

    #message,
    #mobile-chat-input {
        width: 100%;
        min-width: 0;
        height: 28px;
        border: 2px solid transparent;
        border-radius: 4px;
        background: rgba(45, 53, 64, 0.7);
        color: #fff;
        font: 600 12px/1 Arial, sans-serif;
        padding: 0 8px;
        outline: none;
    }

    #message:focus,
    #mobile-chat-input:focus {
        border-color: #fff;
    }

    #message::placeholder,
    #mobile-chat-input::placeholder {
        color: #D1D5DB;
        font-style: italic;
    }

    #chat-send,
    #mobile-chat-send {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 28px;
        border: 0;
        border-radius: 4px;
        background: #2563eb;
        color: #fff;
        cursor: pointer;
    }

    .chat-message-avatar-button {
        width: 24px;
        height: 24px;
        border: 0;
        border-radius: 50%;
        background: transparent;
        padding: 0;
        vertical-align: middle;
        cursor: pointer;
    }

    .chat-message-avatar-button img {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        object-fit: cover;
    }

    #chat-input-field-div {
        position: static;
        transform: none;
        z-index: auto;
    }

    #chat-user-picker {
        position: fixed;
        z-index: 120010;
        width: 190px;
        overflow: hidden;
        border: 1px solid #374151;
        border-radius: 4px;
        background: #16181A;
        color: #fff;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    .chat-picker-user,
    .chat-picker-action {
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr);
        gap: 8px;
        align-items: center;
        width: 100%;
        min-height: 34px;
        border: 0;
        border-bottom: 1px solid #374151;
        background: transparent;
        color: #fff;
        font: 600 12px/1 Arial, sans-serif;
        padding: 5px 8px;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
    }

    .chat-picker-action:hover,
    .chat-picker-user:hover {
        background: #2D3540;
    }

    .chat-picker-action.is-danger {
        background: rgba(255, 73, 33, 0.2);
    }

    .chat-picker-user img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        object-fit: cover;
    }

    .chat-picker-action i {
        text-align: center;
    }

    #chat-user-picker[hidden],
    .chat-picker-action[hidden],
    #chat-profile-follow[hidden],
    #chat-profile-dm[hidden] {
        display: none !important;
    }

    #chat-profile-dialog:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 120011;
        display: grid;
        place-items: center;
        width: 100vw;
        height: 100vh;
        border: 0;
        background: rgba(0, 0, 0, 0.66);
        color: #fff;
        padding: 12px;
        animation: chat-profile-backdrop-enter 180ms ease-out;
    }

    #chat-profile-dialog > * {
        max-width: 100%;
    }

    .chat-profile-panel {
        position: relative;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 190px;
        grid-template-areas:
            "profile-header profile-actions"
            "profile-bio profile-actions"
            "profile-stats profile-stats";
        column-gap: 24px;
        row-gap: 10px;
        align-content: start;
        width: min(700px, calc(100vw - 24px));
        max-width: 700px;
        min-height: 0;
        box-sizing: border-box;
        overflow: hidden;
        border: 1px solid #30373E;
        border-radius: 4px;
        background: #16181A;
        color: #fff;
        padding: 20px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.52);
        font-family: var(--font-rubik), Arial, sans-serif;
        animation: chat-profile-panel-enter 220ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    @keyframes chat-profile-backdrop-enter {
        from { background: rgba(0, 0, 0, 0); }
        to { background: rgba(0, 0, 0, 0.66); }
    }

    @keyframes chat-profile-panel-enter {
        from {
            opacity: 0;
            transform: translateY(10px) scale(0.98);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }

    .chat-profile-header {
        grid-area: profile-header;
        display: flex;
        gap: 18px;
        align-items: center;
        min-width: 0;
        padding: 0;
    }

    .chat-profile-identity {
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-width: 0;
        width: 100%;
        text-align: left;
    }

    #chat-profile-avatar {
        flex: 0 0 112px;
        width: 112px;
        height: 112px;
        border-radius: 8px;
        border: 1px solid #30373E;
        object-fit: contain;
        background: #11161A;
    }

    #chat-profile-name {
        margin: 0;
        color: #fff;
        font-size: 24px;
        font-weight: 700;
        line-height: 1.15;
        overflow-wrap: anywhere;
        text-align: left;
    }

    #chat-profile-role {
        display: inline-flex;
        width: max-content;
        margin: 5px 0 0;
        padding: 3px 7px;
        border: 1px solid #30373E;
        border-radius: 4px;
        background: #20262C;
        color: #9CA3AF;
        font-size: 14px;
        line-height: 1.3;
    }

    #chat-profile-close {
        position: absolute;
        top: 12px;
        right: 12px;
        display: inline-flex;
        width: 32px;
        height: 32px;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 4px;
        background: transparent;
        color: #D1D5DB;
        font-size: 17px;
        cursor: pointer;
        transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
    }

    #chat-profile-close:hover {
        background: #2D3540;
        color: #fff;
    }

    #chat-profile-bio {
        grid-area: profile-bio;
        display: -webkit-box;
        align-self: start;
        min-height: 18px;
        max-height: 2.7em;
        margin: 0;
        overflow: hidden;
        color: #D1D5DB;
        font-size: 14px;
        line-height: 1.35;
        text-align: left;
        white-space: pre-wrap;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow-wrap: anywhere;
    }

    #chat-profile-bio:empty {
        display: none;
    }

    .chat-profile-stats {
        grid-area: profile-stats;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        align-self: end;
        gap: 24px;
        margin: 0 -20px -20px;
        padding: 14px 20px 20px;
        border-top: 1px solid #343A40;
        background: #151A1F;
    }

    .chat-profile-stats dt {
        color: #9CA3AF;
        font-size: 15px;
        font-weight: 700;
        line-height: 1.2;
    }

    .chat-profile-stats dd {
        margin: 0;
        color: #fff;
        font-size: 28px;
        font-weight: 700;
        line-height: 1;
        font-variant-numeric: tabular-nums;
    }

    .chat-profile-actions {
        grid-area: profile-actions;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        align-self: center;
        justify-self: stretch;
        gap: 12px;
        margin-top: 0;
        padding: 32px 0 0 12px;
    }

    .chat-profile-actions #chat-profile-follow,
    .chat-profile-actions #chat-profile-dm {
        justify-content: center;
        width: 100%;
        height: 44px;
        font-size: 14px;
        font-weight: 700;
        transition: background-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
    }

    #chat-profile-follow,
    #chat-profile-dm {
        height: 28px;
    }

    #chat-profile-follow {
        --chat-profile-follow-background: #0072f5;
        --chat-profile-follow-hover-background: #0952a5;
        --chat-profile-following-background: #4c5155;
        --chat-profile-following-hover-background: #3a3f42;
        --chat-profile-unfollow-background: #dc3545;
        --chat-profile-unfollow-hover-background: #e02424;
        --chat-profile-follow-text: #ffffff;
        width: 96px;
        flex: 0 0 auto;
        border: 0;
        border-radius: 4px;
        background: var(--chat-profile-follow-background);
        color: var(--chat-profile-follow-text);
        padding: 0 8px;
        cursor: pointer;
        font: 700 14px/1 Arial, sans-serif;
        white-space: nowrap;
        transition: background-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
    }

    #chat-profile-follow:hover,
    #chat-profile-follow:focus-visible {
        background: var(--chat-profile-follow-hover-background);
    }

    #chat-profile-follow:focus-visible,
    #chat-profile-dm:focus-visible,
    #chat-profile-close:focus-visible {
        outline: 0;
        box-shadow: 0 0 0 2px #86B7FE;
    }

    #chat-profile-follow[data-follow-state="following"] {
        --chat-profile-follow-background: var(--chat-profile-following-background);
        --chat-profile-follow-hover-background: var(--chat-profile-unfollow-background);
    }

    #chat-profile-follow[data-follow-state="following"]:hover,
    #chat-profile-follow[data-follow-state="following"]:focus-visible {
        --chat-profile-follow-hover-background: var(--chat-profile-unfollow-hover-background);
    }

    .chat-profile-follow-hover,
    #chat-profile-follow[data-follow-state="following"]:hover .chat-profile-follow-default,
    #chat-profile-follow[data-follow-state="following"]:focus-visible .chat-profile-follow-default {
        display: none;
    }

    #chat-profile-follow[data-follow-state="following"]:hover .chat-profile-follow-hover,
    #chat-profile-follow[data-follow-state="following"]:focus-visible .chat-profile-follow-hover {
        display: inline;
    }

    #chat-profile-follow:disabled {
        opacity: 0.7;
        cursor: wait;
    }

    #chat-profile-dm {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-top: 0;
        border: 0;
        border-radius: 4px;
        background: #2563eb;
        color: #fff;
        padding: 0 12px;
        cursor: pointer;
    }

    #chat-profile-dm:hover {
        background: #1D4ED8;
    }

    #chat-profile-follow:active,
    #chat-profile-dm:active {
        transform: translateY(1px);
    }

    @media (min-width: 768px) {
        #chat-profile-follow,
        #chat-profile-dm {
            height: 32px;
        }

        #chat-profile-follow {
            width: 112px;
            font-size: 16px;
        }
    }

    @media (min-width: 1024px) {
        #chat-profile-follow,
        #chat-profile-dm {
            height: 40px;
        }

        #chat-profile-follow {
            width: 144px;
        }
    }

    @media (min-width: 1280px) {
        #chat-profile-follow {
            font-size: 20px;
        }
    }

    @media (max-width: 600px) {
        .chat-profile-panel {
            grid-template-columns: minmax(0, 1fr);
            grid-template-areas:
                "profile-header"
                "profile-bio"
                "profile-actions"
                "profile-stats";
            width: min(700px, calc(100vw - 24px));
            max-width: 700px;
            min-height: 0;
            padding: 16px;
            row-gap: 14px;
        }

        .chat-profile-header {
            gap: 14px;
            padding-right: 24px;
        }

        #chat-profile-avatar {
            flex-basis: 96px;
            width: 96px;
            height: 96px;
        }

        #chat-profile-name {
            font-size: 20px;
        }

        .chat-profile-actions {
            padding: 0;
        }

        .chat-profile-stats {
            margin: 0 -16px -16px;
            padding: 14px 16px 16px;
        }

        #chat-profile-close {
            top: 8px;
            right: 8px;
        }
    }

    .mobile-chat-tabs {
        flex: 0 0 auto;
        grid-template-columns: repeat(3, minmax(0, 1fr)) 40px;
        padding-right: 0;
    }

    @media (max-width: 768px) {
        #mobile-chat-modal-messages {
            padding-top: 8px;
        }

        #mobile-chat-close {
            position: static;
            width: 40px;
            height: 36px;
            border-radius: 0;
            background: transparent;
        }
    }

    #chat-box {
        position: fixed !important;
        bottom: 8px !important;
        left: 8px !important;
        z-index: 1045 !important;
        color: #fff;
        font-family: var(--font-rubik), Arial, sans-serif;
        user-select: text;
    }

    #chat-tab-container {
        width: 300px !important;
        max-width: calc(100vw - 16px);
        overflow: visible;
        border-radius: 6px;
        background: rgba(22, 24, 26, 0.5);
    }

    #chat-box #tabs,
    .mobile-chat-tabs {
        display: grid;
        grid-template-columns: 42px repeat(3, minmax(0, 1fr)) 48px;
        min-height: 38px;
        height: auto;
        margin: 0;
        background: transparent;
        border-radius: 6px 6px 0 0;
    }

    #toggle-player-list,
    .chat-scope-tab,
    #hide-chat-button {
        min-width: 0;
        border: 0;
        border-bottom: 2px solid transparent;
        border-radius: 6px 6px 0 0;
        background: transparent;
        color: #fff;
        font: 500 12px/1 var(--font-rubik), Arial, sans-serif;
        padding: 6px 8px;
        text-align: center;
        cursor: pointer;
    }

    #toggle-player-list {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 32px;
        padding: 6px;
    }

    #toggle-player-list.is-active,
    .chat-scope-tab.is-active {
        background: rgba(22, 24, 26, 0.7);
        border-bottom-color: rgba(255, 255, 255, 0.7);
    }

    #hide-chat-button {
        width: fit-content;
        margin-bottom: 4px;
        margin-left: auto;
        padding: 6px 8px;
        font-size: 12px;
        text-transform: lowercase;
    }

    #chat-box .tab-content {
        min-height: 170px;
        height: 20vh;
        max-height: 300px;
        background: rgba(22, 24, 26, 0.7);
        border-radius: 0 0 6px 6px;
        overflow: visible;
    }

    #chat-player-list {
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 5;
        display: flex;
        width: 32px;
        min-width: 32px;
        height: calc(100% - 38px);
        flex-direction: column;
        gap: 4px;
        overflow-x: hidden;
        overflow-y: hidden;
        padding: 4px;
        border-right: 0;
        border-radius: 0 0 0 6px;
        background: rgba(22, 24, 26, 0.5);
        transition: width 0s;
    }

    #chat-player-list.is-expanded,
    #chat-player-list:hover {
        width: 200px;
        min-width: 200px;
        overflow-y: auto;
        background: #16181A;
    }

    #chat-player-list[hidden] {
        display: flex;
    }

    #chat-main-column {
        position: relative;
        display: flex;
        min-width: 0;
        width: 100%;
        height: 100%;
        flex-direction: column;
    }

    #chat-active-heading {
        display: none;
    }

    #chat-history {
        flex: 1;
        min-width: 0;
        margin-left: 32px;
        padding: 8px;
        overflow-y: auto;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .chat-message-row {
        display: block;
        padding: 2px 0 2px 10px;
        font-size: 16px;
        line-height: 1.45;
    }

    .chat-message-avatar-button,
    .chat-message-avatar {
        display: none;
    }

    .chat-message-body {
        min-width: 0;
    }

    .chat-message-author {
        border: 0;
        background: transparent;
        color: #99F000;
        font: 400 16px/1.45 var(--font-rubik), Arial, sans-serif;
        padding: 0;
        cursor: pointer;
    }

    .chat-message-text {
        color: #fff;
        overflow-wrap: anywhere;
        white-space: pre-wrap;
    }

    #chat-history,
    #chat-history .chat-message-row,
    #chat-history .chat-message-body,
    #chat-history .chat-message-text {
        text-align: left !important;
        direction: ltr;
    }

    .chat-system-message {
        color: yellow;
    }

    .chat-player-entry,
    .chat-dm-user,
    .chat-empty-state {
        display: flex;
        width: 100%;
        min-height: 24px;
        align-items: center;
        gap: 6px;
        border: 0;
        border-radius: 3px;
        background: transparent;
        color: #fff;
        padding: 2px 4px;
        text-align: left;
    }

    .chat-player-entry,
    .chat-dm-user {
        cursor: pointer;
    }

    .chat-player-entry:hover,
    .chat-player-entry.is-active,
    .chat-dm-user:hover,
    .chat-dm-user.active {
        background: rgba(255, 255, 255, 0.1);
    }

    .chat-player-avatar,
    .chat-dm-user img {
        width: 24px;
        height: 24px;
        flex: 0 0 auto;
        border-radius: 4px;
        object-fit: contain;
    }

    .chat-player-name {
        display: none;
        min-width: 0;
        overflow: hidden;
        color: #fff;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #chat-player-list.is-expanded .chat-player-name,
    #chat-player-list:hover .chat-player-name {
        display: block;
    }

    #chat-message-input {
        position: relative;
        display: flex;
        width: 100%;
        min-height: 32px;
        align-items: center;
        background: rgba(22, 24, 26, 0.3);
        border-radius: 0 0 6px 6px;
    }

    #chat-message-input #message {
        width: 100%;
        min-width: 0;
        height: 32px;
        resize: none;
        overflow-y: auto;
        border: 2px solid transparent;
        border-radius: 0 0 6px 6px;
        background: transparent;
        color: #fff;
        font: 600 16px/1.25 var(--font-rubik), Arial, sans-serif;
        padding: 2px 32px 2px 4px;
        outline: none;
        box-sizing: border-box;
    }

    #chat-message-input #message:focus {
        border-color: #fff;
    }

    #chat-message-input #message::placeholder {
        color: #D1D5DB;
        font-style: italic;
    }

    #chat-send {
        position: absolute;
        right: 0;
        display: flex;
        width: 28px;
        height: 28px;
        align-items: center;
        justify-content: center;
        margin-right: 4px;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: #fff;
        cursor: pointer;
        font-size: 22px;
    }

    #chat-dm-empty,
    .mobile-chat-dm-empty {
        display: flex;
        min-height: 0;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin: 0;
        padding: 16px 10px;
        color: #D1D5DB;
        font: 500 13px/1.4 var(--font-rubik), Arial, sans-serif;
        text-align: center;
    }

    #chat-dm-empty[hidden],
    .mobile-chat-dm-empty[hidden],
    .chat-dm-login[hidden] {
        display: none !important;
    }

    .chat-dm-login {
        display: inline-flex;
        min-width: 68px;
        height: 30px;
        align-items: center;
        justify-content: center;
        padding: 0 12px;
        border: 1px solid #2563eb;
        border-radius: 7px;
        background: #2563eb;
        color: #fff;
        box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
        cursor: pointer;
        font: 600 14px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    .chat-dm-login:hover,
    .chat-dm-login:focus-visible {
        border-color: #1d4ed8;
        background: #1d4ed8;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
        outline: none;
    }

    #chat-dm-empty {
        margin: auto 8px;
        color: #D1D5DB;
        font-size: 12px;
    }

    #show-chat-button {
        position: fixed;
        bottom: 8px;
        left: 8px;
        z-index: 1045;
        width: 200px;
        border: 0;
        border-radius: 6px;
        background: rgba(22, 24, 26, 0.5);
        color: #fff;
        padding: 6px 8px;
        font: 500 12px/1 var(--font-rubik), Arial, sans-serif;
        text-align: left;
        cursor: pointer;
    }

    #show-chat-button:not(.d-none) {
        display: block !important;
    }

    @media (min-width: 1024px) {
        #chat-box .tab-content {
            height: 25vh;
        }

        #toggle-player-list {
            min-width: 42px;
        }

        #chat-player-list {
            width: 42px;
            min-width: 42px;
        }

        #chat-player-list.is-expanded,
        #chat-player-list:hover {
            width: 200px;
            min-width: 200px;
        }

        #chat-history {
            margin-left: 42px;
        }
    }

    @media (max-width: 768px) {
        #chat-box,
        #show-chat-button,
        #chat-input-field-div {
            display: none !important;
        }
    }

    /* Current Modd.io chat layout source: tmp/moddio-chat-current.js. */
    #chat-box {
        position: fixed !important;
        bottom: 8px !important;
        left: 8px !important;
        z-index: 1045 !important;
        color: #fff;
        font-family: var(--font-rubik), Arial, sans-serif;
        user-select: text;
    }

    #chat-tab-container {
        width: 300px !important;
        max-width: calc(100vw - 16px);
        height: auto !important;
        overflow: visible;
        border-radius: 6px;
        background: rgba(22, 24, 26, 0.5);
        box-shadow: none;
    }

    #chat-box #tabs {
        display: flex;
        width: 100%;
        min-height: 32px;
        align-items: stretch;
        margin: 0;
        overflow: hidden;
        background: transparent;
        border-radius: 6px 6px 0 0;
        box-sizing: border-box;
    }

    #toggle-player-list,
    .chat-scope-tab,
    #hide-chat-button {
        min-width: 0;
        border: 0;
        border-bottom: 2px solid transparent;
        border-radius: 6px 6px 0 0;
        background: transparent;
        color: #fff;
        font: 500 12px/1.25 var(--font-rubik), Arial, sans-serif;
        padding: 4px 5px;
        text-align: center;
        cursor: pointer;
    }

    #toggle-player-list {
        display: inline-flex;
        flex: 0 0 32px;
        align-items: center;
        justify-content: center;
        padding: 4px 6px;
    }

    .chat-scope-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    #toggle-player-list.is-active,
    .chat-scope-tab.is-active,
    .chat-scope-tab.active {
        background: rgba(22, 24, 26, 0.7);
        border-bottom-color: rgba(255, 255, 255, 0.7);
    }

    #hide-chat-button {
        display: inline-flex;
        flex: 0 0 38px;
        width: 38px;
        align-items: center;
        justify-content: center;
        margin-bottom: 0;
        margin-left: auto;
        padding: 4px;
        font-size: 12px;
        text-transform: lowercase;
    }

    #chat-box .tab-content {
        position: relative;
        display: flex;
        height: auto;
        background: transparent;
        border-radius: 0 0 6px 6px;
        overflow: visible;
    }

    #chat-player-list {
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 5;
        display: flex;
        width: 32px;
        min-width: 32px;
        top: 0;
        height: auto;
        flex-direction: column;
        gap: 4px;
        overflow-x: hidden;
        overflow-y: hidden;
        padding: 4px;
        border-right: 0;
        border-radius: 0 0 0 6px;
        background: transparent;
        transition: width 0s;
    }

    #chat-player-list.is-expanded {
        width: 160px;
        min-width: 160px;
        overflow-y: auto;
        background: #16181A;
    }

    #chat-player-list:hover:not(.is-expanded) {
        width: 160px;
        min-width: 160px;
        overflow-y: auto;
        background: #4B5563;
    }

    #chat-player-list:hover:not(.is-expanded) .chat-player-name {
        color: #fff;
    }

    #chat-player-list[hidden] {
        display: flex;
    }

    #chat-main-column {
        position: relative;
        display: flex;
        min-width: 0;
        width: calc(100% - 32px);
        margin-left: 32px;
        flex-direction: column;
    }

    #pc-play-chat-message-container {
        display: flex;
        width: 100%;
        flex-direction: column;
    }

    #chat-message-container {
        display: flex;
        width: 100%;
        min-height: 170px;
        height: 170px;
        max-height: 170px;
        flex-direction: column;
        overflow-y: visible;
        background: rgba(22, 24, 26, 0.7);
    }

    #chat-active-heading {
        display: none;
    }

    #chat-history {
        flex: 1;
        min-width: 0;
        padding: 8px;
        overflow-y: auto;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .chat-message-row {
        display: block;
        padding: 2px 0 2px 10px;
        font-size: 14px;
        line-height: 1.45;
    }

    .chat-message-avatar-button,
    .chat-message-avatar {
        display: none;
    }

    .chat-message-author {
        border: 0;
        background: transparent;
        color: #99F000;
        font: 400 14px/1.45 var(--font-rubik), Arial, sans-serif;
        padding: 0;
        cursor: pointer;
    }

    .chat-message-text {
        color: #fff;
        overflow-wrap: anywhere;
        white-space: pre-wrap;
    }

    .chat-player-entry,
    .chat-dm-user,
    .chat-empty-state {
        display: flex;
        width: 100%;
        height: 32px;
        align-items: center;
        gap: 6px;
        border: 0;
        border-radius: 3px;
        background: transparent;
        color: #fff;
        padding: 4px;
        text-align: left;
    }

    .chat-player-avatar,
    .chat-dm-user img {
        width: 20px;
        height: 20px;
        flex: 0 0 auto;
        border-radius: 4px;
        object-fit: contain;
    }

    .chat-player-name {
        display: none;
        min-width: 0;
        overflow: hidden;
        color: #fff;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-dm-profile {
        position: relative;
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
    }

    .chat-dm-name {
        display: none;
        min-width: 0;
        overflow: hidden;
        color: #fff;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-dm-unread-badge,
    .chat-tab-unread-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #D6E4FF;
        color: #42389D;
        font-weight: 700;
        line-height: 1;
    }

    .chat-dm-unread-badge {
        position: absolute;
        top: -5px;
        left: -5px;
        width: 16px;
        height: 16px;
        font-size: 10px;
    }

    .chat-tab-unread-badge {
        width: 22px;
        height: 22px;
        margin-left: 2px;
        font-size: 10px;
    }
