/* 단체 채팅: 오른쪽 아래에 떠 있는 버튼 + 그 위로 열리는 채팅창 (js/shell/chat.js)
   쌓임 순서: 상단 바 10 · 히든 워드 매칭 표시 20 · 채팅 25 · 설정·계정 창 30 · 시작 화면 50 · 대화상자 60 · 알림 70
   뒤 화면을 막지 않는다: 가리는 막이 없고, 자리만 차지하는 바깥 틀은 누를 수 없게 둔다. */
.chat {
  --chat-edge: 16px;
  --chat-fab: 56px;
  --chat-cut: 9px;
  position: fixed;
  z-index: 25;
  right: calc(var(--chat-edge) + env(safe-area-inset-right));
  bottom: calc(var(--chat-edge) + env(safe-area-inset-bottom) + var(--chat-kb, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.chat[hidden], .chat [hidden] { display: none; }
.chat > * { pointer-events: auto; }

/* ── 버튼: 크롬 테를 두른 어두운 원판 ── */
.chat-fab {
  position: relative;
  flex: none;
  width: var(--chat-fab);
  height: var(--chat-fab);
  padding: 0;
  display: grid;
  place-items: center;
  border: 1.5px solid transparent;
  border-radius: 50%;
  color: var(--chrome-1);
  background:
    radial-gradient(120% 120% at 30% 18%, #3b1a33, #170d1f 62%) padding-box,
    linear-gradient(155deg, var(--chrome-1), var(--chrome-4) 42%, var(--blue-deep) 70%, var(--blue-hi)) border-box;
  box-shadow: 0 16px 30px -12px #000, 0 0 26px -8px rgba(224, 100, 154, .7);
  cursor: pointer;
  transform-origin: 100% 100%;
  transition: transform .18s var(--ease), opacity .2s;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab:active { transform: scale(.94); }
.chat-fab:focus-visible { outline: 2px solid var(--blue-hi); outline-offset: 3px; border-radius: 50%; }
.chat-ico { filter: drop-shadow(0 0 6px rgba(255, 158, 194, .45)); }
.chat-ico-close { display: none; color: var(--blue-hi); }
.chat-fab[aria-expanded="true"] .chat-ico { display: none; }
.chat-fab[aria-expanded="true"] .chat-ico-close { display: block; }
/* 안 읽은 글 수: 접속자 표시와 같은 비스듬한 붉은 판 */
.chat-badge {
  position: absolute;
  top: -5px;
  right: -7px;
  min-width: 26px;
  padding: 2px 9px 2px 8px;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  background: #ff2d4b;
  color: #fff;
  font-size: 12px;
  font-style: italic;
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
  font-variant-numeric: tabular-nums;
  animation: chat-pop .28s var(--ease);
}
@keyframes chat-pop { from { transform: scale(.4); opacity: 0; } }
/* 게임 중에는 작고 흐리게 물러나 있는다.
   크기는 transform 으로만 줄인다 (자리 크기를 바꾸면 화면 배치가 다시 계산돼 버튼과 주변이 떨려 보였다, 12-01).
   오른쪽 아래 모서리를 기준으로 줄여 버튼 자리가 그대로다. 0.786 ≈ 44/56 */
.chat.is-playing:not(.is-open) .chat-fab { transform: scale(.786); opacity: .62; }
.chat.is-playing:not(.is-open) .chat-fab:hover { transform: translateY(-2px) scale(.786); }
.chat.is-playing:not(.is-open) .chat-fab:active { transform: scale(.74); }
.chat.is-playing:not(.is-open) .chat-fab:is(:hover, :focus-visible) { opacity: 1; }
/* 키보드 때문에 세로가 좁을 때는 버튼을 치워 채팅창 자리를 넓힌다 */
.chat.is-tight .chat-fab { display: none; }

/* ── 채팅창 ── */
.chat-panel {
  width: min(364px, calc(100vw - var(--chat-edge) * 2 - env(safe-area-inset-left) - env(safe-area-inset-right)));
  height: min(540px, calc(var(--chat-vh, 100dvh) - var(--chat-fab) - var(--chat-edge) - 92px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  min-height: 190px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(19, 12, 25, .96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line-hi);
  border-radius: 20px;
  box-shadow: 0 34px 70px -26px #000, 0 0 46px -20px rgba(224, 100, 154, .45);
  transform-origin: 100% 100%;
  animation: chat-open .2s var(--ease);
}
.chat.is-tight .chat-panel { height: calc(var(--chat-vh, 100dvh) - var(--chat-edge) * 2); }
@keyframes chat-open { from { opacity: 0; transform: translateY(10px) scale(.96); } }

.chat-head {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px 11px 16px;
  background: linear-gradient(100deg, rgba(255, 45, 75, .16), transparent 62%);
}
.chat-head::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, #ff2d4b, rgba(255, 158, 194, .5) 38%, transparent 82%);
}
.chat-live {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff2338;
  box-shadow: 0 0 0 3px rgba(255, 35, 56, .18), 0 0 12px 2px rgba(255, 35, 56, .9);
  animation: chat-rec 1.6s ease-in-out infinite;
}
@keyframes chat-rec { 0%, 45% { opacity: 1; } 60%, 85% { opacity: .28; } 100% { opacity: 1; } }
.chat-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.3;
  padding-right: 4px;
  background: var(--chrome-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chat-close {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chat-close:hover { color: var(--text); background: var(--surface-hi); }
.chat-close:focus-visible { border-radius: 50%; }

.chat-body { position: relative; flex: 1; min-height: 0; display: flex; }
.chat-list {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 4px 14px 12px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none; /* 보던 줄 지키기는 js 가 직접 한다 (브라우저와 두 번 고치지 않게) */
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 172, 214, .25) transparent;
}
.chat-list:focus-visible { outline-offset: -3px; border-radius: 10px; }
.chat-empty {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  text-align: center;
  text-wrap: balance;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

/* 글 한 줄: 한쪽 모서리를 딴 판. 남의 글은 왼쪽 위, 내 글은 오른쪽 아래를 딴다 */
.chat-msg { display: grid; justify-items: start; margin-top: 12px; }
.chat-msg.is-cont { margin-top: 3px; }
.chat-msg.is-me { justify-items: end; }
.chat-meta { display: flex; align-items: baseline; gap: 7px; max-width: 100%; margin-bottom: 4px; font-size: 12px; line-height: 1.3; }
.chat-msg.is-cont .chat-meta { display: none; }
.chat-msg.is-me .chat-meta { flex-direction: row-reverse; }
.chat-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; color: var(--blue-hi); }
.chat-name.is-guest { color: var(--chrome-2); font-weight: 700; }
.chat-time { flex: none; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chat-row { display: flex; align-items: center; gap: 4px; max-width: 86%; }
.chat-msg.is-me .chat-row { flex-direction: row-reverse; }
.chat-text {
  min-width: 0;
  margin: 0;
  padding: 7px 12px 8px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
  color: var(--text);
  background: rgba(196, 168, 214, .1);
  border-radius: 0 11px 11px 11px;
  clip-path: polygon(var(--chat-cut) 0, 100% 0, 100% 100%, 0 100%, 0 var(--chat-cut));
}
.chat-msg.is-me .chat-text {
  color: #fff;
  background: linear-gradient(135deg, #c04a80, #86224c);
  border-radius: 11px 11px 0 11px;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--chat-cut)), calc(100% - var(--chat-cut)) 100%, 0 100%);
}
/* 자동 번역 표시: 번역된 글 아래 작은 단추 (누르면 원문 ↔ 번역) */
.chat-tr {
  justify-self: start;
  margin: 3px 0 0 2px;
  padding: 2px 8px;
  border: 0;
  border-radius: 999px;
  background: rgba(78, 168, 255, .1);
  color: var(--blue-hi);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
}
.chat-tr:hover, .chat-tr:focus-visible { background: rgba(78, 168, 255, .22); color: #fff; outline: none; }
.chat-tr[aria-pressed="true"] { background: rgba(196, 168, 214, .12); color: var(--chrome-2); }
.chat-del {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.chat-del:hover { color: var(--red-hi); background: rgba(255, 45, 75, .14); }

.chat-jump {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 18px;
  border: 0;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  background: #ff2d4b;
  color: #fff;
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chat-jump:focus-visible { outline: none; box-shadow: inset 0 0 0 2px #fff; }

/* ── 입력 줄 ── */
.chat-form {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  padding: 8px 10px 10px 12px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, .22);
}
.chat-note-row { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chat-note { flex: 1; min-width: 0; margin: 0; font-size: 12px; line-height: 1.35; color: var(--red-hi); }
.chat-note:not(:empty), .chat-count { padding: 0 2px 6px; }
.chat-count { flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-count.is-full { color: var(--red-hi); font-weight: 700; }
.chat-input {
  min-width: 0;
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line-hi);
  border-radius: 12px;
  background: rgba(8, 5, 12, .7);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}
.chat-input::placeholder { color: var(--muted); opacity: .8; }
.chat-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-dim); }
/* 터치 기기: 16px 보다 작으면 아이폰이 입력할 때 화면을 확대한다 */
@media (pointer: coarse) { .chat-input { font-size: 16px; } }
.chat-send {
  position: relative;
  width: 44px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 12px 12px 0 12px;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 11px), calc(100% - 11px) 100%, 0 100%);
  background: linear-gradient(135deg, #ffb3cf, #e0649a 46%, #a52f66);
  color: #2b0717;
  cursor: pointer;
  transition: filter .15s;
}
.chat-send:hover { filter: brightness(1.1); }
.chat-send:active { filter: brightness(.9); }
.chat-send:focus-visible { outline: none; box-shadow: inset 0 0 0 2px #fff; }
/* 3초 제한: 보낸 뒤 어두운 막이 위에서부터 걷히며 다시 보낼 수 있을 때를 알려 준다 */
.chat-send::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(14, 7, 18, .74);
  transform: scaleY(0);
  transform-origin: 50% 100%;
}
.chat-send.is-cooling { cursor: default; }
.chat-send.is-cooling::after { animation: chat-cool var(--chat-cool, 3s) linear; }
@keyframes chat-cool { from { transform: scaleY(1); } to { transform: scaleY(0); } }

/* ── 폰 ── */
@media (max-width: 480px) {
  .chat { --chat-edge: 12px; --chat-fab: 52px; left: calc(var(--chat-edge) + env(safe-area-inset-left)); }
  .chat-panel { width: auto; align-self: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-live { animation: none; }
  .chat-send.is-cooling::after { animation: none; transform: scaleY(1); opacity: .6; }
}
