/* Room page layout + docked chat. */

/* --- Room bar: copyable code, chat jump, connection --- */
.room-code {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: 999px;
  background: #f8d633;
  color: #252046;
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: 800;
}
.room-code b { font-size: 15px; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.room-code span { font-size: 14px; opacity: .7; }
.room-code.copied, .room-code-big.copied { animation: code-copied 600ms cubic-bezier(.34, 1.56, .64, 1); }
@keyframes code-copied {
  0% { transform: scale(1); }
  35% { transform: scale(1.12) rotate(-2deg); background: #b6f06b; }
  100% { transform: scale(1); }
}
#roomConnection { display: inline-flex; align-items: center; gap: 4px; }
.room-chat-jump { position: relative; min-width: 44px; padding-inline: 10px; }
.room-chat-jump[hidden] { display: none; }
.room-chat-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  padding: 0 5px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #ec3d70;
  color: #fff;
  font-size: 11px;
  line-height: 16px;
}
.room-chat-count[hidden] { display: none; }
.chat-wiggle { animation: chat-wiggle 700ms ease-in-out; }
@keyframes chat-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg) scale(1.1); }
  40% { transform: rotate(10deg) scale(1.1); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}

/* --- Lobby: big code and player tiles --- */
.room-code-card { display: grid; justify-items: center; gap: 6px; margin: 0 0 18px; }
.room-code-card small { font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; opacity: .75; }
.room-code-card > span { font-size: 12px; opacity: .7; }
.room-code-big {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  border-radius: 14px;
  background: #252046;
  color: #f8d633;
  font: 800 clamp(22px, calc(5vw / var(--site-zoom, 1)), 34px) var(--mono, ui-monospace, monospace);
}
.room-code-big i {
  display: grid;
  place-items: center;
  width: 1.15em;
  height: 1.4em;
  border-radius: 6px;
  background: #3a3168;
  font-style: normal;
}
.room-code-big:hover i { animation: code-hop 500ms cubic-bezier(.34, 1.56, .64, 1) both; }
.room-code-big:hover i:nth-child(2) { animation-delay: 30ms; } .room-code-big:hover i:nth-child(3) { animation-delay: 60ms; }
.room-code-big:hover i:nth-child(4) { animation-delay: 90ms; } .room-code-big:hover i:nth-child(5) { animation-delay: 120ms; }
.room-code-big:hover i:nth-child(6) { animation-delay: 150ms; } .room-code-big:hover i:nth-child(7) { animation-delay: 180ms; }
.room-code-big:hover i:nth-child(8) { animation-delay: 210ms; }
@keyframes code-hop { 50% { transform: translateY(-6px); } }

.lobby-players { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin: 0 0 16px; }
.lobby-player {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 10px 6px 8px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #fffaf0;
  color: #252046;
  box-shadow: 3px 3px 0 var(--ink);
  animation: tile-pop 420ms cubic-bezier(.34, 1.56, .64, 1) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
.lobby-player b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.lobby-player em { font-style: normal; font-size: 11px; font-weight: 800; color: #7a4fc1; }
.lobby-me { background: #e9ddff; }
.lobby-avatar { display: grid; place-items: center; width: 56px; height: 56px; overflow: hidden; border-radius: 10px; border: 2px solid var(--ink); background: #c6abff; font-size: 26px; font-weight: 800; }
.lobby-avatar svg { display: block; width: 100%; height: 100%; }
.lobby-waiting { border-style: dashed; box-shadow: none; background: transparent; color: inherit; opacity: .7; }
.lobby-waiting .lobby-avatar { border-style: dashed; background: transparent; }
.dots i { font-style: normal; animation: dot-blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dot-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@keyframes tile-pop { from { opacity: 0; transform: translateY(12px) scale(.85); } to { opacity: 1; transform: none; } }

/* --- Docked chat --- */
.room-chat {
  display: flex;
  flex-direction: column;
  height: 340px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--ui-panel, #fffdf7);
  color: var(--ui-text, #252046);
  box-shadow: 4px 4px 0 var(--ink);
  text-align: left;
}
.room-chat .chat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.room-chat h3 { margin: 0; font-size: 16px; }
.room-chat .chat-head small { font-size: 11px; opacity: .7; }
.room-chat.chat-ping { animation: chat-ping 900ms ease-out; }
@keyframes chat-ping { 0% { box-shadow: 4px 4px 0 var(--ink), 0 0 0 0 #ec3d7099; } 100% { box-shadow: 4px 4px 0 var(--ink), 0 0 0 14px #ec3d7000; } }
#chatList { flex: 1; min-height: 0; margin: 8px 0 6px; padding: 0 2px; overflow-y: auto; list-style: none; overscroll-behavior: contain; scroll-behavior: smooth; }
#chatList li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 8px;
  width: fit-content;
  max-width: 88%;
  margin: 5px 0;
  padding: 6px 10px;
  border-radius: 14px 14px 14px 4px;
  background: var(--ui-inset, #fff0c1);
  overflow-wrap: anywhere;
  transform-origin: left bottom;
}
#chatList li.chat-mine { margin-left: auto; border-radius: 14px 14px 4px 14px; background: var(--ui-active, #dbcbff); transform-origin: right bottom; }
#chatList li.chat-new { animation: bubble-in 380ms cubic-bezier(.34, 1.56, .64, 1) both; }
#chatList li.chat-emoji span { font-size: 28px; line-height: 1.1; }
@keyframes bubble-in { from { opacity: 0; transform: scale(.6) translateY(8px); } to { opacity: 1; transform: none; } }
#chatList b { font-size: 12px; }
#chatList time { justify-self: end; font-size: 10px; opacity: .6; }
#chatList span { grid-column: 1 / -1; font-size: 14px; line-height: 1.35; }
#chatEmpty { flex: 1; margin: 8px 0; font-size: 13px; opacity: .75; }
#chatEmpty[hidden] { display: none; }
.chat-quick { display: flex; gap: 5px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chat-quick button { flex: none; min-height: 32px; padding: 2px 10px; border-radius: 999px; font-size: 13px; box-shadow: none; }
#chatForm { display: flex; gap: 6px; }
#chatInput { flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border-radius: 999px; font-size: 16px; }
#chatSend { flex: none; width: 44px; min-height: 44px; padding: 0; border-radius: 50%; background: #7a4fc1; color: #fff; font-size: 18px; }
#chatError { margin: 4px 0 0; color: var(--ui-negative, #a23255); font-size: 12px; }
#chatError:empty { display: none; }

/* Chat below the game until there's room for a side column. */
.room-chat-slot:empty { display: none; }
.room-chat-slot { max-width: 800px; margin: 0 auto 20px; }

@media (min-width: 1100px) {
  .room-body:has(.room-chat-slot .room-chat) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, calc(22vw / var(--site-zoom, 1)), 330px);
    gap: 18px;
    align-items: start;
  }
  .room-body .room-chat-slot { position: sticky; top: calc(var(--site-header-height, 0px) + 12px); max-width: none; margin: 0; }
  .room-body .room-chat-slot .room-chat { height: min(560px, calc(calc(100dvh / var(--site-zoom, 1)) - 190px)); }
  #roomMain .room-body .stage-card { width: 100%; max-width: none; margin-inline: 0; }
  #roomMain [data-chat-jump] { display: none; }
}

/* 13: the chat sits under the played-cards list, beside the table. */
.thirteen-workspace > .room-chat { margin-top: 8px; }
@media (min-width: 900px) {
  .thirteen-workspace > .room-chat { grid-column: 1; grid-row: 2; align-self: stretch; height: auto; min-height: 260px; margin: 0; contain: size; }
  body:has(.thirteen-workspace) #roomMain [data-chat-jump] { display: none; }
}
@media (max-width: 680px) {
  .room-chat { height: 300px; }
  .room-chat-slot { margin-bottom: 14px; }
}
@media (min-width: 900px) and (max-height: 820px) {
  .thirteen-workspace > .room-chat .chat-quick { display: none; }
}

/* Phones: the room bar fits one row (code only, link as an icon). */
@media (max-width: 680px) {
  .room-toolbar > div:first-child { display: grid; justify-items: start; gap: 2px; min-width: 0; }
  .room-code { font-size: 0; gap: 4px; padding: 2px 10px; min-height: 36px; }
  .room-code b { font-size: 14px; letter-spacing: 1px; }
  .room-code span { font-size: 13px; }
  #roomConnection { font-size: 10px !important; white-space: nowrap; }
  [data-room-action="copyLink"] { font-size: 0 !important; min-width: 40px; }
  [data-room-action="copyLink"]::before { content: '🔗'; font-size: 16px; }
  .room-toolbar > div:last-child { gap: 6px; }
}
