/* Room chat (local patch, public/js/ui/chat.js): the room screen's panel and the match's 聊天 button / panel /
   floating feed. Sizes follow the theme's rem (1rem = 1/19.2 of the 1920-wide design). */

.chat {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(8, 11, 10, .9); border: 1px solid var(--line-2); border-radius: .04rem;
  box-shadow: 0 .04rem .16rem rgba(0, 0, 0, .45);
  font-size: .17rem; color: var(--text-md);
}
.chat__head {
  display: flex; align-items: center; gap: .08rem; flex: none;
  height: .42rem; padding: 0 .06rem 0 .14rem; border-bottom: 1px solid var(--line-2);
  color: var(--mint-500); font-weight: 700; letter-spacing: .08em; font-size: .16rem;
}
.chat__head span { flex: 1; }
.chat__time {
  flex: none; color: var(--text-lo); font-size: max(.14rem, 11px); font-weight: 400; letter-spacing: normal;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chat__time:focus-visible { outline: 1px solid var(--mint-400); outline-offset: 2px; }
.chat__x {
  width: .34rem; height: .34rem; display: grid; place-items: center; color: var(--text-lo); font-size: .22rem; line-height: 1;
}
.chat__x:hover { color: var(--mint-400); }
.chat__log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0; padding: .08rem .12rem; list-style: none;
  display: flex; flex-direction: column; gap: .04rem;
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
  /* no scroll anchoring: once KEEP lines are kept, the oldest one leaving the top made the browser shift scrollTop and
     that scroll event read as the reader scrolling up, so new lines stopped following (ChatLog's stick) */
  overflow-anchor: none;
}
.chat__line { line-height: 1.35; word-break: break-word; overflow-wrap: anywhere; }
.chat__message { display: flex; justify-content: space-between; align-items: baseline; gap: .1rem; }
.chat__body { min-width: 0; }
.chat__message .chat__time { cursor: default; }
.chat__name { color: var(--text-lo); font-weight: 700; margin-right: .08rem; }
.chat__name::after { content: ':'; }
.chat__line.is-me .chat__name { color: var(--mint-500); }
.chat__text { color: var(--text-hi, #e8eeeb); user-select: text; -webkit-user-select: text; }
.chat__empty { color: var(--text-dim, var(--text-lo)); opacity: .7; margin: auto; font-size: .15rem; }
.chat__form { position: relative; display: flex; gap: .06rem; flex: none; padding: .08rem; border-top: 1px solid var(--line-2); }
.chat__input {
  flex: 1; min-width: 0; height: .44rem; padding: 0 .12rem;
  background: rgba(0, 0, 0, .45); border: 1px solid var(--line-2); border-radius: .03rem;
  color: var(--text-hi, #e8eeeb); font: inherit; font-size: max(.17rem, 16px); /* ≥ 16 px: iOS does not zoom on focus */
}
.chat__input:focus { outline: none; border-color: var(--mint-700); }
.chat__input:disabled { opacity: .5; }
.chat__send {
  flex: none; width: .5rem; height: .44rem; display: grid; place-items: center;
  background: var(--mint-a20); border: 1px solid var(--mint-700); border-radius: .03rem; color: var(--mint-400);
}
.chat__send .icon { width: .24rem; height: .24rem; }
.chat__send:disabled { opacity: .4; cursor: default; }
.chat__err {
  position: absolute; left: .08rem; bottom: calc(100% + .04rem); padding: .03rem .08rem;
  background: rgba(40, 14, 6, .92); border: 1px solid var(--orange); border-radius: .03rem; color: var(--orange-hi); font-size: .14rem;
}
.chat__badge {
  position: absolute; top: -.08rem; right: -.08rem; min-width: .24rem; height: .24rem; padding: 0 .05rem;
  display: grid; place-items: center; border-radius: .12rem; background: var(--orange); color: #fff;
  font-size: .13rem; font-weight: 700; line-height: 1; pointer-events: none;
}

/* ---- room screen: a column left of the seats (the seat cards give up the width, never overlapped) ---------------- */
.room-screen.has-chat :is(.seats, .specbar) { padding-left: 4.2rem; }
.chat--room { position: absolute; left: .3rem; top: 1.66rem; bottom: 1.74rem; z-index: 6; width: 3.7rem; }
.chat-fold {
  position: absolute; left: .3rem; bottom: 1.74rem; z-index: 6;
  display: flex; align-items: center; gap: .08rem; height: .48rem; padding: 0 .18rem;
  background: rgba(8, 11, 10, .9); border: 1px solid var(--line-2); border-radius: .04rem;
  color: var(--text-md); font-size: .17rem; font-weight: 700; letter-spacing: .08em;
}
.chat-fold:hover { color: var(--mint-400); border-color: var(--mint-700); }
.chat-fold .icon { width: .26rem; height: .26rem; color: var(--mint-500); }

/* ---- match: 聊天 button in the bottom-left corner, panel / feed above it ---------------------------------------- */
.gchat { position: relative; }
.gchat__btn {
  position: relative; width: .56rem; height: .56rem; display: grid; place-items: center;
  background: rgba(8, 11, 10, .85); border: 1px solid var(--line-2); color: var(--text-lo);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.gchat__btn .icon { width: .28rem; height: .28rem; }
.gchat__btn:hover, .gchat__btn.is-on { color: var(--mint-400); border-color: var(--mint-700); }
.chat--game {
  position: absolute; left: 0; bottom: calc(100% + .1rem); z-index: 7;
  width: 3.8rem; height: 2.7rem; animation: chat-in 140ms var(--ease-out, ease-out);
}
.gchat__feed {
  position: absolute; left: 0; bottom: calc(100% + .1rem); z-index: 6; width: 3.8rem; margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: .05rem; pointer-events: none;
}
.gchat__pop {
  align-self: flex-start; max-width: 100%; padding: .05rem .12rem; line-height: 1.35;
  background: rgba(8, 11, 10, .82); border-left: 2px solid var(--mint-600); border-radius: .03rem;
  font-size: .17rem; word-break: break-word; overflow-wrap: anywhere;
  animation: chat-pop 6000ms linear both; animation-delay: calc(-1 * var(--pop-age, 0ms));
}
/* settings 常驻最近 3 条消息: the latest lines stay, no fade-out */
.gchat__pop.is-pinned { animation: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(.08rem); } }
@keyframes chat-pop {
  0% { opacity: 0; transform: translateY(.06rem); }
  4%, 80% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

/* touch: the 聊天 button grows like ⚙ / 📖 (devices.css); the input keeps a 16 px font and a 34 px tap height, so the
   panels get px floors too — otherwise a phone's small rem leaves a big input under a two-line log */
@media (pointer: coarse), (any-pointer: coarse) {
  .gchat__btn { width: max(.56rem, 34px); height: max(.56rem, 34px); }
  .gchat__btn .icon { width: max(.28rem, 17px); height: max(.28rem, 17px); }
  .chat { font-size: max(.17rem, 13px); }
  .chat__head { height: max(.42rem, 28px); font-size: max(.16rem, 12px); }
  .chat__x { width: max(.34rem, 28px); height: max(.34rem, 28px); }
  .chat__form { padding: 5px; gap: 5px; }
  .chat__input { height: 34px; padding: 0 8px; }
  .chat__send { width: 38px; height: 34px; }
  .chat__send .icon { width: 17px; height: 17px; }
  .chat--game, .gchat__feed { width: max(3.8rem, 300px); }
  .chat--game { height: max(2.7rem, 200px); }
  .gchat__pop { font-size: max(.17rem, 13px); }
  .chat--room { width: max(3.7rem, 230px); }
  .room-screen.has-chat :is(.seats, .specbar) { padding-left: calc(max(3.7rem, 230px) + .5rem); }
}
@media (prefers-reduced-motion: reduce) {
  .chat--game { animation: none; }
  .gchat__pop { animation-name: chat-pop-still; }
  @keyframes chat-pop-still { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
}

/* briefing / draft / result screens: the 聊天 button floats bottom-left */
.gchat-float { position: fixed; left: calc(.24rem + var(--sa-l, 0px)); bottom: calc(.24rem + var(--sa-b, 0px)); z-index: 40; }

/* ---- chat faction (local patch): tag after the name, chip left of the input, picker above it ---------------- */
.chat__faction { margin-left: .04rem; font-weight: 700; }
.chat__line--sys .chat__name::after { content: ''; }
.chat__line--sys .chat__text { color: var(--text-lo); }
.chat__fac { position: relative; flex: none; display: flex; }
.chat__facbtn {
  min-width: .56rem; height: .44rem; padding: 0 .08rem; border: 1px solid var(--line-2); border-radius: .03rem;
  background: rgba(0, 0, 0, .45); color: var(--text-lo); font-size: max(.14rem, 12px); font-weight: 700; white-space: nowrap;
}
.chat__facbtn.is-set { display: grid; place-items: center; min-width: .44rem; color: var(--fac); border-color: var(--fac); }
.chat__facico {
  flex: none; display: inline-block; width: max(.24rem, 18px); height: max(.24rem, 18px);
  background: var(--fac); -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
}
.chat__facbtn:disabled { opacity: .5; }
.chat__facs {
  position: absolute; left: 0; bottom: calc(100% + .06rem); z-index: 8; width: max(3rem, 232px);
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .04rem; padding: .06rem;
  background: rgba(8, 11, 10, .96); border: 1px solid var(--line-2); border-radius: .04rem; box-shadow: 0 .04rem .16rem rgba(0, 0, 0, .5);
}
.chat__facs button {
  min-width: 0; overflow: hidden;
  display: flex; align-items: center; gap: .06rem;
  height: max(.36rem, 28px); padding: 0 .08rem; border: 1px solid transparent; border-radius: .03rem;
  background: rgba(255, 255, 255, .04); color: var(--fac); font-size: max(.15rem, 12px); font-weight: 700; text-align: left;
}
.chat__facs button:hover, .chat__facs button.is-on { background: rgba(255, 255, 255, .1); border-color: var(--fac); }
/* a faction whose bond is off this match (m.public.disabledBonds) */
.chat__facs button.is-off { opacity: .45; }
.chat__facs button span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__facs button .chat__facico { flex: none; }
.chat__facs button small { flex: none; margin-left: auto; padding: 0 .03rem; font-size: max(.11rem, 10px); line-height: 1.3; white-space: nowrap; color: var(--text-lo); border: 1px solid var(--line-2); border-radius: .02rem; }
/* 진영별 선발 프리셋 (ui/diyPresets.js): 「…预设已套用 · 撤销」 above the input, for a few seconds after a faction pick */
.chat__preset {
  position: absolute; left: .08rem; right: .08rem; bottom: calc(100% + .04rem); z-index: 7; margin: 0;
  display: flex; align-items: center; gap: .06rem; padding: .04rem .08rem;
  background: rgba(8, 11, 10, .94); border: 1px solid var(--mint-700); border-radius: .03rem; color: var(--text-hi, #e8f0ee);
  font-size: max(.14rem, 12px);
}
.chat__preset > span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* the strategy draft's faction row (ui/factionPick.js DraftFactionPicker): in the flow, under the chips */
.chat__preset--inline { position: static; flex-wrap: wrap; font-size: max(.13rem, 11px); }
.chat__preset--inline > span { flex: 1 1 1.6rem; }
.chat__preset--inline .chat__preset-undo { margin-left: auto; }
@media (max-width: 900px), (max-height: 500px) { .chat__preset--inline .chat__facico { display: none; } }
.chat__preset small { color: var(--text-lo); font-size: max(.12rem, 10px); }
/* a faction whose bond this match disables is still applied (maintainer 2026-10-12): 本局禁用, dashed like the draft's tag */
.chat__preset.is-off { border-style: dashed; }
.chat__preset .chat__preset-off { color: var(--text-dim); }
.chat__preset-undo {
  flex: none; padding: .02rem .1rem; border: 1px solid var(--mint-700); border-radius: .03rem;
  background: var(--mint-a20); color: var(--mint-400); font-weight: 700; font-size: max(.14rem, 12px);
}
.chat__preset-close {
  flex: none; min-width: max(.28rem, 24px); align-self: stretch; padding: 0; border: 0; background: none;
  color: var(--text-lo); font-size: max(.18rem, 15px); line-height: 1;
}
.chat__preset-close:hover { color: var(--text-hi, #e8f0ee); }

/* faction avatar (ui/faction.js FactionGlyph): the tinted nation icon, the name's first letter small under it; sized
   from its avatar box (--av: room seat card AvatarFrame, --pa: PlayerAvatar in the team panel / draft / result) */
.avatar .fglyph { --fg: var(--av); }
.pavatar .fglyph { --fg: var(--pa); }
.fglyph {
  --fg: 1rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--fg) * .02);
}
.fglyph__ico {
  flex: none; width: calc(var(--fg) * .6); height: calc(var(--fg) * .6); background: var(--fac);
  -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
  filter: drop-shadow(0 0 calc(var(--fg) * .04) rgba(0, 0, 0, .55));
}
.fglyph__ch { font-size: calc(var(--fg) * .2); font-weight: 900; line-height: 1; color: var(--text-hi, #f2f2f2); opacity: .9; }

@media (pointer: coarse), (any-pointer: coarse) {
  /* as tall as the 34 px touch input (the faction rules above come after the touch block) */
  .chat__facbtn, .chat__facbtn.is-set { height: 34px; min-width: 34px; }
}

/* faction badge on a strategy icon (PlayerAvatar): bottom-right corner, over the icon */
.pavatar__fac {
  position: absolute; right: calc(var(--pa) * -.08); bottom: calc(var(--pa) * -.08); z-index: 1;
  width: calc(var(--pa) * .4); height: calc(var(--pa) * .4); min-width: 12px; min-height: 12px;
  display: grid; place-items: center; background: rgba(8, 11, 10, .92); border: 1px solid var(--line-2); border-radius: 22%;
}
.pavatar__facico {
  width: 78%; height: 78%; background: var(--fac);
  -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
}
.chat__spec { margin-left: .04rem; font-weight: 400; color: var(--text-lo); }

/* blocking (ui/chat.js 「Blocking」): another player's line opens its block button on a press — the whole line is the
   target, for touch; the notice line only this player sees (「Notice」) */
.chat__line.is-pressable { cursor: pointer; border-radius: .03rem; }
.chat__line.is-pressable:hover { background: rgba(255, 255, 255, .04); }
.chat__line.is-menu { background: rgba(255, 255, 255, .08); outline: 1px solid var(--line-2); }
.chat__menu { display: flex; padding: .04rem 0 .02rem; }
.chat__block {
  min-height: max(.36rem, 32px); padding: 0 .14rem; border: 1px solid var(--orange); border-radius: .03rem;
  background: rgba(40, 14, 6, .92); color: var(--orange-hi); font-size: max(.15rem, 12px); font-weight: 700; white-space: nowrap;
}
.chat__blocked { display: flex; flex-wrap: wrap; align-items: baseline; gap: .08rem; }
.chat__blocked .chat__text { color: var(--text-lo); font-size: max(.13rem, 11px); }
.chat__unblock {
  padding: .02rem .04rem; min-height: max(.28rem, 24px); color: var(--mint-400); font-weight: 700; font-size: max(.13rem, 11px);
  background: none; border: 0;
}
.chat__notice { display: flex; gap: .06rem; color: var(--text-lo); font-size: max(.13rem, 11px); line-height: 1.35; }
.chat__notice::before { content: 'ⓘ'; flex: none; color: var(--mint-500); }
