/* =========================================================================
   gameManager/MTG/chat.css — the in-game chat slide-out. 2026-08-23i batch.

   Two jobs:
   1. The panel itself — dark glass, right-hand slide, resizable, message
      bubbles, presence pills, unread badges, mobile backdrop mode.
   2. THE PUSH — under body.chat-push (desktop, panel open) every
      right-anchored or centered fixed game area shifts left by
      --chat-push, in lockstep with window.gameW() in the JS (chat.js
      owns both), so the whole board compresses instead of being covered.
   ========================================================================= */

/* ---------- Panel shell ---------- */
#chatPanel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 340px;
    display: flex;
    flex-direction: column;
    background: rgba(17, 20, 26, 0.92);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.35);
    color: #e8eaf0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 9500;              /* above the board, below account dialogs (9999) */
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(0.32, 0.72, 0.22, 1);
    visibility: hidden;
}
body.chat-open #chatPanel {
    transform: translateX(0);
    visibility: visible;
}
/* keep it interactable during the slide-out animation */
#chatPanel { transition-property: transform, visibility; }

/* ---------- Resize handle (desktop) ---------- */
#chatResizeHandle {
    position: absolute;
    top: 0;
    left: -4px;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}
#chatResizeHandle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 4px;
    width: 3px;
    height: 44px;
    margin-top: -22px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.18);
    opacity: 0;
    transition: opacity 0.15s ease;
}
#chatResizeHandle:hover::after { opacity: 1; }
body.chat-resizing { cursor: col-resize; user-select: none; }
body.chat-resizing #chatPanel { transition: none; }

/* ---------- Header ---------- */
#chatHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex: 0 0 auto;
}
#chatHeaderText h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
#chatSubtitle {
    display: block;
    font-size: 11px;
    color: rgba(232, 234, 240, 0.45);
}
#chatCloseBtn {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    padding: 7px;
    margin: 0;
    border-radius: 8px;
    color: rgba(232, 234, 240, 0.65);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
#chatCloseBtn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* ---------- Messages ---------- */
#chatScroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
#chatScroll::-webkit-scrollbar { width: 6px; }
#chatScroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* the adopted legacy <ul> — core_base.css zebra styling neutralized */
#chatPanel #messages {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
#chatPanel #messages li { padding: 0; background: none; }
#chatPanel #messages li:nth-child(odd) { background: none; }

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    margin-top: 10px;
    animation: chatMsgIn 0.18s ease both;
}
.chat-msg.chat-grouped { margin-top: 2px; }
.chat-mine { align-self: flex-end; align-items: flex-end; }
.chat-theirs { align-self: flex-start; align-items: flex-start; }

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-name {
    font-size: 11px;
    font-weight: 600;
    color: rgba(232, 234, 240, 0.55);
    margin: 0 4px 3px;
}
.chat-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}
.chat-mine .chat-bubble {
    background: linear-gradient(135deg, #2f6df6, #2558d0);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.chat-theirs .chat-bubble {
    background: rgba(255, 255, 255, 0.09);
    border-bottom-left-radius: 5px;
}
.chat-grouped.chat-mine .chat-bubble { border-top-right-radius: 5px; }
.chat-grouped.chat-theirs .chat-bubble { border-top-left-radius: 5px; }

.chat-time {
    font-size: 10px;
    color: rgba(232, 234, 240, 0.35);
    margin: 3px 6px 0;
}
.chat-grouped .chat-time { display: none; }

.chat-presence {
    display: flex;
    justify-content: center;
    margin: 12px 0 2px;
}
.chat-presence span {
    font-size: 11px;
    color: rgba(232, 234, 240, 0.5);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    padding: 3px 12px;
}

/* ---------- "New messages" jump pill ---------- */
#chatJumpBtn {
    position: absolute;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: #2f6df6;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}
#chatJumpBtn.hidden { display: none; }

/* ---------- Composer (the adopted #chatForm) ---------- */
#chatPanel #chatForm {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    flex: 0 0 auto;
}
#chatPanel #chatForm input#txt {
    flex: 1 1 auto;
    width: auto;
    margin: 0;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: #e8eaf0;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}
#chatPanel #chatForm input#txt::placeholder { color: rgba(232, 234, 240, 0.35); }
#chatPanel #chatForm input#txt:focus {
    border-color: rgba(47, 109, 246, 0.7);
    background: rgba(255, 255, 255, 0.09);
}
#chatPanel #chatForm button {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: #2f6df6;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease;
}
#chatPanel #chatForm button:hover { background: #3b7bff; }
#chatPanel #chatForm button:active { transform: scale(0.92); }

/* ---------- Unread badges ---------- */
.menu-chat-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(245, 245, 245, 0.9);
    pointer-events: none;
}
.menu-chat-dot.hidden { display: none; }
.menu-button { position: relative; }

.chat-unread-badge {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    margin-left: 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
}
.chat-unread-badge.hidden { display: none; }

/* ---------- Mobile: overlay + backdrop ---------- */
#chatBackdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9400;
    opacity: 1;
    transition: opacity 0.24s ease;
}
#chatBackdrop.hidden { opacity: 0; pointer-events: none; }

@media (max-width: 768px) {
    #chatPanel { width: min(88vw, 400px); }
    #chatResizeHandle { display: none; }
}

/* =========================================================================
   THE PUSH — desktop only (body.chat-push). Every right-anchored or
   centered fixed area shifts by --chat-push; the JS math shifts with it
   because window.gameW() subtracts the same width. Left-anchored pieces
   (graveyard, exile, oBattle/oEnchant, planeswalker) don't move.
   The offsets animate with the panel; body.chat-resizing kills the
   transitions so a resize drag tracks 1:1.
   ========================================================================= */
:root { --chat-push: 0px; }

body.chat-push #cardArea,
body.chat-push #cardAreaHidden,
body.chat-push #oCardArea,
body.chat-push #oCardAreaHidden,
body.chat-push #creatureArea,
body.chat-push #oCreatureArea,
body.chat-push #enchantArea,
body.chat-push #battleArea,
body.chat-push #oPlaneswalkerArea,
body.chat-push #oArtifactArea {
    right: var(--chat-push);
}

/* centered pieces re-center inside the reduced game viewport */
body.chat-push #dropZone {
    left: calc((100% - var(--chat-push)) / 2);
}
body.chat-push #landArea,
body.chat-push #oLandArea {
    left: calc(0.25 * (100% - var(--chat-push)));
    right: calc(0.25 * (100% - var(--chat-push)) + var(--chat-push));
}

/* right-hugging containers */
body.chat-push #oGraveyardAreaContainer,
body.chat-push #oExileAreaContainer {
    right: calc(var(--chat-push) + 6px);
}

/* smooth follow while the panel slides (not while hand-resizing) */
#cardArea, #cardAreaHidden, #oCardArea, #oCardAreaHidden,
#creatureArea, #oCreatureArea, #enchantArea, #battleArea,
#oPlaneswalkerArea, #oArtifactArea, #dropZone, #landArea, #oLandArea,
#oGraveyardAreaContainer, #oExileAreaContainer {
    transition: right 0.24s cubic-bezier(0.32, 0.72, 0.22, 1),
                left 0.24s cubic-bezier(0.32, 0.72, 0.22, 1),
                border-color 0.3s ease;   /* keep the dropZone/exile fades */
}
body.chat-resizing #cardArea, body.chat-resizing #cardAreaHidden,
body.chat-resizing #oCardArea, body.chat-resizing #oCardAreaHidden,
body.chat-resizing #creatureArea, body.chat-resizing #oCreatureArea,
body.chat-resizing #enchantArea, body.chat-resizing #battleArea,
body.chat-resizing #oPlaneswalkerArea, body.chat-resizing #oArtifactArea,
body.chat-resizing #dropZone, body.chat-resizing #landArea,
body.chat-resizing #oLandArea, body.chat-resizing #oGraveyardAreaContainer,
body.chat-resizing #oExileAreaContainer {
    transition: none;
}
