/* chat — table chat button, emote tray, speech bubbles, floating emotes,
   the drop-down chat panel and the shared message list (lobby + panel). */

/* ------------------------------------------------------------ table dock */
/* Mounted in .hand-wrap (the player's own area): a pair on the right of the name line,
   just above YANIV — thumb-reachable. Chat is the filled, high-contrast one. */
.chat-dock {
  position: absolute; z-index: 32;
  right: -2px; bottom: 2px; top: auto;
  display: flex; flex-direction: row-reverse; align-items: center; gap: 6px;
  pointer-events: none;
}
.chat-dock > * { pointer-events: auto; }
.chat-fab {
  position: relative; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; padding: 0;
  background: linear-gradient(180deg, #fffdf6, #efdfbd);
  border: 2px solid #b89b6a; color: #5a3a1a;
  box-shadow: 0 3px 0 #8a6c40, 0 6px 12px rgba(60, 40, 15, 0.28);
  transition: transform 0.12s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-fab:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a6c40, 0 3px 6px rgba(60, 40, 15, 0.25); }
.chat-fab:focus-visible { outline: 3px solid #22a9d8; outline-offset: 2px; }
#chatBtn {
  width: 42px; height: 42px; color: #fff;
  background: linear-gradient(180deg, #3fc6f0, #1597cc); border-color: #0b6f9a;
  box-shadow: 0 3px 0 #0a5f84, 0 6px 12px rgba(10, 60, 90, 0.3);
}
#chatBtn:active { box-shadow: 0 1px 0 #0a5f84, 0 3px 6px rgba(10, 60, 90, 0.25); }
#chatBtn[aria-expanded="true"] { background: linear-gradient(180deg, #1597cc, #0b7fb0); border-color: #08597c; }
.emote-fab { width: 36px; height: 36px; }
.emote-fab svg { width: 19px; height: 19px; }
.chat-fab::before { content: ""; position: absolute; inset: -4px; } /* 48px touch target */
.chat-fab svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.chat-fab svg .dots { stroke-width: 3; }
.chat-fab[aria-expanded="true"] { background: linear-gradient(180deg, #ffe680, #ffc928); border-color: #c99a1c; }
.chat-fab.muted svg { opacity: 0.45; }
.chat-fab.muted::after {
  content: ""; position: absolute; left: 9px; right: 9px; top: 50%; height: 2.5px;
  background: #b3261c; border-radius: 2px; transform: rotate(-40deg);
}
.chat-badge {
  position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #e2372b; color: #fff; border: 2px solid #fff;
  font: 700 11px/16px "Fredoka", sans-serif; text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}
.chat-badge.bump { animation: chatBump 0.42s cubic-bezier(0.3, 1.8, 0.5, 1); }
@keyframes chatBump { from { transform: scale(0.4); } to { transform: scale(1); } }

/* quick-reaction tray (drops down under the buttons, right-aligned) */
.emote-tray {
  position: absolute; top: auto; bottom: 52px; right: 0;
  width: min(272px, calc(100vw - 80px));
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px;
  padding: 8px; border-radius: 16px;
  background: linear-gradient(180deg, #fffdf6, #f3e6ca);
  border: 2px solid #d8c19a;
  box-shadow: 0 10px 26px rgba(60, 40, 15, 0.35);
  transform-origin: 85% 100%;
  animation: chatTrayIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes chatTrayIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ chips */
.chat-quick {
  display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain;
  padding: 6px 1px 8px; margin: 0 -2px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
  mask-image: linear-gradient(90deg, #000 88%, transparent);
}
.chat-quick::-webkit-scrollbar { display: none; }
.chat-chip {
  flex: none; min-height: 34px; padding: 4px 11px; border-radius: 999px;
  border: 2px solid rgba(120, 90, 50, 0.22); background: rgba(255, 255, 255, 0.8);
  color: var(--ink); font: 600 12.5px/1 "Fredoka", sans-serif; white-space: nowrap;
  transition: transform 0.12s ease, background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-chip.emoji { font-size: 19px; padding: 2px 8px; min-width: 40px; }
.chat-chip:active { transform: scale(0.9); }
.chat-chip:focus-visible { outline: 3px solid #22a9d8; outline-offset: 1px; }
.chat-chip.sent { animation: chatChipSent 0.35s ease-out; }
@keyframes chatChipSent { 0% { transform: scale(0.85); } 55% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* --------------------------------------------------- bubbles over seats */
.chat-fx { position: absolute; inset: 0; z-index: 30; pointer-events: none; overflow: hidden; }
.chat-bubble {
  --c: hsl(var(--hue, 200) 55% 45%);
  position: absolute; max-width: min(200px, 56vw);
  padding: 7px 11px; border-radius: 14px;
  background: #fffdf6; color: var(--ink);
  border: 2px solid var(--c);
  box-shadow: 0 6px 16px rgba(40, 25, 10, 0.3);
  font: 500 13.5px/1.28 "Fredoka", sans-serif;
  overflow-wrap: anywhere;
  animation: chatBubbleIn 0.32s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.chat-bubble::after {
  content: ""; position: absolute; width: 10px; height: 10px;
  background: inherit; border: inherit; border-width: 0 2px 2px 0; border-style: solid; border-color: var(--c);
}
.chat-bubble.dir-down { transform-origin: var(--tail-x, 50%) 0; }
.chat-bubble.dir-down::after { top: -7px; left: calc(var(--tail-x, 50%) - 6px); transform: rotate(-135deg); }
.chat-bubble.dir-up { transform-origin: var(--tail-x, 50%) 100%; }
.chat-bubble.dir-up::after { bottom: -7px; left: calc(var(--tail-x, 50%) - 6px); transform: rotate(45deg); }
/* side seats face each other: keep each bubble to its own half of the table */
.chat-bubble.dir-right, .chat-bubble.dir-left { max-width: min(150px, calc(50vw - 62px)); }
.chat-bubble.dir-right { transform-origin: 0 var(--tail-y, 50%); }
.chat-bubble.dir-right::after { left: -7px; top: calc(var(--tail-y, 50%) - 6px); transform: rotate(135deg); }
.chat-bubble.dir-left { transform-origin: 100% var(--tail-y, 50%); }
.chat-bubble.dir-left::after { right: -7px; top: calc(var(--tail-y, 50%) - 6px); transform: rotate(-45deg); }
.chat-bubble.mine { background: #fff4c4; }
.chat-bubble.emote {
  background: linear-gradient(180deg, #ffe680, #ffc928); border-color: #c98a00; --c: #c98a00;
  font: 400 19px/1.1 Bangers, Impact, sans-serif; letter-spacing: 0.8px; color: #5a2c0c;
  padding: 6px 12px 5px;
}
.chat-bubble.out { animation: chatBubbleOut 0.24s ease-in both; }
@keyframes chatBubbleIn { from { opacity: 0; transform: scale(0.45); } to { opacity: 1; transform: scale(1); } }
@keyframes chatBubbleOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-6px) scale(0.92); } }

.chat-float {
  position: absolute; font-size: 42px; line-height: 1;
  transform: translate(-50%, -50%); opacity: 0;
  filter: drop-shadow(0 4px 6px rgba(40, 25, 10, 0.35));
  animation: chatFloat 1.9s cubic-bezier(0.25, 0.8, 0.35, 1) forwards;
}
.chat-float.small { font-size: 24px; }
@keyframes chatFloat {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  14% { opacity: 1; transform: translate(-50%, -60%) scale(1.3); }
  28% { transform: translate(-50%, -66%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% - 96px)) scale(1.05); }
}

/* -------------------------------------------- drop-down chat panel */
/* Anchored to the top of the visual viewport so the hand stays visible and
   playable, and the input stays above the on-screen keyboard. --vv-top/--vv-h
   are kept in sync with window.visualViewport by chat.js. */
.chat-panel {
  position: absolute; z-index: 60;
  left: 8px; right: 8px; margin: 0 auto; max-width: 520px;
  top: calc(var(--vv-top, 0px) + var(--safe-top) + 8px);
  height: min(48vh, calc(var(--vv-h, 100vh) - var(--safe-top) - 20px));
  height: min(48dvh, calc(var(--vv-h, 100dvh) - var(--safe-top) - 20px));
  min-height: 200px;
  display: flex; flex-direction: column;
  padding: 8px 12px 10px;
  border-radius: 20px;
  background:
    repeating-linear-gradient(0deg, rgba(150, 115, 60, 0.05) 0 1px, transparent 1px 5px),
    linear-gradient(180deg, #fffdf6, #f3e6ca);
  border: 2px solid #d8c19a;
  box-shadow: 0 18px 44px rgba(40, 25, 10, 0.45);
  color: var(--ink);
  transform-origin: 50% 0;
  animation: chatPanelIn 0.24s cubic-bezier(0.2, 0.9, 0.25, 1);
  --muted: rgba(43, 29, 16, 0.55);
}
.chat-panel.closing { animation: chatPanelOut 0.18s ease-in forwards; }
@keyframes chatPanelIn { from { opacity: 0; transform: translateY(-18px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes chatPanelOut { to { opacity: 0; transform: translateY(-14px) scale(0.98); } }

.chat-panel-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.chat-panel-title { flex: 1; font-weight: 600; font-size: 16px; }
.chat-icon-btn {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; padding: 0;
  border: 2px solid rgba(120, 90, 50, 0.22); background: rgba(255, 255, 255, 0.65); color: var(--ink);
}
.chat-icon-btn:focus-visible { outline: 3px solid #22a9d8; outline-offset: 1px; }
.chat-icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
#chatMute .off, #chatMute[aria-pressed="true"] .on { display: none; }
#chatMute[aria-pressed="true"] .off { display: block; }
#chatMute[aria-pressed="true"] { background: rgba(179, 38, 28, 0.1); border-color: rgba(179, 38, 28, 0.35); color: #b3261c; }

.chat-panel .chat-panel-list {
  flex: 1; min-height: 0; max-height: none; margin: 0 -4px; padding: 4px;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  border-radius: 12px; background: rgba(255, 255, 255, 0.35);
}
.chat-panel .chat-panel-list > :first-child { margin-top: auto; } /* short threads sit at the bottom, near the input */
.chat-panel .chat-quick { padding-top: 7px; }
.chat-panel .chat-form { display: flex; gap: 6px; align-items: center; }
.chat-panel .chat-form input { flex: 1; min-width: 0; font-size: 16px; padding: 10px 12px; border-radius: 12px; }
.chat-send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: linear-gradient(180deg, #ffe680, #ffc928); border: 2px solid #c99a1c; color: #5a2c0c;
  box-shadow: 0 2px 0 #a67c12;
}
.chat-send:active { transform: translateY(1px); box-shadow: none; }
.chat-send svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }

/* --------------------------------------------- message list (shared) */
.lobby-chat .chat-list { max-height: 180px; }
.chat-list { scroll-behavior: auto; }
.cm-empty { color: var(--muted, rgba(43, 29, 16, 0.55)); font-size: 12.5px; text-align: center; padding: 18px 8px; }
.cm { display: flex; align-items: flex-end; gap: 6px; margin-top: 4px; }
.cm.grouped { margin-top: 1px; }
.cm.mine { justify-content: flex-end; }
.cm-av {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 11.5px; font-weight: 700; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5);
}
.cm.grouped .cm-av { visibility: hidden; height: 0; }
.cm-b {
  max-width: 80%; padding: 5px 10px 6px; border-radius: 13px 13px 13px 4px;
  background: rgba(255, 255, 255, 0.88); border: 1px solid rgba(120, 90, 50, 0.14);
}
.cm.mine .cm-b { background: #fff1b8; border-color: rgba(201, 154, 28, 0.35); border-radius: 13px 13px 4px 13px; }
.cm-h { display: flex; align-items: baseline; gap: 6px; }
.cm-h b { font-size: 12px; font-weight: 700; }
.cm time, .cm-emote time { font-size: 10px; color: var(--muted, rgba(43, 29, 16, 0.5)); font-variant-numeric: tabular-nums; }
.cm-emote time { margin-left: 6px; }
.cm-t { font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; color: var(--ink); }
.cm-emote { font-size: 12px; margin: 3px 0 0 30px; color: var(--muted, rgba(43, 29, 16, 0.6)); display: flex; align-items: center; gap: 4px; }
.cm-emote.mine { justify-content: flex-end; margin-left: 0; }
.cm-emote b { font-weight: 700; }
.cm-emoji { font-size: 22px; line-height: 1; }
.cm-shout { font-family: Bangers, Impact, sans-serif; font-size: 16px; letter-spacing: 0.6px; color: #b3700a; }
.cm-sys { text-align: center; margin: 6px 0 4px; }
.cm-sys span {
  display: inline-block; max-width: 92%; padding: 3px 11px; border-radius: 999px;
  font-size: 11.5px; line-height: 1.3; color: rgba(43, 29, 16, 0.62);
  background: rgba(120, 90, 50, 0.08);
}
.cm-sys.tone-join span { color: #2d6b2a; background: rgba(70, 150, 60, 0.12); }
.cm-sys.tone-leave span { color: rgba(43, 29, 16, 0.55); }
.cm-sys.tone-yaniv span {
  color: #6a3f00; font-weight: 600; background: linear-gradient(180deg, #fff0a6, #ffd75a);
  border: 1px solid rgba(201, 138, 0, 0.5);
}
.cm-sys.tone-asaf span { color: #fff; font-weight: 600; background: #c4392c; }
.cm-sys.tone-win span { color: #5a2c0c; font-weight: 700; background: linear-gradient(180deg, #ffe680, #ffc928); border: 1px solid #c99a1c; }

/* ------------------------------------------------------------ small screens */
@media (max-height: 640px) {
  .chat-dock { gap: 5px; }
  #chatBtn { width: 38px; height: 38px; }
  .emote-fab { width: 32px; height: 32px; }
  .chat-fab svg { width: 18px; height: 18px; }
  .emote-tray { bottom: 46px; }
}

/* ------------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  .chat-badge.bump, .chat-chip.sent, .emote-tray { animation: none; }
  .chat-panel, .chat-panel.closing { animation: none; }
  .chat-bubble { animation: chatFadeIn 0.2s linear both; }
  .chat-bubble.out { animation: chatFadeOut 0.2s linear both; }
  .chat-float { animation: chatFadeFloat 1.8s linear forwards; transform: translate(-50%, -50%); }
  .chat-fab, .chat-chip { transition: none; }
}
@keyframes chatFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes chatFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes chatFadeFloat { 0% { opacity: 0; } 15%, 75% { opacity: 1; } 100% { opacity: 0; } }
