/* PixelPals Chat — warm cream indie-game aesthetic */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #FDF6E3;
  --bg-warm: #F5EACC;
  --surface: #FFF8EC;
  --border: #E8D0A0;
  --accent: #C86420;
  --accent-light: #F08040;
  --text: #3A2010;
  --text-muted: #8A6030;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  height: 100vh;
  overflow: hidden;
  line-height: 1.6;
}
.pixel-font { font-family: 'Press Start 2P', monospace; }

/* Nav */
.chat-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border-bottom: 3px solid var(--border);
}
.nav-logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px; color: var(--accent);
  text-decoration: none; letter-spacing: 1px;
}
.nav-logo-dot {
  display: inline-block; width: 6px; height: 6px;
  background: var(--accent-light);
  margin-left: 3px; vertical-align: middle;
}
.nav-right { display: flex; align-items: center; gap: 16px; }
.online-badge {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4CAF50; animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.5; }
}
.nav-link {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-decoration: none;
}
.nav-link:hover { color: var(--accent); }

/* Lobby */
.lobby {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh;
  padding: 80px 24px 40px;
}
.lobby-card {
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 520px; width: 100%;
  box-shadow: 0 4px 20px rgba(180,120,40,0.06);
}
.lobby-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px; color: var(--accent);
  text-align: center; line-height: 2;
  margin-bottom: 8px;
}
.lobby-sub {
  text-align: center; font-size: 14px;
  color: var(--text-muted); font-weight: 600;
  margin-bottom: 28px;
}
.lobby-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px; color: var(--accent);
  letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 16px;
}
.avatar-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 12px; margin-bottom: 24px;
}
@media (max-width: 480px) {
  .avatar-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}
.avatar-pick {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; cursor: pointer; padding: 10px 6px;
  border-radius: 10px; border: 3px solid transparent;
  transition: all 0.2s; background: var(--bg);
}
.avatar-pick:hover { border-color: var(--accent-light); transform: translateY(-2px); }
.avatar-pick.selected {
  border-color: var(--accent); background: #FDE8C8;
  box-shadow: 0 3px 10px rgba(200,100,32,0.15);
}
.avatar-pick img {
  width: 48px; height: 48px;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.avatar-pick-label {
  font-size: 9px; font-weight: 800;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px;
}
.avatar-pick.selected .avatar-pick-label { color: var(--accent); }

.name-section { margin-top: 8px; }
.name-row { display: flex; gap: 10px; margin-top: 12px; }
@media (max-width: 480px) {
  .name-row { flex-direction: column; }
}
.name-input {
  flex: 1; padding: 14px 18px;
  font-family: 'Nunito', sans-serif;
  font-size: 15px; font-weight: 600;
  border: 3px solid var(--border);
  border-radius: 10px; background: var(--bg);
  color: var(--text); outline: none;
  transition: border-color 0.2s;
}
.name-input:focus { border-color: var(--accent); }
.name-input::placeholder { color: #C0A070; }
.join-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px; padding: 16px 24px;
  background: var(--accent); color: white;
  border: none; border-radius: 10px;
  cursor: pointer; letter-spacing: 1px;
  transition: all 0.2s; white-space: nowrap;
  box-shadow: 3px 3px 0 var(--accent-light);
}
.join-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--accent-light);
}
.join-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Chat room */
.chat-room {
  display: none; flex-direction: column;
  height: 100vh; padding-top: 52px;
}
.chat-room.active { display: flex; }
.room-header {
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.room-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px; color: var(--text);
}
.room-desc {
  font-size: 12px; color: var(--text-muted); font-weight: 600;
}

/* Messages */
.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 24px;
  display: flex; flex-direction: column; gap: 2px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 3px;
}
.msg {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px 10px; border-radius: 8px;
  transition: background 0.1s;
}
.msg:hover { background: rgba(200,160,80,0.06); }
.msg-avatar {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);
}
.msg-avatar img {
  width: 100%; height: 100%;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.msg-body { flex: 1; min-width: 0; }
.msg-meta {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 2px;
}
.msg-name { font-weight: 800; font-size: 13px; color: var(--text); }
.msg-time { font-size: 10px; color: var(--text-muted); font-weight: 600; }
.msg-text {
  font-size: 14px; line-height: 1.6; font-weight: 600;
  color: var(--text); word-wrap: break-word;
  white-space: pre-wrap;
}
.system-msg {
  text-align: center; font-size: 12px;
  color: var(--text-muted); font-weight: 700;
  padding: 8px; font-style: italic;
}

/* Input */
.chat-input-area {
  padding: 12px 24px 20px;
  background: var(--surface);
  border-top: 2px solid var(--border);
  flex-shrink: 0;
}
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-textarea {
  flex: 1; padding: 12px 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px; font-weight: 600;
  border: 3px solid var(--border);
  border-radius: 10px; background: var(--bg);
  color: var(--text); outline: none; resize: none;
  max-height: 100px; min-height: 44px;
  line-height: 1.5;
  transition: border-color 0.2s;
}
.chat-textarea:focus { border-color: var(--accent); }
.chat-textarea::placeholder { color: #C0A070; }
.send-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px; padding: 14px 20px;
  background: var(--accent); color: white;
  border: none; border-radius: 10px;
  cursor: pointer; letter-spacing: 1px;
  transition: all 0.2s; white-space: nowrap;
  box-shadow: 3px 3px 0 var(--accent-light);
  flex-shrink: 0;
}
.send-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--accent-light);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Attach button */
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 44px;
  border: 3px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
}
.attach-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #FDE8C8;
}
.attach-btn svg { display: block; }

/* Upload queue */
.upload-queue {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0 4px;
  min-height: 0;
}
.queue-item {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 80px;
}
.queue-thumb {
  width: 68px;
  height: 52px;
  object-fit: cover;
  border-radius: 4px;
  image-rendering: pixelated;
  border: 1px solid var(--border);
}
.queue-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  max-width: 68px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.queue-progress {
  width: 68px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.queue-progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}
.queue-done {
  font-size: 12px;
  color: #4CAF50;
  font-weight: 700;
}
.queue-error {
  font-size: 9px;
  color: #C02020;
  font-weight: 700;
}
.queue-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 50%;
  font-size: 9px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.15s;
}
.queue-remove:hover { background: #FFE8E8; border-color: #C02020; color: #C02020; }

/* Upload progress bar */
.upload-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s;
  width: 0%;
}

.rate-warn {
  font-size: 11px; color: #C02020;
  text-align: center; margin-top: 6px;
  min-height: 18px; font-weight: 600;
}

/* My identity badge (fixed position, kept at top of file) */
.my-identity {
  position: fixed; bottom: 16px; left: 16px;
  display: none; align-items: center; gap: 8px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 10px; padding: 6px 10px;
  box-shadow: 0 2px 8px rgba(180,120,40,0.08);
  z-index: 50;
}
.my-identity.active { display: flex; }
.my-identity img {
  width: 28px; height: 28px;
  border-radius: 50%;
  image-rendering: pixelated;
  border: 1.5px solid var(--border);
}
.my-identity-name {
  font-size: 11px; font-weight: 800;
  color: var(--text);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.change-pal-btn {
  background: none; border: none; cursor: pointer;
  font-size: 12px; color: var(--text-muted);
  padding: 2px 4px; border-radius: 8px;
  transition: background 0.15s, color 0.15s; line-height: 1;
}
.change-pal-btn:hover { background: var(--border); color: var(--accent); }

/* Reactions */
.msg {
  position: relative;
}
.msg-reaction-trigger {
  position: absolute;
  top: 4px; right: 4px;
  width: 24px; height: 24px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}
.msg:hover .msg-reaction-trigger {
  opacity: 1;
}
.msg:hover .msg-reaction-trigger::after {
  content: '+';
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 12px; font-weight: 800; color: var(--text-muted);
}
.reaction-bar {
  position: absolute;
  top: -40px; right: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  gap: 2px;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(60,30,10,0.12);
  flex-wrap: wrap;
  max-width: 200px;
}
.reaction-btn {
  background: none; border: none; padding: 2px;
  cursor: pointer; border-radius: 6px;
  transition: background 0.15s, transform 0.1s;
  display: flex; align-items: center;
  image-rendering: pixelated;
}
.reaction-btn:hover {
  background: var(--bg-warm);
  transform: scale(1.25);
}
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.reaction-badge {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 1px 6px 1px 2px;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  cursor: default; line-height: 1.4;
}
.reaction-badge.mine {
  background: #FDE8C8;
  border-color: var(--accent);
  color: var(--accent);
}
.reaction-badge img {
  image-rendering: pixelated; width: 16px; height: 16px;
}
.reaction-count { font-size: 10px; }

/* Sidebar */
.rooms-sidebar {
  position: fixed; top: 52px; left: 0; bottom: 0;
  width: 180px;
  background: var(--surface);
  border-right: 2px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  z-index: 40;
  display: none;
}
.rooms-sidebar.active { display: block; }
.sidebar-section { margin-bottom: 20px; }
.sidebar-heading {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; color: var(--accent);
  letter-spacing: 1px; text-transform: uppercase;
  padding: 0 16px 8px;
}
.room-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 16px; cursor: pointer;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s;
  border-radius: 0;
  text-decoration: none;
}
.room-item:hover { background: var(--bg-warm); color: var(--text); }
.room-item.active { background: #FDE8C8; color: var(--accent); }
.room-item-hash { font-family: 'Press Start 2P', monospace; font-size: 8px; }
.room-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-create-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; cursor: pointer;
  font-size: 11px; font-weight: 800;
  color: var(--accent);
  transition: all 0.15s;
}
.sidebar-create-btn:hover { color: var(--accent-light); }
.sidebar-plus { font-size: 14px; font-weight: 700; }

/* Room header layout */
.room-header-left { flex: 1; }
.room-header-right { flex-shrink: 0; display: flex; align-items: center; gap: 8px; }

/* DM sidebar items */
.dm-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; cursor: pointer;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s;
}
.dm-item:hover { background: var(--bg-warm); color: var(--text); }
.dm-item.active { background: #FDE8C8; color: var(--accent); }
.dm-item-avatar {
  width: 28px; height: 28px; border-radius: 6px; overflow: hidden;
  border: 2px solid var(--border); flex-shrink: 0;
  image-rendering: pixelated;
}
.dm-item-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.dm-item-info { flex: 1; min-width: 0; }
.dm-item-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'Press Start 2P', monospace; font-size: 7px; color: inherit;
}
.dm-item-preview {
  font-size: 10px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
.dm-unread-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  animation: pulse 2s infinite;
}

/* DM Panel */
#dmPanel {
  position: fixed; top: 52px; right: 0; bottom: 0;
  width: 340px; background: var(--surface);
  border-left: 2px solid var(--border);
  display: none; flex-direction: column;
  z-index: 80; box-shadow: -4px 0 16px rgba(60,30,10,0.08);
}
#dmPanel.active { display: flex; }
.dm-panel-header {
  padding: 12px 16px; border-bottom: 2px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; background: var(--surface);
  position: relative;
}
.dm-back-btn {
  background: none; border: 2px solid var(--border); border-radius: 8px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px;
  color: var(--text-muted); flex-shrink: 0; transition: all 0.15s;
}
.dm-back-btn:hover { background: var(--bg-warm); color: var(--text); }
#dmPanelAvatar {
  width: 32px; height: 32px; border-radius: 8px; overflow: hidden;
  border: 2px solid var(--border); image-rendering: pixelated; flex-shrink: 0;
}
.dm-panel-name {
  font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--text);
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dm-messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.dm-messages::-webkit-scrollbar { width: 6px; }
.dm-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.dm-input-area {
  padding: 10px 16px 16px;
  border-top: 2px solid var(--border); flex-shrink: 0;
}

/* DM messages — smaller, right-aligned for self */
.dm-msg {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 6px 8px; border-radius: 8px; transition: background 0.1s;
}
.dm-msg:hover { background: rgba(200,160,80,0.06); }
.dm-msg.mine { flex-direction: row-reverse; }
.dm-msg-avatar { width: 32px; height: 32px; flex-shrink: 0; border-radius: 6px; overflow: hidden; border: 1.5px solid var(--border); image-rendering: pixelated; }
.dm-msg-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.dm-msg-body { max-width: 72%; min-width: 0; }
.dm-msg-meta { display: flex; align-items: baseline; gap: 6px; margin-bottom: 2px; }
.dm-msg-name { font-weight: 800; font-size: 11px; color: var(--text); }
.dm-msg-time { font-size: 9px; color: var(--text-muted); font-weight: 600; }
.dm-msg.mine .dm-msg-meta { flex-direction: row-reverse; }
.dm-msg-text { font-size: 13px; line-height: 1.5; font-weight: 600; color: var(--text); word-wrap: break-word; white-space: pre-wrap; }
.dm-msg.mine .dm-msg-text { text-align: right; }
.dm-reactions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.dm-system-msg { text-align: center; font-size: 11px; color: var(--text-muted); font-weight: 700; padding: 6px; font-style: italic; }

/* DM sidebar heading separator */
#dmThreadList { min-height: 4px; }

/* Invite pill */
.invite-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; letter-spacing: 0.5px;
  background: var(--accent); color: white;
  border: none; border-radius: 20px;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 2px 2px 0 var(--accent-light);
  white-space: nowrap;
}
.invite-pill:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--accent-light);
}
.invite-icon { font-size: 12px; }

/* Create Room Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(60,30,10,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 360px; max-width: 90vw;
  box-shadow: 0 8px 32px rgba(60,30,10,0.15);
}
.modal-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px; color: var(--accent);
  text-align: center; margin-bottom: 24px;
  letter-spacing: 1px; line-height: 1.8;
}
.modal-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; color: var(--accent);
  letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 10px;
}
.modal-input {
  width: 100%; padding: 12px 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 15px; font-weight: 600;
  border: 3px solid var(--border);
  border-radius: 10px; background: var(--bg);
  color: var(--text); outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-hint {
  font-size: 11px; color: var(--text-muted);
  margin-top: 8px; font-weight: 600;
  min-height: 16px;
}
.modal-actions {
  display: flex; gap: 10px; margin-top: 20px;
}
.modal-cancel {
  flex: 1; padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px; letter-spacing: 0.5px;
  background: var(--bg-warm); color: var(--text-muted);
  border: 2px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: all 0.2s;
}
.modal-cancel:hover { background: var(--border); color: var(--text); }
.modal-create {
  flex: 1; padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px; letter-spacing: 0.5px;
  background: var(--accent); color: white;
  border: none; border-radius: 10px;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 3px 3px 0 var(--accent-light);
}
.modal-create:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--accent-light);
}
.modal-create:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.modal-error {
  font-size: 11px; color: #C02020;
  text-align: center; margin-top: 10px;
  font-weight: 600;
}

/* Typing strip */
.typing-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 6px 0;
  min-height: 28px;
  transition: opacity 0.3s;
}
.typing-avatars {
  display: flex;
  align-items: center;
}
.typing-avatar {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  margin-left: -6px;
  image-rendering: pixelated;
  animation: typing-bounce 0.8s ease-in-out infinite alternate;
  background: var(--bg);
}
.typing-avatar:first-child { margin-left: 0; }
@keyframes typing-bounce {
  from { transform: translateY(1px); }
  to { transform: translateY(-1px); }
}
.typing-avatar img {
  width: 100%; height: 100%;
  image-rendering: pixelated;
}
.typing-text {
  font-family: 'VT323', monospace;
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* Speaker / sound toggle button */
.speaker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-muted);
  padding: 0;
}
.speaker-btn:hover {
  background: var(--bg-warm);
  border-color: var(--accent);
  color: var(--accent);
}
.speaker-btn.muted {
  color: var(--text-muted);
  opacity: 0.7;
}
.speaker-icon { display: block; }
.speaker-off { display: none; }
.speaker-btn.muted .speaker-on { display: none; }
.speaker-btn.muted .speaker-off { display: block; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  font-size: 11px; font-weight: 700;
  padding: 10px 20px;
  border-radius: 20px;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(60,30,10,0.2);
  transition: opacity 0.3s;
}

/* Mention highlight */
.msg.mentioned {
  border-left: 3px solid #F5C9A1;
  background: rgba(245, 201, 161, 0.12);
}
.mention-chip {
  display: inline;
  background: rgba(245, 201, 161, 0.35);
  color: #9A5010;
  border-radius: 4px;
  padding: 0 4px;
  font-weight: 800;
  cursor: default;
}

/* Mention autocomplete dropdown */
.mention-dropdown {
  position: relative;
  margin-bottom: 6px;
  margin-left: 24px;
  margin-right: 24px;
}
.mention-dropdown-inner {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(60,30,10,0.12);
  z-index: 60;
  max-height: 200px;
  overflow-y: auto;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.mention-item:hover,
.mention-item.selected {
  background: rgba(245, 201, 161, 0.25);
}
.mention-item img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.mention-item-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--text);
  letter-spacing: 0.5px;
}
.mention-empty {
  padding: 10px 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
}

@media (max-width: 600px) {
  .messages { padding: 12px 16px; }
  .chat-input-area { padding: 10px 16px 16px; }
  .lobby-card { padding: 28px 20px; }
  .my-identity { display: none !important; }
  .rooms-sidebar { display: none !important; }
  .mention-dropdown { margin-left: 0; margin-right: 0; }
  .mention-dropdown-inner { left: 0; right: 0; max-height: 180px; }
}

/* ── Image Attachments ───────────────────────────────────────────────────── */

.attachments {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.att-single { flex-direction: column; }
.att-double { flex-direction: row; }
.att-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 6px;
}
.att-item {
  border-radius: 6px;
  overflow: hidden;
  border: 4px solid var(--border);
  box-shadow: 1px 1px 0 var(--text);
  background: var(--bg);
  line-height: 0;
}
.att-img {
  display: block;
  max-width: 360px;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}
.att-grid .att-item:first-child:nth-last-child(3),
.att-grid .att-item:first-child:nth-last-child(3) ~ .att-item:nth-child(3) {
  grid-column: 1 / -1;
}
.att-grid .att-item:first-child:nth-last-child(4) {
  grid-column: auto;
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 20, 5, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.lightbox-inner {
  background: var(--surface);
  border: 4px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(40,20,5,0.3);
  max-width: 800px;
  max-height: 90vh;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.lightbox-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}
.lightbox-header img {
  border-radius: 6px;
  border: 2px solid var(--border);
  image-rendering: pixelated;
  flex-shrink: 0;
}
.lightbox-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text);
  flex: 1;
}
.lightbox-close {
  background: none;
  border: 2px solid var(--border);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.lightbox-close:hover { background: var(--bg-warm); color: var(--text); }
.lightbox-img {
  display: block;
  width: 100%;
  max-height: calc(90vh - 80px);
  object-fit: contain;
  background: #1a1a2e;
  image-rendering: pixelated;
}
.lightbox-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.lightbox-filename {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  font-family: 'VT323', monospace;
}

/* ── Thread Panel ────────────────────────────────────────────────────────── */

.thread-panel {
  position: fixed;
  top: 52px; right: 0; bottom: 0;
  width: 360px;
  background: #f4e4c1;
  border-left: 2px solid #8b6f47;
  display: none; flex-direction: column;
  z-index: 80;
  box-shadow: -4px 0 16px rgba(60,30,10,0.08);
  animation: slideInRight 0.2s ease-out;
}
.thread-panel.open { display: flex; }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0.8; }
  to { transform: translateX(0); opacity: 1; }
}
.thread-panel-header {
  padding: 12px 16px;
  border-bottom: 2px solid #8b6f47;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  background: #fff8ec;
}
.thread-close-btn {
  background: none; border: 2px solid #c4a060; border-radius: 8px;
  width: 26px; height: 26px; cursor: pointer; font-size: 11px;
  color: #8a6030; flex-shrink: 0; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.thread-close-btn:hover { background: #f0eacc; border-color: #8b6f47; }
.thread-panel-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px; color: #c86420;
  letter-spacing: 1px; flex: 1;
}

/* Parent message (darker bg) */
.thread-parent {
  background: #e8d4a8;
  border-bottom: 2px solid #c4a060;
  padding: 14px 16px;
  flex-shrink: 0;
}
.thread-parent .tp-msg-avatar {
  width: 36px; height: 36px; border-radius: 8px; overflow: hidden;
  border: 2px solid #c4a060; flex-shrink: 0; image-rendering: pixelated;
}
.thread-parent .tp-msg-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.thread-parent .tp-msg-body { flex: 1; min-width: 0; }
.thread-parent .tp-msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.thread-parent .tp-msg-name { font-weight: 800; font-size: 13px; color: #3a2010; }
.thread-parent .tp-msg-time { font-size: 10px; color: #8a6030; font-weight: 600; }
.thread-parent .tp-msg-text { font-size: 14px; line-height: 1.5; font-weight: 600; color: #3a2010; word-wrap: break-word; }
.thread-parent .tp-deleted { font-style: italic; color: #8a6030; }

/* Replies area */
.thread-replies {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.thread-replies::-webkit-scrollbar { width: 5px; }
.thread-replies::-webkit-scrollbar-track { background: transparent; }
.thread-replies::-webkit-scrollbar-thumb { background: #c4a060; border-radius: 3px; }

.tr-msg {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 6px 8px; border-radius: 8px;
  transition: background 0.1s;
}
.tr-msg:hover { background: rgba(200,160,80,0.08); }
.tr-msg-avatar { width: 32px; height: 32px; border-radius: 6px; overflow: hidden; border: 1.5px solid #c4a060; flex-shrink: 0; image-rendering: pixelated; }
.tr-msg-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.tr-msg-body { flex: 1; min-width: 0; }
.tr-msg-meta { display: flex; align-items: baseline; gap: 6px; margin-bottom: 2px; }
.tr-msg-name { font-weight: 800; font-size: 12px; color: #3a2010; }
.tr-msg-time { font-size: 9px; color: #8a6030; font-weight: 600; }
.tr-msg-text { font-size: 13px; line-height: 1.5; font-weight: 600; color: #3a2010; word-wrap: break-word; white-space: pre-wrap; }
.tr-deleted { font-style: italic; color: #8a6030; font-size: 12px; }
.tr-empty {
  text-align: center; font-size: 12px; color: #8a6030;
  font-weight: 700; padding: 24px; font-style: italic;
}

/* Thread input area */
.thread-input-area {
  padding: 10px 16px 16px;
  border-top: 2px solid #8b6f47;
  background: #fff8ec;
  flex-shrink: 0;
}
.thread-textarea {
  font-size: 13px;
  min-height: 40px;
}

/* Thread reply pill on parent message in main feed */
.thread-pill {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px; padding: 3px 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; color: #c86420;
  background: rgba(200,100,32,0.1);
  border: 1.5px solid rgba(200,100,32,0.3);
  border-radius: 20px; cursor: pointer;
  transition: all 0.15s; white-space: nowrap;
}
.thread-pill:hover {
  background: rgba(200,100,32,0.2);
  border-color: #c86420;
}
.thread-pill-icon { font-size: 10px; }

/* Thread button on message hover */
.msg-thread-btn {
  position: absolute;
  top: 4px; right: 28px;
  width: 24px; height: 24px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.msg:hover .msg-thread-btn { opacity: 1; }
.msg-thread-btn::after {
  content: '\uD83D\uDCAC';
  font-size: 13px;
  width: 22px; height: 22px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}

/* Thread message in main feed (reply posted) */
.msg.has-thread .msg-reactions {
  border-top: 1px dashed var(--border);
  padding-top: 4px;
  margin-top: 6px;
}

/* Thread reply in DM panel */
.thread-reply-in-dm {
  display: flex; gap: 6px; align-items: flex-start;
  padding: 4px 8px; border-radius: 6px;
  border-left: 2px solid #c4a060;
  margin-left: 20px; margin-top: 2px;
  transition: background 0.1s;
}
.thread-reply-in-dm:hover { background: rgba(200,160,80,0.06); }
.thread-reply-in-dm .trd-avatar { width: 28px; height: 28px; border-radius: 6px; overflow: hidden; border: 1.5px solid #c4a060; flex-shrink: 0; image-rendering: pixelated; }
.thread-reply-in-dm .trd-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.thread-reply-in-dm .trd-body { flex: 1; min-width: 0; }
.thread-reply-in-dm .trd-meta { display: flex; align-items: baseline; gap: 6px; margin-bottom: 1px; }
.thread-reply-in-dm .trd-name { font-weight: 800; font-size: 11px; color: #3a2010; }
.thread-reply-in-dm .trd-time { font-size: 9px; color: #8a6030; font-weight: 600; }
.thread-reply-in-dm .trd-text { font-size: 12px; line-height: 1.5; font-weight: 600; color: #3a2010; word-wrap: break-word; }
.thread-reply-in-dm .trd-deleted { font-style: italic; color: #8a6030; font-size: 11px; }

/* Mobile: full screen thread panel */
@media (max-width: 600px) {
  .thread-panel {
    width: 100%;
    top: 0;
  }
  .thread-panel-header { padding-top: 16px; }
}

/* ── Emoji Picker Popup (CRT-styled) ── */
.emoji-picker-popup {
  position: absolute;
  z-index: 200;
  width: 220px;
  background: #e8d4a8;
  border: 3px solid #5a4a35;
  border-radius: 12px;
  box-shadow: 4px 4px 0 #3a2010, inset 0 0 0 1px rgba(58,32,16,0.12);
  overflow: hidden;
  display: none;
}
.emoji-picker-popup.open { display: block; }

/* CRT scanline overlay */
.emoji-picker-popup::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(58, 32, 16, 0.04) 3px,
    rgba(58, 32, 16, 0.04) 4px
  );
  pointer-events: none;
  border-radius: 9px;
}

.emoji-picker-inner {
  position: relative;
  z-index: 1;
  padding: 8px;
}

.emoji-picker-search-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #d4b88a;
  border-bottom: 2px solid #c8a870;
  margin-bottom: 6px;
}

.emoji-search-icon { flex-shrink: 0; color: #8a6030; }

.emoji-picker-search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: #3a2010;
  caret-color: #c86420;
}
.emoji-picker-search::placeholder { color: #a08050; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c8a870 #e8d4a8;
}
.emoji-grid::-webkit-scrollbar { width: 5px; }
.emoji-grid::-webkit-scrollbar-track { background: #e8d4a8; }
.emoji-grid::-webkit-scrollbar-thumb { background: #c8a870; border-radius: 3px; }

.emoji-btn {
  background: none;
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  image-rendering: pixelated;
}
.emoji-btn:hover {
  background: rgba(58,32,16,0.12);
  border-color: #8a6030;
  transform: scale(1.2);
}
.emoji-btn.hidden { display: none; }
.emoji-btn img {
  image-rendering: pixelated;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* Reaction badge tooltip */
.reaction-badge {
  position: relative;
}
.reaction-badge:hover .reaction-tooltip {
  display: block;
}
.reaction-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #3a2010;
  color: #FDF6E3;
  font-size: 10px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 50;
  font-family: 'Nunito', sans-serif;
  box-shadow: 0 2px 8px rgba(60,30,10,0.2);
}
.reaction-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #3a2010;
}

/* Bounce animation for new reactions */
@keyframes reaction-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}
.reaction-badge.bounce {
  animation: reaction-bounce 0.3s ease-out;
}

/* DM reaction picker trigger */
.dm-msg .msg-reaction-trigger {
  top: 2px; right: 2px;
}
.dm-msg:hover .msg-reaction-trigger { opacity: 1; }

/* ── Search Palette (Cmd/Ctrl+K) ── */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 32, 16, 0.55);
  z-index: 900;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

.search-palette {
  width: 600px;
  max-width: 95vw;
  background: #e8d4a8;
  border: 3px solid #5a4a35;
  box-shadow: 6px 6px 0 #3a2010, inset 0 0 0 1px rgba(58,32,16,0.15);
  position: relative;
  overflow: hidden;
}

/* CRT scanline overlay */
.search-palette::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(58, 32, 16, 0.04) 3px,
    rgba(58, 32, 16, 0.04) 4px
  );
  pointer-events: none;
}

.search-palette-inner {
  position: relative;
  z-index: 1;
}

/* Filter chips */
.search-filters {
  display: flex;
  gap: 6px;
  padding: 12px 16px 0;
  flex-wrap: wrap;
}

.search-chip {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #3a2010;
  background: #d4b88a;
  border: 2px solid #8a6030;
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.search-chip:hover,
.search-chip.active {
  background: #c8a870;
  border-color: #5a4a35;
}
.search-chip.active {
  background: #5a4a35;
  color: #e8d4a8;
}

/* Input row */
.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 2px solid #c8a870;
  margin-top: 10px;
}

.search-icon {
  flex-shrink: 0;
  color: #8a6030;
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: #3a2010;
  caret-color: #c86420;
  letter-spacing: 0.5px;
}
.search-input::placeholder {
  color: #a08050;
}

/* Blinking VT323 cursor effect via animation */
@keyframes blink-cursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.search-input:focus {
  animation: none;
}

/* ESC badge */
.search-esc-hint {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #8a6030;
  background: #d4b88a;
  border: 1.5px solid #8a6030;
  border-radius: 3px;
  padding: 3px 6px;
  flex-shrink: 0;
}

/* Results list */
.search-results {
  max-height: 380px;
  overflow-y: auto;
  border-top: 1px solid #c8a870;
  scrollbar-width: thin;
  scrollbar-color: #c8a870 #e8d4a8;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: #e8d4a8; }
.search-results::-webkit-scrollbar-thumb { background: #c8a870; border-radius: 3px; }

.search-result-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(200, 160, 80, 0.25);
  transition: background 0.1s;
}
.search-result-row:hover,
.search-result-row.selected {
  background: rgba(58, 32, 16, 0.07);
}
.search-result-row:last-child { border-bottom: none; }

.search-result-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid #c8a870;
  image-rendering: pixelated;
  background: #d4b88a;
}
.search-result-avatar img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.search-result-body { flex: 1; min-width: 0; }

.search-result-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.search-result-name {
  font-weight: 800;
  font-size: 13px;
  color: #3a2010;
}
.search-result-room {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: #8a6030;
  font-weight: 400;
}
.search-result-time {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: #a08050;
  font-weight: 400;
}
.search-result-snippet {
  font-size: 12px;
  line-height: 1.5;
  color: #5a4030;
  word-wrap: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-snippet mark {
  background: #d4a017;
  color: #3a2010;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 700;
}

/* Empty states */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  gap: 12px;
  color: #8a6030;
}
.search-empty-icon {
  opacity: 0.5;
}
.search-empty-text {
  font-family: 'VT323', monospace;
  font-size: 16px;
  text-align: center;
}
.search-empty-sub {
  font-size: 12px;
  color: #a08050;
  text-align: center;
}

/* Recent searches */
.search-recent-label {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: #8a6030;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 16px 4px;
}
.search-recent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 15px;
  color: #5a4030;
  transition: background 0.1s;
}
.search-recent-item:hover { background: rgba(58,32,16,0.06); }
.search-recent-item svg { color: #8a6030; flex-shrink: 0; }

/* Loading */
.search-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #8a6030;
  font-family: 'VT323', monospace;
  font-size: 15px;
  gap: 10px;
}
.search-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #c8a870;
  border-top-color: #c86420;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Message highlight pulse (when jumping to a result) */
@keyframes result-pulse {
  0%, 100% { background: transparent; }
  30% { background: rgba(212, 160, 23, 0.35); box-shadow: inset 0 0 0 2px #d4a017; }
}
.msg-highlight {
  animation: result-pulse 0.8s ease-out;
}

/* ── Creature Onboarding Modal ── */
.creature-onboarding {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.creature-onboarding.active { display: flex; }

.co-card {
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(60,30,10,0.12);
  position: relative;
  z-index: 1;
}
.co-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--accent);
  text-align: center;
  line-height: 2;
  margin-bottom: 8px;
}
.co-sub {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 28px;
}
.co-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}
@media (max-width: 480px) {
  .co-grid { grid-template-columns: repeat(3, 1fr); }
}
.co-creature {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 10px 4px;
  border-radius: 12px;
  border: 2.5px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  gap: 4px;
}
.co-creature:hover {
  border-color: var(--border);
  transform: translateY(-2px);
}
.co-creature.selected {
  border-color: var(--accent);
  background: rgba(200,100,32,0.07);
}
.co-creature-img-wrap {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
}
.co-creature-img-wrap img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.co-creature-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.5px;
}
.co-creature-desc {
  font-size: 9px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
  display: none;
}
.co-confirm-row {
  display: flex;
  justify-content: center;
}
.co-confirm-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 3px 3px 0 var(--accent-light);
}
.co-confirm-btn:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--accent-light);
}
.co-confirm-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Ambient stars for onboarding */
.co-star {
  position: fixed;
  border-radius: 50%;
  background: var(--accent-light);
  opacity: 0.15;
  pointer-events: none;
}
.co-star-1 { width: 4px; height: 4px; top: 12%; left: 8%; animation: twinkle 3s infinite 0.5s; }
.co-star-2 { width: 3px; height: 3px; top: 22%; right: 14%; animation: twinkle 4s infinite 1.2s; }
.co-star-3 { width: 5px; height: 5px; bottom: 20%; left: 18%; animation: twinkle 2.5s infinite 0.8s; }
@keyframes twinkle {
  0%, 100% { opacity: 0.1; }
  50% { opacity: 0.35; }
}

/* ── @Mention Highlights ──────────────────────────────────────────────────── */

.msg-mentioned-highlight {
  border: 2px solid #F5C9A1 !important;
  background: rgba(245, 201, 161, 0.18) !important;
  box-shadow: 0 0 0 2px rgba(245, 201, 161, 0.3), inset 0 0 12px rgba(245, 201, 161, 0.1) !important;
  animation: mention-glow 0.8s ease-out;
}
@keyframes mention-glow {
  0% { box-shadow: 0 0 0 4px rgba(240, 160, 64, 0.6), 0 0 20px rgba(240, 160, 64, 0.4) !important; }
  100% { box-shadow: 0 0 0 2px rgba(245, 201, 161, 0.3), inset 0 0 12px rgba(245, 201, 161, 0.1) !important; }
}

.msg-mention-jump {
  animation: mention-jump 0.6s ease-out;
}
@keyframes mention-jump {
  0% { background: rgba(245, 201, 161, 0.35); }
  100% { background: transparent; }
}

.dm-msg-mentioned-highlight {
  border: 2px solid #F5C9A1 !important;
  background: rgba(245, 201, 161, 0.15) !important;
  animation: mention-glow 0.8s ease-out;
}

/* Mention badge on sidebar rows */
.mention-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #F08040;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  border-radius: 8px;
  padding: 2px 5px;
  margin-left: 4px;
  min-width: 16px;
  line-height: 1;
  flex-shrink: 0;
}

/* Mentions tab in sidebar */
.sidebar-mentions-section {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
}

#mentionsTabHeading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
}

.mentions-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #F08040;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  border-radius: 10px;
  padding: 2px 6px;
  min-width: 18px;
  line-height: 1;
}

.mentions-empty {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 8px;
  font-family: 'VT323', monospace;
  font-size: 14px;
}

.mentions-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}
.mentions-item:hover {
  background: rgba(245, 201, 161, 0.2);
}
.mentions-item.unread {
  background: rgba(245, 201, 161, 0.15);
}

.mentions-item-avatar img {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.mentions-item-info {
  flex: 1;
  min-width: 0;
}

.mentions-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.mentions-item-sender {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--text);
  font-weight: 700;
}

.mentions-item-source {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.mentions-item-preview {
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Room row mention badge — added dynamically in JS */
.room-item[data-room-key] .mention-badge {
  display: inline-flex;
}

/* ── Presence Indicators ───────────────────────────────────────────────────── */

.presence-dot-wrap {
  position: relative;
  display: inline-block;
}

/* 4×4px pixel-art presence dot, positioned at bottom-right of avatar */
.presence-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 6px;
  height: 6px;
  image-rendering: pixelated;
  border-radius: 0;
  /* Hard pixel edges via box-shadow */
  box-shadow: 1px 0 0 rgba(0,0,0,0.15);
}

.presence-dot.online {
  background: #4CAF50;
}

.presence-dot.idle {
  background: #FFC107;
  animation: idle-blink 2s steps(1) infinite;
}

.presence-dot.offline {
  background: #9E9E9E;
}

@keyframes idle-blink {
  0%, 70%, 100% { opacity: 1; }
  35%           { opacity: 0.3; }
}

/* Presence dot on avatar picker items in sidebar lists */
.pal-item.has-presence {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pal-item.has-presence .presence-dot-wrap {
  position: relative;
  flex-shrink: 0;
}

.pal-item.has-presence .pal-avatar-wrap {
  position: relative;
}

/* Offline: dim the avatar to ~40% */
.pal-item.offline .pal-avatar-wrap {
  opacity: 0.4;
}

.pal-item.offline .pal-name {
  color: var(--text-muted);
}

/* Idle: subtle sleepy z above the head */
.pal-item.idle .pal-avatar-wrap::after {
  content: 'z';
  position: absolute;
  top: -10px;
  right: -6px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #8a6030;
  opacity: 0.6;
  animation: sleepy-z 8s steps(1) infinite;
}

@keyframes sleepy-z {
  0%, 80% { opacity: 0; transform: translateY(0); }
  82%      { opacity: 0.6; }
  88%      { opacity: 0.6; transform: translateY(-4px); }
  90%      { opacity: 0; }
  100%     { opacity: 0; }
}

/* Online first, idle second, offline last — applied via JS sort */
.pal-item { transition: opacity 0.3s; }
.pal-item.online  { order: -1; }
.pal-item.idle    { order: 0; }
.pal-item.offline { order: 1; }

/* Room item icons in sidebar */
.room-item-icon {
  width: 14px;
  height: 14px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

/* Room icon in header */
.room-icon-img img {
  image-rendering: pixelated;
  vertical-align: middle;
}

/* Icon picker in create room modal */
.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin: 8px 0 12px;
  padding: 8px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
}

.icon-pick-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.icon-pick-btn img {
  image-rendering: pixelated;
  display: block;
}

.icon-pick-btn:hover {
  border-color: var(--accent);
  background: var(--bg-warm);
}

.icon-pick-btn.selected {
  border-color: var(--accent);
  background: #FDE8C8;
}

/* Modal hint inline label */
.modal-hint-inline {
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}

/* Pin button in room header */
.pin-btn {
  display: flex; align-items: center; gap: 4px;
  background: none; border: 2px solid var(--border);
  border-radius: 8px; padding: 4px 8px;
  cursor: pointer; color: var(--text-muted);
  font-size: 11px; font-weight: 700;
  transition: all 0.15s;
}
.pin-btn:hover { background: var(--bg-warm); color: var(--accent); border-color: var(--accent); }
.pin-btn.has-pins { color: var(--accent); border-color: var(--accent); }
.pin-btn-icon { width: 16px; height: 16px; flex-shrink: 0; }
.pin-count {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; min-width: 14px; text-align: center;
}

/* Pinned messages panel */
.pinned-panel {
  position: fixed; top: 52px; right: 0; bottom: 0;
  width: 360px; background: var(--surface);
  border-left: 2px solid var(--border);
  display: none; flex-direction: column;
  z-index: 80; box-shadow: -4px 0 16px rgba(60,30,10,0.08);
}
.pinned-panel.open { display: flex; }

.pinned-panel-header {
  padding: 12px 16px; border-bottom: 2px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; background: var(--surface);
}
.pinned-close-btn {
  background: none; border: 2px solid var(--border); border-radius: 8px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px;
  color: var(--text-muted); flex-shrink: 0; transition: all 0.15s;
}
.pinned-close-btn:hover { background: var(--bg-warm); color: var(--text); }
.pinned-panel-title {
  display: flex; align-items: center; gap: 6px;
  font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--text); flex: 1;
}
.pinned-panel-icon { color: var(--accent); }
.pinned-count-badge {
  font-family: 'Press Start 2P', monospace; font-size: 7px;
  background: var(--accent); color: white;
  border-radius: 10px; padding: 2px 6px;
  flex-shrink: 0;
}
.pinned-list {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.pinned-list::-webkit-scrollbar { width: 6px; }
.pinned-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Pinned message card */
.pinned-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  cursor: pointer; transition: all 0.15s;
}
.pinned-card:hover { border-color: var(--accent); background: #FDF0DC; }
.pinned-card-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.pinned-card-avatar {
  width: 28px; height: 28px; border-radius: 6px; overflow: hidden;
  border: 2px solid var(--border); flex-shrink: 0; image-rendering: pixelated;
}
.pinned-card-avatar img { width: 100%; height: 100%; image-rendering: pixelated; }
.pinned-card-name {
  font-family: 'Press Start 2P', monospace; font-size: 7px; color: var(--text);
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pinned-card-time { font-size: 9px; color: var(--text-muted); }
.pinned-card-body {
  font-size: 12px; line-height: 1.5; color: var(--text);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.pinned-card-body code { font-size: 10px; }
.pinned-card-footer {
  display: flex; align-items: center; justify-content: flex-end;
  margin-top: 6px; gap: 6px;
}
.pinned-unpin-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px;
  cursor: pointer; font-size: 9px; font-weight: 700;
  color: var(--text-muted); transition: all 0.15s;
}
.pinned-unpin-btn:hover { border-color: #c0392b; color: #c0392b; background: #fde8e8; }

/* Pinned empty state */
.pinned-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 12px;
  color: var(--text-muted); text-align: center; padding: 24px;
}
.pinned-empty-icon { font-size: 32px; opacity: 0.5; }
.pinned-empty-text { font-size: 12px; font-weight: 600; line-height: 1.6; }

/* Push messages when pinned panel is open */
.pinned-panel.open ~ .chat-room .messages { margin-right: 360px; }

/* Inline pin badge on message bubble */
.msg-pin-badge {
  position: absolute; top: 6px; right: 6px;
  width: 18px; height: 18px; opacity: 0.7;
  pointer-events: none;
}

/* Pin hover button on message */
.msg-pin-btn {
  position: absolute; top: 4px;
  opacity: 0; cursor: pointer; transition: opacity 0.15s;
  z-index: 10;
}
.msg-pin-btn:hover { opacity: 1 !important; }

/* Thread reply reactions */
.tr-msg { position: relative; }
.tr-reactions {
  display: flex; flex-wrap: wrap; gap: 3px;
  margin-top: 3px;
}
.tr-reaction-trigger { z-index: 15; }
.tr-msg:hover .tr-reaction-trigger { opacity: 1 !important; }
