/*
 * The site chat, docked to the right.
 *
 * Loaded on every page. The panel is a real layout column rather than a fixed
 * overlay, because a floating chat covers the thing the page is for - and on
 * the battle page it covered the reels.
 *
 * Two halves that have to agree:
 *   - `body.mm2chat-on` reserves the column, so page content ends where chat
 *     begins instead of running underneath it;
 *   - the panel itself slides out of that column when closed, and the content
 *     widens to fill it. That is the whole animation, and it is a transform
 *     rather than a margin so it stays on the compositor.
 *
 * The breakpoints are not arbitrary: at 1100px the column narrows, and below
 * 820px it stops being a column at all and becomes an overlay, because a
 * 320px column on a phone leaves nothing for the game.
 */

:root {
  --mm2chat-w: 320px;
}

body.mm2chat-on {
  padding-right: var(--mm2chat-w);
  transition: padding-right 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When closed the page takes the space back. */
body.mm2chat-on.mm2chat-closed {
  padding-right: 0;
}

/* ── the panel ──────────────────────────────────────────────────────── */
.mm2chat {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--mm2chat-w);
  background: #111827;
  border-left: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  z-index: 120;
  transform: translateX(0);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.85rem;
}

.mm2chat.mm2chat-hidden {
  transform: translateX(100%);
  /* Off-screen but still focusable without this, which leaves a keyboard
     user's cursor trapped in a panel they cannot see. */
  pointer-events: none;
  visibility: hidden;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0s linear 0.32s;
}

.mm2chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1e293b;
  flex: 0 0 auto;
}

.mm2chat-title {
  font-weight: 700;
  letter-spacing: 0.4px;
}

.mm2chat-close {
  background: none;
  border: none;
  color: #8899aa;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}

.mm2chat-close:hover {
  color: #fff;
  background: #1e293b;
}

.mm2chat-msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
}

.mm2chat-msg {
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px);
  animation: mm2chat-in 0.28s ease forwards;
  /* A very long unbroken token (a URL, a paste) must not widen the column. */
  overflow-wrap: anywhere;
}

@keyframes mm2chat-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mm2chat,
  body.mm2chat-on,
  .mm2chat-toggle,
  .mm2chat-msg {
    animation: none;
    transition: none;
  }
}

/*
 * Suppress every transition until after the first paint.
 *
 * The panel is mounted already carrying whatever state the reader last chose,
 * so on load it starts life at translateX(0) and immediately transitions to
 * translateX(100%) - which means a page that loads with chat closed animates
 * the panel in from off-screen, once, on every single page load. The state is
 * correct throughout; the arrival is not.
 *
 * `mm2chat-ready` is added on the frame after mount, which is after the first
 * paint, so the initial position is never animated. Transitions are then
 * re-enabled and every subsequent open/close slides as intended.
 */
body.mm2chat-mounting .mm2chat,
body.mm2chat-mounting .mm2chat-toggle,
body.mm2chat-mounting .mm2chat-msg {
  animation: none !important;
  transition: none !important;
}

.mm2chat-author {
  font-weight: 700;
  color: #4a90d9;
}

.mm2chat-text {
  color: #ccc;
}

.mm2chat-amount {
  color: #f0c040;
  font-weight: 600;
}

.mm2chat-form {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-top: 1px solid #1e293b;
  display: flex;
  gap: 8px;
}

.mm2chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  background: #1a2540;
  border: 1px solid #253550;
  border-radius: 8px;
  color: #fff;
  font-size: 0.85rem;
  outline: none;
}

.mm2chat-input:focus {
  border-color: #f0c040;
}

.mm2chat-send {
  flex: 0 0 auto;
  padding: 10px 14px;
  background: #f0c040;
  border: none;
  border-radius: 8px;
  color: #0b0f1a;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}

.mm2chat-send:hover {
  background: #ffd75e;
}

/* ── the button that brings it back ─────────────────────────────────── */
.mm2chat-toggle {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #cfd8e3;
  border: 1px solid #253550;
  border-right: none;
  border-radius: 8px 0 0 8px;
  padding: 16px 9px;
  cursor: pointer;
  z-index: 121;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, background 0.2s ease;
}

.mm2chat-toggle span {
  display: block;
  writing-mode: vertical-rl;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.mm2chat-toggle:hover {
  background: #253550;
}

/* Hidden while the panel is open, and the fade is what makes closing feel
   like a slide rather than a pop. */
.mm2chat-toggle:not(.mm2chat-hidden) {
  opacity: 1;
  pointer-events: auto;
}

.mm2chat-toggle.mm2chat-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── narrower ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  :root {
    --mm2chat-w: 280px;
  }
}

/* Below this the column would leave the game nothing to render, so the panel
   overlays instead. The page no longer reserves space in this mode. */
@media (max-width: 820px) {
  body.mm2chat-on,
  body.mm2chat-on.mm2chat-closed {
    padding-right: 0;
  }

  .mm2chat {
    width: min(320px, 92vw);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.55);
  }

  .mm2chat-toggle {
    padding: 14px 8px;
  }
}