/* ==============================
   chat.css — Full Discord/WhatsApp Style (Merged)
   ============================== */

/* Root variables */
:root {
  --bg: #121212;
  --surface: rgba(24, 24, 24, 0.95);
  --surface-alt: #1b1b1b;
  --bubble-self: #056162;
  --bubble-other: #262d31;
  --text-primary: #f5f5f5;
  --text-muted: rgba(255, 255, 255, 0.65);
  --accent: #25d366;
  --border-color: rgba(255, 255, 255, 0.12);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --input-bg: #1f1f1f;
  --input-border: rgba(255, 255, 255, 0.18);
  --picker-bg: #1e1e1e;
  --picker-border: rgba(255, 255, 255, 0.12);
  --landing-bg: #000000;
  --link-preview-bg: rgba(255, 255, 255, 0.05);
  --link-preview-hover: rgba(255, 255, 255, 0.1);
  --pinned-bg: #2b2b2b;
  --typing-bg: rgba(0, 0, 0, 0.25);
  --preview-bg: rgba(255, 255, 255, 0.08);
  --status-online: #25d366;
  --status-offline: rgba(255, 255, 255, 0.35);
  --status-border: rgba(0, 0, 0, 0.45);
  --toolbar-padding-y: 12px;
  --toolbar-padding-x: 16px;
  --toolbar-gap: 16px;
  --toolbar-logo-size: 40px;
  --toolbar-control-height: 42px;
  --toolbar-button-padding-y: 6px;
  --toolbar-button-padding-x: 12px;
  --toolbar-icon-button-size: 42px;
  --toolbar-button-font-size: 0.95em;
  --toolbar-link-padding-y: 8px;
  --toolbar-link-padding-x: 14px;
  --toolbar-search-gap: 6px;
  --toolbar-search-padding-y: 4px;
  --toolbar-search-padding-x: 6px;
  --toolbar-search-margin-left: 16px;
  --toolbar-search-font-size: 0.85em;
  --room-name-font-size: 1.1em;
  --messages-padding-y: 12px;
  --messages-padding-x: 12px;
  --message-gap: 10px;
  --message-padding-y: 12px;
  --message-padding-x: 16px;
  --message-font-size: 1em;
  --message-meta-font-size: 0.75em;
  --scroll-to-latest-bottom: 110px;
  --scroll-to-latest-padding-y: 10px;
  --scroll-to-latest-padding-x: 16px;
  --scroll-to-latest-font-size: 0.9rem;
  --input-padding-y: 10px;
  --input-padding-x: 12px;
  --input-field-padding-y: 10px;
  --input-field-padding-x: 14px;
  --input-font-size: 1em;
  --input-button-gap: 5px;
  --input-button-font-size: 1.3em;
  --input-icon-size: 42px;
  --quick-emoji-gap: 6px;
  --quick-emoji-margin-left: 8px;
  --quick-emoji-size: 36px;
  --sidebar-width: 260px;
  --sidebar-min-width: 220px;
  --sidebar-padding-y: 16px;
  --sidebar-padding-x: 18px;
  --sidebar-gap: 12px;
}

body:not(.dark) {
  --bg: #f5f7fb;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-alt: #ffffff;
  --bubble-self: #20c373;
  --bubble-other: #e9edf2;
  --text-primary: #1f2933;
  --text-muted: #5f6368;
  --accent: #1fa866;
  --border-color: rgba(17, 17, 17, 0.12);
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  --input-bg: #ffffff;
  --input-border: rgba(17, 17, 17, 0.12);
  --picker-bg: #ffffff;
  --picker-border: rgba(17, 17, 17, 0.12);
  --landing-bg: #fefefe;
  --link-preview-bg: rgba(17, 17, 17, 0.05);
  --link-preview-hover: rgba(17, 17, 17, 0.1);
  --pinned-bg: #ffffff;
  --typing-bg: rgba(17, 17, 17, 0.08);
  --preview-bg: rgba(17, 17, 17, 0.08);
  --status-online: #1fa866;
  --status-offline: rgba(17, 17, 17, 0.28);
  --status-border: rgba(17, 17, 17, 0.08);
}

body.compact-mode {
  --toolbar-padding-y: 8px;
  --toolbar-padding-x: 12px;
  --toolbar-gap: 10px;
  --toolbar-logo-size: 32px;
  --toolbar-control-height: 36px;
  --toolbar-button-padding-y: 4px;
  --toolbar-button-padding-x: 10px;
  --toolbar-icon-button-size: 34px;
  --toolbar-button-font-size: 0.9em;
  --toolbar-link-padding-y: 6px;
  --toolbar-link-padding-x: 12px;
  --toolbar-search-gap: 4px;
  --toolbar-search-padding-y: 3px;
  --toolbar-search-padding-x: 4px;
  --toolbar-search-margin-left: 10px;
  --toolbar-search-font-size: 0.8em;
  --room-name-font-size: 1em;
  --messages-padding-y: 8px;
  --messages-padding-x: 8px;
  --message-gap: 6px;
  --message-padding-y: 8px;
  --message-padding-x: 12px;
  --message-font-size: 0.95em;
  --message-meta-font-size: 0.7em;
  --scroll-to-latest-bottom: 84px;
  --scroll-to-latest-padding-y: 8px;
  --scroll-to-latest-padding-x: 14px;
  --scroll-to-latest-font-size: 0.85rem;
  --input-padding-y: 6px;
  --input-padding-x: 10px;
  --input-field-padding-y: 8px;
  --input-field-padding-x: 12px;
  --input-font-size: 0.95em;
  --input-button-gap: 4px;
  --input-button-font-size: 1.15em;
  --input-icon-size: 34px;
  --quick-emoji-gap: 4px;
  --quick-emoji-margin-left: 4px;
  --quick-emoji-size: 32px;
  --sidebar-width: 220px;
  --sidebar-min-width: 200px;
  --sidebar-padding-y: 12px;
  --sidebar-padding-x: 14px;
  --sidebar-gap: 10px;
}

/* ==============================
   Body & Chat Container
   ============================== */
body {
  font-family: 'Segoe UI', sans-serif;
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
}

@supports (height: 100dvh) {
  body {
    height: 100dvh;
    min-height: 100dvh;
  }

  #chat-container {
    min-height: 100dvh;
  }
}

body.dark { background: var(--bg); color: var(--text-primary); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#chat-container {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  box-sizing: border-box;
}

/* ==============================
   Landing Page
   ============================== */
#username-prompt {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 12px;
  background: var(--landing-bg);
  color: var(--text-primary);
  padding: 32px 24px;
  padding-top: calc(32px + env(safe-area-inset-top));
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
  box-sizing: border-box;
}

#username-prompt .logo {
  width: min(160px, 48vw);
  height: auto;
  max-height: 140px;
  margin-bottom: 12px;
  object-fit: contain;
}

#username-prompt h1 { font-size: 2em; margin: 0 0 12px; color: var(--text-primary); }

.landing-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 260px;
}

.landing-inputs input {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
}

.landing-inputs input::placeholder { color: var(--text-muted); }

#join-btn {
  margin-top: 8px;
  padding: 10px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

#join-btn:hover { opacity: 0.9; }

#room-list { margin-top: 20px; text-align: center; color: var(--text-primary); }

#public-room-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#public-room-list li {
  background: var(--surface-alt);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
  cursor: default;
  align-items: flex-start;
}

#public-room-list li.clickable {
  cursor: pointer;
}

#public-room-list li.clickable:hover {
  transform: scale(1.05);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px rgba(37, 211, 102, 0.32);
}

#public-room-list li.locked {
  border-style: dashed;
  cursor: pointer;
}

#public-room-list li.locked:hover {
  transform: none;
  background: var(--surface-alt);
  color: var(--text-primary);
  box-shadow: none;
}

#public-room-list li.empty {
  width: 100%;
  justify-content: center;
  text-align: center;
  opacity: 0.7;
  border-style: dashed;
  background: transparent;
  color: var(--text-muted);
  cursor: default;
  box-shadow: none;
  pointer-events: none;
  min-width: 0;
}

#public-room-list li .room-name {
  font-weight: 600;
  font-size: 1em;
}

#public-room-list li .room-meta {
  font-size: 0.75em;
  color: var(--text-muted);
}

#public-room-list li.clickable .room-meta {
  color: inherit;
  opacity: 0.85;
}

/* ==============================
   Header
   ============================== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--toolbar-padding-y) var(--toolbar-padding-x);
  background: var(--surface);
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
  color: var(--text-primary);
  gap: var(--toolbar-gap);
  flex-wrap: wrap;
}

header.toolbar-flash-message {
  animation: toolbarFlashOrange 1.4s ease-in-out 2;
}

header.toolbar-flash-join {
  animation: toolbarFlashGreen 1.1s ease-in-out 1;
}

@keyframes toolbarFlashOrange {
  0%,
  100% {
    background-color: var(--surface);
    border-bottom-color: var(--border-color);
    box-shadow: none;
  }
  25%,
  75% {
    background-color: #ff9f1c;
    border-bottom-color: #ffb347;
    box-shadow: 0 0 18px rgba(255, 159, 28, 0.45);
  }
  50% {
    background-color: var(--surface);
    border-bottom-color: var(--border-color);
    box-shadow: none;
  }
}

@keyframes toolbarFlashGreen {
  0%,
  100% {
    background-color: var(--surface);
    border-bottom-color: var(--border-color);
    box-shadow: none;
  }
  40% {
    background-color: #2ecc71;
    border-bottom-color: #6de0a0;
    box-shadow: 0 0 14px rgba(46, 204, 113, 0.4);
  }
  70% {
    background-color: #24b862;
    border-bottom-color: #6de0a0;
    box-shadow: 0 0 18px rgba(46, 204, 113, 0.45);
  }
}

header .header-left { display: flex; align-items: center; gap: 10px; }

header .logo {
  width: var(--toolbar-logo-size);
  height: var(--toolbar-logo-size);
  max-width: var(--toolbar-logo-size);
  max-height: var(--toolbar-logo-size);
  flex: 0 0 var(--toolbar-logo-size);
  object-fit: contain;
  border-radius: calc(var(--toolbar-logo-size) / 5);
  overflow: hidden;
}

#chat-container header .header-right {
  display: flex;
  align-items: center;
  gap: var(--toolbar-gap);
  padding-left: var(--toolbar-gap);
  margin-left: auto;
}

.psybin-player {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--text-primary);
  flex: 0 1 320px;
  min-width: 220px;
}

.psybin-player[hidden] {
  display: none !important;
}

.psybin-player-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78em;
  line-height: 1.4;
  color: var(--text-secondary, rgba(255, 255, 255, 0.72));
  min-height: 1.2em;
}

.psybin-player-meta[data-state="loading"] .psybin-player-meta-status {
  display: inline-block;
}

.psybin-player-meta-status {
  width: 0.75em;
  height: 0.75em;
  border-radius: 50%;
  border: 2px solid var(--accent, #b266ff);
  border-top-color: transparent;
  display: none;
  animation: psybin-player-spin 0.75s linear infinite;
}

.psybin-player-meta-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.psybin-player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.psybin-player-label {
  font-size: 0.85em;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.psybin-player-button {
  border: none;
  background: var(--surface);
  color: inherit;
  border-radius: var(--radius-sm, 6px);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.9em;
  transition: background 0.2s ease, color 0.2s ease;
}

.psybin-player-button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.psybin-player-button:not([disabled]):hover,
.psybin-player-button:not([disabled]):focus-visible {
  background: var(--accent-muted, rgba(178, 102, 255, 0.15));
  outline: none;
}

.psybin-player-volume {
  flex: 1 1 110px;
  min-width: 90px;
  max-width: 180px;
  accent-color: var(--accent, #b266ff);
}

@keyframes psybin-player-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.stream-modal {
  position: fixed;
  top: 88px;
  left: 20px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  width: min(640px, calc(100vw - 40px));
  height: min(360px, calc(100vh - 180px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  overflow: hidden;
  z-index: 40;
  user-select: none;
}

.stream-modal[hidden] {
  display: none !important;
}

.stream-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border-color);
  cursor: grab;
  font-weight: 600;
  letter-spacing: 0.01em;
  touch-action: none;
}

.stream-modal:active .stream-modal-header,
.stream-modal.dragging .stream-modal-header {
  cursor: grabbing;
}

.stream-modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95em;
}

.stream-modal-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stream-modal-button {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.1em;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.2s ease, color 0.2s ease;
}

.stream-modal-button:hover,
.stream-modal-button:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

body:not(.dark) .stream-modal-button:hover,
body:not(.dark) .stream-modal-button:focus-visible {
  background: rgba(0, 0, 0, 0.08);
}

.stream-modal-body {
  position: relative;
  flex: 1;
  background: #000;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding-bottom: 24px;
}

.stream-modal-body > * {
  flex: 1 1 auto;
  min-width: 0;
}

#infowars-stream-frame,
#infowars-stream-frame > * {
  width: 100%;
  height: 100%;
}

#infowars-stream-frame .rumble {
  display: flex !important;
  align-items: stretch;
  justify-content: center;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  padding: 0 !important;
  position: relative !important;
}

.stream-modal-body iframe,
#infowars-stream-frame .rumble iframe {
  border: none;
  width: 100% !important;
  height: 100% !important;
  display: block;
  background: #000;
  max-width: none !important;
  max-height: none !important;
}

.stream-resize-handle {
  width: 18px;
  height: 18px;
  background: transparent;
  cursor: nwse-resize;
  border-radius: 4px;
  position: absolute;
  bottom: 6px;
  right: 6px;
  touch-action: none;
}

.stream-resize-handle::before,
.stream-resize-handle::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}

.stream-resize-handle::before {
  width: 60%;
  height: 2px;
  bottom: 4px;
  right: 2px;
}

.stream-resize-handle::after {
  width: 2px;
  height: 60%;
  bottom: 2px;
  right: 4px;
}

.stream-modal.collapsed {
  height: auto !important;
  min-height: 0;
}

.stream-modal.collapsed .stream-modal-body {
  display: none;
}

.stream-modal.collapsed .stream-modal-header {
  cursor: pointer;
}

@media (max-width: 768px) {
  .stream-modal {
    left: 10px;
    top: 74px;
    width: min(520px, calc(100vw - 20px));
    height: min(300px, calc(100vh - 160px));
  }
}

#chat-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

#chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

#chat-container .search-bar {
  display: flex;
  align-items: center;
  gap: var(--toolbar-search-gap);
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: var(--toolbar-search-padding-y) var(--toolbar-search-padding-x);
  border: 1px solid var(--border-color);
  margin-left: var(--toolbar-search-margin-left);
}

#chat-container .search-bar input,
#chat-container .search-bar select {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--toolbar-search-font-size);
}

#chat-container .search-bar input::placeholder {
  color: var(--text-muted);
}

#chat-container .search-bar select {
  cursor: pointer;
  background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 8px 8px, 8px 8px;
  background-repeat: no-repeat;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 4px 24px 4px 10px;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
}

#chat-container .search-bar select option {
  background: var(--surface-alt);
  color: var(--text-primary);
}

#message-search:focus,
#message-search-filter:focus {
  outline: none;
}

#room-name { font-weight: 600; font-size: var(--room-name-font-size); color: var(--text-primary); }

/* Header buttons */
.header-right button {
  font-size: var(--toolbar-button-font-size);
  margin-left: 0;
  cursor: pointer;
  border-radius: var(--radius);
  padding: var(--toolbar-button-padding-y) var(--toolbar-button-padding-x);
  border: 1px solid transparent;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
  background: transparent;
  color: var(--text-primary);
  min-height: var(--toolbar-control-height);
}

.header-right button#leave-btn {
  background: #ff4d4d;
  color: #fff;
  font-weight: 600;
  border-color: transparent;
}

.header-right button#leave-btn:hover {
  background: #ff6666;
  transform: scale(1.05);
}

.header-right button#toggle-theme {
  background: var(--surface-alt);
  border-color: var(--border-color);
}

.header-right button#toggle-theme:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 18px rgba(123, 47, 247, 0.25);
}

.header-right button#toggle-density {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--toolbar-button-padding-y);
  min-width: var(--toolbar-icon-button-size);
  width: var(--toolbar-icon-button-size);
  height: var(--toolbar-icon-button-size);
  background: var(--surface-alt);
  border-color: var(--border-color);
}

.header-right button#toggle-density .icon {
  font-size: 1.15em;
  line-height: 1;
}

.header-right button#toggle-density:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 18px rgba(123, 47, 247, 0.25);
}

.header-right button#toggle-density.is-active {
  background: rgba(187, 134, 252, 0.18);
  border-color: rgba(187, 134, 252, 0.6);
  box-shadow: 0 0 0 1px rgba(187, 134, 252, 0.35);
  color: #f1e7ff;
}

.header-right button#toggle-density.is-active .icon {
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.25));
}

.header-right button#toggle-sounds {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--toolbar-button-padding-y);
  min-width: var(--toolbar-icon-button-size);
  width: var(--toolbar-icon-button-size);
  height: var(--toolbar-icon-button-size);
  background: var(--surface-alt);
  border-color: var(--border-color);
}

.header-right button#toggle-sounds .icon {
  font-size: 1.15em;
  line-height: 1;
}

.header-right button#toggle-sounds:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 18px rgba(123, 47, 247, 0.25);
}

.header-right button#toggle-sounds[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(37, 211, 102, 0.3);
}

.header-right button#toggle-sounds[aria-pressed="true"] .icon {
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.25));
}

.header-right button#copy-join-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--toolbar-link-padding-y) var(--toolbar-link-padding-x);
  background: var(--surface);
  border-color: var(--border-color);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  line-height: 1.1;
}

.header-right button#copy-join-link .icon {
  font-size: 1.1em;
  line-height: 1;
}

.header-right button#copy-join-link .label {
  letter-spacing: 0.02em;
}

.header-right button#copy-join-link:hover {
  background: var(--surface-alt);
  box-shadow: 0 8px 18px rgba(123, 47, 247, 0.25);
  transform: translateY(-1px);
}

.header-right button#copy-join-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body:not(.dark) .header-right button#copy-join-link {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(17, 17, 17, 0.12);
  box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.05);
  color: #1f2933;
}

body:not(.dark) .header-right button#copy-join-link:hover {
  background: #eef2fb;
}

body:not(.dark) .header-right button#toggle-density {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(17, 17, 17, 0.12);
  color: #1f2933;
}

body:not(.dark) .header-right button#toggle-density.is-active {
  background: rgba(123, 47, 247, 0.16);
  border-color: rgba(123, 47, 247, 0.45);
  color: #3b1d75;
}

/* ==============================
   Messages Area
   ============================== */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--messages-padding-y) var(--messages-padding-x);
  padding-bottom: calc(
    var(--messages-padding-y) + var(--input-icon-size) + env(safe-area-inset-bottom)
  );
  display: flex;
  flex-direction: column;
  gap: var(--message-gap);
  scroll-behavior: smooth;
  background: var(--surface-alt);
}

#messages-end-sentinel {
  width: 100%;
  height: 1px;
  flex: 0 0 auto;
  pointer-events: none;
}

.scroll-to-latest[hidden] {
  display: none !important;
}

.scroll-to-latest {
  position: absolute;
  left: 50%;
  bottom: var(--scroll-to-latest-bottom);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--scroll-to-latest-padding-y) var(--scroll-to-latest-padding-x);
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: rgba(17, 17, 17, 0.65);
  color: #fff;
  font-size: var(--scroll-to-latest-font-size);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(17, 17, 17, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  transform: translateX(-50%);
  z-index: 5;
}

body:not(.dark) .scroll-to-latest {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
  border-color: rgba(17, 17, 17, 0.12);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.18);
}

.scroll-to-latest:hover {
  transform: translate(-50%, -1px);
  box-shadow: 0 16px 30px rgba(17, 17, 17, 0.38);
}

.scroll-to-latest:active {
  transform: translate(-50%, 0);
  box-shadow: 0 10px 20px rgba(17, 17, 17, 0.28);
}

.scroll-to-latest:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scroll-to-latest .scroll-to-latest-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.8rem;
  line-height: 1.1;
}

.scroll-to-latest.has-new {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 18px 32px rgba(123, 47, 247, 0.35);
}

body:not(.dark) .scroll-to-latest.has-new {
  box-shadow: 0 18px 32px rgba(123, 47, 247, 0.28);
}

.scroll-to-latest.has-new .scroll-to-latest-count {
  background: rgba(255, 255, 255, 0.25);
}

.scroll-to-latest:not(.has-new) .scroll-to-latest-count {
  display: none;
}

@media (max-width: 768px) {
  .scroll-to-latest {
    bottom: 96px;
    font-size: 0.85rem;
    padding: 9px 14px;
  }
}

.day-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 18px 0 8px;
}

.day-separator::before,
.day-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
  opacity: 0.6;
}

#user-sidebar {
  width: var(--sidebar-width);
  max-width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border-color);
  padding: var(--sidebar-padding-y) var(--sidebar-padding-x);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--sidebar-gap);
  flex: 0 0 var(--sidebar-width);
  min-width: var(--sidebar-min-width);
}

#user-sidebar .sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#user-sidebar .sidebar-header h2 {
  font-size: 1rem;
  margin: 0;
  color: var(--text-primary);
}

#user-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

#user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.user-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-alt);
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease;
  cursor: default;
}

.user-entry .user-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text-primary);
}

.user-entry .user-name .user-crown {
  font-size: 1.05em;
}

.user-entry .user-name .self-pill {
  font-size: 0.75rem;
  background: rgba(187, 134, 252, 0.25);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 999px;
}

.user-entry .user-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-entry .user-status.bad {
  color: #ff6b6b;
}

.user-entry .user-status.warn {
  color: #f6c343;
}

.user-entry.actionable {
  cursor: pointer;
}

.user-entry.actionable:focus-visible {
  outline: 2px solid rgba(187, 134, 252, 0.85);
  outline-offset: 2px;
  border-color: rgba(187, 134, 252, 0.55);
}

.user-entry.actionable:hover {
  transform: translateY(-1px);
  border-color: rgba(187, 134, 252, 0.35);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

.user-entry.disabled {
  opacity: 0.65;
}

#user-list-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.user-context-menu {
  position: absolute;
  display: none;
  flex-direction: column;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
  padding: 6px;
  z-index: 60;
}

.user-context-menu.open {
  display: flex;
}

.user-context-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.user-context-menu button:hover {
  background: rgba(187, 134, 252, 0.18);
  transform: translateY(-1px);
}

.user-context-menu button:focus-visible {
  outline: 2px solid rgba(187, 134, 252, 0.7);
  outline-offset: 2px;
  background: rgba(187, 134, 252, 0.18);
}

.user-context-menu button.danger {
  color: #ff6b6b;
}

.user-context-menu button.danger:hover {
  background: rgba(255, 107, 107, 0.16);
}

@media (max-width: 900px) {
  header {
    align-items: flex-start;
    gap: 12px;
  }

  header .header-left {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
  }

  header .header-left #room-name {
    flex: 1 1 100%;
    min-width: 0;
  }

  .psybin-player {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  #chat-container header .header-right {
    width: 100%;
    margin-left: 0;
    padding-left: 0;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    display: flex;
  }

  #chat-container .search-bar {
    order: -1;
    width: 100%;
    margin-left: 0;
    padding: 6px 10px;
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  #chat-container .search-bar input {
    flex: 1 1 100%;
    min-width: 0;
  }

  #chat-container .search-bar select {
    flex: 1 1 160px;
    min-width: 140px;
  }

  .header-right button {
    margin-left: 0;
    flex: 0 0 auto;
    min-width: 0;
  }

  .header-right button#toggle-density {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  .header-right button#toggle-sounds {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  .header-right button#copy-join-link {
    justify-content: center;
  }

  .header-right button#copy-join-link .label {
    display: none;
  }

  #chat-main {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  #user-sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    border-left: none;
    border-top: 1px solid var(--border-color);
    --sidebar-padding-y: min(var(--sidebar-padding-y), 12px);
    --sidebar-padding-x: min(var(--sidebar-padding-x), 16px);
    order: 1;
  }

  #chat-content {
    order: 0;
  }
}

@media (max-width: 768px) {
  header {
    --toolbar-padding-y: min(var(--toolbar-padding-y), 10px);
    --toolbar-padding-x: min(var(--toolbar-padding-x), 12px);
    --toolbar-gap: min(var(--toolbar-gap), 12px);
    --toolbar-control-height: min(var(--toolbar-control-height), 36px);
    --toolbar-icon-button-size: min(var(--toolbar-icon-button-size), 36px);
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  header .header-left {
    width: 100%;
    justify-content: space-between;
  }

  #chat-container header .header-right {
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: min(var(--toolbar-gap), 8px);
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  #chat-container .search-bar {
    order: -1;
    width: 100%;
    gap: min(var(--toolbar-search-gap), 4px);
    margin-left: 0;
  }

  #chat-container .search-bar input,
  #chat-container .search-bar select {
    flex: 1 1 100%;
    min-width: 0;
  }

  .header-right button {
    flex: 0 0 auto;
    min-height: var(--toolbar-control-height);
  }

  #chat-main {
    border-radius: calc(var(--radius) / 2);
  }

  #messages {
    --messages-padding-y: min(var(--messages-padding-y), 12px);
    --messages-padding-x: min(var(--messages-padding-x), 10px);
  }
}

.message {
  position: relative;
  max-width: 75%;
  padding: var(--message-padding-y) var(--message-padding-x);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  word-wrap: break-word;
  font-size: var(--message-font-size);
  animation: fadeIn 0.25s ease-in;
  display: inline-block;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  color: var(--text-primary);
}

.message:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

.message.menu-open {
  z-index: 100;
}

.message.menu-open,
.message.menu-open:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.message.self {
  align-self: flex-end;
  background: var(--bubble-self);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.other {
  align-self: flex-start;
  background: var(--bubble-other);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message[data-deleted="true"] {
  opacity: 0.65;
  background: rgba(128, 128, 128, 0.35);
  box-shadow: none;
}

.message .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: var(--message-meta-font-size);
  color: var(--text-muted);
  margin-bottom: 4px;
  padding-right: 32px;
}

.message .meta .meta-name {
  font-weight: 600;
}

.message .meta .meta-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.message .meta .meta-time {
  opacity: 0.8;
}

.message .meta .meta-status {
  position: relative;
  width: 18px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.95em;
  letter-spacing: -0.02em;
}

.message .meta .meta-status::before,
.message .meta .meta-status::after {
  content: "✓";
  position: absolute;
  font-weight: 700;
  line-height: 1;
  font-size: 0.95em;
}

.message .meta .meta-status::after {
  opacity: 0;
}

.message .meta .meta-status[data-status="sent"]::before {
  color: rgba(255, 255, 255, 0.75);
  right: 0;
}

body:not(.dark) .message.self .meta .meta-status[data-status="sent"]::before {
  color: rgba(0, 0, 0, 0.6);
}

.message .meta .meta-status[data-status="delivered"]::before,
.message .meta .meta-status[data-status="delivered"]::after {
  color: rgba(255, 255, 255, 0.8);
}

body:not(.dark) .message.self .meta .meta-status[data-status="delivered"]::before,
body:not(.dark) .message.self .meta .meta-status[data-status="delivered"]::after {
  color: rgba(0, 0, 0, 0.7);
}

.message .meta .meta-status[data-status="delivered"]::before {
  right: 0;
}

.message .meta .meta-status[data-status="delivered"]::after {
  right: 5px;
  opacity: 1;
}

.message .meta .meta-status[data-status="read"]::before,
.message .meta .meta-status[data-status="read"]::after {
  color: #34b7f1;
}

.message .meta .meta-status[data-status="read"]::before {
  right: 0;
}

.message .meta .meta-status[data-status="read"]::after {
  right: 5px;
  opacity: 1;
}

.message.other .meta .meta-status {
  display: none;
}

.message .message-flags {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.message .message-flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.75em;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
}

.message.other .message-flag {
  background: rgba(0, 0, 0, 0.15);
}

.message .message-flag.pinned {
  background: rgba(37, 211, 102, 0.2);
  color: #20c373;
}

.message .message-flag.starred {
  background: rgba(255, 215, 0, 0.25);
  color: #ffd700;
}

.message .message-flag .count {
  font-weight: 600;
}

#reply-preview {
  display: none;
  align-items: center;
  gap: 12px;
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-alt);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#reply-preview.show {
  display: flex;
}

#reply-preview .reply-preview-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

#reply-preview .reply-preview-title {
  font-size: 0.85em;
  color: var(--accent);
  font-weight: 600;
}

#reply-preview .reply-preview-text {
  font-size: 0.9em;
  color: var(--text-primary);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reply-preview .reply-preview-content:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#reply-preview button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1em;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
}

#reply-preview button:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.message .reply-context {
  margin: 2px 0 8px;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message .reply-context:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.message.self .reply-context {
  background: rgba(255, 255, 255, 0.12);
}

.message .reply-context:hover {
  background: var(--link-preview-hover);
}

.message .reply-context .reply-author {
  font-weight: 600;
  font-size: 0.82em;
  color: var(--accent);
}

.message .reply-context .reply-snippet {
  font-size: 0.88em;
  color: var(--text-primary);
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
}

.message .reply-context.deleted .reply-snippet {
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.7;
}

.message .reply-context .reply-attachment-label {
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.message .text {
  white-space: pre-wrap;
}

.message .text.hidden {
  display: none;
}

.message .deleted-label {
  font-style: italic;
  color: var(--text-muted);
}

.message .message-actions-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1.1em;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.message .message-actions-toggle:hover,
.message .message-actions-toggle[aria-expanded="true"] {
  opacity: 1;
}

.message .message-actions-menu {
  position: absolute;
  top: 28px;
  right: 8px;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: none;
  flex-direction: column;
  z-index: 50;
}

.message .message-actions-menu.open {
  display: flex;
}

.message .message-actions-menu button {
  background: transparent;
  border: none;
  padding: 8px 12px;
  text-align: left;
  color: inherit;
  cursor: pointer;
  font-size: 0.9em;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.message .message-actions-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.message .message-actions-menu button.danger {
  color: #ff6b6b;
}

.message.self .message-actions-menu button.danger {
  color: #ffdede;
}

.message .text img.custom-emoji {
  display: inline-block;
  height: 3em;
  width: auto;
  margin: 0 2px;
  vertical-align: middle;
  image-rendering: auto;
}

.message .text img.custom-emoji.custom-emoji-gif {
  display: block;
  width: min(240px, 100%);
  height: auto;
  margin: 6px 0;
  border-radius: 12px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.message.self .text img.custom-emoji.custom-emoji-gif {
  margin-left: auto;
}

.message.other .text img.custom-emoji.custom-emoji-gif {
  margin-right: auto;
}

.message .text.has-emoji-gif {
  display: flex;
  flex-direction: column;
  gap: 8px;
  white-space: pre-wrap;
}

.message.self .text.has-emoji-gif {
  align-items: flex-end;
  text-align: right;
}

.message.other .text.has-emoji-gif {
  align-items: flex-start;
  text-align: left;
}

.message .text.has-emoji-gif.emoji-gif-only {
  gap: 10px;
}

.message.has-emoji-gif {
  max-width: min(260px, 90vw);
  padding: 10px 12px;
}


.message.has-inline-preview {
  padding: 10px 12px;
}

.message.has-inline-media {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: min(280px, 100%);
}

.message.has-inline-media .inline-preview {
  width: 100%;
}

.message.search-hit {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 12px rgba(37, 211, 102, 0.4);
}

.message.has-inline-preview .text:empty {
  display: none;
}

.message.media-only,
.message.tenor-only {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
}

.message.media-only {
  max-width: min(320px, 100%);
}

.message.tenor-only {
  max-width: min(260px, 100%);
}

.message.media-only .inline-preview,
.message.tenor-only .inline-preview {
  margin-top: 0;
  width: 100%;
  padding: 6px;
}

.message.tenor-only .inline-preview.tenor-inline {
  width: 100%;
}

.message .text img.custom-emoji:first-child {
  margin-left: 0;
}

.message .text img.custom-emoji:last-child {
  margin-right: 0;
}

/* Pin & Star Buttons */
.message .pin-btn,
.message .star-btn {
  position: absolute;
  top: 8px;
  font-size: 1.3em;
  cursor: pointer;
  opacity: 0.8;
  border: none;
  background: none;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.message .pin-btn { right: 32px; }
.message .star-btn { right: 6px; }
.message .pin-btn:hover,
.message .star-btn:hover { transform: scale(1.4); opacity: 1; }

/* Reactions */
.message .reactions {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.message .reactions .reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 3px 8px;
  font-size: 0.85em;
  color: inherit;
  cursor: default;
  transition: transform 0.15s ease, background 0.2s ease, border 0.2s ease;
}

.message .reactions .reaction-chip.own {
  cursor: pointer;
}

.message .reactions .reaction-chip.own:hover,
.message .reactions .reaction-chip.own:focus-visible {
  transform: translateY(-1px) scale(1.05);
  background: rgba(187,134,252,0.28);
  border-color: rgba(187,134,252,0.6);
  outline: none;
}

.message .reactions .reaction-chip .reaction-emoji,
.message .reactions .reaction-chip .reaction-count {
  line-height: 1;
}

.message .reactions .reaction-chip .reaction-count {
  font-size: 0.75em;
  opacity: 0.85;
}

.message .reactions .reaction-chip img {
  width: 1.2em;
  height: 1.2em;
  object-fit: contain;
  border-radius: 8px;
}

.message .reactions .reaction-chip.own {
  background: rgba(187,134,252,0.35);
  border-color: rgba(187,134,252,0.75);
  box-shadow: 0 0 8px rgba(187,134,252,0.35);
}

body.light .message .reactions .reaction-chip {
  border-color: rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.05);
}

body.light .message .reactions .reaction-chip.own:hover,
body.light .message .reactions .reaction-chip.own:focus-visible {
  background: rgba(187,134,252,0.25);
  border-color: rgba(187,134,252,0.55);
}

body.light .message .reactions .reaction-chip.own {
  background: rgba(187,134,252,0.32);
  border-color: rgba(187,134,252,0.7);
}

/* ==============================
   Input Bar
   ============================== */
#form {
  display: flex;
  align-items: center;
  padding: var(--input-padding-y) var(--input-padding-x);
  border-top: 1px solid var(--border-color);
  background: var(--surface);
  backdrop-filter: blur(8px);
  position: sticky;
  bottom: 0;
  z-index: 15;
}

#quick-emoji-panel {
  display: inline-flex;
  align-items: center;
  gap: var(--quick-emoji-gap);
  margin-left: var(--quick-emoji-margin-left);
  flex-shrink: 0;
}

#quick-emoji-panel:empty {
  display: none;
}

#quick-emoji-panel .quick-emoji-button {
  width: var(--quick-emoji-size);
  height: var(--quick-emoji-size);
  border-radius: var(--radius-sm, 10px);
  border: 1px solid var(--border-color);
  background: var(--surface-alt);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  margin-left: 0;
}

#quick-emoji-panel .quick-emoji-button.quick-emoji-button-image {
  padding: 0;
  font-size: 0;
  overflow: hidden;
}

#quick-emoji-panel .quick-emoji-button.quick-emoji-button-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: inherit;
  pointer-events: none;
}

body.dark #quick-emoji-panel .quick-emoji-button {
  background: rgba(178, 102, 255, 0.15);
  border-color: rgba(178, 102, 255, 0.35);
  color: #f5f0ff;
}

body:not(.dark) #quick-emoji-panel .quick-emoji-button {
  background: rgba(178, 102, 255, 0.12);
  border-color: rgba(178, 102, 255, 0.3);
  color: #5b21b6;
}

#quick-emoji-panel .quick-emoji-button:hover,
#quick-emoji-panel .quick-emoji-button:focus-visible {
  transform: translateY(-1px) scale(1.05);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(123, 47, 247, 0.18);
}

#quick-emoji-panel .quick-emoji-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#quick-emoji-panel .quick-emoji-button:active {
  transform: scale(0.95);
}

#input {
  flex: 1;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  padding: var(--input-field-padding-y) var(--input-field-padding-x);
  font-size: var(--input-font-size);
  background: var(--input-bg);
  color: var(--text-primary);
  outline: none;
}

#input::placeholder { color: var(--text-muted); }

#form button {
  margin-left: var(--input-button-gap);
  border: none;
  background: none;
  font-size: var(--input-button-font-size);
  cursor: pointer;
  color: var(--text-primary);
  transition: transform 0.15s ease;
}

#form button:hover { transform: scale(1.2); }

#voice-btn {
  position: relative;
  font-size: 1.4em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  min-width: var(--input-icon-size);
}

#voice-btn.recording {
  color: #ff4d6d;
  background: rgba(255, 77, 109, 0.18);
  border-radius: 999px;
  box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.45);
  animation: voice-btn-pulse 1.1s ease-in-out infinite;
}

body:not(.dark) #voice-btn.recording {
  color: #c9184a;
  background: rgba(255, 77, 109, 0.12);
}

#voice-btn.recording:hover,
#voice-btn.recording:focus-visible {
  transform: scale(1.05);
}

#voice-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes voice-btn-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.45);
  }
  100% {
    transform: scale(1.08);
    box-shadow: 0 0 0 8px rgba(255, 77, 109, 0);
  }
}

.voice-recording-modal {
  position: absolute;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  width: min(280px, calc(100% - 32px));
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  background: var(--surface-alt, var(--surface));
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 25;
}

.voice-recording-modal.visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.voice-recording-modal[hidden] {
  display: none;
}

.voice-recording-modal.finishing {
  cursor: progress;
}

.voice-recording-status {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.voice-meter {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

body:not(.dark) .voice-meter {
  background: rgba(0, 0, 0, 0.06);
}

.voice-meter-fill {
  --level: 0;
  height: 100%;
  width: calc(var(--level) * 100%);
  border-radius: inherit;
  background: linear-gradient(90deg, #4fc3f7, #1e88e5);
  transition: width 0.12s ease-out;
}

.voice-recording-timer {
  font-family: "SFMono-Regular", "Roboto Mono", "Fira Code", monospace;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-align: center;
}

.voice-recording-controls {
  display: flex;
  gap: 10px;
}

.voice-recording-controls button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 999px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.voice-recording-controls button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.voice-recording-controls button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.voice-recording-modal.finishing .voice-recording-controls button,
.voice-recording-controls button:disabled {
  opacity: 0.6;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

.voice-recording-finish {
  background: var(--accent);
  color: #fff;
}

body:not(.dark) .voice-recording-finish {
  color: #fff;
}

.voice-recording-cancel {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

@media (max-width: 720px) {
  .voice-recording-modal {
    bottom: calc(80px + env(safe-area-inset-bottom));
    width: min(320px, calc(100% - 16px));
  }
}

#gif-btn {
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--surface-alt);
  color: var(--text-primary);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

#gif-btn span[aria-hidden="true"] {
  pointer-events: none;
}

body.dark #gif-btn {
  background: rgba(123, 47, 247, 0.22);
  border-color: rgba(123, 47, 247, 0.45);
  color: #f5f0ff;
}

body:not(.dark) #gif-btn {
  background: rgba(123, 47, 247, 0.12);
  border-color: rgba(123, 47, 247, 0.35);
  color: #5b21b6;
}

#gif-btn:hover,
#gif-btn:focus-visible {
  background: #7b2ff7;
  color: #ffffff;
  border-color: #6820d7;
  box-shadow: 0 0 12px rgba(123, 47, 247, 0.45);
  transform: scale(1.1);
}

#gif-btn:focus-visible {
  outline: 2px solid rgba(123, 47, 247, 0.6);
  outline-offset: 2px;
}

#soundboard-btn {
  font-size: 1.05em;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--surface-alt);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

#soundboard-btn .soundboard-icon {
  font-size: 1.2em;
  line-height: 1;
}

body.dark #soundboard-btn {
  background: rgba(187, 134, 252, 0.22);
  border-color: rgba(187, 134, 252, 0.45);
  color: #f5f0ff;
}

body:not(.dark) #soundboard-btn {
  background: rgba(187, 134, 252, 0.12);
  border-color: rgba(187, 134, 252, 0.3);
  color: #5b21b6;
}

#soundboard-btn:hover,
#soundboard-btn:focus-visible {
  background: #b266ff;
  color: #ffffff;
  border-color: #8c3edd;
  box-shadow: 0 0 12px rgba(187, 134, 252, 0.45);
  transform: scale(1.08);
}

#soundboard-btn:focus-visible {
  outline: 2px solid rgba(187, 134, 252, 0.6);
  outline-offset: 2px;
}

/* ==============================
   Emoji Picker
   ============================== */
#emoji-picker {
  position: absolute;
  bottom: 60px;
  right: 20px;
  width: 320px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--picker-bg);
  border: 1px solid var(--picker-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
  z-index: 500;
  padding: 8px;
  color: var(--text-primary);
}

#emoji-picker.show {
  display: block;
}

#quick-emojis {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

#quick-emojis button {
  font-size: 1.5em;
  cursor: pointer;
  border: none;
  background: none;
  transition: transform 0.15s ease;
}

#quick-emojis button.pop { transform: scale(1.5); }

#emoji-search {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.9em;
  outline: none;
}

#emoji-search::placeholder { color: var(--text-muted); }

#emoji-catalog {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.emoji-category-title {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 6px;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border 0.12s ease, background 0.12s ease;
  color: var(--text-primary);
}

.emoji-item.emoji-item-image {
  height: 72px;
  padding: 4px;
  background: var(--surface-alt);
  border-color: var(--border-color);
  grid-column: span 2;
}

.emoji-item img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  pointer-events: none;
}

.emoji-item.emoji-item-image img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.emoji-item:hover {
  transform: translateY(-1px) scale(1.05);
  border-color: var(--border-color);
  background: var(--surface-alt);
}

.emoji-empty {
  text-align: center;
  padding: 12px 0;
  font-size: 0.85em;
  color: var(--text-muted);
}

/* ==============================
   Pinned Messages
   ============================== */
#pinned-messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--pinned-bg);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius);
  margin: 8px;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid rgba(37, 211, 102, 0.35);
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

#pinned-messages .pinned-entry {
  list-style: none;
  padding: 6px 8px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  font-size: 0.9em;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

#pinned-messages .pinned-entry:hover {
  background: var(--link-preview-hover);
  transform: translateY(-1px);
}

#pinned-messages .pinned-entry .pinned-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#pinned-messages .pinned-entry .pinned-meta {
  font-size: 0.75em;
  color: var(--text-muted);
}

/* ==============================
   Search Results Overlay
   ============================== */
#search-results {
  margin: 0 16px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: none;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

#search-results.show {
  display: flex;
}

#search-results .search-result-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#search-results .search-result-item:hover {
  background: var(--link-preview-hover);
}

#search-results .search-result-meta {
  font-size: 0.75em;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

#search-results .search-result-text {
  font-size: 0.85em;
  color: var(--text-primary);
}

/* ==============================
   Typing Bubble
   ============================== */
#typing-bubble {
  position: sticky;
  bottom: 60px;
  z-index: 10;
  background: var(--typing-bg);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.95em;
  color: var(--text-primary);
  text-align: center;
  align-self: center;
  max-width: 60%;
  word-wrap: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.2s ease;
  visibility: hidden;
  pointer-events: none;
}

#typing-bubble.show {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}

#typing-bubble.hide {
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  pointer-events: none;
}

/* ==============================
   File & Link Previews
   ============================== */
.file-preview { margin-top: 6px; max-width: 240px; border-radius: var(--radius); overflow: hidden; }

.inline-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(240px, 100%);
  border-radius: 16px;
  margin-top: 8px;
  background: var(--preview-bg);
  border: 1px solid var(--border-color);
  padding: 10px;
  box-sizing: border-box;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.inline-preview .embed-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}

.inline-preview .embed-links a {
  color: var(--accent);
  font-size: 0.8em;
  text-decoration: underline;
  word-break: break-all;
}

.inline-preview:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  border-color: rgba(123, 47, 247, 0.45);
}

.inline-preview.inline-image {
  padding: 8px;
  gap: 6px;
}

.inline-preview.inline-image .preview-media {
  min-height: 0;
  padding: 0;
  background: transparent;
}

.preview-media {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80px;
}

.preview-media img,
.preview-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.inline-preview.inline-image .preview-media img {
  height: auto;
  object-fit: contain;
}

.inline-preview.tenor-inline {
  width: min(220px, 100%);
  padding: 8px;
  gap: 6px;
}

.inline-preview.tenor-inline .preview-media {
  min-height: 0;
  background: transparent;
}

.inline-preview.tenor-inline .preview-media img,
.inline-preview.tenor-inline .preview-media video {
  height: auto;
  border-radius: 12px;
}

.inline-preview.tenor-inline .preview-actions {
  justify-content: space-between;
}

.preview-media video {
  background: #000;
}

.preview-media audio {
  width: 100%;
}

.soundcloud-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8em;
  color: var(--text-primary);
}

.soundcloud-controls button {
  border: none;
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.soundcloud-controls button:hover {
  background: rgba(0, 0, 0, 0.35);
}

.soundcloud-controls input[type="range"] {
  flex: 1;
}

.inline-preview.inline-audio .preview-media,
.inline-preview.inline-pdf .preview-media,
.inline-preview.inline-file .preview-media {
  background: var(--surface-alt);
  border: 1px dashed var(--border-color);
  padding: 20px 12px;
}

.inline-preview .preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  text-transform: uppercase;
  text-align: center;
}

.inline-preview .preview-label a {
  color: inherit;
  text-decoration: underline;
  word-break: break-word;
}

.inline-preview .preview-label a:hover,
.inline-preview .preview-label a:focus {
  color: var(--accent);
}

.preview-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.preview-actions .preview-open,
.preview-actions .preview-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(187, 134, 252, 0.4);
  background: rgba(187, 134, 252, 0.15);
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}

.preview-actions .preview-open:hover,
.preview-actions .preview-download:hover {
  background: rgba(187, 134, 252, 0.3);
  transform: translateY(-1px);
}

.preview-actions .preview-open {
  border-color: rgba(37, 211, 102, 0.35);
  background: rgba(37, 211, 102, 0.16);
}

.preview-actions .preview-open:hover {
  background: rgba(37, 211, 102, 0.28);
}

.embed-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.embed-iframe {
  width: min(340px, 100%);
  height: 190px;
  border: none;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.embed-iframe.spotify { height: 152px; }
.embed-iframe.soundcloud { height: 166px; background: transparent; }

.link-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(187, 134, 252, 0.25);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-top: 8px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.link-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(187, 134, 252, 0.3);
}

.link-card:focus {
  outline: 2px solid rgba(187, 134, 252, 0.8);
  outline-offset: 2px;
}

.link-card .link-thumb {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.08);
}

.link-card .link-thumb.link-thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  background: linear-gradient(135deg, rgba(187, 134, 252, 0.35), rgba(37, 211, 102, 0.3));
}

.link-card .link-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.link-card .link-domain {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.link-card .link-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.link-card .link-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.link-card .link-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.4));
}

#media-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 4000;
}

#media-lightbox.show {
  display: flex;
}

#media-lightbox .media-frame {
  background: rgba(15, 15, 15, 0.92);
  border-radius: 18px;
  padding: 20px;
  max-width: min(90vw, 960px);
  max-height: min(90vh, 720px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.media-frame .media-close {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

.media-frame .media-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-media {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.media-frame .media-caption {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
}

.link-preview {
  display: flex; align-items: center; gap: 8px; background: var(--link-preview-bg);
  border-radius: var(--radius); padding: 6px; margin-top: 6px; cursor: pointer; transition: background 0.2s ease, box-shadow 0.2s ease;
}
.link-preview:hover { background: var(--link-preview-hover); box-shadow: 0 6px 14px rgba(0,0,0,0.18); }
.link-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }

/* ==============================
   Animations
   ============================== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ==============================
   Responsive Adjustments
   ============================== */
@media (max-width: 640px) {
  body {
    --toolbar-padding-y: 8px;
    --toolbar-padding-x: 12px;
    --toolbar-gap: 10px;
    --toolbar-logo-size: 34px;
    --toolbar-control-height: 38px;
    --toolbar-button-padding-y: 4px;
    --toolbar-button-padding-x: 10px;
    --toolbar-icon-button-size: 36px;
    --toolbar-button-font-size: 0.9em;
    --toolbar-link-padding-y: 6px;
    --toolbar-link-padding-x: 12px;
    --toolbar-search-gap: 4px;
    --toolbar-search-padding-y: 3px;
    --toolbar-search-padding-x: 4px;
    --toolbar-search-margin-left: 10px;
    --toolbar-search-font-size: 0.8em;
    --room-name-font-size: 1em;
    --messages-padding-y: 8px;
    --messages-padding-x: 8px;
    --message-gap: 8px;
    --message-padding-y: 9px;
    --message-padding-x: 12px;
    --message-font-size: 0.95em;
    --message-meta-font-size: 0.7em;
    --scroll-to-latest-bottom: 96px;
    --scroll-to-latest-padding-y: 8px;
    --scroll-to-latest-padding-x: 14px;
    --scroll-to-latest-font-size: 0.85rem;
    --input-padding-y: 8px;
    --input-padding-x: 10px;
    --input-field-padding-y: 8px;
    --input-field-padding-x: 12px;
    --input-font-size: 0.95em;
    --input-button-gap: 4px;
    --input-button-font-size: 1.2em;
    --input-icon-size: 36px;
    --quick-emoji-gap: 4px;
    --quick-emoji-margin-left: 4px;
    --quick-emoji-size: 32px;
  }

  header {
    align-items: center;
    gap: 10px;
  }

  header .header-left {
    gap: 8px;
    justify-content: flex-start;
    width: 100%;
  }

  header .logo {
    width: var(--toolbar-logo-size);
    height: var(--toolbar-logo-size);
    max-width: var(--toolbar-logo-size);
    max-height: var(--toolbar-logo-size);
    flex-basis: var(--toolbar-logo-size);
  }

  #chat-container .search-bar {
    flex-direction: column;
    align-items: stretch;
    display: none;
  }

  #chat-container .search-bar input,
  #chat-container .search-bar select {
    width: 100%;
  }

  #chat-container header .header-right {
    gap: 6px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    align-items: stretch;
  }

  #emoji-picker { bottom: 60px; width: 90%; right: 5%; }
  #pinned-messages { max-height: 100px; margin: 4px; font-size: 0.85em; }
  #typing-bubble { bottom: 70px; font-size: 0.85em; max-width: 80%; }
  .message { max-width: 88%; font-size: 0.9em; padding: 8px 10px; }
  .message.has-inline-media {
    width: min(100%, 360px);
    max-width: min(100%, 360px);
    min-width: min(320px, 100%);
  }
  .link-preview img { width: 40px; height: 40px; }
  #input { font-size: 0.95em; }
  .header-right button {
    font-size: 0.85em;
    padding: 6px 12px;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }
  .header-right button#toggle-sounds {
    flex: 0 0 36px;
    align-self: center;
    width: auto;
  }
  .header-right button#toggle-density {
    width: auto;
  }
  #form {
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  #form button {
    margin-left: 0;
    flex: 0 1 auto;
  }
  #file-attach,
  #gif-btn,
  #soundboard-btn,
  #emoji-btn {
    order: 0;
  }
  #input {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
  }
  #form button[type="submit"] {
    order: 1;
    margin-left: 0;
  }
  #quick-emoji-panel {
    order: 2;
    display: flex;
    flex: 0 0 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-left: 0;
    gap: 6px;
    max-width: 100%;
    align-items: center;
    overflow-x: auto;
    padding-top: 4px;
  }
  .inline-preview { width: min(200px, 100%); }
}

@media (max-width: 480px) {
  header {
    --toolbar-logo-size: clamp(22px, 18vw, 26px);
  }

  header .header-left {
    gap: 6px;
  }
}

@media (max-width: 360px) {
  header {
    --toolbar-logo-size: clamp(20px, 22vw, 24px);
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  header {
    padding: 8px 12px;
  }

  #chat-container header .header-right {
    gap: 6px;
  }

  #messages {
    padding: 10px 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .scroll-to-latest {
    bottom: 88px;
  }

  #form {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  #username-prompt {
    padding: 24px 16px;
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
    gap: 12px;
  }
  #username-prompt .logo {
    width: min(120px, 60vw);
    max-height: min(120px, 60vw);
  }
  #username-prompt h1 { font-size: 1.4em; }
  .landing-inputs { width: 100%; max-width: 260px; flex-direction: column; gap: 8px; }
  .landing-inputs input { width: 100%; padding: 10px 12px; font-size: 0.95em; }
  #join-btn { width: 100%; padding: 10px; font-size: 1em; }
  #room-list h3 { font-size: 1em; }
  #public-room-list { gap: 6px; }
  #public-room-list li { font-size: 0.85em; padding: 5px 8px; }
  .inline-preview { width: min(180px, 100%); }
}

/* ==============================
   Scrollbar Styling
   ============================== */
#messages::-webkit-scrollbar,
#pinned-messages::-webkit-scrollbar,
#emoji-picker::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb,
#pinned-messages::-webkit-scrollbar-thumb,
#emoji-picker::-webkit-scrollbar-thumb { background: #444; border-radius: 6px; }
#messages::-webkit-scrollbar-track,
#pinned-messages::-webkit-scrollbar-track,
#emoji-picker::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); }

/* ==============================
   DIZY PURPLE PATCH
   ============================== */
.upload-progress {
  width: 100%;
  max-width: 360px;
  height: 6px;
  border-radius: 999px;
  background: rgba(123, 47, 247, 0.15);
  margin: 8px auto;
  overflow: hidden;
}

.upload-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: #7B2FF7;
  box-shadow: 0 0 12px rgba(123, 47, 247, 0.6) inset;
  transition: width .12s linear;
}

.inline-video,
.inline-audio,
.inline-pdf,
.inline-text {
  margin-top: 6px;
  border-radius: 12px;
  max-width: 100%;
  background: rgba(255,255,255,0.05);
}

#file-attach:hover,
#emoji-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(123,47,247,0.4);
}
/* DIZY PURPLE PATCH (Upload Progress + Media + Embeds) */
#upload-progress {
  width: 100%;
  height: 4px;
  background: #222;
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0 0;
  display: none;
}
#upload-progress::-webkit-progress-value { background: #bb86fc; }
#upload-progress::-moz-progress-bar { background: #bb86fc; }

.inline-image,
.file-preview {
  border-radius: 12px;
}

.embed-card {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(187,134,252,0.2);
}
.embed-card iframe {
  display: block;
  width: 100%;
  max-width: 420px;
  height: 240px;
  border: 0;
}
.link-preview-lite {
  display: inline-block;
  margin-top: 6px;
  max-width: 420px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  color: #bb86fc;
  text-decoration: none;
  word-break: break-word;
}

#file-attach:hover,
#emoji-btn:hover {
  transform: scale(1.1);
  filter: drop-shadow(0 0 6px rgba(187,134,252,0.45));
}
/* ==============================
   DIZY FUSION SUPERNOVA PATCH 💜
   ============================== */

/* Upload progress overlay */
.upload-progress {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  width: 260px;
  height: 8px;
  background: rgba(187,134,252,0.15);
  border-radius: 999px;
  overflow: hidden;
  z-index: 1000;
  text-align: center;
  color: #fff;
  font-size: 0.75em;
}
.upload-progress .bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg,#b266ff,#7B2FF7);
  box-shadow: 0 0 8px rgba(187,134,252,0.4);
  transition: width 0.25s ease;
}

/* GIF picker */
#gif-picker {
  position: fixed;
  bottom: 70px;
  left: 10px;
  width: 340px;
  max-height: 320px;
  overflow-y: auto;
  background: rgba(20,20,20,0.95);
  border: 1px solid rgba(187,134,252,0.25);
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(123,47,247,0.3);
  display: none;
  padding: 10px;
  z-index: 1000;
}
#gif-picker input {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #111;
  color: #fff;
  margin-bottom: 8px;
}
#gif-picker .gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  grid-auto-rows: 72px;
}
#gif-picker .gif-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#gif-picker .gif-thumb:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 8px rgba(187,134,252,0.45);
}

#soundboard-picker {
  position: fixed;
  bottom: 70px;
  left: 10px;
  width: 340px;
  max-height: 320px;
  display: none;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(187,134,252,0.25);
  box-shadow: 0 0 10px rgba(187,134,252,0.3);
  background: rgba(20,20,20,0.95);
  z-index: 1000;
}

#soundboard-picker .soundboard-search input {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #111;
  color: #fff;
  margin-bottom: 8px;
}

#soundboard-picker .soundboard-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
}

.soundboard-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(187,134,252,0.25);
  background: rgba(30,30,30,0.9);
  color: #f5f0ff;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.soundboard-item:hover,
.soundboard-item:focus-visible {
  background: rgba(178,102,255,0.9);
  box-shadow: 0 0 12px rgba(178,102,255,0.45);
  transform: translateY(-1px);
}

.soundboard-item:focus-visible {
  outline: 2px solid rgba(178,102,255,0.55);
  outline-offset: 2px;
}

.soundboard-item-icon {
  font-size: 1.2em;
  line-height: 1;
}

.soundboard-item-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.soundboard-item-title {
  font-weight: 600;
  font-size: 0.95em;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.soundboard-item-meta {
  font-size: 0.75em;
  color: rgba(240, 240, 255, 0.75);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.soundboard-status {
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed rgba(187,134,252,0.35);
  text-align: center;
  font-size: 0.9em;
  color: #e0d7ff;
}

.soundboard-status--loading {
  border-style: solid;
  border-color: rgba(187,134,252,0.45);
  background: rgba(187,134,252,0.12);
}

.soundboard-status--error {
  border-color: rgba(244,67,54,0.5);
  color: #ffbdb6;
}

.soundboard-status--warn {
  border-color: rgba(255,193,7,0.55);
  color: #ffe9a6;
}

body:not(.dark) #soundboard-picker {
  background: rgba(248,248,255,0.98);
  border-color: rgba(123,47,247,0.2);
  box-shadow: 0 0 10px rgba(123,47,247,0.2);
}

body:not(.dark) .soundboard-item {
  background: rgba(247,240,255,0.9);
  color: #39226b;
  border-color: rgba(123,47,247,0.25);
}

body:not(.dark) .soundboard-item-meta {
  color: rgba(57,34,107,0.7);
}

body:not(.dark) .soundboard-item:hover,
body:not(.dark) .soundboard-item:focus-visible {
  background: rgba(123,47,247,0.18);
  color: #24104c;
  box-shadow: 0 0 10px rgba(123,47,247,0.25);
}

body:not(.dark) .soundboard-status {
  color: #39226b;
  border-color: rgba(123,47,247,0.25);
}

body:not(.dark) .soundboard-status--loading {
  background: rgba(123,47,247,0.08);
}

/* Admin badge and system messages */
.admin-badge {
  margin-left: 8px;
  padding: 2px 6px;
  background: rgba(187,134,252,0.2);
  border-radius: 8px;
  font-size: 0.8em;
  color: #bb86fc;
}
.system-bubble {
  text-align: center;
  background: rgba(187,134,252,0.1);
  border-left: 3px solid #bb86fc;
  border-radius: 10px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 0.9em;
  color: #d1b9ff;
}

/* ==============================
   Dialogs
   ============================== */
.confirm-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}

.confirm-dialog {
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  width: min(320px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
}

.confirm-dialog h3 {
  margin: 0;
  font-size: 1.1em;
}

.confirm-dialog .confirm-dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-dialog .confirm-dialog-actions button {
  flex: 1;
  border-radius: 10px;
  border: none;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

.confirm-dialog .confirm-dialog-actions button.primary {
  background: var(--accent);
  color: #fff;
}

.confirm-dialog .confirm-dialog-actions button.danger {
  background: #ff4d4d;
  color: #fff;
}

.confirm-dialog .confirm-dialog-actions button.neutral {
  background: var(--surface-alt);
  color: var(--text-primary);
}
/* ==============================
   DIZY TOAST NOTIFICATIONS 💜
   ============================== */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 200px;
  max-width: 280px;
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 0 8px rgba(187, 134, 252, 0.4);
  font-size: 0.9em;
  opacity: 0;
  transform: translateX(20px);
  animation: toastSlide 0.4s ease forwards;
}

.toast.success { border-left: 4px solid #7B2FF7; }
.toast.error { border-left: 4px solid #ff4d4d; }
.toast.info { border-left: 4px solid #25d366; }

@keyframes toastSlide {
  to { opacity: 1; transform: translateX(0); }
}

.toast.hide {
  animation: toastHide 0.3s ease forwards;
}
@keyframes toastHide {
  to { opacity: 0; transform: translateX(30px); }
}
/* ==============================
   DIZY PURPLE GLOW PATCH 🌌
   ============================== */

/* Toasts — bottom-left, glowing, fade + slide stack */
.toast-container {
  position: fixed;
  bottom: 76px;
  left: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9em;
  min-width: 200px;
  max-width: 320px;
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  font-weight: 500;
  animation: toastPop 0.25s ease forwards;
}

/* Success, Error, and Info Toasts */
.toast.success {
  border-left: 4px solid #2ecc71;
  box-shadow: 0 0 10px rgba(46, 204, 113, 0.45);
}

.toast.error {
  border-left: 4px solid #e74c3c;
  box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.toast.info {
  border-left: 4px solid #bb86fc;
  box-shadow: 0 0 10px rgba(187, 134, 252, 0.55);
}

/* Embed / Link Card Glow */
.embed-iframe,
.embed-image,
.embed-media,
.embed-audio {
  border-radius: 10px;
  box-shadow: 0 0 8px rgba(187, 134, 252, 0.25);
}

/* Toast Slide Up & Fade Animation */
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-12px) translateY(10px); }
  100% { opacity: 1; transform: translateX(0) translateY(0); }
}

/* Toast container auto-stack animation */
.toast-container .toast:nth-child(1) {
  animation-delay: 0s;
}

.toast-container .toast:nth-child(2) {
  animation-delay: 0.15s;
}

.toast-container .toast:nth-child(3) {
  animation-delay: 0.3s;
}

.toast-container .toast:nth-child(4) {
  animation-delay: 0.45s;
}

.toast-container .toast:nth-child(5) {
  animation-delay: 0.6s;
}
