/* ---- chat panel (right side, beside the canvas) ------------------------- */

.chat-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 16px;
  width: 336px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 10;
  animation: panel-in 0.3s var(--ease);
}

@keyframes panel-in {
  from { opacity: 0; transform: translateX(12px); }
}

@media (max-width: 900px) {
  .chat-panel {
    top: 60px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    z-index: 15;
  }
}

/* tabs */

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  position: relative;
  padding: 8px 12px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}
.tab:focus-visible { outline: 2px solid #3b82f6; outline-offset: -2px; border-radius: 8px; }

.tab-count {
  margin-left: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--hover);
  font-size: 11.5px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 0 0 4px auto;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.tab-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.tab-panel[hidden] { display: none; }

/* messages */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 8px;
  overscroll-behavior: contain;
}

.msg { padding-top: 10px; }
.msg.grouped { padding-top: 2px; }
.msg:first-child { padding-top: 0; }

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 1px;
}
.msg .who {
  font-size: 13px;
  font-weight: 650;
  color: var(--c, var(--text));
}
.msg time {
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.msg .text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.notice {
  margin: 8px 0 2px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

.chat-empty {
  margin: 24px 0;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.chat-tools {
  display: flex;
  justify-content: flex-end;
  padding: 0 14px;
}
.link-btn {
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover { color: var(--danger); text-decoration: underline; }

/* composer */

.composer {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
}
.composer-row {
  display: flex;
  gap: 8px;
}
.composer input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.2);
}
.composer input[aria-invalid="true"] { border-color: var(--danger); }

.send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s var(--ease);
}
.send:hover { opacity: 0.9; }
.send:active { transform: scale(0.94); }
.send:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }
.send svg { width: 18px; height: 18px; }

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 16px;
  margin-top: 4px;
}
.chat-error {
  margin: 0;
  color: var(--danger);
  font-size: 12.5px;
}
.chat-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.chat-count.over { color: var(--danger); }

/* people */

.users-tab { overflow-y: auto; padding: 10px 8px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 6px 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}
.switch-row strong { display: block; font-size: 14px; }
.switch-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }

/* A plain checkbox styled as a switch. */
input[role="switch"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: var(--border);
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
input[role="switch"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.2s var(--ease);
}
input[role="switch"]:checked { background: #22c55e; }
input[role="switch"]:checked::after { transform: translateX(16px); }

.user-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.user { border-radius: 12px; }
.user:has(.user-actions) { background: var(--hover); }

.user-main {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
}
button.user-main { cursor: pointer; }
button.user-main:hover { background: var(--hover); }
button.user-main:focus-visible { outline: 2px solid #3b82f6; outline-offset: -2px; }

.mini-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 11px;
  font-weight: 650;
}
.user-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.user .tag.muted { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 10px 10px 46px;
}
.secondary.small {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 10px;
}

/* unread counter on the chat button */

.unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.unread[hidden] { display: none; }
#chatToggle[aria-expanded="true"] { background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--border); }

/* whispers: private messages, styled apart from the chat */

.msg.whisper {
  margin: 8px -8px 0;
  padding: 6px 8px 7px;
  border-radius: 10px;
  background: rgb(139 92 246 / 0.1);
  box-shadow: inset 3px 0 0 #8b5cf6;
}
.msg.whisper .who { color: #7c3aed; }
.msg.whisper .text { font-style: italic; }
@media (prefers-color-scheme: dark) {
  .msg.whisper { background: rgb(139 92 246 / 0.16); }
  .msg.whisper .who { color: #a78bfa; }
}

/* online list (lobby) */

.where {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.place-list {
  margin: 0;
  padding: 0 10px 6px 46px;
  list-style: none;
}
.place {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}
.place span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Clicking a whisper starts a reply. */
.msg.whisper { cursor: pointer; transition: background 0.15s; }
.msg.whisper:hover { background: rgb(139 92 246 / 0.17); }
.msg.whisper:focus-visible { outline: 2px solid #8b5cf6; outline-offset: 1px; }
@media (prefers-color-scheme: dark) {
  .msg.whisper:hover { background: rgb(139 92 246 / 0.24); }
}
